{{ "now"|date("d.m.Y") }}
{{ model.created_at|date_modify("+180 day")|date("m.d.Y")}}
In the basic templates, variables are written as follows:
{{ product_price|format_currency('USD', locale='en') }}
To replace the currency display with «dollar», simply delete |format_currency(‘USD’, locale=‘en’) and move «dollar» outside the curly brackets:
{{ product_price }} dollar
Set the parameters for creating the desired variable:
{% set mnths = ['','January','February','March','April','May','June','July', 'August','September','October','November','December'] %}
After that, we write the variable itself in the right place:
{{ model.created_at|date("j") }} {{ mnths[model.created_at|date("n")] }} {{ model.created_at|date("Y") }}.
<img src="{{ product.picture }}" height="100">
{% set gtc = model.products_sum|round(0, 'floor') %}
{% set gtr = model.products_sum * 100 % 100 %}
<strong>{{ ((gtc|format_number(style="spellout", locale="en"))|capitalize) }}
{% set currencySuffix = (gtc % 100 >= 11 and gtc % 100 <= 14) ? 'dollars' : (gtc % 10 == 1) ?
'dollar' : (gtc % 10 >= 2 and gtc % 10 <= 4) ? 'dollar' : 'dollar' %}
{{ currencySuffix }}
{{ gtr|format_number(locale="en") }}
{% set centsSuffix = (gtr % 100 >= 11 and gtr % 100 <= 14) ? 'cents' : (gtr % 10 == 1) ?
'cent' : (gtr % 10 >= 2 and gtr % 10 <= 4) ? 'cents' : 'cents' %}
{{ centsSuffix }}</strong>
To add payment information to a document, you need to use a for loop. It allows you to get a list of all payments that are in the card and output the data of the variables you need.
An example of a list of all payments from a card with variables available for output:
{% for payment in model.payments %}
{{ payment.payment_date }} - payment date and time
{{ payment.type }} - payment type
{{ payment.status }} - payment status
{{ payment.amount }} - payment amount
{{ payment.description }} - description
{% endfor %}
An example of displaying all records of payments made by bank card in the card with the status «Paid», indicating only the date and amount:
{% for payment in model.payments %}
{% if payment.type == "Bank card" %}
{% if payment.status == "paid" %}
Date and time of payment: {{ payment.payment_date }}<br>
Payment amount: {{ payment.amount|format_currency('USD', locale='en') }}
{% endif %}
{% endif %}
{% endfor %}
You have already paid: {% for payment in model.payments %}
{% if payment.status == "paid" %}{{ payment.amount|format_currency('USD', locale='en') }}, {% endif %}{% endfor %}
{% set paid_amount = 0 %}
{% for payment in model.payments %}
{% if payment.status == "paid" %}
{% set paid_amount = paid_amount + payment.amount %}
{% endif %}
{% endfor %}
Balance due: {{ ( model.products_sum - paid_amount)|format_currency('USD', locale='en') }}
You can add currency formatting to the variable:
{{ product.price_sold|format_currency('USD', locale='en') }}
Or formatting to display 2 digits after the comma:
{{ product.price_sold|number_format(2, ',', '') }}
If mathematical rounding to a smaller or larger number is required:
{{ product.price_sold|format_currency('USD', locale='en') }}
If rounding is always required to the greater value:
{{ model.grand_total|round(0, 'floor')|format_currency(currency, locale='de') }}
If rounding is always required to the lower value:
{{ model.grand_total|round(0, 'ceil')|format_currency(currency, locale='de') }}