<?php

function get_fi_company_loan_repayments($cutoff_date, $batch_size)
{
    $sql = "SELECT pay.id,
                pay.loan_id,
                pay.payment_amount,
                pay.payment_interest_amount,
                pay.late_interest_amount,
                pay.tran_date,
                pay.bank_account_id,
                pay.is_return,
                cl.loan_account,
                cl.interest_account,
                cl.late_interest_account,
                ba.account_code 

            FROM ".TB_PREF."company_loan_payments pay 
                JOIN ".TB_PREF."company_loans cl  
                    ON cl.id = pay.loan_id   
                JOIN ".TB_PREF."bank_accounts ba 
                    ON ba.id = pay.bank_account_id

            WHERE pay.tran_date <= ".db_escape($cutoff_date)."  
                    AND pay.fi_batch_no = 0 
            ORDER BY pay.id 
            LIMIT ".$batch_size;
    
    return db_query($sql);
}

