X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fcustomer_delivery.php;h=90905a2cbbc32267a69e5771a2cf138ce4cd08d1;hb=bb82c831a23d39a13018df6571bdb7600db101bf;hp=ee19660c95aef179f922430fe509dfa8a4cac48b;hpb=46c5f7a65a7659a44ae8254c63152074363d3987;p=fa-stable.git diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index ee19660c..90905a2c 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -89,30 +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) { - $_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", @@ -176,12 +167,6 @@ function check_data() set_focus('ref'); return false; } - - if ($_SESSION['Items']->trans_no==0 && !is_new_reference($_POST['ref'], ST_CUSTDELIVERY)) { - display_error(_("The entered reference is already in use.")); - set_focus('ref'); - return false; - } } if ($_POST['ChargeFreightCost'] == "") { $_POST['ChargeFreightCost'] = price_format(0); @@ -278,28 +263,38 @@ 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()) { - $dn = &$_SESSION['Items']; if ($_POST['bo_policy']) { @@ -312,16 +307,23 @@ if (isset($_POST['process_delivery']) && check_data() && check_qoh()) { copy_to_cart(); if ($newdelivery) new_doc_date($dn->document_date); $delivery_no = $dn->write($bo_policy); - - processing_end(); - if ($newdelivery) { - meta_forward($_SERVER['PHP_SELF'], "AddedID=$delivery_no"); - } else { - meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$delivery_no"); + if ($delivery_no == -1) + { + display_error(_("The entered reference is already in use.")); + set_focus('ref'); } + else + { + processing_end(); + if ($newdelivery) { + meta_forward($_SERVER['PHP_SELF'], "AddedID=$delivery_no"); + } else { + meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$delivery_no"); + } + } } -if (isset($_POST['Update']) || isset($_POST['_Location_update'])) { +if (isset($_POST['Update']) || isset($_POST['_Location_update']) || isset($_POST['qty'])) { $Ajax->activate('Items'); } //------------------------------------------------------------------------------ @@ -438,6 +440,10 @@ foreach ($_SESSION['Items']->line_items as $line=>$ln_itm) { if ($ln_itm->quantity==$ln_itm->qty_done) { continue; //this line is fully delivered } + if(isset($_POST['_Location_update']) || isset($_POST['clear_quantity']) || isset($_POST['reset_quantity'])) { + // reset quantity + $ln_itm->qty_dispatched = $ln_itm->quantity-$ln_itm->qty_done; + } // if it's a non-stock item (eg. service) don't show qoh $show_qoh = true; if ($SysPrefs->allow_negative_stock() || !has_stock_holding($ln_itm->mb_flag) || @@ -468,6 +474,10 @@ foreach ($_SESSION['Items']->line_items as $line=>$ln_itm) { label_cell($ln_itm->units); qty_cell($ln_itm->qty_done, false, $dec); + if(isset($_POST['clear_quantity'])) { + $ln_itm->qty_dispatched = 0; + } + $_POST['Line'.$line]=$ln_itm->qty_dispatched; /// clear post so value displayed in the fiel is the 'new' quantity small_qty_cells(null, 'Line'.$line, qty_format($ln_itm->qty_dispatched, $ln_itm->stock_id, $dec), null, null, $dec); $display_discount_percent = percent_format($ln_itm->discount_percent*100) . "%"; @@ -519,9 +529,15 @@ textarea_row(_("Memo"), 'Comments', null, 50, 4); end_table(1); div_end(); submit_center_first('Update', _("Update"), - _('Refresh document page'), true); + _('Refresh document page'), true); +if(isset($_POST['clear_quantity'])) { + submit('reset_quantity', _('Reset quantity'), true, _('Refresh document page')); +} +else { + submit('clear_quantity', _('Clear quantity'), true, _('Refresh document page')); +} submit_center_last('process_delivery', _("Process Dispatch"), - _('Check entered data and save document'), 'default'); + _('Check entered data and save document'), 'default'); end_form();