update
This commit is contained in:
50
ts/formats/factories/decoder.factory.ts
Normal file
50
ts/formats/factories/decoder.factory.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { BaseDecoder } from '../base/base.decoder.js';
|
||||
import { InvoiceFormat } from '../../interfaces/common.js';
|
||||
import { FormatDetector } from '../utils/format.detector.js';
|
||||
|
||||
// Import specific decoders
|
||||
// import { XRechnungDecoder } from '../ubl/xrechnung/xrechnung.decoder.js';
|
||||
import { FacturXDecoder } from '../cii/facturx/facturx.decoder.js';
|
||||
// import { ZUGFeRDDecoder } from '../cii/zugferd/zugferd.decoder.js';
|
||||
|
||||
/**
|
||||
* Factory to create the appropriate decoder based on the XML format
|
||||
*/
|
||||
export class DecoderFactory {
|
||||
/**
|
||||
* Creates a decoder for the specified XML content
|
||||
* @param xml XML content to decode
|
||||
* @returns Appropriate decoder instance
|
||||
*/
|
||||
public static createDecoder(xml: string): BaseDecoder {
|
||||
const format = FormatDetector.detectFormat(xml);
|
||||
|
||||
switch (format) {
|
||||
case InvoiceFormat.UBL:
|
||||
// return new UBLDecoder(xml);
|
||||
throw new Error('UBL decoder not yet implemented');
|
||||
|
||||
case InvoiceFormat.XRECHNUNG:
|
||||
// return new XRechnungDecoder(xml);
|
||||
throw new Error('XRechnung decoder not yet implemented');
|
||||
|
||||
case InvoiceFormat.CII:
|
||||
// For now, use Factur-X decoder for generic CII
|
||||
return new FacturXDecoder(xml);
|
||||
|
||||
case InvoiceFormat.ZUGFERD:
|
||||
// For now, use Factur-X decoder for ZUGFeRD
|
||||
return new FacturXDecoder(xml);
|
||||
|
||||
case InvoiceFormat.FACTURX:
|
||||
return new FacturXDecoder(xml);
|
||||
|
||||
case InvoiceFormat.FATTURAPA:
|
||||
// return new FatturaPADecoder(xml);
|
||||
throw new Error('FatturaPA decoder not yet implemented');
|
||||
|
||||
default:
|
||||
throw new Error(`Unsupported invoice format: ${format}`);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user