<?php session_start();
include("conn.php");
if($_POST['action'])
{
  $action=$_POST['action'];
  //Add Data Start
  if($action=="Add")
  {
    if($_POST['services'] && $_POST['designation'] && $_POST['amount'] && $_POST['discount'])

    {
       
         $services = $_POST['services'];
         $designation = $_POST['designation'];
         $amount = $_POST['amount'];
         $discount =$_POST['discount'];

        $sql="insert into tbl_services(services,designation,amount,discount)values('$services','$designation','$amount','$discount')";
        if(mysqli_query($conn,$sql))
        {
          echo "Record added successfully.";
        }
        else
        {
          echo "Record not added. Error:".mysqli_error($conn);
        }

    }
    else
    {
      echo "Please complete all required fields.";
    }
  }
  //Add Data End  
  //Update Data Start
  else if($action=="Edit")
  {
    if($_POST['services'] && $_POST['designation'] && $_POST['amount'] && $_POST['discount'])
    {
        $id=$_POST['id'];
       $services = $_POST['services'];
         $designation = $_POST['designation'];
         $amount = $_POST['amount'];
         $discount =$_POST['discount'];
       
        $sql="update tbl_services set id='$id',services='$services',designation='$designation',amount='$amount',discount='$discount', updated_at=CURRENT_TIMESTAMP() where id='$id'";   
       
        if(mysqli_query($conn,$sql))
        {
          echo "Record updated successfully.";
        }
        else
        {
          echo "Record not updated. Error:".mysqli_error($conn);
        }

    }
        else
        {
          echo "Please complete all required fields.";
        }
  }
  //Update Data End
  //Delete Data Start
  else if($action=="Delete")
  {
    $id=$_POST['id'];

    $sql="update tbl_services set deleted_at=CURRENT_TIMESTAMP() where id='$id'";
    if(mysqli_query($conn,$sql))
    {
      echo "Record deleted successfully.";
    }
    else
    {
      echo "Record not deleted. Error:".mysqli_error($conn);
    }
  }
  //Delete Data End
}
else
{
  echo "Invalid action specified.";
}


  mysqli_close($conn);

