fix: make HR shift stats match the table query so counts are accurate

This commit is contained in:
2026-07-15 11:14:46 +08:00
parent 30a5aa6bdc
commit 930e71dfd8

View File

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