perbaikan bug dashboard
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m20s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 14s
Build, Push and Deploy / deploy-staging (push) Successful in 26s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-18 19:55:00 +07:00
5 changed files with 20 additions and 20 deletions

View File

@@ -34,7 +34,7 @@ public function getDashboardData()
public function yearlySubscriptions() public function yearlySubscriptions()
{ {
$subscriptions = PlanSubscribe::whereYear('created_at', request('year') ?? date('Y')) $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') ->groupBy('month')
->get(); ->get();

View File

@@ -33,13 +33,13 @@ public function lossProfit(Request $request)
$salesQuery = DB::table('sales') $salesQuery = DB::table('sales')
->select( ->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(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) ->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId)) ->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); $this->applyDateFilter($salesQuery, $duration, 'saleDate', $request->from_date, $request->to_date);
@@ -56,12 +56,12 @@ public function lossProfit(Request $request)
$incomeQuery = DB::table('incomes') $incomeQuery = DB::table('incomes')
->select( ->select(
DB::raw('DATE(incomeDate) as date'), DB::raw('"incomeDate"::date as date'),
DB::raw('SUM(amount) as total_incomes') DB::raw('SUM(amount) as total_incomes')
) )
->where('business_id', $businessId) ->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId)) ->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); $this->applyDateFilter($incomeQuery, $duration, 'incomeDate', $request->from_date, $request->to_date);
$dailyIncomes = $incomeQuery->get(); $dailyIncomes = $incomeQuery->get();
@@ -92,12 +92,12 @@ public function lossProfit(Request $request)
if (moduleCheck('HrmAddon')) { if (moduleCheck('HrmAddon')) {
$payrollQuery = DB::table('payrolls') $payrollQuery = DB::table('payrolls')
->select( ->select(
DB::raw('DATE(date) as date'), DB::raw('date::date as date'),
DB::raw('SUM(amount) as total_payrolls') DB::raw('SUM(amount) as total_payrolls')
) )
->where('business_id', $businessId) ->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId)) ->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); $this->applyDateFilter($payrollQuery, $duration, 'date', $request->from_date, $request->to_date);
$dailyPayrolls = $payrollQuery->get(); $dailyPayrolls = $payrollQuery->get();
@@ -105,12 +105,12 @@ public function lossProfit(Request $request)
$expenseQuery = DB::table('expenses') $expenseQuery = DB::table('expenses')
->select( ->select(
DB::raw('DATE(expenseDate) as date'), DB::raw('"expenseDate"::date as date'),
DB::raw('SUM(amount) as total_expenses_only') DB::raw('SUM(amount) as total_expenses_only')
) )
->where('business_id', $businessId) ->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId)) ->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); $this->applyDateFilter($expenseQuery, $duration, 'expenseDate', $request->from_date, $request->to_date);
$dailyExpenses = $expenseQuery->get(); $dailyExpenses = $expenseQuery->get();

View File

@@ -106,16 +106,16 @@ public function dashboard()
return response()->json(['error' => 'Invalid duration'], 400); return response()->json(['error' => 'Invalid duration'], 400);
} }
// SQL date format for grouping // SQL date format for grouping (PostgreSQL TO_CHAR format)
$dateFormatSQL = match ($format) { $dateFormatSQL = match ($format) {
'H' => '%H', 'H' => 'HH24',
'd' => '%Y-%m-%d', 'd' => 'YYYY-MM-DD',
'M' => '%Y-%m', 'M' => 'YYYY-MM',
default => '%Y-%m-%d', default => 'YYYY-MM-DD',
}; };
// Sales data fetch and map // 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) ->where('business_id', $business_id)
->whereBetween('created_at', [$start, $end]) ->whereBetween('created_at', [$start, $end])
->groupBy('date') ->groupBy('date')
@@ -128,7 +128,7 @@ public function dashboard()
->keyBy('date'); ->keyBy('date');
// Purchase data fetch and map // 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) ->where('business_id', $business_id)
->whereBetween('created_at', [$start, $end]) ->whereBetween('created_at', [$start, $end])
->groupBy('date') ->groupBy('date')

View File

@@ -34,7 +34,7 @@ protected static function boot()
static::creating(function ($transfer) { static::creating(function ($transfer) {
$lastNumber = (int) self::whereNotNull('invoice_no') $lastNumber = (int) self::whereNotNull('invoice_no')
->orderByDesc('id') ->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); $transfer->invoice_no = str_pad($lastNumber + 1, 5, '0', STR_PAD_LEFT);
}); });

View File

@@ -3,7 +3,7 @@
'name' => 'laravel/laravel', 'name' => 'laravel/laravel',
'pretty_version' => 'dev-main', 'pretty_version' => 'dev-main',
'version' => 'dev-main', 'version' => 'dev-main',
'reference' => '1228c5253893609f4a5e4925446eea451b71ebfc', 'reference' => 'e2fa4d2d7b9354d862c244652af2d69b1b43c608',
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@@ -778,7 +778,7 @@
'laravel/laravel' => array( 'laravel/laravel' => array(
'pretty_version' => 'dev-main', 'pretty_version' => 'dev-main',
'version' => 'dev-main', 'version' => 'dev-main',
'reference' => '1228c5253893609f4a5e4925446eea451b71ebfc', 'reference' => 'e2fa4d2d7b9354d862c244652af2d69b1b43c608',
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),