Skip to content

Shifts (الورديات)

Shift definitions with automatic working hours calculation and per-shift attendance rules. Supports night shifts that cross midnight.

Attributes

FieldTypeDescription
idintegerPrimary key
name_arstringArabic name
name_enstringEnglish name (nullable)
start_timetimeShift start (HH:mm)
end_timetimeShift end (HH:mm)
break_duration_minutesintegerBreak duration in minutes (default 60)
working_hoursdecimalAuto-calculated working hours
is_night_shiftbooleanNight shift flag
grace_period_minutesintegerLegacy grace period (default 15)
overtime_start_after_minutesintegerMinutes after shift before overtime starts
late_threshold_minutesintegerMinutes before counting as late (default 60)
late_counts_fullbooleanIf true: late = all minutes from shift start. If false: only excess beyond threshold (default true)
max_late_before_absentintegerMaximum late minutes before auto-absent (default 180)
early_leave_threshold_minutesintegerEarly leave grace minutes (default 30)
early_leave_counts_fullbooleanSame logic as late_counts_full for early leave (default true)
flexibility_minutesintegerFlex time — can come late and compensate at end of day (default 0)
hours_per_daydecimal(4,1)How many hours equal one full day (default 6.0)
nursing_extra_minutesintegerExtra late threshold for nursing employees (default 60)
special_needs_extra_minutesintegerExtra threshold for special-needs employees (default 60)
presence_check_enabledbooleanWhether presence verification punch is required during shift (default false)
presence_check_intervalintegerMinutes between required presence checks (default 120)
colorstringColor code for UI
statusstringactive or inactive

API Endpoints

MethodURLDescription
GET/api/hr/shiftsList shifts (paginated)
POST/api/hr/shiftsCreate shift
GET/api/hr/shifts/{id}Show shift
PUT/api/hr/shifts/{id}Update shift
DELETE/api/hr/shifts/{id}Delete shift

Query Parameters

ParameterTypeDescription
statusstringFilter by active or inactive

Attendance Rules

Each shift has its own attendance settings that control how lateness and early leave are calculated:

Late Arrival Logic

  1. Employee checks in at actual_time
  2. Effective threshold = late_threshold_minutes + nursing bonus + special-needs bonus
  3. If actual_time - shift_start > effective_threshold:
    • If late_counts_full = true → late_minutes = total minutes from shift start
    • If late_counts_full = false → late_minutes = minutes beyond threshold only
  4. If actual_time - shift_start > max_late_before_absent → marked as absent

Early Leave Logic

  1. Employee checks out at actual_time
  2. Effective threshold = early_leave_threshold_minutes + special-needs bonus
  3. If shift_end - actual_time > effective_threshold:
    • If early_leave_counts_full = true → early_leave_minutes = total early minutes
    • If early_leave_counts_full = false → early_leave_minutes = minutes beyond threshold only

Nursing & Special Needs Exemptions

  • Nursing employees (is_nursing = true): get nursing_extra_minutes added to their late threshold
  • Special-needs employees (is_special_needs = true): get special_needs_extra_minutes added to both late and early-leave thresholds

Examples

bash
# Create a shift with attendance rules
curl -X POST "https://moon-erp.elbaset.com/api/hr/shifts" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "name_ar": "وردية صباحية",
    "name_en": "Morning Shift",
    "start_time": "08:00",
    "end_time": "16:00",
    "break_duration_minutes": 60,
    "late_threshold_minutes": 30,
    "late_counts_full": true,
    "max_late_before_absent": 120,
    "early_leave_threshold_minutes": 15,
    "hours_per_day": 7.0,
    "nursing_extra_minutes": 60,
    "special_needs_extra_minutes": 60,
    "status": "active"
  }'
dart
final response = await dio.post('/api/hr/shifts', data: {
  'name_ar': 'وردية صباحية',
  'name_en': 'Morning Shift',
  'start_time': '08:00',
  'end_time': '16:00',
  'break_duration_minutes': 60,
  'late_threshold_minutes': 30,
  'late_counts_full': true,
  'max_late_before_absent': 120,
  'early_leave_threshold_minutes': 15,
  'hours_per_day': 7.0,
  'nursing_extra_minutes': 60,
  'special_needs_extra_minutes': 60,
  'status': 'active',
});

Business Rules

  • working_hours is auto-calculated: (end_time - start_time - break) / 60
  • Night shifts crossing midnight are handled automatically (end_time < start_time adds 24h)
  • Cannot delete a shift that has future schedule assignments
  • All attendance settings have sensible defaults — existing shifts work without changes
  • Morning shift example: 08:00–16:00 with 60min break = 7.0 hours
  • Night shift example: 22:00–06:00 with 30min break = 7.5 hours

Moon ERP API Documentation