build fix
This commit is contained in:
@@ -298,11 +298,13 @@ class ShiftController extends Controller
|
||||
});
|
||||
|
||||
$departments = \App\Models\Department::select('id', 'name')->get();
|
||||
$allShifts = \App\Models\Shift::whereIn('created_by', getCompanyAndUsersId())->where('status', 'active')->get();
|
||||
|
||||
return Inertia::render('hr/shifts/calendar', [
|
||||
'users' => $users,
|
||||
'dates' => $dates,
|
||||
'departments' => $departments,
|
||||
'shifts' => $allShifts,
|
||||
'filters' => [
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
@@ -313,4 +315,41 @@ class ShiftController extends Controller
|
||||
}
|
||||
return redirect()->back()->with('error', __('Permission Denied.'));
|
||||
}
|
||||
|
||||
public function assignShift(Request $request)
|
||||
{
|
||||
if (Auth::user()->can('manage-shifts')) {
|
||||
$validated = $request->validate([
|
||||
'employee_id' => 'required|exists:users,id',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'required|date|after_or_equal:start_date',
|
||||
'shift_id' => 'required_without:is_rest_day|nullable|exists:shifts,id',
|
||||
'is_rest_day' => 'boolean',
|
||||
]);
|
||||
|
||||
$startDate = \Carbon\Carbon::parse($validated['start_date']);
|
||||
$endDate = \Carbon\Carbon::parse($validated['end_date']);
|
||||
|
||||
$period = \Carbon\CarbonPeriod::create($startDate, $endDate);
|
||||
|
||||
foreach ($period as $date) {
|
||||
\App\Models\AttendanceRecord::updateOrCreate(
|
||||
[
|
||||
'employee_id' => $validated['employee_id'],
|
||||
'date' => $date->format('Y-m-d'),
|
||||
'created_by' => creatorId(),
|
||||
],
|
||||
[
|
||||
'shift_id' => $validated['is_rest_day'] ? null : $validated['shift_id'],
|
||||
'is_rest_day' => $validated['is_rest_day'] ?? false,
|
||||
'status' => $validated['is_rest_day'] ? 'absent' : 'present', // Default status for scheduled shift
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', __('Shifts assigned successfully.'));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', __('Permission Denied.'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user