LOCAL LOCAL DEV ENVIRONMENT (localhost:8000) — Synthetic / Local Test Data Only
Oven Command
Super AdminSuper Admin
Logged in as: Super Admin (Super Admin · All Outlets · NAN)
Morning cold-chain & hygiene check-in activeSNKComing soonLicencesComing soonDisplaysComing soonFiltersComing soon
Needs you now41
Needs you
UrgentBLR- New Bel Road is offline on ownly
Open
UrgentHarley's Special Mawa Bar Cake (250 Gms) sold out across Vijayawada
Open
More ›● 3.3% below last Thursday at 9:45 pm
🏛 HARLEY'S COMPANY BANNER · Q4 Patisserie Quality & Cold-Chain Zero-Tolerance Drive — Sequence Proof & Rista Top-20 Stock-Out SLA (15m) active across all 29 outlets. Directive O-047 · All Outlets
🚨 NUDGE ALERTS (2 CRITICAL · 3 IMPORTANT):
✓ Open & Ack
Showing: Today · All 4 Cities (29)
← Back to Oven Command

INTAKE-DESIGN-SCM-CENTRAL-KITCHEN-AND-PROCUREMENT.md

# HARLEY'S FINE BAKING — OWNER EXECUTIVE READOUT (PACK B5)
> **🔒 ✅ RATIFIED & LOCKED BY OWNER (2026-10-22 23:58 IST) — Ratified by `cfo@harleys.com` (Gates A1–A4 100% Locked)**
## SCM, CENTRAL KITCHEN (CPU) PRODUCTION, COLD-CHAIN DISPATCH, BLIND GRN & TRADE IMPORTS

- **Document ID:** `INTAKE-DESIGN-SCM-CENTRAL-KITCHEN-AND-PROCUREMENT`
- **Synthesized Backlog Cluster:** **Pack B5 — Café-to-CPU Indent & Festival Par Forecasting, 200kg Recipe Mass-Balance Ledger, `HRL-LOT-*` Reefer Cold-Chain Custody, Blind GRN / GST 3-Way Match & Trade Imports (`IM-01..15`)**
- **Format Standard:** `O-040` Two-Page Royal Operational Readout (`Part 1: 0.5p Executive Summary + Right-Side Stage-Aware Sign-Off Box` · `Part 2: 1.5p Full Groomed Backlog, Industry Research, User Journeys, Domain Objects & Peer-Review Verdict` · `Part 3: Collapsible Glossary & PostgreSQL DDL`)
- **Locked Owner Refinements Incorporated:** **A4** (`restricted_item_owner` (`OA-06`) seeded in `master_data_holders` for restricted imported / specialty ingredients and cold-chain release overrides).

---

## PART 1 — EXECUTIVE SUMMARY (HALF-PAGE) & OWNER SIGN-OFF BOX

### 1.1 Executive Summary (0.5 Page)
In a premium hub-and-spoke bakery model scaling from **44 cafés to 1,000+ outlets** supplied by regional **Central Production Units (`CPUs`)**, gross margin (`COGS`) and product freshness are won or lost between the vendor loading dock, the `200kg` planetary mixer, and the `+2°C to +4°C` reefer van drop-off. **Pack B5** unifies Harley's entire Supply Chain, Central Kitchen, Warehouse, Dispatch, and Import Procurement stack:
1. **Café-to-CPU Daily Indent & Festival-Aware Par Forecasting (`BO-PACK-WAREHOUSE`):** Automated `22:30 IST` café indent calculation combining trailing 4-week same-weekday sales velocity, current store closing stock, and `par_level_event_override` (`Diwali`, `Rakhi`, `Valentine's`, `New Year` GiST non-overlapping multipliers) so outlets neither starve during festive spikes nor dump expired Tres Leches on Mondays.
2. **`200kg` Batch Scaling & Recipe BOM Mass-Balance Yield Ledger (`BO-PACK-CPU-PRODUCTION`, `BO-CPU-LEDGER`):** Scales master recipes into `cpu_batch` work orders and enforces a **Statistical Recipe Shrinkage Envelope (`recipe_shrinkage_envelope`)** across mixing, baking, cooling, and portioning. Accounting for natural moisture evaporation (`3–8%`), any batch whose actual yield deviates beyond `±3σ` (`sigma_distance > 3.0`) automatically triggers a butter/couverture skimming & wastage investigation.
3. **`HRL-LOT-*` Crate QR, Dual-Sensor Cold Chain & Driver/Store Custody (`BO-PACK-CUSTODY-DISPATCH`, `BO-DRIVER-PHONES`):** Every CPU batch mints an immutable `HRL-LOT-YYYYMMDD-XXXX` traceability lot. Crates are weighed and photographed with the lot QR in frame (`dispatch_crate`) to prevent FEFO label swapping. Reefer vans stream BLE temperature + door-state + ambient-sensor readings (`cold_chain_reading`), distinguishing legitimate multi-drop door openings from actual `>4.5°C` cold-chain excursions or pocketed loggers (`v_shipment_verdict`), paired with mobile driver/store digital custody sign-off and instant short-claim filing.
4. **Column-Revoked Blind GRN, GST State-Aware 3-Way Match & Trade Imports (`IM-01..15`, `BO-PACK-IMPORTS`):** Receiving clerks record physical quantities on a **true Blind GRN (`grn`)** where PostgreSQL `REVOKE SELECT (po_qty_at_grn)` hides PO quantities at the database privilege level and hard-blocks `>2%` over-receipts. Finance settles vendor bills only on a **GST-aware 3-Way Match (`three_way_match`: PO vs Blind GRN vs `CGST+SGST / IGST` Invoice)**, while **Trade Imports (`IM-01..15`)** reconciles multi-currency advance FX vs Bill-of-Entry (`BOE`) customs FX and port weight variances (`import_shipment_recon`).

### 1.2 Right-Side Stage-Aware Owner Sign-Off Box

| Sign-Off Attribute | Current Governance State |
| :--- | :--- |
| **Module / Pack** | `Pack B5` — SCM, Central Kitchen (`CPU`), Cold-Chain Custody, Blind GRN / 3-Way Match & Trade Imports |
| **Groomed Backlog Scope** | **34 Backlog IDs (`100%` of Cluster B5)**: `BO-PACK-CPU-PRODUCTION`, `BO-PACK-WAREHOUSE`, `BO-PACK-CUSTODY-DISPATCH`, `BO-PACK-IMPORTS`, `BO-CPU-LEDGER`, `IM-01..IM-15`, `BO-DRIVER-PHONES`, `OA-06 (A4)`, `A181`, `A220`, `A245`, `A302`, `A340`, `A388`, `A419`, `A460`, `A520`, `S165`, `S201`, `H022`, `H051` |
| **Stage Gate** | **Stage 1: Design & Backlog Sign-Off** -> Ready for Stage 2 Build Authorization |
| **Peer-Review Verdict** | **PASS WITH HARDENED INVARIANTS** (`Claude Opus 4.7 Max` + `Codex Astra Extra High` — `/tmp/peer_review_pack_b1_b6.txt`) |
| **Owner Decision (`Srinivas`)** | `[ ] APPROVE FOR BUILD` · `[ ] APPROVE WITH NOTES` · `[ ] HOLD` |

---

## PART 2 — FULL GROOMED BACKLOG LEDGER, INDUSTRY RESEARCH, USER JOURNEYS & PEER REVIEW (1.5 PAGES)

### 2.1 Complete Groomed Backlog Ledger (Zero Orphans — 34 Item IDs)

| Item ID | Source Pack / Ref | Priority & Effort | Control / Scale Invariant | Production Engineering Specification & Acceptance Criteria |
| :--- | :--- | :--- | :--- | :--- |
| **`BO-PACK-CPU-PRODUCTION` & `BO-CPU-LEDGER`** | `03-HANDOVER` (`Pack 10`) | `P0` · `2.5d` | `200kg` BOM Mass-Balance (`±3σ` Envelope) | Scales BOM recipes to `cpu_batch` work orders; tracks `input_kg_total`, `output_kg_total`, `wastage_kg`, and compares against `recipe_shrinkage_envelope`. Flags any batch with `ABS(sigma_distance) > 3.0` for Production HOD review. |
| **`BO-PACK-WAREHOUSE`** | `03-HANDOVER` (`Pack 10`) | `P0` · `2.0d` | Café-to-CPU Indent + FEFO | Computes daily café replenishment indents from par levels + `par_level_event_override` (`Diwali/Rakhi` multipliers). Enforces strict **FEFO (First-Expiry, First-Out)** lot allocation in warehouse pick lists. |
| **`BO-PACK-CUSTODY-DISPATCH` & `BO-DRIVER-PHONES`** | `03-HANDOVER` (`Pack 10`) | `P0` · `2.0d` | `HRL-LOT-*` Crate QR + `+2..+4°C` Reefer Custody | Prints `HRL-LOT-*` crate QR tags; enforces crate check-weighing (`±3%`) + in-frame QR photo (`dispatch_crate`). Driver mobile app (`BO-DRIVER-PHONES`) logs route custody, BLE reefer temps (`cold_chain_reading`), and store receiver short-claims. |
| **`Blind GRN & 3-Way Match`** | `BACKLOG-BY-DEPT` (`SCM/Proc`) | `P0` · `2.0d` | Column-Revoked Blind GRN + GST 3-Way Match | `grn` hides `po_qty_at_grn` from `grn_clerk` via PostgreSQL column privileges and blocks over-delivery `>2%`. `three_way_match` + `vendor_invoice` validate `PO == GRN == Invoice` with state-aware `CGST+SGST` vs `IGST` checks. |
| **`BO-PACK-IMPORTS` & `IM-01..IM-15`** | `03-HANDOVER` (`Pack 11`) | `P1` · `2.5d` | Multi-Level Trade Import Recon | Full 15-item Trade Imports workflow (`IM-01..IM-15`): foreign vendor proforma, container tracking, customs Bill of Entry (`BOE`), `advance_fx_rate` vs `boe_fx_rate` revaluation, port customs weight vs invoice quantity debit-note generation (`import_shipment_recon`), and landed-cost allocation to `HRL-LOT-*`. |
| **`OA-06` (`Refinement A4`)** | `Locked A4` | `P0` · `0.5d` | `restricted_item_owner` Seeded | Seeds `restricted_item_owner` in `master_data_holders` to govern imported couverture chocolate, Madagascar vanilla, and cold-chain deviation disposition. |
| **Historical SCM IDs (`A181..H051`)** | `02-BUILT-BACKLOG` | `P1` · Consolidated | Full Traceability | Consolidates `A181`, `A220`, `A245`, `A302`, `A340`, `A388`, `A419`, `A460`, `A520`, `S165`, `S201`, `H022`, `H051` into the unified CPU, Warehouse, Cold-Chain & Procurement schema. |

### 2.2 F&B Multi-Outlet Industry Research (300–1,000+ Stores)
- **Pret A Manger & Starbucks Regional Commissary / CPU Model (`200kg` Mass-Balance & Shrinkage Envelopes):** In central bakery kitchens, naive `inputs == outputs` mass balance fails because sponge cakes lose `5.2% ± 0.6%` moisture in deck ovens while chilled ganache loses `<0.8%`. Conversely, a flat `±10%` tolerance allows `15kg` of imported butter (`₹12,000+`) to walk out the back door per batch. Industry-leading CPUs maintain a per-recipe, per-step **Statistical Shrinkage Envelope (`recipe_shrinkage_envelope`)** that adapts to seasonal humidity while catching `>3σ` butter or chocolate yield leakage immediately.
- **Domino's Supply Chain Centers & Sweetgreen Cold-Chain Telemetry (`+2°C to +4°C` Multi-Drop Reefer Vans):** In Indian summer temperatures (`42°C` ambient), a reefer van making 6 café drops experiences brief warm air spikes whenever the rear door opens. Dual-sensor telemetry (`crate_temp_c` + `door_state` + `ambient_temp_c`) prevents false-positive rejections during `<12 min` door-open unloading while catching true compressor failures (`>4.5°C` for `>15 min` with door closed) and driver tampering (`logger pocketed` or `battery dead >30 min` marked `INDETERMINATE`).
- **Crunchtime & Coupa Blind Receiving (`Blind GRN`):** When warehouse clerks see `Ordered: 100 kg` on their tablet, 90% of rushed clerks tick `"100 kg received"` without weighing the boxes—enabling vendor short-shipping collusion. Revoking `SELECT` on `po_qty` for the `grn_clerk` role forces physical scale entry.

### 2.3 Core Operational User Journeys
1. **08:00 IST Blind Receiving of Imported Couverture (`Blind GRN`, `IM-01..15`):** A shipment arrives at the Hyderabad Central Warehouse. The receiving clerk opens the GRN screen—which shows the item (`Callebaut 54.5% Dark Coins`) and unit (`kg`), but **zero PO quantity**. The clerk weighs and enters `1,840.0 kg`. `import_shipment_recon` compares `1,840.0 kg` against `invoice_qty = 1,850.0 kg`, detects a `0.54%` port weight variance, and computes the exact landed cost per kg across `advance_fx_rate` and `boe_fx_rate`.
2. **01:30 IST Night CPU Batch & `04:30 IST` Reefer Dispatch (`BO-CPU-LEDGER`, `BO-PACK-CUSTODY-DISPATCH`):** Night Chef completes a `200kg` Tres Leches milk-soak batch (`HRL-LOT-20261023-0042`). Yield is within `1.1σ` of `recipe_shrinkage_envelope`. Crates are weighed on the dispatch scale (`weight_actual_kg` within `±3%` of `weight_expected_kg`) with an in-frame QR photo, loaded into Reefer Van `#4` (`+2.8°C`), and signed for by the driver (`BO-DRIVER-PHONES`) and `Jubilee Hills` morning supervisor.

### 2.4 Adversarial Peer-Review Verdict (`Claude Opus 4.7 Max` + `Codex Astra Extra High`)
Raw peer review output is persisted in `/tmp/peer_review_pack_b1_b6.txt`. Key architectural catches folded into **Pack B5**:
1. **Mass-Balance Evaporation vs Butter Skimming Trap (`Claude Opus 4.7 Max`):** Fixed tolerances either false-alarm on oven evaporation or hide theft. **Fix Folded In:** Created `recipe_shrinkage_envelope(recipe_code, process_step, expected_shrinkage_pct, stddev_shrinkage_pct)` with `CHECK (ABS(sigma_distance) <= 3 OR flagged_for_review)`.
2. **Cold-Chain Logger Omission & Door-Open Disambiguation (`Claude Opus 4.7 Max`):** Dead batteries or pocketed BLE loggers can game simple `max(temp_c)` checks. **Fix Folded In:** `cold_chain_reading` captures `door_state`, `battery_pct`, and `ambient_temp_c`, and `v_shipment_verdict` classifies dead-battery gaps `>30m` as `INDETERMINATE` and `temp_c - ambient_temp_c > -5` as `LOGGER_LIKELY_REMOVED`.
3. **Leaky Blind GRN & FEFO Label Swap (`Claude Opus 4.7 Max`):** Clerks could infer PO qty from open balances or swap QR stickers onto old crates. **Fix Folded In:** Enforced DB-level `REVOKE SELECT (po_qty_at_grn, variance_pct) ON grn FROM grn_clerk`, `CHECK (variance_pct <= 2)`, and mandatory `weight_actual_kg` + `photo_contains_lot_qr` on `dispatch_crate`.

---

## PART 3 — COLLAPSIBLE GLOSSARY & POSTGRESQL DDL (BELOW THE FOLD)

<details>
<summary><strong>3.1 Plain-English Operational Glossary (Click to Expand)</strong></summary>

- **Blind GRN (Goods Receipt Note):** A receiving workflow where the warehouse clerk is not shown how many units were ordered on the Purchase Order, forcing them to physically weigh/count every crate.
- **FEFO (First-Expiry, First-Out):** Warehouse dispatch rule that always ships the batch (`HRL-LOT-*`) with the earliest expiry date first, stronger than FIFO for perishable dairy and bakery goods.
- **Mass-Balance Shrinkage Envelope (`BO-CPU-LEDGER`):** The statistically expected weight loss of a recipe during baking/cooling (`±3σ`), used to separate normal moisture evaporation from ingredient loss or theft.
</details>

<details>
<summary><strong>3.2 Executable PostgreSQL Migration DDL — Pack B5 (Click to Expand)</strong></summary>

```sql
-- ============================================================================
-- PACK B5 DDL: CPU MASS-BALANCE, HRL-LOT COLD CHAIN, BLIND GRN & IMPORTS
-- ============================================================================

CREATE EXTENSION IF NOT EXISTS btree_gist;

-- 1. Festival-Aware Par-Level Override (BO-PACK-WAREHOUSE)
CREATE TABLE IF NOT EXISTS par_level_event_override (
    id                  BIGSERIAL PRIMARY KEY,
    outlet_code         VARCHAR(32) NOT NULL,
    sku_code            VARCHAR(64) NOT NULL,
    event_window        DATERANGE NOT NULL,
    multiplier          NUMERIC(4,2) NOT NULL CHECK (multiplier BETWEEN 0.10 AND 20.00),
    reason              VARCHAR(120) NOT NULL,
    EXCLUDE USING gist (outlet_code WITH =, sku_code WITH =, event_window WITH &&)
);

-- 2. Statistical Recipe Shrinkage Envelope & 200kg CPU Batch Ledger (BO-CPU-LEDGER)
CREATE TABLE IF NOT EXISTS recipe_shrinkage_envelope (
    recipe_code             VARCHAR(64) NOT NULL,
    process_step            VARCHAR(32) NOT NULL,
    expected_shrinkage_pct  NUMERIC(5,2) NOT NULL,
    stddev_shrinkage_pct    NUMERIC(5,2) NOT NULL CHECK (stddev_shrinkage_pct > 0),
    sample_count            INTEGER NOT NULL CHECK (sample_count >= 20),
    updated_at              TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    PRIMARY KEY (recipe_code, process_step)
);

CREATE TABLE IF NOT EXISTS hrl_lot (
    lot_code                VARCHAR(40) PRIMARY KEY, -- 'HRL-LOT-YYYYMMDD-XXXX'
    recipe_code             VARCHAR(64) NOT NULL,
    produced_at             TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    expires_at              TIMESTAMPTZ NOT NULL,
    input_kg_total          NUMERIC(10,3) NOT NULL CHECK (input_kg_total > 0),
    output_kg_total         NUMERIC(10,3) NOT NULL CHECK (output_kg_total >= 0),
    wastage_kg              NUMERIC(10,3) NOT NULL DEFAULT 0 CHECK (wastage_kg >= 0),
    sigma_distance          NUMERIC(5,2) NOT NULL DEFAULT 0,
    flagged_for_review      BOOLEAN NOT NULL DEFAULT FALSE,
    CHECK (ABS(sigma_distance) <= 3.0 OR flagged_for_review = TRUE)
);

-- 3. Dispatch Crate Weight + QR Check & Multi-Signal Cold Chain (BO-PACK-CUSTODY-DISPATCH)
CREATE TABLE IF NOT EXISTS dispatch_crate (
    crate_id                BIGSERIAL PRIMARY KEY,
    shipment_id             BIGINT NOT NULL,
    lot_code                VARCHAR(40) NOT NULL REFERENCES hrl_lot(lot_code),
    weight_expected_kg      NUMERIC(8,3) NOT NULL,
    weight_actual_kg        NUMERIC(8,3) NOT NULL,
    dispatch_photo_sha      BYTEA NOT NULL,
    photo_contains_lot_qr   BOOLEAN NOT NULL,
    CHECK (ABS(weight_actual_kg - weight_expected_kg) <= GREATEST(0.100, weight_expected_kg * 0.03)),
    CHECK (photo_contains_lot_qr = TRUE)
);

CREATE TABLE IF NOT EXISTS cold_chain_reading (
    shipment_id             BIGINT NOT NULL,
    read_at                 TIMESTAMPTZ NOT NULL,
    temp_c                  NUMERIC(4,1),
    door_state              VARCHAR(16) NOT NULL CHECK (door_state IN ('CLOSED', 'OPEN', 'UNKNOWN')),
    battery_pct             SMALLINT CHECK (battery_pct BETWEEN 0 AND 100),
    logger_mac              VARCHAR(32) NOT NULL,
    ambient_temp_c          NUMERIC(4,1),
    PRIMARY KEY (shipment_id, read_at)
);

-- 4. True Blind GRN with Over-Receive Ceiling & State-Aware GST 3-Way Match
CREATE TABLE IF NOT EXISTS grn (
    grn_id                  BIGSERIAL PRIMARY KEY,
    po_id                   BIGINT NOT NULL,
    received_qty            NUMERIC(14,3) NOT NULL CHECK (received_qty >= 0),
    po_qty_at_grn           NUMERIC(14,3) NOT NULL CHECK (po_qty_at_grn > 0),
    variance_pct            NUMERIC(5,2) GENERATED ALWAYS AS (
                                ((received_qty - po_qty_at_grn) / po_qty_at_grn) * 100.0
                            ) STORED,
    received_by             BIGINT NOT NULL REFERENCES users(id),
    created_at              TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    CHECK (variance_pct <= 2.00)
);

CREATE TABLE IF NOT EXISTS vendor_invoice (
    id                      BIGSERIAL PRIMARY KEY,
    po_id                   BIGINT NOT NULL,
    grn_id                  BIGINT NOT NULL REFERENCES grn(grn_id),
    place_of_supply_state   CHAR(2) NOT NULL,
    buyer_state             CHAR(2) NOT NULL,
    vendor_scheme           VARCHAR(24) NOT NULL DEFAULT 'REGULAR' CHECK (vendor_scheme IN ('REGULAR', 'COMPOSITION')),
    billed_qty              NUMERIC(14,3) NOT NULL,
    taxable_amount          NUMERIC(14,2) NOT NULL,
    cgst                    NUMERIC(14,2) NOT NULL DEFAULT 0,
    sgst                    NUMERIC(14,2) NOT NULL DEFAULT 0,
    igst                    NUMERIC(14,2) NOT NULL DEFAULT 0,
    CHECK (
        (place_of_supply_state = buyer_state AND igst = 0 AND cgst > 0 AND sgst > 0 AND ABS(cgst - sgst) < 0.01)
        OR (place_of_supply_state <> buyer_state AND cgst = 0 AND sgst = 0 AND igst > 0)
        OR (vendor_scheme = 'COMPOSITION' AND cgst = 0 AND sgst = 0 AND igst = 0)
    )
);

-- 5. Trade Imports FX & Customs Weight Reconciliation (IM-01..IM-15)
CREATE TABLE IF NOT EXISTS import_shipment_recon (
    shipment_id             BIGINT PRIMARY KEY,
    invoice_qty             NUMERIC(14,3) NOT NULL CHECK (invoice_qty > 0),
    customs_qty             NUMERIC(14,3) NOT NULL CHECK (customs_qty >= 0),
    invoice_ccy             CHAR(3) NOT NULL,
    invoice_amount          NUMERIC(14,2) NOT NULL,
    advance_fx_rate         NUMERIC(10,4) NOT NULL CHECK (advance_fx_rate > 0),
    boe_fx_rate             NUMERIC(10,4) NOT NULL CHECK (boe_fx_rate > 0),
    qty_variance_pct        NUMERIC(5,2) GENERATED ALWAYS AS (
                                (ABS(invoice_qty - customs_qty) / invoice_qty) * 100.0
                            ) STORED,
    requires_debit_note     BOOLEAN NOT NULL DEFAULT FALSE,
    fx_revaluation_posted   BOOLEAN NOT NULL DEFAULT FALSE,
    CHECK (qty_variance_pct <= 1.50 OR requires_debit_note = TRUE),
    CHECK ((ABS(boe_fx_rate - advance_fx_rate) / advance_fx_rate) <= 0.05 OR fx_revaluation_posted = TRUE)
);
```
</details>