<?php

function get_fi_supplier_payments($trans_type, $cutoff_date, $batch_size)
{
    $sql = "SELECT st.trans_no, 
                    st.type, 
                    st.supplier_id, 
                    st.tran_date, 
                    st.ov_amount, 
                    st.ov_discount, 
                    st.ov_gst, 
                    st.rate,  
                    st.float_id,  
                    sup.purchase_account, 
                    sup.payable_account, 
                    sup.payment_discount_account, 
                    sup.curr_code 
                    
            FROM ".TB_PREF."supp_trans st  
                JOIN ".TB_PREF."suppliers sup 
                    ON st.supplier_id = sup.supplier_id 
                    
            WHERE st.tran_date <= ".db_escape($cutoff_date)."  
                    AND st.type = ".db_escape($trans_type)."  
                    AND st.fi_batch_no = 0 
                    
            ORDER BY st.trans_no LIMIT ".$batch_size;

    return db_query($sql, "get_fi_supplier_payments");
}

function get_fi_supplier_payments_bank_transaction($trans_type, $trans_no)
{
    $sql = "SELECT bt.bank_act,
                    bt.amount,
                    ba.account_code 
            FROM ".TB_PREF."bank_trans bt 
                JOIN ".TB_PREF."bank_accounts ba 
                    ON bt.bank_act = ba.id 
            WHERE bt.type = ".db_escape($trans_type)." 
                    AND bt.trans_no = ".db_escape($trans_no);            
                    

    $result = db_query($sql, "get_fi_supplier_payments_bank_transaction");
    
    return db_fetch($result);
}
