<?php
include 'db.php';

$bank_name = trim($_POST['bank_name'] ?? '');
$account_title = trim($_POST['account_title'] ?? '');
$account_number = trim($_POST['account_number'] ?? '');
$iban = trim($_POST['iban'] ?? '');
$branch_name = trim($_POST['branch_name'] ?? '');
$branch_code = trim($_POST['branch_code'] ?? '');
$swift_code = trim($_POST['swift_code'] ?? '');
$address = trim($_POST['address'] ?? '');
$is_active = isset($_POST['is_active']) ? 1 : 0;

if ($bank_name && $account_title && $account_number) {
    $stmt = $conn->prepare("INSERT INTO bank_accounts 
        (bank_name, account_title, account_number, iban, branch_name, branch_code, swift_code, address, is_active) 
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("ssssssssi", $bank_name, $account_title, $account_number, $iban, $branch_name, $branch_code, $swift_code, $address, $is_active);
    $stmt->execute();
    header("Location: bank_account_list.php?success=1");
    exit;
} else {
    echo "Missing required fields!";
}
