fix(zugferd): Refactor Zugferd decoders to properly extract house numbers from street names and remove unused imports; update readme hints with additional TInvoice reference and refresh PDF metadata timestamps.

This commit is contained in:
2025-04-03 20:23:09 +00:00
parent a077f5c335
commit a5d5525e7a
8 changed files with 104 additions and 32 deletions

View File

@ -1,7 +1,7 @@
import { CIIBaseDecoder } from '../cii.decoder.js';
import type { TInvoice, TCreditNote, TDebitNote } from '../../../interfaces/common.js';
import { ZUGFERD_V1_NAMESPACES } from '../cii.types.js';
import { business, finance, general } from '@tsclass/tsclass';
import { business, finance } from '@tsclass/tsclass';
/**
* Decoder for ZUGFeRD v1 invoice format
@ -80,8 +80,8 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
// Extract currency
const currencyCode = this.getText('//ram:InvoiceCurrencyCode') || 'EUR';
// Extract total amount
const totalAmount = this.getNumber('//ram:GrandTotalAmount');
// Extract total amount (not used in this implementation but could be useful)
// const totalAmount = this.getNumber('//ram:GrandTotalAmount');
// Extract notes
const notes = this.extractNotes();
@ -125,16 +125,25 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
const name = this.getText(`${partyXPath}/ram:Name`);
// Extract address
const street = this.getText(`${partyXPath}/ram:PostalTradeAddress/ram:LineOne`);
const streetName = this.getText(`${partyXPath}/ram:PostalTradeAddress/ram:LineOne`);
const city = this.getText(`${partyXPath}/ram:PostalTradeAddress/ram:CityName`);
const zip = this.getText(`${partyXPath}/ram:PostalTradeAddress/ram:PostcodeCode`);
const postalCode = this.getText(`${partyXPath}/ram:PostalTradeAddress/ram:PostcodeCode`);
const country = this.getText(`${partyXPath}/ram:PostalTradeAddress/ram:CountryID`);
// Try to extract house number from street if possible
let houseNumber = '';
const streetParts = streetName.match(/^(.*?)\s+(\d+.*)$/);
if (streetParts) {
// If we can split into street name and house number
houseNumber = streetParts[2];
}
// Create address object
const address = {
street: street,
streetName: streetName,
houseNumber: houseNumber,
city: city,
zip: zip,
postalCode: postalCode,
country: country
};
@ -226,9 +235,14 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
/**
* Creates a default date for empty date fields
* @returns Default date as timestamp
* @returns Default date object compatible with TContact
*/
private createDefaultDate(): number {
return new Date('2000-01-01').getTime();
private createDefaultDate(): any {
// Create a date object that will be compatible with TContact
return {
year: 2000,
month: 1,
day: 1
};
}
}