X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=purchasing%2Fincludes%2Fdb%2Fgrn_db.inc;h=23ca2e223c7fb64f2eccfa395002bd755be461dd;hb=1626f8d1594dc467722783e3818f222dae88ad0b;hp=9b56b0f747608a7bd1391ac670b1067756862d33;hpb=096d797f8ba90391f8fb047e904edcd8dd7c965d;p=fa-stable.git diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 9b56b0f7..23ca2e22 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -31,20 +31,18 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, $exclude = 0; $qoh = get_qoh_on_date($stock_id, null, $date, $exclude); - if ($qoh + $qty <= 0) - $material_cost = 0; - else + if ($adj_only) { - if ($adj_only) - { - if ($qoh <= 0) - $material_cost = 0; - else - $material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) / $qoh; - } + if ($qoh <= 0) + $material_cost = 0; else - $material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) / ($qoh + $qty); + $material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) / $qoh; } + elseif ($qoh + $qty <= 0) + $material_cost = 0; + else + $material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) / ($qoh + $qty); + $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)." WHERE stock_id='$stock_id'"; db_query($sql,"The cost details for the inventory item could not be updated");