<?php
class Loan_Due_Process_Model extends CI_Model {
	 private $tableName = 'loan_panalty';
  
  
  function __construct() 
  {
   		/* Call the Model constructor */
    	parent::__construct();
        $this->load->database();
        $this->load->helper('url');
        //$this->load->library(array('email'));
  }
 
	function ssss($loan_id,$data)
	{		
		$this->db->where('loan_id', $loan_id);
		return $this->db->update('loan_panalty',$data);
		
	}
	
	function save_today_due($data)
	{
		if ($data)
		{			
			return $this->db->insert('loan_due_amount',$data);
		}else{
			return false;	
		}
	}
   
   
    function getLoan_approved_issued($today)
   {
	   $this->db->select('b.*,c.cus_name');
	    $this->db->select('mpt.payment_term_name');
       $this->db->from('loan b');
	   $this->db->join('warehouses w', 'w.id = b.warehouse_id', 'left');
	   $this->db->join('customer c', 'c.cus_id = b.cus_id', 'inner');
	    $this->db->join('mstr_payment_terms mpt', 'mpt.id = b.loan_payment_term', 'left');
	    $this->db->where("b.approval_status",1);
	    $this->db->where("b.enable_due",1);
		$this->db->where("b.loan_issue_status",1);
		$this->db->where("b.is_closed",0);
		$this->db->where("b.loan_close_date <=",$today);
	   //$this->db->order_by("b.loan_id", "desc");
	   $query = $this->db->get();	  
     if($query->num_rows() >0)
     {
       return $query->result();
     }
     else
     {
       return false;
     }
   }
   
   
   
   	function get_loan_due_by_loan_id($loan_id) {
		$this->db->select('loan_due_amount.*');
		$this->db->from('loan_due_amount');
		$this->db->order_by("loan_due_amount.system_date_time", "desc");
		$this->db->where("loan_due_amount.loan_id",$loan_id);
		$query = $this->db->get();
		return $query->result();
	}
	
	function get_loan_due_sum_by_loan_id($loan_id) {
		$this->db->select_sum('loan_due_amount.due_amount');
		$this->db->from('loan_due_amount');
		$this->db->where("loan_due_amount.loan_id",$loan_id);
		$this->db->where("loan_due_amount.is_removed",0);
		$query = $this->db->get();
		return $query->row_array();
	}
   
   
   
   
   
   
   
   
   
   
}