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


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $customer_id = $_POST['customer_id'];
    $cheque_number = $_POST['cheque_number'];
    $bank_name = $_POST['bank_name'];
    $amount = $_POST['amount'];
    $issued_date = $_POST['issued_date'];
    $hold_until = $_POST['hold_until'];
    $clearance_date = $_POST['clearance_date'];
    $status = $_POST['status'];

    try {
        $stmt = $conn->prepare("INSERT INTO `cheque_payments` 
            (`customer_id`, `cheque_number`, `bank_name`, `amount`, `issued_date`, `hold_until`, `clearance_date`, `status`) 
            VALUES (:customer_id, :cheque_number, :bank_name, :amount, :issued_date, :hold_until, :clearance_date, :status)");

        $stmt->bindParam(':customer_id', $customer_id);
        $stmt->bindParam(':cheque_number', $cheque_number);
        $stmt->bindParam(':bank_name', $bank_name);
        $stmt->bindParam(':amount', $amount);
        $stmt->bindParam(':issued_date', $issued_date);
        $stmt->bindParam(':clearance_date', $clearance_date);
        $stmt->bindParam(':hold_until', $hold_until);
        $stmt->bindParam(':status', $status);

        $stmt->execute();

        header('Location: list_cheque.php');
        exit();
    } catch (PDOException $e) {
        die("Error inserting data: " . $e->getMessage());
    }
}
?>
