Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32
  1. #1
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default [Done v1.3.9] tax calculation

    given:
    zc138
    tax == 19%
    price with tax == 9.99
    result == 10.00

    because the function zen_add_tax() "double rounds" the value
    PHP Code:
    return zen_round($price$currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + zen_calculate_tax($price$tax); 
    8.40 + 1.60 == 10.00


    i think it should be
    PHP Code:
            $tax $price $tax 100;
            
    $priceInclTax $price $tax;
            
    $priceInclTaxFormatted zen_round($priceInclTax$currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
            return 
    $priceInclTaxFormatted
    8.395 + 1.59505 = 9.99005 ==> 9.99
    Last edited by hugo13; 15 Aug 2008 at 06:37 AM.

  2. #2
    Join Date
    Sep 2004
    Posts
    71
    Plugin Contributions
    0

    Default Re: tax calculation

    Absolutely correct , just the problem I was looking for has been solved.

    Strange no one else noticed this....thanks man!

  3. #3
    Join Date
    Jan 2008
    Posts
    22
    Plugin Contributions
    0

    Default Re: tax calculation

    In which file I need to change this?

  4. #4
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default Re: tax calculation

    Quote Originally Posted by Marco_K View Post
    In which file I need to change this?
    /includes/functions/functions_taxes.php

  5. #5
    Join Date
    Jan 2008
    Posts
    22
    Plugin Contributions
    0

    Default Re: tax calculation

    Didn't work for me. I use 1.3.8.
    TAX 19% €10,099 was rounded off at €10,11

  6. #6
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default Re: tax calculation

    MY VALUES: ( http://demo.zen-cart.at/index.php?ma...roducts_id=184 )

    Products Price (Net): 53.1526
    Products Price (Gross): 63.2516
    Tax: 19%

    ==> shopdisplay
    €53.15 Sub-Total:
    €0.00 Store Pickup (Walk In):
    €10.10 19%:
    €63.25 Total:

    and YOUR VALUES ?

  7. #7
    Join Date
    Jan 2008
    Posts
    22
    Plugin Contributions
    0

    Default Re: tax calculation

    Currencie with 2 numbers after the comma:
    Sub-Total: €14,90
    Transport: €7,50
    Tax 19%: €4,27
    Total: €26,67


    Currencie with 3 numbers after the comma:
    Sub-Total: €14,900
    Transport: €7,500
    Tax 19%: €4,256
    Total: €26,656

  8. #8
    Join Date
    Jan 2008
    Posts
    22
    Plugin Contributions
    0

    Default Re: tax calculation

    Quote Originally Posted by hugo13 View Post
    /includes/functions/functions_taxes.php

    Maybe you can send me your /includes/functions/functions_taxes.php file ?

    Let's see what happens when i overwrite my one (making a backup first).

  9. #9
    Join Date
    Jan 2008
    Posts
    22
    Plugin Contributions
    0

    Default Re: tax calculation

    I think i've got it (EUREKA) ;-)

    This is what my code looks like now, Line 160 til 180, in /includes/functions/functions_taxes.php:

    PHP Code:
    // Add tax to a products price based on whether we are displaying tax "in" the price
      
    function zen_add_tax($price$tax) {
        global 
    $currencies;
        if ( (
    DISPLAY_PRICE_WITH_TAX == 'true') && ($tax 0) ) {
                  
    $tax $price $tax 100;
            
    $priceInclTax $price $tax;
            
    $priceInclTaxFormatted zen_round($priceInclTax$currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
            return 
    $priceInclTaxFormatted;
        } else {
          return 
    zen_round($price$currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
        }
      }

    // Calculates Tax rounding the result
      
    function zen_calculate_tax($price$tax) {
        global 
    $currencies;
        
    $result bcmul($price$tax$currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
        
    $result bcdiv($result100$currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
        return 
    $result;
        return 
    zen_round($price $tax 100$currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
      } 
    Tax 19% €4,256 is now rounded off at €4,26 and NOT €4,27

  10. #10
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default Re: tax calculation

    I think, the php-function round is buggy ( http://php.net/manual/de/function.round.php see the comments and workarounds: setting of type, doesnt helped)

    bcmul & co is problematic, because php must be compiled with --enable-bcmath

    the only working way was to change the function zen_round (includes/functions/function_general.php)
    PHP Code:
      function zen_round($number$precision) {
    /// fix rounding error on GVs etc.
        
    $number round($number$precision+1);   // round with a higher prec
        
    $number round($number$precision);

        return 
    $number;
      } 
    the second helping way was:
    settype($tax, 'string);
    if I set it to "float" its also wrong
    its a bit crazy

 

 
Page 1 of 4 123 ... LastLast

Similar Threads

  1. [Done 1.3.9b] One Time Charges Tax Calculation
    By clide in forum Bug Reports
    Replies: 0
    Last Post: 26 Apr 2010, 09:33 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. Problem with tax calculation on Tax Exempt goods
    By vickula in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 3
    Last Post: 25 Mar 2009, 03:49 PM
  4. Replies: 31
    Last Post: 12 Dec 2006, 06:36 AM
  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