<?php
include_once('../config.php');

$id_conta = $_GET['id'] ?? null;
$valor_pago = $_GET['pago'] ?? 0;

if (!$id_conta) { echo "ERRO: RECIBO INVÁLIDO"; exit; }

$busca = $conn->query("SELECT * FROM CONTAS_RECEBER WHERE ID = '$id_conta'");
$c = $busca->fetch_assoc();
?>

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>RECIBO DE PAGAMENTO</title>
    <style>
        body { font-family: 'Courier New', monospace; width: 300px; margin: 0; padding: 10px; text-transform: uppercase; font-size: 12px; }
        .text-center { text-align: center; }
        .linha { border-bottom: 1px dashed #000; margin: 10px 0; }
        .bold { font-weight: bold; }
        .btn-print { background: #000; color: #fff; padding: 5px; border: none; width: 100%; cursor: pointer; margin-top: 20px; }
        @media print { .btn-print { display: none; } }
    </style>
</head>
<body onload="window.print()">

    <div class="text-center">
        <span class="bold" style="font-size: 16px;">COMPROVANTE DE PAGAMENTO</span><br>
        LOJA DE VARIEDADES - PDV
    </div>

    <div class="linha"></div>

    <p>DATA/HORA: <?php echo date('d/m/Y H:i:s'); ?></p>
    <p>CLIENTE: <span class="bold"><?php echo $c['CLIENTE_NOME']; ?></span></p>
    <p>VENDA REF: #<?php echo $c['VENDA_ID']; ?></p>

    <div class="linha"></div>

    <div style="display: flex; justify-content: space-between;">
        <span>VALOR PAGO AGORA:</span>
        <span class="bold">R$ <?php echo number_format($valor_pago, 2, ',', '.'); ?></span>
    </div>

    <div style="display: flex; justify-content: space-between; margin-top: 5px;">
        <span>SALDO RESTANTE:</span>
        <span class="bold">R$ <?php echo number_format($c['VALOR_TOTAL'], 2, ',', '.'); ?></span>
    </div>

    <div class="linha"></div>

    <div class="text-center" style="margin-top: 20px;">
        ___________________________<br>
        ASSINATURA RESPONSÁVEL
    </div>

    <p class="text-center" style="font-size: 10px; margin-top: 15px;">
        OBRIGADO PELA PREFERÊNCIA!
    </p>

    <button class="btn-print" onclick="window.print()">IMPRIMIR RECIBO</button>

</body>
</html>