Skip to content

Commit a15cf1b

Browse files
author
Brijesh
committed
Exemption PDF changes
1 parent 0b1842a commit a15cf1b

6 files changed

Lines changed: 17 additions & 4 deletions

File tree

exemptionTemplate.docx

31.1 KB
Binary file not shown.

planTemplate.docx

-7.97 KB
Binary file not shown.

src/libs/db2/model/exemption.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class Exemption extends Model {
7171
.orderBy(orderBy, order);
7272
return Promise.all(
7373
results.map(async (row) => {
74-
const exemption = new Exemption(row);
74+
const exemption = new Exemption(row, trx);
7575
exemption.attachments = await ExemptionAttachment.findByExemptionId(trx, exemption.id);
7676
return exemption;
7777
}),
@@ -103,7 +103,7 @@ export default class Exemption extends Model {
103103
return null;
104104
}
105105

106-
const exemption = new Exemption(row);
106+
const exemption = new Exemption(row, trx);
107107
exemption.attachments = await ExemptionAttachment.findByExemptionId(trx, exemption.id);
108108
return exemption;
109109
}

src/router/controllers_v1/ExemptionController.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ export default class ExemptionController {
487487
const { exemptionId } = params;
488488
checkRequiredFields(['exemptionId'], 'params', req);
489489
const exemption = await Exemption.findById(db, exemptionId);
490+
const agreement = await Agreement.findById(db, exemption.agreementId);
491+
console.log('agreement', agreement);
492+
if (agreement) {
493+
await agreement.fetchClients();
494+
exemption.agreement = agreement;
495+
}
490496
const response = await generateExemptionPDF(exemption);
491497
res.json(response.data).end();
492498
}
@@ -496,6 +502,12 @@ export default class ExemptionController {
496502

497503
// 1. Generated PDF
498504
try {
505+
const agreement = await Agreement.findById(db, exemption.agreementId);
506+
console.log('agreement', agreement);
507+
if (agreement) {
508+
await agreement.fetchClients();
509+
exemption.agreement = agreement;
510+
}
499511
const pdfResponse = await generateExemptionPDF(exemption);
500512
emailAttachments.push({
501513
content: Buffer.from(pdfResponse.data).toString('base64'),

src/router/controllers_v1/PDFGeneration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const generatePlanPDF = async (plan) => {
2020
export const generateExemptionPDF = async (exemption) => {
2121
const dogs = new Cdogs();
2222
dogs.init('exemptionTemplate.docx');
23+
2324
const response = await dogs.generatePDF(exemption, `${exemption.agreementId}_exemption.pdf`);
2425
return response;
2526
};

src/router/controllers_v1/PlanVersionController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import DataManager from '../../libs/db2';
44
import config from '../../config';
55
import { PlanRouteHelper } from '../helpers';
66
import PlanSnapshot from '../../libs/db2/model/plansnapshot';
7-
import { generatePDFResponse } from './PDFGeneration';
7+
import { generatePlanPDF } from './PDFGeneration';
88

99
const dm = new DataManager(config);
1010
const { db, Plan, Agreement } = dm;
@@ -142,7 +142,7 @@ export default class PlanVersionController {
142142
dateOut: entry.dateOut ? new Date(entry.dateOut).toISOString().split('T')[0] : null,
143143
})),
144144
}));
145-
const response = await generatePDFResponse(versionData.snapshot);
145+
const response = await generatePlanPDF(versionData.snapshot);
146146
PlanSnapshot.update(db, { plan_id: planId, version }, { pdf_file: response.data });
147147
res.send(response.data);
148148
} catch (error) {

0 commit comments

Comments
 (0)