feat: add config-driven jsPDF invoice renderer with all header and table styles
This commit is contained in:
37
src/utils/invoicePdf.ts
Normal file
37
src/utils/invoicePdf.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { jsPDF } from 'jspdf'
|
||||||
|
import type { Invoice } from '../stores/invoices'
|
||||||
|
import type { Client } from '../stores/clients'
|
||||||
|
import { renderInvoicePdf, type BusinessInfo } from './invoicePdfRenderer'
|
||||||
|
import { getTemplateById } from './invoiceTemplates'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice item interface for line items on the invoice
|
||||||
|
*/
|
||||||
|
export interface InvoiceItem {
|
||||||
|
id?: number
|
||||||
|
description: string
|
||||||
|
quantity: number
|
||||||
|
rate: number
|
||||||
|
amount: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a PDF invoice using a template
|
||||||
|
* @param invoice - The invoice data
|
||||||
|
* @param client - The client data
|
||||||
|
* @param items - The invoice line items
|
||||||
|
* @param templateId - Template ID to use (defaults to 'clean-minimal')
|
||||||
|
* @param businessInfo - Optional business identity info
|
||||||
|
* @returns The generated jsPDF document
|
||||||
|
*/
|
||||||
|
export function generateInvoicePdf(
|
||||||
|
invoice: Invoice,
|
||||||
|
client: Client,
|
||||||
|
items: InvoiceItem[],
|
||||||
|
templateId: string = 'clean-minimal',
|
||||||
|
businessInfo?: BusinessInfo,
|
||||||
|
): jsPDF {
|
||||||
|
const config = getTemplateById(templateId)
|
||||||
|
const info: BusinessInfo = businessInfo || { name: '', address: '', email: '', phone: '', logo: '' }
|
||||||
|
return renderInvoicePdf(config, invoice, client, items, info)
|
||||||
|
}
|
||||||
1121
src/utils/invoicePdfRenderer.ts
Normal file
1121
src/utils/invoicePdfRenderer.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user