# Indirect Goods Upgrade — Phase 12 Completion

## Test suites

### Accounting and domain rules

`tests/Unit/IndirectGoodsAccountingTest.php` and `tests/Unit/IndirectGoodsDomainInvariantTest.php` cover:

- FEFO allocation with FIFO tie-breaking.
- Weighted-average and zero-cost valuation.
- Pending/partial/full request-status calculation.
- Fulfillment and allocation outstanding balances.
- Prevention of over-accounting across return, consumption and transfer.
- Supplier direct-delivery accepted/rejected bounds.
- Serviceable FOC eligibility and quarantine of damaged, expired and scrap stock.
- Reserved and depleted FOC exclusion.
- Division closing-balance, project reconciliation and reversal calculations.
- Partial return followed by consumption, including overage rejection.

The shared production calculator is `IndirectGoodsBalanceCalculator`; reconciliation now uses the same variance formula tested by the suite.

### Permission boundaries

`tests/Unit/IndirectGoodsPermissionBoundaryTest.php` covers:

- All 13 Phase 11 permission gates.
- Every current indirect mutation route.
- Warehouse, FOC and consumption stock APIs.

### Workflow integration

`tests/Feature/IndirectGoodsWorkflowIntegrationTest.php` uses the configured MySQL dataset without resetting or truncating it. It covers:

- Production-sized warehouse/project/FOC reconciliation.
- Negative-balance and over-accounting detection.
- Double-click/idempotency behavior.
- Over-issue rejection with unchanged request balances.
- Material Issue report totals against the fulfillment authority.
- Indirect Material Issue document rendering.

The rejected operation is contained by the service transaction. Other integration checks are read-only.

## Scenario coverage mapping

| Scenario | Coverage |
|---|---|
| Direct-only flow | Existing direct models/controllers remain unchanged; full suite regression |
| Indirect-only and mixed reports | Report integration plus goods-type/source tests from Phases 9–10 |
| Partial and multi-source issue | Request status, allocation conservation and fulfillment-type tests |
| Multi-batch FEFO/FIFO | Accounting unit test |
| Supplier accepted/rejected quantities | Domain invariant tests |
| FOC issue and conditions | FOC eligibility, reservation and accounting tests |
| Partial/full return | Return bounds and outstanding-balance tests |
| Consumption after partial return | Allocation sequence test |
| Over-issue/over-return/negative stock | Integration rejection, invariant and reconciliation tests |
| Double-click/idempotency | Live integration test |
| Transaction rollback | Rejected service operation proves unchanged persisted balances |
| Reports and documents | Live total reconciliation and print-render test |
| Permissions | Route/gate/API boundary tests |

Database row locks remain the concurrency control for issue, delivery, return and consumption services. A deterministic multi-process lock-contention test is reserved for deployment staging because SQLite cannot represent MySQL row-lock semantics and the production dataset must not be mutated by tests.

## Final results

- Full application suite: **30 passed**.
- Assertions: **74**.
- Failures: **0**.
- Production reconciliation variance: **0.0000**.
- Negative warehouse rows: **0**.
- Negative project rows: **0**.
- Negative FOC rows: **0**.
- Over-accounted fulfillments: **0**.
- Over-accounted allocations: **0**.

The old scaffold feature test was corrected to verify the registered `admin.login` route instead of assuming the application exposes an unauthenticated `/` route.

