+ end_page();
+ exit;
+} elseif (!check_quantities()) {
+ display_error(_("Selected quantity cannot be less than quantity credited nor more than quantity not invoiced yet."));
+}
+if (isset($_POST['Update'])) {
+ $Ajax->activate('Items');
+}
+if (isset($_POST['_InvoiceDate_changed'])) {
+ $_POST['due_date'] = get_invoice_duedate($_SESSION['Items']->customer_id,
+ $_POST['InvoiceDate']);
+ $Ajax->activate('due_date');
+}
+//-----------------------------------------------------------------------------
+function check_quantities()
+{
+ $ok =1;
+ foreach ($_SESSION['Items']->line_items as $line_no=>$itm) {
+ if (isset($_POST['Line'.$line_no])) {
+ if($_SESSION['Items']->trans_no) {
+ $min = $itm->qty_done;
+ $max = $itm->quantity;
+ } else {
+ $min = 0;
+ $max = $itm->quantity - $itm->qty_done;
+ }
+ if (check_num('Line'.$line_no, $min, $max)) {
+ $_SESSION['Items']->line_items[$line_no]->qty_dispatched =
+ input_num('Line'.$line_no);
+ }
+ else {
+ $ok = 0;
+ }
+
+ }