<?php 
 $cc=0;
      
 
if(isset($_POST["searchValue"]))

{

  $searchValue= $_POST['searchValue'];
            //CHECKING ENDS HERE

  require_once "labClass.php";
  
  $con = new labClass();
  
 $chkp= $con->getItemBySearch($searchValue); 
    
     
if ($chkp->rowCount()>0) {

  $chp=$chkp->fetchAll();
  ?>
  <table class="table"> 
   
<?php
 foreach ($chp as $key => $p) {
    $itemID=$p['itemID'];
      $cc++; 
     
        ?>
 <tr>
     <td colspan="5">
       <sup id="rdn<?php echo $cc;?>" class="text-danger" ></sup>
     </td>
   </tr> 
  <tr>
   <td colspan="5">
       <input type="hidden" name="itemD<?php echo $cc;?>" id="itemD<?php echo $cc;?>" value="<?php echo $p['itemID'];?>"/>
    <!--<div class="input-group">
    <span class="input-group-text">-->

       Item name:
       <input  style="color:blue; border:none; outline:none; caret-color:white; background:transparent; cursor:pointer; width:100%;" 
  value="<?php echo $p['iname'];?>" 
  onclick="var sdate =$('#sdate').val();var iname =$('#inam<?php echo $cc;?>').val();
         var itemID =$('#itemD<?php echo $cc;?>').val();
         var user =$('#user').val();
         var orderID =$('#orderID').val();  
         if(iname!=''&& orderID!='' && itemID!='' && user!='' ) { 
            $.post('createPorder.php',{sdate:sdate,iname:iname,itemID:itemID,orderID:orderID,user:user},function(data){
                $('#sss<?php echo $cc;?>').html(data).show();
            }); 
         } else {
            document.getElementById('sss<?php echo $cc;?>').innerHTML='Valide item detail required!..';
         }" 
>
<sup id="sss<?php echo $cc;?>"></sup>
         <textarea style="background-color:white; height:30px; width:95%; display:none;" disabled="true" name="inam<?php echo $cc;?>" id="inam<?php echo $cc;?>"><?php echo $p['iname'];?></textarea> 
  </td>
</tr>
<tr>
  <td>
    Stock:
  <input type="number" style="background-color:white;border-radius:12px; width:100%;" disabled="true" name="iQt<?php echo $cc;?>" id="iQt<?php echo $cc;?>"  value="<?php echo $p['iqty'];?>" />
  </td> 
  <td>
    Rate(P/Price):
    <input type="hidden" style="background-color:white;border-radius:12px; width:100%;"  name="isprice<?php echo $cc;?>" id="isprice<?php echo $cc;?>"  value="<?php echo $p['isprice'];?>" />
    <input type="number" style="background-color:white;border-radius:12px; width:100%;"  name="iprice<?php echo $cc;?>" id="iprice<?php echo $cc;?>"  value="<?php echo $p['ipprice'];?>" />
  </td>
  
     
   
  <td>
    Qty:
    <input type="number" style="background-color:white;border-radius:12px; width:100%;"  name="nQt<?php echo $cc;?>" id="nQt<?php echo $cc;?>" />
  </td>
  <td valign="bottom"> 
  <input type="submit" name="add<?php echo $cc;?>" id="add<?php echo $cc;?>" value="Add" id="submit" onclick="
    var iname=$('#inam<?php echo $cc;?>').val();
    //var no=0;
    var ch=0;
    no=$('#cc').val();
    //alert(no);
    for (var i = no; i > 0; i--){
        var itemN= document.getElementById('iname'+i).value;
        //alert(itemN);
        if(itemN==iname)
                     {
                   ch++;
                     }         
                    }
          if(ch==0){
          var sdate=$('#sdate').val(); var user=$('#user').val();isprice=$('#isprice<?php echo $cc;?>').val(); ipprice=$('#iprice<?php echo $cc;?>').val(); var iqty=$('#iQt<?php echo $cc;?>').val(); var nQty=$('#nQt<?php echo $cc;?>').val(); var orderID =$('#orderID').val(); var itemID =$('#itemD<?php echo $cc;?>').val();parseInt(nQty); if(orderID!=''&& itemID!=''&& sdate!=''&& isprice!='' && iname!=''&& user!='' && nQty!='' && ipprice!=''  && nQty > 0  ) {document.getElementById('nQt<?php echo $cc;?>').value=''; $.post('pharmptempProLPO.php',{orderID:orderID,user:user,itemID:itemID,nQty:nQty,isprice:isprice,ipprice:ipprice,iname:iname,sdate:sdate},function(data){$('#dR').html(data).show();});} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide item detail required!..';}
          }else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Item exist!..';}
        " />
  </td>
   
</tr> 
  <?php
}
$cc=0;
 
}
}
  ?>