From 1626f8d1594dc467722783e3818f222dae88ad0b Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sat, 20 Jun 2009 07:28:11 +0000 Subject: [PATCH] [0000137] Material Cost Averaging Problem when voiding Supp Inv and qoh reaches 0. --- CHANGELOG.txt | 4 ++++ purchasing/includes/db/grn_db.inc | 20 +++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b4644fd5..b5f8bd34 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,10 @@ Legend: ! -> Note $ -> Affected files +20-Jun-2009 Joe Hunt/Tu Nguyen +# [0000137] Material Cost Averaging Problem when voiding Supp Inv and qoh reaches 0. +$ /purchasing/includes/db/grn_db.inc + 18-Jun-2009 Joe Hunt ! Better support for conversion_factor in Purchasing Pricing. Instruction on Sticky Inventory Forum. $ /inventory/purchasing_data.php 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"); -- 2.30.2