<?php
include '../includes/config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $cheque_id = isset($_POST['cheque_id']) ? $_POST['cheque_id'] : '';

    try {
        $conn->beginTransaction();

        // $deleteCashDeposit = "DELETE FROM cash_deposit WHERE cheque_id = :cheque_id";
        // $stmt = $conn->prepare($deleteCashDeposit);
        // $stmt->bindParam(':cheque_id', $cheque_id);
        // $stmt->execute();

        $deleteChequePayments = "DELETE FROM cheque_payments WHERE id = :cheque_id";
        $stmt = $conn->prepare($deleteChequePayments);
        $stmt->bindParam(':cheque_id', $cheque_id);
        $stmt->execute();

        $conn->commit();

        echo "<script>
                alert('Cheque and related data deleted successfully!');
                window.location.href = '../list_cheque.php';
              </script>";
    } catch (PDOException $e) {
        $conn->rollBack();
        echo "Error: " . $e->getMessage();
    }
}
?>
