THE LABS GADGET CRM — PHASE 14
CUSTOMER REPAIR TRACKING PORTAL / PRIVATE QR LINK
======================================================

WHAT THIS ADDS
- Tracking QR link per repair job, created by authorized staff (not automatic).
- Public track.php page that shows repair reference, device brand/model, status progress,
  registration/completion/collection dates, optional estimated ready date, and warranty
  state/expiry (when available).
- DOES NOT display customer name/phone/email, IMEI, serial, repair complaint, prices,
  technician identity, QC photos, internal notes or payments.
- Print a standalone QR Tracking Card for the customer; print the QR on repair
  invoices and payment receipts WHEN an active tracking link already exists.
- Staff may deactivate/re-enable or regenerate a link (rotating invalidates all old QR printouts).
- Audit created/disabled/enabled/rotated/estimated-date edits, with staff ID + UTC timestamp.
- Expiry is 365 days from link creation or rotation. To renew, regenerate the link
  (old printed QR codes will become invalid). A disabled link stays disabled.
- All new pages retain English CRM UI, white logo, dark-blue design.

INSTALLATION (BACK UP FIRST)
1. Export database through phpMyAdmin > Export > Quick > SQL.
2. Back up the full current CRM folder. Separately preserve these FOUR files:
     crm3.php        (based on official Fasa13 version)
     repair-view.php (based on official Fasa12 version)
     receipt.php     (based on official Fasa10 version)
     invoice.php     (based on official Fasa10 version)
3. Upload ZIP to the EXISTING document root of crm.thelabsgadget.com.
4. EXTRACT to that directory, with directories preserved. Only four existing
   files above should need overwriting, assuming no custom edits since those versions.
   All other PHP/JS/CSS files in this ZIP are newly added.
5. Log in as Owner and open:
     https://crm.thelabsgadget.com/upgrade-fasa14.php
   Click Activate Phase 14 once. This adds only two new tables:
     repair_tracking_links
     repair_tracking_audit
   Existing CRM data is not erased. No tracking links are automatically published.
6. After success, DELETE upgrade-fasa14.php from File Manager.
7. Visit CRM sidebar > Customer Repair Tracking > Manage any repair > Create.
   Print QR Tracking Card; scan with a PHONE IN A PRIVATE TEST before giving to customer.
   Existing repair invoices and payment receipts gain the QR once link is active.

SECURITY / IMPORTANT
- install_key in your existing config.php MUST be a unique secret (min 16 characters,
  ideally random 32+). DO NOT share it. Changing it after QR codes were printed
  INVALIDATES ALL existing links. Please do not modify this key during normal operation.
- QR token = random 128-bit nonce plus HMAC-SHA256 proof. Only nonce is stored
  in database; token authentication proof is derived on demand from install_key.
- QR link is a BEARER LINK. Anyone who sees the printed code or URL can view
  the limited status, so do not publish it on public social media.
- `track.php` requires no CRM login. Public page sends no customer PII; no external QR APIs.
  The QR is generated locally using a bundled MIT-licensed QRCode JavaScript library.
- URLs use https://crm.thelabsgadget.com as the canonical trusted domain. If domain
  changes, update crm-tracking.php in a controlled release and reprint QR cards.
- Public portal is deliberately read-only. A refresh fetches current repair status.
- No automatic WhatsApp message or notification is sent.
- The estimated date is optional and only shown after staff enters it; it is not a guarantee.
- Access to tracking management is checked server-side: Owner/Manager/Accounts/Frontdesk
  and staff assigned to or registering the relevant job, subject to Repairs permission.
- The QR vendor library is local, not a CDN. QR testing confirmed decodability offline,
  but you MUST verify printing/scanning from an actual receipt printer and phone.

VERIFY
- Staff without permission cannot open tracking-manage.php?id=other_staff_job.
- Create a link: QR scans to limited tracking page with correct status; no PII.
- Update job from Checking to Repairing: public page changes after refresh.
- Print receipt/invoice: if a tracking link is active, QR appears and scans correctly.
- Disable link: old QR leads to generic "link unavailable" page.
- Regenerate link: old QR fails; new one works. DO NOT do this using an actual customer's
  existing printed code without informing them.
- No repair job without a created tracking link should be viewable publicly.
- Check warranty only when available; public page must not show coverage notes.

ROLLBACK
- Restore the four backed-up overwritten PHP files; leave additive tables in place
  unless you have professional DBA supervision and a verified backup.
- To stop public tracking quickly, temporarily deny access to track.php or disable
  links through the CRM. Deleting the code will break the customer QR codes.

NOT YET VERIFIED
- End-to-end MySQL integration, cPanel web server settings, live receipt printing,
  actual Android/iPhone scanning. Please test before publishing to customers.

THIRD-PARTY QR IMPLEMENTATION ATTRIBUTION
QRCode for JavaScript (c) 2009 Kazuhiko Arase, MIT License,
http://www.d-project.com/ . Source adapted from qrcode-terminal's vendor/QRCode.
MIT license: Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
 Software, and to permit persons to whom the Software is furnished to do so,
 subject to the following conditions:
 The above copyright notice and this permission notice shall be included in all
 copies or substantial portions of the Software.
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
