344 lines
12 KiB
JavaScript
344 lines
12 KiB
JavaScript
'use strict';
|
|
|
|
var fs = require('fs');
|
|
var PDFDocument = require('pdfkit');
|
|
const connection = require('../conf/connection');
|
|
const express = require('express');
|
|
var app = express();
|
|
const sql = require('mssql')
|
|
|
|
function query(consulta) {
|
|
return new Promise(function(resolve, reject) {
|
|
connection.query(`${consulta}`, (error, results, files) => {
|
|
if (error) reject(error);
|
|
resolve(results);
|
|
});
|
|
})
|
|
}
|
|
|
|
|
|
|
|
let g_pdf = async function hacer(id_proyecto) {
|
|
|
|
let id = id_proyecto;
|
|
const doc = new PDFDocument({ size: 'A4' });
|
|
doc.pipe(fs.createWriteStream(__dirname + `/../public/comprobante-${id}.pdf`));
|
|
|
|
|
|
|
|
console.log("el id proyetco en pdf= ", id);
|
|
|
|
|
|
|
|
let inicio = 120;
|
|
var datetime = new Date();
|
|
var anio = new Date();
|
|
anio = anio.getFullYear();
|
|
|
|
|
|
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(`Red de Investigación ${ anio }`, inicio + 127, 70);
|
|
|
|
doc.image(__dirname + '/Imagenes/Fesa.jpg', inicio + 305, 30, { scale: 0.05 });
|
|
|
|
doc.moveTo(70, 100)
|
|
.lineTo(542, 100).stroke();
|
|
|
|
|
|
let datos = '';
|
|
//console.log(id);
|
|
|
|
let cad = `select * from proyecto where id_proyecto=${ id };`;
|
|
let respuesta = query(cad);
|
|
await respuesta.then(element => {
|
|
datos = element[0];
|
|
console.log(datos);
|
|
|
|
}).catch(error => { return error; });
|
|
|
|
|
|
let sang = 70;
|
|
//console.log("datos ", datos);
|
|
doc.moveDown().font('Helvetica-Bold').fontSize(10).text("Datos del profesor responsable del proyecto de invesitgación", sang + 80, 120);
|
|
|
|
|
|
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Nombre del profesor: ${ datos.nombre_responsable }`, sang);
|
|
|
|
try {
|
|
let pass = "67NHA*Y";
|
|
// make sure that any items are correctly URL encoded in the connection string
|
|
await sql.connect(`mssql://USR_REDINVESTIGACION:${pass}@132.248.180.228/DB_ARES`)
|
|
const result = await sql.query `EXEC DB_ARES.dbo.SPD_CONSULTA_DATOS_X_PROFESOR_RED_INVESTIGACION ${datos.rfc_responsable};`
|
|
// console.log("sss");
|
|
// console.log(result.recordsets);
|
|
console.log("datos ", datos.rfc_responsable, ' ', result.recordsets[0][0]);
|
|
let base = result.recordsets[0][0];
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Numero de trabajador: ${ base.Numero_Trabajador } RFC: ${ base.Rfc }`, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Categoria: ${ base.Categoria }`, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Adscripcion: ${ base.Adscripcion }`, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Nivel maximo de estudios: ${ base['Nivel maximo de estudios'] }`, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Telefono de oficina: ${ base['Tel. oficina'] } Extensión: ${ base['Extensión'] }`, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Telefono particular: ${ base.Particular } Celular: ${ base.Celular }`, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Correo institucional: ${ base['Correo Institucional'] } `, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Correo personal: ${ base['Correo Personal'] } `, sang);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Espacio fisico: ${ base.EspacioFisico } Edificio: ${base.Edificio}`, sang);
|
|
|
|
} catch (err) {
|
|
console.log(err);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doc.moveDown().font('Helvetica-Bold').fontSize(10).text("Datos del proyecto de investigación", sang + 140);
|
|
doc.font('Times-Roman').moveDown().fontSize(10).text(`Nombre del proyecto: ${ datos.nombre_proyecto }`, sang);
|
|
|
|
let campo = '';
|
|
try {
|
|
let cad = `select nombre from campo_conocimiento inner join proyecto_campo on id_proyecto=${ id } and proyecto_campo.id_campo = campo_conocimiento.id_campo;`;
|
|
respuesta = await query(cad);
|
|
//console.log(respuesta);
|
|
for (let i = 0; i < respuesta.length; i++) {
|
|
campo += respuesta[i].nombre;
|
|
if (i < respuesta.length - 2)
|
|
campo += ', ';
|
|
if (i == respuesta.length - 2)
|
|
campo += ' y ';
|
|
}
|
|
//console.log(campo);
|
|
} catch {
|
|
return;
|
|
}
|
|
doc.moveDown().fontSize(10).text(`Campo de conocimiento: ${ campo }`, {
|
|
x: sang
|
|
});
|
|
|
|
doc.moveDown().fontSize(10).text(`Disciplina: ${ datos.disciplina }`, {
|
|
x: sang
|
|
});
|
|
|
|
|
|
|
|
doc.moveDown().fontSize(10).text(`Linea de Investigación: ${ datos.linea_investigacion }`, {
|
|
x: sang
|
|
});
|
|
|
|
doc.moveDown().fontSize(10).text(`Objetivo general: ${ datos.objetivo_general }`, {
|
|
x: sang
|
|
});
|
|
|
|
doc.moveDown().fontSize(10).text(`Objetivo particular:`);
|
|
try {
|
|
let cad = `select objetivo_texto from proyecto_objetivo where id_proyecto=${ id };`;
|
|
respuesta = await query(cad);
|
|
//console.log(respuesta);
|
|
for (let i = 0; i < respuesta.length; i++) {
|
|
doc.moveDown(.5).fontSize(10).text(` ${ i + 1 }.- ${ respuesta[i].objetivo_texto }`);
|
|
}
|
|
|
|
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
doc.moveDown().fontSize(10).text(`Hipotesis(en su caso): ${ datos.hipotesis }`);
|
|
|
|
doc.moveDown().fontSize(10).text(`Resumen del proyecto de investigacion: ${ datos.resumen }`);
|
|
|
|
let f_i = new Date(datos.fecha_inicio);
|
|
let an = f_i.getFullYear();
|
|
let m = f_i.getMonth() + 1;
|
|
//console.log(m.length);
|
|
if (m < 10)
|
|
m = '0' + m;
|
|
let d = f_i.getDate();
|
|
if (d < 10)
|
|
d = '0' + d;
|
|
doc.moveDown().fontSize(10).text(`Fecha de inicio(dd / mm / aaaa): ${ d } / ${m} / ${ an }`);
|
|
|
|
let f_f = new Date(datos.fecha_final);
|
|
|
|
let ano = f_f.getFullYear();
|
|
|
|
let mes = f_f.getMonth() + 1;
|
|
//console.log(m.length);
|
|
if (mes < 10)
|
|
mes = '0' + mes;
|
|
let dia = f_f.getDate();
|
|
|
|
if (dia < 10)
|
|
dia = '0' + dia;
|
|
doc.moveDown().fontSize(10).text(`Fecha de final(dd / mm / aaaa): ${ dia } / ${mes} / ${ ano }`);
|
|
|
|
doc.moveDown().fontSize(10).text(`Estado de avance: ${ datos.estado_avance }`);
|
|
|
|
doc.moveDown().fontSize(10).text(`Avance: ${ datos.avance } %`);
|
|
|
|
doc.moveDown().fontSize(10).text(`Duración: ${ datos.duracion }`);
|
|
|
|
doc.moveDown().fontSize(10).text(`Financiamiento del proyecto: ${ datos.financiamiento }`);
|
|
|
|
doc.moveDown().fontSize(10).text(`Número del registro: ${ datos.numero_registro }`);
|
|
|
|
doc.moveDown().fontSize(10).text(`Entidades participantes(ademas de la FES Acatlán): `);
|
|
|
|
try {
|
|
let cad = `select tipo, nombre_entidad from entidades inner join proyecto_entidad where id_proyecto=${ id } and proyecto_entidad.id_entidad=entidades.id_entidad;`;
|
|
respuesta = await query(cad);
|
|
//console.log(respuesta);
|
|
for (let i = 0; i < respuesta.length; i++) {
|
|
doc.moveDown(.5).fontSize(10).text(` ${ i + 1 }. - ${ respuesta[i].tipo }: ${ respuesta[i].nombre_entidad }`);
|
|
}
|
|
|
|
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
let cad = `select nombre from producto as p inner join proyecto_producto as p_p where p_p.id_proyecto =${ id } and p_p.id_producto=p.id_producto;`;
|
|
respuesta = await query(cad);
|
|
if (respuesta.length > 1)
|
|
doc.moveDown().fontSize(10).text(`Producto(s): `);
|
|
else
|
|
doc.moveDown().fontSize(10).text(`Producto: `);
|
|
//console.log(respuesta);
|
|
for (let i = 0; i < respuesta.length; i++) {
|
|
doc.moveDown(.5).fontSize(10).text(` ${ i + 1 }.- ${ respuesta[i].nombre }`);
|
|
}
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
let alumnos_internos = null;
|
|
let alumnos_externos = null;
|
|
let profesores_internos = null;
|
|
let profesores_externos = null;
|
|
try {
|
|
let cad = `select nombre, tipo_particicipacion from persona as p inner join proyecto_entidad as p_e where p_e.nombre_entidad = "FES-Acatlan"and p_e.id_pro_entidad = p.id_proyecto_entidad and p.tipo = "alumno"and p_e.id_proyecto = ${ id };`;
|
|
alumnos_internos = await query(cad);
|
|
|
|
} catch (error) {
|
|
console.log(error);
|
|
return;
|
|
}
|
|
|
|
|
|
try {
|
|
let cad = `select nombre, tipo_particicipacion, nombre_entidad, e.tipo from persona as p inner join proyecto_entidad as p_e inner join entidades as e where e.id_entidad = p_e.id_entidad and p_e.nombre_entidad != "FES-Acatlan"and p_e.id_pro_entidad = p.id_proyecto_entidad and p.tipo = "alumno"and p_e.id_proyecto = ${ id };`;
|
|
alumnos_externos = await query(cad);
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
let cad = `select nombre, tipo_particicipacion from persona as p inner join proyecto_entidad as p_e where p_e.nombre_entidad = "FES-Acatlan"and p_e.id_pro_entidad = p.id_proyecto_entidad and p.tipo = "profesor"and p_e.id_proyecto = ${ id };`;
|
|
profesores_internos = await query(cad);
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
let cad = `select nombre, tipo_particicipacion, nombre_entidad, e.tipo from persona as p inner join proyecto_entidad as p_e inner join entidades as e where e.id_entidad = p_e.id_entidad and p_e.nombre_entidad != "FES-Acatlan"and p_e.id_pro_entidad = p.id_proyecto_entidad and p.tipo = "profesor"and p_e.id_proyecto = ${ id };`;
|
|
profesores_externos = await query(cad);
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
if (profesores_internos.length != 0) {
|
|
doc.moveDown().fontSize(10).text(`Profesores Internos Participantes: `);
|
|
for (let i = 0; i < profesores_internos.length; i++) {
|
|
doc.moveDown(.5).fontSize(10).text(` ${ profesores_internos[i].nombre } - ${ profesores_internos[i].tipo_particicipacion }`);
|
|
}
|
|
} else {
|
|
doc.moveDown().fontSize(10).text(`Profesores Internos Participantes: No se registro`);
|
|
}
|
|
|
|
if (profesores_externos.length != 0) {
|
|
doc.moveDown().fontSize(10).text(`Profesores Externos Participantes: `);
|
|
for (let i = 0; i < profesores_externos.length; i++) {
|
|
|
|
doc.moveDown(.5).fontSize(10).text(` ${ profesores_externos[i].nombre } - ${ profesores_externos[i].tipo_particicipacion } - ${ profesores_externos[i].nombre_entidad }`);
|
|
}
|
|
} else {
|
|
doc.moveDown().fontSize(10).text(`Profesores Externos Participantes: No se registro`);
|
|
}
|
|
|
|
if (alumnos_internos.length != 0) {
|
|
doc.moveDown().fontSize(10).text(`Alumnos Internos Participantes: `);
|
|
for (let i = 0; i < alumnos_internos.length; i++) {
|
|
doc.moveDown(.5).fontSize(10).text(` ${ alumnos_internos[i].nombre } - ${ alumnos_internos[i].tipo_particicipacion }`);
|
|
}
|
|
} else {
|
|
doc.moveDown().fontSize(10).text(`Alumnos Internos Participantes: No se registro`);
|
|
}
|
|
|
|
if (alumnos_externos.length != 0) {
|
|
doc.moveDown().fontSize(10).text(`Alumnos Externos Participantes: `);
|
|
for (let i = 0; i < alumnos_externos.length; i++) {
|
|
|
|
doc.moveDown(.5).fontSize(10).text(` ${ alumnos_externos[i].nombre } - ${ alumnos_externos[i].tipo_particicipacion } - ${ alumnos_externos[i].nombre_entidad }`);
|
|
}
|
|
} else {
|
|
doc.moveDown().fontSize(10).text(`Alumnos Externos Participantes: No se registro`);
|
|
}
|
|
|
|
f_f = new Date(datos.fecha_creacion);
|
|
|
|
ano = f_f.getFullYear();
|
|
|
|
mes = f_f.getMonth() + 1;
|
|
//console.log(m.length);
|
|
if (mes < 10)
|
|
mes = '0' + mes;
|
|
dia = f_f.getDate();
|
|
|
|
if (dia < 10)
|
|
dia = '0' + dia;
|
|
doc.moveDown().fontSize(10).text(`Fecha de creación (dd / mm / aaaa): ${ dia } / ${mes} / ${ ano }`);
|
|
|
|
f_f = new Date(datos.fecha_modificiacion);
|
|
|
|
ano = f_f.getFullYear();
|
|
|
|
mes = f_f.getMonth() + 1;
|
|
//console.log(m.length);
|
|
if (mes < 10)
|
|
mes = '0' + mes;
|
|
dia = f_f.getDate();
|
|
|
|
if (dia < 10)
|
|
dia = '0' + dia;
|
|
doc.moveDown().fontSize(10).text(`Ultima fecha de modificación (dd / mm / aaaa): ${ dia } / ${mes} / ${ ano }`);
|
|
|
|
doc.moveDown(5).fontSize(12).text(`Lugar: __________________________ `);
|
|
|
|
doc.moveDown().fontSize(12).text(`Nombre: __________________________ `);
|
|
|
|
doc.moveDown().fontSize(12).text(`Firma: __________________________ `);
|
|
|
|
|
|
// console.log(profesores_internos);
|
|
// console.log(profesores_externos);
|
|
// console.log(alumnos_internos);
|
|
// console.log(alumnos_externos);
|
|
|
|
|
|
doc.end();
|
|
|
|
return "acabo papa";
|
|
}
|
|
module.exports = g_pdf; |