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

$uploadsDir = __DIR__ . '/uploads/transactions';
$transactionId = intval($_GET['transactionId'] ?? 0);
$folder = 'invoices'; // fixed for invoices table

$transactionDir = "$uploadsDir/transaction_$transactionId/$folder";

$files = [];
if (is_dir($transactionDir)) {
    $files = array_values(array_filter(scandir($transactionDir), function($f) {
        return !in_array($f, ['.', '..']);
    }));
}

echo json_encode(['success' => true, 'files' => $files]);
