{{ (() => { const LOGO_URL = "https://raw.githubusercontent.com/agencia-buffalo/riesgonet-dev/main/src/img/rn-logo-header.png"; // Fecha/Hora de generación const now = new Date(); const pad2 = (n) => String(n).padStart(2, '0'); const fechaHora = `${pad2(now.getDate())}/${pad2(now.getMonth()+1)}/${now.getFullYear()} ` + `${pad2(now.getHours())}:${pad2(now.getMinutes())}:${pad2(now.getSeconds())}`; return ` Informe de Crédito - RiesgoNet
Generado: ${fechaHora}
Informe de Crédito
`; })() }} {{ (() => { // Función safeText function safeText(val) { if (val === null || val === undefined) return '-'; const str = String(val).trim(); return str || '-'; } // Formateos function onlyDigits(s) { return String(s || '').replace(/\D+/g, ''); } function formatDNI(val) { const d = onlyDigits(val); if (!d) return safeText(val); const rev = d.split('').reverse().join(''); const chunks = rev.match(/.{1,3}/g) || []; return chunks.join('.').split('').reverse().join(''); } function formatCUIT(val) { const d = onlyDigits(val); if (d.length !== 11) return safeText(val); return `${d.slice(0,2)}-${d.slice(2,10)}-${d.slice(10)}`; } function formatSexo(val) { const s = safeText(val); const up = String(s).toUpperCase(); if (up === 'M' || up === 'MASCULINO') return 'Masculino'; if (up === 'F' || up === 'FEMENINO') return 'Femenino'; return s; } function formatValueByLabel(label, value) { const L = String(label || '').toUpperCase(); if (L.includes('DNI')) return formatDNI(value); if (L.includes('CUIT') || L.includes('CUIL') || L.includes('CLAVE FISCAL')) return formatCUIT(value); if (L.includes('SEXO')) return formatSexo(value); return safeText(value); } function findValueByLabel(list, searchTerms) { if (!Array.isArray(list)) return null; const item = list.find(r => { if (!r || !r.label) return false; const label = String(r.label).toUpperCase(); return searchTerms.some(term => label.includes(term.toUpperCase())); }); return item ? item.value : null; } function removeFieldsByLabel(list, searchTerms) { if (!Array.isArray(list)) return list; return list.filter(r => { if (!r || !r.label) return true; const label = String(r.label).toUpperCase(); return !searchTerms.some(term => label.includes(term.toUpperCase())); }); } const iv1 = ($json && $json.individualizacion_v1) ? $json.individualizacion_v1 : {}; const raw = (iv1 && iv1.raw) ? iv1.raw : {}; const ocupacion = safeText( raw.ocupacion || raw.profesion || raw['ocupación'] || raw['profesión'] ); let list = Array.isArray(iv1.individualizacion) ? [...iv1.individualizacion] : []; let locList = Array.isArray(iv1.localizacion) ? [...iv1.localizacion] : []; // 1) COMBINAR APELLIDO Y NOMBRE const apellido = findValueByLabel(list, ['APELLIDO']); const nombre = findValueByLabel(list, ['NOMBRE']) || findValueByLabel(list, ['NOMBRES']); if (apellido && nombre) { list = removeFieldsByLabel(list, ['APELLIDO', 'NOMBRE', 'NOMBRES']); list.unshift({ label: 'Apellido y Nombre', value: `${apellido} ${nombre}` }); } // 2) COMBINAR TIPO DE DOCUMENTO Y NÚMERO const tipoDoc = findValueByLabel(list, ['EJEMPLAR', 'TIPO']); const dni = findValueByLabel(list, ['DNI', 'DOCUMENTO']); if (dni) { list = removeFieldsByLabel(list, ['DNI', 'DOCUMENTO', 'EJEMPLAR', 'TIPO']); const docCompleto = tipoDoc ? `DNI ${tipoDoc} ${formatDNI(dni)}` : `DNI ${formatDNI(dni)}`; list.unshift({ label: 'Documento', value: docCompleto }); } // 3) MOVER NACIONALIDAD DE LOCALIZACIÓN A INDIVIDUALIZACIÓN const nacionalidad = findValueByLabel(locList, ['NACIONALIDAD']); if (nacionalidad) { locList = removeFieldsByLabel(locList, ['NACIONALIDAD']); list.push({ label: 'Nacionalidad', value: nacionalidad }); } // 4) SI HAY FECHA DE NACIMIENTO, NO IMPRIMIR CLASE const fechaNac = findValueByLabel(list, ['FECHA', 'NACIMIENTO']); if (fechaNac) { list = removeFieldsByLabel(list, ['CLASE']); } // 5) CAMBIAR CUIL/CUIT A "CLAVE FISCAL" list = list.map(item => { if (!item || !item.label) return item; const label = String(item.label).toUpperCase(); if (label.includes('CUIT') || label.includes('CUIL') || label.includes('REGISTRO FISCAL')) { return { ...item, label: 'Clave Fiscal' }; } return item; }); // 7) COMBINAR DOMICILIO CON LOCALIDAD, PROVINCIA Y CP const domicilio = findValueByLabel(locList, ['DOMICILIO', 'CALLE', 'DIRECCIÓN', 'PADRÓN']); const localidad = findValueByLabel(locList, ['LOCALIDAD', 'CIUDAD']); const provincia = findValueByLabel(locList, ['PROVINCIA']); const cp = findValueByLabel(locList, ['CÓDIGO POSTAL', 'CP', 'CPA']); if (domicilio || localidad || provincia || cp) { locList = removeFieldsByLabel(locList, ['DOMICILIO', 'CALLE', 'DIRECCIÓN', 'PADRÓN', 'LOCALIDAD', 'CIUDAD', 'PROVINCIA', 'CÓDIGO POSTAL', 'CP', 'CPA']); const partes = []; if (domicilio && safeText(domicilio) !== '-') partes.push(safeText(domicilio)); if (localidad && safeText(localidad) !== '-') partes.push(safeText(localidad)); if (provincia && safeText(provincia) !== '-') partes.push(safeText(provincia)); if (cp && safeText(cp) !== '-') partes.push(`CP ${safeText(cp)}`); const domicilioCompleto = partes.length > 0 ? partes.join(', ') : '-'; locList.unshift({ label: 'Domicilio', value: domicilioCompleto }); } // 8) COMBINAR DEPARTAMENTO, SECCIÓN Y CIRCUITO const depto = findValueByLabel(locList, ['DEPARTAMENTO']); const seccion = findValueByLabel(locList, ['SECCIÓN', 'SECCION']); const circuito = findValueByLabel(locList, ['CIRCUITO']); if (depto || seccion || circuito) { locList = removeFieldsByLabel(locList, ['DEPARTAMENTO', 'SECCIÓN', 'SECCION', 'CIRCUITO']); const partes = []; if (depto && safeText(depto) !== '-') partes.push(`Depto ${safeText(depto)}`); if (seccion && safeText(seccion) !== '-') partes.push(`Secc ${safeText(seccion)}`); if (circuito && safeText(circuito) !== '-') partes.push(`Circ ${safeText(circuito)}`); if (partes.length > 0) { locList.push({ label: 'Distrito Electoral', value: partes.join(' - ') }); } } const hasOcupacion = list.some(x => (x && x.label ? String(x.label) : '').toUpperCase().includes('OCUP') ); const ocupacionRow = (!hasOcupacion && ocupacion && safeText(ocupacion) !== '-') ? `
Ocupación
${ocupacion}
` : ''; const posibleFallecido = safeText(iv1 && iv1.estado ? iv1.estado.posible_fallecido : ''); const existencia = safeText(iv1 && iv1.estado ? (iv1.estado.existencia || '-') : '-'); const mapa = (iv1 && iv1.mapa) ? iv1.mapa : null; const hasCoords = !!(mapa && mapa.lat && mapa.lon); const isPF = (String(posibleFallecido).toUpperCase() === 'SI'); return `
Individualización
Existencia
${existencia}
Posible fallecido
${isPF ? 'SI' : 'NO'}
${(list || []).map(r => { const label = safeText(r && r.label ? r.label : '-'); const value = (r && r.value !== undefined) ? r.value : '-'; const formatted = formatValueByLabel(label, value); const isEmail = String(label).toUpperCase().includes('EMAIL') || String(label).toUpperCase().includes('E-MAIL') || String(label).toUpperCase().includes('CORREO'); const valueDisplay = isEmail && safeText(value) !== '-' ? \`\${safeText(value)}\` : formatted; return \`
\${label}
\${valueDisplay}
\`; }).join('')} ${ocupacionRow}
Localización
${(locList || []).map(r => { const label = safeText(r && r.label ? r.label : '-'); const value = (r && r.value !== undefined) ? r.value : '-'; const formatted = formatValueByLabel(label, value); const isEmail = String(label).toUpperCase().includes('EMAIL') || String(label).toUpperCase().includes('E-MAIL') || String(label).toUpperCase().includes('CORREO'); const valueDisplay = isEmail && safeText(value) !== '-' ? \`\${safeText(value)}\` : formatted; return \`
\${label}
\${valueDisplay}
\`; }).join('')} ${hasCoords ? \`
Mapa (domicilio padrón)
\${safeText(mapa.domicilio_texto)}
Lat: \${safeText(mapa.lat)} · Lon: \${safeText(mapa.lon)}
Abrir en Google Maps \${mapa.swapped ? \\\` · (coords corregidas)\\\` : \\\`\\\`}
\${mapa.swapped ? \\\`
Nota: coordenadas corregidas (lat/lon venían invertidas en origen).
\\\` : \\\`\\\`}
\` : \`
Mapa
Sin coordenadas
\` }
Fuente de Información
Relevamiento propio
Registros Públicos - On line
AFIP - On line
Verificación de Identidad - Internet
`; })() }} {{ (() => { return `
`; })() }}