Flow: price list → order → ERP → warehouse → stock → statistics.
Order lines are matched to ERP items by the Chinese name. If an item is missing the line is skipped and the invoice stays a draft for the manager to fix.
Stock = sum of all moves for an item and warehouse. There is no other source — ERP, warehouse and manager desk all read the same view v_stock.
| Operation | Where | Writes | Stock |
|---|---|---|---|
| Receipt (delivery) | Warehouse, ERP | moves.kind=in | + |
| Sale / shipment | ERP, invoice posting | moves.kind=out | − |
| Write-off (damage) | Warehouse | kind=writeoff | − |
| Transfer between warehouses | Warehouse | kind=move, wh_id → wh_to | 0 |
| Stocktake | ERP, invoice posting | kind=adjust | ± |
The warehouse never goes negative: stock is checked before writing off. A sale reduces stock only when the invoice is posted, not when it is drafted.
| What | How |
|---|---|
| Separate accounts | ERP → Users: login, password, role admin / manager / staff, blocking. One admin owns catalogues and people. |
| Own documents | Every draft records its author (sales.user); a manager sees own invoices, admin sees all. |
| Concurrent writes | SQLite in WAL mode, busy_timeout 10 s: readers never block writers, writers queue instead of failing with “database is locked”. |
| Document numbers | XSCK-YYYYMMDD-00001; on a collision the insert retries with a new number (up to 6 tries) — no race. |
| No double posting | Posting is one BEGIN IMMEDIATE transaction guarded by approved=0. The second manager gets “already posted”, movements never duplicate. |
| Action history | Every action is written to audit with the login: who posted, who wrote off, who created a user. |
Practice: 4 managers create orders and drafts, posting is a single point (admin). That rules out double write-offs and stock drift without locks or waiting.
| System | Address | Data |
|---|---|---|
| Control centre | hub.redbutton.beer | reads both databases, changes nothing |
| ERP | erp2.redbutton.beer | bb_erp.db |
| Warehouse | stock.redbutton.beer | bb_erp.db · moves |
| Manager desk | manager.redbutton.beer | bb_erp.db · drafts |
| Price list | bbprice.redbutton.beer | bb_reg.db · orders |