Skip to content

Instantly share code, notes, and snippets.

@iBobik
Created July 11, 2018 22:39
Show Gist options
  • Select an option

  • Save iBobik/a61f3a3ffe757103107c1d9e54aae850 to your computer and use it in GitHub Desktop.

Select an option

Save iBobik/a61f3a3ffe757103107c1d9e54aae850 to your computer and use it in GitHub Desktop.
Drupal 8 Commerce 2 Twig template for rendering order as an CZ/EU invoice. This is rendered to PDF by entity_print then. Also includes "QR Faktura" - Czech standardized QR code format for invoices and bank transfers.
{#
/**
* @file
* Template for orders in the 'user' view mode.
*
* Available variables:
* - attributes: HTML attributes for the wrapper.
* - order: The rendered order fields.
* Use 'order' to print them all, or print a subset such as
* 'order.order_number'. Use the following code to exclude the
* printing of a given field:
* @code
* {{ order|without('order_number') }}
* @endcode
* - order_entity: The order entity.
*
* @ingroup themeable
*/
#}
<h1>Faktura {{ order.order_number[0] }}</h1>
<div style="margin: 2em 0 0 0">
<style>
h2 {
font-size: 1.1em;
}
p.address {
margin: 0;
}
.field--label-inline > * {
display: inline;
}
.field--label-inline .field__label:after {
content: ":";
}
</style>
<div style="float: left; width: 50%">
<h2>Dodavatel</h2>
{{ order.store_id[0] }}
</div>
<div style="float: left">
<h2>Odběratel</h2>
{{ order.billing_information }}
</div>
</div>
<div style="clear: both; padding-top: 1em"></div>
{% set store = order.store_id[0]['#commerce_store'] %}
Datum vystavení a splatnosti: {{ order_entity.getCreatedTime() | format_date('custom', 'j. n. Y') }}<br>
Číslo účtu: {{ store.field_bankaccount.getString() }}<br>
Variabilní symbol: {{ order.order_number[0] }}
<style>
table {
margin-top: 1em;
width: 100%;
}
.field--name-total-price,
.views-field-unit-price__number,
.views-field-quantity,
.views-field-total-price__number {
text-align: right;
}
</style>
{{ order.order_items }}
{{ order.total_price }}
<img src="https://api.qrfgen.cz/generator/image?ID={{ order.order_number[0] -}}
&AM={{ order.total_price[0]['#totals']['total'].getNumber() -}}
&CC={{ order.total_price[0]['#totals']['total'].getCurrencyCode() -}}
&DD={{ order_entity.getCreatedTime() | format_date('custom', 'Ymd') -}}
&DT={{ order_entity.getCreatedTime() | format_date('custom', 'Ymd') -}}
&VS={{ order.order_number[0] -}}
&ACC={{ store.field_iban.getString() -}}
&INI={{ store.field_ico.getString() -}}
&INR={{ order.billing_information['#profile'].field_ico.getString() -}}
&ks=9&qrplatba=1" style="margin-top: 2em">
@iBobik
Copy link
Copy Markdown
Author

iBobik commented Jul 12, 2018

invoice example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment