X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fcustomer_delivery.php;h=c7e051e1bab3c43962a3c1ae33e8df3dc1e0979a;hb=20d61f658e58584338364ce8ea86cc66d0dba8fd;hp=ee19660c95aef179f922430fe509dfa8a4cac48b;hpb=46c5f7a65a7659a44ae8254c63152074363d3987;p=fa-stable.git diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index ee19660c..c7e051e1 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -89,30 +89,18 @@ if (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) { $ord = new Cart(ST_SALESORDER, $_GET['OrderNumber'], true); - /*read in all the selected order into the Items cart */ - if ($ord->count_items() == 0) { hyperlink_params($path_to_root . "/sales/inquiry/sales_orders_view.php", _("Select a different sales order to delivery"), "OutstandingOnly=1"); die ("
" . _("This order has no items. There is nothing to delivery.") . ""); } - $ord->trans_type = ST_CUSTDELIVERY; - $ord->src_docs = $ord->trans_no; - $ord->order_no = key($ord->trans_no); - $ord->trans_no = 0; - $ord->reference = $Refs->get_next(ST_CUSTDELIVERY); - $ord->document_date = new_doc_date(); - $cust = get_customer($ord->customer_id); - // 2010-09-03 Joe Hunt - $ord->dimension_id = $cust['dimension_id']; - $ord->dimension2_id = $cust['dimension2_id']; $_SESSION['Items'] = $ord; copy_from_cart(); } elseif (isset($_GET['ModifyDelivery']) && $_GET['ModifyDelivery'] > 0) { - $_SESSION['Items'] = new Cart(ST_CUSTDELIVERY,$_GET['ModifyDelivery']); + $_SESSION['Items'] = new Cart(ST_CUSTDELIVERY, $_GET['ModifyDelivery']); if ($_SESSION['Items']->count_items() == 0) { hyperlink_params($path_to_root . "/sales/inquiry/sales_orders_view.php", @@ -278,24 +266,35 @@ function check_quantities() function check_qoh() { - global $SysPrefs; - - if (!$SysPrefs->allow_negative_stock()) { - foreach ($_SESSION['Items']->line_items as $itm) { - - if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) { - $qoh = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); - - if ($itm->qty_dispatched > $qoh) { - display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") . - " " . $itm->stock_id . " - " . $itm->item_description); - return false; - } - } - } - } - return true; + global $SysPrefs; + $dn = &$_SESSION['Items']; + $newdelivery = ($dn->trans_no==0); + if (!$SysPrefs->allow_negative_stock()) { + foreach ($_SESSION['Items']->line_items as $itm) { + + if ($itm->qty_dispatched && has_stock_holding($itm->mb_flag)) { + $qoh_by_date = get_qoh_on_date($itm->stock_id, $_POST['Location'], $_POST['DispatchDate']); + $qoh_abs = get_qoh_on_date($itm->stock_id, $_POST['Location'], null); + //If editing current delivery delivered qty should be added + if (!$newdelivery) + { + $delivered = get_already_delivered($itm->stock_id, $_POST['Location'], key($dn->trans_no)); + + $qoh_abs = $qoh_abs - $delivered; + $qoh_by_date = $qoh_by_date - $delivered; + } + $qoh = ($qoh_by_date < $qoh_abs ? $qoh_by_date : $qoh_abs); + if ($itm->qty_dispatched > $qoh) { + display_error(_("The delivery cannot be processed because there is an insufficient quantity for item:") . + " " . $itm->stock_id . " - " . $itm->item_description); + return false; + } + } + } + } + return true; } + //------------------------------------------------------------------------------ if (isset($_POST['process_delivery']) && check_data() && check_qoh()) {