Actualizar automatizaciones.html
This commit is contained in:
@@ -6,19 +6,38 @@
|
|||||||
<title>Automatizaciones - Integra Repara</title>
|
<title>Automatizaciones - Integra Repara</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
<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">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Estilos para integrarse con tu layout.js */
|
/* Estilos críticos para que encaje con el sidebar de Integra Repara */
|
||||||
body { background-color: #f8fafc; margin: 0; }
|
body { background-color: #f8fafc; overflow-x: hidden; }
|
||||||
#main-content { margin-left: 260px; padding: 2rem; margin-top: 60px; min-height: calc(100vh - 60px); transition: 0.3s; }
|
|
||||||
|
|
||||||
.service-card { border: none; border-radius: 12px; background: white; border-left: 5px solid #22c55e; transition: 0.2s; margin-bottom: 1rem; }
|
/* Contenedor principal que deja espacio a la barra lateral */
|
||||||
.service-card:hover { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }
|
#main-content {
|
||||||
|
margin-left: 260px; /* Ancho exacto de tu sidebar azul */
|
||||||
|
padding: 2rem;
|
||||||
|
margin-top: 60px; /* Espacio para la cabecera superior */
|
||||||
|
min-height: calc(100vh - 60px);
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-card {
|
||||||
|
border: none;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: white;
|
||||||
|
border-left: 5px solid #22c55e;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
.service-card:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.05); }
|
||||||
|
|
||||||
.badge-provider { font-weight: 800; font-size: 0.7rem; padding: 4px 10px; border-radius: 20px; text-transform: uppercase; }
|
.badge-provider { font-weight: 800; font-size: 0.7rem; padding: 4px 10px; border-radius: 20px; text-transform: uppercase; }
|
||||||
.multiasistencia { background: #dbeafe; color: #1e40af; }
|
.multiasistencia { background: #dbeafe; color: #1e40af; }
|
||||||
.homeserve { background: #fee2e2; color: #991b1b; }
|
.homeserve { background: #fee2e2; color: #991b1b; }
|
||||||
|
|
||||||
@media (max-width: 992px) { #main-content { margin-left: 0; } }
|
/* Ajuste para móviles: el margen desaparece si el menú se oculta */
|
||||||
|
@media (max-width: 992px) {
|
||||||
|
#main-content { margin-left: 0; padding: 1rem; }
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -28,26 +47,32 @@
|
|||||||
|
|
||||||
<div id="main-content">
|
<div id="main-content">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
<div class="row mb-4">
|
||||||
<div>
|
<div class="col-md-8">
|
||||||
<h2 class="fw-bold mb-0">🤖 Buzón de Automatizaciones</h2>
|
<h2 class="fw-bold mb-0">🤖 Buzón de Automatizaciones</h2>
|
||||||
<p class="text-muted">Revisa, edita e importa los servicios de Multiasistencia y HomeServe.</p>
|
<p class="text-muted">Revisa, edita e importa los servicios detectados.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 text-end">
|
||||||
|
<button onclick="loadInbox()" class="btn btn-primary rounded-pill px-4 shadow-sm">
|
||||||
|
<i class="fas fa-sync-alt me-2"></i>Actualizar Buzón
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<button onclick="loadInbox()" class="btn btn-primary rounded-pill px-4 shadow-sm">
|
|
||||||
<i class="fas fa-sync-alt me-2"></i>Actualizar Buzón
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="inboxContainer">
|
<div id="inboxContainer">
|
||||||
|
<div class="text-center py-5">
|
||||||
|
<div class="spinner-border text-primary"></div>
|
||||||
|
<p class="mt-2">Conectando con los robots...</p>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" id="editImportModal" tabindex="-1">
|
<div class="modal fade" id="editImportModal" tabindex="-1" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-lg">
|
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||||
<div class="modal-content border-0 shadow-lg">
|
<div class="modal-content border-0 shadow-lg">
|
||||||
<div class="modal-header bg-primary text-white">
|
<div class="modal-header bg-dark text-white p-4">
|
||||||
<h5 class="modal-title fw-bold"><i class="fas fa-edit me-2"></i>Revisar e Importar Servicio</h5>
|
<h5 class="modal-title fw-bold"><i class="fas fa-edit me-2"></i>Validar Datos del Servicio</h5>
|
||||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body p-4">
|
<div class="modal-body p-4">
|
||||||
@@ -55,45 +80,45 @@
|
|||||||
<input type="hidden" id="scrapedId">
|
<input type="hidden" id="scrapedId">
|
||||||
|
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<label class="form-label small fw-bold text-secondary">NOMBRE DEL CLIENTE</label>
|
<label class="form-label small fw-bold">NOMBRE COMPLETO</label>
|
||||||
<input type="text" id="imp_name" class="form-control form-control-lg border-2">
|
<input type="text" id="imp_name" class="form-control border-2">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-5">
|
<div class="col-md-5">
|
||||||
<label class="form-label small fw-bold text-secondary">TELÉFONO DE CONTACTO</label>
|
<label class="form-label small fw-bold">TELÉFONO</label>
|
||||||
<input type="text" id="imp_phone" class="form-control form-control-lg border-2">
|
<input type="text" id="imp_phone" class="form-control border-2">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<label class="form-label small fw-bold text-secondary">DIRECCIÓN DE LA REPARACIÓN</label>
|
<label class="form-label small fw-bold">DIRECCIÓN COMPLETA</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text bg-white border-2"><i class="fas fa-map-marker-alt text-danger"></i></span>
|
<span class="input-group-text bg-white border-2"><i class="fas fa-map-marker-alt text-primary"></i></span>
|
||||||
<input type="text" id="imp_address" class="form-control form-control-lg border-2">
|
<input type="text" id="imp_address" class="form-control border-2">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<label class="form-label small fw-bold text-secondary">DESCRIPCIÓN DE TRABAJOS</label>
|
<label class="form-label small fw-bold">DESCRIPCIÓN DE LA AVERÍA</label>
|
||||||
<textarea id="imp_description" class="form-control border-2" rows="5" placeholder="Detalle de la avería detectada..."></textarea>
|
<textarea id="imp_description" class="form-control border-2" rows="5"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<label class="form-label small fw-bold text-secondary">REFERENCIA</label>
|
<label class="form-label small fw-bold">EXPEDIENTE REF.</label>
|
||||||
<input type="text" id="imp_ref" class="form-control border-2 bg-light" readonly>
|
<input type="text" id="imp_ref" class="form-control bg-light" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<label class="form-label small fw-bold text-secondary">COMPAÑÍA</label>
|
<label class="form-label small fw-bold">COMPAÑÍA ORIGEN</label>
|
||||||
<input type="text" id="imp_company" class="form-control border-2 bg-light">
|
<input type="text" id="imp_company" class="form-control bg-light" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<label class="form-label small fw-bold text-secondary">URGENCIA</label>
|
<label class="form-label small fw-bold">TIPO AVISO</label>
|
||||||
<select id="imp_urgent" class="form-select border-2">
|
<select id="imp_urgent" class="form-select border-2">
|
||||||
<option value="false">Normal</option>
|
<option value="false">Servicio Normal</option>
|
||||||
<option value="true">⚠️ URGENTE</option>
|
<option value="true">🚨 URGENTE</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer bg-light border-0">
|
<div class="modal-footer bg-light p-3">
|
||||||
<button type="button" class="btn btn-link text-secondary" data-bs-dismiss="modal">Descartar</button>
|
<button type="button" class="btn btn-secondary rounded-pill px-4" data-bs-dismiss="modal">Cerrar</button>
|
||||||
<button onclick="saveToCRM()" class="btn btn-success btn-lg px-5 fw-bold rounded-pill">
|
<button onclick="saveToCRM()" class="btn btn-success rounded-pill px-5 fw-bold shadow">
|
||||||
<i class="fas fa-cloud-upload-alt me-2"></i>GUARDAR EN CRM
|
<i class="fas fa-save me-2"></i>CONFIRMAR E IMPORTAR
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -103,12 +128,10 @@
|
|||||||
<script src="./js/layout.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="./js/layout.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let mappings = [];
|
let globalMappings = [];
|
||||||
|
|
||||||
async function loadInbox() {
|
async function loadInbox() {
|
||||||
const container = document.getElementById('inboxContainer');
|
const container = document.getElementById('inboxContainer');
|
||||||
container.innerHTML = '<div class="text-center py-5"><div class="spinner-border text-primary"></div></div>';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [svcRes, mapRes] = await Promise.all([
|
const [svcRes, mapRes] = await Promise.all([
|
||||||
fetch(`${API_URL}/providers/scraped`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` }}),
|
fetch(`${API_URL}/providers/scraped`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` }}),
|
||||||
@@ -116,78 +139,76 @@
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const svcData = await svcRes.json();
|
const svcData = await svcRes.json();
|
||||||
mappings = await mapRes.json();
|
globalMappings = await mapRes.json();
|
||||||
|
|
||||||
if (!svcData.services || svcData.services.length === 0) {
|
if (!svcData.services || svcData.services.length === 0) {
|
||||||
container.innerHTML = '<div class="alert alert-light text-center py-5 border-dashed">No hay servicios nuevos pendientes.</div>';
|
container.innerHTML = '<div class="alert alert-light text-center py-5 border-dashed">No hay nuevos expedientes detectados por el robot.</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
svcData.services.forEach(svc => {
|
svcData.services.forEach(svc => {
|
||||||
const raw = svc.raw_data || {};
|
const raw = svc.raw_data || {};
|
||||||
const myMap = mappings.filter(m => m.provider === svc.provider);
|
const myMap = globalMappings.filter(m => m.provider === svc.provider);
|
||||||
|
|
||||||
// Extraer según tu mapeo configurado
|
// Mapeo dinámico para el listado
|
||||||
const name = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "Sin nombre";
|
const name = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "No detectado";
|
||||||
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "Sin dirección";
|
const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "Sin dirección";
|
||||||
const phone = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "S/T";
|
const phone = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "S/T";
|
||||||
const desc = raw[myMap.find(m => m.target_key === 'descripcion')?.original_key] || raw['Descripción'] || "Sin descripción";
|
|
||||||
|
|
||||||
const card = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
card.className = 'service-card shadow-sm p-4 d-flex justify-content-between align-items-center';
|
div.innerHTML = `
|
||||||
card.innerHTML = `
|
<div class="service-card shadow-sm p-4 d-flex justify-content-between align-items-center">
|
||||||
<div class="row w-100 align-items-center">
|
<div class="row w-100 align-items-center">
|
||||||
<div class="col-md-2 border-end">
|
<div class="col-md-2 border-end">
|
||||||
<span class="badge-provider ${svc.provider}">${svc.provider}</span>
|
<span class="badge-provider ${svc.provider}">${svc.provider}</span>
|
||||||
<div class="small fw-bold mt-2 text-muted">#${svc.service_ref}</div>
|
<div class="small fw-bold mt-2 text-primary">#${svc.service_ref}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="small fw-bold text-secondary">CLIENTE</div>
|
<div class="small text-muted fw-bold">CLIENTE</div>
|
||||||
<div class="fw-bold">${name}</div>
|
<div class="fw-bold text-uppercase">${name}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="small fw-bold text-secondary">UBICACIÓN</div>
|
<div class="small text-muted fw-bold">UBICACIÓN</div>
|
||||||
<div class="text-truncate" style="max-width: 250px;">${addr}</div>
|
<div class="text-truncate" title="${addr}">${addr}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-2">
|
<div class="col-md-2 text-center">
|
||||||
<div class="small fw-bold text-secondary">TELÉFONO</div>
|
<div class="small text-muted fw-bold">TELÉFONO</div>
|
||||||
<div>${phone}</div>
|
<div class="badge bg-light text-dark border">${phone}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-1 text-end">
|
<div class="col-md-1 text-end">
|
||||||
<button onclick="openEditor(${svc.id}, '${svc.provider}')" class="btn btn-outline-success rounded-circle shadow-sm">
|
<button onclick="editAndImport(${svc.id}, '${svc.provider}')" class="btn btn-success rounded-circle shadow">
|
||||||
<i class="fas fa-check"></i>
|
<i class="fas fa-check"></i>
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
container.appendChild(card);
|
container.appendChild(div);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
container.innerHTML = '<div class="alert alert-danger">Error de sincronización con la API.</div>';
|
container.innerHTML = '<div class="alert alert-danger">Error de conexión con el servidor Integra Repara.</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openEditor(scrapedId, provider) {
|
async function editAndImport(scrapedId, provider) {
|
||||||
try {
|
const res = await fetch(`${API_URL}/providers/scraped`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` }});
|
||||||
const res = await fetch(`${API_URL}/providers/scraped`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` }});
|
const data = await res.json();
|
||||||
const data = await res.json();
|
const svc = data.services.find(s => s.id === scrapedId);
|
||||||
const svc = data.services.find(s => s.id === scrapedId);
|
const raw = svc.raw_data;
|
||||||
const raw = svc.raw_data;
|
const myMap = globalMappings.filter(m => m.provider === provider);
|
||||||
const myMap = mappings.filter(m => m.provider === provider);
|
|
||||||
|
|
||||||
// Llenar el formulario del modal
|
// Rellenar formulario modal con los datos mapeados
|
||||||
document.getElementById('scrapedId').value = scrapedId;
|
document.getElementById('scrapedId').value = scrapedId;
|
||||||
document.getElementById('imp_name').value = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
document.getElementById('imp_name').value = raw[myMap.find(m => m.target_key === 'clientName')?.original_key] || "";
|
||||||
document.getElementById('imp_phone').value = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
document.getElementById('imp_phone').value = raw[myMap.find(m => m.target_key === 'phone')?.original_key] || raw['Teléfono'] || "";
|
||||||
document.getElementById('imp_address').value = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
document.getElementById('imp_address').value = raw[myMap.find(m => m.target_key === 'address')?.original_key] || "";
|
||||||
document.getElementById('imp_ref').value = svc.service_ref;
|
document.getElementById('imp_ref').value = svc.service_ref;
|
||||||
document.getElementById('imp_company').value = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || provider.toUpperCase();
|
document.getElementById('imp_company').value = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || provider.toUpperCase();
|
||||||
document.getElementById('imp_description').value = raw[myMap.find(m => m.target_key === 'descripcion')?.original_key] || raw['Descripción'] || "";
|
document.getElementById('imp_description').value = raw[myMap.find(m => m.target_key === 'descripcion')?.original_key] || raw['Descripción'] || "";
|
||||||
document.getElementById('imp_urgent').value = (raw['Urgente'] === 'Sí').toString();
|
document.getElementById('imp_urgent').value = (raw['Urgente'] === 'Sí').toString();
|
||||||
|
|
||||||
new bootstrap.Modal(document.getElementById('editImportModal')).show();
|
new bootstrap.Modal(document.getElementById('editImportModal')).show();
|
||||||
} catch (e) { alert("No se pudo abrir el editor."); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveToCRM() {
|
async function saveToCRM() {
|
||||||
@@ -201,19 +222,17 @@
|
|||||||
is_urgent: document.getElementById('imp_urgent').value === 'true'
|
is_urgent: document.getElementById('imp_urgent').value === 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
const res = await fetch(`${API_URL}/providers/import/${id}`, {
|
||||||
const res = await fetch(`${API_URL}/providers/import/${id}`, {
|
method: 'POST',
|
||||||
method: 'POST',
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
body: JSON.stringify(payload)
|
||||||
body: JSON.stringify(payload)
|
});
|
||||||
});
|
|
||||||
|
if ((await res.json()).ok) {
|
||||||
if ((await res.json()).ok) {
|
bootstrap.Modal.getInstance(document.getElementById('editImportModal')).hide();
|
||||||
bootstrap.Modal.getInstance(document.getElementById('editImportModal')).hide();
|
loadInbox();
|
||||||
loadInbox();
|
alert("✅ Expediente importado y guardado en Servicios.");
|
||||||
alert("✅ ¡Servicio creado correctamente en el CRM!");
|
}
|
||||||
}
|
|
||||||
} catch (e) { alert("Error al importar al CRM."); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', loadInbox);
|
document.addEventListener('DOMContentLoaded', loadInbox);
|
||||||
|
|||||||
Reference in New Issue
Block a user