grales
This commit is contained in:
@@ -61,8 +61,718 @@
|
||||
<body>
|
||||
|
||||
<div class="content">
|
||||
<h4 class="mb-4 animate__animated animate__fadeInDown title_glow">⚙️ Automatizaciones</h4>
|
||||
<h4 class="mb-4 animate__animated animate__fadeInDown title-glow">⚙️ Automatizaciones</h4>
|
||||
|
||||
<!-- Card de conexión WINSAAI -->
|
||||
<div class="row mb-4 fade-in-up">
|
||||
<div class="col-12">
|
||||
<div class="card shadow-sm card-hover">
|
||||
<div class="card-header bg-primary text-white d-flex align-items-center justify-content-between">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-plug me-2"></i>
|
||||
<h5 class="mb-0">Conexión con WINSAAI</h5>
|
||||
</div>
|
||||
<div id="connection_status_header">
|
||||
<span class="badge bg-secondary">Verificando...</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<!-- Estado cuando NO hay configuración -->
|
||||
<div id="no_config_section">
|
||||
<p class="text-muted mb-3">
|
||||
<i class="fas fa-info-circle me-2"></i>
|
||||
Configura la conexión con el sistema WINSAAI para importar automáticamente pedimentos y COVES.
|
||||
</p>
|
||||
|
||||
<!-- Botón para conectar -->
|
||||
<button class="btn btn-success btn-animated btn-pulse" type="button"
|
||||
onclick="showConfigForm()">
|
||||
<i class="fas fa-wifi me-2"></i>
|
||||
Conectar con WINSAAI
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Estado cuando SÍ hay configuración -->
|
||||
<div id="existing_config_section" style="display: none;">
|
||||
<div class="alert alert-success border-0" role="alert">
|
||||
<div class="d-flex align-items-center mb-3">
|
||||
<i class="fas fa-check-circle me-2 text-success fs-5"></i>
|
||||
<h6 class="mb-0 fw-bold">¡Estás configurado para conectarte a WINSAAI!</h6>
|
||||
</div>
|
||||
|
||||
<!-- Información de la configuración actual -->
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-server me-2 text-primary"></i>
|
||||
<div>
|
||||
<small class="text-muted d-block">Servidor</small>
|
||||
<span id="current_server" class="fw-semibold">-</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-user me-2 text-info"></i>
|
||||
<div>
|
||||
<small class="text-muted d-block">Usuario</small>
|
||||
<span id="current_user" class="fw-semibold">-</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-shield-alt me-2 text-warning"></i>
|
||||
<div>
|
||||
<small class="text-muted d-block">Protocolo</small>
|
||||
<span id="current_protocol" class="fw-semibold">-</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-center">
|
||||
<i class="fas fa-clock me-2 text-secondary"></i>
|
||||
<div>
|
||||
<small class="text-muted d-block">Última sincronización</small>
|
||||
<span id="last_sync_display" class="fw-semibold">Nunca</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Opciones de sincronización activas -->
|
||||
<div class="mb-3">
|
||||
<small class="text-muted d-block mb-2">Datos configurados para sincronizar:</small>
|
||||
<div class="d-flex gap-2">
|
||||
<span id="sync_pedimentos_badge" class="badge bg-primary" style="display: none;">
|
||||
<i class="fas fa-file-alt me-1"></i> Pedimentos
|
||||
</span>
|
||||
<span id="sync_coves_badge" class="badge bg-info" style="display: none;">
|
||||
<i class="fas fa-ship me-1"></i> COVES
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Botones de acción -->
|
||||
<div class="d-flex gap-2 flex-wrap">
|
||||
<button type="button" class="btn btn-outline-primary btn-animated btn-sm"
|
||||
onclick="showConfigForm(true)">
|
||||
<i class="fas fa-edit me-2"></i>
|
||||
Editar Conexión
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-warning btn-animated btn-sm"
|
||||
onclick="toggleConfigStatus()">
|
||||
<i class="fas fa-pause me-2"></i>
|
||||
<span id="toggle_status_text">Desactivar</span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-secondary btn-animated btn-sm"
|
||||
onclick="testExistingConnection()">
|
||||
<i class="fas fa-vial me-2"></i>
|
||||
Probar Conexión
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-success btn-animated btn-sm"
|
||||
onclick="syncData()">
|
||||
<i class="fas fa-sync-alt me-2"></i>
|
||||
Sincronizar Ahora
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-danger btn-animated btn-sm"
|
||||
onclick="deleteConfig()">
|
||||
<i class="fas fa-trash me-2"></i>
|
||||
Eliminar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Formulario de configuración (inicialmente oculto) -->
|
||||
<div class="collapse mt-4" id="winsaaiConfig">
|
||||
<div class="card border-secondary">
|
||||
<div class="card-header bg-light d-flex justify-content-between align-items-center">
|
||||
<h6 class="mb-0">
|
||||
<i class="fas fa-cog me-2"></i>
|
||||
<span id="form_title">Configuración de Conexión API</span>
|
||||
</h6>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary"
|
||||
onclick="hideConfigForm()">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form id="winsaaiForm">
|
||||
<div class="row">
|
||||
<!-- Dirección IP/DNS -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="winsaai_host" class="form-label">
|
||||
<i class="fas fa-server me-1"></i>
|
||||
Dirección IP / DNS
|
||||
</label>
|
||||
<input type="text" class="form-control" id="winsaai_host"
|
||||
placeholder="192.168.1.100 o api.winsaai.com" required>
|
||||
<div class="form-text">
|
||||
Ingresa la dirección IP o nombre de dominio del servidor WINSAAI
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Puerto -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="winsaai_port" class="form-label">
|
||||
<i class="fas fa-network-wired me-1"></i>
|
||||
Puerto
|
||||
</label>
|
||||
<input type="number" class="form-control" id="winsaai_port"
|
||||
placeholder="8080" min="1" max="65535" required>
|
||||
<div class="form-text">
|
||||
Puerto del servicio API (ejemplo: 8080, 80, 443)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Usuario -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="winsaai_usuario" class="form-label">
|
||||
<i class="fas fa-user me-1"></i>
|
||||
Usuario
|
||||
</label>
|
||||
<input type="text" class="form-control" id="winsaai_usuario"
|
||||
placeholder="Tu usuario de WINSAAI" required>
|
||||
<div class="form-text">
|
||||
Nombre de usuario proporcionado por WINSAAI
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Contraseña -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="winsaai_password" class="form-label">
|
||||
<i class="fas fa-lock me-1"></i>
|
||||
Contraseña
|
||||
</label>
|
||||
<input type="password" class="form-control" id="winsaai_password"
|
||||
placeholder="Tu contraseña" required>
|
||||
<div class="form-text">
|
||||
Contraseña de acceso al sistema WINSAAI
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Protocolo -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="winsaai_protocol" class="form-label">
|
||||
<i class="fas fa-shield-alt me-1"></i>
|
||||
Protocolo
|
||||
</label>
|
||||
<select class="form-select" id="winsaai_protocol" required>
|
||||
<option value="">Seleccionar protocolo</option>
|
||||
<option value="http">HTTP</option>
|
||||
<option value="https">HTTPS (Recomendado)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Estado Actual -->
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">
|
||||
<i class="fas fa-info-circle me-1"></i>
|
||||
Estado Actual
|
||||
</label>
|
||||
<div id="connection_status_display" class="form-control-plaintext">
|
||||
<span class="badge bg-secondary">No configurado</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Opciones de sincronización -->
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
<label class="form-label">
|
||||
<i class="fas fa-sync me-1"></i>
|
||||
Datos a sincronizar
|
||||
</label>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="sync_pedimentos" checked>
|
||||
<label class="form-check-label" for="sync_pedimentos">
|
||||
<i class="fas fa-file-alt me-1 text-primary"></i>
|
||||
Pedimentos
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="sync_coves" checked>
|
||||
<label class="form-check-label" for="sync_coves">
|
||||
<i class="fas fa-ship me-1 text-info"></i>
|
||||
COVES
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Botones de acción -->
|
||||
<div class="d-flex gap-2 flex-wrap">
|
||||
<button type="button" class="btn btn-outline-secondary btn-animated"
|
||||
onclick="testConnection()">
|
||||
<i class="fas fa-vial me-2"></i>
|
||||
Probar Conexión
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary btn-animated">
|
||||
<i class="fas fa-save me-2"></i>
|
||||
Guardar Configuración
|
||||
</button>
|
||||
<button type="button" class="btn btn-warning btn-animated"
|
||||
onclick="syncData()">
|
||||
<i class="fas fa-sync-alt me-2"></i>
|
||||
Sincronizar Ahora
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Estado de conexión -->
|
||||
<div id="connectionStatus" class="mt-3" style="display: none;">
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-info-circle me-2"></i>
|
||||
<span id="statusMessage">Verificando conexión...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Scripts para funcionalidad WINSAAI -->
|
||||
<script>
|
||||
let currentConfig = null;
|
||||
|
||||
// Cargar configuración al inicio
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadExistingConfig();
|
||||
});
|
||||
|
||||
// Cargar configuración existente
|
||||
async function loadExistingConfig() {
|
||||
try {
|
||||
const response = await fetch('/IMPORTADORES/winsaai/get_config');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success && result.data) {
|
||||
currentConfig = result.data;
|
||||
showExistingConfig(result.data);
|
||||
} else {
|
||||
showNoConfig();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error cargando configuración:', error);
|
||||
showNoConfig();
|
||||
}
|
||||
}
|
||||
|
||||
// Mostrar estado cuando NO hay configuración
|
||||
function showNoConfig() {
|
||||
document.getElementById('no_config_section').style.display = 'block';
|
||||
document.getElementById('existing_config_section').style.display = 'none';
|
||||
document.getElementById('connection_status_header').innerHTML = '<span class="badge bg-secondary">Sin configurar</span>';
|
||||
}
|
||||
|
||||
// Mostrar estado cuando SÍ hay configuración
|
||||
function showExistingConfig(config) {
|
||||
// Ocultar sección de "no config" y mostrar sección existente
|
||||
document.getElementById('no_config_section').style.display = 'none';
|
||||
document.getElementById('existing_config_section').style.display = 'block';
|
||||
|
||||
// Actualizar información mostrada
|
||||
document.getElementById('current_server').textContent = `${config.protocol}://${config.host}:${config.port}`;
|
||||
document.getElementById('current_user').textContent = config.usuario;
|
||||
document.getElementById('current_protocol').textContent = config.protocol.toUpperCase();
|
||||
|
||||
// Mostrar última sincronización
|
||||
if (config.last_sync) {
|
||||
const lastSyncDate = new Date(config.last_sync);
|
||||
document.getElementById('last_sync_display').textContent = lastSyncDate.toLocaleString();
|
||||
} else {
|
||||
document.getElementById('last_sync_display').textContent = 'Nunca';
|
||||
}
|
||||
|
||||
// Mostrar badges de sincronización
|
||||
const pedimentosBadge = document.getElementById('sync_pedimentos_badge');
|
||||
const covesBadge = document.getElementById('sync_coves_badge');
|
||||
|
||||
if (config.sync_pedimentos) {
|
||||
pedimentosBadge.style.display = 'inline-block';
|
||||
} else {
|
||||
pedimentosBadge.style.display = 'none';
|
||||
}
|
||||
|
||||
if (config.sync_coves) {
|
||||
covesBadge.style.display = 'inline-block';
|
||||
} else {
|
||||
covesBadge.style.display = 'none';
|
||||
}
|
||||
|
||||
// Actualizar header según estado
|
||||
updateHeaderStatus(config.status);
|
||||
|
||||
// Actualizar botón de toggle según estado
|
||||
updateToggleButton(config.status);
|
||||
|
||||
// Llenar formulario con datos existentes para edición
|
||||
document.getElementById('winsaai_host').value = config.host || '';
|
||||
document.getElementById('winsaai_port').value = config.port || '';
|
||||
document.getElementById('winsaai_protocol').value = config.protocol || '';
|
||||
document.getElementById('winsaai_usuario').value = config.usuario || '';
|
||||
document.getElementById('sync_pedimentos').checked = config.sync_pedimentos == 1;
|
||||
document.getElementById('sync_coves').checked = config.sync_coves == 1;
|
||||
}
|
||||
|
||||
// Actualizar estado en el header
|
||||
function updateHeaderStatus(status) {
|
||||
const headerStatus = document.getElementById('connection_status_header');
|
||||
let badgeHtml = '';
|
||||
|
||||
switch(status) {
|
||||
case 'activo':
|
||||
badgeHtml = '<span class="badge bg-success"><i class="fas fa-check-circle me-1"></i>Conectado</span>';
|
||||
break;
|
||||
case 'inactivo':
|
||||
badgeHtml = '<span class="badge bg-warning"><i class="fas fa-pause me-1"></i>Inactivo</span>';
|
||||
break;
|
||||
case 'error':
|
||||
badgeHtml = '<span class="badge bg-danger"><i class="fas fa-exclamation-triangle me-1"></i>Error</span>';
|
||||
break;
|
||||
default:
|
||||
badgeHtml = '<span class="badge bg-secondary">Sin configurar</span>';
|
||||
}
|
||||
|
||||
headerStatus.innerHTML = badgeHtml;
|
||||
}
|
||||
|
||||
// Actualizar botón de toggle según estado
|
||||
function updateToggleButton(status) {
|
||||
const toggleBtn = document.querySelector('button[onclick="toggleConfigStatus()"]');
|
||||
const toggleText = document.getElementById('toggle_status_text');
|
||||
const icon = toggleBtn.querySelector('i');
|
||||
|
||||
if (status === 'activo') {
|
||||
toggleText.textContent = 'Desactivar';
|
||||
icon.className = 'fas fa-pause me-2';
|
||||
toggleBtn.className = 'btn btn-outline-warning btn-animated btn-sm';
|
||||
} else {
|
||||
toggleText.textContent = 'Activar';
|
||||
icon.className = 'fas fa-play me-2';
|
||||
toggleBtn.className = 'btn btn-outline-success btn-animated btn-sm';
|
||||
}
|
||||
}
|
||||
|
||||
// Mostrar formulario de configuración
|
||||
function showConfigForm(isEdit = false) {
|
||||
const formTitle = document.getElementById('form_title');
|
||||
const configCollapse = new bootstrap.Collapse(document.getElementById('winsaaiConfig'), { show: true });
|
||||
|
||||
if (isEdit) {
|
||||
formTitle.textContent = 'Editar Configuración de WINSAAI';
|
||||
} else {
|
||||
formTitle.textContent = 'Nueva Configuración de WINSAAI';
|
||||
// Limpiar formulario para nueva configuración
|
||||
document.getElementById('winsaaiForm').reset();
|
||||
}
|
||||
}
|
||||
|
||||
// Ocultar formulario de configuración
|
||||
function hideConfigForm() {
|
||||
const configCollapse = new bootstrap.Collapse(document.getElementById('winsaaiConfig'), { hide: true });
|
||||
}
|
||||
|
||||
// Probar conexión con configuración existente
|
||||
async function testExistingConnection() {
|
||||
if (!currentConfig) {
|
||||
showStatus('error', 'No hay configuración para probar');
|
||||
return;
|
||||
}
|
||||
|
||||
showStatus('info', 'Probando conexión con configuración actual...');
|
||||
|
||||
try {
|
||||
const response = await fetch('/IMPORTADORES/winsaai/test_connection', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
host: currentConfig.host,
|
||||
port: currentConfig.port,
|
||||
protocol: currentConfig.protocol,
|
||||
usuario: currentConfig.usuario,
|
||||
password: 'existing_config' // Indicador para usar configuración guardada
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showStatus('success', result.message);
|
||||
updateHeaderStatus('activo');
|
||||
} else {
|
||||
showStatus('error', result.message);
|
||||
updateHeaderStatus('error');
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus('error', 'Error de red: ' + error.message);
|
||||
updateHeaderStatus('error');
|
||||
}
|
||||
}
|
||||
|
||||
// Activar/Desactivar configuración
|
||||
async function toggleConfigStatus() {
|
||||
if (!currentConfig) {
|
||||
showStatus('error', 'No hay configuración para modificar');
|
||||
return;
|
||||
}
|
||||
|
||||
const currentStatus = currentConfig.status;
|
||||
const newStatus = currentStatus === 'activo' ? 'inactivo' : 'activo';
|
||||
const action = newStatus === 'activo' ? 'activar' : 'desactivar';
|
||||
|
||||
if (confirm(`¿Estás seguro de que deseas ${action} la configuración de WINSAAI?`)) {
|
||||
showStatus('info', `${action === 'activar' ? 'Activando' : 'Desactivando'} configuración...`);
|
||||
|
||||
try {
|
||||
// Aquí harías la llamada al servidor para cambiar el estado
|
||||
// Por ahora simularemos el cambio
|
||||
currentConfig.status = newStatus;
|
||||
updateHeaderStatus(newStatus);
|
||||
updateToggleButton(newStatus);
|
||||
showStatus('success', `Configuración ${action === 'activar' ? 'activada' : 'desactivada'} correctamente`);
|
||||
} catch (error) {
|
||||
showStatus('error', `Error al ${action} configuración: ` + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Eliminar configuración
|
||||
async function deleteConfig() {
|
||||
if (!currentConfig) {
|
||||
showStatus('error', 'No hay configuración para eliminar');
|
||||
return;
|
||||
}
|
||||
|
||||
if (confirm('¿Estás seguro de que deseas eliminar completamente la configuración de WINSAAI? Esta acción no se puede deshacer.')) {
|
||||
showStatus('info', 'Eliminando configuración...');
|
||||
|
||||
try {
|
||||
// Aquí harías la llamada al servidor para eliminar
|
||||
// Por ahora simularemos la eliminación
|
||||
currentConfig = null;
|
||||
showNoConfig();
|
||||
hideConfigForm();
|
||||
showStatus('success', 'Configuración eliminada correctamente');
|
||||
} catch (error) {
|
||||
showStatus('error', 'Error al eliminar configuración: ' + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Función para probar la conexión (desde formulario)
|
||||
async function testConnection() {
|
||||
const host = document.getElementById('winsaai_host').value;
|
||||
const port = document.getElementById('winsaai_port').value;
|
||||
const protocol = document.getElementById('winsaai_protocol').value;
|
||||
const usuario = document.getElementById('winsaai_usuario').value;
|
||||
const password = document.getElementById('winsaai_password').value;
|
||||
|
||||
if (!host || !port || !protocol || !usuario || !password) {
|
||||
showStatus('error', 'Por favor completa todos los campos obligatorios');
|
||||
return;
|
||||
}
|
||||
|
||||
showStatus('info', 'Probando conexión con WINSAAI...');
|
||||
|
||||
try {
|
||||
const response = await fetch('/IMPORTADORES/winsaai/test_connection', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
host: host,
|
||||
port: parseInt(port),
|
||||
protocol: protocol,
|
||||
usuario: usuario,
|
||||
password: password
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showStatus('success', result.message);
|
||||
} else {
|
||||
showStatus('error', result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus('error', 'Error de red: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Función para sincronizar datos
|
||||
async function syncData() {
|
||||
let pedimentos, coves;
|
||||
|
||||
if (currentConfig) {
|
||||
// Usar configuración existente
|
||||
pedimentos = currentConfig.sync_pedimentos;
|
||||
coves = currentConfig.sync_coves;
|
||||
} else {
|
||||
// Usar valores del formulario
|
||||
pedimentos = document.getElementById('sync_pedimentos').checked;
|
||||
coves = document.getElementById('sync_coves').checked;
|
||||
}
|
||||
|
||||
if (!pedimentos && !coves) {
|
||||
showStatus('warning', 'No hay datos configurados para sincronizar');
|
||||
return;
|
||||
}
|
||||
|
||||
showStatus('info', 'Iniciando sincronización de datos...');
|
||||
|
||||
let syncType = 'both';
|
||||
if (pedimentos && !coves) syncType = 'pedimentos';
|
||||
else if (!pedimentos && coves) syncType = 'coves';
|
||||
|
||||
try {
|
||||
const response = await fetch('/IMPORTADORES/winsaai/sync_data', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sync_type: syncType
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
let message = 'Sincronización completada: ';
|
||||
if (result.data.pedimentos) {
|
||||
message += `${result.data.pedimentos.processed} pedimentos `;
|
||||
}
|
||||
if (result.data.coves) {
|
||||
message += `${result.data.coves.processed} COVES `;
|
||||
}
|
||||
showStatus('success', message);
|
||||
|
||||
// Actualizar última sincronización si hay configuración
|
||||
if (currentConfig) {
|
||||
currentConfig.last_sync = new Date().toISOString();
|
||||
document.getElementById('last_sync_display').textContent = new Date().toLocaleString();
|
||||
}
|
||||
} else {
|
||||
showStatus('error', result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus('error', 'Error de red: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Función para mostrar estado
|
||||
function showStatus(type, message) {
|
||||
const statusDiv = document.getElementById('connectionStatus');
|
||||
const statusMessage = document.getElementById('statusMessage');
|
||||
const alertDiv = statusDiv.querySelector('.alert');
|
||||
|
||||
// Remover clases anteriores
|
||||
alertDiv.className = 'alert';
|
||||
|
||||
// Agregar nueva clase según el tipo
|
||||
switch(type) {
|
||||
case 'success':
|
||||
alertDiv.classList.add('alert-success');
|
||||
statusMessage.innerHTML = `<i class="fas fa-check-circle me-2"></i>${message}`;
|
||||
break;
|
||||
case 'error':
|
||||
alertDiv.classList.add('alert-danger');
|
||||
statusMessage.innerHTML = `<i class="fas fa-exclamation-circle me-2"></i>${message}`;
|
||||
break;
|
||||
case 'warning':
|
||||
alertDiv.classList.add('alert-warning');
|
||||
statusMessage.innerHTML = `<i class="fas fa-exclamation-triangle me-2"></i>${message}`;
|
||||
break;
|
||||
default:
|
||||
alertDiv.classList.add('alert-info');
|
||||
statusMessage.innerHTML = `<i class="fas fa-info-circle me-2"></i>${message}`;
|
||||
}
|
||||
|
||||
statusDiv.style.display = 'block';
|
||||
|
||||
// Auto-ocultar después de 5 segundos para mensajes de éxito
|
||||
if (type === 'success') {
|
||||
setTimeout(() => {
|
||||
statusDiv.style.display = 'none';
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
// Manejar envío del formulario
|
||||
document.getElementById('winsaaiForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const config = {
|
||||
host: document.getElementById('winsaai_host').value,
|
||||
port: parseInt(document.getElementById('winsaai_port').value),
|
||||
protocol: document.getElementById('winsaai_protocol').value,
|
||||
usuario: document.getElementById('winsaai_usuario').value,
|
||||
password: document.getElementById('winsaai_password').value,
|
||||
sync_pedimentos: document.getElementById('sync_pedimentos').checked,
|
||||
sync_coves: document.getElementById('sync_coves').checked
|
||||
};
|
||||
|
||||
// Validar campos obligatorios
|
||||
if (!config.host || !config.port || !config.protocol || !config.usuario || !config.password) {
|
||||
showStatus('error', 'Por favor completa todos los campos obligatorios');
|
||||
return;
|
||||
}
|
||||
|
||||
showStatus('info', 'Guardando configuración...');
|
||||
|
||||
try {
|
||||
const response = await fetch('/IMPORTADORES/winsaai/save_config', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showStatus('success', result.message);
|
||||
// Recargar configuración para mostrar el nuevo estado
|
||||
await loadExistingConfig();
|
||||
hideConfigForm();
|
||||
} else {
|
||||
showStatus('error', result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error completo:', error);
|
||||
showStatus('error', 'Error de red: ' + error.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Animación suave para el collapse
|
||||
document.getElementById('winsaaiConfig').addEventListener('show.bs.collapse', function() {
|
||||
this.style.opacity = '0';
|
||||
this.style.transform = 'translateY(-20px)';
|
||||
setTimeout(() => {
|
||||
this.style.transition = 'all 0.3s ease';
|
||||
this.style.opacity = '1';
|
||||
this.style.transform = 'translateY(0)';
|
||||
}, 50);
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user