241 lines
6.1 KiB
JavaScript
241 lines
6.1 KiB
JavaScript
'use strict';
|
|
const connection = require('../conf/connection.js');
|
|
const express = require('express');
|
|
var qr = require('qr-image');
|
|
const fs = require('fs');
|
|
const PDFDocument = require('./pdfkit-tables');
|
|
|
|
function query(consulta) {
|
|
return new Promise(function(resolve, reject) {
|
|
connection.query(`${consulta}`, (error, results, files) => {
|
|
if (error) reject(error);
|
|
resolve(results);
|
|
});
|
|
})
|
|
}
|
|
|
|
|
|
let c_pdf = function(id_persona) {
|
|
return new Promise(async function(resolve, reject) {
|
|
|
|
let doc = new PDFDocument();
|
|
let inicio = 120;
|
|
// let cad = `select * from persona where id_persona=${id_persona}`;
|
|
// let resp = await query(cad);
|
|
// let data = resp[var i_m = require('./g_img.js');0];
|
|
|
|
|
|
doc.pipe(fs.createWriteStream(__dirname + `/../files/lista-${id_persona}.pdf`));
|
|
|
|
|
|
doc.image(__dirname + '/Imagenes/logo_unam.png', inicio, 30, { scale: 0.04 });
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(10)
|
|
.text('UNIVERSIDAD NACIONAL AUTONOMA DE MEXICO', inicio + 60, 40);
|
|
doc.font('Times-Roman')
|
|
.fontSize(10)
|
|
.text('FACULTAD DE ESTUDIOS SUPERIORES ACATLÁN', inicio + 66, 50);
|
|
doc.font('Times-Roman')
|
|
.fontSize(10)
|
|
.text('COLOQUIO INTERNACIONAL DE EDUCACION', inicio + 72, 60);
|
|
|
|
doc.image(__dirname + '/Imagenes/Fes-aniversario.png', inicio + 305, 28, { scale: 0.035 });
|
|
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(8)
|
|
.text('COMPROBANTE DE INSCRIPCIÓN', inicio + 120, 80);
|
|
|
|
doc.moveTo(70, 110)
|
|
.lineTo(542, 110);
|
|
|
|
|
|
var datetime = new Date();
|
|
console.log(datetime);
|
|
let d = datetime.getDate();
|
|
let m = datetime.getMonth();
|
|
m++;
|
|
let a = datetime.getFullYear();
|
|
if (d < 10) {
|
|
let aux = `0${d}`;
|
|
d = aux;
|
|
|
|
}
|
|
if (m < 10) {
|
|
let aux = `0${m}`;
|
|
m = aux;
|
|
|
|
}
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(13)
|
|
.text(`${d}/${m}/${a}`, inicio + 305, 120);
|
|
let marg = 70;
|
|
|
|
doc.image(qr.imageSync(`${id_persona}`, { type: 'png' }), marg, 120, { scale: 0.85 });
|
|
|
|
|
|
const table0 = {
|
|
headers: ['Nombre', 'Correo'],
|
|
rows: []
|
|
};
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(13)
|
|
.text('CONFERENCIAS', inicio + 142, 240);
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(12)
|
|
.text('Nota:', marg, 270);
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(10)
|
|
.text(` 1.- Presentarse 10 minutos antes de que inicie la actividad.`, marg, 285);
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(10)
|
|
.text(' 2.-Si seleccionaste talleres y no los has pagado el sistema no permitira tu ingreso', marg, 295);
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(12)
|
|
.text('', marg, 300);
|
|
|
|
|
|
let n_cad=`select * from persona where id_persona=${id_persona}`;
|
|
let resu=await query(n_cad);
|
|
table0.rows.push([resu[0].nombre + " " + resu[0].apellido_p+ " " + resu[0].apellido_m, resu[0].correo_electronico]);
|
|
doc.moveDown().table(table0, 200, 150, { width: 300 });
|
|
|
|
|
|
|
|
var table1 = {
|
|
headers: ['Nombre', 'Lugar',' Fecha Hora '],
|
|
rows: []
|
|
};
|
|
|
|
let todos_los_eventos=`select distinct f.id_evento from fecha as f inner join asistencia as a where a.id_persona=${id_persona} and a.id_fecha=f.id_fecha `;
|
|
let eventos= await query(todos_los_eventos);
|
|
console.log(eventos);
|
|
for(let j=0; j<eventos.length; j++)
|
|
{
|
|
let new_cad=`select * from evento where id_evento=${eventos[j].id_evento};`;
|
|
let new_ans=await query(new_cad);
|
|
//console.log(new_ans);
|
|
new_cad=`select * from fecha where id_evento=${eventos[j].id_evento};`;
|
|
let fechas=await query(new_cad);
|
|
let aux=[];
|
|
console.log(fechas);
|
|
for(let h=0; h<fechas.length; h++)
|
|
{
|
|
let po = fechas[h].fecha_inicio;
|
|
let dia = po.getDate();
|
|
let mes = po.getMonth();
|
|
mes++
|
|
let anio = po.getFullYear();
|
|
let hora = po.getHours();
|
|
let min = po.getMinutes();
|
|
if (hora < 10) {
|
|
let aux = `0${hora}`;
|
|
hora = aux;
|
|
|
|
}
|
|
if (min < 10) {
|
|
let aux = `0${min}`;
|
|
min = aux;
|
|
|
|
}
|
|
if (dia < 10) {
|
|
let aux = `0${dia}`;
|
|
dia = aux;
|
|
|
|
}
|
|
if (mes < 10) {
|
|
let aux = `0${mes}`;
|
|
mes = aux;
|
|
|
|
}
|
|
let uno = `${dia}/${mes}/${anio}`;
|
|
let dos = "";
|
|
dos = `${hora}:${min}`;
|
|
if(aux.length==0)
|
|
aux.push(`${uno} ${dos}`);
|
|
else
|
|
aux.push(`\n${uno} ${dos}`);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table1.rows.push([new_ans[0].nombre_evento, new_ans[0].lugar,aux]);
|
|
}
|
|
doc.moveDown().table(table1, 70, 340, { width: 470 });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// doc.image(qr.imageSync(`${id_persona}`, { type: 'png' }), {
|
|
// fit: [250, 300],
|
|
// align: 'center',
|
|
// valign: 'center'
|
|
// });
|
|
doc.end();
|
|
resolve({ "docx": `${id_persona}.pdf` })
|
|
reject(err=>{
|
|
console.log(err);
|
|
return err;
|
|
})
|
|
|
|
});
|
|
}
|
|
|
|
let g_pdf = async function(idPersona) {
|
|
|
|
|
|
// console.log("datos: ", req.query);
|
|
let inicio = 120;
|
|
let id_persona = idPersona;
|
|
|
|
|
|
c_pdf(id_persona)
|
|
//await doc
|
|
// .fontSize(25)
|
|
// .text('Some text with an embedded font!', 100, 100);
|
|
// await doc.font('Times-Roman')
|
|
// .fontSize(10)
|
|
// .text(`${data.nombre} ${ data.apellido_p} ${data.apellido_m}: ${data.id_persona}`, inicio + 60, 40);
|
|
|
|
|
|
//return res.download(__dirname + `/../files/lista-${req.query.id_persona}.pdf`);
|
|
//return
|
|
.then(data => {
|
|
|
|
//res.download(__dirname + `/../files/comprobante_pago-${req.query.id_persona}.docx`);
|
|
console.log(data)
|
|
})
|
|
.catch(err => {
|
|
console.log(err);
|
|
return;
|
|
})
|
|
// console.log(data);
|
|
|
|
};
|
|
|
|
module.exports = g_pdf; |