feat: format ABN for consistency, enhance invoice data structure, and add contact email to invoice

This commit is contained in:
Astrian Zheng 2025-01-12 10:45:54 +11:00
parent daab8ec07d
commit feee4184a4
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -51,19 +51,23 @@ export default async (prisma: PrismaClient, payerId: number, period: Date[], ite
// 写入数据
console.log(payerInfo.address.split('\n')[0])
const formatAbn = (abn: string) => {
return abn.replace(/(\d{2})(\d{3})(\d{3})(\d{3})/, '$1 $2 $3 $4')
}
const data = {
invoiceNumber: invoiceNumber,
invoiceDate: dayjs(newInvoice.issueTime).format('D, MMMM YYYY'),
payee: JSON.parse(process.env.PAYEE_JSON || '{}') || {
name: 'Payee Name',
address: ['Payee Address Line 1', 'Payee Address Line 2'],
abn: '12345678901'
abn: formatAbn('12345678901')
},
payer: {
name: payerInfo.name,
address_line_one: payerInfo.address.split('\n')[0],
address_line_two: payerInfo.address.split('\n')[1],
abn: payerInfo.abn
abn: payerInfo.abn ? formatAbn(payerInfo.abn) : undefined
},
billingPeriod: {
start: dayjs(period[0]).format('D, MMMM YYYY'),
@ -74,19 +78,20 @@ export default async (prisma: PrismaClient, payerId: number, period: Date[], ite
items: items.map(item => {
return {
description: item.description,
quantity: item.quantity,
unit: item.unit,
rate: `\$${(item.unitPrice ?? 0).toFixed(2)}`,
amount: `\$${(item.getSubtotal() ?? 0).toFixed(2)}`
amount: item.quantity,
total: `\$${item.getSubtotal().toFixed(2)}`
}
}),
subtotal: `\$${newInvoice.getTotal().toFixed(2)}`,
subtotal: `\$${newInvoice.getTotal().toFixed(2)}`,
paymentInstructions: JSON.parse(process.env.PAYMENT_JSON || '{}') || {
bankName: 'Bank Name',
accountName: 'Account Name',
accountNumber: '123456789',
bsb: '123456'
},
contactEmail: process.env.CONTACT_EMAIL || ''
}
// 使用 handlebars 渲染模板
@ -100,7 +105,13 @@ export default async (prisma: PrismaClient, payerId: number, period: Date[], ite
await page.pdf({
path: `./dist/${invoiceNumber}.pdf`,
format: 'A4',
printBackground: true
printBackground: true,
margin: {
top: '1.5cm',
right: '1cm',
bottom: '1cm',
left: '1cm'
}
})
await browser.close()
}