# Working request contracts

The application uses server-rendered Bootstrap forms, POST/Redirect/GET and bound SQL. Every POST requires CI4 CSRF validation. No request may choose its actor, price or permission.

| Contract | Behavior |
| --- | --- |
| `GET/POST /setup` | Local development only, first-manager provisioning and currency setup, closes permanently after provisioning |
| `GET/POST /login` | Individual active account authentication, throttled, session regenerated |
| `POST /logout` | Destroy staff session |
| `GET /dashboard` | Authenticated dashboard from stored records |
| `GET /admin/{module}` | Authorized, searched and paginated records |
| `GET /admin/{module}/new`, `GET /admin/{module}/{id}/edit` | Labeled create/edit forms |
| `POST /admin/{module}`, `POST /admin/{module}/{id}/save` | Validate explicit fields, save transaction and audit |
| `POST /admin/{module}/{id}/archive` | Deactivate editable master record, retain all history |
| `GET/POST /admin/inventory/{id}/adjust` | Manager quantity adjustment with mandatory reason and repeat-safe stock ledger |
| `GET/POST /admin/menu/{id}/recipe` | Versioned recipe and exact quantities |
| `GET/POST /admin/settings` | Currency and payment methods, restrict currency changes once financial history exists |
| `GET/POST /admin/serving-supplies` | Configure disposable serving quantities from supply inventory |
| `GET/POST /pos` | Menu, recent bills and creation using stored prices and currency snapshots |
| `GET /pos/{id}` | Persisted bill, fulfillment units and payment history |
| `POST /pos/{id}/payments` | Positive partial/full payment up to the remaining balance; unique request key; no stock change |
| `POST /pos/{id}/items/{itemId}/prepare` | Recipe consumption once, exact quantities, transaction rollback on shortage |
| `POST /pos/{id}/items/{itemId}/hand-over` | Recipe handover without a second deduction; retail/prepared portion consumption once |
| `POST /pos/{id}/cancel` | Manager-only complete cancellation/full refund before any stock use |

Modules: categories, menu, inventory, suppliers, tables, users. Staff permission boundaries are enforced on routes and controls. Password fields are never put into flashdata or audit details.

Core settings are selected by the owner in setup, not inferred from mockup totals. CRUD delete behavior is archival because stock and financial references must survive.

## Purchasing and stock

| Contract | Behavior |
| --- | --- |
| `GET /admin/purchases`, `GET /admin/purchases/new`, `POST /admin/purchases` | Manager purchase listing/creation; no stock or debt |
| `GET /admin/purchases/{id}` | Delivery progress, receipt/payment history and debt |
| `POST /admin/purchases/{id}/receipts` | Accepted quantities, exact conversion and actual cost; repeat-safe stock/debt |
| `POST /admin/purchases/{id}/payments` | Supplier payment up to accepted debt |
| `POST /admin/purchases/{id}/close-short` | Close undelivered remainder with a reason |
| `GET /admin/production`, `GET /admin/production/recipes/new` | Batch recipes and actual production history |
| `POST /admin/production/recipes`, `GET /admin/production/recipes/{id}/edit`, `POST /admin/production/recipes/{id}/save` | Versioned template; active/inactive control |
| `GET/POST /admin/production/recipes/{id}/produce` | Actual ingredient use and actual yield |
| `GET/POST /admin/stock-counts` | Manager count snapshots and differences |
| `GET/POST /admin/waste` | Inventory waste quantity/reason |
| `POST /pos/{id}/items/{itemId}/discard` | Manager prepared-item waste; no second stock deduction |
| `POST /pos/{id}/close-loss` | Manager closes uncollected remainder after fulfillment/discard |

## QR, photographs and reports

| Contract | Behavior |
| --- | --- |
| `GET/POST /admin/tables/{id}/qr` | Manager printable code / rotation revoking prior code |
| `GET /menu/{tableToken}` | Public stock-aware menu and cart |
| `POST /menu/{tableToken}/requests` | Session-issued request key, server table/prices, throttled pending request |
| `GET /order/{statusToken}` | Public status for exactly one request/order |
| `GET /pos/qr-requests` | Staff approval queue |
| `POST /pos/qr-requests/{id}/accept`, `/reject` | Recheck availability or record rejection reason |
| `GET /pos/tables` | Open table bills and occupancy |
| `GET/POST /admin/menu/{id}/photo`, `POST /admin/menu/{id}/photo/remove` | Manager validated sanitized photograph |
| `GET /menu-photos/{randomName}.jpg` | Strictly named JPEG from private storage |
| `GET /admin/reports` | Redirect to Sales report |
| `GET /admin/reports/{sales,income,inventory,suppliers,audit}` | Five separate manager reports with page-specific filters |
| `GET /admin/reports/{report}/{xlsx,pdf}` | Download the currently filtered report as Excel or PDF |
| `GET/POST /admin/expense-types`, `POST /admin/expense-types/{id}` | List, create and edit expense types |
| `POST /admin/expense-types/{id}/status` | Activate or deactivate an expense type |
| `GET/POST /admin/expenses`, `POST /admin/expenses/{id}` | Filter, record and correct expenses |
| `POST /admin/expenses/{id}/void` | Soft-void an expense with a reason |

Pending QR requests cannot take payment or use stock. Each acceptance preserves a separate bill. Public capabilities never authorize staff actions.
