
<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 = "../admin/searchhousebalance";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../admin/searchhousebalance";

		    // document.body.innerHTML = originalContents;

	}
}


       
		 
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid").val(itemid); 
		  
		  
		   
        });
		








	</script>
   <style type="text/css">
  
  

    #printable { display: none; }

    #myprint { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;12px;
  
    


}


#sale{  	
background-image:url(images/add.png) ;

    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>







 <div class="row">

 

   	<div class="col-md-12">

				 
				 	<div class="print-hide" id="non-printable"  >
<form name="print" method="post" action="">
 
 <div class="row">

 

   	<div class="col-md-6">
				 <a href="<?php echo base_url(); ?>admin/searchbalance">More reports</a><BR>
				 <a href="<?php echo base_url(); ?>admin/viewpallmyplots">	GO BACK</a> ||
										 <a href="<?php echo base_url(); ?>user/mysales">	Back to cashier sales</a>

	
</div>
   	<div class="col-md-6">
<input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="print receipt!" />
</form></div></div>
							</div> 
     
	 
	 <?php
	 	$session_data = $this->session->userdata('logged_in');

    $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
 $data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
        
		 $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
			 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	        		$configuration = $this->usermodel->populateallarray('smsconfig','id',$companyid);
					
					    $deletebank=$this->usermodel->populatuserpermissionsdataarray('accounting','deletebank',$userid);
	 	      $givediscount=$this->usermodel->populatuserpermissionsdataarray('accomodation','givediscount',$userid);

    $mpesaaction=$this->usermodel->populatuserpermissionsdataarray('accomodation','mpesa',$userid);
	      $chequeaction=$this->usermodel->populatuserpermissionsdataarray('accomodation','cheque',$userid);
 $voucheraction=$this->usermodel->populatuserpermissionsdataarray('accomodation','voucher',$userid);
	      $creditaction=$this->usermodel->populatuserpermissionsdataarray('accomodation','credit',$userid);
		   $pointsaction=$this->usermodel->populatuserpermissionsdataarray('accomodation','points',$userid);
	      $cardaction=$this->usermodel->populatuserpermissionsdataarray('accomodation','card',$userid);
		    $cashpayment=$this->usermodel->populatuserpermissionsdataarray('accomodation','cash',$userid);


		

	 
	 ?>
	 
	 
	 


 <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>DAILY SALES </Center>	
		</center>	
		</td>

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

												  
<center>
				<h4><b>Bookings  between <?php echo $MYfromdate = date("d/m/Y H:i:a", strtotime($fromdate)); ?> to  <?php  echo $MYtodate = date("d/m/Y H:i:a", strtotime($todate));  ?>.</b></h4>	</td>
					<td><h4><b>Printed on <?php echo $date = date("Y-m-d"); ?></b></h4></td>
</center>
		</tr>
			
			
				<?php 
				
				}
			
			?>
			
			
			
</table >
			
			
		<?php
		
			$totlbal=0;
		$collected=0;
		 $totlbal=0;
				 $actualtotal=0;

		
		
		
		
		
 if( $display!="balance"){
	 ?>
   
	
				
			
			

<table  border="1"width="100%">
             <thead>
	
			
         <tr>
		 
		 		   <th>Rct No </th>

		 
		
    
    <th>Rm No </th>
	<th>HS No</th>
    
<th>Customer</th> 	
	<th>Id Number</th> 
	<th>Phone Number</th> 
	<th>Check-In </th> 
		<th>Check-Out </th>
		 <th>Pple</th> 		

 <th>Days</th> 		
	 <th>TT Exp</th> 
		 <th>Sale Price</th> 


	 <th>Cash </th> 
	  <th>Mpesa </th> 
	 <th>Card </th> 
	 	 <th>Cheque </th> 


	<?php
 if( $creditaction==true){
	 ?>
   
	 <th>Credit </th> 
		 
	 	<?php	
		}
		?>
		
					
 
 	<?php
 if( $voucheraction==true){
	 ?>
   
		 	 	 <th>Voucher </th> 

		 
	 	<?php	
		}
		?>
		
		 	<?php
 if( $givediscount==true){
	 ?>
   

						 		 	 	 <th>Dsc </th> 
 
	 	<?php	
		}
		?>
	 <th>Others </th> 
	 <th>Balance </th> 

		 <th>Vat </th> 

	  	 <th>Lvy </th> 



	 <th> Status </th> 

	
		 <th>Code  </th> 

	
	
	
	
	
	
	 <th>Rm Status</th> 

		 <th>NB  </th> 

	 <th>Staff</th> 
	 <th>$</th> 

		<th id="non-printable">Print</th> 

		<!--<th id="non-printable">delete</th> -->
		<th id="non-printable">update</th> 



                 </tr>
             </thead>
<?php
	
				echo $this->session->flashdata('msg');
				 echo $this->session->flashdata('deletemsg'); 
		if(validation_errors()):
		 endif;
 if(!is_array($booking)) 

 {




    
       echo '<div class="alert alert-warning text-center">There is no booking found by now from system..</div>';
    
    }else {
?>
    
             <?php 
  $totalamount=0;
  $totalpaid=0;
    //$actualtotal=0;
    $people=0;
    $discount=0;

    $totalbalance=0;
	    $roomtype=0;
   $mpesa=0;
      $card=0;
	   $cash=0;
	    $credit=0;
			    $cheque=0;
			    $count=0;

	   $voucher=0;
	  $mycount=0;
	     $tax1=0;
	  $tax2=0;
	  
	  

  	foreach ($booking as $c): 
									// echo$totalpaid= $c->card+$c->amount+$c->mpesa+$c->voucher+$c->cheque;;
		  $count++

             ?>



             <tr>
                
            <?php 
		$id=$c->id;
		 //  $count=count($id);
			$myroomtype=($c->roomtype);

$people=(double)$people+(double)$c->people;
  $voucher=(double)$voucher+(double)$c->voucher;
$actualtotal=(double)$actualtotal+(double)$c->total;
  $credit=(double)$credit+(double)$c->credit;
    $card=(double)$card+(double)$c->card;

  $cash=(double)$cash+(double)$c->amount;
    $cheque=(double)$cheque+(double)$c->cheque;
	    $discount=(double)$discount+(double)$c->discount;
   $houseno=$c->houseno;
   $plotno=$c->plotno;

   $mpesa=(double)$mpesa+(double)$c->mpesa;
   $totalamount=(double)$mpesa+(double)$cash+ (double)$card+(double)$voucher+(double)$credit+(double)$cheque;
$mycount= (double)$mycount++;
		  $myhouse = $this->usermodel->populatealldataarray('house','plotno', $plotno,'houseno', $houseno);
						$roomidentifier=$myhouse[0]["id"];

					 $getroomamount= $this->usermodel->populateall('roomsales','transactioncode',$c->transactioncode);

$roomtotals=0;

if(is_array($getroomamount)) {

   foreach($getroomamount as $getroomamountrow){

   $roomtotals=$roomtotals+ $getroomamountrow->total;
 
 
}} else {
    //echo 'No Name.';
}

		$roomtype=(double)($roomtype)+(double)($c->total)+(double)$roomtotals;

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


             <td><?php echo $c->houseno." ". $c->bedname ; ;
			 ?></td> 
				<td><?php echo $c->plotno ; ?></td> 


<td>
 
  <?php  $mycustomer= $c->tenantid ;
  $idno="";
    if($mycustomer!=""){

$myuser=$this->usermodel->getpeople($mycustomer);
    $myname=$myuser[0]['company'];
	    $phone=$myuser[0]['phone'];
    $idno=$myuser[0]['idno'];
     $firstname=$myuser[0]['firstname'];
   if($myname!=""){
	   echo $myname;
	   
   }else{
	   
	   echo $firstname; 
	   
   }
	}else{
		echo $mycustomer;
		
	}
  ?>
 
 
 </td>


				 		<td><?php  
				 echo $idno;
				 
		
				 ?></td>
				 
				 
				 		<td><?php  $tenantid=$c->tenantid ; 
				 
				 
				    $tenantsid = $this->accomodationmodel->gettenantbyid($tenantid);
								


if(is_array($tenantsid)) {

   foreach($tenantsid as $tenantsidrow){

   echo $tenantsidrow->phone; 
    

}} else {
   echo" GENERAL";
}
				 
				 
				 
				 
				 
				 ?></td>
				 
				 <td><?php echo $c->createdat;
												//   	  echo $datespent = date("H:i:a", strtotime($c->createdat));


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

												   	  //echo $datespent = date("H:i:a", strtotime($c->checkoutdate));


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

       <td><?php echo $c->number; ?></td>
					                      <td><?php echo (double)$c->total+(double)$roomtotals; ?></td>
					               					                      <td><?php echo $c->total; ?></td>


									<td><?php echo $c->amount; ?></td>
					 <td><?php echo $c->mpesa; ?></td>
					 					 <td><?php echo $c->card; ?></td>
									<td><?php echo $c->cheque; ?></td>

										  
										  
										  
										  
										  	<?php
 if( $creditaction==true){
	 ?>
   
										 		 <td><?php echo $c->credit; ?></td>
		 
	 	<?php	
		}
		?>
		
					
 
 	<?php
 if( $voucheraction==true){
	 ?>
   
										 <td><?php echo $c->voucher; ?></td>

		 
	 	<?php	
		}
		?>
		
		 	<?php
 if( $givediscount==true){
	 ?>
   

										  <td><?php echo $c->discount; ?></td>
 
	 	<?php	
		}
		?>
		
				 		 <td><?php 




 echo $roomtotals;





						 ?></td>							  
										  
										  
										  
										  
																					      				<td><?php echo (-1*(double)$c->balance ); ?></td> 
		  
										  
	 <td><?php echo $c->tax1; ?></td>
 <td><?php echo $c->tax2;

$tax1=(double)$tax1+(double)$c->tax1;
$tax2=(double)$tax2+(double)$c->tax2;


 ?></td>
									  
										  


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

									
								

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

					 
					 
					 
					 
					 
					 
					 
					 
					 
					 
					 
					 
						 
								 
				<td><?php  $status = $c->status ;
				if($status=="reserved"){
					
					echo "reserved";
				}else 
				if($status=="active"){
					
					echo "occupaid";
				}else{
					echo "vacant";
					
				}
				?></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><?php echo $c->currency; ?></td>

		 
		 	
		  	<td id="non-printable">
							  <a class="btn btn-primary"    id="more" href="<?php echo base_url();?>admin/housereceiptbynoold?randomitemidentifier=<?php   {echo  $c->transactioncode;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;}  ?>">Receipt  </a>

				  <a class="btn btn-primary"    id="more" href="<?php echo base_url();?>admin/housereceiptbyno?randomitemidentifier=<?php   {echo  $c->transactioncode;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;}  ?>">Print(A4)  </a>
			 <a class="btn btn-primary"    id="more" href="<?php echo base_url();?>admin/printhouseinvoice?randomitemidentifier=<?php   {echo  $c->transactioncode;}  ?>&plotno=<?php   {echo  $c->plotno;}  ?>&houseno=<?php   {echo  $c->houseno;}  ?>"> Invoice </a>

						
						

				</td>
				
		 
		 
		 
		  
		 	
		  <!--	<td id="non-printable">
			<?php
										if($usertype=="admin"){
											
											?>

						 <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>
																Cancel
                                                </a>		
						 <?php }?>

				</td>-->
				
		 		  	<td id="non-printable">

		 		 						<a  id="more" class=" btn-info" href="<?php echo base_url();?>admin/viewbalance?invoice=<?php echo $c->transactioncode ?>&randomitemidentifier=<?php echo $houseno ?>&randomitemidentifier1=<?php echo $plotno ?>&roomidentifier=<?php echo $roomidentifier ?>">  Receive  </a>

		 						<a  id="more" class=" btn-warning" href="<?php echo base_url();?>user/mychangepayment?myid=<?php echo $c->transactioncode ?>&randomitemidentifier=<?php echo $houseno ?>&randomitemidentifier1=<?php echo $plotno ?>&roomidentifier=<?php echo $roomidentifier ?>">   Update </a>

		 </td>
		  
             </tr>

             <?php endforeach; ?>
			 <tr>
			 			   <td  colspan="2"> <b>TT Rooms: </b></td>

			  <td> <b> <?php echo  $count;  ?> </b></td>
		
			 <td colspan="3"> <b> Sales Total Summary: </b></td>
			 			 			   <td  colspan="2"> <b>TT People: </b></td>

			 			  <td colspan="2"> <b> <?php echo $people;  ?> </b></td>

			  <td> <b> <?php echo $roomtype;  ?> </b></td>

			  <td>  <b><?php echo $actualtotal;  ?> </b></td>

			  <td>  <b><?php echo $cash;  ?> </b></td>
			  <td >  <b><?php echo $mpesa;  ?> </b></td>
			  	<td >  <b><?php echo $card;  ?> </b></td>
				
				
				

			  	<td >  <b><?php echo $cheque;  ?> </b></td>
				
				
				
				
									  
										  
										  
										  	<?php
 if( $creditaction==true){
	 ?>
   
			     <td >  <b><?php echo $credit;  ?> </b></td>
		 
	 	<?php	
		}
		?>
		
					
 
 	<?php
 if( $voucheraction==true){
	 ?>
   
			  	<td >  <b><?php echo $voucher;  ?> </b></td>

		 
	 	<?php	
		}
		?>
		
		 	<?php
 if( $givediscount==true){
	 ?>
   

							  	<td >  <b ><?php echo $discount;  ?> </b></td>
 
	 	<?php	
		}
		?>
		
										  
										  
										  
				
				
				
				
				
				
				
				
				
				


										  	
											
											<td colspan="2">
											<b>
											<?php
												echo "Balance :";
												$collected=($cash+$mpesa+$card+$cheque);
										echo$totlbal=$actualtotal-$collected;
											?></b></td>						
											
											<td>
											<b>
											<?php
												
										echo$tax1
											?></b></td>
											<td>
											<b>
											<?php
												
										echo$tax2
											?></b></td>
											
											
											
											
											
											
											
											

			 </tr>

              <?php }?>

        </table>
		
		
	 	<?php	
		}else{
			
			
			
			 if(is_array($booking)) 

 {

  $mytotlbal=0;
  $mycollected=0;
    $mympesa=0;
   $mycash=0;
  $mycard=0;
    $mycheque=0;
    $myactualtotal=0;
  

  	foreach ($booking as $c){
								
			
			
			$myactualtotal=(double)$myactualtotal+(double)$c->total;
			
			$mympesa = $mympesa+$c->mpesa;
			$mycash = $mycash+$c->amount;
			$mycard = $mycard+$c->card;
				$mycheque = $mycheque+$c->cheque;
			$mycollected=($mycash+$mympesa+$mycard+$mycheque);
										//echo$mytotlbal=$myactualtotal-$collected;
			
			
			
			
	}
			
			
		?>	
		<b >
		<center>
		<h2>
				CURRENT SALES REPORT  FOR THE MONTH OF  <?php  	$month = date("F",strtotime($todate));  echo strtoupper($month); ?> <?php  echo $YEAR = date("Y",strtotime($todate));; ?><br>

		Expected sales :	<?php echo $myactualtotal;  ?> 	<br>
			Cash sales :	<?php echo $mycash;  ?> 	<br>
		
				Mpesa sales :	<?php echo $mympesa;  ?> 	<br>
		
				Card/ Bank / Cheque:	<?php echo $mycheque;  ?> 	<br>
		
		
			
				Total Money Collected  :	<?php echo $mycollected;  ?> 	<br>

						Balance   :	<?php echo $mytotlbal;  ?> 	<br>

			
			</h2>
			</center>
			
				</b>
		 <?php	
		}
		
		}
		?>

    </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/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="bookroom" value="bookroom">
 <input type="hidden" id="view2"name="view2" class="view2" placeholder="view2" value="">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="admin/searchbalance">
 <input type="hidden" id="itemid"name="itemid" class="itemid" placeholder="itemid" value=""><br>
           <input type="hidden" id="houseno"name="houseno" class="form-control" placeholder="houseno"  value="">

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