# Implementation Plan - Advanced Schedule Management

This plan outlines the refactoring and enhancement of the Schedule Management system, adding granular role-based access control, automated notifications, and bulk operations.

## Proposed Changes

### 1. Database & Model

#### [NEW] [Migration: create_notifications_table](file:///d:/Laragon/www/absensi/database/migrations/xxxx_xx_xx_xxxxxx_create_notifications_table.php)
- Create the standard Laravel notifications table for the database channel.

#### [MODIFY] [Schedule.php](file:///d:/Laragon/www/absensi/app/Models/Schedule.php)
- Implement Scopes:
    - `scopeBySite($query, $site_id)`
    - `scopeUpcoming($query)`
    - `scopeToday($query)`

### 2. Authorization & Validation

#### [NEW] [SchedulePolicy.php](file:///d:/Laragon/www/absensi/app/Policies/SchedulePolicy.php)
- Implement role-based logic:
    - Global CRUD: `super_admin`, `hr`, `hq`, `head_dev_hq`.
    - Site-Specific CRUD: `cinema_manager`, `supervisor`, `cinema_technical_support` (CTS).
    - Own View: All roles.

#### [NEW] [StoreScheduleRequest.php](file:///d:/Laragon/www/absensi/app/Http/Requests/StoreScheduleRequest.php)
- Add custom validation rule to prevent overlapping schedules for the same user, date, and site.

### 3. Notifications

#### [NEW] [ScheduleCreatedNotification.php](file:///d:/Laragon/www/absensi/app/Notifications/ScheduleCreatedNotification.php)
- Create a notification to alert employees when a new schedule is created or updated.

### 4. Controller Refactoring

#### [MODIFY] [ScheduleController.php](file:///d:/Laragon/www/absensi/app/Http/Controllers/Api/ScheduleController.php)
- `index()`: Integrate new scopes and filters.
- `store()`: Use `StoreScheduleRequest` and fire notifications.
- `storeBulk()`: Handle bulk creation with transaction and notifications.
- `mySchedule()`: Dedicated endpoint for staff to view their upcoming shifts.

### 5. API Routes

#### [MODIFY] [api.php](file:///d:/Laragon/www/absensi/routes/api.php)
- Register `mySchedule` endpoint.
- Ensure all endpoints use the correct middleware aliases.

## Verification Plan

### Automated Tests
- Test overlap validation with two identical requests.
- Verify notifications are recorded in the `notifications` table.
- Verify site-restricted managers cannot create schedules for other sites.

### Manual Verification
- Test `my-schedule` endpoint with a crew-level user.
- Test `storeBulk` with an array of dates.
