From 930e71dfd8ea702573cb3277bc471df380ed8d1e Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 15 Jul 2026 11:14:46 +0800 Subject: [PATCH] fix: make HR shift stats match the table query so counts are accurate --- app/Http/Controllers/ShiftController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ShiftController.php b/app/Http/Controllers/ShiftController.php index a2209d735..ae5e73c15 100644 --- a/app/Http/Controllers/ShiftController.php +++ b/app/Http/Controllers/ShiftController.php @@ -70,10 +70,16 @@ class ShiftController extends Controller $allShifts = Shift::where(function ($q) { if (Auth::user()->can('manage-any-shifts')) { $q->whereIn('created_by', getCompanyAndUsersId()); - } elseif (Auth::user()->can('manage-own-shifts')) { - $q->where('created_by', Auth::id()); } else { - $q->whereRaw('1 = 0'); + $branchId = Auth::user()->branch_id ?? Auth::user()->employee->branch_id ?? null; + if ($branchId) { + $q->where(function($q2) use ($branchId) { + $q2->where('branch_id', $branchId) + ->orWhereNull('branch_id'); // company wide shifts + })->whereIn('created_by', getCompanyAndUsersId()); + } else { + $q->whereIn('created_by', getCompanyAndUsersId()); + } } });