diff --git a/common/config/rush/version-policies.json b/common/config/rush/version-policies.json index 7d0efc3f..10f27c64 100644 --- a/common/config/rush/version-policies.json +++ b/common/config/rush/version-policies.json @@ -68,7 +68,7 @@ { "policyName": "saxon", "definitionName": "lockStepVersion", - "version": "0.0.16-beta.1", + "version": "12.5.0-beta.1", "nextBump": "patch" }, { diff --git a/packages/cfdi/xml/src/cfdi.ts b/packages/cfdi/xml/src/cfdi.ts index 341ba29c..6943c4a0 100755 --- a/packages/cfdi/xml/src/cfdi.ts +++ b/packages/cfdi/xml/src/cfdi.ts @@ -3,7 +3,7 @@ import { cer, key } from '@cfdi/csd'; import { Comprobante } from './elements/Comprobante'; import { FileSystem } from './utils/FileSystem'; -import { Options, XsltSheet } from './types/types'; +import { Config, SaxonHe, XsltSheet } from './types/types'; import { Transform } from '@saxon-he/cli'; import { XmlCdfi } from './types/xmlCdfi.interface'; import xmlJS from 'xml-js'; @@ -13,6 +13,7 @@ import { CFDIError } from './common/error'; */ export class CFDI extends Comprobante { private _cadenaOriginal: string = ''; + protected saxon?: SaxonHe | undefined = undefined protected xslt?: XsltSheet | null = null; private debug = false; @@ -24,9 +25,10 @@ export class CFDI extends Comprobante { * @param options *Options; */ - constructor(options?: Options) { + constructor(options?: Config) { super(options); this.xslt = options?.xslt; + this.saxon = options?.saxon this._cadenaOriginal = ''; this.setDebug(Boolean(options?.debug)); } @@ -122,17 +124,14 @@ export class CFDI extends Comprobante { const result = xmlJS.js2xml(this.xml, options); fs.writeFileSync(fullPath, result, 'utf8'); - let cadena: string = ''; - - const transform = new Transform(); - //console.time('saxon cli 2'); - cadena = transform + + const transform = new Transform(this.saxon) + const cadena = transform .s(fullPath) .xsl(String(this.xslt.path)) .warnings('silent') .run(); - //console.timeEnd('saxon cli'); - + if (this.debug) { console.log('xslt =>', this.xslt); console.log('cadena original =>', cadena); diff --git a/packages/cfdi/xml/src/elements/Comprobante.ts b/packages/cfdi/xml/src/elements/Comprobante.ts index b12ed14c..b31d1787 100644 --- a/packages/cfdi/xml/src/elements/Comprobante.ts +++ b/packages/cfdi/xml/src/elements/Comprobante.ts @@ -1,7 +1,7 @@ import { CFDIComprobante, ComprobanteAttributes, - Options, + Config, TagComprobante, XmlCdfi, XmlComprobante, @@ -34,7 +34,7 @@ export class Comprobante { ]; schema = Schema.of(); - constructor(options?: Options) { + constructor(options?: Config) { const { debug, schema } = options || { debug: false }; this.schema.setConfig({ debug: debug, @@ -266,20 +266,14 @@ export class Comprobante { * @param complements * ComlementType */ - public async complemento(complements: ComlementType): Promise { + public complemento(complements: ComlementType): void { if (!this.xml['cfdi:Comprobante']['cfdi:Complemento']) { this.xml['cfdi:Comprobante']['cfdi:Complemento'] = {} as XmlComplements; } - const complement = await complements.getComplement(); + const complement = complements.getComplement(); this.addXmlns(complement.xmlnskey, complement.xmlns); this.addSchemaLocation(complement.schemaLocation); - if ( - this.xml['cfdi:Comprobante'] && - this.xml['cfdi:Comprobante']['cfdi:Complemento'] - ) { - this.xml['cfdi:Comprobante']['cfdi:Complemento'][complement.key] = - complement.complement; - } + this.xml['cfdi:Comprobante']['cfdi:Complemento'][complement.key] = complement.complement } public setCertificado(certificado: string): void { diff --git a/packages/cfdi/xml/src/types/types.ts b/packages/cfdi/xml/src/types/types.ts index 36557643..3dc74f94 100644 --- a/packages/cfdi/xml/src/types/types.ts +++ b/packages/cfdi/xml/src/types/types.ts @@ -1,16 +1,25 @@ -export interface Options { - debug?: boolean; - compact?: boolean; - customTags?: any; - schema?: { - path: string; - }, - xslt: XsltSheet // @ Extensible Stylesheet Language Transformation +export interface Schema { + path: string; } + +export interface SaxonHe { + binary: string; +} + export interface XsltSheet { path: string; } +export interface Config { + debug?: boolean; + compact?: boolean; + customTags?: any; + schema?: Schema + saxon?: SaxonHe + xslt?: XsltSheet // @ Extensible Stylesheet Language Transformation +} + + export enum InvoiceType { INGRESO = 'I', EGRESO = 'E', diff --git a/packages/cfdi/xml/test/facturas/general.test.ts b/packages/cfdi/xml/test/facturas/general.test.ts index 4d20e724..c6cc7fa1 100644 --- a/packages/cfdi/xml/test/facturas/general.test.ts +++ b/packages/cfdi/xml/test/facturas/general.test.ts @@ -39,6 +39,7 @@ describe('general', () => { it('debe generar una factura general con xslt', async () => { const cfdi = new CFDI({ xslt: { path: xslt_path }, + // saxon: { binary: 'java -jar /opt/homebrew/Cellar/saxon/12.5/libexec/saxon-he-12.5.jar '} }); cfdi.comprobante({ diff --git a/packages/cfdi/xml/test/facturas/vehiculo-usado.test.ts b/packages/cfdi/xml/test/facturas/vehiculo-usado.test.ts new file mode 100644 index 00000000..71102343 --- /dev/null +++ b/packages/cfdi/xml/test/facturas/vehiculo-usado.test.ts @@ -0,0 +1,138 @@ +import { describe, it, expect } from 'vitest'; +import { + CFDI, + Concepto, + Emisor, + Impuestos, + ObjetoImpEnum, + Receptor, +} from '../../src'; +import path from 'path'; +import { VehiculoUsado } from '@cfdi/complementos'; + +const files = path.resolve(__dirname, '..', '..', '..', '..', 'files'); + +const key_path = `${files}/certificados/LAN7008173R5.key`; +const cer_path = `${files}/certificados/LAN7008173R5.cer`; +const xslt_path = `${files}/4.0/cadenaoriginal.xslt`; + +const expectedXml = ` + + + + + + + + + + + + + + + + + + + + + +`; + +describe('general', () => { + it('debe generar una factura de vehiculo usado con xslt', async () => { + const cfdi = new CFDI({ + xslt: { path: xslt_path }, + //saxon: { binary: 'java -jar /opt/homebrew/Cellar/saxon/12.5/libexec/saxon-he-12.5.jar '} + }); + + cfdi.comprobante({ + Version: '4.0', + Serie: 'Serie', + Folio: 'Folio', + Fecha: '2024-03-01T00:00:00', + FormaPago: 99, + CondicionesDePago: 'CondicionesDePago', + SubTotal: 2000, + Moneda: 'MXN', + TipoCambio: '1', + Total: 2000.16, + TipoDeComprobante: 'I', + Exportacion: '01', + MetodoPago: 'PUE', + LugarExpedicion: '20000', + }); + + const emisor = new Emisor({ + Rfc: 'EKU9003173C9', + Nombre: 'ESCUELA KEMPER URGATE', + RegimenFiscal: 601, + }); + const receptor = new Receptor({ + Rfc: 'URE180429TM6', + Nombre: 'UNIVERSIDAD ROBOTICA ESPAÑOLA', + DomicilioFiscalReceptor: '86991', + RegimenFiscalReceptor: 601, + UsoCFDI: 'S01', + }); + + const concepto = new Concepto({ + ClaveProdServ: '50211503', + Cantidad: 1, + ClaveUnidad: 'H87', + Unidad: 'Servicio', + Descripcion: 'Servicio', + ValorUnitario: '200.00', + Importe: '200.00', + ObjetoImp: '02', + }); + concepto.traslado({ + Base: 1, + Impuesto: '002', + TipoFactor: 'Tasa', + TasaOCuota: '0.160000', + Importe: 0.16, + }); + + const impuestos = new Impuestos({ + TotalImpuestosTrasladados: '0.16', + }); + + impuestos.traslados({ + Base: 1, + Impuesto: '002', + TipoFactor: 'Tasa', + TasaOCuota: '0.160000', + Importe: 0.16, + }); + + const vehiculoUsado = new VehiculoUsado({ + Version: '1.0', + montoAdquisicion: '10000.00', + montoEnajenacion: '0.00', + claveVehicular: 'AAAABBB', + marca: 'FORD', + tipo: 'Mustang', + modelo: '1989', + numeroMotor: '123123123', + numeroSerie: '12312323', + NIV: '1234ASD', + valor: '5000.00', + }); + + cfdi.emisor(emisor) + cfdi.receptor(receptor) + cfdi.concepto(concepto) + cfdi.impuesto(impuestos) + cfdi.complemento(vehiculoUsado) + + cfdi.certificar(cer_path); + + //cfdi.setDebug(true); + await cfdi.sellar(key_path, '12345678a'); + const jsonToXml = cfdi.getXmlCdfi() + expect(jsonToXml.trim()).toBe(expectedXml.trim()); + + }); +}); diff --git a/packages/clir/saxon-he/package.json b/packages/clir/saxon-he/package.json index 960b00b5..4877ad22 100644 --- a/packages/clir/saxon-he/package.json +++ b/packages/clir/saxon-he/package.json @@ -1,5 +1,5 @@ { - "version": "0.0.16-beta.1", + "version": "12.5.0-beta.1", "license": "MIT", "name": "@saxon-he/cli", "main": "./dist/index.js", diff --git a/packages/clir/saxon-he/src/query.ts b/packages/clir/saxon-he/src/query.ts index b60c2582..1fc18c82 100644 --- a/packages/clir/saxon-he/src/query.ts +++ b/packages/clir/saxon-he/src/query.ts @@ -1,6 +1,4 @@ import { CliShare } from './cli-share'; -import { platform } from 'os'; - /** * */ @@ -14,9 +12,10 @@ export class Query extends CliShare { /** *constructor */ - constructor() { + constructor(options: {binary?: string}) { super(); - this.saxonBin = this.getOS(); + const { binary } = options || {} + this.saxonBin = binary || this.getOS(); this.commandline = this.saxonBin; } @@ -128,11 +127,7 @@ export class Query extends CliShare { /** *getOS */ - private getOS(): string { - if (platform() === 'win32') { - return 'query.exe'; - } - + private getOS(): string { return 'query'; } } diff --git a/packages/clir/saxon-he/src/transform.ts b/packages/clir/saxon-he/src/transform.ts index b024e575..05a66bd6 100644 --- a/packages/clir/saxon-he/src/transform.ts +++ b/packages/clir/saxon-he/src/transform.ts @@ -1,6 +1,5 @@ import { CliShare } from './cli-share'; import { existsSync } from 'fs'; -import { platform } from 'os'; /** * @@ -15,9 +14,10 @@ export class Transform extends CliShare { /** *constructor */ - constructor() { + constructor(options?: {binary?: string}) { super(); - this.saxonBin = this.getOS(); + const { binary } = options || {} + this.saxonBin = binary || this.getOS(); this.commandline = this.saxonBin; } @@ -264,11 +264,7 @@ export class Transform extends CliShare { /** *string */ - private getOS(): string { - if (platform() === 'win32') { - return 'transform.exe'; - } - + private getOS(): string { return 'transform'; } } diff --git a/packages/files/4.0/complementos/vehiculousado.xslt b/packages/files/4.0/complementos/vehiculousado.xslt index 1447e9d6..352643be 100644 --- a/packages/files/4.0/complementos/vehiculousado.xslt +++ b/packages/files/4.0/complementos/vehiculousado.xslt @@ -3,9 +3,6 @@ - - - |||