diff --git a/server.js b/server.js index aba5ec5..ec39006 100644 --- a/server.js +++ b/server.js @@ -330,7 +330,9 @@ async function syncInvoiceToQbo(invoiceId, client) { return { success: true, sync_token: updated.SyncToken }; } - +function formatMoney(val) { + return parseFloat(val).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); +} // ===================================================== // POST /api/invoices — Create + Auto QBO Export // ===================================================== @@ -1231,19 +1233,19 @@ app.get('/api/quotes/:id/pdf', async (req, res) => { itemsHTML += ` Subtotal: - $${parseFloat(quote.subtotal).toFixed(2)} + $${formatMoney(quote.subtotal)} `; if (!quote.tax_exempt) { itemsHTML += ` Tax (${quote.tax_rate}%): - $${parseFloat(quote.tax_amount).toFixed(2)} + $${formatMoney(quote.tax_amount)} `; } itemsHTML += ` - TOTAL: - $${parseFloat(quote.total).toFixed(2)} + TOTAL: + $${formatMoney(quote.total)} Thank you for your business! @@ -1353,13 +1355,13 @@ app.get('/api/invoices/:id/pdf', async (req, res) => { itemsHTML += ` Subtotal: - $${parseFloat(invoice.subtotal).toFixed(2)} + $${formatMoney(invoice.subtotal)} `; if (!invoice.tax_exempt) { itemsHTML += ` Tax (${invoice.tax_rate}%): - $${parseFloat(invoice.tax_amount).toFixed(2)} + $${formatMoney(invoice.tax_amount)} `; } const amountPaid = parseFloat(invoice.amount_paid) || 0; @@ -1367,19 +1369,19 @@ app.get('/api/invoices/:id/pdf', async (req, res) => { itemsHTML += ` - TOTAL: - $${parseFloat(invoice.total).toFixed(2)} + TOTAL: + $${formatMoney(invoice.total)} `; if (amountPaid > 0) { itemsHTML += ` - Downpayment: - -$${amountPaid.toFixed(2)} + Downpayment: + -$${formatMoney(amountPaid)} BALANCE DUE: - $${balanceDue.toFixed(2)} + $${formatMoney(balanceDue)} `; } @@ -1491,19 +1493,19 @@ app.get('/api/quotes/:id/html', async (req, res) => { itemsHTML += ` Subtotal: - $${parseFloat(quote.subtotal).toFixed(2)} + $${formatMoney(quote.subtotal)} `; if (!quote.tax_exempt) { itemsHTML += ` Tax (${quote.tax_rate}%): - $${parseFloat(quote.tax_amount).toFixed(2)} + $${formatMoney(quote.tax_amount)} `; } itemsHTML += ` - TOTAL: - $${parseFloat(quote.total).toFixed(2)} + TOTAL: + $${formatMoney(quote.total)} Thank you for your business! @@ -1596,13 +1598,13 @@ app.get('/api/invoices/:id/html', async (req, res) => { itemsHTML += ` Subtotal: - $${parseFloat(invoice.subtotal).toFixed(2)} + $${formatMoney(invoice.subtotal)} `; if (!invoice.tax_exempt) { itemsHTML += ` Tax (${invoice.tax_rate}%): - $${parseFloat(invoice.tax_amount).toFixed(2)} + $${formatMoney(invoice.tax_amount)} `; } const amountPaid = parseFloat(invoice.amount_paid) || 0; @@ -1611,18 +1613,18 @@ app.get('/api/invoices/:id/html', async (req, res) => { itemsHTML += ` TOTAL: - $${parseFloat(invoice.total).toFixed(2)} + $${formatMoney(invoice.total)} `; if (amountPaid > 0) { itemsHTML += ` Downpayment: - -$${amountPaid.toFixed(2)} + -$${formatMoney(amountPaid)} BALANCE DUE: - $${balanceDue.toFixed(2)} + $${formatMoney(balanceDue)} `; }