159 lines
7.4 KiB
JSON
159 lines
7.4 KiB
JSON
{
|
|
"name": "Portal de Verificación de Nómina El Salvador - Históricos",
|
|
"nodes": [
|
|
{
|
|
"parameters": {
|
|
"path": "cruce-cuentas-sv-historicos",
|
|
"responseMode": "responseNode",
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.webhook",
|
|
"typeVersion": 2.1,
|
|
"position": [
|
|
608,
|
|
400
|
|
],
|
|
"id": "485c6599-40fd-491b-b62d-e3acb92c23d8",
|
|
"name": "Webhook Históricos SV",
|
|
"webhookId": "b225465a-eaa6-4d3e-ab6b-9ea4fc7375d1"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "const items = $input.all();\n\nfunction formatDate(value) {\n if (!value) return '';\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) return String(value).slice(0, 10);\n return date.toISOString().slice(0, 10);\n}\n\nfunction toNumber(value) {\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : 0;\n}\n\nfunction normalizeStatus(value, discrepancias) {\n const status = String(value || '').toLowerCase();\n\n if (status === 'resuelto') return 'resuelto';\n if (status === 'procesado' && toNumber(discrepancias) === 0) return 'procesado';\n\n return 'pendiente_revision';\n}\n\nfunction statusLabel(status) {\n if (status === 'resuelto') return 'RESUELTO';\n if (status === 'procesado') return 'PROCESADO';\n return 'PENDIENTE REVISIÓN';\n}\n\nconst reports = items.map((item) => {\n const row = item.json || {};\n\n const discrepancias = toNumber(row.discrepancias);\n const bancoSinNomina = toNumber(row.banco_sin_nomina);\n const nominaSinCuenta = toNumber(row.nomina_sin_cuenta);\n const bancoSinBamboo = toNumber(row.banco_sin_bamboo);\n const nominaSinBamboo = toNumber(row.nomina_sin_bamboo);\n const bambooSinNomina = toNumber(row.bamboo_sin_nomina);\n\n const totalPendientes =\n discrepancias +\n bancoSinNomina +\n nominaSinCuenta +\n bancoSinBamboo +\n nominaSinBamboo +\n bambooSinNomina;\n\n const estado = normalizeStatus(row.estado, totalPendientes);\n\n return {\n id: row.id,\n\n fecha: formatDate(row.period_end || row.ejecutado_en || row.created_at),\n fechaEjecucion: row.ejecutado_en || row.created_at,\n\n periodo: row.period_label || '',\n year: row.year,\n month: row.month,\n periodType: row.period_type,\n periodStart: row.period_start,\n periodEnd: row.period_end,\n\n archivoNomina: row.payroll_file_name || '',\n archivosBanco: row.bank_file_names || [],\n\n coincidencias: toNumber(row.coincidencias),\n discrepancias,\n bancoSinNomina,\n nominaSinCuenta,\n bancoSinBamboo,\n nominaSinBamboo,\n bambooSinNomina,\n totalPendientes,\n\n totalNomina: toNumber(row.total_nomina),\n totalBanco: toNumber(row.total_banco),\n diferenciaTotal: toNumber(row.diferencia_total),\n\n estado,\n estadoLabel: statusLabel(estado),\n\n reportUrl: row.report_url || '',\n spreadsheetId: row.spreadsheet_id || '',\n\n ejecutadoPorNombre: row.ejecutado_por_nombre || '',\n ejecutadoPorEmail: row.ejecutado_por_email || '',\n\n resueltoPorNombre: row.resuelto_por_nombre || '',\n resueltoPorEmail: row.resuelto_por_email || '',\n resueltoEn: row.resuelto_en || null,\n comentarioResolucion: row.comentario_resolucion || '',\n };\n});\n\nreturn [\n {\n json: {\n ok: true,\n stage: 'historicos_sv_listos',\n count: reports.length,\n reports,\n },\n },\n];"
|
|
},
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 2,
|
|
"position": [
|
|
1024,
|
|
400
|
|
],
|
|
"id": "9531b25a-916e-4788-841a-68ccb2a42d3d",
|
|
"name": "Normalizar históricos para app"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"url": "https://dbit.digitalcompass.agency/rest/v1/cruces_cuentas_gt_reportes?select=*&country=eq.SV&order=ejecutado_en.desc&limit=100",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "apikey",
|
|
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Authorization",
|
|
"value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q"
|
|
},
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
}
|
|
]
|
|
},
|
|
"options": {}
|
|
},
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4.4,
|
|
"position": [
|
|
816,
|
|
400
|
|
],
|
|
"id": "bb61d9d5-8258-44b7-9d4b-18633fdc8bc4",
|
|
"name": "Consultar históricos Supabase"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"respondWith": "json",
|
|
"responseBody": "={{ $json }}",
|
|
"options": {
|
|
"responseHeaders": {
|
|
"entries": [
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
},
|
|
{
|
|
"name": "Access-Control-Allow-Origin",
|
|
"value": "*"
|
|
},
|
|
{
|
|
"name": "Access-Control-Allow-Methods",
|
|
"value": "GET,POST,OPTIONS"
|
|
},
|
|
{
|
|
"name": "Access-Control-Allow-Headers",
|
|
"value": "Content-Type, Authorization"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"type": "n8n-nodes-base.respondToWebhook",
|
|
"typeVersion": 1.5,
|
|
"position": [
|
|
1248,
|
|
400
|
|
],
|
|
"id": "769a572b-e78a-4327-a397-66438783bbef",
|
|
"name": "Responder históricos app"
|
|
},
|
|
{
|
|
"parameters": {
|
|
"content": "# 📚 HISTÓRICOS DE VERIFICACIÓN — EL SALVADOR\n\nEntrega a la aplicación el historial de reportes procesados para El Salvador.\n\n- Consulta únicamente registros con `country = SV`.\n- Supabase sigue usando la tabla histórica compartida `cruces_cuentas_gt_reportes`; el nombre es legado, pero la tabla es multi-país.\n- Devuelve la misma estructura que Guatemala y Trinidad y Tobago.\n- Este webhook sirve como respaldo; la app intenta primero la RPC paginada de Supabase.",
|
|
"height": 496,
|
|
"width": 1360,
|
|
"color": 6
|
|
},
|
|
"type": "n8n-nodes-base.stickyNote",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
304,
|
|
128
|
|
],
|
|
"id": "60352e6e-7a0c-4a73-adf2-0183a78e1796",
|
|
"name": "Sticky Note"
|
|
}
|
|
],
|
|
"pinData": {},
|
|
"connections": {
|
|
"Consultar históricos Supabase": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Normalizar históricos para app",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Normalizar históricos para app": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Responder históricos app",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Webhook Históricos SV": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Consultar históricos Supabase",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
},
|
|
"active": false,
|
|
"settings": {
|
|
"executionOrder": "v1",
|
|
"binaryMode": "separate"
|
|
},
|
|
"tags": []
|
|
} |