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
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