feat: Add branch selection for admins when creating shifts

This commit is contained in:
2026-07-15 11:07:59 +08:00
parent 5a40ae9b75
commit cb4f4dfb1c
420 changed files with 25069 additions and 14524 deletions

View File

@@ -84,8 +84,11 @@ class ShiftController extends Controller
'day' => (clone $allShifts)->where('is_night_shift', false)->count(),
];
$branches = \App\Models\Branch::whereIn('created_by', getCompanyAndUsersId())->get(['id', 'name']);
return Inertia::render('hr/shifts/index', [
'shifts' => $shifts,
'branches' => $branches,
'stats' => $stats,
'filters' => $request->all(['search', 'status', 'shift_type', 'sort_field', 'sort_direction', 'per_page']),
]);
@@ -116,7 +119,7 @@ class ShiftController extends Controller
if (!Auth::user()->can('manage-any-shifts')) {
$validated['branch_id'] = Auth::user()->branch_id ?? Auth::user()->employee->branch_id ?? null;
} else {
$validated['branch_id'] = null; // company wide
$validated['branch_id'] = $request->input('branch_id') ?: null;
}
// Check if shift with same name already exists
@@ -163,8 +166,15 @@ class ShiftController extends Controller
'grace_period' => 'required|integer|min:0',
'is_night_shift' => 'boolean',
'status' => 'nullable|in:active,inactive',
'branch_id' => 'nullable|exists:branches,id',
]);
if (!Auth::user()->can('manage-any-shifts')) {
$validated['branch_id'] = Auth::user()->branch_id ?? Auth::user()->employee->branch_id ?? null;
} else {
$validated['branch_id'] = $request->input('branch_id') ?: null;
}
// Check if shift with same name already exists (excluding current)
$exists = Shift::where('name', $validated['name'])
->whereIn('created_by', getCompanyAndUsersId())