From 2239d18068cb8e7303088f3ed2ad749343baf631 Mon Sep 17 00:00:00 2001 From: khaangnguyeen <78076796+khengyun@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:13:47 +0700 Subject: [PATCH 1/4] Update chartRevenueByDay.jspf --- .../admin/components/chartRevenueByDay.jspf | 74 +++++++++---------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/src/main/webapp/WEB-INF/jspf/admin/components/chartRevenueByDay.jspf b/src/main/webapp/WEB-INF/jspf/admin/components/chartRevenueByDay.jspf index e0a3256b..c3d2c28d 100644 --- a/src/main/webapp/WEB-INF/jspf/admin/components/chartRevenueByDay.jspf +++ b/src/main/webapp/WEB-INF/jspf/admin/components/chartRevenueByDay.jspf @@ -5,44 +5,40 @@ \ No newline at end of file + new Chart(weeklyRevenueChart, { + type: "line", + data: { + labels: dates, + datasets: [ + { + label: "Doanh thu", + data: weeklyRevenue, + borderWidth: 1, + }, + ], + }, + options: { + scales: { + y: { + beginAtZero: false, + }, + }, + responsive: true, + maintainAspectRatio: false, + }, + }); + }) + .catch((error) => { + console.error("Error fetching data:", error); + }); + From 8ef718018f5615c488fae9d87d67903e078c4ab1 Mon Sep 17 00:00:00 2001 From: khaangnguyeen <78076796+khengyun@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:14:03 +0700 Subject: [PATCH 2/4] Create todayview.jspf --- .../jspf/admin/components/todayview.jspf | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/webapp/WEB-INF/jspf/admin/components/todayview.jspf diff --git a/src/main/webapp/WEB-INF/jspf/admin/components/todayview.jspf b/src/main/webapp/WEB-INF/jspf/admin/components/todayview.jspf new file mode 100644 index 00000000..f948ce5c --- /dev/null +++ b/src/main/webapp/WEB-INF/jspf/admin/components/todayview.jspf @@ -0,0 +1,45 @@ +<%@ page pageEncoding="UTF-8" %> +
+

Số liệu hôm nay

+
+
+

20.035.000đ

+
Doanh thu bán hàng
+
+
+

354

+
Đơn hàng
+
+
+

2.138

+
Khách thăm
+
+
+

21

+
khách vip hôm nay
+
+
+

Cơm gà xối mỡ

+
Món bán chạy nhất
+
+
+
+ + From 11a0014b79408993166f9cd823ca18043534e018 Mon Sep 17 00:00:00 2001 From: khaangnguyeen <78076796+khengyun@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:14:15 +0700 Subject: [PATCH 3/4] Update Food.py --- api/psqlserver/model/Food.py | 46 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/api/psqlserver/model/Food.py b/api/psqlserver/model/Food.py index 19c057c1..5b704e83 100644 --- a/api/psqlserver/model/Food.py +++ b/api/psqlserver/model/Food.py @@ -78,30 +78,52 @@ def search_food_by_name(self, food_name: str): def get_daily_revenue(self): try: - today = date.today() with pymssql.connect(**self.db_config) as conn: cursor = conn.cursor() - cursor.execute(""" - SELECT SUM(CI.food_quantity * F.food_price) AS daily_revenue - FROM [Order] AS O - INNER JOIN CartItem AS CI ON O.cart_id = CI.cart_id - INNER JOIN Food AS F ON CI.food_id = F.food_id - WHERE CAST(O.order_time AS DATE) = %s - """, (today,)) + WITH DailySales AS ( + SELECT + A.account_username, + CI.food_id, + SUM(CI.food_quantity) AS total_items_sold + FROM [Order] AS O + INNER JOIN CartItem AS CI ON O.cart_id = CI.cart_id + INNER JOIN Account AS A ON O.customer_id = A.customer_id + WHERE CAST(CONVERT(DATE, O.order_time) AS DATE) = CAST(GETDATE() AS DATE) + GROUP BY A.account_username, CI.food_id + ) + + + + SELECT + SUM(CI.food_quantity * F.food_price) AS daily_revenue, + COUNT(O.order_id) AS daily_orders, + A.account_username AS customer_with_most_orders + FROM [Order] AS O + INNER JOIN CartItem AS CI ON O.cart_id = CI.cart_id + INNER JOIN Food AS F ON CI.food_id = F.food_id + INNER JOIN Account AS A ON O.customer_id = A.customer_id + WHERE CAST(CONVERT(DATE, O.order_time) AS DATE) = CAST(GETDATE() AS DATE) + GROUP BY A.account_username; + + """) row = cursor.fetchone() - daily_revenue = float(row[0]) if row else 0.0 - return daily_revenue + result = { + 'daily_revenue': float(row[0]) if row else 0.0, + 'daily_orders': int(row[1]) if row else 0, + 'customer_with_most_orders': row[2] if row else 0 + } + + return result except Exception as e: - return str(e) + return {'error': str(e)} def get_top_selling_foods(self): try: with pymssql.connect(**self.db_config) as conn: cursor = conn.cursor() - cursor.execute(""" SELECT TOP 5 F.food_id, From afb0397fe4c941fb4a26f82416575d572e4c8824 Mon Sep 17 00:00:00 2001 From: khaangnguyeen <78076796+khengyun@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:14:29 +0700 Subject: [PATCH 4/4] Update home.jspf --- src/main/webapp/WEB-INF/jspf/admin/home.jspf | 30 ++------------------ 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/main/webapp/WEB-INF/jspf/admin/home.jspf b/src/main/webapp/WEB-INF/jspf/admin/home.jspf index 4eee3dc4..6b3104bf 100644 --- a/src/main/webapp/WEB-INF/jspf/admin/home.jspf +++ b/src/main/webapp/WEB-INF/jspf/admin/home.jspf @@ -7,33 +7,10 @@ 14) { greeting = "Chào buổi trưa"; } else if (hour >= 14 && hour < 18) { greeting = "Chào buổi chiều"; } else { greeting = "Chào buổi tối"; } %>

<%= greeting %>, ${adminName}!

- + -
-

Số liệu hôm nay

-
-
-

20.035.000đ

-
Doanh thu bán hàng
-
-
-

354

-
Đơn hàng
-
-
-

2.138

-
Khách thăm
-
-
-

21

-
Khách hàng mới
-
-
-

Cơm gà xối mỡ

-
Món bán chạy nhất
-
-
-
+ <%@ include file="components/todayview.jspf" %> +
@@ -53,5 +30,4 @@ <%@ include file="components/chartMonthlyTarget.jspf" %>
-