THE LABS GADGET CRM — PHASE 16
Cash Register & Daily Closing (MYT / MYR)
=============================================
REQUIREMENTS: PHP 8.1+, MySQL/MariaDB with InnoDB, working CRM Phase 15, activated Phase 4 Repair Payments, and Phase 11 POS. This patch ONLY adds 3 database tables; it does not modify existing sales, inventory, accounts or historical payments.

BEFORE UPLOADING:
1. BACK UP WEBSITE ZIP outside public_html and EXPORT full SQL database from phpMyAdmin.
2. BACK UP current crm3.php separately.
3. Inspect current crm3.php for your own changes/patches after Phase 15. If it is modified, DO NOT BLINDLY OVERWRITE. Merge ONLY this navigation line from the supplied crm3.php:
<?php if(in_array((string)$user['role'],['admin','manager','accounts','frontdesk'],true) && tlg10_permission($user,'payments')): ?><a class="db2-nav-link <?= in_array($active,['cash-register.php','cash-history.php','cash-close.php'],true)?'active':'' ?>" href="cash-register.php"><span class="db2-nav-icon">▤</span> Cash Register &amp; Closing</a><?php endif; ?>
All NEW pages work by direct URL even if you do not replace crm3.php. No existing CRM page other than crm3.php is replaced.

INSTALL:
- Upload ZIP to SAME folder as app.php, crm3.php and dashboard.php; extract; verify assets/cash.css exists.
- Owner logs in and opens https://crm.thelabsgadget.com/upgrade-fasa16.php.
- Activate; after success DELETE upgrade-fasa16.php immediately.
- Open cash-register.php. Other URLs: cash-history.php, cash-close.php?id=N; cash-export.php (supervisors only).

WORKFLOW:
Today: staff counts Opening Cash -> Open Cash Register -> POS and repair cash payments automatically included as paid -> Cash In/Out for NON-SALES physical transfers only -> count physical money -> Submit Daily Closing -> DIFFERENT supervisor (Owner/Manager/Accounts) approves. The Owner can self-approve with an explanation.
Daily Closing snapshots (including method-level breakdowns) are immutable. If later voids/late payments alter totals, the report shows a Live vs Snapshot discrepancy. Approving with a discrepancy requires a note, not silently rewriting history.
A previous day's OPEN drawer can be submitted only by Owner/Manager/Accounts/HR via cash-close.php; no backdated Cash In/Out or manual opening is supported.

IMPORTANT ACCOUNTING NOTES:
- Payment sources: repair_payments, pos_payments joined to active pos_sales; only status='paid'. sales_ledger deliberately excluded to prevent counting the same receipts twice. Repair deposits count at payment time, not again at Collected.
- MYT calendar day UTC start/end window used for both sources (00:00 local day => 16:00 UTC previous day). No timezone setting is changed in your database.
- Each cash movement is a transfer of physical notes/coins, NOT an added sale; it does not create expenses, Account Payables or Finance payments. Bank deposits/supplier cash payments should also be entered into Finance separately if you use a connected Finance system (avoid duplication). Reconcile against bank separately.
- Voided POS/repair payments are excluded from live totals. A historical snapshot does NOT automatically restate on void; it highlights the discrepancy.
- If you already use a finance-sync patch, this module reads CRM's payment tables only; it does not run the finance-sync or modify Finance records. Check consistency before merging numbers.
- Cash register assumes ONE cash drawer, ONE location and ONE session per MYT business date. Multiple tills/branches require a future upgrade.
- Employee permissions: Owner/Manager/Accounts-HR can view and approve closing reports, Frontdesk can open, record movements and submit their assigned session; Technicians no access by default. All require the Phase 10 payments permission.
- Manual cash count is required; NO automatic bank reconciliation, fingerprint verification, payroll linkage or transaction posting to Finance.

TEST WITHOUT TOUCHING REAL ACCOUNTS:
1. Open test drawer using opening float ONLY if today has no production register; otherwise use staging copy of DB/site.
2. Confirm Repair cash deposit and POS split sale appear ONCE in cash and non-cash breakdown.
3. Test Cash In/Out and reason, then count and Submit -> separate supervisor Approve.
4. Confirm Frontdesk cannot approve, technician cannot enter, no second register for same date.
5. Confirm closed drawer blocks movements, CSV exports, and void/late payments raise drift alert.
Delete test cash sessions only under controlled staging/test database procedures. Opening/closing production date changes legitimate audit history and must NOT be treated as disposable test data.

If a new patch changed crm3.php after Phase15, cherry-pick the nav line instead of installing the packaged crm3.php version. Security matters more than sidebar convenience.
