Additional dev related exclusions in gitignore, small cleanups in old upgrade classes.
[fa-stable.git] / includes / db / inventory_db.inc
index 19f54f2b9802d08cafeba64bc362d9266433cad1..e46dd6de82e128ae7baf48d1e4f7848307a94735 100644 (file)
@@ -110,6 +110,20 @@ function get_unit_cost($stock_id)
        return $myrow[0];
 }
 
+//--------------------------------------------------------------------------------------
+function get_purchase_cost($stock_id)
+{
+       $sql = "SELECT purchase_cost
+               FROM ".TB_PREF."stock_master
+               WHERE stock_id=".db_escape($stock_id);
+       $result = db_query($sql, "The purchase cost cannot be retrieved");
+
+       $myrow = db_fetch_row($result);
+
+       return $myrow[0];
+}
+
 //--------------------------------------------------------------------------------------
 
 function is_inventory_item($stock_id)
@@ -215,14 +229,14 @@ function get_deliveries_from_trans($stock_id, $move_id)
         WHERE stock_id=".db_escape($stock_id)." AND qty < 0 AND
             trans_id>='$move_id' GROUP BY stock_id";
        $result = db_query($sql, "The deliveries could not be updated");
-       $row = db_fetch_row($result);
+       $row = db_fetch_row($result);   // fetch quantity and cost of all deliveries including move_id
        
     $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 ='$move_id'";
     $result = db_query($sql, "The deliveries could not be updated");
-    $cost = db_fetch_row($result);
+    $cost = db_fetch_row($result);      // fetch unit cost at move_id
 
        // Adjusting QOH valuation 
        $sql = "SELECT SUM(qty)
@@ -230,9 +244,10 @@ function get_deliveries_from_trans($stock_id, $move_id)
                WHERE stock_id=".db_escape($stock_id)." AND
                        trans_id<'$move_id' GROUP BY stock_id";
        $result = db_query($sql, "The deliveries could not be updated");
-       $qoh = db_fetch_row($result);
+       $qoh = db_fetch_row($result);   // find qoh before inventory went negative
 
-       $qty = $row[0] - $qoh[0]; //QOH prior to -ve stock is subtracted
+        // adjust cost and quantity for part of move_id transaction on positive inventory
+       $qty = $row[0] - $qoh[0]; // QOH prior to -ve stock is subtracted
        $final_cost = $row[1] - $qoh[0]*$cost[0];
        
        return array($qty,$final_cost); 
@@ -317,7 +332,7 @@ function get_stock_gl_code($stock_id)
 {
        /*Gets the GL Codes relevant to the item account  */
        $sql = "SELECT mb_flag, inventory_account, cogs_account,
-               adjustment_account, sales_account, assembly_account, dimension_id, dimension2_id FROM
+               adjustment_account, sales_account, wip_account, dimension_id, dimension2_id FROM
                ".TB_PREF."stock_master WHERE stock_id = ".db_escape($stock_id);
 
        $get = db_query($sql,"retreive stock gl code");
@@ -326,6 +341,7 @@ function get_stock_gl_code($stock_id)
 
 function get_purchase_value($stock_id)
 {
+
        $sql = "SELECT purchase_cost FROM
                ".TB_PREF."stock_master WHERE stock_id = ".db_escape($stock_id);