Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32
  1. #1
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default [Done 1.3.6] 1.3.5 coupon tax calculation and fix

    Note: Tax calculation for discount coupons was broken prior to 1.3.5, but the line numbers
    specified below are for the 1.3.5 version of ot_coupon.php.

    To reproduce:
    Enable discount coupon under modules/order total. Set recalculate tax to standard.
    Add two items to your cart and check out. (If you simply add one item, the tax is correct.)

    Fix: In ot_coupon.php, delete the following lines: l 279-280.
    Then delete lines 214-218.

    Now the tax will always show as the tax on the subtotal, but if you "include tax"
    in your coupon settings, the amount shown for the discount will compensate
    for the price deduction. I believe that this is the correct approach, and the way
    that group discounts does it (which modifies the tax) is misleading - but in any event,
    the calculations are correct.

    Scott
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: 1.3.5 coupon tax calculation and fix

    I've done some more testing with different settings and this fix seems good.
    If you want to just grab it and not have to make the file edits I've described, please
    download

    <moderator edit: file link removed>

    Good luck,
    Scott
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  3. #3
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: 1.3.5 coupon tax calculation and fix

    I hate to be blunt here, but I would not advise anyione to use the fixes you mentuion here,

    They basically remove all of the product restriction code, which for some people is one of the major components of the coupon system.

    However, if you do have a bug related to the coupon tax, I would really like to help you resolve that in a way that does not mean removing features.

    I reaise tis may be difficut if you have now changed your codebase, but what would have been nice would have been a posted example from checkout showing how the tax calculation was wrong. such an example should also include details of ALL of the settings you used for the coupon module.

    One thing that should be noted is that the default settings are not always the best for specific purposes, and unfortunately I have to admit that docs in this area are lacking. That will improve,

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: 1.3.5 coupon tax calculation and fix

    I posted instructions on reproducing the problem in my first post. Did you not see the problem when you followed these instructions? I can provide some more testcases tonight, but I used the default settings, the problem seemed to occur in any number of cases where I added multiple items to my cart.

    Scott
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  5. #5
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: 1.3.5 coupon tax calculation and fix

    Hi,

    yes I did read your first post.

    My point in this, With the greatest will in the world, its impossible to reproduce some one elses setup. k, so you said you were using the default settings of the coupon module, but you did not give any details of the coupon, was it a percentage or fixed coupon, I assumed it was not a restricted coupon, but that was an assumption.

    All I was asking for was you to actually show some figures. If there is a bug, having the figures can actually help in debugging the problem

  6. #6
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: 1.3.5 coupon tax calculation and fix

    I added three items to my cart. The store is in FL, and I live in FL.
    State sales tax is 7%. Products are taxable goods. Here are the numbers:

    Without a coupon:
    Sub-Total: $360.
    Flat Rate (Best Way): $10.00
    FL TAX 7.0%: $25.20
    Total: $395.20
    -- these numbers are correct.

    Now add a 10% off coupon. Nothing special, just 10% off,
    uses per customer is blank.

    Coupon:
    Sub-Total: $360
    Flat Rate (Best Way): $10.00
    Discount Coupon: SAVETEN : -$36.00
    FL TAX 7.0%: $17.64
    Total: $351.64
    The state tax here is wrong.

    with my fix:
    Sub-Total: $360
    Flat Rate (Best Way): $10.00
    Discount Coupon: SAVETEN : -$36.00
    FL TAX 7.0%: $25.20
    Total: $359.20
    The state tax here is correct.


    Discount Coupon Settings:

    Sort Order
    280

    Include Shipping
    false

    Include Tax
    false

    Re-calculate Tax
    Standard

    Tax Class
    --none--

    The only difference between this and the default is that include shipping is set to false.
    However, sales tax is still wrong if include shipping is set to true.

    The coupon itself was just a 10% coupon - nothing special.

    I don't use the product restriction code, but I do need the sales tax to be correct.

    Can you post a testcase in which the numbers work correctly? Or can you post
    a fix that maintains the product restriction code but fixes the sales tax?

    Thanks,
    Scott
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  7. #7
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: 1.3.5 coupon tax calculation and fix

    Scott,

    Sorry for being so anal, but having the figures does make bugfixing so much easier,

    Thanks for the detail

  8. #8
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: 1.3.5 coupon tax calculation and fix

    My fault; I spend all day long complaining about irreproduceable phantom bug reports and then I commit the same sin! :)

    Hopefully you can dup this easily. One thing: is it possible that you've been testing with Re-Calculate Tax = None? Because this will bypass the code that I believe is causing the problem.

    Thanks,
    Scott
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  9. #9
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: 1.3.5 coupon tax calculation and fix

    Actually once I had your figures and I tested against a couple of different selections of cart contents I found the bug fairly quickly.

    I am a bit shamefaced that this made its way thru testing, as I was sure that I had tested this fairly comprehensivly

    As mentioned the bug only shows if there is more than 1 item in the cart, the bug however has nothing to do with the restriction code.

    heres my updated function. Note I would like to test this a bit more before saying that this fix is authorative, especially as I have not tested this with restrictions in place.

    PHP Code:
      function calculate_deductions($order_total) {
        global 
    $db$order$messageStack;
        
    $tax_address zen_get_tax_locations();
        
    $od_amount = array();
        if (
    $_SESSION['cc_id']) {
          
    $coupon $db->Execute("select * from " TABLE_COUPONS " where coupon_id = '" . (int)$_SESSION['cc_id'] . "'");
          if ((
    $coupon->RecordCount() > && $order_total !=0) || ($coupon->RecordCount() > && $coupon->fields['coupon_type']=='S') ) {
            if (
    $coupon->fields['coupon_minimum_order'] <= $order_total) {
              if (
    $coupon->fields['coupon_type']=='S') {
                
    $od_amount['total'] = $order->info['shipping_cost'];
                
    $od_amount['type'] = 'S';
              } else {
                if (
    $coupon->fields['coupon_type'] == 'P') {
                  
    $od_amount['total'] = zen_round($order_total*($coupon->fields['coupon_amount']/100), 2);
               } else {
                  
    $od_amount['total'] = $coupon->fields['coupon_amount'] * ($order_total>0);
                }
                if (
    $od_amount['total']>$order_total$od_amount['total'] = $order_total;
                
    $products $_SESSION['cart']->get_products();
                for (
    $i=0$i<sizeof($products); $i++) {
                  
    // speed up process and store value
                  
    $is_valid_results is_product_valid($products[$i]['id'], $_SESSION['cc_id']);
                  if (
    $is_valid_results) {
                    if (
    $coupon->fields['coupon_type'] == 'P') {
                      switch (
    $this->calculate_tax) {
                        case 
    'Credit Note':
                          
    $tax_rate zen_get_tax_rate($this->tax_class$tax_address['country_id'], $tax_address['zone_id']);
                          
    $tax_desc zen_get_tax_description($this->tax_class$tax_address['country_id'], $tax_address['zone_id']);
                          
    $od_amount[$tax_desc] = $od_amount['total'] / 100 $tax_rate;
                          
    $od_amount['tax'] += $od_amount[$tax_desc];
                        break;
                        case 
    'Standard':
                          
    $ratio $od_amount['total']/$this->get_order_total();
                            
    $t_prid zen_get_prid($products[$i]['id']);
                            
    $cc_result $db->Execute("select products_tax_class_id
                                                       from " 
    TABLE_PRODUCTS " where products_id = '" $t_prid "'");

                            if (
    $is_valid_results) {
                              
    $tax_rate zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                              
    $tax_desc zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                              if (
    $tax_rate 0) {
                                
    $od_amount[$tax_desc] += round(((($products[$i]['final_price'] * $products[$i]['quantity']) * $tax_rate) + .5)/100 $ratio2);
                                
    $od_amount['tax'] += $od_amount[$tax_desc];
                              }
                            }
                        break;
                        default:
                      }
                    }
                    if (
    $coupon->fields['coupon_type'] == 'F') {
                      switch (
    $this->calculate_tax) {
                        case 
    'Credit Note':
                          
    $tax_rate zen_get_tax_rate($this->tax_class$tax_address['country_id'], $tax_address['zone_id']);
                          
    $tax_desc zen_get_tax_description($this->tax_class$tax_address['country_id'], $tax_address['zone_id']);
                          
    $od_amount[$tax_desc] = $od_amount['total'] / 100 $tax_rate;
                          
    $od_amount['tax'] += $od_amount[$tax_desc];
                        break;
                        case 
    'Standard':
                          
    $ratio $od_amount['total']/$this->get_order_total();
                          
    $products $_SESSION['cart']->get_products();
                            
    $t_prid zen_get_prid($products[$i]['id']);
                            
    $cc_result $db->Execute("select products_tax_class_id
                                                       from " 
    TABLE_PRODUCTS " where products_id = '" $t_prid "'");

                            if (
    $is_valid_results) {
                              
    $tax_rate zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                              
    $tax_desc zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                              if (
    $tax_rate 0) {
                                
    $od_amount[$tax_desc] += round(((($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate) + .5)/100 $ratio2);
                                
    $od_amount['tax'] += $od_amount[$tax_desc];
                              }
                            }
                        break;
                        default:
                      }
                    }
                  }
                }
              }
            }
          }
        }
        return 
    $od_amount;
      } 

  10. #10
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default Re: 1.3.5 coupon tax calculation and fix

    This is good news! Please post a new copy of ot_coupon.php when you're satisfied.

    Other readers of this thread: I have deleted coupon_1.3.5_fix.zip off my site; please sit tight until Wilt's comprehensive fix is ready.

    Thanks,
    Scott
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

 

 
Page 1 of 4 123 ... LastLast

Similar Threads

  1. Replies: 18
    Last Post: 12 Mar 2010, 06:37 PM
  2. [Done v1.3.9] Sales Tax Calculation Incorrect
    By fergusmacdonald in forum Bug Reports
    Replies: 28
    Last Post: 21 May 2009, 10:49 PM
  3. [Done v1.3.9] tax calculation
    By hugo13 in forum Bug Reports
    Replies: 31
    Last Post: 17 Mar 2009, 11:07 PM
  4. Discount Coupon Tax calculation problem
    By Amit001 in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 1
    Last Post: 1 Aug 2008, 02:00 PM
  5. Replies: 7
    Last Post: 13 Nov 2006, 12:11 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