<?php
require_once "config.php";
$product_name=$_POST['product'];
$hsn=$_POST['hsn'];
$qty=$_POST['qty'];
$unit=$_POST['unit'];
$base_price=$_POST['base_price'];
$gst=$_POST['gst'];
$grand_total=$_POST['total'];
$data=array();
$quotation_no=$_POST['quotation_no'];

$sql="select * from add_remove_product where product_name='".$product_name."' and quotation_no='".$quotation_no."'";
    $query=mysqli_query($con,$sql);
if($query==false){
    die(mysqli_error($con));
}
if($result=mysqli_fetch_array($query)){
    die("product exists");
}


$sql="insert into add_remove_product(product_name,hsn,qty,unit,base_price,gst,grand_total,quotation_no,created_on) values('".$product_name."',"
        . "'".$hsn."','".$qty."','".$unit."','".$base_price."','".$gst."','".$grand_total."','".$quotation_no."',now())";
$query=mysqli_query($con,$sql);
if($query==false){
    die(mysqli_error($con));
}else{
    $sql="select * from add_remove_product where quotation_no='".$quotation_no."'";
    $query=mysqli_query($con,$sql);
if($query==false){
    die(mysqli_error($con));
}
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC)){
    array_push($data,$result);
}
echo json_encode(array(
    "data"=>$data
));
}

