Skip to content
Snippets Groups Projects
Commit 9f2004a4 authored by khaled-sadegh's avatar khaled-sadegh
Browse files

page 1 - convention

parent 03d742a3
No related branches found
No related tags found
1 merge request!18Generer convention
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"eslint-import-resolver-typescript": "^3.5.2", "eslint-import-resolver-typescript": "^3.5.2",
"fastify": "^4.9.2", "fastify": "^4.9.2",
"mailgun-js": "^0.22.0", "mailgun-js": "^0.22.0",
"moment": "^2.29.4",
"mongoose": "^6.7.2", "mongoose": "^6.7.2",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"node-fetch": "^2.6.9", "node-fetch": "^2.6.9",
...@@ -10573,6 +10574,14 @@ ...@@ -10573,6 +10574,14 @@
"mkdirp": "bin/cmd.js" "mkdirp": "bin/cmd.js"
} }
}, },
"node_modules/moment": {
"version": "2.29.4",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
"engines": {
"node": "*"
}
},
"node_modules/mongodb": { "node_modules/mongodb": {
"version": "4.11.0", "version": "4.11.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.11.0.tgz", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.11.0.tgz",
...@@ -22398,6 +22407,11 @@ ...@@ -22398,6 +22407,11 @@
"minimist": "^1.2.6" "minimist": "^1.2.6"
} }
}, },
"moment": {
"version": "2.29.4",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
},
"mongodb": { "mongodb": {
"version": "4.11.0", "version": "4.11.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.11.0.tgz", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.11.0.tgz",
......
...@@ -8,6 +8,7 @@ import { join } from 'path'; ...@@ -8,6 +8,7 @@ import { join } from 'path';
@Injectable() @Injectable()
export class InternshipService { export class InternshipService {
constructor(private readonly _internshipsDao: InternshipDao) {} constructor(private readonly _internshipsDao: InternshipDao) {}
...@@ -22,46 +23,285 @@ export class InternshipService { ...@@ -22,46 +23,285 @@ export class InternshipService {
this._internshipsDao.save(internship); this._internshipsDao.save(internship);
async generatePDF (id: string): Promise<InternshipEntity>{ async generatePDF (id: string): Promise<InternshipEntity>{
var information = await this.findOne(id).then( (data: InternshipEntity) =>
data.information);
//on recupere les informations de l'entreprise
var nomEntreprise = information.company.companyName;
var adresse = information.company.address;
var adresseString = adresse.street + ', ' + adresse.postalCode + ', ' + + adresse.city + ', ' + adresse.country;
var telOrganisme = '+33 6 63 12 84 65';
var melOrganisme = information.company.hrContactEmail;
var reprsentePar = information.company.ceoName;
var qualiteRepresentant = 'CEO';
var nomService = information.affectation.service;
var lieuStage = information.company.address;
var lieuStageString = lieuStage.street + ', ' + lieuStage.postalCode + ', ' + lieuStage.city + ', ' + lieuStage.country;
//on recupere les informations de l'etudiant
var etudiant = information.student;
var nomEtudiant = etudiant.completeName;
var dateNaissanceEtudiant = etudiant.birthDate.toDateString();
var adresseEtudiant = etudiant.address.street + ', ' + etudiant.address.postalCode + ', ' + etudiant.address.city + ', ' + etudiant.address.country;
console.log("generation pdf"); var telEtudiant = etudiant.phone;
var melEtudiant = etudiant.email;
//on recupere les informations du stage
var sujetStage = 'NULL';
var dateDebutStage = information.affectation.dateStart.toDateString();
var dateFinStage = information.affectation.dateEnd.toDateString();
const diffInMs = information.affectation.dateEnd.getTime() - information.affectation.dateStart.getTime();
const diffInWeeks = diffInMs / 1000 / 60 / 60 / 24 / 7;
var dureeStageEnSemaines = Math.ceil(diffInWeeks);
var dureeStageEnJours = dureeStageEnSemaines * 5;
//on recupere les informations du tuteur du stage
var nomCompletTuteur = information.affectation.responsibleName;
var fonctionTuteur = information.affectation.responsibleFunction;
var telTuteur = information.affectation.responsiblePhone;
var melTuteur = information.affectation.responsibleEmail;
const filePath = join(__dirname, '..', '..', 'files', 'convention_a_modifier.pdf'); const filePath = join(__dirname, '..', '..', 'files', 'convention_a_modifier.pdf');
const existingPdfBytes = readFileSync(filePath); const existingPdfBytes = readFileSync(filePath);
const pdfDoc = await PDFDocument.load(existingPdfBytes); const pdfDoc = await PDFDocument.load(existingPdfBytes);
// Embed the Helvetica font // Embed the Helvetica font
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica); const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
// Get the first page of the document // Get the first page of the document
const pages = pdfDoc.getPages(); const pages = pdfDoc.getPages();
console.log("nombres de pages : ", pages.length ) const firstPage = pages[0];
const firstPage = pages[0];
// Get the width and height of the first page // on remplit les informations de l'entreprise
const { width, height } = firstPage.getSize(); firstPage.drawText(nomEntreprise, {
x: 61,
y: 564,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
// Draw a string of text diagonally across the first page firstPage.drawText(adresseString, {
firstPage.drawText('This text was added with JavaScript!', { x: 73,
x: 5, y: 542,
y: height / 2 + 300, size: 9,
size: 50,
font: helveticaFont, font: helveticaFont,
color: rgb(0.95, 0.1, 0.1), color: rgb(0.95, 0.1, 0.1),
rotate: degrees(-45), rotate: degrees(0),
}); });
firstPage.drawText(telOrganisme, {
x: 52,
y: 522,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(melOrganisme, {
x: 149,
y: 522,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(reprsentePar, {
x: 98,
y: 501,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(qualiteRepresentant, {
x: 130,
y: 480,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(nomService, {
x: 230,
y: 459,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(lieuStageString, {
x: 98,
y: 438,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
// on remplit les informations de l'entreprise
firstPage.drawText(nomEtudiant, {
x: 98,
y: 396,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(dateNaissanceEtudiant, {
x: 137,
y: 374,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(adresseEtudiant, {
x: 73,
y: 353,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(telEtudiant, {
x: 52,
y: 331,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(melEtudiant, {
x: 149,
y: 331,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(sujetStage, {
x: 102,
y: 231,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(dateDebutStage, {
x: 119,
y: 214,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(dateFinStage, {
x: 221,
y: 214,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(dureeStageEnSemaines.toString(), {
x: 200,
y: 197,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(dureeStageEnJours.toString(), {
x: 276,
y: 197,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(nomCompletTuteur, {
x: 380,
y: 131,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(fonctionTuteur, {
x: 360,
y: 110,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(telTuteur, {
x: 345,
y: 89,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
firstPage.drawText(melTuteur, {
x: 345,
y: 69,
size: 9,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(0),
});
// Serialize the PDFDocument to bytes (a Uint8Array) // Serialize the PDFDocument to bytes (a Uint8Array)
const pdfBytes = await pdfDoc.save(); const pdfBytes = await pdfDoc.save();
const newFileName = 'convention-' + id; const newFileName = 'convention-' + id;
const newFilePath = join(__dirname, '..', '..', 'files', newFileName + '.pdf'); const newFilePath = join(__dirname, '..', '..', 'files', newFileName + '.pdf');
writeFileSync(newFilePath, pdfBytes); writeFileSync(newFilePath, pdfBytes);
//on recupere les informations de l'entreprise
var nomEntreprise = 'capgemini';
var adresse = '99 rue CEDEX, Courbevoie';
return null; return null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment