From 90ceb2ec190a56a2b8be22b5c46d0391d1391c17 Mon Sep 17 00:00:00 2001 From: eko54r Date: Wed, 22 Apr 2026 17:59:25 +0700 Subject: [PATCH] update revenue chart --- .../App/Http/Controllers/DashboardController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/Business/App/Http/Controllers/DashboardController.php b/Modules/Business/App/Http/Controllers/DashboardController.php index e6a10824..5da2f9a7 100644 --- a/Modules/Business/App/Http/Controllers/DashboardController.php +++ b/Modules/Business/App/Http/Controllers/DashboardController.php @@ -196,17 +196,17 @@ public function revenue() $data['loss'] = Sale::where('business_id', auth()->user()->business_id) ->whereYear('created_at', request('year') ?? date('Y')) ->where('lossProfit', '<', 0) - ->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)") ->get(); $data['profit'] = Sale::where('business_id', auth()->user()->business_id) ->whereYear('created_at', request('year') ?? date('Y')) ->where('lossProfit', '>=', 0) - ->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)") ->get(); return response()->json($data);