Fixed bug in voiding GRN/Purchase resulting in invalid average unit cost.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 10 Jun 2013 18:47:09 +0000 (20:47 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 10 Jun 2013 18:47:09 +0000 (20:47 +0200)
includes/db/inventory_db.inc
purchasing/includes/db/grn_db.inc

index fa465ba7b62f9560f77e9cac2b66410275c33386..aca5447577cf512cab8d7bbfc6c75886411dd13e 100644 (file)
@@ -392,13 +392,13 @@ function void_stock_move($type, $type_no)
                        // The cost has to be adjusted.
                        // 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"];
+                       if (in_array($type, $types))
+                               $unit_cost = $row["price"];
                        else
-                               $trans_rate = $row["standard_cost"];
+                               $unit_cost = $row["standard_cost"];
 
-                       update_average_material_cost(0, $row["stock_id"],
-                               $trans_rate, -$row["qty"], sql2date($row["tran_date"]));
+                       update_average_material_cost($row["person_id"], $row["stock_id"],
+                               $unit_cost, -$row["qty"], sql2date($row["tran_date"]));
                }
 
     }
index 6c684cff4cb838d799c157fb8bac0f1f4b1dd54d..f5bbf4ac8a0e993004cc085621eb97fafaefcd6c 100644 (file)
@@ -75,14 +75,14 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date,
                        $qoh = 0;
                }
                if ($qoh + $qty > 0)
-                       $material_cost 
-= ($qoh * $material_cost + $qty * $price_in_home_currency) /   ($qoh + $qty);
-       }       
-       
+                       $material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) /     ($qoh + $qty);
+       }
+
        if ($cost_adjust) // new 2010-02-10 //Chaitanya : Material_cost replaced with price
                adjust_deliveries($stock_id, $price_in_home_currency_, $date);
        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
                WHERE stock_id=".db_escape($stock_id);
+
        db_query($sql,"The cost details for the inventory item could not be updated");
        return $material_cost;
 }