0001085: When doing multiple deliveries for an order should account for shipping...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 27 Sep 2011 07:39:52 +0000 (09:39 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 27 Sep 2011 07:39:52 +0000 (09:39 +0200)
sales/customer_delivery.php
sales/includes/db/sales_delivery_db.inc

index c7e051e1bab3c43962a3c1ae33e8df3dc1e0979a..30e359193d6e25253d0ac1ed60d4084b235cb30b 100644 (file)
@@ -95,6 +95,9 @@ if (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) {
                die ("<br><b>" . _("This order has no items. There is nothing to delivery.") . "</b>");
        }
 
+       // Adjust Shipping Charge based upon previous deliveries TAM
+       adjust_shipping_charge($ord, $_GET['OrderNumber']);
        $_SESSION['Items'] = $ord;
        copy_from_cart();
 
index 72392077b4e619f0a2f4e2ab7b84626dfdf1b7ce..f92feca5b02622541dcddf3a48563d0f883ddaa3 100644 (file)
@@ -148,6 +148,18 @@ function write_sales_delivery(&$delivery,$bo_policy)
        return $delivery_no;
 }
 
+//--------------------------------------------------------------------------------------------------
+function adjust_shipping_charge(&$delivery, $trans_no)
+{
+       $sql = "SELECT sum(ov_freight) as freight FROM ".TB_PREF."debtor_trans WHERE order_ = $trans_no AND type = " . ST_CUSTDELIVERY . " AND debtor_no = " . $delivery->customer_id;
+       $result = db_query($sql, "Can not find delivery notes");
+       $row = db_fetch_row($result);
+       if (!$row[0]) $freight = 0;
+       else $freight = $row[0];
+       if ($freight < $delivery->freight_cost) $delivery->freight_cost = $delivery->freight_cost - $freight;
+       else $delivery->freight_cost = 0;
+}
+
 //--------------------------------------------------------------------------------------------------
 
 function void_sales_delivery($type, $type_no, $transactions=true)