<?php
/**********************************************************************
***********************************************************************/
function add_loan_installment($loan_id, $installment_amount, $interest_amount, 
                                $payroll_run_id = 0, $comments = "", $status_code = "")
{
	$created_by = $_SESSION['wa_current_user']->user;
	$created_on = date('Y-m-d H:i:s');
        
        $sql = "INSERT INTO ".TB_PREF."loan_installments (
                    loan_id, payroll_run_id, 
                    installment_amount, interest_amount, 
                    comments, status_code, 
                    created_by, created_on) 
		VALUES ("
                .db_escape($loan_id).", ".db_escape($payroll_run_id).", "
                .db_escape($installment_amount).", ".db_escape($interest_amount).", "
                .db_escape($comments).", ".db_escape($status_code).", "
                .db_escape($created_by).", ".db_escape($created_on).")";
	
	db_query($sql,"Loan installment could not be added");		
}

function get_loan_installments($loan_id)
{
    $sql = "SELECT * 
            FROM ".TB_PREF."loan_installments                     
            WHERE status_code <> 'L' AND 
                    loan_id = ".db_escape($loan_id);
        
	//$sql .= " ORDER BY id";
        
    $result =  db_query($sql, "Loan installments could not be retrieved");
    
    return $result;

}


function get_loan_total_paid_amount($loan_id)
{
    $sql = "SELECT * 
            FROM 
                ".TB_PREF."vw_loan_installments 
            WHERE 
		loan_id = ".db_escape($loan_id);
        
	//$sql .= " ORDER BY id";
        
    $result =  db_query($sql, "Loan total paid amount could not be retrieved");
    
    return db_fetch($result);

}
?>