From: Joe Hunt Date: Mon, 10 Oct 2011 06:50:20 +0000 (+0200) Subject: Small changes in costing by Chaitanya. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=423a4eb4f59dc60f3b4d1a4069234fe5efc9d173;p=textcart.git Small changes in costing by Chaitanya. --- diff --git a/includes/db/inventory_db.inc b/includes/db/inventory_db.inc index 1f1c3c3..5a5dda4 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 56e694b..df35e23 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