function calculate_tax_deduction($amount, $od_amount, $method) { global $customer_id, $order, $cc_id, $cart; $coupon_query = smn_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'"); if (smn_db_num_rows($coupon_query) != 0) { $coupon_result = smn_db_fetch_array($coupon_query); $coupon_get = smn_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '" . $coupon_result['coupon_code'] . "'"); $get_result = smn_db_fetch_array($coupon_get); if ($get_result['coupon_type'] != 'S') { //RESTRICTION-------------------------------- if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) { // What to do here. // Loop through all products and build a list of all product_ids, price, tax class // at the same time create total net amount. // then // for percentage discounts. simply reduce tax group per product by discount percentage // or // for fixed payment amount // calculate ratio based on total net // for each product reduce tax group per product by ratio amount. $products = $cart->get_products(); $valid_product = false; for ($i = 0; $i < sizeof($products); $i++) { $valid_product = false; $t_prid = smn_get_prid($products[$i]['id']); $cc_query = smn_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'"); $cc_result = smn_db_fetch_array($cc_query); if ($get_result['restrict_to_products']) { $pr_ids = split("[,]", $get_result['restrict_to_products']); for ($p = 0; $p < sizeof($pr_ids); $p++) { if ($pr_ids[$p] == $t_prid) { $valid_product = true; } } } if ($get_result['restrict_to_categories']) { $cat_ids = split("[,]", $get_result['restrict_to_categories']); $my_path = smn_get_product_path($t_prid); $sub_cat_ids = split("[_]", $my_path); for ($iii = 0; $iii < count($sub_cat_ids); $iii++) { for ($ii = 0; $ii < count($cat_ids); $ii++) { if ($sub_cat_ids[$iii] == $cat_ids[$ii]) { $valid_product = true; continue 2; } } } } if ($valid_product) { $price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity']; $price_incl_vat = $this->product_price($t_prid); $valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']); $total_price += $price_excl_vat; } } if (sizeof($valid_array) > 0) { if ($get_result['coupon_type'] == 'P') { $ratio = $get_result['coupon_amount'] / 100; } else { $ratio = $od_amount / $total_price; } if ($get_result['coupon_type'] == 'S') { $ratio = 1; } if ($method == 'Credit Note') { $tax_rate = smn_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tax_desc = smn_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); if ($get_result['coupon_type'] == 'P') { $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate; } else { $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100; } $order->info['tax_groups'][$tax_desc] -= $tod_amount; $order->info['total'] -= $tod_amount; $order->info['tax'] -= $tod_amount; } else { for ($p = 0; $p < sizeof($valid_array); $p++) { $tax_rate = smn_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']); $tax_desc = smn_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']); if ($tax_rate > 0) { $tod_amount = $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $order->info['tax_groups'][$tax_desc] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $order->info['total'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $order->info['tax'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; } } } } //NO RESTRICTION-------------------------------- } else { if ($get_result['coupon_type'] == 'F') { $tod_amount = 0; if ($method == 'Credit Note') { $tax_rate = smn_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tax_desc = smn_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate; $order->info['tax_groups'][$tax_desc] -= $tod_amount; } else { reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $ratio1 = $od_amount / ($amount - $order->info['tax_groups'][$key]); $tax_rate = smn_get_tax_rate_from_desc($key); $net = $tax_rate * $order->info['tax_groups'][$key]; if ($net > 0) { $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['total'] -= $tod_amount; $order->info['tax'] -= $tod_amount; } if ($get_result['coupon_type'] == 'P') { $tod_amount = 0; if ($method == 'Credit Note') { $tax_desc = smn_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount / 100; $order->info['tax_groups'][$tax_desc] -= $tod_amount; } else { reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $god_amount = 0; $tax_rate = smn_get_tax_rate_from_desc($key); $net = $tax_rate * $order->info['tax_groups'][$key]; if ($net > 0) { $god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount'] / 100; $tod_amount += $god_amount; $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; } } } $order->info['total'] -= $tod_amount; // have to modify total also $order->info['tax'] -= $tod_amount; } } } } return $tod_amount; }
//set the layout for the the template system..... require DIR_WS_CLASSES . 'template_setup.php'; $store_layout = new template_setup(); $store_layout->smn_set_template(); // auto activate and expire banners require DIR_WS_FUNCTIONS . 'banner.php'; smn_activate_banners(); smn_expire_banners(); // auto expire special products require DIR_WS_FUNCTIONS . 'specials.php'; smn_expire_specials(); // calculate category path if (isset($_GET['cPath'])) { $cPath = $_GET['cPath']; } elseif (isset($_GET['products_id']) && !isset($_GET['manufacturers_id'])) { $cPath = smn_get_product_path($set_product_id); } else { $cPath = ''; } if (smn_not_null($cPath)) { $cPath_array = smn_parse_category_path($cPath); $cPath = implode('_', $cPath_array); $current_category_id = $cPath_array[sizeof($cPath_array) - 1]; } else { $current_category_id = 0; } require DIR_WS_CLASSES . 'spath_setup.php'; $spath_setup = new spath_setup(); // calculate store_category path $sPath = $spath_setup->smn_set_sPath($sPath); if (smn_not_null($sPath)) {