Files
kulakpos_web/walkthroughs/2026-04-22_2957c4ca_Walkthrough__Revenue_Chart_Fix.md
eko54r 05fd3230b8
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped
update marketing
2026-05-14 11:55:22 +07:00

1.8 KiB

Walkthrough - Revenue Chart Fix

I have fixed the issue where the revenue chart was not displaying data on the business dashboard. The root cause was a mismatch between the PostgreSQL output format for month names and the expected format in the frontend JavaScript, combined with incorrect database grouping.

Changes Made

Business Module

DashboardController.php

I updated the revenue method to ensure correct data aggregation and formatting for PostgreSQL:

  • FM (Fill Mode): Changed TO_CHAR(created_at, 'Month') to TO_CHAR(created_at, 'FMMonth'). This removes trailing spaces from month names (e.g., "January " becomes "January"), allowing them to match the keys expected by the frontend.
  • Grouping and Sorting: Replaced groupBy('created_at') and orderBy('created_at') with logic that correctly aggregates data by month using DATE_TRUNC('month', created_at).
-            ->selectRaw("TO_CHAR(created_at, 'Month') as month, SUM(ABS(lossProfit)) as total")
-            ->orderBy('created_at')
-            ->groupBy('created_at')
+            ->selectRaw("TO_CHAR(created_at, 'FMMonth') as month, SUM(ABS(lossProfit)) as total")
+            ->groupByRaw("TO_CHAR(created_at, 'FMMonth'), DATE_TRUNC('month', created_at)")
+            ->orderByRaw("DATE_TRUNC('month', created_at)")

Verification Results

Logic Verification

  • The use of FMMonth ensures that PostgreSQL returns strings like "January", "February", which directly match the getMonthNameFromIndex function in business-dashboard.js.
  • The updated grouping ensures that all sales within a single month are summed together into one data point per month, as expected by the chart rendering logic.