Commit graph

127 commits

Author SHA1 Message Date
43f0861591 feat: manager PO creation, vendor management, import from Excel, item fuzzy search
Permissions & access:
- MANAGER gains create_po, submit_po, edit_own_draft_po, view_own_pos, manage_vendors
- ACCOUNTS gains manage_vendors
- ACCOUNTS added to provide_vendor_id state transition
- MANAGER added to DRAFT/EDITS_REQUESTED submit allowed roles
- canProvideVendorId now includes ACCOUNTS and any MANAGER/SUPERUSER

Vendor required for approval:
- approvepo() now returns error if po.vendorId is null
- Approval page shows danger banner when vendor is missing

Navigation:
- MANAGER gets "New PO", "My Purchase Orders", "Import PO", "Vendors" nav items
- ACCOUNTS gets "Vendors" nav item

Seed data:
- Vendors: 12 total (up from 3), with GST, address, contact details
- Products: 25 total (up from 4), with lastPrice pre-populated

Product fuzzy search in line items editor:
- Typing ≥2 chars in description fetches /api/products/search?q=
- Dropdown shows code, name, description, last price
- Selecting a product auto-fills description and unit price
- Linked items show a "✓ linked" indicator
- productId passed through FormData to createPo action and stored on POLineItem

Excel PO import (/po/import):
- MANAGER, SUPERUSER, ADMIN can access
- Uploads .xlsx file to /api/po/import which parses the Pelagia PO format
- Extracts vendor, line items, quotation ref, T&C, delivery address
- Preview step: user selects vessel + account, auto-matches vendor by name
- Confirmed import creates PO in DRAFT status

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 18:52:51 +05:30
17586e6ea1 fix: serialize Prisma Decimal fields before server→client boundary
Convert quantity, unitPrice, totalPrice, gstRate, and totalAmount to
plain numbers in server pages before passing to client components,
preventing Next.js serialization errors on Decimal objects.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 17:51:54 +05:30
dd7a40e523 fix(ui): remove font-mono from line items numeric cells; revert formatCurrency
font-mono (monospace) renders optically larger than the surrounding
sans-serif at the same em size. Removing it from quantity, unit price,
taxable, GST% and total cells in both read-only and edit mode makes
all numbers visually consistent with the rest of the page.

formatCurrency reverted to Intl.NumberFormat with style:currency (the
original implementation); the spacing issue the user saw was font-related,
not symbol-related.
2026-05-06 00:50:32 +05:30
6f536734bd fix(ui): cohesive currency symbol and vendor field styling
formatCurrency: manually prepend Rs symbol instead of using Intl currency
style, which could inject a non-breaking space between the symbol and number.

po-detail vendor section: replace font-mono on Vendor ID with font-medium
text-neutral-900 so it matches all other detail fields. Not assigned
indicator changed from italic warning text to a small pill badge.
GSTIN keeps mono (it is a standardised code) but now has correct text colour
and tracking for legibility.
2026-05-06 00:45:39 +05:30
2ca1861226 feat(approvals): manager can edit all PO fields during review
Replaces the line-items-only editor with a full ManagerEditPoForm that
covers every field: title, vessel, account, vendor, project code, delivery
date, PI/Quotation No+Date, Requisition No+Date, place of delivery, all
structured T&C fields, and line items (with GST rate).

Edit toggle is amber-styled to distinguish manager changes from submitter
input. On save, a complete snapshot of original values is written to the
audit trail (MANAGER_LINE_EDIT action with metadata.original).

managerEditPo server action: validates manager permission, checks
status == MGR_REVIEW, recalculates totalAmount as grand total including
GST, and persists all updated fields.

Approval detail page now fetches vessels/accounts/vendors to populate the
edit form dropdowns.
2026-05-06 00:38:14 +05:30
ac584bce2f fix: totalAmount always stores grand total including GST
manager-line-edit-actions: add gstRate to lineItemSchema; recalculate
newTotal as sum(qty * unitPrice * (1 + gstRate)) and persist gstRate
on recreated line items.

seed: patch existing POs totalAmount to grand total (taxable * 1.18):
  PO-2026-00001: 8450 -> 9971
  PO-2026-00002: 3200 -> 3776
  PO-2026-00003:  950 -> 1121
2026-05-06 00:30:49 +05:30
bde7fc9842 fix(seed): patch existing PO currency from USD to INR on re-seed 2026-05-06 00:26:59 +05:30
67beccc16d fix(seed): upsert POs so re-running seed does not fail on duplicate poNumber; currency USD -> INR 2026-05-06 00:21:37 +05:30
7c31b0e838 feat(storage): shared link-document action and Python package requirements
link-document server action attaches an uploaded file to a PO after creation.
requirements.txt lists Python packages used for standalone PO generation scripts.
2026-05-06 00:17:56 +05:30
e07ce9bd02 test: unit, integration and E2E test suite (110 unit tests passing)
Unit (Vitest + jsdom):
  po-state-machine.test.ts   21 tests — all transitions and helpers
  permissions.test.ts        11 tests — all 7 roles
  utils.test.ts              17 tests — formatCurrency INR, formatDate, status labels
  validations.test.ts        24 tests — createPoSchema, lineItemSchema, TC defaults
  po-status-badge.test.tsx   17 tests — all 10 statuses
  po-line-items-editor.test.tsx 20 tests — add/remove, GST calc, read-only, diff mode

Integration (Vitest + real DB, mocked auth/notifier):
  create-po.test.ts          — S-01 create, S-02 draft, S-03 submit
  approval-actions.test.ts   — M-02 approve, M-03 reject, M-04 edits/vendor-id, S-06/S-07
  payment-actions.test.ts    — A-01 queue, A-02 mark paid with reference

E2E (Playwright):
  auth.spec.ts               — login, role nav, sign out
  submitter-journey.spec.ts  — S-01 to S-08
  manager-approvals.spec.ts  — M-01 to M-04
  accounts-payment.spec.ts   — A-01, A-02
  po-export.spec.ts          — export buttons, endpoint responses, PDF content
2026-05-06 00:16:10 +05:30
5cb8b228b1 feat(export): individual PO export as PDF and XLSX matching Sample_PO format
GET /api/po/[id]/export?format=pdf — HTML print page; company header, PO meta grid,
vendor block with GSTIN, line items table with taxable/GST%/total columns,
totals (taxable subtotal, GST, grand total), numbered T&C list, dual signature block.
GET /api/po/[id]/export?format=xlsx — SheetJS workbook matching Sample_PO.xlsx column layout.
Export PDF / Export XLSX buttons added to PO detail header.
2026-05-06 00:15:57 +05:30
0d053d9bd4 feat(products): admin product catalogue with auto price update on payment
Products: code, name, description; lastPrice and lastVendor are read-only.
On markPaid: for each line item linked to a product, Product.lastPrice and
lastVendorId are updated automatically and logged as PRODUCT_PRICE_UPDATED.
2026-05-06 00:15:47 +05:30
446c226c77 feat(admin): user, vendor, vessel and account management
Users: CRUD with role assignment, bcrypt password, cannot deactivate own account.
Vendors: CRUD with address, GSTIN, contact mobile; isVerified set when vendorId provided.
Vessels: CRUD with IMO number uniqueness check.
Accounts: CRUD with unique account code.
2026-05-06 00:15:41 +05:30
31906ec8bb feat(history): PO history list with date/vessel/status filters and bulk CSV and PDF export
Full audit list of all POs (latest 200). Filters: date range, vessel, status.
CSV export respects active filters. PDF export renders print-optimised HTML table.
2026-05-06 00:15:33 +05:30
c0ec7716d7 feat(orders): my orders list and receipt confirmation to close PO
My Orders: all submitter POs grouped as open/past with live status, manager note inline.
Receipt: upload receipt file, optional notes; confirms delivery and closes PO to CLOSED.
2026-05-06 00:15:22 +05:30
207c16e0e5 feat(payments): accounts payment queue with two-step payment and product price auto-update
Step 1 (process): MGR_APPROVED → SENT_FOR_PAYMENT, notifies submitter and managers.
Step 2 (mark paid): SENT_FOR_PAYMENT → PAID_DELIVERED, stores paymentRef.
On mark paid: auto-updates Product.lastPrice and lastVendorId for any line items
linked to a product code; logs PRODUCT_PRICE_UPDATED action.
2026-05-06 00:15:14 +05:30
a685e093ac feat(approvals): manager approval queue with decisions and line item editing
Approval queue: paginated list with search (PO number, vessel, submitter, date range).
Decision actions: approve, approve with note, reject (with reason), request edits,
request vendor ID.
Manager line edit: amend line items during review; original snapshot saved to audit
trail; diff shown with amber strikethrough on PO detail.
2026-05-06 00:15:05 +05:30
7e12e24af0 feat(po): PO detail view, vendor ID form and edit/resubmit flow
Detail: order info, vendor (address/GSTIN/contact), line items with GST breakdown,
structured T&C, attachments, activity trail, Export PDF/XLSX buttons.
Vendor ID form: inline on PO detail when status is VENDOR_ID_PENDING.
Edit: pre-populated form for DRAFT and EDITS_REQUESTED; resubmit transitions to MGR_REVIEW.
2026-05-06 00:14:55 +05:30
5a1db32cee feat(po): new PO form with line items, GST rate, structured T&C and file uploads
Form sections: order info, quotation reference (PI No/Date), requisition (No/Date),
place of delivery, line items (UoM dropdown, size, GST% per item), vendor, T&C, attachments.
Line items editor: add/remove rows, GST dropdown (0/5/12/18/28%, default 18%),
live taxable/GST/grand-total breakdown.
T&C: fixed line 1, individual inputs for Delivery, Dispatch, Inspection,
Transit Insurance, Payment Terms, Others.
Save as draft or submit directly for approval (→ MGR_REVIEW).
2026-05-05 23:25:06 +05:30
94774ca96b feat(dashboard): role-specific dashboards for submitter, manager, accounts and admin
Submitter: open PO count, recent orders table, New PO CTA.
Manager: approvals count, approved PO listing, spend by vessel and month bar charts (Recharts).
Accounts: payment queue total value, ready-for-payment count.
Admin/Auditor: total PO count card.
2026-05-05 23:24:55 +05:30
77aafcce99 feat(ui): shared component library — buttons, badges, cards, inputs, header, stat cards 2026-05-05 23:24:46 +05:30
62c5a52fc0 feat(storage): file storage with local dev server and Cloudflare R2 for production
Sign API returns presigned upload URL + storage key.
Dev: files served through auth-gated /api/files/dev route with path-traversal protection.
Prod: R2 presigned URLs for upload and time-limited download.
2026-05-05 23:24:41 +05:30
92b80dd278 feat(notifications): email notifications via Resend with React Email templates
7 event templates: po-submitted, po-approved, po-rejected, edits-requested,
vendor-id-needed, payment-processed, receipt-confirmed.
Notifier uses Resend in production and console.log in development.
2026-05-05 23:24:34 +05:30
c67afb2fff feat(state-machine): PO lifecycle state machine with role-gated transitions
10 statuses, 11 transitions. Each transition declares allowedRoles,
requiresNote flag and sideEffects (which email groups to notify).
Helpers: getTransition, canPerformAction, getAvailableActions, requiresNote.
2026-05-05 23:24:24 +05:30
043b26921a feat(auth): NextAuth v5 credentials login, database sessions and role permissions
7 roles: TECHNICAL, MANNING, ACCOUNTS, MANAGER, SUPERUSER, AUDITOR, ADMIN.
hasPermission / requirePermission helpers used across all server actions.
Login page with email + bcrypt password auth.
Middleware protects all portal routes.
2026-05-05 23:24:15 +05:30
535200aca2 feat(db): Prisma schema with all 11 models, migrations and seed data
Models: User, Vessel, Account, Vendor, Product, PurchaseOrder, POLineItem,
PODocument, POAction, Receipt, Notification.
PO fields include piQuotationNo/Date, requisitionNo/Date, placeOfDelivery,
structured T&C (tcDelivery/tcDispatch/tcInspection/tcTransitInsurance/
tcPaymentTerms/tcOthers), currency default INR.
POLineItem includes gstRate (default 0.18).
Vendor includes address, gstin, contactMobile.
Seed: 5 users across all roles, 3 vessels, 3 accounts, 3 vendors, 3 POs, 4 products.
2026-05-05 23:24:04 +05:30
36f3826684 chore: initialize Next.js 15 project with Tailwind, TypeScript and tooling config 2026-05-05 23:23:43 +05:30