Forums / All Other Contributions/Addons / Customer Tax Exempt

Customer Tax Exempt

Locked

Views: 12,932

Results 41 to 47 of 47
This thread is locked. New replies are disabled.
7 Aug 2008, 1:20 PM
#41
mindows avatar

mindows

New Zenner

Join Date:
Jul 2008
Posts:
8
Plugin Contributions:
0

Customer Tax Exempt

Hi, The last version 1.12a for ZC 1.3.8a working nice.

How to place "VAT inc." next to the price in the catalog for those, who are not approved as the companies and "VAT exc." - for those, who is approved.

Mainly question: If price is without VAT, need to put next to the price (VAT exc.) and if the customers see the price with VAT, need to put (VAT inc.)

Thanks in advance.

16 Oct 2008, 11:52 PM
#42
portalparts avatar

portalparts

New Zenner

Join Date:
Jun 2008
Posts:
1
Plugin Contributions:
0

Re: Customer Tax Exempt

I have not been able to get this addon to work with my 1.39 installation and it's likely a setup issue but I've read every post and piece of documentation about the addon from this site as well as on numinix's site.

I've tried to contact someone at numinix to pay for support now twice in the past week and have no replies.

I've attempted to register on their site today, but have not received my registration confirmation and it's been like 8hrs.

As an opensource developer and one that supports multiple contributions, I have tried to be patient, work the process and offer to pay for support - but am beginning to get a bit frustrated.

Does anyone have this addon working with a 1.39 site?

17 Oct 2008, 6:35 AM
#43
numinix avatar

numinix

Totally Zenned

Join Date:
Apr 2007
Location:
Vancouver, Canada
Posts:
1,567
Plugin Contributions:
58

Re: Customer Tax Exempt

Hi PortalParts,

This is because the email address you used to register and contact us is not valid. Please try with a valid email address and I am sure you will have better success. I will be more than happy to assist you and can have this completed for you on Friday.

13 Nov 2008, 3:30 PM
#44
dogtags avatar

dogtags

Totally Zenned

Join Date:
Nov 2003
Posts:
876
Plugin Contributions:
1

Re: Customer Tax Exempt

Will the latest version of the Tax Exempt module work with zc 1.3.7.1 ?

Thanks :smile:

4 Jan 2009, 3:49 PM
#45
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Customer Tax Exempt

Hello Numinix.
The mod is not working for me at all, and is even conflicting with dual pricing and fast and easy checkout.

I've added ALL for the customer to be exempt from all taxes, added an item to cart which shows the wholesale price in the item description, but when I check the cart it shows the retail price and not the wholesale price. Taxes are there as well.

Do you have a fix for this issue?

Thank you in advance.

M.Valenti
Contemporary Artist - Entrepreneur
http://www.manuelavalenti.com - http://www.byvalenti.com

5 Jan 2009, 2:05 PM
#46
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Customer Tax Exempt

I think I found the solution? I'm not php programmer and my guy the one maintaining my site is on vacations, so I tried to tackle the includes/functions/functions_taxes.php file, with my very limited knowledge, and I made the mod work with dual pricing/ wholesale. The main issue with this file is that no where it integrates the dual pricing mod in it, so when I installed this tax exempt mode it broke my dual pricing.

I don't quite know if what I did was correct but it works on my site. It ads taxes to customers that are not set as wholesale, and eliminates the taxes completely if customers are set as wholesale and ALL is entered in the Customer Tax Exempt box in the customers page as it's supposed to do.

I also had to edit the admin/customers.php file to accommodate both, the dual pricing and the tax exempt.

New functions_taxes.php

<?php
/**
 * functions_taxes
 *
 * @package functions
 * @copyright Copyright 2007-2008 Numinix Technology http://www.numinix.com
 * @copyright Portions Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: functions_taxes.php 6789 2007-08-24 15:46:37Z drbyte $
 * Customer Tax Exempt v1.12a
 */

////
// Returns the tax rate for a zone / class
// TABLES: tax_rates, zones_to_geo_zones
  function zen_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {
    global $db;

    if ( ($country_id == -1) && ($zone_id == -1) ) {
      if (isset($_SESSION['customer_id'])) {
        $country_id = $_SESSION['customer_country_id'];
        $zone_id = $_SESSION['customer_zone_id'];
      } else {
        $country_id = STORE_COUNTRY;
        $zone_id = STORE_ZONE;
      }
    }

    if (STORE_PRODUCT_TAX_BASIS == 'Store') {
      if ($zone_id != STORE_ZONE) return 0;
    }
// begin Customer Tax Exempt edit    
    if ($_SESSION['customer_id']) {
    	$customers_id = $_SESSION['customer_id'];
		$customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = '$customers_id'");
//VALENTI added dual pricing/wholesale if statement
    if ($customer_check->fields['customers_whole'] != "0") {
        $whole = 1;
	}
}
	
	if ($customer_check->fields['customers_tax_exempt'] != "") {
    	global $db;
	    $tax_query = "select tax_description
              from (" . TABLE_TAX_RATES . " tr
              left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id)
              left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) )
              where (za.zone_country_id is null or za.zone_country_id = 0
              or za.zone_country_id = '" . (int)$country_id . "')
              and (za.zone_id is null
              or za.zone_id = 0
              or za.zone_id = '" . (int)$zone_id . "')
              and tr.tax_class_id = '" . (int)$class_id . "'
              order by tr.tax_priority";
    	
        $tax = $db->Execute($tax_query);		
    	$tax_description = '';
  		while (!$tax->EOF) {
      		$match = 0;
      		$exempt_taxes = $customer_check->fields['customers_tax_exempt'];
      		$exempt_taxes = split(",", $exempt_taxes);
      		foreach ($exempt_taxes as $exempt_tax) {
	      		if (trim(strtolower($exempt_tax)) == trim(strtolower($tax->fields['tax_description']))) {
		      		$match++;
	      		}
      		}
      		if ($match == 0) {
	      		$tax_description .= $tax->fields['tax_description'] . ' + ';
      		}
    		$tax->MoveNext();
  		}
  		$tax_description = substr($tax_description, 0, -3);
	    $tax_rate = 0.00;
	    $tax_descriptions = explode(' + ', $tax_description);
	    foreach ($tax_descriptions as $tax_description) {
	      $tax_query = "SELECT tax_rate
                   FROM " . TABLE_TAX_RATES . "
                   WHERE tax_description = :taxDescLookup";
	      $tax_query = $db->bindVars($tax_query, ':taxDescLookup', $tax_description, 'string'); 
	      $tax = $db->Execute($tax_query);
	      $tax_rate += $tax->fields['tax_rate'];
   		}
    } else {
		$tax_query = "select sum(tax_rate) as tax_rate
	                  from (" . TABLE_TAX_RATES . " tr
	                  left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id)
	                  left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) )
	                  where (za.zone_country_id is null
	                  or za.zone_country_id = 0
	                  or za.zone_country_id = '" . (int)$country_id . "')
	                  and (za.zone_id is null
	                  or za.zone_id = 0
	                  or za.zone_id = '" . (int)$zone_id . "')
	                  and tr.tax_class_id = '" . (int)$class_id . "'
	                  group by tr.tax_priority";
	    $tax = $db->Execute($tax_query);
    }
   

    if ($customer_check->fields['customers_tax_exempt'] == "ALL") {
	    return 0;
	}
//VALENTI added dual pricing/wholesale if statement
	    if ($customer_check->fields['customers_whole'] != "0") {
        $whole = 1;
//VALENTI added 'customers_whole'
    } else if ($customer_check->fields['customers_tax_exempt' . 'customers_whole'] != "") {
	    return $tax_rate;
 	} else {

	    if ($tax->RecordCount() > 0) {
	      $tax_multiplier = 1.0;
	      while (!$tax->EOF) {
	        $tax_multiplier *= 1.0 + ($tax->fields['tax_rate'] / 100);
	        $tax->MoveNext();
	      }
	      return ($tax_multiplier - 1.0) * 100;
	    } else {
	      return 0;
	    }
 	}
}

////
// Return the tax description for a zone / class
// TABLES: tax_rates;
 
function zen_get_tax_description($class_id, $country_id = -1, $zone_id = -1) {
    global $db;

    if ( ($country_id == -1) && ($zone_id == -1) ) {
      if (isset($_SESSION['customer_id'])) {
        $country_id = $_SESSION['customer_country_id'];
        $zone_id = $_SESSION['customer_zone_id'];
      } else {
        $country_id = STORE_COUNTRY;
        $zone_id = STORE_ZONE;
      }
    }

    $tax_query = "select tax_description
                  from (" . TABLE_TAX_RATES . " tr
                  left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id)
                  left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) )
                  where (za.zone_country_id is null or za.zone_country_id = 0
                  or za.zone_country_id = '" . (int)$country_id . "')
                  and (za.zone_id is null
                  or za.zone_id = 0
                  or za.zone_id = '" . (int)$zone_id . "')
                  and tr.tax_class_id = '" . (int)$class_id . "'
                  order by tr.tax_priority";

    $tax = $db->Execute($tax_query);

	if ($_SESSION['customer_id']) {
	    $customers_id = $_SESSION['customer_id'];
	    $customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = " . $customers_id);
    }    

	if ($customer_check->fields['customers_tax_exempt'] == "ALL") {
	    return TEXT_UNKNOWN_TAX_RATE;
    } else if ($customer_check->fields['customers_tax_exempt'] != "") {
	    if ($tax->RecordCount() > 0) {
	      		$tax_description = '';
	      		while (!$tax->EOF) {
		      		$match = 0;
		      		$exempt_taxes = $customer_check->fields['customers_tax_exempt'];
		      		$exempt_taxes = split(",", $exempt_taxes);
		      		foreach ($exempt_taxes as $exempt_tax) {
			      		if (trim(strtolower($exempt_tax)) == trim(strtolower($tax->fields['tax_description']))) {
				      		$match++;
			      		}
		      		}
		      		if ($match == 0) {
			      		$tax_description .= $tax->fields['tax_description'] . ' + ';
		      		}
		      		//$tax_description .= $tax->fields['tax_description'] . ' + ';
	        		$tax->MoveNext();
	      		}
	      		$tax_description = substr($tax_description, 0, -3);
	
	      		return $tax_description;
	    	} else {
	      		return TEXT_UNKNOWN_TAX_RATE;
	    	}
    	} else {
		    if ($tax->RecordCount() > 0) {
		      $tax_description = '';
		      while (!$tax->EOF) {
		        $tax_description .= $tax->fields['tax_description'] . ' + ';
		        $tax->MoveNext();
		      }
		      $tax_description = substr($tax_description, 0, -3);
		
		      return $tax_description;
		    } else {
		      return TEXT_UNKNOWN_TAX_RATE;
		    }
  		}
}
// end Customer Tax Exempt edit

////
// Return the tax rates for each defined tax for the given class and zone
// @returns array(description => tax_rate)
  function zen_get_multiple_tax_rates($class_id, $country_id, $zone_id, $tax_description=array()) {
    global $db;

    if ( ($country_id == -1) && ($zone_id == -1) ) {
      if (isset($_SESSION['customer_id'])) {
        $country_id = $_SESSION['customer_country_id'];
        $zone_id = $_SESSION['customer_zone_id'];
      } else {
        $country_id = STORE_COUNTRY;
        $zone_id = STORE_ZONE;
      }
    }
    
    // BEGIN CUSTOMER TAX EXEMPT
    if (isset($_SESSION['customer_id'])) {
      $customer_query = "select * from " . TABLE_CUSTOMERS . " where customers_id = " . $_SESSION['customer_id'] . " LIMIT 1";
      $customer_check = $db->Execute($customer_query);
      $customers_tax_exempt = $customer_check->fields['customers_tax_exempt'];
//VALENTI added dual pricing/wholesale if statement
    if ($customer_check->fields['customers_whole'] != "0") {
        $whole = 1;
    }
    }

    
    $tax_query = "select tax_description, tax_rate, tax_priority
                  from (" . TABLE_TAX_RATES . " tr
                  left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id)
                  left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) )
                  where (za.zone_country_id is null or za.zone_country_id = 0
                  or za.zone_country_id = '" . (int)$country_id . "')
                  and (za.zone_id is null
                  or za.zone_id = 0
                  or za.zone_id = '" . (int)$zone_id . "')
                  and tr.tax_class_id = '" . (int)$class_id . "'
                  order by tr.tax_priority";
    $tax = $db->Execute($tax_query);
    
    //echo 'exempt:' . $customers_tax_exempt;
    //die();
    
    switch($customers_tax_exempt) {
      case "ALL":
        $rates_array[0] = TEXT_UNKNOWN_TAX_RATE;
        break;
      case "":
        // calculate appropriate tax rate respecting priorities and compounding
        if ($tax->RecordCount() > 0) {
          $tax_aggregate_rate = 1;
          $tax_rate_factor = 1;
          $tax_prior_rate = 1;
          $tax_priority = 0;
          while (!$tax->EOF) {
            if ((int)$tax->fields['tax_priority'] > $tax_priority) {
              $tax_priority = $tax->fields['tax_priority'];
              $tax_prior_rate = $tax_aggregate_rate;
              $tax_rate_factor = 1 + ($tax->fields['tax_rate'] / 100);
              $tax_rate_factor *= $tax_aggregate_rate;
              $tax_aggregate_rate = 1;
            } else {
              $tax_rate_factor = $tax_prior_rate * ( 1 + ($tax->fields['tax_rate'] / 100));
            }
            $rates_array[$tax->fields['tax_description']] = 100 * ($tax_rate_factor - $tax_prior_rate);
            $tax_aggregate_rate += $tax_rate_factor - 1;
            $tax->MoveNext();
          }
        } else {
          // no tax at this level, set rate to 0 and description of unknown
          $rates_array[0] = TEXT_UNKNOWN_TAX_RATE;
        }
        break;
      default:
        // calculate appropriate tax rate respecting priorities and compounding
        if ($tax->RecordCount() > 0) {
          $tax_aggregate_rate = 1;
          $tax_rate_factor = 1;
          $tax_prior_rate = 1;
          $tax_priority = 0;
          while (!$tax->EOF) {
            $match = 0;
            //$exempt_taxes = $customer_check->fields['customers_tax_exempt'];
            $exempt_taxes = split(",", $customers_tax_exempt);
            foreach ($exempt_taxes as $exempt_tax) {
              if (trim(strtolower($exempt_tax)) == trim(strtolower($tax->fields['tax_description']))) {
                $match++;
              }
            }
            if ($match == 0) {
              if ((int)$tax->fields['tax_priority'] > $tax_priority) {
                $tax_priority = $tax->fields['tax_priority'];
                $tax_prior_rate = $tax_aggregate_rate;
                $tax_rate_factor = 1 + ($tax->fields['tax_rate'] / 100);
                $tax_rate_factor *= $tax_aggregate_rate;
                $tax_aggregate_rate = 1;
              } else {
                $tax_rate_factor = $tax_prior_rate * ( 1 + ($tax->fields['tax_rate'] / 100));
              }
              $rates_array[$tax->fields['tax_description']] = 100 * ($tax_rate_factor - $tax_prior_rate);
              $tax_aggregate_rate += $tax_rate_factor - 1;
            } 
            $tax->MoveNext();
          }
        } else {
          // no tax at this level, set rate to 0 and description of unknown
          $rates_array[0] = TEXT_UNKNOWN_TAX_RATE;
        }
        break;
    }
    // END CUSTOMER TAX EXEMPT
    return $rates_array;       
  }

  	

////
// 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) ) {
      return zen_round($price, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']) + zen_calculate_tax($price, $tax);
    } 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($result, 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
//    return $result;
    return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
  }


////
// Output the tax percentage with optional padded decimals
  function zen_display_tax_value($value, $padding = TAX_DECIMAL_PLACES) {
    if (strpos($value, '.')) {
      $loop = true;
      while ($loop) {
        if (substr($value, -1) == '0') {
          $value = substr($value, 0, -1);
        } else {
          $loop = false;
          if (substr($value, -1) == '.') {
            $value = substr($value, 0, -1);
          }
        }
      }
    }


    if ($padding > 0) {
      if ($decimal_pos = strpos($value, '.')) {
        $decimals = strlen(substr($value, ($decimal_pos+1)));
        for ($i=$decimals; $i<$padding; $i++) {
          $value .= '0';
        }
      } else {
        $value .= '.';
        for ($i=0; $i<$padding; $i++) {
          $value .= '0';
        }
      }
    }

    return $value;
  }

////
// Get tax rate from tax description
 function zen_get_tax_rate_from_desc($tax_desc) {
    global $db;
    $tax_rate = 0.00;


    $tax_descriptions = explode(' + ', $tax_desc);
    foreach ($tax_descriptions as $tax_description) {
      $tax_query = "SELECT tax_rate
                    FROM " . TABLE_TAX_RATES . "
                    WHERE tax_description = :taxDescLookup";
      $tax_query = $db->bindVars($tax_query, ':taxDescLookup', $tax_description, 'string'); 

      $tax = $db->Execute($tax_query);

      $tax_rate += $tax->fields['tax_rate'];
    }

    return $tax_rate;
  }

 function zen_get_tax_locations($store_country = -1, $store_zone = -1) {
  global $db;
    switch (STORE_PRODUCT_TAX_BASIS) {

      case 'Shipping':
        $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
                                from " . TABLE_ADDRESS_BOOK . " ab
                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
                                where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
                                and ab.address_book_id = '" . (int)$_SESSION['sendto'] . "'";
        $tax_address_result = $db->Execute($tax_address_query);
      break;
      case 'Billing':

        $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
                                from " . TABLE_ADDRESS_BOOK . " ab
                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
                                where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
                                and ab.address_book_id = '" . (int)$_SESSION['billto'] . "'";
        $tax_address_result = $db->Execute($tax_address_query);
      break;
      case 'Store':
        $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
                                from " . TABLE_ADDRESS_BOOK . " ab
                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
                                where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
                                and ab.address_book_id = '" . (int)$_SESSION['billto'] . "'";
        $tax_address_result = $db->Execute($tax_address_query);

        if ($tax_address_result ->fields['entry_zone_id'] == STORE_ZONE) {

        } else {
          $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
                                  from " . TABLE_ADDRESS_BOOK . " ab
                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
                                  where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
                                  and ab.address_book_id = '" . (int)$_SESSION['sendto'] . "'";
        $tax_address_result = $db->Execute($tax_address_query);
       }
     }
     $tax_address['zone_id'] = $tax_address_result->fields['entry_zone_id'];
     $tax_address['country_id'] = $tax_address_result->fields['entry_country_id'];
     return $tax_address;
 }
?>

M.Valenti
Contemporary Artist - Entrepreneur
http://www.manuelavalenti.com - http://www.byvalenti.com

5 Jan 2009, 2:11 PM
#47
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Customer Tax Exempt

**New customers.php **
customers.php

I know there must be a better more professional way to write the changes I did to these files, but for now it does what I need for my site. Hope someone else finds it useful too :smile:

M.Valenti
Contemporary Artist - Entrepreneur
http://www.manuelavalenti.com - http://www.byvalenti.com