X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fcustomer_delivery.php;h=c7e051e1bab3c43962a3c1ae33e8df3dc1e0979a;hb=d69e655cbe282e2dbb261e207fcfacc5c3b8b246;hp=d8545523a328740e4447db2dea9ed5aec61415fa;hpb=e0e9bd8bd00ee6d601be62991d5e59fe03d07f80;p=fa-stable.git diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index d8545523..c7e051e1 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -266,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()) {