THE LABS GADGET CRM — OPTION B
AUTOMATIC REPAIR WORKFLOW + JOB TIMER

VERSION: 2026-10-16
PATCH: Only 5 application files + 1 README. Not a full CRM reinstall.
PREREQUISITE: Phase 3 already activated (customers, repair_jobs, repair_events).

FILES IN THIS PATCH:
  repair-view.php                (REPLACES EXISTING FILE)
  crm-workflow.php               (NEW)
  upgrade-workflow.php           (TEMPORARY ONE-TIME INSTALLER; DELETE AFTER ACTIVATION)
  assets/repair-workflow.css     (NEW)
  assets/repair-workflow.js      (NEW)
  README-WORKFLOW-B.txt

BEFORE INSTALLATION:
  1. In cPanel > File Manager, go to the DOCUMENT ROOT for crm.thelabsgadget.com.
  2. Back up repair-view.php as repair-view.php.bak OUTSIDE public_html, or download it.
  3. Export the entire CRM database to an SQL backup from phpMyAdmin.
  4. Do NOT delete config.php, app.php, crm3.php, databases, user accounts or other folders.

INSTALL:
  1. Upload the ZIP into the CRM document root.
  2. Extract in the current CRM folder (not a nested subfolder).
  3. Overwrite repair-view.php when prompted. The other PHP/asset files are new.
  4. Log in as Owner, then visit:
       https://crm.thelabsgadget.com/upgrade-workflow.php
  5. Click Activate Workflow & Timer; wait for confirmation.
  6. Immediately delete upgrade-workflow.php from the server.
  7. Go to Repairs > Open a job and test on a test device, not a real customer repair.

WORKFLOW (NO MANUAL STATUS DROPDOWN):
  Register Device -> Pending
  Start Inspection -> Checking
  Start Repair & Timer -> Repairing, timer starts
  Pause Timer -> Repairing (paused, no time counted while paused)
  Start / Resume Timer -> Repairing, timer starts a new session
  Complete Repair -> Completed (timer stops)
  Confirm Device Collection -> Collected (requires staff confirmation)

SPECIAL CASES:
  * Checking -> Complete Inspection (No Repair), with required reason.
  * Owner/Manager can cancel an open job (reason required), reopen cancelled
    registration, or reopen a completed repair (new timer session starts).
  * A pre-existing job already in Repairing starts with timer paused/not started.
    Click Start / Resume Timer to begin measuring; historical work is NOT guessed.
  * An unfinished timer will keep running on the server even when the browser
    is closed. Staff must Pause before breaks, or Complete when the job is done.
  * Repairs In Progress dashboard category also includes paused Repairing jobs.
  * All existing customer data, repair records, sales access and staff passwords
    are preserved. No existing status columns or role assignments are changed.

ACCESS CONTROL:
  * Owner / Manager: can operate any job, assign any active staff, and use
    cancellation/reopening controls.
  * Any currently assigned and active staff: can operate their assigned job,
    regardless of their role (including Manager, Frontdesk, Accounts / HR).
  * Frontdesk and Accounts / HR: can also confirm customer collection.
  * Timer and job transitions are validated on the server using transactions,
    row locks, role checks, session-based login and CSRF validation.
  * Role-based sales visibility is not modified by this patch.

DATA STORAGE:
  New table: repair_work_sessions
  Each timer session records starting staff and UTC time, stopping staff and
  UTC time, optional pause reason. The timer total is the sum of work sessions
  from the database. The on-screen clock is only a live display.
  repair_events continues logging actions, actor and timestamps.
  Work Sessions displays up to 100 latest sessions per job; total uses all.

ROLLBACK (IF NEEDED):
  Restore your original repair-view.php from its backup. New files and timer
  table can remain unused. Do not drop the table unless you have exported it
  and understand the loss of recorded work sessions.

IMPORTANT:
  This package passed PHP syntax and workflow permission checks locally.
  Actual hosting / database behavior requires verification after activation.
  This is a PHP server-side workflow, NOT an external scheduled automation.
