X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Discount Coupons and Tax Calculation (https://forum.x-cart.com/showthread.php?t=7655)

mixman 05-19-2004 10:43 AM

Discount Coupons and Tax Calculation
 
Can anyone help me modify my discount coupon and tax calculation for xcart ver. 3.4.8

Xcart seems to still base sales tax on the price before the coupon.

For example, a customer makes a $100 purchase and applies a 10% discount coupon. Currently Xcart calculates sales tax based on $100 instead of $90. I would like it calculate the tax on the total after the discount is applied. I have had a few customers notice this and complain that I'm overcharging. They are right! I use Canadian Tax system GST & PST . If anyone knows how to correct this that would be great.

Thanks
Mike

Mod King 05-19-2004 12:16 PM

You're best bet is to look at the 2 functions func_calculate_single and func_calculate and see if its doing the tax calculation before the discount

In the version i have it does the discount before the taxes (or atleast the comments say so)


I don't have access to the version of cart that you are using, but if you have trouble, you can e-mail me your func.php and i can take a look.

adpboss 05-19-2004 04:56 PM

Let's keep this forum for finished mods only please. This is a better post for Order Management or Storefront Management.

That said, I would love to know the answer as well, but hopefully a moderator will move it back once we have modified code to share.

Mod King 05-19-2004 05:21 PM

I made an attempt to fix it, and sent it to him for testing.

If it works i'll post the fix.

adpboss 05-19-2004 05:29 PM

That would be great.

The idea is try to keep this forum clean and free of requests that should be posted in the other areas dedicated to Q & A. Tested and complete solutions are always welcome.

Mod King 05-19-2004 05:37 PM

that is totally understandable, i'll watch before I post next time.


But from what i looked at. It appears that they calculate a taxable total for all 3 types tax, gst, pst then they only subtract the discount from the shipping_total and total instead of those 3 values.

So I added some code to subtract discount and coupon discount from all three of those.

Hopefully it works properly.

adpboss 05-19-2004 05:40 PM

Should really be an option in the admin. Check boxes to enable various taxes on discounts.

I've suggested it to X-cart before, I hope it makes it into future builds.

Mod King 05-19-2004 05:50 PM

I'm really surprised it isn't. It seems logical to not tax the discounted amount.

Mod King 05-19-2004 06:07 PM

Here's the fix i did that seemed to work.

I didn't post the whole function, but here is part of it. I am not sure what versions everyone is using, but this is the fix to mixmans

its in ./funch.php
around line 731 for his, in the function func_calculate_single

I put comments in where i added some lines so everyone can see the change.


Code:

#
# Deduct discount
#
                $discount_info = func_query_first("select * from $sql_tbl[discounts] where minprice<='$avail_discount_total' $provider_condition and membership='$customer_info[membership]' order by minprice desc");
                $discountall_info = func_query_first("select * from $sql_tbl[discounts] where minprice<='$avail_discount_total' $provider_condition and membership='' order by minprice desc");
                if ($discount_info["discount_type"]=="absolute" && $avail_discount_total>0)
                                $discount += $discount_info["discount"];
                elseif ($discount_info["discount_type"]=="percent")
                                $discount += $avail_discount_total*$discount_info["discount"]/100;
              elseif ($discountall_info["discount_type"]=="absolute" && $avail_discount_total>0)
                $discount += $discountall_info["discount"];
                elseif ($discountall_info["discount_type"]=="percent")
                                $discount += $avail_discount_total*$discountall_info["discount"]/100;

                $total = $total-$discount;
        //mod king change here
        $total_shipping -= $discount;
        $total_taxable_gst-=$discount;
        $total_taxable_pst-=$discount;
                //end of lines added
        $total_taxable-=$discount;
                if ($total_shipping < 0)
                        $total_shipping = 0;
#
# Deduct discount by discount coupon
#
        $coupon_discount=0;
        $coupon_total = 0;
        $coupon_amount = 0;

        $discount_coupon_data = func_query_first("select * from $sql_tbl[discount_coupons] where coupon='$discount_coupon' $provider_condition");

        if (($discount_coupon_data["productid"]>0) and (($discount_coupon_data["coupon_type"]=="absolute") or ($discount_coupon_data["coupon_type"]=="percent"))) {
                foreach($products as $product) {
                        if ($product["productid"] == $discount_coupon_data["productid"]) {
                                $coupon_total += $product["price"]*$product["amount"];
                                $coupon_amount += $product["amount"];
                        }
                }
                if ($discount_coupon_data["coupon_type"]=="absolute") {
                        $coupon_discount = $coupon_amount*$discount_coupon_data["discount"];
                } else {
                        $coupon_discount = $coupon_total*$discount_coupon_data["discount"]/100;
                }
        } elseif (($discount_coupon_data["categoryid"]>0) and (($discount_coupon_data["coupon_type"]=="absolute") or ($discount_coupon_data["coupon_type"]=="percent"))) {
                foreach ($products as $product) {
                        if ($product["categoryid"] == $discount_coupon_data["categoryid"]) {
                                $coupon_total += $product["price"]*$product["amount"];
                                $coupon_amount += $product["amount"];
                        }
                }
                if ($discount_coupon_data["coupon_type"]=="absolute") {
                        $coupon_discount = $coupon_amount*$discount_coupon_data["discount"];
                } else {
                        $coupon_discount = $coupon_total*$discount_coupon_data["discount"]/100;
                }
        } else {
                if ($discount_coupon_data["coupon_type"]=="absolute")
                $coupon_discount = $discount_coupon_data["discount"];
        elseif ($discount_coupon_data["coupon_type"]=="percent")
                $coupon_discount = $total*$discount_coupon_data["discount"]/100;
        }

        if ((!$single_mode) and (($discount_coupon_data["provider"] != $provider_for) or (!$products)))
                $discount_coupon = "";

        $total = $total-$coupon_discount;
        //mod king change here added these 3 lines
        $total_taxable_gst-=$coupon_discount;
        $total_taxable-=$coupon_discount;
        $total_taxable_pst-=$coupon_discount;
                //end of change
        $total_shipping -= $coupon_discount;
        if ($total_shipping<0)
                $total_shipping = 0;


mixman 05-19-2004 06:08 PM

discount coupons and taxes
 
Hi Mod King,

Thanks for solving the problem. It is calculating everything correctly. Job well done!!!

To adpboss; I got your message and will stick to recommended forums.

Regards,
Mixman


All times are GMT -8. The time now is 05:18 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.