Freelance Creative Project Invoice Customizer

Freelance Creative Project Invoice Customizer

Freelance Creative Project Invoice Customizer

This is a live preview of your invoice. Use the other tabs to customize it.

Invoice

Bill To

Item Description Quantity Rate Total
Subtotal $0.00
Tax (0%) $0.00
Discount -$0.00
Total Due $0.00

Payment Details

Your Information

Client Information

Payment Details & Notes

Add Line Item

Current Items

No items added yet.

${item.qty} @ ${formatCurrency(item.rate)}

`; currentItemsList.appendChild(itemEl); }); document.querySelectorAll('.remove-item-btn').forEach(btn => { btn.addEventListener('click', handleRemoveItem); }); } function renderDashboard() { // Your Info document.getElementById('preview-your-name').textContent = invoiceData.yourInfo.name; document.getElementById('preview-your-address').innerHTML = invoiceData.yourInfo.address; document.getElementById('preview-your-email').textContent = invoiceData.yourInfo.email; document.getElementById('preview-your-phone').textContent = invoiceData.yourInfo.phone; // Client Info document.getElementById('preview-client-name').textContent = invoiceData.clientInfo.name; document.getElementById('preview-client-address').innerHTML = invoiceData.clientInfo.address; document.getElementById('preview-client-email').textContent = invoiceData.clientInfo.email; // Invoice Details document.getElementById('preview-invoice-id').textContent = `Invoice #${invoiceData.invoiceDetails.id}`; document.getElementById('preview-invoice-date').textContent = `Date: ${invoiceData.invoiceDetails.date}`; document.getElementById('preview-invoice-due').textContent = `Due: ${invoiceData.invoiceDetails.dueDate}`; // Payment Details document.getElementById('preview-payment-details').innerHTML = invoiceData.paymentDetails.bank; document.getElementById('preview-payment-note').innerHTML = invoiceData.paymentDetails.note; // Line Items previewItemTableBody.innerHTML = ''; let subtotal = 0; invoiceData.lineItems.forEach(item => { const total = item.qty * item.rate; subtotal += total; const row = ` ${item.desc} ${item.qty} ${formatCurrency(item.rate)} ${formatCurrency(total)} `; previewItemTableBody.innerHTML += row; }); // Summary const taxAmount = subtotal * (invoiceData.summary.taxRate / 100); const total = subtotal + taxAmount - invoiceData.summary.discount; document.getElementById('preview-subtotal').textContent = formatCurrency(subtotal); document.getElementById('preview-tax-label').textContent = `Tax (${invoiceData.summary.taxRate}%)`; document.getElementById('preview-tax-amount').textContent = formatCurrency(taxAmount); document.getElementById('preview-discount-amount').textContent = `-${formatCurrency(invoiceData.summary.discount)}`; document.getElementById('preview-total').textContent = formatCurrency(total); } function handleAddItem() { const desc = document.getElementById('item-desc').value; const qty = parseFloat(document.getElementById('item-qty').value); const rate = parseFloat(document.getElementById('item-rate').value); if (!desc || isNaN(qty) || isNaN(rate) || qty <= 0 || rate <= 0) { alert("Please enter a valid description, quantity, and rate."); return; } invoiceData.lineItems.push({ id: crypto.randomUUID(), desc, qty, rate }); document.getElementById('item-desc').value = ''; document.getElementById('item-qty').value = ''; document.getElementById('item-rate').value = ''; renderLineItemsList(); } function handleRemoveItem(e) { const itemId = e.target.getAttribute('data-item-id'); invoiceData.lineItems = invoiceData.lineItems.filter(item => item.id !== itemId); renderLineItemsList(); } async function generatePdf() { downloadPdfBtn.textContent = 'Generating...'; downloadPdfBtn.disabled = true; try { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const elementToCapture = document.getElementById('invoice-preview-pane'); const canvas = await html2canvas(elementToCapture, { scale: 2, useCORS: true, logging: false, backgroundColor: '#ffffff' }); const imgData = canvas.toDataURL('image/png'); const pdfWidth = doc.internal.pageSize.getWidth(); const pdfHeight = doc.internal.pageSize.getHeight(); const imgProps = doc.getImageProperties(imgData); const imgRatio = imgProps.height / imgProps.width; let finalImgWidth = pdfWidth; let finalImgHeight = pdfWidth * imgRatio; // If height is too large, scale based on height if (finalImgHeight > pdfHeight) { finalImgHeight = pdfHeight; finalImgWidth = finalImgHeight / imgRatio; } const x = (pdfWidth - finalImgWidth) / 2; const y = (pdfHeight - finalImgHeight) / 2; doc.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); doc.save(`Invoice-${invoiceData.invoiceDetails.id}.pdf`); } catch (error) { console.error("PDF generation failed:", error); alert("Could not generate PDF. Please try again."); } finally { downloadPdfBtn.textContent = 'Download Invoice as PDF'; downloadPdfBtn.disabled = false; } } // --- INITIALIZATION --- function initialize() { renderConfig(); renderLineItemsList(); renderDashboard(); switchTab(0); // Event Listeners tabs.forEach((tab, index) => tab.addEventListener('click', () => switchTab(index))); prevBtn.addEventListener('click', () => switchTab(currentTab - 1)); nextBtn.addEventListener('click', () => switchTab(currentTab + 1)); addItemBtn.addEventListener('click', handleAddItem); refreshDashboardBtn.addEventListener('click', handleRefreshDashboard); downloadPdfBtn.addEventListener('click', generatePdf); } initialize(); });
Scroll to Top