City Tax Rate Hack for MS1 bug fix

ZAP <[email protected]>
Newsgroups gmane.comp.web.oscommerce.features
Message-ID <d2e6ed38ae249e96062e830d103006c4@osCommerce-Forums>
This message was sent from: Features
http://forums.oscommerce.com/viewtopic.php?p=190319#190319
----------------------------------------------------------------

Last post on this from me tonight...

I've tested this a little bit more, and it seems to be working fine. It's a hard-coded brute hack (you might even be tempted to call it a "kludge"), but it works for me in my situation, and it might be helpful to others. To do this right (in all languages and in all places in the code) would require more time than I have on my hands at the moment, so I'll post my code here so that someone else can use/tweak/improve it.

I modified the references to the tax functions in classes/order.php as mentioned above, and those functions in general.php now look like this:

$BARTtaxcities = array (
'ALAMEDA',
'ALAMO',
'ALBANY',
'ANTIOCH',
'BAY POINT',
'BETHEL ISLAND',
'BERKELEY',
'BRENTWOOD',
'BYRON',
'CASTRO VALLEY',
'CLAYTON',
'CLYDE',
'CONCORD',
'CROCKETT',
'DANVILLE',
'DISCOVERY BAY',
'DUBLIN',
'EL CERRITO',
'EL SOBRANTE',
'EMERYVILLE',
'FREMONT',
'HAYWARD',
'HERCULES',
'KENSINGTON',
'KNIGHTSEN',
'LAFAYETTE',
'LIVERMORE',
'MARTINEZ',
'MORAGA',
'NEWARK',
'OAKLAND',
'OAKLEY',
'ORINDA',
'PACHECO',
'PIEDMONT',
'PLEASANTON',
'PINOLE',
'PITTSBURG',
'PLEASANT HILL',
'PORT COSTA',
'RODEO',
'RICHMOND',
'SAN LEANDRO',
'SAN LORENZO',
'SAN PABLO',
'SAN RAMON',
'SUNOL',
'UNION CITY',
'WALNUT CREEK');

////
// CUSTOMIZED FOR SF RATES: Returns the tax rate for a zone / class
// TABLES: tax_rates, zones_to_geo_zones
  function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1, $shipping_city = '', $shipping_zone = '') {
    global $customer_zone_id, $customer_country_id, $customer_id, $BARTtaxcities;

    $BARTtaxzone = 'nope';
    foreach($BARTtaxcities as $val){
         if (($shipping_city == $val) && ($shipping_zone == 12)) {
              $BARTtaxzone = 'yep';
              }
         }

     if (($shipping_city == 'SAN FRANCISCO') && ($shipping_zone == 12)) {
          return 8.5000;
     }

     elseif ( $BARTtaxzone == 'yep' ) {
          return 7.7500;
     }

     elseif ( ($country_id == -1) && ($zone_id == -1) ) {
      if (!tep_session_is_registered('customer_id')) {
        $country_id = STORE_COUNTRY;
        $zone_id = STORE_ZONE;
      } else {
        $country_id = $customer_country_id;
        $zone_id = $customer_zone_id;
      }
    }

    $tax_query = tep_db_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 = '" . $country_id . "') AND (za.zone_id IS NULL OR za.zone_id = '0' OR za.zone_id = '" . $zone_id . "') AND tr.tax_class_id = '" . $class_id . "' GROUP BY tr.tax_priority");
    if (tep_db_num_rows($tax_query)) {
      $tax_multiplier = 0;
      while ($tax = tep_db_fetch_array($tax_query)) {
        $tax_multiplier += $tax['tax_rate'];
      }
      return $tax_multiplier;
    } else {
      return 0;
    }
  }

////
// CUSTOMIZED FOR SF RATES: Return the tax description for a zone / class
// TABLES: tax_rates;
  function tep_get_tax_description($class_id, $country_id, $zone_id, $shipping_city = '', $shipping_zone = '') {
    global $customer_id, $BARTtaxcities;

    $BARTtaxzone = 'nope';
    foreach($BARTtaxcities as $val){
         if (($shipping_city == $val) && ($shipping_zone == 12)) {
              $BARTtaxzone = 'yep';
              }
         }

    $tax_query = tep_db_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 = '" . $country_id . "') AND (za.zone_id IS NULL OR za.zone_id = '0' OR za.zone_id = '" . $zone_id . "') AND tr.tax_class_id = '" . $class_id . "' order by tr.tax_priority");

     if (($shipping_city == 'SAN FRANCISCO') && ($shipping_zone == 12)) {
          return 'San Francisco and California sales tax';
          }
     elseif ( $BARTtaxzone == 'yep' ) {
          return 'California and BART district sales tax';
          }

    elseif (tep_db_num_rows($tax_query)) {
      $tax_description = '';
      while ($tax = tep_db_fetch_array($tax_query)) {
        $tax_description .= $tax['tax_description'] . ' + ';
      }
      $tax_description = substr($tax_description, 0, -3);

      return $tax_description;
    }

     else {
      return TEXT_UNKNOWN_TAX_RATE;
    }
  }


The array of cities is because those are all the cities in a special Bay Area Rapid Transit tax zone for which I have to charge a different tax rate (since San Francisco is also part of this zone).

Hope this helps someone (I've seen a lot of posts regarding similar situations). I'm sure it could be made more efficient or more elegant, but I'm on a deadline here. Feel free to improve upon it and make it your own.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.