Flow
A blind count from morning to send
1Save
Save what the system thinks each store has, once a day.
2Pick
A fixed formula picks a few products from both back room and floor.
3Hide
The sheet shows where to look but never the expected number.
4Send once
Each store gets one sheet a day, and only in the morning.
The first blind inventory audit lost stock before the store ever saw the form. A package with no quantity of its own came in as zero, not unknown. The code skips anything with zero on hand, so that product could never be picked to count.
Why the sheet hides the number
Each morning a timer has the ordering system save what it thinks every store has. Later it picks a few products per store, checks stock again, and makes a count sheet. The sheet lists the product, its tags, the rooms to look in, and a blank box. It never shows the number the system expects.
If you can see the number, you will find a way to match it. So I hide it. Both of my numbers, the morning one and the fresh one, stay on the server, and the team compares them with the count later.
How a missing quantity became zero
When a package had no quantity, the code was meant to add up its rooms instead. But in JavaScript, Number(null) is zero, and so is an empty string. Zero looks like a real answer, so the room total was never used. Now the code checks for missing values first and treats them as missing. A test proves a package with no quantity but stocked rooms gets the room total.
The lock that couldn't be read back
The morning save must happen once a day, so it takes a database lock first. I used a helper that tries to read the lock's result back, and there is no result to read. A different helper fixed it. The test for it uses a fake database and only checks that the right helper got called.
The sandbox, the retries and the empty days
The timer's sandbox hid the folder the app lives in, which I'd bet kept it from reaching the app. I opened just that. A failed morning save now gets a couple of retries and then stops. A save with no stores, or too few products, fails instead of locking in a bad day. A sheet from yesterday can't go out today.
Picking the products
A hash of the date, store and product decides the order, so the same day always gives the same list and nobody can reroll it. Later I added a rule that each sheet needs products from both the back room and the sales floor, and only rooms with stock get listed.
The send goes automatic
Sending began as a button. By the end of the day a second timer did it, but only in the morning, only with that day's save, and only once per store per day.
Before the counts come back
This is all code and tests, and I haven't seen a store send a counted sheet back. Until one does, I don't know what the counts will show.