X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fcustomer_delivery.php;h=df8bad06d9ebd4016d13e8f24174a1cf90420c50;hb=9a98bb3bc7a94f1a8e47f8dab45a87c8b4212080;hp=ee19660c95aef179f922430fe509dfa8a4cac48b;hpb=a02e687697549fcc9e911e0529aaec892ba3c2d9;p=fa-stable.git diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index ee19660c..df8bad06 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -89,29 +89,21 @@ 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']; + // Adjust Shipping Charge based upon previous deliveries TAM + adjust_shipping_charge($ord, $_GET['OrderNumber']); + $_SESSION['Items'] = $ord; copy_from_cart(); } elseif (isset($_GET['ModifyDelivery']) && $_GET['ModifyDelivery'] > 0) { + check_is_closed(ST_CUSTDELIVERY, $_GET['ModifyDelivery']); $_SESSION['Items'] = new Cart(ST_CUSTDELIVERY,$_GET['ModifyDelivery']); if ($_SESSION['Items']->count_items() == 0) { @@ -159,7 +151,7 @@ function check_data() } if (!is_date_in_fiscalyear($_POST['DispatchDate'])) { - display_error(_("The entered date of delivery is not in fiscal year.")); + display_error(_("The entered date is out of fiscal year or is closed for further data entry.")); set_focus('DispatchDate'); return false; } @@ -278,24 +270,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()) {