<?php


function get_sql_for_fixed_deposits_inquiry($from_date, $to_date, $bank_account_id)
{        
    $sql = "SELECT fd.id,
                    fd.name,
                    fd.description,
                    fd.amount,
                    fd.start_date,
                    fd.end_date,
                    fd.interest,
                    lv.value_name bank_name,
                    bb.branch_name,
                    ba.bank_account_name,
                    fd.security_type_id,
                    fd.security_id,
                    fd.lien_amount,
                    fd.matured,
                    fd.original_fixed_deposit_id

            FROM ".TB_PREF."fixed_deposits fd 
                LEFT JOIN ".TB_PREF."list_values lv ON
                    lv.id = fd.bank_id
                LEFT JOIN ".TB_PREF."bank_branches bb ON
                    bb.id = fd.branch_id
                LEFT JOIN ".TB_PREF."bank_accounts ba ON
                    ba.id = fd.bank_account_id 
                    
            WHERE ((fd.start_date >=".db_escape(date2sql($from_date))." AND fd.start_date <=".db_escape(date2sql($to_date)).") OR       
                    (fd.end_date >=".db_escape(date2sql($from_date))."AND fd.end_date <=".db_escape(date2sql($to_date))."))";     
        
    if($bank_account_id > 0)
    {
        $sql .= " AND fd.bank_account_id =".db_escape($bank_account_id);            
    }  

    return $sql;
        
}



?>
