<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">
	 <script src="<?php echo base_url(); ?>assets/autocomplete/jquery.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.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(); -->

        });
		
		
		
		

function selectvat()
{
  var vattype = document.getElementById('vattype').value;;

  

	 
	 if(vattype!=""){
		 
		  
		 
 document.forms[2].submit() ;
		
		

	 }else{
		 alert("There is aproblem reloading the page. Kindly logout then login again");
	 }
  //id.value = myproductcategory;
 
//alert(myproductcategory);

}


		
		
		
		
		
		
		
		
        </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['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
    $deletebank=$this->usermodel->populatuserpermissionsdataarray('accounting','deletebank',$userid);
 $mpesaaction=$this->usermodel->populatuserpermissionsdataarray('sales','mpesa',$userid);
	      $chequeaction=$this->usermodel->populatuserpermissionsdataarray('sales','cheque',$userid);
 $voucheraction=$this->usermodel->populatuserpermissionsdataarray('sales','voucher',$userid);
	      $creditaction=$this->usermodel->populatuserpermissionsdataarray('sales','credit',$userid);
		   $pointsaction=$this->usermodel->populatuserpermissionsdataarray('sales','points',$userid);
	      $cardaction=$this->usermodel->populatuserpermissionsdataarray('sales','card',$userid);
	      $orderaction=$this->usermodel->populatuserpermissionsdataarray('sales','order',$userid);
		  	 $cashaction=$this->usermodel->populatuserpermissionsdataarray('sales','cash',$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"> Update/Create Sales Order  </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/salesorder" class="btn btn-info"> Back </a>

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


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

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


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

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

 </div>
	<div class="col-md-12">
									<input type="hidden" name="view" value="user/viewnewsalesorder?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="status" value="s.o" class="form-control" required placeholder="Enter sales">

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

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


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



if(is_array($mysupplier)) {

   foreach($mysupplier as $mysupplierrow){
$comapany=$mysupplierrow->company;
    ?>
					<option selected="selected" value="<?=  $mysupplierrow->id;   ?>"><?php if($comapany==""){echo $mysupplierrow->firstname;}else{ echo $comapany;}?></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){
$comapany=$mycustomerrow->company;

   //echo $courserow->coursename;
   ?>
					<option  value="<?=  $mycustomerrow->id;   ?>"><?php if($comapany==""){echo $mycustomerrow->firstname;}else{ echo $comapany;}?></option>





	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>		
		  		
				
		<span class="text-danger"> 	<?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>	
  	
		
		
	
  	
		<div class="form-group">
    <label for="inputorderedby" class="col-sm-2 control-label">	Ordered by: </label>
    <div class="col-sm-4">
	
		  		<input type="text" name="orderedby" value="<?php echo set_value('orderedby',$purchaseorder[0]['orderedby']); ?>" class="form-control"  placeholder="Enter  contact Name for P.O ">
		 
				
		<span class="text-danger"> <?php echo form_error('orderedby'); ?>
		
		</span>
	</div>
  </div>
	 
	   </div>
		<div class="col-md-12">

		
		
				
			  <div class="form-group">
    <label for="inputorderdate" class="col-sm-2 control-label">S.Order Date </label>
    <div class="col-sm-4">

	<input type="text" name="orderdate" value="<?php echo set_value('orderdate',$purchaseorder[0]['orderdate']); ?>"id="orderdate" class="form-control" required placeholder="Enter specific order date  (dd-mm-YYY) ">
			<span class="text-danger"> <?php echo form_error('orderdate'); ?>
		
		</span>
	</div>
  </div>		
			
		
					  <div class="form-group">
    <label for="inputcanceldate" class="col-sm-2 control-label">Exp Expiry Date </label>
    <div class="col-sm-4">

	<input type="text" name="canceldate" value="<?php echo set_value('canceldate',$purchaseorder[0]['canceldate']); ?>"id="canceldate" class="form-control" required placeholder="Enter cancel order date  (dd-mm-YYY) ">
			<span class="text-danger"> <?php echo form_error('canceldate'); ?>
		
		</span>
	</div>
  </div>		
		
		   </div>
	
		<div class="col-md-12">			
			  <div class="form-group">
    <label for="inputfob" class="col-sm-2 control-label">Freight On Board </label>
    <div class="col-sm-4">

	<input type="text" name="fob" value="<?php echo set_value('fob',$purchaseorder[0]['fob']); ?>"id="fob" class="form-control"  placeholder="Enter person in charge   ">
			<span class="text-danger"> <?php echo form_error('fob'); ?>
		
		</span>
	</div>
  </div>		
		
		
		
		
		
		
		<div class="form-group">
    <label for="inputordernumber" class="col-sm-2 control-label">Sales Order  No: </label>
    <div class="col-sm-4">
	
		  		<input type="text"  name="ordernumber" value="<?php echo set_value('ordernumber',$purchaseorder[0]['ordernumber']); ?>" class="form-control"  placeholder="Enter  order number ">
		 
				
		<span class="text-danger"> <?php echo form_error('ordernumber'); ?>
		
		</span>
	</div>
  </div>
		</div>
		<div class="col-md-12">

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

	<input type="text" name="terms" value="<?php echo set_value('terms',$purchaseorder[0]['terms']); ?>"id="terms" class="form-control"  placeholder="Enter Terms of payment  ">
			<span class="text-danger"> <?php echo form_error('terms'); ?>
		
		</span>
	</div>
  </div>
 
  	    <div class="form-group">
    <label for="inputdeliverymethod" class="col-sm-2 control-label"> Delivery Method:   </label>
    <div class="col-sm-4">
		
				<input type="text" name="deliverymethod" value="<?php echo set_value('deliverymethod',$purchaseorder[0]['deliverymethod']) ;?>" id="dob" class="form-control"   placeholder="Please provide delivery method ">

				
		
	</div>
  </div>
  	

				</div>
		<div class="col-md-12">	
					
  
  
  
  <div class="form-group">
    <label for="inputshippingto" class="col-sm-2 control-label">Shipping to details.</label>
    <div class="col-sm-4">

	<textarea name="shippingto" class="form-control" placeholder="Shipping No"><?php echo set_value('shippingto',$purchaseorder[0]['shippingto']); ?></textarea> 
			
	</div>
  </div>
<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">Note/Message</label>
    <div class="col-sm-4">

	<textarea name="description" class="form-control" placeholder="Bussines/comments/note"><?php echo set_value('description',$purchaseorder[0]['description']); ?></textarea> 
			
	</div>
  </div>
  
</div>
	
  	<div class="col-md-12">					
				
			 <div class="form-group">
			 
    <label for="inputagent" class="col-sm-2 control-label">Agent/ Sales person</label>
    <div class="col-sm-4">
	


	
	
	
		<select class="form-control"name="agent" id="agent" >
	
	<option value=""  >---Select Agent/ Sales person if any--</option>
	<option value=""  >---No agent/Sales person Required--</option>


   <?php
 $agentid= $purchaseorder[0]['agent'];
 		$mysupplier= $this->usermodel->populateall('people','id',$agentid);



if(is_array($mysupplier)) {

   foreach($mysupplier as $mysupplierrow){
$comapany=$mysupplierrow->company;
    ?>
					<option selected="selected" value="<?=  $mysupplierrow->id;   ?>"><?php if($comapany==""){echo $mysupplierrow->firstname;}else{ echo $comapany;}?></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){

$comapany=$mycustomerrow->company;

   //echo $courserow->coursename;
   ?>
					<option  value="<?=  $mycustomerrow->id;   ?>"><?php if($comapany==""){echo $mycustomerrow->firstname;}else{ echo $comapany;}?></option>




	<?php

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

	<select name="paymentmethodes" required id="paymentmethodes" class="form-control1" style="width:60%">
					<?php	
					if(trim($purchaseorder[0]['paymentmethodes']) != ""){
?>
						<option selected="selected" value="<?=  $purchaseorder[0]['paymentmethodes'];  ?>"><?php  $purchaseorder[0]['paymentmethodes']; 
						  if($$purchaseorder[0]['paymentmethodes']="Mpesa"){ echo "Mobile Money";}else{ echo $c->type ; }

						
					
						?></option>


			<?php

					}else{
						?>
					<option value="" selected="selected">Select Mode of payment</option>
		
						
				<?php
				}
						?>					
						

		<option value="" >Select Mode of payment</option>


	
	<option value="Cash" >Cash</option>

	









<?php
 if( $mpesaaction==true){
	 ?>
<option value="Mpesa">Mobile Money</option>
		<?php	
		}
  ?>


<?php
 if( $cardaction==true){
	 ?>
<option value="Card">Card</option>
		<?php	
		}
  ?>
  
  
  
<?php
 if( $creditaction==true){
	 ?>
<option value="Invoice">Invoice / Credit</option>
		<?php	
		}
  ?>
  
  

  
<?php
 if( $chequeaction==true){
	 ?>
<option value="Bank">Bank</option>
		<?php	
		}
  ?>
  
  
  <?php
 if( $voucheraction==true){
	 ?>
<option value="Voucher">Voucher/Complimentary</option>
		<?php	
		}
  ?>
  
  
<?php
 if( $pointsaction==true){
	 ?>
<option value="Points">Bonga Points</option>
		<?php	
		}
  ?>
  
  
  
<?php
 if( $creditnoteeaction==true){
	 ?>
<option value="Creditnote">Credit Note</option>
		<?php	
		}
  ?>
  
<option value="Delivery">Cash On Delivery</option>


<option value="Savedata">Save Customer</option>

</select>										
</BR>
	
	
	
	
	
	
     
	         <button type="submit"  name="btn_purchaseorder"  value="mysalesorder"  class="btn btn-primary"> Update Sales order </button>

<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printsalesorder?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&type=so">  Print Sales Order   </a>

	  <button type="submit"  name="btn_purchaseorder"  value="generatedelivery"  class="btn btn-success"> <?php   if(($confirminvoice)) {echo  "Update Invoice  Delivery";}else{ echo  "Process Invoice Delivery";} ?></button>
 
 	
	 <button type="submit"  name="btn_purchaseorder"  value="generatesales"  class="btn btn-success"> <?php   if(($confirminvoice)) {echo  "Update Cash Delivery";}else{ echo  "Process Cash Delivery";} ?></button>

 
 <?php   if(($confirminvoice)) {
	 ?>
	 <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printdelivery?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>">  Print Delivery    </a>
	 <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printinvoice?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>">  Print Invoice   </a>

	 <?php
	
	 }else{
		 
		 ?>
		 	<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printinvoice?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&type=invoice">  Print Invoice   </a>

		 <?php
		
		 }

 ?>
 <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printquote?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&type=quotation">  Print Quotation   </a>

    </div>
  </div>
  
						
			
			    <div class="form-group">  
			
			
				
    <label for="inputamount" class="col-sm-2 control-label">    </label>
    <div class="col-sm-4">Category/Table:
		
		<select class="form-control2"name="mytable" id="mytable" >
	
	<option value=""  >---Select---</option>


   <?php
 $mytable= $purchaseorder[0]['remarks'];
 		$allmysupplier= $this->usermodel->populateall('tables','name',$mytable);



if(is_array($allmysupplier)) {

   foreach($allmysupplier as $mysupplierrows){
    ?>
					<option selected="selected" value="<?=  $mysupplierrows->name;   ?>"><?php echo$mysupplierrows->name;?></option>

   
    <?php

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

		<?php 
}


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


if(is_array($allmycustomer)) {

   foreach($allmycustomer as $allmycustomers){

   //echo $courserow->coursename;
   ?>
					<option  value="<?=  $allmycustomers->name;   ?>"><?php echo$allmycustomers->name;?></option>





	<?php

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

<select class="form-control2"name="transactionstatus" id="transactionstatus" >
		<option value="<?PHP echo $purchaseorder[0]['transactionstatus']; ?>" selected="selected" ><?PHP echo $purchaseorder[0]['transactionstatus']; ?></option>

	<option value=""  >---Select status---</option>


	<option value="open"  >Open</option>
	<option value="closed"  >Closed</option>


</select>						
			</br>	
				
		
		
		
		</br>Amount:
		
		
		
				<input type="text"  name="amount" readonly value="<?php echo set_value('amount',$purchaseorder[0]['amount']) ;?>" id="dob" class="form-control" required  placeholder="Please enter amount ">

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

	
  					<?php echo form_close();?>
					
		 </div>			
			  </div>		
			
				<div class="widget-content nopadding table_holder table-responsive"  >		
	
		
	
					
					
				
					<div class="table-responsive">
						<table id="register" class="table table-bordered " width="100%" >
						<thead>
							<tr>
								<th  colspan="4">Products:</th>
							
								
								<th colspan="3">Qty</th>
								<th> Vat</th>
																<th> Bal</th>

								
								
							</tr>
								<tr>
								<th colspan="6">
										<?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'); 

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

 	$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);
		  		  	      $changetaxstatus=$this->usermodel->populatuserpermissionsdataarray('sales','changetaxstatus',$userid);

      $invoicestatus=$this->usermodel->populateallarray('purchaseorder','invoice',$finalsalesid);
$myinvoice=$invoicestatus[0]["status"];
$smsconfig = $this->usermodel->populateallarray('smsconfig','id',$companyid);
		 	  $view=$smsconfig[0]['view'];	
			  		  		 	  $display1=$smsconfig[0]['display1'];	

  
                 echo form_open('user/addsalesorderdata' , 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="invoice" value="<?php echo set_value('invoice',$finalsalesid); ?>" class="form-control" required placeholder="Enter invoice">

			  		<input type="text" name="code" id="id" autofocus value="<?php echo set_value('code'); ?>" class="form-control" required placeholder="Enter code or name">

		 
								</th>
								
								
								
								
								
								
								
								
								
					
					
								
								
								
								<th>
								

								
		  		<input type="text" name="qty" id="qty" value="<?php echo set_value('qty','1'); ?>" class="form-control" required placeholder="Qty" >
								
								</th>
							
								<th>
								
			
				  
				  
				  
				  
				  <select class="form-control" name="vattype" >
	
			 <?php
				 if( $display1=="yes"){
					 ?>
						<option value="VATABLE" selected  >VATABLE</option>
 
					 <?php
				 }else{
					  ?>
					  				<option value="EXEMPTED"  selected >EXEMPTED</option>

					 <?php
				 }
					 ?>
							<option value="VATABLE"   >VATABLE</option>

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

	
</select>
		
				  
				  
				  
				  
				  

								</th>
								
								<th>Bal</th>
								<th colspan="4">

								
								<button type="submit"  value="sale" name="btn_addsale" class="btn btn-primary"> Click to add sales order   </button>

 
  					<?php echo form_close();?>
								
								</th>
								
							</tr>
								<tr>
								<th>Code</th>
								<th>Item Name</th>
								<th>Description</th>
	<th>Serials</th>
								<th>Allocated Qty</th>
								<th>S Price </th>
								<th>Sold qty</th>
								<th>Vat</th>

								<th>Balance</th>
								<th>Total</th>
								

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

			 }else{
 
 $totalcost=0;
  $finaltotal=0;
    $finaltotalEXACT=0;

  	foreach ($viewreceivings as $row){
		
	
 $itemid=$row->code;
  $myid=$row->id;
   $productid=$row->id;
		 		$recaiving= $this->usermodel->populateall('products', 'code',$itemid);
				
			
 if(is_array($recaiving)){
	 
	 foreach ($recaiving as $c){
 
   $c->code;

             ?>
				                    <tbody >
									
										 
										<?php
					
		
                 echo form_open('user/updatesalesorder' , 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="finalsalesid" id="finalsalesid" value="<?php echo set_value('finalsalesid',$finalsalesid); ?>" class="form-control" required placeholder="finalsalesid" >
		

			<tr>
			 <td><?php ; 
				//echo$c->invoice;										
   $customer=$c->code;
   if($customer!=""){
	  
      $productname = $this->usermodel->populateallarray('products','code',$itemid);
  
?>
 <a class="btn primary editbtn" id="editbtn"data-tax_included='<?php echo  $productname[0]['tax_included'];?>' data-expdate='<?php echo  $productname[0]['expdate'];?>'data-store='<?php echo  $productname[0]['store'];?>' 	 data-orderamount='<?php echo  $productname[0]['orderamount'];?>' data-supplier='<?php echo  $productname[0]['supplier'];?>'  data-category='<?php echo  $productname[0]['category'];?>'  data-buyingprice='<?php echo  $productname[0]['buyingprice'];?>' data-sellingprice='<?php echo  $productname[0]['sellingprice'];?>'data-promoprice='<?php echo  $productname[0]['promoprice'];?>'  data-wholesaleprice='<?php echo  $productname[0]['wholesaleprice'];?>' data-code='<?php echo  $productname[0]['code'];?>' data-qty='<?php echo  $productname[0]['qty'];?>'	data-description='<?php echo  $productname[0]['description'];?>' data-name='<?php echo  $productname[0]['name'];?>'	data-reorderevel='<?php echo  $productname[0]['reorderevel'];?>'  data-id='<?php echo  $productname[0]['id'];?>' data-toggle='modal' data-target='#editProductModel'> <?php echo $productname[0]['code'] ; ?> </a>	 

<?php
	
   }else{
	    echo "No Product";  
   }

  
  ?></td>
  								
													    <td><?php ; 
						 $receiptdescription=$configuration[0]['receiptdescription'];
									
   $customer=$c->code;
   if($customer!=""){
	  
     // $productname = $this->usermodel->geteproductbyid($customer);
  
     echo "<b>";
     echo$name=$productname[0]['name']; if($receiptdescription=="yes"){ echo"-".$description=$productname[0]['description'];}
	 
	 
	  echo "</b>";

	
   }else{
	    echo "No Product";  
   }

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


</td>				
	<td>
  <input type="text" name="serial" value="<?php echo set_value('serial',$row->serial); ?>" class="form-control"  placeholder="Enter serial No" >

  </td>											
													<td>
												<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',$row->id); ?>" class="form-control" required placeholder="itemid" >
							<input type="hidden" name="view" value="user/viewnewsalesorder?randomitemidentifier=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">
	<input type="hidden" name="oldamount" id="oldamount" value="<?php echo set_value('oldamount',$row->amount); ?>" class="form-control" required placeholder="myid" >

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

																						<input type="hidden" name="branch" id="branch" value="<?php echo set_value('myid',$row->branch); ?>" class="form-control" required placeholder="branch" >
																						<input type="hidden" name="code" id="code" value="<?php echo set_value('code',$row->code); ?>" class="form-control" required placeholder="code" >

											
																			<?php	

if(($updateclosedinvoiceaction==false) && ($myinvoice=="closed")){
  	?>

	<?php
 echo $row->sales;
}else{
	?>
			
					<input type="text" name="sales" id="sales" value="<?php echo set_value('sales',$row->sales); ?>" class="form-control" required placeholder="sold qty" >
					
	
		<?php
}
	?>	
											
											
											
											
											
											
											
											
											
											
											
</td>
									

<td>
											 
											 
											 
																	
														<?php

	if(($updateclosedinvoiceaction==false) && ($myinvoice=="closed")){
	echo $c->sprice;
	}
 else if(($updatesellingpriceaction==true) && ($myinvoice!="closed")){
	 ?>

					<input type="text" name="sellingprice" id="sellingprice" value="<?php echo set_value('sellingprice',$row->sprice); ?>" class="form-control" required placeholder="selling price" >

	 	<?php	

 } else if(($updateclosedinvoiceaction==true) && ($updatesellingpriceaction==true)){
  ?>

					<input type="text" name="sellingprice" id="sellingprice" value="<?php echo set_value('sellingprice',$row->sprice); ?>" class="form-control" required placeholder="selling price" >

	 	<?php	
 
 } else{
	echo $row->sprice;
 }
 
 
 
  ?>						 

											 </td>
											 









									<td>
																										
														<?php

	if(($updateclosedinvoiceaction==false) && ($myinvoice=="closed")){
	echo $c->sprice;
	}
 else if(($updatesellingpriceaction==true) && ($myinvoice!="closed")){
	if(($confirminvoice)) {
		  ?>
		
	<input type="text" name="qty" readonly id="qty" value="<?php echo set_value('qty',$row->qty); ?>" class="form-control" required placeholder="Qty" >

	  
	 	<?php	
	  }else{

echo $row->qty;

	 
	  
	  
	  
	  }



	 	

 } else if(($updateclosedinvoiceaction==true) && ($updatesellingpriceaction==true)){
	 
	  if(($confirminvoice)) {
		  ?>
		
	<input type="text" readonly name="qty" id="qty" value="<?php echo set_value('qty',$row->qty); ?>" class="form-control" required placeholder="Qty" >

	  
	 	<?php	
	  }else{

echo $row->qty;

	 
	  
	  
	  
	  }
	 


  
  

 
 } else{
	echo $row->qty;
 }
  ?>						 

													
												
													</td>
										 	 
											 <td>
											  <select class="form-control1" onchange="selectvat()" id="vattype" name="vattype"  >
			<option selected="selected" value="<?php echo $row->vattype; ?>"  ><?php echo $row->vattype;?></option>

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

			<option value="ZERO RATED"  >ZERO RATED</option>
				<option value="EXEMPTED"  >EXEMPTED</option>
		
</select>
											 </td>
											 
											 
									 <td><?php 
												
												echo $balance=(($row->sales-$row->qty)) ;
												 ?></td>			 
											 
											 
											 
											 	 <td><?php 
												
												echo $totalcost=(($row->amount)) ;
												 $finaltotal=$finaltotal+$totalcost;
												 $finaltotalEXACT= $finaltotalEXACT+($row->qty*$row->sprice);
												 ?></td>
				  
												  
											  
											  
											  
											  
											  
											  
											  
												 	<td  style='color:green'> 
				<?php

	
 if( $deleteaction==true){
	 ?>
		                              <a  id="more" class="btn btn-danger" href="<?php echo base_url();?>user/deletedata?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&itemid=<?php   {echo  $row->id;}  ?>&view=user/viewnewsalesorder?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&deltetable=sales_order&maintable=purchaseorder&fieldname=amount"> <span class="glyphicon glyphicon-trash"></span> </a>

	 
	 	<?php	

 }else{
	
 }
  ?>
		                              </td> 
									  
									  
									  
 <td>
									  
									  
																		<?php

	if(($updateclosedinvoiceaction==false) && ($myinvoice=="closed")){

	}
 else if(($updateaction==true) && ($myinvoice!="closed")){
	 ?>

<button type="submit"  value="editorder" name="btn_editorder" class="btn btn-primary"><?php   if(($confirminvoice)) {echo  "Update";}else{ echo  "Update";} ?>   </button>

	 	<?php	

 } else if(($updateclosedinvoiceaction==true) && ($updateaction==true)){
  ?>

<button type="submit"  value="editorder" name="btn_editorder" class="btn btn-primary"> <span class="glyphicon glyphicon-pencil"><?php   if(($confirminvoice)) {echo  "Update";}else{ echo  "Update";} ?></button>

	 	<?php	
 
 } else{

	}
  ?>						  
 </td>
 <?php echo form_close();?>	
  					


 </tr>
 <?php 
	 }?>
				<?php }?>							
	<?php }} ?>

              <?php ?>	

							
								<tr>
									<th colspan="3"></b>Ref Number:	</b><?php echo$finalsalesid?>   : 
							
																				<?php   if(($confirminvoice)) {?>
																							 								<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>user/delivergoods?invoice=<?php   {echo  $finalsalesid;}  ?>"> Deliver Products</a>

																				
																				<?php }else{ ?>
																				
																				<span style="color:red"> Click on Process Invoice/Cash Delivery First for you to enable deliver goods button</span>
																				<?php
																				} ?>


								
								</th>
								<th colspan="2"> <h3>Exp TT :<?php if(isset($finaltotal)) {echo formatMoney($finaltotal, true); }?></h3>
							</th>
								<th colspan="2"><h3>Exact Total:<?php if(isset($finaltotalEXACT)) {echo formatMoney($finaltotalEXACT, true); }?></h3>
							</th>
								<th colspan="3"><h3>Balance:<?php if(isset($finaltotal)) {echo formatMoney(($finaltotal-$finaltotalEXACT), true); }?></h3>
							</th>
							</tr>
				
									</tbody>
									
									
					</table>
					<table id="register" class="table table-bordered " width="100%" >

						
						<?php
								 if(!is_array($batch)) {
	

								}else{
									?>
										<tr>
								<th colspan="6">GOODS DELIVERED HISTORY(BATCHES)</th>
								
									
								</tr>
								<tr>
								<th>Delivery </br>/Batch No</th>
								
								<th>Qty delivered</th>
							<th>TT Amount</th>

								<th>Date</th>
								<th> User</th>
								<th>View</th>
									
								</tr>
<?php
$ttamount=0;
$ttqy=0;
  	foreach ($batch as $myrow){
		$myinvoice= $myrow->invoice ;
				$batchid= $myrow->batchid ;

		?>
		<tr>
		
		<td><?php

		echo$myrow->id; ?>


		</td>
		
		 <td><?php  $ordernumber=$myrow->batchid ; 
	   
	   $totalexpense=$this->usermodel->populateallexpensebyno("orderlist","qty", "batchid",$ordernumber);
	   echo $qty= $totalexpense[0]["qty"];
	   $ttqy= $ttqy+$qty;
	   
	   
	   
	   
	   ?></td>
		
			 <td><?php  $ordernumber=$myrow->batchid ; 
	   
	   $totalexpense=$this->usermodel->populateallexpensebyno("orderlist","amount", "batchid",$ordernumber);
	    $amount= $totalexpense[0]["amount"];
	   if(isset($amount)) {echo formatMoney($amount, true); }
	   $ttamount=$ttamount+$amount;
	   
	   
	   
	   ?></td>
		
			
						<td><?php	echo$myrow->exactime; ?>	</td>	
				

						
 <td><?php  $userids= $myrow->userid ;

$myuser=$this->usermodel->geteuser($userids);
   echo $myname=$myuser[0]['firstname'];

  ?></td> 
		<td>

			 <a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printdeliverysingle?invoice=<?php   if(isset($myinvoice)) {echo $myinvoice; } ?>&batchid=<?php   if(isset($batchid)) {echo $batchid; } ?>">  Print Delivery Note    </a>

		
		
		
		</td>		
		
		</tr>
	<?php	
	}
	
}
		?>
				<tr>
									<th></b>Total	</b></th>
							
									

									<th><h3><?php if(isset($ttqy)) {echo formatMoney($ttqy); }?></h3></th>

								
	<th colspan="2"><h3>Total Amount:<?php if(isset($ttamount)) {echo formatMoney($ttamount, true); }?></h3></th>
							
							</tr>
							
	
							</table>
				</div>	
			</div>			
					
					
					
					
					
					
					
					
					
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

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

 
</div>


















