Fixed small bugs in function void_stock_move in file /includes/db/inventory_db.inc.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 2 Feb 2012 07:24:51 +0000 (08:24 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 2 Feb 2012 07:24:51 +0000 (08:24 +0100)
includes/db/inventory_db.inc

index 093ea6f1332c3288b5e16bedff4f915924cb76b9..068c1645ee7451e48f1f63c7d8ec975bc52e9098 100644 (file)
@@ -381,8 +381,12 @@ function get_stock_moves($type, $type_no, $visible=false)
 
 function void_stock_move($type, $type_no)
 {
-   \r
-    $sql = "SELECT * from ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
+   
+    $sql = "SELECT stock_id, standard_cost, loc_code, tran_date, reference, person_id, visible, discount_percent, price, 
+       sum(qty) qty FROM ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no)." 
+       GROUP BY stock_id, standard_cost, loc_code, tran_date, reference, person_id, visible, discount_percent, price HAVING sum(qty) <> 0";
+
+
     $result = db_query($sql, "Could not void stock moves");
     while ($row = db_fetch($result))
     {
@@ -390,7 +394,7 @@ function void_stock_move($type, $type_no)
                if (is_inventory_item($row["stock_id"]))
                {        
                        // The cost has to be adjusted.
-                       // Transaction rates are stored either as price or standard_cost depending on types\r
+                       // Transaction rates are stored either as price or standard_cost depending on types
                        $types = array(ST_SUPPCREDIT, ST_SUPPRECEIVE);
                        if (in_array($type,$types))
                                $trans_rate = $row["price"];
@@ -406,7 +410,7 @@ function void_stock_move($type, $type_no)
                sql2date($row["tran_date"]), $row["reference"], -$row["qty"]
                        , $row["standard_cost"], $row["person_id"], $row["visible"],
                $row["price"], $row["discount_percent"]);
-    }
+    }\r
 }
 
 //--------------------------------------------------------------------------------------------------