Fix param validation errors and add TNS config section
- terceros/transaccion: return clear error when required params (doc_num, num_factura) are missing instead of passing empty dict to Firebird causing Column unknown error - transaccion: remove prefijo from 'por factura' query; parse num_factura as int when digit - automation: add /preview endpoint to show patient/reception counts before sending; update UI with preview step and disabled run button until preview loads - config: add TNS credentials section (tns_empresa, tns_usuario, tns_password, api_sucursal) with test-connection button - config: add POST /config/test-tns endpoint Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3755a51562
commit
b4a7271d8d
@@ -76,6 +76,57 @@ async def automation_page(request: Request, user: dict = Depends(get_current_use
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/preview")
|
||||||
|
async def preview_automation(
|
||||||
|
request: Request,
|
||||||
|
user: dict = Depends(get_current_user),
|
||||||
|
fecha: str = Form(...),
|
||||||
|
):
|
||||||
|
conn = get_connection()
|
||||||
|
configs = {row["key"]: row["value"] for row in conn.execute("SELECT * FROM config").fetchall()}
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
fb, fb_ok, fb_msg = get_firebird_from_config(configs)
|
||||||
|
if not fb_ok:
|
||||||
|
return JSONResponse({"success": False, "message": f"Error Firebird: {fb_msg}"})
|
||||||
|
|
||||||
|
fecha_ini = f"{fecha} 00:00:00"
|
||||||
|
fecha_fin = f"{fecha} 23:59:59"
|
||||||
|
params = {"fecha_ini": fecha_ini, "fecha_fin": fecha_fin}
|
||||||
|
|
||||||
|
ok1, err1, rows_pac = fb.execute_query(_SQL_PACIENTES, params)
|
||||||
|
if not ok1:
|
||||||
|
fb.disconnect()
|
||||||
|
return JSONResponse({"success": False, "message": f"Error BD pacientes: {err1}"})
|
||||||
|
|
||||||
|
ok2, err2, rows_rda = fb.execute_query(_SQL_RDA, params)
|
||||||
|
fb.disconnect()
|
||||||
|
if not ok2:
|
||||||
|
return JSONResponse({"success": False, "message": f"Error BD RDA: {err2}"})
|
||||||
|
|
||||||
|
grupos = agrupar_por_recepcion(rows_rda)
|
||||||
|
total_examenes = sum(len(v) for v in grupos.values())
|
||||||
|
|
||||||
|
pacientes_preview = [
|
||||||
|
{
|
||||||
|
"doc": str(p.get("DOCIDENT", "")),
|
||||||
|
"nombre": f"{p.get('NOMBRES', '')} {p.get('APELLIDOS', '')}".strip(),
|
||||||
|
"tipo": str(p.get("TIPOIDENT", "")),
|
||||||
|
}
|
||||||
|
for p in rows_pac[:10]
|
||||||
|
]
|
||||||
|
|
||||||
|
return JSONResponse({
|
||||||
|
"success": True,
|
||||||
|
"fecha": fecha,
|
||||||
|
"pacientes": len(rows_pac),
|
||||||
|
"recepciones": len(grupos),
|
||||||
|
"examenes": total_examenes,
|
||||||
|
"pacientes_preview": pacientes_preview,
|
||||||
|
"hay_mas": len(rows_pac) > 10,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@router.post("/run")
|
@router.post("/run")
|
||||||
async def run_automation(
|
async def run_automation(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
|||||||
+16
-1
@@ -1,7 +1,8 @@
|
|||||||
from fastapi import APIRouter, Request, Form, Depends
|
from fastapi import APIRouter, Request, Form, Depends
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import JSONResponse, RedirectResponse
|
||||||
from app.database import get_connection
|
from app.database import get_connection
|
||||||
from app.auth import get_current_user
|
from app.auth import get_current_user
|
||||||
|
from app.services.api_client import get_tns_token
|
||||||
|
|
||||||
router = APIRouter(prefix="/config", tags=["config"])
|
router = APIRouter(prefix="/config", tags=["config"])
|
||||||
|
|
||||||
@@ -45,6 +46,20 @@ async def config_page(request: Request, user: dict = Depends(get_current_user)):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/test-tns")
|
||||||
|
async def test_tns(
|
||||||
|
request: Request,
|
||||||
|
user: dict = Depends(get_current_user),
|
||||||
|
empresa: str = Form(""),
|
||||||
|
usuario: str = Form(""),
|
||||||
|
password: str = Form(""),
|
||||||
|
):
|
||||||
|
token, err = await get_tns_token(empresa, usuario, password)
|
||||||
|
if token:
|
||||||
|
return JSONResponse({"success": True, "message": "Login TNS exitoso"})
|
||||||
|
return JSONResponse({"success": False, "message": err or "Error desconocido"})
|
||||||
|
|
||||||
|
|
||||||
@router.post("/save")
|
@router.post("/save")
|
||||||
async def config_save(request: Request, user: dict = Depends(get_current_user)):
|
async def config_save(request: Request, user: dict = Depends(get_current_user)):
|
||||||
form = await request.form()
|
form = await request.form()
|
||||||
|
|||||||
+10
-2
@@ -79,8 +79,12 @@ async def preview_query(
|
|||||||
if not ok:
|
if not ok:
|
||||||
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
||||||
|
|
||||||
|
if ":doc_num" in q["query_text"] and not doc_num:
|
||||||
|
fb.disconnect()
|
||||||
|
return JSONResponse({"success": False, "message": "Ingresa el número de documento para buscar el paciente"})
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
if ":doc_num" in q["query_text"] and doc_num:
|
if ":doc_num" in q["query_text"]:
|
||||||
params["doc_num"] = doc_num
|
params["doc_num"] = doc_num
|
||||||
if ":fecha_ini" in q["query_text"]:
|
if ":fecha_ini" in q["query_text"]:
|
||||||
params["fecha_ini"] = "1900-01-01"
|
params["fecha_ini"] = "1900-01-01"
|
||||||
@@ -124,9 +128,13 @@ async def send_terceros(
|
|||||||
if not ok:
|
if not ok:
|
||||||
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
||||||
|
|
||||||
|
if ":doc_num" in q["query_text"] and not doc_num:
|
||||||
|
fb.disconnect()
|
||||||
|
return JSONResponse({"success": False, "message": "Ingresa el número de documento"})
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
if ":doc_num" in q["query_text"]:
|
if ":doc_num" in q["query_text"]:
|
||||||
params["doc_num"] = doc_num or configs.get("doc_num_default", "")
|
params["doc_num"] = doc_num
|
||||||
|
|
||||||
success, error, rows = fb.execute_query(q["query_text"], params if params else None)
|
success, error, rows = fb.execute_query(q["query_text"], params if params else None)
|
||||||
fb.disconnect()
|
fb.disconnect()
|
||||||
|
|||||||
+12
-10
@@ -53,12 +53,13 @@ async def preview_transaccion(
|
|||||||
if not ok:
|
if not ok:
|
||||||
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
||||||
|
|
||||||
|
if ":num_factura" in q["query_text"] and not factura:
|
||||||
|
fb.disconnect()
|
||||||
|
return JSONResponse({"success": False, "message": "Ingresa el número de factura"})
|
||||||
|
|
||||||
params = {"fecha_ini": fecha_inicio, "fecha_fin": fecha_fin}
|
params = {"fecha_ini": fecha_inicio, "fecha_fin": fecha_fin}
|
||||||
if ":num_factura" in q["query_text"] and factura:
|
if ":num_factura" in q["query_text"]:
|
||||||
params["num_factura"] = factura
|
params["num_factura"] = int(factura) if factura.isdigit() else factura
|
||||||
prefijo = configs.get("api_prefijo", "")
|
|
||||||
if prefijo:
|
|
||||||
params["prefijo"] = prefijo
|
|
||||||
|
|
||||||
success, error, rows = fb.execute_query(q["query_text"], params)
|
success, error, rows = fb.execute_query(q["query_text"], params)
|
||||||
fb.disconnect()
|
fb.disconnect()
|
||||||
@@ -101,12 +102,13 @@ async def send_transaccion(
|
|||||||
if not ok:
|
if not ok:
|
||||||
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
return JSONResponse({"success": False, "message": f"Error Firebird: {msg}"})
|
||||||
|
|
||||||
|
if ":num_factura" in q["query_text"] and not factura:
|
||||||
|
fb.disconnect()
|
||||||
|
return JSONResponse({"success": False, "message": "Ingresa el número de factura"})
|
||||||
|
|
||||||
params = {"fecha_ini": fecha_inicio, "fecha_fin": fecha_fin}
|
params = {"fecha_ini": fecha_inicio, "fecha_fin": fecha_fin}
|
||||||
if ":num_factura" in q["query_text"] and factura:
|
if ":num_factura" in q["query_text"]:
|
||||||
params["num_factura"] = factura
|
params["num_factura"] = int(factura) if factura.isdigit() else factura
|
||||||
prefijo = configs.get("api_prefijo", "")
|
|
||||||
if prefijo:
|
|
||||||
params["prefijo"] = prefijo
|
|
||||||
|
|
||||||
success, error, rows = fb.execute_query(q["query_text"], params)
|
success, error, rows = fb.execute_query(q["query_text"], params)
|
||||||
fb.disconnect()
|
fb.disconnect()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<i class="fas fa-paper-plane mr-2 text-blue-500"></i>Envío automático por fecha
|
<i class="fas fa-paper-plane mr-2 text-blue-500"></i>Envío automático por fecha
|
||||||
</h3>
|
</h3>
|
||||||
<p class="text-xs text-gray-500 mt-1">
|
<p class="text-xs text-gray-500 mt-1">
|
||||||
Selecciona una fecha, el sistema enviará todos los pacientes y sus RDA a TNS.
|
Selecciona una fecha para ver cuántos pacientes y RDA se enviarán a TNS.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
@@ -21,15 +21,49 @@
|
|||||||
<input type="date" id="fecha-input" value="{{ today }}"
|
<input type="date" id="fecha-input" value="{{ today }}"
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
|
||||||
</div>
|
</div>
|
||||||
|
<button onclick="previewAutomation()"
|
||||||
|
id="btn-preview"
|
||||||
|
class="px-6 py-2 bg-gray-600 hover:bg-gray-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 whitespace-nowrap">
|
||||||
|
<i class="fas fa-eye"></i> Vista previa
|
||||||
|
</button>
|
||||||
<button onclick="runAutomation()"
|
<button onclick="runAutomation()"
|
||||||
id="btn-run"
|
id="btn-run"
|
||||||
class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 whitespace-nowrap">
|
class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors flex items-center gap-2 whitespace-nowrap disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
disabled>
|
||||||
<i class="fas fa-play"></i> Ejecutar envío
|
<i class="fas fa-play"></i> Ejecutar envío
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Vista previa de datos -->
|
||||||
|
<div id="preview-section" class="hidden bg-white rounded-xl shadow-sm border border-gray-200">
|
||||||
|
<div class="px-6 py-4 border-b border-gray-200 flex items-center justify-between">
|
||||||
|
<h3 class="font-semibold text-gray-800"><i class="fas fa-search mr-2 text-gray-500"></i>Resumen de la fecha</h3>
|
||||||
|
<span id="preview-fecha" class="text-sm text-gray-500"></span>
|
||||||
|
</div>
|
||||||
|
<div class="p-6 space-y-4">
|
||||||
|
<div class="grid grid-cols-3 gap-4">
|
||||||
|
<div class="bg-blue-50 rounded-lg p-4 text-center">
|
||||||
|
<div id="cnt-pacientes" class="text-3xl font-bold text-blue-600">0</div>
|
||||||
|
<div class="text-sm text-blue-700 mt-1">Pacientes</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-purple-50 rounded-lg p-4 text-center">
|
||||||
|
<div id="cnt-recepciones" class="text-3xl font-bold text-purple-600">0</div>
|
||||||
|
<div class="text-sm text-purple-700 mt-1">Recepciones</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-green-50 rounded-lg p-4 text-center">
|
||||||
|
<div id="cnt-examenes" class="text-3xl font-bold text-green-600">0</div>
|
||||||
|
<div class="text-sm text-green-700 mt-1">Exámenes</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs font-medium text-gray-600 mb-2">Primeros pacientes:</p>
|
||||||
|
<div id="preview-table" class="divide-y divide-gray-100 border border-gray-100 rounded-lg overflow-hidden text-sm"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Progreso -->
|
<!-- Progreso -->
|
||||||
<div id="progress-section" class="hidden space-y-4">
|
<div id="progress-section" class="hidden space-y-4">
|
||||||
|
|
||||||
@@ -42,8 +76,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<span id="p1-badge" class="text-sm text-gray-400">Esperando...</span>
|
<span id="p1-badge" class="text-sm text-gray-400">Esperando...</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="p1-detalle" class="divide-y divide-gray-100 hidden">
|
<div id="p1-detalle" class="divide-y divide-gray-100 hidden"></div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Paso 2 -->
|
<!-- Paso 2 -->
|
||||||
@@ -55,14 +88,67 @@
|
|||||||
</div>
|
</div>
|
||||||
<span id="p2-badge" class="text-sm text-gray-400">Esperando...</span>
|
<span id="p2-badge" class="text-sm text-gray-400">Esperando...</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="p2-detalle" class="divide-y divide-gray-100 hidden">
|
<div id="p2-detalle" class="divide-y divide-gray-100 hidden"></div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
async function previewAutomation() {
|
||||||
|
const fecha = document.getElementById('fecha-input').value;
|
||||||
|
if (!fecha) { showToast('Selecciona una fecha', 'error'); return; }
|
||||||
|
|
||||||
|
const btn = document.getElementById('btn-preview');
|
||||||
|
showLoading(btn);
|
||||||
|
|
||||||
|
document.getElementById('preview-section').classList.add('hidden');
|
||||||
|
document.getElementById('progress-section').classList.add('hidden');
|
||||||
|
document.getElementById('btn-run').disabled = true;
|
||||||
|
|
||||||
|
const form = new FormData();
|
||||||
|
form.append('fecha', fecha);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const resp = await fetch('/automation/preview', { method: 'POST', body: form, credentials: 'include' });
|
||||||
|
const data = await resp.json();
|
||||||
|
hideLoading(btn, '<i class="fas fa-eye"></i> Vista previa');
|
||||||
|
|
||||||
|
if (!data.success) {
|
||||||
|
showToast(data.message || 'Error al consultar', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('cnt-pacientes').textContent = data.pacientes;
|
||||||
|
document.getElementById('cnt-recepciones').textContent = data.recepciones;
|
||||||
|
document.getElementById('cnt-examenes').textContent = data.examenes;
|
||||||
|
document.getElementById('preview-fecha').textContent = data.fecha;
|
||||||
|
|
||||||
|
const table = document.getElementById('preview-table');
|
||||||
|
if (data.pacientes === 0) {
|
||||||
|
table.innerHTML = '<div class="p-4 text-gray-400 text-center">No hay pacientes para esta fecha</div>';
|
||||||
|
showToast('No hay datos para esa fecha', 'warning');
|
||||||
|
} else {
|
||||||
|
table.innerHTML = data.pacientes_preview.map(p => `
|
||||||
|
<div class="flex items-center gap-3 px-4 py-2 text-sm hover:bg-gray-50">
|
||||||
|
<span class="text-gray-400 text-xs w-8">${p.tipo}</span>
|
||||||
|
<span class="text-gray-500 w-32 font-mono">${p.doc}</span>
|
||||||
|
<span class="text-gray-700 flex-1">${p.nombre}</span>
|
||||||
|
</div>
|
||||||
|
`).join('') + (data.hay_mas ? '<div class="px-4 py-2 text-xs text-gray-400">... y más pacientes</div>' : '');
|
||||||
|
|
||||||
|
document.getElementById('btn-run').disabled = false;
|
||||||
|
showToast(`${data.pacientes} paciente(s) y ${data.recepciones} recepción(es) encontradas`, 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('preview-section').classList.remove('hidden');
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
hideLoading(btn, '<i class="fas fa-eye"></i> Vista previa');
|
||||||
|
showToast('Error de conexión', 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function runAutomation() {
|
async function runAutomation() {
|
||||||
const fecha = document.getElementById('fecha-input').value;
|
const fecha = document.getElementById('fecha-input').value;
|
||||||
if (!fecha) { showToast('Selecciona una fecha', 'error'); return; }
|
if (!fecha) { showToast('Selecciona una fecha', 'error'); return; }
|
||||||
@@ -71,6 +157,7 @@ async function runAutomation() {
|
|||||||
|
|
||||||
const btn = document.getElementById('btn-run');
|
const btn = document.getElementById('btn-run');
|
||||||
showLoading(btn);
|
showLoading(btn);
|
||||||
|
document.getElementById('btn-preview').disabled = true;
|
||||||
document.getElementById('progress-section').classList.remove('hidden');
|
document.getElementById('progress-section').classList.remove('hidden');
|
||||||
document.getElementById('p1-badge').textContent = 'Enviando...';
|
document.getElementById('p1-badge').textContent = 'Enviando...';
|
||||||
document.getElementById('p1-badge').className = 'text-sm text-blue-500';
|
document.getElementById('p1-badge').className = 'text-sm text-blue-500';
|
||||||
@@ -84,6 +171,7 @@ async function runAutomation() {
|
|||||||
const resp = await fetch('/automation/run', { method: 'POST', body: form, credentials: 'include' });
|
const resp = await fetch('/automation/run', { method: 'POST', body: form, credentials: 'include' });
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
hideLoading(btn, '<i class="fas fa-play"></i> Ejecutar envío');
|
hideLoading(btn, '<i class="fas fa-play"></i> Ejecutar envío');
|
||||||
|
document.getElementById('btn-preview').disabled = false;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
showToast(data.message || 'Error', 'error');
|
showToast(data.message || 'Error', 'error');
|
||||||
@@ -94,22 +182,17 @@ async function runAutomation() {
|
|||||||
|
|
||||||
const r = data.resultado;
|
const r = data.resultado;
|
||||||
|
|
||||||
// Paso 1
|
|
||||||
renderBadge('p1-badge', r.paso1_terceros.enviados, r.paso1_terceros.errores);
|
renderBadge('p1-badge', r.paso1_terceros.enviados, r.paso1_terceros.errores);
|
||||||
renderDetalle('p1-detalle', r.paso1_terceros.detalle.map(d => ({
|
renderDetalle('p1-detalle', r.paso1_terceros.detalle.map(d => ({
|
||||||
col1: d.doc,
|
col1: d.doc, col2: d.nombre,
|
||||||
col2: d.nombre,
|
col3: `${d.ok ? '✅' : '❌'} ${d.msg || ''}`, ok: d.ok,
|
||||||
col3: `${d.ok ? '✅' : '❌'} ${d.msg || ''}`,
|
|
||||||
ok: d.ok,
|
|
||||||
})));
|
})));
|
||||||
|
|
||||||
// Paso 2
|
|
||||||
renderBadge('p2-badge', r.paso2_rda.enviados, r.paso2_rda.errores);
|
renderBadge('p2-badge', r.paso2_rda.enviados, r.paso2_rda.errores);
|
||||||
renderDetalle('p2-detalle', r.paso2_rda.detalle.map(d => ({
|
renderDetalle('p2-detalle', r.paso2_rda.detalle.map(d => ({
|
||||||
col1: `Fac. ${d.factura}`,
|
col1: `Fac. ${d.factura}`,
|
||||||
col2: `Pac. ${d.paciente} — ${d.examenes} examen(es)`,
|
col2: `Pac. ${d.paciente} — ${d.examenes} examen(es)`,
|
||||||
col3: `${d.ok ? '✅' : '❌'} ${d.msg || ''}`,
|
col3: `${d.ok ? '✅' : '❌'} ${d.msg || ''}`, ok: d.ok,
|
||||||
ok: d.ok,
|
|
||||||
})));
|
})));
|
||||||
|
|
||||||
const totalErr = r.paso1_terceros.errores + r.paso2_rda.errores;
|
const totalErr = r.paso1_terceros.errores + r.paso2_rda.errores;
|
||||||
@@ -118,6 +201,7 @@ async function runAutomation() {
|
|||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
hideLoading(btn, '<i class="fas fa-play"></i> Ejecutar envío');
|
hideLoading(btn, '<i class="fas fa-play"></i> Ejecutar envío');
|
||||||
|
document.getElementById('btn-preview').disabled = false;
|
||||||
showToast('Error de conexión', 'error');
|
showToast('Error de conexión', 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +222,7 @@ function renderBadge(id, enviados, errores) {
|
|||||||
|
|
||||||
function renderDetalle(id, items) {
|
function renderDetalle(id, items) {
|
||||||
const el = document.getElementById(id);
|
const el = document.getElementById(id);
|
||||||
if (!items || items.length === 0) { return; }
|
if (!items || items.length === 0) return;
|
||||||
el.innerHTML = items.map(i => `
|
el.innerHTML = items.map(i => `
|
||||||
<div class="px-6 py-2 flex items-center gap-3 text-sm ${i.ok ? '' : 'bg-red-50'}">
|
<div class="px-6 py-2 flex items-center gap-3 text-sm ${i.ok ? '' : 'bg-red-50'}">
|
||||||
<span class="text-gray-500 w-28 shrink-0">${i.col1}</span>
|
<span class="text-gray-500 w-28 shrink-0">${i.col1}</span>
|
||||||
|
|||||||
+58
-19
@@ -53,23 +53,51 @@
|
|||||||
|
|
||||||
<hr class="border-gray-200">
|
<hr class="border-gray-200">
|
||||||
|
|
||||||
<h4 class="font-medium text-gray-800"><i class="fas fa-cloud mr-2 text-blue-500"></i>API de Envío</h4>
|
<h4 class="font-medium text-gray-800"><i class="fas fa-key mr-2 text-orange-500"></i>Credenciales TNS</h4>
|
||||||
<div>
|
<p class="text-xs text-gray-500 -mt-2">Acceso a <strong>api.tns.co</strong> — portal de envío RIPS</p>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-1">URL Base de la API</label>
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<input type="text" name="config_api_url"
|
<div>
|
||||||
value="{{ configs|selectattr('key', 'equalto', 'api_url')|map(attribute='value')|first }}"
|
<label class="block text-sm font-medium text-gray-700 mb-1">Código Empresa</label>
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm"
|
<input type="text" name="config_tns_empresa"
|
||||||
placeholder="https://api.ejemplo.com">
|
value="{{ configs|selectattr('key', 'equalto', 'tns_empresa')|map(attribute='value')|first }}"
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm"
|
||||||
|
placeholder="Ej: 9002787299">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 mb-1">Código Sucursal</label>
|
||||||
|
<input type="text" name="config_api_sucursal"
|
||||||
|
value="{{ configs|selectattr('key', 'equalto', 'api_sucursal')|map(attribute='value')|first }}"
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm"
|
||||||
|
placeholder="Ej: 81080">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 gap-4">
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-1">Método HTTP</label>
|
<label class="block text-sm font-medium text-gray-700 mb-1">Usuario TNS</label>
|
||||||
<select name="config_api_method"
|
<input type="text" name="config_tns_usuario"
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm">
|
value="{{ configs|selectattr('key', 'equalto', 'tns_usuario')|map(attribute='value')|first }}"
|
||||||
<option value="POST" {% if (configs|selectattr('key', 'equalto', 'api_method')|map(attribute='value')|first) == 'POST' %}selected{% endif %}>POST</option>
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm"
|
||||||
<option value="PUT" {% if (configs|selectattr('key', 'equalto', 'api_method')|map(attribute='value')|first) == 'PUT' %}selected{% endif %}>PUT</option>
|
placeholder="Ej: DOCUXER">
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-gray-700 mb-1">Contraseña TNS</label>
|
||||||
|
<input type="password" name="config_tns_password"
|
||||||
|
value="{{ configs|selectattr('key', 'equalto', 'tns_password')|map(attribute='value')|first }}"
|
||||||
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button type="button" onclick="testTNS()"
|
||||||
|
class="px-4 py-2 bg-orange-50 text-orange-700 border border-orange-200 rounded-lg hover:bg-orange-100 text-sm font-medium">
|
||||||
|
<i class="fas fa-satellite-dish mr-1"></i> Probar conexión TNS
|
||||||
|
</button>
|
||||||
|
<span id="tns-status" class="text-sm ml-3"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr class="border-gray-200">
|
||||||
|
|
||||||
|
<h4 class="font-medium text-gray-800"><i class="fas fa-clock mr-2 text-blue-500"></i>API General</h4>
|
||||||
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-1">Timeout (seg)</label>
|
<label class="block text-sm font-medium text-gray-700 mb-1">Timeout (seg)</label>
|
||||||
<input type="number" name="config_api_timeout"
|
<input type="number" name="config_api_timeout"
|
||||||
@@ -77,12 +105,6 @@
|
|||||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm">
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-1">API Key (Bearer token)</label>
|
|
||||||
<input type="text" name="config_api_key"
|
|
||||||
value="{{ configs|selectattr('key', 'equalto', 'api_key')|map(attribute='value')|first }}"
|
|
||||||
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 text-sm">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr class="border-gray-200">
|
<hr class="border-gray-200">
|
||||||
|
|
||||||
@@ -112,6 +134,23 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
async function testTNS() {
|
||||||
|
const form = document.querySelector('form');
|
||||||
|
const status = document.getElementById('tns-status');
|
||||||
|
status.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Probando...';
|
||||||
|
|
||||||
|
const data = new FormData();
|
||||||
|
data.append('empresa', form.querySelector('[name="config_tns_empresa"]').value);
|
||||||
|
data.append('usuario', form.querySelector('[name="config_tns_usuario"]').value);
|
||||||
|
data.append('password', form.querySelector('[name="config_tns_password"]').value);
|
||||||
|
|
||||||
|
const resp = await fetch('/config/test-tns', { method: 'POST', body: data });
|
||||||
|
const result = await resp.json();
|
||||||
|
status.innerHTML = result.success
|
||||||
|
? '<span class="text-green-600"><i class="fas fa-check-circle"></i> ' + (result.message || 'Conexión exitosa') + '</span>'
|
||||||
|
: '<span class="text-red-600"><i class="fas fa-times-circle"></i> ' + result.message + '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
async function testFirebird() {
|
async function testFirebird() {
|
||||||
const btn = event.target;
|
const btn = event.target;
|
||||||
const status = document.getElementById('fb-status');
|
const status = document.getElementById('fb-status');
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user