pelagia-portal/App/lib/validations/po.ts
Hardik e308d86e93 feat: Companies — multi-company PO support with admin CRUD and export integration
Schema:
- New Company model (name, gstNumber, address, telephone, mobile, email, invoiceAddress, isActive)
- PurchaseOrder.companyId FK (optional, SET NULL on company delete)
- Migration: 20260530000003_add_company

Admin:
- /admin/companies page with full CRUD (create, edit, deactivate, delete)
- Companies table shows name, GST, contact details, status
- Companies link added to Admin section of sidebar (Briefcase icon)

PO forms (new / edit / import / manager-edit):
- Company dropdown appears at the top of Order Information when companies exist
- Pre-populated with first active company; selection persisted to DB via companyId

Import form:
- parseSheet() now extracts companyName from Excel row 1 (col A)
- Import preview auto-matches detected company name against known companies
- Shows detected name as a hint; user can override before saving

Export (PDF + XLSX):
- Company constants (CO_NAME, CO_ADDR, CO_TEL, INV_ADDR, INV_GST) are now
  derived from the linked Company record when present, falling back to the
  original Pelagia Marine hardcoded defaults when no company is set

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 19:31:34 +05:30

75 lines
2.7 KiB
TypeScript

import { z } from "zod";
export const lineItemSchema = z.object({
name: z.string().min(1, "Item name is required"),
description: z.string().optional(),
quantity: z.coerce.number().positive("Quantity must be positive"),
unit: z.string().min(1, "Unit is required"),
size: z.string().optional(),
unitPrice: z.coerce.number().nonnegative("Unit price must be non-negative"),
gstRate: z.coerce.number().min(0).max(1).default(0.18),
productId: z.string().optional(),
accountId: z.string().optional(),
});
export const TC_FIXED_LINE =
"Please quote this purchase order no. for further communications and invoices pertaining to this indent.";
export const TC_FIXED_LINE_2 =
"We encourage bulk packaging and avoid plastic. No asbestos to be used in any product or packing material.";
export const TC_DEFAULTS = {
tcDelivery: "Within 4 to 5 days",
tcDispatch: "To be transported to site address as above. Freight Supplier's A/C",
tcInspection: "NA",
tcTransitInsurance: "NA",
tcPaymentTerms: "Within 30 days from delivery.",
tcOthers: "",
};
export const createPoSchema = z.object({
title: z.string().min(1, "Title is required").max(200),
vesselId: z.string().min(1, "Cost Centre is required"),
accountId: z.string().min(1, "Accounting Code is required"),
companyId: z.string().optional(),
projectCode: z.string().optional(),
dateRequired: z.string().optional(),
vendorId: z.string().optional(),
currency: z.string().default("INR"),
piQuotationNo: z.string().optional(),
piQuotationDate: z.string().optional(),
requisitionNo: z.string().optional(),
requisitionDate: z.string().optional(),
placeOfDelivery: z.string().optional(),
tcDelivery: z.string().optional(),
tcDispatch: z.string().optional(),
tcInspection: z.string().optional(),
tcTransitInsurance: z.string().optional(),
tcPaymentTerms: z.string().optional(),
tcOthers: z.string().optional(),
lineItems: z.array(lineItemSchema).min(1, "At least one line item is required"),
});
export const approvePoSchema = z.object({
note: z.string().optional(),
});
export const rejectPoSchema = z.object({
note: z.string().min(1, "A rejection reason is required"),
});
export const requestEditsSchema = z.object({
note: z.string().min(1, "Please specify what edits are needed"),
});
export const processPaymentSchema = z.object({
paymentRef: z.string().min(1, "Payment reference is required"),
paymentAmount: z.number().positive("Payment amount must be greater than 0").optional(),
});
export const confirmReceiptSchema = z.object({
notes: z.string().optional(),
});
export type CreatePoInput = z.infer<typeof createPoSchema>;
export type LineItemInput = z.infer<typeof lineItemSchema>;