Rollback. Update material cost when quantity on hand is zero. @notrinos.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 9 Jan 2019 22:15:27 +0000 (23:15 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 9 Jan 2019 22:15:27 +0000 (23:15 +0100)
manufacturing/includes/db/work_order_costing_db.inc

index d3c96a5ffc625ecda474c816be4fd0a72a9d2cf6..48cb7f3b2d811fdc18c478f26c5dc5f57801920e 100644 (file)
@@ -105,9 +105,9 @@ function update_material_cost($stock_id, $qty, $unit_cost, $date)
 
        if ($qty > 0 && ($qoh != -$qty)) {
                if ($qoh == 0 && $avg_cost != 0)
-                       $avg_cost = ($avg_cost + ($unit_cost*$qty_new)/$qty)/2;
-               else
-                       $avg_cost = ($avg_cost*($qoh+$qty_delayed)+$unit_cost*$qty_new)/($qoh+$qty);
+               $avg_cost = ($avg_cost + ($unit_cost*$qty_new)/($qoh+$qty))/2;
+       else
+               $avg_cost = ($avg_cost*($qoh+$qty_delayed)+$unit_cost*$qty_new)/($qoh+$qty);
        }
 
        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($avg_cost)."