fix(compliance): Improve compliance

This commit is contained in:
2025-05-26 10:17:50 +00:00
parent 113ae22c42
commit e7c3a774a3
26 changed files with 2435 additions and 2010 deletions

View File

@ -41,9 +41,9 @@ export abstract class CIIBaseDecoder extends BaseDecoder {
const typeCode = this.getText('//ram:TypeCode');
if (typeCode === '381') { // Credit note type code
return this.decodeCreditNote();
return this.decodeCreditNote() as unknown as TInvoice;
} else {
return this.decodeDebitNote();
return this.decodeDebitNote() as unknown as TInvoice;
}
}

View File

@ -22,12 +22,8 @@ export abstract class CIIBaseEncoder extends BaseEncoder {
* @returns CII XML string
*/
public async encode(invoice: TInvoice): Promise<string> {
// Determine if it's a credit note or debit note
if (invoice.invoiceType === 'creditnote') {
return this.encodeCreditNote(invoice as TCreditNote);
} else {
return this.encodeDebitNote(invoice as TDebitNote);
}
// TInvoice is always an invoice, treat it as debit note for encoding
return this.encodeDebitNote(invoice as unknown as TDebitNote);
}
/**

View File

@ -18,8 +18,8 @@ export class FacturXDecoder extends CIIBaseDecoder {
// Create a credit note with the common data
return {
...commonData,
invoiceType: 'creditnote'
} as TCreditNote;
accountingDocType: 'creditnote' as const
} as unknown as TCreditNote;
}
/**
@ -33,8 +33,8 @@ export class FacturXDecoder extends CIIBaseDecoder {
// Create a debit note with the common data
return {
...commonData,
invoiceType: 'debitnote'
} as TDebitNote;
accountingDocType: 'debitnote' as const
} as unknown as TDebitNote;
}
/**
@ -47,7 +47,8 @@ export class FacturXDecoder extends CIIBaseDecoder {
// Extract issue date
const issueDateStr = this.getText('//ram:IssueDateTime/udt:DateTimeString');
const issueDate = issueDateStr ? new Date(issueDateStr).getTime() : Date.now();
const issueDateFormat = this.getText('//ram:IssueDateTime/udt:DateTimeString/@format');
const issueDate = this.parseCIIDate(issueDateStr, issueDateFormat);
// Extract seller information
const seller = this.extractParty('//ram:SellerTradeParty');
@ -60,7 +61,8 @@ export class FacturXDecoder extends CIIBaseDecoder {
// Extract due date
const dueDateStr = this.getText('//ram:SpecifiedTradePaymentTerms/ram:DueDateDateTime/udt:DateTimeString');
const dueDate = dueDateStr ? new Date(dueDateStr).getTime() : Date.now();
const dueDateFormat = this.getText('//ram:SpecifiedTradePaymentTerms/ram:DueDateDateTime/udt:DateTimeString/@format');
const dueDate = dueDateStr ? this.parseCIIDate(dueDateStr, dueDateFormat) : issueDate;
const dueInDays = Math.round((dueDate - issueDate) / (1000 * 60 * 60 * 24));
// Extract currency
@ -77,10 +79,12 @@ export class FacturXDecoder extends CIIBaseDecoder {
// Create the common invoice data
return {
type: 'invoice',
type: 'accounting-doc' as const,
accountingDocType: 'invoice' as const,
id: invoiceId,
accountingDocId: invoiceId,
date: issueDate,
status: 'invoice',
accountingDocStatus: 'issued' as const,
versionInfo: {
type: 'final',
version: '1.0.0'
@ -96,8 +100,7 @@ export class FacturXDecoder extends CIIBaseDecoder {
currency: currencyCode as finance.TCurrency,
notes: notes,
deliveryDate: issueDate,
objectActions: [],
invoiceType: 'debitnote' // Default to debit note, will be overridden in decode methods
objectActions: []
};
}
@ -146,8 +149,8 @@ export class FacturXDecoder extends CIIBaseDecoder {
* Extracts invoice items from Factur-X XML
* @returns Array of invoice items
*/
private extractItems(): finance.TInvoiceItem[] {
const items: finance.TInvoiceItem[] = [];
private extractItems(): finance.TAccountingDocItem[] {
const items: finance.TAccountingDocItem[] = [];
// Get all item nodes
const itemNodes = this.select('//ram:IncludedSupplyChainTradeLineItem', this.doc);

View File

@ -20,7 +20,7 @@ export class FacturXEncoder extends CIIBaseEncoder {
this.setDocumentTypeCode(xmlDoc, '381');
// Add common invoice data
this.addCommonInvoiceData(xmlDoc, creditNote);
this.addCommonInvoiceData(xmlDoc, creditNote as unknown as TInvoice);
// Serialize to string
return new XMLSerializer().serializeToString(xmlDoc);
@ -39,7 +39,7 @@ export class FacturXEncoder extends CIIBaseEncoder {
this.setDocumentTypeCode(xmlDoc, '380');
// Add common invoice data
this.addCommonInvoiceData(xmlDoc, debitNote);
this.addCommonInvoiceData(xmlDoc, debitNote as unknown as TInvoice);
// Serialize to string
return new XMLSerializer().serializeToString(xmlDoc);
@ -145,6 +145,17 @@ export class FacturXEncoder extends CIIBaseEncoder {
issueDateElement.appendChild(dateStringElement);
documentElement.appendChild(issueDateElement);
// Add notes if present
if (invoice.notes && invoice.notes.length > 0) {
for (const note of invoice.notes) {
const noteElement = doc.createElement('ram:IncludedNote');
const contentElement = doc.createElement('ram:Content');
contentElement.textContent = note;
noteElement.appendChild(contentElement);
documentElement.appendChild(noteElement);
}
}
// Create transaction element if it doesn't exist
let transactionElement = root.getElementsByTagName('rsm:SupplyChainTradeTransaction')[0];
if (!transactionElement) {

View File

@ -17,8 +17,8 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
// Create a credit note with the common data
return {
...commonData,
invoiceType: 'creditnote'
} as TCreditNote;
accountingDocType: 'creditnote' as const
} as unknown as TCreditNote;
}
/**
@ -32,8 +32,8 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
// Create a debit note with the common data
return {
...commonData,
invoiceType: 'debitnote'
} as TDebitNote;
accountingDocType: 'debitnote' as const
} as unknown as TDebitNote;
}
/**
@ -46,7 +46,8 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
// Extract issue date
const issueDateStr = this.getText('//ram:IssueDateTime/udt:DateTimeString');
const issueDate = issueDateStr ? new Date(issueDateStr).getTime() : Date.now();
const issueDateFormat = this.getText('//ram:IssueDateTime/udt:DateTimeString/@format');
const issueDate = this.parseCIIDate(issueDateStr, issueDateFormat);
// Extract seller information
const seller = this.extractParty('//ram:SellerTradeParty');
@ -76,10 +77,12 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
// Create the common invoice data
return {
type: 'invoice',
type: 'accounting-doc' as const,
accountingDocType: 'invoice' as const,
id: invoiceId,
accountingDocId: invoiceId,
date: issueDate,
status: 'invoice',
accountingDocStatus: 'issued' as const,
versionInfo: {
type: 'final',
version: '1.0.0'
@ -95,8 +98,7 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
currency: currencyCode as finance.TCurrency,
notes: notes,
deliveryDate: issueDate,
objectActions: [],
invoiceType: 'debitnote' // Default to debit note, will be overridden in decode methods
objectActions: []
};
}
@ -129,7 +131,7 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
houseNumber: houseNumber,
city: city,
postalCode: postalCode,
country: country
countryCode: country
};
// Extract VAT ID
@ -158,8 +160,8 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
* Extracts invoice items from ZUGFeRD XML
* @returns Array of invoice items
*/
private extractItems(): finance.TInvoiceItem[] {
const items: finance.TInvoiceItem[] = [];
private extractItems(): finance.TAccountingDocItem[] {
const items: finance.TAccountingDocItem[] = [];
// Get all item nodes
const itemNodes = this.select('//ram:IncludedSupplyChainTradeLineItem', this.doc);

View File

@ -27,7 +27,7 @@ export class ZUGFeRDEncoder extends CIIBaseEncoder {
this.setDocumentTypeCode(xmlDoc, '381');
// Add common invoice data
this.addCommonInvoiceData(xmlDoc, creditNote);
this.addCommonInvoiceData(xmlDoc, creditNote as unknown as TInvoice);
// Serialize to string
return new XMLSerializer().serializeToString(xmlDoc);
@ -46,7 +46,7 @@ export class ZUGFeRDEncoder extends CIIBaseEncoder {
this.setDocumentTypeCode(xmlDoc, '380');
// Add common invoice data
this.addCommonInvoiceData(xmlDoc, debitNote);
this.addCommonInvoiceData(xmlDoc, debitNote as unknown as TInvoice);
// Serialize to string
return new XMLSerializer().serializeToString(xmlDoc);

View File

@ -32,8 +32,8 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
// Create a credit note with the common data
return {
...commonData,
invoiceType: 'creditnote'
} as TCreditNote;
accountingDocType: 'creditnote' as const
} as unknown as TCreditNote;
}
/**
@ -47,8 +47,8 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
// Create a debit note with the common data
return {
...commonData,
invoiceType: 'debitnote'
} as TDebitNote;
accountingDocType: 'debitnote' as const
} as unknown as TDebitNote;
}
/**
@ -61,7 +61,8 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
// Extract issue date
const issueDateStr = this.getText('//ram:IssueDateTime/udt:DateTimeString');
const issueDate = issueDateStr ? new Date(issueDateStr).getTime() : Date.now();
const issueDateFormat = this.getText('//ram:IssueDateTime/udt:DateTimeString/@format');
const issueDate = this.parseCIIDate(issueDateStr, issueDateFormat);
// Extract seller information
const seller = this.extractParty('//ram:SellerTradeParty');
@ -91,10 +92,12 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
// Create the common invoice data
return {
type: 'invoice',
type: 'accounting-doc' as const,
accountingDocType: 'invoice' as const,
id: invoiceId,
accountingDocId: invoiceId,
date: issueDate,
status: 'invoice',
accountingDocStatus: 'issued' as const,
versionInfo: {
type: 'final',
version: '1.0.0'
@ -110,8 +113,7 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
currency: currencyCode as finance.TCurrency,
notes: notes,
deliveryDate: issueDate,
objectActions: [],
invoiceType: 'debitnote' // Default to debit note, will be overridden in decode methods
objectActions: []
};
}
@ -144,7 +146,7 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
houseNumber: houseNumber,
city: city,
postalCode: postalCode,
country: country
countryCode: country
};
// Extract VAT ID
@ -173,8 +175,8 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
* Extracts invoice items from ZUGFeRD v1 XML
* @returns Array of invoice items
*/
private extractItems(): finance.TInvoiceItem[] {
const items: finance.TInvoiceItem[] = [];
private extractItems(): finance.TAccountingDocItem[] {
const items: finance.TAccountingDocItem[] = [];
// Get all item nodes
const itemNodes = this.select('//ram:IncludedSupplyChainTradeLineItem', this.doc);