envio-comprobantes-sri
Version:
Envia comprobantes electronicos al SRI (Ecuador). Recibe un objeto JSON. Lo convierte a XML, lo firma, lo envía al servicio web del SRI y devuelve la respuesta.
29 lines (28 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VALIDATION_CURRENCY_NUMBER = exports.MIN_CURRENCY_MANDATORY = exports.MAX_CURRENCY_VALUE = exports.XMLCompatibilityForDecimalPlaces = exports.Transform2Places = exports.REGEXP_ddMMyyyy = exports.REGEXP_NUMERO_COMPROBANTE = void 0;
const class_transformer_1 = require("class-transformer");
exports.REGEXP_NUMERO_COMPROBANTE = /^\d{3}\-\d{3}-\d{9}$/;
exports.REGEXP_ddMMyyyy = /^(?:(?:31(\/)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/;
function Transform2Places(param) {
return (typeof param.value === typeof 1) ? +param.value.toFixed(2) : param.value;
}
exports.Transform2Places = Transform2Places;
/*
* Este es un Helper que al momento de ejecutarse la funcion instanceToPlain
* convertira una clase en texto xml, este helper convertira todos los atributos asociados a este helper
* en un String con 2 decimales, ejemplo, si es '0' -> '0.00', si es , '3.1548' -> '3.15'
*/
function XMLCompatibilityForDecimalPlaces() {
return (0, class_transformer_1.Transform)(({ value }) => {
if (typeof value === "number") {
// siempre number para class-validator
return value.toFixed(2);
}
return value;
}, { toPlainOnly: true });
}
exports.XMLCompatibilityForDecimalPlaces = XMLCompatibilityForDecimalPlaces;
exports.MAX_CURRENCY_VALUE = 99999999999.99;
exports.MIN_CURRENCY_MANDATORY = 0.01;
exports.VALIDATION_CURRENCY_NUMBER = { maxDecimalPlaces: 2, allowInfinity: false, allowNaN: false };