VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: stensbo on January 24, 2019, 11:46:39 AM

Title: VAT is calculated incorrectly after upgrade
Post by: stensbo on January 24, 2019, 11:46:39 AM
Hello,
Using Joomla 3.9.2, Virtuemart 3.4.3 10005, PHP Version 7.1.26, vm overrides.
template Storefront version 3.23.3

I discovered that VAT is calculated wrong (on cart) if a discount is given. (i think after update to 3.4.2)

Attached image of calculation on cart - Moms(VAT) correctly should have been DKK 52,92 and Total Amount correctly should have been DKK 264,60.

We use
Vat rule: TaxBill - Vat pr. invoice (B2B)
Discount  rule: DBTaxBill - Price -% modification before Tax per bill.

I don't know if this is a bug ... debug comes with some notice


Notice: Undefined index: subTotal in /var/www/..../administrator/components/com_virtuemart/helpers/calculationh.php on line 834

Notice: Undefined index: percentage in /var/www/..../administrator/components/com_virtuemart/helpers/calculationh.php on line 917


Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on February 13, 2019, 13:22:29 PM
Hello,
Just tested with VirtueMart 3.4.3 10014.

It is still the same - VAT for calculation rule -% 'Price modifier before tax per bill' is not calculated and gives an incorrect VAT Amount ond a incorrect Total amount

Please see this topic https://forum.virtuemart.net/index.php?topic=141909.msg500418#msg500418
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on February 28, 2019, 16:01:39 PM
Made a test on the virtuemart official demo site 3.4.10014. Added a product to cart from a category that uses the calculation rule DBTaxBill - Price -% modification after Tax per bill.
Please see the screenshot re. the VAT amount and tell me if I'm wrong and if you are working on this. In Denmark we calculate outgoing and incoming VAT of total amount - maybe is it different in other countries..
Title: Re: VAT is calculated incorrectly after upgrade
Post by: jjk on February 28, 2019, 19:41:27 PM
What is the result if you use 'Price modifier before tax per bill'?
Title: Re: VAT is calculated incorrectly after upgrade
Post by: Milbo on February 28, 2019, 19:46:00 PM
I tested with the last one and it works for me (Result Total:    64,23 € -268,14 € 402,22 €), please try
http://dev.virtuemart.net/attachments/download/1154/com_virtuemart.3.4.3.10020_package_or_extract.zip
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on March 01, 2019, 12:55:53 PM
@jjk
the same -  gives VAT an incorrect total amount

@milbo
Have just tested with version 3.4.3.10020 - also tested with Protostar and vmbeez template - still get an incorrect Vat amount - please see screnshot.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on March 18, 2019, 13:35:33 PM
Just tested with 3.4.3.10031

My settings for
Calculation rule VAT : +% 25 TAX PER BILL
Calculation rule discount: -% 2 Price modifier before tax per bill

Still get an incorrect Vat amount - testet with Protostar template - please see screnshot.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on March 19, 2019, 14:35:19 PM
Test with 3.4.3.10031

Tried to change my VAT setting from Calculation rule VAT : +% 25 TAX PER BILL ( which is "the normal one" for B2B - price display without VAT) and worked
back in version 3.2.15.9866 together with the other calc rules - to

Calculation rule VAT : +% 25 VAT tax per product
Calculation rule discount: -% 2 Price modifier before tax per bill
Calculation rule discount: -% 2 Price modifier after tax per bill

Please see screenshot for result - VAT amount is incorrect - vat is not calculated for calculation rule discount: -% 2 Price modifier after tax per bill.
Is it planned to get the calc. rule TAX PER BILL to work again so it can be used for VAT per bill ?
Title: Re: VAT is calculated incorrectly after upgrade
Post by: jjk on March 19, 2019, 21:15:44 PM
I think your mistake is that you are mixing a VAT calculation rule (B2C) with a Tax per bill calculation rule (B2B).
If you want to use Tax per bill, your product prices and your discount should all be net (without tax). In your latest screenshot the 'Total' should be DKK 24.00 instead of DKK 30.00.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: Milbo on March 20, 2019, 00:13:49 AM
Notice: Undefined index: subTotal in /var/www/..../administrator/components/com_virtuemart/helpers/calculationh.php on line 834

Notice: Undefined index: percentage in /var/www/..../administrator/components/com_virtuemart/helpers/calculationh.php on line 917

There is the problem, I rewrote it using the old var names (subtotal instead of subTotal) was accidently renamed. Just use the new core on dev.virtuemart.net
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on March 20, 2019, 10:53:37 AM
@milbo

QuoteJust use the new core on dev.virtuemart.net

What do you mean - latest com_virtuemart.3.4.3.10031_package_or_extract.zip  ?  It is the version I'm testing and still get this notice

Notice: Undefined index: percentage in /var/www/danrider.dk/test/administrator/components/com_virtuemart/helpers/calculationh.php on line 917
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on March 20, 2019, 11:40:23 AM
@jjk

Thanks but i'm not mixing VAT rules.

We want to use TAX PER BILL (B2B) which we have used for many years together with some discount rules and vat/discount/total amounts
and pricedisplay (without vat) has been calculated and displayed correct .

After upgrade to 3.4.x, vat for discount rules (if you use TAX PER BILL as vat rule) is not deducted in vat total amount.

My post you are refer to was a test to see if vat was calculated and deducted vat amount for discount rules if you use VAT TAX PER PRODUCT (B2C) as a vat rule. And screenshot tells that it does not for all discount rules.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on March 20, 2019, 16:52:15 PM
Downloaded and installed a brand new VirtueMart3.4.2_Joomla_3.8.12-Stable-Full_Package.zip - updated them to Joomla 3.9.4/Virtuemart 3.4.3.10031.

Disabled existing Taxes & Calculation Rules and added 3 new ones - available for all

1 VAT Rule     : +25% TAX PER BILL
1 discount rule:  -10% price modifier before tax per bill
1 discount rule:  -10% price modifier after tax per bill

Please test http://joom.danrider.dk/index.php/wear/lady/skirt-knock-rock-detail and add 1 to cart - then you can see calulations...no need for check out:)
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 08, 2019, 13:41:17 PM
Just updated and tested with com_virtuemart.3.4.5.10054_package_or_extract.zip.

VAT amount is incorrect - vat is not calculated for discount calculation rules.

Please test http://joom.danrider.dk/index.php/wear/lady/skirt-knock-rock-detail and add 1 to cart - then you can see calculations....

Get this notice : Notice: Undefined index: percentage in /var/www/danrider.dk/joom/administrator/components/com_virtuemart/helpers/calculationh.php on line 917
Title: Re: VAT is calculated incorrectly after upgrade
Post by: jjk on May 09, 2019, 15:25:46 PM
Quote from: stensbo on March 20, 2019, 16:52:15 PM
1 discount rule:  -10% price modifier before tax per bill
1 discount rule:  -10% price modifier after tax per bill

I don't know what you are trying to achieve with adding two different discount rules.
Is the 'normal' calculation shown in the attached screenshot what you want? It uses a single 'Price modifier after tax' rule set to -10%.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 09, 2019, 16:10:31 PM
Thanks - jjk

Please try to change your discount rule to 'Price modifier before tax per bill' and set your VAT rule to 'Tax per bill' - this is "normal" for B2B customer... and then attach your screenshot -  to see if you get the correct VAT amount / total VAT amount

Title: Re: VAT is calculated incorrectly after upgrade
Post by: jjk on May 09, 2019, 16:42:51 PM
If you use 'Price modifier after tax' rule set to -10%, this happens:
The discount is based on net price with VAT, the tax amount is recalculated based on the new net price. And the result are correct numbers.  I think you should just use it and it solves your problem.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 09, 2019, 17:23:07 PM
... but that rule is not 'per bill'
Title: Re: VAT is calculated incorrectly after upgrade
Post by: StefanSTS on May 09, 2019, 20:06:39 PM
Quote from: stensbo on May 09, 2019, 16:10:31 PM
and set your VAT rule to 'Tax per bill' - this is "normal" for B2B customer...

Is it normal? I must have done something really wrong the last few years.

Maybe you could use VAT tax per product instead and prepare your invoice in a way that it shows what you want.

Regards
Stefan
Title: Re: VAT is calculated incorrectly after upgrade
Post by: jjk on May 09, 2019, 23:11:29 PM
Quote from: stensbo on May 09, 2019, 17:23:07 PM
... but that rule is not 'per bill'

The 25% tax rule is a tax per bill rule. See attached screenshot. A tax per product would show in the product row next to the Quantity column.

Quote from: StefanSTS on May 09, 2019, 20:06:39 PM
Is it normal? I must have done something really wrong the last few years.

B2B VAT tax per bill is common practice in EU countries, because both, the net amount and the tax amount have to be on the invoice to allow pre-tax deduction for a business customer. At least for invoices above 250 Euro (due to EU Regulations). However, if the invoice includes products with different VAT percentages, it becomes more complicated. (But VM can handle that, too)
Title: Re: VAT is calculated incorrectly after upgrade
Post by: StefanSTS on May 10, 2019, 00:54:02 AM
Quote from: jjk on May 09, 2019, 23:11:29 PM
B2B VAT tax per bill is common practice in EU countries, because both, the net amount and the tax amount have to be on the invoice to allow pre-tax deduction for a business customer. At least for invoices above 250 Euro (due to EU Regulations). However, if the invoice includes products with different VAT percentages, it becomes more complicated. (But VM can handle that, too)

You can achieve that with VAT tax per product too. No need to use a tax that is called different. Especially using VAT tax and deducting another tax, as I have seen in places, to show the net is not necessary. Especially if you sell B2B and B2C on the same site that is complicating things for no reason.

The attached invoice is all done with VAT tax per product and shows everything you need for invoices over 250 Euro.

Regards
Stefan
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 10, 2019, 11:31:02 AM
@jjk
QuoteThe 25% tax rule is a tax per bill rule. See attached screenshot

Yes but I meant that the discount rule  'Price modifier after tax' is not a PER BILL rule.

If I do as you suggested the discount is displayed as a strikethrough the price and the discounted price is displayed - you don't tell your costumer what discount they get - see screenshot of cart  'tax per bill- price modifier after tax' and order email confirmation screenshot 'order tax per bill- price modifier after tax'   

AND what if you have 2 discount rules this way  ??? then cart looks like this screeshot 'with 2 price modifire after tax' - this is not good..

I know that the discount rules that is NOT per bill is working and gives the correct VAT amount.

We need the discount calculations rules per bill like it worked back in version before upgrade to 3.4.x  please se screenshot 'Price modifier before tax per bill'  and you can see what I mean.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 10, 2019, 13:36:06 PM
@StefanSTS
QuoteMaybe you could use VAT tax per product instead and prepare your invoice in a way that it shows what you want.

Thanks but we do not do invoices in virtuemart - maybee same can be done with order email confirmation...
If discount rules per bill is used together with VAT TAX per product -  amounts is displayed incl. VAT  - that is why we have used tax per bill and discount rules per bill.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: Milbo on May 15, 2019, 16:43:30 PM
Stensbo, thank you for your good bug report.

Please test this version http://dev.virtuemart.net/attachments/1163/com_virtuemart.3.4.5.10057_package_or_extract.zip

I fixed some notices and so I know it could not work as expected. Please try the version above.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 16, 2019, 10:55:07 AM
Thanks Milbo,

Have tested with 3.4.5.10057 - :'( but I do not get correct VAT amount  - please try to add 1 to cart  joom.danrider.dk/index.php/wear/skirt-knock-rock-detail  and view cart then you can see calculation  - or see attached screenshot
Title: Re: VAT is calculated incorrectly after upgrade
Post by: jjk on May 16, 2019, 13:54:19 PM
Just curious - what are the settings for your shipment and payment fees? Both shown tax amounts for these don't look correct to me either.
For a total of 169,63 you would owe the Danish Skat kontor 33,93 €.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 16, 2019, 15:05:10 PM
I downloaded demo version and have not changed settings for these - did not think they where affecting calculation of vat/dis on product - of course total amounts they will affect Yes. I will just disable them so we don't get confused.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: Milbo on May 21, 2019, 14:27:01 PM
Please test the next version http://dev.virtuemart.net/attachments/1164/com_virtuemart.3.4.5.10059_package_or_extract.zip
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 22, 2019, 10:01:36 AM
Thanks Milbo - I have tested with 3.4.5.10059 -  8)
I can now confirm that if you use

Calculations rule for VAT: 'Tax per bill'
Calculations rule for discount: -% 'Price modifier before tax'
Calculations rule for discount: -% 'Price modifier before tax per bill'

..you get correct amounts for product/VAT/discount and correct Total amounts for product/VAT

..but Total discount amount is incorrect when you use both discount rules at the same time, we often do that - please see screenshot -
checked in old orderconfirmations and this have been present a long time back, but I haven't noticed it before now.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: Milbo on May 22, 2019, 17:21:15 PM
omg.

I just thought about to write "But it may not correctly work for both kind of discount rules applied in one bill."

Okey, you have it extra complex. Lets see what I can do. Anyway time for a rewrite of the calculator, next time.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: Milbo on May 22, 2019, 20:21:48 PM
I just tested the case and "Price modifier after tax per product" + "Price modifier before tax per bill" and it works correctly.

(I thought at begin you use "Price modifier before tax per bill" and "Price modifier after tax per bill".

But I see now, for the case "Price modifier BEFORE tax per product" it works wrong. Crazy. Thanks for the report.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 23, 2019, 14:50:28 PM
QuoteI just tested the case and "Price modifier after tax per product" + "Price modifier before tax per bill" and it works correctly.
Agrees

Quote(I thought at begin you use "Price modifier before tax per bill" and "Price modifier after tax per bill".
Sorry if I have made confusion - we use

Calculations rule for VAT: 'Tax per bill'
Calculations rule for discount: -% 'Price modifier before tax' (is per product)
Calculations rule for discount: -% 'Price modifier before tax per bill'

QuoteBut I see now, for the case "Price modifier BEFORE tax per product" it works wrong.
Agrees - you get incorrect Total amount for discount - discount amount is considered as positiv (I think :-\) for this rule - and only in calculation of Total discount amount - all other amounts/total amounts is correct
Title: Re: VAT is calculated incorrectly after upgrade
Post by: Milbo on May 23, 2019, 21:50:27 PM
In your setting, it would make no difference to use the other rule, because you add the VAT at the end. Just so, but it should be fixed, please test.

http://dev.virtuemart.net/attachments/1165/com_virtuemart.3.4.5.10063_package_or_extract.zip

I dont know how it behaves in order edit and the shipment radical vat setting. Maybe it works only correct with the radical tax. Did not test it yet. Please do that, it was hard enough to get it working.

Time to rewrite the calculator. The new calculator will gather first all rules per product, even when they are per bill, because our rules per bill work also per category and so on (which makes it so hard to write). Finally we collect the result and display it. It is almost that way already.
Title: Re: VAT is calculated incorrectly after upgrade
Post by: stensbo on May 24, 2019, 17:52:39 PM
YES :) Thanks Milbo - I appreciate your help a lot.

I have tested 3.4.5.10063 on our test site (also with a mix of categories and shoppergroups) and I can confirm that all amounts/total amounts are now
correct calculated if you use

Calculations rule for VAT: 'Tax per bill'
Calculations rule for discount: -% 'Price modifier before tax' (is per product)
Calculations rule for discount: -% 'Price modifier before tax per bill'.

But you are right you can't edit an order without screw it up - in our case it is not a problem  - we don't edit orders in Virtuemart.
If you wants some screenshot and explanations how it act - please let me know.

...the shipment radical vat setting - I managed to make a test in demo shop with differentiated VAT rules and the 'Simplified VAT for shipping' enabled,
I can tell that if you use

Calculations rule for VAT: +7% 'Tax per bill'
Calculations rule for VAT: +10% 'Tax per bill'
Calculations rule for discount: -% 'Price modifier before tax' (is per product)
Calculations rule for discount: -% 'Price modifier before tax per bill'

it does not work properly. In Denmark we do not have differentiated VAT - we only have the 25% rate so in our case it is not a problem,
we do not use the radical vat setting. I know that "it does not work properly" is a very short comment for a test. If you wants some screenshot and explanations how it act - please let me know.

QuoteTime to rewrite the calculator
I can imagine that it is hard to write with all these opportunities available. Please have in mind that it is important, in cart and order confirmation, to tell/display for
customer/shopper what discount they get - especially the per bill rules.