How can I separate product and shipping tax on my invoice slip?

StudioVliering
New Member
20 0 0

Hi,

 

I'm trying to update the code below so that my customers see the tax of the orders seperate for the products and shipping. But it isn't working out. Can someone please help me with this:

 

<p style="float: right; text-align: right; margin: 0;">
{{ "now" | date: "%d/%m/%y" }}<br />
Factuur voor bestelling {{ order_name }}
</p>

<div style="float: left; margin: 0 0 1.5em 0;" >
<strong style="font-size: 2em;">{{ shop_name }}</strong><br /><br />
{{ shop.address }}<br/>
{{ shop.city }} {{ shop.province_code }} {{ shop.zip | upcase }}<br/>
{{ shop.country }}
<p>KVK nummer 71969713</p>
<p>BTW-nummer NL858922137B01</p>
</div>
{% if note %}
<h3 style="margin: 0 0 1em 0;">PO Nummer of boodschap:</h3>
<p>{{ note }}</p>
{% endif %}
<hr />

<h3 style="margin: 0 0 1em 0;">Item Details</h3>

<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<thead>
<tr>
<th>Aantallen</th>
<th>Product</th>
{% if show_line_item_taxes %}
<th>BTW</th>
{% endif %}
<th>Prijs</th>
</tr>
</thead>
<tbody>
{% for line_item in line_items %}
<tr>
<td>{{ line_item.quantity }} x</td>
<td><b>{{ line_item.title }}</b></td>
{% if show_line_item_taxes %}
<td>
{% for tax_line in line_item.tax_lines %}
{{ tax_line.price | money }} {{ tax_line.title }}<br/>
{% endfor %}
</td>
{% endif %}
<td>
{% if line_item.original_price != line_item.price %}
<s>{{ line_item.original_price | money }}</s>
{% endif %}
{{ line_item.price | money }}
</td>
</tr>
{% endfor %}
</tbody>
</table>

{% if transactions.size > 1 %}
<h3 style="margin: 0 0 1em 0;">Betaling Details</h3>
<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<thead>
<tr>
<th>Type</th>
<th>Amount</th>
<th>Kind</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for transaction in transactions %}
<tr>
<td>{{ transaction.gateway | payment_method }}</td>
<td>{{ transaction.amount | money }}</td>
<td>{{ transaction.kind }}</td>
<td>{{ transaction.status }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}

<h3 style="margin: 0 0 1em 0;">Betaling Details</h3>

<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<tr>
<td>Totaal bedrag:</td>
<td>{{ subtotal_price | money }}</td>
</tr>
{% for discount in discounts %}
<tr>
<td>Includes discount "{{ discount.code }}"</td>
<td>{{ discount.savings | money }}</td>
</tr>
{% endfor %}
<tr>
<td>Totale BTW:</td>
<td>{{ tax_price | money }}</td>
</tr>
{% if shipping_address %}
<tr>
<td>Verzending:</td>
<td>{{ shipping_price | money }}</td>
</tr>
{% endif %}
<tr>
<td><strong>Totaal incl. BTW en verzendkosten:</strong></td>
<td><strong>{{ total_price | money }}</strong></td>
</tr>
{% if total_paid != total_price %}
<tr>
<td><strong>Total betaald:</strong></td>
<td><strong>{{ total_paid | money }}</strong></td>
</tr>
<tr>
<td><strong>Openstaand bedrag:</strong></td>
<td><strong>{{ total_price | minus: total_paid | money }}</strong></td>
</tr>
{% endif %}
</table>

{% if shipping_address %}
<h3 style="margin: 0 0 1em 0;">Verzendadres:</h3>

<div style="margin: 0 0 1em 0; padding: 1em; border: 1px solid black;">
<strong>{{ shipping_address.name }}</strong><br/>
{{ shipping_address | format_address }}
</div>
{% endif %}

<p>Bij vragen over de factuur graag mailen naar administratie@dekoekfabriek.com</p>

Replies 4 (4)

ki2la
Visitor
2 0 0

To display the tax of orders separately for products and shipping, you will need to make some changes to the code.

First, you will need to calculate the tax for each line item and the shipping separately. You can do this by using the line_item.tax_lines and shipping_line.tax_lines arrays and summing up the price attribute for each tax line.

Then, you will need to update the template to display the tax for each line item and shipping separately. Here's an updated template that should work:

<p style="float: right; text-align: right; margin: 0;">
{{ "now" | date: "%d/%m/%y" }}<br />
Factuur voor bestelling {{ order_name }}
</p>

<div style="float: left; margin: 0 0 1.5em 0;" >
<strong style="font-size: 2em;">{{ shop_name }}</strong><br /><br />
{{ shop.address }}<br/>
{{ shop.city }} {{ shop.province_code }} {{ shop.zip | upcase }}<br/>
{{ shop.country }}
<p>KVK nummer 71969713</p>
<p>BTW-nummer NL858922137B01</p>
</div>
{% if note %}
<h3 style="margin: 0 0 1em 0;">PO Nummer of boodschap:</h3>
<p>{{ note }}</p>
{% endif %}
<hr />

<h3 style="margin: 0 0 1em 0;">Item Details</h3>

<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<thead>
<tr>
<th>Aantallen</th>
<th>Product</th>
{% if show_line_item_taxes %}
<th>BTW</th>
{% endif %}
<th>Prijs</th>
</tr>
</thead>
<tbody>
{% for line_item in line_items %}
{% assign line_item_tax = 0 %}
{% for tax_line in line_item.tax_lines %}
{% assign line_item_tax = line_item_tax | plus: tax_line.price %}
{% endfor %}
<tr>
<td>{{ line_item.quantity }} x</td>
<td><b>{{ line_item.title }}</b></td>
{% if show_line_item_taxes %}
<td>{{ line_item_tax | money }}</td>
{% endif %}
<td>
{% if line_item.original_price != line_item.price %}
<s>{{ line_item.original_price | money }}</s>
{% endif %}
{{ line_item.price | money }}
</td>
</tr>
{% endfor %}
{% if shipping_line %}
{% assign shipping_tax = 0 %}
{% for tax_line in shipping_line.tax_lines %}
{% assign shipping_tax = shipping_tax | plus: tax_line.price %}
{% endfor %}
<tr>
<td></td>
<td>Shipping</td>
{% if show_line_item_taxes %}
<td>{{ shipping_tax | money }}</td>
{% endif %}
<td>{{ shipping_price | money }}</td>
</tr>
{% endif %}
</tbody>
</table>

{% if transactions.size > 1 %}
<h3 style="margin: 0 0 1em 0;">Betaling Details</h3>
<table class="table-tabular" style="margin: 0 0 1.5em 0;">
<thead>
<tr>
<th>Type</th>
<th>Amount</th>
<th>Kind</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for transaction in transactions %}
<tr>
<td>{{ transaction.gateway | payment_method }}</td>
<td>{{ transaction.amount | money }}</td>
<td>{{ transaction.kind }}</td>
<td>{{ transaction.status }}</td>
</tr>
{% endfor %}
</tbody>
</table

It seems like the error where I encountered with in: https://www.howtodo.blog 

 

StudioVliering
New Member
20 0 0

Thanks Ki2la, when I try this. It is not completely working maybe I still do something wrong? Please see the preview of the overview where we want to show the tax. But it still says 0,- 

Schermafbeelding 2023-03-16 om 13.21.18.png

 

ki2la
Visitor
2 0 0

To show the tax of the orders separately for the products and shipping, you can add the following changes to the code:

Add two new variables product_tax_price and shipping_tax_price to calculate the tax for products and shipping respectively.

Update the table to show the new tax prices. You can add two new rows to the table: one for product tax and one for shipping tax.

Here's the updated code:

less
Copy code
{% assign product_tax_price = 0 %}
{% assign shipping_tax_price = 0 %}

{% for line_item in line_items %}
{% for tax_line in line_item.tax_lines %}
{% if line_item.line_price == shipping_price %}
{% assign shipping_tax_price = shipping_tax_price | plus: tax_line.price %}
{% else %}
{% assign product_tax_price = product_tax_price | plus: tax_line.price %}
{% endif %}
{% endfor %}
{% endfor %}

...

<tr>
<td>Totale BTW voor producten:</td>
<td>{{ product_tax_price | money }}</td>
</tr>
{% if shipping_address %}
<tr>
<td>Totale BTW voor verzending:</td>
<td>{{ shipping_tax_price | money }}</td>
</tr>
{% endif %}

...

<tr>
<td>Totale BTW:</td>
<td>{{ tax_price | money }}</td>
</tr>
{% if shipping_address %}
<tr>
<td>Verzending:</td>
<td>{{ shipping_price | money }}</td>
</tr>
<tr>
<td>Totale BTW voor verzending:</td>
<td>{{ shipping_tax_price | money }}</td>
</tr>
{% endif %}
<tr>
<td><strong>Totaal incl. BTW voor producten:</strong></td>
<td><strong>{{ product_price | money }}</strong></td>
</tr>
{% if shipping_address %}
<tr>
<td><strong>Totaal incl. BTW voor verzending:</strong></td>
<td><strong>{{ shipping_price | money }}</strong></td>
</tr>
{% endif %}
<tr>
<td><strong>Totaal incl. BTW:</strong></td>
<td><strong>{{ total_price | money }}</strong></td>
</tr>
Here, we calculate the tax for each line item, and if the line item is a shipping line item, we add the tax to the shipping_tax_price variable; otherwise, we add it to the product_tax_price variable. We then show these values in the table by adding two new rows: one for product tax and one for shipping tax.

 

Try this, if it is not working, please wait for someone else to reply to it. Pardon me 🙂

StudioVliering
New Member
20 0 0

Can some body else help me with this? It is still not working good. Thanks in advance!