From 8f68ed02c56ce15687a1d67d14e12dc72527def3 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Thu, 26 Feb 2026 18:04:34 -0600 Subject: [PATCH] changes --- public/app.js | 3 ++- public/index.html | 5 +++++ server.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/public/app.js b/public/app.js index 4454b5b..ba79841 100644 --- a/public/app.js +++ b/public/app.js @@ -677,7 +677,7 @@ async function openInvoiceModal(invoiceId = null) { document.getElementById('invoice-terms').value = data.invoice.terms; document.getElementById('invoice-authorization').value = data.invoice.auth_code || ''; document.getElementById('invoice-tax-exempt').checked = data.invoice.tax_exempt; - + document.getElementById('invoice-bill-to-name').value = data.invoice.bill_to_name || ''; // Scheduled Send Date const sendDateEl = document.getElementById('invoice-send-date'); if (sendDateEl) { @@ -951,6 +951,7 @@ async function handleInvoiceSubmit(e) { auth_code: document.getElementById('invoice-authorization').value, tax_exempt: document.getElementById('invoice-tax-exempt').checked, scheduled_send_date: document.getElementById('invoice-send-date')?.value || null, + bill_to_name: document.getElementById('invoice-bill-to-name')?.value || null, items: getInvoiceItems() // Deine bestehende Funktion }; diff --git a/public/index.html b/public/index.html index fa4066a..8d40f41 100644 --- a/public/index.html +++ b/public/index.html @@ -430,6 +430,11 @@ +
+ + +
{ // 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) => { $${parseFloat(invoice.tax_amount).toFixed(2)} `; } + const amountPaid = parseFloat(invoice.amount_paid) || 0; + const balanceDue = parseFloat(invoice.total) - amountPaid; + itemsHTML += ` TOTAL: $${parseFloat(invoice.total).toFixed(2)} + `; + + if (amountPaid > 0) { + itemsHTML += ` + + Less: Payment received: + -$${amountPaid.toFixed(2)} + + BALANCE DUE: + $${balanceDue.toFixed(2)} + `; + } + + itemsHTML += ` Thank you for your business! `; @@ -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) => { $${parseFloat(invoice.tax_amount).toFixed(2)} `; } + const amountPaid = parseFloat(invoice.amount_paid) || 0; + const balanceDue = parseFloat(invoice.total) - amountPaid; + itemsHTML += ` TOTAL: $${parseFloat(invoice.total).toFixed(2)} + `; + + if (amountPaid > 0) { + itemsHTML += ` + + Less: Payment received: + -$${amountPaid.toFixed(2)} + + BALANCE DUE: + $${balanceDue.toFixed(2)} + `; + } + + itemsHTML += ` Thank you for your business! `;