fix(compliance): improve compliance

This commit is contained in:
2025-05-27 12:23:50 +00:00
parent 206bef0619
commit be123e41c9
22 changed files with 725 additions and 793 deletions

View File

@ -556,6 +556,18 @@ export class UBLEncoder extends UBLBaseEncoder {
private addBusinessReferencesToUBL(doc: Document, root: Element, businessReferences?: any): void {
if (!businessReferences) return;
// Add BuyerReference
if (businessReferences.buyerReference && !root.getElementsByTagName('cbc:BuyerReference')[0]) {
const buyerRef = doc.createElement('cbc:BuyerReference');
buyerRef.textContent = businessReferences.buyerReference;
// Insert after DocumentCurrencyCode
const currencyCode = root.getElementsByTagName('cbc:DocumentCurrencyCode')[0];
if (currencyCode && currencyCode.parentNode) {
currencyCode.parentNode.insertBefore(buyerRef, currencyCode.nextSibling);
}
}
// Add OrderReference
if (businessReferences.orderReference && !root.getElementsByTagName('cac:OrderReference')[0]) {
const orderRef = doc.createElement('cac:OrderReference');
@ -563,10 +575,12 @@ export class UBLEncoder extends UBLBaseEncoder {
orderId.textContent = businessReferences.orderReference;
orderRef.appendChild(orderId);
// Insert after DocumentCurrencyCode
// Insert after BuyerReference or DocumentCurrencyCode
const buyerRef = root.getElementsByTagName('cbc:BuyerReference')[0];
const currencyCode = root.getElementsByTagName('cbc:DocumentCurrencyCode')[0];
if (currencyCode && currencyCode.parentNode) {
currencyCode.parentNode.insertBefore(orderRef, currencyCode.nextSibling);
const insertAfter = buyerRef || currencyCode;
if (insertAfter && insertAfter.parentNode) {
insertAfter.parentNode.insertBefore(orderRef, insertAfter.nextSibling);
}
}

View File

@ -141,6 +141,7 @@ export class XRechnungDecoder extends UBLBaseDecoder {
}
// Extract business references
const buyerReference = this.getText('//cbc:BuyerReference', this.doc);
const orderReference = this.getText('//cac:OrderReference/cbc:ID', this.doc);
const contractReference = this.getText('//cac:ContractDocumentReference/cbc:ID', this.doc);
const projectReference = this.getText('//cac:ProjectReference/cbc:ID', this.doc);
@ -207,6 +208,7 @@ export class XRechnungDecoder extends UBLBaseDecoder {
version: '1.0.0',
extensions: {
businessReferences: {
buyerReference,
orderReference,
contractReference,
projectReference

View File

@ -60,16 +60,17 @@ export class XRechnungEncoder extends UBLEncoder {
// Add or update Buyer Reference (required for XRechnung)
let buyerRef = root.getElementsByTagName('cbc:BuyerReference')[0];
const buyerReferenceValue = (invoice as any).buyerReference || metadata?.businessReferences?.buyerReference || invoice.id;
if (!buyerRef) {
// Find where to insert it (after DocumentCurrencyCode)
const currencyCode = root.getElementsByTagName('cbc:DocumentCurrencyCode')[0];
if (currencyCode) {
buyerRef = doc.createElement('cbc:BuyerReference');
buyerRef.textContent = invoice.buyerReference || invoice.id;
buyerRef.textContent = buyerReferenceValue;
currencyCode.parentNode!.insertBefore(buyerRef, currencyCode.nextSibling);
}
} else if (!buyerRef.textContent || buyerRef.textContent.trim() === '') {
buyerRef.textContent = invoice.buyerReference || invoice.id;
buyerRef.textContent = buyerReferenceValue;
}
// Update payment terms to German