{
  "id": "F4JTphX0XULuFHuM",
  "createdAt": "2023-12-07T01:33:02.817Z",
  "updatedAt": "2024-02-06T19:18:22.347Z",
  "name": "Actualizar asignaciones ene2024 temp",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select distinct upper(c.rut_proveedor) 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 rut_proveedor is not null\n#and rut_proveedor in (\n#'105084935')\n#limit 0,3000\n;",
        "options": {}
      },
      "id": "e7198fac-0e6f-48de-b6bf-f8d46a3da436",
      "name": "asignaciones en HS",
      "type": "n8n-nodes-base.mySql",
      "position": [
        2800,
        1080
      ],
      "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": [
        3100,
        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,
        880
      ],
      "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": [
        3400,
        1100
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "update internal_requests_internalrequest ir \nset ir.representative_id = $1 \nwhere ir.requester_id = $2 \nand ir.created_at >= '2024-01-01' and ir.created_at < '2024-01-31'\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": [
        3880,
        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 >= '2024-01-01' and lr.created_at < '2024-01-31'\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": [
        3880,
        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": [
        2460,
        980
      ]
    },
    {
      "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\nlr.created_at >= '2024-01-01' and lr.created_at < '2024-01-31'\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": [
        3100,
        1200
      ],
      "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 en registry",
            "type": "main",
            "index": 0
          },
          {
            "node": "asignaciones en HS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "empresas con operaciones en loans": {
      "main": [
        [
          {
            "node": "asignaciones v\u00e1lidas",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  },
  "settings": {
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v0"
  },
  "staticData": {
    "node:Schedule Trigger1": {
      "recurrencyRules": []
    },
    "node:Schedule Trigger2": {
      "recurrencyRules": []
    }
  },
  "versionId": "daff073c-49c1-4cbf-aec2-a5801c02f38d",
  "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"
    }
  ]
}