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()); + } } });