Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Tax display off by a penny for some tax rates

    Tax calculations are off by a penny when using a tax-rate with more significant digits than the currency displays.

    Using a fresh zc156 base with the demo products loaded, I started by creating a Taxable Goods product with a price of $5.00.

    I then modified the tax-rate for Florida to be a 5.5% tax and modified the Flat Rate shipping (still $5.00) to be also Taxable Goods.

    Went to the storefront and added 2 x the $5.00 product to my cart, went to checkout choosing 'Flat Rate' as my shipping option.

    On the checkout_payment page, the order's total is off by a penny:

    Sub-Total: $10.00
    Flat Rate (Best Way): $5.00
    FL Tax 5.5%: $0.82
    Total: $15.83

    The issue lies with the ot_tax display, since the tax on $15.00 is $0.825 (rounded for display to $0.83).

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Tax display off by a penny for some tax rates

    Is this unique to v1.5.6?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Tax display off by a penny for some tax rates

    Nope, I've verified back to zc154. I just used zc156 as the base to see if, perhaps, something had changed.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Tax display off by a penny for some tax rates

    Here's another one (store is not displaying prices with tax). Using demo installation.

    Create a product, priced at $74.75.
    Modify one of the shipping methods (flat or item) to be (a) taxed and (b) to have a fixed cost of $5.00.
    Create a fixed-price coupon for $1.01.
    Modify the store's tax-rate to be 6%.

    Add 1 x the product to the cart and go to checkout, choosing a shipping address that will have the 6% tax applied and choose the taxed $5.00 shipping method.

    On entry to the checkout_payment page, the order's totals show:

    Sub-Total: $74.75
    Shipping: $5.00
    Sales Tax: $4.79
    Total: $84.54

    Apply the fixed-price coupon. Totals now show

    Sub-Total: $74.75
    Shipping: $5.00
    Coupon: -$1.01
    Sales Tax: $4.73 ... should be $4.72 = 4.42 (rounded from 4.4244) + 0.30
    Total: $83.47

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Tax display off by a penny for some tax rates

    FWIW, I believe that the second example's output is corrected by making the following modification to the zc155/zc156 versions' /includes/modules/order_total/ot_coupon.php:
    Code:
              switch ($this->calculate_tax)
              {
                case 'None':
                  break;
                case 'Standard':
                  if ($od_amount['total'] >= $orderTotalDetails['orderTotal']) $ratio = 1;
                  foreach ($orderTotalDetails['orderTaxGroups'] as $key=>$value)
                  {
    //-bof-20190217-lat9-Don't pre-round tax to be subtracted, can result in penny-off calculations
    //                $od_amount['tax_groups'][$key] = zen_round($orderTotalDetails['orderTaxGroups'][$key] * $ratio, $currencyDecimalPlaces);
                    $od_amount['tax_groups'][$key] = $orderTotalDetails['orderTaxGroups'][$key] * $ratio;
    //-eof-20190217-lat9
                    $od_amount['tax'] += $od_amount['tax_groups'][$key];
                    if ($od_amount['tax_groups'][$key] == 0) unset($od_amount['tax_groups'][$key]);
                  }
                  if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon->fields['coupon_type'] == 'F') $od_amount['total'] = $od_amount['total'] + $od_amount['tax'];
                  break;
                case 'Credit Note':
                  $tax_rate = zen_get_tax_rate($this->tax_class);
                  $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
                  $tax_description = zen_get_tax_description($this->tax_class);
                  $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
              }
    Note that the "real" tax-rounding is happening in the order-total's process method.

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Tax display off by a penny for some tax rates

    Nope, that didn't work. Taking the configuration from post #4, with the following modification:

    Create a product priced at $98.75
    Modify store's tax rate to 7%
    Create a 5%-off discount coupon

    On entry to checkout_payment:

    Sub-Total: $98.75
    Shipping: $5.00
    Tax (7%): $7.26 (actually 7.2625)
    Total: $111.01

    Apply the 5%-off coupon:

    Sub-Total: $98.75
    Coupon: -$4.94 (actually 4.9375)
    Shipping: $5.00
    Tax (7%): $6.91 (should be $6.92, rounded from 6.9167)
    Total: $105.72

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Tax display off by a penny for some tax rates

    I'm all over the place with this one; the invalid output was due to a previous edit of the order-class operation. Using zc155f's order-class with the change proposed in post #5 of this thread produces the correct results.

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Tax display off by a penny for some tax rates

    Quote Originally Posted by lat9 View Post
    Tax calculations are off by a penny when using a tax-rate with more significant digits than the currency displays.

    Using a fresh zc156 base with the demo products loaded, I started by creating a Taxable Goods product with a price of $5.00.

    I then modified the tax-rate for Florida to be a 5.5% tax and modified the Flat Rate shipping (still $5.00) to be also Taxable Goods.

    Went to the storefront and added 2 x the $5.00 product to my cart, went to checkout choosing 'Flat Rate' as my shipping option.

    On the checkout_payment page, the order's total is off by a penny:

    Sub-Total: $10.00
    Flat Rate (Best Way): $5.00
    FL Tax 5.5%: $0.82
    Total: $15.83

    The issue lies with the ot_tax display, since the tax on $15.00 is $0.825 (rounded for display to $0.83).
    Just to update the calculation method, the individual taxes ($0.55 on $10.00 and $0.275 on $5.00) are each rounded to their currency-specified decimal digits (0.55 and 0.28, respectively) to produce the total of $0.83.

    Quote Originally Posted by lat9 View Post
    I'm all over the place with this one; the invalid output was due to a previous edit of the order-class operation. Using zc155f's order-class with the change proposed in post #5 of this thread produces the correct results.
    As indicated, I believe that the change posted corrects the tax-related rounding issue(s) with ot_coupon, but I'm still trying to find the root-cause of the base order penny-off calculations.

    Here's another one, created a product priced at $98.75, still using that $5.00 flat-rate (and taxed) shipping.
    Modified the tax-rate for Florida to be 6.5%.

    On the checkout_payment page, the order's calculated tax is off by a penny:

    Sub-Total: $98.75 ... tax is 6.41875, rounded to 6.42.
    Flat Rate (Best Way) $5.00 ...tax is 0.325, rounded to .33
    FL TAX 6.5%: $6.74 ... should be 6.42 + 0.33 = $6.75
    Total: $110.49 ... should be $110.50

  9. #9
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Tax display off by a penny for some tax rates

    Why for the state of Florida is the shipping and item being taxed separately? Doesn't Florida Administrative Code (Rule 12A-1.045) identify that the tax should be applied against the entire purchase such that 98.75+5 = 103.75 and that 6.5% sales tax is to be applied such that the tax is 6.74375 and is then rounded down (amount after 6.74 is less than 5) such that the tax is 6.74 and the total is 110.49? Or is Florida a state that requires rounding up of final values to the nearest 0.01 such that the above would still be expected to be 110.50? Or even for that matter is the shipping taxable (if customer is given the option to pick up in store then presumably not)?

    While I haven't worked out what combination of numbers would be necessary, it seems that if the proposed method of calculation (round tax at each item/method and then sum the taxes) were used that amounts in excess of the amount due would be collected instead of not enough...

    And further than any of that being specific to FL (considering using the default database which tags FL for an example), which way is appropriate for general taxation? Sum of all items in a tax group and then tax on it, or tax on each item that is then summed to give a total? I pick this aspect of discussion as I am aware also of work on the VAT type module where the goal is to display the total including tax and total without the tax including such information on a page where each item is listed with both sets of numbers. As I have commented elsewhere in the forum, the associated values can vary depending on what the final expectations are. E.g. Tax on an item is calculated to the currencies number of decimal places and then multiplied by the quantity of items, total amount for the number of the product is determined then tax is calculated from that result, summation of all products cost and then tax from there, etc...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Tax display off by a penny for some tax rates

    @mc12345678, that's called a test, simply using the Taxable Goods configuration provided by Zen Cart to model/test various tax situations that have nothing to do with Florida specifically.

    The real question is: At what point should tax-related rounding occur?

    Zen Cart pricing/tax calculations get rounded by the order- and shopping-cart classes and various payment methods and order-totals, so that each taxed addition (or subtraction) from an order's pricing is rounded (or not) at the hands of the module that's making that change to the order's totals.

    I guess the question is whether any tax additions/subtractions from the order should be performed with or without rounding, leaving the final rounding operation to the ot_tax module.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v154 Tax rates, shopping cart spiltting tax rates
    By jwlamb in forum General Questions
    Replies: 0
    Last Post: 24 Mar 2015, 08:20 PM
  2. What is best tax plugin to auto-set tax rates for Canada/US?
    By crexis in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 21 Jul 2013, 03:23 AM
  3. Display prices with TAX and without tax
    By liizz in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 3
    Last Post: 3 Aug 2011, 03:29 AM
  4. Rounding tax rates, result wrong tax.
    By Swech in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 1
    Last Post: 7 Jul 2009, 02:22 PM
  5. Local tax rates to add to state tax
    By terrykiwi in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 2
    Last Post: 18 Feb 2008, 04:02 AM

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