Faulty invoice and tax calculation! - Solved

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #5847

Hello,

now, near the lunch of my shop and some ordering testing, I ran into a big problem. The tax calculation and shipping-tax calculation makes some mistakes.

I did a testorder and took some screenshots (all from the same order) to explain it. and the tax for germany is 19%.



Here you see a screenshot of the cart in the frontend. Here is the first mistake:
- the "Zwischensumme" (sum) incl. the tax is 44,-€ -> thats ok.
- the "Versand" (shipping) incl. the tax is 5,95 -> thats ok.
- the "Steuern" (tax) is wrong. If 49,95€ is the endprice with tax, than 41,97€ is the endprice without tax and the tax is 7,98€ (not 7,95€).

Next screenshot. This time from the email the user will get:



Here the user gets an email with the price without tax. Ok, I think this could be changed in the emailsettings, but also here the price calculation is wrong. Because the price without tax from 44,-€ is not 37,-€, it should be 36,974789915966386554621848739496€ or better 36,97€.

Next screenshot from the invoice in the backend:



Here are some more mistakes:
- the 37,-€ without tax is wrong, as I allready said in the second picture.
- The MwSt. is wrong. Why only 7,-€? In the cart is was 7,95€ (that was allready wrong) and now its only 7,-€ (more wrong) but we allready told the user in the mail that it was 7,95€? I am confused about this.
- the rest is ok.

Ok, last screenshot. Now from my own invoice-program I use for a long time and do the calculation right:



Here you see the price per pcs. of 0,44€ with tax. So for 100 pcs. 44,-€. Then the shipping with 5,95€ incl. tax and the endprice incl. tax is 49,95. And now the big difference at the tax, with 7,98€ its right in this calculation.

So what do do? I think I know where is the big problem. At the product page I type in the price incl. tax. and I type there the price of 0,44€ incl. tax at min. 100pcs. When I leave the "price incl. tax" field it automatic write at the field "without tax" the value 0.37000€. And thats the mistake I think.

Regards, Benny.

Attachments:
Last edit: 13 years 9 months ago by benkly.

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #5864

@ nicolas

If it would be usefull to chat with me for this issue, here is my chat:

www.eiwomisa.de/website/chat.html

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #5872

Hi,

In HikaShop the price stored in the database is the price without taxes. The taxed price is always calculated dynamically from the untaxed price.
So, if you set an untaxed price of 0.37 it's normal that you get 37€ when buying 100 pieces.

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #5877

Hmmmm, thats bad and makes the shop less usefull for me as my clients are most endusers and they don't want to know the untaxed price.
And where does hikashop get his price from for the database? I told them the taxed price. If hikashop would write the right price in the database, we all would be happy. As example:

I set a taxed price of 0,44€ with 19% tax in a product. Then hikashop should write in the database a untaxed price of 0,36974789915966386554621848739496€ in the database. This way my client would have to order a very lot from this product to get any rounding errors.

I don't know if this all is a big problem to solve, but virtuemart does this the right way.

And the other thing is, this all does not explain the mistake that is in pic number 3. Why only 7,-€ MwSt.? It should be 7,95€.

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #5884

I understand what you're saying but it doesn't work like this actually and changing the system to work like you want means that we need to change the whole price/tax calculation system... That's not something we can do in a few hours and will require a lot of work.

Concerning the pic3, this a bug whch will be fixed in next release :
www.hikashop.com/en/support/forum/3-bug-...ount-error.html#5302

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #5885

Hmmm, I understand. But I think this is a problem you should solve when you got time for that.

But I think I have another bug. Like you said, I now did not set the taxed price of 0,44€ for the product, I set the untaxed price of 0,36975€ and saved. Now in the backend it display the right value in the pricelist in the product view of 0,36975€ untaxed and 0,44€ taxed. But still if I would order 100pcs. it says still 37,-€ untaxed and 44,-€ taxed. And now?

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #5909

Yes, the prices are rounded directly before the calculation. So even if you enter 0.369 in the untaxed price, it will still use 0.37.

If you want, you could try to increase the number of decimals of your currency to 3 decimals. That will not round the prices.
Then, you can always round them when displaying them in the views checkout and product that you can edit via the menu Display->Views.

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #5948

Hi,

ok, I set the decimals to 5 in the currency. To set it to 3 is not enough.
I think this shop is very good the its very easy to manage all the normal work you have with a online shop. But to round a value before its calculation is not very smart. It was the first thing I learned in math to, if possible, only round the sum.

Ok, set the decimals to 5. Now my views are a little strange with 5 decimals. How could I set this to 2 rounded decimals in the views? What code do I need and where?

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #5949

You could edit the file adminsitrator/components/com_hikashop/classes/currency.php and add just after the line:
function format($number,$currency_id=0,$format_override='') {

the code:
$number = round($number,2);

That will round all the prices display to 2 decimals everywhere. That is way easier than rounding the prices everywhere where that function is called.

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #5952

Hi,

thanks, 50% solved. Now it does the rounding, but still shows all 5 decimals. Now its not 0,36975€, now its 0,37000€.

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #5953

Ah yes, you also need to add:
$locale=2;
$locale=2;
right after:
$locale = $data->currency_locale;

a few lines below.

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #6032

Hi again,

ok, now its all fine, not all but most. In the backend in the product view I can only set an untaxed price with 5 decimals. How could I set this to 6 or 7 decimals?
And if I set there a taxed price, it automatical sets the untaxed price for this. But this way it only sets it automatical with 2 decimals, how could I make it that it automatical set the untaxed price with the max possible decimals available?

The problem is, if I have a taxed price of 0,38€ and a client wants 5000pcs, then it should be 1900,-€. But with the 5 decimals untaxed price (0,31933€) this would be 1900,01€ :(

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #6043

Hi,

HikaShop doesn't handle more than 5 decimals in the prices in the database.
You would have to increase the number of decimals in the table hikashop_price directly.

For the untaxed conversion on the product page, you can change the line:
$newprice = $currencyClass->$function($price,array_shift($main_tax_zone),$tax_id);
to:
$newprice = $currencyClass->$function($price,array_shift($main_tax_zone),$tax_id,hikashop::getCurrency());
in the file administrator/components/com_hikashop/controllers/product.php
That's something which we'll do right now in HikaShop because that's the way it should be anyway, regardless of the tax calculation issues you raised earlier.

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #6102

Hi,

the first thing worked fine. Now I have 7 decimals in the table. But the second thing with the code didn't work. After I change that line and set a taxed price then it rounds only to 1 decimal in the untaxed price :dry:

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #6103

Ah, you're right.

It should have been:

$newprice = $currencyClass->$function($price,array_shift($main_tax_zone),$tax_id,$currencyClass->getRounding(hikashop::getCurrency()));

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #6159

Thanks! That works right!

How do you mean that? Would this function, of the automatic untaxed calculation from the taxed price, be included in the next release? And do I have to change all my changes ones more after an update?

Regards, Benny.

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #6160

Not all these changes will be implemented. So you will have to reapply them if you update, at least until we change the way we calculate taxes.

We will try to do it next month... But I can't guarantee it as we have a lot of things going on and that there is a work around which is not too difficult since there is 4 lines of code to change and one column in the database.

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

  • Posts: 73
  • Thank you received: 0
  • Hikashop Essential
13 years 9 months ago #6162

Ahhh, ok. No problem and don't hurry! This workaround is ok and I think I could exchange virtuemart with hikashop in the next days.
I do electronic engineering and need the shop only to sell some of my projects, because of this I know this -> "Its done when its done" ;-)

Regards, Benny.

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

  • Posts: 16
  • Thank you received: 0
13 years 9 months ago #7108

Hi,

I had the same problem and fixed it with the mentioned solution, but now I have a problem with the paypal plugin. When a customer is redirected to paypal, he gets the following message at PayPal: The link you have used to enter the PayPal system contains an incorrectly formatted item amount.

Used price with taxes: € 19,95, without tax: 16,76470 (19% tax).
International fractional digits: 5
Local fractional digits: 5

When I create a testproduct of € 1,00 without tax (€ 1,19 with tax), I don't get the paypal error.

Thanks for your help.

Regards,

Eppo

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

  • Posts: 82795
  • Thank you received: 13356
  • MODERATOR
13 years 9 months ago #7109

If you use a paypal with this fix, you also need to edit the file plugins/hikashoppayment/paypal.php and add the line:
$currency->currency_locale = 2;
after the line:
$currency=$currencies[$order->order_currency_id];
and after the line:
$currency=$currencies[$dbOrder->order_currency_id];

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

Time to create page: 0.108 seconds
Powered by Kunena Forum