[Skip to main content](#vessel-content)

#   Calculate subtotal at PDF invoice

##

- **[miracle](/forum/user/17825-miracle "View miracle's Profile")**
- [![miracle's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/17825-miracle "View miracle's Profile") Topic Author
- [ Offline](/forum/user/17825-miracle)

Less More

- Posts: 91
- Thank you received: 3
-
-

12 years 7 months ago [\#150091](#150091) by [miracle](/forum/user/17825-miracle "View miracle's Profile")  *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150091 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")* was created by *[miracle](/forum/user/17825-miracle "View miracle's Profile")*

Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).

See the attachment. Let me first translate the 5 rows with Dutch words. It says:
- Subtotal before VAT and discount
- Discount
- Shipping
- Subtotal
- VAT

As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation.
It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping.
In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.

Can you help me with the code?

- [ ![ha6d9d57.png](/forum/attachment/16349) ](/forum/attachment/16349 "ha6d9d57.png") [ ](/forum/attachment/16349?download=1 "ha6d9d57.png")
- [ ![h92624cb.png](/forum/attachment/16350) ](/forum/attachment/16350 "h92624cb.png") [ ](/forum/attachment/16350?download=1 "h92624cb.png")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

12 years 7 months ago [\#150274](#150274) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150274 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

Hi,

You just have to use this kind of code: Code:

if($config-&gt;get('price_with_tax')){ $yourSubtotal = (float)$order-&gt;order_subtotal + (float)$order-&gt;order_discount_price*-1 + (float)$order-&gt;order_shipping_price; echo $currencyHelper-&gt;format($yourSubtotal, $order-&gt;order_currency_id); }else{ $yourSubtotal = (float)$order-&gt;order_subtotal_no_vat + ((float)$order-&gt;order_discount_price-(float)@$order-&gt;order_discount_tax)*-1 + ((float)$order-&gt;order_shipping_price - (float)@$order-&gt;order_shipping_tax); echo $currencyHelper-&gt;format($yourSubtotal, $order-&gt;order_currency_id); }

The following user(s) said Thank You: [miracle](/forum/user/17825-miracle "View miracle's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[miracle](/forum/user/17825-miracle "View miracle's Profile")**
- [![miracle's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/17825-miracle "View miracle's Profile") Topic Author
- [ Offline](/forum/user/17825-miracle)

Less More

- Posts: 91
- Thank you received: 3
-
-

12 years 7 months ago [\#150295](#150295) by [miracle](/forum/user/17825-miracle "View miracle's Profile")  Replied by *[miracle](/forum/user/17825-miracle "View miracle's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150295 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

Thanks for the code, it works fine. But unfortunately another problem. I'm wondering if I have caused this problem or if it's a standard issue with the PDF invoice plugin.

At this moment the VAT is calculated over the whole amount. The 25% discount we currently give is not used when calculating the VAT. It doesn't matter if I select in Configuration to calculate the discount exclusive or inclusive VAT.

See the attachment. VAT should have been € 105,84 (21% of € 504,00) but is now incorrectly € 141,12 (21% of € 672,00)

- [ ![h4193655.png](/forum/attachment/16409) ](/forum/attachment/16409 "h4193655.png") [ ](/forum/attachment/16409?download=1 "h4193655.png")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

12 years 7 months ago [\#150806](#150806) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150806 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

Hi,

Are you talking about the option "Apply discounts" in Configuration &gt; Main &gt; Taxes ?

Are the prices correct in the checkout, or in any other place in the site ?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[miracle](/forum/user/17825-miracle "View miracle's Profile")**
- [![miracle's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/17825-miracle "View miracle's Profile") Topic Author
- [ Offline](/forum/user/17825-miracle)

Less More

- Posts: 91
- Thank you received: 3
-
-

12 years 7 months ago -  12 years 7 months ago [\#150807](#150807) by [miracle](/forum/user/17825-miracle "View miracle's Profile")  Replied by *[miracle](/forum/user/17825-miracle "View miracle's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150807 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

Can someone please have a look at this system. The VAT is calculated wrong and the customers are complaining....

Update: I just posted this message while you were answering. Must be telepathy ![;-)](/media/kunena/emoticons/24.png ";-)")

Last edit: 12 years 7 months ago by [miracle](/forum/user/17825-miracle "View miracle's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[miracle](/forum/user/17825-miracle "View miracle's Profile")**
- [![miracle's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/17825-miracle "View miracle's Profile") Topic Author
- [ Offline](/forum/user/17825-miracle)

Less More

- Posts: 91
- Thank you received: 3
-
-

12 years 7 months ago [\#150809](#150809) by [miracle](/forum/user/17825-miracle "View miracle's Profile")  Replied by *[miracle](/forum/user/17825-miracle "View miracle's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150809 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

"It doesn't matter if I select in Configuration to calculate the discount exclusive or inclusive VAT." was about Configuration &gt; Main &gt; Taxes

I now see the VAT calculation is going wrong already in the checkout (that's the first place customers will see the discount).

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14325
-
-

12 years 7 months ago [\#150808](#150808) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150808 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

The VAT will be calculated taking the discount into account or not based on how you configured the "apply discount" option of the configuration and how you configured the "tax category" option of your coupon. So please try the different combinations with a new order each time and you should find what you want.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[miracle](/forum/user/17825-miracle "View miracle's Profile")**
- [![miracle's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/17825-miracle "View miracle's Profile") Topic Author
- [ Offline](/forum/user/17825-miracle)

Less More

- Posts: 91
- Thank you received: 3
-
-

12 years 7 months ago [\#150895](#150895) by [miracle](/forum/user/17825-miracle "View miracle's Profile")  Replied by *[miracle](/forum/user/17825-miracle "View miracle's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150895 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

So many options, I didn't know / remember this one. But it was the one I needed, now it seems to work good.
Is it easy to modify the existing orders to get a correct invoice?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

12 years 7 months ago [\#150911](#150911) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Calculate subtotal at PDF invoice](/forum/35-orders-management/867017-calculate-subtotal-at-pdf-invoice#150911 "Hi, I use the the invoice PDF plugin. My client wants to have the calculations more specific and I must say there is some improvement possible (it took me a while to understand the invoice myself).  See the attachment. Let me first translate the 5 rows with Dutch words. It says: - Subtotal before VAT and discount - Discount - Shipping - Subtotal - VAT  As you see the Subtotal is empty. That's because I just created it and I don't know how to do the calculation. It should be calculated the following way: Subtotal = Subtotal before VAT and discount + Discount + Shipping. In this specific example it should be € 20,00 + (- € 5,00) + € 5,00 = € 20,00.  Can you help me with the code?")*

Hi,

No it's working the same way than in the PDF invoice, you have to edit the view "order / show" (frontend template) via the menu Display &gt; Views.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg2NzAxNy1jYWxjdWxhdGUtc3VidG90YWwtYXQtcGRmLWludm9pY2U/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.084 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
