Hi all,
I am just about done with cloning the TaxExempt module to work for me as a Surcharge module. My problem is that I do not know what I can take out of the Tax_Exempt Module.
I have replaced the following
PHP Code:
function process() {
global $db, $order, $currencies;
$tax_exempt_query = $db->Execute("select customers_tax_exempt from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
if ($tax_exempt_query->fields['customers_tax_exempt'] != '0') {
$tax_exempt_discount = $db->Execute("select tax_exempt_name, tax_exempt_percentage from " . TABLE_TAX_EXEMPT . " where
tax_exempt_id = '" . $tax_exempt_query->fields['customers_tax_exempt'] . "'");
$order_total = $this->get_order_total();
$gift_vouchers = $_SESSION['cart']->gv_only();
$discount = ($order_total - $gift_vouchers) * $tax_exempt_discount->fields['tax_exempt_percentage'] / 100;
//Absolute Solutions Edit
$tod_amount = 0;
$product_count = sizeof($order->products);
$products = $order->products;
$taxable_order = 0.00;
$customer_exempt_taxation = floatval($tax_exempt_discount->fields['tax_exempt_percentage']);
for ($p = 0; $p < $product_count; $p++) {
if (round($products[$p]['tax'] - $customer_exempt_taxation, 4) == 0) {
$taxable_order += ($products[$p]['qty'] * $products[$p]['final_price']);
}
}
// echo 'Taxable Order = ' . $taxable_order;
$discount = ($taxable_order - $gift_vouchers) * $customer_exempt_taxation / 100;
$od_amount = zen_round($discount, 2);
if ($this->calculate_tax != "none") {
$tod_amount = $this->calculate_tax_deduction($order_total, $od_amount, $this->calculate_tax, true);
// $od_amount = $this->calculate_credit($order_total);
}
$this->deduction = $od_amount;
if ($discount > 0 ) {
$order->info['total'] -= $this->deduction;
$this->output[] = array('title' => $this->title . ':',
'text' => '-' . $currencies->format($this->deduction, true, $order->info['currency'], $order->info['currency_value']),
'value' => $this->deduction);
}
}
}
with this, as I did not need any of that other code.
PHP Code:
function process() {
global $db, $order;
$hazmat_query = $db->Execute("select count (*) from " . PRODUCTS . " where products_model = '" .'22-0060-01' . "' OR '".'PART # 22-0080-01'."' OR '".'PART # 22-0090-00'."' OR '".'PART # 22-0910-00'."' ");
if ($hazmat_query->fields['products_model'] != '0') {
$order_total = $this->get_order_total();
$hazmatCharge = ($order_total + 20*$hazmat_query);
}
}
This is the entire ot_hazmat file I have created.
PHP Code:
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: ot_hazmat.php 827 2004-12-16 18:17:08Z wilt $
//
class ot_hazmat {
var $title, $output;
function ot_hazmat() {
$this->code = 'ot_hazmat';
$this->title = MODULE_ORDER_TOTAL_HAZMAT_TITLE;
$this->description = MODULE_ORDER_TOTAL_HAZMAT_DESCRIPTION;
$this->sort_order = MODULE_ORDER_TOTAL_HAZMAT_SORT_ORDER;
$this->include_shipping = MODULE_ORDER_TOTAL_HAZMAT_INC_SHIPPING;
$this->include_tax = MODULE_ORDER_TOTAL_HAZMAT_INC_TAX;
$this->calculate_tax = MODULE_ORDER_TOTAL_HAZMAT_CALC_TAX;
$this->credit_tax = MODULE_ORDER_TOTAL_HAZMAT_CREDIT_TAX;
$this->credit_class = true;
$this->output = array();
}
function process() {
global $db, $order, $currencies;
$hazmat_query = $db->Execute("select count (*) from " . PRODUCTS . " where products_model = '" .'22-0060-01' . "' OR '".'PART # 22-0080-01'."' OR '".'PART # 22-0090-00'."' OR '".'PART # 22-0910-00'."' ");
if ($hazmat_query->fields['products_model'] != '0') {
$order_total = $this->get_order_total();
$hazmatCharge = ($order_total + 20*$hazmat_query);
}
}
function get_order_total() {
global $order;
$order_total = $order->info['total'];
if ($this->include_tax == 'false') $order_total = $order_total - $order->info['tax'];
if ($this->include_shipping == 'false') $order_total = $order_total - $order->info['shipping_cost'];
return $order_total;
}
function pre_confirmation_check($order_total) {
global $order, $db;
if ($this->include_shipping == 'false') $order_total -= $order->info['shipping_cost'];
if ($this->include_tax == 'false') $order_total -= $order->info['tax'];
$hazmat_query = $db->Execute("select count (*) from " . PRODUCTS . " where products_model = '" .'22-0060-01' . "' OR '".'PART # 22-0080-01'."' OR '".'PART # 22-0090-00'."' OR '".'PART # 22-0910-00'."' ");
if ($hazmat_query->fields['products_model'] != '0') {
$order_total = $this->get_order_total();
$hazmatCharge = ($order_total + 20*$hazmat_query);
}
}
function credit_selection() {
return $selection;
}
function collect_posts() {
}
function update_credit_account($i) {
}
function apply_credit() {
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_HAZMAT_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function keys() {
return array('MODULE_ORDER_TOTAL_HAZMAT_STATUS', 'MODULE_ORDER_TOTAL_HAZMAT_SORT_ORDER', 'MODULE_ORDER_TOTAL_HAZMAT_INC_SHIPPING', 'MODULE_ORDER_TOTAL_HAZMAT_INC_TAX', 'MODULE_ORDER_TOTAL_HAZMAT_CALC_TAX', 'MODULE_ORDER_TOTAL_HAZMAT_TAX_CLASS');
}
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, sort_order, set_function, date_added) values ('This module is installed', 'MODULE_ORDER_TOTAL_HAZMAT_STATUS', 'true', '', '1','zen_cfg_select_option(array(\'true\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_HAZMAT_SORT_ORDER', '290', 'Sort order of display.', '2', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_ORDER_TOTAL_HAZMAT_INC_SHIPPING', 'false', 'Include Shipping in calculation', '5', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_ORDER_TOTAL_HAZMAT_INC_TAX', 'true', 'Include Tax in calculation.','6','zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, sort_order, set_function ,date_added) values ('Re-calculate Tax', 'MODULE_ORDER_TOTAL_HAZMAT_CALC_TAX', 'Standard', 'Re-Calculate Tax', '7','zen_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_ORDER_TOTAL_HAZMAT_TAX_CLASS', '0', 'Use the following tax class when treating Tax Exemption as Credit Note.', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
}
?>
Am I missing any necessary pieces or do I have any thing in there that will keep this from working?
Thank you,
TheMusician
Bookmarks