150 lines
4.4 KiB
JavaScript
150 lines
4.4 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const PDFDocument = require('./pdfkit-tables');
|
|
const connection = require('../conf/connection.js');
|
|
const path = require('path');
|
|
|
|
|
|
let g_pdf = async function(idPersona) {
|
|
|
|
|
|
const doc = new PDFDocument({ size: 'A4' });
|
|
doc.pipe(fs.createWriteStream(__dirname + `/../public/comprobante-${idPersona}.pdf`));
|
|
|
|
|
|
let inicio = 120;
|
|
var datetime = new Date();
|
|
|
|
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('JORNADA DE INSERCIÓN LABORAL', inicio + 95, 60);
|
|
|
|
doc.image(__dirname + '/Imagenes/Fesa.jpg', inicio + 305, 30, { scale: 0.05 });
|
|
// Add another page
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(8)
|
|
.text('COMPROBANTE DE INSCRIPCIÓN', inicio + 120, 80);
|
|
|
|
doc.moveTo(70, 110)
|
|
.lineTo(542, 110);
|
|
|
|
//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(__dirname + `/Imagenes/persona_${idPersona}.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.- Todas las actividades serán en el auditorio 901, excepto la Feria se llevará acabo en el Corredor Multidisciplinario.', marg, 295);
|
|
|
|
doc.font('Times-Roman')
|
|
.fontSize(12)
|
|
.text('', marg, 300);
|
|
var table1 = {
|
|
headers: ['Nombre', 'Fecha ', 'Hora'],
|
|
rows: []
|
|
};
|
|
connection.query(`select * from persona where idPersona=${idPersona}`,
|
|
(erro, results, file) => {
|
|
if (erro) {
|
|
res.status(400).json({ mjs: "Error en traer los datos del alumno" });
|
|
return;
|
|
}
|
|
table0.rows.push([results[0].nombre + " " + results[0].apellidos, results[0].correo]);
|
|
doc.moveDown().table(table0, 200, 150, { width: 300 });
|
|
});
|
|
connection.query(`select * from asistencia a join conferencia c on a.idConferencia=c.idConferencia where idPersona=${idPersona} order by c.fecha;`,
|
|
(erro, results, file) => {
|
|
if (erro) {
|
|
res.status(400).json({ mjs: "error en las conferencias" });
|
|
return;
|
|
}
|
|
//console.log(results)
|
|
for (let index = 0; index < results.length; index++) {
|
|
let po = results[index].fecha;
|
|
let dia = po.getDate();
|
|
let mes = po.getMonth();
|
|
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 = "";
|
|
if (results[index].idConferencia == 7)
|
|
dos = `${hora}:${min} - 16:00`;
|
|
else
|
|
dos = `${hora}:${min}`;
|
|
|
|
table1.rows.push([results[index].nombre, uno, dos])
|
|
|
|
}
|
|
doc.moveDown().table(table1, 70, 340, { width: 470 });
|
|
doc.end();
|
|
});
|
|
return;
|
|
}
|
|
module.exports = g_pdf; |