import type { InvoiceStatus, PaymentStatus } from "./types"; export type PaymentMode = "bank_transfer" | "upi" | "cash" | "cheque" | "other"; export const PAYMENT_MODES: { id: PaymentMode; label: string }[] = [ { id: "bank_transfer", label: "Bank transfer" }, { id: "upi", label: "UPI" }, { id: "cash", label: "Cash" }, { id: "cheque", label: "Cheque" }, { id: "other", label: "Other" }, ]; export const paymentModeLabel = (mode: string): string => PAYMENT_MODES.find((m) => m.id === mode)?.label ?? mode; /** A payment as stored: amounts are integer paise. `amountPaise` is cash; `tdsPaise` is tax the client deducted. */ export interface Payment { id: number; invoiceId: number; paidOn: string; amountPaise: number; tdsPaise: number; mode: PaymentMode; reference: string; notes: string; createdAt: string; /** Payment Entry name on ERPNext once the payment was sent. */ erpnextPaymentEntry?: string | null; } export type PaymentInput = Omit; type TagType = "red" | "green" | "blue" | "gray" | "warm-gray" | "cool-gray" | "purple"; /** What to show in the status column and badges: the cancelled state wins over payment state. */ export function statusBadge(status: InvoiceStatus, payment: PaymentStatus | undefined): { label: string; type: TagType } { if (status === "cancelled") return { label: "Cancelled", type: "gray" }; if (status === "draft") return { label: "Draft", type: "warm-gray" }; switch (payment) { case "paid": return { label: "Paid", type: "green" }; case "partially_paid": return { label: "Partly paid", type: "blue" }; case "overdue": return { label: "Overdue", type: "red" }; default: return { label: "Unpaid", type: "cool-gray" }; } }