<?php
session_start();
include("fphp.php");
$enlace = cargar_conexion();

// Consulta de lotes disponibles
$query = "
    SELECT fecha_registro, COUNT(*) AS cantidad, SUM(monto) AS total, desconcepto
    FROM historico_pagos_conectiv
    WHERE estado_aprobacion_2 = 'Aprobado'
    GROUP BY fecha_registro, desconcepto
    ORDER BY fecha_registro ASC
";
menu();
$result = mysqli_query($enlace, $query);
?>

            <div class="saireh-container">

                <h2 class="saireh-title">Generar TXT Banco Mercantil</h2>

                <table class="saireh-table">
                    <tr>
                        <th>Fecha Registro</th>
                        <th>Detalle</th>
                        <th>Cantidad Registros</th>
                        <th>Monto Total</th>
                        <th>Acción</th>
                    </tr>

                    <?php while ($row = mysqli_fetch_assoc($result)) { ?>
                        <tr>
                            <td><?= $row['fecha_registro'] ?></td>
                            <td><?= $row['desconcepto'] ?></td>
                            <td><?= $row['cantidad'] ?></td>
                            <td><?= number_format($row['total'], 2, ',', '.') ?></td>
                            <td>
                                <a href="txt_pago_conectiv.php?fecha=<?= $row['fecha_registro'] ?>" 
                                class="boton-saireh">
                                    Generar TXT
                                </a>
                            </td>
                        </tr>
                    <?php } ?>

                </table>

            </div>

<style>

/* CONTENEDOR */
.saireh-container {
    width: 90%;
    max-width: 1100px;
    margin: 40px auto;
    background: #ffffff;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.12);
}

/* TÍTULO */
.saireh-title {
    text-align: center;
    color: #003366;
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 20px;
}

/* TABLA */
.saireh-table {
    width: 100%;
    border-collapse: collapse;
    border-radius: 10px;
    overflow: hidden;
}

.saireh-table th {
    background: #36C1E2;
    color: white;
    padding: 12px;
    font-size: 14px;
    letter-spacing: 0.3px;
    text-align: left;
}

.saireh-table td {
    padding: 12px;
    font-size: 14px;
    color: #333;
    border-bottom: 1px solid #e5e5e5;
}

.saireh-table tr:hover {
    background: #eef5f9;
}

/* BOTÓN */
.boton-saireh {
    background: #0066cc;
    color: white;
    padding: 7px 14px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    transition: 0.2s;
}

.boton-saireh:hover {
    background: #004c99;
}
</style>