Work Orders (product) - changes

1. (2026-12-01) Started from a copy of a working shop app. Every shop-specific detail is now a setting:
   shop name, address, phone, email, logo (Settings), and web addresses and time zone (config.php: app_url,
   portal_url, site_url, time_zone). A new shop starts as "Your Shop Name" with nothing filled in. Pages with no
   logo show the shop's name instead. Neutral app icons. The service agreement says "the shop". Links never use
   the address a request claims to come from.

2. (2026-12-02) The app has its own database. Jobs, boats, leads, stock items, purchase orders, reminders sent and the shop's settings
   are kept there instead of in Shopify. With nothing set up it is one file, data/shop.sqlite; a shop can use MySQL instead (the 'db'
   line in config.php). Records have the app's own ids (gid://shop/Record/123). Lists are always exact, so the list copy kept in
   data/cache is gone. Backups read the records from the database, never copy the database file, and a restore gives the new folder
   its own database with every record under its old number. Customers, parts and payments still go through Shopify until later steps.

3. (2026-12-02) Demo version. Turned on with 'demo' => true in config.php on its own copy with its own data folder. Visitors pick owner,
   office or technician on the sign-in page. A pretend store stands in for Shopify (customers, parts, stock, payments), card checkout
   is pretend (demo-pay.php, signed links), no email is sent, and people, passwords, backups and imports are locked. A "Demo shop"
   bar shows on every page. "php demo-reset.php" (nightly cron) puts the sample shop back and signs everyone out; it refuses any folder
   without the demo mark. Tests: tests/demo_t.py.

4. (2026-12-03) Customers live in the app's own database (customers.php), not in Shopify. Ids look like gid://shop/Customer/12.
   Search, add, edit (now with full address and tax exempt), labor rates, unsubscribe from reminders, the customer app, leads turned
   into jobs, the QuickBooks import and backups/restores all use them. Shopify draft orders get the customer's email and tax-exempt
   flag instead of a Shopify customer, and $0 orders no longer try to attach a Shopify customer afterwards.
   New: Customers > Import from CSV (owner only, locked in the demo). Reads comma, semicolon or tab files, column names in many
   spellings (or chosen by the owner), "Last, First" names, business names, ZIPs that lost a leading zero and old Windows text.
   Preview first; existing customers (same email, or same name and phone/address) only get blanks filled in; running it twice adds
   no one. Tests: tests/cust_t.py, tests/cust_ui.py. tests/lappt_ui.py now books appointments for today and tomorrow (it failed
   Thursday to Sunday). The QuickBooks import test (qbo_t) still needs the real data file and has not been run with this change.

5. (2026-12-03) Parts catalog, stock and supplier stock (catalog.php). Stock items are now the parts catalog and every count is the
   app's own; the Shopify stock links (store products, live Shopify counts, Turn on tracking, Unlink, counting location) are gone.
   A part has a name, part number, barcode, brand, category, shelf, unit, cost, markup (a markup with no price sets the price),
   price, shop-supply box, reorder point and amount, and a list of suppliers with their part number and cost (the first is the main
   one). Searching parts on a job, estimate, quick sale or purchase order searches the catalog (words in any order, part numbers
   written any way, a supplier's part number), and each result shows the shelf count and what each supplier has. A part with none
   on the shelf whose suppliers are all out says so before a date is promised. Estimate part lines remember the catalog part and
   come off stock once the sale is paid (once; a failure is retried); an invoice warns when the shelf hasn't enough. Invoices send
   parts as plain lines taxed as the box says.
   Load price file (owner only, locked in the demo): a supplier's price list or an old program's parts list as CSV, up to 20,000
   rows, columns read by name or chosen by hand, an optional supplier and markup for the whole file. Parts already here (same part
   number, barcode or supplier part number) get the file's cost, price, brand and category; loading twice changes nothing.
   Supplier feeds (owner only, locked in the demo): a link to each supplier's stock file. sweep.php reads each one about once an hour,
   or Refresh supplier stock reads them now. Each part then shows e.g. "CWR: 14 in stock, $57.25, checked 40 min ago". When a main
   supplier's cost changes the part's cost follows, and its price too if the owner ticked "Prices follow supplier cost" and the part
   has a markup. Feeds may only point at public web addresses (no local network), 60 s and 30 MB limits.
   Purchase order suggestions order each low part from the supplier that has it in stock at the best cost (then one whose stock
   isn't known), with that supplier's part number and cost. The demo has sample parts with suppliers.
   Fixed: a new demo filled in from the sign-in page skipped its sample stock items (the stock code wasn't loaded there).
   Tests: tests/stk.py and tests/stkui.py rewritten; taxbox_t, refund_t, scan_sale and demo_t updated. A direct CWR connection (their
   dealer API) is not built yet: CWR's stock file works through a feed.

6. (2026-12-03) Invoices, payments and refunds are kept in the app (ledger.php), not as Shopify draft orders and orders.
   An invoice is a pay request named after the job (INV-1056); deposits and card requests are PAY-1001 and up. Every payment,
   deposit or paid invoice makes a receipt (R-1001 and up) with its lines, tax, total, how it was paid, the check or reference
   number and the day the money came in. Tax is worked out the same way as on the job (taxable lines after credits x the rate,
   rounded to the cent), so the invoice, the receipt and the job always agree. A pay request is never paid twice, and a payment
   that is cut off part way is finished, not repeated, the next time the job is opened.
   Refunds: Record a refund on the job (owner and office) picks a receipt and records the amount and how it was given back
   (cash, check, card, wire, other). It can't be more than is left on that receipt or on another job's receipt.
   Card payments online come in step 7. Until then the pay page (pay.php, signed links) only works in the demo, where it pretends;
   a real shop records card payments by hand ("Card"), and the customer approval page says to call or stop by to pay a deposit.
   The daily payment check now compares jobs with their receipts. Gone: Open in Shopify, Check for refunds, the fulfillment
   and order-permission notes, the Shopify order totals warning and demo-pay.php.
   Tests: money_t, taxbox_t, refund_t, paydate_t, health_t, safe_t, demo_t and ask_ui updated; tests/ledger_cli.php stands in
   for a customer paying online.

7. (2026-12-03) Card payments online (payments.php, pay.php, paywebhook.php). The owner connects the shop's own Stripe, Square or
   Shopify account in Settings > Card payments; the money goes straight to the shop. Test mode comes first: Stripe test keys,
   Square's sandbox or a Shopify development store. Pay pages say TEST MODE, receipts say "Card (Stripe test)", and a live key is
   refused in test mode (and the other way round). Keys are kept in the database, only their last 4 characters are ever shown,
   they never reach a browser and are not in backups (type them again after a move). Locked in the demo.
   Every invoice, deposit request and "customer pays on their phone" card payment has a pay link (invoice page, approval page,
   customer app, QR code). The customer presses Pay and pays on the company's own page for exactly that amount; the app never
   sees a card. A payment counts only when the company itself says it is paid: when the customer comes back, when the company's
   signed message arrives (paywebhook.php?p=stripe|square|shopify), when the job is opened, or at the next scheduled check
   (sweep.php). A customer's checkout is closed first whenever the amount changes, the request is removed, or staff record a
   payment in person; if they paid meanwhile, their payment counts and the change stops. A payment of a different amount is
   recorded and flagged. Refunds: Record a refund > Back to their card sends it through the same company (with a key so trying
   again after no answer never refunds twice), then records it.
   Tests: tests/cardpay_t.py and cardpay_ui.py against pretend Stripe, Square and Shopify (tests/fakepay.php, port 8098).
   Not yet tried against the real companies' test accounts: that needs the shop's own test keys.

8. (2026-12-03) QuickBooks Online sync, one way (qbo-sync.php, qbo-connect.php). The owner connects in Settings > QuickBooks Online
   (Intuit's own sign-in, OAuth; the app keeps only the tokens, in the database, never in a browser or a backup), then picks the
   income accounts for labor, parts and other charges, the account money goes into, the sales tax and a start date. The app makes
   its own three items, "Labor / Parts / Other charges (Work Orders)", on those accounts. Invoice lines now carry their kind
   (labor, part...) so each goes on the right item.
   Sent from the start date on: customers (matched to existing QuickBooks customers by email, then name; a name already used
   gets the email added), invoices once emailed or opened (kept up to date; voided if the app removes them unpaid), money received
   (a Payment on the job's invoice when it is in QuickBooks, otherwise a Sales Receipt R-xxxx; $0 receipts that only close an
   invoice are skipped) and refunds (a Refund Receipt R-xxxx-RFn split over the receipt's lines and tax). The QuickBooks invoice is
   always the whole job less what already went over as Sales Receipts, so a job adds up to its total and tax to the cent however it
   was paid. Every amount and the tax are the app's; QuickBooks' total is read back and must match to the cent, or the item stops
   under "Need a look" (Try again corrects that same transaction, never a second one).
   No doubles: one record per item ('$app:qbosync'), Intuit's requestid on every create, and the document number looked up after
   an answer that never came. QuickBooks down or busy: items wait and retry later (up to 6 hours apart). Tokens are refreshed
   as needed; if the shop disconnects the app in QuickBooks the owner gets an email and Connect again carries on. Connecting a
   different company after sales went over is refused. Runs from sweep.php and Send now. Owner only; blocked in the demo.
   Tests: tests/qbosync_t.py and qbosync_ui.py against a pretend QuickBooks (tests/fakeqbo.php, port 8097).
   Not yet tried with a real QuickBooks sandbox company: that needs the app's own Intuit developer keys. Other shops can connect
   only after Intuit reviews the app.

9. (2026-12-04) Setup screen and one-tap updates (setup.php, update.php, version.php, tools/release.php).
   New shop: upload the release zip and open the app. With no config.php every page goes to setup.php, which checks the server
   (PHP 8, SQLite or MySQL, curl, OpenSSL, mbstring, zip, writable folders), asks for the code kept in setup-code.php (only someone
   with the server's files can see it; 10 wrong tries make a new one), the shop's name, email, phone, address and sales tax, the
   time zone, the app's https address, the data folder (outside the web folder when the hosting allows) and SQLite or MySQL, and the
   owner's login. It writes config.php (with its own new secret), makes the database and the owner, signs them in, removes
   setup-code.php and shows the one cron line to add. Once there is an owner it is closed for good. If config.php was made by hand,
   setup only asks for the shop and the owner. If the folder can't be written, it shows config.php's text to save by hand.
   Updates: Settings > Updates (owner only, locked in the demo) shows the version, checks the publisher's feed (every 6 hours or on
   Check for updates) and installs with Update now. A release is used only if its feed is signed with the publisher's key (EC P-256,
   public key in version.php), the zip matches the signed size and SHA-256, every file matches the list inside, PHP files parse and
   the version matches. The shop's own files (config.php, data/, .htaccess, setup-code.php) are never in a release and never touched.
   The records are backed up first, the old files kept, version.php copied last, removed files deleted, and anything going wrong part
   way puts the old files back. Go back to (version) restores the earlier version exactly. Both are in the history log.
   Publisher: php tools/release.php keygen KEYDIR once, then php tools/release.php build VERSION --key KEYDIR/release-private.pem
   --out OUTDIR --feed https://.../feed.json --notes "...", and upload the zip and feed.json. Found by the new tests and fixed: the
   setup page's https check had a broken pattern.
   Tests: tests/setup_t.py (a fresh copy with the real lib.php on its own server), tests/update_t.py (real signed releases).

10. (2026-12-04) Ready for the first shops (pilot.php). The plan's step 10 is two or three shops using the app on real work for a
   month; this is what the app needs for that month.
   Getting your shop ready (owner only, not in the demo): a list on the Jobs screen until everything needed is done, and always in
   Settings > Getting started. It reads the shop's own data, so it can't be ticked by hand: shop name, email, phone and address; an
   email that really went out; the background job (sweep.php) ran in the last 2 hours (with the exact cron line to add); customers;
   a first work order; a backup. Then, if the shop uses them: staff logins, a parts list, card payments, QuickBooks Online. Each has
   an Open button to the right screen. The owner can hide it from the Jobs screen and show it again.
   Report a problem (everyone, including technicians and the stock room computer): More > Report a problem on a phone, the side
   menu on a computer, and My account. They type what happened and tick "This stopped work". It goes by email to the shop's owner
   and, when set, the app's support address (SUPPORT_EMAIL in version.php, set with release.php --support, or support_email in
   config.php), with the shop, who sent it, the screen, the version, the device and the app's five most recent errors. Reports that
   stopped work start with "STOPPED WORK:". The owner sees the last ones in Settings > App health; each is in the history log. At
   most 10 a day from one person. Nothing about customers is added; only what the person types.
   sweep.php notes when it last ran; a sent email notes that email works.
   Tests: tests/pilot_t.py, tests/pilot_ui.py.

11. (2026-12-04) Found while building the first test release. A new install now gets the app's web server rules: the release
   carries htaccess.dist, and setup.php copies it to .htaccess when there is none (updates still never change .htaccess). The rules
   no longer name any one shop, and now also refuse the newer helper files and .pem files. Setup's suggested data folder is outside
   every web folder even when cPanel puts a subdomain inside public_html, and is named for the app's address, so two copies on one
   hosting account never share one. Setup refuses a data folder that already holds another copy's logins, records or backups.
   Tests: setup_t.py (also runs against an unpacked release zip with GM_SETUP_SRC).
   Still to tidy: the inquiry form's "guild" style name and a colour comment in themes.css.
