

 

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </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 href="<?php echo base_url();?>user/viewexpenses" class="btn btn-default"> View/add expense</a>
						 
	  	  				 <a href="<?php echo base_url();?>user/receivebill" class="btn btn-default"> Add bill/Supplier invoice</a>
	  	  				 <a href="<?php echo base_url();?>user/paybill" class="btn btn-default"> Pay bills</a>
	  	  				 <a href="<?php echo base_url();?>user/allinvoices" class="btn btn-default"> All Invoices</a>
	  	  				 <a href="<?php echo base_url();?>user/incoicepayments" class="btn btn-default"> Receive Payments</a>
	  	  				 <a href="<?php echo base_url();?>user/allcreditors" class="btn btn-default"> All Debtors</a>

				
            	</div>
            </div>
			<div class="panel-body">

				<div class="widget-content nopadding table_holder table-responsive" >				
	<?PHP
      $mydate=date("Y-m-d H:i:s");

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


				echo $this->session->flashdata('msg'); 
								?>	
										
					<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>Ref 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> 
				
		

                 </tr>
             </thead>
<?php
  $total=0;
 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 

  	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-default"  href="<?php echo base_url();?>user/editexpense?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>">More  </a>

  </td>
<td>

	 <?php  $supplierid= $c->supplier ;
	 $myuser = $this->usermodel->populateallarray('people','id', $supplierid);

   echo $myuser[0]['company'];

  ?>



</td>

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

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

					 $branch= $this->usermodel->populateall('glaccounts','id',$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 echo $c->description ; ?></td>
		  <td><?php echo $c->status ; ?></td>
			   <td>
	 <a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/viewmoredocs?randomitemidentifier=<?php   {echo  $img_id;}  ?>">View document  </a>

	  </td>
	
             </tr>

	<?php endforeach;} ?>
<tr>
<td></td>
<td colspan="3">
<h2>
Total Expense</br>
Total Money</br>

Total Profit

</h2>
</td>
<td colspan="8">
<h2>
<?php 
if(isset($total)) {echo $total; }
if(isset($finaltotal)) {
	echo "<br>";
	echo $finaltotal;
	echo "<br>";
	$profit=$finaltotal-$total;
	
	echo $profit; 
	
	}




?>
</td>

</h2>


</tr>
           

        </table>

			 						
									
									
					</div>	

		<div id="deleteModal" 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('logged_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="expenses">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewexpenses">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-default" 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 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 Expense</h4>
      </div>
      <div class="modal-body">
      
	  	

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

$img_id = rand(100, 990000).time();

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addexpense' , 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="view" value="user/viewexpenses" class="form-control" required placeholder="Enter view">

         								<input type="hidden" name="type" value="Expense" class="form-control" required placeholder="Enter Expense">

     								<input type="hidden" name="action" value="insert" class="form-control" required placeholder="Enter invoiceno">

<div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier ?</label>
    <div class="col-sm-10">
		
	
		<select class="form-control"name="supplier" id="supplier" >
	
	<option value=""  >---Select Customer/supplier/vender---</option>

	


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


if(is_array($mycustomer)) {

   foreach($mycustomer as $mycustomerrow){

   //echo $courserow->coursename;
   ?>
					<option value="<?=  $mycustomerrow->id;   ?>"><?=  $mycustomerrow->idno ."". $mycustomerrow->firstname ." ".$mycustomerrow->lastname.""; ?></option>




	<?php

}} else {
    echo 'No Customer available.';
}
	
?>
</select>		
		  		
				
		<span class="text-danger"> 	<?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>	
  	
	      <div class="form-group">
    <label for="inputbankname" class="col-sm-2 control-label">Bank name?</label>
    <div class="col-sm-10">
	<select class="form-control" name="bankname" required>
	
	<option value=""  >---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');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->id;   ?>"><?=  $bankingrow->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 class="form-group">
    <label for="inputtype" class="col-sm-2 control-label">	Ref No </label>
    <div class="col-sm-10">
	
			<input type="text" readonly name="invoice" value="<?php echo set_value('invoiceno',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoiceno">

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

  
  	<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">	Amount </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="amount" value="<?php echo set_value('amount'); ?>" 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="inputuser" class="col-sm-2 control-label">Name? </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="user" value="<?php echo set_value('user'); ?>" class="form-control" required placeholder="Enter the person in charge">
		 
				
		<span class="text-danger"> <?php echo form_error('user'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Invoice /Purchase Order No</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="idno" value="<?php echo set_value('idno'); ?>" class="form-control"  placeholder="Enter Invoice or Purchase Order Number if any ">
		 
				
		<span class="text-danger"> <?php echo form_error('idno'); ?>
		
		</span>
	</div>
  </div>
  <div class="form-group">
    <label for="inputcontact" class="col-sm-2 control-label">Contact </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="contact" value="<?php echo set_value('contact'); ?>" class="form-control"  placeholder="Phone of person incharge ">
		 
				
		<span class="text-danger"> <?php echo form_error('contact'); ?>
		
		</span>
	</div>
  </div>
  	<div class="form-group">
    <label for="inputcontroller" class="col-sm-2 control-label">Approved by? </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="controller" value="<?php echo set_value('controller'); ?>" class="form-control" required placeholder="Confirmed by?">
		 
				
		<span class="text-danger"> <?php echo form_error('controller'); ?>
		
		</span>
	</div>
  </div>
  
  <div class="form-group">
    <label for="inputpaymentmethodes" class="col-sm-2 control-label">Payment mode </label>
    <div class="col-sm-10">
	
<select class="form-control" name="paymentmethodes" required>
	<option value="" selected="selected"  >---Select payment methods---</option>

	
	
<?php 


	
	$paymentmethodes= $this->usermodel->populateall('paymentmethodes','companyid',$companyid);


	
if(is_array($paymentmethodes)) {

   foreach($paymentmethodes as $paymentmethodesrow){

    ?>
					<option value="<?=  $paymentmethodesrow->id;   ?>"><?=  $paymentmethodesrow->name; ?></option>



	<?php

}} else {
    echo 'No method.';
}
	
?>
</select>								
				 
				
		<span class="text-danger"> <?php echo form_error('controller'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
  
  
  
  	<div class="form-group">
    <label for="inputdatespent" class="col-sm-2 control-label">	Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="datespent" value="<?php echo set_value('datespent', $mydate); ?>" class="form-control" required placeholder="Enter date ">
		 
				
		<span class="text-danger"> <?php echo form_error('datespent'); ?>
		
		</span>
	</div>
  </div>
  	<div class="form-group">
    <label for="inputphoto" class="col-sm-2 control-label">	Upload Document</label>
    <div class="col-sm-10">
	<input type="hidden" name="img_id"   value="<?php if(isset($img_id)) {echo $img_id; }?>"  class="form-control">


	<input type="file" name="photo" value="<?php echo set_value('photo'); ?>"id="photo" class="form-control"  placeholder="Please upload image if any">
			<span class="text-danger"> <?php echo form_error('photo'); ?>
		
		</span>
	</div>		
</div>

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

				<textarea name="description" value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter description"></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"  value="expense" name="btn_addexpense" class="btn btn-default"> Add Expense/Income   </button>

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

    

				</div>

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





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

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

 
</div>


















