document.addEventListener('DOMContentLoaded', function() { let itemCount = 0; const itemsTable = document.getElementById('itemsTable'); // Load saved "From" details if they exist const savedFromDetails = JSON.parse(localStorage.getItem('fromDetails')) || {}; if (savedFromDetails.businessName) { document.querySelector('input[placeholder="Your Business Name"]').value = savedFromDetails.businessName; } if (savedFromDetails.address) { document.querySelector('input[placeholder="Address"]').value = savedFromDetails.address; } if (savedFromDetails.cityStateZip) { document.querySelector('input[placeholder="City, State, ZIP"]').value = savedFromDetails.cityStateZip; } if (savedFromDetails.email) { document.querySelector('input[placeholder="Email"]').value = savedFromDetails.email; } if (savedFromDetails.phone) { document.querySelector('input[placeholder="Phone"]').value = savedFromDetails.phone; } // Save "From" details when they change const fromInputs = document.querySelectorAll('input[placeholder^="Your"]'); fromInputs.forEach(input => { input.addEventListener('change', () => { const fromDetails = { businessName: document.querySelector('input[placeholder="Your Business Name"]').value, address: document.querySelector('input[placeholder="Address"]').value, cityStateZip: document.querySelector('input[placeholder="City, State, ZIP"]').value, email: document.querySelector('input[placeholder="Email"]').value, phone: document.querySelector('input[placeholder="Phone"]').value }; localStorage.setItem('fromDetails', JSON.stringify(fromDetails)); }); }); const addItemBtn = document.getElementById('addItemBtn'); const generateBtn = document.getElementById('generateBtn'); const closeModalBtn = document.getElementById('closeModalBtn'); const printBtn = document.getElementById('printBtn'); const downloadBtn = document.getElementById('downloadBtn'); const invoiceModal = document.getElementById('invoiceModal'); const invoiceContent = document.getElementById('invoiceContent'); const taxRateInput = document.getElementById('taxRate'); // Add new item row addItemBtn.addEventListener('click', addItemRow); // Generate invoice generateBtn.addEventListener('click', generateInvoice); // Close modal closeModalBtn.addEventListener('click', () => { invoiceModal.classList.add('hidden'); }); // Print invoice printBtn.addEventListener('click', () => { window.print(); }); // Download as PDF (placeholder functionality) downloadBtn.addEventListener('click', () => { alert('PDF download functionality would be implemented here with a library like jsPDF'); }); // Recalculate totals when tax rate changes taxRateInput.addEventListener('change', calculateTotals); // Add initial item row addItemRow(); function addItemRow() { itemCount++; const row = document.createElement('tr'); row.className = 'item-row'; row.innerHTML = `
${fromAddress}
${fromCityStateZip}
${fromEmail}
${fromPhone}
Date: ${invoiceDate}
Invoice #: ${invoiceNumber}
${toName}
${toAddress}
${toCityStateZip}
${toEmail}
${toPhone}
| Description | Qty | Unit Price | Amount |
|---|
Thank you for your business!
Please make payment within 30 days