File "exportar_pdf.php.bak"
Full Path: C:/wamp64/www/APPSST/Admin/firmadot/exportar_pdf.php.bak
File size: 16.36 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start();
require_once('../../bd/conexion.php');
// Verificar que se recibió la cédula
if (!isset($_GET['cedula']) || empty($_GET['cedula'])) {
die('Error: No se especificó la cédula del empleado.');
}
$cedula_busqueda = $_GET['cedula'];
// Consultar los datos del empleado
$query = "SELECT * FROM entregasst WHERE cedula = '$cedula_busqueda' ORDER BY FIRMA IS NULL DESC, fEntrega DESC";
$result = $conexion->query($query);
if (!$result || $result->num_rows == 0) {
die('Error: No se encontraron entregas para esta cédula.');
}
$resultados = $result->fetch_all(MYSQLI_ASSOC);
$primer_registro = $resultados[0];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="../img/icono.png">
<title>Entregas EPP - <?= htmlspecialchars($cedula_busqueda) ?></title>
<style>
@media print {
.no-print { display: none !important; }
body { margin: 0; }
.page-break { page-break-before: always; }
}
@page {
size: A4 landscape;
margin: 10mm;
}
body {
font-family: Arial, sans-serif;
font-size: 10px;
margin: 0;
color: #333;
background: white;
}
.container {
max-width: 100%;
margin: 0 auto;
}
.header {
text-align: center;
margin-bottom: 15px;
border-bottom: 3px solid #FF8A37;
padding-bottom: 10px;
}
.header h1 {
color: #FF8A37;
margin: 0;
font-size: 18px;
}
.header h2 {
color: #666;
margin: 3px 0;
font-size: 12px;
}
.empleado-info {
background-color: #f8f9fa;
padding: 10px;
border-radius: 3px;
margin-bottom: 15px;
border-left: 4px solid #FF8A37;
}
.empleado-info h3 {
margin: 0 0 8px 0;
color: #FF8A37;
font-size: 12px;
}
.info-row {
display: flex;
justify-content: space-between;
margin-bottom: 3px;
}
.info-col {
flex: 1;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
font-size: 8px;
}
th, td {
border: 1px solid #333;
padding: 4px 2px;
text-align: left;
vertical-align: top;
}
th {
background-color: #FF8A37;
color: white;
font-weight: bold;
text-align: center;
font-size: 7px;
}
.status-signed {
background-color: #d1e7dd;
}
.status-pending {
background-color: #fff3cd;
}
.text-center {
text-align: center;
}
.text-success {
color: #28a745;
font-weight: bold;
}
.text-warning {
color: #ffc107;
font-weight: bold;
}
/* ★★★ ESTILOS ESPECÍFICOS PARA FIRMAS ★★★ */
.firma-container {
text-align: center;
padding: 2px;
}
.firma-img {
max-width: 80px;
max-height: 40px;
border: 1px solid #ddd;
border-radius: 3px;
background-color: white;
}
.firma-pendiente {
color: #999;
font-style: italic;
font-size: 7px;
}
.resumen {
margin-top: 15px;
padding: 10px;
background-color: #e9ecef;
border-radius: 3px;
border-left: 4px solid #6c757d;
}
.resumen h4 {
margin: 0 0 8px 0;
color: #495057;
font-size: 10px;
}
.resumen-row {
display: flex;
justify-content: space-between;
margin-bottom: 3px;
font-size: 9px;
}
.footer {
margin-top: 20px;
text-align: center;
font-size: 7px;
color: #666;
border-top: 1px solid #ddd;
padding-top: 10px;
}
.btn-container {
text-align: center;
margin: 20px 0;
padding: 20px;
background-color: #f8f9fa;
border-radius: 5px;
}
.btn {
background-color: #FF8A37;
color: white;
padding: 12px 25px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
margin: 0 10px;
text-decoration: none;
display: inline-block;
transition: background-color 0.3s;
}
.btn:hover {
background-color: #e67e22;
}
.btn-secondary {
background-color: #6c757d;
}
.btn-secondary:hover {
background-color: #5a6268;
}
.btn i {
margin-right: 8px;
}
/* ★★★ ESTILOS PARA MEJORAR LA VISUALIZACIÓN DE FIRMAS ★★★ */
.entrega-row {
page-break-inside: avoid;
}
.firma-cell {
width: 90px;
min-width: 90px;
max-width: 90px;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
</head>
<body>
<div class="container">
<div class="btn-container no-print">
<button class="btn" onclick="window.print()" title="Imprimir o guardar como PDF">
<i class="fas fa-file-pdf"></i> Generar PDF con Firmas
</button>
<a href="ENTREFIRMA.PHP?cedula=<?= urlencode($cedula_busqueda) ?>" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Volver
</a>
<div style="margin-top: 10px; font-size: 12px; color: #666;">
<i class="fas fa-info-circle"></i> Las firmas digitales se incluirán en el PDF generado
</div>
</div>
<div class="header">
<h1>REGISTRO DE ENTREGAS EPP</h1>
<h2>Reporte Individual de Empleado con Firmas Digitales</h2>
<p><strong>Fecha de generación:</strong> <?= date('d/m/Y H:i:s') ?></p>
</div>
<div class="empleado-info">
<h3>Información del Empleado</h3>
<div class="info-row">
<div class="info-col">
<p><strong>Cédula:</strong> <?= htmlspecialchars($primer_registro['cedula']) ?></p>
<p><strong>Nombre:</strong> <?= htmlspecialchars($primer_registro['nombre'] ?? 'No especificado') ?></p>
</div>
<div class="info-col">
<p><strong>Centro de Costo:</strong> <?= htmlspecialchars($primer_registro['ccosto'] ?? 'No especificado') ?></p>
<p><strong>Cargo:</strong> <?= htmlspecialchars($primer_registro['cargo'] ?? 'No especificado') ?></p>
</div>
</div>
</div>
<table>
<thead>
<tr>
<th style="width: 8%;">Fecha</th>
<th style="width: 10%;">Tipo Entrega</th>
<th style="width: 6%;">Estado</th>
<th style="width: 6%;">Devolutivo</th>
<th style="width: 25%;">EPP Entregado</th>
<th style="width: 4%;">Cant.</th>
<th style="width: 12%;">Entregado por</th>
<th style="width: 8%;">Estado Firma</th>
<th style="width: 6%;">Código</th>
<th style="width: 15%;">Firma Digital</th>
</tr>
</thead>
<tbody>
<?php
$total_entregas = 0;
$entregas_firmadas = 0;
foreach ($resultados as $entrega):
$tieneFirma = !empty($entrega['FIRMA']);
$rowClass = $tieneFirma ? 'status-signed' : 'status-pending';
$total_entregas++;
if ($tieneFirma) $entregas_firmadas++;
?>
<tr class="<?= $rowClass ?> entrega-row">
<td class="text-center"><?= date('d/m/Y', strtotime($entrega['fEntrega'])) ?></td>
<td><?= htmlspecialchars($entrega['tpEntrega']) ?></td>
<td class="text-center"><?= htmlspecialchars($entrega['tpEstado']) ?></td>
<td class="text-center"><?= htmlspecialchars($entrega['tpDevolutivo']) ?></td>
<td><?= htmlspecialchars($entrega['epp']) ?></td>
<td class="text-center"><?= htmlspecialchars($entrega['cantidad'] ?? '1') ?></td>
<td><?= htmlspecialchars($entrega['userEntrega'] ?? 'No especificado') ?></td>
<td class="text-center">
<?php if ($tieneFirma): ?>
<span class="text-success">FIRMADO</span>
<?php else: ?>
<span class="text-warning">PENDIENTE</span>
<?php endif; ?>
</td>
<td class="text-center"><?= htmlspecialchars($entrega['codigo'] ?? 'N/A') ?></td>
<td class="firma-cell">
<div class="firma-container">
<?php if ($tieneFirma): ?>
<?php
// ★★★ MOSTRAR LA FIRMA DIGITAL ★★★
$firma_src = htmlspecialchars($entrega['FIRMA']);
// Verificar si la firma es una URL completa o datos base64
if (strpos($firma_src, 'data:image') === 0) {
// Es una imagen base64, usarla directamente
echo '<img src="' . $firma_src . '" class="firma-img" alt="Firma digital" title="Firmado el ' . date('d/m/Y', strtotime($entrega['fEntrega'])) . '">';
} elseif (strpos($firma_src, 'http') === 0) {
// Es una URL completa, usarla directamente
echo '<img src="' . $firma_src . '" class="firma-img" alt="Firma digital" title="Firmado el ' . date('d/m/Y', strtotime($entrega['fEntrega'])) . '">';
} elseif (!empty($firma_src)) {
// Es una ruta relativa, construir la URL completa
$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'];
$firma_url = $base_url . '/' . ltrim($firma_src, '/');
echo '<img src="' . $firma_url . '" class="firma-img" alt="Firma digital" title="Firmado el ' . date('d/m/Y', strtotime($entrega['fEntrega'])) . '">';
} else {
echo '<span class="firma-pendiente">Sin firma</span>';
}
?>
<div style="font-size: 6px; color: #666; margin-top: 2px;">
Firmado: <?= date('d/m/Y', strtotime($entrega['fEntrega'])) ?>
</div>
<?php else: ?>
<span class="firma-pendiente">Pendiente de firma</span>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
$entregas_pendientes = $total_entregas - $entregas_firmadas;
$porcentaje = $total_entregas > 0 ? round(($entregas_firmadas / $total_entregas) * 100, 1) : 0;
?>
<div class="resumen">
<h4>Resumen de Entregas y Firmas</h4>
<div class="resumen-row">
<div><strong>Total de entregas:</strong> <?= $total_entregas ?></div>
<div><strong>Entregas firmadas:</strong> <span class="text-success"><?= $entregas_firmadas ?></span></div>
</div>
<div class="resumen-row">
<div><strong>Entregas pendientes:</strong> <span class="text-warning"><?= $entregas_pendientes ?></span></div>
<div><strong>Porcentaje completado:</strong> <?= $porcentaje ?>%</div>
</div>
<div class="resumen-row">
<div><strong>Firmas digitales incluidas:</strong> <?= $entregas_firmadas ?></div>
<div><strong>Estado de cumplimiento:</strong>
<?php if ($porcentaje >= 100): ?>
<span class="text-success">COMPLETO</span>
<?php elseif ($porcentaje >= 50): ?>
<span style="color: #ffc107;">PARCIAL</span>
<?php else: ?>
<span class="text-warning">PENDIENTE</span>
<?php endif; ?>
</div>
</div>
</div>
<div class="footer">
<p><strong>CERTIFICACIÓN DE FIRMAS DIGITALES</strong></p>
<p>Este documento contiene <?= $entregas_firmadas ?> firma(s) digital(es) válida(s) capturada(s) electrónicamente</p>
<p>Las firmas mostradas corresponden a la aceptación y recibo de los elementos de protección personal</p>
<p>Documento generado automáticamente por el Sistema de Gestión de EPP</p>
<p>Fecha y hora de generación: <?= date('d/m/Y H:i:s') ?> | Usuario: <?= isset($_SESSION['DIGITA']) ? $_SESSION['DIGITA'] : 'Sistema' ?></p>
</div>
</div>
<script>
// Función para imprimir automáticamente si viene con parámetro
if (window.location.search.includes('autoprint=1')) {
window.onload = function() {
setTimeout(function() {
window.print();
}, 1000); // Dar tiempo para que carguen las imágenes
}
}
// Mejorar la experiencia de impresión
window.addEventListener('beforeprint', function() {
document.title = 'Entregas_EPP_con_Firmas_<?= $cedula_busqueda ?>_<?= date("Y-m-d") ?>';
});
// ★★★ VERIFICAR QUE LAS IMÁGENES DE FIRMAS SE CARGUEN CORRECTAMENTE ★★★
window.addEventListener('load', function() {
const firmaImages = document.querySelectorAll('.firma-img');
let imagenesCorrectas = 0;
let totalImagenes = firmaImages.length;
firmaImages.forEach(function(img, index) {
img.onload = function() {
imagenesCorrectas++;
console.log('Firma ' + (index + 1) + ' cargada correctamente');
};
img.onerror = function() {
console.error('Error cargando firma ' + (index + 1) + ': ' + img.src);
// Mostrar un placeholder en caso de error
img.style.display = 'none';
img.parentNode.innerHTML += '<div style="color: red; font-size: 7px;">Error: Firma no disponible</div>';
};
});
// Mostrar estadísticas de carga
setTimeout(function() {
console.log('Firmas cargadas: ' + imagenesCorrectas + '/' + totalImagenes);
}, 2000);
});
</script>
</body>
</html>