<?php
require_once __DIR__ . '/../auth/verifica.php';
require_once __DIR__ . "/../config/conexao.php";

$sql = "SELECT r.*, c.nome as cliente 
        FROM recibos r
        JOIN clientes c ON r.cliente_id = c.id
        ORDER BY r.id DESC";

$dados = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Recibos</title>

<style>
body { font-family: Arial; background:#f4f4f4; }
.container { width:95%; margin:auto; background:#fff; padding:20px; }

table { width:100%; border-collapse: collapse; }
th, td { padding:10px; border-bottom:1px solid #ddd; }

.acoes a { margin-right:10px; text-decoration:none; }

</style>
</head>
<body>

<div class="container">

<h2>🧾 Histórico de Recibos</h2>

<table>
<tr>
<th>Nº</th>
<th>Cliente</th>
<th>Valor</th>
<th>Data</th>
<th>Ações</th>
</tr>

<?php foreach($dados as $d){ ?>

<tr>
<td><?= $d['numero_recibo'] ?></td>

<td><?= $d['cliente'] ?></td>

<td>R$ <?= number_format($d['valor'],2,',','.') ?></td>

<td><?= date("d/m/Y", strtotime($d['data_pagamento'])) ?></td>

<td class="acoes">
    <a href="visualizar_recibo.php?id=<?= $d['id'] ?>">👁 Ver</a>
    <a href="baixar_recibo.php?id=<?= $d['id'] ?>">⬇ PDF</a>
    <a href="enviar_recibo.php?id=<?= $d['id'] ?>">📲 Enviar</a>
</td>

</tr>

<?php } ?>

</table>

</div>

</body>
</html>