I was pleasantly surprised to discover the generate pdf using Markdown template function. I could achieve my first version of the invoice quickly and with a clean Markdown template. However, I noticed that currencies and time formats were not taken from the UI; currency fields seem to be rendered as numbers and dates seem to be rendered using a default locale.
I learned I can work around this using Javascript, but the code gets out of hand quickly and looses the clarity of the plain Markdown template I had in my first iteration.
I will share my template below. This are the issues I have:
- Dates not formatted in my nl-nl locale
- Money fields in the invoice line table formatted as plain numbers
- I need to cache the field values before I can use them in Javascript
- The table shorthand
{{Invoice Lines: ...
will require a Javascript replacement, because money fields are not using currency formatting - the template lacks clarity and this makes it prone to errors, which I do not want in my invoices
Alternative I consider is to use a local Pyhton script that retrieves invoice data using graphql api, generates a pdf and attaches it to the invoice in Fibery.
Any thoughts on how I can address the above issues in my current template?
This is my current template:
<%
// nl-NL and de-DE locales do not work, so go with en-US and replace
const cur = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'EUR',
minimumFractionDigits: 2, // (0 will print 2500.10 as $2,500.1)
maximumFractionDigits: 2, // (0 causes 2500.99 to be printed as $2,501)
});
function fmtcur(fieldName){
return cur.format(Entity[fieldName]).replace(',', ' ').replace('.', ',');
}
%>
<!-- START OF TEMPLATE -->
![Logo Serra ICT Diensten](https://www.serraict.com/assets/img/logo.png)
### Van:
Serra ICT Diensten <br/>
Hugo de Grootstraat 58 <br/>
2613TW Delft <br/>
info@serraict.com
### Aan:
{{Customer Name}}<br/>
{{Customer Address}}<br/>
{{Customer Zipcode}} {{Customer City}}<br/>
{{Customer Email}}
### Betreft:
Factuurnummer: {{Invoice Number}}<br/>
Uw referentie: {{Customer Reference}}<br/>
Factuurdatum: {{Invoice Date}}<br/>
Vervaldatum: {{Due Date}}<br/>
# Factuur {{Name}}
### Diensten:
{{Invoice Lines:Name, Quantity, Unit Price, Total Price}}
<!--
Retrieve these values so that we can use them in Javascript
{{VAT}} {{Total Amount}} {{Total Including VAT}}
-->
Subotaal: <%= fmtcur("Total Amount") %> <br/>
BTW ({{VAT Percentage}}): <%= fmtcur("VAT") %> <br/>
__Totaal: <%= fmtcur("Total Including VAT") %> <br/>__
<br/>
<br/>
---
www.serraict.com - \o/ more company info here \o/