ORDERTHIS QR - ORDERED ITEMS AND TRANSACTION GUARD
Requires the installed dedicated table-ordering and KDS snapshot updates.

ThinkPad terminal:
scp ~/Downloads/orderthis-qr-order-history.zip root@161.97.110.243:/root/

VPS terminal:
python3 -m zipfile -e /root/orderthis-qr-order-history.zip /root/qr-order-history
python3 /root/qr-order-history/vps/install.py

Then upload the CONTENTS of cpanel/ into:
/home/orderthis/public_html/qr.orderthis.website/
Replace page.php and assets/table-order.js; keep all other files.
Hard-refresh the QR page (Ctrl+Shift+R).

Features:
Already ordered shows quantities, item names, modifiers and line totals from
the existing staff table bill. This is the whole table, including server orders,
not just one phone. It is available only while a staff-assigned table is open.
It exposes no customer tokens, contact details or staff notes. Closed table
history is omitted. Payment, fees and final totals remain with the server.
Unsent cart remains separate. Successful sends refresh ordered items.
Error messages appear both at the top and next to Send.

Confirmation fix:
The native promo pricing helper calls ensure_loyalty_schema, whose schema DDL
can implicitly commit a MariaDB transaction. This can save the order but make
the final commit report an error. Setup now runs before the QR send transaction;
repeat loyalty DDL is skipped inside this QR transaction only. Normal schema
setup outside QR transactions is unchanged. Pending sends retain their original
request ID; retry SAME SEND to reconcile an already-saved order.

Installer validates exact helper and prerequisite markers, lints candidate PHP,
and backs up both changed VPS files before replacing. STOP means paste output.
No existing sales, tabs, balances or item rows are rewritten by installation.
No change to TV, personal tabs, or cPanel private/connection.php.

Acceptance:
- Refresh the table page and check Already ordered against the POS table bill.
- If a previous send is pending, retry SAME SEND; verify it clears without
  another chit or additional quantity.
- Send one designated test item, verify immediate confirmation, one new chit,
  same table bill and history refresh.
- Close/pay via normal POS; table ordering and history must close.
- If database error continues, capture the PHP log entry prefixed QR table send.

Local validation:
PHP syntax; JS DOM test for history plus closed/open gate, modifiers, send;
HTTP backend fixture for history sanitization, no new tabs, duplicate retry,
POS prices, CSRF, rollback and table-visit checks; exact loyalty helper guard
fixture verifies schema DDL is skipped inside QR transaction.
Fixtures do not replace live MariaDB/POS acceptance testing.
