When voiding Inventory Adjustment transaction, the costs are not getting adjusted.
[fa-stable.git] / inventory / includes / db / items_adjust_db.inc
index 5274584d13a35b4748d60cda53d5cce691cb8d9c..f3c8c9d2be303aef54915208e0223acae26c3a57 100644 (file)
@@ -51,6 +51,14 @@ function add_stock_adjustment($items, $location, $date_, $type, $increase, $refe
 function void_stock_adjustment($type_no)
 {
        hook_db_prevoid(ST_INVADJUST, $type_no);
+
+    //Average the cost while voiding
+    $adjustment_items = get_stock_adjustment_items($type_no);
+    while ($adjustment = db_fetch($adjustment_items))
+    {
+        update_average_material_cost(0, $adjustment['stock_id'],
+            $adjustment['standard_cost'], -$adjustment['qty'], sql2date($adjustment['tran_date']));
+    }
        void_gl_trans(ST_INVADJUST, $type_no);
        void_stock_move(ST_INVADJUST, $type_no);
 }