<?php
include_once("../includes/config.php");
session_start();

if (!$_SESSION['email']) {
    header('location:../login.php');
    exit();
}

$sale_id = isset($_GET['sale_id']) ? $_GET['sale_id'] : '';
$invoice_no = isset($_GET['invoice']) ? $_GET['invoice'] : '';

if ($sale_id) {
    try {
        $query = "DELETE FROM stock_sale WHERE sale_id = :sale_id";
        $stmt = $conn->prepare($query);
        $stmt->execute(['sale_id' => $sale_id]);
        $_SESSION['success'] = "Item deleted successfully.";
    } catch (PDOException $e) {
        $_SESSION['error'] = "Error: " . $e->getMessage();
    }
}

header('Location: ../edit_pos.php?invoice=' . $invoice_no);
exit();
?>