  
       <script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

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

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

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>
   
   
   
   
   
   <div class="row">
  
  
     <div class="col-md-12">
	 <div class="table-responsive">
		
		
	<div class="panel panel-default" data-collapsed="0">
        	
			<div class="panel-body">
		
					<?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'];	
	 
	 
				$data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
	



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;
					}
								?>
		
		
		
		
		 
		  	  	 <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>
 <a href="<?php echo base_url(); ?>user/viewexpenses">Go Back to all Expense</a>

 </div>      	
	
		
		
  <div class="col-md-12">
<p class="text-left">






<h1><center>
Daily expense report 
</center>
</h1>

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

             <thead>
			 	 <?php
			 
			 if(isset($configuration[0]['businessname'])) {
				 ?>
			 	 <tr>
								
								<td colspan="6" ><center  >
								
						
									

										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {
											//
										//echo   $bussinessname; 
										}
										
									$myname="";
									if($mybranchid!="all"){
								$maincategory = $this->usermodel->populateallarray('branch','id',$mybranchid);
	$myname=$maincategory[0]["name"];
									}else{
											$myname="All branches";
									}
									  
										?>
												<span id="mytitle"></br><b> Expenses statement  from  <?PHP echo  date("d/m/Y", strtotime($fromdate)) ?> to <?PHP echo  date("d/m/Y", strtotime($todate)) ?></b>		
									<span id="mytitle"></br><b>   Baranch Name:  <?PHP echo $myname ?></b>	
									</span>

								</center></td>
								
								
							</tr>
							<?php
			 }
							?>
						
         <tr>
     <th>Code</th>
	 
	        <th>Date</th>
	 

	        <th>Expense type</th>
			 <th>Description</th>
	    <th>Amount</th>
     <th>Transaction Code</th>
	 
   <th>Branch</th>
   <th>Staff</th>

                 </tr>
             </thead><tbody>
<?php
 $totalamount=0;

 if(!is_array($viewexpense)) {
	 
				//    echo '<div class="alert alert-danger text-center">There was no group/ category found in the system. Please create group/category first</div>';

			 }else{

    
       
 
  	foreach ($viewexpense as $c){

		 

             ?>



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

$totalamount=(double)$totalamount+(double)$c->amount;

  	$getgroupsss= $this->usermodel->populateallarray('expenses','invoice',$c->invoice );







?>
   <td><?php
								$groupname=$getgroupsss[0]['id'];



   echo $c->account ; ?></td>  
      <td><?php echo $c->crateddate ; ?></td>  
         

  <td><?php 
  
  	$getgroup= $this->usermodel->populateallarray('glaccounts','number',$c->account );
								echo$groupname=$getgroup[0]['accountname'];
  
  
  ?></td>
      <td><?php echo $c->description ; ?></td>


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

  </td> 
      <td><?php echo $c->refno ; ?></td>
	  <td><?php  $mybranchid=$c->branch ;

$mybranch=$this->usermodel->populateallarray('branch','id', $mybranchid);


			echo$myname=$mybranch[0]['name'];
if($c->branch != $getgroupsss[0]['branchid']){
	echo "<b style=' color:red'>  Err $c->invoice</b>";
}
 ?>
 
 
 </td>	
   <td><?php 
   
     	$names= $this->usermodel->populateallarray('people','id',$c->userid );
								echo$allnames=$names[0]['firstname'];
   ?></td>

	  

	 
	 
		 
             </tr>

	<?php }
	
	
	
	 ?>
  <tfoot>
           <tr>
		 
    <td colspan="4"></b>Total Amount:</b></td>
	    <td  colspan="5"><b>
		<?php  echo formatMoney($totalamount, true); ?>
		<br>
		<br>Name-----------------------------------------------Date--------------------Signature----------------
		</b>
		</td>
			  
     </tr>		   
 </tfoot>
 <?php 
 	} ?>
        </table>





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

		
</div>
	
		

</div>

