Fix BadMethodCallException and remaining PostgreSQL issues

This commit is contained in:
2026-05-14 12:24:33 +07:00
parent b76d34cc64
commit ce2b815b07
4 changed files with 18 additions and 6 deletions

View File

@@ -241,7 +241,7 @@ public function incomeExpense(Request $request)
$data['expenses'] = Sale::where('business_id', auth()->user()->business_id) $data['expenses'] = Sale::where('business_id', auth()->user()->business_id)
->whereYear('created_at', request('year') ?? date('Y')) ->whereYear('created_at', request('year') ?? date('Y'))
->where('lossProfit', '<', 0) ->where('lossProfit', '<', 0)
->selectRaw("EXTRACT(MONTH FROM created_at) as month_number, TO_CHAR(created_at, 'Month') as month, SUM(ABS(lossProfit)) as total") ->selectRaw("EXTRACT(MONTH FROM created_at) as month_number, TO_CHAR(created_at, 'Month') as month, SUM(ABS(\"lossProfit\")) as total")
->groupBy('month_number', 'month') ->groupBy('month_number', 'month')
->orderBy('month_number') ->orderBy('month_number')
->get(); ->get();
@@ -249,7 +249,7 @@ public function incomeExpense(Request $request)
$data['incomes'] = Sale::where('business_id', auth()->user()->business_id) $data['incomes'] = Sale::where('business_id', auth()->user()->business_id)
->whereYear('created_at', request('year') ?? date('Y')) ->whereYear('created_at', request('year') ?? date('Y'))
->where('lossProfit', '>=', 0) ->where('lossProfit', '>=', 0)
->selectRaw("EXTRACT(MONTH FROM created_at) as month_number, TO_CHAR(created_at, 'Month') as month, SUM(ABS(lossProfit)) as total") ->selectRaw("EXTRACT(MONTH FROM created_at) as month_number, TO_CHAR(created_at, 'Month') as month, SUM(ABS(\"lossProfit\")) as total")
->groupBy('month_number', 'month') ->groupBy('month_number', 'month')
->orderBy('month_number') ->orderBy('month_number')
->get(); ->get();

View File

@@ -34,8 +34,9 @@ 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("TO_CHAR(created_at, 'Month') as month, SUM(price) as total_amount") ->selectRaw("TO_CHAR(created_at, 'FMMonth') as month, SUM(price) as total_amount")
->groupBy('month') ->groupBy(DB::raw("TO_CHAR(created_at, 'FMMonth')"))
->orderBy(DB::raw("MIN(created_at)"))
->get(); ->get();
return response()->json($subscriptions); return response()->json($subscriptions);

View File

@@ -118,7 +118,7 @@ public function dashboard()
$sales_data = Sale::selectRaw("TO_CHAR(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(DB::raw("TO_CHAR(created_at, '$dateFormatSQL')"))
->orderBy('date') ->orderBy('date')
->get() ->get()
->map(function ($item) { ->map(function ($item) {
@@ -131,7 +131,7 @@ public function dashboard()
$purchase_data = Purchase::selectRaw("TO_CHAR(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(DB::raw("TO_CHAR(created_at, '$dateFormatSQL')"))
->orderBy('date') ->orderBy('date')
->get() ->get()
->map(function ($item) { ->map(function ($item) {

View File

@@ -84,6 +84,17 @@ public function dueCollect()
{ {
return $this->hasOne(DueCollect::class); return $this->hasOne(DueCollect::class);
} }
public function dueForBranch($branchId = null)
{
$query = $this->type === 'Supplier' ? $this->purchases_dues() : $this->sales_dues();
if ($branchId) {
$query->where('branch_id', $branchId);
}
return $query->sum('dueAmount');
}
/** /**
* The attributes that should be cast to native types. * The attributes that should be cast to native types.
* *