
      <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); 
		   
		   
        });
		
		
		
    </script> 





<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="#add" data-toggle="tab"><i class="entypo-plus-circled"></i>
					 Bulk Utilities Invoice 
                    	</a></li>
						
							<li>
            	<a href="#utilities" data-toggle="tab"><i class="entypo-plus-circled"></i>
					View Invoiced Utilities  
                    	</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'); 
	 $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;
					}	 
			?>
            <!----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>House Number </th>
	<th>Plot Name</th>
    
	<th>Type</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."</br>". $c->transactioncode; ?></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->paymentstatus ; ?></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."    "; ?>
						 
						 
																							 						<a  id="more" class="btn btn-success" href="<?php echo base_url();?>admin/rentinvoicedetails?transactioncode=<?php echo $c->transactioncode ;  ?>">Sms Invoice </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>
									
                                    <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>

											<li>


                                     
				<a  id="more" class=" btn-success"  target="_blank"  href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo  $c->transactioncode;}  ?> ">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															View	GL Transactions
                                                </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 > 
		 
		 

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



</div>

</div>
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			   <div class="tab-pane box" id="utilities" 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 No</th>
    
	<th>Type</th> 	
	<th>Tenant </th> 
	<th>Amount </th> 
		<th> Invoice Name</th> 
		<th> Month </th> 
		<th> Year </th> 
	<th> Invoice Date </th> 
	<th>Due Date</th> 
 
	 <th>More</th> 




                 </tr>
             </thead>
<?php

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

 {



   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 
  
  	foreach ($otherinvoice as $c): 

		 

             ?>



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


?>

             <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->paymentstatus ; ?></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 $c->amount ; ?></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 echo $c->month ; ?></td>
							         <td><?php echo $c->year ; ?></td>
                     <td><?php echo $c->createdat; ?></td>
					     <td><?php echo $c->duedate; ?></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-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>
		<!----CREATION FORM STARTS---->
		<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/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="invoice">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/invoice?randomitemidentifier1=">
 <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 class="tab-pane box" id="add" 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 bulk invoice
            	</div>
            </div>
			<div class="panel-body">





				<?PHP
				  $monthinvoice = Date('M') ;
				  $mydescription= $monthinvoice." invoice";
				 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
				 $currentmonthyear = Date('Y-m') ;
			 
		 $plotdata=$this->usermodel->populateallarray('plot','id', $plotno);

  $invoicedate=($plotdata[0]['invoicedate']);
	$penaltydate=($plotdata[0]['penaltydate']);	
				
				
				echo $this->session->flashdata('msg'); 
				
				$startdate=$currentmonthyear."-".$invoicedate;
						$enddate=$currentmonthyear."-".$penaltydate;

                 echo form_open('addbulkinvoice' , 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="type" value="<?php echo set_value('type','rent'); ?>" id="idno" class="form-control" required placeholder="Enter type">
	
 
  <div class="form-group">

    <label for="inputplotno" class="col-sm-2 control-label">Plot Number</label>
    <div class="col-sm-7">
	<input type="text" name="plotno" readonly value="<?php  echo $plotno  ; ?>"id="plotno" class="form-control" required placeholder="Enter invoice 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">Month of Invoice</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 Invoice</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">Invoice Date</label>
    <div class="col-sm-7">
				<input type="date" name="createdat" value="<?php echo set_value('createdat',$startdate); ?>" 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">Due Date</label>
    <div class="col-sm-7">
				<input type="date" name="duedate" value="<?php echo set_value('duedate',$enddate); ?>" id="idno" class="form-control" required placeholder="Enter Due Date">
        <span class="text-danger"><?php echo form_error('duedate'); ?></span>
	</div>
  </div>
					
   <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Charge Name</label>
    <div class="col-sm-7">
				    	
			  	<select name="chargeid" class="form-control" required>
				
<option value="" >---Select charges to Invoice---</option>
<option value="all" selected>Invoice Everything</option>

		<?php 

 
if(is_array($plotcharges)) {

   foreach($plotcharges as $plotchargessrow){
	   
	   	$housescharge = $this->usermodel->populateallarray('charges','id',$plotchargessrow->chargeid);

		
		
		
     $type = $housescharge[0]['type'];
	   

    ?>
	    <option value="<?php echo set_value('chargeid',$plotchargessrow->chargeid); ?> "><?=$type?></option>

   
    <?php

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

?>
	</select>
				

	  <span class="text-danger"><?php echo form_error('amount'); ?></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"><?php echo set_value('description',$mydescription); ?></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_invoice" value="invoice" class="btn btn-primary">Add Bulk invoice to Plot (<?php  echo $plotno  ; ?>)</button>

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


   </div>
   
   
   
  


   </div>
</div>




			