<?php
// submit_transaction.php
include('includes/dbconn.php'); // Include the database connection

$accountId = $_POST['account_id'];
$companyId = $_SESSION['company_id'];// From session
$amount = $_POST['amount'];
$type = $_POST['type'];
$date = $_POST['date'];
$description = $_POST['description'] ?? '';

//$stmt = $conn->prepare("INSERT INTO transactions (company_id, account_id, amount, type, transaction_date, description) VALUES (?, ?, ?, ?, ?, ?)");

$stmt = $conn->prepare("INSERT INTO transactions (company_id, account_id, amount, type, transaction_date, description) VALUES (?, ?, ?, ?, ?, ?)");

if ($stmt === false) {
    die("Error preparing statement: " . $conn->error);
}

$stmt->bind_param("iidsss", $companyId, $accountId, $amount, $type, $date, $description);
$stmt->execute();

if ($stmt->error) {
    echo "Error: " . $stmt->error;
} else {
    echo "Transaction recorded successfully.";
    header("Location: coa.php");
    exit(); // Always call exit after header redirects
}

$stmt->close();
$conn->close();
?>
