← Back to all projects
Ready

Cotton PO — Calculation Logic (Web App Spec)

Purpose: Port the Cotton PO generator's line-item math into the RBD Ordering web app (Cotton POs module). This is the calculation model only — sheet column letters are omitted; use the field names below. Last updated: 2026-08-11 (reflects the Master-Template fixes shipped this date).


1. SKU classification (tiers)

Classify each line by SKU prefix / pattern:

Tier Rule Examples
Main Cotton C#####-COLOR where the numeric design # ends in 0 C18690-DENIM
Yardage (coordinate) Cotton C#####-COLOR, design # ends 1–9 C18691-RED
Wideback WB… WB18748-CREAM
Precut FQ- / 5- / 10- / RP- / 1YD- / ASY- / 3YD- / 3SYD- 10-18690-42
Casepack CP10… / CP15… CP15-18690-22
Panel 1P- out of scope (manual)
Kit / Display KT- / SD- separate sections

-ROT suffix = a special allocation line (ordered flat, no coverage buffer); keep separate from the tier math.


2. Per-line yardage

  • D&R Yds = fabric quantity ordered for this SKU (dye & repeat yardage), with a floor of 500 total across D&R+precut+casepack+advanced (i.e. if the natural order is under 500, top up to 500).
  • Precut Yds, Casepack Yds, ROT, Advanced Yds = pulled per SKU from their sources.
  • Total Yds = D&R + Precut + Casepack + ROT + Advanced.
  • Bolt size = 15 or 10 (yards per bolt) — determines which D/R bucket the line falls in.

3. Dropship accounting ⚠️ (fixed 2026-08-11)

A dropship line = a customer sales order shipping direct to the customer (matched by SKU + SO#), not into the RBD warehouse.

  • Excluded from Ship-to-RBD (see §4) — those units never touch the RBD warehouse.
  • Included in the mill PO grand total — the mill still produces them.
  • Included in the D/R surcharge base — the mill still dyes them.

There can be any number of dropship SOs per PO (0..N), each its own column/record. The web app should treat dropship quantities as a per-SKU list, not a fixed count.


4. Ship-to-RBD (what the warehouse actually receives)

For each SKU, split by bolt size:

  • Ship-to-RBD 15yd = if bolt = 15 → D&R Yds − (dropship 15yd D/R units + dropship CP15 units)
  • Ship-to-RBD 10yd = if bolt = 10 → D&R Yds − (dropship 10yd D/R units + dropship CP10 units)

(Only one of the two applies per SKU, per its bolt size.) The subtraction must span all dropship SOs on the PO, not a fixed first-N.


5. Pricing

  • Base Rate = looked up by vendor (mill) + SKU prefix from the pricing table. Per-piece prefixes (FQ-, 1YD-, ASY-FQ, 1P-P, 1P-PD) multiply the rate by the trailing piece count. (Base rate itself is correct today — no change.)
  • Amount = Base Rate × (D&R + ROT + Advanced + Casepack yardage).

D/R surcharge ⚠️ (fixed 2026-08-11)

A per-yard surcharge on the dye-&-repeat yardage, by bolt bucket:

Bucket Standard (all mills) TaiHan Textile Co., Ltd.
D/R 15 (15yd bolts) $0.15 / yd $0.15 / yd (same)
D/R 10 (10yd bolts) $0.20 / yd $0.17 / yd
  • D/R 15 Surcharge = (15yd D/R yardage, incl. dropship 15yd/CP15) × 0.15
  • D/R 10 Surcharge = (10yd D/R yardage, incl. dropship 10yd/CP10) × (0.17 if mill = TaiHan Textile Co., Ltd., else 0.20)
  • The mill/vendor is a per-PO value (one mill per PO), read from the collection's vendor. Only Taihan differs today; model it as "standard + Taihan override" so a second exception is a one-line add later.

  • Line Total = Amount + D/R 15 Surcharge + D/R 10 Surcharge + Laminate Surcharge.


6. Totals

  • PO grand total = Σ line totals across cotton + precut + kit sections. Includes dropship units (§3).
  • Precut Total / Kit Total = section subtotals; PO Total = cotton + precut + kit.

7. Notes for the port

  • Base rate lookup, dropship exclusion, and the Taihan surcharge are the three areas most likely to be mis-modeled — unit-test each: (a) a Taihan PO shows D/R-10 at 0.17; (b) a dropshipped SKU drops out of Ship-to-RBD but stays in the grand total; (c) Ship-to-RBD subtraction covers every dropship SO on the PO, not just the first few.
  • Panels (1P-) are intentionally manual (sizes 24"/36"/56" vary) — surface the base rate, let the buyer edit qty/size.
  • Reference tier/coverage logic for order quantities lives in reference_rbd_collection_ordering_tiers memory (main/precut ~1.8×, yardage ~1.6×).