function cart() { global $oCurrencies; $this->content_type = $_SESSION['cart']->get_content_type(); $nLanguageID = isset($_SESSION['language_id']) ? $_SESSION['language_id'] + 0 : 1; // Get database information $dbconn =& oosDBGetConn(); $oostable =& oosDBGetTables(); $customerstable = $oostable['customers']; $address_booktable = $oostable['address_book']; $zonestable = $oostable['zones']; $countriestable = $oostable['countries']; $sql = "SELECT c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address,\n ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city,\n ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2,\n co.countries_iso_code_3, co.address_format_id, ab.entry_state\n FROM {$customerstable} c,\n {$address_booktable} ab LEFT JOIN\n {$zonestable} z\n ON (ab.entry_zone_id = z.zone_id) LEFT JOIN\n {$countriestable} co\n ON (ab.entry_country_id = co.countries_id)\n WHERE c.customers_id = '" . intval($_SESSION['customer_id']) . "' AND\n ab.customers_id = '" . intval($_SESSION['customer_id']) . "' AND\n c.customers_default_address_id = ab.address_book_id"; $customer_address = $dbconn->GetRow($sql); $address_booktable = $oostable['address_book']; $zonestable = $oostable['zones']; $countriestable = $oostable['countries']; $sql = "SELECT ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address,\n ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name,\n ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2,\n c.countries_iso_code_3, c.address_format_id, ab.entry_state\n FROM {$address_booktable} ab LEFT JOIN\n {$zonestable} z\n ON (ab.entry_zone_id = z.zone_id) LEFT JOIN\n {$countriestable} c ON\n (ab.entry_country_id = c.countries_id)\n WHERE ab.customers_id = '" . intval($_SESSION['customer_id']) . "' AND\n ab.address_book_id = '" . intval($_SESSION['sendto']) . "'"; $shipping_address = $dbconn->GetRow($sql); $address_booktable = $oostable['address_book']; $zonestable = $oostable['zones']; $countriestable = $oostable['countries']; $sql = "SELECT ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address,\n ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name,\n ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2,\n c.countries_iso_code_3, c.countries_moneybookers, c.address_format_id, ab.entry_state\n FROM {$address_booktable} ab LEFT JOIN\n {$zonestable} z\n ON (ab.entry_zone_id = z.zone_id) LEFT JOIN\n {$countriestable} c ON\n (ab.entry_country_id = c.countries_id)\n WHERE ab.customers_id = '" . intval($_SESSION['customer_id']) . "' AND\n ab.address_book_id = '" . intval($_SESSION['billto']) . "'"; $billing_address = $dbconn->GetRow($sql); $class =& $_SESSION['payment']; $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'campaigns' => $_SESSION['campaigns_id'], 'currency' => $_SESSION['currency'], 'currency_value' => $oCurrencies->currencies[$_SESSION['currency']]['value'], 'payment_method' => $GLOBALS[$class]->title, 'cc_type' => isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : '', 'cc_owner' => isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : '', 'cc_number' => isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : '', 'cc_expires' => isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : '', 'cc_cvv' => isset($GLOBALS['cc_cvv']) ? $GLOBALS['cc_cvv'] : '', 'shipping_method' => $_SESSION['shipping']['title'], 'shipping_cost' => $_SESSION['shipping']['cost'], 'comments' => isset($_SESSION['comments']) ? $_SESSION['comments'] : '', 'shipping_class' => strpos($shipping['id'], '_') > 0 ? substr(strrev(strchr(strrev($shipping['id']), '_')), 0, -1) : $shipping['id'], 'payment_class' => $_SESSION['payment']); if (isset($GLOBALS['payment']) && is_object($GLOBALS['payment'])) { $this->info['payment_method'] = $GLOBALS['payment']->title; if (isset($GLOBALS['payment']->order_status) && is_numeric($GLOBALS['payment']->order_status) && $GLOBALS['payment']->order_status > 0) { $this->info['order_status'] = $GLOBALS['payment']->order_status; } } $this->customer = array('firstname' => $customer_address['customers_firstname'], 'lastname' => $customer_address['customers_lastname'], 'company' => $customer_address['entry_company'], 'street_address' => $customer_address['entry_street_address'], 'suburb' => $customer_address['entry_suburb'], 'city' => $customer_address['entry_city'], 'postcode' => $customer_address['entry_postcode'], 'state' => oos_is_not_null($customer_address['entry_state']) ? $customer_address['entry_state'] : $customer_address['zone_name'], 'zone_id' => $customer_address['entry_zone_id'], 'country' => array('id' => $customer_address['countries_id'], 'title' => $customer_address['countries_name'], 'iso_code_2' => $customer_address['countries_iso_code_2'], 'iso_code_3' => $customer_address['countries_iso_code_3']), 'format_id' => $customer_address['address_format_id'], 'telephone' => $customer_address['customers_telephone'], 'email_address' => $customer_address['customers_email_address']); $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'lastname' => $shipping_address['entry_lastname'], 'company' => $shipping_address['entry_company'], 'street_address' => $shipping_address['entry_street_address'], 'suburb' => $shipping_address['entry_suburb'], 'city' => $shipping_address['entry_city'], 'postcode' => $shipping_address['entry_postcode'], 'state' => oos_is_not_null($shipping_address['entry_state']) ? $shipping_address['entry_state'] : $shipping_address['zone_name'], 'zone_id' => $shipping_address['entry_zone_id'], 'country' => array('id' => $shipping_address['countries_id'], 'title' => $shipping_address['countries_name'], 'iso_code_2' => $shipping_address['countries_iso_code_2'], 'iso_code_3' => $shipping_address['countries_iso_code_3']), 'country_id' => $shipping_address['entry_country_id'], 'format_id' => $shipping_address['address_format_id']); $this->billing = array('firstname' => $billing_address['entry_firstname'], 'lastname' => $billing_address['entry_lastname'], 'company' => $billing_address['entry_company'], 'street_address' => $billing_address['entry_street_address'], 'suburb' => $billing_address['entry_suburb'], 'city' => $billing_address['entry_city'], 'postcode' => $billing_address['entry_postcode'], 'state' => oos_is_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'country' => array('id' => $billing_address['countries_id'], 'title' => $billing_address['countries_name'], 'iso_code_2' => $billing_address['countries_iso_code_2'], 'iso_code_3' => $billing_address['countries_iso_code_3'], 'moneybookers' => $billing_address['countries_moneybookers']), 'country_id' => $billing_address['entry_country_id'], 'format_id' => $billing_address['address_format_id']); $index = 0; $products = $_SESSION['cart']->get_products(); for ($i = 0, $n = sizeof($products); $i < $n; $i++) { $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'ean' => $products[$i]['ean'], 'tax' => oos_get_tax_rate($products[$i]['tax_class_id'], $billing_address['entry_country_id'], ${$billing_address}['entry_zone_id']), 'tax_description' => oos_get_tax_description($products[$i]['tax_class_id'], $billing_address['entry_country_id'], $billing_address['entry_zone_id']), 'price' => $products[$i]['price'], 'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']), 'weight' => $products[$i]['weight'], 'towlid' => $products[$i]['towlid'], 'id' => $products[$i]['id']); if ($products[$i]['attributes']) { $subindex = 0; foreach ($products[$i]['attributes'] as $option => $value) { $products_optionstable = $oostable['products_options']; $products_options_valuestable = $oostable['products_options_values']; $products_attributestable = $oostable['products_attributes']; if ($value == PRODUCTS_OPTIONS_VALUE_TEXT_ID) { $sql = "SELECT popt.products_options_name, poval.products_options_values_name,\n pa.options_values_price, pa.price_prefix\n FROM {$products_optionstable} popt,\n {$products_options_valuestable} poval,\n {$products_attributestable} pa\n WHERE\n pa.products_id = '" . oos_db_input($products[$i]['id']) . "' AND\n pa.options_id = '" . oos_db_input($option) . "' AND\n pa.options_id = popt.products_options_id AND\n popt.products_options_languages_id = '" . intval($nLanguageID) . "'"; } else { $sql = "SELECT popt.products_options_name, poval.products_options_values_name,\n pa.options_values_price, pa.price_prefix\n FROM {$products_optionstable} popt,\n {$products_options_valuestable} poval,\n {$products_attributestable} pa\n WHERE pa.products_id = '" . oos_db_input($products[$i]['id']) . "' AND\n pa.options_id = '" . oos_db_input($option) . "' AND\n pa.options_id = popt.products_options_id AND\n pa.options_values_id = '" . oos_db_input($value) . "' AND\n pa.options_values_id = poval.products_options_values_id AND\n popt.products_options_languages_id = '" . intval($nLanguageID) . "' AND\n poval.products_options_values_languages_id = '" . intval($nLanguageID) . "'"; } $attributes = $dbconn->GetRow($sql); if ($value == PRODUCTS_OPTIONS_VALUE_TEXT_ID) { $attr_value = $products[$i]['attributes_values'][$option]; } else { $attr_value = $attributes['products_options_values_name']; } $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options_name'], 'value' => $attr_value, 'option_id' => $option, 'value_id' => $value, 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price']); $subindex++; } } $shown_price = oos_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']; $this->info['subtotal'] += $shown_price; $products_tax = $this->products[$index]['tax']; if ($_SESSION['member']->group['show_price_tax'] == 1) { $this->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)); $this->info['tax_groups']["{$products_tax}"] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)); } else { $this->info['tax'] += $products_tax / 100 * $shown_price; $this->info['tax_groups']["{$products_tax}"] += $products_tax / 100 * $shown_price; } $index++; } if ($_SESSION['member']->group['show_price_tax'] == 1) { $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost']; } else { $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost']; } }
function calculate_tax_deduction($amount, $od_amount, $method) { global $oOrder; switch ($method) { case 'Standard': $ratio1 = round($od_amount / $amount, 2); $tod_amount = 0; foreach ($oOrder->info['tax_groups'] as $key => $value) { $tax_rate = oos_get_tax_rate_from_desc($key); $total_net += $tax_rate * $oOrder->info['tax_groups'][$key]; } if ($od_amount > $total_net) { $od_amount = $total_net; } foreach ($oOrder->info['tax_groups'] as $key => $value) { $tax_rate = oos_get_tax_rate_from_desc($key); $net = $tax_rate * $oOrder->info['tax_groups'][$key]; if ($net > 0) { $god_amount = $oOrder->info['tax_groups'][$key] * $ratio1; $tod_amount += $god_amount; $oOrder->info['tax_groups'][$key] = $oOrder->info['tax_groups'][$key] - $god_amount; } } $oOrder->info['tax'] -= $tod_amount; $oOrder->info['total'] -= $tod_amount; break; case 'Credit Note': $tax_rate = oos_get_tax_rate($this->tax_class, $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); $tax_desc = oos_get_tax_description($this->tax_class, $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate; $oOrder->info['tax_groups'][$tax_desc] -= $tod_amount; // $oOrder->info['total'] -= $tod_amount; break; default: } return $tod_amount; }
function calculate_tax_deduction($amount, $od_amount, $method) { global $oOrder, $cc_id; // Get database information $dbconn =& oosDBGetConn(); $oostable =& oosDBGetTables(); $cc_id = intval($_SESSION['cc_id']); $couponstable = $oostable['coupons']; $coupon_query = $dbconn->Execute("SELECT coupon_code FROM {$couponstable} WHERE coupon_id = '" . intval($cc_id) . "'"); if ($coupon_query->RecordCount() != 0) { $coupon_result = $coupon_query->fields; $coupon_get = $dbconn->Execute("SELECT coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type FROM " . $oostable['coupons'] . " WHERE coupon_code = '" . $coupon_result['coupon_code'] . "'"); $get_result = $coupon_get->fields; if ($get_result['coupon_type'] != 'S') { 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 = $_SESSION['cart']->get_products(); $nArrayCountProducts = count($products); for ($i = 0; $i < $nArrayCountProducts; $i++) { $t_prid = oos_get_product_id($products[$i]['id']); $productstable = $oostable['products']; $cc_query = $dbconn->Execute("SELECT products_tax_class_id FROM {$productstable} WHERE products_id = '" . (int) $t_prid . "'"); $cc_result = $cc_query->fields; $valid_product = false; if ($get_result['restrict_to_products']) { $pr_ids = split("[,]", $get_result['restrict_to_products']); $nArrayCountProductsIds = count($pr_ids); for ($p = 0; $p < $nArrayCountProductsIds; $p++) { if ($pr_ids[$p] == $t_prid) { $valid_product = true; } } } if ($get_result['restrict_to_categories']) { $cat_ids = split("[,]", $get_result['restrict_to_categories']); for ($c = 0; $c < count($cat_ids); $c++) { $products_to_categoriestable = $oostable['products_to_categories']; $cat_query = $dbconn->Execute("SELECT products_id FROM {$products_to_categoriestable} WHERE products_id = '" . (int) $products_id . "' AND categories_id = '" . (int) $cat_ids[$i] . "'"); if ($cat_query->RecordCount() != 0) { $valid_product = true; } } } if ($valid_product) { $valid_array[] = array('product_id' => $t_prid, 'products_price' => $products[$i]['final_price'] * $products[$i]['quantity'], 'products_tax_class' => $cc_result['products_tax_class_id']); $total_price += $products[$i]['final_price'] * $products[$i]['quantity']; } } if ($valid_product) { 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 = oos_get_tax_rate($this->tax_class, $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); $tax_desc = oos_get_tax_description($this->tax_class, $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); if ($get_result['coupon_type'] == 'P') { $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate; } else { $tod_amount = $oOrder->info['tax_groups'][$tax_desc] * $od_amount / 100; } $oOrder->info['tax_groups'][$tax_desc] -= $tod_amount; $oOrder->info['total'] -= $tod_amount; } else { $nArrayCountValid = count($valid_array); for ($p = 0; $p < $nArrayCountValid; $p++) { $tax_rate = oos_get_tax_rate($valid_array[$p]['products_tax_class'], $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); $tax_desc = oos_get_tax_description($valid_array[$p]['products_tax_class'], $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); if ($tax_rate > 0) { $tod_amount[$tax_desc] += $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $oOrder->info['tax_groups'][$tax_desc] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; $oOrder->info['total'] -= $valid_array[$p]['products_price'] * $tax_rate / 100 * $ratio; } } } } } else { if ($get_result['coupon_type'] == 'F') { $tod_amount = 0; if ($method == 'Credit Note') { $tax_rate = oos_get_tax_rate($this->tax_class, $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); $tax_desc = oos_get_tax_description($this->tax_class, $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); $tod_amount = $od_amount / (100 + $tax_rate) * $tax_rate; $oOrder->info['tax_groups'][$tax_desc] -= $tod_amount; } else { $ratio1 = $od_amount / $amount; foreach ($oOrder->info['tax_groups'] as $key => $value) { $tax_rate = oos_get_tax_rate_from_desc($key); $net = $tax_rate * $oOrder->info['tax_groups'][$key]; if ($net > 0) { $god_amount = $oOrder->info['tax_groups'][$key] * $ratio1; $tod_amount += $god_amount; $oOrder->info['tax_groups'][$key] = $oOrder->info['tax_groups'][$key] - $god_amount; } } } $oOrder->info['total'] -= $tod_amount; } if ($get_result['coupon_type'] == 'P') { $tod_amount = 0; if ($method == 'Credit Note') { $tax_desc = oos_get_tax_description($this->tax_class, $oOrder->delivery['country']['id'], $oOrder->delivery['zone_id']); $tod_amount = $oOrder->info['tax_groups'][$tax_desc] * $od_amount / 100; $oOrder->info['tax_groups'][$tax_desc] -= $tod_amount; } else { foreach ($oOrder->info['tax_groups'] as $key => $value) { $god_amout = 0; $tax_rate = oos_get_tax_rate_from_desc($key); $net = $tax_rate * $oOrder->info['tax_groups'][$key]; if ($net > 0) { $god_amount = $oOrder->info['tax_groups'][$key] * $get_result['coupon_amount'] / 100; $tod_amount += $god_amount; $oOrder->info['tax_groups'][$key] = $oOrder->info['tax_groups'][$key] - $god_amount; } } } $oOrder->info['tax'] -= $tod_amount; } } } } return $tod_amount; }