 <?php 
 
if( isset($_POST['shopid']) && isset($_POST['owniD']))
  {
 require("../buda_myStockAgro_class.php");
 $myAgrocon = new  buda_myStockAgro_class();
 $shopid=$_POST['shopid'];
 $ownID=$_POST['owniD']; 
 $searchValue=$_POST['searchValue'];
//////////////////
 ////////////// 
$getS=$myAgrocon->getSelectedShopOther($shopid);
 if ($getS->rowCount()>0) {
  $shop=$getS->fetch();
 }
    
      
?> 
 
  
 
   <!--NEW USER REGISTRATION FORM, DISPLAYED BY DEFAULTS IN PAGE LOAD-->


<center>
 

<table border="1" style="border-color:white;" id="reg_form_table">
  <tr>
      <td id="td_height" ><label id="inner_top">S/N</label></td>
      <td id="td_height" ><label id="inner_top">NAME</label></td> 
 
 
                <td id="td_height" ><label id="inner_top">BUYING PRICE</label></td>
                
                <td id="td_height" ><label id="inner_top">SALE PRICE</label></td></td><td  ><label id="inner_top">SELLING CURRENCY</label></td>
                <td id="td_height" ><label id="inner_top">CURRENT QUANTITY</label></td>
                <td id="td_height" ><label id="inner_top">BEST SUPPLY</label></td>
                <td id="td_height" ><label id="inner_top"> QUANTITY</label></td>
               <td id="td_height" ><label id="inner_top">NEW ENTRY</label></td>
               
               <td id="td_height" ><label id="inner_top">DATE </label></td>
               <td colspan="2" id="td_height" ><label id="inner_top">UPDATE / DELETE </label></td> 
 
 
                </tr>  

 <input class="hi" type="hidden" name="owniDs" id="owniDs" value="<?php echo $ownID;?>">


   <input class="hi" type="hidden" name="shopids" id="shopids"  value="<?php echo $shopid;?>">


 <?php 
 $cc=0;
    $item=$myAgrocon->getItemBySearch($searchValue);
    if ($item->rowCount()>0) {
    $pm=$item->fetchAll();
    foreach ($pm as $key => $p) {
      $itemid=$p['itemid'];
      $chk= $myAgrocon->getThisShopItemPrice($itemid,$shopid,$ownID);
      $c=$chk->fetch();
      if ( $chk->rowCount()>0) {
       
      $cc++;
     
        ?>
  <tr>
      
     <td colspan="10" align="right">
       <sup id="rdn<?php echo $cc;?>"></sup>
     </td>
   </tr>
  <tr>
 <td >
 
     <?php
          echo $p['s_no'];
       ?>
  </td> 
  <td id="itemname<?php echo $cc;?>" >
 
     <?php
          echo $c['itemName'];
   ?>
    </td> 
    
   <td id="reg_form_table_cell">

        <input type="hidden" name="itemid<?php echo $cc;?>" id="itemid<?php echo $cc;?>" value="<?php echo $c['itemID'];?>"/>
         <input type="number" disabled="true" min="1" step="1" oninput="validity.valid||(value='');" name="itemcost<?php echo $cc;?>" id="itemcost<?php echo $cc;?>" class="prof_info" value="<?php echo $c['buyprice'];?>" /><br/>
         
  </td>
  
<td id="reg_form_table_cell">

        <input type="hidden" name="itemid<?php echo $cc;?>" id="itemid<?php echo $cc;?>" value="<?php echo $p['itemid'];?>"/>
        <input type="number" disabled="true" min="1" step="1" oninput="validity.valid||(value='');"  name="scost<?php echo $cc;?>" id="scost<?php echo $cc;?>" class="prof_info"  value="<?php echo $c['price'];?>"/><br/>
         
  </td>
  <td id="reg_form_table_cell">

        <input type="hidden" name="itemid<?php echo $cc;?>" id="itemid<?php echo $cc;?>" value="<?php echo $p['itemid'];?>"/>
        <input type="number" disabled="true" min="1" step="1" oninput="validity.valid||(value='');" name="cquantity<?php echo $cc;?>" id="cquantity<?php echo $cc;?>" class="prof_info"  value="<?php echo $c['quantity'];?>" /><br/>
         
 </td>

  <td id="reg_form_table_cell">

    
         <select disabled ="false" name="currency<?php echo $cc;?>" id="currency<?php echo $cc;?>" class="prof_info">
          <option value="<?php echo $c['currency'];?>"><?php echo $c['currency'];?></option>
          <option value="TZS">TZS</option>
          <option value="USD">USD</option>
         </select>  
  </td>
  
   <td id="reg_form_table_cell">

        <input type="hidden" name="itemid<?php echo $cc;?>" id="itemid<?php echo $cc;?>" value="<?php echo $c['itemID'];?>"/>
         <input type="text" disabled="true" name="bestsupply<?php echo $cc;?>" id="bestsupply<?php echo $cc;?>" class="prof_info" value="<?php echo $c['bestsupply'];?>" /><br/>
         
  </td>
  
  <td>
     <input type="submit"  name="postEdit<?php echo $cc;?>" id="postEdit<?php echo $cc;?>" value="Edit" id="submit" onclick="document.getElementById('scost<?php echo $cc;?>').disabled=false;document.getElementById('bestsupply<?php echo $cc;?>').disabled=false;document.getElementById('itemcost<?php echo $cc;?>').disabled=false;document.getElementById('currency<?php echo $cc;?>').disabled=false;$('#postEdit<?php echo $cc;?>').hide();$('#postUpdate<?php echo $cc;?>').show();" />


        <input type="submit" class="hi" name="postUpdate<?php echo $cc;?>" id="postUpdate<?php echo $cc;?>"value="Update" id="submit" onclick="var shopid=$('#shopids').val();var ownID=$('#owniDs').val();var scost = $('#scost<?php echo $cc;?>').val();var currency=$('#currency<?php echo $cc;?>').val();var bestsupply=$('#bestsupply<?php echo $cc;?>').val();var itemcost=$('#itemcost<?php echo $cc;?>').val(); var itemid =$('#itemid<?php echo $cc;?>').val();if(currency!='' && scost!='' && itemcost!='' && bestsupply!='') {$.post('updateStockPro.php',{scost:scost,bestsupply:bestsupply,itemid:itemid,owniD:ownID,currency:currency,shopid:shopid,itemcost:itemcost},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});document.getElementById('scost<?php echo $cc;?>').disabled=true;document.getElementById('bestsupply<?php echo $cc;?>').disabled=true;document.getElementById('itemcost<?php echo $cc;?>').disabled=true;document.getElementById('currency<?php echo $cc;?>').disabled=true;$('#postUpdate<?php echo $cc;?>').hide();$('#postEdit<?php echo $cc;?>').show();} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide price and currency required!..';}" />
  </td> 
    
  <td id="reg_form_table_cell">

        <input type="hidden" name="itemid<?php echo $cc;?>" id="itemid<?php echo $cc;?>" value="<?php echo $p['itemid'];?>"/>
        <input type="number" min="1" step="1" oninput="validity.valid||(value='');" name="quantity<?php echo $cc;?>" id="quantity<?php echo $cc;?>" class="prof_info" /><br/>
         
 </td>
 <td id="reg_form_table_cell">

        <input type="hidden" name="itemid<?php echo $cc;?>" id="itemid<?php echo $cc;?>" value="<?php echo $p['itemid'];?>"/>
         <input type="date" name="dateBought<?php echo $cc;?>" id="dateBought<?php echo $cc;?>" value="<?php echo date("Y-m-d");?>" class="prof_info" /><br/>
         
  </td>
  <td>
     

        <input type="submit"   name="qUpdate<?php echo $cc;?>" id="qUpdate<?php echo $cc;?>"value="Add stock" id="submit" onclick=" var itemname=document.getElementById('itemname<?php echo $cc;?>').innerHTML; var shopid=$('#shopids').val();var ownID=$('#owniDs').val();var dateBought=$('#dateBought<?php echo $cc;?>').val(); var cquantity=$('#cquantity<?php echo $cc;?>').val();var quantity=$('#quantity<?php echo $cc;?>').val();var scost = $('#scost<?php echo $cc;?>').val();cquantity = parseInt(cquantity) + parseInt(quantity);document.getElementById('cquantity<?php echo $cc;?>').value=cquantity;var currency=$('#currency<?php echo $cc;?>').val();var bestsupply=$('#bestsupply<?php echo $cc;?>').val();var itemcost=$('#itemcost<?php echo $cc;?>').val(); var itemid =$('#itemid<?php echo $cc;?>').val();if(itemname!='' && cquantity!='' && quantity!=''&& currency!='' && scost!='' && itemcost!='' && bestsupply!='') {$.post('updateQuantityPro.php',{itemname:itemname,dateBought:dateBought,cquantity:cquantity,quantity:quantity,scost:scost,bestsupply:bestsupply,itemid:itemid,owniD:ownID,currency:currency,shopid:shopid,itemcost:itemcost},function(data){$('#rdn<?php echo $cc;?>').html(data).show();document.getElementById('quantity<?php echo $cc;?>').value='';});} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide price and currency required!..';}" />
  </td> 
  <td>
   <?php
       /* <input type="submit"  name="postDelete<?php echo $cc;?>" id="postDelete<?php echo $cc;?>"value="Delete" id="submit" onclick="var shopid=$('#shopids').val();var ownID=$('#owniDs').val();  var itemid =$('#itemid<?php echo $cc;?>').val(); $.post('deleteItemFromStock.php',{ itemid:itemid,owniD:ownID, shopid:shopid},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});  " />
  */?></td> 
    

 

</tr>
 
 
</form>
  <?php
}
}
 $cc=0;

 ?>
</table>
  
</center>
 <?php

    }
    else{
    echo "No item match!";
  }
  }
  else{
    echo "Error while processing!";
  }
  ?>
 





