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


// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Collect form data
    $supplier_id = $_POST['supplier_id'];
    $cheque_number = $_POST['cheque_number'];
    $bank_name = $_POST['bank_name'];
    $amount = $_POST['amount'];
    $issued_date = $_POST['issued_date'];
    $hold_until = $_POST['hold_until'];
    $status = $_POST['status'];

    try {
        // Prepare the SQL insert query
        $stmt = $conn->prepare("INSERT INTO `payable_cheque` 
            (`supplier_id`, `cheque_number`, `bank_name`, `amount`, `issued_date`, `hold_until`, `status`) 
            VALUES (:supplier_id, :cheque_number, :bank_name, :amount, :issued_date, :hold_until, :status)");

        // Bind parameters
        $stmt->bindParam(':supplier_id', $supplier_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(':hold_until', $hold_until);
        $stmt->bindParam(':status', $status);

        // Execute the query
        $stmt->execute();

        // Redirect to the list_cheque.php page after successful insertion
        header('Location: list_cheque_payable.php');
        exit(); // Make sure no further code is executed
    } catch (PDOException $e) {
        // Handle any errors that occur during the insert
        die("Error inserting data: " . $e->getMessage());
    }
}
?>
