I rebuilt a question found in actual production source as independent synthetic code. The complete implementation, examples and tests are shared without connecting the original business program or material.

Only good output enters available inventory

Start declares a target; apply accepts production and delivery events. Good units increase inventory, defects remain separate and require a reason, and delivery cannot exceed available good stock. This example rejects over-target production; a real factory needs its own approved excess policy.

Production and delivery completion remain distinct. Making the target does not mark delivery complete. Functions copy state without changing an actual ledger or warehouse. The synthetic memory event list is not an authenticated audit log.

Define the population before limiting the screen

Dashboard counts risk across all supplied rows, sorts risk first with stable identifier order, and then limits visible rows. Three risky entries late in a thousand-row input still produce a global count of three when only two are displayed. Risk is caller-declared, not a process diagnosis.

Calendar average sums good output over today and the preceding four civil dates, dividing by five including empty days. No in-range observation gives null; an observed zero gives zero. Working calendars, holidays and equipment hours are not modeled.

Keep the quantity target visible

Keypad edits the selected good or defect buffer using digits, clear and backspace. The live example connects both buffers, defect reason and delivery quantity to synthetic state. Stubbed event checks confirm that a failed action leaves inventory unchanged; there is no gloved-tablet usability test.

The original prototype uses a database service, while this module is pure memory. Persistence, concurrent users and duplicate requests are not implemented. They require a separate integration rather than being implied by this state example.

Explore the implementation

Complete independent synthetic implementation

function qty(n){if(!Number.isSafeInteger(n)||n<0||n>1000000)throw Error('Bounded whole quantity required');return n;}
export function start(target){qty(target);if(!target)throw Error('Positive target');return{target,good:0,defect:0,delivered:0,inventory:0,events:[]};}
export function apply(state,event){if(!state||!Array.isArray(state.events)||state.events.length>=1000)throw Error('Bounded state required');for(const k of['target','good','defect','delivered','inventory'])qty(state[k]);if(!state.target||state.good>state.target||state.delivered>state.good||state.inventory!==state.good-state.delivered)throw Error('State invariant');const s=structuredClone(state);if(event.kind==='production'){qty(event.good);qty(event.defect);if(!event.good&&!event.defect)throw Error('Empty production');if(event.defect&&(typeof event.reason!=='string'||!event.reason.trim()||event.reason.length>100))throw Error('Defect reason required');if(s.good+event.good>s.target||s.defect+event.defect>1000000)throw Error('Limit exceeded');s.good+=event.good;s.defect+=event.defect;s.inventory+=event.good;}else if(event.kind==='delivery'){qty(event.quantity);if(!event.quantity||event.quantity>s.inventory)throw Error('Delivery exceeds available good stock');s.delivered+=event.quantity;s.inventory-=event.quantity;}else throw Error('Unknown event');s.events.push(structuredClone(event));return s;}
export function status(s){return{production:s.good===s.target?'complete':'in_progress',delivery:s.delivered===s.target?'complete':s.delivered?'partial':'not_started',inventory:s.inventory,defect:s.defect};}
export function dashboard(rows,limit){if(!Number.isSafeInteger(limit)||limit<1||limit>1000)throw Error('Bounded limit');if(new Set(rows.map(r=>r.id)).size!==rows.length)throw Error('Duplicate ID');for(const r of rows)if(typeof r.id!=='string'||!r.id||typeof r.risk!=='boolean')throw Error('Declared risk and ID required');const all=[...rows].sort((a,b)=>Number(b.risk)-Number(a.risk)||(a.id<b.id?-1:a.id>b.id?1:0));return{population:all.length,riskCount:all.filter(r=>r.risk).length,rows:all.slice(0,limit),hasMore:all.length>limit};}
function day(s){if(typeof s!=='string'||!/^\d{4}-\d{2}-\d{2}$/.test(s))throw Error('Civil date required');const n=Date.parse(s+'T00:00:00Z');if(!Number.isFinite(n)||new Date(n).toISOString().slice(0,10)!==s)throw Error('Invalid date');return n;}
export function calendarAverage(rows,today){const end=day(today),start=end-4*86400000;let total=0,count=0;for(const r of rows){const d=day(r.date);qty(r.good);if(d>=start&&d<=end){total+=r.good;count++;}}if(!Number.isSafeInteger(total))throw Error('Total overflow');return{calendarDays:5,total,averagePerCalendarDay:count?total/5:null,observations:count,workingDayCalendar:false};}
export function keypad(value,key){if(typeof value!=='string'||!/^\d{0,6}$/.test(value))throw Error('Bounded digit buffer');if(key==='C')return'';if(key==='backspace')return value.slice(0,-1);if(!/^[0-9]$/.test(key))throw Error('Digit key required');if(value.length===6)return value;return(value==='0'?'':value)+key;}

Do not conflate completion and inventory

With a target of ten, six good and two defective units create inventory six. Delivering three leaves inventory three while cumulative good remains six. Four further good units complete production, but not delivery. One completion badge cannot accurately describe all those states.

The counterexample is inspectable through tests and saved execution records. Adoption requires checking input meaning and failure policy before changing labels. A small independent function does not replace an operational application.

Published code and ZIP use the same reviewed files. The central decision can be inspected without importing company records or running another system. Any added integration needs separate observed results; the existing package does not pre-certify its behavior.

Actual execution evidence and its boundary

The source folder and a fresh ZIP extraction each passed 25 tests. Actual example results are saved in records.json, and the published core can be compared with the download. Historical project completion messages and test totals were not reused as evidence of this execution.

The live screen changes synthetic state through its actual inline code, with handlers also executed against DOM stubs. These checks do not establish rendered-browser or physical-device behavior. An integrated service needs its own observed verification rather than inheriting a broader claim from these small tests.

Changes synthetic state inside this frame only; no company operation or external delivery.

Before adapting the download

The ZIP contains core implementation, tests, runner, saved results and guidance; live examples also include bilingual HTML. This is new synthetic code with permission to modify and reuse, without original customer images, operational records or credentials. It contains no instruction to execute the source business program or transmit its material.

Begin adoption by defining units, input provenance and failure messages for the actual workflow. Passing tests cannot certify all supplied facts or grant operational authority. Authentication, persistence, transmission and rendered-interface review remain outside the small contract. I share both a reusable implementation and the decisions an adopter still needs to make.

Download implementation, tests and examples
Independent synthetic code; modification and reuse permitted