<?php
include('connection.php');

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Sanitize and validate the inputs
    $getReservationId = mysqli_real_escape_string($conn, $_POST['rv_id']);
    $postDate = mysqli_real_escape_string($conn, $_POST['date']);
    $postAmount = mysqli_real_escape_string($conn, $_POST['amount']);
    $postMethod = mysqli_real_escape_string($conn, $_POST['method']);
    $postNote = mysqli_real_escape_string($conn, $_POST['note']);

    // Assuming you have $adminDetail variable available from somewhere
    // Admin ID
    $adminDetail = $_SESSION['admin'];
    $adminId = $adminDetail['a_id'];

    // Prepare and bind the SQL statement
    $stmt = $conn->prepare("INSERT INTO deposit (rv_id, dp_received_at, dp_amount, dp_method, dp_note, a_id) VALUES (?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("isdisi", $getReservationId, $postDate, $postAmount, $postMethod, $postNote, $adminId);

    // Execute the statement
    if ($stmt->execute()) {
        echo "Data inserted successfully";
    } else {
        echo "Error: " . $stmt->error;
    }

    // Close the statement
    $stmt->close();
} else {
    echo "Invalid request method";
}
?>
