|
From: <te...@us...> - 2013-07-07 09:57:25
|
Revision: 6057
http://sourceforge.net/p/web-erp/reponame/6057
Author: tehonu
Date: 2013-07-07 09:57:21 +0000 (Sun, 07 Jul 2013)
Log Message:
-----------
Added all destination address fields and use of country for calculation of freight costs
Modified Paths:
--------------
trunk/ConfirmDispatch_Invoice.php
trunk/DeliveryDetails.php
trunk/includes/FreightCalculation.inc
Modified: trunk/ConfirmDispatch_Invoice.php
===================================================================
--- trunk/ConfirmDispatch_Invoice.php 2013-07-07 09:43:00 UTC (rev 6056)
+++ trunk/ConfirmDispatch_Invoice.php 2013-07-07 09:57:21 UTC (rev 6057)
@@ -431,6 +431,9 @@
list ($FreightCost, $BestShipper) = CalcFreightCost($_SESSION['Items'.$identifier]->total,
$_SESSION['Items'.$identifier]->BrAdd2,
$_SESSION['Items'.$identifier]->BrAdd3,
+ $_SESSION['Items'.$identifier]->BrAdd4,
+ $_SESSION['Items'.$identifier]->BrAdd5,
+ $_SESSION['Items'.$identifier]->BrAdd6,
$_SESSION['Items'.$identifier]->totalVolume,
$_SESSION['Items'.$identifier]->totalWeight,
$_SESSION['Items'.$identifier]->Location,
Modified: trunk/DeliveryDetails.php
===================================================================
--- trunk/DeliveryDetails.php 2013-07-07 09:43:00 UTC (rev 6056)
+++ trunk/DeliveryDetails.php 2013-07-07 09:57:21 UTC (rev 6057)
@@ -117,7 +117,15 @@
if ($InputErrors==0){
if ($_SESSION['DoFreightCalc']==True){
- list ($_POST['FreightCost'], $BestShipper) = CalcFreightCost($_SESSION['Items'.$identifier]->total, $_POST['BrAdd2'], $_POST['BrAdd3'], $_SESSION['Items'.$identifier]->totalVolume, $_SESSION['Items'.$identifier]->totalWeight, $_SESSION['Items'.$identifier]->Location, $db);
+ list ($_POST['FreightCost'], $BestShipper) = CalcFreightCost($_SESSION['Items'.$identifier]->total,
+ $_POST['BrAdd2'],
+ $_POST['BrAdd3'],
+ $_POST['BrAdd4'],
+ $_POST['BrAdd5'],
+ $_POST['BrAdd6'],
+ $_SESSION['Items'.$identifier]->totalVolume,
+ $_SESSION['Items'.$identifier]->totalWeight,
+ $_SESSION['Items'.$identifier]->Location, $db);
if ( !empty($BestShipper) ){
$_POST['FreightCost'] = round($_POST['FreightCost'],2);
$_POST['ShipVia'] = $BestShipper;
Modified: trunk/includes/FreightCalculation.inc
===================================================================
--- trunk/includes/FreightCalculation.inc 2013-07-07 09:43:00 UTC (rev 6056)
+++ trunk/includes/FreightCalculation.inc 2013-07-07 09:57:21 UTC (rev 6057)
@@ -7,37 +7,41 @@
Function CalcFreightCost ($TotalValue,
$BrAdd2,
$BrAdd3,
+ $BrAdd4,
+ $BrAdd5,
+ $BrAddCountry,
$TotalVolume,
$TotalWeight,
$FromLocation,
$db){
- # make an array of all the words that could be the name of the destination city
- $FindCity = explode(' ', $BrAdd2 . ' ' . $BrAdd3);
+ # make an array of all the words that could be the name of the destination zone (city, state or ZIP)
+ $FindCity = explode(' ', $BrAdd2 . ' ' . $BrAdd3 . ' ' . $BrAdd4 . ' ' . $BrAdd5);
- $sql = 'Select shipperid,
- kgrate *' . $TotalWeight . ' AS kgcost,
- cubrate * ' . $TotalVolume . " AS cubcost,
- fixedprice, minimumchg
- FROM freightcosts
- WHERE locationfrom = '$FromLocation'
- AND maxkgs > " . $TotalWeight . '
- AND maxcub >' . $TotalVolume . '
- AND (';
-
- foreach ($FindCity as $City) {
-
- $sql = $sql . ' destination ' . LIKE . " '" . ucwords($City) . "%' OR";
-
- }
- $sql = mb_substr($sql, 0, strrpos($sql,' OR')) . ')';
-
+ $sql = "SELECT shipperid,
+ kgrate * " . $TotalWeight . " AS kgcost,
+ cubrate * " . $TotalVolume . " AS cubcost,
+ fixedprice,
+ minimumchg
+ FROM freightcosts
+ WHERE locationfrom = " . $FromLocation . "
+ AND destinationcountry = " . $BrAddCountry . "
+ AND maxkgs > " . $TotalWeight . "
+ AND maxcub >" . $TotalVolume . " ";
+ if (($BrAdd2 != "") OR ($BrAdd3 != "") OR ($BrAdd4 != "") OR ($BrAdd5 != "")){
+ // if there is some details of the address besides the country
+ $sql .= " AND (";
+ foreach ($FindCity as $City) {
+ $sql = $sql . " destination LIKE '" . ucwords($City) . "%' OR";
+ }
+ $sql = mb_substr($sql, 0, strrpos($sql,' OR')) . ')';
+ }
$CalcFreightCostResult = DB_query($sql,$db);
if (DB_error_no($db) !=0) {
echo _('The freight calculation for the destination city cannot be performed because') . ' - ' . DB_error_msg($db);
} elseif (DB_num_rows($CalcFreightCostResult)>0) {
- $CalcFreightCost =9999999;
+ $CalcFreightCost =9999999999;
while ($myrow = DB_fetch_array($CalcFreightCostResult)) {
|