# Bhagirath ERP: what changed (before and after)

Summary of the changes made to the ERP between the original code ("Audi new", the starting point) and
the handover version of October 2026. All existing features were kept; changes are to presentation,
data handling, workflow, security and code quality.

In numbers: 236 files changed; 5 new database migrations; 22 new database tables (17 dropdown lists,
plus registry, station staff, QA photos, station hand-over and QA section remarks); every table now
has a description.

---

## 1. Production floor and station work

| Area | Before | After |
|---|---|---|
| Production Floor screen | The live station view and roster were empty: the screen read fields the server never sent | Live line view: every station in sequence with its chassis, timers and holds; "where is this chassis?" search; tabs for All chassis, Holds and Overdue |
| Station check-in / check-out | No screen recorded it, so station positions were never captured | Operators check chassis in and mark them complete; times are recorded per station |
| Operator screen | None | **My Station** (phone-first): one tab per assigned station, scan or pick a chassis, check in, mark complete, see parts and QA status, chassis age in days |
| Who works where | Not recorded | **Station Staff** screen: assign each user to stations as Operator or QA; people see only their stations |
| Moving to the next station | A chassis could be checked in anywhere at any time | **QA-gated hand-over**: after an operator completes a station that has QA checksheets, the chassis waits for QA. Only when QA passes every mandatory checksheet and releases it can the next station check it in. Stations without checksheets pass it on at once. A QA fail sends it back for rework. |
| Which station is next | Not defined | The next station in sequence where the chassis's own BOM has parts, otherwise simply the next station |
| Time display | Minutes only (e.g. "3120m") | Days and hours (e.g. "2d 4h"); chassis age in days |

## 2. Quality (QA)

| Area | Before | After |
|---|---|---|
| Inspecting on the floor | Desktop-oriented inspection page | **QA Inspection** (phone-first): tabs per QA station, "Waiting for QA" list, checksheets per chassis, OK / Not OK / N/A, measurements, sign-off, release to the next station |
| Photos | Not possible per checkpoint | Photos on each checkpoint, taken with the phone camera |
| Remarks | Limited | Remarks on every checkpoint, on every section and on the whole checksheet; shown again on reopen |
| Checksheet set-up | One long scrolling list | Checksheets grouped by station, collapsible sections, search and filters, tab for station assignments |
| Duplicate inspections | Opening an inspection twice at the same moment created duplicate records | Prevented (server-side lock); the pass check tolerates any existing duplicates |
| Invented data | A missing revision date showed a made-up "2026-05-01" | Shows only real data |

## 3. Dropdown lists and hard-coded data

| Before | After |
|---|---|
| 17 dropdown lists were typed into the program code (production lines, AC makes, interior work, yard locations, machine types, material categories, rental vendors and equipment, QA verification methods, hold types, payment terms, regions, enquiry types and sources, chassis document types, gate-pass items, thermal checksheet items). Changing a value needed a developer. | Each list is its own database table, editable by admins under **Setup > Production Masters > Dropdown Lists**. A registry table names every list. |
| Some screens loaded photos from a fixed `http://localhost:8000` address, which broke on any other computer | Addresses come from the app's configuration |
| PO, GRN and debit-note numbers were random numbers created in the browser (duplicates possible) | Issued by the server in sequence: `PO-2026-00001`, `GRN-2026-00001`, `DN-2026-00001` |
| Debit-note value was rejected quantity × a fixed ₹100 | Rejected quantity × the actual PO unit price |
| Demo-data files and mock pricing logic (QuoteWizard, cpqLogic, seat configurations) shipped with the app | Removed |

## 4. Reports and dashboards

| Area | Before | After |
|---|---|---|
| Production report | One very wide table needing sideways scrolling | View tabs (Overview, Specs & features, Seating & body, Shop floor, Dates & ageing, Dealer & PDI, All columns); click a chassis for a grouped detail panel |
| Sales dashboard | Showed nothing: the server side did not exist and the page crashed | Live figures: chassis in production, DA-lite holds, ready for dispatch, arrivals; pipeline by station (from the stations list); top dealers; model mix; recent movements; date range filter |
| Home dashboard | Fake "All systems operational" badge, generic greeting | Greets the signed-in user by name; badge removed |
| Dispatch queue | Model column always empty | Shows the chassis model |

## 5. Navigation and look

| Before | After |
|---|---|
| Menu grouped by department with mixed labels and colours | Grouped by task: Chassis & Yard, Production, Quality, Sales & Orders, Purchasing, Stock, Setup, Admin; plain labels; one accent colour |
| Browser pop-up alerts and confirms | The app's own toasts and confirmation dialogs |
| Emoji in headings and buttons | Removed for a consistent professional look |
| Diagnostics/debug page reachable in the app | Removed |
| Operators saw the full office menu on phones | Phone tab bar shows My Station / QA Inspection to people who have them |

## 6. Bugs fixed

| Problem before | Now |
|---|---|
| Feature BOM screen and BOM analysis crashed (they read columns removed from the database earlier) | Work; a feature option's parts apply to every model |
| Payment confirmation: two copies of the same endpoints, the working one never reached | Duplicates removed |
| Ad-hoc material issue to a chassis failed with a programming error | Fixed |
| Customer profile could crash on a removed "Quotes" section | Removed |
| Starting the app a second time silently moved it to another port and login said "Unable to connect" | Start-up script stops the old copy and keeps fixed ports |
| Rebuilding the database from the migration history failed | Completes |
| Automated tests failed (they were not signed in, and expected outdated behaviour) | All pass |

## 7. Security

| Before | After |
|---|---|
| 36 maintenance endpoints (diesel, LPG, solar, incoming material, stock, equipment, machine cost, consumables) could be read, changed or deleted without signing in | Require sign-in and the MAINTENANCE permission |
| BOM analysis endpoints open without sign-in | Require BOM view permission |
| A database password and personal computer paths written in scripts; demo users seeded with a fixed password | Removed; passwords come from settings or the environment |
| A test endpoint that deliberately produced errors | Removed |

## 8. Database

| Before | After |
|---|---|
| No table descriptions; hard to tell what a table holds | Every table carries a plain-English description visible in pgAdmin (Properties → Comment) |
| Dropdown values inside program code | 17 `*_master` tables plus `master_list_registry` |
| No record of who works at which station | `station_user_assignment` |
| No hand-over or QA gate record | `chassis_station_handoff` (AWAITING_QA → QA_PASSED → RELEASED → RECEIVED) |
| No QA photos or section remarks | `qa_response_photo`, `qa_section_remark` |
| Program's model of the database and the real database had drifted | Checked and in sync |

New migrations, in order: `c7d8e9f0a1b2`, `e1f2a3b4c5d6`, `f2a3b4c5d6e7`, `g3b4c5d6e7f8` (plus a repair
to an older one). All are safe to run on the existing database and keep existing data.

## 9. Code quality and housekeeping

| Before | After |
|---|---|
| 20 one-off fix, refactor and check scripts mixed with the real data loaders | Removed; remaining scripts documented in `backend/scripts/README.md` |
| Unused imports and components across backend and frontend, and 10 screen files nothing linked to | Removed |
| Informal comments ("let's just…", "for now") | Rewritten |
| No settings template | `.env.example` for backend and frontend |
| Outdated documentation (referred to removed files; duplicated names) | Archived; replaced by the new documents below |

## 10. Set-up, phones and documentation

| Before | After |
|---|---|
| Windows-only setup notes | Step-by-step setup guides for Windows and Mac; one-command Mac setup and start scripts |
| Phones on the plant Wi-Fi blocked by the server's security settings | Allowed for private network addresses (`ALLOWED_ORIGIN_REGEX`); `run_mac.sh --lan` |
| No technical handover | `docs/TECHNICAL_HANDOVER.md`: architecture, every module and screen, database guide, business flows, what affects what, how to make common changes |
| No database reference | `docs/DATABASE_REFERENCE.md`: every table and column, generated from the database |

---

## Known limitations at handover

- Phone browsers allow the camera only on HTTPS pages; on the local (HTTP) setup operators pick or type
  the chassis number instead of scanning.
- New installations should be built from the database dump; a database built from migrations alone
  differs slightly in detail.
- Uploaded photos and documents are files on disk (`backend/uploads`) and must be backed up with the
  database.
- QA shortage logging has an API but no screen (the screen was already disconnected in the original).
