<?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"> 
  <th>
        <small><h6>S/N</h6></small>
      </th>

      <th>
        <small><h6>ITEM NAME</h6></small>
      </th>
       <th>
        <small><h6>STOCK</h6></small>
      </th>
      
      <th>
        <small><h6>P. PRICE</h6></small>
      </th>
      <th>
        <small><h6>W. PRICE</h6></small>
      </th>
      <th>
        <small><h6>S. PRICE</h6></small>
      </th>

       <th>
        <small><h6>S/T QTY</h6></small>
      </th>
        <th>
        <small><h6>SELL</h6></small>
       
      </th>
        <th>
        <small><h6>TRANS</h6></small>
       
      </th>
       
<?php
 foreach ($chp as $key => $p) {
    $itemID=$p['itemID'];
      $cc++; 
      $iname=$p['iname'];
     
    $r= $con->getThisStoreItem($iname)->fetch(); 
        ?>
 <tr>
     <td colspan="8">
       <sup id="rdn<?php echo $cc;?>" class="text-danger" ></sup>
     </td>
   </tr> 
  <tr>
   <td width="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">-->

      <?php
          echo $cc;
       ?>  
      </td>
       <td width="40%">
         <textarea style="background-color:white; height:30px; width:100%;" disabled="true" name="inam<?php echo $cc;?>" id="inam<?php echo $cc;?>"><?php echo $p['iname'];?></textarea> 
  </td>
  <td width="8%"> 
     <?php echo "Store:". $r['iqty'];?>
  <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>
    <input type="number" 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'];?>" />   
  </td>
   <td>
   <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>
   <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>
    <input type="number" style="background-color:white;border-radius:12px; width:100%;"  name="nQt<?php echo $cc;?>" id="nQt<?php echo $cc;?>" />
  </td>
  <td> 
        <input type="submit" name="add<?php echo $cc;?>" id="add<?php echo $cc;?>" value="Sell" id="submit" onclick=" const now = new Date(); var hours = now.getHours();const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0');const ampm = hours >= 12 ? 'PM' : 'AM';
          var tim = `${hours}:${minutes}:${seconds} ${ampm}`;  var sdate=$('#sdate').val(); var user=$('#user').val();isprice=$('#sprice<?php echo $cc;?>').val(); var iname=$('#inam<?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 pOpt =$('#pOpt').val(); var itemID =$('#itemD<?php echo $cc;?>').val();var tQty=0; tQty=parseInt(iqty)-parseInt(nQty); if(itemID!=''&& sdate!=''&& isprice!='' && pOpt!=''&& iname!=''&& user!='' && nQty!=''  && tim!='' && ipprice!='' && iqty!='' && parseInt(nQty) <= parseInt(iqty) && parseInt(nQty) > 0) {document.getElementById('iQt<?php echo $cc;?>').value=tQty;document.getElementById('nQt<?php echo $cc;?>').value=''; $.post('pharItemSeachFsPro.php',{user:user,itemID:itemID,tQty:tQty,pOpt:pOpt,nQty:nQty,tim:tim,isprice:isprice,ipprice:ipprice,iname:iname,sdate:sdate},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide item detail required!..';}" />
  </td>
   <td> 
        <input type="submit" name="trans<?php echo $cc;?>" id="trans<?php echo $cc;?>" value="T Store" id="submit" onclick=" const now = new Date(); var hours = now.getHours();const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0');const ampm = hours >= 12 ? 'PM' : 'AM';
          var tim = `${hours}:${minutes}:${seconds} ${ampm}`;  var sdate=$('#sdate').val(); var user=$('#user').val();isprice=$('#sprice<?php echo $cc;?>').val(); var iname=$('#inam<?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 pOpt =$('#pOpt').val(); var itemID =$('#itemD<?php echo $cc;?>').val();var tQty=0; tQty=parseInt(iqty)-parseInt(nQty); if(itemID!=''&& sdate!=''&& isprice!='' && pOpt!=''&& iname!=''&& user!='' && nQty!=''  && tim!='' && ipprice!='' && iqty!='' && parseInt(nQty) <= parseInt(iqty) && parseInt(nQty) > 0) {document.getElementById('iQt<?php echo $cc;?>').value=tQty;document.getElementById('nQt<?php echo $cc;?>').value=''; $.post('shoptransPro.php',{user:user,itemID:itemID,tQty:tQty,pOpt:pOpt,nQty:nQty,tim:tim,isprice:isprice,ipprice:ipprice,iname:iname,sdate:sdate},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide item detail required!..';}" />
  </td>
  
</tr> 
  <?php
}
$cc=0;
 ?> 
 <?php
}
}
   

  ?>