update
This commit is contained in:
@ -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}`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user