kimai / invoice-templates

A place for sharing Kimai invoice templates
MIT License
16 stars 9 forks source link

[din5008.pdf.twig] Custom invoice date not been set #13

Closed affeldt28 closed 8 months ago

affeldt28 commented 9 months ago

Describe the issue

When I'm creating a new invoice and set a custom invoice date, the date on the invoice is always the current date.

I already tried

Kimai version

2.5.0

How do you run Kimai?

Docker

Which PHP version are you using?

8.1

Logfile

No response

Screenshots

No response

kevinpapst commented 9 months ago

Works for me. Which invoice template do you use?

affeldt28 commented 9 months ago

I'm using a custom template, I've found online. Now that you say that, the built in templates work just fine. I not very familiar with twig and how to use it, for my eyes this looks ok. Could you check this out and tell me what could cause the problem, so I can look into that?

din5008.pdf.twig ```twig {%- set setAutoTopMargin = pdfContext.setOption('setAutoTopMargin', false) -%} {%- set setAutoBottomMargin = pdfContext.setOption('setAutoBottomMargin', false) -%} {%- set marginBottom = pdfContext.setOption('margin_bottom', 20) -%} {%- set marginLeft = pdfContext.setOption('margin_left', 25) -%} {%- set marginRight = pdfContext.setOption('margin_right', 20) -%} {# You can override the following variables in your own template to customize the template: #} {# set logo url #} {% set logoUrl = logoUrl|default(config('theme.branding.logo')) %} {# set font family #} {% set fontFamily = fontFamily|default("'Arial', sans-serif") %} {# set the sender address that is displayed in the address window #} {% set invoiceSenderAddress = invoiceSenderAddress|default(invoice['template.company'] ~ ' • ' ~ invoice['template.address']|nl2str(' • ')) %} {# set if fold and hole marks are printed #} {% set showFoldHoleMarks = showFoldHoleMarks ?? true %} {% set fallback = app.request is not null ? app.request.locale : 'en' %} {% set language = invoice['template.language']|default(fallback) %} {% set isDecimal = invoice['template.decimalDuration']|default(false) %} {% set currency = invoice['currency'] %} {% block title %}{{ invoice['invoice.number'] }}-{{ invoice['customer.company']|default(invoice['customer.name'])|u.snake }}{% endblock %} {% block invoice_styles %} {% endblock %} {% block invoice_address %}
{% block invoice_address_sender %}
{{ invoiceSenderAddress|raw }}
{% endblock %} {% block invoice_address_recipient %}
{{ invoice['customer.company']|default(invoice['customer.name']) }}

{{ invoice['customer.address']|nl2br }}
{% endblock %}
{% endblock %} {% block invoice_details %}
{% block invoice_details_invoice_date %} {% endblock %} {% block invoice_details_vatid %} {% if invoice['template.vat_id'] is not empty %} {% endif %} {% endblock %} {% block invoice_details_customer_number %} {% endblock %} {% block invoice_details_invoice_number %} {% endblock %} {% block invoice_details_contact %} {% if invoice['template.contact'] is not empty %} {% for line in invoice['template.contact']|split("\n") %} {% set lineData = line|split(':', 2) %} {% if lineData|length > 1 %} {% endif %} {% endfor %} {% endif %} {% endblock %}
{{ 'date'|trans }}: {{ invoice['invoice.date']|date('d.m.Y') }}
{{ 'vat_id'|trans }}: {{ invoice['template.vat_id'] }}
{{ 'number'|trans }}: {{ invoice['customer.number'] }}
{{ 'invoice.number'|trans }}: {{ invoice['invoice.number'] }}
{{ attribute(lineData, 0) }}: {{ attribute(lineData, 1) }}
 
{% endblock %}
{% block invoice_content %}
{% block invoice_content_subject %}

{{ invoice['template.title'] }}

{% endblock %} {% block invoice_content_introduction %} {% if invoice['customer.invoice_text'] is not empty%}

{{ invoice['customer.invoice_text']|md2html }}

{% endif %} {% endblock %} {% block invoice_content_items %}
{% for invoiceLineItem in entries %} {% endfor %} {% if invoice['invoice.tax_hide'] %} {% endif %}
{{ 'description'|trans }} {{ 'amount'|trans }} {{ 'unit_price'|trans }} {{ 'total_rate'|trans }}
{{ invoiceLineItem['entry.project'] }} {% if invoiceLineItem['entry.description'] is not empty %} {{ invoiceLineItem['entry.description']|nl2br }} {% else %} {{ invoiceLineItem['entry.activity']|nl2br }} {% endif %} {{ invoiceLineItem['entry.amount'] }} {{ invoiceLineItem['entry.rate'] }} {{ invoiceLineItem['entry.total'] }}
{{ 'invoice.subtotal'|trans }} {{ invoice['invoice.subtotal'] }}
{{ 'invoice.tax'|trans }} ({{ invoice['invoice.vat'] }}%) {{ invoice['invoice.tax'] }}
{{ 'invoice.total'|trans }} {{ invoice['invoice.total'] }}
{{ 'invoice.total'|trans }} {{ invoice['invoice.total'] }}
{% endblock %}
{% block payment_terms %} {% if invoice['template.payment_terms'] is not empty %}

{{ invoice['template.payment_terms']|md2html }}

{% endif %} {% endblock %}
{% endblock %} ```
kevinpapst commented 9 months ago

ping @LiaraAlis

LiaraAlis commented 8 months ago

@kevinpapst The template @affeldt28 mentioned looks very similar to my din5008 template, but it is not the same - it is very different. I tested the template from this repository and cannot reproduce this issue.

@affeldt28 Where did you find the template? Can you please try the template from this repository (https://github.com/kimai/invoice-templates/blob/main/din5008-invoice/din5008-invoice.pdf.twig)?

affeldt28 commented 8 months ago

I don't know anymore where I got this template from, maybe I also edited by myself.

With the template from this repo it also works for me, but the date is formatted like dd.mm.yy but I like to have it this dd.mm.yyyy

kevinpapst commented 8 months ago

Then you have to change this line: https://github.com/kimai/invoice-templates/blob/main/din5008-invoice/din5008-invoice.pdf.twig#L334

affeldt28 commented 8 months ago

But when I change invoice['invoice.date']|date_short to invoice['invoice.date']|date('d.m.Y') it always shows the current date. The array syntax documented way to access the variables: https://www.kimai.org/documentation/invoices.html#template-variables

Is it safe to use model.invoiceDate? It's stated here (https://www.kimai.org/documentation/invoices.html#twig-templates) that I should not rely on the model variable.

affeldt28 commented 8 months ago

Ping @kevinpapst

kevinpapst commented 8 months ago

I do like that your read the docs. But I don't like pings for nothing. Thousands use Kimai, what would happen if everyone does that?

I did not answer, because you are can try if it works.