<?php
require_once "db.php";

if (isset($_GET['id'])) {
    $id = intval($_GET['id']);

    // Delete sale items first
    $stmt = $conn->prepare("DELETE FROM sale_items WHERE sale_id=?");
    $stmt->bind_param("i", $id);
    $stmt->execute();

    // Delete sale
    $stmt = $conn->prepare("DELETE FROM sales WHERE sale_id=?");
    $stmt->bind_param("i", $id);
    $stmt->execute();
}

header("Location: sales-list.php");
exit();
?>
