TWIG: How to print/select all invoice-tasks like invoice-items?

Hey guys!

I’m trying to modify my invoice- and quote-designs by using twig. But somehow i cannot create a table for the tasks. My code is:

<ninja>
            {% if invoices %}
                {% set invoice = invoices|first %}

                {% if invoice.line_items|e %}
                    <table class="artikelliste">
                        <thead>
                            <tr>
                                <th>Artikel</th>
                                <th>Preis</th>
                                <th>Menge</th>
                                <th>USt.</th>
                                <th>Rabatt</th>
                                <th>Gesamt</th>
                            </tr>
                        </thead>

                        <tbody>
                        {% for item in invoice.line_items|filter(item => item.type_id == 1) %}
                            <tr>
                                <td>{{ item.product_key }}
                                    <p class="artikeldetails">{{ item.notes }}</p>
                                </td>
                                <td>{{ item.cost }}</td>
                                <td>{{ item.quantity }}</td>
                                <td>{{ item.tax_rate1 }}</td>
                                <td>{{ item.discount }}</td>
                                <td>{{ item.line_total }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>					
                {% endif %}

                {% if tasks|e %}

                <table class="artikelliste">
                    <thead>
                        <tr>
                            <th>Dienstleistung</th>
                            <th>€/Std.</th>
                            <th>Menge</th>
                            <th>USt.</th>
                            <th>Rabatt</th>
                            <th>Gesamt</th>
                        </tr>
                    </thead>

                    <tbody>
                    {% for task in tasks %}
                        <tr>
                            <td>{{ task.description }}
                                {% for t in task.time_log %}
                                    <div class="task-dauer">{{ t.start_date }} bis {{ t.end_date }}, {{ (t.duration/60/60) }}</div>
                                    <div class="task-protokoll">{{ t.description }}</div>
                                {% endfor %}
                            </td>
                            <td>{{ task.rate }}</td>
                            {% set duration = (task.duration/60/60) %}
                            <td>{{ duration }}</td>
                            <td>{{ item.tax_rate1 }}</td>
                            <td>{{ item.discount }}</td>
                            <td>{{ (task.rate_raw * duration)|format_currency(invoice.client.currency, locale=invoice.client.locale) }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
                {% endif %}
                
            {% endif %}
            </ninja>

I guess I must filter the tasks to those who are linked to the entity. But how?

Hi,

If I’m understanding correctly you can use:

{% for item in invoice.line_items|filter(item => item.type_id == 2) %}

Ahhhhh, I already thought so when I found the item-type_id in the API-documentation. But I wasn’t sure.

I’ll try it and give a feedback afterwards! :smiley:

It looks right, but it does not work. I use the twig-code within my designs. But at one point the design won’t update; and there’s no error-description at all. Well, It seems that I’ll have to wait for the next implementations. :slight_smile:

Are you using the latest version of the app, I believe there have been some related changes recently.

Hello!

As I use Docker I usually do an update everytime when I’m trying to improve my invoice-designs. Last update was yesterday after your last posting.

But please have a look on my next forums-posting. There’s something going really wrong with my installation I guess. At least the React-web-app does not work correctly on my configuration it seems.

Greetings!

Hey @hillel and @david,
well, it seems that the type_id 2 does not work or there are no services in the invoice-example-data of the template-editor available.
If one does not know, which data are available, creating a template is like a roulette-game, you know. And sadly there’s no feedback where an error in the code occurs. Then just the recreating of the pdf results in a non-updated pdf (although first it looks like a new, updated pdf is created).
That’s really kind of exciting … :wink:
Always thankful for your help
Schmitti :smiley: