<?php
session_start();
include "conexion.php";

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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);
    $idinv = $data['idinv'] ?? null;

    if (!$idinv) {
        echo json_encode(['success' => false]);
        exit;
    }

    $sql = "SELECT reninv FROM inversionista WHERE idinv = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i", $idinv);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();

    if ($row) {
        echo json_encode([
            'success' => true,
            'rendimiento' => floatval($row['reninv'])
        ]);
    } else {
        echo json_encode(['success' => false]);
    }

    $stmt->close();
    $conn->close();
}
?>