THE LABS GADGET CRM — PHASE 5
SALES ANALYTICS & STAFF PERFORMANCE
===================================

ABOUT
This is an ADD-ON to the currently running CRM Phases 1–4 with
Automatic Repair Workflow + Job Timer. It uses the official existing
The Labs Gadget logo and English dark-blue interface.

FEATURES
- Sales by selected date range in Malaysia timezone (MYT).
- Paid transaction counts; voided sales are excluded.
- Store-wide reports for admin, manager, accounts only.
- Other roles can only access their own sales and performance.
- Staff performance: paid sales credit, completed assigned repairs,
  work-session hours, collection counts.
- Repair payment channel breakdown (cash / card / QR / bank / e-wallet).
- Outstanding balances for non-cancelled repairs (store-access only).
- Download sales, staff and payment-method reports as Excel-compatible CSV.

FILES (ONLY THESE ARE UPDATED)
  dashboard.php          REPLACED (sidebar link only)
  crm3.php               REPLACED (sidebar link only)
  crm-reports.php        NEW: server reporting helpers
  reports.php            NEW: reports page
  report-export.php      NEW: CSV export endpoint
  assets/reports.css     NEW: responsive styling
  README-PHASE5.txt      NEW: installation instructions

REQUIREMENTS
The existing CRM must already have the following tables:
  users, sales_ledger, repair_jobs, repair_work_sessions,
  repair_payments, repair_invoices.
No database migration or activation script is needed. No password,
configuration or sales records are modified by this package.

INSTALL
1. In cPanel, verify the CRM Document Root and back up the entire
   application folder plus the MariaDB/MySQL database (phpMyAdmin Export).
2. In particular, keep safe copies of dashboard.php and crm3.php.
3. Upload the ZIP into the CRM Document Root and use Extract there.
4. Overwrite dashboard.php and crm3.php ONLY after checking that they
   still match the latest Phase 4 versions (custom changes may conflict).
5. Do NOT delete config.php, current repair records or other files.
6. Sign in as Owner and open https://crm.thelabsgadget.com/reports.php
7. Test with Owner, Manager, Accounts/HR and a regular staff account.

SECURITY / REPORTING NOTES
- Report permissions are enforced server-side (including CSV export).
- Date filters use Malaysia dates but query UTC database timestamps.
- Financial reporting is based on paid ledger entries, not service prices.
- Voided payments are excluded from results but preserved in payment audit.
- Voiding is not a genuine cash refund; reconcile actual refunds externally.
- Method breakdown is for repair payments, not any future ledger sources.
- Completed repairs are attributed to CURRENT assigned user; reassignment
  after completion can change historical staff attribution.
- Work-session durations are attributed to the staff who started the session.
- Sessions started within the date range are included, including any still
  open; those may overstate actual active working time if forgotten.
- Outstanding balance is CURRENT balance, not a historical snapshot.
- Exports are CSV files intended for Excel. They are not native .xlsx files.
- Reporting does not connect to Loyverse or external POS services.
- CRM receipts are not verified Malaysian e-Invoices.

ROLLBACK
Restore dashboard.php and crm3.php from your backup; remove the new
reports.php, report-export.php, crm-reports.php, assets/reports.css.
No database rollback is necessary because this module adds no tables.

TESTING
- PHP syntax validated; static role/date checks performed.
- Live MySQL and cPanel integration cannot be verified outside hosting.
