<?php 
if(isset($_POST['acid'])){
extract($_POST);

$sr=1;
require 'connection.php';
  $qry = "SELECT * FROM feedrate  where accid = $acid order by sorting ASC";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   while($row = mysqli_fetch_array($run)){
   	$btnid='btn';
	$supid='sup';
  $custid='cust';
  $addrateid='addrt';
  $percent='percent';
  $disc='disc';
  $disctafterp='discafter';
  $percentshd='percentshd';
	$fullrate='ful';
   	$btnid=$btnid.$sr;
   	$supid=$supid.$sr;
    $custid=$custid.$sr;
    $addrateid=$addrateid.$sr;
    $percent=$percent.$sr;
    $percentshd=$percentshd.$sr;
    $disc=$disc.$sr;
    $disctafterp=$disctafterp.$sr;
   	$fullrate=$fullrate.$sr;
	?>
    <div class="col-lg-2 col-md-12">
 <button id="<?php echo $row['itemid']; ?>" class="btn btn-inverse btn-info btn-sm <?php echo $btnid; ?>"> <?php echo $row['itemname']; ?> </button>

<input style="width: 50px;"  id="<?php echo $fullrate; ?>" value="<?php echo $row['fullrate']; ?>">
<input type="hidden"   id="<?php echo $addrateid; ?>" value=" <?php echo $row['addrate']; ?>">
<input type=""   id="<?php echo $percent; ?>" value=" <?php echo $row['percent']; ?>">
<input type=""  id="<?php echo $percentshd; ?>" value=" <?php echo $row['shedpercent']; ?>">
<input type="hidden"  id="<?php echo $disc; ?>" value=" <?php echo $row['discrate']; ?>">
<input type="hidden"  id="<?php echo $disctafterp; ?>" value=" <?php echo $row['discAfterPercent']; ?>">
</div>
<?php
$sr=$sr+1;


?>

<script type="text/javascript">
  
$(".<?php echo $btnid; ?>").click(function(){
  $('#itemid').val($('.<?php echo $btnid; ?>').get(0).id).change();

if($('#discshd'). prop("checked") == true){
  var dis= $("#<?php echo $disc; ?>").val()
  var fr= $("#<?php echo $fullrate; ?>").val()
  var fulshd = (parseInt(fr))-(parseInt(dis))

}
else{
  var fulshd= $("#<?php echo $fullrate; ?>").val()

}

 var dis= $("#<?php echo $disc; ?>").val()
 var disafter= $("#<?php echo $disctafterp; ?>").val()
  var fr= $("#<?php echo $fullrate; ?>").val()
  var fulco = (parseInt(fr))-(parseInt(dis))

if($('#addrateshd'). prop("checked") == true){
  var crate= (parseInt(fulshd) + parseInt($("#<?php echo $addrateid; ?>").val())) - ((parseInt(fulshd) + parseInt($("#<?php echo $addrateid; ?>").val())) * parseInt($("#<?php echo $percentshd; ?>").val()) /100 )
}
else{
    var crate= (parseInt(fulshd)) - ((parseInt(fulshd)) * parseInt($("#<?php echo $percentshd; ?>").val()) /100 )
}

if($('#addrateco'). prop("checked") == true){
    var srate= (parseInt(fulco) + parseInt($("#<?php echo $addrateid; ?>").val())) - ((parseInt(fulco) + parseInt($("#<?php echo $addrateid; ?>").val())) * parseFloat($("#<?php echo $percent; ?>").val()) /100 )- parseInt($("#<?php echo $disctafterp; ?>").val())
}
else{
   var srate= (parseInt(fulco)) - ((parseInt(fulco)) * parseFloat($("#<?php echo $percent; ?>").val()) /100 )- parseInt($("#<?php echo $disctafterp; ?>").val())
}

if($('#farmrid'). prop("checked") == true){
var crate= (parseInt($("#<?php echo $fullrate; ?>").val()) + parseInt($("#<?php echo $addrateid; ?>").val()))
  $('#Crate').val(crate);
}
else{
     $('#Crate').val(crate);
}
  // $('#Srate').((parseInt(srate)) - (parseInt(disafter)));
$('#Srate').val(srate);

  var qty= $("#qty").val()
    var suprate= $("#Srate").val()
  var custrate= $("#Crate").val()
  $("#Samt").val(suprate*qty)
  $("#Camt").val(custrate*qty)

})
</script>
<?php
}

}
 ?>

