<?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:
         <textarea style="background-color:white; height:30px; width:95%;" 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>
    W/price:
     <input type="hidden" style="background-color:white;border-radius:12px; width:100%;" disabled="true" name="iprice<?php echo $cc;?>" id="iprice<?php echo $cc;?>"  value="<?php echo $p['ipprice'];?>" />
    <input type="number" style="background-color:white;border-radius:12px; width:100%;" disabled="true" name="wsprice<?php echo $cc;?>" id="wsprice<?php echo $cc;?>"  value="<?php echo $p['wsprice'];?>" />   
  </td>
  <td>
    S/price:
   <input type="number" style="background-color:white;border-radius:12px; width:100%;"  name="sprice<?php echo $cc;?>" id="sprice<?php echo $cc;?>"  value="<?php echo $p['isprice'];?>" />  
  </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=$('#sprice<?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();var tQty=0; tQty=parseInt(iqty) - parseInt(nQty); if(orderID!=''&& itemID!=''&& sdate!=''&& isprice!='' && iname!=''&& user!='' && nQty!='' && ipprice!='' && iqty!='' && nQty > 0 && tQty >= 0 && (nQty <= parseInt(iqty)) ) {document.getElementById('iQt<?php echo $cc;?>').value=tQty;document.getElementById('nQt<?php echo $cc;?>').value=''; $.post('phrmtemporderPro.php',{orderID:orderID,user:user,itemID:itemID,tQty:tQty,nQty:nQty,isprice:isprice,ipprice:ipprice,iname:iname,sdate:sdate},function(data){$('#dR').html(data).show();});alert(iqty+':'+nQty);} 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;
 
}
}
  ?>