/** * Copyright since 2025 Mifos Initiative * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * A one-page issuance-slip PDF for a cheque book already issued to an account — the "Cheque Book" * print action was previously a dead menu stub. This is a record of the issuance itself (which * book/series, leaf range, issued-to account, issue date, branch), not a physical cheque leaf. */ import { jsPDF } from 'jspdf'; const BANK_NAME = 'Nexora Co-operative Bank Ltd.'; const C_TEXT: [number, number, number] = [ 15, 23, 42 ]; const C_MUTED: [number, number, number] = [ 100, 116, 139 ]; const C_BORDER: [number, number, number] = [ 226, 232, 240 ]; const ACCENT: [number, number, number] = [ 30, 64, 175 ]; function formatDate(iso: string | null | undefined): string { if (!iso) return '—'; const d = new Date(iso); if (isNaN(d.getTime())) return String(iso); return d.toLocaleDateString('en-IN', { day: '2-digit', month: 'short', year: 'numeric' }); } export interface ChequeIssuanceSlipBook { id: number | string; accountNo?: string; clientName?: string; accountType?: string; officeName?: string; seriesCode?: string; rangeStart?: string | number; rangeEnd?: string | number; noOfBooks?: number; status?: string; issueDate?: string; } export function buildChequeIssuanceSlipPdf(book: ChequeIssuanceSlipBook): jsPDF { const doc = new jsPDF({ unit: 'mm', format: 'a5' }); const pageWidth = doc.internal.pageSize.getWidth(); const margin = 12; let y = 16; doc.setFillColor(...ACCENT); doc.rect(0, 0, pageWidth, 4, 'F'); doc.setFont('helvetica', 'bold'); doc.setFontSize(14); doc.setTextColor(...C_TEXT); doc.text(BANK_NAME, margin, y); y += 6; doc.setFont('helvetica', 'normal'); doc.setFontSize(10); doc.setTextColor(...C_MUTED); doc.text('Cheque Book Issuance Slip', margin, y); y += 8; doc.setDrawColor(...C_BORDER); doc.line(margin, y, pageWidth - margin, y); y += 8; const row = (label: string, value: string) => { doc.setFont('helvetica', 'bold'); doc.setFontSize(9); doc.setTextColor(...C_MUTED); doc.text(label, margin, y); doc.setFont('helvetica', 'normal'); doc.setFontSize(10.5); doc.setTextColor(...C_TEXT); doc.text(value, margin + 45, y); y += 7; }; row('Issuance ID', String(book.id ?? '—')); row('Account No.', book.accountNo ?? '—'); row('Account Holder', book.clientName ?? '—'); row('Account Type', book.accountType ?? '—'); row('Branch', book.officeName ?? '—'); row('Series', book.seriesCode ?? '—'); row('Leaf Range', book.rangeStart != null && book.rangeEnd != null ? `${book.rangeStart} – ${book.rangeEnd}` : '—'); row('No. of Books', String(book.noOfBooks ?? '—')); row('Status', book.status ?? '—'); row('Issue Date', formatDate(book.issueDate)); y += 6; doc.setDrawColor(...C_BORDER); doc.line(margin, y, pageWidth - margin, y); y += 14; doc.setFont('helvetica', 'normal'); doc.setFontSize(9); doc.setTextColor(...C_MUTED); doc.text('Issued by: ______________________', margin, y); doc.text('Received by: ______________________', margin, y + 16); return doc; }