<?php
require_once"labClass.php";
$con=new labClass();
$user=$_POST['user'];
$rQ= $con->getThisTempStoreQ();

  if ($rQ->rowCount()>0) {
  $chp=$rQ->fetchAll();
  foreach ($chp as $key => $p) {
    $nr=$p["orderID"];
                               }
                          }else{
    $Q =$con->genStoreID();
    $nr=$Q->rowCount()+1;
                      }
?> 
  
 ///////
 ///////
 <table>
   <tr>
     <td width="40%" valign="top"> 
 <input type="hidden" id="orderID" value="<?php echo $nr;?>" name="orderID" required>
 
   <div class="row">
    <div class="col">
      <h6>Search item here:</h6>  
      <input type="text" onkeyup ="submision()" class="form-control" id="tname" style="width:100%; height:40px; border-radius:12px;" placeholder="Test name" name="tname" required>  
    </div>
</div> 
 

<!-- SEARCH BOX END-->

 

 
 <div id="dispR">
   
 <?php
   //require_once "labToolkitListOp.php";
   ?>
   
 </div>
     </td>
     <td valign="top">
     <div id="co">  
<!--INVOICE  DEVELOPMENT CODE-->
<table width="100%" border="0">
    <tr>
    <td colspan="2">
    <h4>KWIZERA INVESTMENT COMPANY STORE REQUEST</h4>              
      
    </td>
</tr>
  <tr>
    <td valign="top">
        <h6>
            <p/><p/><p/>
        <b style="color:blue;">Location:  Katoro-Geita<br/>Tel:  +255 788253958/796318675<br/>Email:  speciosylver@gmail.com <br/>         
      <h6>
    </td>
    <td>
          <h6>
            Request No:   
      <?php 

      echo "".$nr;
      ?>
      <br/>
      Date:  <?php echo Date("Y-m-d");?></h6>
    </td>
  </tr>
   <tr>
    <td colspan="2">
      <img src="assets/logo.png" style="width:100%;height:70px;" >
    </td>

  </tr>
   <tr>
    <td colspan="2">
        <h5>
M/S:   
<sub id="stf"><?php echo $user;?></sub>
<small id="mc"></small>
 </h5>
    </td>
  </tr>
</table>


<!--CODE END YEAR-->

<div id="dR">
<?php
require_once "storeqL.php";
?></div>
</div>
<div>
   <button type="submit" class="btn btn-primary" value="Print" style="width:13%; height:40px;" onclick="printPageArea();">Print </button>
   <button type="submit" class="btn btn-primary"  style="width:13%; height:40px;" onclick="editData();">Edit </button>
   <button type="submit" id="sbtn" value="Save" class="btn btn-primary"  style="width:13%; height:40px;" onclick="savData();">Save </button>
</div>
     </td>
   </tr>


 </table>
 <script>
 function shareData(){ 
  var ecc =0;
var tprice =0;
var cc=document.getElementById('cc').value; 
for (var i = cc; i > 0; i--) {
  

var iname =document.getElementById('iname'+i).value; 
//document.getElementById('iname'+i).disabled=false; 
var rate =document.getElementById('rate'+i).value; 
//document.getElementById('rate'+i).disabled=false;
var eQty =document.getElementById('eQty'+i).value; 
//document.getElementById('eQty'+i).disabled=false;
document.getElementById('isp'+i).value=rate;
document.getElementById('tprice'+i).value=rate*eQty;
document.getElementById('tp'+i).innerHTML=rate*eQty;
//tprice+rate*eQty; 
tprice =tprice+rate*eQty;
//alert(tprice);
  
  
  
if(tprice==""){ 
         ecc++;
              }
     
if(iname==""){ 
         ecc++;
             }
if(eQty==""){ 
         ecc++;
             }
if(rate==""){ 
         ecc++;
             }
}
 document.getElementById('tprice').value=tprice;
 document.getElementById('tsp').innerHTML=tprice;
 //alert(tprice);
} 

 function editData(){ 
  var ecc =0;
var cc=document.getElementById('cc').value; 
for (var i = cc; i > 0; i--) {
  

//var iname =document.getElementById('iname'+i).value; 
//document.getElementById('iname'+i).disabled=false;
$('#rate'+i).show();
$('#isp'+i).hide(); 
var rate =document.getElementById('rate'+i).value; 
document.getElementById('rate'+i).disabled=false;
var eQty =document.getElementById('eQty'+i).value; 
//document.getElementById('eQty'+i).disabled=false;
var tprice =document.getElementById('tprice'+i).value; 
//document.getElementById('tprice'+i).disabled=false;

  
  
  
if(tprice==""){ 
         ecc++;
              }
     
//if(iname==""){ 
         //ecc++;
             //}
if(eQty==""){ 
         ecc++;
             }
if(rate==""){ 
         ecc++;
             }
}



   /* if(ecc==0)
    { 
        $.post("expensesRegFormPro.php",
          {submit:submit,tname:tname,tPrice:tPrice,sdate:sdate},
          function(data){
      $('#disp').html(data).show();

    });
    }*/
 
} 

/*function processData(){ 
document.getElementById('dispR').innerHTML='';
var ecc=0; 
var cname =document.getElementById('cname').value; 
$.trim(cname);  
  //FIRST NAME VALIDATION
  
if(cname==""){ 

         ecc++;
         alert('Item customer is required!..');
             }
 
  
    if(ecc==0)
    { 
        $.post("pharmGetAgBN.php",
          {cname:cname},
          function(data){
      $('#ph').html(data).show();

    });
    }
  } 
*/


function savData(){ 
var n=0;
var cash=0;
var ecc =0;
var pst ='';
var cc=document.getElementById('cc').value;  
//var pOpt=document.getElementById('pOpt').value; 
for (var i = cc; i > 0; i--) {

var iname =document.getElementById('iname'+i).value;   
var rate =document.getElementById('rate'+i).value; 
var eQty =document.getElementById('eQty'+i).value;  
var tprice =document.getElementById('tprice'+i).value;  
var orderID =document.getElementById('orderID').value;
var itemID =document.getElementById('item'+i).value;
var tsprice =document.getElementById('tprice').value;
var cus =document.getElementById('user').value;
/*if( document.getElementById('pst').checked==true)
        {
    var pst =document.getElementById('pst').value;
        }
else if(document.getElementById('npst').checked==true)
        {
    var pst =document.getElementById('npst').value;
        }    
          else{
         ecc++;
              }*/
if(itemID==""){ 
         ecc++;
              }
 if(cus==""){ 
         ecc++;
              }
 if(tsprice==""){ 
         ecc++;
              }
/*if(pOpt==""){ 
         ecc++;
              }*/
if(orderID==""){ 
         ecc++;
              }
if(tprice==""){ 
         ecc++;
              }

if(tprice==""){ 
         ecc++;
              }

if(iname==""){ 
         ecc++;
             }

if(eQty==""){ 
         ecc++;
             }

if(rate==""){ 
         ecc++;
             }
}
////////////////////
 if(ecc==0)
    { 
for (var i = cc; i > 0; i--) { 
  n=i;
  //alert(n);
  //var pOpt=document.getElementById('pOpt').value;
  iname =document.getElementById('iname'+i).value;  
  rate =document.getElementById('rate'+i).value; 
  eQty =document.getElementById('eQty'+i).value;  
  tprice =document.getElementById('tprice'+i).value;  
  orderID =document.getElementById('orderID').value;
  tsprice =document.getElementById('tprice').value;
  itemID =document.getElementById('item'+i).value;
  cus =document.getElementById('ms').innerHTML;
  var user =document.getElementById('user').value;
  var sdate =document.getElementById('sdate').value;
  /*if( document.getElementById('pst').checked==true)
        {
        pst =document.getElementById('pst').value;

        cash =document.getElementById('tprice').value;
        }
   else if(document.getElementById('npst').checked==true)
        {
        pst =document.getElementById('npst').value;
        cash =document.getElementById('cash').value;
        }*/    
         
         $.post("storeQsavpro.php",
          {cus:cus,itemID:itemID,n:n,orderID:orderID,user:user, rate:rate,eQty:eQty,iname:iname,tprice:tprice,tsprice:tsprice,sdate:sdate},
          function(data){
      $('#disp').html(data).show();

    }); }
}else{
    alert('All detail require!');
}
////////////////
} 
 
  function printPageArea(){
    var printContent = document.getElementById('co').innerHTML;
    var originalContent = document.body.innerHTML;
    document.body.innerHTML = printContent;
    window.print();
    document.body.innerHTML = originalContent;
}
 
/* 
function ncashS(){
     $('#cs').show();
     document.getElementById('pst').checked=false;
  }
 function cashS(){
    
       document.getElementById('npst').checked=false;
      $('#cs').hide();
      document.getElementById('cash').value=0;
    }
    
  
 function submision(){
    
    var searchValue=$('#tname').val();
    $('#dispR').empty();
    $.post('pharmInvpiceL.php',{searchValue:searchValue},function(data){
      $('#dispR').html(data);

    });
  }*/

   function getCusN(){
    
    var cus=$('#cus').val();
    $('#mc').empty();
    $.post('profGetSt.php',{cus:cus},function(data){
      $('#mc').html(data);});
    $('#cus').hide();
  }
 

  function submision(){
    
    var searchValue=$('#tname').val();
    
    $('#dispR').empty();
    $.post('storeRqSchAddL.php',{searchValue:searchValue},function(data){
      $('#dispR').html(data);

    });
    }
    
</script>
 