<?php

require_once "config.php";

header('Content-Type: application/json');

$method = $_SERVER['REQUEST_METHOD'];

switch ($method) {
    case 'GET':
        $ckodecust = isset($_GET['ckodecust']) ? $_GET['ckodecust'] : '';
        $cnoid = isset($_GET['cnoid']) ? $_GET['cnoid'] : '';

        if (empty($ckodecust) || empty($cnoid)) {
            echo json_encode(["success" => "false", "error" => "Missing required parameters", "message" => "Please provide both ckodecust and cnoid."]);
            exit;
        }

        $deleteQuery = $conn->prepare("
            DELETE FROM tbalamatkirim 
            WHERE ckodecust = ? AND cnoid = ?
        ");

        $deleteQuery->bind_param("ss", $ckodecust, $cnoid);

        if ($deleteQuery->execute()) {
            echo json_encode([
                "success" => "true", 
                "message" => "Data deleted successfully"
            ]);
        } else {
            echo json_encode([
                "success" => "false", 
                "error" => "Failed to delete data",
                "message" => "Data deletion failed. Please try again."
            ]);
        }

        $deleteQuery->close();
        break;

    default:
        echo json_encode(["error" => "Invalid request method"]);
        break;
}

mysqli_close($conn);
?>
