<?php
session_start();
include("../bd/conexion.php");
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gestión de Devolutivos</title>
<link rel="icon" type="image/png" href="../img/icono.png">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
body {
background-image: linear-gradient(to right, #e2e2e2, #ffe5c9);
padding: 20px;
}
.container {
margin-top: 30px;
}
.search-box {
background-color: #f8f9fa;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.results-table {
margin-top: 20px;
}
.table th {
background-color: #343a40;
color: white;
}
.btn-update {
min-width: 80px;
}
.alert-success {
background-color: #d4edda;
color: #155724;
border-color: #c3e6cb;
}
.header-actions {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">
<a href="../dotacion/MENUP.PHP" class="btn btn-secondary"><i class="fas fa-home"></i> Menú Principal</a>
<div class="card">
<div class="card-header" style="background-color: #FF8A37; color: white;">
<h4>Gestión de Elementos Devolutivos</h4>
</div>
<?php
// Mostrar mensajes de éxito/error
if(isset($_SESSION['mensaje'])) {
echo '<div class="alert alert-'.$_SESSION['tipo_mensaje'].' alert-dismissible fade show" role="alert">';
echo $_SESSION['mensaje'];
echo '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
echo '</div>';
// Limpiar mensajes después de mostrarlos
unset($_SESSION['mensaje']);
unset($_SESSION['tipo_mensaje']);
}
?>
<div class="search-box">
<form method="GET" action="">
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label for="cedula"><strong>Buscar por Cédula:</strong></label>
<input type="text" class="form-control" id="cedula" name="cedula"
placeholder="Ingrese número de cédula" required
value="<?php echo isset($_GET['cedula']) ? htmlspecialchars($_GET['cedula']) : ''; ?>">
</div>
</div>
<div class="col-md-4 d-flex align-items-end">
<button type="submit" class="btn w-100" style="background-color: #FF8A37; color: white;">
<i class="fas fa-search"></i> Buscar
</button>
</div>
</div>
</form>
</div>
<?php
// Procesar búsqueda
if(isset($_GET['cedula'])) {
$cedula = mysqli_real_escape_string($conexion, $_GET['cedula']);
// Consulta modificada para excluir registros con entrego = 'Si'
$query = "SELECT id, fEntrega, cedula, nombre, codigo, epp, cantidad, entrego
FROM entregasst
WHERE cedula = '$cedula'
AND tpDevolutivo = 'Si'
AND (entrego IS NULL OR entrego != 'Si')
ORDER BY fEntrega DESC";
$result = mysqli_query($conexion, $query);
if(mysqli_num_rows($result) > 0) {
?>
<div class="table-responsive results-table">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Fecha Entrega</th>
<th>Cédula</th>
<th>Nombre</th>
<th>Código</th>
<th>EPP</th>
<th>Cantidad</th>
<th>Estado</th>
<th>Entrego</th>
<th>Observacion</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".date('d/m/Y', strtotime($row['fEntrega']))."</td>";
echo "<td>".$row['cedula']."</td>";
echo "<td>".$row['nombre']."</td>";
echo "<td>".$row['codigo']."</td>";
echo "<td>".$row['epp']."</td>";
echo "<td>".$row['cantidad']."</td>";
echo "<td>".($row['entrego'] ? $row['entrego'] : 'Pendiente')."</td>";
echo "<td>";
echo "<form method='POST' action='actualizar_devolutivo.php' class='d-flex'>";
echo "<input type='hidden' name='id' value='".$row['id']."'>";
echo "<select name='entrego' class='form-select form-select-sm me-2'>";
echo "<option value='Si'".($row['entrego'] == 'Si' ? ' selected' : '').">Si</option>";
echo "<option value='No'".($row['entrego'] == 'No' ? ' selected' : '').">No</option>";
echo "</select>";
echo "<button type='submit' class='btn btn-sm btn-success btn-update'>";
echo "<i class='fas fa-save'></i> Guardar";
echo "</button>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
<?php
} else {
echo "<div class='alert alert-success'>No hay elementos devolutivos pendientes para la cédula $cedula</div>";
}
}
?>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Función para confirmar antes de actualizar
document.querySelectorAll('form').forEach(form => {
form.addEventListener('submit', function(e) {
if(!confirm('¿Está seguro de actualizar el estado de este elemento?')) {
e.preventDefault();
}
});
});
// Cerrar automáticamente las alertas después de 5 segundos
setTimeout(() => {
const alerts = document.querySelectorAll('.alert');
alerts.forEach(alert => {
new bootstrap.Alert(alert).close();
});
}, 5000);
</script>
</body>
</html>