<?php
require_once "config.php";

$qtn=$_POST['qtn'];

$sql="select * from quotation_details where quotation_no='".$qtn."'";
$query=mysqli_query($con,$sql);
if($result=mysqli_fetch_array($query)){
  $discount=$result['discount'];
  $shipment_charges=$result['shipment_charges'];
}
//echo $discount;

$sql="select * from quotation_details_all where quotation_no='".$qtn."'";
$query=mysqli_query($con,$sql);
$gst=0;$grand_total=0;$total=0;
$t=0;
while($result=mysqli_fetch_array($query)){
    //t1_gst=parseFloat(t1_gst)+parseFloat(gst/100*(grand_total-(grand_total*discount/100)));
          $total=$total+$result['grand_total'];
          $gst=$gst+$result['gst']/100*($result['grand_total']-($result['grand_total']*$discount/100));
         //$t=$t +$shipment_charges-$result['grand_total']*$discount/100;
    
    // t1_gst=parseFloat(t1_gst)+parseFloat(gst/100)*(grand_total-(grand_total*discount/100));
}
//echo $gst;
//$total=$total-$total*$discount/100;
$gst=$gst+$shipment_charges*0.18;
$grand_total=($gst)+$total-$total*$discount/100+$shipment_charges;
echo json_encode(
        array("total"=>$total,"gst"=>$gst,"grand_total"=>$grand_total)
        );


//require_once "config.php";
//$con->autocommit(FALSE);
//$sql="select * from quotation_no_table";
//$query=mysqli_query($con,$sql);
//if($result=mysqli_fetch_array($query)){
//    $sql1="update quotation_no_table set quotation_no=quotation_no+1";
//    $query1=mysqli_query($con,$sql1);
//    echo "AMUL-".$result['quotation_no'];
//}
//$con->commit();
//$con->close();