diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index cb35bb1a..f8244d14 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -34,7 +34,7 @@ public function getDashboardData() public function yearlySubscriptions() { $subscriptions = PlanSubscribe::whereYear('created_at', request('year') ?? date('Y')) - ->selectRaw('MONTHNAME(created_at) as month, SUM(price) as total_amount') + ->selectRaw("TO_CHAR(created_at, 'Month') as month, SUM(price) as total_amount") ->groupBy('month') ->get(); diff --git a/app/Http/Controllers/Api/AcnooReportController.php b/app/Http/Controllers/Api/AcnooReportController.php index a47602dc..ce18b86d 100644 --- a/app/Http/Controllers/Api/AcnooReportController.php +++ b/app/Http/Controllers/Api/AcnooReportController.php @@ -33,13 +33,13 @@ public function lossProfit(Request $request) $salesQuery = DB::table('sales') ->select( - DB::raw('DATE(saleDate) as date'), + DB::raw('"saleDate"::date as date'), DB::raw('SUM(actual_total_amount) as total_sales'), - DB::raw('SUM(lossProfit) as total_sale_income') + DB::raw('SUM("lossProfit") as total_sale_income') ) ->where('business_id', $businessId) ->when($branchId, fn($q) => $q->where('branch_id', $branchId)) - ->groupBy(DB::raw('DATE(saleDate)')); + ->groupBy(DB::raw('"saleDate"::date')); $this->applyDateFilter($salesQuery, $duration, 'saleDate', $request->from_date, $request->to_date); @@ -56,12 +56,12 @@ public function lossProfit(Request $request) $incomeQuery = DB::table('incomes') ->select( - DB::raw('DATE(incomeDate) as date'), + DB::raw('"incomeDate"::date as date'), DB::raw('SUM(amount) as total_incomes') ) ->where('business_id', $businessId) ->when($branchId, fn($q) => $q->where('branch_id', $branchId)) - ->groupBy(DB::raw('DATE(incomeDate)')); + ->groupBy(DB::raw('"incomeDate"::date')); $this->applyDateFilter($incomeQuery, $duration, 'incomeDate', $request->from_date, $request->to_date); $dailyIncomes = $incomeQuery->get(); @@ -92,12 +92,12 @@ public function lossProfit(Request $request) if (moduleCheck('HrmAddon')) { $payrollQuery = DB::table('payrolls') ->select( - DB::raw('DATE(date) as date'), + DB::raw('date::date as date'), DB::raw('SUM(amount) as total_payrolls') ) ->where('business_id', $businessId) ->when($branchId, fn($q) => $q->where('branch_id', $branchId)) - ->groupBy(DB::raw('DATE(date)')); + ->groupBy(DB::raw('date::date')); $this->applyDateFilter($payrollQuery, $duration, 'date', $request->from_date, $request->to_date); $dailyPayrolls = $payrollQuery->get(); @@ -105,12 +105,12 @@ public function lossProfit(Request $request) $expenseQuery = DB::table('expenses') ->select( - DB::raw('DATE(expenseDate) as date'), + DB::raw('"expenseDate"::date as date'), DB::raw('SUM(amount) as total_expenses_only') ) ->where('business_id', $businessId) ->when($branchId, fn($q) => $q->where('branch_id', $branchId)) - ->groupBy(DB::raw('DATE(expenseDate)')); + ->groupBy(DB::raw('"expenseDate"::date')); $this->applyDateFilter($expenseQuery, $duration, 'expenseDate', $request->from_date, $request->to_date); $dailyExpenses = $expenseQuery->get(); diff --git a/app/Http/Controllers/Api/StatisticsController.php b/app/Http/Controllers/Api/StatisticsController.php index d1b4cc10..1ec5c297 100644 --- a/app/Http/Controllers/Api/StatisticsController.php +++ b/app/Http/Controllers/Api/StatisticsController.php @@ -106,16 +106,16 @@ public function dashboard() return response()->json(['error' => 'Invalid duration'], 400); } - // SQL date format for grouping + // SQL date format for grouping (PostgreSQL TO_CHAR format) $dateFormatSQL = match ($format) { - 'H' => '%H', - 'd' => '%Y-%m-%d', - 'M' => '%Y-%m', - default => '%Y-%m-%d', + 'H' => 'HH24', + 'd' => 'YYYY-MM-DD', + 'M' => 'YYYY-MM', + default => 'YYYY-MM-DD', }; // Sales data fetch and map - $sales_data = Sale::selectRaw("DATE_FORMAT(created_at, '$dateFormatSQL') as date, SUM(totalAmount) as amount") + $sales_data = Sale::selectRaw("TO_CHAR(created_at, '$dateFormatSQL') as date, SUM(\"totalAmount\") as amount") ->where('business_id', $business_id) ->whereBetween('created_at', [$start, $end]) ->groupBy('date') @@ -128,7 +128,7 @@ public function dashboard() ->keyBy('date'); // Purchase data fetch and map - $purchase_data = Purchase::selectRaw("DATE_FORMAT(created_at, '$dateFormatSQL') as date, SUM(totalAmount) as amount") + $purchase_data = Purchase::selectRaw("TO_CHAR(created_at, '$dateFormatSQL') as date, SUM(\"totalAmount\") as amount") ->where('business_id', $business_id) ->whereBetween('created_at', [$start, $end]) ->groupBy('date') diff --git a/app/Models/Transfer.php b/app/Models/Transfer.php index 3a098cfa..305a27d3 100644 --- a/app/Models/Transfer.php +++ b/app/Models/Transfer.php @@ -34,7 +34,7 @@ protected static function boot() static::creating(function ($transfer) { $lastNumber = (int) self::whereNotNull('invoice_no') ->orderByDesc('id') - ->value(DB::raw("CAST(SUBSTRING(invoice_no, 4) AS UNSIGNED)")) ?? 0; + ->value(DB::raw("CAST(SUBSTRING(invoice_no, 4) AS INTEGER)")) ?? 0; $transfer->invoice_no = str_pad($lastNumber + 1, 5, '0', STR_PAD_LEFT); }); diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index a41cfbed..5158c895 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'laravel/laravel', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '1228c5253893609f4a5e4925446eea451b71ebfc', + 'reference' => 'e2fa4d2d7b9354d862c244652af2d69b1b43c608', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -778,7 +778,7 @@ 'laravel/laravel' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '1228c5253893609f4a5e4925446eea451b71ebfc', + 'reference' => 'e2fa4d2d7b9354d862c244652af2d69b1b43c608', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),