Your app now matches the flow you described. The revision-1 blocker — approvals only existed on the order checkout, so a factory indent could be awarded with no sign-off — is fixed: an indent is now routed by value through Dept Manager → Plant Head before any vendor can see it, and an emergency can bypass the quote step. Every gap listed in revision 1 has been closed in code, deployed, and verified with a real end-to-end test.
| # | Step | Verdict | Evidence |
|---|---|---|---|
| 1 | Factory employee raises a requirement from the factory login | SUPPORTED | “Photo Request” tab — photo, title, description, category, qty, urgency, now also estimated value + department. POST /api/part-requests (factory/admin only). FactoryDashboard.tsx · api/part-requests/route.ts |
| 2 | It appears in the factory’s own view with its approval state | SUPPORTED | GET /api/part-requests?mine=1; the card now shows “Waiting for approval / Approved — visible to sellers / Rejected”. FactoryDashboard.tsx |
| 3 | Department level, then Plant Head final approval — dept heads also have rights | SUPPORTED new | An Approval row is created with the indent, with level/totalLevels/department. Routing: below the auto limit → auto-approved; mid range → Dept Manager (level 1, final); above → Dept Manager, then Plant Head (level 2, final). A plant head may also decide a dept-level item (senior override). Dept managers only see their own department. lib/approvals.ts (routeApprovalChain) · api/part-requests/route.ts · api/approvals/route.ts · ApproverDashboard.tsx |
| 4 | Vendor gets it; if stocked, packs and makes a challan in the monthly-billing format | SUPPORTED | Vendors only see approved indents. “New Challan” form with Challan Type = Regular (per delivery) | Monthly Consolidated, month picker, party select, and line items with product/HSN/qty/unit/price/GST. Regular → auto-invoice; monthly → month-end bill. VendorDashboard.tsx:937,2084,2090 · api/challans/route.ts |
| 5 | Vendor sees what to repair and what to supply new | SUPPORTED | Response types new_item | repair | amc; request kinds part | contract; awarding an AMC response creates an active Service Contract. Repair work is filed by a vendor account (the unreachable repair role was removed). api/part-requests/[id]/respond/route.ts · award/route.ts |
| 6 | Vendor quotes; in an emergency the factory can start work directly | SUPPORTED new | Quoting unchanged, plus a real bypass: an emergency indent can be awarded with no quotation at all (allowed even while still pending approval). The factory sees a “Start work now” action. api/part-requests/[id]/award/route.ts · FactoryDashboard.tsx (emergencyStart) |
| 7 | Month-end bill challan-wise; a new party can be billed immediately | SUPPORTED new | MonthlyBill per factory+vendor+period aggregates that month’s challans; POST /api/monthly-bills builds the draft and a Vercel cron runs on the 1st for active monthly configs. Immediate billing via Quick Bill. Vendors now have a “Monthly Bills” screen (the tab existed in the type union but was never rendered). api/monthly-bills · api/cron/monthly-bills · VendorDashboard.tsx (billing tab) |
| File | Change |
|---|---|
prisma/schema.prisma | Approval gained scope, requestId (unique), level, totalLevels, department; orderId became optional so the same table serves indents and orders. PartRequest gained department, estimatedValue, approvalId, requestNumber. |
src/lib/approvals.ts | Added routeApprovalChain() (auto / dept / dept→plant-head) and fixed the stale threshold comment. |
src/app/api/part-requests/route.ts | On create, generates PR-YYYY-NNNN, routes the chain, writes the Approval, and sets the indent to pending_approval (or open when auto-approved). |
src/app/api/approvals/route.ts | Serves indent approvals in the approver queue, scopes dept managers to their department, advances level 1 → level 2, and on final approval releases the indent to vendors (status: open). |
src/app/api/part-requests/[id]/award/route.ts | Emergency direct-start with no quotation. |
src/app/api/part-requests/[id]/respond/route.ts | Removed the unreachable repair role branch. |
FactoryDashboard.tsx | Estimated value + department inputs; approval state on each indent; “Start work now” for emergencies. |
ApproverDashboard.tsx | Rows now show an Indent/Order chip, chain step, and department. |
VendorDashboard.tsx | New “Monthly Bills” tab; removed the demo party-name fallback from the challan form. |
Run against the live Neon database with the app’s own login flow; all test rows and the temporary password were removed afterwards.
After cleanup the database holds 1 user (the admin), 0 part requests, 0 approvals, 0 challans, 0 monthly bills.
The new screens are in the production JavaScript actually served from https://toolsnaka.store (not merely deployed):
| UI string found in the live bundle | Endpoint on production |
|---|---|
| Monthly Bills | /api/approvals?myQueue=1 → 401 |
| Start work now | /api/monthly-bills → 401 |
| Waiting for approval | /api/billing-config → 401 |
| Estimated value | /api/cron/monthly-bills → 401 |
| Approved — visible to sellers | health → 200, db:ok, Server: Vercel |
| Emergency: you may start the work now | — |
| Check | Observed |
|---|---|
Local ToolNaka server / cloudflared tunnel | not running; port 3000 free |
GET https://toolsnaka.store/ | 200, Server: Vercel |
GET https://toolsnaka.store/api/health | 200 {"status":"ok","db":"ok"} |
Served by Vercel with a brand-new serverless uptime — shutting the laptop down does not take the site down.
MOCK_*) remain in the vendor dashboard but render nothing except a network fallback for service-area zones.APPROVAL_AUTO_LIMIT in src/lib/approvals.ts to change that.Code inspection with exact file:line references, a live end-to-end test against Neon (16/16), and live HTTP checks on https://toolsnaka.store. The three delegated inspectors could not run — the sub-agent model returned 403 Auto-Fast free quota used up — so the work was completed on the mainline; that limitation is stated rather than hidden.