From ac2c74c6af4b82dc0f39e0107022d695b66ce499 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sat, 14 Mar 2026 14:26:02 +0000 Subject: [PATCH] Actualizar proveedores.html --- proveedores.html | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/proveedores.html b/proveedores.html index 92a0ecd..f81250a 100644 --- a/proveedores.html +++ b/proveedores.html @@ -672,21 +672,31 @@ } document.getElementById('impScrapedId').value = id; - document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N"; + // 1. LEER PRIMERO DE LA RAÍZ (DATOS EDITADOS), LUEGO DEL RAW (DATOS ORIGINALES) + document.getElementById('impName').value = svc.name || raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N"; const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || ""; - document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || ""; + document.getElementById('impPhone').value = svc.phone || (rawPhone.match(/[6789]\d{8}/)?.[0] || ""); - const addr = raw['Dirección'] || raw['DOMICILIO'] || ""; + // 2. REPARACIÓN DE LA DIRECCIÓN DUPLICADA + const baseAddr = svc.address || raw['Dirección'] || raw['DOMICILIO'] || ""; const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || ""; - document.getElementById('impAddress').value = `${addr} ${pop}`.trim(); - document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || ""; - document.getElementById('impDesc').value = raw['Descripción'] || ""; + + let finalAddr = baseAddr; + // Solo añadimos la población si hay población Y la dirección actual no la contiene ya + if (pop && !finalAddr.toLowerCase().includes(pop.toLowerCase())) { + finalAddr = `${finalAddr} ${pop}`.trim(); + } + document.getElementById('impAddress').value = finalAddr; + + document.getElementById('impCP').value = svc.cp || raw['Código Postal'] || raw['C.P.'] || ""; + document.getElementById('impDesc').value = svc.description || raw['Descripción'] || ""; const isUrgent = svc.is_urgent === true || raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI'; document.getElementById('impUrgent').value = isUrgent.toString(); - document.getElementById('impNotesInt').value = raw['internal_notes'] || ""; - document.getElementById('impNotesExt').value = raw['client_notes'] || ""; + + document.getElementById('impNotesInt').value = svc.internal_notes || raw['internal_notes'] || ""; + document.getElementById('impNotesExt').value = svc.client_notes || raw['client_notes'] || ""; const rawGuildId = svc.guild_id || raw['guild_id'] || raw.guild_id; document.getElementById('impGuild').value = rawGuildId ? String(rawGuildId) : "";