# Status Mappings - Kaabil Recruiter ATS

This document contains the definitive status code mappings verified against the org-recruiter (original) codebase.

## Job Status Codes (company_jobs.status)

| Code | Status Name | Description |
|------|-------------|-------------|
| 1 | Pending | Job awaiting approval |
| 2 | Active | Job is live and accepting applications |
| 3 | Inactive | Job manually deactivated by recruiter |
| 4 | Expired | Job past expiry date (job_expiry column) |
| 5 | Deleted | Job soft-deleted |
| 6 | Draft | Job saved but not published |
| 7 | Discard | Job discarded/cancelled |

### Source Reference
From `org-recruiter/application/controllers/superadmin/Company.php:3173-3182`:
```sql
CASE cj.status
    WHEN 1 THEN 'Pending'
    WHEN 2 THEN 'Active'
    WHEN 3 THEN 'In-active'
    WHEN 4 THEN 'Expired'
    WHEN 5 THEN 'Deleted'
    WHEN 6 THEN 'Draft'
    WHEN 7 THEN 'Discard'
END AS 'Job Status'
```

### Status Transitions
From `org-recruiter/application/models/V2/CompanyModel.php:4397-4427`:
- **Activate Job**: Set `status = 2` (Job activated)
- **Inactivate Job**: Set `status = 3` (Job inActivated)
- **Delete Job**: Set `status = 5` (Job deleted)

## Application Status Codes (users_job.job_status)

| Code | Status Name | Description |
|------|-------------|-------------|
| 0 | Applied | Candidate applied to job |
| 2 | Shortlisted | Candidate shortlisted for review |
| 3 | Rejected | Candidate rejected |
| 4 | Interview | Interview scheduled |
| 6 | Waitlist | Candidate on waitlist |
| 7 | Selected | Candidate selected/hired |

### Note
Status code `1` is not used in the application status workflow.

## UI Status Name Mapping (jobs.php)

The frontend uses friendly status names that map to database codes:

| UI Name | Database Code | Filter Query |
|---------|---------------|--------------|
| open | 2 | Active jobs |
| closed | 3 | Inactive jobs |
| expired | 4 | Expired jobs |
| all | null | All published jobs (2, 3, 4) |

## Files Using Status Mappings

### Core Mapping Files
- `app/helpers/db_mapping.php` - DBMapping class with constants and mapping functions
- `app/Services/ProductionDBAdapter.php` - mapStatusCodeToName() and mapStatusNameToCode()

### Files Referencing Status Codes
- `public/inactive_job.php` - Sets job to status 3 (Inactive)
- `public/delete_job.php` - Sets job to status 5 (Deleted)
- `public/jobs.php` - Job listing with status filters
- `app/views/jobs.php` - Job list view with status badges

## Bug Fixes Applied (Feb 2026)

### db_mapping.php
**Before (INCORRECT):**
```php
$statuses = [
    1 => 'Pending',
    2 => 'Active',
    3 => 'Expired',  // WRONG - should be Inactive
    4 => 'Closed',   // WRONG - should be Expired
    5 => 'Draft',    // WRONG - should be Deleted
    6 => 'Deleted',  // WRONG - should be Draft
    7 => 'Discard'
];
```

**After (CORRECT):**
```php
$statuses = [
    1 => 'Pending',
    2 => 'Active',
    3 => 'Inactive',
    4 => 'Expired',
    5 => 'Deleted',
    6 => 'Draft',
    7 => 'Discard'
];
```

### ProductionDBAdapter.php
**Before (INCORRECT):**
```php
$mapping = [
    'open' => 2,
    'closed' => 4,    // WRONG - should be 3
    'expired' => 3,   // WRONG - should be 4
    'deleted' => 6,   // WRONG - should be 5
    'draft' => 5      // WRONG - should be 6
];
```

**After (CORRECT):**
```php
$mapping = [
    'open' => 2,
    'active' => 2,
    'closed' => 3,
    'inactive' => 3,
    'expired' => 4,
    'deleted' => 5,
    'draft' => 6
];
```

## Usage Examples

### Checking if job is active
```php
if ($job['status'] == 2) {
    // Job is active
}
// Or use constant:
if ($job['status'] == DBMapping::JOB_STATUS_ACTIVE) {
    // Job is active
}
```

### Getting status name
```php
$statusName = DBMapping::getJobStatusName($job['status']);
// Returns: 'Active', 'Inactive', 'Expired', etc.
```

### Filtering published jobs (excludes drafts and deleted)
```php
$where = DBMapping::getPublishedJobsWhere();
// Returns: "status IN (2, 3, 4)"
```
