update
This commit is contained in:
@ -267,7 +267,7 @@ export class EInvoice implements TInvoice {
|
||||
}
|
||||
|
||||
// Get appropriate decoder
|
||||
const decoder = DecoderFactory.createDecoder(xmlString);
|
||||
const decoder = DecoderFactory.createDecoder(xmlString, !this.options.validateOnLoad);
|
||||
const invoice = await decoder.decode();
|
||||
|
||||
// Map the decoded invoice to our properties
|
||||
@ -528,6 +528,14 @@ export class EInvoice implements TInvoice {
|
||||
return this.detectedFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the original XML string
|
||||
* @returns The XML string
|
||||
*/
|
||||
public getXml(): string {
|
||||
return this.xmlString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the total net amount
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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}`);
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user