<?php
require_once "../config/db.php";

$id = (int) ($_GET['id'] ?? 0);

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

// Delete invoice
$stmt = $conn->prepare("DELETE FROM invoices WHERE id=?");
$stmt->bind_param("i", $id);
$stmt->execute();

header("Location: ../pages/invoices.php");
exit;
