lbx-invoice
Version:
Provides functionality around generating invoices.
37 lines • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.XRechnungUtilities = void 0;
const pdf_lib_1 = require("pdf-lib");
const pdf_utilities_1 = require("./pdf.utilities");
const xml_utilities_1 = require("./xml.utilities");
/**
* Provides functionality for handling the german X-Rechnung format.
*/
class XRechnungUtilities {
/**
* Creates and attaches a factur-x xml to the invoice pdf at the given path.
* @param pdfFilePath - The path of the invoice pdf to attach to.
* @param invoice - The invoice data to generate the xml from.
* @param currency - The currency code, eg. 'USD'.
* @param companyInfo - Info about the seller.
* @param tradeContact - The trade contact. Defaults to companyInfo.ceo.
*/
static async attachXRechnung(pdfFilePath, invoice, currency, companyInfo, tradeContact = companyInfo.ceo) {
const xmlBytes = this.createXRechnungBytes(invoice, currency, companyInfo, tradeContact);
const now = new Date();
await pdf_utilities_1.PdfUtilities.attach(pdfFilePath, xmlBytes, 'xrechnung.xml', {
mimeType: 'text/xml',
afRelationship: pdf_lib_1.AFRelationship.Alternative,
creationDate: now,
modificationDate: now
});
}
static createXRechnungBytes(invoice, currency, companyInfo, tradeContact = companyInfo.ceo) {
const xml = xml_utilities_1.XmlUtilities.createCrossIndustryInvoiceXml(invoice, currency, companyInfo, tradeContact, 'urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0');
const xmlString = xml.end({ prettyPrint: true });
const xmlBytes = new TextEncoder().encode(xmlString);
return xmlBytes;
}
}
exports.XRechnungUtilities = XRechnungUtilities;
//# sourceMappingURL=x-rechnung.utilities.js.map