<?php

function get_fi_customer_payments($trans_type, $cutoff_date, $batch_size)
{
    $sql = "SELECT dt.trans_no, 
                    dt.tran_date,
                    dt.due_date,
                    dt.ov_amount,
                    dt.ov_gst,
                    dt.ov_freight,
                    dt.ov_freight_tax,
                    dt.ov_discount,
                    dt.debtor_no,
                    dt.project_id,
                    dt.rate,
                    cb.sales_account,
                    cb.sales_discount_account,
                    cb.receivables_account,
                    cb.payment_discount_account,
                    dm.curr_code 
            FROM ".TB_PREF."debtor_trans dt    
                JOIN ".TB_PREF."debtors_master dm ON 
                    dt.debtor_no = dm.debtor_no  
                JOIN ".TB_PREF."cust_branch cb ON 
                    dt.branch_code = cb.branch_code    
           WHERE dt.type = ".db_escape($trans_type)." 
               AND dt.tran_date <= ".db_escape($cutoff_date)."    
                    AND dt.fi_batch_no = 0 
            ORDER BY dt.trans_no LIMIT ".$batch_size ;

    return db_query($sql);
}

function get_fi_customer_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);
    
    return db_fetch($result);
}




