
      <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
                    	</a></li>
			
						<li>
            	<a href="#thirdtab" data-toggle="tab"><i class="entypo-plus-circled"></i>
					Add  Charges Invoices  
                    	</a></li>
						
								<li>
            	<a href="#utilities" data-toggle="tab"><i class="entypo-plus-circled"></i>
					View Invoiced Utilities  
                    	</a></li>
							
							<li>
										                     <a class="btn btn-info"  id="more" href="<?php echo base_url();?>admin/receivepayment?randomitemidentifier=<?php   {echo  $houseno;}  ?>&randomitemidentifier1=<?php   {echo  $plotno;}  ?>&category=<?php echo $category; ?>">Receive payments  </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" id="utilities" style="padding: 5px">

			

				
     


				 		 	<div class="pull-right"  id="non-printable" >

<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('example')" value="print receipt!" />
</form></div>

 <div class="panel panel-primary" data-collapsed="0" >
 
<table id="example"  cellspacing="1" class="table" width="100%">
             <thead>
			
         <tr>
    
    <th> No </th>
		    <th id="non-printable">Priority </th>

	<th>Name</th>
    
	<th>Ref No</th> 	
	<th>Customer </th> 
	<th>Exp Amount </th> 
		<th>Paid </th> 
		<th>Copa </th> 
			<th>comm </th> 
			
			
		<th> Invoice Name</th> 
		<th> Month </th> 
		<th> Year </th> 
	<th> Invoice Date </th> 
	<th>Due Date</th> 
		<th id="non-printable">More</th> 
  <!---<th>Delete</th> -->
	 




                 </tr>
             </thead>
<?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'];	
		if(validation_errors()):
		 endif;
 if(!is_array($otherinvoice)) 

 {




    }else {
?>
    
             <?php 
    $totalpaid=0;
  
  $totalinvoice=0;
    $totalbalance=0;
  	foreach ($otherinvoice as $c): 

		 

             ?>


             <tr>
                
            <?php 
		$id=$c->id;
  $totalpaid= $totalpaid+$c->paid ;
  
  $totalinvoice= $totalinvoice+$c->amount ;
    $totalbalance=  $totalinvoice-$totalpaid;

?>

             <td><?php echo $c->houseno ; ?></td> 
			              <td id="non-printable"><?php echo $c->priority ; ?></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;
}
				 $mydifference=0;
				 $diffrence=($c->amount-$c->paid)+ $c->coparent  ;
				 if( $diffrence < $c->amount){
					 $mydifference= $diffrence;
				 }else{
					 $mydifference= 0;
 
					 
				 }
				 
				 
				 
				 ?></td>
				       <td><?php echo $c->amount ; ?></td>
					         <td><?php echo $c->paid ; ?></td>
							     <td><?php echo $c->coparent ; ?></td>
							     <td><?php echo $TTCOM=($c->commission+$c->coparentcommission) ; ?></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 id="non-printable">
					<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-info managebtn" id="managebtncoparent" data-type='<?php echo  $c->type;?>'  data-coparentvat='<?php echo  $c->coparentvat;?>'  data-coparentcommission='<?php echo  $c->coparentcommission;?>'  data-coparent='<?php echo  $c->coparent;?>' data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'	 data-amount='<?php echo  $mydifference;?>'   data-toggle='modal' data-target='#Coparent<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Pay through Coparent 
                                                </a>
                                                        </li>
										
                                           <li class="divider"></li>
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete2"	data-transactioncode='<?php echo  $c->transactioncode;?>'   data-amount='<?php echo  $c->amount;?>' data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#myModal2<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel Invoice
                                                </a>
                                                        </li>
									
									
                                        <li class="divider"></li>
                                        				
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtncancelpayamnt"	 data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#myClearpaymentModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Cancel real payment
                                                </a>
                                                        </li>
														
														      <li class="divider"></li>
														
														  <li> 
										 <a class="btn btn-danger managebtn" id="managebtncancelpayamntcopa"	 data-houseno='<?php echo  $c->houseno;?>'	 data-id='<?php echo  $c->id;?>'   data-plotno='<?php echo  $c->plotno;?>'  data-toggle='modal' data-target='#myClearpaymentModalCopa<?php  $c->id; ?>'>	 


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

             <?php endforeach; ?>

              <?php }?>
 <tfoot>
<th>
    <td colspan="5"></td> 
 
	
	 <td colspan="9"><b>Total Balance:<?php 
	if(isset($totalbalance)) {echo  "KSHS  =" .$totalbalance; }
	 ?> </b></td > 
		 
	

 
	 
	




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


</div>

</div>
			
			
			
			
			
			
            <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> No</th>
	<th> Name</th>
    
	<th>REF No</th> 	
	<th>Name </th> 
	<th>Amount </th> 
	<th>Paid </th> 
	<th>Balance </th> 
		<th> Description</th> 
	
	<th> Invoice Date </th> 
	<th>Due Date</th> 
			<th id="non-printable">Print</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  id="non-printable" >
						
			 <a class="btn btn-primary"  target="_blank" id="more" href="<?php echo base_url();?>admin/housereceiptinvoice?randomitemidentifier=<?php   {echo  $c->id;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;}  ?>&nyumbaid=<?php   {echo  $c->tenantid;} ?>">Print  </a>

																	 						<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>
										<?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>
																Cancel
                                                </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="3"></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 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>
				invoice other Charges
            	</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('addinvoice' , 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;?>
			<CENTER>CREATE A NEW INVOICE</CENTER>		
  <div class="form-group">

    <label for="inputhouseno" class="col-sm-2 control-label"> Number</label>
    <div class="col-sm-7">
			  		<input type="text" readonly name="houseno" value="<?php  echo $houseno ; ?>"id="invoiceno" class="form-control" required placeholder="Enter invoice 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" style="display:none">

    <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">
				<input type="hidden" name="paymentcode" value="<?php echo set_value('paymentcode'); ?>" id="idno" class="form-control"  placeholder="Enter paymentcode">


     <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 
		$tenantid=$tenant[0]['tenantid'];
		$tenantsdetails = $this->accomodationmodel->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 {
    		$this->session->set_flashdata('msg1','<div class="alert alert-danger text-center">Oops! Error. No tenant yet allocated.. Please allocate the room first for you to invoice it </div>');
	echo $this->session->flashdata('msg1');
}
				 
		
	?>	
		
		<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">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="inputphone3" class="col-sm-2 control-label">Description </label>
    <div class="col-sm-7">
	<textarea name="description" 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>
		 


		 
	
        
  





<table cellpadding="0" cellspacing="0" border="0" class="table  table" id="example" style="border-color:#CCCCCC; width:100%;"  >

  <tr>

    <th>Charge name</th>

    <th>Invoice?</th>    

    <th>Amount</th>    

    <th>Month</th>   
 <th>Year</th>  


  </tr>

<?php 

if(is_array($charges)) {

   foreach($charges as $chargesrow){

   $chargeid=$chargesrow->chargeid;
   $chargesbyid = $this->accomodationmodel->getchargesbyid($chargeid);
								


if(is_array($chargesbyid)) {

   foreach($chargesbyid as $chargesbyidrow){

  echo "<tr>";
$chargetype="";
    

    echo "<td>".$chargesbyidrow->type."=".$chargesrow->cost."=".$chargesrow->name;
	?>
<input type="hidden" name="type[]" value="<?php echo set_value('type',$chargesbyidrow->id); ?>" id="type" class="form-control" required placeholder="Enter harge type">
<input type="hidden" name="name[]" value="<?php echo set_value('type',$chargesrow->name); ?>" id="type" class="form-control" required placeholder="Enter charge name">

<input type="hidden" name="priority[]" value="<?php echo set_value('type',$chargesbyidrow->priority); ?>" id="type" class="form-control" required placeholder="Enter priority ">

</td>
	 <td>
	<select name="yesno[]" class="form-control" required>
<option value="" >Invoice this charge?</option>
<option value="Yes"  >Yes</option>
<option value="No" selected="selected" >No</option>
	</select>
				</td>
				 <td><?php
				 $chargetype=$chargesbyidrow->type;
				 if($chargetype=="RENT"){
					?> 
									<input type="text" name="amount[]" value="<?php echo set_value('amount',$chargesrow->cost); ?>" id="idno" class="form-control"  placeholder="Enter amount for the charge">

					<?php 
				 }else{
					?> 
									<input type="text" name="amount[]" value="<?php echo set_value('amount',$chargesrow->cost); ?>" id="idno" class="form-control"  placeholder="Enter amount for the charge">

					<?php
				 }
				 ?>
    </td>
   <td>
	<select name="month[]" class="form-control" required>
<option value="" >Select month</option>

<option value="<?php echo $month; ?>" selected="selected" ><?php echo  $month; ?></option>
<option value="01"  >01</option>
<option value="02"  >02</option>
<option value="03"  >03</option>
<option value="04"  >04</option>
<option value="05"  >05</option>

<option value="06"  >06</option>
<option value="07"  >07</option>
<option value="08"  >08</option>
<option value="09"  >09</option>
<option value="10"  >10</option>
<option value="11"  >11</option>
<option value="12"  >12</option>

	</select>
   </td>
     <td>
   				<input type="text" name="year[]" value="<?php echo set_value('year',$year); ?>" id="idno" class="form-control"  placeholder="Enter year">

   </td>
    
   				<input type="hidden" name="createdat2[]" value="<?php echo set_value('createdat',$date); ?>" id="idno" class="form-control"  placeholder="Enter Start Date">

 
	 				<input type="hidden" name="duedate2[]" value="<?php echo set_value('duedate',$date); ?>" id="idno" class="form-control"  placeholder="Enter Due Date">

	

 
<?php
}} else {
    echo 'There is no charge in the system.... try again.';
}
   
   
  

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


?>

</table>
		  
  <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 for other charges</button>

    </div>
  </div>
            

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




			