// Invoice Generator Utility // Generates invoice data and creates downloadable PDF export const generateInvoiceNumber = (count) => { return `INV-2026-${String(count + 1).padStart(6, '0')}`; }; export const createInvoiceData = (booking, photographer, customer) => { const subtotal = booking.totalPrice || 0; const taxRate = 18; // 18% GST const tax = (subtotal * taxRate) / 100; const totalAmount = subtotal + tax; const items = [ { description: `${photographer.firstName} ${photographer.lastName} - Photography Session`, quantity: 1, unitPrice: subtotal, total: subtotal, }, ]; return { issueDate: new Date(), dueDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), items, subtotal, tax, taxRate, totalAmount, photographerId: photographer._id, customerId: customer._id, bookingId: booking._id, }; }; export const formatInvoiceForDisplay = (invoice) => { return { ...invoice, issueDate: new Date(invoice.issueDate).toLocaleDateString('en-IN', { year: 'numeric', month: 'long', day: 'numeric', }), dueDate: new Date(invoice.dueDate).toLocaleDateString('en-IN', { year: 'numeric', month: 'long', day: 'numeric', }), }; }; // Simple text-based invoice template (can be extended with jsPDF for actual PDF) export const generateInvoiceHTML = (invoice, photographer, customer) => { const formatted = formatInvoiceForDisplay(invoice); return `
SnapLocal - Professional Photography Services
Invoice #: ${invoice.invoiceNumber}
Issue Date: ${formatted.issueDate}
Due Date: ${formatted.dueDate}
${photographer.firstName} ${photographer.lastName}
${photographer.bio || 'Professional Photographer'}
Email: ${photographer.email || 'N/A'}
${customer.firstName} ${customer.lastName}
Email: ${customer.email}
| Description | Quantity | Unit Price | Total |
|---|---|---|---|
| ${item.description} | ${item.quantity} | ₹${item.unitPrice.toFixed(2)} | ₹${item.total.toFixed(2)} |
| Subtotal: | ₹${invoice.subtotal.toFixed(2)} | ||
| Tax (${invoice.taxRate}%): | ₹${invoice.tax.toFixed(2)} | ||
| Discount: | -₹${invoice.discount.toFixed(2)} | ||
| TOTAL AMOUNT DUE: | ₹${invoice.totalAmount.toFixed(2)} | ||
Paid on ${new Date(invoice.paidAt).toLocaleDateString()}
` : '' }