From 6b23dea47745e98371a65a4f577f2e20cfdfe597 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 31 Mar 2021 16:31:44 +0200 Subject: [PATCH] Now calculateing total donations (perdistance) ref #36 --- src/controllers/PdfController.ts | 6 ++++++ src/models/CertificateRunner.ts | 11 ++++++++++- src/templates/runner_certificate.html | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/controllers/PdfController.ts b/src/controllers/PdfController.ts index 0b33f07..665f36f 100644 --- a/src/controllers/PdfController.ts +++ b/src/controllers/PdfController.ts @@ -97,6 +97,12 @@ export class PdfController { else { runner.group.fullName = `${runner.group.parentGroup.name}/${runner.group.name}`; } + runner.donationPerDistanceTotal = runner.distanceDonations.reduce(function (sum, current) { + return sum + current.amountPerDistance; + }, 0); + runner.donationTotal = runner.distanceDonations.reduce(function (sum, current) { + return sum + current.amount; + }, 0); response.push(runner) } return response; diff --git a/src/models/CertificateRunner.ts b/src/models/CertificateRunner.ts index a30b356..ef6168a 100644 --- a/src/models/CertificateRunner.ts +++ b/src/models/CertificateRunner.ts @@ -1,5 +1,5 @@ import { - IsArray + IsArray, IsNumber, IsOptional } from "class-validator"; import { DistanceDonation } from './DistanceDonation'; import { Runner } from './Runner'; @@ -13,4 +13,13 @@ export class CertificateRunner extends Runner { */ @IsArray() distanceDonations: DistanceDonation[]; + + @IsNumber() + @IsOptional() + donationPerDistanceTotal?: number = 0; + + @IsNumber() + @IsOptional() + donationTotal?: number = 0; + } diff --git a/src/templates/runner_certificate.html b/src/templates/runner_certificate.html index 9f40e8a..f4c6871 100644 --- a/src/templates/runner_certificate.html +++ b/src/templates/runner_certificate.html @@ -79,8 +79,8 @@ {{__ "gesamt"}} - 0.5 {{../currency_symbol}} - 1 {{../currency_symbol}} + {{--format_currency this.donationPerDistanceTotal}} {{../currency_symbol}} + {{--format_currency this.donationTotal}} {{../currency_symbol}}