Invoice - USA Security & Protection Group LLC

Date:

INVOICE # 100

PROTOS SECURITY

90 Town Center St. Suite 202

Daleville, VA 24083

866-403-9630

Payment Terms
Due Date
Generating PDF...

Client Address Information:

Hours Description Rate Line Total
Service Dates    
Subtotal
Sales Tax
Total
`; const rows = document.querySelectorAll("#invoiceTable tbody tr"); rows.forEach(row => { const hours = row.querySelector(".hours").value; const desc = row.querySelector(".desc").value; const rate = row.querySelector(".rate").value; const total = row.querySelector(".lineTotal").value; if (hours || desc || rate || total) { tableHTML += ``; } }); tableHTML += `
USA SECURITY & PROTECTION GROUP LLC
INVOICE #${document.getElementById("invoiceNumber").value}
Date${document.getElementById("currentDate").textContent}
CLIENT DETAILS
${document.getElementById("clientNameInput").value}
${document.getElementById("clientAddress1Input").value}
${document.getElementById("clientAddress2Input").value}
${document.getElementById("clientPhoneInput").value}
Payment Terms${document.getElementById("paymentTerms").value} Due Date${document.getElementById("dueDate").value}
Service Dates${document.getElementById("serviceDates").value}
HoursDescriptionRateLine Total
${hours}${desc}${rate}${total}
Subtotal${document.getElementById("subtotal").value}
Sales Tax${document.getElementById("salesTax").value}
Total${document.getElementById("total").value}
`; const dataType = 'application/vnd.ms-excel'; const tableSelect = encodeURIComponent(tableHTML); const downloadLink = document.createElement("a"); downloadLink.href = 'data:' + dataType + ', ' + tableSelect; downloadLink.download = 'Invoice_' + document.getElementById("invoiceNumber").value + '.xls'; document.body.appendChild(downloadLink); downloadLink.click(); document.body.removeChild(downloadLink); }; function formatRateAndCalc(input) { let val = input.value.replace(/[^0-9.]/g, ""); if (val && parseFloat(val) > 0) { input.value = formatCurrency(parseFloat(val)); } else { input.value = ""; } calcRow(input); } function calcRowWithoutFormat(input) { const tr = input.closest("tr"); const hours = parseFloat(tr.querySelector(".hours").value) || 0; const rateValue = input.value.replace(/[^0-9.]/g, ""); const rate = parseFloat(rateValue) || 0; const lineTotal = hours * rate; tr.querySelector(".lineTotal").value = lineTotal > 0 ? formatCurrency(lineTotal) : ""; updateTotals(); } function addRow(hours = "", desc = "", rate = "", total = "") { const tbody = document.querySelector("#invoiceTable tbody"); const tr = document.createElement("tr"); tr.innerHTML = ` `; tbody.appendChild(tr); } function removeRow(btn) { btn.closest("tr").remove(); updateTotals(); } function calcRow(input) { const tr = input.closest("tr"); const hours = parseFloat(tr.querySelector(".hours").value) || 0; const rateValue = tr.querySelector(".rate").value.replace(/[^0-9.]/g, ""); const rate = parseFloat(rateValue) || 0; const lineTotal = hours * rate; tr.querySelector(".lineTotal").value = lineTotal > 0 ? formatCurrency(lineTotal) : ""; updateTotals(); } function formatSalesTaxAndUpdate(input) { let val = input.value.replace(/[^0-9.]/g, ""); if (val && parseFloat(val) >= 0) { input.value = formatCurrency(parseFloat(val)); } else { input.value = "$0"; } updateTotals(); } function updateTotals() { let subtotal = 0; document.querySelectorAll(".lineTotal").forEach((input) => { const val = input.value.replace(/[^0-9.]/g, ""); subtotal += parseFloat(val) || 0; }); document.getElementById("subtotal").value = subtotal > 0 ? formatCurrency(subtotal) : ""; const salesTaxValue = document.getElementById("salesTax").value.replace(/[^0-9.]/g, ""); const salesTax = parseFloat(salesTaxValue) || 0; const total = subtotal + salesTax; document.getElementById("total").value = total > 0 ? formatCurrency(total) : ""; } // Add initial empty rows for (let i = 0; i < 20; i++) { addRow(); }