Project Rule
Build one phase at a time. Do not start the next phase until the current phase passes its checks in TESTING.md. Before every deploy: back up stock.db, upload stock_control.php (+ includes/) only, never touch users or passwords.
Phase 0 — Hardening & structure
Tasks
- Add CSRF token to every POST form and API write.
session_regenerate_id(true)on login.- Create
includes/and move nothing existing yet — new code only goes there;stock_control.phprequires it. - Add
eventstable and alogEvent()helper; call it from existing stock IN/OUT, set_stock and XLSM sync. - Fix: allow catalog-only XLSM apply.
- Nightly
stock.dbbackup (cron) to a folder outsidepublic_html. - Add indexes on
transactions(product_code).
Deliverable: same app, safer, with an event stream. Verify: all existing pages work (regression list); a POST without a token is rejected; backup file appears.
Phase 1 — Customers & Orders (intake)
Depends on: Phase 0 Tasks
- Tables
customers,orders,order_lines,order_attachments,order_events. - Pages: Customers list/edit; Orders list; New/Edit order; Order detail with timeline.
- Units / cartons toggle; product search reuse; duplicate PO warning.
- Non-airline availability check + suggested date.
- Record Xero invoice no. (labels SkyCrest / Annie Makes Cakes).
- Print kitchen ticket; copy confirmation email text; mark confirmed.
- Hamburger menu: new Orders section (Orders, Customers).
Deliverable: office can enter airline and non-airline orders and move them to CONFIRMED_SENT. Verify: TESTING §4–5.
Phase 2 — Packing & allocation
Depends on: Phase 1 Tasks
allocationstable; available-to-promise function (aggregate query).- Packing page (tablet layout); Allocate / partial / Mark short / Inform Alex.
- Add
packingrole and permission checks. - Live stock displays on Stock and Products pages also show "allocated" and "available".
Deliverable: packing team can reserve stock for orders. Verify: TESTING §6.
Phase 3 — Production Planner link
Depends on: Phase 2 Tasks
- Airline order lines drive Production Planning cells (sum per product × port × date); linked cells shown locked with a link icon.
- Missing-items list for Alex (non-airline shorts).
- Tartlet page: show allocated vs ordered (no merge yet).
Deliverable: no double entry between Orders and the planner. Verify: TESTING §7.
Phase 4 — Delivery schedule & dispatch
Depends on: Phase 3 Tasks
- Dispatch Schedule page: three groups, port sub-groups, booking type/ref, print,
.xlsx. - Dispatch action:
outtransactions per allocated line (in one DB transaction),transactions.order_idlink, status update, events. - Partial dispatch (admin + reason); Undo dispatch (admin,
intransactions).
Deliverable: full order lifecycle NEW → DISPATCHED with automatic stock removal. Verify: TESTING §8 + full critical journey.
Phase 4b — Dashboard & airline analytics
Depends on: Phase 4 Tasks
- Dashboard as the new home page: KPI tiles, role panels, activity feed (
DASHBOARD.md§2). staff_profiles,dashboard_views; seen-tracking JS +?api=dashboard_seen; Admin → Staff screen.- One-off import of the 2025–26 Excel dispatch history; Analytics page (
AIRLINE_ANALYSIS.md§7). - Planner columns for PER, CBR, DRW.
Deliverable: everyone starts the day on one screen; admins see who has looked. Verify: TESTING §9a.
Phase 5 — Agent framework + rule-based bots
Depends on: Phase 4 Tasks
- Tables
agent_settings,agent_proposals,agent_runs,agent_log. - CLI entry
--agent=(refuses web requests); one cron line → dispatcher. - Bot inbox page, activity feed, Admin → Agents (kill switches, levels).
- Bots: Availability, Allocation, Production, Dispatch Scheduler, Stock Reconciler, Order Pattern, Confirmation (drafts).
- All bots start disabled; enable one at a time.
Deliverable: bots draft and remind; humans approve in one place. Verify: TESTING §9.
Phase 5b — Hermes Reminder Bot
Depends on: Phase 4b (seen tracking), a VPS or office PC, Twilio account Tasks
- Install Hermes Agent; messaging gateway (WhatsApp or Telegram) on a dedicated business number.
- Token-protected APIs
agent_unseen,agent_reminder,agent_ack;reminder_log; heartbeat check. - Hermes skill
skycrest-reminder+ cron (every 15 min 06:00–11:00 weekdays); telephony skill with Twilio AU number. - Staff consent (messages / calls) captured; ladder and quiet hours configurable; kill switch.
- Pilot with 2 staff for 1 week before everyone.
Deliverable: nobody misses their morning dashboard without being chased. Verify: TESTING §9b.
Phase 6 — AI Order Intake Bot
Depends on: Phase 5, hosting checks (IMAP / outbound HTTPS) Tasks
- Orders mailbox connection; PDF/HTML/text extraction.
- Template parsers first for dnata (
O1-…) and Gate Gourmet (5000…) PO emails; AI only for non-airline. - Claude API call with strict JSON schema; confidence per field; product matching.
- Draft order proposal with original email attached; low-confidence fields highlighted.
- Config file outside web root for API key.
Deliverable: forwarded order emails become draft orders for review. Verify: TESTING §10 using 20 real past orders (≥ 90 % of lines correct before going live).
Phase 7 — Integrations (V2)
- Xero API (two organisations): create draft invoices, store invoice ID.
- SMTP send for confirmation emails (template, BCC office).
- Optional: merge Tartlet Orders into Orders.
Out of Scope for V1
- Pricing, payments and credit control (stay in Xero).
- Customer self-service portal.
- Automatic transport booking via Roadmaster API.
- Native mobile app.
- Replacing the XLSM file entirely (Sync stays manual).
Suggested order of releases
| Release | Phases | What users see |
|---|---|---|
| R1 | 0 | Nothing visible — safer app, backups running |
| R2 | 1 | Orders & Customers menu |
| R3 | 2 + 3 | Packing page; planner fills itself from airline orders |
| R4 | 4 | Dispatch schedule; stock comes off automatically |
| R4b | 4b | Dashboard home page, Analytics |
| R5 | 5 + 5b | Bot inbox, make-list, Hermes reminders & calls |
| R6 | 6 | Orders drafted from email |