Pharmacy purchasing - shelf-life-capped order-quantity calculator, single-file tool - ordinary retail stops at "safety stock," but medicine ordering has a second ceiling: will this batch sell through before the minimum-remaining-shelf-life gate; the tool computes both the conventional reorder quantity and the shelf-life ceiling and takes the smaller, prints which constraint bound, suggests split shipments when shelf life binds, and ships with zero built-in defaults - gates and lead times are entered by the buyer or left empty
Build a single-file HTML tool for a pharmacy (no dependencies, offline,
opens in the buyer's browser): an order-quantity calculator that computes
the conventional reorder quantity AND the shelf-life ceiling together,
recommends the smaller, and says which constraint bound.
Background: the difference between pharmacy ordering and ordinary retail is
the second constraint. Over-ordering ordinary goods ties up cash;
over-ordering medicine past its shelf life is a write-off. A product's
right order quantity is the intersection of two lines:
- Line one (conventional): expected demand across the supply cycle, minus
sellable stock on hand
- Line two (shelf life): what can sell within the arriving batch's remaining
life and still clear the store's minimum-remaining-life gate - the part
that cannot sells into the gate line as future write-off
Input page (one row per product):
- Product name, strength
- Last-30-day sales (user-entered; the user owns judgment on stripping
campaign anomalies - the tool needs only a one-line reminder)
- Supplier lead time (days, per actual supplier)
- Typical remaining shelf life of arriving batches (months, from that
supplier's history; without history, enter an estimate and flag it
"estimated")
- Current stock: quantity + per-lot remaining-life distribution (enter lot
by lot; entering only the total is allowed, and the tool then notes
"ceiling computed against the earliest lot")
- Store's minimum-remaining-life gate (months; one store-wide setting)
Calculation page (four outputs per row, never fewer):
1. Conventional reorder = (lead time + review period) x daily rate -
sellable stock on hand (the review period is user-entered; displayed,
never defaulted)
2. Shelf-life ceiling = batch remaining life - minimum gate = sellable
window (months), x daily rate = what the window can sell
3. Recommended order = min(conventional, ceiling), rounded UP to the
supplier's minimum pack (user-entered)
4. Constraint verdict, one sentence: this product is bound by [demand] or
by [shelf life]. When shelf life binds, append: "Where the minimum pack
exceeds the recommendation, negotiate split or smaller packs and order
more often - rounding up to a full case under a shelf-life constraint
trades a stockout problem for a write-off problem"
Missing-data behavior (the tool's line of conscience):
- Under 30 days of sales data: compute from available days and flag
"N days of data, low confidence"
- No per-lot life distribution: ceiling computed conservatively against
the earliest lot, flagged
- Any core input empty (gate, lead time, remaining life): the row prints
"missing: X" and produces NO recommended quantity - better to send the
buyer back for data than to print a complete-looking wrong number
Explicitly not built:
- No built-in defaults of any kind - gate, review period, minimum pack,
daily rate are all user-entered; an empty field stays empty and is never
filled with an "industry typical" value
- No network, no integration to the inventory system, no uploads - data
entered by hand or pasted as CSV, results stay on the page
- No "smart sales forecasting" (no seasonality models, no trend
extrapolation) - the daily rate is a user-supplied fact, and the tool
does not predict
- No inventory-ledger features - this is an ordering calculator; ledgers
belong to the inventory system
Why it is written this way
The take-the-smaller-of-two-constraints structure is the tool's reason to exist. The buyer's real dilemma: sales logic says order 50 packs, shelf-life logic says 20 - 50 writes off, 20 stocks out, and both outcomes are wrong, with the correct move living outside ordering entirely (split shipments, a supplier with longer-dated batches, better merchandising). The all-too-human failure is computing only one line: under pressure, sales binds (stockouts are today's problem), and the write-off surfaces months later. Forcing both lines on every calculation and printing which one bound is pushing the buyer's attention onto the constraint that actually governs.
The constraint verdict matters more than the recommended quantity, because the two shortage types have opposite prescriptions. Demand-bound shortage: order more. Shelf-life-bound shortage: ordering more converts today's stockout into tomorrow's write-off - plus disposal costs. The line "rounding up to a full case under a shelf-life constraint trades a stockout problem for a write-off problem" is common sense printed into the output itself, restated on every calculation.
Zero built-in defaults is deliberate self-protection. Gates, lead times, and batch lives vary enormously across stores, categories, and suppliers - every "industry typical" number filled in silently becomes a confidently wrong answer for some store's some category. The missing-data behavior is the same instinct: a tool's most dangerous moment is not refusing to compute but quietly back-filling absent inputs with plausible values - the recommendation then looks exactly like a real one.
"No sales forecasting" is drawn as a line against the standard slide of this tool class: an order calculator naturally "helps" by making the daily rate smarter - seasonal adjustment, trend extrapolation - and the smarter the model, the less the buyer knows where the number came from. The daily rate is a user-entered fact and the tool does intersections only; forecasting accuracy is the buyer's responsibility, but one they can see and touch.
Variables
| Variable | Description |
|---|---|
| Minimum-remaining-life gate | One store-wide value (per-category is better); its source of truth is the gate written into the purchase agreement per the intake checklist - where the tool's gate and the agreement disagree, the agreement wins and the tool gets corrected |
| Supplier batch-life expectations | Tracked per supplier (batches of the same product can differ by months across suppliers), reviewed quarterly - a supplier's new packaging line or warehouse changes the expectation, and a stale number in the tool keeps computing confidently |