Staff Module Documentation
Overview
The Staff Module acts as the central directory for human resources. It manages the identity, access, and daily lifecycle of every employee. It serves as the single source of truth for the HR/Payroll module (compensation data) and Housekeeping module (assignment data).
Key Features
- Centralized Profiles: Manages "Party" data (PII) separately from "Staff" data (Employment).
- Attendance Tracking: Supports Dual-Mode clocking (Web Dashboard for back-office, PIN Kiosk for operations).
- Leave Management: Automated balance checking, approval workflows, and cancellation logic.
- Role Management: Links staff to Departments (Front Office, Kitchen) and Positions.
- Document Management: Stores contracts, IDs, and certifications.
Architecture
Domain Layer (app/Domain/Staff)
Models (6 Models)
Staff (Staff.php)
- Table:
staff - Description: The employment record.
- Key Fields:
party_id: Link to PII (Name, Email, Phone).property_id: Tenant scope.employee_code: Unique ID (e.g., STF-1234).employee_pin: 4-digit PIN for Kiosk access.department_id,position_id: Organization links.base_salary: Monthly compensation amount.available_leave_days: Current balance.is_active: Employment status.
- Relationships:
party(): BelongsTo Party.user(): HasOne User (optional login).
StaffAttendance (StaffAttendance.php)
- Table:
staff_attendance - Description: Daily work log.
- Key Fields:
staff_id: Link to Staff.work_date: Date of shift.clock_in_time: Timestamp.clock_out_time: Timestamp.hours_worked: Calculated duration.
StaffLeaveRecord (StaffLeaveRecord.php)
- Table:
staff_leave_records - Description: A request for time off.
- Key Fields:
leave_type: ANNUAL | SICK | UNPAID | MATERNITY.start_date,end_date: Duration.status: PENDING | APPROVED | REJECTED | CANCELLED.days_taken: Calculated count.
Services
StaffManagementService (StaffManagementService.php)
Purpose: Handles the daily operations of staff management.
Key Methods:
createStaff(partyData, staffData)
Onboards a new hire.
- Logic:
- Creates
Partyrecord (PII). - Generates unique
employee_code(e.g., STF-9988). - Creates
Staffrecord linked to Party. - Returns unified entity.
- Creates
requestLeave(staff, type, dates)
Submits a time-off request.
- Logic:
- Calculates
daysTaken. - Validation: If type=ANNUAL, checks
staff.available_leave_days >= daysTaken. - Overlap Check: Prevents double-booking dates.
- Creates record (Status: PENDING).
- Calculates
approveLeave(record)
Manager authorizes the time off.
- Logic:
- Status -> APPROVED.
- Side Effect: If type=ANNUAL, decrements
staff.leave_days_used.
cancelLeave(record)
Restores balance if plans change.
- Logic:
- Status -> CANCELLED.
- Side Effect: If previously APPROVED ANNUAL leave, restores
staff.leave_days_used.
clockWithPin(pin)
Kiosk logic for shared terminals.
- Logic:
- Finds active staff by PIN.
- Smart Toggle:
- If no record for today -> Call
clockIn(). - If record exists & open -> Call
clockOut(). - If record exists & closed -> Error "Already completed today".
- If no record for today -> Call
Workflows
1. Hiring & Onboarding
- HR Entry: Admin enters "John Doe", "Chef", Salary $1000.
- System: Creates Party record + Staff record
STF-1001. - User Account: Admin toggles "Create Login". System sends invitation email to John.
- Kiosk Setup: Admin assigns PIN
1001. John can now use the kitchen tablet.
2. Time & Attendance (Kitchen API_
- Start Shift: John types
1001on Kitchen Tablet.- System: "Welcome John! Clocked in at 08:00 AM".
- End Shift: John types
1001on Kitchen Tablet.- System: "Goodbye John! Worked 9.0 hours".
3. Leave Request Cycle
- Request: John logs into Portal, requests 3 days for "Family Event".
- Validation: System checks balance (15 days avail). Allows request.
- Approval: Chef Manager gets notification. Clicks "Approve".
- Effect:
- Request -> APPROVED.
- Balance -> 12 days avail.
- Roster -> marked as "On Leave" for those dates.
- Cancellation (Optional): John cancels request.
- Balance -> 15 days avail.
Audit Findings & Improvements
Strengths
- Transactional Integrity: Leave workflows (Request/Approve/Cancel) are wrapped in DB transactions to ensure
available_leave_daysnever drifts. - PII Separation: Using the
Partymodel is excellent for GDPR/Privacy compliance, keeping strict separation between "The Person" and "The Job".
Issues Identified
Major
Major
- Hardcoded Context: [FIXED]
createStaffnow requires explicitproperty_idparameter, removing reliance on unsafe fallbacks.
Minor
- Time Logic:
calculateHoursis a simple subtraction. Needs logic for "Unpaid Breaks" (e.g., auto-deduct 30 mins if shift > 6h). - Shift Enforcement: Currently, staff can clock in at 3 AM for a 9 AM shift. Needs "Tolerance" settings (e.g., max 15 mins early).
Configuration
Config: config/staff.php
php
return [
'default_leave_days' => 21,
'currency' => 'USD',
];Module Version: 1.0 Status: Production Ready