This commit is contained in:
2025-05-28 08:40:26 +00:00
parent e4c762658d
commit 32f8bc192a
24 changed files with 3350 additions and 5416 deletions

View File

@ -8,9 +8,11 @@ import type { ValidationResult } from '../../interfaces/common.js';
*/
export abstract class BaseDecoder {
protected xml: string;
protected skipValidation: boolean;
constructor(xml: string) {
constructor(xml: string, skipValidation: boolean = false) {
this.xml = xml;
this.skipValidation = skipValidation;
}
/**

View File

@ -12,8 +12,8 @@ export abstract class CIIBaseDecoder extends BaseDecoder {
protected select: xpath.XPathSelect;
protected profile: CIIProfile = CIIProfile.EN16931;
constructor(xml: string) {
super(xml);
constructor(xml: string, skipValidation: boolean = false) {
super(xml, skipValidation);
// Parse XML document
this.doc = new DOMParser().parseFromString(xml, 'application/xml');

View File

@ -116,8 +116,10 @@ export class FacturXDecoder extends CIIBaseDecoder {
objectActions: []
};
// Validate mandatory EN16931 fields
EN16931Validator.validateMandatoryFields(invoiceData);
// Validate mandatory EN16931 fields unless validation is skipped
if (!this.skipValidation) {
EN16931Validator.validateMandatoryFields(invoiceData);
}
return invoiceData;
}

View File

@ -115,8 +115,10 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
objectActions: []
};
// Validate mandatory EN16931 fields
EN16931Validator.validateMandatoryFields(invoiceData);
// Validate mandatory EN16931 fields unless validation is skipped
if (!this.skipValidation) {
EN16931Validator.validateMandatoryFields(invoiceData);
}
return invoiceData;
}

View File

@ -11,9 +11,10 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
/**
* Constructor
* @param xml XML string to decode
* @param skipValidation Whether to skip EN16931 validation
*/
constructor(xml: string) {
super(xml);
constructor(xml: string, skipValidation: boolean = false) {
super(xml, skipValidation);
// Override namespaces for ZUGFeRD v1
this.namespaces = {
rsm: ZUGFERD_V1_NAMESPACES.RSM,

View File

@ -15,32 +15,33 @@ export class DecoderFactory {
/**
* Creates a decoder for the specified XML content
* @param xml XML content to decode
* @param skipValidation Whether to skip EN16931 validation
* @returns Appropriate decoder instance
*/
public static createDecoder(xml: string): BaseDecoder {
public static createDecoder(xml: string, skipValidation: boolean = false): BaseDecoder {
const format = FormatDetector.detectFormat(xml);
switch (format) {
case InvoiceFormat.UBL:
case InvoiceFormat.XRECHNUNG:
return new XRechnungDecoder(xml);
return new XRechnungDecoder(xml, skipValidation);
case InvoiceFormat.CII:
// For now, use Factur-X decoder for generic CII
return new FacturXDecoder(xml);
return new FacturXDecoder(xml, skipValidation);
case InvoiceFormat.ZUGFERD:
// Determine if it's ZUGFeRD v1 or v2 based on root element
if (xml.includes('CrossIndustryDocument') ||
xml.includes('urn:ferd:CrossIndustryDocument:invoice:1p0') ||
(xml.includes('ZUGFeRD') && !xml.includes('CrossIndustryInvoice'))) {
return new ZUGFeRDV1Decoder(xml);
return new ZUGFeRDV1Decoder(xml, skipValidation);
} else {
return new ZUGFeRDDecoder(xml);
return new ZUGFeRDDecoder(xml, skipValidation);
}
case InvoiceFormat.FACTURX:
return new FacturXDecoder(xml);
return new FacturXDecoder(xml, skipValidation);
case InvoiceFormat.FATTURAPA:
// return new FatturaPADecoder(xml);
@ -49,11 +50,11 @@ export class DecoderFactory {
default:
// If format is unknown but contains CrossIndustryInvoice, try ZUGFeRD decoder
if (xml.includes('CrossIndustryInvoice')) {
return new ZUGFeRDDecoder(xml);
return new ZUGFeRDDecoder(xml, skipValidation);
}
// If format is unknown but contains CrossIndustryDocument, try ZUGFeRD v1 decoder
if (xml.includes('CrossIndustryDocument')) {
return new ZUGFeRDV1Decoder(xml);
return new ZUGFeRDV1Decoder(xml, skipValidation);
}
throw new Error(`Unsupported invoice format: ${format}`);
}

View File

@ -11,8 +11,8 @@ export abstract class UBLBaseDecoder extends BaseDecoder {
protected namespaces: Record<string, string>;
protected select: xpath.XPathSelect;
constructor(xml: string) {
super(xml);
constructor(xml: string, skipValidation: boolean = false) {
super(xml, skipValidation);
// Parse XML document
this.doc = new DOMParser().parseFromString(xml, 'application/xml');

View File

@ -247,8 +247,10 @@ export class XRechnungDecoder extends UBLBaseDecoder {
}
};
// Validate mandatory EN16931 fields
EN16931Validator.validateMandatoryFields(invoiceData);
// Validate mandatory EN16931 fields unless validation is skipped
if (!this.skipValidation) {
EN16931Validator.validateMandatoryFields(invoiceData);
}
return invoiceData;
} catch (error) {