+// Update debtor trans alloc field according to current status of cust_allocations
+//
+function update_debtor_trans_allocation($trans_type, $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);
+
+ db_query($sql, "The debtor transaction record could not be modified for the allocation against it");
+}