{
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);
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);
+ $avg_cost = ($avg_cost + ($unit_cost*$qty_new)/$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)."