Stock goes negative even, the negative inventory is turned off. Fix by kvvaradha.
[fa-stable.git] / admin / void_transaction.php
index f490cb237fe8b195e6073e39e3b927bdd0ab19a1..32d3a038e57cf1c12d250407f2c66402de5277f7 100644 (file)
@@ -73,7 +73,7 @@ function exist_transaction($type, $type_no)
                        return false;
 
                case ST_SUPPRECEIVE : // it's a GRN
-                       if (exists_grn($type_no))
+                       if (!exists_grn($type_no))
                                return false;
                        break;
 
@@ -222,7 +222,24 @@ function voiding_controls()
                }       
                else
                {
-               display_warning(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
+               if ($_POST['filterType'] == ST_SUPPRECEIVE) { 
+                $result = get_grn_items($_POST['trans_no']);
+                if (db_num_rows($result) > 0) {
+                    while ($myrow = db_fetch($result)) {
+                        if (is_inventory_item($myrow["item_code"])) {
+                            if (check_negative_stock($myrow["item_code"], -$myrow["qty_recd"], null, $_POST['date_'])) {
+                                $stock = get_item($myrow["item_code"]);
+                                display_error(_("The void cannot be processed because there is an insufficient quantity for item:") .
+                                    " " . $stock['stock_id'] . " - " . $stock['description'] . " - " .
+                                    _("Quantity On Hand") . " = " . number_format2(get_qoh_on_date($stock['stock_id'], null, 
+                                    $_POST['date_']), get_qty_dec($stock['stock_id'])));
+                                return false;
+                            }
+                        }
+                    }
+                }
+            }
+                       display_warning(_("Are you sure you want to void this transaction ? This action cannot be undone."), 0, 1);
                        br();
                submit_center_first('ConfirmVoiding', _("Proceed"), '', true);
                submit_center_last('CancelVoiding', _("Cancel"), '', 'cancel');
@@ -290,7 +307,6 @@ function handle_void_transaction()
                        display_notification_centered(_("Selected transaction has been voided."));
                        unset($_POST['trans_no']);
                        unset($_POST['memo_']);
-                       unset($_POST['date_']);
                }
                else {
                        display_error($msg);
@@ -319,6 +335,7 @@ if (isset($_POST['ProcessVoiding']))
 if (isset($_POST['ConfirmVoiding']))
 {
        handle_void_transaction();
+       $selected_id = '';
        $Ajax->activate('_page_body');
 }