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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Collect POST data
    $refNo = $_POST['ref_no'];
    $supplierId = $_POST['supplier_id'];
    $bankId = $_POST['bank_id'];
    $amount = $_POST['amount'];
    $note = $_POST['note'];
    $date = $_POST['date'];
    $status = 'purchase'; 

    $query = "INSERT INTO bank_debit_amount (bank_id, supplier_id, ref_no, amount, note, date, status) 
              VALUES (:bank_id, :supplier_id, :ref_no, :amount, :note, :date, :status)";
    $stmt = $conn->prepare($query);

    $stmt->bindParam(':bank_id', $bankId);
    $stmt->bindParam(':supplier_id', $supplierId);
    $stmt->bindParam(':ref_no', $refNo);
    $stmt->bindParam(':amount', $amount);
    $stmt->bindParam(':note', $note);
    $stmt->bindParam(':date', $date);
    $stmt->bindParam(':status', $status);

    if ($stmt->execute()) {
        echo 'success';
    } else {
        echo 'failure';
    }
}
