Package Exports
- xrechnung-generator
- xrechnung-generator/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xrechnung-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
XRechnung Generator
XRechnung is a standardized electronic invoice format developed to comply with the European Directive 2014/55/EU, which mandates electronic invoicing in public procurement. It is primarily used in Germany, but it adheres to EU-wide guidelines for electronic invoicing.
A lightweight Node.js module for creating XRechnung-compliant invoices in the UBL (Universal Business Language) format.
Installation
Install the module via npm:
npm install xrechnung-generatorUsage
Import the Module
import XRechnungGenerator from 'xrechnung-generator'Example: Using the Functions
const invoiceData = {
id: 'INV-001',
issueDate: '2024-01-01',
currency: 'EUR',
supplier: { name: 'Supplier Ltd.', country: 'DE' },
customer: { name: 'Customer Ltd.', country: 'DE' },
taxTotal: { taxAmount: 19, taxPercentage: 19 },
lineItems: [
{
id: 'ITEM-001',
description: 'Product A',
quantity: 1,
unitPrice: 100,
lineTotal: 100,
},
],
};
// Create a new invoice
const xrechnung = new XRechnungGenerator(invoiceData);
console.log(xrechnung.toXMLString());API
XRechnungGenerator
const xrechnung = new XRechnungGenerator(invoiceData);invoiceData(InvoiceData): The invoice to convert (see example above).
interface InvoiceData {
id: string;
issueDate: string;
dueDate?: string; // optional
currency: string;
totalAmount: number;
supplier: {
name: string;
country: string;
street?: string; // optional
postalCode?: string; // optional
city?: string; // optional
taxNumber?: string; // optional
legalEntityID?: string; // optional
};
customer: {
name: string;
country: string;
street?: string; // optional
postalCode?: string; // optional
city?: string; // optional
taxNumber?: string; // optional
legalEntityID?: string; // optional
};
taxTotal: {
taxAmount: number;
taxPercentage: number;
};
paymentDetails?: { // optional
paymentMeansCode?: string; // optional
paymentID?: string; // optional
bankDetails?: { // optional
accountName?: string; // optional
iban?: string; // optional
bic?: string; // optional
bankName?: string; // optional
}
};
notes?: string[]; // optional
lineItems: {
id: string;
description: string;
quantity: number;
unitPrice: number;
lineTotal: number;
}[];
}Methods
toXMLString()- Returns the XML representation of the invoice as a string.
const xmlString = xrechnung.toXMLString();
toBuffer()- Returns the XML representation as a
Bufferobject.
const buffer = xrechnung.toBuffer();
- Returns the XML representation as a
toBlob()- Returns the XML representation as a
Blobobject (useful for browser environments).
const blob = xrechnung.toBlob(); console.log(blob.content);
- Returns the XML representation as a
writeFile(filePath)- Writes the XML representation to the specified file path.
- Parameters:
filePath(String): Path to the output file.
- Returns a
Promise.
xrechnung.writeFile('/path/to/invoice.xrechnung') .then(() => console.log('File written successfully.')) .catch(console.error);
Contribution
Contributions in the form of bug reports, feature requests, or pull requests are welcome! Please ensure you run the tests and cover new functionality when contributing.
License
This project is licensed under the MIT License.
Hire Me
Looking for a developer with expertise in Node.js? Feel free to reach out to me for freelance projects, collaborations, or full-time opportunities!
Contact me hello@pixelpal.io