{% set seller = data.get('seller', {}) or {} %} {% set customer = data.get('customer', {}) or {} %} {% set invoice = data.get('invoice', {}) or {} %} {% set payment = data.get('payment', {}) or {} %} {% set items = data.get('items', []) or [] %} {% set materials = data.get('materials', []) or [] %} {% set notes_input = data.get('notes', data.get('message', [])) %} {% set notes = [notes_input] if notes_input is string else (notes_input or []) %} {% set currency_symbol = data.get('currency_symbol', 'kr') %} {% macro format_decimal(value, digits=2, trim_zero=False) -%} {%- set amount = (value or 0) | float -%} {%- set pattern = "{:,.%sf}" % digits -%} {%- set formatted = pattern.format(amount) | replace(",", " ") | replace(".", ",") -%} {%- if trim_zero and formatted[-3:] == ",00" -%} {{- formatted[:-3] -}} {%- else -%} {{- formatted -}} {%- endif -%} {%- endmacro %} {% macro format_percent(value, trim_zero=False) -%} {%- if value is none or value == '' -%} {%- else -%} {%- set raw = value | float -%} {%- set rate = raw / 100 if raw > 1 else raw -%} {{- format_decimal(rate * 100, 2, trim_zero) -}}% {%- endif -%} {%- endmacro %} {% macro meta_row(label, value) -%} {{ label }} {{ value | e if value is not none else '' }} {%- endmacro %} {% macro render_lines(lines) -%} {%- for line in lines if line -%}
{{ line | e }}
{%- endfor -%} {%- endmacro %} {% macro render_logo(class_name='') -%}
{{ seller.get('name', 'Company logo') | e }}
{%- endmacro %}
{{ render_logo('continuation-logo') }}
{{ invoice.get('title', 'Faktura') | e }}
{{ render_logo('header-logo') }}
{% if seller.get('name') %}
{{ seller.get('name') | e }}
{% endif %}
{{ render_lines(seller.get('address_lines', []) or []) }} {% if seller.get('phone') %}
{{ (seller.get('phone_label', 'Telefon') ~ ': ' ~ seller.get('phone')) | e }}
{% endif %}
{% set late_interest_rate = invoice.get('late_interest_rate') %}
{{ meta_row('Fakturadatum', invoice.get('issue_date', '')) }} {{ meta_row('Fakturanummer', invoice.get('invoice_number', '')) }} {{ meta_row('Kundnummer', invoice.get('customer_number', '')) }} {{ meta_row('Förfallodag', invoice.get('due_date', '')) }} {{ meta_row('Dröjsmålsränta', format_percent(late_interest_rate)) }} {{ meta_row('Betalningsvillkor', invoice.get('payment_terms', '')) }} {{ meta_row('Er referens', invoice.get('reference', '')) }}
{{ invoice.get('customer_label', 'Mottagare') | e }}
{% if customer.get('name') %}
{{ customer.get('name') | e }}
{% endif %}
{{ render_lines(customer.get('address_lines', []) or []) }}
{% set totals = namespace(subtotal=0.0, vat_total=0.0) %} {% for item in items %} {% set quantity = item.get('quantity', 0) | float %} {% set unit_price = item.get('unit_price', 0) | float %} {% set raw_vat_rate = item.get('vat_rate', 0) | float %} {% set vat_rate = raw_vat_rate / 100 if raw_vat_rate > 1 else raw_vat_rate %} {% set line_subtotal = (item.get('subtotal') if item.get('subtotal') is not none else quantity * unit_price) | float %} {% set line_vat = (item.get('vat_amount') if item.get('vat_amount') is not none else line_subtotal * vat_rate) | float %} {% set line_total = (item.get('line_total') if item.get('line_total') is not none else line_subtotal + line_vat) | float %} {% set totals.subtotal = totals.subtotal + line_subtotal %} {% set totals.vat_total = totals.vat_total + line_vat %} {% endfor %} {% if not items %} {% endif %}
Beskrivning Antal Enhet à pris Moms Moms kr Belopp
{{ item.get('description', '') | e }} {{ format_decimal(quantity, 2, True) }} {{ item.get('unit', '') | e }} {{ format_decimal(unit_price) }} {{ currency_symbol | e }} {{ format_percent(vat_rate, True) }} {{ format_decimal(line_vat) }} {{ currency_symbol | e }} {{ format_decimal(line_total) }} {{ currency_symbol | e }}
             
{% set rounding_amount = (data.get('rounding_amount') if data.get('rounding_amount') is not none else 0) | float %} {% set total_due = totals.subtotal + totals.vat_total + rounding_amount %}
{% if notes %}
Noteringar
{% for note in notes %}
{{ note | e }}
{% endfor %} {% endif %}
Belopp före moms {{ format_decimal(totals.subtotal) }} {{ currency_symbol | e }}
Total moms {{ format_decimal(totals.vat_total) }} {{ currency_symbol | e }}
Öresutjämning {{ format_decimal(rounding_amount) }} {{ currency_symbol | e }}
Summa att betala {{ format_decimal(total_due) }} {{ currency_symbol | e }}
{% if materials %}

Detaljerad tidsredovisning

Kund: {{ customer.get('name', 'Okand kund') | e }}
{% for material in materials %}

{{ material.get('project', '(no project)') | e }} - {{ material.get('task', '(no task)') | e }}

{% for entry in material.get('entries', []) or [] %} {% endfor %}
Beskrivning Starttid Sluttid Total tid Belopp
{{ entry.get('description', '') | e }} {{ ((entry.get('start_date') or '') ~ ' ' ~ (entry.get('start_time') or '')) | trim | e }} {{ ((entry.get('end_date') or '') ~ ' ' ~ (entry.get('end_time') or '')) | trim | e }} {% if entry.get('duration_text') %} {{ entry.get('duration_text') | e }} {% else %} {{ format_decimal(entry.get('duration_hours', 0), 2, True) }} h {% endif %} {% if entry.get('billable_amount_ex_vat_sek') is not none %} {{ format_decimal(entry.get('billable_amount_ex_vat_sek')) }} {{ currency_symbol | e }} {% elif entry.get('net_amount_sek') is not none %} {{ format_decimal(entry.get('net_amount_sek')) }} {{ currency_symbol | e }} {% elif entry.get('receipt_net_amount_sek') is not none %} {{ format_decimal(entry.get('receipt_net_amount_sek')) }} {{ currency_symbol | e }} {% elif entry.get('billable_amount_incl_vat_sek') is not none %} {{ format_decimal(entry.get('billable_amount_incl_vat_sek')) }} {{ currency_symbol | e }} {% elif entry.get('gross_amount_sek') is not none %} {{ format_decimal(entry.get('gross_amount_sek')) }} {{ currency_symbol | e }} {% elif entry.get('receipt_gross_amount_sek') is not none %} {{ format_decimal(entry.get('receipt_gross_amount_sek')) }} {{ currency_symbol | e }} {% elif entry.get('fare_sek') is not none %} {{ format_decimal(entry.get('fare_sek')) }} {{ currency_symbol | e }} {% else %} - {% endif %}
{% endfor %}
{% endif %}