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 += `
`;
+
+ if (amountPaid > 0) {
+ itemsHTML += `
+
+ `;
+ }
+
+ itemsHTML += `
`;
@@ -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 += `
`;
+
+ if (amountPaid > 0) {
+ itemsHTML += `
+
+ `;
+ }
+
+ itemsHTML += `
`;