{
  "id": "K2ehjaHcLomzSyLS",
  "createdAt": "2023-08-08T21:49:26.298Z",
  "updatedAt": "2023-08-17T17:07:09.662Z",
  "name": "[eliminado] Parche comisiones Hubspot Julio 2023",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select distinct upper(enterprise_document_number) as enterprise_document_number, representative_email from hubspot.parche\n#and rut_proveedor in (\n#'77760001K')\n#limit 0,3000\n;",
        "options": {}
      },
      "id": "49163e42-6d26-4b23-9f0e-dd741b399007",
      "name": "asignaciones en HS",
      "type": "n8n-nodes-base.mySql",
      "position": [
        460,
        660
      ],
      "typeVersion": 2.1,
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {
              "field1": "representative_email",
              "field2": "representative_email"
            }
          ]
        },
        "options": {}
      },
      "id": "75d41ef6-8c8d-4f70-9213-b3cb06687f1e",
      "name": "empresas con ejecutivos v\u00e1lidos",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        760,
        560
      ]
    },
    {
      "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": "b79b02ba-9de4-4d0a-a239-3583ece6e109",
      "name": "ejecutivos en registry",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        460,
        460
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "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.requester_id=1498\n    and\n                                                    lr.created_at between DATE_ADD(\n                                                            DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 2 MONTH), INTERVAL 1\n                                                            DAY) and DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH );",
        "options": {}
      },
      "id": "7b5511d1-2a13-40c0-a4db-302396e02e99",
      "name": "empresas con operaciones en loans",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        760,
        820
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {
              "field1": "enterprise_document_number",
              "field2": "enterprise_document_number"
            }
          ]
        },
        "options": {}
      },
      "id": "680b5084-f8d4-466e-8335-f9beceb898b2",
      "name": "asignaciones v\u00e1lidas",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        1060,
        680
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "update internal_requests_internalrequest ir \nset ir.representative_id = $1 \nwhere ir.requester_id = $2 \nand ir.created_at between  DATE_ADD(DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 2 MONTH ), INTERVAL 1 DAY) and DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH );",
        "options": {
          "queryReplacement": "={{ $json.representative_id }}, {{ $json.enterprise_id }}"
        }
      },
      "id": "bcf97d08-55f2-48a1-96f4-78ad6bd8d936",
      "name": "update en financing",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        1540,
        560
      ],
      "alwaysOutputData": true,
      "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 between DATE_ADD(DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 2 MONTH ), INTERVAL 1 DAY) and DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 1 MONTH );",
        "options": {
          "queryReplacement": "={{ $json.representative_id }}, {{ $json.enterprise_id }}"
        }
      },
      "id": "03f80283-7c04-4d16-b8ca-f8d9078d8a79",
      "name": "update en loans",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        1540,
        800
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "triggerAtMinute": 40
            }
          ]
        }
      },
      "id": "1cb0fb5f-73a9-4111-adf7-22b7cb796e97",
      "name": "Schedule Trigger1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        120,
        560
      ]
    }
  ],
  "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
          }
        ]
      ]
    },
    "empresas con operaciones en loans": {
      "main": [
        [
          {
            "node": "asignaciones v\u00e1lidas",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "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
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "versionId": "fad219ae-82d3-43c9-9337-b6f470e55407",
  "triggerCount": 0,
  "tags": []
}