function void_stock_move($type, $type_no)
{
- \r
- $sql = "SELECT * from ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
+
+ $sql = "SELECT stock_id, standard_cost, loc_code, tran_date, reference, person_id, visible, discount_percent, price,
+ sum(qty) qty FROM ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no)."
+ GROUP BY stock_id, standard_cost, loc_code, tran_date, reference, person_id, visible, discount_percent, price HAVING sum(qty) <> 0";
+
+
$result = db_query($sql, "Could not void stock moves");
while ($row = db_fetch($result))
{
if (is_inventory_item($row["stock_id"]))
{
// The cost has to be adjusted.
- // Transaction rates are stored either as price or standard_cost depending on types\r
+ // Transaction rates are stored either as price or standard_cost depending on types
$types = array(ST_SUPPCREDIT, ST_SUPPRECEIVE);
if (in_array($type,$types))
$trans_rate = $row["price"];
sql2date($row["tran_date"]), $row["reference"], -$row["qty"]
, $row["standard_cost"], $row["person_id"], $row["visible"],
$row["price"], $row["discount_percent"]);
- }
+ }\r
}
//--------------------------------------------------------------------------------------------------