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

$m = new Manager();
$supplier_id = $_REQUEST['supplier_id'] ?? null; // Fetch the supplier_id from the request

if ($supplier_id) {
    // Define the filter condition for fetching bank details
    $filter = "WHERE supplier_id = '$supplier_id' AND status = 'active'";
    
    // Fetch the list of bank details using the existing SupplierBankSetup class method
    $banks = SupplierBankSetup::GetBankSetupList($filter);

    if ($banks) {
        // Transform the bank details into the required JSON structure
        $response = array_map(function ($bank) {
            return [
                'id' => $bank->id,
                'deposit_bank_name' => $bank->bank_name,
                'deposit_account_no' => $bank->bank_account_number,
            ];
        }, $banks);

        // Output the transformed data as a JSON response
        echo json_encode($response);
    } else {
        // If no bank details are found, return an appropriate error message
        echo json_encode(['error' => 'No banks found for the supplier']);
    }
} else {
    // If no supplier_id is provided, return an error
    echo json_encode(['error' => 'Invalid supplier ID']);
}
?>