Post by joegolike » Fri Aug 29, 2008 6:34 pm

Following Bruce's tax setup doc I was able to solve the problem of taxes being automatically added to products' display prices. But then I saw that after an order was completed, viewing an invoice under the customer's My Account page or as Admin on the Order page, it was still rolling tax into the product price. This resulted in a strange situation where the product subtotal math looked wrong, even though the final order total was correct. Tax is being displayed twice: once as part of the product price, and also separately in the subtotal column.

I made a couple of mods in two controller files that seems to have resolved this issue.

catalog/controller/account_invoice.php
lines 121-126:

Code: Select all

//	'price'    => $currency->format(($product['price'] + ($product['price'] * $product['tax'] / 100)), $order_info['currency'], $order_info['value']),
	'price'    => $currency->format($product['price'], $order_info['currency'], $order_info['value']),
//	'discount' => (ceil($product['discount']) ? $currency->format(($product['price'] - $product['discount']) + (($product['price'] - $product['discount']) * $product['tax'] / 100), $order_info['currency'], $order_info['value']) : NULL),
	'discount' => (ceil($product['discount']) ? $currency->format($product['price'] - $product['discount'], $order_info['currency'], $order_info['value']) : NULL),
//	'total'    => $currency->format($product['total'] + ($product['total'] * $product['tax'] / 100), $order_info['currency'], $order_info['value'])
	'total'    => $currency->format($product['total'], $order_info['currency'], $order_info['value'])
Also admin/controller/order.php
lines 412-417:

Code: Select all

//	'price'    => $currency->format(($product['price'] + ($product['price'] * $product['tax'] / 100)), $order_info['currency'], $order_info['value']),
	'price'    => $currency->format($product['price'], $order_info['currency'], $order_info['value']),
//	'discount' => (ceil($product['discount']) ? $currency->format(($product['price'] - $product['discount']) + (($product['price'] - $product['discount']) * $product['tax'] / 100), $order_info['currency'], $order_info['value']) : NULL),
	'discount' => (ceil($product['discount']) ? $currency->format(($product['price'] - $product['discount']), $order_info['currency'], $order_info['value']) : NULL),
//	'total'    => $currency->format($product['total'] + ($product['total'] * $product['tax'] / 100), $order_info['currency'], $order_info['value'])
	'total'    => $currency->format($product['total'], $order_info['currency'], $order_info['value'])
Basically I identified the parts where tax was being added to the "price", "discount", and "total" values in the $product_data array, and cut it out so only price was left. This fixed the Order page in the Admin control panel, and the Order Invoice page under the customer's My Account page.

Is anyone aware of any other pages that might have this problem?

New member

Posts

Joined
Fri May 23, 2008 3:42 pm

Post by bruce » Fri Aug 29, 2008 6:51 pm

Sorry, $tax->getRate() is innocuous enough and I did not mean to point out that function as the problem. It is how it is used further on without taking into account whether the tax rate should be applied that causes the problem.

In Canada there are multiple tax rates. In Quebec for example there is a state tax and a city tax. Both of which should show on an invoice  and opencart cannot do that.

My comment on confused concepts is about exactly what you have described. There is support in the database etc for multiple rates and their names but they are then combined into a single rate that has the name of the tax class instead.

In addition, there is no support for the notion that a price entered for a product could actually include the tax. In Australia for example, the advertised price must include the GST tax and is a whole number of dollars and cents. Opencart forward calculates the display price from the tax exclusive price and this forces store owners to back calculate the tax exclusive price to enter into opencart and also can introduce rounding errors. There are forum posts on rounding and calculation errors in some of the reports too.

enough from me  ;)

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by JNeuhoff » Fri Aug 29, 2008 8:35 pm

I made a couple of mods in two controller files that seems to have resolved this issue.
Your proposed fixes in the /catalog/controller/account_invoice.php and in the /admin/controller/order.php don't take into account the $config->get('config_tax') boolean flag which is set in

  Admin > Configuration > Setting > Local > Tax: Yes or No

Hence, this is how my proposed fix for e.g. the /admin/controller/order.php in method getForm looks like:

Code: Select all

			if ($config->get('config_tax')) {
				$product_data[] = array(
					'name'     => $product['name'],
					'model'    => $product['model'],
					'option'   => $option_data,
					'quantity' => $product['quantity'],
					'price'    => $currency->format(($product['price'] + ($product['price'] * $product['tax'] / 100)), $order_info['currency'], $order_info['value']),
					'discount' => (ceil($product['discount']) ? $currency->format(($product['price'] - $product['discount']) + (($product['price'] - $product['discount']) * $product['tax'] / 100), $order_info['currency'], $order_info['value']) : NULL),
					'total'    => $currency->format($product['total'] + ($product['total'] * $product['tax'] / 100), $order_info['currency'], $order_info['value'])
				);
			}
			else {
				$product_data[] = array(
					'name'     => $product['name'],
					'model'    => $product['model'],
					'option'   => $option_data,
					'quantity' => $product['quantity'],
					'price'    => $currency->format($product['price'], $order_info['currency'], $order_info['value']),
					'discount' => (ceil($product['discount']) ? $currency->format(($product['price'] - $product['discount']) , $order_info['currency'], $order_info['value']) : NULL),
					'total'    => $currency->format($product['total'], $order_info['currency'], $order_info['value'])
				);
			}
And the other file at /catalog/controller/account_invoice.php should have this fix:

Code: Select all

.....
			$config  =& $this->locator->get('config');
			foreach ($products as $product) {
.....
				if ($config->get('config_tax')) {
					$product_data[] = array(
						'name'     => $product['name'],
						'model'    => $product['model'],
						'option'   => $option_data,
						'quantity' => $product['quantity'],
						'price'    => $currency->format(($product['price'] + ($product['price'] * $product['tax'] / 100)), $order_info['currency'], $order_info['value']),
						'discount' => (ceil($product['discount']) ? $currency->format(($product['price'] - $product['discount']) + (($product['price'] - $product['discount']) * $product['tax'] / 100), $order_info['currency'], $order_info['value']) : NULL),
						'total'    => $currency->format($product['total'] + ($product['total'] * $product['tax'] / 100), $order_info['currency'], $order_info['value'])
					);
				}
				else {
					$product_data[] = array(
						'name'     => $product['name'],
						'model'    => $product['model'],
						'option'   => $option_data,
						'quantity' => $product['quantity'],
						'price'    => $currency->format($product['price'], $order_info['currency'], $order_info['value']),
						'discount' => (ceil($product['discount']) ? $currency->format(($product['price'] - $product['discount']), $order_info['currency'], $order_info['value']) : NULL),
						'total'    => $currency->format($product['total'], $order_info['currency'], $order_info['value'])
					);
				}
			}
.......

Once we have these fixes, the taxes should be sorted out I think, except for the multiple taxes scenario for Canada users. Of course, all product prices are to be entered by the admin store owner without the taxes. OpenCart just does a forward calculate with taxes included when they are being displayed to the user, and only if the store has been configured to do so (Admin > Configuration > Setting > Local > Tax:Yes).
Last edited by JNeuhoff on Fri Aug 29, 2008 8:41 pm, edited 1 time in total.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by bruce » Sun Aug 31, 2008 7:45 pm

Sorry guys,

Both of these solutions are mostly ok but flawed in that they use the present time value of the product tax rate and the $config->get('config_tax') boolean flag, which can change over time, to recalculate historical tax values. They also make the incorrect assumption that if the flag is not set then no tax applies.

An example is the usual US scenario where the 'config_tax' flag is always "off" and whether to apply tax or not is based on the shipping address geo zone.

The path to a rigorous solution lies in the contents of the order_product table. It should contain a complete snapshot of the calculated data at the time of order processing in the same way as the totals are held in the totals table.

Finally, the concept of a product price that does or does not already include the tax is important. If a store owner must calculate a tax exclusive price from the "display price" so that opencart can forward calculate it to produce the "display price" then rounding errors can creep into the values or totals displayed unless a large number of decimal places are entered for the price.

I believe that the data in the order_product table should also handle the price includes tax concept as well.

More than 2 cents, I know but these are my thoughts  ;)

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by JNeuhoff » Sun Aug 31, 2008 8:37 pm

They also make the incorrect assumption that if the flag is not set then no tax applies.
How so? If I set the Admin > Configuration > Setting > Local > Tax to 'No', it still applies the taxes and they show up in the final invoice as a separate item, and is included in the total. The only difference is that the product prices are displayed without the tax as it should be with this flag 'Tax:No' setting (that is, $config->get('config_tax')==FALSE)
The path to a rigorous solution lies in the contents of the order_product table. It should contain a complete snapshot of the calculated data at the time of order processing in the same way as the totals are held in the totals table.
Agreed. At the moment it always stores the product price without the tax and the tax rate, hence it is always possible to re-produce the final total. It should also store the boolean flag from the $config->get('config_tax') at the time the order was originally submitted, and this saved flag should then be used to display the product prices correctly on the invoice with or without taxes as needed, and do the same for the subtotal.

At the moment, the only solution for an OpenCart store owner is to not change the Admin > Configuration > Setting > Local > Tax while there are orders stored in the database.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by fido-x » Mon Sep 01, 2008 9:35 am

By default OpenCart displays the prices that are applicable in the region/country the store is located in, inclusive of all charges/taxes applicable in that region/country. With regard to "window shoppers" (still an appropriate term), they see the price that is applicable in your country.

I would think the easiest way to display product prices to "window shoppers" without any local charges/taxes being added, would be to add extra entries to the "country" and "zone" tables in your database (eg. "Earth" and "Somewhere"). Configure these to have no taxes or charges, then move your store to this location through Admin->Configure->Settings->Local.

Although the methods suggested by Bruce and JNeuhoff are probably better, the method suggested here is a lot easier. ;)

Regards, Fido-X.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by hm2k » Fri Sep 05, 2008 12:20 am

Based on this thread, I fixed the bug on the homepage, as mentioned in this bug report http://code.google.com/p/open-cart/issues/detail?id=42

For any other issues, please raise a bug report, and we'll address each issue on an individual basis, otherwise it's going to get complicated.

Based on bruce's comments, it doesn't seem like a simple issue to overcome.

It's also worth noting that in the UK under the Distance Selling Act, prices must be displayed inclusive of taxes, including VAT.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by JNeuhoff » Fri Sep 05, 2008 7:56 pm

I added another bug report (http://code.google.com/p/open-cart/issu ... &thanks=46) which describes the same bug for 2 other pages, and which refers to a proposed bugfix from this thread.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by hm2k » Wed Sep 10, 2008 8:07 am

bruce wrote: Sorry guys,

Both of these solutions are mostly ok but flawed in that they use the present time value of the product tax rate and the $config->get('config_tax') boolean flag, which can change over time, to recalculate historical tax values. They also make the incorrect assumption that if the flag is not set then no tax applies.

An example is the usual US scenario where the 'config_tax' flag is always "off" and whether to apply tax or not is based on the shipping address geo zone.

The path to a rigorous solution lies in the contents of the order_product table. It should contain a complete snapshot of the calculated data at the time of order processing in the same way as the totals are held in the totals table.

Finally, the concept of a product price that does or does not already include the tax is important. If a store owner must calculate a tax exclusive price from the "display price" so that opencart can forward calculate it to produce the "display price" then rounding errors can creep into the values or totals displayed unless a large number of decimal places are entered for the price.

I believe that the data in the order_product table should also handle the price includes tax concept as well.

More than 2 cents, I know but these are my thoughts  ;)
I've added 2 of the bug fixes into the core script now...
http://code.google.com/p/open-cart/issues/detail?id=46
http://code.google.com/p/open-cart/issues/detail?id=47

However, I share bruce's concerns, and a better solution does need to be proposed.

What I will say is if someone has a problem with the new fixes, they can raise a bug report and then I can investigate it better from both perspectives.

Unless people are willing to voice their opinions and provide feedback now...

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by JNeuhoff » Wed Sep 10, 2008 4:54 pm

However, I share bruce's concerns, and a better solution does need to be proposed.
At least we have now achieved a consistent behavior for the way product prices are being displayed in OpenCart (e.g. Home Page, Search Results, Cart, Product page, etc.). At the moment, all products are being maintained with a tax-exclusive price in the database, and taxes are dynamically calculated as per the config_tax flag.

The next step might indeed be along the lines of Bruce's suggestion:

- Change the order_product table in a way that it keeps a snapshot of the ordered product as is done
  in the order_total table.
- Make some of the extensions (e.g. Calculate Tax, Calculate Total) more configurable
  so as to support stores were product prices are always being maintained including sales taxes
- Figure out a way to support multiple sales taxes

Perhaps it is now a good idea to study the solutions implemented in some other shopping carts (ZenCart, OSCommerce, etc.) to see how they solved this problem and then come up without something similar for OpenCart.
Last edited by JNeuhoff on Wed Sep 10, 2008 4:59 pm, edited 1 time in total.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by hm2k » Wed Sep 10, 2008 6:55 pm

If any further work is required, I'd suggest people open a tracker so I am able to follow up the issue.

Thanks.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK
Who is online

Users browsing this forum: No registered users and 3 guests