Fresh-food store purchasing - have a coding agent build the tomorrow's-order calculator - group pre-orders deducted first, and leafy greens ordered to sell out, not carry over
Build me a single-file HTML calculator for tomorrow's order, used at
8 p.m. on a phone by whoever places orders for a neighborhood
fresh-food store. It ends by generating a plain-text order that pastes
straight into a message to the supplier.
Item profile (maintained in a settings area, stored in localStorage):
- Item name, unit, and one of three category rules: same-day items
(leafy greens, fresh tofu) / short-cycle items (fresh meat, fresh
milk) / cycle items (rice, oil, eggs, frozen)
- Order unit and rounding per category: greens by the pound, eggs by
the tray, milk by the case, rice by the bag
Daily entry (one line per item, spreadsheet paste supported):
- Today's sales, on-hand stock, in-transit (already on tonight's truck)
- Group pre-orders: quantities reserved in the customer chat group for
tomorrow pickup (0 if none)
Calculation rules (fixed in code, each explained on screen in one
plain sentence):
- Expected sales tomorrow = 7-day daily average x tomorrow factor.
Factors default to 1.0 weekdays, 1.3 weekends, manual entry before
holidays; with fewer than 7 days of history use today's sales and
flag "thin data - single-day basis"
- Net demand = expected sales + group pre-orders - on-hand - in-transit
- Same-day items: suggested order = net demand x 0.9, then rounded.
The factor below 1 is deliberate: a leafy-green stockout costs one
transaction; carryover costs the entire goods value. Better sold
out by evening than leftover at close
- Cycle items: days of cover = on-hand / 7-day average; order only
when cover drops below the safety days (default 3), up to 7 days,
rounded to cases or bags
- Short-cycle items: net demand, rounded, no factor
- Negative suggestions display 0 with the note "skip this one
tomorrow"
Output area:
- One table: item / net demand / suggested / rounded / note ("thin
data", "insufficient history", or "group pre-order of X deducted";
blank otherwise)
- A manual override box per line, pre-filled with the suggestion;
overridden lines turn amber, and the totals count overridden values
only
- One-click copy of a plain-text order (item + quantity + unit, one
per line) that pastes into a chat to the supplier
Hard requirements:
- Single file, no build step, no CDN, opens directly in a phone browser
- Wrong column count on paste must surface an error on screen; never
silently misalign
- No accounts, no cloud sync; localStorage on-device only - deliberate
- Daily sales for the 7-day history can be back-filled quickly on the
entry page; missing days simply drop out of the average
Why it is written this way
Deducting group pre-orders inside the formula is the most neighborhood-store thing about this tool. Chat-group reservations are tomorrow's confirmed demand; failing to deduct them means ordering too much every single day - and the surplus leafy greens become the evening markdown and the nightly spoilage log. Pre-orders live scattered through chat history; memory always drops some, so the tool makes them an explicit term in the equation.
The 0.9 safety factor on same-day items is counterintuitive and correct: a stockout costs one transaction's margin (the customer comes back tomorrow); carryover costs the whole goods value. Classic ordering formulas use safety factors above 1 to prevent stockouts - for same-day fresh produce you want the opposite. That is a rule from scar tissue, which is why the spec demands it be explained on screen in one sentence rather than buried in code.
Three category rule-sets instead of one uniform formula, because rounding granularity differs by an order of magnitude: "greens by the pound, eggs by the tray, rice by the bag." Suggest rice in pounds and the ordering person still converts to bags in their head - at which point the tool saved no work. Rounding follows the category so the numbers can be read aloud to the supplier as-is.
"Manual override, totals count overrides only" keeps the human in the loop. The factor does not know the block's water gets shut off tomorrow or the supplier is repricing. The tool's job is turning mental arithmetic into a visible draft; the final number always belongs to the person placing the order.
Variables
| Variable | Notes |
|---|---|
| Same-day safety factor | Default 0.9; stores with strong evenings that sell out early can raise to 0.95 |
| Tomorrow factor | Default 1.0 weekday / 1.3 weekend; enter holiday peaks by hand - do not let the tool guess |
| Cycle safety days | Default 3 days; use 5 for suppliers who miss deliveries regularly |