perbaikan bug dashboard
All checks were successful
All checks were successful
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user