<?php
include '../../config.php';
header('Content-Type: application/json');

$customer_id = intval($_GET['customer_id'] ?? 0);
$loan_id     = intval($_GET['loan_id'] ?? 0);

$sql = "SELECT id, customer_id, loan_id, document_path, date
        FROM documents
        WHERE customer_id = $customer_id
          AND loan_id = $loan_id";
$result = mysqli_query($conn, $sql);

$docs = [];
while ($row = mysqli_fetch_assoc($result)) {
    $docs[] = $row;
}
echo json_encode($docs);