<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(); -->

        });
        </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);
 $weight="";

  
  ?>
		<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 Delivery  </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/viewparceldelivery" 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/addparceldelivery' , 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/editparceldelivery?randomitemidentifier=<?php echo $purchaseorder[0]['invoice']; ?>" 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="mycategoryid" value="<?php echo set_value('id',$purchaseorder[0]['id']); ?>" class="form-control" required placeholder="Enter invoiceno">

 	
		
	 
		
		
	
  	
		<div class="form-group">
    <label for="inputstatus" class="col-sm-2 control-label">	Delivery status </label>
    <div class="col-sm-4">
	
	
	

	<select class="form-control" name="status" required>
	
	<option value=""  >--Delivery Status--</option>
			<option   selected="selected" value="<?php echo set_value('status',$purchaseorder[0]['status']); ?>" selected="selected" ><?php echo $purchaseorder[0]['status']; ?></option>

<option value="Booked"     >Booked</option>

		<option value="Dispatched"      >Dispatched</option>


			<option value="Undispatched"   >Undispatched</option>


			<option value="Failed Delivery"   >Failed Delivery</option>

		<option value="Returned and Received"  >Returned and Received</option>
		<option value="Returned"  >Returned</option>


 		<option value="Delivered"  >Delivered</option>




</select>
	
		 
				
		<span class="text-danger"> <?php echo form_error('mode'); ?>
		
		</span>
	</div>
  </div>
  
  
 
  
  
  
  <div class="form-group">
    <label for="inputid" class="col-sm-2 control-label">Delivery  No: </label>
    <div class="col-sm-4">
	
		  		<input type="text" readonly name="id" value="<?php echo set_value('id',$purchaseorder[0]['id']); ?>" class="form-control2" required placeholder="Enter  quotation number ">
		 
			
	Payment Mode?
	
	
		<select class="form-control" name="mode" required>
			<option selected="selected" value="<?php echo set_value('mode',$purchaseorder[0]['mode']); ?>" selected="selected" ><?php echo $purchaseorder[0]['mode']; ?></option>

	<option value=""  >---Select Payment mode---</option>
	<option value="COD"  > C.O.D (Cash On Delivery)</option>
	<option value="Prepaid"  >Prepaid</option>



</select>
	

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

		
		
				
			  <div class="form-group">
    <label for="inputdateposted" class="col-sm-2 control-label">Delivery Date </label>
    <div class="col-sm-4">

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

	<input type="text" name="invoice" value="<?php echo set_value('invoice',$purchaseorder[0]['invoice']); ?>"id="canceldate" class="form-control" required placeholder="Enter invoice No ">
			<span class="text-danger"> <?php echo form_error('invoice'); ?>
		
		</span>
	</div>
  </div>		
		
		   </div>
	
		<div class="col-md-12">			
			  <div class="form-group">
    <label for="inputduedate" class="col-sm-2 control-label">Due date </label>
    <div class="col-sm-4">
<input type="text" readonly name="duedate" value="<?php echo set_value('duedate',$purchaseorder[0]['duedate']); ?>" class="form-control" required placeholder="Enter due date.">
		
		</span>
	</div>
  </div>		
		
		
		
		
		
		
	 <div class="form-group">
    <label for="inputincharge" class="col-sm-2 control-label">	Customer details: </label>
    <div class="col-sm-4">
	
				<input type="text"   name="incharge" value="<?php echo set_value('incharge',$purchaseorder[0]['customer']) ;?>" id="details" class="form-control" required  placeholder="customer name">

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

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

				
		</span>
	</div>
  </div>
			
  	 
			 <div class="form-group">
    <label for="inputdetails" class="col-sm-2 control-label">Note/Message</label>
    <div class="col-sm-4">
				<input type="text"   name="details" value="<?php echo set_value('details',$purchaseorder[0]['details']) ;?>" id="details" class="form-control" required  placeholder="Bussines/comments/note ">

			
	</div>
  </div>
				 
  	

				</div>

	
  	<div class="col-md-12">					
				
			 <div class="form-group">
    <label for="inputriderdetails" class="col-sm-2 control-label">Rider Details</label>
    <div class="col-sm-4">
				<input type="text"   name="riderdetails" value="<?php echo set_value('riderdetails',$purchaseorder[0]['riderdetails']) ;?>" id="details" class="form-control"   placeholder="Rider Details ">

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

    <div class="col-sm-4">
	         <button type="submit"  value="delivery" name="btn_parceldelivery" class="btn btn-primary"> Update</button>


  				 <a  id="non-printable"  class="btn btn-info" href="<?php echo base_url();?>user/printparcelitem?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&view=user/viewparceldelivery&customer=<?php   if(isset($purchaseorder[0]['incharge'])) {echo $purchaseorder[0]['incharge']; } ?>"> Print   Receipt</a>
  				  				 <a  id="non-printable"  class="btn btn-info" href="<?php echo base_url();?>user/printparcelitemdelivery?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&view=user/viewparceldelivery&customer=<?php   if(isset($purchaseorder[0]['incharge'])) {echo $purchaseorder[0]['incharge']; } ?>"> Print   Delivery</a>

				<a  id="non-printable"  class="btn btn-info" href="<?php echo base_url();?>user/printparceliteminvoice?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&view=user/viewparceldelivery&customer=<?php   if(isset($purchaseorder[0]['incharge'])) {echo $purchaseorder[0]['incharge']; } ?>"> Print   Delivery invoice</a>

    </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="6">Receivings:</th>
							
								
								<th>Qty</th>
								<th> </th>
								
								
							</tr>
								<tr>
								<th colspan="4">
										<?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('purchaseorder','invoice',$finalsalesid);
$myinvoice=$invoicestatus[0]["status"];
  
   echo $this->session->flashdata('productmsg'); 
                 echo form_open('user/addquotation' , 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">

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

								</th>
								
								
								
								
								
								
								
								
								
					
					
								
								
								
								<th>
								

								
		  		<input type="text" name="qty" id="qty" value="<?php echo set_value('qty','1'); ?>" class="form-control" required placeholder="Qty" >
								
								</th>
							
								
								<th colspan="2">

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

 
  					<?php echo form_close();?>
								
								</th>
								
							</tr>
								<tr>
								<th>Code</th>
								<th>Item Name</th>
<?php
if($weight=="Yes"){
 ?>
		
										<th>Unit</th>
											<th>TT Weight</th>
											
											
<?php
}
 ?>
	
								<th>Qty</th>
								<th>S Price</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;
  	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/editquotation' , 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>
			 <td>
			 		 									<input type="hidden" name="view" value="user/editparceldelivery?randomitemidentifier=<?php echo $purchaseorder[0]['invoice']; ?>" class="form-control" required placeholder="Enter invoiceno">

			 <?php ; 
														
   $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";  
   }

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

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

  
  </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";  
   }

if($uom=$productname[0]['uom']!=""){
	
echo "  (".$uom=$productname[0]['uom'].")";
	
}
		




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


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

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

  </td>
  	
								
											
<?php
}else{
	?>
	
	
	
    											<input type="hidden" name="unit"  value="<?php echo set_value('unit',$row->unit); ?>" class="form-control"  placeholder="Enter weight unit" >


  

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

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

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

											
											
																			<?php	

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

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

	if(($updateclosedinvoiceaction==false) && ($myinvoice=="closed")){
	echo $row->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 $c->sellingprice;
 }
  ?>						 

											 </td>
											 
											 
											 
											 
											 
											 
											 
											 
											 	 <td><?php 
												
												echo $totalcost=(($row->qty)*($row->sprice)) ;
												 $finaltotal=$finaltotal+$totalcost;
												 ?></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 $row->id;}  ?>&view=user/editlease?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&deltetable=purchaseorderlist&maintable=quotation"> <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="myedit" name="btn_editreceivedproduct" class="btn btn-primary"> <span class="glyphicon glyphicon-pencil"></span> </a>   </button>

	 	<?php	

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

<button type="submit"  value="myedit" name="btn_editreceivedproduct" class="btn btn-primary"> <span class="glyphicon glyphicon-pencil"></span> </a>   </button>

	 	<?php	
 
 } else{

	}
  ?>						  

 <?php echo form_close();?>	
  					

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

              <?php ?>	

								<tr>
									<th colspan="4"></b>Invoice Number:	</b><?php echo$finalsalesid?>   : 
							
				
								
								</th>
								<th colspan="4"><h3>Total:<?php if(isset($finaltotal)) {echo formatMoney($finaltotal, true); }?></h3>
							</th>
							
							</tr>
				
									</tbody>
									
									
					</table>
				</div>	
			</div>			
					
					
					
					
					
					
					
					
					
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

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

 
</div>


















