Files
HRM-System/docs/PLAN-shift-rest-days.md

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_days JSON column to the shifts table.
  • Provide a default value of ['saturday', 'sunday'] for existing rows to maintain current behavior.

Backend Models & Controllers

[MODIFY] app/Models/Shift.php

  • Add rest_days to the $fillable array.
  • Add $casts = ['rest_days' => 'array'] to handle automatic JSON serialization/deserialization.

[MODIFY] app/Http/Controllers/ShiftController.php

  • Update validation logic in store and update methods to accept rest_days as 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 the rest_days array of the employee's assigned shift.

[MODIFY] app/Services/PayrollService.php

  • Update the $isRestDay fallback logic.
  • Currently it falls back to $currentDate->isWeekend().
  • Change it to check: Does the day name of $currentDate exist in the employee's $shift->rest_days array? If the shift lacks the array, then fallback to weekend.

Verification Plan

Manual Verification

  1. Create a new shift (e.g., "BPO Night Shift") and set its Rest Days to Tuesday and Wednesday.
  2. Assign this shift to a test employee.
  3. Open the Attendance Calendar and click on a Tuesday. Verify the "Is Rest Day?" toggle appears or defaults correctly.
  4. Click on a Saturday (a standard weekend but NOT their rest day). Verify it treats it as a normal working day.
  5. Run Payroll and verify the DOLE multiplier ONLY applies if they work on Tuesday or Wednesday.