<?php
require_once __DIR__ . '/../../engine/engine.php';
header('Content-Type: application/json; charset=utf-8');

try {
$pid = (int)($_GET['pid'] ?? 0);
if ($pid <= 0) throw new RuntimeException('Missing pid');

$stmt = $pdo->prepare("SELECT id, label, category, value, currency, notes, updated_at
	FROM depot_manual_assets
	WHERE portfolio_id = :pid
	ORDER BY label");
	$stmt->execute([':pid' => $pid]);
	$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
	
	echo json_encode(['success' => true, 'data' => $rows]);
} catch (Throwable $e) {
	http_response_code(400);
	echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}