<?php 
 $cc=0;
      
 // ini_set('display_errors', 1);
    // ini_set('display_startup_errors', 1);
    // error_reporting(E_ALL);
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>QTY</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>ADD QTY</h6></small>
      </th>
        <th>
        <small><h6>SAVE</h6></small>
       
      </th>
      <th>
        <small><h6>EDIT</h6></small>
      </th>
      <th>
        <small><h6>DELETE</h6></small>
      </th>
<?php
 foreach ($chp as $key => $p) {
    $itemID=$p['itemID'];
      $iname=$p['iname'];
      $r= $con->getThisStoreItem($iname)->fetch(); 
      $cc++; 
     
        ?>
 <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> 
     <?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="text" 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>
   <input type="number" style="background-color:white;border-radius:12px; width:100%;"   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="Add" id="submit" onclick="var etype=$('#etype').val();  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 itemID =$('#itemD<?php echo $cc;?>').val();var tQty=0; tQty=parseInt(nQty)+parseInt(iqty); if(itemID!=''&& etype!='' && sdate!=''&& isprice!='' &&  iname!=''&& user!='' && nQty!='' && ipprice!='' && iqty!='' && nQty > 0 && tQty > 0) { 

          document.getElementById('iQt<?php echo $cc;?>').value=tQty;document.getElementById('nQt<?php echo $cc;?>').value=''; $.post('pharItemSearchPro.php',{user:user, itemID:itemID,etype:etype, tQty:tQty,nQty:nQty,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="postEdit<?php echo $cc;?>" id="postEdit<?php echo $cc;?>" value="Edit" id="submit" onclick="var itemID =$('#itemD<?php echo $cc;?>').val();var iname =$('#inam<?php echo $cc;?>').val();$.post('pharItemEditF.php',{itemID:itemID, iname:iname},function(data){$('#disp').html(data).show();});" />
  </td>
   <td> 
   <input type="submit" name="dele<?php echo $cc;?>" id="dele<?php echo $cc;?>" value="Delete" id="submit" onclick="alert('You are about deleting this item!..');$('#dele<?php echo $cc;?>').hide();$('#del<?php echo $cc;?>').show();" />
        <input type="submit" style="background-color:red;display:none;" name="del<?php echo $cc;?>" id="del<?php echo $cc;?>" value="Delete" id="submit" onclick="  var iname=$('#inam<?php echo $cc;?>').val();  var itemID =$('#itemD<?php echo $cc;?>').val();  if(itemID!='' &&  iname!='') { 

            $.post('pharItemSearchDelPro.php',{itemID:itemID,iname:iname},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});
           
        } else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide item detail required!..';} $('#dele<?php echo $cc;?>').show();$('#del<?php echo $cc;?>').hide();" />
  </td>
</tr> 
  <?php
}
$cc=0;
 ?> 
 <?php
}
}
   

  ?>