inscripcion al sat
This commit is contained in:
@@ -44,14 +44,14 @@ const obtenerCarrera = async (idCarrera) => {
|
||||
});
|
||||
};
|
||||
|
||||
const usuarioInscrito = async (numeroCuenta, realizoPago) => {
|
||||
const usuarioInscrito = async (numeroCuenta, idArea) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(
|
||||
`INSERT INTO alumno_inscrito(id_cuenta,id_periodo,id_plataforma,realizo_pago,platica) values(${numeroCuenta}, 20, 4, ${realizoPago}, 1)`
|
||||
`INSERT INTO alumno_inscrito(realizo_pago, id_cuenta, id_periodo, id_plataforma) values(1, ${numeroCuenta}, 20, ${idArea})`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
@@ -63,4 +63,28 @@ const usuarioInscrito = async (numeroCuenta, realizoPago) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { obtenerDatosUsr, obtenerCarrera, usuarioInscrito };
|
||||
const agregarRecibo = async (folio, monto, fechaTicket, numeroCuenta) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(
|
||||
`INSERT INTO recibo(folio_recibo, monto, fecha_recibo, id_cuenta) values(${folio}, ${monto}, ${fechaTicket}, ${numeroCuenta})`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
return rows[0];
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
throw new Error('Hubo un problema con el querry.' + err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
obtenerDatosUsr,
|
||||
obtenerCarrera,
|
||||
usuarioInscrito,
|
||||
agregarRecibo,
|
||||
};
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
Reference in New Issue
Block a user