# Implementation Plan - Employee Management Module

This plan outlines the creation of a comprehensive Employee Management module for the HR Dashboard, including CRUD operations for employees and sites, advanced filtering, and role-based access control.

## Proposed Changes

### 1. Database & Models

#### [NEW] [Migration: users_add_soft_deletes](file:///d:/Laragon/www/absensi/database/migrations/xxxx_xx_xx_xxxxxx_add_soft_deletes_to_users_table.php)
- Add `deleted_at` column to `users` table.

#### [MODIFY] [User.php](file:///d:/Laragon/www/absensi/app/Models/User.php)
- Add `Illuminate\Database\Eloquent\SoftDeletes` trait.

### 2. Request & Resource Layer

#### [NEW] [UserResource.php](file:///d:/Laragon/www/absensi/app/Http/Resources/UserResource.php) [NEW] [SiteResource.php](file:///d:/Laragon/www/absensi/app/Http/Resources/SiteResource.php)
- Transform User and Site models into consistent API responses.

#### [NEW] [StoreEmployeeRequest.php](file:///d:/Laragon/www/absensi/app/Http/Requests/StoreEmployeeRequest.php) [NEW] [UpdateEmployeeRequest.php](file:///d:/Laragon/www/absensi/app/Http/Requests/UpdateEmployeeRequest.php)
- Implement validation for employee data (email, employee_id, role, sites, etc.).

### 3. Middleware & Filtering

#### [NEW] [CheckRole.php](file:///d:/Laragon/www/absensi/app/Http/Middleware/CheckRole.php)
- Custom middleware to verify roles using Spatie's `hasRole` method.

#### [NEW] [EmployeeFilter.php](file:///d:/Laragon/www/absensi/app/Filters/EmployeeFilter.php)
- Logic to filter employees by `site_id`, `role`, and `status`.

### 4. Authorization

#### [NEW] [UserPolicy.php](file:///d:/Laragon/www/absensi/app/Http/Policies/UserPolicy.php) [NEW] [SitePolicy.php](file:///d:/Laragon/www/absensi/app/Http/Policies/SitePolicy.php)
- **UserPolicy**: 
    - HR/SuperAdmin: Full access.
    - Cinema Manager: Only view employees assigned to their site.
- **SitePolicy**:
    - HR/SuperAdmin: Full CRUD.
    - Cinema Manager: View only.

### 5. Controllers

#### [NEW] [EmployeeController.php](file:///d:/Laragon/www/absensi/app/Http/Controllers/Api/EmployeeController.php)
- `index()`: Paginated list with filtering.
- `store()`: Create user, assign role, and sites.
- `update()`: Update info and role/sites.
- `destroy()`: Soft delete.
- `assignSite()`: Specialized endpoint for updating site assignments.

#### [NEW] [SiteController.php](file:///d:/Laragon/www/absensi/app/Http/Controllers/Api/SiteController.php)
- CRUD operations for sites.
- `listEmployeesBySite()`: Fetch all employees associated with a site.

### 6. Routes

#### [MODIFY] [api.php](file:///d:/Laragon/www/absensi/routes/api.php)
- Add new endpoints protected by `auth:sanctum` and `CheckRole`.

## Verification Plan

### Automated Tests
- Run `php artisan migrate` to add soft deletes.
- Verify controller logic via test script (simulating HR vs Cinema Manager).

### Manual Verification
- Test employee creation with multiple sites.
- Test filtering by status/role.
- Verify soft delete (user should still be in DB but not in index).
