Commit 88148120 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix dashboard branch scoping: invoices don't have branch_id column

Invoices use billable morph (not direct branch_id). Scope through
whereHasMorph on the participant's branch_id instead.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 909a0b40
...@@ -48,7 +48,7 @@ public function render() ...@@ -48,7 +48,7 @@ public function render()
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('amount'), ->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('amount'),
'outstanding_invoices' => Invoice::whereIn('status', [ 'outstanding_invoices' => Invoice::whereIn('status', [
InvoiceStatus::Sent, InvoiceStatus::PartiallyPaid, InvoiceStatus::Overdue, InvoiceStatus::Sent, InvoiceStatus::PartiallyPaid, InvoiceStatus::Overdue,
])->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('due_amount'), ])->when($branchId, fn ($q) => $q->whereHasMorph('billable', [Participant::class], fn ($p) => $p->where('branch_id', $branchId)))->sum('due_amount'),
'pos_today' => POSTransaction::whereDate('processed_at', $today) 'pos_today' => POSTransaction::whereDate('processed_at', $today)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('total_amount'), ->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('total_amount'),
'pos_today_count' => POSTransaction::whereDate('processed_at', $today) 'pos_today_count' => POSTransaction::whereDate('processed_at', $today)
...@@ -90,8 +90,8 @@ public function render() ...@@ -90,8 +90,8 @@ public function render()
->count(); ->count();
$overdueInvoices = Invoice::where('status', InvoiceStatus::Overdue) $overdueInvoices = Invoice::where('status', InvoiceStatus::Overdue)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId)) ->when($branchId, fn ($q) => $q->whereHasMorph('billable', [Participant::class], fn ($p) => $p->where('branch_id', $branchId)))
->with('participant.person') ->with('billable')
->orderBy('due_date') ->orderBy('due_date')
->limit(5) ->limit(5)
->get(); ->get();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment