# Inventory API — Implementation checklist

QuickBooks-style inventory: movement history, starting value, and quantity adjustments.

---

## Phase 1 — Read hub (current)

Unified read API for inventory movements from existing bill receipts and invoice sales (FIFO layers).

| Task | Status |
|------|--------|
| `InventoryTransactionHubService` — merge receipt + sale rows | Done |
| `GET /inventory-transactions` route + controller | Done |
| `InventoryTransactionResource` | Done |
| `IndexInventoryTransactionRequest` validation | Done |
| `InventoryTransactionPolicy` + gate | Done |
| `docs/api/inventory-transactions.md` | Done |
| `tests/Feature/InventoryTransactionApiTest.php` | Done |
| Update `docs/features-list.md` | Done |

**No migrations. No changes to bill receive or invoice post.**

---

## Phase 3 — Quantity adjustments  ✅ DONE

| Task | Status |
|------|--------|
| Migration 0023: make `inventory_cost_layers.bill_line_id` nullable | Done |
| Migration 0024: `inventory_adjustments` | Done |
| Migration 0025: `inventory_adjustment_lines` | Done |
| Migration 0026: `inventory_adjustment_line_layers` (FIFO consumption audit) | Done |
| `Transaction::TYPE_INVENTORY_ADJUSTMENT` | Done |
| `InventoryAdjustmentService` (FIFO + GL) | Done |
| `InventoryAdjustmentPolicy` | Done |
| `InventoryAdjustmentController` + `InventoryAdjustmentResource` | Done |
| `StoreInventoryAdjustmentRequest` | Done |
| `GET/POST /inventory-adjustments` + `GET /inventory-adjustments/{id}` | Done |
| `POST /inventory-adjustments/{id}/void` | Done |
| Hub includes `ADJUSTMENT_IN` / `ADJUSTMENT_OUT` movement types | Done |
| Hub `receiptRows()` filtered to `whereNotNull('bill_line_id')` | Done |
| `IndexInventoryTransactionRequest` regex updated for new types | Done |
| `docs/api/inventory-adjustments.md` | Done |
| `tests/Feature/InventoryAdjustmentApiTest.php` | Done |

**FifoInventoryService, InvoicePostingService, BillProcessingService — NOT TOUCHED.**

---

## Phase 2 — Starting value  ✅ DONE

| Task | Status |
|------|--------|
| Migration 0037: `inventory_starting_values` | Done |
| Migration 0038: `Transaction::TYPE_INVENTORY_STARTING` enum | Done |
| `ItemStartingValueService` + FIFO opening layer | Done |
| `GET/PUT /items/{id}/starting-value` | Done |
| `POST /items/{id}/starting-value/void` | Done |
| Hub includes `STARTING_VALUE` movement type | Done |
| `docs/api/inventory-starting-value.md` | Done |
| `tests/Feature/ItemStartingValueApiTest.php` | Done |

> Note: `bill_line_id` was already made nullable in Phase 3 migration 0023.

### Phase 2 (additive)

**New**

- `database/migrations/0037_create_inventory_starting_values_table.php`
- `database/migrations/0038_add_inventory_starting_to_transactions_type_enum.php`
- `app/Modules/Inventory/Models/InventoryStartingValue.php`
- `app/Modules/Inventory/Services/ItemStartingValueService.php`
- `app/Modules/Inventory/Controllers/Api/ItemStartingValueController.php`
- `app/Modules/Inventory/Resources/ItemStartingValueResource.php`
- `app/Modules/Inventory/Requests/UpsertItemStartingValueRequest.php`
- `app/Modules/Inventory/Requests/VoidItemStartingValueRequest.php`
- `app/Modules/Inventory/Policies/ItemStartingValuePolicy.php`
- `tests/Feature/ItemStartingValueApiTest.php`
- `docs/api/inventory-starting-value.md`

**Edited (additive only)**

- `app/Modules/Core/Models/Transaction.php` — `TYPE_INVENTORY_STARTING`
- `app/Modules/Inventory/Services/InventoryTransactionHubService.php` — `STARTING_VALUE` rows
- `app/Modules/Inventory/Requests/IndexInventoryTransactionRequest.php` — regex extended
- `app/Modules/Inventory/Models/Item.php` — `startingValue()` relation
- `routes/api/inventory.php` — 3 new routes
- `app/Providers/AppServiceProvider.php` — gates
- `docs/features-list.md`, `docs/api/inventory-transactions.md`

**Unchanged**

- `FifoInventoryService`, `InvoicePostingService`, `BillProcessingService`
- All existing tests

---

## Phase 4 — Polish (optional)

| Task | Status |
|------|--------|
| Batch quantity adjustment (multi-item form) | Pending |
| Bulk starting value import (`POST /inventory-starting-values/bulk`) | Done |
| Physical inventory worksheet export | Pending |
| Reversal / void adjustment with audit trail | Done |
| Optional `inventory_movements` audit log table | Pending |

---

## Files touched by phase

### Phase 1 (additive only)

**New**

- `app/Modules/Inventory/Services/InventoryTransactionHubService.php`
- `app/Modules/Inventory/Controllers/Api/InventoryTransactionController.php`
- `app/Modules/Inventory/Resources/InventoryTransactionResource.php`
- `app/Modules/Inventory/Requests/IndexInventoryTransactionRequest.php`
- `app/Modules/Inventory/Policies/InventoryTransactionPolicy.php`
- `tests/Feature/InventoryTransactionApiTest.php`
- `docs/api/inventory-transactions.md`
- `docs/inventory-api-checklist.md`

**Edited**

- `routes/api/inventory.php`
- `app/Providers/AppServiceProvider.php`
- `app/Modules/Inventory/Models/InventoryCostLayer.php` — `billLine()` relation
- `docs/features-list.md`

**Unchanged**

- `InvoicePostingService`, `BillProcessingService`, `FifoInventoryService`
- Sales / purchase transaction hubs
- Existing inventory reports

### Phase 3 (additive; one safe schema change)

**New**

- `database/migrations/0023_make_bill_line_id_nullable_on_inventory_cost_layers.php`
- `database/migrations/0024_create_inventory_adjustments_table.php`
- `database/migrations/0025_create_inventory_adjustment_lines_table.php`
- `database/migrations/0026_create_inventory_adjustment_line_layers_table.php`
- `app/Modules/Inventory/Models/InventoryAdjustment.php`
- `app/Modules/Inventory/Models/InventoryAdjustmentLine.php`
- `app/Modules/Inventory/Models/InventoryAdjustmentLineLayer.php`
- `app/Modules/Inventory/Services/InventoryAdjustmentService.php`
- `app/Modules/Inventory/Controllers/Api/InventoryAdjustmentController.php`
- `app/Modules/Inventory/Resources/InventoryAdjustmentResource.php`
- `app/Modules/Inventory/Requests/StoreInventoryAdjustmentRequest.php`
- `app/Modules/Inventory/Policies/InventoryAdjustmentPolicy.php`
- `tests/Feature/InventoryAdjustmentApiTest.php`
- `docs/api/inventory-adjustments.md`

**Edited (additive only)**

- `app/Modules/Core/Models/Transaction.php` — `TYPE_INVENTORY_ADJUSTMENT` constant
- `app/Modules/Inventory/Services/InventoryTransactionHubService.php` — adjustment rows + receipt filter
- `app/Modules/Inventory/Requests/IndexInventoryTransactionRequest.php` — regex extended
- `routes/api/inventory.php` — 3 new routes
- `app/Providers/AppServiceProvider.php` — 2 new gates + import
- `docs/inventory-api-checklist.md`

**Unchanged**

- `FifoInventoryService`, `InvoicePostingService`, `BillProcessingService`
- All existing tests
