{
// -ve qty is delivery either by ST_CUSTDELIVERY or inventory adjustment
//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
{
// -ve qty is delivery either by ST_CUSTDELIVERY or inventory adjustment
//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