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,6 @@
import { CIIBaseDecoder } from '../cii.decoder.js';
import type { TInvoice, TCreditNote, TDebitNote } from '../../../interfaces/common.js';
import { ZUGFERD_PROFILE_IDS } from './zugferd.types.js';
import { business, finance, general } from '@tsclass/tsclass';
import { business, finance } from '@tsclass/tsclass';
/**
* Decoder for ZUGFeRD invoice format
@@ -66,8 +65,8 @@ export class ZUGFeRDDecoder 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();
@@ -111,16 +110,25 @@ export class ZUGFeRDDecoder 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
};
@@ -214,7 +222,12 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
* Creates a default date for empty date fields
* @returns Default date as timestamp
*/
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
};
}
}