2.8 KiB
2.8 KiB
Fix Shift-Based Rest Days Configuration
Goal
Implement Option B: allow HR to configure specific rest days per Shift and have the Attendance Calendar and Payroll System automatically recognize those rest days instead of defaulting to global weekends.
User Review Required
Important
- Should "Rest Days" be treated as an array of days (e.g.,
['Saturday', 'Sunday']) or integers (e.g.,[6, 7]) in the database? Storing as an array of lowercase strings (['saturday', 'sunday']) is usually easiest for frontend dropdowns.- What should happen to existing Shifts? We will need to set a default (e.g., Saturday, Sunday) for all existing shifts during the database migration.
Proposed Changes
Database
[MODIFY] database/migrations/xxxx_add_rest_days_to_shifts_table.php
- Create a new migration to add a
rest_daysJSON column to theshiftstable. - Provide a default value of
['saturday', 'sunday']for existing rows to maintain current behavior.
Backend Models & Controllers
[MODIFY] app/Models/Shift.php
- Add
rest_daysto the$fillablearray. - Add
$casts = ['rest_days' => 'array']to handle automatic JSON serialization/deserialization.
[MODIFY] app/Http/Controllers/ShiftController.php
- Update validation logic in
storeandupdatemethods to acceptrest_daysas an array of strings.
Frontend UI (Shift Management)
[MODIFY] resources/js/Pages/hr/shifts/index.tsx
- Add a new "Rest Days" multi-select field (or group of checkboxes) to the Shift creation/edit modal.
- Allow HR to select any combination of days (Monday through Sunday).
Core Logic (Attendance & Payroll)
[MODIFY] resources/js/Pages/hr/attendance-records/calendar.tsx
- Update the conditional rendering logic for the "Is Rest Day? (For DOLE Multiplier)" toggle.
- Instead of relying on manual selection, make the toggle automatically default to
ON(or just automatically appear) if the selected date matches therest_daysarray of the employee's assigned shift.
[MODIFY] app/Services/PayrollService.php
- Update the
$isRestDayfallback logic. - Currently it falls back to
$currentDate->isWeekend(). - Change it to check: Does the day name of
$currentDateexist in the employee's$shift->rest_daysarray? If the shift lacks the array, then fallback to weekend.
Verification Plan
Manual Verification
- Create a new shift (e.g., "BPO Night Shift") and set its Rest Days to Tuesday and Wednesday.
- Assign this shift to a test employee.
- Open the Attendance Calendar and click on a Tuesday. Verify the "Is Rest Day?" toggle appears or defaults correctly.
- Click on a Saturday (a standard weekend but NOT their rest day). Verify it treats it as a normal working day.
- Run Payroll and verify the DOLE multiplier ONLY applies if they work on Tuesday or Wednesday.