# 04 · Delivery Plan (MVP)

Build in this order. Each phase ends with a working, deployed slice that Operations can use and test.

| Phase | Scope | Done when |
|---|---|---|
| 0 · Foundation | Repo, CI, environments, database baseline (`schema.sql`, `seed.sql`), SSO login, users & roles screen, audit writer, notifications outbox + worker | The four named users can sign in; an unknown email is refused; every write appears in Audit Log |
| 1 · Pipeline | Registration, Location Screening, Documents (upload, versions, verify/reject), Merchant master page with stage/next action, Tasks & PIC | A merchant can go from application to "documents complete" with correct gates and emails |
| 2 · Onboarding & activation | 7 onboarding steps with their fields, activation, dashboard pipeline counters | Activation is impossible until all gates pass |
| 3 · Sales & settlement | Sales CSV/Excel import (validate → preview → confirm → error report), manual entry, daily settlement batch job, bank transaction import, receipt recording and matching | "Whose money is this?" answered for every bank receipt |
| 4 · Funds, restock, stock | Allocation rule screen, allocation on matched settlement, restock balance, orders, deliveries, stock movements, low-stock alerts | Restock over balance is blocked; stock updates on completed delivery |
| 5 · Repayment & issues | Repayment plans/payments, overdue view, issue workflow | Dashboard shows outstanding/overdue merchants and unresolved issues with owners |
| 6 · Finance & closing | Daily Finance report flow, missing-day alerts, monthly closing checklist and lock, adjustment requests | A month can be locked only when clean; locked data changes only through approved adjustments |
| 7 · Reports & polish | All exports (XLSX/CSV/PDF), management dashboard filters, mobile pass, performance, backup/restore test | Acceptance checklist below passes |

## Acceptance checklist

The portal must answer each question in one or two clicks:

- [ ] Which applicants are currently pending? (Registration / Dashboard)
- [ ] Which locations are waiting for ZUS approval? (Location Screening)
- [ ] Whose documents are incomplete? (Documents → checklist progress)
- [ ] Who is ready to activate? (Onboarding / Dashboard)
- [ ] Who is responsible for this task? (Tasks & PIC; PIC name + email on every task)
- [ ] How much did each merchant sell? (Sales, by period)
- [ ] Which sales have been settled? (Settlement status per day)
- [ ] Whose money is this? (Bank receipts without an owner → match)
- [ ] How much money belongs to each merchant? (Fund Allocation running balance)
- [ ] Which merchant has enough money to restock? (Restock → Ready for Restock)
- [ ] Which merchant is running low? (Stock → Low Stock alert)
- [ ] Who has outstanding repayment? (Repayment)
- [ ] What issue is still unresolved and who owns it? (Issues → Open)
- [ ] Has today's report been sent to Finance? (Dashboard first card)
- [ ] Who changed this record and when? (Audit Log / merchant Audit tab)

Rule tests (all must be refused): Ops user verifies a document · uploader verifies own upload (non-Full Access) · onboarding before documents complete · activation with a step missing · restock order above balance · editing a sale in a locked month · locking a month with unmatched settlement or bank receipt · approving your own adjustment · deleting or editing an audit entry · reopening a locked month.

`database/rules_test.sql` covers these at database level; add the same cases as end-to-end tests in the app.

## Non-functional targets

- Pages load in under 2 s on office broadband for 5,000 merchants / 1M sales rows (indexes on merchant_id + date)
- Imports of 10,000 rows validate in under 30 s
- Works on current Chrome, Edge, Safari; usable at 390 px phone width
- Daily backups with point-in-time restore; restore tested before go-live
