<?php
include("../classes/manager.class.php");

$m = new Manager();

// Get supplier ID from request
$supplierId = isset($_GET['supplier_id']) ? intval($_GET['supplier_id']) : 0;

if ($supplierId > 0) {
    // Define filter for active suppliers
    $filter = "WHERE supplier_id = '$supplierId' AND status = 'active'";
    $banks = SupplierBankSetup::GetBankList($filter); // Fetch bank details from DB

    // If banks are found, format them as JSON
    if ($banks) {
        echo json_encode(array_map(function ($bank) {
            return [
                'id' => $bank->id,
                'bank_name' => $bank->bank_name,
                'bank_account_number' => $bank->bank_account_number,
            ];
        }, $banks));
    } else {
        // Return an empty array if no banks are found
        echo json_encode([]);
    }
} else {
    // Return an empty array if the supplier ID is invalid
    echo json_encode([]);
}
?>
