102 lines
3.9 KiB
Markdown
102 lines
3.9 KiB
Markdown
# Andris Car Service — Order Management Dashboard
|
||
|
||
A full-stack Next.js application for managing car service orders, tasks, parts, pricing and printing. Data is persisted in a SQLite database via Prisma, and all functionality is exposed as REST/JSON endpoints so future Android/iOS apps can consume the same backend.
|
||
|
||
## Getting started
|
||
|
||
```bash
|
||
# Install dependencies
|
||
npm install
|
||
|
||
# Push the Prisma schema to the SQLite database
|
||
npx prisma db push
|
||
|
||
# Seed the quick-task list
|
||
npx prisma db seed
|
||
|
||
# Start the dev server
|
||
npm run dev
|
||
```
|
||
|
||
Open http://localhost:3000 in your browser.
|
||
|
||
## Environment variables
|
||
|
||
Copy `.env.example` to `.env` if needed.
|
||
|
||
| Variable | Description |
|
||
|----------|-------------|
|
||
| `DATABASE_URL` | SQLite file path, e.g. `file:./prisma/dev.db` |
|
||
| `DVLA_API_KEY` | Optional UK DVLA vehicle-enquiry API key. Without it (or for Irish registrations), vehicle lookup falls back to manual entry. |
|
||
|
||
## Main API routes
|
||
|
||
All endpoints return JSON.
|
||
|
||
### Cars
|
||
|
||
- `GET /api/cars?q=SEARCH` — list/search cars by reg or owner name; includes orders and parts.
|
||
- `POST /api/cars` — create or return existing car. Body: `{ regNumber, make?, model?, color?, year?, ownerName?, ownerPhone?, ownerEmail?, vin?, engineNumber?, notes?, lookup? }`. Passing `lookup: true` attempts automatic vehicle lookup.
|
||
- `GET /api/cars/:id` — car detail with service history.
|
||
- `PATCH /api/cars` — update a car. Body: `{ id, ...fields }`.
|
||
- `DELETE /api/cars/:id`.
|
||
|
||
### Vehicle lookup
|
||
|
||
- `GET /api/lookup?reg=REG` — attempt to look up make/model/color/year for a registration.
|
||
|
||
### Orders
|
||
|
||
- `GET /api/orders?status=open|closed&carId=ID` — list orders with car and tasks.
|
||
- `POST /api/orders` — create order. Body: `{ carId }`.
|
||
- `GET /api/orders/:id` — order details.
|
||
- `PATCH /api/orders/:id` — update status. Body: `{ status }`.
|
||
- `DELETE /api/orders/:id`.
|
||
|
||
### Tasks
|
||
|
||
- `POST /api/tasks` — add a task. Body: `{ orderId, title, notes?, laborHours?, hourlyRate?, partIds? }`.
|
||
- `GET /api/tasks/:id` — task details.
|
||
- `PATCH /api/tasks/:id` — edit and/or finish a task. Set `status: "finished"` to record completion time automatically. Body accepts `{ title, notes, status, laborHours, hourlyRate, price, partIds }`.
|
||
- `DELETE /api/tasks/:id`.
|
||
|
||
### Parts
|
||
|
||
- `GET /api/parts?q=SEARCH&carId=ID&global=true` — list parts. `carId` returns global parts plus parts linked to that car.
|
||
- `POST /api/parts` — create part. Body: `{ name, manufacturer?, supplierLink?, purchasePrice?, notes?, carId?, isGlobal? }`.
|
||
- `PATCH /api/parts` — update part. Body: `{ id, ...fields }`.
|
||
- `DELETE /api/parts/:id`.
|
||
|
||
### Scrape part info
|
||
|
||
- `POST /api/scrape-part` — body `{ url }`. Returns `{ name?, manufacturer?, price? }` or 422 if scraping fails.
|
||
|
||
### Quick tasks
|
||
|
||
- `GET /api/quick-tasks` — list common tasks sorted by usage.
|
||
- `POST /api/quick-tasks` — upsert a quick task. Body: `{ title }`.
|
||
- `DELETE /api/quick-tasks` — body `{ id }`.
|
||
|
||
### Print data
|
||
|
||
- `GET /api/print/:id?day=YYYY-MM-DD&from=YYYY-MM-DD&to=YYYY-MM-DD&prices=true|false` — returns order, completed tasks filtered by date, a flag for price inclusion and the computed total.
|
||
|
||
## Features
|
||
|
||
- Car record management with Irish/UK registration lookup (falls back to manual entry when lookup is unavailable).
|
||
- Jobs and tasks with automatic finish timestamp.
|
||
- Quick-task list seeded with common service tasks and sorted by usage.
|
||
- Parts library with supplier-link scraping.
|
||
- Task pricing from parts + labour hours × rate, with manual overrides.
|
||
- Print view for a chosen day or date range, with or without prices.
|
||
- Responsive dashboard, car search, car detail, order create/edit, parts library and quick-task management pages.
|
||
|
||
## Scripts
|
||
|
||
- `npm run dev` — start Next.js dev server on port 3000.
|
||
- `npm run build` — production build.
|
||
- `npm run start` — start production server.
|
||
- `npx prisma db push` — apply schema changes.
|
||
- `npx prisma db seed` — reseed quick tasks.
|
||
- `npx prisma studio` — open database studio.
|