226 lines
8.6 KiB
PHP
226 lines
8.6 KiB
PHP
<?php include __DIR__ . '/../partials/sidebar_importador.php'; ?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>📤 Importar Claves CSV</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<!-- Font Awesome -->
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
<style>
|
|
body { font-family: 'Segoe UI', sans-serif; background-color: #f4f6f9; }
|
|
.content { margin-top: 56px; padding: 40px 20px; position: relative; z-index: 1; background-color: #f4f6f9; transition: margin-left 0.3s ease;}
|
|
@media (min-width: 768px) { .content { margin-left: 250px; } }
|
|
@media (max-width: 767.98px) { .content { margin-left: 0; } }
|
|
.card { border-radius: 12px; }
|
|
.btn-animated { transition: all 0.3s ease; position: relative; overflow: hidden; }
|
|
.btn-animated:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); }
|
|
.file-drop-area {
|
|
border: 2px dashed #007bff;
|
|
border-radius: 10px;
|
|
padding: 40px;
|
|
text-align: center;
|
|
background-color: #f8f9ff;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
}
|
|
.file-drop-area:hover {
|
|
border-color: #0056b3;
|
|
background-color: #e7f1ff;
|
|
}
|
|
.file-drop-area.dragover {
|
|
border-color: #28a745;
|
|
background-color: #d4edda;
|
|
}
|
|
.file-info {
|
|
background-color: #e9ecef;
|
|
border-radius: 8px;
|
|
padding: 15px;
|
|
margin-top: 15px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="content">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h4><i class="fas fa-upload text-primary"></i> Importar Claves de Pedimentos por CSV</h4>
|
|
<div>
|
|
<a href="/IMPORTADORES/public/downloads/claves_pedimentos_template.csv" class="btn btn-outline-info btn-animated me-2" download>
|
|
<i class="fas fa-download"></i> Descargar Plantilla
|
|
</a>
|
|
<a href="/IMPORTADORES/claves_pedimentos/lista" class="btn btn-secondary btn-animated">
|
|
<i class="fas fa-arrow-left"></i> Regresar
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-primary text-white">
|
|
<h5 class="mb-0"><i class="fas fa-file-csv"></i> Cargar Archivo CSV</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="/IMPORTADORES/claves_pedimentos/procesar_csv" method="POST" enctype="multipart/form-data" id="csvForm">
|
|
|
|
<div class="file-drop-area" id="fileDropArea">
|
|
<i class="fas fa-cloud-upload-alt fa-3x text-primary mb-3"></i>
|
|
<h5>Arrastra tu archivo CSV aquí</h5>
|
|
<p class="text-muted">o haz clic para seleccionar archivo</p>
|
|
<input type="file" name="csv_file" id="csvFile" accept=".csv" style="display: none;" required>
|
|
</div>
|
|
|
|
<div id="fileInfo" class="file-info" style="display: none;">
|
|
<h6><i class="fas fa-file-check text-success"></i> Archivo seleccionado:</h6>
|
|
<p id="fileName" class="mb-1"></p>
|
|
<small id="fileSize" class="text-muted"></small>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<h6><i class="fas fa-cogs"></i> Opciones de importación:</h6>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" name="omitir_duplicados" id="omitirDuplicados" checked>
|
|
<label class="form-check-label" for="omitirDuplicados">
|
|
Omitir códigos duplicados (no reemplazar los existentes)
|
|
</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" name="activar_todas" id="activarTodas" checked>
|
|
<label class="form-check-label" for="activarTodas">
|
|
Activar todas las claves importadas
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-4 text-center">
|
|
<button type="submit" class="btn btn-success btn-lg btn-animated" id="submitBtn" disabled>
|
|
<i class="fas fa-upload"></i> Procesar Archivo CSV
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-info text-white">
|
|
<h5 class="mb-0"><i class="fas fa-info-circle"></i> Instrucciones</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<h6>📋 Formato del archivo CSV:</h6>
|
|
<ul class="small">
|
|
<li><strong>Separador:</strong> Coma (,)</li>
|
|
<li><strong>Codificación:</strong> UTF-8</li>
|
|
<li><strong>Encabezados:</strong> Obligatorios</li>
|
|
</ul>
|
|
|
|
<h6>🏷️ Columnas requeridas:</h6>
|
|
<ul class="small">
|
|
<li><strong>codigo:</strong> Código de la clave (ej: A1, B2)</li>
|
|
<li><strong>descripcion:</strong> Descripción detallada</li>
|
|
<li><strong>tipo_operacion:</strong> importacion o exportacion</li>
|
|
<li><strong>activo:</strong> 1 (activo) o 0 (inactivo)</li>
|
|
</ul>
|
|
|
|
<div class="alert alert-warning small mt-3">
|
|
<i class="fas fa-exclamation-triangle"></i>
|
|
<strong>Importante:</strong> Los códigos deben ser únicos. Si existe un código duplicado, se omitirá según la configuración seleccionada.
|
|
</div>
|
|
|
|
<div class="mt-3">
|
|
<a href="/IMPORTADORES/public/downloads/claves_pedimentos_template.csv" class="btn btn-sm btn-outline-primary w-100" download>
|
|
<i class="fas fa-download"></i> Descargar plantilla de ejemplo
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<script>
|
|
const fileDropArea = document.getElementById('fileDropArea');
|
|
const csvFile = document.getElementById('csvFile');
|
|
const fileInfo = document.getElementById('fileInfo');
|
|
const fileName = document.getElementById('fileName');
|
|
const fileSize = document.getElementById('fileSize');
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
|
|
// Eventos de drag & drop
|
|
fileDropArea.addEventListener('click', () => csvFile.click());
|
|
fileDropArea.addEventListener('dragover', handleDragOver);
|
|
fileDropArea.addEventListener('dragleave', handleDragLeave);
|
|
fileDropArea.addEventListener('drop', handleDrop);
|
|
csvFile.addEventListener('change', handleFileSelect);
|
|
|
|
function handleDragOver(e) {
|
|
e.preventDefault();
|
|
fileDropArea.classList.add('dragover');
|
|
}
|
|
|
|
function handleDragLeave(e) {
|
|
e.preventDefault();
|
|
fileDropArea.classList.remove('dragover');
|
|
}
|
|
|
|
function handleDrop(e) {
|
|
e.preventDefault();
|
|
fileDropArea.classList.remove('dragover');
|
|
|
|
const files = e.dataTransfer.files;
|
|
if (files.length > 0) {
|
|
csvFile.files = files;
|
|
handleFileSelect();
|
|
}
|
|
}
|
|
|
|
function handleFileSelect() {
|
|
const file = csvFile.files[0];
|
|
|
|
if (file) {
|
|
// Validar que sea CSV
|
|
if (!file.name.toLowerCase().endsWith('.csv')) {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Archivo inválido',
|
|
text: 'Por favor selecciona un archivo CSV válido.'
|
|
});
|
|
csvFile.value = '';
|
|
return;
|
|
}
|
|
|
|
// Mostrar información del archivo
|
|
fileName.textContent = file.name;
|
|
fileSize.textContent = `Tamaño: ${(file.size / 1024).toFixed(1)} KB`;
|
|
fileInfo.style.display = 'block';
|
|
submitBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
// Validar formulario antes de enviar
|
|
document.getElementById('csvForm').addEventListener('submit', function(e) {
|
|
const file = csvFile.files[0];
|
|
|
|
if (!file) {
|
|
e.preventDefault();
|
|
Swal.fire({
|
|
icon: 'warning',
|
|
title: 'Archivo requerido',
|
|
text: 'Por favor selecciona un archivo CSV.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Mostrar indicador de carga
|
|
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Procesando...';
|
|
submitBtn.disabled = true;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|