# Phase 11 — Fuel management

Phase 11 adds airline-scoped fuel suppliers and prices, flight fuel plans, uplift approval, consumption calculations, supplier invoices, finance posting, and fuel variance reporting. Fuel quantities and money use fixed-scale decimal arithmetic; no live aircraft tracking is involved.

## Files created

- `database/migrations/2026_07_19_000012_create_fuel_management_tables.php`
- `app/Modules/Fuel/Repositories/FuelRepository.php`
- `app/Modules/Fuel/Services/FuelService.php`
- `app/Modules/Fuel/Controllers/FuelController.php`
- `resources/views/fuel/index.php`
- `resources/views/fuel/reports.php`
- `docs/PHASE_11_IMPLEMENTATION.md`

## Files modified

- `routes/web.php`
- `database/seeders/RolesAndPermissionsSeeder.php`
- `resources/views/layouts/app.php`
- `app/Core/Auth.php`
- `tests/run.php`
- `README.md`

## Database migrations added

Migration `2026_07_19_000012` creates `fuel_suppliers`, `fuel_prices`, `flight_fuel_plans`, `fuel_uplifts`, `fuel_consumption_records`, `fuel_invoices`, `fuel_invoice_items`, and `fuel_variances`. Operational tables include `airline_id`, UTC event fields, fixed-scale `DECIMAL` columns, tenant-aware indexes, uniqueness controls, and foreign keys.

## Security controls added

- Server-side permissions for view, setup, planning, uplift entry, approval, and reports.
- CSRF middleware on every fuel write route.
- Airline ownership validation for every selected record.
- Backend quantity, currency, date, unit, aircraft-assignment, and cost validation.
- Private receipt storage and permission-checked downloads with path confinement and MIME-sniffing protection.
- Atomic approval and finance posting, with a unique uplift-to-expense link and duplicate invoice checks.
- Immutable approved uplift behavior and complete fuel audit events.

## Tests performed

- Ran `php -l` against Phase 11 PHP files and the consolidated test runner.
- Ran `php tests/run.php`: **45 passed, 0 failed**.
- Verified plan totals, approval, consumption, fuel burn per block hour, quantity/cost variances, alert creation, expense integration, duplicate-post prevention, audit logging, protected routes, dashboard rendering, and every requested report heading.
- Attempted `php cli migrate:status`; the workspace has no reachable configured MySQL connection, so migrations could not be executed against MySQL in this environment.

## Remaining known limitations

- Fuel consumption is an operational estimate derived from opening fuel plus uplift minus closing fuel; it is not a calibrated aircraft fuel-measurement system.
- Block-hour burn is available only after valid off-block and on-block actuals exist.
- Uplift approval creates a draft expense for the existing Phase 9 approval/payment workflow; it does not bypass financial approval controls.
- Receipt upload itself requires an HTTP upload context, while its metadata linkage and protected access paths are covered by service and route tests.
- MySQL migration execution remains pending until valid database credentials and a reachable MySQL 8 server are available.
