Calculate subtotal at PDF invoice

  • Posts: 91
  • Thank you received: 3
10 years 7 months ago #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?

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 7 months ago #150274

Hi,

You just have to use this kind of code:

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

The following user(s) said Thank You: miracle

Please Log in or Create an account to join the conversation.

  • Posts: 91
  • Thank you received: 3
10 years 7 months ago #150295

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)

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 7 months ago #150806

Hi,

Are you talking about the option "Apply discounts" in Configuration > Main > Taxes ?

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

Please Log in or Create an account to join the conversation.

  • Posts: 91
  • Thank you received: 3
10 years 7 months ago #150807

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 ;-)

Last edit: 10 years 7 months ago by miracle.

Please Log in or Create an account to join the conversation.

  • Posts: 91
  • Thank you received: 3
10 years 7 months ago #150809

"It doesn't matter if I select in Configuration to calculate the discount exclusive or inclusive VAT." was about Configuration > Main > 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 or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
10 years 7 months ago #150808

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 or Create an account to join the conversation.

  • Posts: 91
  • Thank you received: 3
10 years 7 months ago #150895

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 or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 7 months ago #150911

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 > Views.

Please Log in or Create an account to join the conversation.

Time to create page: 0.081 seconds
Powered by Kunena Forum