facturacionelectronicapy-ts-xmlgen
Version:
Genera el contenido del archivo XML del Documento electrónico exigido por la SET
422 lines (416 loc) • 15.4 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const xml2js = __importStar(require("xml2js"));
const DateHelper_1 = __importDefault(require("../helpers/DateHelper"));
const CancellationEvent_schema_1 = require("../schemas/events/CancellationEvent.schema");
const DisablingEvent_schema_1 = require("../schemas/events/DisablingEvent.schema");
const Events_1 = require("../types/Events");
const ConformityEvent_schema_1 = require("../schemas/events/ConformityEvent.schema");
const DisconformityEvent_schema_1 = require("../schemas/events/DisconformityEvent.schema");
const IgnoranceEvent_schema_1 = require("../schemas/events/IgnoranceEvent.schema");
const NominationEvent_schema_1 = require("../schemas/events/NominationEvent.schema");
const NotificationEvent_schema_1 = require("../schemas/events/NotificationEvent.schema");
const TransportUpdateEvent_schema_1 = require("../schemas/events/TransportUpdateEvent.schema");
const removeUndefinedValues_1 = require("../helpers/removeUndefinedValues");
/** VER:
* 11. Gestión de eventos
* Tabla J: Resumen de los eventos de SIFEN según los actores
* Tabla K: Correcciones de los eventos del Receptor en el SIFEN
*/
class EventService {
builder = new xml2js.Builder({
xmldec: {
version: '1.0',
encoding: 'UTF-8',
standalone: false,
},
renderOpts: {
// Para firmar tiene que estar normalizado
pretty: false,
},
});
generateXMLEvent(_id, data) {
return new Promise(async (resolve, reject) => {
try {
let xml = await this._generateXMLEvent(_id, data);
// DELETE: una vez este seguro de que no tiene sentido
/* xml = xml.replace(
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>',
'',
); */
resolve(xml);
}
catch (error) {
reject(error);
}
});
}
/**
* Metodo principal de generacion de XML del Evento
* @param params
* @param data
* @returns
*/
_generateXMLEvent(Id, data) {
const result = {
rEnviEventoDe: {
$: {
xmlns: 'http://ekuatia.set.gov.py/sifen/xsd',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
},
dEvReg: {
// GDE000
gGroupGesEve: {
// GDE001
rGesEve: {
$: {
'xsi:schemaLocation': 'http://ekuatia.set.gov.py/sifen/xsd siRecepEvento_v150.xsd',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
},
// GDE002
rEve: {
$: {
// GDE003
Id,
},
// GDE004
dFecFirma: DateHelper_1.default.getIsoDateTime(new Date()),
// GDE005
dVerFor: 150,
// GDE007
gGroupTiEvt: (0, removeUndefinedValues_1.removeUndefinedValues)(this.get_gGroupTiEvt(data)),
// GDE008
Signature: undefined,
},
},
},
},
},
/* // GDE000
gGroupGesEve: {
$: {
xmlns: 'http://ekuatia.set.gov.py/sifen/xsd',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation':
'http://ekuatia.set.gov.py/sifen/xsd/siRecepEvento_v150.xsd',
},
// GDE001
rGesEve: {
// GDE002
rEve: {
$: {
// GDE003
Id: 1,
},
// GDE004
dFecFirma: DateHelper.getIsoDateTime(new Date()),
// GDE005
dVerFor: 150,
// GDE007
gGroupTiEvt: removeUndefinedValues(this.get_gGroupTiEvt(data)),
},
},
}, */
};
return this.builder.buildObject(result); //Para firmar tiene que estar normalizado
}
get_gGroupTiEvt(data) {
switch (data.event) {
case Events_1.SIFENEvent.CANCELACION:
return this.eventoEmisorCancelacion(data);
case Events_1.SIFENEvent.INUTILIZACION:
return this.eventoEmisorInutilizacion(data);
case Events_1.SIFENEvent.CONFORMIDAD:
return this.eventoReceptorConformidad(data);
case Events_1.SIFENEvent.DISCONFORMIDAD:
return this.eventosReceptorDisconformidad(data);
case Events_1.SIFENEvent.DESCONOCIMIENTO:
return this.eventosReceptorDesconocimiento(data);
case Events_1.SIFENEvent.NOTIFICACION:
return this.eventosReceptorNotificacionRecepcion(data);
case Events_1.SIFENEvent.NOMINACION:
return this.eventoEmisorNominacion(data);
case Events_1.SIFENEvent.ACTUALIZACION_DATOS_TRANSPORTE:
return this.eventoEmisorActualizacionDatosTransporte(data);
default:
throw new Error('Tipo de Evento no soportado');
}
}
eventoEmisorCancelacion(data) {
const d = CancellationEvent_schema_1.CancellationEventSchema.parse(data);
return {
// GEC001
rGeVeCan: {
// GEC002
Id: d.cdc,
// GEC003
mOtEve: d.motivo,
},
};
}
eventoEmisorInutilizacion(data) {
const d = DisablingEvent_schema_1.DisablingEventSchema.parse(data);
return {
// GEI001
rGeVeInu: {
// GEI002
dNumTim: d.timbrado,
// GEI003
dEst: d.establecimiento,
// GEI004
dPunExp: d.punto,
// GEI005
dNumIn: d.desde,
// GEI006
dNumFin: d.hasta,
// GEI007
iTiDE: d.tipoDocumento,
// GEI008
mOtEve: d.motivo,
// GEI009
// VER: https://www.dnit.gov.py/documents/20123/420595/NT_E_KUATIA_010_MT_V150.pdf/d64a693b-6c63-86e1-ec6a-d4fe5ec4eeea?t=1687353747196
dSerieNum: d.serie,
},
};
}
eventoReceptorConformidad(data) {
const d = ConformityEvent_schema_1.ConformityEventSchema.parse(data);
return {
// GCO001
rGeVeConf: {
// GCO002
Id: d.cdc,
// GCO003
iTipConf: d.tipoConformidad,
// GCO004
dFecRecep: d.fechaRecepcion,
},
};
}
eventosReceptorDisconformidad(data) {
const d = DisconformityEvent_schema_1.DisconformityEventSchema.parse(data);
return {
// GDI001
rGeVeDisconf: {
// GDI002
Id: d.cdc,
// GDI003
mOtEve: d.motivo,
},
};
}
eventosReceptorDesconocimiento(data) {
const d = IgnoranceEvent_schema_1.IgnoranceEventSchema.parse(data);
return {
// GED001
rGeVeDescon: {
// GED002
Id: d.cdc,
// GED003
dFecEmi: d.fechaEmision,
// GED004
dFecRecep: d.fechaRecepcion,
// GED005
iTipRec: d.contribuyente,
// GED006
dNomRec: d.nombre,
// GED007
dRucRec: d.rucID,
// GED008
dDVRec: d.rucDV,
// GED009
dTipIDRec: d.documentoTipo,
// GED010
dNumID: d.documentoNumero,
// GED011
mOtEve: d.motivo,
},
};
}
eventosReceptorNotificacionRecepcion(data) {
const d = NotificationEvent_schema_1.NotificationEventSchema.parse(data);
return {
// GEN001
rGeVeNotRec: {
// GEN002
Id: d.cdc,
// GEN003
dFecEmi: d.fechaEmision,
// GEN004
dFecRecep: d.fechaRecepcion,
// GEN005
iTipRec: d.contribuyente,
// GEN006
dNomRec: d.nombre,
// GEN007
dRucRec: d.rucID,
// GEN008
dDVRec: d.rucDV,
// GEN009
dTipIDRec: d.documentoTipo,
// GEN010
dNumID: d.documentoNumero,
// GEN011
dTotalGs: d.totalPYG,
},
};
}
// VER: https://www.dnit.gov.py/documents/20123/420595/NT_E_KUATIA_014_MT_V150X.pdf/dbbb0294-8678-357a-1657-bcd0318077f9?t=1706189857282
eventoEmisorNominacion(data) {
const d = NominationEvent_schema_1.NominationEventSchema.parse(data);
return {
// GENFE001
rGEveNom: {
// GENFE002
Id: d.cdc,
// GENFE003
mOtEve: d.motive,
// GENFE004
iNatRec: d.contribuyente,
// GENFE027
iTiOpe: d.tipoOperacion,
// GENFE005
cPaisRec: d.pais,
// GENFE006
dDesPaisRe: d.paisDescripcion,
// GENFE007
iTiContRec: d.tipoReceptor,
// GENFE008
dRucRec: d.rucID,
// GENFE009
dDVRec: d.rucDV,
// GENFE010
iTipIDRec: d.documentoTipo,
// GENFE011
dDTipIDRec: d.descripcionTipoDocumento,
// GENFE012
dNumIDRec: d.documentoNumero,
// GENFE013
dNomRec: d.razonSocial,
// GENFE014
dNomFanRec: d.nombreFantasia,
// GENFE015
dDirRec: d.direccion,
// GENFE016
dNumCasRec: d.numeroCasa,
// GENFE017
cDepRec: d.departamento,
// GENFE018
dDesDepRec: d.descripcionDepartamento,
// GENFE019
cDisRec: d.distrito,
// GENFE020
dDesDisRec: d.descripcionDistrito,
// GENFE021
cCiuRec: d.ciudad,
// GENFE022
dDesCiuRec: d.descripcionCiudad,
// GENFE023
dTelRec: d.telefono,
// GENFE024
dCelRec: d.celular,
// GENFE025
dEmailRec: d.email,
// GENFE026
dCodCliente: d.codigo,
},
};
}
eventoEmisorActualizacionDatosTransporte(data) {
const d = TransportUpdateEvent_schema_1.TransportUpdateEventSchema.parse(data);
const entrega = d.entrega;
const transportista = d.transportista;
const chofer = transportista.chofer;
const vehiculo = entrega.vehiculo;
return {
// GET001
rGeVeTr: {
// GET002
Id: d.cdc,
// GET003
dMotEv: d.motivo,
// GET004
cDepEnt: entrega.departamento,
// GET005
dDesDepEnt: entrega.departamento,
// GET006
cDisEnt: entrega.distrito,
// GET007
dDesDisEnt: entrega.descripcionDistrito,
// GET008
cCiuEnt: entrega.ciudad,
// GET009
dDesCiuEnt: entrega.descripcionCiudad,
// GET010
dDirEnt: entrega.direccion,
// GET011
dNumCas: entrega.numeroCasa,
// GET012
dCompDir1: entrega.direccionComplementaria1,
// GET013
dNomChof: chofer.nombre,
// GET014
dNumIDChof: chofer.documentoNumero,
// GET015
iNatTrans: transportista.contribuyente,
// GET016
dRucTrans: transportista.rucID,
// GET017
dDVTrans: transportista.rucDV,
// GET018
dNomTrans: transportista.nombre,
// GET019
iTipIDTrans: transportista.documentoTipo,
// GET020
dDTipIDTrans: transportista.descripcionTipoDocumento,
// GET021
dNumIDTrans: transportista.documentoNumero,
// GET022
iTipTrans: entrega.tipoTransporte,
// GET023
dDesTipTrans: entrega.descripcionTipoTransporte,
// GET024
iModTrans: entrega.modalidadTransporte,
// GET025
dDesModTrans: entrega.descripcionModalidadTransporte,
// GET026
dTiVehTras: vehiculo.tipo,
// GET027
dMarVeh: vehiculo.marca,
// GET028
dTipIdenVeh: vehiculo.documentoTipo,
// GET029
dNroIDVeh: vehiculo.documentoNumero,
// GET030
dNroMatVeh: vehiculo.numeroMatricula,
},
};
}
}
exports.default = new EventService();