Commit aecd624c authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix ReportService: invoices don't have branch_id, scope via billable morph

Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 8ba06281
...@@ -17,12 +17,12 @@ public function financialSummary(string $from, string $to, ?int $branchId = null ...@@ -17,12 +17,12 @@ public function financialSummary(string $from, string $to, ?int $branchId = null
{ {
return [ return [
'total_invoiced' => Invoice::whereBetween('created_at', [$from, $to]) 'total_invoiced' => Invoice::whereBetween('created_at', [$from, $to])
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('total_amount'), ->when($branchId, fn ($q) => $q->whereHasMorph('billable', [Participant::class], fn ($p) => $p->where('branch_id', $branchId)))->sum('total_amount'),
'total_collected' => Payment::where('status', 'confirmed') 'total_collected' => Payment::where('status', 'confirmed')
->whereBetween('created_at', [$from, $to]) ->whereBetween('created_at', [$from, $to])
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('amount'), ->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('amount'),
'total_outstanding' => Invoice::whereIn('status', ['sent', 'partially_paid', 'overdue']) 'total_outstanding' => Invoice::whereIn('status', ['sent', 'partially_paid', '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_revenue' => POSTransaction::whereBetween('processed_at', [$from, $to]) 'pos_revenue' => POSTransaction::whereBetween('processed_at', [$from, $to])
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('total_amount'), ->when($branchId, fn ($q) => $q->where('branch_id', $branchId))->sum('total_amount'),
'payment_methods' => Payment::where('status', 'confirmed') 'payment_methods' => Payment::where('status', 'confirmed')
......
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