

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

 

         <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 Bills</span>					                    
						 <a data-toggle='modal' data-target='#addModal' class="btn btn-default">Add Bill </a>
	  	  				 <a href="<?php echo base_url();?>user/viewexpenses" class="btn btn-default"> View Expense</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 Creditors</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="row">
				
				
               
           
		  <?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;
					}
					
		 $mydate=date("Y-m-d");

        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallbills", $attr);?>
			
				
				  <div class="col-md-2">            				<input type="hidden" name="view" value="userdata/receivebill"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-2">
		  		<input type="text" name="startdate" value="<?php echo set_value('startdate',$mydate); ?>" class="form-control" required placeholder="Enter from date">

					</div>
				
				
				
				  <div class="col-md-2">
		  		<input type="text" name="closedate" value="<?php echo set_value('closedate',$mydate); ?>" class="form-control" 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"  selected="selected" >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">
				<select class="form-control" name="download"  id="download" required>
	
	
	<option value=""  >---Select Activity--</option>

			<option value="no"  selected="selected">Just View</option>

				<!--	<option value="yes"  >Download</option>
	
-->
	

					
</select>
                </div>
				
                <div class="col-md-2">
				                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-default" value="Search" />
                    <a href="<?php echo base_url(). "user/receivebill"; ?>" class="btn btn-default">Refresh</a>
				</div>
		
        <?php echo form_close(); ?>
            </div>
							<div class="panel-body">
	
									
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>

    	      <th>View</th>
			      	      <th>No</th>

    	      <th>Supplier</th>

		   <th>Amount</th>
		       <th>Contact Person</th>
		    <th>Billing Paid</th>
		      <th>Due Date</th>
			        <th>Approver</th>
	     <th>Description</th>
			<th>Status</th>		 
				<th>Payments</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-default"  href="<?php echo base_url();?>user/editbill?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>">View  </a>

  </td>
  	   <td><?php echo $c->type." :". $c->id ; ?></td>

<td>

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

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

  ?>



</td>
           
	  <td><?php echo $c->amount ; ?></td>
	   <td><?php echo $c->user ; ?></td>
	   
  <td><?php echo $c->datespent; ?></td>
   <td><?php echo $c->duedate; ?></td>
	   <td><?php echo $c->controller ; ?></td>
	    <td><?php echo $c->description ; ?></td>
		  <td><?php echo $c->status ; ?></td>
		
		
			<td><?php 
 $billid=$c->id;
	
	  ?>
	  	  	  	 <a  id="more" class="btn btn-default"  href="<?php echo base_url();?>user/viewpaidbills?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>">View Payments  </a>

  </td>
	   <td> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									<?php
										if($usertype=="admin"){
											
											?>
                                    <ul class="dropdown-menu dropdown-default 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>
<h2>
Balance
</h2>
</td>
<td colspan="10">
<h2>
<?php 
if(isset($total)) {echo $total; }


?>
</td>

</h2>


</tr>
           

        </table>

			  <div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "  Records in the system. " ;?>    </span>

        
        </div>						
									
									
					</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/paybill">
 <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 Bill</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/addbill' , 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/paybill" class="form-control" required placeholder="Enter view">

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

     								<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->company ."(". $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="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="inputidno" class="col-sm-2 control-label">Number</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">Invoice / P Order / Sales Order No <?php echo form_error('idno'); ?>
		
		</span>
	</div>
  </div>
  	<div class="form-group" style="display:none">
    <label for="inputreceiptno" class="col-sm-2 control-label">		Bill No </label>
    <div class="col-sm-10">
	
			<input type="text" readonly  name="receiptno" value="<?php echo set_value('receiptno'); ?>" class="form-control" required placeholder="Enter bill no">

		<span class="text-danger"> <?php echo form_error('receiptno'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group" style="display:none">
    <label for="inputamount" class="col-sm-2 control-label">Total Bill	Amount </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="amount"   value="0.00" 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">Contact Person? </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="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="inputdatespent" class="col-sm-2 control-label">	Bill 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="inputduedate" class="col-sm-2 control-label">	Due Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="duedate" value="<?php echo set_value('duedate', $mydate); ?>" class="form-control" required placeholder="Enter due date ">
		 
				
		<span class="text-danger"> <?php echo form_error('duedate'); ?>
		
		</span>
	</div>
  </div>
   	<div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">Payment terms </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="terms" value="<?php echo set_value('terms'); ?>" class="form-control"  placeholder="Enter the payment terms">
		 
				
		<span class="text-danger"> <?php echo form_error('terms'); ?>
		
		</span>
	</div>
  </div>

	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">Memo/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="bill" name="btn_addbill" class="btn btn-default"> Next>>   </button>

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

    

				</div>

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





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

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

 
</div>


















