+function check_item_data($n)
+{
+ global $SysPrefs;
+
+ 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;
+ }
+
+ $margin = $SysPrefs->over_charge_allowance();
+ if ($SysPrefs->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 + ($margin/ 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 :") . $margin . "%");
+ set_focus('ChgPrice'.$n);
+ return false;
+ }
+ }
+ }
+
+ if ($SysPrefs->check_qty_charged_vs_del_qty == true && ($_POST['qty_recd'.$n] != $_POST['prev_quantity_inv'.$n])
+ && !empty($_POST['prev_quantity_inv'.$n]))
+ {
+ if (input_num('this_quantity_inv'.$n) / ($_POST['qty_recd'.$n] - $_POST['prev_quantity_inv'.$n]) >
+ (1+ ($margin / 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 :") . $margin . "%");
+ set_focus('this_quantity_inv'.$n);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function commit_item_data($n)
+{
+ if (check_item_data($n))
+ {
+ $_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));
+ reset_tax_input();
+ }
+}
+
+//-----------------------------------------------------------------------------------------
+
+$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);
+ }
+ }
+}
+