MEDSERV API DEPLOY — meeting-day round (2026-08-27)
====================================================

WHAT THIS IS
The API changes for the team's 13-point testing feedback, plus everything
from the earlier aug7 round. This zip is a FULL copy of the API (every
file), so it is safe to extract whether or not the aug7 zips were ever
deployed — it SUPERSEDES medserv-api-aug7-deploy.zip completely.
Your server .env is NOT in the zip and will not be touched.

HOW TO DEPLOY (do this BEFORE the web zip and BEFORE the app update)
1. Upload this zip to public_html/ and extract it there
   (it writes into medserv-api/).
2. In cPanel Terminal:
      cd /home/agguae/public_html/medserv-api && php bin/migrate.php
   This applies every pending migration up to 044 (including the aug7
   ones 034-041 if they were never run).
3. Then run the checks:
      php bin/smoke_test.php
      php bin/isolation_test.php

WHAT CHANGED (server side)
- Hospitals can now have several works at the same time — the
  "duplicate work" block only applies to patients now (team item 11).
- Office managers can change the assigned engineer at ANY stage of a
  work, not just right after assignment (team item 12).
- Completing a work now requires at least one attached document/photo.
  Old phone apps are NOT affected until they update — the rule only
  fires for the new app (0.23.0) and the web ERP (team item 13).
- Consumable linking, per the owner's clarification: the link lives on the
  Consumable TYPE — in Masters, each consumable type can be linked to
  SEVERAL machine types (migration 043; the old single machine-type pick
  is carried over automatically). The machine picker on the individual
  consumable form was removed.
- The machines list shows the newest machine first (team item 5).
- Doctors can have an Email ID (team item 6, migration 042).
- New machine registrations can carry a ticked list of accessories
  (team item 7 — no schema change).

NEW (28 Aug): PURCHASE ENTRY + CONSUMABLE CATEGORIES (migration 044)
- Masters gains a "Consumable categories" list, and every consumable type
  gets two dropdowns: Category and Subcategory (GST / Non-GST). Existing
  types start unset — pick them once in Masters; each pick saves itself.
- New "Purchases" screen: one entry per purchase invoice (supplier,
  invoice no + attachment, date). Machine rows register machines (purpose
  Sale, condition Good, warranty computed from years, supplier owed
  updated); consumable rows and non-GST sub-rows add stock. The entry
  number (PE-...) is generated automatically. Entries cannot be edited
  after saving — fix mistakes in the Machines/Consumables screens.
- IMPORTANT: Purchase Entry only offers consumable types whose GST /
  Non-GST subcategory is set — set those in Masters first.
- "+ Register machine" and "+ New consumable" now point staff to
  Purchase Entry (editing existing machines/consumables is unchanged).

AFTER TESTING — CLEARING THE TEST DATA (keeps all masters)
When you are done testing and want the test activity gone, run:
      cd /home/agguae/public_html/medserv-api
      php bin/reset_data.php --transactions-only
That is a DRY RUN — it shows exactly what would be deleted and prints the
confirm command to actually do it (it takes a backup automatically first).
It keeps machines, users, consumables, patients, hospitals, doctors,
suppliers and every setting; it removes work orders, payments, invoices,
expenses, attendance, salaries, visits, leads, transfers, notifications
and the audit log, puts every machine back in stock, restores consumable
stock counts, and restarts work/invoice numbering. Nobody is logged out.
(The same wipe exists as plain SQL in bin/reset_transactions.sql for
phpMyAdmin — export a backup manually first if you use that instead.)

NOTE: app/latest.json is deliberately NOT in this zip. The new app
release ships separately in medserv-app-0.23.0-update.zip — extract
that one only when you want phones to receive the update.
