-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreport-pdf-service.ts
98 lines (90 loc) · 2.81 KB
/
report-pdf-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* SudoSOS back-end API service.
* Copyright (C) 2024 Study association GEWIS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license
*/
/**
* This is the page of report-pdf-service.
*
* @module internal/pdf/report-pdf-service
*/
import {
FileResponse,
FineReportParameters,
FineRouteParams, Product,
ProductPricing,
TotalPricing,
VAT,
} from 'pdf-generator-client';
import {
PDF_VAT_HIGH,
UNUSED_NUMBER,
UNUSED_PARAM,
} from '../../helpers/pdf';
import { UnstoredPdfService } from './pdf-service';
import { FineReport } from '../../entity/report/fine-report';
const HANDED_OUT_FINES = 'Handed out';
const WAIVED_FINES = 'Waived';
export default class FineReportPdfService extends UnstoredPdfService<FineReport, FineRouteParams> {
routeConstructor = FineRouteParams;
generator(routeParams: FineRouteParams): Promise<FileResponse> {
return this.client.generateFineReport(routeParams);
}
async getParameters(entity: FineReport): Promise<FineReportParameters> {
const handedOut = new Product({
name: HANDED_OUT_FINES,
summary: UNUSED_PARAM,
pricing: new ProductPricing({
basePrice: entity.handedOut.getAmount(),
vatAmount: PDF_VAT_HIGH,
// is actually unused
vatCategory: VAT.ZERO,
quantity: entity.count,
}),
});
const fines = [handedOut];
if (entity.waivedCount > 0) {
const waived = new Product({
name: WAIVED_FINES,
summary: UNUSED_PARAM,
pricing: new ProductPricing({
basePrice: entity.waivedAmount.getAmount() * -1,
vatAmount: PDF_VAT_HIGH,
// is actually unused
vatCategory: VAT.ZERO,
quantity: entity.waivedCount,
}),
});
fines.push(waived);
}
const inclVat = entity.handedOut.getAmount() - entity.waivedAmount.getAmount();
const exclVat = Math.round(inclVat / (1 + (PDF_VAT_HIGH / 100)));
const highVat = inclVat - exclVat;
const total = new TotalPricing({
exclVat,
lowVat: UNUSED_NUMBER,
highVat,
inclVat,
});
return new FineReportParameters({
startDate: entity.fromDate,
endDate: entity.toDate,
fines,
total,
});
}
}