"use client"; import dayjs from "dayjs"; export const generatePDF = ( accountNo: string, balance: string, txns: any[], customerName: string, periodFrom: string, periodTo: string, // branchName: string, branchCode: string, cifNumber: string, address: string ) => { const html2pdf = require("html2pdf.js"); /* --------------------------------------------------------- * 1) BUILD TRANSACTION ROWS * --------------------------------------------------------- */ const rows = txns .map((t: any) => { return ` ${t.date} ${t.name} ${parseFloat(t.amount).toLocaleString("en-IN", { minimumFractionDigits: 2, })} ${t.type} ${t.balance} `; }) .join(""); /* --------------------------------------------------------- * 2) MAIN PAGE CONTENT * --------------------------------------------------------- */ const firstPage = `

THE KANGRA CENTRAL CO-OPERATIVE BANK LTD.

Head Office: Dharmsala, District Kangra (H.P.), Pin. 176215

e-Statement Service
Generated: ${dayjs().format("DD/MM/YYYY HH:mm")}
Account Name ${customerName} Branch Name ${branchCode}
Account Number ${accountNo} Branch Code ${branchCode}
CIF Number ${cifNumber} Branch Address DHARAMSHALA, KANGRA
Address ${address}
NEVER SHARE your Card number, CVV, PIN, OTP, Internet Banking User ID, Password or URB with anyone even if the caller claims to be a bank employee. Sharing these details can lead to unauthorized access to your account.

Account statement from ${periodFrom} to ${periodTo}

${rows}
Date Mode / Particulars Withdrawals / Deposits Balance

*** END OF STATEMENT ***

`; /* --------------------------------------------------------- * 3) LAST PAGE * --------------------------------------------------------- */ const lastPage = `

IMPORTANT INFORMATION:

The Kangra Central Cooperative Bank Officials or representatives will NEVER ask you for your personal information i.e. your card details, passwords, PIN, CVV, OTP etc. Do not share such details with anyone over phone, SMS or email.

Always stay vigilant to suspicious emails. Do not open any suspicious emails.

Always stay vigilant when giving out sensitive personal or account information.

Beware of messages that instill a sense of urgency (e.g., account will expire unless you "verify" your information). Contact the Bank directly if unsure.

Always log out of secondary devices and reset your passwords frequently.

Use strong passwords: Create strong passwords that are difficult for hackers to guess.

Use public Wi-Fi with caution: Be careful when using public Wi-Fi networks.

Back up your data regularly to a secure, encrypted, off-site location.

Follow corporate security policies: Adhere to your company's security guidelines.

Assess third-party app permissions carefully before granting access.

Lock your computer and mobile phone when not in use.

Don't leave devices unattended. Keep all mobile devices, such as laptops and cell phones, physically secured.

Don't leave Bluetooth / Wireless turned on when not in use. Enable them only when needed and in a safe environment.

`; /* --------------------------------------------------------- * 4) PDF GENERATION * --------------------------------------------------------- */ const opt = { margin: [15, 10, 20, 10], filename: `Statement_${accountNo}_${dayjs().format("DDMMYYYY_HHmm")}.pdf`, image: { type: "jpeg", quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, letterRendering: true, }, jsPDF: { unit: "mm", format: "a4", orientation: "portrait", compress: true, }, pagebreak: { mode: ["css", "legacy"], before: '.page-break-before', after: '.page-break-after', avoid: ['tr', '.txn-row'] }, }; html2pdf() .set(opt) .from(firstPage + lastPage) .toPdf() .get("pdf") .then((pdf: any) => { const total = pdf.internal.getNumberOfPages(); const w = pdf.internal.pageSize.getWidth(); const h = pdf.internal.pageSize.getHeight(); const hasGState = typeof pdf.GState === "function" && typeof pdf.setGState === "function"; for (let i = 1; i <= total; i++) { pdf.setPage(i); /* LIGHT WATERMARK */ try { if (hasGState) { const light = pdf.GState({ opacity: 0.03 }); pdf.setGState(light); pdf.addImage("/kccb_watermark.png", "PNG", 35, 70, 140, 140); pdf.setGState(pdf.GState({ opacity: 1 })); } else { pdf.addImage("/kccb_watermark.png", "PNG", 35, 70, 140, 140); } } catch { } /* FOOTER */ pdf.setFont("times", "italic"); pdf.setFontSize(9); pdf.setTextColor(100, 100, 100); pdf.text( "** This is only for information purpose and not for legal use **", w / 2, h - 12, { align: "center" } ); /* PAGE NUMBER */ pdf.setFont("times", "normal"); pdf.setFontSize(9); pdf.setTextColor(0, 0, 0); pdf.text(`Page ${i} of ${total}`, w - 15, h - 12, { align: "right", }); } }) .save(); };