THE LABS GADGET CRM — PHASE 6: BARCODE INVENTORY
================================================
Compatibility: installs as an add-on to Phase 5 and the latest Phase 3/4 repair workflow.
Language: English | Theme: Futuristic Dark Blue | Your existing logo is reused.

IMPORTANT — BEFORE UPGRADING
1. Export a full database backup in cPanel > phpMyAdmin > Export.
2. Back up your existing CRM files, especially dashboard.php, crm3.php and repair-view.php.
3. Do NOT delete config.php, other existing PHP files, or your database.
4. Upload this ZIP into the DOCUMENT ROOT of crm.thelabsgadget.com and Extract.
5. Overwrite ONLY dashboard.php, crm3.php and repair-view.php in the current CRM folder.
   All other files in this ZIP are new, independent inventory files.
6. Sign in as OWNER, visit https://crm.thelabsgadget.com/upgrade-fasa6.php,
   click Activate Phase 6 ONCE. Requires Phase 3 database.
7. After successful activation DELETE upgrade-fasa6.php from the server.
8. Open https://crm.thelabsgadget.com/inventory.php
9. Test with one low-value or dummy product, then undo any test stock through
   an auditable Owner/Manager adjustment (do not delete database entries).

PAGES
inventory.php          Inventory dashboard, search, barcode scan, register, stock in,
                       unit cost (authorized roles), count adjustments (Owner/Manager).
inventory-use.php       Scan a part for a particular repair; press Confirm Use Part.
inventory-history.php   Auditable list of stock movements / staff / repair jobs.
inventory-barcode.php   Authenticated printable SVG Code 39 barcode.
inventory-label.php     Barcode label printing with The Labs Gadget branding.
upgrade-fasa6.php      ONE-TIME database activation; delete once activated.

SCAN METHODS
- USB or Bluetooth keyboard-wedge scanner: click inside Barcode field and scan.
  Press Enter or configure your scanner to append Enter if it does not already.
- Camera: press Start Camera in inventory.php or inventory-use.php on HTTPS.
  Allow camera permission. BarcodeDetector (if available) supports common retail
  1D formats including Code 39, Code 128 and EAN/UPC depending on the browser.
  Offline JS fallback reads standard Code 39 barcode labels generated by CRM.
  It may not decode every supplier's barcode in older browsers: use a USB/Bluetooth
  scanner or type the code in those cases. No image is uploaded to a server.
- New item, no vendor barcode: leave Barcode blank and CRM will generate a unique
  Code 39-compatible number. Click Print Barcode Label to make your own stickers.
- Supported manually registered barcode text: uppercase letters, 0-9 and Code39
  punctuation (space, period, hyphen, dollar, slash, plus, percent); 3–64 chars.

STOCK LOGIC
- Scan alone NEVER changes stock.
- Staff can register products and confirm delivery Stock In. Every change is audited.
- Stock is deducted IMMEDIATELY when an assigned staff member, Owner or Manager
  presses Confirm Use Part on a repair in Checking or Repairing status.
- Owner/Manager can reverse an accidental part usage on that repair, limited to
  the net quantity previously consumed by that job.
- Inventory count adjustments require Owner/Manager and a written reason.
- All stock mutations use MySQL transactions with row locks, a no-negative-stock
  rule, CSRF validation and unique request tokens to prevent double submission.
- Cost/stock valuation is visible ONLY to Owner, Manager and Accounts/HR.
  Price-change notes are hidden from other staff in the history view.
- No repair sales, account access, payments, timers, customer records, or older
  inventory counts are changed by this package. There is NO automatic import
  of stock from other software, and there are NO fabricated stock counts.

ADDED DATABASE TABLES
  inventory_items (products, supplier, cost, current quantity, barcode/SKU)
  inventory_movements (append-only quantity and cost-change audit)

TROUBLESHOOTING
- Missing Inventory menu after extraction: replace dashboard.php and crm3.php.
- HTTP 503 / Inventory not active: ensure activation was completed once.
- Camera blocked: your subdomain must serve HTTPS, grant browser permission.
- Scanner inserts code but doesn't search: press Enter or click Find Item.
- Database permission error: ensure user has CREATE, SELECT, INSERT, UPDATE.
- Reinstallation is not needed after the two inventory tables exist. Do not
  run activation repeatedly as a replacement for a backup.
- If any error occurs, DO NOT delete database tables; restore the backup and
  contact your developer with a redacted error screenshot (never passwords).

SECURITY / DEPLOYMENT
- This package deliberately does NOT include config.php or .htaccess.
- Access to all inventory pages requires existing CRM authentication.
- Delete the activation script after installation.
- Use HTTPS and browser permissions for camera scan.
- Syntax validation is not a full substitute for testing on the live hosting.
