Order-to-cash is the heart of the business. This pipeline traces a sales order from intake (manual / email / EDI / portal) through customer + credit validation, inventory check, pricing application, approval, pick + pack + ship, invoice, payment, AR aging, and finally the customer-health signal that feeds churn prediction. $15K average order value; bid-driven; K-12 + USDA + NYC schools dominant.
orders@ai-globalfoodsolutions.co → src/email.tstransactions (SalesOrd) · so_linescustomers · v_customer_ar_agingcredit_limit · hold_status · service_hold flagsinventory_balance · so_linesso_lines.backorder_flagpricing_master · customer_programs · contracts/proposed-actions.htmlproposed_actions · transactions (status flip)itemfulfillment opens In Progress.itemfulfillmenttransactions (ItemShip-pick stage)itemfulfillment (status='Shipped')transactions (ItemShip) · inventory_balanceinvoice_lines mirror so_lines.CustInvctransactions (CustInvc) · invoice_linespayment_applications ties payment to invoice(s).CustPymtcustomer_payments · payment_applicationsv_customer_ar_aging recomputes. Buckets surface on the customer entity page and finance tile.v_customer_ar_aging/customer/<slug> · admin-dashboard finance tileorder_velocity_decline baseline updates (rolling 90d); customer_health_predictor recomputes churn risk. Feeds back into next SO's credit + pricing gate.customer_health · eventsevents.customer.health_changed/customer/<slug> · admin-dashboard health tile · chat get_customer_health| kind | name | purpose |
|---|---|---|
| D1 table | transactions | SalesOrd, ItemShip, CustInvc, CustPymt rows |
| D1 table | so_lines | line-level SO data · item, qty, price, backorder_flag |
| D1 table | invoice_lines | generated from so_lines using shipped qty |
| D1 table | customer_payments | payment receipts · CustPymt mirror |
| D1 table | payment_applications | matches payment to invoice(s) |
| D1 table | customers | credit_limit, hold_status, service_hold |
| D1 table | pricing_master | tier price · effective_date |
| D1 table | customer_programs | customer-specific overrides |
| D1 view | v_customer_ar_aging | buckets · current / 30 / 60 / 90+ |
| D1 table | customer_health | score, velocity baseline, churn_risk |
| D1 table | events | customer.health_changed event ledger row |
| NS record | SalesOrd | system-of-record SO |
| NS record | itemfulfillment | pick + ship |
| NS record | CustInvc | invoice |
| NS record | CustPymt | payment |
| Endpoint | POST /api/so/create | orchestrates intake through pricing |
| Endpoint | POST /api/so/approve | HITL approval flip |
| Endpoint | GET /api/customer/{slug}/health | customer health surface |
| Code path | src/email.ts | email intake |
| Code path | src/index.ts (pricing-cascade) | tier + program + contract resolution |
| Code path | customer_health_predictor | R549-R564 substrate |
POST /api/so/create.