
      <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); 
		   
        });
		
				 $(document).on("click", "#managebtndelete2", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid2").val(itemid); 
		  
		    var plotno = $(this).data('plotno');
		   $("#plotno2").val(plotno); 
		     
		    var houseno = $(this).data('houseno');
		   $("#houseno2").val(houseno); 
		   
		    var mytransactioncode = $(this).data('transactioncode');
		   $("#mytransactioncode").val(mytransactioncode); 
		   
		   	       var ttamount = $(this).data('amount');
		   $("#ttamount").val(ttamount);
		   
        });
		
		
    </script> 

<?php
	echo $this->session->flashdata('msg'); 
			 
	 $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'];	
					
					  function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
			?>




<ul class="nav nav-tabs bordered">
			<li class="active">
            	<a href="#list" data-toggle="tab"><i class="entypo-menu"></i> 
					All Invoices for this House
                    	</a></li>
			
				
						
							<li>
            									 <a href="<?php echo base_url(); ?>admin/viewpallmyplots">Back Home </a>


							</li>
		</ul>
    	<!------CONTROL TABS END------>
        
		<div class="tab-content">
		<?php
					echo $this->session->flashdata('deletemsg'); 

			?>
            <!----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>Inv No </th>
    <th>Room No</th>
	<th>Plot Name</th>
    
	<th>REF No</th> 	
	<th>Tenant </th> 
	<th>Amount </th> 
	<th>Paid </th> 
	<th>Balance </th> 
		<th> Description</th> 
	
	<th> Invoice Date </th> 
	<th>Due Date</th> 
		<th>More</th> 


                 </tr>
             </thead>
<?php

		if(validation_errors()):
		 endif;
 if(!is_array($invoice)) 

 {



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

		 $confirm= $this->accomodationmodel->confirmrentpayments($c->companyid,$c->transactioncode);
$amount=$confirm[0]["amount"];
$paid=$confirm[0]["paid"];
$balance=$c->amount-$paid;
$totalpaid=$totalpaid+$paid;
		   $totalinvoice= $totalinvoice+$c->amount ;
   $totalbalance=  $totalinvoice-$totalpaid;
             ?>



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


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

             <td><?php echo $c->houseno ; ?></td> 
				<td><?php 
$myplot = $this->usermodel->populateallarray('plot','id',$c->plotno);
										echo$myplot[0]['name'];
								


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

                 <td><?php  $tenantid=$c->tenantid ; 
				 
				 
				    $tenants = $this->accomodationmodel->gettenantbyid($tenantid);
								


if(is_array($tenants)) {

   foreach($tenants as $tenantsrow){

   echo $tenantsrow->lastname. "  ".$tenantsrow->firstname ; 
    

}} else {
    echo $c->tenantid;
}
				 
				 
				 
				 
				 
				 ?></td>
				   		       <td><?php echo formatMoney($c->amount,true) ; ?></td>
										   			       <td><?php echo formatMoney($paid,true) ; ?></td>
														       <td><?php echo formatMoney($balance,true) ; ?></td>
					   <td><?php echo $c->description ; ?></td> 
					      
                     <td><?php echo $c->createdat; ?></td>
					     <td><?php echo $c->exactime; ?></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>
									
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                 
										
										<li>
												 						<a  id="more" class="btn btn-info" href="<?php echo base_url();?>admin/rentinvoicedetails?transactioncode=<?php echo $c->transactioncode ;  ?>"> View Utilities Invoiced  </a>

                                        </li>
                                              <li class="divider"></li>
										<?php
										if($usertype=="admin"){
											
											?>
											  <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>
										<?php
										}
										?>
									
                                    
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
										
                                </div>
							</td>
		 
            
             </tr>

             <?php endforeach; ?>

              <?php }?>
			  
				   <tfoot>
<th>
    <td colspan="4">Total invoice</td> 
 					   				 

	 <td colspan="1"><b><?php 
	if(isset($totalinvoice)) {echo formatMoney($totalinvoice,true) ; }
	 ?> </b></td > 
	     <td>TT Balance</td> 
	 <td colspan="3"><b><?php 
	if(isset($totalbalance)) {echo  formatMoney($totalbalance,true) ;}
	 ?> </b></td > 
		 
		   <td colspan="2"></td> 

                 </th>
				  </tfoot>
        </table>



</div>

</div>
		<!----CREATION FORM STARTS---->
		
		
		
		
		 <div id="myModal2" 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">Cancel Utility</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to Cancel Utility 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="table"name="table2" class="table" placeholder="view" value="invoice">
 <input type="hidden" name="transactioncode" id="mytransactioncode" placeholder="transactioncode" value=""><br>
 <input type="hidden" id="ttamount"name="amount" class="amount" placeholder="amount" value=""><br>
 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/rentinvoice?randomitemidentifier=">
  <input type="hidden" id="view2"name="view2" class="view2" placeholder="view" value="&randomitemidentifier1=">
 <input type="hidden" id="houseno2"name="houseno" class="houseno" placeholder="houseno" value=""><br>

 <input type="hidden" id="itemid2"name="itemid" class="itemid" placeholder="itemid" value=""><br>
          <input type="hidden" id="plotno2"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"> Cancel  </button>

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

  </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 cancel this invoice  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="receipt">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/rentinvoice?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 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 invoice/receipt? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('admin/deletestudentdocuments' , 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="documentname1"name="documentname" class="form-control" placeholder="Full Name"  value="">
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletestudentdocuments" class="btn btn-danger"> Delete  </button>

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

  </div>

  </div>






   </div>
</div>




			