new message for overdue

This commit is contained in:
2026-03-25 15:42:51 -05:00
parent cc154141bd
commit acd5b7d605
2 changed files with 44 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
// Modal to review and send invoice emails via AWS SES
// With Stripe Payment Link integration
import { showSpinner, hideSpinner } from '../utils/helpers.js';
import { showSpinner, hideSpinner, formatDate } from '../utils/helpers.js';
let currentInvoice = null;
let quillInstance = null;
@@ -118,7 +118,8 @@ function renderModalContent() {
// Variablen für den Text aufbereiten
const invoiceNum = currentInvoice.invoice_number || currentInvoice.id;
const totalDue = parseFloat(currentInvoice.balance ?? currentInvoice.total).toFixed(2);
const customerName = currentInvoice.customer_name || 'Valued Customer';
// Datum formatieren
let dueDateStr = 'Upon Receipt';
if (currentInvoice.due_date) {
@@ -135,17 +136,46 @@ function renderModalContent() {
} else {
paymentText = 'Our terms are Net 30.';
}
const customerName = currentInvoice.customer_name || 'Valued Customer';
const defaultHtml = `
<p>Dear ${customerName},</p>
<p>Attached is invoice <strong>#${invoiceNum}</strong> for service performed at your location. The total amount due is <strong>$${totalDue}</strong>, ${paymentText}</p>
<p>Please pay at your earliest convenience. We appreciate your continued business.</p>
<p>If you have any questions about the invoice, feel free to reply to this email.</p>
<p>Best regards,</p>
<p><strong>Claudia Knuth</strong></p>
<p>Bay Area Affiliates, Inc.</p>
<p>accounting@bayarea-cc.com</p>
`;
// Detect overdue: unpaid + older than 30 days
const invoiceDateParsed = currentInvoice.invoice_date
? new Date(currentInvoice.invoice_date.split('T')[0])
: null;
const daysSinceInvoice = invoiceDateParsed
? Math.floor((new Date() - invoiceDateParsed) / 86400000)
: 0;
const isOverdue = !currentInvoice.paid_date && daysSinceInvoice > 30;
let defaultHtml = '';
if (isOverdue) {
// Reminder / Overdue template
defaultHtml = `
<p>Dear ${customerName},</p>
<p>We hope this message finds you well. Our records indicate that invoice <strong>#${invoiceNum}</strong> in the amount of <strong>$${totalDue}</strong>, dated ${formatDate(currentInvoice.invoice_date)}, remains unpaid.</p>
<p>This invoice is now <strong>${daysSinceInvoice} days past the invoice date</strong>. We kindly request prompt payment at your earliest convenience.</p>
<p>For your convenience, you can pay securely online using the payment link included below. We accept both Credit Card and ACH bank transfer.</p>
<p>If payment has already been sent, please disregard this notice. Should you have any questions or need to discuss payment arrangements, please do not hesitate to reply to this email.</p>
<p>Thank you for your attention to this matter. We value your business and look forward to continuing our partnership.</p>
<p>Best regards,</p>
<p><strong>Claudia Knuth</strong></p>
<p>Bay Area Affiliates, Inc.</p>
<p>accounting@bayarea-cc.com</p>
`;
} else {
// Standard template
defaultHtml = `
<p>Dear ${customerName},</p>
<p>Attached is invoice <strong>#${invoiceNum}</strong> for service performed at your location. The total amount due is <strong>$${totalDue}</strong>, ${paymentText}</p>
<p>Please pay at your earliest convenience. We appreciate your continued business.</p>
<p>If you have any questions about the invoice, feel free to reply to this email.</p>
<p>Best regards,</p>
<p><strong>Claudia Knuth</strong></p>
<p>Bay Area Affiliates, Inc.</p>
<p>accounting@bayarea-cc.com</p>
`;
}
quillInstance.root.innerHTML = defaultHtml;
// Bind Submit Handler