# 05 · Admin Backend Guide

Every staff screen, organised the way the work actually flows rather than the way the menu is
ordered. Written so a new employee can be handed the section for their role and start.

Staff sign in at **`/login`**. Customers use a different door entirely (`/customer/login`) — the
two are separate authentication systems and neither account works on the other side.

> **Want to see it rather than read it?** [`07-ILLUSTRATED-HANDBOOK.html`](07-ILLUSTRATED-HANDBOOK.html)
> covers the same ground with a screenshot of every screen, every role's sidebar and the full order
> lifecycle — each one photographed from the running application rather than drawn, and each captioned
> with the role it was taken as and the URL it came from.

---

## 1. What you see depends on who you are

There are **12 operational roles plus a super-root master account**. Your role decides your
landing dashboard, your menu, and which buttons exist at all. If a colleague can see a screen you
cannot, that is the permission system working, not a fault.

| Role | Lands on | Owns |
|---|---|---|
| Management | Management board | Everything except the master override |
| Sales / Customer Service | Sales dashboard | Leads, quotations, customer conversation |
| Measurement Rep | Rep dashboard | Home visits, measurements, fabric selection |
| Production Manager | Production board | Scheduling, assignments, work in progress |
| Cutter | Cutting desk | Pattern, cutting, bundling, leftover fabric |
| Tailor | Tailoring station | The 12-step construction sequence |
| QC Officer | Quality desk | Initial and final inspection, packing release |
| Finishing & Packing | Finishing desk | Pressing, contents, two-person sealing |
| Rider | Run sheet | Collection, delivery, proof, cash |
| Inventory / Procurement | Stock desk | Fabric lots, purchase orders, inspection |
| Finance | Finance desk | Ledger, closings, payments, refunds |
| Super root | Management board | The master override, impersonation, everything |

> **Two-factor:** super-root, management and finance accounts must enrol a code generator before
> they can reach anything. You will be redirected to `/admin/identity/security/two-factor` until
> you do — on *every* request, not just the first, so it is a wall rather than a prompt.
>
> **Keep the recovery codes.** Enrolment issues **eight single-use recovery codes**, and the
> sign-in screen accepts one in place of a code from the app. They are shown once. Store them
> somewhere other than the machine they unlock — a finance manager with a lost phone and no
> recovery code cannot reach the ledger, and a super-root in the same position cannot reach
> anything at all.

---

## 2. The spine — how one garment moves through the system

This is the sequence everything else supports. Each step names the screen that performs it and the
**stage gate** that must be satisfied before the work may advance.

| # | Step | Screen | Gate |
|---|---|---|---|
| 1 | Inquiry arrives, owner assigned | `/admin/crm/leads` | **G1** |
| 2 | Home visit booked | `/admin/crm/appointments` | **G2** |
| 3 | Measurements + fabric captured | `/admin/measurements` | **G3** |
| 4 | Quotation issued, advance taken | `/admin/orders/desk/quotations` | **G4** |
| 5 | Fabric received and inspected | `/admin/inventory/fabric-inspection` | **G5** |
| 6 | Production file released, work scheduled | `/admin/production/files` | **G6** |
| 7 | Cutting, bundling, leftover recorded | `/admin/production/cutting` | **G7** |
| 8 | Stitching — 12 steps | `/admin/production/tailoring` | **G8** |
| 9 | Final QC signed | `/admin/production/quality` | **G9** |
| 10 | Two-person packing and sealing | `/admin/production/packing` | **G10** |
| 11 | Dispatch authorised | `/admin/shipping/manifests` | **G11** |
| 12 | Delivered, proof captured | `/admin/shipping/pod` | **G12** |
| 13 | Order closed, costs recorded | `/admin/orders` | **G13** |

**A gate is not a checkbox.** The system refuses the transition until the evidence genuinely
exists — and for G7, G9, G10 and G12 that includes a photograph. If a button is disabled or an
action is refused, open `/admin/orders/desk/gates`, find the order, and it will tell you exactly
which criterion is outstanding.

Only the super-root account can override a gate, it must give a written reason, and the override
raises an escalation that management sees. That is deliberate.

---

## 3. Sales and CRM

### Leads — `/admin/crm/leads`
Board view (`/board`) for working the pipeline, list view (`/list`) for searching. Every lead has
an owner and a next action; both are mandatory because an unowned lead is how an inquiry dies.

**First response is on a 30-minute clock** during business hours (10:00–19:00, Mon–Sat). The
countdown chip on each lead shows green, amber, then red. Breaches escalate.

### Appointments — `/admin/crm/appointments`
Calendar (`/calendar`) or list (`/list`). Booking checks the service area: an address outside the
serviceable radius is refused with a readable message rather than silently accepted.

Reminders go out automatically the day before and three hours before. Both are email — **this
system never sends SMS or WhatsApp, anywhere, by design**.

### Complaints — `/admin/crm/complaints`
Every complaint gets a category, an owner and a resolution trail. Complaints tied to a production
error feed the alteration flow at no charge to the customer.

### Feedback — `/admin/crm/feedback` · Follow-ups — `/admin/crm/follow-ups` · Route plans — `/admin/crm/route-plans`

---

## 4. Orders

### The register — `/admin/orders`
Every order, filterable by stage. Tabs across the top count what is in each phase. **Inspect**
opens the full order.

### Creating one — `/admin/orders/create`
A wizard: customer → garments → measurements → fabric and customisation → charges → quotation.
Measurements are *pinned by version* to the order — later edits to the customer's profile do not
retroactively change what a garment was cut from.

### Quotations — `/admin/orders/desk/quotations`
Price, charges, discounts. **A discount beyond the configured threshold (15% of the line total, or
Rs 5,000) requires management sign-off before the quotation can be issued.** The request is raised
automatically; you do not need to remember to ask.

### Stage gates — `/admin/orders/desk/gates`
The single most useful screen when something is stuck. Shows every gate on every order, what has
been recorded, what is outstanding, and who owns it.

### Approvals — `/admin/orders/desk/approvals` and `/admin/approvals/desk`
Seven customer approval points and nine internal ones. Anything awaiting a decision appears here
with its SLA clock.

### Cancellations — `/admin/orders/desk/cancellations`
Three cancellation stages with 16 cost categories, because cancelling before cutting and
cancelling after cutting are financially different events.

---

## 5. Production

### Files — `/admin/production/files`
The seven-point verification a garment must pass before the floor may touch it. **Schedule the
work (assign cutter, tailor, QC officer and the dates) before releasing the file** — G6 requires
assignments and a schedule, and release is refused without them.

### Cutting — `/admin/production/cutting`
Start the job, cut, then complete it: piece counts, fabric used, wasted and leftover, and **a
photograph of the labelled bundle**. The photograph is mandatory — a mislabelled bundle is how a
customer receives somebody else's fabric, so the SOP makes the photograph the gate itself.

Cut cloth cannot be returned to stock. This is the point of no return.

### Tailoring — `/admin/production/tailoring`
Twelve construction steps, ticked as they are completed. Completing the twelfth moves the garment
to initial QC — provided the bench handover has been acknowledged by the receiving tailor
personally (G8 needs both halves).

### Quality — `/admin/production/quality`
Initial and final inspection against a category checklist, with defects recorded by severity and
responsible role.

**The inspector may never be the person who stitched the garment.** This is enforced in the
application *and* by a database constraint. Final QC requires a signed sign-off photograph before
the garment may be released to packing.

A failed inspection sends the garment to alteration with correction instructions — and failing is
never blocked by missing pass-evidence, which would be absurd.

### Finishing — `/admin/production/finishing` · Packing — `/admin/production/packing`
Packing requires **two different people** to verify contents before sealing. One person cannot
complete it alone; the system rejects a second signature from the same account.

### Alterations — `/admin/production/alterations`
Categorised by cause. **A production error is never chargeable to the customer** — the system will
not let you bill for it.

---

## 6. Inventory

| Screen | Purpose |
|---|---|
| `/admin/inventory/stock-lots` | Fabric lots, quantities, quarantine status |
| `/admin/inventory/suppliers` | Supplier records |
| `/admin/inventory/purchase-orders` | Draft → submit → approve, as **three separately-gated steps** — one person cannot do all three |
| `/admin/inventory/goods-receipt` | Receiving against a purchase order |
| `/admin/inventory/fabric-inspection` | The six-point check: colour/shade, length/width, weave, stains and holes, uneven dye, shrinkage |
| `/admin/inventory/customer-fabric` | Cloth the customer supplied — held in custody, never mixed with stock |

A failure on **colour/shade or dye evenness** fails the fabric outright and quarantines the lot,
because it cannot be matched across a seam. Any other single failure is a conditional pass.

---

## 7. Shipping

| Screen | Purpose |
|---|---|
| `/admin/shipping/shipments` | All shipments and their status |
| `/admin/shipping/manifests` | Rider run-sheets for the day |
| `/admin/shipping/pod` | Proof of delivery — photograph, signature, failure reasons |
| `/admin/shipping/cod` | Cash-on-delivery reconciliation |

Karachi is served by own-fleet zones; the rest of Pakistan by courier zones with manual
tracking-number entry.

**Dispatching with an outstanding balance requires finance approval.** A fully-paid order needs
nothing.

**COD cash** moves rider → finance as a recorded custody handover, then finance counts it in
against the declared amount. Discrepancies are visible, not absorbed.

---

## 8. Finance

| Screen | Purpose |
|---|---|
| `/admin/finance/ledger` | The double-entry general ledger — 31 seeded accounts |
| `/admin/finance/closings` | Daily register closing |
| `/admin/finance/reports` | Financial reporting |
| `/admin/payments/desk` | Recording payments, verifying bank-transfer proofs |

Every payment posts a balanced journal entry. **Accounting periods are locked by a database
trigger**, not by application code — once a period is closed, a late entry cannot slip in behind
the snapshot even by direct database access.

Payment methods are COD, bank transfer (with proof upload and a verification queue) and PayFast.

---

## 9. Commission

`/admin/commission` · `/admin/commission/payouts` · `/admin/commission/statement`

Category-level split rates, pre-sale and post-sale. Commission **matures 15 days after delivery**:
before maturity it can be voided; after maturity a reversal is a clawback. Managers earn a
configurable override on their team's matured commissions. Negative agent balances are allowed and
net against the next payout.

---

## 10. Analytics

`/admin/analytics/dashboard` — the management board: 13 widgets across four priority tiers.
Also `/financial`, `/leaderboard`, `/production-board`.

Figures that are not yet being computed say **"Awaiting data"** rather than showing a zero. This is
deliberate: a zero is a number somebody acts on.

---

## 11. Identity, audit and system

| Screen | Purpose |
|---|---|
| `/admin/identity/users` · `/teams` · `/users/tree` | Staff accounts and the org tree |
| `/admin/identity/roles` | Role and permission editing |
| `/admin/identity/security/*` | Sessions, devices, login history, 2FA enrolment |
| `/admin/audit/trail` · `/activity` | The immutable activity trail — append-only, enforced at the database |
| `/admin/audit/logins` · `/impersonations` | Who signed in, and who acted as whom |
| `/admin/audit/escalations` · `/exceptions` | Escalation board and exception register |
| `/admin/notifications/*` | Email templates, preview, delivery log, preferences |
| `/admin/core/settings` · `/geography` · `/feature-flags` | Business settings, Karachi zones, flags |
| `/admin/queue` | Background job monitor — **check here first when emails stop arriving** |
| `/admin/my-checklist` | Your role's own operational checklist |

---

## 12. Super root

`/admin/identity/impersonation`

Super root can **take over any account** — staff or customer — to see exactly what they see.
Every impersonated session is time-limited (30 minutes by default), fully logged, and **financial
writes are blocked while impersonating**. You can look, you cannot spend.

Super root is also the only account that can **bypass a stage gate**. It requires a written
reason, it is audited, and it raises an escalation. Use it when reality and the system disagree —
not to save two minutes.

---

## 13. When something is refused

| What you see | What it means |
|---|---|
| A button is missing entirely | Your role does not hold that permission |
| "Gate G_ is not satisfied" | Evidence is outstanding — open `/admin/orders/desk/gates` to see exactly what |
| "Requires approval" | An approval request has been raised; it is on the approver's desk with an SLA clock |
| Inspector refusal at QC | You stitched this garment — someone else must inspect it |
| Packing will not seal | It needs a second, different person to verify |
| A discount will not apply | It exceeds the threshold and needs management sign-off |
| Emails are not arriving | Check `/admin/queue` — the worker is probably not running |

Nothing above is a fault. Each one is a control that exists because the SOP asked for it.
