Now formatting currency ans distance

ref #36
This commit is contained in:
Nicolai Ort 2021-03-31 16:24:05 +02:00
parent 1d12de7045
commit e0add846bb
2 changed files with 18 additions and 6 deletions

View File

@ -98,6 +98,18 @@ export class PdfCreator {
return config.sponor_logos[index];
}
);
await Handlebars.registerHelper('--format_kilometers',
function (str) {
let meters = parseInt(str);
return ((meters / 1000).toFixed(3).toString())
}
);
await Handlebars.registerHelper('--format_currency',
function (str) {
let meters = parseInt(str);
return ((meters / 100).toFixed(2).toString())
}
);
this.browser = await puppeteer.launch({ headless: true, args: minimal_args });
}
@ -179,7 +191,7 @@ export class PdfCreator {
await i18next.changeLanguage(locale);
const template_source = fs.readFileSync(`${this.templateDir}/runner_certificate.html`, 'utf8');
const template = Handlebars.compile(template_source);
let result = template({ runners, eventname: config.eventname });
let result = template({ runners, eventname: config.eventname, currency_symbol: config.currency_symbol });
result = await awaitAsyncHandlebarHelpers(result);
const pdf = await this.renderPdf(result, { format: "A4", landscape: false, printBackground: true });
return pdf;

View File

@ -50,7 +50,7 @@
{{this.middlename}} {{this.lastname}}
</p>
<p style="font-size: 1cm; margin-bottom: 0;">{{__ "hat-beim-eventname"}}</p>
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{this.distance}}km</p>
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{--format_kilometers this.distance}}km</p>
<p style="font-size: 1cm;">{{__ "fuer-den-guten-zweck-zurueckgelegt"}}</p>
</main>
<footer class="certificate-footer">
@ -72,15 +72,15 @@
{{#each this.distanceDonations}}
<tr>
<td>{{this.donor.firstname}} {{this.donor.middlename}} {{this.donor.lastname}}</td>
<td>{{this.amountPerDistance}}</td>
<td>{{this.amount}}</td>
<td>{{--format_currency this.amountPerDistance}} {{../../currency_symbol}}</td>
<td>{{--format_currency this.amount}} {{../../currency_symbol}}</td>
</tr>
{{/each}}
</tbody>
<tfoot>
<td>{{__ "gesamt"}}</td>
<td>0.5</td>
<td>1</td>
<td>0.5 {{../currency_symbol}}</td>
<td>1 {{../currency_symbol}}</td>
</tfoot>
</table>
</main>