- // clear any allocations for this transaction
- $sql = "SELECT * FROM ".TB_PREF."supp_allocations
- WHERE (trans_type_from=".db_escape($type)." AND trans_no_from=".db_escape($type_no).")
- OR (trans_type_to=".db_escape($type)." AND trans_no_to=".db_escape($type_no).")";
- $result = db_query($sql, "could not void supp transactions for type=$type and trans_no=$type_no");
-
- while ($row = db_fetch($result))
- {
- $sql = "UPDATE ".TB_PREF."supp_trans SET alloc=alloc - " . $row['amt'] . "
- WHERE (type= " . $row['trans_type_from'] . " AND trans_no=" . $row['trans_no_from'] . ")
- OR (type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'] . ")";
- //$sql = "UPDATE ".TB_PREF."supp_trans SET alloc=alloc - " . $row['amt'] . "
- // WHERE type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'];
+ $sql = "UPDATE ".TB_PREF."supp_allocations ca
+ LEFT JOIN ".TB_PREF."supp_trans paym ON ca.trans_type_from=paym.type AND ca.trans_no_from=paym.trans_no
+ LEFT JOIN ".TB_PREF."supp_trans st ON ca.trans_type_to=st.type AND ca.trans_no_to=st.trans_no
+ LEFT JOIN ".TB_PREF."purch_orders po ON ca.trans_type_to=".ST_PURCHORDER." AND ca.trans_no_to=po.order_no
+ SET paym.alloc=paym.alloc - ca.amt,
+ st.alloc=st.alloc - ca.amt,
+ po.alloc=po.alloc - ca.amt
+ WHERE (ca.trans_type_from=".db_escape($type)." AND ca.trans_no_from=".db_escape($type_no).")
+ OR (ca.trans_type_to=".db_escape($type)." AND ca.trans_no_to=".db_escape($type_no).")";