<?php
include("db_connection.php");
$Mainclass=new DB_Controller();

$Discount_Id=$_REQUEST['per'];
$active="No";
$Created_At=date('Y-m-d H:i:s');

$Upd_Sql=$Mainclass->dbh->prepare("UPDATE gold_discount_master SET Active=?,Updated_At=? WHERE SLN=?");
$Upd_Sql->bind_param("ssi",$active,$Created_At,$Discount_Id);
$Upd_Sql->execute();
$Upd_Sql->close();


// Delete existing records
    // Consider wrapping these in a transaction if atomicity is critical
    $Delete_Dealer = $Mainclass->dbh->prepare("DELETE FROM gold_category_discount_dealers WHERE Category_Discount_Id=?");
    $Delete_Dealer->bind_param("i", $Discount_Id);
    $Delete_Dealer->execute();
    $Delete_Dealer->close();


// Delete existing records
    // Consider wrapping these in a transaction if atomicity is critical
    $Delete_collection = $Mainclass->dbh->prepare("DELETE FROM gold_category_discount_collection WHERE Category_Discount_Id=?");
    $Delete_collection->bind_param("i", $Discount_Id);
    $Delete_collection->execute();
    $Delete_collection->close();

$Delete_category = $Mainclass->dbh->prepare("DELETE FROM gold_category_discount_product_cat WHERE Category_Discount_Id=?");
    $Delete_category->bind_param("i", $Discount_Id);
    $Delete_category->execute();
    $Delete_category->close();

?>