
   <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		    var plotno = $(this).data('plotno');
		   $("#plotno1").val(plotno); 
		     
		    var houseno = $(this).data('houseno');
		   $("#houseno1").val(houseno); 
		   
        });
		
		
		
    </script> 


<ul class="nav nav-tabs bordered">
			<li class="active">
            	<a href="#list" data-toggle="tab"><i class="entypo-menu"></i> 
					All Payment for this Room
                    	</a></li>
			
						<li>
            	<a href="#thirdtab" data-toggle="tab"><i class="entypo-plus-circled"></i>
					Add  Payment  
                    	</a></li>
							<li>
            	<a href="#balance" data-toggle="tab"><i class="entypo-plus-circled"></i>
					ALL BALANCE 
                    	</a></li>
		</ul>
    	<!------CONTROL TABS END------>
        
		<div class="tab-content">
            <!----TABLE LISTING STARTS-->
            <div class="tab-pane box active" id="list">
				
     


 <div class="panel panel-primary" data-collapsed="0">
 
<table id="example"  cellspacing="1" class="table  table" width="100%">
             <thead>
			
         <tr>
    
    <th>Room Number </th>
	<th>House Name</th>
    
	<th>Mode</th> 	
	<th>Customer </th> 
	<th>Amount </th> 
	<th>Reason </th> 
		<th>Type</th> 
		<th> Month </th> 
		<th> Year </th> 
	<th> Payment Date </th> 
	<th> Paid By: </th> 
 <th> Print: </th> 
	 
	 <th> Monthly: </th> 

	 <th> More: </th> 


                 </tr>
             </thead>
<?php
	 $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];

 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
				echo $this->session->flashdata('msg'); 
 
		if(validation_errors()):
		 endif;
 if(!is_array($payment)) 

 {



   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='13'>";
    
       echo '<div class="alert alert-warning text-center">There is no Payment found by now from system..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  
  	foreach ($payment as $c): 

		 

             ?>



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


?>

             <td><?php echo $c->houseno ; ?></td> 
				<td><?php echo $c->plotno ; ?></td> 
<td><?php 


  $paymentsectionbyid = $this->adminusermodel->getpaymentsectionid($c->paymentmode);
								


if(is_array($paymentsectionbyid)) {

   foreach($paymentsectionbyid as $paymentsectionbyidrow){

  echo $paymentsectionbyidrow->name ; 
    

}} else {
    echo 'Invoiced';
}







?></td> 
					

              
				 				         <td><?php 
					
   $tenantid=$c->tenantid;
				    $tenants = $this->adminusermodel->gettenantbyid($tenantid);
 if(is_array($tenants)) {
   foreach($tenants as $tenantsrow){

    $names=$tenantsrow->lastname. " ".$tenantsrow->firstname ; 
   
   ?>
   
                     <a class="btn btn-warning"  target="_blank"  id="more" href="<?php echo base_url();?>admin/edittenant?randomitemidentifier=<?php   {echo  $tenantid;}  ?>"><?php   {echo  $names;}  ?>  </a>

   
   <?php
    

}
    } else {
    echo 'No tenant.';
}
?>
				 
				 
		</td>
				
				       <td><?php echo $c->amount ; ?></td>
					    <td><?php echo $c->type ; ?></td> 
					   <td><?php echo $c->paymentstatus ; ?></td> 
					          <td><?php echo $c->month ; ?></td>
							         <td><?php echo $c->year ; ?></td>
                     <td><?php echo $c->createdat; ?></td>
					     <td><?php echo $c->userid; ?></td>
				
         						<td>
						<?php
						
						$typs=$c->paymentstatus ;
						if ($typs=="receipt"){
							?>
			 <a class="btn btn-primary"  target="_blank" id="more" href="<?php echo base_url();?>admin/housereceiptbyno?randomitemidentifier=<?php   {echo  $c->id;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;}  ?>">Print  </a>

						
						

				
						
						<?php
						}
						?>
				
				</td>
				
							<td>
						<?php
						
						$typs=$c->paymentstatus ;
						if ($typs=="receipt"){
							?>

						
						
				                     <a class="btn btn-primary" target="_blank"  id="more" href="<?php echo base_url();?>admin/allhousereceiptbyno?randomitemidentifier1=<?php   {echo  $c->id;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;} ?>&nyumbaid=<?php   {echo  $c->tenantid;} ?>&year=<?php   {echo  $c->year;} ?>&month=<?php   {echo  $c->month;} ?>">Print (Month)  </a>

				
						
						<?php
						}
						?>
				
				</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-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#myModal<?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>

</div>
		
   
   
   <div class="tab-pane box" id="thirdtab" style="padding: 5px">
			
			



		
<div class="row">
	<div class="col-md-12">
		<div class="panel panel-primary" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" >
            		<i class="entypo-plus-circled"></i>
				Add new Payment
            	</div>
            </div>
			<div class="panel-body">





				<?PHP

				echo $this->session->flashdata('msg'); 
		 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
                 echo form_open('addpayment' , 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;?>
								  		<input type="hidden" name="roomidentifier" value="<?php  echo $roomidentifier ; ?>"id="roomidentifier" class="form-control"  placeholder="Enter roomidentifier">

  <div class="form-group">

    <label for="inputhouseno" class="col-sm-2 control-label">Room Number</label>
    <div class="col-sm-7">
			  		<input type="text" name="houseno" value="<?php  echo $houseno ; ?>"id="Paymentno" class="form-control" required placeholder="Enter Payment number">
  		<input type="hidden" name="action" value="<?php echo set_value('action','insert'); ?>"id="action" class="form-control" required >


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

    <label for="inputplotno" class="col-sm-2 control-label">House Number</label>
    <div class="col-sm-7">
	<input type="text" name="plotno" value="<?php  echo $plotno  ; ?>"id="plotno" class="form-control" required placeholder="Enter Payment number">


     <span class="text-danger"><?php echo form_error('plotno'); ?></span>
   </div>
  </div>
  
 <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Customer Name</label>
    <div class="col-sm-7">
       	<input type="hidden" name="tenantid" value="<?php echo set_value('tenantid',$tenant[0]['tenantid']); ?>" id="idno" class="form-control" required placeholder="Enter Name">
 
		
		<?php 
		$names="";
		$tenantid=$tenant[0]['tenantid'];
		$tenantsdetails = $this->adminusermodel->gettenantbyid($tenantid);
								


if(is_array($tenantsdetails)) {

   foreach($tenantsdetails as $tenantsdetailsrow){

    $names=$tenantsdetailsrow->lastname. " ".$tenantsdetailsrow->firstname ; 
    ?>

	<input type="text" name="mytenantid" value="<?php echo set_value('tenantid',$names); ?>" id="idno" class="form-control" required placeholder="Enter Name">

	<?php

}} else {
  
  
         echo '<div class="alert alert-warning text-center">There is no tenant  found for this house.</div>';


	
}
				 
		
	?>	
		
		<span class="text-danger"><?php echo form_error('tenantid'); ?></span>
	</div>
  </div>
  
  
  
  
		 		  <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Payment for?:</label>
    <div class="col-sm-7">
				    	
			  	<select name="type" class="form-control" required>
<option value="" >---Select charges type---</option>

		<?php 

//$nation = $this->nationmodel->populatenation();


if(is_array($charges)) {

   foreach($charges as $chargesrow){

   $chargeid=$chargesrow->id;

   


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

   
    <?php   


   
   
  

}} else {
    echo 'There is no any  charges for this house.... PLease add charges first.';
}

?>
<!--<option value="all" >---ALL ---</option>-->

	</select>

	  <span class="text-danger"><?php echo form_error('amount'); ?></span>
	</div>
  </div>	
		 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
   <div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Amount</label>
    <div class="col-sm-7">
				<input type="text" name="amount" value="<?php echo set_value('amount'); ?>" id="amount" class="form-control" required placeholder="Enter amount">
        <span class="text-danger"><?php echo form_error('amount'); ?></span>
	</div>
  </div>
  
  
  
  
  
  
  
  
  
  
  
  
 <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Paid By:</label>
    <div class="col-sm-7">
				<input type="text" name="userid" value="<?php echo set_value('userid',$names); ?>" id="idno" class="form-control" required placeholder="Paid by (Name)">
        <span class="text-danger"><?php echo form_error('year'); ?></span>
	</div>
  </div>  
    <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Month of Payment</label>
    <div class="col-sm-7">
				<input type="text" name="month" value="<?php echo set_value('month',$month); ?>" id="idno" class="form-control" required placeholder="Enter month">
        <span class="text-danger"><?php echo form_error('year'); ?></span>
	</div>
  </div>
  <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Year of Payment</label>
    <div class="col-sm-7">
				<input type="text" name="year" value="<?php echo set_value('year',$year); ?>" id="idno" class="form-control" required placeholder="Enter year">
        <span class="text-danger"><?php echo form_error('year'); ?></span>
	</div>
  </div>

   <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Created Date</label>
    <div class="col-sm-7">
				<input type="text" name="createdat" value="<?php echo set_value('createdat',$date); ?>" id="idno" class="form-control" required placeholder="Enter Start Date">
        <span class="text-danger"><?php echo form_error('createdat'); ?></span>
	</div>
  </div>
		  <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Payment Mode</label>
    <div class="col-sm-7">
				    	
			  	<select name="paymentmode" class="form-control" required>
<option value="" >---Select Payment Mode---</option>

		<?php 

//$nation = $this->nationmodel->populatenation();


if(is_array($methode)) {

   foreach($methode as $methoderow){

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

   
    <?php

}} else {
    echo 'There is no other  payment mode for this house.... PLease add charges first.';
}

?>
	</select>
				

	  <span class="text-danger"><?php echo form_error('paymentmode'); ?></span>
	</div>
  </div>			
  
    	 
	   <div class="form-group">
    <label for="inputpaymentcode" class="col-sm-2 control-label">Payment Code</label>
    <div class="col-sm-7">
				<input type="text" name="paymentcode" value="<?php echo set_value('paymentcode'); ?>" id="idno" class="form-control"  placeholder="Enter paymentcode">
        <span class="text-danger"><?php echo form_error('paymentcode'); ?></span>
	</div>
  </div>	 
		 
		 
		 
		 
		 
		 
   <div class="form-group">
    <label for="inputphone3" class="col-sm-2 control-label">Description </label>
    <div class="col-sm-7">
	<textarea name="description" id="ttt" rows="5" placeholder="add Description" class="form-control"></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-7">
     
	       <button type="submit" name="btn_payment" value="payment" class="btn btn-primary">Add Payment</button>

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

   </div>
   
   
   
   
   
   
      
   <div class="tab-pane box" id="balance" style="padding: 5px">
 <div class="panel panel-primary" data-collapsed="0">
 
<table id="example"  cellspacing="1" class="table  table" width="100%">
             <thead>
			
         <tr>
    
    <th>House Number </th>
	<th>Plot Name</th>
    
	<th>Mode</th> 	
	<th>Tenant </th> 
	<th>Amount </th> 
		<th>Reason</th> 
		<th>Type</th> 
		<th> Month </th> 
		<th> Year </th> 
	<th> Payment Date </th> 
	<th> Paid By: </th> 
 	<th> Monthly: </th> 
	 <th></th>
	




                 </tr>
             </thead>
<?php

	echo $this->session->flashdata('msg'); 
		if(validation_errors()):
		 endif;
 if(!is_array($allpayment)) 

 {



   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='13'>";
    
       echo '<div class="alert alert-warning text-center">There is no Payment found by now from system..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $total=0;
  	foreach ($allpayment as $c): 

		 

             ?>



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


?>

             <td><?php echo $c->houseno ; ?></td> 
				<td><?php echo $c->plotno ; ?></td> 
<td><?php 


  $paymentsectionbyid = $this->adminusermodel->getpaymentsectionid($c->paymentmode);
								


if(is_array($paymentsectionbyid)) {

   foreach($paymentsectionbyid as $paymentsectionbyidrow){

  echo $paymentsectionbyidrow->name ; 
    

}} else {
    echo 'Invoiced';
}







?></td> 
					

           
				 
				 
				 
				 				         <td><?php 
					
   $tenantid=$c->tenantid;
				    $tenants = $this->adminusermodel->gettenantbyid($tenantid);
 if(is_array($tenants)) {
   foreach($tenants as $tenantsrow){

    $names=$tenantsrow->lastname. " ".$tenantsrow->firstname ; 
   
   ?>
   
                     <a class="btn btn-warning"  target="_blank"  id="more" href="<?php echo base_url();?>admin/edittenant?randomitemidentifier=<?php   {echo  $tenantid;}  ?>"><?php   {echo  $names;}  ?>  </a>

   
   <?php
    

}
    } else {
    echo 'No tenant.';
}
?>
				 
				 
		</td>
				 
				 
				 
				 
				 
				 
				 
				 
				 
				 
				       <td><?php echo $c->amount ;
  $total=$total+$c->amount ;
					   ?></td>
					   <td><?php echo $c->type ; ?></td> 
					     <td><?php echo $c->paymentstatus ; ?></td> 
					          <td><?php echo $c->month ; ?></td>
							         <td><?php echo $c->year ; ?></td>
                     <td><?php echo $c->createdat; ?></td>
					     <td><?php echo $c->userid; ?></td>
				
         						<td>
						<?php
						
						$typs=$c->paymentstatus ;
						if ($typs=="receipt"){
							?>
			 <a class="btn btn-primary"  target="_blank" id="more" href="<?php echo base_url();?>admin/housereceiptbyno?randomitemidentifier=<?php   {echo  $c->id;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;}  ?>">Print  </a>

						
						

				
						
						<?php
						}
						?>
				
				</td>
				
							<td>
						<?php
						
						$typs=$c->paymentstatus ;
						if ($typs=="receipt"){
							?>

						
						
				                     <a class="btn btn-primary" target="_blank"  id="more" href="<?php echo base_url();?>admin/allhousereceiptbyno?randomitemidentifier1=<?php   {echo  $c->id;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;} ?>&nyumbaid=<?php   {echo  $c->tenantid;} ?>&year=<?php   {echo  $c->year;} ?>&month=<?php   {echo  $c->month;} ?>">Print (Month)  </a>

				
						
						<?php
						}
						?>
				
				</td>
          
             </tr>

             <?php endforeach; ?>

              <?php }?>
<tr>
    
    <th colspan="9">Total Balance</th>
	
	<th colspan="2"><?php 
	if(isset($total)) {echo  "KSHS  =" .$total; }
	 ?> </th> 
		 
	<th  colspan="5">  </th> 

 
	 
	




                 </tr>
        </table>


</div>

</div>


<div id="myModal" 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/deleteallbyid' , 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="invoice">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/invoice?randomitemidentifier=">
  <input type="hidden" id="view2"name="view2" class="view2" placeholder="view" value="&randomitemidentifier1=">
 <input type="hidden" id="houseno1"name="houseno" class="houseno" placeholder="houseno" value=""><br>

 <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>
   </div>
   
</div>




			