Skip to content

Leave Requests (طلبات الإجازة)

Employees submit leave requests which go through an approval workflow. Includes calendar view and automatic balance deduction.

Attributes

FieldTypeDescription
idintegerPrimary key
employee_idintegerEmployee FK
leave_type_idintegerLeave Type FK
start_datedateLeave start date
end_datedateLeave end date
total_daysdecimalCalculated working days
reasonstringReason for leave
statusenumdraft, pending, manager_approved, approved, rejected, cancelled
attachment_pathstringAttachment file path (nullable)
contact_during_leavestringContact info while on leave (nullable)

Status Workflow

API Endpoints

MethodURLDescription
GET/api/hr/leave-requestsList leave requests
POST/api/hr/leave-requestsSubmit leave request
GET/api/hr/leave-requests/calendarCalendar view of leaves
GET/api/hr/leave-requests/{id}Show leave request
POST/api/hr/leave-requests/{id}/approveApprove request
POST/api/hr/leave-requests/{id}/rejectReject request
POST/api/hr/leave-requests/{id}/cancelCancel request

Query Parameters

ParameterTypeDescription
employee_idintegerFilter by employee
leave_type_idintegerFilter by leave type
statusstringFilter by status
date_fromdateFilter from date
date_todateFilter to date

Examples

bash
# Submit leave request
curl -X POST "https://moon-erp.elbaset.com/api/hr/leave-requests" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "employee_id": 1,
    "leave_type_id": 1,
    "start_date": "2026-03-10",
    "end_date": "2026-03-14",
    "reason": "Family vacation"
  }'

# Approve
curl -X POST "https://moon-erp.elbaset.com/api/hr/leave-requests/1/approve" \
  -H "Authorization: Bearer {token}"

# Reject
curl -X POST "https://moon-erp.elbaset.com/api/hr/leave-requests/1/reject" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{ "rejection_reason": "Team is understaffed this week" }'

# Calendar
curl -X GET "https://moon-erp.elbaset.com/api/hr/leave-requests/calendar?month=3&year=2026" \
  -H "Authorization: Bearer {token}"
dart
// Submit leave request
final response = await dio.post('/api/hr/leave-requests', data: {
  'employee_id': 1,
  'leave_type_id': 1,
  'start_date': '2026-03-10',
  'end_date': '2026-03-14',
  'reason': 'Family vacation',
});

// Approve
await dio.post('/api/hr/leave-requests/1/approve');

Business Rules

  • total_days is auto-calculated from working days (excludes weekends based on company settings)
  • Validates against the employee's remaining leave balance
  • requires_attachment on the leave type enforces file upload
  • Gender restriction on leave type is validated
  • Minimum service months checked against employee's hire date
  • Approving a leave request deducts from the employee's balance
  • Cancelling restores the balance

Moon ERP API Documentation