# SalePro E2E Inventory Verification

- Run ID: `20260625013402`
- Prefix: `E2E-INV-20260625013402`
- Result: `PASS`
- Persistence: `rolled back after report`

## Products
- standard: ID `36`, code `E2E-INV-20260625013402-STD`, type `standard`
- variantProduct: ID `37`, code `E2E-INV-20260625013402-VAR`, type `standard`
- combo: ID `40`, code `E2E-INV-20260625013402-COMBO`, type `combo`
- componentA: ID `38`, code `E2E-INV-20260625013402-CMPA`, type `standard`
- componentB: ID `39`, code `E2E-INV-20260625013402-CMPB`, type `standard`
- variant code: `E2E-INV-20260625013402-VAR-RED`

## References
- `E2E-INV-20260625013402-PUR`
- `E2E-INV-20260625013402-SALE`
- `E2E-INV-20260625013402-SRET`
- `rr-20260625-013403`
- `E2E-INV-20260625013402-PRET`
- `prr-20260625-013403`

## Flow Summary
- Setup: Created deterministic products and reference master data.
  Context: `{"standard":"E2E-INV-20260625013402-STD","variant":"E2E-INV-20260625013402-VAR-RED","combo":"E2E-INV-20260625013402-COMBO","components":["E2E-INV-20260625013402-CMPA","E2E-INV-20260625013402-CMPB"]}`
- Purchase: Purchased standard, variant, and combo component products.
  Context: `{"reference":"E2E-INV-20260625013402-PUR","grand_total":405,"supplier_due_delta":405}`
- Sale: Sold standard, variant, and combo product.
  Context: `{"reference":"E2E-INV-20260625013402-SALE","paid":100,"due":40}`
- Stock Transfer: Transferred standard, variant, and combo component stock. Direct combo transfer is not used because combo stock is component-derived.
  Context: `{"reference":"salepro20260625-013403"}`
- Sale Return: Returned standard, variant, and combo product from completed sale.
  Context: `{"reference":"E2E-INV-20260625013402-SRET","customer_due_delta":-45}`
- Purchase Return: Returned standard and variant purchase quantities. Combo purchase return was not direct-tested because combo stock is component-derived in this verification.
  Context: `{"reference":"E2E-INV-20260625013402-PRET","supplier_due_delta":-30}`
- Damage / Adjustment: Recorded adjustment and damaged stock. Direct combo damage is treated as unsupported for this verification; component damage was verified.
  Context: `{"adjustment_id":3,"damage_id":2}`

## Checks
- [PASS] Purchase listing contains the verification purchase.
  Context: `{"reference":"E2E-INV-20260625013402-PUR"}`
- [PASS] Purchase standard product stock
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":20,"actual":20}`
- [PASS] Purchase variant product stock in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":15,"actual":15}`
- [PASS] Purchase variant product stock global variant quantity matches warehouse total
  Context: `{"expected":15,"actual":15}`
- [PASS] Purchase combo component A stock
  Context: `{"product":"E2E-INV-20260625013402-CMPA","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":12,"actual":12}`
- [PASS] Purchase combo component B stock
  Context: `{"product":"E2E-INV-20260625013402-CMPB","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":10,"actual":10}`
- [PASS] Combo product has no direct purchased warehouse stock
  Context: `{"product":"E2E-INV-20260625013402-COMBO","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":0,"actual":0}`
- [PASS] Sale listing contains the verification sale.
  Context: `{"reference":"E2E-INV-20260625013402-SALE"}`
- [PASS] Sale deducts standard product stock
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":17,"actual":17}`
- [PASS] Sale deducts variant stock in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":11,"actual":11}`
- [PASS] Sale deducts variant stock global variant quantity matches warehouse total
  Context: `{"expected":11,"actual":11}`
- [PASS] Sale deducts combo component A stock
  Context: `{"product":"E2E-INV-20260625013402-CMPA","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":8,"actual":8}`
- [PASS] Sale deducts combo component B stock
  Context: `{"product":"E2E-INV-20260625013402-CMPB","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":8,"actual":8}`
- [PASS] Sale paid and due amounts are correct.
  Context: `{"grand_total":140,"paid_amount":100,"due":40}`
- [PASS] Transfer listing contains the verification transfer.
  Context: `{"reference":"salepro20260625-013403"}`
- [PASS] Transfer decreases standard source warehouse
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":12,"actual":12}`
- [PASS] Transfer increases standard destination warehouse
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-B","expected":5,"actual":5}`
- [PASS] Transfer decreases variant source warehouse in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":8,"actual":8}`
- [PASS] Transfer decreases variant source warehouse global variant quantity matches warehouse total
  Context: `{"expected":11,"actual":11}`
- [PASS] Transfer increases variant destination warehouse in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-B","expected":3,"actual":3}`
- [PASS] Transfer increases variant destination warehouse global variant quantity matches warehouse total
  Context: `{"expected":11,"actual":11}`
- [PASS] Component transfer used instead of direct combo transfer
  Context: `{"product":"E2E-INV-20260625013402-CMPA","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":6,"actual":6}`
- [PASS] Component transfer reaches destination warehouse
  Context: `{"product":"E2E-INV-20260625013402-CMPA","warehouse":"E2E-INV-20260625013402-Warehouse-B","expected":2,"actual":2}`
- [PASS] Sale return listing contains the verification return.
  Context: `{"reference":"E2E-INV-20260625013402-SRET"}`
- [PASS] Sale return restores standard stock
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":13,"actual":13}`
- [PASS] Sale return restores variant stock in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":9,"actual":9}`
- [PASS] Sale return restores variant stock global variant quantity matches warehouse total
  Context: `{"expected":12,"actual":12}`
- [PASS] Sale return restores combo component A
  Context: `{"product":"E2E-INV-20260625013402-CMPA","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":8,"actual":8}`
- [PASS] Sale return restores combo component B
  Context: `{"product":"E2E-INV-20260625013402-CMPB","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":9,"actual":9}`
- [PASS] Purchase return listing contains the verification return.
  Context: `{"reference":"E2E-INV-20260625013402-PRET"}`
- [PASS] Purchase return decreases standard stock
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":11,"actual":11}`
- [PASS] Purchase return decreases variant stock in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":7,"actual":7}`
- [PASS] Purchase return decreases variant stock global variant quantity matches warehouse total
  Context: `{"expected":10,"actual":10}`
- [PASS] Adjustment listing contains standard and variant adjustment rows.
  Context: `{"adjustment_id":3}`
- [PASS] Adjustment decreases standard stock
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":10,"actual":10}`
- [PASS] Adjustment decreases variant stock in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":6,"actual":6}`
- [PASS] Adjustment decreases variant stock global variant quantity matches warehouse total
  Context: `{"expected":9,"actual":9}`
- [PASS] Damage listing contains standard, variant, and component rows.
  Context: `{"damage_stock_id":2}`
- [PASS] Damage decreases standard stock
  Context: `{"product":"E2E-INV-20260625013402-STD","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":9,"actual":9}`
- [PASS] Damage decreases variant stock in warehouse
  Context: `{"product":"E2E-INV-20260625013402-VAR","variant":"E2E-INV-20260625013402-Red","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":5,"actual":5}`
- [PASS] Damage decreases variant stock global variant quantity matches warehouse total
  Context: `{"expected":8,"actual":8}`
- [PASS] Damage uses component stock instead of direct combo damage
  Context: `{"product":"E2E-INV-20260625013402-CMPB","warehouse":"E2E-INV-20260625013402-Warehouse-A","expected":8,"actual":8}`

## Bugs Found
- Flow: Fatal verification failure
  Expected: Command should complete all flows and write an audit report.
  Actual: App\Http\Controllers\ExchangeController::store failed: Something went wrong: SQLSTATE[HY000]: General error: 1364 Field 'amount' doesn't have a default value (Connection: mysql, Host: localhost, Port: 3306, Database: salepro, SQL: insert into `sale_exchanges` (`sale_id`, `customer_id`, `warehouse_id`, `biller_id`, `item`, `total_qty`, `total_tax`, `grand_total`, `reference_no`, `total_discount`, `user_id`, `updated_at`, `created_at`) values (9, 8, 14, 8, 6, 6, 0, 0, exc-20260625-013404, 0, 1, 2026-06-25 01:34:04, 2026-06-25 01:34:04))
  Affected files: `app/Http/Controllers/ExchangeController.php` for combo exchange handling when applicable.
  Proposed minimal fix: route combo exchange return/new rows through the same component stock logic used by sale and sale return.
  Context: `{"file":"C:\\laragon\\www\\salepro\\app\\Console\\Commands\\VerifyE2EInventoryFlow.php","line":811}`

## Commands
- Run and roll back data: `php artisan verify:e2e-inventory-flow`
- Run and keep data for manual UI checks: `php artisan verify:e2e-inventory-flow --commit`
