[FE][Certs] Generate cert for Excavadora Hidraulica

This commit is contained in:
Araozu 2023-09-04 12:32:48 -05:00
parent a2f0e23da3
commit 4c5493eb57
4 changed files with 291 additions and 0 deletions

View File

@ -39,4 +39,9 @@ export type CertData<T> = {
* Id of the certificate
*/
certIId: number,
/**
* Custom label for the certificate.
* Used only in machineries, should be ignored in other cases.
*/
certCustomLabel?: string,
}

View File

@ -0,0 +1,275 @@
/*
import {
Document, Packer, Paragraph, PageOrientation,
FrameAnchorType,
TextRun,
AlignmentType,
BorderStyle,
} from "docx";
*/
import { cmText, createSimpleText, getImage, getQR } from "./utils";
import { CertData } from "./CertData";
const {
Document, Paragraph, PageOrientation,
FrameAnchorType,
TextRun,
AlignmentType,
BorderStyle,
} = window.docx;
const imgFondoDoc = getImage({
name: "fondo_certificado_4x4.png",
height: 21.03,
width: 29.69,
horizontalOffset: 0,
verticalOffset: 0.01,
behindDocument: true,
});
const imgCIP = getImage({
name: "colegio_ingenieros_logo.png",
height: 2.15,
width: 2.15,
horizontalOffset: 26.76,
verticalOffset: 12.26,
});
const imgCEE = getImage({
name: "cee_dark_logo.png",
height: 1.5,
width: 2.1,
horizontalOffset: 26.89,
verticalOffset: 17.06,
});
const imgMTC = getImage({
name: "mtc_transparente.png",
height: 1.65,
width: 5.16,
horizontalOffset: 23.92,
verticalOffset: 18.83,
});
const tCertificate = createSimpleText({
xPosition: 7.7,
yPosition: 3.7,
width: 11.05,
height: 1.72,
text: "CERTIFICADO",
size: 72,
font: "Times New Roman",
bold: true,
});
// Otorgado a
const tExpediteText = createSimpleText({
xPosition: 4.2,
yPosition: 5.5,
width: 3,
height: 0.7,
text: "Otorgado a:",
size: 22,
});
// En temas de...
const tTopics = createSimpleText({
xPosition: 2.3,
yPosition: 10.4,
width: 20.92,
height: 1.5,
text: "En temas de: Descripción general de las excavadoras, Funcionamiento elemental de sus componentes, Símbolos pictográficos, Mandos, indicadores y alarmas, Manejo e interpretación, Normas de arranque y parada, Técnicas operativas en el trabajo con excavadoras, Dispositivos de seguridad de las excavadoras. equivalente a 60 horas lectivas.",
size: 22,
font: "Times New Roman",
alignment: AlignmentType.LEFT,
});
// Se expide certificado...
const tFinishLabel = createSimpleText({
xPosition: 5.95,
yPosition: 11.9,
width: 12.38,
height: 0.75,
text: "Se expide el presente certificado para los fines que se estime conveniente",
size: 22,
font: "Times New Roman",
alignment: AlignmentType.CENTER,
});
// Recuadro de foto
const photoSection = new Paragraph({
frame: {
position: {
x: cmText(-1.68),
y: cmText(8.6),
},
width: cmText(2.7),
height: cmText(3.57),
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
},
children: [],
border: {
top: {
style: BorderStyle.DASHED,
},
bottom: {
style: BorderStyle.DASHED,
},
left: {
style: BorderStyle.DASHED,
},
right: {
style: BorderStyle.DASHED,
},
},
alignment: AlignmentType.LEFT,
});
export async function excavadoraHidraulica(props: CertData<null>): Promise<Document> {
// OPERADOR PROFESIONAL DE EXCAVADORA HIDRÁULICA
const tCourse = createSimpleText({
xPosition: 2.2,
yPosition: 8.4,
width: 20,
height: 1.5,
text: `OPERADOR PROFESIONAL DE EXCAVADORA HIDRÁULICA ${props.certCustomLabel}`,
size: 40,
bold: true,
});
const imgQR = await getQR({
iid: props.certIId,
dni: props.personDni,
height: 2.04,
width: 2.04,
horizontalOffset: 26.85,
verticalOffset: 14.71,
});
// FERNANDO ARAOZ
const tName = createSimpleText({
xPosition: 1,
yPosition: 6.2,
width: 23.13,
height: 1.5,
text: props.personFullName,
size: 52,
bold: true,
underline: {},
});
// Identificado con DNI...
const tContentPart1 = new Paragraph({
frame: {
position: {
x: cmText(2.5),
y: cmText(7.6),
},
width: cmText(20.92),
height: cmText(1),
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
},
children: [
new TextRun({
text: "Identificado con DNI N° ",
font: "Times New Roman",
size: 22,
}),
new TextRun({
text: props.personDni,
font: "Times New Roman",
size: 24,
bold: true,
}),
new TextRun({
text: ", al haber aprobado el curso de capacitación sobre:",
font: "Times New Roman",
size: 22,
}),
],
alignment: AlignmentType.LEFT,
});
// Fecha de Emision: ...
const certificateDate = new Paragraph({
frame: {
position: {
x: cmText(13),
y: cmText(17.3),
},
width: cmText(7.5),
height: cmText(0.5),
anchor: {
horizontal: FrameAnchorType.MARGIN,
vertical: FrameAnchorType.MARGIN,
},
},
children: [
new TextRun({
text: `Fecha de Emisión:\t${props.certDay} / ${props.certMonth} / ${props.certYear}`,
font: "Times New Roman",
size: 20,
}),
],
alignment: AlignmentType.LEFT,
});
// N° XXXX-20XX-EEG
const tCertCode = createSimpleText({
xPosition: -2.15,
yPosition: 12.45,
width: 3.67,
height: 0.8,
text: `${props.certCode}-${props.certYear}-EEG`,
size: 20,
alignment: AlignmentType.CENTER,
});
const doc = new Document({
sections: [
{
properties: {
page: {
size: {
orientation: PageOrientation.LANDSCAPE,
},
},
},
children: [
tCertificate,
tExpediteText,
tName,
tContentPart1,
tCourse,
tTopics,
tFinishLabel,
certificateDate,
photoSection,
tCertCode,
new Paragraph({
children: [
imgFondoDoc,
imgQR,
imgCIP,
imgCEE,
imgMTC,
],
}),
],
},
],
});
// Return document as a buffer
return doc;
}

View File

@ -9,11 +9,13 @@ import { mecanicaBasicaCert } from "./certs/MECANICA_BASICA";
import { segOpMaqPesCert } from "./certs/SEG_OP_MAQ_PES";
import { supervisorEscolta } from "./certs/SUPERVISOR_ESCOLTA";
import { ipercCert } from "./certs/IPERC";
import { excavadoraHidraulica } from "./certs/EXCAVADORA_HIDRAULICA";
declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
docx: any,
certs: CertGenObj,
}
}
@ -70,5 +72,11 @@ export const certGenerator: CertGenObj = Object.freeze({
"Seg. Op. Maquinaria Pesada": certGeneratorGenerator(segOpMaqPesCert),
"Sup. Escolta": certGeneratorGenerator(supervisorEscolta),
"IPERC": certGeneratorGenerator(ipercCert),
"Excavadora": certGeneratorGenerator(excavadoraHidraulica),
});
if (import.meta.env.DEV) {
console.log("Dev time!!");
window.certs = certGenerator;
}

View File

@ -154,6 +154,8 @@ function RegisterEl(props: {register: Register, person: Person, onClick: () => v
const {year, month, day} = dateComponents();
const personFullName = `${person.person_names} ${person.person_paternal_surname} ${person.person_maternal_surname}`;
const certCustomLabel = customLabelsMap()[register.register_custom_label]?.custom_label_value ?? "";
generator(`${courseN} - ${personFullName}.docx`, {
matpel: null,
personFullName,
@ -163,6 +165,7 @@ function RegisterEl(props: {register: Register, person: Person, onClick: () => v
certMonth: month,
certDay: day,
certIId: register.register_code,
certCustomLabel,
});
};