diff --git a/files/fichasDeposito/ficha-1.pdf b/files/fichasDeposito/ficha-1.pdf index 213eb18..5a94dbb 100644 Binary files a/files/fichasDeposito/ficha-1.pdf and b/files/fichasDeposito/ficha-1.pdf differ diff --git a/files/fichasDeposito/ficha-undefined.pdf b/files/fichasDeposito/ficha-undefined.pdf new file mode 100644 index 0000000..f299acd Binary files /dev/null and b/files/fichasDeposito/ficha-undefined.pdf differ diff --git a/files/recibos/recibo-1.pdf b/files/recibos/recibo-1.pdf new file mode 100644 index 0000000..48ef509 Binary files /dev/null and b/files/recibos/recibo-1.pdf differ diff --git a/files/recibos/recibo-undefined.pdf b/files/recibos/recibo-undefined.pdf new file mode 100644 index 0000000..48ef509 Binary files /dev/null and b/files/recibos/recibo-undefined.pdf differ diff --git a/routes/enviar.js b/routes/enviar.js new file mode 100644 index 0000000..8a5f45e --- /dev/null +++ b/routes/enviar.js @@ -0,0 +1,149 @@ + +const connection = require('../conf/connection.js');; +const express = require('express'); +const fileUpload = require('express-fileupload'); +var path = require('path'); +const nodemailer = require("nodemailer"); +const fs = require("fs"); +var app = express() +app.use(fileUpload()); + +function query(consulta) { + return new Promise(function(resolve, reject) { + connection.query(`${consulta}`, (error, results, files) => { + if (error) reject(error); + resolve(results); + }); + }) +} + +function depurado(cadena) { + if (cadena != null) + return cadena.replace(/'/g, "''"); + else + return null; +} + +async function sendEmail( destination, idPersona ) { + + // Generate test SMTP service account from ethereal.email + // Only needed if you don't have a real mail account for testing + let testAccount = await nodemailer.createTestAccount(); + + // create reusable transporter object using the default SMTP transport + let transporter = nodemailer.createTransport({ + service: "Gmail", + port: 587, + secure: false, // true for 465, false for other ports + auth: { + user: 'asinea103@fa.unam.mx', // generated ethereal user + pass: 'As1n34103++' + }, + }); + + // send mail with defined transport object + let info = await transporter.sendMail({ + from: '"ASINEA 2020" ', // sender address + to: `"${destination}"`, // list of receivers + subject: "Ficha de deposito ASINEA 2020", // Subject line + text: ` + La referencia tiene una vigencia de 3 días. En este lapso deberá enviar su comprobante para poder validar que el pago fue realizado correctamente + + Una vez realizado el pago, deberá ingresar nuevamente a la plataforma y adjuntar el voucher o imagen del pago realizado con los siguientes datos: + + -Número de referencia o convenio + -Banco de procedencia + -Fecha de la operación + -Clave de rastreo + -Cuenta de retiro + -Cuenta de depósito e importe. + + + De no tener estos datos, su pago no podrá ser rastreado. + `, // plain text body + attachments: [{ // file on disk as an attachment + filename: 'ficha de deposito.pdf', + path: `${path.join('./files/fichasDeposito', `ficha-${idPersona}.pdf`)}`// stream this file + }] + + }); + + console.log("Message sent: %s", info.messageId); + // Message sent: + + // Preview only available when sending through an Ethereal account + console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); + // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... +} + +app.post('/enviar', async(req, res) => { + console.log(req.files); + console.log(req.body); + if ( req.files === null || req.files.fichaDeposito === null || typeof(req.files) === 'undefined' || typeof(req.files.fichaDeposito) === 'undefined' ) { + res.status(400).json({error: true, msj: 'Falata seleccionar el archivo'}); + return; + } + try { + console.log(req.files); + if (req.files.fichaDeposito != undefined) { + let sampleFile = req.files.fichaDeposito; + let nombreCortado = sampleFile.name.split('.'); + let extencion = nombreCortado[nombreCortado.length - 1]; + let extensionValidas = ['pdf', 'jpg', 'jpeg', 'png', 'docx', 'doc', 'odt', 'pdf']; + + if (extensionValidas.indexOf(extencion) < 0) { + return res.status(400).json({ + error: true, + msj: "Extensión invalida del archivo de fichaDeposito" + }); + } + } + + + + } catch (err) { + console.log(err); + return res.status(400).json({ + error: true, + msj: "error al verificar la extensión" + }); + } + let idPersona = req.body.idPersona; + let correo = req.body.correo; + + try { + + console.log(req.body) + if (req.files.fichaDeposito != undefined) { + let sampleFile = req.files.fichaDeposito; + + sampleFile.mv( path.join('./files/fichasDeposito', `ficha-${idPersona}.pdf`), function(err) { + if (err) + return res.status(400).json({ error: true, msj: "Error al registrar el cartel" }); + + }); + await sendEmail('daniel.adrian.ramirez.george@gmail.com', idPersona); + + let sqlString = `update persona set referenciaEnviada = true where idPersona=${idPersona}`; + + await query(sqlString); + + + } + + } catch (err) { + console.log(err); + res.status(400).json({ error: true, msj: "Error al subir el archivo de comprobante_pago", type: err }); + return; + } + + + + + + res.status(200).json({ error: false, msj: "exito " }); + return; + +}); + +module.exports = app; \ No newline at end of file diff --git a/routes/enviarFicha.js b/routes/enviarFicha.js index 3a1bf3d..5048675 100644 --- a/routes/enviarFicha.js +++ b/routes/enviarFicha.js @@ -4,7 +4,6 @@ const fileUpload = require('express-fileupload'); var path = require('path'); const nodemailer = require("nodemailer"); const fs = require("fs"); - var app = express() app.use(fileUpload()); @@ -17,7 +16,6 @@ function query(consulta) { }) } - function depurado(cadena) { if (cadena != null) return cadena.replace(/'/g, "''"); @@ -25,8 +23,6 @@ function depurado(cadena) { return null; } - - async function sendEmail( destination, idPersona ) { // Generate test SMTP service account from ethereal.email @@ -79,14 +75,10 @@ async function sendEmail( destination, idPersona ) { // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... } - - - - - app.post('/enviarFicha', async(req, res) => { - - if ( req.files === null || req.files.fichaDeposito === null || typeof(req.files) === 'undefined' || typeof(req.files.fichaDeposito) === 'undefined' ) { + console.log(req.files); + console.log(req.body); + if ( req.files === null || typeof(req.files) === 'undefined' ) { res.status(400).json({error: true, msj: 'Falata seleccionar el archivo'}); return; } @@ -115,13 +107,14 @@ app.post('/enviarFicha', async(req, res) => { msj: "error al verificar la extensión" }); } - let idPersona = req.body.idPersona; - let correo = req.body.correo; + try { console.log(req.body) if (req.files.fichaDeposito != undefined) { + let idPersona = req.body.idPersona; + let correo = req.body.correo; let sampleFile = req.files.fichaDeposito; sampleFile.mv( path.join('./files/fichasDeposito', `ficha-${idPersona}.pdf`), function(err) { @@ -144,6 +137,99 @@ app.post('/enviarFicha', async(req, res) => { return; } + try { + + console.log(req.body) + if (req.files.fichaDeposito != undefined) { + + let idPersona = req.body.idPersona; + let correo = req.body.correo; + let sampleFile = req.files.fichaDeposito; + + sampleFile.mv( path.join('./files/fichasDeposito', `ficha-${idPersona}.pdf`), function(err) { + if (err) + return res.status(400).json({ error: true, msj: "Error al registrar el cartel" }); + + }); + await sendEmail(correo, idPersona); + + let sqlString = `update persona set referenciaEnviada = true where idPersona=${idPersona}`; + + await query(sqlString); + + + } + + } catch (err) { + console.log(err); + res.status(400).json({ error: true, msj: "Error al subir el archivo de comprobante_pago", type: err }); + return; + } + + + try { + + console.log(req.body) + if (req.files.reciboPago != undefined) { + + let sampleFile = req.files.reciboPago; + console.log('este es el body antes', req.body); + //req.body = req.body.datos; + let body = req.body; + console.log('este es el body despues', body); + for( item in body){ + console.log(`${item} : ${body[item]}`); + } + let idPersona= body.idPersona; + + sampleFile.mv( path.join('./files/recibos', `recibo-${idPersona}.pdf`), function(err) { + if (err) + return res.status(400).json({ error: true, msj: "Error al registrar el cartel" }); + + }); + + + let sqlString = `update persona set envioComprobante = true where idPersona=${idPersona}`; + await query(sqlString); + + + // CREATE TABLE `comprobante` ( `idComprobante` integer `idPersona` int, `bancoProcedencia` varchar(250), `fechaOperacion` date, `claveRastreo` varchar(250), `cuentaRetiro` varchar(250), `importe` varchar(250), `cuentaDeposito` varchar(250) + + + sqlString = `INSERT INTO comprobante values (null, ${idPersona}, '${ body.bancoProcedencia }', '${ body.fechaOperacion }', '${ body.claveRastreo }', '${ body.cuentaRetiro }', '${ body.importe }', '${ body.cuentaDeposito }' ) ;`; + await query(sqlString); + + if( typeof(body.factura) !== 'undefined' ){ + + + sqlString = `update persona set requiereFactura = true where idPersona=${idPersona}`; + await query(sqlString); + + + // CREATE TABLE `factura` ( `idFactura` integer , `idPersona` int, `rfc` varchar(255), `telefono` varchar(255), `correo` varchar(255), `nombre` varchar(255), ` apellidoPaterno` varchar(255), `apellidoMaterno` varchar(255), `calle` varchar(255), `noInterior` varchar(255), `noExterior` varchar(255), `colonia` varchar(255), `municipio` varchar(255), `estado` varchar(255), `codigoPostal` varchar(255) + + + sqlString = `INSERT INTO factura values (null, ${idPersona}, '${ body.rfc }', '${ body.telefono }', '${ body.correoPersona }', '${ body.nombrePersona }', '${ body.apellidoPaterno }', '${ body.apellidoMaterno }', '${ body.calle }', '${ body.noInterior }' , '${ body.noExterior }', '${ body.colonia }', '${ body.municipio }', '${ body.estado }', '${ body.codigoPostal }' ) ;`; + await query(sqlString); + + res.status(200).json({ error: false, msj: "exito " }); + return; + + + } + + + + } + + } catch (err) { + console.log(err); + res.status(400).json({ error: true, msj: "Error al subir el archivo de comprobante_pago", type: err }); + return; + } + + + @@ -153,4 +239,4 @@ app.post('/enviarFicha', async(req, res) => { }); -module.exports = app \ No newline at end of file +module.exports = app; \ No newline at end of file diff --git a/routes/enviarRecibo.js b/routes/enviarRecibo.js new file mode 100644 index 0000000..773122b --- /dev/null +++ b/routes/enviarRecibo.js @@ -0,0 +1,172 @@ +const connection = require('../conf/connection.js');; +const express = require('express'); +const fileUpload = require('express-fileupload'); +var path = require('path'); +const nodemailer = require("nodemailer"); +const fs = require("fs"); +var app = express() +app.use(fileUpload()); + +function query(consulta) { + return new Promise(function(resolve, reject) { + connection.query(`${consulta}`, (error, results, files) => { + if (error) reject(error); + resolve(results); + }); + }) +} + +function depurado(cadena) { + if (cadena != null) + return cadena.replace(/'/g, "''"); + else + return null; +} + +async function sendEmail( destination, idPersona ) { + + // Generate test SMTP service account from ethereal.email + // Only needed if you don't have a real mail account for testing + let testAccount = await nodemailer.createTestAccount(); + + // create reusable transporter object using the default SMTP transport + let transporter = nodemailer.createTransport({ + service: "Gmail", + port: 587, + secure: false, // true for 465, false for other ports + auth: { + user: 'asinea103@fa.unam.mx', // generated ethereal user + pass: 'As1n34103++' + }, + }); + + // send mail with defined transport object + let info = await transporter.sendMail({ + from: '"ASINEA 2020" ', // sender address + to: `"${destination}"`, // list of receivers + subject: "Ficha de deposito ASINEA 2020", // Subject line + text: ` + La referencia tiene una vigencia de 3 días. En este lapso deberá enviar su comprobante para poder validar que el pago fue realizado correctamente + + Una vez realizado el pago, deberá ingresar nuevamente a la plataforma y adjuntar el voucher o imagen del pago realizado con los siguientes datos: + + -Número de referencia o convenio + -Banco de procedencia + -Fecha de la operación + -Clave de rastreo + -Cuenta de retiro + -Cuenta de depósito e importe. + + + De no tener estos datos, su pago no podrá ser rastreado. + `, // plain text body + attachments: [{ // file on disk as an attachment + filename: 'ficha de deposito.pdf', + path: `${path.join('./files/fichasDeposito', `ficha-${idPersona}.pdf`)}`// stream this file + }] + + }); + + console.log("Message sent: %s", info.messageId); + // Message sent: + + // Preview only available when sending through an Ethereal account + console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); + // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... +} + +app.post('/enviarRecibo', async(req, res) => { + console.log(req.files); + console.log(req.body); + if ( req.files === null || req.files.fichaDeposito === null || typeof(req.files) === 'undefined' || typeof(req.files.fichaDeposito) === 'undefined' ) { + res.status(400).json({error: true, msj: 'Falata seleccionar el archivo'}); + return; + } + try { + console.log(req.files); + if (req.files.fichaDeposito != undefined) { + let sampleFile = req.files.fichaDeposito; + let nombreCortado = sampleFile.name.split('.'); + let extencion = nombreCortado[nombreCortado.length - 1]; + let extensionValidas = ['pdf', 'jpg', 'jpeg', 'png', 'pdf']; + + if (extensionValidas.indexOf(extencion) < 0) { + return res.status(400).json({ + error: true, + msj: "Extensión invalida del archivo de fichaDeposito" + }); + } + } + + + + } catch (err) { + console.log(err); + return res.status(400).json({ + error: true, + msj: "error al verificar la extensión" + }); + } + let idPersona = req.body.idPersona; + + + try { + + console.log(req.body) + if (req.files.fichaDeposito != undefined) { + let sampleFile = req.files.fichaDeposito; + + sampleFile.mv( path.join('./files/recibos', `deposito-${idPersona}.pdf`), function(err) { + if (err) + return res.status(400).json({ error: true, msj: "Error al registrar el cartel" }); + + }); + + let sqlString = `update persona set envioComprobante = true where idPersona=${idPersona}`; + await query(sqlString); + + + // CREATE TABLE `comprobante` ( `idComprobante` integer `idPersona` int, `bancoProcedencia` varchar(250), `fechaOperacion` date, `claveRastreo` varchar(250), `cuentaRetiro` varchar(250), `importe` varchar(250), `cuentaDeposito` varchar(250) + + + sqlString = `INSERT INTO comprobante values (null, ${idPersona}, '${ req.body.bancoProcedencia }', '${ req.body.fechaOperacion }', '${ req.body.claveRastreo }', '${ req.body.cuentaRetiro }', '${ req.body.importe }', '${ req.body.cuentaDeposito }' ) ;`; + await query(sqlString); + + if( typeof(req.body.factura) !== 'undefined' ){ + + + sqlString = `update persona set requiereFactura = true where idPersona=${idPersona}`; + await query(sqlString); + + + // CREATE TABLE `factura` ( `idFactura` integer , `idPersona` int, `rfc` varchar(255), `telefono` varchar(255), `correo` varchar(255), `nombre` varchar(255), ` apellidoPaterno` varchar(255), `apellidoMaterno` varchar(255), `calle` varchar(255), `noInterior` varchar(255), `noExterior` varchar(255), `colonia` varchar(255), `municipio` varchar(255), `estado` varchar(255), `codigoPostal` varchar(255) + + + sqlString = `INSERT INTO factura values (null, ${idPersona}, '${ req.body.rfc }', '${ req.body.telefono }', '${ req.body.correoPersona }', '${ req.body.nombrePersona }', '${ req.body.apellidoPaterno }', '${ req.body.apellidoMaterno }', '${ req.body.calle }', '${ req.body.noInterior }' , '${ req.body.noExterior }', '${ req.body.colonia }', '${ req.body.municipio }', '${ req.body.estado }', '${ req.body.codigoPostal }' ) ;`; + await query(sqlString); + + res.status(200).json({ error: false, msj: "exito " }); + return; + + + } + + + } + + } catch (err) { + console.log(err); + res.status(400).json({ error: true, msj: "Error al subir el archivo de comprobante_pago", type: err }); + return; + } + + + + + + res.status(200).json({ error: false, msj: "exito " }); + return; + +}); + +module.exports = app; \ No newline at end of file diff --git a/routes/getPersona.js b/routes/getPersona.js index 2e933f1..25327c8 100644 --- a/routes/getPersona.js +++ b/routes/getPersona.js @@ -25,13 +25,13 @@ app.get('/getPersona', async(req, res) => { let sqlString = `SELECT * FROM persona WHERE idPersona = ${idPersona };`; let datosPersona = await query(sqlString); datosPersona = datosPersona[0]; - console.log(sqlString); - console.log(datosPersona); + // console.log(sqlString); + // console.log(datosPersona); sqlString = `SELECT * from asistencia where idPersona = ${idPersona};`; let eventos = await query (sqlString); - console.log(sqlString); - console.log(eventos); + // console.log(sqlString); + // console.log(eventos); let registrado = []; diff --git a/routes/getPersonasRecibo.js b/routes/getPersonasRecibo.js new file mode 100644 index 0000000..275bb51 --- /dev/null +++ b/routes/getPersonasRecibo.js @@ -0,0 +1,46 @@ +const connection = require('../conf/connection.js'); +const express = require('express'); + + +var app = express() + +function query(consulta) { + return new Promise(function(resolve, reject) { + connection.query(`${consulta}`, (error, results, files) => { + if (error) reject(error); + resolve(results); + }); + }) +} + +app.get('/getPersonasRecibo', async(req, res) => { + try { + + + + let sqlString = `SELECT * FROM persona WHERE envioComprobante = true and validarPago = false and rechazado = false ;`; + let personasInscritas = await query(sqlString); + + //console.log(personasInscritas); + + for( let item in personasInscritas ){ + let idPersona = personasInscritas[item].idPersona; + sqlString = `SELECT * from comprobante where idPersona = ${idPersona}; `; + let ansSql = await query(sqlString); + ansSql = ansSql[0]; + personasInscritas[item].comprobante = ansSql; + + } + + res.status(200).json({error: false, msj: '', datos: personasInscritas }); + + + } + catch(error){ + console.log(error); + res.status(400).json({ error: true, msj: `Sucedio un error al traer a las personas inscritas msj: ${error}` }); + return; + } +}); + +module.exports = app; diff --git a/routes/index.js b/routes/index.js index 5cf685d..ad1c867 100644 --- a/routes/index.js +++ b/routes/index.js @@ -9,7 +9,12 @@ app.use(require('./registro')); app.use(require('./getPersona')); app.use(require('./getPersonasInscritas')); +app.use(require('./getPersonasRecibo')); app.use(require('./enviarFicha')); +app.use(require('./enviarRecibo')); +app.use(require('./enviar')); app.use(require('./getPersonasPendientes')); + + module.exports = app; \ No newline at end of file diff --git a/sql/database.sql b/sql/database.sql index 10d6bb1..99e398e 100644 --- a/sql/database.sql +++ b/sql/database.sql @@ -23,6 +23,7 @@ CREATE TABLE `asistencia` ( -- INSERT INTO admin VALUES (null, 'Administrador' , '$2b$10$tUzaWli0CUzGnoZ1saxSF.RRtxDcdgRP0tQOQdmqbVG1fiz4jCMLW'); +-- node -- Asin34#2020 INSERT INTO admin VALUES (null, 'Administrador' , '$2b$10$Kv7tMorEyGL934RK.oaQiOSaGiJr56JDT5PxgAcnVAdpIiYRyBAaS'); @@ -50,7 +51,7 @@ CREATE TABLE `persona` ( `envioComprobante` boolean, `referenciaEnviada` boolean, `validarPago` boolean, - `rechazado` boolean, + `rechazado` boolean ); CREATE TABLE `evento` ( @@ -64,6 +65,17 @@ CREATE TABLE `evento` ( ); +CREATE TABLE `comprobante` ( + `idComprobante` integer PRIMARY KEY NOT NULL AUTO_INCREMENT, + `idPersona` int, + `bancoProcedencia` varchar(250), + `fechaOperacion` date, + `claveRastreo` varchar(250), + `cuentaRetiro` varchar(250), + `importe` varchar(250), + `cuentaDeposito` varchar(250) +); + CREATE TABLE `factura` ( `idFactura` integer PRIMARY KEY NOT NULL AUTO_INCREMENT, @@ -89,6 +101,7 @@ ALTER TABLE `asistencia` ADD FOREIGN KEY (`idPersona`) REFERENCES `persona` (`id ALTER TABLE `asistencia` ADD FOREIGN KEY (`idEvento`) REFERENCES `evento` (`idEvento`); +ALTER TABLE `comprobante` ADD FOREIGN KEY (`idPersona`) REFERENCES `persona` (`idPersona`); insert into universidad values (null ,'UNIVERSIDAD AUTÓNOMA DE BAJA CALIFORNIA'); @@ -287,7 +300,7 @@ insert into evento values (null, 'Estudios de practica', '11 ESTUDIO Sensorial S insert into evento values (null, 'Recorridos', 'Candela', 'Ambos', 100 , null, 100 ); -insert into evento values (null, 'Recorridos', 'Campus Central C.U. UNAM Patrimonio Mundial de la UNESCO ', 'Ambos', 100 , null, 100 ); +insert into evento values (null, 'Recorridos', 'Campus Central C.U. UNAM Patrimonio Mundial de la UNESCO', 'Ambos', 100 , null, 100 ); insert into evento values (null, 'Recorridos', 'Museos de la UNAM', 'Ambos', 100 , null, 100 );