+function check_item_data($n)
+{
+ global $check_price_charged_vs_order_price,
+ $check_qty_charged_vs_del_qty;
+ if (!check_num('this_quantity_inv'.$n, 0) || input_num('this_quantity_inv'.$n)==0)
+ {
+ display_error( _("The quantity to invoice must be numeric and greater than zero."));
+ set_focus('this_quantity_inv'.$n);
+ return false;
+ }
+
+ if (!check_num('ChgPrice'.$n))
+ {
+ display_error( _("The price is not numeric."));
+ set_focus('ChgPrice'.$n);
+ return false;
+ }
+
+ if ($check_price_charged_vs_order_price == True)
+ {
+ if ($_POST['order_price'.$n]!=input_num('ChgPrice'.$n)) {
+ if ($_POST['order_price'.$n]==0 ||
+ input_num('ChgPrice'.$n)/$_POST['order_price'.$n] >
+ (1 + (sys_prefs::over_charge_allowance() / 100)))
+ {
+ display_error(_("The price being invoiced is more than the purchase order price by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.") .
+ _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
+ set_focus('ChgPrice'.$n);
+ return false;
+ }
+ }
+ }
+
+ if ($check_qty_charged_vs_del_qty == True)
+ {
+ if (input_num('this_quantity_inv'.$n) / ($_POST['qty_recd'.$n] - $_POST['prev_quantity_inv'.$n]) >
+ (1+ (sys_prefs::over_charge_allowance() / 100)))
+ {
+ display_error( _("The quantity being invoiced is more than the outstanding quantity by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.")
+ . _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
+ set_focus('this_quantity_inv'.$n);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function commit_item_data($n)
+{
+ if (check_item_data($n))
+ {
+ if (input_num('this_quantity_inv'.$n) >= ($_POST['qty_recd'.$n] - $_POST['prev_quantity_inv'.$n]))
+ {
+ $complete = true;
+ }
+ else
+ {
+ $complete = false;
+ }
+
+ $_SESSION['supp_trans']->add_grn_to_trans($n, $_POST['po_detail_item'.$n],
+ $_POST['item_code'.$n], $_POST['item_description'.$n], $_POST['qty_recd'.$n],
+ $_POST['prev_quantity_inv'.$n], input_num('this_quantity_inv'.$n),
+ $_POST['order_price'.$n], input_num('ChgPrice'.$n), $complete,
+ $_POST['std_cost_unit'.$n], "");
+ }
+}
+
+//-----------------------------------------------------------------------------------------
+
+$id = find_submit('grn_item_id');
+if ($id != -1)
+{
+ commit_item_data($id);
+}
+
+if (isset($_POST['InvGRNAll']))
+{
+ foreach($_POST as $postkey=>$postval )
+ {
+ if (strpos($postkey, "qty_recd") === 0)
+ {
+ $id = substr($postkey, strlen("qty_recd"));
+ $id = (int)$id;
+ commit_item_data($id);
+ }
+ }
+}
+