/** * HTML body renderers for the four notification jobs. These are the modern * in-process equivalent of the legacy `getXxxForEmail.php` files the PHP * scripts `fetch()`ed by URL. Rendering server-side and inlining the body * in the response keeps a single SES MessageId tied to one frozen HTML * snapshot (vs. the legacy flow, where the URL kept re-rendering with * whatever the database looked like at click time). * * The visual style mirrors the legacy PHP templates where it makes sense * (the office's customer base has been seeing these letters for years; * gratuitous redesign costs trust). The body shell, table layout and the * canonical contact block are preserved verbatim. English copy because the * legacy letters were English; switching to Spanish is a future decision * (see INSURANCE_FEATURES_SPEC §1.6 "Spanish or English body?"). */ const HEAD = ` {title} `; const FOOT_CONTACT = `

If you have any questions regarding this notice please contact us at: Tel. 011 52 (661) 612 - 1295   Fax. (661) 612 - 1285   For any type of a 24 Hrs. emergencies: please dial 52 (664) 304 - 7778 | jorge@jorgecuadros.com | Contact Us Form

`; const SIGNED = (year: number) => `
This message has been generated by the Jorge Cuadros & Assoc. Information Server.
Copyright ${year} Developed by FreaKmA.Net
`; const esc = (s: string | null | undefined): string => String(s ?? "") .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """); const usd = (n: number | string | null | undefined): string => { if (n === null || n === undefined) return "$ 0.00"; const v = typeof n === "string" ? Number(n) : n; if (!isFinite(v)) return "$ 0.00"; return `$ ${v.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2, })}`; }; /** Shared shell: a 2-column table that matches the PHP output layout. */ function shell(opts: { title: string; bg: string; heading: string; accountId: string | number; accountName: string; body: string; note?: string; statementLink?: string; year: number; }): string { const { title, bg, heading, accountId, accountName, body, note, statementLink, year } = opts; const stmt = statementLink ?? "https://my.jorgecuadros.com/"; return `${HEAD.replace("{title}", esc(title))} ${ note ? `` : `` }
${esc(heading)} Please do not reply to this message. For any Jorge Cuadros & Assoc. customer service inquiries, visit: Customer Support
${esc(accountName)}
ACCOUNT #${esc(String(accountId))}
Click Here to View Your Account Statement
 
${body}
 

${esc(note)}

${FOOT_CONTACT}
${FOOT_CONTACT}
 
${SIGNED(year)}
`; } /* -------------------------------------------------------------------------- */ /* Outstanding payments — Job 1 */ /* -------------------------------------------------------------------------- */ export interface OutstandingRow { date: Date | string; reference: string | null; period: string | null; type: string | null; /** Signed amount (negative for charges). */ amount: number | string; /** Running balance in the customer's currency, after this row. */ balance: number | string; } export function renderOutstanding(args: { customerId: string; customerName: string; total: number | string; rows: OutstandingRow[]; year: number; }): string { const rows = args.rows .map( (r) => ` ${esc(String(r.date))} ${esc(r.reference ?? "")} ${esc(r.period ?? "")} ${esc(r.type ?? "")} ${esc(usd(r.amount))} ${esc(usd(r.balance))} `, ) .join("\n"); const body = `

This needs your prompt attention in order to avoid any disruption(s):

TOTAL OF OUTSTANDING BILLS: ${esc( usd(args.total), )} PESOS.

${rows}
DATEREFERPERIODTYPEOFTRXCHARGECREDITBALANCE
`; return shell({ title: "Outstanding Payments", bg: "#9CC", heading: "Outstanding Payments", accountId: args.customerId, accountName: args.customerName, body, note: "NOTE : IF YOU ALREADY SENT THE CHECK, PLEASE DISREGARD THIS EMAIL", year: args.year, }); } /* -------------------------------------------------------------------------- */ /* Payment confirmation — Job 2 */ /* -------------------------------------------------------------------------- */ export function renderPaymentConfirm(args: { customerId: string; customerName: string; typeOfTrx: string; reference: string | null; /** The deposited amount (positive number — credits are positive in the * unified ledger). */ amount: number | string; year: number; }): string { const body = `
${esc( args.typeOfTrx, )} CONFIRMATION Please do not reply to this message. For any Jorge Cuadros & Assoc. customer service inquiries, visit: Customer Support
HI, ${esc(args.customerName)}
ACCOUNT #${esc(args.customerId)}
REFER# ${esc(args.reference ?? "")}
Click Here to View Your Account Statement
 

Your account is now current to keep paying your future obligations. If for any reason your next bill is more than what's available; our system will email you our automatic alert requesting more funds. Thank You,

Your deposit was for ${esc( usd(args.amount), )} PESOS.

 

NOTE : IF YOU ALREADY SENT THE CHECK, PLEASE DISREGARD THIS EMAIL

${FOOT_CONTACT}
 
${SIGNED(args.year)}
`; return `${HEAD.replace("{title}", "Payment Confirmation")}${body}`; } /* -------------------------------------------------------------------------- */ /* Account status — Job 3 (yellow + red) */ /* -------------------------------------------------------------------------- */ export function renderAccountStatus(args: { customerId: string; customerName: string; level: 0 | 1; // 0 = yellow (DEBAJO DEL TIPO), 1 = red (EN ROJO) balance: number | string; /** Amount the customer needs to deposit to clear the threshold. */ tipo: number | string; year: number; }): string { const isYellow = args.level === 0; const body = isYellow ? `

In order to avoid any disruptions please mail or bring ${esc( usd(args.tipo), )} USD ASAP. As your current Balance ${esc( usd(args.balance), )} is under our minimum required to run this account.

` : `

Sorry Account is overdrawn and all utility bills are on hold please rush ${esc( usd(args.tipo), )} USD these funds must be on hand ASAP to reactivate your payments.

`; return shell({ title: "Account Alert", bg: isYellow ? "#88D5EE" : "#FF8D71", heading: "Account Alert", accountId: args.customerId, accountName: args.customerName, body, note: "NOTE : PLEASE MAKE YOUR CHECK PAYABLE TO UMC AND ASSOCIATES. IF YOU ALREADY SENT THE CHECK, PLEASE DISREGARD THIS EMAIL.", year: args.year, }); } /* -------------------------------------------------------------------------- */ /* Trust payment confirmation — Job 4 */ /* -------------------------------------------------------------------------- */ export function renderTrustConfirm(args: { customerId: string; customerName: string; /** Annual fee amount posted (positive, in MXN per the PHP). */ amount: number | string; year: number; }): string { const body = `

This automatic notice is to confirm, that your Annual Bank Fee has been paid by, and posted in your account. Thank You,

The annual fee was posted for the amount of ${esc( usd(args.amount), )} PESOS.

`; return shell({ title: "Trust Payment Confirmation", bg: "#C0BEA0", heading: "Annual Bank Fee Payment Confirmation", accountId: args.customerId, accountName: args.customerName, body, note: "NOTE : Most banks always request to make such payment in advance.", statementLink: "https://my.jorgecuadros.com/", year: args.year, }); }