<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() {  
            $("#id").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/lookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
			
		 $(document).on("click", "#managebtndelete", function()
        {
          var transactionid = $(this).data('id');
		  $("#transactionid").val(transactionid); 
   var myid = $(this).data('myid');
		  $("#myid").val(myid); 
		   
		   
        });
		  $(function() {
<!--             $(".datepicker").datepicker(); -->
<!--             $(".uniform_on").uniform() -->;
            $(".chzn-select").chosen();
   <!--          $('.textarea').wysihtml5(); -->

        });
        </script>
	   	
 
 <div class="row">
  
   	

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

  <?php
 
				echo $this->session->flashdata('msg'); 
   $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['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
	 
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
    $deletebank=$this->usermodel->populatuserpermissionsdataarray('accounting','deletebank',$userid);
	    $viewaccounting=$this->usermodel->populatuserpermissionsdataarray('accounting','view',$userid);
    $postrentalexpenses=$this->usermodel->populatuserpermissionsdataarray('incomeexpenses','postrentalexpenses',$userid);

	
	
	
	 $closeexpense=$this->usermodel->populatuserpermissionsdataarray('incomeexpenses','closeexpense',$userid);
    $updateclosedexpenses=$this->usermodel->populatuserpermissionsdataarray('incomeexpenses','updateclosedexpenses',$userid);
	 
  
  ?>
		<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-center"> </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/viewexpenses" class="btn btn-info"> Back </a>
DAILY EXPENSES
				 
            	</div>
            </div>
			<div class="panel-body">


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

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

 
	$session_data = $this->session->userdata('logged_in');

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 

		
                 echo form_open('user/addexpense' , array('class' => 'form-inline form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):
				 $salesid=$main[0]['invoice']

				 ?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

 </div>
	<div class="col-md-12">
	
	
	
	<?php 
	if($action=="insert"){
			?>
			<input type="hidden" name="myview" value="user/editexpense?randomitemidentifier=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">
									<input type="hidden" name="filename" value="editexpense" class="form-control" required placeholder="Enter invoiceno">
								<input type="hidden" name="type" value="<?php echo set_value('type',$type); ?>" class="form-control" required placeholder="Enter type">
		<input type="hidden" readonly name="invoice" value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoiceno">

									<input type="hidden" name="view" value="user/editexpense?randomitemidentifier=" class="form-control" required placeholder="Enter invoiceno">
								<input type="hidden" name="action" value="insert" class="form-control" required placeholder="Enter invoiceno">

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

 	
		
		
		
		
	<?php	
	}else{
	?>	
		
			<input type="hidden" name="myview" value="user/editexpense?randomitemidentifier=<?php echo $main[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">
									<input type="hidden" name="filename" value="editexpense" class="form-control" required placeholder="Enter invoiceno">
								<input type="hidden" name="type" value="<?php echo set_value('type',$main[0]['type']); ?>" class="form-control" required placeholder="Enter type">
		<input type="hidden" readonly name="invoice" value="<?php echo set_value('invoice',$main[0]['invoice']); ?>" class="form-control" required placeholder="Enter invoiceno">

									<input type="hidden" name="view" value="user/editexpense?randomitemidentifier=" class="form-control" required placeholder="Enter invoiceno">
								<input type="hidden" name="action" value="update" class="form-control" required placeholder="Enter invoiceno">

								<input type="hidden" name="itemid" value="<?php echo set_value('id',$main[0]['id']); ?>" class="form-control" required placeholder="Enter invoiceno">

 	
		
		
		
		<?php		
	}
	
	?>
	
	
	
									
	      <div class="form-group">
    <label for="inputbankname" class="col-sm-2 control-label">Bank name?</label>
    <div class="col-sm-4">
	<select class="form-control" name="bankname" required>
	
	
   <?php
	$bankid= $main[0]['bankname'];
$bank= $this->usermodel->populateall('glaccounts','number',$bankid);



if(is_array($bank)) {

   foreach($bank as $bankrow){

   $bankamount=$bankrow->amount;
    ?>
					<option  selected="selected"  value="<?=  $bankrow->number;   ?>"><?=  $bankrow->accountname ."(Acc No:". $bankrow->number ."-Acc Name: ".$bankrow->accountname.")"; ?></option>

   
    <?php

}} else {
 ?>
<option value=""  >---Select Bank---</option>

		<?php 
}

										//$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');
										$banking= $this->usermodel->populatealldatanoarraythree('glaccounts','companyid',$companyid,'accounttype','1','accountstatus <>','inactive');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->number;   ?>"><?=  $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="inputsupplier" class="col-sm-2 control-label">Payee ?</label>
    <div class="col-sm-4">
		
	
		<select class="chzn-select"name="supplier" id="supplier" >
	
	<option value=""  >---Select Customer/supplier/vender---</option>


   <?php
 $countryid= $main[0]['supplier'];
 		$mysupplier= $this->usermodel->populateall('people','id',$countryid);



if(is_array($mysupplier)) {

   foreach($mysupplier as $mysupplierrow){

    ?>
					<option selected="selected" value="<?=  $mysupplierrow->id;   ?>"><?=  $mysupplierrow->company ."". $mysupplierrow->firstname ." ".$mysupplierrow->lastname.""; ?></option>

   
    <?php

}} else {
 ?>
<option value=""  >---Select supplier/customer---</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->company ."". $mycustomerrow->firstname ." ".$mycustomerrow->lastname.""; ?></option>




	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>		
		  		
				
		<span class="text-danger"> 	<?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>	
		
	
  	
	 
	   </div>
		<div class="col-md-12">

		
				  <div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">Invoice /Purchase Order No</label>
    <div class="col-sm-4">
	<input type="hidden" readonly  name="dateposted" value="<?php echo set_value('dateposted',$main[0]['dateposted']); ?>"id="dateposted" class="form-control2" required placeholder="Enter date  ">

	<input type="text"   name="idno" style="width:50%" value="<?php echo set_value('idno',$main[0]['idno']); ?>"id="dateposted" class="form-control2"  placeholder="Enter Invoice or Purchase Order Number if any ">
			
			
			
  
									<?php 

	if($action=="insert"){
		?>					
						
				
				<select class="form-control2" name="branchid"  id="branchid" required style="width:20%; margin:0px;">
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
								

	
	<?php
	     $mybranch=$this->usermodel->populateall('branch','id',$branchid);


if(is_array($mybranch)) {

   foreach($mybranch as $branchrow){

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




	<?php

}} else {
    echo 'No Branch available.';
}
	
?>
	
	
	
	
	
	
	
	
	
	
	

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


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
				
									<?php 
										}else{
											?>
 				<select class="form-control2" name="branchid"  id="branchid" required style="width:20%; margin:0px;">

 	<?php
	     $mybranch=$this->usermodel->populateall('branch','id',$main[0]['branchid']);


if(is_array($mybranch)) {

   foreach($mybranch as $branchrow){

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




	<?php

}} else {
    echo 'No Branch available.';
}
	
?>
	
 
				
	
	
	<option value=""  >---Select Branch--</option>

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


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
				
			
 
										<?php 	 
										 }
										?>
										



			
			
			
			
			
			
			
			
			<span class="text-danger"> <?php echo form_error('idno'); ?>
		
		</span>
	</div>
  </div>
				
			
		
			
		
					  <div class="form-group" style=" margin:0px;">
    <label for="inputcanceldate" class="col-sm-2 control-label">Expense Date YYY-M-D </label>
    <div class="col-sm-4">
	<?php 
	if($action=="insert"){
				 $mycurrentdate=date("Y-m-d");

			?>
					  		<input type="date" name="datespent" value="<?php echo set_value('datespent', $mycurrentdate); ?>" class="form-control" required placeholder="Enter date ">

			
		<?php 
	}else{
			?>	

		
		
	<input type="text" name="datespent" value="<?php echo set_value('datespent',$main[0]['datespent']); ?>"id="datespent" class="form-control" required placeholder="Enter spent date ">
			<span class="text-danger"> 

		<?php 
	}
			?>			
			<?php echo form_error('datespent'); ?>
		
		</span>
	</div>
  </div>		
		
		   </div>
	
		<div class="col-md-12">

		
		
				
				  <div class="form-group">
    <label for="inputcontroller" class="col-sm-2 control-label">Approved by? </label>
    <div class="col-sm-4">
<input type="text"  name="controller" value="<?php echo set_value('controller',$main[0]['controller']); ?>" class="form-control" required placeholder="Enter controller">
			<span class="text-danger"> <?php echo form_error('controller'); ?>
		
		</span>
	</div>
  </div>		
			
		
					  <div class="form-group">
    <label for="inputcontact" class="col-sm-2 control-label">Phone/Other details </label>
    <div class="col-sm-4">

	<input type="text" name="contact" value="<?php echo set_value('contact',$main[0]['contact']); ?>"id="contact" class="form-control"  placeholder="Enter contact">
			<span class="text-danger"> <?php echo form_error('contact'); ?>
		
		</span>
	</div>
  </div>		
		
		   </div>
		<div class="col-md-12">


  
<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">Description/Note</label>
    <div class="col-sm-4">
<input type="text"  name="description" value="<?php echo set_value('description',$main[0]['description']); ?>" class="form-control"  placeholder="Enter description">

	
	</div>
  </div>
  

 
  	  

				
  
  
  
 <div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label"> Amount   </label>
    <div class="col-sm-4">
		
				<input type="text"  readonly name="amount" value="<?php echo set_value('amount',$main[0]['amount']) ;?>" id="dob" class="form-control" required  placeholder="Please enter amount ">
<input type="hidden" name="user" value="<?php echo set_value('user',$main[0]['user']); ?>" class="form-control" required placeholder="Enter user/incharge ">
		 
<input type="hidden" name="paymentmethodes" value="n/a" class="form-control" required placeholder="Enter user/incharge ">

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


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

  	

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

    <div class="col-sm-4">
	
	
	<?php 
	if($action=="insert"){
			
			?>

	         <button type="submit"  name="btn_addexpense"  value="expense"  class="btn btn-primary"> Post this Expense </button>

			
		<?php 
	}else{
			?>	


	         <button type="submit"  name="btn_addexpense"  value="expense"  class="btn btn-primary"> Update Expense</button>
<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printmyexpense?invoice=<?php   if(isset($main[0]['invoice'])) {echo $main[0]['invoice']; } ?>">  Print Expense   </a>

		<?php 
	}
			?>	
			
			
			
			
    
    </div>
  </div>
  
  <div class="form-group">
    <label for="inputimgid" class="col-sm-2 control-label">Dep name?</label>
    <div class="col-sm-4">
	<select class="form-control" name="department" >
	
	<option value="" >---Select Department name---</option>

	
	
	   <?php
	   $department=$main[0]['department'];
	   

	   	if($action=="insert"){
			$allplots1=false;
		}else{
			
		
 		$allplots1= $this->usermodel->populateall('department','id',$department);	
			
		}
	   
	   
	   




if(is_array($allplots1)) {

   foreach($allplots1 as $allplotsrow){

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

   
    <?php

}} else {
 ?>

		<?php 
}

										$allplots1= $this->usermodel->populatealldatanoarray('department','id <>',"",'id >',0);


	
if(is_array($allplots1)) {

   foreach($allplots1 as $plotnamerow){

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



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
		
		
			
			
	

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

	</div>
  </div>
				 
						  <?php

 if( $postrentalexpenses==true){
 ?>

 

		
<div class="form-group">
    <label for="inputimgid" class="col-sm-2 control-label">Plot name?</label>
    <div class="col-sm-4">
	<select class="form-control" name="imgid" >
	
	<option value="" >---Select Plot name---</option>

	
	
	   <?php
	   
	   

	   	if($action=="insert"){
			$allplots=false;
		}else{
			
		$plotno=$main[0]['imgid'];
 		$allplots= $this->usermodel->populateall('plot','id',$plotno);	
			
		}
	   
	   
	   




if(is_array($allplots)) {

   foreach($allplots as $allplotsrow){

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

   
    <?php

}} else {
 ?>

		<?php 
}

										$plotname= $this->usermodel->populatealldatanoarray('plot','companyid',$companyid,'id >',0);


	
if(is_array($plotname)) {

   foreach($plotname as $plotnamerow){

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



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
		
		
		
		<?php 
	if($action=="insert"){
			$img_id = rand(100, 990000).time();
			?>

	<input type="hidden" name="img_id"   value="<?php if(isset($img_id)) {echo $img_id; }?>"  class="form-control">
	<input type="hidden" name="photo" value="<?php echo set_value('photo'); ?>"id="photo" class="form-control"  placeholder="Please upload image if any">


			
		<?php 
	}else{
			?>	

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


		<?php 
	}
			?>	
			
	

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

	</div>
  </div>
  
	 <?php	
}else{
	?>
	
	<?php 
	if($action=="insert"){
			$img_id = rand(100, 990000).time();
			?>

	<input type="hidden" name="img_id"   value="<?php if(isset($img_id)) {echo $img_id; }?>"  class="form-control">

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

			
		<?php 
	}else{
			?>	

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

	     				<input type="hidden" readonly name="imgid" value="<?php echo set_value('imgid',$main[0]['imgid']); ?>" class="form-control"  placeholder="Enter plot no">

		<?php 
	}
			?>	
			
	

	
	<?php
}
  ?> 
		
				
			
				 
  	
		
  
  

	
  					<?php echo form_close();?>
					
		 </div>			
			  </div>		
			
				<div class="widget-content nopadding table_holder table-responsive"  >		
	
		
	
					
					
				
					<div class="table-responsive2">
						<table id="register" class="table table-bordered " width="100%" >
						<thead>
							<tr>
								<th>Date</th>
								<th>Account:</th>
							
								<th colspan="2">Description:</th>
								<th>Ref No:</th>

								
								<th>Total</th>
								<th>Tax Type</th>
							

								
								<th>Save</th>
							</tr>
								<tr style="background:gray">
								
										<?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;
					}
	 $session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	    $addproductaction=$this->usermodel->populatuserpermissionsdataarray('purchases','add',$userid);

	 $updateaction=$this->usermodel->populatuserpermissionsdataarray('purchases','update',$userid);
  $updatebuyingpriceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updatebuyingprice',$userid);
  $deleteaction=$this->usermodel->populatuserpermissionsdataarray('purchases','delete',$userid);
  $updatesellingpriceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updatesellingprice',$userid);
    $updateclosedinvoiceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updateclosedinvoice',$userid);

      $invoicestatus=$this->usermodel->populateallarray('expenses','invoice',$finalsalesid);
$myinvoice=$invoicestatus[0]["status"];
  //refno
  
   echo $this->session->flashdata('productmsg'); 
                 echo form_open('user/addexpensestatement' , 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="accounting" value="yes" class="form-control" required placeholder="">

								<input type="hidden" name="invoice" value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoice">
<input type="hidden" name="mybank" id="mybank" value="<?php echo set_value('myid',$bankid); ?>" class="form-control" required placeholder="mybank" >

									<input type="hidden" name="view" value="user/editexpense?randomitemidentifier=<?php echo $main[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">
		<input type="hidden" name="myid" id="myid" value="" class="form-control" required placeholder="myid" >
	<input type="hidden" name="action" value="insert" class="form-control" required placeholder="Enter insert">

				<input type="hidden" readonly name="paymentmethodes" value="<?php echo set_value('paymentmethodes',$main[0]['paymentmethodes']) ;?>" id="paymentmethodes" class="form-control" required  placeholder="Please enter paymentmethodes ">

								
<th>
					<?php 
	if($action=="insert"){
				 $mycurrentdate=date("Y-m-d");

			?>
									<input type="text" text name="crateddate" value="<?php echo set_value('datespent',$mydate); ?>"id="datespent" class="form-control" required placeholder="Enter spent date ">

			
		<?php 
	}else{
			?>	

											<input type="text" text name="crateddate" value="<?php echo set_value('datespent',$main[0]['datespent']); ?>"id="datespent" class="form-control" required placeholder="Enter spent date ">



		<?php 
	}
			?>				


								
								</th>
								
								
									<th>
								

	<select class="chzn-select" name="bankname" required>
	
	<option value=""  >Select Account</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->populatealldatanoarraythree('glaccounts','companyid',$companyid,'description <>','4','accountstatus <>','inactive');

	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
		
	
								
								
								</th>
								
								
									
								
								
								
						<th colspan="2">
								

								
		  		<input type="text" name="description" id="description" value="<?php echo set_value('description'); ?>" class="form-control"  placeholder="Enter description" >
								
								</th>
								
					
							<th>
								

								
		  		<input type="text" name="refno" id="refno" value="<?php echo set_value('refno','N/A'); ?>" class="form-control"  placeholder="Enter refno" >
								
								</th>
								
								<th>
								

								
		  		<input type="text" name="amount" id="amount" value="<?php echo set_value('amount'); ?>" class="form-control" required placeholder="Enter amount" >
								
								</th>
							<th>
							
    
	
	<select class="form-control" name="tax" >
	
							<option value="VATABLE"   >VATABLE</option>

			<option value="ZERO RATED"  >ZERO RATED</option>
					  				<option value="EXEMPTED"  selected >EXEMPTED</option>

	
</select>
		
								<select class="form-control"name="supplier" id="supplier" style="display:none">
	
	<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 supplier available.';
}
	
?>
</select>	
							
							</th>
								
									<th>
																			  		<input type="text" name="code" id="code" style="width:55%" value="<?php echo set_value('code',0); ?>" class="form-control2"  placeholder="Ente Vat %" >

									Vat
									</th>
								<th colspan="2">


	<?php 
	if($action=="insert"){
			
			?>


			
		<?php 
	}else{
			?>	


	       								<button type="submit"  value="statement" name="btn_statment" class="btn btn-primary"> Post Expense  </button>

		<?php 
	}
			?>	
								

 
  					<?php echo form_close();?>
							
								</th>
								
							</tr>
							
							
								
						</thead>
						<?php
					 $finaltotal=0;
  $totalfinaltotal=0;
 if(!is_array($submain)) {
	  echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='5'>";
    echo"There is no data found..";
    echo "</td>";
   echo "</tr>";

			 }else{
 

  	foreach ($submain as $c){
		
$itemid=$c->id;
$total=$c->amount;
$finaltotal=(double)$finaltotal+(double)$total;
             ?>
				                    <tbody >
									
										 
										<?php
					
		
                 echo form_open('user/addexpensestatement' , 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;?>								
											<tr>
		



		
												
												<input type="hidden" name="finalsalesid" id="finalsalesid" value="<?php echo set_value('finalsalesid',$finalsalesid); ?>" class="form-control" required placeholder="finalsalesid" >
		<input type="hidden" name="itemid" id="itemid" value="<?php echo set_value('itemid',$c->id); ?>" class="form-control" required placeholder="itemid" >

<input type="hidden" name="accounting" value="yes" class="form-control" required placeholder="">

								<input type="hidden" name="invoice" value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoice">
<input type="hidden" name="mybank" id="mybank" value="<?php echo set_value('myid',$bankid); ?>" class="form-control" required placeholder="mybank" >

									<input type="hidden" name="view" value="user/editexpense?randomitemidentifier=<?php echo $main[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">

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

				<input type="hidden" readonly name="paymentmethodes" value="<?php echo set_value('paymentmethodes',$main[0]['paymentmethodes']) ;?>" id="paymentmethodes" class="form-control" required  placeholder="Please enter paymentmethodes ">

				<td>
													<input type="text" text name="crateddate" value="<?php echo $c->crateddate; ?>"id="crateddate" class="form-control" required placeholder="Enter spent date ">
							
				</td>
											
											
											
			<td>
			
	
  <select class="chzn-select" name="bankname" required>
	
	
		
	<?php 
	 $accountid= $c->account ;
										$account= $this->usermodel->populateall('glaccounts','number',$accountid);


	
if(is_array($account)) {

   foreach($account as $accountrrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $accountrrow->number;   ?>"><?=  $accountrrow->accountname; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
	<option value=""  >Select Account</option>

	
	<?php 
	
										$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'description','5');


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
			
			</td>
			
			<td colspan="2">
			
			
					  		<input type="text" name="description" id="description" value="<?php echo set_value('description',$c->description); ?>" class="form-control"  placeholder="Enter description" >

			
			</td>

	<td>
	
			  		<input type="text" name="refno" id="refno" value="<?php echo set_value('refno',$c->refno); ?>" class="form-control"  placeholder="refno" >

	
	</td>
					<td><?php  
					
$totalfinaltotal=(double)$totalfinaltotal+(double)$c->amount;
					
					?>
							  		<input type="text" name="amount" id="amount" value="<?php echo set_value('amount',$c->amount); ?>" class="form-control" required placeholder="amount" >

					
					
					</td>
			<td >
			
			
			
				
	<select class="form-control" name="tax" >

								<option  selected="selected" value="<?php echo $c->tax ?>"   ><?php echo $c->tax; ?></option>

							<option value="VATABLE"   >VATABLE</option>

			<option value="ZERO RATED"  >ZERO RATED</option>
					  				<option value="EXEMPTED"   >EXEMPTED</option>

	
</select>
		
			
			
			
			
			
			
			</td>

				<td ><?php echo $c->vat; ?>
				
						  		<input type="hidden" name="vat" id="vat" value="<?php echo set_value('amount',$c->vat); ?>" class="form-control" required placeholder="vat" >


				
				</td>

											
											
											

										
											 
		
				  									 
											 
											 
											 
											 
											 
											 
												  
											  
											  
											  
											  
											  <td>
										  		<input type="text" name="code" id="code" style="width:25%" value="<?php echo set_value('code',$c->code); ?>" class="form-control2"  placeholder="Ente Vat %" >

											  <button type="submit"  value="statement" name="btn_statment" class="btn btn-primary"> <span class="glyphicon glyphicon-pencil">Update</span> </a>   </button>

											  </td>
											  
											  
												 	<td  style='color:green'> 
				<?php

	
 if( $deleteaction==true){
	 
	 ?>
		   		                              <a  id="more" class="btn btn-danger" href="<?php echo base_url();?>user/deletepurchasedproducts?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&itemid=<?php   {echo  $c->id;}  ?>&view=user/editexpense?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&deltetable=statement&maintable=expenses"> <span class="glyphicon glyphicon-trash"></span> </a>

	 
	 	<?php	

 }else{
	
 }
  ?>
		                              </td> 
		  					<?php echo form_close();?>
					
 </tr>
 <?php 
	 }?>
				<?php }?>							
	
	
							
<tr>
			<td colspan="4"><h3 style="padding:0; margin:0;">
			TOTAL MONEY SPENT:
			</h3>
			
			
					<?php 
					
	if($action=="insert"){
			
			?>


			
		<?php 
	}else{
			?>	


	       								<!--<button type="submit"  value="statement" name="btn_statment" class="btn btn-primary"> Add  Account Expense  </button>-->


										
		
					<?php


 if( $closeexpense==true){
	 
if ($myinvoice=="closed"){
	if($updateclosedexpenses==true){
		
		 ?>
<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>user/updateandcloseexpenses?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&status=closed">Click here Complete And Close</a>
									 <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Attach/upload Expense documents </a>

	 
	 	<?php
		
	}
	
}else{
	 
	 ?>
<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>user/updateandcloseexpenses?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&status=closed">Click here Complete And Close</a>
									 <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Attach/upload Expense documents </a>

	 
	 	<?php	
}
 }else{
	
 }
  ?>
		<?php 
	}
			?>	
				</td>
			
								<td colspan="4"><h3 style="padding:0; margin:0;">Total:<?php if(isset($totalfinaltotal)) {echo formatMoney($totalfinaltotal, true); }?></h3></td>
			
				

			</tr>
							
							
         
								
				
									</tbody>
									
									
					</table>
					
					
				</div>	
			</div>			
					
		
			

<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>
    
     <th>Name/title</th>
	 <th>Date Posted</th>
	 <th>No</th>
	  <th>Category</th>
	     <th>Comment</th>
		 <th>Added By?</th>
<th>View</th>		 
		 
	

                 </tr>
             </thead>
<?php
 if(!is_array($viewdocuments)) {
				   // echo '<div class="alert alert-warning text-center">There was no document found in the system. Feel free to add many documents.</div>';

			 }else{
 if(!is_array($viewdocuments)) 

 {


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

		 

             ?>



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

?>

              

  <td><?php echo $c->documentname ; ?></td>
  <td><?php echo $c->entrydate ; ?></td>
    <td><?php echo $c->idno ; ?></td>
	   <td><?php echo $c->category ; ?></td>
     <td><?php echo $c->description ; ?></td>
   <td><?php ; 
   $userid=$c->userid;
   if($userid!=""){
	  
      $myname = $this->usermodel->geteuser($userid);
  
     $fname=$myname[0]['firstname']; 
echo $names= $fname; 
	
   }else{
	    echo "No Sender";  
   }
  
  
  ?></td>
 
	  <td>
	 <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/viewmoredocuments?randomitemidentifier=<?php   {echo  $img_id;}  ?>&type=document">View Document  </a>

	  </td>
	  	  <td>

	  </td>
			
             </tr>

	<?php endforeach;} ?>

              <?php }?>

        </table>











			
					
					
					
					
					
					
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </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">Upload new documents</h4>
      </div>
      <div class="modal-body">
      
	  	

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

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

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



	<?php 
	if($action=="insert"){
			?>
			<input type="hidden" name="view" value="user/editexpense?randomitemidentifier=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">
		<input type="hidden" readonly name="mydocuments" value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoiceno">



 	
		
		
		
		
	<?php	
	}else{
	?>	
		
			<input type="hidden" name="view" value="user/editexpense?randomitemidentifier=<?php echo $main[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">
		<input type="hidden" readonly name="mydocuments" value="<?php echo set_value('invoice',$main[0]['invoice']); ?>" class="form-control" required placeholder="Enter invoiceno">



 	
		
		
		
		<?php		
	}
	
	?>
	













		<div class="form-group">
    <label for="inputphoto" class="col-sm-2 control-label">	Upload Document</label>
    <div class="col-sm-10">
		<input type="hidden" readonly name="img_id" value="<?php echo set_value('invoice',$img_id); ?>" class="form-control" required placeholder="Enter invoiceno">


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





	  		
	<div class="form-group">
    <label for="inputdocumentname" class="col-sm-2 control-label">	document name </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="documentname" value="<?php echo set_value('documentname'); ?>" class="form-control" required placeholder="Enter document name">
		 
				
		<span class="text-danger"> <?php echo form_error('documentname'); ?>
		
		</span>
	</div>
  </div>

  
  
  
  	<div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">	Doc Number/ code </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="idno" value="<?php echo set_value('idno'); ?>" class="form-control"  placeholder="Enter idno/ code/ transaction code if any">
		 
				
		<span class="text-danger"> <?php echo form_error('idno'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
  	<div class="form-group">
    <label for="inputcategory" class="col-sm-2 control-label">	Category </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="category" value="<?php echo set_value('category'); ?>" class="form-control"  required placeholder="Enter category if any">
		 
				
		<span class="text-danger"> <?php echo form_error('category'); ?>
		
		</span>
	</div>
  </div>
  
   	<div class="form-group">
    <label for="inputentrydate" class="col-sm-2 control-label">	Entry Date </label>
    <div class="col-sm-10">
	
		  		<input type="date" name="entrydate" value="<?php echo set_value('entrydate',$mydate); ?>" class="form-control"  required placeholder="Enter entrydate">
		 
				
		<span class="text-danger"> <?php echo form_error('entrydate'); ?>
		
		</span>
	</div>
  </div>
  
  
	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Comment</label>
    <div class="col-sm-10">

				<textarea name="description" value="<?php echo set_value('description'); ?>"  class="form-control"  placeholder="Enter Comment "></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="documents" name="btn_adddocuments" class="btn btn-primary"> Add documents   </button>

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

    

				</div>

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








