Employees (الموظفون)
Comprehensive employee management with lifecycle tracking, documents, emergency contacts, and dependents.
Attributes
| Field | Type | Description |
|---|---|---|
id | integer | Primary key |
employee_number | string | Auto-generated (EMP-0001) |
first_name_ar | string | Arabic first name |
last_name_ar | string | Arabic last name |
first_name_en | string | English first name (nullable) |
last_name_en | string | English last name (nullable) |
department_id | integer | Department FK (nullable) |
position_id | integer | Position FK (nullable) |
branch_id | integer | Branch FK (nullable) |
manager_id | integer | Direct manager (Employee FK, nullable) |
hire_date | date | Hire date |
contract_type | enum | permanent, contract, part_time, probation |
contract_start_date | date | Contract start (nullable) |
contract_end_date | date | Contract end (required if contract type) |
status | enum | active, on_leave, suspended, terminated, resigned |
basic_salary | decimal | Base salary |
payment_method | enum | bank_transfer, cash, check |
gender | string | male or female |
national_id | string | National ID (nullable) |
phone | string | Phone (nullable) |
email | string | Email (nullable) |
API Endpoints
| Method | URL | Description |
|---|---|---|
GET | /api/hr/employees | List employees (paginated) |
POST | /api/hr/employees | Create employee (with nested data) |
GET | /api/hr/employees/{id} | Show employee with all relations |
PUT | /api/hr/employees/{id} | Update employee |
DELETE | /api/hr/employees/{id} | Soft-delete employee |
PUT | /api/hr/employees/{id}/status | Change employee status |
POST | /api/hr/employees/{id}/documents | Add document |
DELETE | /api/hr/employees/{id}/documents/{doc} | Delete document |
Query Parameters
| Parameter | Type | Description |
|---|---|---|
department_id | integer | Filter by department |
position_id | integer | Filter by position |
status | string | Filter by status enum value |
search | string | Search by employee_number |
Create with Nested Data
When creating an employee, you can include documents, emergency contacts, and dependents in a single request:
bash
curl -X POST "https://moon-erp.elbaset.com/api/hr/employees" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"first_name_ar": "أحمد",
"last_name_ar": "محمد",
"first_name_en": "Ahmed",
"last_name_en": "Mohamed",
"hire_date": "2026-03-01",
"contract_type": "permanent",
"status": "active",
"basic_salary": 8000,
"payment_method": "bank_transfer",
"gender": "male",
"department_id": 1,
"position_id": 1,
"emergency_contacts": [
{
"name": "سارة أحمد",
"relationship": "spouse",
"phone": "+20123456789"
}
],
"dependents": [
{
"name": "يوسف أحمد",
"relationship": "child",
"date_of_birth": "2020-05-15",
"gender": "male"
}
]
}'dart
final response = await dio.post('/api/hr/employees', data: {
'first_name_ar': 'أحمد',
'last_name_ar': 'محمد',
'hire_date': '2026-03-01',
'contract_type': 'permanent',
'status': 'active',
'basic_salary': 8000,
'payment_method': 'bank_transfer',
'gender': 'male',
'department_id': 1,
'emergency_contacts': [
{'name': 'سارة أحمد', 'relationship': 'spouse', 'phone': '+20123456789'}
],
});Status Transitions
Use PUT /api/hr/employees/{id}/status with:
json
{
"status": "terminated",
"termination_date": "2026-03-01",
"termination_reason": "Contract ended"
}termination_date is required when status is terminated or resigned.
Business Rules
- Employee number is auto-generated via SequenceService (EMP-0001, EMP-0002, etc.)
contract_end_dateis required whencontract_typeiscontract- Show endpoint eager-loads: department, position, branch, manager, documents, emergencyContacts, dependents
- Documents support file upload with type classification (contract, id_copy, passport, certificate, etc.)