Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Incorrect tax with Group Discount

    I'm having trouble with tax calculations for different products with group discounts. The store has taxable and non-taxable products as well as products that are discountable and non-discountable for group members. Thus I have four conditions to handle in ot_group_pricing.php: (1) taxable and discountable, (2) taxable and non-discountable, (3) non-taxable and discountable, and (4) non-taxable and non-discountable. I've modified ot_group_pricing.php to calculate the totals for each of the four conditions plus calculate total taxable and total non-taxable. The correct discount amount is calculated. A ratio used in tax calculations is defined as:
    Code:
    $ratio = $od_amount['total']/$order_total;
    in line 96 of the unmodified ot_group_pricing zc157c code. Later, $ratio is used in the following code:
    Code:
    case 'Standard':
              if ($od_amount['total'] >= $order_total) {
                $ratio = 1;
              }
              $adjustedTax = $orderTotalTax * $ratio;
              if ($order->info['tax'] == 0) return $od_amount;
              $ratioTax = ($orderTotalTax != 0 ) ? $adjustedTax/$orderTotalTax : 0;
              $tax_deduct = 0;
              foreach ($taxGroups as $key=>$value) {
                $od_amount['tax_groups'][$key] = $value * $ratioTax;
                $tax_deduct += $od_amount['tax_groups'][$key];
              }
              $od_amount['tax'] = $tax_deduct;
            break;
    I think the ratio calculation needs to be modified, but I'm stuck. In the calculation of $ratio, should $order_total be replaced by the order discountable taxable total, the order discountable total, or something else? What exactly is $ratio supposed to represent? Any changes needed in the standard case block? The tax calculated is incorrect when mixed discountable and non-discountable products exist in the order.

    Dave
    zc157c, php7.3, only one tax - state sales tax
    Last edited by Dave224; 23 Jun 2021 at 03:55 PM.

  2. #2
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Incorrect tax with Group Discount

    In addition, in the Standard case, $adjustedTax is calculated as $orderTotalTax * $ratio and two lines later, $ratioTax is calculated as $adjustedTax/$orderTotalTax if the $orderTotalTax is not 0. Why the calculation in this line? It just works out to $ratio since $orderTotalTax cancels out. Should that line be:
    Code:
    $ratioTax = ($orderTotalTax != 0 ) ? $ratio: 0;
    Dave

  3. #3
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Incorrect tax with Group Discount

    $ratio before entering the above if block represents the total of the order minus any gift vouchers (customer's payment amount) times the group discount percentage which means for example on the simplest of calculations if the total cost were 100, and there are no gift vouchers and the group percentage discount were 20%, then the discount amount (ends up being $od_amount['total']) is equal to 20. The ratio at that point becomes 20 divided by whatever amount was fed to the method calculate_deductions. Within the ot module that typically appears to be the array result from $order->get_order_total() that represents the value of the key 'total'.

    So, assuming that everything is on the "normal", the ratio represents the amount of the discount divided by the total of the order. One could say that it represents the percentage of the order that is not being paid by the customer or the total discount percentage.

    Then if the amount that is discounted is more than or equal to the provided order total to consider the ratio equal to 1. What that means at that point is that the customer doesn't pay anything or in the reverse the item is 100% discounted.

    So, then regardless the value of $ratio, the adjusted tax is equal to the total tax of the order times the ratio or... The total tax times the amount/percentage the customer is not paying or the percentage discounted such that the adjustedTax is how much tax is to be removed/ignored.

    So, then (and not sure why it is the next step instead of this step being moved up, but if there is no tax on the order return the previously determined $od_amount array which thus far in this code would have just the one key of 'total' which represents the amount that has been discounted (not a percentage but the actual currency amount).

    Considering though that the order identifies that there is tax involved, then move into the ratioTax calculation which identifies a ratio tax if the ordertotaltax is non-zero which was previously determined by use of the order class module get_order_total() that *may* be different than accessing $order->info['tax'].

    But if the orderTotalTax is something non-zero then the ratio tax is determined by the adjustedTax divided by the orderTotalTax which represents the percentage of the tax that the customer is not paying or the percentage of the tax discount.

    So then the loop is executed to go through each tax group. for each tax group it appears that there is a stored tax value that is being modified/set. So for the discount variable's tax_groups, the particular taxgroup is being identified to have what looks like the amount of tax that was on the order for that tax group multiplied by the percentage of the tax the customer is not paying so that can identify the amount of tax reduction/discount to identify. That tax reduction/discount is then summed up to identify the total amount of tax for the customer not to pay.

    After that for loop, the tax amount to discount is set to the summation of taxes removed from the original tax amount determination.

    So seems like in part that the total order should be split into two order_total amounts to be fed to the function where the discountable amount is all that is being provided and that the "total tax" is reduced by the tax associated with the non-discountable amount... At least that's one way I see it, making that happen can be a little bit more "troublesome" though perhaps it also is simple.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. Sales Tax incorrect with percentage discount coupon
    By coryinit in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 8
    Last Post: 5 Apr 2010, 03:40 AM
  2. Replies: 18
    Last Post: 12 Mar 2010, 06:37 PM
  3. Replies: 0
    Last Post: 13 Jun 2008, 12:57 PM
  4. Discount Coupon AND Group Discount Tax Problem
    By mrkrinkle in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 11
    Last Post: 5 Apr 2007, 12:16 PM
  5. Order total incorrect with discount pricing group + tax
    By dbrewster in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 4
    Last Post: 14 Sep 2006, 03:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR