Commit bf710121 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix: Financial overview branch filter was querying non-existent column

The revenue query filtered by invoice_items.branch_id which doesn't
exist, causing 0 results when a branch is selected. Use
payments.branch_id directly since payments already track their branch.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 4b6ad2ee
...@@ -128,15 +128,20 @@ private function getRevenue($from, $to): array ...@@ -128,15 +128,20 @@ private function getRevenue($from, $to): array
->whereBetween('payment_date', [$from, $to]); ->whereBetween('payment_date', [$from, $to]);
if ($this->branch_id) { if ($this->branch_id) {
$query->whereHas('invoice', fn ($q) => $q->whereHas('items', fn ($iq) => $iq->where('branch_id', $this->branch_id))); $query->where('branch_id', $this->branch_id);
} }
$totalRevenue = $query->sum('amount'); $totalRevenue = $query->sum('amount');
$byMethod = Payment::where('direction', 'inbound') $byMethodQuery = Payment::where('direction', 'inbound')
->where('status', 'confirmed') ->where('status', 'confirmed')
->whereBetween('payment_date', [$from, $to]) ->whereBetween('payment_date', [$from, $to]);
->select('method', DB::raw('SUM(amount) as total'), DB::raw('COUNT(*) as count'))
if ($this->branch_id) {
$byMethodQuery->where('branch_id', $this->branch_id);
}
$byMethod = $byMethodQuery->select('method', DB::raw('SUM(amount) as total'), DB::raw('COUNT(*) as count'))
->groupBy('method') ->groupBy('method')
->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