RE: need a quick help with an order total module

Ian <[email protected]>
Newsgroups gmane.comp.web.oscommerce.devel
Message-ID <95380bf15759e776d90d3bda33c68ea9@osCommerce-Forums>
This message was sent from: Development
http://forums.oscommerce.com/viewtopic.php?p=162951#162951
----------------------------------------------------------------

Joshua,

These are obviously just code snippets but should help.

First there is a little function to find the tax rate for the current tax group.
You can put this function into general.php

[code]////
// Get tax rate from tax description
  function tep_get_tax_rate_from_desc($tax_desc) {
    $tax_query = tep_db_query("select tax_rate from " . TABLE_TAX_RATES . " where tax_description = '" . $tax_desc . "'");
    $tax = tep_db_fetch_array($tax_query);
    return $tax['tax_rate'];
  }
[/code]

The first snippet calculates a percentage discounts effect on tax.
given that the percentage is in $p_deduct

[code]          $tod_amount=0;
          reset($order->info['tax_groups']);
          while (list($key, $value) = each($order->info['tax_groups'])) {
            $god_amout=0;
            $tax_rate = tep_get_tax_rate_from_desc($key);
            $net = $tax_rate * $order->info['tax_groups'][$key];
            if ($net>0) {
              $god_amount = $order->info['tax_groups'][$key] * $p_deduct/100;
              $tod_amount += $god_amount;
              $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
            }
          }           
          $order->info['tax'] -= $tod_amount;
          $order->info['total'] -= $tod_amount; 
[/code]

The second re-calculates tax for a fixed deduction in $f_deduct

[code]          $tod_amount = 0;
          reset($order->info['tax_groups']);
          while (list($key, $value) = each($order->info['tax_groups'])) {
            $tax_rate = tep_get_tax_rate_from_desc($key);
            $net = $tax_rate * $order->info['tax_groups'][$key];
            if ($net>0) {
              $ratio1 = $f_deduct/$net;
              $god_amount = $order->info['tax_groups'][$key] * $ratio1;
              $tod_amount += $god_amount;
              $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
            }
          }           
          $order->info['tax'] -= $tod_amount;
          $order->info['total'] -= $tod_amount;
[/code]

HTH
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.