+//-------------------------------------------------------------------------------------------------------------
+
+function get_allocatable_to_supp_transactions($supplier_id=null, $trans_no=null, $type=null)
+{
+ $sql = "SELECT
+ trans.type,
+ trans.trans_no,
+ IF(trans.supp_reference='',trans.reference,trans.supp_reference) as reference,
+ trans.tran_date,
+ supplier.supp_name,
+ supplier.curr_code,
+ ov_amount+ov_gst+ov_discount AS Total,
+ trans.alloc,
+ trans.due_date,
+ trans.supplier_id,
+ amt,
+ supp_reference
+
+ FROM ".TB_PREF."supp_trans as trans
+ LEFT JOIN ".TB_PREF."supp_allocations as alloc ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to,"
+ .TB_PREF."suppliers as supplier
+ WHERE
+ trans.supplier_id=supplier.supplier_id";
+ if ($supplier_id)
+ $sql .= " AND supplier.supplier_id=".db_escape($supplier_id);
+
+ if ($trans_no != null and $type != null)
+ {
+ $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)."
+ AND alloc.trans_type_from=".db_escape($type);
+ }
+ else
+ {
+ $sql .= " AND round(ov_amount+ov_gst+ov_discount-alloc,6) > 0
+ AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT, ST_BANKPAYMENT)).")";
+ $sql .= " GROUP BY type, trans_no";
+ }