- $sql = "UPDATE ".TB_PREF."debtor_trans SET alloc = alloc + $alloc
- WHERE type=".db_escape($trans_type)." AND trans_no = ".db_escape($trans_no);
+ $sql = "UPDATE `".TB_PREF."debtor_trans` trans,
+ (SELECT sum(amt) amt from ".TB_PREF."cust_allocations
+ WHERE (trans_type_to=".db_escape($trans_type)." AND trans_no_to=".db_escape($trans_no).")
+ OR (trans_type_from=".db_escape($trans_type)." AND trans_no_from=".db_escape($trans_no).")) allocated
+ SET
+ trans.alloc=IFNULL(allocated.amt,0)
+ WHERE trans.type=".db_escape($trans_type)." AND trans_no=".db_escape($trans_no);
+