<?php
class Cheque_Manage_Model extends CI_Model {
	 private $tableName = 'loan';
  
  
  function __construct() 
  {
   		/* Call the Model constructor */
    	parent::__construct();
        $this->load->database();
       // $this->load->helper('url');
        //$this->load->library(array('email'));
  }
 
	function update_cheque_status($pay_id,$data)
	{		
		if($pay_id){
		$this->db->where('paymnt_id', $pay_id);
		return $this->db->update('loan_payment',$data);
		}
		else
		{
			return 0;
		}
		
	}
	
	 function get_all_pending_realize_cheque($wh,$route,$cus_id,$srh_from_date,$srh_to_date)
   {
	   
	   //print_r($srh_from_date);
	$this->db->select('lp.*');
	$this->db->select('c.cus_name');
	$this->db->select('l.loan_ref');
	$this->db->select('b.bank_code');
	$this->db->select('r.route_name');
	$this->db->from('loan_payment lp');
	 $this->db->join('customer c', 'c.cus_id = lp.cus_id', 'left');
	 $this->db->join('loan l', 'l.loan_id = lp.loan_id', 'left');
	 $this->db->join('mstr_bank b', 'b.bank_id = lp.bank_id', 'left');
	 $this->db->join('routes r', 'r.route_id = lp.route_id', 'left');
	$this->db->where('lp.pymnt_paying_by','Cheque');
	$this->db->where('lp.pymnt_returned',0);	
	$this->db->where('lp.pymnt_realize',0);
	//$this->db->where('lp.pymnt_deposited',0);
	$this->db->where('lp.pymnt_collected',1);	
	 if($route){	   
	   $this->db->where("b.route_id",$route);//
	   }
	    if($cus_id){	   
	   $this->db->where("lp.cus_id",$cus_id);//
	   }
	    if($srh_from_date){	   
	    $this->db->where("lp.pymnt_cheque_date >=",$srh_from_date);
	   }
	   if($srh_to_date){	   
	    $this->db->where("lp.pymnt_cheque_date <=",$srh_to_date);
	   }
	   
	   
	   
	   
	  
	
	
	
	
	$query = $this->db->get();
	return $query->result_array(); 
	   
   }
   

    function get_loan_paid_total_by_loan_id($loan_id)
   {
	$this->db->select_sum('pymnt_amount');
	$this->db->from('loan_payment');
	$this->db->where('loan_payment.pymnt_returned',0);	
	$this->db->where('loan_payment.loan_id',$loan_id);
	$query = $this->db->get();
	return $query->row_array(); 
	   
   }
   
  
  
  
   
   
}