Small changes in costing by Chaitanya.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 10 Oct 2011 06:50:20 +0000 (08:50 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 10 Oct 2011 06:50:20 +0000 (08:50 +0200)
includes/db/inventory_db.inc
purchasing/includes/db/grn_db.inc

index 1f1c3c3046cc01da497fab28e66bd08e01cad6fe..5a5dda4b24485f1b58043b445306bad8eef856f4 100644 (file)
@@ -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\r
+    $sql = "SELECT SUM(-qty), SUM(-qty*IF(type=".ST_SUPPRECEIVE." OR type=".ST_SUPPCREDIT.", price, standard_cost))\r
+        FROM ".TB_PREF."stock_moves\r
+        WHERE stock_id=".db_escape($stock_id)." AND qty < 0 AND\r
+            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)\r
+        FROM ".TB_PREF."stock_moves\r
+        WHERE stock_id=".db_escape($stock_id)\r
+            ." AND trans_id ='$from'";\r
+    $result = db_query($sql, "The deliveries could not be updated");\r
+    $cost = db_fetch_row($result);
        
        // Adjusting QOH valuation 
        $sql = "SELECT SUM(qty) FROM ".TB_PREF."stock_moves
index 56e694b4b47ed856815e1c3130557956dbeb9346..df35e23db60577bda56800421bfbcc337bf679e1 100644 (file)
@@ -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\r
+    if (is_inventory_item($stock_id) && !$adj_only) \r
+        handle_negative_inventory($stock_id, $qty, $price, $date);     
 
        // probably this function should be optimized
        // passing transaction cart as argument. This would