This commit is contained in:
2026-02-26 18:04:34 -06:00
parent 54c43fd052
commit 8f68ed02c5
3 changed files with 43 additions and 1 deletions

View File

@@ -1308,6 +1308,7 @@ app.get('/api/invoices/:id/pdf', async (req, res) => {
// KORRIGIERT: Abfrage von line1-4
const invoiceResult = await pool.query(`
SELECT i.*, c.name as customer_name, c.line1, c.line2, c.line3, c.line4, c.city, c.state, c.zip_code, c.account_number
COALESCE((SELECT SUM(pi.amount) FROM payment_invoices pi WHERE pi.invoice_id = i.id), 0) as amount_paid
FROM invoices i
LEFT JOIN customers c ON i.customer_id = c.id
WHERE i.id = $1
@@ -1361,11 +1362,28 @@ app.get('/api/invoices/:id/pdf', async (req, res) => {
<td class="total-amount">$${parseFloat(invoice.tax_amount).toFixed(2)}</td>
</tr>`;
}
const amountPaid = parseFloat(invoice.amount_paid) || 0;
const balanceDue = parseFloat(invoice.total) - amountPaid;
itemsHTML += `
<tr class="footer-row">
<td colspan="3" class="total-label">TOTAL:</td>
<td class="total-amount">$${parseFloat(invoice.total).toFixed(2)}</td>
</tr>`;
if (amountPaid > 0) {
itemsHTML += `
<tr class="footer-row">
<td colspan="3" class="total-label" style="font-size: 12px; color: #059669;">Less: Payment received:</td>
<td class="total-amount" style="font-size: 12px; color: #059669;">-$${amountPaid.toFixed(2)}</td>
</tr>
<tr class="footer-row">
<td colspan="3" class="total-label" style="font-weight: bold; font-size: 14px; border-top: 2px solid #333; padding-top: 8px;">BALANCE DUE:</td>
<td class="total-amount" style="font-weight: bold; font-size: 14px; border-top: 2px solid #333; padding-top: 8px;">$${balanceDue.toFixed(2)}</td>
</tr>`;
}
itemsHTML += `
<tr class="footer-row">
<td colspan="4" class="thank-you">Thank you for your business!</td>
</tr>`;
@@ -1533,6 +1551,7 @@ app.get('/api/invoices/:id/html', async (req, res) => {
// KORREKTUR: Line 1-4 abfragen
const invoiceResult = await pool.query(`
SELECT i.*, c.name as customer_name, c.line1, c.line2, c.line3, c.line4, c.city, c.state, c.zip_code, c.account_number
COALESCE((SELECT SUM(pi.amount) FROM payment_invoices pi WHERE pi.invoice_id = i.id), 0) as amount_paid
FROM invoices i
LEFT JOIN customers c ON i.customer_id = c.id
WHERE i.id = $1
@@ -1586,11 +1605,28 @@ app.get('/api/invoices/:id/html', async (req, res) => {
<td class="total-amount">$${parseFloat(invoice.tax_amount).toFixed(2)}</td>
</tr>`;
}
const amountPaid = parseFloat(invoice.amount_paid) || 0;
const balanceDue = parseFloat(invoice.total) - amountPaid;
itemsHTML += `
<tr class="footer-row">
<td colspan="3" class="total-label">TOTAL:</td>
<td class="total-amount">$${parseFloat(invoice.total).toFixed(2)}</td>
</tr>`;
if (amountPaid > 0) {
itemsHTML += `
<tr class="footer-row">
<td colspan="3" class="total-label" style="font-size: 12px; color: #059669;">Less: Payment received:</td>
<td class="total-amount" style="font-size: 12px; color: #059669;">-$${amountPaid.toFixed(2)}</td>
</tr>
<tr class="footer-row">
<td colspan="3" class="total-label" style="font-weight: bold; font-size: 14px; border-top: 2px solid #333; padding-top: 8px;">BALANCE DUE:</td>
<td class="total-amount" style="font-weight: bold; font-size: 14px; border-top: 2px solid #333; padding-top: 8px;">$${balanceDue.toFixed(2)}</td>
</tr>`;
}
itemsHTML += `
<tr class="footer-row">
<td colspan="4" class="thank-you">Thank you for your business!</td>
</tr>`;