/**
* 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))}
| ${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))} |
|
| |
| ${body} |
| |
${
note
? `${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.
| DATE | REFER | PERIOD | TYPEOFTRX | CHARGECREDIT | BALANCE |
${rows}
`;
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 ?? "")}
|
|
| |
|
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}