      <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </script> 
	 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>

	
        <script>
        $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
        </script>
                  

 	 <?PHP

 echo $this->session->flashdata('imagemsg1'); 
		 
		    
$session_data = $this->session->userdata('logged_in');
 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	
$data['surname'] = $session_data['surname'];
$data['id'] = $session_data['id'];
 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
$surname=$data['surname'];
   $userid=$data['id'];

?>
 <div class="row">
  
   	

   	<div class="col-md-12">
	
  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
						 <span class="pull-right"> View Payment</span>					                    
						 <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Add Landlord Payment </a>

				
            									 <a  class="btn btn-primary" href="<?php echo base_url(); ?>admin/viewpallmyplots">Back Home </a>


							
            	</div>
            </div>
			<div class="panel-body">

				<div class="widget-content nopadding table_holder table-responsive" >				
	<?PHP



				echo $this->session->flashdata('msg'); 
								?>	
										
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
									
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>
    
     <th>Date</th>
	    <th>Month</th>
		   <th>Year</th>
	 	    <th>Landlord</th>
	    <th>Plot No</th>
	   <th>Exp Total</th>
	   	   <th> Total Paid</th>

	         <th>Advance</th>
			       <th>Direct</th>
	      <th>Cash</th>
		  
	  	      <th>Mpesa</th>

	  	  	      <th>Card</th>
	  	  	      <th>Cheque</th>

	  	  	  	      <th>Balance</th>

	  
		   <th>Name</th>
		      <th>Approved by?</th>
	     <th>Description</th>
			<th>Status</th>	
<th>Action</th> 			
		   <th>more</th> 
	

                 </tr>
             </thead>
<?php
 if(!is_array($viewexpenses)) {
				    echo '<div class="alert alert-danger text-center">There no records found</div>';

			 }else{
 if(!is_array($viewexpenses)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  
  	foreach ($viewexpenses as $c): 

		 

             ?>



             <tr>
                
            <?php 
$id=$c->id;
$img_id=$c->img_id;


?>

                <td><?php echo $c->createdat; ?></td>
  <td><?php echo $c->month; ?></td>

    <td><?php echo $c->year; ?></td>

   
	<td><?php  $landlordid=  $c->landlord ; 
							    $landlords = $this->accomodationmodel->getlandlordid($landlordid);
							


if(is_array($landlords)) {

   foreach($landlords as $landlordsrow){

  echo$names= $landlordsrow->lastname. "  ".$landlordsrow->firstname ; 
    
   ?>
   

   
   <?php
}} else {
    echo "General";
}
	
				
				?></td> 
                 <td><?php  $plotno=$c->plotno;
$plotnames = $this->accomodationmodel->getplotid($plotno);
								
echo $plotnames[0]['name'];
			 
				 
				 
				 
				 ?></td>
     <td><?php echo $c->amount ; ?></td>
	      <td><?php echo $c->paid ; ?></td>

  <td><?php echo $c->direct ; ?></td>
  <td><?php echo $c->advance ; ?></td>
	  <td><?php echo $c->cash ; ?></td>
	  
	  
	  	  <td><?php echo $c->mpesa ; ?></td>
	  <td><?php echo $c->card ; ?></td>
	  <td><?php echo $c->cheque ; ?></td>
	  <td><?php echo $c->balance ; ?></td>


	  
	  
	  
	  
	  
	   <td><?php echo $c->user ; ?></td>
	   <td><?php echo $c->controller ; ?></td>
	    <td><?php echo $c->description ; ?></td>
		  <td><?php echo $c->status ; ?></td>
			   <td>
	 <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/viewmoredocs?randomitemidentifier=<?php   {echo  $img_id;}  ?>">View document  </a>

	  </td>
	    	 <td> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									<?php
										if($usertype=="admin"){
											
											?>
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'     data-toggle='modal' data-target='#deltemyModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
</td>
             </tr>

	<?php endforeach;} ?>

              <?php }?>

        </table>

			  <div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "  Records in the system. " ;?>    </span>

        
        </div>						
									
									
					
					
					
					
					
					
					
					
					
					</div>	
			
<div id="addModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Add new Landlord Payment</h4>
      </div>
      <div class="modal-body">
      
	  	 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewexpenditure">


				<?PHP
//$session_data = $this->session->userdata('logged_in');
 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
$img_id = rand(1, 99).time();

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('admin/addallpayments' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

<div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">landlord Name</label>
    <div class="col-sm-10">
				    	
			  	<select name="landlord" class="form-control" required>
<option value="" >---Select landlord for this plot---</option>

		<?php 

$landlord = $this->accomodationmodel->populatealllandlord();


if(is_array($landlord)) {

   foreach($landlord as $landlordrow){

    ?>
	    <option value="<?php echo set_value('landlord',$landlordrow->id); ?> "><?=$landlordrow->lastname." ".$landlordrow->firstname;?></option>

   
    <?php

}} else {
    echo 'There is no other  landlord for this house.... Please add landlord first.';
}

?>
	</select>
				

	  <span class="text-danger"><?php echo form_error('landlord'); ?></span>
	</div>
  </div>








	<input type="hidden" name="view"   value="admin/allpayments"  class="form-control">


  	
  
  
  
  
   <div class="form-group" >
						<label for="field-2" class="col-sm-2 control-label">Plot Name</label>
		                    <div class="col-sm-10">
		                        <select name="plotno" class="form-control"  id="plotno"  >
		                            <option selected value="">--Select Plot--</option>
											                            <option  value="all">all my plots</option>

									   <?php
									$plot = $this->accomodationmodel->populateallplots();


if(is_array($plot)) {

   foreach($plot as $plotrow){

    ?>
	    <option  value="<?php echo set_value('plotno',$plotrow->id); ?> "><?=$plotrow->name ."(".$plotrow->id.")" ;?></option>

   
    <?php

}} else {
    echo 'There is no plot in the system.... Please add plot first.';
}

?>
			                        
			                    </select>
								     <span class="text-danger"><?php echo form_error('plotno'); ?></span>
			                </div>
	</div>
	

  	<div class="form-group">
    <label for="inputcreatedat" class="col-sm-2 control-label">	Date paid </label>
    <div class="col-sm-10">
	
   				<input type="text" name="createdat" value="<?php echo set_value('createdat',$date); ?>" id="idno" class="form-control"  placeholder="Enter Start Date">
		 
				
		<span class="text-danger"> <?php echo form_error('createdat'); ?>
		
		</span>
	</div>
	</div>
<div class="form-group">
    <label for="inputmonth" class="col-sm-2 control-label">	Month </label>
    <div class="col-sm-10">
	
   				<input type="text" name="month" value="<?php echo set_value('month',$month); ?>" id="idno" class="form-control"  placeholder="Enter month">
		 
				
     <span class="text-danger"><?php echo form_error('month'); ?></span>
		
	</div>
  </div>
  
  
<div class="form-group">
    <label for="inputyear" class="col-sm-2 control-label">	Year </label>
    <div class="col-sm-10">
	
   				<input type="text" name="year" value="<?php echo set_value('year',$year); ?>" id="idno" class="form-control"  placeholder="Enter year">
		 
				
     <span class="text-danger"><?php echo form_error('year'); ?></span>
		
	</div>
  </div>
  
	<div class="form-group">
    <label for="inputtype" class="col-sm-2 control-label">	Receipt No </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="receiptno" value="<?php echo set_value('receiptno',$img_id); ?>" class="form-control"  placeholder="Enter receipt number">
		 
				
		<span class="text-danger"> <?php echo form_error('receiptno'); ?>
		
		</span>
	</div>
  </div>
  	<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Exp TT	Amount </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="amount"  value="0" class="form-control" required placeholder="Enter Expected Total Amount ">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
   	<div class="form-group">
    <label for="inputadvance" class="col-sm-2 control-label">Advance Payments </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="advance"  value="0" class="form-control" required placeholder="Enter any advance payments ">
		 
				
		<span class="text-danger"> <?php echo form_error('advance'); ?>
		
		</span>
	</div>
  </div>
  <div class="form-group">
    <label for="inputdirect" class="col-sm-2 control-label">Direct Payments </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="direct" value="0" class="form-control" required placeholder="Enter any direct payments ">
		 
				
		<span class="text-danger"> <?php echo form_error('direct'); ?>
		
		</span>
	</div>
  </div>
     <div class="form-group">
    <label for="inputcash" class="col-sm-2 control-label">Cash Paid</label>
    <div class="col-sm-10">
				<input type="text" name="cash" value="0" id="cash" class="form-control" required placeholder="Enter cash">
        <span class="text-danger"><?php echo form_error('cash'); ?></span>
	</div>
  </div>
   <div class="form-group">
    <label for="inputmpesa" class="col-sm-2 control-label">Mpesa Paid</label>
    <div class="col-sm-10">
				<input type="text" name="mpesa" value="0" id="mpesa" class="form-control" required placeholder="Enter Mpesa">
        <span class="text-danger"><?php echo form_error('mpesa'); ?></span>
	</div>
  </div>
  <div class="form-group">
    <label for="inputcard" class="col-sm-2 control-label">Visa/Master Card</label>
    <div class="col-sm-10">
				<input type="text" name="card" value="0" id="card" class="form-control" required placeholder="Enter card amount">
        <span class="text-danger"><?php echo form_error('card'); ?></span>
	</div>
  </div>
  
    <div class="form-group">
    <label for="inputcheque" class="col-sm-2 control-label">Cheque</label>
    <div class="col-sm-10">
				<input type="text" name="cheque" value="0" id="cheque" class="form-control" required placeholder="Enter cheque amount">
        <span class="text-danger"><?php echo form_error('cheque'); ?></span>
	</div>
  </div>
  
  
    <div class="form-group">
    <label for="inputbalance" class="col-sm-2 control-label">Balance</label>
    <div class="col-sm-10">
				<input type="text" name="balance" readonly value="0" id="balance" class="form-control" required placeholder="Enter balance amount">
        <span class="text-danger"><?php echo form_error('balance'); ?></span>
	</div>
  </div>
  
  
  
  
   	<div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">Paid by? </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="user" value="<?php echo set_value('user'); ?>" class="form-control" required placeholder="Enter the person in charge">
		 
				
		<span class="text-danger"> <?php echo form_error('user'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">ID No </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="idno" value="<?php echo set_value('idno'); ?>" class="form-control"  placeholder="idno of person incharge ">
		 
				
		<span class="text-danger"> <?php echo form_error('idno'); ?>
		
		</span>
	</div>
  </div>
  <div class="form-group">
    <label for="inputcontact" class="col-sm-2 control-label">Contact </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="contact" value="<?php echo set_value('contact'); ?>" class="form-control"  placeholder="Phone of person incharge ">
		 
				
		<span class="text-danger"> <?php echo form_error('contact'); ?>
		
		</span>
	</div>
  </div>
  	<div class="form-group">
    <label for="inputcontroller" class="col-sm-2 control-label">Approved by? </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="controller" value="<?php echo set_value('controller'); ?>" class="form-control" required placeholder="Confirmed by?">
		 
				
		<span class="text-danger"> <?php echo form_error('controller'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
  
  
<div class="form-group">
    <label for="inputphoto" class="col-sm-2 control-label">	Upload Document</label>
    <div class="col-sm-10">
	<input type="hidden" name="img_id"   value="<?php if(isset($img_id)) {echo $img_id; }?>"  class="form-control">


	<input type="file" name="photo" value="<?php echo set_value('photo'); ?>"id="photo" class="form-control"  placeholder="Please upload image if any">
			<span class="text-danger"> <?php echo form_error('photo'); ?>
		
		</span>
	</div>		
</div>

	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Description</label>
    <div class="col-sm-10">

				<textarea name="description" value="<?php echo set_value('description'); ?>"   class="form-control"  placeholder="Enter description"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="allpayments" name="btn_addallpayments" class="btn btn-primary"> Add Payment   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>

		
									
									
							</div>		
									
							</div>
						</div>
				

			
			</div>
		</div>
  
  </div>
			
			
			
		
		
  

 
</div>














		
 <div id="deltemyModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Delete</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to delete this item? </h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('adminlogged_in');
 echo $this->session->flashdata('deletemsg'); 

		
                 echo form_open('user/deletebyid' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="allpayments">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/allpayments">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
          <input type="hidden" id="plotno1"name="plotno" class="form-control" placeholder="plotno"  value="">
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>
			



