Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/config/rush/version-policies.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions packages/cfdi/xml/src/cfdi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand All @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 5 additions & 11 deletions packages/cfdi/xml/src/elements/Comprobante.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CFDIComprobante,
ComprobanteAttributes,
Options,
Config,
TagComprobante,
XmlCdfi,
XmlComprobante,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -266,20 +266,14 @@ export class Comprobante {
* @param complements
* ComlementType
*/
public async complemento(complements: ComlementType): Promise<void> {
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 {
Expand Down
25 changes: 17 additions & 8 deletions packages/cfdi/xml/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/cfdi/xml/test/facturas/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
138 changes: 138 additions & 0 deletions packages/cfdi/xml/test/facturas/vehiculo-usado.test.ts
Original file line number Diff line number Diff line change
@@ -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 = `
<?xml version="1.0" encoding="utf-8"?>
<cfdi:Comprobante xsi:schemaLocation="http://www.sat.gob.mx/cfd/4 http://www.sat.gob.mx/sitio_internet/cfd/4/cfdv40.xsd http://www.sat.gob.mx/vehiculousado http://www.sat.gob.mx/sitio_internet/cfd/vehiculousado/vehiculousado.xsd" Version="4.0" Serie="Serie" Folio="Folio" Fecha="2024-03-01T00:00:00" Sello="AGrVIoICykiW6PO7p+LxtUW3LoEI1lAEBUuPZKz1k7Yz0zU7KiJajYY0lTVSHmARgfkm+af+HADz1E0wFBbDpCBG5U9P0HH0tlAh+v0+FaTHatRrxvUh2AyNsHFOKfgQe8bC2Z+rkE9MngW60yhQsccPihZooIq53b0766ib9uGKZQ+kfH8qf+6oKCF375bFGKNXc7RkoFHKliFJQjJbpISZe1YpuKNCe3LSUA/oUL4ZD9bQp55dSLjh/CfBnloovBIRd5v9g7BVrGE17ITjIDPgondThFiuEM+ZHBTtjJ71WlSjK6pFkizxJvuHHDFr5bkTPFqNhuKMNl26HWkJ6g==" FormaPago="99" NoCertificado="20001000000300022815" Certificado="MIIFxTCCA62gAwIBAgIUMjAwMDEwMDAwMDAzMDAwMjI4MTUwDQYJKoZIhvcNAQELBQAwggFmMSAwHgYDVQQDDBdBLkMuIDIgZGUgcHJ1ZWJhcyg0MDk2KTE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Z88dKHwqxEkwzhMyTbQIDAQABox0wGzAMBgNVHRMBAf8EAjAAMAsGA1UdDwQEAwIGwDANBgkqhkiG9w0BAQsFAAOCAgEAJ/xkL8I+fpilZP+9aO8n93+20XxVomLJjeSL+Ng2ErL2GgatpLuN5JknFBkZAhxVIgMaTS23zzk1RLtRaYvH83lBH5E+M+kEjFGp14Fne1iV2Pm3vL4jeLmzHgY1Kf5HmeVrrp4PU7WQg16VpyHaJ/eonPNiEBUjcyQ1iFfkzJmnSJvDGtfQK2TiEolDJApYv0OWdm4is9Bsfi9j6lI9/T6MNZ+/LM2L/t72Vau4r7m94JDEzaO3A0wHAtQ97fjBfBiO5M8AEISAV7eZidIl3iaJJHkQbBYiiW2gikreUZKPUX0HmlnIqqQcBJhWKRu6Nqk6aZBTETLLpGrvF9OArV1JSsbdw/ZH+P88RAt5em5/gjwwtFlNHyiKG5w+UFpaZOK3gZP0su0sa6dlPeQ9EL4JlFkGqQCgSQ+NOsXqaOavgoP5VLykLwuGnwIUnuhBTVeDbzpgrg9LuF5dYp/zs+Y9ScJqe5VMAagLSYTShNtN8luV7LvxF9pgWwZdcM7lUwqJmUddCiZqdngg3vzTactMToG16gZA4CWnMgbU4E+r541+FNMpgAZNvs2CiW/eApfaaQojsZEAHDsDv4L5n3M1CC7fYjE/d61aSng1LaO6T1mh+dEfPvLzp7zyzz+UgWMhi5Cs4pcXx1eic5r7uxPoBwcCTt3YI1jKVVnV7/w=" CondicionesDePago="CondicionesDePago" SubTotal="2000" Moneda="MXN" TipoCambio="1" Total="2000.16" TipoDeComprobante="I" Exportacion="01" MetodoPago="PUE" LugarExpedicion="20000" xmlns:cfdi="http://www.sat.gob.mx/cfd/4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vehiculousado="http://www.sat.gob.mx/vehiculousado">
<cfdi:Emisor Rfc="EKU9003173C9" Nombre="ESCUELA KEMPER URGATE" RegimenFiscal="601"/>
<cfdi:Receptor Rfc="URE180429TM6" Nombre="UNIVERSIDAD ROBOTICA ESPAÑOLA" DomicilioFiscalReceptor="86991" RegimenFiscalReceptor="601" UsoCFDI="S01"/>
<cfdi:Conceptos>
<cfdi:Concepto ClaveProdServ="50211503" Cantidad="1" ClaveUnidad="H87" Unidad="Servicio" Descripcion="Servicio" ValorUnitario="200.00" Importe="200.00" ObjetoImp="02">
<cfdi:Impuestos>
<cfdi:Traslados>
<cfdi:Traslado Base="1" Impuesto="002" TipoFactor="Tasa" TasaOCuota="0.160000" Importe="0.16"/>
</cfdi:Traslados>
</cfdi:Impuestos>
</cfdi:Concepto>
</cfdi:Conceptos>
<cfdi:Impuestos TotalImpuestosTrasladados="0.16">
<cfdi:Traslados>
<cfdi:Traslado Base="1" Impuesto="002" TipoFactor="Tasa" TasaOCuota="0.160000" Importe="0.16"/>
</cfdi:Traslados>
</cfdi:Impuestos>
<cfdi:Complemento>
<vehiculousado: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:Complemento>
</cfdi:Comprobante>`;

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());

});
});
2 changes: 1 addition & 1 deletion packages/clir/saxon-he/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 4 additions & 9 deletions packages/clir/saxon-he/src/query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { CliShare } from './cli-share';
import { platform } from 'os';

/**
*
*/
Expand All @@ -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;
}

Expand Down Expand Up @@ -128,11 +127,7 @@ export class Query extends CliShare {
/**
*getOS
*/
private getOS(): string {
if (platform() === 'win32') {
return 'query.exe';
}

private getOS(): string {
return 'query';
}
}
12 changes: 4 additions & 8 deletions packages/clir/saxon-he/src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CliShare } from './cli-share';
import { existsSync } from 'fs';
import { platform } from 'os';

/**
*
Expand All @@ -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;
}

Expand Down Expand Up @@ -264,11 +264,7 @@ export class Transform extends CliShare {
/**
*string
*/
private getOS(): string {
if (platform() === 'win32') {
return 'transform.exe';
}

private getOS(): string {
return 'transform';
}
}
3 changes: 0 additions & 3 deletions packages/files/4.0/complementos/vehiculousado.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

<!-- Con el siguiente método se establece que la salida deberá ser en texto -->
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>

<!-- Aquí iniciamos el procesamiento de la cadena original con su | inicial y el terminador || -->
<xsl:template match="/">|<xsl:apply-templates select="/vehiculousado:VehiculoUsado"/>||</xsl:template>
<!-- Aquí iniciamos el procesamiento de los datos incluidos en el comprobante -->
<xsl:template match="vehiculousado:VehiculoUsado">
<!-- Iniciamos el tratamiento de los atributos de comprobante -->
Expand Down