<?php include "../db.php"?>
<?php
$connection=new mysqli($dbhost,$dbusername,$dbpassword,$dbname);
if($_SERVER["REQUEST_METHOD"]=="POST" && isset($_POST["add_salestax_btn"])){
    $amount=$_POST["add_salestax_amount"];
    $status=$_POST["add_salestax_status"];
    if(empty($amount) && empty($status)){
        session_start();
        $_SESSION["salestax_add_error"]="All fields are required!!";
        header("Location: ../salestax.php");
        exit();
    }
    else{

        $salesTaxAddQuery="INSERT into gst (Amount,IsActive) VALUES('$amount','$status')";
        $connection->query($salesTaxAddQuery);
        $_SESSION["salestax_add_alert"]="Sales Tax Added Successfully!!";
        header("Location: ../salestax.php");
        exit();

    }
}
if($_SERVER["REQUEST_METHOD"]=="POST" && isset($_POST["edit_salestax_btn"])){
    $id=$_POST["edit_salestax_id"];
    $amount=$_POST["edit_salestax_amount"];
    $status=$_POST["edit_salestax_status"];
    if(empty($amount) && empty($status)){
          session_start();
        $_SESSION["salestax_add_error"]="All fields are required!!";
        header("Location: ../salestax.php");
        exit(); 
    }
    else{
        $salesTaxEditQuery="UPDATE gst SET Amount='$amount', IsActive='$status' WHERE ID='$id'";
        $connection->query( $salesTaxEditQuery);
        $_SESSION["salestax_add_alert"]="Sales Tax Added Successfully!!";
        header("Location: ../salestax.php");
        exit(); 
    }
}
if($_POST["ID"]){
    $ID=$_POST["ID"];
    $salesTaxDltQuery="DELETE from gst WHERE ID='$ID'";
    $connection->query($salesTaxDltQuery);
}
?>