feat(compliance): improve compliance

This commit is contained in:
2025-05-26 14:49:34 +00:00
parent 26deb14893
commit 206bef0619
3 changed files with 284 additions and 61 deletions

View File

@ -106,6 +106,10 @@ export class XRechnungDecoder extends UBLBaseDecoder {
vatPercentage
};
// Extract order line reference
const orderLineReference = this.getText('./cac:OrderLineReference/cac:OrderReference/cbc:ID', line) || '';
const orderLineReferenceId = this.getText('./cac:OrderLineReference/cbc:LineID', line) || '';
// Extract additional item properties
const additionalProps: Record<string, string> = {};
const propNodes = this.select('./cac:Item/cac:AdditionalItemProperty', line);
@ -120,12 +124,14 @@ export class XRechnungDecoder extends UBLBaseDecoder {
}
// Store additional item data in metadata
if (description || buyerItemID || standardItemID || commodityClassification || Object.keys(additionalProps).length > 0) {
if (description || buyerItemID || standardItemID || commodityClassification || orderLineReference || Object.keys(additionalProps).length > 0) {
item.metadata = {
description,
buyerItemID,
standardItemID,
commodityClassification,
orderLineReference,
orderLineReferenceId,
additionalProperties: additionalProps
};
}
@ -142,8 +148,10 @@ export class XRechnungDecoder extends UBLBaseDecoder {
// Extract payment information
const paymentMeansCode = this.getText('//cac:PaymentMeans/cbc:PaymentMeansCode', this.doc);
const paymentID = this.getText('//cac:PaymentMeans/cbc:PaymentID', this.doc);
const paymentDueDate = this.getText('//cac:PaymentMeans/cbc:PaymentDueDate', this.doc);
const iban = this.getText('//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID', this.doc);
const bic = this.getText('//cac:PaymentMeans/cac:PayeeFinancialAccount/cac:FinancialInstitutionBranch/cac:FinancialInstitution/cbc:ID', this.doc);
const bic = this.getText('//cac:PaymentMeans/cac:PayeeFinancialAccount/cac:FinancialInstitutionBranch/cbc:ID', this.doc);
const bankName = this.getText('//cac:PaymentMeans/cac:PayeeFinancialAccount/cac:FinancialInstitutionBranch/cbc:Name', this.doc);
const accountName = this.getText('//cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:Name', this.doc);
// Extract payment terms with discount
@ -206,8 +214,10 @@ export class XRechnungDecoder extends UBLBaseDecoder {
paymentInformation: {
paymentMeansCode,
paymentID,
paymentDueDate,
iban,
bic,
bankName,
accountName,
paymentTermsNote,
discountPercent
@ -272,6 +282,8 @@ export class XRechnungDecoder extends UBLBaseDecoder {
let contactPhone = '';
let contactEmail = '';
let contactName = '';
let gln = '';
const additionalIdentifiers: any[] = [];
// Try to extract party information
const partyNodes = this.select(partyPath, this.doc);
@ -279,6 +291,28 @@ export class XRechnungDecoder extends UBLBaseDecoder {
if (partyNodes && Array.isArray(partyNodes) && partyNodes.length > 0) {
const party = partyNodes[0];
// Extract GLN from EndpointID
const endpointId = this.getText('./cbc:EndpointID[@schemeID="0088"]', party);
if (endpointId) {
gln = endpointId;
}
// Extract additional party identifications
const partyIdNodes = this.select('./cac:PartyIdentification', party);
if (partyIdNodes && Array.isArray(partyIdNodes)) {
for (const idNode of partyIdNodes) {
const idValue = this.getText('./cbc:ID', idNode);
const idElement = (idNode as Element).getElementsByTagName('cbc:ID')[0];
const schemeId = idElement?.getAttribute('schemeID');
if (idValue) {
additionalIdentifiers.push({
value: idValue,
scheme: schemeId || ''
});
}
}
}
// Extract name
name = this.getText('./cac:PartyName/cbc:Name', party) || '';
@ -349,16 +383,28 @@ export class XRechnungDecoder extends UBLBaseDecoder {
}
};
// Store contact information in metadata if available
// Store contact information and additional identifiers in metadata if available
const metadata: any = {};
if (contactPhone || contactEmail || contactName) {
contact.metadata = {
contactInformation: {
phone: contactPhone,
email: contactEmail,
name: contactName
}
metadata.contactInformation = {
phone: contactPhone,
email: contactEmail,
name: contactName
};
}
if (gln) {
(contact as any).gln = gln;
}
if (additionalIdentifiers.length > 0) {
(contact as any).additionalIdentifiers = additionalIdentifiers;
}
if (Object.keys(metadata).length > 0) {
contact.metadata = metadata;
}
return contact;
} catch (error) {