Re: Discount coupon value
I updated ot_coupon.php file. Calculations for both 'Discount coupon' and 'Credit note' are supported for different type of coupons.
'Discount coupon' are discounts applied on customer order, which mean they are calculated on net prices.
'Credit note' are generally used for refunds and are calculated on products or order gross price.
'Penny loss' problem appeared but was solved by applying a rounding on coupon value just before it is included in order total.
There are still lots of testing/fixing with discount per item option, multiple tax class items in cart, coupon validation in general...
Re: Discount coupon value
Quote:
Originally Posted by
pilou2
I updated ot_coupon.php file. Calculations for both 'Discount coupon' and 'Credit note' are supported for different type of coupons.
'Discount coupon' are discounts applied on customer order, which mean they are calculated on net prices.
'Credit note' are generally used for refunds and are calculated on products or order gross price.
'Penny loss' problem appeared but was solved by applying a rounding on coupon value just before it is included in order total.
There are still lots of testing/fixing with discount per item option, multiple tax class items in cart, coupon validation in general...
Thanks, @pilou2. I'll check it out early next week.
Re: Discount coupon value
Quote:
Originally Posted by
lat9
Thanks, @pilou2. I'll check it out early next week.
Wait until next update, I realized there were some mistakes. I did not upload the right version and anyway, now that I am testing with multiple tax rates, I need to rewrite part of the code.
Re: Discount coupon value
Last update uploaded to GitHub.
Results look very good. ;)
Discount coupons should be ok with all coupons options.
Credit notes (refund) too with all usable options. When using credit notes, setting in admin for ot_coupon are important. Some settings should not be used, like setting tax class to 'none'. Always choose a tax class, or total tax won't be right.
I did some testing with products in cart using two different tax classes and all numbers added well, although calculation to check numbers can get pretty complicated.
Re: Discount coupon value
Well... I did all my testing, modifications using a shipping module with tax class set and when I removed this tax class, problems appeared.
I have to rethink everything as I made two assumptions that were wrong:
I thought option 'include shipping' and 'include tax' were here just to choose the limit for discount, which was true for fixed discount, but I realized that it modified how percentage discount are calculated.
And most important, I thought the actual calculation for tax was good... It is if you use free shipping or shipping has a tax class defined, but when tax class is not defined (default in all shipping modules), shipping tax is missing from final tax. Whatever you display prices with or without tax, shipping has always the same value.
I checked and as far as I know, shipping is always taxable. Basic rule for sale tax calculation is:
Taxable amount = Sales - discount + charges
Sales include goods and service provided.
Discount includes sale discount, refunds, non-taxable items...
Charges are shipping fees, handling fees and any other indirect cost incurred to provide goods or services.
Before going further with discount module, this needs to be fixed.
In 'ot_coupon.php', the variable
PHP Code:
$order->info['shipping_tax']
is 0 when no tax class has been defined. In this case, it should be populated by calculating tax (using shop's tax class) from shipping cost considered as a tax included value.
I don't know how to do that...
Re: Discount coupon value
After more research on the topic, it seems that shipping with no tax is necessary in some situations, especially in the United States.
Now that I understand more about taxes and ZC, I was able to write some new code that provides correct calculations. I did a lot of testing, considering all the possibilities with different options in coupon and ot_coupon settings...
There is still one option that has some mystery left, 'Per Qualifying Items'. I did not find where/what are criteria for qualifying or not a product.
New file is available on GitHub.
https://github.com/piloujp/zencart/tree/Coupons
Re: Discount coupon value
This week I did more testing than writing code, and discount coupons should now be usable with most of the options available in Zen Cart.
By the way, I did same kind of work on GV module as it is related.
Here is a quick summary of how discount coupon module work.
In Admin->Modules->Order Total->Discount Coupon, there are few options:
'Include Shipping' will include shipping cost when tax is recalculated and in maximum possible discount amount calculation.
'Include Tax' will include tax amount when tax is recalculated and in maximum possible discount amount calculation. This option should not be used when tax is recalculated, as it does not make sense to do that. A message will pop up if you try anyway.
'Re-calculate Tax' is probably the most important one. It has 3 options:
'None' as it says, no re-calculation is done.
'Standard' does calculate new tax after discount has been made on net total amount. It is for standard discount given to customers on their order total.
'Credit note' will calculate new tax for refund type discounts that are made on gross price. It is useful to correct some mistake in precedent order, like item missing or defective.
'Tax Class' will assign a tax class to discount. It is important to set this when doing tax recalculation. Not setting it will give wrong tax if recalculation is done.
Then, in Discounts->Coupons Admin page, you can set coupons' value, date limit, number of use, if it applies by item or on order total, to all items or only those with no restrictions...
By the way, the button to set restrictions is on the bottom right of the screen and can be easily missed on small screens where it is not visible...
Gift Certificate module has similar options, but it is a discount manageable by customers. Considering tax recalculation, it is exactly the same as discount coupons.
Re: Discount coupon value
Thanks for your hard work on this, @pilou2! It'll take me a couple of weeks, but I will review and provide the testing feedback for these corrections.
Re: Discount coupon value
+1. Thank you @pilou2 for your contributions.
Re: Discount coupon value
Thanks are always welcome. ;)
I really need someone else looking at it. The file was definitely a work in progress with lots of debug comments, and it is complicated. Although most of the calculations were right, I think their base was wrong. For example, when shipping has no taxes but cart has, then depending on displaying option of tax, you get two different results.
I think an invoice whether using numbers including tax or without tax should always have the same final total and tax. This is the first important difference with actual ZC calculations, and because of this my code won't pass ZC validation tests.
Another difference is, as I already wrote, the definition of standard discount and credit note discount.
Standard customer level discount is done on total price (tax incl.) and credit note is product level refund and should be done on gross prices.
My results are (or should be) consistent with these principles.
There should not be important updates from now, but it is always better to download last GitHub file before testing.
I have some nice fix for the lost penny problem, but I will explain in another thread.