 <?php
require_once"labClass.php";
$con=new labClass();
?>
 <div class="container mt-3" style="margin-top:2px;">

 <div  class="mt-4 p-5 bg-white text-dark rounded" >
  <h6>Withdraw excess money here:</h6> 
     Balance to date:<p/><?php
       //ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
           require_once"labClass.php";
           $con=new labClass();
           $sdate=$_POST['sdate'];
           $recID=1; 
           $r= $con->getExcBalance($recID)->fetch(); 
           echo $bal=$r['cbalance'];
           ?>
<sub id="dis"></sub>
<div class="row">
<div class="col">
<div class="form-floating mb-3 mt-3"> 
<h6>Description:</h6>
<sup class="text-danger" id="q"> </sup>
<input class="form-control" id="descrip" name="descrip" list="cnames" onchange="getCusN()">
<datalist id="cnames">
<?php
 $Q= $con->getDrugList();
 if ($Q->rowCount()>0) {
 $lb=$Q->fetchAll();
     foreach ($lb as $key => $l){
      ?>
      <option value="<?php echo  $l["iname"];?>">  
             <?php
           }
           }
      ?></datalist>
      <input type="hidden"  id="am"  name="am" value="<?php echo $bal;?>"  required>
    </div>
     <sup class="text-danger" id="in"> </sup>
</div>
 <div class="col" id="dsp">
    
  </div>
<div class="col-sm justify-content-center">
  <div class="form-floating mb-3 mt-3"> 
  <button type="submit" id="submit" value="Submit" name="submit" class="btn btn-primary" style="height:60px;" onclick="saveData()">Submit</button>

</div>
</div>
</div>

</div>
 </div>
    
<div id="dispR">
   <?php
  require_once "excwithdrawR.php";
  ?>
  
</div>
 
 <script>
 
function getCusN(){
    
    var iname=$('#descrip').val();
    //alert(iname);
    $('#dsp').empty();
    $.post('getAmount.php',{iname:iname},function(data){
      $('#dsp').html(data);});
     
  }
        
 
 function saveData(){ 
var ecc=0; 
var descrip =document.getElementById('descrip').value; 
$.trim(descrip);
var user =document.getElementById('user').value; 
$.trim(user);
var submit =document.getElementById('submit').value;
var tprice =document.getElementById('tPrice').value;
var am =document.getElementById('am').value; 
var sdate =document.getElementById('sdate').value; 
var vN =/[\(A-Za-z)]/g; 

var nV =/[a-z\s]/i;
  var j=0,k=0, g=0,i=0;
//FIRST NAME VALIDATION
 
  
if(tprice==""){ 

         ecc++;
             document.getElementById('q').innerHTML="Amount is required!..";
 

               }
else{

document.getElementById('q').innerHTML="";
    }
    if(parseFloat(tprice)>=parseFloat(am)){ 

         ecc++;
    document.getElementById('q').innerHTML="Invalid amount!..";
 

    }
else{

document.getElementById('q').innerHTML="";
    }
     
if(descrip==""){ 

         ecc++;
             document.getElementById('in').innerHTML="Description is required!..";
 

               }
else{

document.getElementById('in').innerHTML="";
    }
  
    if(ecc==0)
    { 
        $.post("excbalancewithdrawpro.php",
          {submit:submit,user:user,descrip:descrip,tprice:tprice,sdate:sdate},
          function(data){
      $('#disp').html(data).show();

    });
    }
  document.getElementById('descrip').value='';
  document.getElementById('tPrice').value='';
} 
 
 
</script>