
<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">
	
 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>


<script type="text/javascript">
  

		 $(this).ready( function() {  
            $("#transactioncode").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
					  // url: "<?php echo base_url(); ?>Systemusers/branchlookupmpesa",  

                        url: "<?php echo base_url(); ?>Systemusers/branchlookupmpesadebts",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		</script>
		

 


 <style>
  #myDiv 
{
  height:100px;
  width:100px;

}
#myDiv img
{
  max-width:100%; 
  max-height:100%;
  margin:auto;
  border-radius:15px;
  display:block;
}



    #myprint { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;
  
    width:100%; 


}

#sale{  	


    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
		    	#myprint { display: block; font-size:16; width:100%; }

    }
  </style>
  
	 <link href="<?php echo base_url(); ?>assets/select/chosen.min.css" rel="stylesheet" media="screen">
	
		   
		   		   <script src="<?php echo base_url(); ?>assets/select/chosen.jquery.min.js"></script>

  <script type="text/javascript">
        
        
            $(document).ready(function() { 
//
                
                $("#plotno").change(function(){
                 	var plotnoid = $("#plotno").val();
                     /*dropdown post *///
                      $.ajax({
			 		url:"<?php echo base_url();?>admin/populatehousebyid",
			 		
					 data: {plotno: $(this).val()},

                    type: "POST",
                    success:function(data){
                        
                        $("#houseid").html(data);
                    }
                
                    });

               
                });

            });
               $(function () {
        $("#plotno").change(function () {
            if ($(this).val() == "") {
                $("#house").hide();
            } 
            else {
                $("#house").show();
            }
        });
    });
          
        </script>
  
  
  
  
  
  
  
  
  <script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/startsales";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/startsales";

		    // document.body.innerHTML = originalContents;

	}
}
	</script>
  
  
  
				   
	
        <script>
        $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
        </script>
                  
			      <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		 $(document).on("click", "#managebtncheckout", function()
        {
          var itemid2 = $(this).data('id');
		  $("#itemid2").val(itemid2); 
		  
		     var status = $(this).data('status');
		  $("#status").val(status); 
		   
        });
		
		 $(document).on("click", "#managebtnaddpayment", function()
        {
          var itemid3 = $(this).data('id');
		  $("#itemid3").val(itemid3); 
		  
		     var status3 = $(this).data('status');
		  $("#status3").val(status3); 
		   
        });
		
    </script>  









<?PHP




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








$imgid = rand(100, 990000).time();
 $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$totalamount=0;
    $totalbalance=0;
 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];



		  		  	      $backdatesales=$this->usermodel->populatuserpermissionsdataarray('sales','backdatesales',$userid);












?>
<ul class="nav nav-tabs bordered" id="non-printable">
			<li class="active">
            	<a href="#add" data-toggle="tab"><i class="entypo-menu"></i> 
						Add Advance 
                    	</a></li>
			<li>
            	<a href="#list" data-toggle="tab"><i class="entypo-plus-circled"></i>
				View All Advance
                    	</a>
						</li>
	
						
						
								<li>
									 				<a data-toggle='modal' data-target='#addModal' class="btn btn-warning"> Add New Customer </a>
	
						
						</li>
	
		
								<li>


                    
						
										     <a data-toggle='modal' data-target='#viewsms' class="btn btn-primary">Advance Report </a>

						
						</li>
		</ul>
    	<!------CONTROL TABS END------>
        
		<div class="tab-content">
			 <div class="pull-right" style="margin-bottom:20px" id="non-printable" >
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('sortable_table')" value="print receipt!" />
</form></div>
<br>
		<?php
					echo $this->session->flashdata('deletemsg'); 
					echo $this->session->flashdata('msg'); 

			?>
            <!----TABLE LISTING STARTS-->
            <div  class="tab-pane box" id="list">
				
    
		<div class="panel panel-primary" data-collapsed="0" ID="sortable_table">
 <CENTER><B>ADVANCE PAYMENTS</B></CENTER>
<table id="example"  cellspacing="1" class="table table-bordered datatable" width="100%">
             <thead>
			 
         <tr>


 <th>Customer Name </th>
 <th>Expected paid</th> 
  <th>Paid</th> 
    <th>Balance</th>

	<th>IDNO Number</th>	
    <th>Phone Number</th>         
	<th>Start date</th> 
	<th>Due date</th> 
	<th>Description</th> 
	<th>Staff</th> 

 

	<th id="non-printable">Payments</th> 
			  <th>Status </th>
<th id="non-printable">More</th>


                 </tr>
             </thead>
<?php
	
 if(!is_array($advance)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There is no advance found by now from system..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  

  
  	foreach ($advance as $c): 

		 

             ?>



             <tr>
                    
   <td>
            <?php 
		$tenantid=$c->tenantid;
				$myinvoice=$c->houseno;

 $id=$c->id;
 
   $totalamount=$totalamount+$c->amount;
    $totalbalance=$totalbalance+$c->balance;
 							
$mycustomer = $this->usermodel->populateallarray('people','id', $tenantid);
	 $firstname=$mycustomer[0]['firstname'];
	 $idno=$mycustomer[0]['idno'];
	 $phone=$mycustomer[0]['phone'];
	 $lastname=$mycustomer[0]['lastname'];
	 
	 
	 
echo $tenantid."- ";

			
			if($tenantid !=""){
				if($mycustomer[0]['company']!=""){
									echo$myname=$mycustomer[0]['company'];

				}else{
									echo$myname=$mycustomer[0]['firstname'];
									
									

				}
			}

	 
	 
	 
	 
	 
	 
	 
	 
	 


?>
    			
				
				
				
				
				
				
				
				
				
				
				
				

</td> 

		<td><?php  echo formatMoney($c->amount, true);?></td> 
										<td><?php echo formatMoney($c->paid, true);?></td> 
																				<td><?php echo formatMoney($c->amount-$c->paid, true);?></td> 











					 

			 <td><?php echo $idno ; ?></td>
					<td><?php echo $phone ; ?></td> 

            
		
                     <td><?php echo $c->startdate; ?></td>   
                                  <td><?php echo $c->closedate; ?></td>   
                                  <td><?php echo $c->description; ?></td>   
 <td>
												 
	<?php 
					// $branch="";
					 $userid=$c->userid;

					 $user= $this->usermodel->populateall('people','id',$userid);



if(is_array($user)) {

   foreach($user as $userhrow){

   echo $userhrow->surname;
 
 
}} else {
    echo 'No Name.';
}
	
?>
												 
	 </td>	
	 


					          <td id="non-printable">
 <a class="btn btn-info managebtn" id="managebtncheckout"	 data-id='<?php echo  $c->id;?>'     data-status='<?php echo  $c->status;?>'  data-toggle='modal' data-target='#Checkout<?php  $c->id; ?>'>	 Receive
  </a>
   <a class="btn btn-success managebtn" id="managebtnaddpayment"	 data-id='<?php echo  $c->id;?>'     data-status='<?php echo  $c->status;?>'  data-toggle='modal' data-target='#AddPayment<?php  $c->id; ?>'>	 Add
  </a>
  	  	  	  	 <a  id="more" class=" btn-primary"  href="<?php echo base_url();?>user/printadvancereceipt?randomitemidentifier=<?php   {echo  $c->id;}  ?>&myid=<?php   {echo  $userid;}  ?>">Print  </a>

         </td>
		                   <td><?php echo $c->status; ?></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>
									
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                    
 
						<li>
 	
							   <a class="btn btn-success" id="more" href="<?php echo base_url();?>admin/viewmyadvancepayment?randomitemidentifier=<?php   {echo  $c->id;}  ?>">

						
                                                <i>View history</i>
						</a>
						</li>
 						   <li class="divider"></li>

 
 <li>
 	
			 <a class="btn btn-info managebtn" id="managebtncheckout"	 data-id='<?php echo  $c->id;?>'     data-status='<?php echo  $c->status;?>'  data-toggle='modal' data-target='#Checkout<?php  $c->id; ?>'>	 

						
                                                <i>Receive payment</i>
						</a>
						</li>
						   <li class="divider"></li>
						
						
						
												   <li class="divider"></li>

							
						<li>
 	
                     <a  class="btn btn-primary" id="more" href="<?php echo base_url();?>admin/editadvance?randomitemidentifier=<?php   {echo  $id;}  ?>">

						
                                                <i>Update</i>
						</a>
						</li>
						                                        <li class="divider"></li>

						  <?php
										if($usertype=="admin"){
											
											?>
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'     data-toggle='modal' data-target='#myModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
										<?php
										}
										?>
									
									
									
									
									        <li> 
				<a  id="more" class=" btn-success" target="_blank"   href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo  $myinvoice;}  ?> ">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															View	GL Transactions
                                                </a>
																		
										</li>

									
									
									
									
									
									
									
									
						
                                    </ul>
										
                                </div>
</td>

          

             <?php endforeach; ?>

              <?php }?>
  	</tr>
	<tfoot>
			 <tr>
			 
			 <td>					 TOTAL AMOUNT

			 </td>

			
			
			  <td><B>
			  <?php 
echo formatMoney($totalamount, true);


			  ?>
			
			</B> </td>
			 	  <td>
			
			 </td>
			 
			 
			   <td><B>
			  <?php 
echo formatMoney($totalbalance, true);
 ?>
			
			</B> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td> </td>
			   <td id="non-printable"> </td>
			   <td id="non-printable"> </td>

		
			 </tr>
			 	</tfoot>
        </table>

</div></div>
            <!----TABLE LISTING ENDS--->
			
			
			


<div id="viewsms" 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">Booking Report</h4>
      </div>
      <div class="modal-body">
      
	  	

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

 $finalendate=date("Y-m-d H:59:59");
  $finalstartdate=date("Y-m-d 00:00:00");
  
  
  
//

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('admin/searchbookings' , 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;?>

		


  
  
  
  
  

  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$finalstartdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$finalendate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  

  
    

   
  
  <div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">Status </label>
    <div class="col-sm-10">
      <select name="status" required class="form-control" id="section_selector_holder">
		                            <option value="" selected>--Select Status--</option>
			                         			                         <option value="all">all</option>

									 
									 <option value="active">active</option>
									 			                         <option value="reserved">reserved</option>

									   	 <option value="closed">closed</option>

			                    </select>
		

		
	</div>
  </div>
  
  
     <div class="form-group">
   <label for="inputplotno" class="col-sm-2 control-label"> </label>

  
  <div class="col-sm-2">
					<div class="form-group">

                     		  		<input type="text" name="plotno" value="<?php echo set_value('plotno',"all"); ?>" class="form-control"  placeholder="Enter plot/House no ">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					
                     		  		<input type="text" name="houseno" value="<?php echo set_value('houseno',"all"); ?>" class="form-control"  placeholder="Enter Rooms no ">


					</div>
				</div>
			
	</div>
			
  
  
  
  
  
  
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="bookings" name="btn_BOOKINGS" class="btn btn-primary"> View SMS  </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>	

	
			
			
		<div id="addModal" 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">Add new customer</h4>
      </div>
      <div class="modal-body">
      
	  	


		
				  		
	

				<?PHP

 $transactionid = 'rand' .rand(100, 9900) . 'trc' . time();

 
		 $date=date("Y-m-d");

                 echo form_open('addtenant' , 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;?>
					
  <div class="form-group">

    <label for="inputfirstname" class="col-md-3 control-label">Customer Name</label>
    <div class="col-sm-7">
	
	
	
					 <input type="hidden" name="type"    value="tenant"  class="form-control">
					 <input type="hidden" name="view"    value="admin/viewalladvance"  class="form-control">

	
				 <input type="hidden" name="img_id"    value="<?php echo set_value('img_id', $imgid); ?>"  class="form-control">

	<input type="hidden" name="action" value="<?php echo set_value('action','insert'); ?>"id="action" class="form-control" required placeholder="Enter action">
	<input type="hidden" name="transactionid" value="<?php echo set_value('transactionid'); ?>"id="transactionid" class="form-control" required placeholder="Enter transactionid">

		  		<input type="text" name="firstname" value="<?php echo set_value('firstname'); ?>"id="firstname" class="form-control" required placeholder="Enter customer name">
     <span class="text-danger"><?php echo form_error('firstname'); ?></span>
   </div>
  </div>
    <div class="form-group" style="display:none">
    <label for="inputlastname" class="col-md-3 control-label">Last Name</label>
    <div class="col-sm-7">
		<input type="text" name="lastname" value="<?php echo set_value('lastname') ;?>" id="lastname" class="form-control"  placeholder="Enter lastname">
       <span class="text-danger"><?php echo form_error('lastname'); ?></span>
   </div>
  </div>
    <div class="form-group">
    <label for="inputphone3" class="col-md-3 control-label">Id Number </label>
    <div class="col-sm-7">
				<input type="text" name="idno" value="<?php echo set_value('idno'); ?>" id="idno" class="form-control"  placeholder="Enter Id Number">
    <span class="text-danger"><?php echo form_error('idno'); ?></span>
   </div>
  </div>
  
	
   
		
 
  <div class="form-group">
    <label for="inputphone" class="col-md-3 control-label">Phone Number</label>
    <div class="col-sm-7">
				<input type="text" name="phone" value="<?php echo set_value('phone'); ?>" id="phone" class="form-control"  placeholder="Enter Your phone">
        <span class="text-danger"><?php echo form_error('phone'); ?></span>
	</div>
  </div>
  <div class="form-group">
						<label for="field-2" class="col-md-3 control-label">Country</label>
		                    <div class="col-sm-7">
		                        <select name="country" class="form-control" id="section_selector_holder">
		                            <option value="">--Select Country--</option>
									   <?php
									$country = $this->accomodationmodel->populateallcountries();


if(is_array($country)) {

   foreach($country as $countryrow){

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

   
    <?php

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

?>
			                        
			                    </select>
								     <span class="text-danger"><?php echo form_error('country'); ?></span>
			                </div>
	</div>
	
   <div class="form-group">
						<label for="field-2" class="col-md-3 control-label">County</label>
		                    <div class="col-sm-7">
		                        <select name="county" class="form-control" id="section_selector_holder">
		                            <option selected="select" value="">--Select County--</option>
									   <?php
									$county = $this->accomodationmodel->populateallallacounties();


if(is_array($county)) {

   foreach($county as $countyrow){

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

   
    <?php

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

?>
			                        
			                    </select>
								     <span class="text-danger"><?php echo form_error('county'); ?></span>
			                </div>
	</div>
	
	
  	 		
     <div class="form-group" >
    <label for="inputlocation" class="col-md-3 control-label">Company</label>
    <div class="col-sm-7">
				<input type="text" name="location" value="<?php echo set_value('location') ;?>" id="exampleInputlocation" class="form-control"  placeholder="Enter Your company/business name">
    <span class="text-danger"><?php echo form_error('location'); ?></span>
	</div>
  </div>
   <div class="form-group">
    <label for="inputEmail" class="col-md-3 control-label">Email</label>
    <div class="col-sm-7">
				<input type="email" name="email" value="<?php echo set_value('email') ;?>" id="exampleInputEmail" class="form-control"  placeholder="Enter Your email">
    <span class="text-danger"><?php echo form_error('email'); ?></span>
	</div>
  </div>

 
 <div class="form-group" >
						<label for="field-2" class="col-md-3 control-label">Gender</label>
		                    <div class="col-sm-7">
		                        <select name="gender"  class="form-control" id="section_selector_holder">
		                            <option value="" selected>--Select Gender--</option>
			                         <option value="Male">Male</option>
									   <option value="Female">Female</option>
			                    </select>
							 <span class="text-danger"><?php echo form_error('gender'); ?></span>

			                </div>
	</div>	
	
	
		
			
	
	
	
	
	
		
		
		
		
		
	   <div class="form-group" >
    <label for="inputphone3" class="col-md-3 control-label">Entry Date </label>
    <div class="col-sm-7">
				<input type="phone" name="entrydate" value="<?php echo set_value('entrydate',$date); ?>" id="idno" class="form-control"  placeholder="Enter Entry date">
    <span class="text-danger"><?php echo form_error('entrydate'); ?></span>
   </div>
  </div>
  	  <div class="form-group" style="display:none">
						<label for="field-2" class="col-md-3 control-label">House Status</label>
		                    <div class="col-sm-7">
		                        <select name="status" required class="form-control" id="section_selector_holder">
		                            <option value="" >--Select Status--</option>
			                         <option selected="selected"value="active">active</option>
									   <option value="inactive">inactive</option>
			                    </select>
							 <span class="text-danger"><?php echo form_error('gender'); ?></span>

			                </div>
	</div>
	
	 <div class="form-group" style="display:none">
						<label for="field-2" class="col-md-3 control-label"> photo</label>
		                    <div class="col-sm-7">
		                      		<input type="file" name="photo" width="400"  value="<?php echo set_value('photo') ;?>" placeholder="Select Image"  class="form-control"  >

							 <span class="text-danger"><?php echo form_error('photo'); ?></span>

			                </div>
	</div>
	
	
	

   <div class="form-group" style="display:none">
    <label for="inputphone3" class="col-md-3 control-label">Comments </label>
    <div class="col-sm-7">
	<textarea name="description" id="ttt" rows="5" placeholder="Add any description/comment" 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-10">
     
	       <button type="submit" name="btn_tenant"value="tenant" class="btn btn-primary">Add Customer</button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>

		
		
			
			
			
			
			
			
			
			
              <div id="Checkout" 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">Post daily deductions</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to post daily deductions? </h3>
    
    
	  	

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

		   $closedatedate=date("Y-m-d 10:01:01");
                 echo form_open('admin/updatadvancepayment' , 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"  value="advancepayment">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/viewalladvance">
 <input type="hidden" id="itemid2"name="itemid"  value=""><br>
   <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Posting Date</label>
    <div class="col-sm-10">
					<?php
				 if( $backdatesales==true){
					 ?>
					 				<input type="text" name="dateposted" value="<?php echo set_value('amount',$closedatedate); ?>" id="dateposteds" class="form-control" required placeholder="Enter dateposteds">

					 	<?php
				 }else{
					 ?>
					 				<input type="text" readonly name="dateposted" value="<?php echo set_value('amount',$closedatedate); ?>" id="dateposteds" class="form-control" required placeholder="Enter dateposteds">

					 
					 	<?php
				 }
					 ?>
					 
        <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">Amount to deduct</label>
    <div class="col-sm-10">
				<input type="text" name="amount" value="<?php echo set_value('amount'); ?>" id="idno" class="form-control" required placeholder="Enter amount to deduct">
        <span class="text-danger"><?php echo form_error('amount'); ?></span>
	</div>
  </div>
  
    <div class="form-group">

	
	      <div id="bankname">
    <label for="inputbankname" class="col-sm-2 control-label">Bank name?</label>
    <div class="col-sm-4">
	<select class="form-control" name="bankname" required >
	
	<option value="na"  >---Select bank name---</option>
	
	<?php 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
										//$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');
										$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
				<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number .")"; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
$allbanking="";
	//$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype<>','1');
	//$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');
									//	$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');

										
if(is_array($allbanking)) {

   foreach($allbanking as $allbankingrow){

   //echo $courserow->coursename;
    ?>
		<option value="<?=  $allbankingrow->number;   ?>"><?=  $allbankingrow->accountname ."(Acc No:". $bankingrow->number ."-Acc Name: ".$bankingrow->accountname.") "; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
	
	
	
	
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('bankname'); ?>

	</div>
	</div>
	
	
	      <div id="baddebt">
    <label for="inputbaddebt" class="col-sm-2 control-label">Customer Deposit Account?</label>
    <div class="col-sm-4">
	<select class="form-control" name="baddebt" >
	
	<option value=""  >---Select account name---</option>
	
	<?php 
	$session_data = $this->session->userdata('logged_in');
//
  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
										$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','14');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
				<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number .")-Balance: ".$bankingrow->amount.""; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('baddebt'); ?>

	</div>
	</div>
  </div>

	
	
	  
  	<div class="form-group">
    <label for="inputcode" class="col-sm-2 control-label">Transaction Code(F10)<span style="color:red;">*</span></label>
    <div class="col-sm-10">
	
		  		<input type="text"   id="transactioncode"   name="cashier" value="<?php echo set_value('cashier'); ?>" class="form-control"  placeholder="Enter MPESA code e.g X3232">
		 
				
		<span class="text-danger"> <?php echo form_error('cashier'); ?>
		
		</span>
	</div>
  </div>
  
 
 
 
 <div class="form-group" >
    <label for="inputdescription" class="col-sm-2 control-label">	Remarks /Transaction code </label>
    <div class="col-sm-10">

				<textarea name="description"  id="Transaction"   value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter remarks"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
  
  	  <div class="form-group" >
						<label for="field-2" class="col-sm-2 control-label">Status</label>
		                    <div class="col-sm-10">
		                        <select name="status" id="status" class="form-control" >

			                         <option value="active">active</option>
									   	 <option value="closed">closed</option>

			                    </select>
							 <span class="text-danger"><?php echo form_error('status'); ?></span>

			                </div>
	</div>	
		
   </div>
   <div class="modal-footer">
 
 		   		  	         <button type="submit" name="updateadvance" value="advance" class="btn btn-success"> Yes(Post payment)  </button>

 <button type="button" class="btn btn-danger" data-dismiss="modal">No</button>


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

  </div>

  </div>
		
			
			
			
			
              <div id="AddPayment" 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">Add more  Payments</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to add more payment to the existing one? </h3>
    
    
	  	

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

		   $closedatedate=date("Y-m-d 10:01:01");
                 echo form_open('admin/addadvancepayment' , 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"  value="advancepayment">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/viewalladvance">
 <input type="hidden" id="itemid3"name="itemid"  value=""><br>
   <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Date</label>
    <div class="col-sm-10">
	
	
				<?php
				 if( $backdatesales==true){
					 ?>
					 				<input type="text" name="dateposted" value="<?php echo set_value('amount',$closedatedate); ?>" id="dateposteds" class="form-control" required placeholder="Enter dateposteds">

					 	<?php
				 }else{
					 ?>
					 				<input type="text" readonly name="dateposted" value="<?php echo set_value('amount',$closedatedate); ?>" id="dateposteds" class="form-control" required placeholder="Enter dateposteds">

					 
					 	<?php
				 }
					 ?>
	
	
	
	
	
        <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">Amount to add</label>
    <div class="col-sm-10">
				<input type="text" name="amount" value="<?php echo set_value('amount'); ?>" id="idno" class="form-control" required placeholder="Enter amount to add">
        <span class="text-danger"><?php echo form_error('amount'); ?></span>
	</div>
  </div>
  

 
 
 
 <div class="form-group" style="display:none">
    <label for="inputdescription" class="col-sm-2 control-label">	Remarks </label>
    <div class="col-sm-10">

				<textarea name="description" value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter remarks"></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
  
  	  <div class="form-group">
						<label for="field-2" class="col-sm-2 control-label">Status</label>
		                    <div class="col-sm-10">
		                        <select name="status" id="status" class="form-control" >

			                         <option value="active">active</option>
									   	 <option value="closed">closed</option>

			                    </select>
							 <span class="text-danger"><?php echo form_error('status'); ?></span>

			                </div>
	</div>	
		
   </div>
   <div class="modal-footer">
 
 		   		  	         <button type="submit" name="addadvancepayment" value="advance" class="btn btn-success"> Add payment</button>

 <button type="button" class="btn btn-danger" data-dismiss="modal">No</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 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="advance">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/viewalladvance">
 <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>
			<!----CREATION FORM STARTS---->
			<div  class="tab-pane box active" 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 Advance  details
            	</div>
            </div>
			<div class="panel-body">





				<?PHP

 $transactionid = 'rand' .rand(100, 9900) . 'trc' . time();
 $mydate=date("Y-m-d H:i:s");
	
	$next_date = date('Y-m-d', strtotime(' +1 day'));
    $closedatedate=($next_date." 10:00:00");
//
 	 	$finalsalesid = $userid.time();

		 $date=date("Y-m-d H:i:s");

                 echo form_open('admin/addadvancebooking' , 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="myid"    value=""  class="form-control">

					 <input type="hidden" name="action"    value="insert"  class="form-control">


					 <input type="hidden" name="view"    value="admin/viewalladvance"  class="form-control">


	  <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Customer Name</label>
    <div class="col-sm-7">
				    	
			  	<select name="tenantid"  class="chzn-select" style="width:100%" required>
<option value="" >---Select customer for advance--</option>

		<?php 

//$nation = $this->nationmodel->populatenation();
	 					$mytenant = $this->usermodel->populateall('people', 'companyid',$companyid);


if(is_array($mytenant)) {

   foreach($mytenant as $mytenantrow){

    ?>
	    <option value="<?php echo set_value('tenant',$mytenantrow->id); ?> "><?=$mytenantrow->lastname." ".$mytenantrow->firstname." IDNO ".$mytenantrow->idno."  ".$mytenantrow->phone;?></option>

   
    <?php

}} else {
    echo 'There is no customer.';
}

?>
	</select>

   </div>
  </div>

  
  

  
  
  
  
  
  
  
  
   <div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Expected Paid</label>
    <div class="col-sm-7">
				<input type="text" name="amount" value="0" id="Expectedamount" 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="inputbalance" class="col-sm-2 control-label">Balance so far</label>
    <div class="col-sm-7">
				<input type="text" readonly   name="balance" value="0" id="balance" class="form-control" required placeholder="Enter balance ">
        <span class="text-danger"><?php echo form_error('balance'); ?></span>
	</div>
  </div>

		  <div class="form-group">
						<label for="field-2" class="col-sm-2 control-label">Status</label>
		                    <div class="col-sm-7">
		                        <select name="status" required class="form-control" id="section_selector_holder">
		                            <option value="" selected>--Select Status--</option>
			                         <option value="active">active</option>
									 			                         <option value="reserved">reserved</option>

									   	 <option value="closed">closed</option>

			                    </select>
							 <span class="text-danger"><?php echo form_error('status'); ?></span>

			                </div>
	</div>			
  
   

		   <div class="form-group">
   <label for="inputfstartdate" class="col-sm-2 control-label">Start Date  </label>

  
  <div class="col-sm-2">
					<div class="form-group">

                     		  		<input type="date" name="startdate" value="<?php echo set_value('startdate',date("Y-m-d", strtotime($mydate))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					
							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',date("00:00:00")); ?>" class="form-control" required placeholder="Enter start time">


					</div>
				</div>
			
	</div>
			
		





	   <div class="form-group">
   <label for="inputclosedate" class="col-sm-2 control-label">End Date  </label>

  
  <div class="col-sm-2">
					<div class="form-group">

                     		  		<input type="date" name="closedate" value="<?php echo set_value('closedate',date("Y-m-d", strtotime($closedatedate))); ?>" class="form-control" required placeholder="Enter end date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					
							  		<input type="time"  name="totime" value="<?php echo set_value('totime',"23:59:59"); ?>" class="form-control" required placeholder="Enter stop time">


					</div>
				</div>
			
	</div>
			











	  
				<input type="hidden" readonly name="createdat" value="<?php echo set_value('createdat',$date); ?>" id="idno" class="form-control" required placeholder="Enter Start Date">
    
	
   <div class="form-group">
    <label for="inputphone3" class="col-sm-2 control-label">Description / Transaction code </label>
    <div class="col-sm-7">
	<textarea name="description" id="ttt" rows="5" placeholder="Add any description/comment" class="form-control"></textarea>
    <span class="text-danger"><?php echo form_error('description'); ?></span>
   </div>
  </div>
    
  

	   <div class="form-group" style="display:none">
   <label for="inputplotno" class="col-sm-2 control-label"> </label>

  
  <div class="col-sm-2">
					<div class="form-group">

                     		  		<input type="text" name="plotno" value="<?php echo set_value('plotno'); ?>" class="form-control"  placeholder="Enter plot/House no ">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
							 		<input type="text" readonly name="houseno" value="<?php echo set_value('invoiceno',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoiceno">



					</div>
				</div>
			
	</div>
			



  
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-7">
     
	       <button type="submit" name="btn_advance"value="advance" class="btn btn-primary">Create New Advance</button>

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






			
			
			
			
			</div>
			
			



		
			
			
			</div>
			
			
			
			
			
			
			
			





