{
  "id": "exi5PUpvPuItUuZ4",
  "createdAt": "2023-08-11T14:53:18.585Z",
  "updatedAt": "2023-08-21T06:36:38.352Z",
  "name": "[Oscar] pruebaOps",
  "active": true,
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT DISTINCT\np.document_number AS rut_solicitante, \np.id AS id_solicitante,\np.business_name AS solicitante,\nCASE s.owner_type\nWHEN \"EnterprisePerson\" THEN (SELECT ep.document_number FROM cumplo_db_app.enterprise_people AS ep WHERE ep.id = s.owner_id)\nWHEN \"EnterpriseProfile\" THEN (SELECT ep.document_number FROM cumplo_db_app.enterprise_profiles AS ep WHERE ep.id = s.owner_id)\nELSE \"N/A\" END AS rut_representante,\nCASE s.owner_type\nWHEN \"EnterprisePerson\" THEN (SELECT CONCAT(TRIM(ep.names),\" \",TRIM(ep.first_surname),\" \",TRIM(IFNULL(ep.second_surname,\"\"))) FROM cumplo_db_app.enterprise_people AS ep WHERE ep.id = s.owner_id)\nWHEN \"EnterpriseProfile\" THEN (SELECT ep.business_name FROM cumplo_db_app.enterprise_profiles AS ep WHERE ep.id = s.owner_id)\nELSE \"N/A\" END AS representante,\nc2.name as comuna_empresa,\nreg.name region_empresa,\nconcat(a.street,\" \", a.number) AS direccion, \na.apartment AS  depto,\nci.name ciudad,\nre.name AS Region,\nCASE \nWHEN cs.cve IS NULL THEN cs.notary_name \nELSE cs.cve\nEND AS \"notaria/CVE\",\ncs.notary_lawyer_name AS Notario,\nc.name AS comuna_notaria,\ncs.public_notary_date AS \"Fecha Escritura Publica\"\nFROM\nenterprise_profiles as p\nLEFT JOIN cumplo_db_app.addresses AS a ON a.addressable_id = p.id AND a.addressable_type = \"EnterpriseProfile\"\nLEFT JOIN communes as c2 ON a.commune_id = c2.id\nLEFT JOIN regions as reg ON c2.region_id = reg.id\nLEFT JOIN cumplo_db_app.shares AS s ON s.enterprise_profile_id = p.id AND s.is_legal_representative = 1\nLEFT JOIN cumplo_db_app.company_secretaries AS cs ON p.id = cs.enterprise_profile_id\nLEFT JOIN cumplo_db_app.communes AS c ON cs.commune_id = c.id\nLEFT JOIN cumplo_db_app.addresses AS a2 ON c.id = a2.addressable_id\nLEFT JOIN cumplo_db_app.cities AS ci ON c.city_id = ci.id\nLEFT JOIN cumplo_db_app.regions AS re ON ci.region_id = re.id\nwhere p.document_number = $1\norder by 2 desc;\n\n\n",
        "options": {
          "queryReplacement": "={{ $json.rut }}"
        }
      },
      "id": "36202279-4cbd-4321-ad82-35f822912548",
      "name": "MySQL",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.1,
      "position": [
        1040,
        340
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals",
          "mode": "list",
          "cachedResultName": "Mandatos",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Hoja 1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals/edit#gid=0"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [
            "rut_solicitante"
          ],
          "schema": []
        },
        "options": {}
      },
      "id": "f7971453-e14f-4c48-b459-74c602b1675b",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1440,
        400
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "path": "ae8ca39c-f2c2-4e1f-8ea7-1862c4e5e6d5",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "2828b169-7ff6-4556-92b0-d7c2a6d4a1c2",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        340,
        340
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "rut",
              "value": "={{ $json.query.rut}}"
            }
          ]
        },
        "options": {}
      },
      "id": "c768447e-ac53-4404-8ab4-64d657c735d6",
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        560,
        340
      ]
    },
    {
      "parameters": {
        "operation": "clear",
        "documentId": {
          "__rl": true,
          "value": "1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals",
          "mode": "list",
          "cachedResultName": "Mandatos",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "bbdd",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals/edit#gid=0"
        }
      },
      "id": "05485460-2929-4f07-a94a-750967ddfa10",
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        780,
        340
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "MySQL": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "main": [
        [
          {
            "node": "MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": {
    "node:Google Sheets Trigger": {
      "documentId": "1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals",
      "sheetId": "0",
      "lastRevision": 18,
      "lastRevisionLink": "https://docs.google.com/spreadsheets/export?id=1YAf67E4CWYWFbuzHyGT_q1q48O0ewf7om7N6I6clals&revision=18&exportFormat=xlsx"
    }
  },
  "versionId": "b5c9aaeb-a473-47af-86ed-48dacdacaf95",
  "triggerCount": 1,
  "tags": []
}