File "historico_completo.php.bak"

Full Path: C:/wamp64/www/casos_medicos/ausentismos/historico_completo.php.bak
File size: 8.4 KB
MIME-type: text/x-php
Charset: utf-8

<?php
include(__DIR__ . "/../conexion.php");

// Filtros
$cedula = $_GET['cedula'] ?? '';
$fecha_inicio = $_GET['fecha_inicio'] ?? '';
$fecha_fin = $_GET['fecha_fin'] ?? '';
$empresa = $_GET['empresa'] ?? '';

// WHERE dinámico
$where = "WHERE 1=1";

if ($cedula !== '') {
    $cedula = preg_replace('/\D/','',$cedula);
    $where .= " AND cedula = '".$conn->real_escape_string($cedula)."'";
}

if ($empresa !== '') {
    $where .= " AND empresa LIKE '%".$conn->real_escape_string($empresa)."%'";
}

if ($fecha_inicio !== '') {
    $where .= " AND fecha_inicio >= '".$conn->real_escape_string($fecha_inicio)."'";
}

if ($fecha_fin !== '') {
    $where .= " AND fecha_fin <= '".$conn->real_escape_string($fecha_fin)."'";
}

// Obtener registros
$sql = "SELECT * FROM ausentismo $where ORDER BY fecha_registro DESC";
$res = $conn->query($sql);

$total_registros = $res ? $res->num_rows : 0;
?>

<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Histórico de Ausentismos</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">

<style>
body { background:#f4f7f4; }

/* Título */
.titulo-box{
    background:#2d7a2e;
    color:white;
    padding:12px 18px;
    border-radius:8px;
    margin-bottom:18px;
    display:flex;
    justify-content:space-between;
    align-items:center;
}

/* Botón volver */
.btn-volver{
    background:white;
    border:2px solid white;
    color:#2d7a2e;
    font-weight:600;
    border-radius:50px;
    padding:6px 14px;
}
.btn-volver:hover{
    background:#eaf6ea;
    color:#1f5a20;
}

/* Tarjeta resumen tipo dashboard */
.card-resumen {
    border-radius: 10px;
    background:white;
    padding:18px;
    box-shadow:0 0 10px rgba(0,0,0,0.09);
    border-left:6px solid #2d7a2e;
    width:260px;
}

/* Encabezados de tabla */
.table thead th {
    background-color: #e6f4ea !important;
    color: #3e4a3e !important;
    font-weight: 600;
    border-bottom: 2px solid #2d7a2e !important;
}

.table tbody tr:hover { background:#f1f5f1; }

/* Panel de anexos */
.anexos-panel {
    border:1px solid #e9ecef;
    border-radius:6px;
    background:#fafafa;
}
.anexos-panel .panel-head {
    padding:6px 10px;
    border-bottom:1px solid #eee;
    display:flex;
    justify-content:space-between;
    align-items:center;
}
.anexos-panel .panel-body { padding:10px; }
</style>
</head>

<body>

<div class="container-fluid py-3">

<!-- TÍTULO + VOLVER -->
<div class="titulo-box">
    <h4 class="m-0">
        <i class="bi bi-collection"></i> Detalle General de Ausentismos
    </h4>

    <a href=".\index.php" class="btn btn-volver">
        <i class="bi bi-arrow-left-circle"></i> Volver
    </a>
</div>

<!-- TARJETA RESUMEN -->
<div class="card-resumen mb-4">
    <h6 class="text-success mb-1">
        <i class="bi bi-bar-chart-line"></i> Total registros
    </h6>
    <div class="fs-3 fw-bold text-dark">
        <?= number_format($total_registros) ?>
    </div>
</div>

<!-- FILTROS -->
<form class="row g-2 mb-4">
    <div class="col-auto">
        <input type="text" name="cedula" placeholder="Cédula"
               value="<?=htmlspecialchars($cedula)?>"
               class="form-control form-control-sm">
    </div>

    <div class="col-auto">
        <input type="text" name="empresa" placeholder="Empresa"
               value="<?=htmlspecialchars($empresa)?>"
               class="form-control form-control-sm">
    </div>

    <div class="col-auto">
        <input type="date" name="fecha_inicio"
               value="<?=htmlspecialchars($fecha_inicio)?>"
               class="form-control form-control-sm">
    </div>

    <div class="col-auto">
        <input type="date" name="fecha_fin"
               value="<?=htmlspecialchars($fecha_fin)?>"
               class="form-control form-control-sm">
    </div>

    <div class="col-auto">
        <button class="btn btn-sm btn-success"><i class="bi bi-search"></i> Filtrar</button>

        <a href="historico_completo.php" class="btn btn-sm btn-secondary">
            <i class="bi bi-eraser"></i> Limpiar
        </a>
    </div>
</form>

<!-- TABLA -->
<div class="table-responsive">
<table class="table table-bordered table-hover align-middle">
<thead>
<tr>
    <th>#</th>
    <th>Cédula</th>
    <th>Empresa</th>
    <th>Fecha Registro</th>
    <th>Fecha Inicio</th>
    <th>Fecha Fin</th>
    <th>Días</th>
    <th>Tipo</th>
    <th>EPS</th>
    <th>Diagnóstico</th>
    <th>Anexos</th>
</tr>
</thead>
<tbody>

<?php if($res && $res->num_rows > 0): ?>
<?php while($row = $res->fetch_assoc()): ?>

<tr>
    <td><?= $row['id'] ?></td>
    <td><?= htmlspecialchars($row['cedula']) ?></td>
    <td></td> <!-- Empresa en blanco -->
    <td><?= htmlspecialchars($row['fecha_registro']) ?></td>
    <td><?= htmlspecialchars($row['fecha_inicio']) ?></td>
    <td><?= htmlspecialchars($row['fecha_fin']) ?></td>
    <td><?= htmlspecialchars($row['dias']) ?></td>
    <td><?= htmlspecialchars($row['tipo_incapacidad']) ?></td>
    <td><?= htmlspecialchars($row['eps']) ?></td>
    <td></td> <!-- Diagnóstico en blanco -->

    <!-- ANEXOS -->
    <td>
        <?php
        $archivos = [
            "certificado"     => "Certificado",
            "epicrisis"       => "Epicrisis",
            "furips"          => "FURIPS",
            "registro_civil"  => "Registro Civil"
        ];

        $hay = false;
        foreach($archivos as $campo=>$titulo){
            if(!empty($row[$campo])){ $hay=true; break; }
        }

        if(!$hay){
            echo "<small class='text-muted'>Sin anexos</small>";
        } else {
            $unique = "anexos_" . $row['id'];
        ?>

        <button class="btn btn-sm btn-outline-secondary anexos-toggle"
                data-bs-toggle="collapse"
                data-bs-target="#<?= $unique ?>">
            <i class="bi bi-folder2-open icono-anexo"></i>
        </button>

        <div class="collapse mt-2" id="<?= $unique ?>">
            <div class="anexos-panel">
                <div class="panel-head">
                    <strong>Anexos</strong>
                    <button type="button" class="btn btn-sm btn-outline-danger cerrar-anexos"
                            data-target="#<?= $unique ?>">
                        <i class="bi bi-x-lg"></i>
                    </button>
                </div>

                <div class="panel-body d-grid gap-1">

                <?php foreach($archivos as $campo=>$titulo): ?>
                    <?php if(!empty($row[$campo])): ?>
                    <a href="ver_anexo.php?id=<?=intval($row['id'])?>&campo=<?=$campo?>"
                       target="_blank"
                       class="btn btn-sm btn-outline-primary text-start">
                        <i class="bi bi-file-earmark"></i> <?= $titulo ?>
                    </a>
                    <?php endif; ?>
                <?php endforeach; ?>

                </div>
            </div>
        </div>

        <?php } ?>
    </td>
</tr>

<?php endwhile; ?>
<?php else: ?>
<tr><td colspan="11" class="text-center text-muted py-3">No hay registros</td></tr>
<?php endif; ?>

</tbody>
</table>
</div>

</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<script>
(function(){
    // Iconos de abrir/cerrar
    document.querySelectorAll('.anexos-toggle').forEach(btn => {
        const target = btn.dataset.bsTarget;
        const el = document.querySelector(target);

        el.addEventListener('show.bs.collapse', () => {
            btn.querySelector('.icono-anexo')
               .classList.replace('bi-folder2-open','bi-folder-symlink');
        });

        el.addEventListener('hide.bs.collapse', () => {
            btn.querySelector('.icono-anexo')
               .classList.replace('bi-folder-symlink','bi-folder2-open');
        });
    });

    // Botón cerrar
    document.querySelectorAll('.cerrar-anexos').forEach(btn => {
        btn.onclick = () => {
            const target = btn.dataset.target;
            const el = document.querySelector(target);
            bootstrap.Collapse.getOrCreateInstance(el).hide();
        };
    });
})();
</script>

</body>
</html>