pelagia-portal/App/lib/utils.ts
Hardik cf9ff40262 feat(payments): partial/advance payment support
Allow accounts to record partial/advance payments against a PO before
full delivery. A new PARTIALLY_PAID status tracks in-progress payment;
paidAmount accumulates across multiple markPaid calls. PO only closes
when both paidAmount >= totalAmount AND all line items are delivered.

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

77 lines
2 KiB
TypeScript

import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import type { POStatus } from "@prisma/client";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatCurrency(amount: number | string, currency = "INR"): string {
return new Intl.NumberFormat("en-IN", { style: "currency", currency }).format(
Number(amount)
);
}
export function formatDate(date: Date | string): string {
return new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "numeric",
}).format(new Date(date));
}
export function formatDateTime(date: Date | string): string {
return new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
}).format(new Date(date));
}
export function generatePoNumber(): string {
const year = new Date().getFullYear();
const seq = Math.floor(Math.random() * 100000)
.toString()
.padStart(5, "0");
return `PO-${year}-${seq}`;
}
export const PO_STATUS_LABELS: Record<POStatus, string> = {
DRAFT: "Draft",
SUBMITTED: "Submitted",
MGR_REVIEW: "Under Review",
VENDOR_ID_PENDING: "Vendor ID Pending",
EDITS_REQUESTED: "Edits Requested",
REJECTED: "Rejected",
MGR_APPROVED: "Approved",
SENT_FOR_PAYMENT: "Sent for Payment",
PARTIALLY_PAID: "Partially Paid",
PAID_DELIVERED: "Paid",
PARTIALLY_CLOSED: "Partially Received",
CLOSED: "Closed",
};
export type BadgeVariant =
| "default"
| "secondary"
| "success"
| "warning"
| "danger"
| "outline";
export const PO_STATUS_VARIANTS: Record<POStatus, BadgeVariant> = {
DRAFT: "outline",
SUBMITTED: "secondary",
MGR_REVIEW: "secondary",
VENDOR_ID_PENDING: "warning",
EDITS_REQUESTED: "warning",
REJECTED: "danger",
MGR_APPROVED: "success",
SENT_FOR_PAYMENT: "default",
PARTIALLY_PAID: "warning",
PAID_DELIVERED: "success",
PARTIALLY_CLOSED: "warning",
CLOSED: "secondary",
};