From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Preparing total revenue report

Preparing total revenue report

In this lecture, we will implement the revenue report where we will show the total revenue generated by all the purchases. So we will calculate the total amount of the grand total price column of the sales master table, and we will show it in the revenue report. We will start by fetching the data from the sales master table. So inside the get dashboard data function, I will fetch all the data by using the db.findMany method. Now I will calculate the total revenue using the array.reduce method. Here we get the total value for each purchase in the grand total price attribute. So I will say const totalRevenue is equal to salesMasterData.reduce. Now there will be accumulator, sale. And then I will say accumulator plus sale.grandTotalPrice, 0. And I will add a totalRevenue variable inside the dashboard data object. Now I will open the dashboard component and will copy one of the cards and paste it below. Then I will change the title with total revenue and the value will be…

Contents