THE LABS GADGET CRM — PHASE 10
CRM SETTINGS & ADMINISTRATION
=================================

IMPORTANT: This is an upgrade to the CRM already running after Phase 9.
DO NOT install in a new directory, delete config.php, or reset the database.

OWNER AND ACCOUNTS/HR
- Both can open settings.php and admin.php (Staff Management).
- Both can edit company information, payment document footers, default warranty
  settings, overdue repair thresholds, dashboard text, and role-module access.
- Neither can change the Owner's permissions using the interface.
- Only the Owner can visit the Owner Security tab and activate this Phase 10.
- Database passwords are never shown or changed from the browser.

FILES REPLACED (back up BEFORE extracting)
------------------------------------------
app.php
admin.php
crm3.php
dashboard.php
crm-operations.php
operations.php
invoice.php
receipt.php
warranty-job.php

NEW FILES (will be added)
-------------------------
crm-settings.php
settings.php
upgrade-fasa10.php
assets/settings.css
README-PHASE10.txt

INSTALLATION
------------
1. Before modifying the live CRM, export the entire MySQL/MariaDB database
   with phpMyAdmin (Quick -> SQL). Store the SQL file outside public_html.
2. In cPanel File Manager, BACK UP all NINE replaced files above. The safest
   option is to also create a ZIP backup of the entire current CRM directory.
3. Upload The_Labs_Gadget_CRM_Fasa10_Admin_Settings.zip to the EXACT current
   CRM document root (where dashboard.php and crm3.php exist).
4. Extract into that SAME folder and overwrite only the listed replaced files.
   Do NOT overwrite any separate modifications you need to preserve; reconcile
   if you have manually modified CRM scripts since the previous phase.
5. Log in as the Owner, open:
   https://crm.thelabsgadget.com/upgrade-fasa10.php
   Click "Activate Phase 10" ONCE. It creates three new additive tables:
   crm_app_settings, crm_role_permissions, crm_settings_audit.
6. Open settings.php and test with Owner and Accounts/HR accounts.
7. Immediately DELETE upgrade-fasa10.php from cPanel File Manager.

KEY CHECKS
----------
- HR account can open CRM Settings and edit Staff Permissions.
- HR cannot open settings.php?tab=security (403).
- A Technician cannot open settings.php (403).
- Staff Permissions do not allow non-authorised access to Owner privileges.
- Changing a role's permission to OFF hides the module menu and blocks direct
  page and export URLs. ON only enables the module within pre-existing rights;
  for example, technicians still cannot bypass the payment cashier checks.
- Store-wide sales remain visible only to Owner, Manager and Accounts/HR;
  other staff still see only their own sales. No sales amounts are changed.
- Company/receipt text appears on newly rendered printed documents.
- Warranty settings affect ONLY default fields on new warranty forms.
- Alert thresholds are reflected in Daily Operations and Dashboard.
- Log updates in the Audit History tab.

NOTES & LIMITS
--------------
- No existing customers, staff passwords, repairs, stock, warranty records,
  timers or payment rows are changed by activation.
- The Phase 10 forms write settings/permissions when you SAVE them.
- Module toggles are ROLE-LEVEL, not specific to individual staff members.
- They can DENY a module to a role, but CANNOT override built-in rules about
  sales visibility, cashier authorization or assigned repair jobs.
- Currency (MYR) and timezone (Asia/Kuala_Lumpur) remain fixed and safe.
- Contact/customer number format is NOT changed by these settings.
- Company logo upload accepts PNG only (max 2 MB); original logo is backed up
  as assets/tlg-logo-original.png on first replacement. Refresh cache after.
- Settings are logged in crm_settings_audit; it is not a complete login audit.
- CRM-generated invoices are NOT a substitute for validated LHDN e-Invoices.

ROLLBACK
--------
1. Restore the nine replaced PHP files from your phase-10 backup.
2. Remove the new settings.php / crm-settings.php if rolling back entirely.
3. Leave the three additive Phase 10 tables untouched until you can verify
   whether they contain new settings and audit history worth preserving.
4. Restore database from the SQL backup ONLY if necessary and AFTER checking
   for any new live transactions since the backup (a full restore can erase them).
5. If a custom logo was uploaded, restore the original PNG file from the
   assets/tlg-logo-original.png or from your backup copy.

TESTED LOCALLY
--------------
- PHP 8.4 lint, module-permission helper logic and ZIP integrity.
- Production database integration MUST be tested on the actual cPanel hosting.
