From 2f85dd59adb080270e39d0e52edc8af9a60175b1 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Mon, 10 Oct 2011 08:50:20 +0200 Subject: [PATCH] Small changes in costing by Chaitanya. --- includes/db/inventory_db.inc | 19 +++++++++++-------- purchasing/includes/db/grn_db.inc | 5 +++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/includes/db/inventory_db.inc b/includes/db/inventory_db.inc index 1f1c3c30..5a5dda4b 100644 --- a/includes/db/inventory_db.inc +++ b/includes/db/inventory_db.inc @@ -166,17 +166,20 @@ function get_deliveries_between($stock_id, $from, $to) function get_deliveries_from_trans($stock_id, $from) { // -ve qty is delivery either by ST_CUSTDELIVERY or inventory adjustment - $sql = "SELECT SUM(-qty), SUM(-qty*standard_cost) FROM ".TB_PREF."stock_moves - WHERE stock_id=".db_escape($stock_id)." AND qty < 0 AND - trans_id>='$from' GROUP BY stock_id"; + //Price for GRN and SUPPCREDIT and std_cost for other trans_types + $sql = "SELECT SUM(-qty), SUM(-qty*IF(type=".ST_SUPPRECEIVE." OR type=".ST_SUPPCREDIT.", price, standard_cost)) + FROM ".TB_PREF."stock_moves + WHERE stock_id=".db_escape($stock_id)." AND qty < 0 AND + trans_id>='$from' GROUP BY stock_id"; $result = db_query($sql, "The deliveries could not be updated"); $row = db_fetch_row($result); - $sql = "SELECT standard_cost FROM ".TB_PREF."stock_moves - WHERE stock_id=".db_escape($stock_id) - ." AND trans_id ='$from'"; - $result = db_query($sql, "The deliveries could not be updated"); - $cost = db_fetch_row($result); + $sql = "SELECT IF(type=".ST_SUPPRECEIVE." OR type=".ST_SUPPCREDIT.", price, standard_cost) + FROM ".TB_PREF."stock_moves + WHERE stock_id=".db_escape($stock_id) + ." AND trans_id ='$from'"; + $result = db_query($sql, "The deliveries could not be updated"); + $cost = db_fetch_row($result); // Adjusting QOH valuation $sql = "SELECT SUM(qty) FROM ".TB_PREF."stock_moves diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 56e694b4..df35e23d 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -13,8 +13,9 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, $adj_only=false) { //Handle if inventory will become negative - if (is_inventory_item($stock_id)) - handle_negative_inventory($stock_id, $qty, $price, $date); + //8-OCT-2011 : Skip negative inventory adjustment for case of adjust_only + if (is_inventory_item($stock_id) && !$adj_only) + handle_negative_inventory($stock_id, $qty, $price, $date); // probably this function should be optimized // passing transaction cart as argument. This would -- 2.30.2