From ca3af895c069979d693a98c49255a48664061cd4 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Thu, 30 Aug 2018 08:04:27 +0200 Subject: [PATCH] Update material cost when quantity on hand is zero. @notrinos. --- manufacturing/includes/db/work_order_costing_db.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/manufacturing/includes/db/work_order_costing_db.inc b/manufacturing/includes/db/work_order_costing_db.inc index e44de122..7671e7ba 100644 --- a/manufacturing/includes/db/work_order_costing_db.inc +++ b/manufacturing/includes/db/work_order_costing_db.inc @@ -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); -- 2.30.2