<link rel="stylesheet" href="../css/sweet-alert.css" /> 
<?php
include("../connection.php");
include("../user.php");

$del_id = mysqli_real_escape_string($con, $_POST['deleteID']);

// First, get the asset_id from the record
$asset_query = "SELECT asset_id FROM scrab_master WHERE id = '$del_id'";
$asset_result = mysqli_fetch_array(mysqli_query($con, $asset_query));
$asset_id = $asset_result['asset_id'];

// Now delete the record
$delete_repair = mysqli_query($con, "DELETE FROM scrab_master WHERE id = '$del_id'");

if ($delete_repair) {
    $update_repair = mysqli_query($con, "UPDATE asset_master SET status = 0 WHERE id = '$asset_id'");
    ?>
    <script>
        setTimeout(function () {
            swal({
                title: "Success",
                text: "Deleted Successfully!",
                type: "success"
            }, function () {
                window.location = "repair.php";
            });
        }, 100);
    </script>
    <?php
} else {
    ?>
    <script>
        setTimeout(function () {
            swal({
                title: "Error",
                text: "Delete Failed!",
                type: "error"
            }, function () {
                window.location = "repair.php";
            });
        }, 100);
    </script>
    <?php
}
?>
