<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Accomodationmodel extends CI_Model {


function insertPlot($data)
    {
		return $this->db->insert('plot', $data);
	}
	function insertPlotCharges($data)
    {
		return $this->db->insert('plotcharges', $data);
	}
	
	function populateallplots(){
 

  $this -> db -> select('*');

   $this -> db -> from('plot');

$this->db->order_by("id", "ASC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function getstatementbypenalty($plotno,$houseno,$fromdate,$todate,$type,$tenantid){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
 	  $this->db->where('tenantid',$tenantid);

	  $this->db->where('type',$type);
	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);
	 	 $this->db->select('paid, SUM(paid) AS paid', FALSE);

//$this->db->where("( SUM(paid) AS paid )", NULL, FALSE);

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

$this->db->group_by('tenantid');
 $this->db->group_by('houseno');
 $this->db->group_by('type');
 $query1 = $this -> db -> get();


 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}




  
   	public function searchroomscleanedandsold($fromdate,$enddate,$companyid) {
      
	$this->db->select("  * ,counter, SUM(counter) AS counter ");

	
	  
	          //$this->db->limit($limit, $start);
	  	 $this->db->where('exactdate >=', $fromdate);
			$this->db->where('exactdate <=',$enddate);

			
	  
	
	  
	  			$this->db->where('companyid', $companyid);
	  			//	$this->db->where("(  dateposted BETWEEN '$startdate'  and '$enddate' and companyid='$companyid'   )", NULL, FALSE);


	  
				
				 $this->db->order_by('exactdate','asc');
				  $this->db->order_by('id','asc');
	$this->db->group_by('housekeeping.userid');

        $query = $this->db->get("housekeeping");

    
 if($query -> num_rows() >0)

   {
  return $query->result();

   }

   else

   {

     return false;

   }
   }
   
   
   


   
   
   	public function searchroomsallocated($fromdate,$enddate,$companyid) {
      

	
	  
	          //$this->db->limit($limit, $start);
	  	 $this->db->where('exactdate >=', $fromdate);
			$this->db->where('exactdate <=',$enddate);

			
	  
	
	  
	  			$this->db->where('companyid', $companyid);
	  			//	$this->db->where("(  dateposted BETWEEN '$startdate'  and '$enddate' and companyid='$companyid'   )", NULL, FALSE);


	  
				
				 $this->db->order_by('exactdate','asc');
				  $this->db->order_by('id','asc');
	$this->db->group_by('asignrooms.userid');

        $query = $this->db->get("asignrooms");

    
 if($query -> num_rows() >0)

   {
  return $query->result();

   }

   else

   {

     return false;

   }
   }
   
   
   




   
   	public function searchroomscleaned($fromdate,$enddate,$companyid,$user) {
      
	$this->db->select("  * ,counter, SUM(counter) AS counter ");

	
	  
	          //$this->db->limit($limit, $start);
	  	 $this->db->where('exactdate >=', $fromdate);
			$this->db->where('exactdate <=',$enddate);

						if($user!="all") {
			$this->db->where('userid', $user);
		
				}
	  
	
	  
	  			$this->db->where('companyid', $companyid);
	  			//	$this->db->where("(  dateposted BETWEEN '$startdate'  and '$enddate' and companyid='$companyid'   )", NULL, FALSE);


	  
				
				 $this->db->order_by('exactdate','asc');
				  $this->db->order_by('id','asc');
	$this->db->group_by('housekeeping.plotno');
$this->db->group_by('housekeeping.houseno');


        $query = $this->db->get("housekeeping");

    
 if($query -> num_rows() >0)

   {
  return $query->result();

   }

   else

   {

     return false;

   }
   }
   
   
   













      function uploadhouse($data)
{
// Query to insert data in database
  $plotno = $data['plotno'];
    $houseno = $data['houseno'];
   $this -> db -> select("* from house where plotno='$plotno' and houseno='$houseno' ");
  $this -> db -> limit(1);
   $query = $this -> db -> get();
  if($query -> num_rows() == 0)

   {

    $this->db->insert('house', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }

   }

   else

   {
	   
return $plotno;
return $houseno;
     return false;

   }


}





function tenantavailableonly222($plotno,$houseno) 
{
			$this->db->select("  * ,house.id  AS roomid ");

          $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('status','active');
	$this -> db -> limit(1);
	 $this->db->order_by("id", "DESC");

		$this->db->join('house', 'bookroom.plotno = house.plotno  and  bookroom.houseno = house.houseno ',   'INNER JOIN');

	
	 

        $query = $this->db->get($database);

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }
	
	
	













function tenantavailableonly($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('status','active');
	$this -> db -> limit(1);
	 $this->db->order_by("id", "DESC");
	$tenantquery = $this->db->get('bookroom');
 if($tenantquery->num_rows()>0){

   return $tenantquery->result();
   

    
   } else {
     
          return false;
   }
}







function insertHouse($data)
    {
		return $this->db->insert('house', $data);
	}
	
	function populateallHouses(){
 

  $this -> db -> select('*');

   $this -> db -> from('house');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
	function populateallcountries(){
 

  $this -> db -> select('*');

   $this -> db -> from('nation');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
function gethousebyid($id){

if($id!=null){
$this->db->select(" * from  house where plotno= '$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



function getallhousebystatusid($id){

if($id!=null){

	
$this->db->select(" * from  house where plotno= '$id' ");

	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}





function gethousearreas($plotno,$houseno,$tenantid,$type,$fromdate){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
 
		  $this->db->where('tenantid',$tenantid);

	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
	   	   $this->db->where('type',$type);
	 $this->db->where('createdat <',$fromdate);
//$this->db->where("( amount > paid  )", NULL, FALSE);

	 $this->db->select('amount, SUM(amount) AS myamount', FALSE);
	 $this->db->select('paid, SUM(paid) AS mypaid', FALSE);

$this->db->group_by('houseno');
$this->db->group_by('tenantid');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function getplothouseinvoicewithbalance($plotno,$houseno,$tenantid,$fromdate,$display){
 

  $this -> db -> select('*');
   $this->db->select('amount, SUM(amount) AS myamount', FALSE);
	 $this->db->select('paid, SUM(paid) AS mypaid', FALSE);

   $this -> db -> from('invoice');
 
		  $this->db->where('tenantid',$tenantid);
	 $this->db->where('createdat < ',$fromdate);
//$this->db->where("( createdat < '$fromdate'  )", NULL, FALSE);

	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
	 // $this->db->where('amount','>paid');
//$this->db->where("( amount > paid  )", NULL, FALSE);
if($display !="all"){
$this->db->where('type', 1);
	
}
$this->db->group_by('plotno');
	
$this->db->group_by('houseno');
$this->db->group_by('tenantid');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function gettenantallbookings($tenantid){

if($tenantid!=null){
$this->db->select(" * from  bookroom inner join house  on bookroom.plotno= house.plotno and bookroom.houseno= house.houseno  inner join plot on bookroom.plotno=plot.id where tenantid= '$tenantid' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}


function getotherstatementrental($plotno,$fromdate,$todate){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
    
	  $this->db->where("( type!='1' )", NULL, FALSE);
	  $this->db->where("( type!='4' )", NULL, FALSE);
	  
	  $this->db->where('plotno',$plotno);
	  $this->db->where('createdat >=', $fromdate);
			$this->db->where('createdat <=', $todate);
	 $this->db->select('paid, SUM(paid) AS paid', FALSE);
	  $this->db->select('coparent, SUM(coparent) AS coparent', FALSE);
	  $this->db->select('amount, SUM(amount) AS amount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
$this->db->group_by('type');
//$this->db->group_by('houseno');


//$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}




function tenantavailablenoarray($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('status','active');
	$this -> db -> limit(1);
	 $this->db->order_by("id", "DESC");
	$tenantquery = $this->db->get('bookroom');
 if($tenantquery->num_rows()>0){

   return $tenantquery->result_array();
   

    
   } else {
     
          return false;
   }
}



function gethousebystatusid($id,$status){

if($id!=null){
	if($status=="all"){
	
$this->db->select(" * from  house where plotno= '$id' ");
	}else{
		
	$this->db->select(" * from  house where plotno= '$id' and status= '$status' ");
	
	}
	
	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

function getplothousebystatusid($plotno,$houseno){

if($plotno!=null){
$this->db->select(" * from  house where plotno= '$plotno' and houseno= '$houseno' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

function getplothousebyallstatusid($plotno,$houseno){

if($plotno!=null){
$this->db->select(" * from  house where plotno= '$plotno' and houseno= '$houseno' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}
function getplotbyallstatusid($plotno){

if($plotno!=null){
$this->db->select(" * from  plot where id= '$plotno'  ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}

function gethousebyplotbyid($id){

if($id!=null){
$this->db->select(" * from  house where plotno= '$id' and status='vacant'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



function populatehouseidvacant ($id,$transactiontype){

if($id!=null){
	if($transactiontype=="reserved"){
				$this->db->select(" * from  house where plotno= '$id' ");

	}else{
		$this->db->select(" * from  house where plotno= '$id' and status='vacant' ");

	}

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}




function gethousebyplotid ($id){

if($id!=null){
$this->db->select(" * from  house where plotno= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}











function gettransactionid($id){

if($id!=null){
$this->db->select(" * from  people where transactionid= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}





function gethousebno($id){

if($id!=null){
$this->db->select(" * from  house where houseno= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}


function getbookingbytenant($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  bookroom where 	houseno= '$houseno' and plotno='$plotno' and status='active' ");
 $this->db->order_by("id", "DESC");
$bioquery = $this -> db -> get();
	$this -> db -> limit(1);
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}



function gethousedetailsbytenetid($plotno,$houseno,$tenantid){

if($houseno!=null){
$this->db->select(" * from  bookroom where plotno= '$plotno' and houseno= '$houseno' and  tenantid= '$tenantid' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}






	
  	function pushroomsms($mainmessage,$maincontact,$myview)
	{
 
		
			$session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
         $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
		 //$userid = $data['id'];
		 	 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 		
		 		// $contact = trim($this->input->post("contact"));
				
				
				
				
				
					$configuration= $this->usermodel->populateallarray('smsconfig','id',$companyid);




				$userid=$configuration[0]["paymenttypes"];

		$sigature=$configuration[0]["sigature"];

	if($sigature!=""){
		
		$mainmessage=$mainmessage. " ".$sigature;
	}else{
				$mainmessage=$mainmessage;
	}
				
				
				
				
				
				
				
				
				
				
				
				
				
								$contact = htmlspecialchars(trim($maincontact));

		   	  $mymessage = trim($mainmessage);
			
				
				
				
				
				
			
			// htmlspecialchars($_POST['firstname'])
			 $message = htmlspecialchars($mymessage);
			 
			 
			
			 
			
			 
			 
						   
				
					 
			
				// $xml = "<smslist><sms><user>robiseach</user><password>r12345</password><message>Hi robert Manyala</message><mobiles>25418667391</mobiles><senderid>INFOTEXT</senderid><cdmasenderid>00201009546244</cdmasenderid><group>-1</group><clientsmsid>0</clientsmsid><accountusagetypeid>1</accountusagetypeid></sms></smslist>";

			
			$myArray = explode(',', $contact);
foreach($myArray as $allcontacts){
			    $confirmaccount_result = $this->usermodel->confirmaccount($userid);
$totalsms=$confirmaccount_result[0]['totalsms'];
$apiid=$confirmaccount_result[0]['companyid'];
//$stop=$confirmaccount_result[0]['stop'];

						   
						   $countmessage =strlen($message);
					 $COST="";
				 if($countmessage<=144){
				
					$COST=1;
				 }else if($countmessage<=304){
					 
					$COST=2;
				 }else if($countmessage<=464){
					$COST=3;
					
				 }
				 else if($countmessage<=624){
					$COST=4;
				
				 }
				 else if($countmessage<=784){
					 $COST=5;
					
				 }
												if($confirmaccount_result[0]['totalsms']< $COST){
			
			
			 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error!</strong> Your account has insufficient balance . Please recharge and try again</div>');
								
								 //redirect($myview);
		}else{
			
			 $confirmsmsaccount_result = $this->usermodel->confirmasmsccount($apiid);
$username=$confirmsmsaccount_result[0]['username'];
$from=$confirmsmsaccount_result[0]['from'];
$password=$confirmsmsaccount_result[0]['password'];
		  
		
   // echo $my_Array.'<br>';  

												$data=array(		
			'userid'=>$userid,
			
				'contact'=>$allcontacts,
			
		  	'message'=>$message,
			
			'companyid'=>$companyid,
			'postedtime'=>$dateposted,
				
			
								);
									
		
			
			
			
			
			$finalURL = "https://sms.bulksmschapchap.com/api/services/sendsms/?apikey=" . urlencode($password) . "&partnerID=" . urlencode($username) . "&message=" . urlencode($message) . "&shortcode=$from&mobile=$allcontacts";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $finalURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
$finalcode="";

			    if ($output != null) {
        $responseData = json_decode($output, TRUE);


	
	 if(isset($responseData["responses"][0]["response-description"])){
	$finalcode=$responseData["responses"][0]["response-description"];

	} 
	if(isset($responseData["response-description"])){
		
		$finalcode=$responseData["response-description"];
		
	}
 

				if($finalcode=="Success"){
	$usr_result = $this->usermodel->add($data,'sms');
				
					 $countmessage =strlen($message);
				 if($countmessage<=144){
					$finaltotalsms=$totalsms-1;
				 }else if($countmessage<=304){
					 
					$finaltotalsms=$totalsms-2;
				 }else if($countmessage<=464){
					 $finaltotalsms=$totalsms-3;
					
				 }
				 else if($countmessage<=624){
					 $finaltotalsms=$totalsms-4;
				
				 }
				 else if($countmessage<=784){
					 $finaltotalsms=$totalsms-5;
					
				 }

				$usr_result2 = $this->usermodel->updateusersms($userid,$finaltotalsms);
			}
				
						
			} else {

				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error occurred during Sending Message!</strong> Please check on your internet connection or balance.Try again </div>');
								// redirect($myview);
				}
				
			
}
}
			
				if($finalcode=="Success"){	
			
				
				$this->session->set_flashdata('msg','<div class="alert alert-success text-center">sms   is sent Successfully ! !!!</div>');
					
			
								// redirect($myview);
			}else{
				
				
				$this->session->set_flashdata('msg', '<div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>
						  <strong>Error occurred during Sending Message!</strong> '.$finalcode .' .SMS  not Sent to  '.$allcontacts .' <a href=' .base_url(). 'user/viewsms> clicke here to go back  </a> </div>');
								 //redirect($myview);

			}
			
			
			


						   
						   
						   
						   
						   
			
							
							//check if username and password is correct
			
					  
	    
    }
  
  
  
  
  
  




function gethousedetailsActive($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  house where plotno= '$plotno' and houseno= '$houseno' and status= 'occupied' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}


function gethousedetails($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  house where plotno= '$plotno' and houseno= '$houseno'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}

function getbulkhousedetails($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  house where plotno= '$plotno' and houseno= '$houseno'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}








function getrentalhouseinvoice($plotno,$houseno,$tenantid){






if($houseno!=null){
$this->db->select(" * from  receipt where plotno= '$plotno' and houseno= '$houseno' and paymentstatus ='invoice' and tenantid ='$tenantid'   ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



	public function getrentalutilitiestenant($fromdate,$todate,$plotno,$tenantid) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}
$this->db->where('tenantid', $tenantid);

$this->db->from("invoice");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }










	public function getrentalutilitiespaymets($fromdate,$todate,$plotno,$paymentstatus,$charges) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

$this->db->where('paymentdate >=', $fromdate);
$this->db->where('paymentdate <=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}
if($charges !="all"){
$this->db->where('type', $charges);
	
}

$this->db->from("utilityinvoice");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }












	public function getrentalutilities($fromdate,$todate,$plotno,$paymentstatus,$charges) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}
if($charges !="all"){
$this->db->where('type', $charges);
	
}

$this->db->from("invoice");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }



	public function searchfordepositreport($fromdate,$todate,$plotno,$paymentstatus) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}


$this->db->from("depositrefunds");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }

	
		public function getrentalleinvoice($fromdate,$todate,$plotno,$paymentstatus) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}

if($paymentstatus!="all Statement"){
	$this->db->where('paymentstatus', $paymentstatus);

}
$this->db->from("receipt");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }





           function uploadalltenants2($data)
{
// Query to insert data in database
  $idno = $data['idno'];

   $this -> db -> select("* from people where idno='$idno'");

   $query = $this -> db -> get();
  if($query -> num_rows() == 0)

   {

    $this->db->insert('people', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
		     return false;
  
	  }

   }

  


}


	
		public function searchatenatstatment($fromdate,$todate,$tenantid,$paymentstatus,$plotno) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}
$this->db->where('tenantid', $tenantid);

if($paymentstatus!="all Statement"){
	$this->db->where('paymentstatus', $paymentstatus);

}
$this->db->from("receipt");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }






		public function getrentbalancesbytenant($tenatid) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

//$this->db->where('createdat >=', $fromdate);
//$this->db->where('createdat <=', $todate);

//$this->db->where('plotno', $plotno);

//$this->db->where('houseno', $houseno);
$this->db->where('tenantid', $tenatid);

$this->db->where('totalamount >', 0);

$this->db->from("bookroom");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }















		public function getrentbalances($fromdate,$todate,$plotno,$status,$type) {

		//	$this->db->select("  * ,glaccounts.description, debitcredit.description AS mydescription,debitcredit.id AS id  ");

//$this->db->where('createdat >=', $fromdate);
//$this->db->where('createdat <=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}

if($status !="all"){
$this->db->where('status', $status);
	
}
if($type=="balances"){
	
	$this->db->where('totalamount >', 0);

}
if($type=="deposit"){
	$this->db->where('deposite >', 0);

	
}
if($type=="overpayment"){
	$this->db->where('overpayment >', 0);

	
}

$this->db->from("bookroom");
 $this->db->order_by("id", "DESC");



			$query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }



















function gethouseinvoice($plotno,$houseno,$tenantid){

if($houseno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno' and houseno= '$houseno' and paymentstatus ='invoice' and tenantid ='$tenantid'   ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}






function getbulkhouseentalinvoice($plotno){

if($plotno!=null){
	
$this->db->select(" * from  invoice where plotno= '$plotno'  and paymentstatus ='invoice'");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}






function getbulkhouseinvoice($plotno){

if($plotno!=null){

$this->db->select(" * from  receipt where plotno= '$plotno'  and paymentstatus ='invoice'");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}








function gethouseinvoicepayment($plotno,$houseno,$status,$fromdate,$todate){




	if(($status=="none")&&($plotno=="all")){
$this->db->select(" * from  invoice where  createdat BETWEEN '$fromdate'  and '$todate' ");
	}else if(($status=="none")&&($plotno!="all")){
$this->db->select(" * from  invoice where   plotno= '$plotno'   and createdat BETWEEN '$fromdate'  and '$todate' ");
	}
	
	else if(($status!="none")&&($plotno!="all")){
$this->db->select(" * from  invoice   where plotno= '$plotno' and paymentstatus ='$status'  and createdat BETWEEN '$fromdate'  and '$todate' ");
	}
	else if(($plotno=="all")&&($status!="none")){
$this->db->select(" * from  invoice   where  paymentstatus ='$status'  and createdat BETWEEN '$fromdate'  and '$todate' ");
	}

else if(($plotno!="")&&($houseno!="")){
$this->db->select(" * from  invoice where plotno= '$plotno' and houseno= '$houseno' and createdat BETWEEN '$fromdate'  and '$todate' ");
	}
	
		 $this->db->order_by('id','desc');

	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}
function confirmname1($name){

if($code!=null){
$this->db->select(" * from charges where type='$type' ");

$n = $this -> db -> get();
if($n->num_rows()>0){

  return true;
}else{

  return false;
}

}


}



function getmyhousebooingsandroomscleaned($plotno,$houseno,$companyid,$fromdate,$todate){
	
	 	$this->db->select("  booings, SUM(booings) AS booings ");
$this->db->from("bookroom");


if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}

if($houseno!="all"){
	$this->db->where('houseno', $houseno);
	
	
}

	
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);



 $this->db->group_by('plotno');
$this->db->group_by('houseno');


$bioquery = $this -> db -> get();
		
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}




function viewsalesandexpenses($plotno,$companyid,$branchid,$fromdate,$todate){
	
	 	$this->db->select("  total, SUM(total) AS total ");
$this->db->from("bookroom");


if($plotno !="all"){
$this->db->where('companyid', $plotno);
	
}

$this->db->where('companyid', $companyid);


	
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);



 $this->db->group_by('companyid');


$bioquery = $this -> db -> get();
		
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}







function getmyhouseinvoicepayment($plotno,$houseno,$user,$fromdate,$todate,$category){
	
		$this->db->from("bookroom");

	
//$this->db->where('createdat < ', $fromdate );
//$this->db->where('checkoutdate >=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}

if($houseno!="all"){
	$this->db->where('houseno', $houseno);

}



if($category=="active"){
	$this->db->where('status', $category);

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

}  
if($category=="reserved"){
	$this->db->where('status', $category);
	$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);


}  


if($category=="inactive"){
	$this->db->where('status', $category);
$this->db->where('checkoutdate >=', $fromdate);
$this->db->where('checkoutdate <=', $todate);

}
if($category=="pactive"){
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

}
if($category=="pinactive"){
$this->db->where('checkoutdate >=', $fromdate);
$this->db->where('checkoutdate <=', $todate);

}

if($category=="all"){
	
	//$this->db->where('userid', $user);
	
	$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

}



if($user!="all"){
	$this->db->where('userid', $user);

}




	 $this->db->order_by('id','desc');

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}
















function getmyhouseinvoicepaymentCombined($plotno,$houseno,$user,$fromdate,$todate,$category,$tenantid,$chargeid){
	
		$this->db->from("bookroom");

	
//$this->db->where('createdat < ', $fromdate );
//$this->db->where('checkoutdate >=', $todate);
if($plotno !="all"){
$this->db->where('plotno', $plotno);
	
}

if($houseno!="all"){
	$this->db->where('houseno', $houseno);

}

if($tenantid!="all"){
	
	$this->db->where('tenantid', $tenantid);

}



if($category=="active"){
	$this->db->where('status', $category);

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

}  
if($category=="reserved"){
	$this->db->where('status', $category);
	$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);


}  


if($category=="inactive"){
	$this->db->where('status', $category);
$this->db->where('checkoutdate >=', $fromdate);
$this->db->where('checkoutdate <=', $todate);

}
if($category=="pactive"){
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

}
if($category=="pinactive"){
$this->db->where('checkoutdate >=', $fromdate);
$this->db->where('checkoutdate <=', $todate);

}

if($category=="all"){
	
	//$this->db->where('userid', $user);
	
	$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

}



if($user!="all"){
	$this->db->where('userid', $user);

}

if($chargeid !="all"){
	$this->db->where('chargeid', $chargeid);

}


	 $this->db->order_by('id','desc');

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}





function getmyhousepaymentbycustomer($plotno,$tenantid,$fromdate,$todate,$daterange,$branchid)
{



$this->db->where('branchid', $branchid);

if($daterange=="yes"){
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
	
}

$this->db->where('credit > ',0);

$this->db->order_by('createdat','DESC');

$this->db->from('bookroom');





	



$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}



}


	
	
	
	
	
	
	
	

















function getallhouseinvoicepayment($plotno,$houseno,$status,$fromdate,$todate){
 if(($houseno=="all")&& ($status=="all")&& ($plotno=="all")  ){
$this->db->select(" * from   bookroom where createdat BETWEEN '$fromdate'  AND '$todate' ");

	}else 
 if(($houseno=="all")&&  ($plotno=="all")  ){
$this->db->select(" * from   bookroom where  paymentstatus='$status' and createdat BETWEEN '$fromdate'  AND '$todate' ");

	}
	else 
 if(($houseno=="all")&&  ($plotno!="all") && ($status=="all")  ){
$this->db->select(" * from   bookroom where plotno='$plotno' and createdat BETWEEN '$fromdate'  AND '$todate' ");

	}
	else 
 if(($houseno=="all")&&  ($plotno!="all") && ($status!="all")  ){
$this->db->select(" * from   bookroom where plotno='$plotno' and  paymentstatus='$status' and createdat BETWEEN '$fromdate'  AND '$todate' ");

	}
	
		else {
			
			

$this->db->select(" * from   bookroom where plotno='$plotno' and  houseno='$houseno'  and  paymentstatus='$status' and createdat BETWEEN '$fromdate'  AND '$todate' ");

	}
		 $this->db->order_by('id','desc');

	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}




function confirmname($name){

if($code!=null){
$this->db->select(" * from charges where type='$type' ");

$n = $this -> db -> get();
if($n->num_rows()>0){

  return true;
}else{

  return false;
}

}


}

    

function confirmsmsconfig($id){

if($id!=null){
$this->db->select(" * from smsconfig where id='$id' ");

$n = $this -> db -> get();
if($n->num_rows()>0){

  return $n->result_array();
}else{

  return false;
}

}


}


function confirmnhouseno($id){

if($id!=null){
$this->db->select(" * from plot where id='$id' ");

$n = $this -> db -> get();
if($n->num_rows()>0){

  return $n->result_array();
}else{

  return false;
}

}


}


function getotherstatement($plotno,$status,$fromdate,$todate){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
     $this->db->where('paymentstatus',$status);
	  $this->db->where("( type!='RENT' )", NULL, FALSE);

	  $this->db->where('plotno',$plotno);
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
$this->db->group_by('type');
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

//$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}






function getplotreceiptallbyno($plotno,$houseno,$month,$year, $tenantid){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
     $this->db->where('paymentstatus','receipt');
	  //$this->db->where("( type!='RENT' )", NULL, FALSE);
 $this->db->where('houseno',$houseno);
	  $this->db->where('plotno',$plotno);
	  $this->db->where('month',$month);
	  $this->db->where('year',$year);
	   $this->db->where('tenantid',$tenantid);
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
$this->db->group_by('tenantid');


$this->db->order_by("id", "DESC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function getplotreceiptallbybalance($plotno,$houseno,$month,$year, $tenantid){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
   
	  //$this->db->where("( type!='RENT' )", NULL, FALSE);
 $this->db->where('houseno',$houseno);
	  $this->db->where('plotno',$plotno);
	  //$this->db->where('month',$month);
	  //$this->db->where('year',$year);
	   $this->db->where('tenantid',$tenantid);
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
$this->db->group_by('tenantid');


$this->db->order_by("id", "DESC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function getplotreceiptallbyype($plotno,$houseno,$month,$year, $tenantid){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
     $this->db->where('paymentstatus','receipt');
	  //$this->db->where("( type!='RENT' )", NULL, FALSE);
 $this->db->where('houseno',$houseno);
	  $this->db->where('plotno',$plotno);
	  $this->db->where('month',$month);
	  $this->db->where('year',$year);
	   $this->db->where('tenantid',$tenantid);
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
$this->db->group_by('type');


$this->db->order_by("id", "DESC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function getstatementbytype($plotno,$houseno,$fromdate,$todate,$type,$tenantid){
 

 // $this -> db -> select('*');
	 $this->db->select('amount, SUM(amount) AS amount,coparent, SUM(coparent) AS coparent,paid, SUM(paid) AS paid,vat, SUM(vat) AS vat,commission, SUM(commission) AS commission', FALSE);

   $this -> db -> from('invoice');
    // $this->db->where('paymentstatus',$status);
	  $this->db->where('type',$type);
	  $this->db->where('tenantid',$tenantid);
	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
$this->db->group_by('tenantid');
$this->db->group_by('type');
$this->db->group_by('plotno');
$this->db->group_by('houseno');

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}




function getallpayments($plotno,$houseno,$fromdate,$todate,$tenantid){
 

  $this -> db -> select('*');
	// $this->db->select('amount, SUM(amount) AS amount', FALSE);

   $this -> db -> from('receipt');
     $this->db->where('paymentstatus',"receipt");
$this->db->where('tenantid',$tenantid);
	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
//$this->db->group_by('paymentmode');
//$this->db->group_by('tenantid');
$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}




function getallinvoices($plotno,$houseno,$fromdate,$todate,$tenantid,$display){
 

  $this -> db -> select('*');
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);

   $this -> db -> from('invoice');
     $this->db->where('paymentstatus',"invoice");
$this->db->where('tenantid',$tenantid);
	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
if($display !="all"){
$this->db->where('type', 1);
	
}
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
$this->db->group_by('tenantid');
$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }

}



function getplotforbulkinvoice($day){


  $this -> db -> select('*');

   $this -> db -> from('plot');

$this->db->where('category', "rental");

$this->db->where('invoicedate <= ', $day);
$this->db->where('invoicedate <> ', "");

$this->db->order_by("id", "asc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}



function getplotforbulkpenaltyinvoice($day){


  $this -> db -> select('*');

   $this -> db -> from('plot');

$this->db->where('category', "rental");

$this->db->where('penaltydate <= ', $day);
$this->db->where('penaltydate <> ', "");

$this->db->order_by("id", "asc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}




function getplotforbulpenaltykinvoice($day){


  $this -> db -> select('*');

   $this -> db -> from('plot');

$this->db->where('category', "rental");

$this->db->where('invoicedate <= ', $day);
$this->db->where('invoicedate <> ', "");

$this->db->order_by("id", "asc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}




function getallpaid($plotno,$houseno,$fromdate,$tenantid){
 

 // $this -> db -> select('*');
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);

   $this -> db -> from('receipt');
     $this->db->where('paymentstatus',"receipt");
$this->db->where('tenantid',$tenantid);
	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);

$this->db->where('createdat < ', $fromdate);
$this->db->group_by('tenantid');
$this->db->group_by('plotno');
$this->db->group_by('houseno');
$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }

}





function getallinvoiceswithcodes($plotno,$houseno,$fromdate,$todate,$tenantid){
 

  $this -> db -> select('*');
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);

   $this -> db -> from('receipt');
     $this->db->where('paymentstatus',"invoice");
$this->db->where('tenantid',$tenantid);
	  $this->db->where('plotno',$plotno);
	   $this->db->where('houseno',$houseno);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);

$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);
$this->db->group_by('tenantid');
$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}








function getstatement($plotno,$status,$fromdate,$todate){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
     $this->db->where('paymentstatus',$status);
	  $this->db->where('type','RENT');
	  $this->db->where('plotno',$plotno);
	 $this->db->select('amount, SUM(amount) AS amount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
$this->db->group_by('tenantid');
$this->db->where('createdat >=', $fromdate);
$this->db->where('createdat <=', $todate);

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}



function getstatement2($plotno,$status,$fromdate,$todate){


	

$this->db->select(" * from  invoice where plotno= '$plotno'   and paymentstatus ='$status'  and createdat BETWEEN '$fromdate'  and '$todate' ");
	
	
	
	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}






function getstatementtenant($plotno,$fromdate,$todate,$display){


	  if($display=="payment"){

		$this->db->select(" *,paymentcode,coparent, SUM(coparent) AS coparent,paid, SUM(paid) AS paid ,amount, SUM(amount) AS amount,vat, SUM(vat) AS vat,commission, SUM(commission) AS commission from  invoice where type= '1' AND plotno= '$plotno'      and createdat BETWEEN '$fromdate'  and '$todate'  and  paid  >0 group by houseno  ORDER BY id ASC");

	}else{
		
			$this->db->select(" * ,paymentcode,coparent, SUM(coparent) AS coparent,paid, SUM(paid) AS paid ,amount, SUM(amount) AS amount,vat, SUM(vat) AS vat,commission, SUM(commission) AS commission from  invoice where type= '1'     AND  plotno= '$plotno'      and createdat BETWEEN '$fromdate'  and '$todate' group by houseno ORDER BY id ASC ");
			
			
			
//$this->db->select(" * ,amount, SUM(amount) AS amount,vat, SUM(vat) AS vat,commission, SUM(commission) AS commission from  invoice where  type= 'RENT'   AND plotno= '$plotno'      and createdat BETWEEN '$fromdate'  and '$todate' group by houseno ORDER BY priority ASC ");

	}

//$this->db->select(" * from  invoice where plotno= '$plotno'      and createdat BETWEEN '$fromdate'  and '$todate'  group by houseno");

	 
	
	//$this->db->order_by("id", "ASC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}

function getplotchargesrental($plotno){

if($plotno!=null){
$this->db->select(" * from  plotcharges where 	plotno= '$plotno'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

function depositrefunds($plotno,$status,$fromdate,$todate){




$this->db->select(" * from  depositrefunds where plotno= '$plotno'    and createdat	 BETWEEN '$fromdate'  and '$todate' ");
	
	
	
	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}


function getexpenditure($plotno,$status,$fromdate,$todate){


	//$this->db->select(" * from  expenses where imgid= '$plotno'   and type ='$status'  and dateposted	 BETWEEN '$fromdate'  and '$todate' ");


$this->db->select(" * from  expenses where imgid= '$plotno'    and dateposted	 BETWEEN '$fromdate'  and '$todate' ");
	
	
	
	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}



function gethousepayment($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno' and houseno= '$houseno' and paymentstatus ='receipt'");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
function getcoparentapproval($id){

if($id!=null){
$this->db->select(" * from  invoice where id= '$id' ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}









function getnewcoparent(){


$this->db->select(" * from  invoice where approval= 'new' and paymentmode= '15' and paymentstatus ='receipt'");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}




function getallcoparent(){


$this->db->select(" * from  invoice where   paymentmode= '15' and paymentstatus ='receipt'");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}






function getallhousepayment($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno' and houseno= '$houseno'");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}


function getallplotinvoice($plotno,$month,$year){

if($plotno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno' and month ='$month' and year ='$year' and paymentstatus ='invoice'  ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

function getallplotreceipt($plotno,$month,$year){

if($plotno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno' and month ='$month' and year ='$year' and paymentstatus ='receipt'  ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

function getplotreceiptbynorent($id){

if($id!=null){
$this->db->select(" * from  receipt where id= '$id'  ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}
}

}



function getplotreceiptbyno($id){

if($id!=null){
$this->db->select(" * from  bookroom where transactioncode= '$id'  ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}
}

}

function getallplotreceiptbyno($plotno,$houseno){

if($plotno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno' and houseno ='$houseno' and paymentstatus ='receipt'  ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



function deletebyid($id,$tablename){

if($id!=null){

 $this->db->where('id',$id);
 $deleted=$this->db->delete($tablename);

if($deleted){

   return true;
   


}else{

  return false;
}

}


}



function getbookingbyhouseno($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  bookroom where 	houseno= '$houseno' and plotno='$plotno' and status='active' OR  houseno= '$houseno' and plotno='$plotno' and status='reserved'");
 $this->db->order_by("id", "DESC");
$bioquery = $this -> db -> get();

if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
function tenantavailable($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('status','active');
	$this -> db -> limit(1);
	 $this->db->order_by("id", "DESC");
	$tenantquery = $this->db->get('bookroom');
 if($tenantquery->num_rows()>0){

   return $tenantquery->result();
   

    
   } else {
     
          return false;
   }
}



function dispalytenantavailable($plotno) 
{
   $this->db->where('plotno',$plotno);
 
    $this->db->where('status','active');
	$tenantquery = $this->db->get('bookroom');
 if($tenantquery->num_rows()>0){

   return $tenantquery->result();
   

    
   } else {
     
          return false;
   }
}



function dispalytenantavailablebychargename($plotno,$chargeid) 
{
   $this->db->where('plotno',$plotno);
    $this->db->where('chargeid',$chargeid);

    $this->db->where('status','active');
	$tenantquery = $this->db->get('bookroom');
 if($tenantquery->num_rows()>0){

   return $tenantquery->result();
   

    
   } else {
     
          return false;
   }
}






function occupyHouse($plotno,$houseno,$status) 
{
	
	if($status=="reserved"){
			$finalstatus="reserved";

	}else{
					$finalstatus="occupied";

	}
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->set('status',$finalstatus);
	 $this->db->update('house');
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
 


}



function checkinvoice($plotno,$houseno,$type,$month,$year,$tenantid) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('type',$type);
	 $this->db->where('month',$month);
	 	 $this->db->where('tenantid',$tenantid);

  $this->db->where('year',$year);
  $q = $this->db->get('invoice');
   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}
function checkcoparentinvoice($plotno,$houseno,$month,$year) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    
	 $this->db->where('month',$month);
  $this->db->where('year',$year);
  $q = $this->db->get('coparentinvoice');
   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}


      public function getcoursecampus($cam_id,$programid)
    {
            $this->db->select('*');
        $this->db->from('coursedepartment');
        $this->db->where('campusid',$cam_id); 
         $this->db->where('programeid',$programid); 
  $this->db->where('visibility',1); 
        $query = $this->db->get();
    return $query->result();
    }     
  


      public function getcoursebyid($cam_id)
    {
            $this->db->select('*');
        $this->db->from('course');
        $this->db->where('id',$cam_id); 
        $query = $this->db->get();
    return $query->result();
    } 


function checkroomavailablity($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
   
   $q = $this->db->get('house');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}

function checkrentvacancy($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('status','vacant');
   $q = $this->db->get('house');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}







function checkvacancyarray($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
   $this->db->where('status','vacant');

//$this->db->where("( status='vacant'  )", NULL, FALSE);


   $bioquery = $this->db->get('house');

if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   



   } else {
     
          return false;
   }
}
function checkvacancy($plotno,$houseno,$type) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
   $this->db->where('status','vacant');

//$this->db->where("( status='vacant'  )", NULL, FALSE);



   $q = $this->db->get('house');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}
function checkbookingvacancy($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('status','active');
	//$this->db->where("( status='active' OR 	status='reserved' )", NULL, FALSE);

   $q = $this->db->get('bookroom');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}


function checkbookoccupancy($plotno,$houseno) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
    $this->db->where('status <>','vacant');

   $q = $this->db->get('bookroom');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}




function checkbookingdate($plotno,$houseno,$createdat,$checkoutdate)
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
 $this->db->where('status','reserved');

	$this->db->where("( '$createdat'   BETWEEN  checkin and checkout OR   '$checkoutdate' BETWEEN  checkin and checkout  OR  checkin= '$createdat'  OR checkout =  '$checkoutdate' )", NULL, FALSE);

   $q = $this->db->get('dailycharges');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}




function checkbookingdateMain($plotno,$houseno,$createdat,$checkoutdate)
{
   $this->db->where('plotno',$plotno);
   $this->db->where('houseno',$houseno);
 $this->db->where('status','reserved');

	$this->db->where("( '$createdat'   BETWEEN  createdat and checkoutdate OR   '$checkoutdate' BETWEEN  createdat and checkoutdate  OR  createdat= '$createdat'  OR checkoutdate =  '$checkoutdate' )", NULL, FALSE);

   $q = $this->db->get('bookroom');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}



function checktenatidno($idno) 
{
   $this->db->where('idno',$idno);
  

   $q = $this->db->get('people');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}
function checkagentidno($idno) 
{
   $this->db->where('idno',$idno);
  

   $q = $this->db->get('people');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}
function checkalandlordidno($idno) 
{
   $this->db->where('idno',$idno);
  

   $q = $this->db->get('people');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}
function PlotCharges($plotno,$chargeid) 
{
   $this->db->where('plotno',$plotno);
   $this->db->where('chargeid',$chargeid);
    $this->db->where('status','active');
   $q = $this->db->get('plotcharges');

   if ( $q->num_rows() > 0 ) 
   {
      return true;
   } else {
     
          return false;
   }
}


function getbookingbyid($id){

if($id!=null){
$this->db->select(" * from  bookroom where 	id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}

function gettenantid2($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  bookroom where plotno= '$plotno' and houseno= '$houseno' and status='active'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   
//

}else{

  return false;
}

}


}


  
  function gettenantid($plotno,$houseno){
	   $this -> db -> from('bookroom');

$this->db->where('plotno', $plotno);
$this->db->where('houseno', $houseno);
$this->db->where('status', "active");
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}











function getvacanthouse($plotno){

if($plotno!=null){
$this->db->select(" * from  house where plotno= '$plotno'  and status='vacant'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}


function gethouseid($id){

if($id!=null){
$this->db->select(" * from  house where 	id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}
function getlandlordbyid($id){

if($id!=null){
$this->db->select(" * from  landlord where 	id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}

function getplotchargebyid($id){

if($id!=null){
$this->db->select(" * from  plotcharges where 	id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}
function getlandlordid($id){

if($id!=null){
$this->db->select(" * from  people where 	id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

function getagentbyid($id){

if($id!=null){
$this->db->select(" * from  people where 	id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}
function getagentid($id){

if($id!=null){
$this->db->select(" * from  people where 	id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

function getcharges($plotno){

if($plotno!=null){
$this->db->select(" * from  charges where 	plotno= '$plotno'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



	
	function getallcharges(){
 

  $this -> db -> select('*');

   $this -> db -> from('charges');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}



function getchargesbyid($chargeid){

if($chargeid!=null){
$this->db->select(" * from  charges where 	id='$chargeid'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}




function getplotrentalchargesgetplotrentalcharges($plotno){

if($plotno!=null){
$this->db->select(" * from  plotcharges where 	plotno= '$plotno' and  cost > 0");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



function getplotchargesarray($plotno,$roomid,$type){

if($plotno!=null){
$this->db->select(" * from  roomcharges where 	plotno= '$plotno' and roomid= '$roomid' and chargeid= '$type'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}

function getplotcharges($plotno,$roomid){

if($plotno!=null){
$this->db->select(" * from  roomcharges where 	plotno= '$plotno' and roomid= '$roomid' and status !='inactive'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



function getplotchargesbychargeid($plotno,$roomid,$chargeid){

if($plotno!=null){
$this->db->select(" * from  roomcharges where 	plotno= '$plotno' and roomid= '$roomid' and chargeid= '$chargeid' and status !='inactive'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}


function getplotchargesNEW($plotno,$roomid){

if($plotno!=null){
$this->db->select(" * from  roomcharges where 	plotno= '$plotno' and roomid= '$roomid' and status !='inactive'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
function getpaymentsection(){
 

  $this -> db -> select('*');

   $this -> db -> from('paymentmethodes');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
function insertbulkinvoice($data)
  
{
// Query to insert data in database
  if($data!=null){
   
 $this->db->trans_start();
 
      $this->db->insert('invoice', $data);
   


 



  
    $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE){// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }
    
} else

   {

     return false;

   }

}
  
  function upadeteHousedata($data,$houseno,$plotno)
    {
  
     $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('houseno', $houseno);
$this->db->where('plotno', $plotno);
$this->db->set('updatedat', $updatedat);
  $this->db->update('house', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
  function getrentplotcharges($plotno){

if($plotno!=null){
$this->db->select(" * from  plotcharges where 	plotno= '$plotno'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
  
  
  
  

function confirmrentpayments($companyid,$invoice){
	   $this -> db -> from('invoice');

$this->db->select("  * ,invoice.id  AS id,amount,SUM(amount) AS amount,paid,SUM(paid) AS paid ");


	
$this->db->where('companyid', $companyid);
$this->db->where('transactioncode', $invoice);

$this->db->group_by('transactioncode');
	
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}


  
  
  
  
  
  function gethouserentinvoicewithbalance($plotno,$houseno){
	   $this -> db -> from('invoice');


$this->db->where("( amount > paid  )", NULL, FALSE);

	
//$this->db->where('companyid', $companyid);
$this->db->where('plotno', $plotno);
$this->db->where('houseno', $houseno);

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}


  
  
  
  
  
  function gethouserentinvoicewithbalance_______OLD($plotno,$houseno){

if($houseno!=null){
	
$this->db->select(" * from  invoice where plotno= '$plotno' and houseno= '$houseno' and paymentstatus ='invoice' and paid < amount");

$this->db->order_by("id", "ASC");
$bioquery = $this -> db -> get();
 


if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

  
  
  
  
  
  
  function gethouseinvoicewithbalance($plotno,$houseno,$tenantid){

if($houseno!=null){
	//$this->db->select(" * from  receipt where plotno= '$plotno' and houseno= '$houseno' and paymentstatus ='invoice'");

$this->db->select(" * from  receipt where plotno= '$plotno' and houseno= '$houseno' and paymentstatus ='invoice' and paid < amount and tenantid ='$tenantid' ");

$this->db->order_by("id", "ASC");
$bioquery = $this -> db -> get();
 


if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}

  function getmyhousepayment($plotno,$houseno,$tenantid){

if($houseno!=null){
$this->db->select(" * from  receipt where plotno= '$plotno' and houseno= '$houseno' and paymentstatus='receipt' and tenantid ='$tenantid' ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}



function getplotcoparentbalance($plotno,$deudate,$month,$year){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
   
	  //$this->db->where("( type!='RENT' )", NULL, FALSE);
 //$this->db->where('houseno',$houseno);
	 $this->db->where('plotno',$plotno);
	  $this->db->where('month',$month);
	  $this->db->where('year',$year);
	  // $this->db->where('tenantid',$tenantid);
	   $this->db->where('amount < ', 'paid');
$this->db->where('duedate <', $deudate);
	// $this->db->select('paid, SUM(paid) AS paid', FALSE);
	//  $this->db->select('amount, SUM(amount) AS orignalmount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);

    $this->db->where('type <> ',4);


 //$this->db->group_by('tenantid');

$this->db->order_by("id", "DESC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}







function getplotbalance($plotno,$houseno, $tenantid,$deudate,$month,$year){
 

  $this -> db -> select('*');

   $this -> db -> from('invoice');
   
	  //$this->db->where("( type!='RENT' )", NULL, FALSE);
 $this->db->where('houseno',$houseno);
	  $this->db->where('plotno',$plotno);
	  $this->db->where('month',$month);
	  $this->db->where('year',$year);
	   $this->db->where('tenantid',$tenantid);
	 $this->db->select('paid, SUM(paid) AS paid', FALSE);
	  $this->db->select('amount, SUM(amount) AS orignalmount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);

$this->db->where('duedate <', $deudate);

 $this->db->group_by('tenantid');

$this->db->order_by("id", "DESC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }

}



function getmybulkhousedetails($plotno,$houseno){

if($houseno!=null){
$this->db->select(" * from  house where plotno= '$plotno' and houseno= '$houseno'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}

}


}






function getplotreceiptallbybalancerent($plotno,$houseno, $tenantid){
 

  $this -> db -> select('*');

   $this -> db -> from('bookroom');
   
	  //$this->db->where("( type!='RENT' )", NULL, FALSE);
 $this->db->where('houseno',$houseno);
	  $this->db->where('plotno',$plotno);
  $this->db->where('tenantid',$tenantid);
	   $this->db->where('totalamount<>',0);
	 //$this->db->select('paid, SUM(paid) AS paid', FALSE);
	 // $this->db->select('amount, SUM(amount) AS orignalmount', FALSE);
//$this->db->where("( SUM(amount) AS amount )", NULL, FALSE);
//$this->db->group_by('tenantid');


$this->db->order_by("id", "DESC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }

}

function getbulkcoparentnvoice($plotno){

if($plotno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno'  and paymentstatus ='invoice' AND  coparent > 0 ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}












function getbulkpenaltyinvoice($plotno){

if($plotno!=null){
$this->db->select(" * from  invoice where plotno= '$plotno'  and paymentstatus ='invoice' AND  type='PENALTY' ");
 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}


function checkpayamntacode($paymentcode){

if($paymentcode!=null){
$this->db->select(" * from  receipt where paymentcode= '$paymentcode' and paymentcode != ''  ");


$bioquery = $this -> db -> get();
 


if($bioquery->num_rows()>0){

  return true;
   


}else{

  return false;
}

}


}








function populateoverpayment($id){

if($id!=null){
$postedtime = date('Y-m-d');
$this->db->select(" * from receipt where companyid='$id' and  overpayment > 0  ORDER BY exactime DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

  return $bioquery->result();
 
}else{

  return false;
}

}else{
 return false;	
}


}

   public function getothercost($cam_id,$programid)
    {
            $this->db->select('*');
        $this->db->from('tenant');
        $this->db->where('id',$cam_id); 
       
        $query = $this->db->get();
    return $query->result();
    }     
  

function insertInvoice($data)
    {
		return $this->db->insert('invoice', $data);
	}
	
	
	
	
function insertExpenditure($data)
    {
		return $this->db->insert('expenditure', $data);
	}
	
	
	
	

function insertHousepayment($data)
    {
		return $this->db->insert('invoice', $data);
	}
	function insertCoparent($data)
    {
		return $this->db->insert('coparentinvoice', $data);
	}
function insertBooking($data)
    {
		return $this->db->insert('bookroom', $data);
	}
	
	
	
	
	
	function getmytenantid($idno){

if($idno!=null){
$this->db->select(" * from  people where idno= '$idno'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}
	}
	
	
	
	
	
	

function insertlandlord($data)
    {
		return $this->db->insert('people', $data);
	}
	
	function populatealllandlord(){
 

  $this -> db -> select('*');

   $this -> db -> from('people');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
	function populateallallacountries(){
 

  $this -> db -> select('*');

   $this -> db -> from('nation');

$this->db->order_by("id", "ASC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function populatepostimages($img_id){

if($img_id!=null){
$this->db->select(" * from uploadedimages where img_id= '$img_id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();

}else{

  return false;
}

}


}



	function populateallallacounties(){
 

  $this -> db -> select('*');

   $this -> db -> from('county');

$this->db->order_by("id", "ASC");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}









function insertagent($data)
    {
		return $this->db->insert('people', $data);
	}
	
	function populateallagent(){
 

  $this -> db -> select('*');

   $this -> db -> from('people');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function inserttenant($data)
    {
		return $this->db->insert('people', $data);
	}
	
	
	
	function insertsmscategory($data)
    {
		return $this->db->insert('smscategory', $data);
	}
	
		function insertsms($data)
    {
		return $this->db->insert('sms', $data);
	}
	
	
	
	
	
	
	
	
	
	function populatealltenant(){
 

  $this -> db -> select('*');

   $this -> db -> from('people');

 $this->db->order_by("id", "DESC");
 //$this->db->limit(3);

 $query1 = $this -> db -> get();
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function insertpaymentmethod($data)
    {
		return $this->db->insert('paymentmethod', $data);
	}
	function insertCountry($data)
    {
		return $this->db->insert('nation', $data);
	}
	function populateallpaymentmethod(){
 

  $this -> db -> select('*');

   $this -> db -> from('paymentmethodes');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
	function populateallexpenditure(){
 

  $this -> db -> select('*');

   $this -> db -> from('expenses');
        $this->db->where('type','plot'); 
$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


	function populatesms(){
 

  $this -> db -> select('*');

   $this -> db -> from('sms');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


	function populatesmscategory(){
 

  $this -> db -> select('*');

   $this -> db -> from('smscategory');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}














function insertpaymentcharge($data)
    {
		return $this->db->insert('charges', $data);
	}
	
function insertpaymentsection($data)
    {
		return $this->db->insert('paymentmethodes', $data);
	}
	
	function populateallpaymentsection(){
 

  $this -> db -> select('*');

   $this -> db -> from('paymentmethodes');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
	function populateallpaymentcharges(){
 

  $this -> db -> select('*');

   $this -> db -> from('charges');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
function populateallusers(){
 

  $this -> db -> select('*');

   $this -> db -> from('user');

//$this->db->where('postype',2);
   $this->db->order_by('id');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function populateallcontact(){
 

  $this -> db -> select('*');

   $this -> db -> from('contact');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function insertUser($data)
    {
    return $this->db->insert('users', $data);
	
  }
    function Updateusers($data,$id)
    {
    $updatedat = Date('Y-m-d H:i:s') ;
	$this->db->where('id', $id);
	$this->db->set('updatedate', $updatedat);
  $this->db->update('user', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  function UpdateBooking($data,$id)
    {
    $updatedat = Date('Y-m-d H:i:s') ;
	$this->db->where('id', $id);
	$this->db->set('updatedat', $updatedat);
  $this->db->update('bookroom', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
   function Updateapproval($data,$id)
    {
    $updatedat = Date('Y-m-d H:i:s') ;
	$this->db->where('id', $id);
	$this->db->set('updatedat', $updatedat);
  $this->db->update('invoice', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
    function upadeteHouse($data,$id)
    {
  
     $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
$this->db->set('updatedat', $updatedat);
  $this->db->update('house', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
   function upadetePlotcharge($data,$id)
    {
  
     $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
$this->db->set('updatedat', $updatedat);
  $this->db->update('plotcharges', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
 function upadeteLandlord($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('people', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
function upadeteAgent($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('people', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  function upadeteTenant($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('people', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
    function upadetePlot2($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('plot', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
   function upadetePaymentmethod($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('paymentmethod', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
  
  
  
  
  function upadetesmscategory($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('smscategory', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
  
  
  
  
    function upadetesms($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('sms', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  
  
  
  function upadetecountry($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('nation', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  function upadeteTenat($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('tenat', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
	
function addmessage($data,$id) 
{
   $this->db->where('courseid',$id);
   $q = $this->db->get('coursemessage');

   if ( $q->num_rows() > 0 ) 
   {
      $this->db->where('courseid',$id);
      $this->db->update('coursemessage',$data);
    if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }

   } else {
     
      $this->db->insert('coursemessage',$data);
        if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
   }
}
function specificapplications($campusid,$collegeid,$departmentid){


  $this -> db -> select('*');

   $this -> db -> from('studentapplication');
$this -> db -> where('campusname', $campusid);
   $this -> db -> where('department', $departmentid);

   $this -> db -> where('college', $collegeid);
 $this->db->order_by('id');
$appquery = $this -> db -> get();
if($appquery->num_rows()>0){

   return $appquery->result();
   


}else{

  return false;
}
}
function displayvacant($plotno){


  $this -> db -> select('*');

   $this -> db -> from('house');
$this -> db -> where('plotno', $plotno);
 

   $this -> db -> where('status', 'vacant');
 $this->db->order_by('id');
$appquery = $this -> db -> get();
if($appquery->num_rows()>0){

   return $appquery->num_rows();
   


}else{

  return false;
}
}
function displayoccupied($plotno){


  $this -> db -> select('*');

   $this -> db -> from('house');
$this -> db -> where('plotno', $plotno);
 

   $this -> db -> where('status', 'occupied');
 $this->db->order_by('id');
$appquery = $this -> db -> get();
if($appquery->num_rows()>0){

   return $appquery->num_rows();
   


}else{

  return false;
}
}function displaycoparentbalance($transactioncode){


  $this -> db -> select('*');

   $this -> db -> from('coparentinvoice');
$this -> db -> where('transactioncode', $transactioncode);
 $this->db->order_by("id", "DESC");
$appquery = $this -> db -> get();
if($appquery->num_rows()>0){

   return $appquery->result();
   


}else{

  return false;
}
}

function getapplicationsadmission($id){


  $this -> db -> select('*');

   $this -> db -> from('studentapplication');
$this -> db -> where('id', $id);
 
 
 $this->db->order_by('id');
$appquery = $this -> db -> get();
if($appquery->num_rows()>0){

   return $appquery->result();
   


}else{

  return false;
}
}

function populatepmsdata($id){


  $this -> db -> select('*');

   $this -> db -> from('user');
$this -> db -> where('id', $id);
 
 
 $this->db->order_by('id');
$appquery = $this -> db -> get();
if($appquery->num_rows()>0){

   return $appquery->result();
   


}else{

  return false;
}
}

function getspecificapplications($campusid, $courseid){


  $this -> db -> select('*');

   $this -> db -> from('coursedepartment');
$this -> db -> where('campusid', $campusid);
   $this -> db -> where('courseid', $courseid);
 
 $this->db->order_by('id');
$appquery = $this -> db -> get();
if($appquery->num_rows()>0){

   return $appquery->result_array();
   


}else{

  return false;
}
}

function getmyapplications($id){


$this->db->select(" * from  studentapplication where studentid= '$id'");
$this -> db -> limit(1);
 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}



function viewallspecificapplications($id){


$this->db->select(" * from  studentapplication where coursename= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}





function getpaymentsectionbyid($id){


$this->db->select(" * from  paymentmethodes where methodid= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}

function gettenantbyid($id){


$this->db->select(" * from  people where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}
function getcoparentbyreceiptid($transactioncode){


$this->db->select(" * from  coparentinvoice where transactioncode= '$transactioncode'");

 $this->db->order_by("id", "DESC");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}



function gettenantallid($id){


$this->db->select(" * from  people where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}


function upadetePlot($data,$id)
    {
	  $updatedat = Date('Y-m-d H:i:s') ;
$this->db->where('id', $id);
  $this->db->set('updatedat', $updatedat);
  $this->db->update('plot', $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
function getplotid($id){


$this->db->select(" * from  plot where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}
function getpaymentmethodid($id){


$this->db->select(" * from  paymentmethod where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}


function getpaymentmethodbyid($id){


$this->db->select(" * from  paymentmethod where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}



function getbycheckoutdate($checkoutdate,$plotno){


$this->db->select(" * from  bookroom where checkoutdate < '$checkoutdate' and status='active' and paymentstatus='Cleared' and plotno='$plotno' ");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}







function getcountryid($id){


$this->db->select(" * from  nation where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}




public function countplotcompanyid($companyid)
	{
		 $sql = "SELECT COUNT(*) As cnt FROM plot WHERE companyid='$companyid'  ";
   
		$q = $this->db->query($sql);
		$row = $q->row(); 
		return $row->cnt;
	}   





public function countplotno($plotno)
	{
		 $sql = "SELECT COUNT(*) As cnt FROM house WHERE plotno='$plotno'  ";
   
		$q = $this->db->query($sql);
		$row = $q->row(); 
		return $row->cnt;
	}   
function getcountrybyid($id){


$this->db->select(" * from  nation where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}





function getbookingtenantbyid($tenantid){
 

  $this -> db -> select('*');

   $this -> db -> from('bookroom');
 $this -> db -> where('tenantid',$tenantid);

   $this->db->order_by('id');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}





function bookingstenantbyid($tenantid){


$this->db->select(" * from  bookroom where tenantid= '$tenantid'");

 $this->db->order_by('id' , "DESC");
$bioquery = $this -> db -> get();

if($bioquery->num_rows()>0){

     return $bioquery->result();


}else{

  return false;
}




}





function gettotalbookingtenantbyid($tenantid){


$this->db->select(" * from  bookroom where tenantid= '$tenantid'");

 $this->db->order_by('id' , "DESC");
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

  return $bioquery->num_rows();
   


}else{

  return false;
}




}




function getcountybyid($id){


$this->db->select(" * from  county where id= '$id'");

 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}






function getpaymentsectionid($id){

if($id!=null){
$this->db->select(" * from paymentmethodes where id= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();

}else{

  return false;
}

}

}









function getapplications($id){


$this->db->select(" * from  studentapplication where id= '$id'");
$this -> db -> limit(1);
 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
   


}else{

  return false;
}




}


function getmymessage($id){

if($id!=null){
$this->db->select(" * from coursemessage where courseid= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();

}else{

  return false;
}

}

}

function getapplicationsfeedback($id){


$this->db->select(" * from  studentapplication where id= '$id'");
$this -> db -> limit(1);
 $this->db->order_by('id');
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}



 
function signupuser($data)
{// Query to insert data in database
  $regno = $data['regno'];
   $this -> db -> select("* from studentlogin where regno='$regno'");
  $this -> db -> limit(1);
   $query = $this -> db -> get();
  if($query -> num_rows() == 0)

   {

    $this->db->insert('studentlogin', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }

   }

   else

   {

     return false;

   }


}
function populateadmindata($id){

if($id!=null){
$this->db->select(" * from user where id= '$id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();

}else{

  return false;
}

}


}

function sigadmin($data)
{
// Query to insert data in database
	$username = $data['username'];
	 $this -> db -> select("* from users where username='$username'");
 	$this -> db -> limit(1);
	 $query = $this -> db -> get();
	if($query -> num_rows() == 0)

   {

    $this->db->insert('users', $data);
	if ($this->db->affected_rows() > 0) 
			{
	return true;

			}

   }

   else

   {

     return false;

   }


}

            function uploadstudent1($data)
{
// Query to insert data in database
  $regno = $data['regno'];
   $this -> db -> select("* from students where regno='$regno'");
  $this -> db -> limit(1);
   $query = $this -> db -> get();
  if($query -> num_rows() == 0)

   {

    $this->db->insert('students', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }

   }

   else

   {

     return false;

   }


}


            function uploadstudent($data)
{
// Query to insert data in database



    $this->db->insert('coursedepartment', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }

   

   else

   {

     return false;

   }


}

function populatenoramusers(){
 

  $this -> db -> select('*');

   $this -> db -> from('users');


   $this->db->order_by('id');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
function populateusers(){
 

  $this -> db -> select('*');

   $this -> db -> from('admintable');


   $this->db->order_by('id');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
function populateallapplication(){
 

  $this -> db -> select('*');

   $this -> db -> from('studentapplication');


   $this->db->order_by('id');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

            
 function displayallstudents()
 

{


   $query1 = $this->db->get('students');
   $this->db->order_by('id');
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}





  function getapplytudents($email, $password)

{

   $this -> db -> select('*');

   $this -> db -> from('user');

   $this -> db -> where('email', $email);

   $this -> db -> where('indexno', ($password));

   $this -> db -> limit(1);

 

   $query = $this -> db -> get();

 

   if($query -> num_rows() == 1)

   {

     return $query->result();

   }

   else

   {

     return false;

   }

}

	
function populatependingpayment($phone){
 if(($phone)!=""){
	 


  $this -> db -> select('*');

   $this -> db -> from('sms_in');
	$this->db->where("(sender_number='$phone' and used='2'  OR 	code='$phone' and used='2' )", NULL, FALSE);

 //$this -> db -> where('sender_numbe', $phone);
 //$this -> db -> where('transactioncode', $phone);
 $this -> db -> where('used', 2);

 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }
 }else{
	    return false; 
 }
}

	public function displayallmpesapendingsalesbydate($limit, $start,$database,$startdate,$enddate) {
      
	  
	$this->db->where("( exactime BETWEEN '$startdate'  and '$enddate'  and used='2' and amount >0 )", NULL, FALSE);
	
				 $this->db->order_by('id','DESC');

        $query = $this->db->get($database);

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }
	
	

	function count_allpendingmpesasalesbydate($tablename,$startdate,$enddate) 
	{

				$this->db->where("( exactime BETWEEN '$startdate'  and '$enddate' and used='2'  and amount >0 )", NULL, FALSE);

	

	
		$this->db->from($tablename);
		
		return $this->db->count_all_results();
	}
	
	


function populatealldataarray($table,$where, $value,$where1, $value1){
 

  $this -> db -> select('*');

   $this -> db -> from($table);

  $this->db->where($where,$value);
  $this->db->where($where1,$value1);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }
}

function populatuserpermissionsdataarray($moduleid,$actionid,$userid){
 

  $this -> db -> select('*');

   $this -> db -> from('permissionsactions');
 $this -> db -> where('moduleid', $moduleid);
$this -> db -> where('actionid', $actionid);
 $this -> db -> where('userid', $userid);
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
	     return true;


   }

   else

   {

     return false;

   }

}


function populatuserpermissionsactions($moduleid,$userid,$actionid){
 

  $this -> db -> select('*');

   $this -> db -> from('permissionsactions');
 $this -> db -> where('moduleid', $moduleid);
$this -> db -> where('actionid', $actionid);
 $this -> db -> where('userid', $userid);
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
	     return true;
  //return $query1->result();

   }

   else

   {

     return false;

   }

}














function confirmaccountcode($code){

if($code!=null){
$this->db->select(" * from smsconfig where id='$code' ");

$n = $this -> db -> get();
if($n->num_rows()>0){

  return $n->result();
  // return true;
}else{

  return false;
}

}


}





function populateallarray($table,$where, $value){
 

  $this -> db -> select('*');

   $this -> db -> from($table);

  $this->db->where($where,$value);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }

}


















function confirmemail($email){

if($email!=null){
$this->db->select(" * from user where email='$email' ");

$n = $this -> db -> get();
if($n->num_rows()>0){

  return $n->result();
  // return true;
}else{

  return false;
}

}


}
 function updatedatabytwo($data,$tablename,$where,$value,$where1,$value1)
    {

	$this->db->where($where, $value);
 	$this->db->where($where1, $value1);

  $this->db->update($tablename, $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
  function updatedata($data,$tablename,$where,$value)
    {

	$this->db->where($where, $value);
 
  $this->db->update($tablename, $data);
   if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
        return false; 
      }
  }
function confirmphone($phone){

if($phone!=null){
$this->db->select(" * from user where phone='$phone' ");

$n = $this -> db -> get();
if($n->num_rows()>0){

  return $n->result();
  // return true;
}else{

  return false;
}

}


}

public function displayall($limit, $start,$database,$where,$value) {
        $this->db->limit($limit, $start);
		$this->db->where($where, $value);
				 $this->db->order_by('id','DESC');

        $query = $this->db->get($database);

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }

function add_studentdata($data,$id) 
{
   $this->db->where('id',$id);
   $q = $this->db->get('students');

   if ( $q->num_rows() > 0 ) 
   {
      $this->db->where('id',$id);
      $this->db->update('students',$data);
   } else {
     
      $this->db->insert('students',$data);
   }
   $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE)
	   {// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }
}







	function getusers($email, $password)

{

   $this -> db -> select('*');

   $this -> db -> from('user');

   $this -> db -> where('email', $email);

   $this -> db -> where('password', ($password));

   $this -> db -> limit(1);

 

   $query = $this -> db -> get();

 

   if($query -> num_rows() == 1)

   {

     return $query->result();

   }

   else

   {

     return false;

   }

}






function populatestudent($username, $password){

if($username!=null){
$this->db->select(" * from user where username='$username' or password='$password'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   //return $bioquery->result();
   return true;
}else{

  return false;
}

}


}




function updatemember($data,$id) 
{

   $this->db->where('id',$id);

   if ( $this->db->update('people',$data) ) 
   {
      return true;
   } else {
     
          return false;
   }
}



function populatemember($id){

if($id!=null){
$this->db->select(" * from people where id='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

  return $bioquery->result_array();
 
}else{

  return false;
}

}else{
 return false;	
}


}



function populatedailypeyment($id){

if($id!=null){
$postedtime = date('Y-m-d');
$this->db->select(" * from bookroom where companyid='$id' and  createdat like '$postedtime%'  ");
 $this->db->order_by('id','desc');

$bioquery = $this -> db -> get();

if($bioquery->num_rows()>0){

  return $bioquery->result();
 
}else{

  return false;
}

}else{
 return false;	
}


}
function populatmyemember($id){

if($id!=null){
$this->db->select(" * from people where id='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

  return $bioquery->result();
 
}else{

  return false;
}

}else{
 return false;	
}


}


function populattenantbyid($id){

if($id!=null){
$this->db->select(" * from people where id='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

  return $bioquery->result();
 
}else{

  return false;
}

}else{
 return false;	
}


}












function populategrouping($id){

if($id!=null){
$this->db->select(" * from grouping where 	memberid='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

  return $bioquery->result_array();
 
}else{

  return false;
}

}else{
 return false;	
}


}

function confirmgrouping($memberid,$userid, $categoryid){

if($memberid!=null){
$this->db->select(" * from grouping where 	memberid='$memberid' and userid='$userid' and categoryid='$categoryid' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

 return true;
 
}else{

  return false;
}

}else{
 return false;	
}


}
function populatemembergrouping($memberid,$userid){
 

  $this -> db -> select('*');

   $this -> db -> from('grouping');
$this -> db -> where('memberid', $memberid);
 $this -> db -> where('userid', $userid);

 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function populatememberbygrouping($groupid,$userid,$status){
 

  $this -> db -> select('*');

   $this -> db -> from('grouping');
$this -> db -> where('categoryid', $groupid);
$this -> db -> where('status', $status);
 $this -> db -> where('userid', $userid);

 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}



function updatememberstatus($id,$status) 
{
 $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;
   $this->db->where('id',$id);
 $this->db->set('status',$status);
$this->db->set('updatedat',$dateposted);
   if ( $this->db->update('grouping') ) 
   {
      return true;
   } else {
     
          return false;
   }
}

function updateusersms($id,$totalsms) 
{

   $this->db->where('id',$id);

 $this->db->set('totalsms',$totalsms);
   if ( $this->db->update('user') ) 
   {
      return true;
   } else {
     
          return false;
   }
}









            function uploadmembers($data)
{
// Query to insert data in database
  $userid = $data['userid'];
  $idno = $data['idno'];
   $phone = $data['phone'];
   $this -> db -> select("* from people where idno='$idno' and userid='$userid' and phone='$phone'");

   $query = $this -> db -> get();
  if($query -> num_rows() == 0)

   {

    $this->db->insert('people', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }else{
		     return false;
  
	  }

   }

  


}









function getnewstudent($username){

if($username!=null){
$this->db->select(" * from registration where username='$username'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   //return $bioquery->result();
   return true;
}else{

  return false;
}

}


}

function getsales()

{

   $this -> db -> select('id');

   $this -> db -> from('sales');

 $this->db->order_by('id','DESC');
   $this -> db -> limit(1);

 

   $query = $this -> db -> get();

 

   if($query -> num_rows() == 1)

   {

     return $query->result_array();

   }

   else

   {

     return false;

   }

}


function getsetting()

{

   $this -> db -> select('*');

   $this -> db -> from('setting');

 $this->db->order_by('name','DESC');


 

   $query = $this -> db -> get();

 

   if($query -> num_rows() == 1)

   {

     return $query->result_array();

   }

   else

   {

     return false;

   }

}













function geteproductbyid($id){

if($id!=null){
$this->db->select(" * from products where code='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
 
}else{

  return false;
}

}


}







function getemployee($id){

if($id!=null){
$this->db->select(" * from people where id='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
 
}else{

  return false;
}

}


}







function getesales_order($id){

if($id!=null){
$this->db->select(" * from sales_order where invoice='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
 
}else{

  return false;
}

}


}



function geteuser($id){

if($id!=null){
$this->db->select(" * from user where id='$id' ");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();
 
}else{

  return false;
}

}


}


function populatedocumets($id){

if($id!=null){
$this->db->select(" * from documents where studentid= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();

}else{

  return false;
}

}}

function populatemessage($id){

if($id!=null){
$this->db->select(" * from coursemessage where courseid= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result_array();

}else{

  return false;
}

}

}

function confirmaccount($id)
{// Query to insert data in database
  //$paymentno = $data['paymentno'];
   $this -> db -> select("* from user where id='$id'");
  $this -> db -> limit(1);
   $query = $this -> db -> get();
  if($query -> num_rows() > 0)

   {
    return $query->result_array();

   
  //return true;


   }

   else

   {

     return false;

   }
}




function confirmasmsccount($id)
{// Query to insert data in database
  //$paymentno = $data['paymentno'];
   $this -> db -> select("* from smsconfig where id='$id'");
  $this -> db -> limit(1);
   $query = $this -> db -> get();
  if($query -> num_rows() > 0)

   {
    return $query->result_array();

   
  //return true;


   }

   else

   {

     return false;

   }
}




function confirmgroupsaccount($id)
{// Query to insert data in database
  //$paymentno = $data['paymentno'];
   $this -> db -> select("* from grouping where categoryid='$id' AND status='1'");

   $query = $this -> db -> get();
  if($query -> num_rows() > 0)

   {
    return $query->result();

   
  //return true;


   }

   else

   {

     return false;

   }
}




function confirmstep($paymentno)
{// Query to insert data in database
  //$paymentno = $data['paymentno'];
   $this -> db -> select("* from studentapplication where paymentno='$paymentno'");
  $this -> db -> limit(1);
   $query = $this -> db -> get();
  if($query -> num_rows() > 0)

   {
    return $query->result();

   
  //return true;


   }

   else

   {

     return false;

   }
}


function confirmstep1($paymentno)
  
{
 
  if($paymentno!=null){
     $this->db->where('paymentno',$paymentno);
 
   $confirmquey = $this->db->get('studentapplication');
    $this->db->trans_start();
   if ( $confirmquey->num_rows() > 0 ) 
   {
        return $confirmquey->result();

          //return true;

   } else {
      
      return false;
      
   }


  
     
    
} else {

     return false;

        }

}
public function countMembers($userid)
	{
		 $sql = "SELECT COUNT(*) As cnt FROM people WHERE userid='$userid'  ";
   
		$q = $this->db->query($sql);
		$row = $q->row(); 
		return $row->cnt;
	}
	public function countamount($userid)
	{
		 $sql = "SELECT totalsms FROM user WHERE id='$userid'  ";
   
		$q = $this->db->query($sql);
		
		 return $q->result_array();
	}
	
	
	public function countSMS($userid)
	{
		 $sql = "SELECT COUNT(*) As cnt FROM sms WHERE userid='$userid'  ";
   
		$q = $this->db->query($sql);
		$row = $q->row(); 
		return $row->cnt;
	}

	function count_allwhere($tablename,$where,$value)
	{
		$this -> db -> where($where, $value);
		$this->db->from($tablename);
		
		return $this->db->count_all_results();
	}
		public function displayallsmsperuser($limit, $start,$userid) {
        $this->db->limit($limit, $start);
		$this->db->where('userid', $userid);
        $query = $this->db->get("sms");

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }	
 


public function displayallmembersperuser($limit, $start,$userid) {
        $this->db->limit($limit, $start);
		$this->db->where('userid', $userid);
        $query = $this->db->get("people");

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }	



function populatecoursedocumets($id){

if($id!=null){
$this->db->select(" * from coursedocuments where courseid= '$id'");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();

}else{

  return false;
}

}

}

function add($data,$table)
{
	
    $this->db->insert($table, $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }
 }

function uploadcoursedocument($data)
{// Query to insert data in database
    //$regnumber = $data['regnumber'];
  
    $this->db->insert('coursedocuments', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }


}

function startapplication($data)
{// Query to insert data in database
    //$regnumber = $data['regnumber'];
  
    $this->db->insert('studentapplication', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }


}
function signup($data)
{// Query to insert data in database
  $email = $data['email'];
   $this -> db -> select("* from user where email='$email'");
  $this -> db -> limit(1);
   $query = $this -> db -> get();
  if($query -> num_rows() == 0)

   {

    $this->db->insert('user', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }

   }

   else

   {

     return false;

   }
}

function populatebiodata($id){

if($id!=null){
$this->db->select(" * from students where id= '$id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();

}else{

  return false;
}

}


}


function updatephoto($data,$paymentno)
  
{
 
  if($paymentno!=null){
     $this->db->where('paymentno',$paymentno);
 
   $qq = $this->db->get('studentapplication');
    $this->db->trans_start();
   if ( $qq->num_rows() > 0 ) 
   {
      $this->db->where('paymentno',$paymentno);
      $this->db->update('studentapplication',$data);

      $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE){// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }

   } else {
      
      return false;
      
   }


  
     
    
} else

   {

     return false;

   }

}


function updatepayment($data,$paymentno)
  
{
 
  if($paymentno!=null){
     $this->db->where('paymentno',$paymentno);
 
   $qq = $this->db->get('studentapplication');
    $this->db->trans_start();
   if ( $qq->num_rows() > 0 ) 
   {
      $this->db->where('paymentno',$paymentno);
      $this->db->update('studentapplication',$data);

      $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE){// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }

   } else {
      
      return false;
      
   }


  
     
    
} else

   {

     return false;

   }

}

function updateacademic($data,$paymentno)
  
{
 
  if($paymentno!=null){
     $this->db->where('paymentno',$paymentno);
 
   $qq = $this->db->get('studentapplication');
    $this->db->trans_start();
   if ( $qq->num_rows() > 0 ) 
   {
      $this->db->where('paymentno',$paymentno);
      $this->db->update('studentapplication',$data);

      $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE){// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }

   } else {
      
      return false;
      
   }


  
     
    
} else

   {

     return false;

   }

}











function updatecouse($data,$paymentno)
  
{
 
  if($paymentno!=null){
     $this->db->where('paymentno',$paymentno);
 
   $qq = $this->db->get('studentapplication');
    $this->db->trans_start();
   if ( $qq->num_rows() > 0 ) 
   {
      $this->db->where('paymentno',$paymentno);
      $this->db->update('studentapplication',$data);

      $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE){// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }

   } else {
      
      return false;
      
   }


  
     
    
} else

   {

     return false;

   }

}















function updateapplication($data,$id)
  
{
 
  if($id!=null){
     $this->db->where('id',$id);
 
   $qq = $this->db->get('studentapplication');
    $this->db->trans_start();
   if ( $qq->num_rows() > 0 ) 
   {
      $this->db->where('id',$id);
      $this->db->update('studentapplication',$data);
   } else {
      
      $this->db->insert('studentapplication', $datas);
      
   }



  
    $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE){// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }
    
} else

   {

     return false;

   }

}

 function updateapplication1($data,$id) 
{
   $this->db->where('id',$id);
   $q = $this->db->get('studentapplication');

   if ( $q->num_rows() > 0 ) 
   {
      $this->db->where('id',$id);
      $this->db->update('studentapplication',$data);
   } 
}


 function populateapplyself($studentid){
 

  $this -> db -> select('*');

   $this -> db -> from('studentapplication');

 $this -> db -> where('studentid', $studentid);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
function populateproducts(){
 

  $this -> db -> select('*');

   $this -> db -> from('products');

 //$this -> db -> where('indexno', $indexno);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function populatexpenses(){
 

  $this -> db -> select('*');

   $this -> db -> from('expenses');

 //$this -> db -> where('indexno', $indexno);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function populatemyexpenses($userid){
 if(($userid)!=""){
	 


  $this -> db -> select('*');

   $this -> db -> from('expenses');

 $this -> db -> where('userid', $userid);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }
 }else{
	    return false; 
 }
}






function populatecategory($userid){
 if(($userid)!=""){
	 


  $this -> db -> select('*');

   $this -> db -> from('category');

 $this -> db -> where('companyid', $userid);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }
 }else{
	    return false; 
 }
}
function getcategory($id){
 if(($id)!=""){
	 


  $this -> db -> select('*');

   $this -> db -> from('category');

 $this -> db -> where('id', $id);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result_array();

   }

   else

   {

     return false;

   }
 }else{
	    return false; 
 }
}









function populateallstatus($table,$where, $value,$where1, $value1){
 

  $this -> db -> select('*');

   $this -> db -> from($table);
  $this->db->where($where1,$value1);
  $this->db->where($where,$value);
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}








function populateuser(){
 

  $this -> db -> select('*');

   $this -> db -> from('people');

 $this -> db -> where('status', 1);
 $this->db->order_by('email','ASC');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}








function populateall($table,$where, $value){
 

  $this -> db -> select('*');

   $this -> db -> from($table);

  $this->db->where($where,$value);

 $query1 = $this -> db -> get();
    $this->db->order_by('id','DESC');

 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
function populatesupplier(){
 

  $this -> db -> select('*');

   $this -> db -> from('people');

 $this -> db -> where('category', 'supplier');
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function populateviewmember($userid){
 

  $this -> db -> select('*');

   $this -> db -> from('people');
 $this -> db -> where('userid', $userid);
 $this -> db -> where('category', 'member');
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}





function populateviewemployees(){
 

  $this -> db -> select('*');

   $this -> db -> from('people');

 $this -> db -> where('category', 'employee');
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}



function populateviewsetting(){
 

  $this -> db -> select('*');

   $this -> db -> from('setting');

 //$this -> db -> where('category', 'employee');
// $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function populateviewloyality(){
 

  $this -> db -> select('*');

   $this -> db -> from('loyalitycards');

 //$this -> db -> where('category', 'employee');
 $this->db->order_by('id','desc');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function populatemymessage($courseid){
 

  $this -> db -> select('*');

   $this -> db -> from('coursemessage');

 $this -> db -> where('courseid', $courseid);
   $this->db->order_by('id');
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


} 

?>