diff --git a/automatizaciones.html b/automatizaciones.html index 3fe5fab..8b01e69 100644 --- a/automatizaciones.html +++ b/automatizaciones.html @@ -34,7 +34,7 @@ Buzón de Automatizaciones -

Gestiona e importa los avisos capturados por los robots.

+

Validación y limpieza quirúrgica de expedientes externos.

` : ` -
+
`}
@@ -226,14 +234,15 @@ document.getElementById('imp_phone').value = phoneMatch ? phoneMatch[0] : ""; document.getElementById('imp_phone_extra').innerText = phoneVal !== (phoneMatch ? phoneMatch[0] : "") ? `Dato original capturado: ${phoneVal}` : ""; - // 2. CP Y DIRECCIÓN + POBLACIÓN - const addr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || ""; - const pop = raw[myMap.find(m => m.target_key === 'poblacion')?.original_key] || ""; - const cpVal = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || ""; - const cpMatch = cpVal.match(/\b\d{5}\b/); - - document.getElementById('imp_address').value = `${addr} ${pop}`.trim(); - document.getElementById('imp_cp').value = cpMatch ? cpMatch[0] : ""; + // 2. SEPARAR CP Y POBLACIÓN DEL CAMPO CP + const rawAddr = raw[myMap.find(m => m.target_key === 'address')?.original_key] || ""; + const rawCPField = raw[myMap.find(m => m.target_key === 'cp')?.original_key] || raw['Población_CP'] || ""; + const cpMatch = rawCPField.match(/\b\d{5}\b/); + const cpOnly = cpMatch ? cpMatch[0] : ""; + const popOnly = rawCPField.replace(cpOnly, '').replace('-', '').trim(); + + document.getElementById('imp_address').value = `${rawAddr} ${popOnly}`.trim(); + document.getElementById('imp_cp').value = cpOnly; // 3. PROVEEDOR ACORTADO EN COMPAÑÍA const cia = raw[myMap.find(m => m.target_key === 'compania')?.original_key] || raw['Compañía'] || ""; @@ -269,11 +278,11 @@ try { const res = await fetch(`${API_URL}/providers/import/${document.getElementById('scrapedId').value}`, { 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) }); if(res.ok) { - showToast("✅ ¡Expediente importado con éxito!"); + showToast("✅ ¡Expediente importado!"); closeModal(); loadInbox(); } else { showToast("Error al importar", true); }