| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Business Invoice Generator</title> |
| <script src="https://cdn.tailwindcss.com"></script> |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script> |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> |
| <style> |
| @keyframes fadeIn { |
| from { opacity: 0; transform: translateY(10px); } |
| to { opacity: 1; transform: translateY(0); } |
| } |
| |
| .invoice-item:last-child { |
| border-bottom: none; |
| } |
| |
| .modal { |
| animation: fadeIn 0.3s ease-out; |
| } |
| |
| #invoice-preview { |
| background-color: white; |
| color: black; |
| box-shadow: 0 0 20px rgba(0,0,0,0.1); |
| } |
| |
| #logo-preview { |
| max-width: 150px; |
| max-height: 80px; |
| object-fit: contain; |
| } |
| |
| .logo-upload-container { |
| border: 2px dashed #d1d5db; |
| border-radius: 0.5rem; |
| padding: 1rem; |
| text-align: center; |
| cursor: pointer; |
| transition: all 0.3s; |
| } |
| |
| .logo-upload-container:hover { |
| border-color: #3b82f6; |
| background-color: #f8fafc; |
| } |
| </style> |
| </head> |
| <body class="bg-gray-100 min-h-screen"> |
| <div class="container mx-auto px-4 py-8"> |
| <div class="flex justify-between items-center mb-8"> |
| <div class="flex items-center"> |
| <h1 class="text-3xl font-bold text-gray-800"> |
| <i class="fas fa-file-invoice-dollar mr-2 text-blue-600"></i> |
| Invoice Generator |
| </h1> |
| <button id="theme-toggle" type="button" class="ml-4 p-2 rounded-full bg-gray-200 text-gray-700"> |
| <i id="theme-icon" class="fas fa-moon"></i> |
| </button> |
| </div> |
| <button id="preview-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg transition flex items-center"> |
| <i class="fas fa-eye mr-2"></i> Preview Invoice |
| </button> |
| </div> |
| |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-6"> |
| |
| <div class="lg:col-span-2 bg-white rounded-xl shadow-md p-6"> |
| <h2 class="text-xl font-semibold mb-4 text-gray-800">Invoice Details</h2> |
| |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6"> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Invoice Number</label> |
| <input type="text" id="invoice-number" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="INV-0001"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Date</label> |
| <input type="date" id="invoice-date" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Due Date</label> |
| <input type="date" id="due-date" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Currency</label> |
| <select id="currency" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> |
| <option value="TSh">Tanzania (TSh)</option> |
| <option value="KSh">Kenya (KSh)</option> |
| <option value="USh">Uganda (USh)</option> |
| <option value="RF">Rwanda (RF)</option> |
| <option value="FBu">Burundi (FBu)</option> |
| <option value="$">USD ($)</option> |
| <option value="€">EUR (€)</option> |
| <option value="£">GBP (£)</option> |
| </select> |
| </div> |
| </div> |
| |
| |
| <div class="mb-6"> |
| <label class="block text-sm font-medium text-gray-700 mb-2">Company Logo</label> |
| <div id="logo-upload" class="logo-upload-container"> |
| <div id="logo-upload-placeholder" class="flex flex-col items-center justify-center"> |
| <i class="fas fa-image text-3xl text-gray-400 mb-2"></i> |
| <p class="text-sm text-gray-500">Click to upload logo</p> |
| <p class="text-xs text-gray-400">(Recommended: 300x100px)</p> |
| </div> |
| <img id="logo-preview" class="hidden mx-auto mb-2" alt="Logo Preview"> |
| <input type="file" id="logo-input" accept="image/*" class="hidden"> |
| </div> |
| <button id="remove-logo-btn" class="mt-2 text-sm text-red-600 hover:text-red-800 hidden"> |
| <i class="fas fa-trash mr-1"></i> Remove Logo |
| </button> |
| </div> |
| |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6"> |
| |
| <div> |
| <h3 class="text-lg font-medium mb-2 text-gray-800 flex items-center"> |
| <i class="fas fa-building mr-2 text-blue-600"></i> From |
| </h3> |
| <div class="space-y-3"> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Business Name</label> |
| <input type="text" id="from-name" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="Your Company Name"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Email</label> |
| <input type="email" id="from-email" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="contact@yourcompany.com"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Phone</label> |
| <input type="text" id="from-phone" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="+255 123 456 789"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Address</label> |
| <textarea id="from-address" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">123 Business St, Dar es Salaam |
| Tanzania</textarea> |
| </div> |
| </div> |
| </div> |
| |
| |
| <div> |
| <h3 class="text-lg font-medium mb-2 text-gray-800 flex items-center"> |
| <i class="fas fa-user-tie mr-2 text-blue-600"></i> To |
| </h3> |
| <div class="space-y-3"> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Client Name</label> |
| <input type="text" id="to-name" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="Client Name"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Email</label> |
| <input type="email" id="to-email" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="client@example.com"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Phone</label> |
| <input type="text" id="to-phone" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" value="+255 987 654 321"> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Address</label> |
| <textarea id="to-address" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">456 Client Ave, Dar es Salaam |
| Tanzania</textarea> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| |
| <div class="mb-6"> |
| <div class="flex justify-between items-center mb-4"> |
| <h3 class="text-lg font-medium text-gray-800 flex items-center"> |
| <i class="fas fa-list-ul mr-2 text-blue-600"></i> Items |
| </h3> |
| <button id="add-item-btn" class="bg-green-600 hover:bg-green-700 text-white font-medium py-1 px-3 rounded-md text-sm transition flex items-center"> |
| <i class="fas fa-plus mr-1"></i> Add Item |
| </button> |
| </div> |
| |
| <div id="invoice-items" class="space-y-4"> |
| |
| </div> |
| |
| <div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-4"> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label> |
| <textarea id="notes" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">Thank you for your business!</textarea> |
| </div> |
| <div> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Terms</label> |
| <textarea id="terms" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">Payment due within 15 days. Late payments subject to 5% fee.</textarea> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| |
| <div class="lg:col-span-1"> |
| <div class="bg-white rounded-xl shadow-md p-6 sticky top-6"> |
| <h2 class="text-xl font-semibold mb-4 text-gray-800">Invoice Summary</h2> |
| |
| <div class="space-y-4"> |
| <div class="flex justify-between"> |
| <span class="text-gray-600">Subtotal:</span> |
| <span id="subtotal" class="font-medium">0.00</span> |
| </div> |
| <div class="flex justify-between"> |
| <span class="text-gray-600">Tax (%):</span> |
| <div class="flex items-center"> |
| <input type="number" id="tax-rate" min="0" max="100" value="18" class="w-16 px-2 py-1 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> |
| <span class="ml-2">%</span> |
| </div> |
| </div> |
| <div class="flex justify-between"> |
| <span class="text-gray-600">Tax Amount:</span> |
| <span id="tax-amount" class="font-medium">0.00</span> |
| </div> |
| <div class="border-t border-gray-200 pt-2"> |
| <div class="flex justify-between font-bold text-lg"> |
| <span>Total:</span> |
| <span id="total" class="text-blue-600">0.00</span> |
| </div> |
| </div> |
| </div> |
| |
| <div class="mt-6 space-y-3"> |
| <button id="download-pdf-btn" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition flex items-center justify-center"> |
| <i class="fas fa-file-pdf mr-2"></i> Download PDF |
| </button> |
| <button id="download-png-btn" class="w-full bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-4 rounded-md transition flex items-center justify-center"> |
| <i class="fas fa-image mr-2"></i> Download PNG |
| </button> |
| <button id="copy-link-btn" class="w-full bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-4 rounded-md transition flex items-center justify-center"> |
| <i class="fas fa-link mr-2"></i> Copy Share Link |
| </button> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| |
| <div id="preview-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> |
| <div class="bg-white rounded-xl shadow-xl max-w-4xl w-full max-h-[90vh] overflow-auto"> |
| <div class="flex justify-between items-center border-b border-gray-200 p-4"> |
| <h3 class="text-xl font-semibold text-gray-800">Invoice Preview</h3> |
| <button id="close-preview-btn" class="text-gray-500 hover:text-gray-700"> |
| <i class="fas fa-times"></i> |
| </button> |
| </div> |
| <div class="p-6"> |
| <div id="invoice-preview" class="p-8 mx-auto"> |
| |
| </div> |
| </div> |
| <div class="border-t border-gray-200 p-4 flex justify-end"> |
| <button id="download-from-preview-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-md transition flex items-center"> |
| <i class="fas fa-download mr-2"></i> Download |
| </button> |
| </div> |
| </div> |
| </div> |
| |
| <script> |
| |
| document.addEventListener('DOMContentLoaded', function() { |
| const today = new Date().toISOString().split('T')[0]; |
| document.getElementById('invoice-date').value = today; |
| |
| |
| const dueDate = new Date(); |
| dueDate.setDate(dueDate.getDate() + 15); |
| document.getElementById('due-date').value = dueDate.toISOString().split('T')[0]; |
| |
| |
| addInvoiceItem(); |
| |
| |
| const themeToggle = document.getElementById('theme-toggle'); |
| const themeIcon = document.getElementById('theme-icon'); |
| |
| themeToggle.addEventListener('click', function() { |
| document.documentElement.classList.toggle('dark'); |
| |
| if (document.documentElement.classList.contains('dark')) { |
| themeIcon.classList.remove('fa-moon'); |
| themeIcon.classList.add('fa-sun'); |
| localStorage.setItem('theme', 'dark'); |
| } else { |
| themeIcon.classList.remove('fa-sun'); |
| themeIcon.classList.add('fa-moon'); |
| localStorage.setItem('theme', 'light'); |
| } |
| }); |
| |
| |
| if (localStorage.getItem('theme') === 'dark') { |
| document.documentElement.classList.add('dark'); |
| themeIcon.classList.remove('fa-moon'); |
| themeIcon.classList.add('fa-sun'); |
| } |
| |
| |
| const logoUpload = document.getElementById('logo-upload'); |
| const logoInput = document.getElementById('logo-input'); |
| const logoPreview = document.getElementById('logo-preview'); |
| const logoPlaceholder = document.getElementById('logo-upload-placeholder'); |
| const removeLogoBtn = document.getElementById('remove-logo-btn'); |
| |
| logoUpload.addEventListener('click', function() { |
| logoInput.click(); |
| }); |
| |
| logoInput.addEventListener('change', function(e) { |
| if (e.target.files.length) { |
| const reader = new FileReader(); |
| reader.onload = function(event) { |
| logoPreview.src = event.target.result; |
| logoPreview.classList.remove('hidden'); |
| logoPlaceholder.classList.add('hidden'); |
| removeLogoBtn.classList.remove('hidden'); |
| }; |
| reader.readAsDataURL(e.target.files[0]); |
| } |
| }); |
| |
| removeLogoBtn.addEventListener('click', function(e) { |
| e.stopPropagation(); |
| logoPreview.src = ''; |
| logoPreview.classList.add('hidden'); |
| logoPlaceholder.classList.remove('hidden'); |
| removeLogoBtn.classList.add('hidden'); |
| logoInput.value = ''; |
| }); |
| |
| |
| const previewBtn = document.getElementById('preview-btn'); |
| const previewModal = document.getElementById('preview-modal'); |
| const closePreviewBtn = document.getElementById('close-preview-btn'); |
| |
| previewBtn.addEventListener('click', function() { |
| renderInvoicePreview(); |
| previewModal.classList.remove('hidden'); |
| }); |
| |
| closePreviewBtn.addEventListener('click', function() { |
| previewModal.classList.add('hidden'); |
| }); |
| |
| |
| previewModal.addEventListener('click', function(e) { |
| if (e.target === previewModal) { |
| previewModal.classList.add('hidden'); |
| } |
| }); |
| |
| |
| const downloadPdfBtn = document.getElementById('download-pdf-btn'); |
| const downloadPngBtn = document.getElementById('download-png-btn'); |
| const downloadFromPreviewBtn = document.getElementById('download-from-preview-btn'); |
| |
| downloadPdfBtn.addEventListener('click', generatePdf); |
| downloadPngBtn.addEventListener('click', generatePng); |
| downloadFromPreviewBtn.addEventListener('click', generatePdf); |
| |
| |
| document.getElementById('copy-link-btn').addEventListener('click', function() { |
| |
| alert('Share link copied to clipboard!'); |
| }); |
| }); |
| |
| |
| function getInvoiceItemTemplate(index = 0) { |
| return ` |
| <div class="invoice-item bg-gray-50 p-4 rounded-lg border border-gray-200" data-index="${index}"> |
| <div class="grid grid-cols-12 gap-3"> |
| <div class="col-span-12 md:col-span-5"> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Description</label> |
| <input type="text" class="item-description w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Item description"> |
| </div> |
| <div class="col-span-6 md:col-span-2"> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Quantity</label> |
| <input type="number" min="1" value="1" class="item-quantity w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> |
| </div> |
| <div class="col-span-6 md:col-span-2"> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Price</label> |
| <input type="number" min="0" step="0.01" value="0.00" class="item-price w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> |
| </div> |
| <div class="col-span-9 md:col-span-2"> |
| <label class="block text-sm font-medium text-gray-700 mb-1">Amount</label> |
| <input type="text" class="item-amount w-full px-3 py-2 border border-gray-300 rounded-md bg-gray-100 font-medium" readonly> |
| </div> |
| <div class="col-span-3 md:col-span-1 flex items-end"> |
| <button class="remove-item-btn w-full py-2 text-red-600 hover:text-red-800"> |
| <i class="fas fa-trash"></i> |
| </button> |
| </div> |
| </div> |
| </div> |
| `; |
| } |
| |
| |
| function addInvoiceItem() { |
| const itemsContainer = document.getElementById('invoice-items'); |
| const index = itemsContainer.children.length; |
| const itemTemplate = getInvoiceItemTemplate(index); |
| |
| itemsContainer.insertAdjacentHTML('beforeend', itemTemplate); |
| |
| |
| const newItem = itemsContainer.lastElementChild; |
| const quantityInput = newItem.querySelector('.item-quantity'); |
| const priceInput = newItem.querySelector('.item-price'); |
| const amountInput = newItem.querySelector('.item-amount'); |
| const removeBtn = newItem.querySelector('.remove-item-btn'); |
| |
| quantityInput.addEventListener('input', calculateItemAmount); |
| priceInput.addEventListener('input', calculateItemAmount); |
| |
| removeBtn.addEventListener('click', function() { |
| newItem.remove(); |
| calculateInvoiceTotal(); |
| }); |
| |
| |
| calculateItemAmount.call(quantityInput); |
| } |
| |
| |
| function calculateItemAmount() { |
| const item = this.closest('.invoice-item'); |
| const quantity = parseFloat(item.querySelector('.item-quantity').value) || 0; |
| const price = parseFloat(item.querySelector('.item-price').value) || 0; |
| const amount = quantity * price; |
| |
| item.querySelector('.item-amount').value = amount.toFixed(2); |
| calculateInvoiceTotal(); |
| } |
| |
| |
| function calculateInvoiceTotal() { |
| const items = document.querySelectorAll('.invoice-item'); |
| let subtotal = 0; |
| |
| items.forEach(item => { |
| const amount = parseFloat(item.querySelector('.item-amount').value) || 0; |
| subtotal += amount; |
| }); |
| |
| const taxRate = parseFloat(document.getElementById('tax-rate').value) || 0; |
| const taxAmount = subtotal * (taxRate / 100); |
| const total = subtotal + taxAmount; |
| |
| document.getElementById('subtotal').textContent = subtotal.toFixed(2); |
| document.getElementById('tax-amount').textContent = taxAmount.toFixed(2); |
| document.getElementById('total').textContent = total.toFixed(2); |
| } |
| |
| |
| document.getElementById('add-item-btn').addEventListener('click', addInvoiceItem); |
| |
| |
| document.getElementById('tax-rate').addEventListener('input', calculateInvoiceTotal); |
| |
| |
| function renderInvoicePreview() { |
| const previewContainer = document.getElementById('invoice-preview'); |
| const currency = document.getElementById('currency').value; |
| const invoiceNumber = document.getElementById('invoice-number').value; |
| const invoiceDate = document.getElementById('invoice-date').value; |
| const dueDate = document.getElementById('due-date').value; |
| const fromName = document.getElementById('from-name').value; |
| const fromEmail = document.getElementById('from-email').value; |
| const fromPhone = document.getElementById('from-phone').value; |
| const fromAddress = document.getElementById('from-address').value; |
| const toName = document.getElementById('to-name').value; |
| const toEmail = document.getElementById('to-email').value; |
| const toPhone = document.getElementById('to-phone').value; |
| const toAddress = document.getElementById('to-address').value; |
| const notes = document.getElementById('notes').value; |
| const terms = document.getElementById('terms').value; |
| const subtotal = document.getElementById('subtotal').textContent; |
| const taxAmount = document.getElementById('tax-amount').textContent; |
| const total = document.getElementById('total').textContent; |
| const taxRate = document.getElementById('tax-rate').value; |
| |
| |
| const formattedInvoiceDate = formatDate(invoiceDate); |
| const formattedDueDate = formatDate(dueDate); |
| |
| |
| let itemsHtml = ''; |
| document.querySelectorAll('.invoice-item').forEach(item => { |
| const description = item.querySelector('.item-description').value; |
| const quantity = item.querySelector('.item-quantity').value; |
| const price = parseFloat(item.querySelector('.item-price').value).toFixed(2); |
| const amount = item.querySelector('.item-amount').value; |
| |
| itemsHtml += ` |
| <tr class="border-b border-gray-200"> |
| <td class="py-3 px-2">${description || 'No description'}</td> |
| <td class="py-3 px-2 text-right">${quantity}</td> |
| <td class="py-3 px-2 text-right">${currency} ${price}</td> |
| <td class="py-3 px-2 text-right">${currency} ${amount}</td> |
| </tr> |
| `; |
| }); |
| |
| |
| const logoPreview = document.getElementById('logo-preview'); |
| let logoHtml = ''; |
| if (!logoPreview.classList.contains('hidden')) { |
| logoHtml = `<img src="${logoPreview.src}" alt="Company Logo" class="h-16">`; |
| } |
| |
| |
| previewContainer.innerHTML = ` |
| <div class="max-w-4xl mx-auto"> |
| <div class="flex justify-between items-start mb-8"> |
| <div> |
| ${logoHtml} |
| <h1 class="text-3xl font-bold text-gray-800 mt-4">INVOICE</h1> |
| </div> |
| <div class="text-right"> |
| <p class="text-lg font-semibold">${fromName}</p> |
| <p class="text-sm text-gray-600">${fromAddress.replace(/\n/g, '<br>')}</p> |
| <p class="text-sm text-gray-600 mt-2">${fromEmail}</p> |
| <p class="text-sm text-gray-600">${fromPhone}</p> |
| </div> |
| </div> |
| |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-8"> |
| <div> |
| <h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Bill To</h2> |
| <p class="font-medium">${toName}</p> |
| <p class="text-sm text-gray-600">${toAddress.replace(/\n/g, '<br>')}</p> |
| <p class="text-sm text-gray-600 mt-2">${toEmail}</p> |
| <p class="text-sm text-gray-600">${toPhone}</p> |
| </div> |
| <div> |
| <div class="grid grid-cols-2 gap-4"> |
| <div> |
| <h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Invoice #</h2> |
| <p>${invoiceNumber}</p> |
| </div> |
| <div> |
| <h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Date</h2> |
| <p>${formattedInvoiceDate}</p> |
| </div> |
| <div> |
| <h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Due Date</h2> |
| <p>${formattedDueDate}</p> |
| </div> |
| <div> |
| <h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Currency</h2> |
| <p>${currency}</p> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <div class="mb-8"> |
| <table class="w-full"> |
| <thead> |
| <tr class="border-b border-gray-200 text-left"> |
| <th class="py-2 px-2 font-semibold">Description</th> |
| <th class="py-2 px-2 font-semibold text-right">Qty</th> |
| <th class="py-2 px-2 font-semibold text-right">Price</th> |
| <th class="py-2 px-2 font-semibold text-right">Amount</th> |
| </tr> |
| </thead> |
| <tbody> |
| ${itemsHtml} |
| </tbody> |
| </table> |
| </div> |
| |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-8"> |
| <div> |
| <h2 class="text-sm font-semibold text-gray-500 uppercase mb-2">Notes</h2> |
| <p class="text-gray-600">${notes}</p> |
| |
| <h2 class="text-sm font-semibold text-gray-500 uppercase mb-2 mt-4">Terms</h2> |
| <p class="text-gray-600">${terms}</p> |
| </div> |
| <div> |
| <div class="ml-auto max-w-xs"> |
| <div class="flex justify-between py-2"> |
| <span class="text-gray-600">Subtotal:</span> |
| <span class="font-medium">${currency} ${subtotal}</span> |
| </div> |
| <div class="flex justify-between py-2"> |
| <span class="text-gray-600">Tax (${taxRate}%):</span> |
| <span class="font-medium">${currency} ${taxAmount}</span> |
| </div> |
| <div class="flex justify-between py-2 border-t border-gray-200 font-bold text-lg"> |
| <span>Total:</span> |
| <span>${currency} ${total}</span> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| `; |
| } |
| |
| |
| function formatDate(dateString) { |
| if (!dateString) return ''; |
| |
| const options = { year: 'numeric', month: 'short', day: 'numeric' }; |
| const date = new Date(dateString); |
| return date.toLocaleDateString('en-US', options); |
| } |
| |
| |
| function generatePdf() { |
| const { jsPDF } = window.jspdf; |
| const doc = new jsPDF('p', 'pt', 'a4'); |
| const preview = document.getElementById('invoice-preview'); |
| |
| html2canvas(preview, { |
| scale: 2, |
| logging: false, |
| useCORS: true |
| }).then(canvas => { |
| const imgData = canvas.toDataURL('image/png'); |
| const imgWidth = doc.internal.pageSize.getWidth() - 40; |
| const imgHeight = (canvas.height * imgWidth) / canvas.width; |
| |
| doc.addImage(imgData, 'PNG', 20, 20, imgWidth, imgHeight); |
| |
| |
| const invoiceNumber = document.getElementById('invoice-number').value || 'invoice'; |
| doc.save(`${invoiceNumber}.pdf`); |
| }); |
| } |
| |
| |
| function generatePng() { |
| const preview = document.getElementById('invoice-preview'); |
| |
| html2canvas(preview, { |
| scale: 2, |
| logging: false, |
| useCORS: true |
| }).then(canvas => { |
| const link = document.createElement('a'); |
| link.download = `${document.getElementById('invoice-number').value || 'invoice'}.png`; |
| link.href = canvas.toDataURL('image/png'); |
| link.click(); |
| }); |
| } |
| </script> |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=THEMONEYHOLLIC/invoice-generator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> |
| </html> |