<?php
include 'config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $agency_id = $_SESSION['agency_id'];
    $client_id = $_POST['client_id'];
    $amount    = $_POST['amount'];
    $method    = $_POST['method'];
    $date      = $_POST['p_date'];
    $notes     = $_POST['notes'];

    $stmt = $conn->prepare("INSERT INTO payments (agency_id, client_id, amount_paid, payment_method, payment_date, notes) VALUES (?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("iissss", $agency_id, $client_id, $amount, $method, $date, $notes);

    if ($stmt->execute()) {
        header("Location: ledger.php?msg=PaymentRecorded");
    } else {
        echo "Error: " . $conn->error;
    }
}
?>