<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>
	   	<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/allinvoices";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/allinvoices";

		    // document.body.innerHTML = originalContents;

	}
}




	$(document).on("click", "#invocebtn", function()
        {
          var phone = $(this).data('phone');
		  $("#phone1").val(phone); 
		
		   		   
   var message = $(this).data('message');
		   $("#message1").val(message);
 

		  
		   
        });
		
	</script>
  <style type="text/css">
  
  

    #myprint { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;
  
    width:100%; 


}

#sale{  	


    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
		    	#myprint { display: block; font-size:16; width:100%; }

    }
    </style>
 
 <div class="row">
  
   	

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

  <?php
  $confirminvoice=false;
  
 $deliverydate= $purchaseorder[0]['deliverydate'];
  
  
  if( $deliverydate==""){
	  
	   $confirminvoice=false;
	  
  }else{
	   $confirminvoice=true;
	  
  }

 
				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);
	   $priceaction=$this->usermodel->populatuserpermissionsdataarray('products','price',$userid);
$smsconfig = $this->usermodel->populateallarray('smsconfig','id',$companyid);
		 	  $view=$smsconfig[0]['view'];	
			  		  		 	  $display1=$smsconfig[0]['display1'];	
								  
				   $people=$this->usermodel->populateallarray('people','id', $purchaseorder[0]['supplier']);
							  $phone=$people[0]['phone'];
							  
							  $salesid=$purchaseorder[0]['invoice'];
							  	$receiptlink= base_url()."printlpo?invoice=".$salesid;
								$receiptemessage="Hello, this is to inform you that your L.P.O has been generated. Thank you for showing interest. We are Looking for forward to doing business with you. Click here to download/Print the L.P.O: ".$receiptlink."";
				  
								  
  
  ?>
		<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 Purchase Order  </span>
	  
				 	  				 <a href="<?php echo base_url();?>user/allpurchaseorder" class="btn btn-info"> Back </a>

				 	 <div class="pull-right"  >
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-default"  name="print"onclick="printDiv('sortable_table')" value="print receipt!" />

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


	<a  id="more" class="btn btn-success"  target="_blank" href="https://api.whatsapp.com/send?phone=<?php echo  $phone;?>&text=<?php echo  $receiptemessage;?>&source=&data=&app_absent="> Whatsapp LPO </a>
	<a class="btn btn-warning invocebtn" id="invocebtn" data-phone='<?php echo  $phone;?>'   data-message='<?php echo  $receiptemessage;?>'  data-id='<?php echo  $salesid;?>' data-toggle='modal' data-target='#addinvoicesmsModal'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Send LPO through  sms
                                                </a>
	<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/viewnewpurchaseorder?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="p.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="branchto" value="<?php echo set_value('branchto',$purchaseorder[0]['branchto']); ?>" class="form-control" required placeholder="Enter branchto">

 	<div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier ?</label>
    <div class="col-sm-4">
		
	
		<select class="form-control" required 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){

   //echo $courserow->coursename;
   ?>
					<option value="<?=  $mycustomerrow->id;   ?>"><?=  $mycustomerrow->company ; ?></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">
	
	
	
	
	 		
		<select class="form-control"name="orderedby" id="orderedby" >
	
	<option value=""  >---Select approver of the request---</option>


   <?php
 $orderedby1= $purchaseorder[0]['orderedby'];
 		$mysupplier1= $this->usermodel->populateall('people','id',$orderedby1);



if(is_array($mysupplier1)) {

   foreach($mysupplier1 as $mysupplierrow){
    ?>
					<option selected="selected" value="<?=  $mysupplierrow->id;   ?>"><?php echo $mysupplierrow->firstname." ".$mysupplierrow->surname;?></option>

   
    <?php

}} else {
 ?>

		<?php 
}


				///$mycustomer  = $this->usermodel->populatealldatanoarrayorderby('people','firstname',"asc",'status', 1,'category', 'user');
											$mycustomer = $this->usermodel->populatealldatanoarraythree('people', 'companyid',$companyid,'status',1,'category','user');

					 
	     // $mycustomer=$this->usermodel->populatealldatawhere('products','bulk',$userid);


if(is_array($mycustomer)) {

   foreach($mycustomer as $mycustomerrow){

   //echo $courserow->coursename;
   ?>

					<option  value="<?=  $mycustomerrow->id;   ?>"><?php echo $mycustomerrow->firstname." ".$mysupplierrow->surname;?></option>



	<?php

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

	
		 
				
		<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">P.Order Date </label>
    <div class="col-sm-4">

	<input type="text" name="orderdate" value="<?php echo set_value('orderdate',$purchaseorder[0]['fromdate']); ?>"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 Cancel Date </label>
    <div class="col-sm-4">

	<input type="text" name="canceldate" value="<?php echo set_value('canceldate',$purchaseorder[0]['paiddate']); ?>"id="canceldate" class="form-control"  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">P.Order  No: <?php echo set_value('id',$purchaseorder[0]['id']); ?></label>
    <div class="col-sm-4">
	
		 <b>	Ref / Invoice No.</b><input type="text"  name="ordernumber" value="<?php echo set_value('ordernumber',$purchaseorder[0]['ordernumber']); ?>" class="form-control" required placeholder="Enter  invoice 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="inputcanceldate" class="col-sm-2 control-label">Delivery  Date </label>
    <div class="col-sm-4">

	
<?php   if(($confirminvoice)) {
	 ?>
	<input type="text" name="deliverydate" value="<?php echo set_value('deliverydate',$purchaseorder[0]['deliverydate']); ?>"id="canceldate" class="form-control"  placeholder="Enter cancel order date  (dd-mm-YYY) ">

	 <?php
	
	 }else{
		 
		 ?>
		 	<input type="text" readonly name="deliverydate" value="<?php echo set_value('deliverydate',$purchaseorder[0]['deliverydate']); ?>"id="canceldate" class="form-control"  placeholder="Enter cancel order date  (dd-mm-YYY) ">

		 <?php
		
		 }

 ?>
	
	
	
	
	
	
			<span class="text-danger"> <?php echo form_error('deliverydate'); ?>
		
		</span>
	</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',$purchaseorder[0]['amount']) ;?>" id="dob" class="form-control" required  placeholder="Please enter amount ">

				
		</span>
	</div>
  </div>
				 
  	  	<div class="col-md-12">					
		<div class="form-group">
 
 

    <div class="col-sm-6">
	<?PHP
	 $APPROVALSTATUS=$purchaseorder[0]['approvalstatus'] ;
    if($APPROVALSTATUS=="Temporary Approved") {
		
		?>
		<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printpurchaseordernoprice?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>">  Print LPO Request  </a>

		
			<?PHP
	}
		  if($APPROVALSTATUS=="Approved") {
		
		?>
<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printpurchaseorder?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&type=lpo">  Print LPO    </a>
<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printpurchaseorder?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&type=oversees">  Print Oversees PO    </a>

<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printpurchaseordernoprice?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>">  Print LPO( No Price)   </a>

	  <button type="submit"  name="btn_receivegoods"  value="receivedelivery"  class="btn btn-success"> <?php   if(($confirminvoice)) {echo  "Update  Receivings";}else{ echo  "Start Receiving Goods";} ?></button>
		 	         <button type="submit"  name="btn_purchaseorder"  value="purchaseorder"  class="btn btn-primary"> Update LPO </button>
	<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/printgrn?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&type=receiving">  Print GRN   </a>




<?php   if(($confirminvoice)) {
	 ?>


	 <?php
	
	 }else{
		 
		 ?>

		 <?php
		
		 }
	}else{
		
	 ?>
		 	         <button type="submit"  name="btn_purchaseorder"  value="purchaseorder"  class="btn btn-primary"> Update purchase order </button>

		 <?php
		
	
	
	}

 ?>
 
 
    </div>
	<br>
	   <label for="inputcontroller" class="col-sm-2 control-label"> Approver   </label>
	   
    <div class="col-sm-4">
	   		
		<select class="form-control"name="controller" id="controller" >
	
	<option value=""  >---Select approver of the request---</option>


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



if(is_array($mysupplier)) {

   foreach($mysupplier as $mysupplierrow){
    ?>
					<option selected="selected" value="<?=  $mysupplierrow->id;   ?>"><?php echo $mysupplierrow->firstname." ".$mysupplierrow->surname;?></option>

   
    <?php

}} else {
 ?>

		<?php 
}
											$mycustomer = $this->usermodel->populatealldatanoarraythree('people', 'companyid',$companyid,'status',1,'category','user');


					//$mycustomer  = $this->usermodel->populatealldatanoarrayorderby('people','firstname',"asc",'status', 1,'category', 'user');

					 
			//$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;   ?>"><?php echo $mycustomerrow->firstname." ".$mysupplierrow->surname;?></option>



	<?php

}} else {
    echo 'No supplier available.';
}
	
?>
</select>		
						<b style="color:blue">
						<?php echo "Approval status: ".$purchaseorder[0]['approvalstatus'] ;?>
	</b>
	   
	   </div>
	   
	   
	   
  </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 " id="sortable_table" width="100%" >
						<thead>
							<tr>
								<th  colspan="6">Select Products:</th>
							
								
								<th>Ordered Qty</th>
								<th> </th>
								
									<th> </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);

$addbatchno=$this->usermodel->populatuserpermissionsdataarray('purchases','addbatchno',$userid);
	   $addexpirydate=$this->usermodel->populatuserpermissionsdataarray('purchases','addexpirydate',$userid);




      $invoicestatus=$this->usermodel->populateallarray('purchaseorder','invoice',$finalsalesid);
$myinvoice=$invoicestatus[0]["status"];
  
   echo $this->session->flashdata('productmsg'); 
                 echo form_open('user/addpurchaseorderdata' , 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 colspan="4">

								
								
									
					  
				  <select class="form-control2" name="tax" >
	
			 <?php
				 if( $display1=="yes"){
					 ?>
						<option value="VATABLE" >VATABLE</option>
 						<option value="pick" selected  > Pick Vat From Database</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>
															  
																		<?php

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

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

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

	 	<?php	

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

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

	 	<?php	
 
 } else{

	}
  ?>	
								
								
							
					
								
								
								
								
								

 
  					<?php echo form_close();?>
								
								</th>
								
							</tr>
								<tr>
								<th>Code</th>
								<th>Item Name</th>
								
								<th>Ordered Qty</th>
								<th>B Price </th>
								<th>Qty Received</th>
									<th>Bal</th>
									<th>To?</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->	item_id;
  $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
					
		$batchno = $userid.time();
                 echo form_open('user/updatepurchaseorder' , 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><?php ; 
				   $enddate=$row->enddate;
										
   $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";  
   }

  
  ?>
  
    	<textarea name="description" class="form-control" placeholder="Item description"><?php echo set_value('description',$row->description); ?></textarea> 

  
		 	 <?php
				 if( $addexpirydate==true){
					 ?>
				  	<input type="date" name="enddate" id="enddate" value="<?php if($enddate==""){echo "";}else{ echo set_value('enddate',date("Y-m-d", strtotime($enddate)));} ?>" class="form-control"  placeholder="Expiry date" >
	 
					 
						<?php
				 }else{
						 ?>
  	<input type="hidden" name="enddate" id="enddate" value="<?php if($enddate==""){echo "";}else{ echo set_value('enddate',date("Y-m-d", strtotime($enddate)));} ?>" class="form-control"  placeholder="Expiry date" >

						 
					<?php	 
				 }
					 ?>
					 
					  <?php
				 if( $addbatchno==true){
					 ?>
					  	<input type="text" name="batchno" id="batchno" value="<?php echo set_value('batchno',$row->batchno); ?>" class="form-control"  placeholder="Batch No" >
 
					 
						<?php
				 }else{
						 ?>

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

  
  
  </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/viewnewpurchaseorder?randomitemidentifier=<?php echo $finalsalesid; ?>" class="form-control" required placeholder="Enter invoiceno">

											<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="batchno" id="batchno" value="<?php echo set_value('batchno',$batchno); ?>" class="form-control" required placeholder="btachno" >

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

											
																			<?php	

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

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














													<td>
													
													
														<?php

	if(($updateclosedinvoiceaction==false) && ($myinvoice=="Approved")){
		echo $row->buyingprice;
	}
 else if(($updatebuyingpriceaction==true) && ($myinvoice!="Approved")){
	 ?>

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

	 	<?php	

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

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

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

	
 if( $priceaction==true){
	 ?>
	 	 <a  id="more" target="_blank" class=" btn-info" href="<?php echo base_url();?>user/viewprice?randomitemidentifier=<?php   {echo  $c->code;}  ?>&page=<?php   {1;}  ?>">Price  </a>

	 	<?php	

 }else{
	
 }
  ?>


													
													</td>
													<td>
																										
														<?php


		
	  
	
	 
	  if(($confirminvoice)) {
		  ?>
		
	<input type="text" name="total" readonly id="total" value="<?php echo set_value('total',$row->total); ?>" class="form-control" required placeholder="Qty Received" >

	  
	 	<?php	
	  }else{

echo $row->total;

	 
	  
	  
	  
	  }
	 

  ?>						 

													
	</td>
			<td>
		


	 	<?php	
	
	 
	  if(($confirminvoice)) {
		echo $balance=(($row->qty)-($row->total)) ;	
	  }else{

	  
	  }
	
  ?>						 



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

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

			<option value="ZERO RATED"  >ZERO RATED</option>
				<option value="EXEMPTED"  >EXEMPTED</option>
		
</select>
		<?php
	$vat=$row->vat;
echo$vat;
							?>								 
											 


	 	<?php	
	
	 
	  if(($confirminvoice)) {
		  ?>
		
<select class="form-control2" name="to" required>
	
	<option value=""  >---Branch?---</option>
	<option value="Main"  >Main </option>

	
	<?php 
					 

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



if(is_array($branch)) {

   foreach($branch as $branchrow){

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



	<?php

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



	 
	  
	  
	  
	  }
	
  ?>						 











</td>				
											 
											 
											 
											 
											 
											 
											 
											 	 <td><?php 
												
												echo $totalcost=(($row->buyingprice)*($row->qty)) ;
												 $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/deletedata?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&itemid=<?php   {echo  $row->id;}  ?>&view=user/viewnewpurchaseorder?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&deltetable=newstock&maintable=purchaseorder&fieldname=amount"> <span class="glyphicon glyphicon-trash"></span> </a>

	 
	 	<?php	

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

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

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

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

	 	<?php	

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

<button type="submit"  value="myeditpurchase" name="btn_editpurchases" 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="6"></b>Ref Number:	</b><?php echo$finalsalesid?>   : 
							
							
									<?PHP
	
		  if($APPROVALSTATUS=="Approved") {
		
		?>
				
			 								<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>user/receivepurchases?invoice=<?php   {echo  $finalsalesid;}  ?>"> Receive Products</a>

	
	<?php	
	}
	?>
		
							
							
														  
						
							
							
							
							
							
							
									

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

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

								}else{
									?>
										<tr>
								<th colspan="5">GOODS RECEIVED HISTORY(BATCHES)</th>
								
									
								</tr>
								<tr>
								<th>Batch No</th>
								<th>Batch Ref No</th>
								
								<th>Date</th>
								<th> User</th>
								<th>View</th>
									
								</tr>
<?php
  	foreach ($batch as $myrow){
		$myinvoice= $myrow->invoice ;
				$batchid= $myrow->batchid ;

		?>
		<tr>
			<td><?php	echo$myrow->batchno; ?>	</td>	
		
				<td><?php	echo$myrow->batchid; ?>	</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-info" href="<?php echo base_url();?>user/printgrn?invoice=<?php   if(isset($purchaseorder[0]['invoice'])) {echo $purchaseorder[0]['invoice']; } ?>&type=receiving">  Print Main GRN   </a>

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

		
		
		
		</td>		
		
		</tr>
	<?php	
	}
	
}
		?>
				
				
		<?PHP
	
		  if($APPROVALSTATUS=="Approved") {
		
		?>
				
						<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>user/updatereceivedeals?randomitemidentifier=<?php   {echo  $finalsalesid;}  ?>&status=closed"> Complete/Close</a>

	
	<?php	
	}
	?>
			
				
		

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

    

				</div>

		</div>
	    </div>
    

						<div id="addinvoicesmsModal" 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 Sms</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addsalessms' , 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;?>
				  		
	<div class="form-group">
    <label for="inputcontact" class="col-sm-2 control-label">	Contact </label>
    <div class="col-sm-10">
								<input type="hidden" name="view" value="user/viewnewquotation?randomitemidentifier=<?php echo $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">

	
	<textarea name="contact" value="<?php echo set_value('contact'); ?>" id="phone1" class="form-control"  placeholder="Enter phone e.g  254712345678,254712345678"></textarea>

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

	

	<div class="form-group">
    <label for="inputmessage" class="col-sm-2 control-label">	Message</label>
    <div class="col-sm-10">
		
<textarea   maxlength="800" required name="message" id="message1" value="pos.robisearch.com/printinvoice?refnumber=11597205277" class="form-control" rows="3" cols="60" onFocus="countChars('textbox','char_count',0)" onKeyDown="countChars('textbox','char_count',0)" onKeyUp="countChars('textbox','char_count',0)"></textarea> <br />Characters:<span id="char_count"></span>

			
		
			
		<span class="char_count"> <?php echo form_error("message"); ?>
		
		</span>
	</div>
  </div>
		

	
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="sms" name="btn_addsms" class="btn btn-primary"> Send SMS   </button>

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

    

				</div>

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



			
			
		</div>
	    </div>
		
  

 
</div>


















