* @version $Id: store.shipping_modules.php 1750 2009-05-01 06:25:34Z rolandd $ * @package VirtueMart * @subpackage html * @copyright Copyright (C) 2004-2007 soeren - All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net */ mm_showMyFileName(__FILE__); require_once CLASSPATH . "ps_shipping_method.php"; $ps_shipping_method = new ps_shipping_method(); ?> <table width="100%" cellspacing="0" cellpadding="4" border="0"> <tr> <td> <br /> <img src="<?php echo VM_THEMEURL; ?> images/administration/dashboard/ups.gif" border="0" /> <br /><br /> </td> <td><span class="sectionname"><?php echo $VM_LANG->_('VM_SHIPPING_MODULE_LIST_LBL'); ?> </span></td> </tr>
/** * Calculate the tax charges for the current order. * You can switch the way, taxes are calculated: * either based on the VENDOR address, * or based on the ship-to address. * ! Creates the global $order_tax_details * * @param float $order_taxable * @param array $d * @return float */ function calc_order_tax($order_taxable, $d) { global $order_tax_details, $discount_factor; $total = 0; $order_tax = 0; $auth = $_SESSION['auth']; $ps_vendor_id = $_SESSION["ps_vendor_id"]; $db = new ps_DB(); $ship_to_info_id = vmGet($_REQUEST, 'ship_to_info_id'); require_once CLASSPATH . 'ps_tax.php'; $ps_tax = new ps_tax(); $discount_factor = 1; // Shipping address based TAX if (!ps_checkout::tax_based_on_vendor_address()) { $q = "SELECT state, country FROM #__{vm}_user_info "; $q .= "WHERE user_info_id='" . $ship_to_info_id . "'"; $db->query($q); $db->next_record(); $state = $db->f("state"); $country = $db->f("country"); $q = "SELECT * FROM #__{vm}_tax_rate WHERE tax_country='{$country}' "; if (!empty($state)) { $q .= "AND (tax_state='{$state}' OR tax_state=' {$state} ')"; } $db->query($q); if ($db->next_record()) { $rate = $order_taxable * floatval($db->f("tax_rate")); if (empty($rate)) { $order_tax = 0.0; } else { $cart = $_SESSION['cart']; $order_tax = 0.0; if ((!empty($_SESSION['coupon_discount']) || !empty($d['payment_discount'])) && PAYMENT_DISCOUNT_BEFORE == '1') { require_once CLASSPATH . 'ps_product.php'; $ps_product = new ps_product(); for ($i = 0; $i < $cart["idx"]; $i++) { $item_weight = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity']; if ($item_weight != 0 or TAX_VIRTUAL) { $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]); $price['product_price'] = $GLOBALS['CURRENCY']->convert($price['product_price'], $price['product_currency']); $tax_rate = $db->f("tax_rate"); $use_coupon_discount = @$_SESSION['coupon_discount']; //if( !empty( $_SESSION['coupon_discount'] )) { // if( $auth["show_price_including_tax"] == 1 ) { // $use_coupon_discount = $_SESSION['coupon_discount'] / ($tax_rate+1); // } //} $factor = 100 * ($use_coupon_discount + @$d['payment_discount']) / $this->_subtotal; $price["product_price"] = $price["product_price"] - $factor * $price["product_price"] / 100; @($order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate * $cart[$i]["quantity"]); $order_tax += $price["product_price"] * $tax_rate * $cart[$i]["quantity"]; $total += $price["product_price"] * $cart[$i]["quantity"]; } else { $order_tax += 0.0; } } } else { $order_tax = $rate; } } } else { $order_tax = 0.0; } $order_tax_details[$db->f('tax_rate')] = $order_tax; } else { // Calculate the Tax with a tax rate for every product $cart = $_SESSION['cart']; $order_tax = 0.0; $total = 0.0; if ((!empty($_SESSION['coupon_discount']) || !empty($d['payment_discount'])) && PAYMENT_DISCOUNT_BEFORE == '1') { // We need to recalculate the tax details when the discounts are applied // BEFORE taxes - because they affect the product subtotals then $order_tax_details = array(); } require_once CLASSPATH . 'ps_product.php'; $ps_product = new ps_product(); require_once CLASSPATH . 'ps_shipping_method.php'; for ($i = 0; $i < $cart["idx"]; $i++) { $item_weight = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity']; if ($item_weight != 0 or TAX_VIRTUAL) { $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]); $price['product_price'] = $GLOBALS['CURRENCY']->convert($price['product_price'], $price['product_currency']); $tax_rate = $ps_product->get_product_taxrate($cart[$i]["product_id"]); if ((!empty($_SESSION['coupon_discount']) || !empty($d['payment_discount'])) && PAYMENT_DISCOUNT_BEFORE == '1') { $use_coupon_discount = @$_SESSION['coupon_discount']; if (!empty($_SESSION['coupon_discount'])) { if ($auth["show_price_including_tax"] == 1) { $use_coupon_discount = $_SESSION['coupon_discount'] / ($tax_rate + 1); } } $factor = 100 * ($use_coupon_discount + @$d['payment_discount']) / $this->_subtotal; $price["product_price"] = $price["product_price"] - $factor * $price["product_price"] / 100; @($order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate * $cart[$i]["quantity"]); } $order_tax += $price["product_price"] * $tax_rate * $cart[$i]["quantity"]; $total += $price["product_price"] * $cart[$i]["quantity"]; } } if ((!empty($_SESSION['coupon_discount']) || !empty($d['payment_discount'])) && PAYMENT_DISCOUNT_BEFORE != '1') { // Here we need to re-calculate the Discount // because we assume the Discount is "including Tax" $discounted_total = @$d['order_subtotal_withtax'] - @$_SESSION['coupon_discount'] - @$d['payment_discount']; if ($discounted_total != @$d['order_subtotal_withtax'] && @$d['order_subtotal_withtax'] > 0.0) { $discount_factor = $discounted_total / $d['order_subtotal_withtax']; foreach ($order_tax_details as $rate => $value) { $order_tax_details[$rate] = $value * $discount_factor; } } } if (is_object($this->_SHIPPING)) { $taxrate = $this->_SHIPPING->get_tax_rate(); if ($taxrate) { $rate = $this->_SHIPPING->get_rate($d); if ($auth["show_price_including_tax"] == 1) { @($order_tax_details[$taxrate] += $rate - $rate / ($taxrate + 1)); } else { @($order_tax_details[$taxrate] += $rate * $taxrate); } } } } return round($order_tax, 2); }
function get_weight($pid) { global $vendor_country_2_code; if (empty($GLOBALS['product_info'][$pid]['weight'])) { if ($vendor_country_2_code == "US" || $vendor_country_2_code == "PR" || $vendor_country_2_code == "DO") { defined('WEIGHT_UOM') or define('WEIGHT_UOM', "LB"); $GLOBALS['product_info'][$pid]['weight'] = ps_shipping_method::get_weight_LB($pid); return $GLOBALS['product_info'][$pid]['weight']; } else { defined('WEIGHT_UOM') or define('WEIGHT_UOM', "KG"); $GLOBALS['product_info'][$pid]['weight'] = ps_shipping_method::get_weight_KG($pid); return $GLOBALS['product_info'][$pid]['weight']; } } else { return $GLOBALS['product_info'][$pid]['weight']; } }
/* Product PRICE */ $my_taxrate = $ps_product->get_product_taxrate($cart[$i]["product_id"], $weight_subtotal); $tax = $my_taxrate * 100; $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]); $price['product_price'] = $GLOBALS['CURRENCY']->convert($price['product_price'], $price['product_currency']); if ($auth["show_price_including_tax"] == 1) { $product_price = $price["product_price"] * ($my_taxrate + 1); } else { $product_price = $price["product_price"]; } $product_price = round($product_price, 5); $product_rows[$i]['product_price'] = $GLOBALS['CURRENCY_DISPLAY']->getFullValue(round($product_price, 2)); /* Quantity Box */ $product_rows[$i]['quantity'] = $cart[$i]["quantity"]; /* WEIGHT CALCULATION */ $weight_subtotal = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity']; $weight_total += $weight_subtotal; /* SUBTOTAL CALCULATION */ $subtotal = $product_price * $cart[$i]["quantity"]; $total += $subtotal; $product_rows[$i]['subtotal'] = $GLOBALS['CURRENCY_DISPLAY']->getFullValue($subtotal); if (!empty($my_taxrate) && MULTIPLE_TAXRATES_ENABLE == '1') { if ($auth["show_price_including_tax"] == 1) { eval("\$message = \"" . $VM_LANG->_('PHPSHOP_INCLUDING_TAX') . "\";"); $product_rows[$i]['subtotal'] .= " " . $message; } else { $product_rows[$i]['subtotal'] .= " (+ {$tax}% " . $VM_LANG->_('PHPSHOP_CART_TAX') . ")"; } } // UPDATE CART / DELETE FROM CART $action_url = $_SERVER['SERVER_PORT'] == "443" ? SECUREURL : URL . basename($_SERVER['PHP_SELF']);
/** * Validate a selected Shipping Rate * * @param array $d * @return boolean */ function validate(&$d) { global $VM_LANG, $vmLogger; $cart = $_SESSION['cart']; $d['shipping_rate_id'] = vmGet($_REQUEST, 'shipping_rate_id'); $d['ship_to_info_id'] = vmGet($_REQUEST, 'ship_to_info_id'); if (empty($_SESSION[$d['shipping_rate_id']])) { return false; } $details = explode("|", urldecode($d['shipping_rate_id'])); $rate_id = intval($details[4]); $totalweight = 0; require_once CLASSPATH . 'ps_shipping_method.php'; for ($i = 0; $i < $cart["idx"]; $i++) { $weight_subtotal = ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity']; $totalweight += $weight_subtotal; } $dbu = new ps_DB(); //DB User $q = "SELECT country,zip FROM #__{vm}_user_info WHERE user_info_id = '" . $dbu->getEscaped($d["ship_to_info_id"]) . "'"; $dbu = new ps_DB(); //DB User $dbu->query($q); if (!$dbu->next_record()) { /*$vmLogger->err( $VM_LANG->_('PHPSHOP_CHECKOUT_ERR_SHIPTO_NOT_FOUND',false) ); return False;*/ } $zip = $dbu->f("zip"); $country = $dbu->f("country"); $q = "SELECT shipping_rate_id FROM #__{vm}_shipping_rate WHERE shipping_rate_id = '{$rate_id}'"; $dbs = new ps_DB(); // DB Shiping_rate $dbs->query($q); if (!$dbs->next_record()) { $vmLogger->err($VM_LANG->_('PHPSHOP_CHECKOUT_ERR_RATE_NOT_FOUND', false)); return False; } return $this->rate_id_valid($rate_id, $country, $zip, $totalweight); }