UNPKG

facturacionelectronicapy-ts-xmlgen

Version:

Genera el contenido del archivo XML del Documento electrónico exigido por la SET

95 lines (94 loc) 3.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.IgnoranceEventSchema = void 0; const zod_1 = require("zod"); const CommonValidators_1 = __importDefault(require("../../helpers/validation/CommonValidators")); const taxpayerNotTaxpayer_table_1 = require("../../data/taxpayerNotTaxpayer.table"); const ZodValidator_1 = __importDefault(require("../../helpers/validation/ZodValidator")); const idDocsCarriers_table_1 = require("../../data/idDocsCarriers.table"); const Path_1 = require("../../helpers/Path"); const SDParser_1 = __importDefault(require("../../helpers/SDParser")); // GED001 exports.IgnoranceEventSchema = zod_1.z .object({ // GED002 cdc: CommonValidators_1.default.cdc().describe(SDParser_1.default.stringify('GED002')), // GED003 fechaEmision: CommonValidators_1.default.isoDateTime().describe(SDParser_1.default.stringify('GED003')), // GED004 fechaRecepcion: CommonValidators_1.default.isoDateTime().describe(SDParser_1.default.stringify('GED004')), // GED005 contribuyente: CommonValidators_1.default.taxpayer().describe(SDParser_1.default.stringify('GED005')), // GED006 nombre: CommonValidators_1.default.name().describe(SDParser_1.default.stringify('GED006')), // para calcular GED007 y GED008 ruc: CommonValidators_1.default.ruc() .optional() .describe(SDParser_1.default.stringify('GED007 y GED008')), // GED009 documentoTipo: zod_1.z .nativeEnum(idDocsCarriers_table_1.IdentityDocumentCarrier) .optional() .describe(SDParser_1.default.stringify('GED009', { e: 'IdentityDocumentCarrier' })), // GED010 documentoNumero: CommonValidators_1.default.identityDocNumber() .optional() .describe(SDParser_1.default.stringify('GED010')), // GED011 motivo: CommonValidators_1.default.motive() .optional() .describe(SDParser_1.default.stringify('GED011')), }) .transform((data, ctx) => { const validator = new ZodValidator_1.default(ctx, data); /**GED005=1 */ const isTaxpayer = data.contribuyente == taxpayerNotTaxpayer_table_1.TaxpayerNotTaxpayer.CONTRIBUYENTE; /**GED005=2 */ const isNotTaxpayer = data.contribuyente == taxpayerNotTaxpayer_table_1.TaxpayerNotTaxpayer.NO_CONTRIBUYENTE; // ⚠️ esto no esta en el manual { const emission = new Date(data.fechaEmision); const reception = new Date(data.fechaRecepcion); const receptionDatePath = new Path_1.Path('fechaRecepcion'); validator.validate('fechaEmision', emission > reception, `$path no puede ser después de '${receptionDatePath}'`); } // GED007 y GED008 - ruc { /* Requerido solo cuando el tipo de receptor es Contribuyente (GED005=1) No Informar si GED005=2 */ if (isTaxpayer) { validator.requiredField('ruc'); } else if (isNotTaxpayer) { validator.undesiredField('ruc'); } } // GED009 y GED010 - documentoTipo y documentoNumero { /* No Informar si GED005=1 Requerido solo cuando el tipo de receptor es No Contribuyente (GED005=2) */ if (isNotTaxpayer) { validator.requiredField('documentoTipo'); } else if (isTaxpayer) { validator.undesiredField('documentoTipo'); } } const [rucID, rucDV] = data.ruc?.split('-') ?? []; return { ...data, // GED007 rucID: rucID, // GED008 rucDV: rucDV, }; });