

 <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).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
			  $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });

		
		
    </script>  

 
 <div class="row">
  
   	

   	<div class="col-md-12">
	
  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
						 <span class="pull-right"> View Expense</span>					                    
						 <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Add Expense </a>
	  	  				 <a href="<?php echo base_url();?>user/receivebill" class="btn btn-info"> Add bill/Supplier invoice</a>
	  	  				 <a href="<?php echo base_url();?>user/paybill" class="btn btn-info"> Pay bills</a>
	  	  				 <a href="<?php echo base_url();?>user/allinvoices" class="btn btn-success"> All Invoices</a>
	  	  				 <a href="<?php echo base_url();?>user/incoicepayments" class="btn btn-success"> Receive Payments</a>
	  	  				 <a href="<?php echo base_url();?>user/allcreditors" class="btn btn-info"> All Debtors</a>
						 	  	  				 <a href="<?php echo base_url();?>user/viewallcreditors" class="btn btn-info"> All Creditors</a>

                        <a data-toggle='modal' data-target='#addsupplierModal' class="btn btn-info">Add Campany </a>

				
            	</div>
						<br>

				<div class="row">
						<div class="col-md-12">
<?php 
			 				echo $this->session->flashdata('deletemsg'); 

		 echo $this->session->flashdata('msg'); 
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallmyexpenses", $attr);?>
	

            				<input type="hidden" name="view" value="userdata/viewexpenses" id="view" class="form-control" required placeholder="Enter status">

			
                <div class="col-md-2">
                    <input class="form-control" id="searchterm" name="searchterm" placeholder="General search.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
                  <div class="col-md-2">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-success" value="Search" />
                    <a href="<?php echo base_url(). "user/viewexpenses"; ?>" class="btn btn-primary">Refresh</a>
              
			
        <?php echo form_close(); ?>
		  </div>
				
                 <div class="col-md-2">
           
		  <?php 
		 $mydate=date("Y-m-d");

        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallexpenses", $attr);?>
			
				
				            				<input type="hidden" name="view" value="userdata/viewexpenses"id="view" class="form-control" required placeholder="Enter status">


    				   

	<select class="chzn-select" name="searchterm" style="width:200px; margin:0px;" required>
	
	<option value=""  >-Select Company/Customer-</option>
	<option value="all"  >-All companies-</option>

	


	<?php 
					 
			$mycustomer= $this->usermodel->populateviewcustomers('people','company','ASC','companyid', $companyid);
	     // $mycustomer=$this->usermodel->populatealldatawhere('products','bulk',$userid);


if(is_array($mycustomer)) {

   foreach($mycustomer as $mycustomerrow){

   $company= $courserow->company;
   ?>
					<option value="<?=  $mycustomerrow->id;   ?>"><?=  $mycustomerrow->company ." (". $mycustomerrow->firstname ." ".$mycustomerrow->lastname.")"; ?></option>




	<?php

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

	</div>
				
				
				
				    <div class="col-md-1">
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$mydate); ?>" class="form-control2" required placeholder="Enter from date">

					</div>
				
				
				
				  <div class="col-md-1">
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$mydate); ?>" class="form-control2" required placeholder="Enter TO date">

					</div>
					  <div class="col-md-2" >
<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
					<option value="all"  >All branches/Counters</option>
								

	
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option selected="selected" value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
					</div>
				
				
				
				
				
                <div class="col-md-2">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-success" value="Search" />
                </div>
		
        <?php echo form_close(); ?>
            </div>
			 </div>	
				
				
				
            </div>
			
			<div class="panel-body">

				<div class="widget-content nopadding table_holder table-responsive" >				
	
										<?php
 
   $session_data = $this->session->userdata('logged_in');

      $mydate=date("Y-m-d H:i:s");
 $date = Date('Y-m-d') ;
		 	 $year = Date('Y') ;
		  $month = Date('m') ;
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
    $deletebank=$this->usermodel->populatuserpermissionsdataarray('accounting','deletebank',$userid);
	    $viewaccounting=$this->usermodel->populatuserpermissionsdataarray('accounting','view',$userid);

			 $finalsalesid = $userid.time();

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

 echo $this->session->flashdata('deletemsg'); 


  
  ?>
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
									
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>
		      <th>More</th>
    	      <th>Supplier</th>
  <th>P.O No</th>
    	 

	      <th>Bank Name</th>
		   <th>Amount</th>
		       <th>Name</th>
		    <th>Date Paid</th>
		      <th>Approved by?</th>
	     <th>Description</th>
			<th>Status</th>		 
		   <th>Action</th> 
				
		<th>More</th>

                 </tr>
             </thead>
<?php

 if(!is_array($viewexpenses)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='8'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $total=0;
  	foreach ($viewexpenses as $c): 

		 

             ?>



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

  $total=$total+$c->amount;

?>
<td><?php 
 $invoice_number=$c->invoice;
	
	  ?>
	  	  	  	 <a  id="more" class="btn btn-warning"  href="<?php echo base_url();?>user/editexpense?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>">View Items  </a>

  </td>
<td>

	 <a  href="<?php echo base_url();?>user/editmember?randomitemidentifier=<?php   {echo  $c->supplier ;}  ?>">

	 <?php  
	 $userids= $c->supplier;

$myuser=$this->usermodel->getpeople($userids);
    $myname=$myuser[0]['company'];
     $firstname=$myuser[0]['firstname'];
   if($myname!=""){
	   echo $myname;
	   
   }else{
	   
	   echo $firstname; 
	   
   }

  ?>
  </a>


</td>

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

           <td>
												 
	<?php 
					// $branch="";
					 $bankid=$c->bankname;

					 $branch= $this->usermodel->populateall('glaccounts','number',$bankid);



if(is_array($branch)) {

   foreach($branch as $branchrow){

   echo $branchrow->accountname;
 
 
}} else {
    echo 'General.';
}
	
?>
												 
	 </td>    

	  <td><?php echo $c->amount ; ?></td>
	   <td><?php echo $c->user ; ?></td>
	   
  <td><?php echo $c->datespent; ?></td>
	   <td><?php echo $c->controller ; ?></td>
	   
	      <td>
	   
	   	 <?php  $controller= $c->controller ;

		  
		  	 $mycontroller = $this->usermodel->populateallarray('people','id',$controller);
		 
   if($mycontroller!=FALSE){
 echo $myname=$mycontroller[0]['firstname'];	   
   }else{
	     echo   $controller;

	   
   }

  ?>
	   
	   
	   
	   
	   
	   
	   </td>
	    <td><?php echo $c->description ; ?></td>
		  <td><?php echo $c->status ; ?></td>
			   <td>
	 <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/viewmoredocs?randomitemidentifier=<?php   {echo  $img_id;}  ?>">View document  </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>
									<?php
										if($usertype=="admin"){
											
											?>
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
										
											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#deleteModal<?php  $c->id; ?>'>	 


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

	<?php endforeach;} ?>
<tr>
<td></td>
<td colspan="3">
<h2>
Total Expense:
</h2>
</td>
<td colspan="7">
<h2>
<?php 
if(isset($total)) {echo $total; }


?>
</td>

</h2>


</tr>
           

        </table>

								
									
									
					</div>	
					
					
					
					
					
					
					
					
					
					
					
					
					
					
	
			

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

 
</div>


















