More regarding costing valuations
[fa-stable.git] / includes / db / inventory_db.inc
index 56e9419679d035adf4e148db8052ed1c581a4dd9..6a1a7f52c1298c9986a6990412e3455af97d98c1 100644 (file)
@@ -399,18 +399,29 @@ function void_stock_move($type, $type_no)
     while ($row = db_fetch($result))
     {
         add_stock_move($type, $row["stock_id"], $type_no, $row["loc_code"],
-               sql2date($row["tran_date"]), $row["reference"], -$row["qty"], $row["standard_cost"], $row["person_id"], $row["visible"],
-               $row["price"], $row["discount_percent"]);
+            sql2date($row["tran_date"]), $row["reference"], -$row["qty"], $row["standard_cost"], $row["person_id"], $row["visible"],
+            $row["price"], $row["discount_percent"]);
         
         // If there is cost difference, then cost has to be adjusted.
         // IMP : Adjusting cost is suitable instead of normal averaging as it will not work properly for manufactured items. Reason being Avg cost is suitable only for purchased items
+        
         $curr_std_cost = get_standard_cost($row["stock_id"]);
-        if ($curr_std_cost != $row["standard_cost"])
+        
+        //Chaitanya : Transaction rates are stored either as price or standard_cost depending
+        //on types
+        $types = array(ST_SUPPCREDIT);
+        if (in_array($type,$types))
+            $trans_rate = $row["price"];
+        else
+            $trans_rate = $row["standard_cost"];
+        
+        if ($curr_std_cost != $trans_rate)
         {
-            $cost_diff = $row["standard_cost"] - $curr_std_cost;
+            $cost_diff = $trans_rate - $curr_std_cost;
             update_average_material_cost(0, $row["stock_id"],
                 $cost_diff, -$row["qty"], sql2date($row["tran_date"]), true);
         }
+
     }
 }