{
  "id": "F4JTphX0XULuFHuM",
  "createdAt": "2023-12-07T01:33:02.817Z",
  "updatedAt": "2024-03-13T22:23:15.477Z",
  "name": "Actualizar asignaciones Kimchi (KP)",
  "active": true,
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select distinct upper(c.documento_tributario) as enterprise_document_number, o.email as representative_email from hubspot.companies c left join hubspot.owners o on c.owner_id = o.id\nwhere documento_tributario is not NULL",
        "options": {}
      },
      "id": "e7198fac-0e6f-48de-b6bf-f8d46a3da436",
      "name": "asignaciones en HS",
      "type": "n8n-nodes-base.mySql",
      "position": [
        2800,
        1000
      ],
      "typeVersion": 2.1,
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {
              "field1": "representative_email",
              "field2": "representative_email"
            }
          ]
        },
        "options": {}
      },
      "id": "df4629b8-c81a-4d76-b135-6c0e0a9d0863",
      "name": "empresas con ejecutivos v\u00e1lidos",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        3080,
        980
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select core_user.id as representative_id,\n       core_user.email as representative_email\n\nfrom api_registry_common.core_user\n         inner join api_registry_common.core_profile\n                    on core_user.id = core_profile.user_id",
        "options": {}
      },
      "id": "9fbac161-c7d1-4a97-b3e1-fb7db39a7481",
      "name": "ejecutivos en registry",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        2800,
        800
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {
              "field1": "enterprise_document_number",
              "field2": "enterprise_document_number"
            }
          ]
        },
        "options": {}
      },
      "id": "6f8285ff-bf92-474c-bc7e-3e15a0d8e0d6",
      "name": "asignaciones v\u00e1lidas",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        3360,
        1100
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "update internal_requests_internalrequest ir \nset ir.representative_id = $1 \nwhere ir.requester_id = $2 \nand ir.created_at >= DATE_ADD(LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)), INTERVAL 1 DAY) and ir.created_at < DATE_ADD(LAST_DAY(CURDATE()), INTERVAL 1 DAY)\n",
        "options": {
          "queryReplacement": "={{ $json.representative_id }}, {{ $json.enterprise_id }}"
        }
      },
      "id": "33d9e906-a891-41c0-923f-1a40f130812e",
      "name": "update en financing",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        3680,
        980
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "update loan_requests_loanrequest lr\nset lr.representative_id = $1\nwhere lr.requester_id = $2\n  and lr.created_at >= DATE_ADD(LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)), INTERVAL 1 DAY) and lr.created_at < DATE_ADD(LAST_DAY(CURDATE()), INTERVAL 1 DAY)\n",
        "options": {
          "queryReplacement": "={{ $json.representative_id }}, {{ $json.enterprise_id }}"
        }
      },
      "id": "cbc730b5-9653-4199-be55-6c085566cb39",
      "name": "update en loans",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        3680,
        1220
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "triggerAtMinute": 40
            }
          ]
        }
      },
      "id": "fb387b48-8ee8-4144-b39e-52ce99de0a87",
      "name": "Schedule Trigger1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        1380,
        1000
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select distinct upper(document_number) as enterprise_document_number,\n                ce.id                  as enterprise_id\nfrom core_enterprise ce\n         inner join loans_loan l on ce.id = l.requester_id\n         inner join loan_requests_loanrequest lr on l.loan_request_id = lr.id\n    and l.state != 'canceled'\n    and lr.created_at >= DATE_ADD(LAST_DAY(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)), INTERVAL 1 DAY) and\n                                                    lr.created_at < DATE_ADD(LAST_DAY(CURDATE()), INTERVAL 1 DAY);\n#and upper(ce.name)='HIMMEL FACTORING SPA'",
        "options": {}
      },
      "id": "ab7d3580-5a78-4d1f-bc89-78ba04c85ca8",
      "name": "empresas con operaciones en loans",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        3080,
        1500
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "upsert",
        "table": {
          "__rl": true,
          "value": "core_user",
          "mode": "list",
          "cachedResultName": "core_user"
        },
        "columnToMatchOn": "id",
        "options": {}
      },
      "id": "78f0a1cc-af02-4c1b-9733-ffbdace2b64b",
      "name": "insert or update financing",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        1880,
        1000
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "upsert",
        "table": {
          "__rl": true,
          "value": "core_user",
          "mode": "list",
          "cachedResultName": "core_user"
        },
        "columnToMatchOn": "id",
        "options": {}
      },
      "id": "194c7a0d-91bc-45e5-8f14-c3627447ac29",
      "name": "insert or update loans",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        2320,
        1000
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 2,
        "unit": "seconds"
      },
      "id": "5cebfd13-3b2e-47cf-a266-c8485ea7ee1a",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        2540,
        1000
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select core_user.id,\n       #core_user.email,\n       core_profile.document_number,\n       concat(COALESCE(first_name, ''), ' ', COALESCE(last_name, '')) as name,\n       0                                                              as has_bank_account\n\nfrom api_registry_common.core_user\n         inner join api_registry_common.core_profile\n                    on core_user.id = core_profile.user_id;",
        "options": {}
      },
      "id": "968a114b-b75b-461a-b431-b877dd2f3d91",
      "name": "ejecutivos para financing",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        1660,
        1000
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select core_user.id,\n       core_profile.document_number,\n       concat(COALESCE(first_name, ''), ' ', COALESCE(last_name, '')) as name,\n       core_user.email\n\nfrom api_registry_common.core_user\n         inner join api_registry_common.core_profile\n                    on core_user.id = core_profile.user_id",
        "options": {}
      },
      "id": "f6a3b801-3e58-4107-b680-5d5cfeb82eeb",
      "name": "ejecutivos para loans",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        2100,
        1000
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "asignaciones en HS": {
      "main": [
        [
          {
            "node": "empresas con ejecutivos v\u00e1lidos",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "empresas con ejecutivos v\u00e1lidos": {
      "main": [
        [
          {
            "node": "asignaciones v\u00e1lidas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ejecutivos en registry": {
      "main": [
        [
          {
            "node": "empresas con ejecutivos v\u00e1lidos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "asignaciones v\u00e1lidas": {
      "main": [
        [
          {
            "node": "update en loans",
            "type": "main",
            "index": 0
          },
          {
            "node": "update en financing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "ejecutivos para financing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "empresas con operaciones en loans": {
      "main": [
        [
          {
            "node": "asignaciones v\u00e1lidas",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "insert or update financing": {
      "main": [
        [
          {
            "node": "ejecutivos para loans",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "insert or update loans": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "ejecutivos en registry",
            "type": "main",
            "index": 0
          },
          {
            "node": "asignaciones en HS",
            "type": "main",
            "index": 0
          },
          {
            "node": "empresas con operaciones en loans",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ejecutivos para financing": {
      "main": [
        [
          {
            "node": "insert or update financing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ejecutivos para loans": {
      "main": [
        [
          {
            "node": "insert or update loans",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1",
    "saveExecutionProgress": false
  },
  "staticData": {
    "node:Schedule Trigger1": {
      "recurrencyRules": []
    },
    "node:Schedule Trigger2": {
      "recurrencyRules": []
    }
  },
  "versionId": "ec42634e-9197-4425-a86e-b98e00217437",
  "triggerCount": 1,
  "tags": [
    {
      "id": "aDpcKzUzGLCXMKzG",
      "createdAt": "2023-07-14T19:51:58.772Z",
      "updatedAt": "2023-07-14T19:51:58.772Z",
      "name": "kimchi"
    },
    {
      "id": "v25eD48xihLAmSfO",
      "createdAt": "2023-07-14T19:51:55.716Z",
      "updatedAt": "2023-07-14T19:51:55.716Z",
      "name": "bi"
    }
  ]
}