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

<?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['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
		echo $this->session->flashdata('deletemsg'); 
					
					  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;
					}
					
			
	        		$configuration= $this->usermodel->populateallarray('smsconfig','id',$companyid);
					
					
					
					
					
					
					
					
					
			?>




<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/searchhouse">Search tenant statement </a>


							</li>
					
							<li>
            									 <a href="<?php echo base_url(); ?>admin/searchstatement">Search more statement </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">
 
 
 <div class="panel panel-primary" data-collapsed="0">
 	<div class="table-responsive">
			<div id="printableArea">
			
			<table width="100%">
           
			
			<tr>
				 	
	<td colspan="2" width="100%">
	<center>
	
	
		<?php 
																				 $countbranch=$this->usermodel->countbranches($companyid);

										 if( $countbranch>1){
										 $mybranches= $this->usermodel->populateallarray('branch','id',$branchid);
										$branchdescription=$mybranches[0]['description']; if(isset($branchdescription)) {echo   $branchdescription; }


										}else{
									$bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }
 
											 
										 }
										?>
					
					
		</center>	
		</td>

			</tr>
			<?php if(isset($fromdate)) {
			
				
				

			?>
		<tr>
				<td>

				<h4><b>Account statement for <?php echo $myname; ?>  between <?php echo date("d/m/Y", strtotime($fromdate)); ?> and <?php echo  date("d/m/Y", strtotime($todate)) ?>.</b></h4>	</td>
					<td><h4><b>Printed on <?php echo $date = date("H:s d/m/Y"); ?></b></h4></td>

		</tr>
			
			
				<?php 
				
				}
			
			?>
			
			
			
</table >
 
<table id="example"  cellspacing="1" class="table  table" width="100%" border="1">
             <thead>
			
         <tr>
      <th>Inv No </th>
    <th>Hs No </th>
	<th>Plot Name</th>
    
	<th>Type</th> 	
		<th>Name</th> 	
	<th>Tenant </th> 
	<th>Amount </th>
<?php

if($paymentstatus!="receipt"){
	?>
	
		<th>Paid </th> 
	<th>Balance </th> 
	
<?php	
}
?>	

		<th> Code </th> 

	<th> Invoice Date </th> 

		<th>More</th> 


                 </tr>
             </thead>
			 
             <tr>
			 
			   <td colspan="8"><b>Opening Balance</b></td> 

             <td>0</td>
             </tr>
<?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): 
$balance=$c->amount -$c->paid;
$totalpaid=$totalpaid+$c->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 

	   
			        		$getplot = $this->usermodel->populateallarray('plot','id',$c->plotno);

						echo$plotname=$getplot[0]["name"];


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

		   	
				$mycharges = $this->usermodel->populateallarray('charges','id',$c->type);
					
					if($mycharges[0]['type']!=""){
						echo $mycharges[0]['type'];
					}else{
						
						echo $c->type ;
					}
					   


 ?></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>
										   	
					      
						  
						  
						  
						  <?php

if($paymentstatus!="receipt"){
	?>
			       <td><?php echo formatMoney($c->paid,true) ; ?></td>
				 <td><?php echo formatMoney($balance,true) ; ?></td>
	
<?php	
}
?>	

						  
						  
						  						  <?php

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

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

	

<?php	
}
?>	

						  			  
                     <td><?php echo $c->createdat; ?></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" target="_blank" href="<?php echo base_url();?>admin/rentinvoicedetails?transactioncode=<?php echo $c->transactioncode ;  ?>"> View Utilities Invoiced  </a>

                                        </li>
                                              <li class="divider"></li>
								
                                    
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
										
                                </div>
							</td>
		 
            
             </tr>

             <?php endforeach; ?>

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

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

if($paymentstatus !="receipt"){
	?>
			     <td>TT Balance</td> 
	 <td colspan="3"><b><?php 
	if(isset($totalbalance)) {echo  formatMoney($totalbalance,true) ;}
	 ?> </b></td > 
		 
	
<?php	
}else{
	
	
}
?>	

	

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



</div>

</div>
		<!----CREATION FORM STARTS---->
		




   </div>
</div>




			