Exemple #1
0
 function query($order_id)
 {
     global $shipping;
     $order_query = vam_db_query("select * from " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'");
     $order = vam_db_fetch_array($order_query);
     $totals_query = vam_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int) $order_id . "' order by sort_order");
     while ($totals = vam_db_fetch_array($totals_query)) {
         $this->totals[] = array('title' => $totals['title'], 'text' => $totals['text'], 'class' => $totals['class'], 'value' => $totals['value'], 'sort_order' => $totals['sort_order'], 'orders_total_id' => $totals['orders_total_id']);
     }
     $this->info = array('currency' => $order['currency'], 'currency_value' => $order['currency_value'], 'payment_method' => $order['payment_method'], 'payment_class' => $order['payment_class'], 'shipping_class' => $order['shipping_class'], 'status' => $order['customers_status'], 'status_name' => $order['customers_status_name'], 'status_image' => $order['customers_status_image'], 'status_discount' => $order['customers_status_discount'], 'cc_type' => $order['cc_type'], 'cc_owner' => $order['cc_owner'], 'cc_number' => $order['cc_number'], 'cc_expires' => $order['cc_expires'], 'cc_cvv' => $order['cc_cvv'], 'comments' => $order['comments'], 'language' => $order['language'], 'date_purchased' => $order['date_purchased'], 'orders_status' => $order['orders_status'], 'last_modified' => $order['last_modified'], 'shipping_method' => $shipping['title'], 'shipping_cost' => $shipping['cost'], 'shipping_id' => $order['shipping_module'], 'subtotal' => 0, 'tax' => 0, 'tax_groups' => array());
     $this->customer = array('name' => $order['customers_name'], 'company' => $order['customers_company'], 'csID' => $order['customers_cid'], 'vat_id' => $order['customers_vat_id'], 'shop_id' => $order['shop_id'], 'ID' => $order['customers_id'], 'cIP' => $order['customers_ip'], 'street_address' => $order['customers_street_address'], 'suburb' => $order['customers_suburb'], 'city' => $order['customers_city'], 'postcode' => $order['customers_postcode'], 'state' => $order['customers_state'], 'country' => $order['customers_country'], 'country_id' => oe_get_country_id($order['customers_country']), 'zone_id' => oe_get_zone_id(oe_get_country_id($order['customers_country']), $order['customers_state']), 'format_id' => $order['customers_address_format_id'], 'telephone' => $order['customers_telephone'], 'email_address' => $order['customers_email_address'], 'orig_reference' => $order['orig_reference'], 'login_reference' => $order['login_reference']);
     $this->delivery = array('name' => $order['delivery_name'], 'company' => $order['delivery_company'], 'street_address' => $order['delivery_street_address'], 'suburb' => $order['delivery_suburb'], 'city' => $order['delivery_city'], 'postcode' => $order['delivery_postcode'], 'state' => $order['delivery_state'], 'country' => $order['delivery_country'], 'country_id' => oe_get_country_id($order['delivery_country']), 'zone_id' => oe_get_zone_id(oe_get_country_id($order['delivery_country']), $order['delivery_state']), 'format_id' => $order['delivery_address_format_id']);
     $this->billing = array('name' => $order['billing_name'], 'company' => $order['billing_company'], 'street_address' => $order['billing_street_address'], 'suburb' => $order['billing_suburb'], 'city' => $order['billing_city'], 'postcode' => $order['billing_postcode'], 'state' => $order['billing_state'], 'country' => $order['billing_country'], 'country_id' => oe_get_country_id($order['billing_country']), 'zone_id' => oe_get_zone_id(oe_get_country_id($order['billing_country']), $order['billing_state']), 'format_id' => $order['billing_address_format_id']);
     $index = 0;
     $orders_products_query = vam_db_query("select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int) $order_id . "' order by orders_products_id");
     while ($orders_products = vam_db_fetch_array($orders_products_query)) {
         $orders_products_tax_query = vam_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = " . $orders_products['products_id'] . "");
         $orders_products_tax = vam_db_fetch_array($orders_products_tax_query);
         $this->products[$index] = array('qty' => $orders_products['products_quantity'], 'name' => $orders_products['products_name'], 'model' => $orders_products['products_model'], 'tax' => $orders_products['products_tax'], 'tax_description' => vam_get_tax_description($orders_products_tax['products_tax_class_id'], $this->delivery["country_id"], $this->delivery["zone_id"]), 'price' => $orders_products['products_price'], 'final_price' => $orders_products['products_price'] * $orders_products['products_quantity'], 'products_id' => $orders_products['products_id'], 'orders_products_id' => $orders_products['orders_products_id']);
         $subindex = 0;
         $attributes_query = vam_db_query("select products_options, products_options_values, options_values_price, price_prefix, orders_products_attributes_id from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int) $order_id . "' and orders_products_id = '" . (int) $orders_products['orders_products_id'] . "'");
         if (vam_db_num_rows($attributes_query)) {
             while ($attributes = vam_db_fetch_array($attributes_query)) {
                 $this->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price'], 'orders_products_attributes_id' => $attributes['orders_products_attributes_id']);
                 $subindex++;
             }
         }
         $shown_price = vam_add_tax($this->products[$index]['price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];
         $this->info['subtotal'] += $shown_price;
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if (DISPLAY_PRICE_WITH_TAX == 'true') {
             $this->info['tax'] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $shown_price - $shown_price / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $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;
             if (isset($this->info['tax_groups']["{$products_tax_description}"])) {
                 $this->info['tax_groups']["{$products_tax_description}"] += $products_tax / 100 * $shown_price;
             } else {
                 $this->info['tax_groups']["{$products_tax_description}"] = $products_tax / 100 * $shown_price;
             }
         }
         $index++;
     }
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         $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 process()
 {
     global $order, $vamPrice;
     if (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] >= $vamPrice->Format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER, false, 0, true)) {
             $order->info['shipping_method'] = $this->title;
             $order->info['total'] -= $order->info['shipping_cost'];
             $order->info['shipping_cost'] = 0;
         }
     }
     $module = substr($_SESSION['shipping']['id'], 0, strpos($_SESSION['shipping']['id'], '_'));
     if (vam_not_null($order->info['shipping_method'])) {
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
             // price with tax
             $shipping_tax = vam_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $shipping_tax_description = vam_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax = $vamPrice->Format(vam_add_tax($order->info['shipping_cost'], $shipping_tax), false, 0, false) - $order->info['shipping_cost'];
             $tax = $vamPrice->Format($tax, false, 0, true);
             $order->info['shipping_cost'] = vam_add_tax($order->info['shipping_cost'], $shipping_tax);
             $order->info['tax'] += $tax;
             $order->info['tax_groups'][TAX_ADD_TAX . "{$shipping_tax_description}"] += $tax;
             $order->info['total'] += $tax;
         } else {
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $shipping_tax = vam_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                 $shipping_tax_description = vam_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                 $tax = $vamPrice->Format(vam_add_tax($order->info['shipping_cost'], $shipping_tax), false, 0, false) - $order->info['shipping_cost'];
                 $tax = $vamPrice->Format($tax, false, 0, true);
                 $order->info['tax'] = $order->info['tax'] += $tax;
                 $order->info['tax_groups'][TAX_NO_TAX . "{$shipping_tax_description}"] = $order->info['tax_groups'][TAX_NO_TAX . "{$shipping_tax_description}"] += $tax;
             }
         }
         $this->output[] = array('title' => $order->info['shipping_method'] . ':', 'text' => $vamPrice->Format($order->info['shipping_cost'], true, 0, true), 'value' => $vamPrice->Format($order->info['shipping_cost'], false, 0, true));
     }
 }
 function process()
 {
     global $order, $vamPrice;
     //include needed functions
     require_once DIR_FS_INC . 'vam_calculate_tax.inc.php';
     if (MODULE_ORDER_TOTAL_LOWORDERFEE_LOW_ORDER_FEE == 'true') {
         switch (MODULE_ORDER_TOTAL_LOWORDERFEE_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
             default:
                 $pass = false;
                 break;
         }
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) {
             $tax = vam_get_tax_rate(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_description = vam_get_tax_description(MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
                 $order->info['tax'] += vam_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['tax_groups'][TAX_ADD_TAX . "{$tax_description}"] += vam_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['total'] += MODULE_ORDER_TOTAL_LOWORDERFEE_FEE + vam_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $low_order_fee = vam_add_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $low_order_fee = MODULE_ORDER_TOTAL_LOWORDERFEE_FEE;
                 $order->info['tax'] += vam_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['tax_groups'][TAX_NO_TAX . "{$tax_description}"] += vam_calculate_tax(MODULE_ORDER_TOTAL_LOWORDERFEE_FEE, $tax);
                 $order->info['subtotal'] += $low_order_fee;
                 $order->info['total'] += $low_order_fee;
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] != 1) {
                 $low_order_fee = MODULE_ORDER_TOTAL_LOWORDERFEE_FEE;
                 $order->info['subtotal'] += $low_order_fee;
                 $order->info['total'] += $low_order_fee;
             }
             $this->output[] = array('title' => $this->title . ':', 'text' => $vamPrice->Format($low_order_fee, true), 'value' => $low_order_fee);
         }
     }
 }
Exemple #4
0
 function selection()
 {
     global $vamPrice, $order;
     if (MODULE_ORDER_TOTAL_COD_FEE_STATUS == 'true') {
         $cod_country = false;
         //process installed shipping modules
         if ($_SESSION['shipping']['id'] == 'flat_flat') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FLAT);
         }
         if ($_SESSION['shipping']['id'] == 'item_item') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ITEM);
         }
         if ($_SESSION['shipping']['id'] == 'table_table') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_TABLE);
         }
         if ($_SESSION['shipping']['id'] == 'zones_zones') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ZONES);
         }
         if ($_SESSION['shipping']['id'] == 'ap_ap') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_AP);
         }
         if ($_SESSION['shipping']['id'] == 'dp_dp') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DP);
         }
         if ($_SESSION['shipping']['id'] == 'chp_ECO') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
         }
         if ($_SESSION['shipping']['id'] == 'chp_PRI') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
         }
         if ($_SESSION['shipping']['id'] == 'chp_URG') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
         }
         if ($_SESSION['shipping']['id'] == 'chronopost_chronopost') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHRONOPOST);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_ECX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_DOX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_SDX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_MDX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'dhl_WPX') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
         }
         if ($_SESSION['shipping']['id'] == 'ups_ups') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPS);
         }
         if ($_SESSION['shipping']['id'] == 'upse_upse') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPSE);
         }
         if ($_SESSION['shipping']['id'] == 'free_free') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREE);
         }
         if ($_SESSION['shipping']['id'] == 'freeamount_freeamount') {
             $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_FREEAMOUNT_FREE);
         }
         for ($i = 0; $i < count($cod_zones); $i++) {
             if ($cod_zones[$i] == $order->delivery['country']['iso_code_2']) {
                 $cod_cost = $cod_zones[$i + 1];
                 $cod_country = true;
                 break;
             } elseif ($cod_zones[$i] == '00') {
                 $cod_cost = $cod_zones[$i + 1];
                 $cod_country = true;
                 break;
             } else {
             }
             $i++;
         }
     } else {
         //COD selected, but no shipping module which offers COD
     }
     if ($cod_country) {
         $cod_tax = vam_get_tax_rate(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
         $cod_tax_description = vam_get_tax_description(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
             $cod_cost_value = vam_add_tax($cod_cost, $cod_tax);
             $cod_cost = $vamPrice->Format($cod_cost_value, true);
         }
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
             $cod_cost_value = $cod_cost;
             $cod_cost = $vamPrice->Format($cod_cost, true);
         }
         if (!$cod_cost_value) {
             $cod_cost_value = $cod_cost;
             $cod_cost = $vamPrice->Format($cod_cost, true);
         }
         $this->cost = '+ ' . $cod_cost;
     }
     return array('id' => $this->code, 'module' => $this->title, 'description' => $this->info, 'module_cost' => $this->cost);
 }
 function calculate()
 {
     global $vamPrice;
     $this->total = 0;
     $this->qty = 0;
     $this->weight = 0;
     $this->tax = array();
     if (!is_array($this->contents)) {
         return 0;
     }
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
         $qty = $this->contents[$products_id]['qty'];
         // products price
         $product_query = vam_db_query("select products_id, products_price, products_discount_allowed, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . vam_get_prid($products_id) . "'");
         if ($product = vam_db_fetch_array($product_query)) {
             $products_price = $vamPrice->GetPrice($product['products_id'], $format = false, $qty, $product['products_tax_class_id'], $product['products_price']);
             $this->total += $products_price * $qty;
             $this->qty += $qty;
             $this->weight += $qty * $product['products_weight'];
             // attributes price
             $attribute_price = 0;
             if (isset($this->contents[$products_id]['attributes'])) {
                 reset($this->contents[$products_id]['attributes']);
                 while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
                     $values = $vamPrice->GetOptionPrice($product['products_id'], $option, $value);
                     $this->weight += $values['weight'] * $qty;
                     $this->total += $values['price'] * $qty;
                     $this->qty += $qty;
                     $attribute_price += $values['price'];
                 }
             }
             if ($product['products_tax_class_id'] != 0) {
                 if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                     $products_price_tax = $products_price - $products_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
                     $attribute_price_tax = $attribute_price - $attribute_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
                 }
                 $products_tax = $vamPrice->TAX[$product['products_tax_class_id']];
                 $products_tax_description = vam_get_tax_description($product['products_tax_class_id']);
                 // price incl tax
                 if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '1') {
                     if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price_tax + $attribute_price_tax) / (100 + $products_tax) * $products_tax * $qty;
                         $this->tax[$product['products_tax_class_id']]['desc'] = TAX_ADD_TAX . "{$products_tax_description}";
                     } else {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price + $attribute_price) / (100 + $products_tax) * $products_tax * $qty;
                         $this->tax[$product['products_tax_class_id']]['desc'] = TAX_ADD_TAX . "{$products_tax_description}";
                     }
                 }
                 // excl tax + tax at checkout
                 if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                     if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price_tax + $attribute_price_tax) / 100 * $products_tax * $qty;
                         $this->total += ($products_price_tax + $attribute_price_tax) / 100 * $products_tax * $qty;
                         $this->tax[$product['products_tax_class_id']]['desc'] = TAX_NO_TAX . "{$products_tax_description}";
                     } else {
                         $this->tax[$product['products_tax_class_id']]['value'] += ($products_price + $attribute_price) / 100 * $products_tax * $qty;
                         $this->total += ($products_price + $attribute_price) / 100 * $products_tax * $qty;
                         $this->tax[$product['products_tax_class_id']]['desc'] = TAX_NO_TAX . "{$products_tax_description}";
                     }
                 }
             }
         }
     }
     //		echo 'total_VOR'.$this->total;
     if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] != 0) {
         //			$this->total -= $this->total / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
     }
     //		echo 'total_NACH'.$this->total;
 }
 function process()
 {
     global $order, $vamPrice, $ps_cost, $ps_country, $shipping;
     $customer_id = $_SESSION['customer_id'];
     if (MODULE_ORDER_TOTAL_PS_FEE_STATUS == 'true') {
         //Will become true, if ps can be processed.
         $ps_country = false;
         //check if payment method is ps. If yes, check if ps is possible.
         $count_query = vam_db_query("select count(*) as count from " . TABLE_CUSTOMERS_BASKET . " cb, " . TABLE_PRODUCTS . " p  where cb.customers_id = '" . $customer_id . "' and cb.products_id = p.products_id and p.products_fsk18 = '1'");
         $num = vam_db_fetch_array($count_query);
         $age = $num['count'];
         if ($age > '0') {
             //process installed shipping modules
             if ($_SESSION['shipping']['id'] == 'flat_flat') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_FLAT);
             }
             if ($_SESSION['shipping']['id'] == 'item_item') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_ITEM);
             }
             if ($_SESSION['shipping']['id'] == 'table_table') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_TABLE);
             }
             if ($_SESSION['shipping']['id'] == 'zones_zones') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_ZONES);
             }
             if ($_SESSION['shipping']['id'] == 'ap_ap') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_AP);
             }
             if ($_SESSION['shipping']['id'] == 'dp_dp') {
                 $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_DP);
             }
             for ($i = 0; $i < count($ps_zones); $i++) {
                 if ($ps_zones[$i] == $order->billing['country']['iso_code_2']) {
                     $ps_cost = $ps_zones[$i + 1];
                     $ps_country = true;
                     //print('match' . $ps_zones[$i] . ': ' . $ps_cost);
                     break;
                 } elseif ($ps_zones[$i] == '00') {
                     $ps_cost = $ps_zones[$i + 1];
                     $ps_country = true;
                     //print('match' . $i . ': ' . $ps_cost);
                     break;
                 } else {
                     //print('no match');
                 }
                 $i++;
             }
         } else {
             //PS selected, but no shipping module which offers PS
         }
         if ($ps_country) {
             $ps_tax = vam_get_tax_rate(MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $ps_tax_description = vam_get_tax_description(MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
                 $order->info['tax'] += vam_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $order->info['tax_groups'][TAX_ADD_TAX . "{$ps_tax_description}"] += vam_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $order->info['total'] += $ps_cost + (vam_add_tax($ps_cost, $ps_tax) - $ps_cost);
                 $ps_cost_value = vam_add_tax($ps_cost, $ps_tax);
                 $ps_cost = $vamPrice->Format($ps_cost_value, true);
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $order->info['tax'] += vam_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $order->info['tax_groups'][TAX_NO_TAX . "{$ps_tax_description}"] += vam_add_tax($ps_cost, $ps_tax) - $ps_cost;
                 $ps_cost_value = $ps_cost;
                 $ps_cost = $vamPrice->Format($ps_cost, true);
                 $order->info['subtotal'] += $ps_cost_value;
                 $order->info['total'] += $ps_cost_value;
             }
             if (!$ps_cost_value) {
                 $ps_cost_value = $ps_cost;
                 $ps_cost = $vamPrice->Format($ps_cost, true);
                 $order->info['total'] += $ps_cost_value;
             }
             $this->output[] = array('title' => $this->title . ':', 'text' => $ps_cost, 'value' => $ps_cost_value);
         } else {
             //Following pse should be improved if we can't get the shipping modules disabled, who don't allow PS
             // as well as countries who do not have ps
             //          $this->output[] = array('title' => $this->title . ':',
             //                                  'text' => 'No PS for this module.',
             //                                  'value' => '');
         }
     }
 }
Exemple #7
0
 function cart()
 {
     global $currencies, $vamPrice;
     $this->content_type = $_SESSION['cart']->get_content_type();
     $customer_address_query = vam_db_query("select c.payment_unallowed,c.customers_id,c.shipping_unallowed,c.customers_firstname,c.customers_secondname,c.customers_cid, c.customers_gender,c.customers_lastname, c.customers_telephone, c.customers_email_address, c.orig_reference, c.login_reference, c.customers_personal_discount, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from " . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id) where c.customers_id = '" . $_SESSION['customer_id'] . "' and ab.customers_id = '" . $_SESSION['customer_id'] . "' and c.customers_default_address_id = ab.address_book_id");
     $customer_address = vam_db_fetch_array($customer_address_query);
     $shipping_address_query = vam_db_query("select ab.entry_firstname, ab.entry_secondname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . $_SESSION['customer_id'] . "' and ab.address_book_id = '" . $_SESSION['sendto'] . "'");
     $shipping_address = vam_db_fetch_array($shipping_address_query);
     $billing_address_query = vam_db_query("select ab.entry_firstname, ab.entry_secondname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) where ab.customers_id = '" . $_SESSION['customer_id'] . "' and ab.address_book_id = '" . $_SESSION['billto'] . "'");
     $billing_address = vam_db_fetch_array($billing_address_query);
     $tax_address_query = vam_db_query("select ab.entry_country_id, ab.entry_zone_id from " . TABLE_ADDRESS_BOOK . " ab left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = '" . $_SESSION['customer_id'] . "' and ab.address_book_id = '" . ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'");
     $tax_address = vam_db_fetch_array($tax_address_query);
     $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, 'currency' => $_SESSION['currency'], 'currency_value' => $vamPrice->currencies[$_SESSION['currency']]['value'], 'payment_method' => $_SESSION['payment'], 'cc_type' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_type']) ? $_SESSION['ccard']['cc_type'] : '', 'cc_owner' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_owner']) ? $_SESSION['ccard']['cc_owner'] : '', 'cc_number' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_number']) ? $_SESSION['ccard']['cc_number'] : '', 'cc_expires' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_expires']) ? $_SESSION['ccard']['cc_expires'] : '', 'cc_start' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_start']) ? $_SESSION['ccard']['cc_start'] : '', 'cc_issue' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_issue']) ? $_SESSION['ccard']['cc_issue'] : '', 'cc_cvv' => isset($_SESSION['payment']) == 'cc' && isset($_SESSION['ccard']['cc_cvv']) ? $_SESSION['ccard']['cc_cvv'] : '', 'shipping_method' => $_SESSION['shipping']['title'], 'shipping_cost' => $_SESSION['shipping']['cost'], 'comments' => $_SESSION['comments'], 'shipping_class' => $_SESSION['shipping']['id'], 'payment_class' => $_SESSION['payment']);
     if (isset($_SESSION['payment']) && is_object($_SESSION['payment'])) {
         $this->info['payment_method'] = $_SESSION['payment']->title;
         $this->info['payment_class'] = $_SESSION['payment']->title;
         if (isset($_SESSION['payment']->order_status) && is_numeric($_SESSION['payment']->order_status) && $_SESSION['payment']->order_status > 0) {
             $this->info['order_status'] = $_SESSION['payment']->order_status;
         }
     }
     $this->customer = array('id' => $customer_address['customers_id'], 'firstname' => $customer_address['customers_firstname'], 'secondname' => $customer_address['customers_secondname'], 'lastname' => $customer_address['customers_lastname'], 'csID' => $customer_address['customers_cid'], 'gender' => $customer_address['customers_gender'], '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' => vam_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'], 'payment_unallowed' => $customer_address['payment_unallowed'], 'shipping_unallowed' => $customer_address['shipping_unallowed'], 'email_address' => $customer_address['customers_email_address'], 'personal_discount' => $customer_address['customers_personal_discount'], 'orig_reference' => $customer_address['orig_reference'], 'login_reference' => $customer_address['login_reference']);
     //*******
     $this->delivery = array('firstname' => $shipping_address['entry_firstname'], 'secondname' => $shipping_address['entry_secondname'], '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' => vam_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'], 'secondname' => $billing_address['entry_secondname'], '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' => vam_not_null($billing_address['entry_state']) ? $billing_address['entry_state'] : $billing_address['zone_name'], 'zone_id' => $billing_address['entry_zone_id'], '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']), '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++) {
         $products_price = $vamPrice->GetPrice($products[$i]['id'], $format = false, $products[$i]['quantity'], $products[$i]['tax_class_id'], '') + $vamPrice->Format($_SESSION['cart']->attributes_price($products[$i]['id']), false);
         $this->products[$index] = array('qty' => $products[$i]['quantity'], 'name' => $products[$i]['name'], 'model' => $products[$i]['model'], 'tax_class_id' => $products[$i]['tax_class_id'], 'tax' => vam_get_tax_rate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'tax_description' => vam_get_tax_description($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']), 'price' => $products_price, 'final_price' => $products_price * $products[$i]['quantity'], 'shipping_time' => $products[$i]['shipping_time'], 'weight' => $products[$i]['weight'], 'id' => $products[$i]['id'], 'image' => $products[$i]['image']);
         if ($products[$i]['attributes']) {
             $subindex = 0;
             reset($products[$i]['attributes']);
             while (list($option, $value) = each($products[$i]['attributes'])) {
                 $attributes_query = vam_db_query("select popt.products_options_name, popt.products_options_type, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $products[$i]['id'] . "' and pa.options_id = '" . $option . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $value . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'");
                 $attributes = vam_db_fetch_array($attributes_query);
                 if ($attributes['products_options_type'] == '2' || $attributes['products_options_type'] == '3') {
                     $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 = $this->products[$index]['final_price'];
         $this->info['subtotal'] += $shown_price;
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
             $shown_price_tax = $shown_price - $shown_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
         }
         $products_tax = $this->products[$index]['tax'];
         $products_tax_description = $this->products[$index]['tax_description'];
         if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '1') {
             if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                 $this->info['tax'] += $shown_price_tax - $shown_price_tax / ($products_tax < 10 ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax));
                 $this->info['tax_groups'][TAX_ADD_TAX . "{$products_tax_description}"] += $shown_price_tax / (100 + $products_tax) * $products_tax;
             } else {
                 $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'][TAX_ADD_TAX . "{$products_tax_description}"] += $shown_price / (100 + $products_tax) * $products_tax;
             }
         } else {
             if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1) {
                 $this->info['tax'] += $shown_price_tax / 100 * $products_tax;
                 $this->info['tax_groups'][TAX_NO_TAX . "{$products_tax_description}"] += $shown_price_tax / 100 * $products_tax;
             } else {
                 $this->info['tax'] += $shown_price / 100 * $products_tax;
                 $this->info['tax_groups'][TAX_NO_TAX . "{$products_tax_description}"] += $shown_price / 100 * $products_tax;
             }
         }
         $index++;
     }
     //$this->info['shipping_cost']=0;
     if ($_SESSION['customers_status']['customers_status_show_price_tax'] == '0') {
         $this->info['total'] = $this->info['subtotal'] + $vamPrice->Format($this->info['shipping_cost'], false, 0, true);
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1') {
             $this->info['total'] -= $this->info['subtotal'] / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
         }
     } else {
         $this->info['total'] = $this->info['subtotal'] + $vamPrice->Format($this->info['shipping_cost'], false, 0, true);
         if ($_SESSION['customers_status']['customers_status_ot_discount_flag'] == '1') {
             $this->info['total'] -= $this->info['subtotal'] / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
         }
     }
 }
 function process()
 {
     global $order, $vamPrice, $cod_cost, $cod_country, $shipping;
     if (MODULE_ORDER_TOTAL_COD_FEE_STATUS == 'true') {
         //Will become true, if cod can be processed.
         $cod_country = false;
         //check if payment method is cod. If yes, check if cod is possible.
         if ($_SESSION['payment'] == 'cod') {
             //process installed shipping modules
             if ($_SESSION['shipping']['id'] == 'flat_flat') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FLAT);
             }
             if ($_SESSION['shipping']['id'] == 'item_item') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ITEM);
             }
             if ($_SESSION['shipping']['id'] == 'table_table') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_TABLE);
             }
             if ($_SESSION['shipping']['id'] == 'zones_zones') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ZONES);
             }
             if ($_SESSION['shipping']['id'] == 'ap_ap') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_AP);
             }
             if ($_SESSION['shipping']['id'] == 'dp_dp') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DP);
             }
             // module chp
             if ($_SESSION['shipping']['id'] == 'chp_ECO') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
             }
             if ($_SESSION['shipping']['id'] == 'chp_PRI') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
             }
             if ($_SESSION['shipping']['id'] == 'chp_URG') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
             }
             // module chronopost
             if ($_SESSION['shipping']['id'] == 'chronopost_chronopost') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHRONOPOST);
             }
             // module DHL
             if ($_SESSION['shipping']['id'] == 'dhl_ECX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_DOX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_SDX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_MDX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             if ($_SESSION['shipping']['id'] == 'dhl_WPX') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
             }
             // UPS
             if ($_SESSION['shipping']['id'] == 'ups_ups') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPS);
             }
             if ($_SESSION['shipping']['id'] == 'upse_upse') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPSE);
             }
             // Free Shipping
             if ($_SESSION['shipping']['id'] == 'free_free') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREE);
             }
             if ($_SESSION['shipping']['id'] == 'freeamount_freeamount') {
                 $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_FREEAMOUNT_FREE);
             }
             for ($i = 0; $i < count($cod_zones); $i++) {
                 if ($cod_zones[$i] == $order->delivery['country']['iso_code_2']) {
                     $cod_cost = $cod_zones[$i + 1];
                     $cod_country = true;
                     break;
                 } elseif ($cod_zones[$i] == '00') {
                     $cod_cost = $cod_zones[$i + 1];
                     $cod_country = true;
                     break;
                 } else {
                 }
                 $i++;
             }
         } else {
             //COD selected, but no shipping module which offers COD
         }
         if ($cod_country) {
             $cod_tax = vam_get_tax_rate(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $cod_tax_description = vam_get_tax_description(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
                 $order->info['tax'] += vam_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $order->info['tax_groups'][TAX_ADD_TAX . "{$cod_tax_description}"] += vam_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $order->info['total'] += $cod_cost + (vam_add_tax($cod_cost, $cod_tax) - $cod_cost);
                 $cod_cost_value = vam_add_tax($cod_cost, $cod_tax);
                 $cod_cost = $vamPrice->Format($cod_cost_value, true);
             }
             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
                 $order->info['tax'] += vam_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $order->info['tax_groups'][TAX_NO_TAX . "{$cod_tax_description}"] += vam_add_tax($cod_cost, $cod_tax) - $cod_cost;
                 $cod_cost_value = $cod_cost;
                 $cod_cost = $vamPrice->Format($cod_cost, true);
                 $order->info['subtotal'] += $cod_cost_value;
                 $order->info['total'] += $cod_cost_value;
             }
             if (!$cod_cost_value) {
                 $cod_cost_value = $cod_cost;
                 $cod_cost = $vamPrice->Format($cod_cost, true);
                 $order->info['total'] += $cod_cost_value;
             }
             $this->output[] = array('title' => $this->title . ':', 'text' => $cod_cost, 'value' => $cod_cost_value);
         } else {
             //Following code should be improved if we can't get the shipping modules disabled, who don't allow COD
             // as well as countries who do not have cod
             //          $this->output[] = array('title' => $this->title . ':',
             //                                  'text' => 'No COD for this module.',
             //                                  'value' => '');
         }
     }
 }
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $order;
     $coupon_query = vam_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $_SESSION['cc_id'] . "'");
     if (vam_db_num_rows($coupon_query) != 0) {
         $coupon_result = vam_db_fetch_array($coupon_query);
         $coupon_get = vam_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 = vam_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 = $_SESSION['cart']->get_products();
                 $valid_product = false;
                 for ($i = 0; $i < sizeof($products); $i++) {
                     $valid_product = false;
                     $t_prid = vam_get_prid($products[$i]['id']);
                     $cc_query = vam_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
                     $cc_result = vam_db_fetch_array($cc_query);
                     if ($get_result['restrict_to_products']) {
                         $pr_ids = preg_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']) {
                         // v5.13a Tanaka 2005-4-30:  New code, this correctly identifies valid products in subcategories
                         $cat_ids = preg_split("/[,]/", $get_result['restrict_to_categories']);
                         $my_path = vam_get_product_path($t_prid);
                         $sub_cat_ids = preg_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 ($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 = vam_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tax_desc = vam_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 = vam_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
                             $tax_desc = vam_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 = vam_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                         $tax_desc = vam_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_ADD_TAX . $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 = vam_get_tax_rate_from_desc(str_replace(TAX_ADD_TAX, "", $key));
                             $net = $tax_rate * $order->info['tax_groups'][$key];
                             if ($net > 0) {
                                 $god_amount = $od_amount * $tax_rate / (100 + $tax_rate);
                                 $tod_amount += $god_amount;
                                 $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 = vam_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_ADD_TAX . $tax_desc] -= $tod_amount;
                     } else {
                         reset($order->info['tax_groups']);
                         while (list($key, $value) = each($order->info['tax_groups'])) {
                             $god_amout = 0;
                             $tax_rate = vam_get_tax_rate_from_desc(str_replace(TAX_ADD_TAX, "", $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['tax'] -= $tod_amount;
                 }
             }
         }
     }
     return $tod_amount;
 }
Exemple #10
0
 function calculate_tax_deduction($amount, $od_amount, $method)
 {
     global $order;
     switch ($method) {
         case 'Standard':
             $ratio1 = number_format($od_amount / $amount, 2);
             $tod_amount = 0;
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = vam_get_tax_rate_from_desc($key);
                 $total_net += $tax_rate * $order->info['tax_groups'][$key];
             }
             if ($od_amount > $total_net) {
                 $od_amount = $total_net;
             }
             reset($order->info['tax_groups']);
             while (list($key, $value) = each($order->info['tax_groups'])) {
                 $tax_rate = vam_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['tax'] -= $tod_amount;
             $order->info['total'] -= $tod_amount;
             break;
         case 'Credit Note':
             $tax_rate = vam_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tax_desc = vam_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
             $tod_amount = $this->deduction / (100 + $tax_rate) * $tax_rate;
             $order->info['tax_groups'][$tax_desc] -= $tod_amount;
             //          $order->info['total'] -= $tod_amount;   //// ????? Strider
             break;
         default:
     }
     return $tod_amount;
 }