inscripcion al sat

This commit is contained in:
Andres2908
2022-03-23 18:51:32 -06:00
parent 4cdadae9ba
commit b1b2b38d88
2 changed files with 45 additions and 7 deletions
@@ -1,6 +1,12 @@
const moment = require('moment');
const fs = require('fs');
const { validarNumeroEntero, validarNumero } = require('../../helper/validar');
const { usuarioInscrito, agregarRecibo } = require('../../config/mariadb.conf');
const {
validarNumeroEntero,
validarNumero,
validarNumeroCuenta,
validarFecha,
} = require('../../helper/validar');
const { eliminarArchivo } = require('../../helper/helper');
const gmail = require('../../helper/gmail');
const correoInscripciones = require('../../helper/correo');
@@ -10,8 +16,14 @@ const Inscripcion = require(`${dbPath}/Inscripcion`);
const inscripcion = async (body, file) => {
const ahora = moment();
const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true);
const numeroCuenta = validarNumeroCuenta(
body.numeroCuenta,
'numero de cuenta',
true
);
const idArea = validarNumeroEntero(body.idArea, 'id Area', true);
const monto = validarNumero(body.monto, 'monto', true);
const fechaTicket = body.fechaTicket;
const folio = body.folio;
let correo = {};
@@ -26,9 +38,9 @@ const inscripcion = async (body, file) => {
where: { idUsuario, idArea, cancelacion: 0 },
}).then((res) => {
if (res) throw new Error('Ya estas registrado en esta área');
email = `${body.numeroCuenta}@pcpuma.acatlan.unam.mx`;
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
correo = correoInscripciones();
if (file && folio && body.fechaTicket) {
if (file && folio && fechaTicket) {
return Inscripcion.create({
idUsuario,
idArea,
@@ -38,7 +50,7 @@ const inscripcion = async (body, file) => {
rutaTicket: file.path,
extension: file.mimetype.split('/')[1],
fechaInscripcion: ahora.format(),
fechaTicket: body.fechaTicket,
fechaTicket,
});
} else {
return Inscripcion.create({
@@ -53,6 +65,8 @@ const inscripcion = async (body, file) => {
.then((res) => {
if (file)
fs.renameSync(file.path, file.path + '.' + file.mimetype.split('/')[1]);
usuarioInscrito(numeroCuenta, idArea);
agregarRecibo(folio, monto, fechaTicket, numeroCuenta);
return gmail(correo.subject, email, correo.msj);
})
.then((res) => ({