X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=manufacturing%2Fincludes%2Fdb%2Fwork_order_costing_db.inc;h=48cb7f3b2d811fdc18c478f26c5dc5f57801920e;hb=85cdc977a80b32727c13aae517f58437e908a033;hp=e44de122f7185eb1fd221ac6764dc15b2ead9c15;hpb=4bb6535b5a8c42b9e2be05e4acb75444d8a2ccf0;p=fa-stable.git diff --git a/manufacturing/includes/db/work_order_costing_db.inc b/manufacturing/includes/db/work_order_costing_db.inc index e44de122..48cb7f3b 100644 --- a/manufacturing/includes/db/work_order_costing_db.inc +++ b/manufacturing/includes/db/work_order_costing_db.inc @@ -48,8 +48,8 @@ function update_material_cost($stock_id, $qty, $unit_cost, $date) { global $Refs; - $product = get_item($stock_id); - $avg_cost = $product['material_cost']; + $item = get_item($stock_id); + $avg_cost = $item['material_cost']; $qoh = get_qoh_on_date($stock_id, null, $date); @@ -103,8 +103,12 @@ function update_material_cost($stock_id, $qty, $unit_cost, $date) write_journal_entries($cart); } - if ($qty > 0 && ($qoh != -$qty)) - $avg_cost = ($avg_cost*($qoh+$qty_delayed)+$unit_cost*$qty_new)/($qoh+$qty); + if ($qty > 0 && ($qoh != -$qty)) { + if ($qoh == 0 && $avg_cost != 0) + $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)." WHERE stock_id=".db_escape($stock_id);