Files
points-mall/supplied-service/tools/test/test-invoice-template.js
T

21 lines
920 B
JavaScript

import { readFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { generateMockInvoicePdf } from '../mock-invoice-pdf.js'
const directory = path.dirname(fileURLToPath(import.meta.url))
const inputPath = path.join(directory, 'invoice-template-example.json')
const outputPath = process.argv[2]
? path.resolve(process.argv[2])
: path.resolve(directory, '../output/pdf/test-invoice-template.pdf')
try {
const invoice = JSON.parse(readFileSync(inputPath, 'utf8'))
generateMockInvoicePdf(invoice, outputPath, { fontPath: process.argv[3] })
console.log(`发票已生成:${outputPath}`)
console.log(`测试金额:不含税 ${invoice.invoiceNakedPrice} 元,税额 ${invoice.invoiceTaxPrice} 元,价税合计 ${invoice.orderTotalPrice} 元`)
} catch (error) {
console.error(error instanceof Error ? error.message : String(error))
process.exitCode = 1
}