Teacher training videos • Join competitions today!
Abacus Teacher Training
Videos
Vedic Maths Teacher Training
Videos
100 Level Challenge
Master Competition
International Abacus Competition
Global Challenge

Elementor #4734

📄 Invoice Generator

Apni company, customer aur item details bharein, phir "Generate Invoice" dabayein.

🏢 Your Company

No logo

📋 Invoice Details

👤 Bill To (Customer)

📦 Items

Item Qty Rate Amount

💰 Charges

💳 Payment Status

🧾 Invoice yahan dikhega

Left side mein details bharein aur "Generate Invoice" dabayein.

Your Company

INVOICE

No.
Date:

Bill To

Payment

Pay to:

ItemQtyRate (₹)Amount (₹)
Thank you! 🙏
'; } }; reader.readAsDataURL(file); }); } var clearLogoBtn = doc.getElementById('clearLogoBtn'); if (clearLogoBtn) { clearLogoBtn.addEventListener('click', function(){ logoDataUrl = null; if (logoInput) logoInput.value = ''; if (logoPreview) logoPreview.innerHTML = 'No logo'; }); } // Initial 3 rows var itemRows = doc.getElementById('itemRows'); if (itemRows) { // Clear any existing rows itemRows.innerHTML = ''; // Add 3 initial rows for (var i = 0; i < 3; i++) { addNewItem(); } } // Payment status toggle var paymentStatus = 'pending'; var payPendingBtn = doc.getElementById('payOptPending'); var payPaidBtn = doc.getElementById('payOptPaid'); function setPayStatus(status){ paymentStatus = status; if (payPendingBtn) payPendingBtn.classList.toggle('active', status === 'pending'); if (payPaidBtn) payPaidBtn.classList.toggle('active', status === 'paid'); } if (payPendingBtn) { payPendingBtn.addEventListener('click', function(){ setPayStatus('pending'); }); } if (payPaidBtn) { payPaidBtn.addEventListener('click', function(){ setPayStatus('paid'); }); } // Collect items from form function collectItems(){ if (!itemRows) return []; var rows = itemRows.querySelectorAll('tr'); var items = []; rows.forEach(function(tr){ var nameInput = tr.querySelector('.i-name'); var qtyInput = tr.querySelector('.i-qty'); var rateInput = tr.querySelector('.i-rate'); if (!nameInput || !qtyInput || !rateInput) return; var name = nameInput.value.trim(); var qty = parseFloat(qtyInput.value)||0; var rate = parseFloat(rateInput.value)||0; if(!name && qty===0 && rate===0) return; items.push({name: name || 'Item', qty: qty, rate: rate, amount: qty*rate}); }); return items; } function totalRow(label, value, cssClass){ return '
'+ label +''+ value +'
'; } // Generate Invoice function renderInvoice(){ var items = collectItems(); // Company var outCompanyName = doc.getElementById('outCompanyName'); var cName = doc.getElementById('cName'); if (outCompanyName && cName) outCompanyName.textContent = cName.value || 'Your Company'; var outCompanyMeta = doc.getElementById('outCompanyMeta'); var cAddress = doc.getElementById('cAddress'); var cPhone = doc.getElementById('cPhone'); var cGst = doc.getElementById('cGst'); if (outCompanyMeta) { var metaParts = []; if (cAddress && cAddress.value) metaParts.push(cAddress.value); if (cPhone && cPhone.value) metaParts.push('Ph: ' + cPhone.value); if (cGst && cGst.value) metaParts.push('GSTIN: ' + cGst.value); outCompanyMeta.textContent = metaParts.join('\n'); } // Logo var outLogoWrap = doc.getElementById('outLogoWrap'); if (outLogoWrap) { if(logoDataUrl){ outLogoWrap.innerHTML = '
'; } else { outLogoWrap.innerHTML = ''; } } // Invoice number & date var outInvoiceNo = doc.getElementById('outInvoiceNo'); var invNumber = doc.getElementById('invNumber'); if (outInvoiceNo && invNumber) outInvoiceNo.textContent = invNumber.value || '—'; var outInvoiceDate = doc.getElementById('outInvoiceDate'); var invDate = doc.getElementById('invDate'); if (outInvoiceDate && invDate) outInvoiceDate.textContent = formatDate(invDate.value) || '—'; // Customer var outCustName = doc.getElementById('outCustName'); var custName = doc.getElementById('custName'); if (outCustName && custName) outCustName.textContent = custName.value || 'Customer name'; var outCustAddress = doc.getElementById('outCustAddress'); var custAddress = doc.getElementById('custAddress'); if (outCustAddress && custAddress) outCustAddress.textContent = custAddress.value || ''; var outCustMobile = doc.getElementById('outCustMobile'); var custMobile = doc.getElementById('custMobile'); if (outCustMobile && custMobile) { var mobile = custMobile.value; outCustMobile.textContent = mobile ? ('Mobile: ' + mobile) : ''; } // Payment var outPaymentPending = doc.getElementById('outPaymentPending'); var outPaymentPaid = doc.getElementById('outPaymentPaid'); var outPayDetails = doc.getElementById('outPayDetails'); var cPay = doc.getElementById('cPay'); if (outPaymentPending && outPaymentPaid) { if(paymentStatus === 'paid'){ outPaymentPending.style.display = 'none'; outPaymentPaid.style.display = 'block'; } else { outPaymentPending.style.display = 'block'; outPaymentPaid.style.display = 'none'; if (outPayDetails && cPay) outPayDetails.textContent = cPay.value || '—'; } } // Items table var outItemsBody = doc.getElementById('outItemsBody'); if (outItemsBody) { outItemsBody.innerHTML = ''; if(items.length === 0){ outItemsBody.innerHTML = 'Koi item add nahi kiya gaya.'; } else { items.forEach(function(it){ var tr = document.createElement('tr'); tr.innerHTML = ''+ esc(it.name) +''+ ''+ it.qty +''+ ''+ money(it.rate) +''+ ''+ money(it.amount) +''; outItemsBody.appendChild(tr); }); } } // Totals var subtotal = items.reduce(function(s,it){ return s + it.amount; }, 0); var discountType = doc.getElementById('discountType'); var discountValue = doc.getElementById('discountValue'); var discountRaw = parseFloat(discountValue ? discountValue.value : 0)||0; var discountAmount = discountType && discountType.value === 'percent' ? subtotal * discountRaw / 100 : discountRaw; if(discountAmount > subtotal) discountAmount = subtotal; var taxable = subtotal - discountAmount; var gstType = doc.getElementById('gstType'); var gstValue = doc.getElementById('gstValue'); var gstRaw = parseFloat(gstValue ? gstValue.value : 0)||0; var gstAmount = gstType && gstType.value === 'percent' ? taxable * gstRaw / 100 : gstRaw; var courierValue = doc.getElementById('courierValue'); var courier = parseFloat(courierValue ? courierValue.value : 0)||0; var finalTotal = taxable + gstAmount + courier; var rows = ''; rows += totalRow('Subtotal', '₹' + money(subtotal)); if(discountAmount > 0){ var discLabel = 'Discount' + (discountType && discountType.value==='percent' ? ' ('+discountRaw+'%)' : ''); rows += totalRow(discLabel, '- ₹' + money(discountAmount)); } if(gstAmount > 0){ var gstLabel = 'GST' + (gstType && gstType.value==='percent' ? ' ('+gstRaw+'%)' : ''); rows += totalRow(gstLabel, '+ ₹' + money(gstAmount)); } rows += totalRow('Courier / Shipping', courier > 0 ? '₹' + money(courier) : 'FREE'); rows += '
Grand Total₹'+ money(finalTotal) +'
'; var outTotals = doc.getElementById('outTotals'); if (outTotals) outTotals.innerHTML = rows; // Footer var outFootNote = doc.getElementById('outFootNote'); var footNote = doc.getElementById('footNote'); if (outFootNote && footNote) outFootNote.textContent = footNote.value || ''; var emptyState = doc.getElementById('emptyState'); var invoice = doc.getElementById('invoice'); if (emptyState) emptyState.style.display = 'none'; if (invoice) invoice.classList.add('show'); } var generateBtn = doc.getElementById('generateBtn'); if (generateBtn) { generateBtn.addEventListener('click', renderInvoice); } // Reset var resetBtn = doc.getElementById('resetBtn'); if (resetBtn) { resetBtn.addEventListener('click', function(){ if(!confirm('Sab fields clear kar dein?')) return; doc.querySelectorAll('.panel input[type=text], .panel input[type=number], .panel textarea').forEach(function(el){ el.value=''; }); var itemRows = doc.getElementById('itemRows'); if (itemRows) { itemRows.innerHTML = ''; for (var i = 0; i < 3; i++) { addNewItem(); } } logoDataUrl = null; var logoInput = doc.getElementById('logoInput'); var logoPreview = doc.getElementById('logoPreview'); if (logoInput) logoInput.value = ''; if (logoPreview) logoPreview.innerHTML = 'No logo'; var invDate = doc.getElementById('invDate'); var invNumber = doc.getElementById('invNumber'); if (invDate) invDate.value = todayStr(); if (invNumber) invNumber.value = 'INV-' + Math.floor(1000+Math.random()*9000); setPayStatus('pending'); var invoice = doc.getElementById('invoice'); var emptyState = doc.getElementById('emptyState'); if (invoice) invoice.classList.remove('show'); if (emptyState) emptyState.style.display = 'block'; }); } // Print var printBtn = doc.getElementById('printBtn'); if (printBtn) { printBtn.addEventListener('click', function(){ window.print(); }); } // Download PDF var downloadPdfBtn = doc.getElementById('downloadPdfBtn'); if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', function(){ var invoiceEl = doc.getElementById('invoice'); var actionRow = doc.querySelector('.action-row'); var invNumber = doc.getElementById('invNumber'); var custName = doc.getElementById('custName'); var invNo = (invNumber ? invNumber.value : 'invoice').trim(); var custNameVal = (custName ? custName.value : '').trim(); var safeName = custNameVal ? custNameVal.replace(/[^a-zA-Z0-9\u0900-\u097F ]/g, '').trim().replace(/\s+/g, '_') : ''; var pdfFileName = safeName ? (invNo + '-' + safeName) : invNo; var btn = downloadPdfBtn; var originalLabel = btn.textContent; btn.textContent = '⏳ Preparing PDF…'; if (actionRow) actionRow.style.display = 'none'; window.scrollTo(0, 0); if (typeof html2pdf !== 'undefined') { html2pdf().set({ margin: 8, filename: pdfFileName + '.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, scrollX: 0, scrollY: 0, windowWidth: document.documentElement.scrollWidth }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } }).from(invoiceEl).save().then(function(){ if (actionRow) actionRow.style.display = 'flex'; btn.textContent = originalLabel; }).catch(function(err){ if (actionRow) actionRow.style.display = 'flex'; btn.textContent = originalLabel; alert('PDF banane mein dikkat aayi. Kripya "Print" button se Save-as-PDF try karein.'); console.error(err); }); } else { alert('html2pdf library not loaded. Please check your internet connection.'); if (actionRow) actionRow.style.display = 'flex'; btn.textContent = originalLabel; } }); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();
Join Our WhatsApp Channel
Scroll to Top