Custom Payment Invoice Generator

Custom Payment Invoice Generator

Design and generate professional invoices for your clients.

${appData.from.address}

${appData.from.email}

To

${appData.to.name}

${appData.to.address}

${appData.to.email}

Issue Date

${appData.details.issueDate}

Due Date

${appData.details.dueDate}

${lineItemsHtml}
Description Qty Unit Price Total
Subtotal:${formatCurrency(subtotal)}
Discount (${appData.totals.discountType === 'percent' ? appData.totals.discountValue+'%' : formatCurrency(appData.totals.discountValue)}):-${formatCurrency(discountAmount)}
Tax (${appData.totals.taxRate}%):${formatCurrency(taxAmount)}
Total Due:${formatCurrency(total)}

Notes

${appData.notes}

`; document.getElementById('download-pdf-btn').addEventListener('click', generatePdf); }; const renderDataConfig = () => { const configContent = document.getElementById('content-data-configuration'); if(!configContent) return; const itemsHtml = appData.items.map(item => `
`).join(''); configContent.innerHTML = `
Your Information (From)
Client Information (To)
Invoice Details
Line Items
${itemsHtml}
Notes & Totals
`; lucide.createIcons(); attachConfigListeners(); }; // --- EVENT HANDLERS & LOGIC --- const attachConfigListeners = () => { const handler = () => { document.querySelectorAll('.config-input').forEach(input => { const path = input.dataset.path.split('.'); let current = appData; path.slice(0, -1).forEach(key => current = current[key]); current[path[path.length - 1]] = input.value; }); document.querySelectorAll('.item-input').forEach(input => { const id = parseInt(input.dataset.id); const field = input.dataset.field; const value = input.type === 'number' ? parseFloat(input.value) || 0 : input.value; const item = appData.items.find(i => i.id === id); if(item) item[field] = value; }); renderDashboard(); }; document.querySelectorAll('.config-input, .item-input').forEach(input => input.addEventListener('input', handler)); document.querySelectorAll('.remove-item-btn').forEach(btn => btn.addEventListener('click', e => { const id = parseInt(e.currentTarget.dataset.id); appData.items = appData.items.filter(i => i.id !== id); renderDataConfig(); renderDashboard(); })); document.getElementById('add-item-btn').addEventListener('click', () => { const newId = appData.items.length > 0 ? Math.max(...appData.items.map(i => i.id)) + 1 : 1; appData.items.push({ id: newId, description: 'New Item', quantity: 1, unitPrice: 0 }); renderDataConfig(); }); }; const generatePdf = () => { loadingOverlay.style.display = 'flex'; const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content-area'); html2canvas(pdfContent, { scale: 2, useCORS: true, logging: false, windowWidth: 1000 }) .then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, imgHeight); pdf.save(`Invoice-${appData.details.invoiceNumber}.pdf`); loadingOverlay.style.display = 'none'; }).catch(err => { console.error("PDF generation failed:", err); loadingOverlay.style.display = 'none'; alert('An error occurred generating the PDF.'); }); }; // --- TAB NAVIGATION & INITIALIZATION --- const switchTab = (tabIndex) => { activeTabIndex = tabIndex; document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex)); document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex)); updateNavButtons(); }; const updateNavButtons = () => { prevTabBtn.disabled = activeTabIndex === 0; nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1; }; const initializeUI = () => { const tabs = [ { name: 'Invoice Dashboard', id: 'invoice-dashboard' }, { name: 'Data Configuration', id: 'data-configuration' } ]; tabIdentifiers = tabs.map(t => t.id); tabsContainer.innerHTML = tabs.map(tab => ``).join(''); mainContent.innerHTML = tabs.map(tab => `
`).join(''); tabs.forEach((tab, index) => { document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index)); }); renderDashboard(); renderDataConfig(); switchTab(0); }; initializeUI(); prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); }); });
Scroll to Top