{
  "updatedAt": "2026-06-07T18:18:10.068Z",
  "createdAt": "2026-06-04T20:28:14.453Z",
  "id": "REwgrt3cW9JlS2NY",
  "name": "Natuurwaarnemer ERP \u2014 Klant verwijderen",
  "description": null,
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "klant-verwijderen",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "a9b26535-fc00-4b61-a1fc-253171a2f31c",
      "name": "Webhook: klant-verwijderen",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "functionCode": "function sanitize(val) {\n  if (val === null || val === undefined) return '';\n  return String(val).replace(/'/g, \"''\").trim();\n}\nconst b = items[0].json.body || items[0].json;\nreturn [{json: { naam: sanitize(b.naam) }}];"
      },
      "id": "815b2131-eed2-405c-8c75-ee61f41088bc",
      "name": "Function: Input valideren",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        224,
        0
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "DELETE FROM customers WHERE name='{{ $node[\"Function: Input valideren\"].json.naam }}'"
      },
      "id": "9a72c7d6-d0a0-4468-9511-7e472127ef32",
      "name": "MySQL: Klant verwijderen",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2,
      "position": [
        1108,
        0
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT name FROM (SELECT name FROM customers UNION ALL SELECT '__sentinel__') AS t ORDER BY name ASC"
      },
      "id": "62f09aec-25aa-4496-b5d7-685affc2fa8a",
      "name": "MySQL: Alle klanten ophalen",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2,
      "position": [
        1332,
        0
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const rows = items.map(i => i.json.name).filter(n => n && n !== '__sentinel__');\nconst naam = $node['Function: Input valideren'].json.naam;\nconst klanten = ['--- Selecteer klant ---', ...rows];\nreturn [{ json: { klanten, klanten_json: JSON.stringify(klanten), type: 'klant',\n  bericht: `Klant '${naam}' verwijderd. ${rows.length} klant(en) in systeem.` }}];"
      },
      "id": "592e6231-1511-4089-87ef-2c792d674bdf",
      "name": "Function: Klantenlijst opbouwen",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1556,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://192.168.2.17:8123/api/services/input_select/set_options",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"entity_id\": \"input_select.factuur_klant\",\n  \"options\": {{ $json.klanten_json }}\n}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "id": "50193d99-a3ff-4d75-918b-d0aa476ba9c6",
      "name": "HTTP: HA input_select bijwerken",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1780,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://192.168.2.17:8123/api/services/input_text/set_value",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"entity_id\": \"input_text.erp_status\",\n  \"value\": \"klant|klant_verwijderd|{{ $node['Function: Klantenlijst opbouwen'].json.bericht }}\"\n}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "id": "1c4a9b36-de79-4da6-b550-f01c8d487473",
      "name": "HTTP: HA terugkoppeling",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        2004,
        0
      ]
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {}
      },
      "id": "7ab15293-bde3-4080-b896-96968ab92ac2",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        2228,
        0
      ]
    },
    {
      "id": "f1a2b3c4-1111-2222-3333-444455556666",
      "name": "MySQL: Facturen check",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2,
      "position": [
        448,
        0
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      },
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT COUNT(*) AS aantal FROM invoices i JOIN customers c ON i.customer_id = c.id WHERE c.name = '{{ $json.naam }}' AND i.status != 'verwijderd'"
      }
    },
    {
      "id": "a1b2c3d4-5555-6666-7777-888899990000",
      "name": "IF: Heeft actieve facturen",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        668,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "cond1",
              "leftValue": "={{ $json.aantal }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "b2c3d4e5-aaaa-bbbb-cccc-ddddeeee1111",
      "name": "HTTP: HA foutmelding",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        888,
        -160
      ],
      "parameters": {
        "method": "POST",
        "url": "http://192.168.2.17:8123/api/services/input_text/set_value",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "body": "={\"entity_id\":\"input_text.erp_status\",\"value\":\"klant|fout|\u26a0\ufe0f Verwijderen niet mogelijk \u2014 verwijder eerst alle facturen van deze klant\"}"
      }
    },
    {
      "id": "ff11ee22-aaaa-bbbb-cccc-dd33ee441234",
      "name": "MySQL: Ontkoppel facturen",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2,
      "position": [
        888,
        160
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      },
      "parameters": {
        "operation": "executeQuery",
        "query": "UPDATE invoices SET customer_id = NULL WHERE customer_id = (SELECT id FROM customers WHERE name = '{{ $node[\"Function: Input valideren\"].json.naam }}')"
      }
    }
  ],
  "connections": {
    "Webhook: klant-verwijderen": {
      "main": [
        [
          {
            "node": "Function: Input valideren",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function: Input valideren": {
      "main": [
        [
          {
            "node": "MySQL: Facturen check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL: Klant verwijderen": {
      "main": [
        [
          {
            "node": "MySQL: Alle klanten ophalen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL: Alle klanten ophalen": {
      "main": [
        [
          {
            "node": "Function: Klantenlijst opbouwen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function: Klantenlijst opbouwen": {
      "main": [
        [
          {
            "node": "HTTP: HA input_select bijwerken",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP: HA input_select bijwerken": {
      "main": [
        [
          {
            "node": "HTTP: HA terugkoppeling",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP: HA terugkoppeling": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL: Facturen check": {
      "main": [
        [
          {
            "node": "IF: Heeft actieve facturen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF: Heeft actieve facturen": {
      "main": [
        [
          {
            "node": "HTTP: HA foutmelding",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "MySQL: Ontkoppel facturen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP: HA foutmelding": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL: Ontkoppel facturen": {
      "main": [
        [
          {
            "node": "MySQL: Klant verwijderen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "staticData": null,
  "meta": null,
  "versionId": "9c7a03dd-7571-4990-9dde-80374d96c215",
  "activeVersionId": "9c7a03dd-7571-4990-9dde-80374d96c215",
  "versionCounter": 21,
  "triggerCount": 1,
  "shared": [
    {
      "updatedAt": "2026-06-04T20:28:14.459Z",
      "createdAt": "2026-06-04T20:28:14.459Z",
      "role": "workflow:owner",
      "workflowId": "REwgrt3cW9JlS2NY",
      "projectId": "m5RFSl9CcHUdb8CB",
      "project": {
        "updatedAt": "2026-04-21T19:10:08.086Z",
        "createdAt": "2026-04-21T18:59:53.063Z",
        "id": "m5RFSl9CcHUdb8CB",
        "name": "Ruud Hogenberg <info@natuurwaarnemer.nl>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "4e4dfe16-eb75-4c88-ac33-b7c362667bc3"
      }
    }
  ],
  "tags": [],
  "activeVersion": {
    "updatedAt": "2026-06-07T18:18:10.071Z",
    "createdAt": "2026-06-07T18:18:10.071Z",
    "versionId": "9c7a03dd-7571-4990-9dde-80374d96c215",
    "workflowId": "REwgrt3cW9JlS2NY",
    "nodes": [
      {
        "parameters": {
          "httpMethod": "POST",
          "path": "klant-verwijderen",
          "responseMode": "responseNode",
          "options": {}
        },
        "id": "a9b26535-fc00-4b61-a1fc-253171a2f31c",
        "name": "Webhook: klant-verwijderen",
        "type": "n8n-nodes-base.webhook",
        "typeVersion": 2,
        "position": [
          0,
          0
        ],
        "webhookId": "2b32cd61-795e-4b4b-bf00-3789ee8287ce"
      },
      {
        "parameters": {
          "functionCode": "function sanitize(val) {\n  if (val === null || val === undefined) return '';\n  return String(val).replace(/'/g, \"''\").trim();\n}\nconst b = items[0].json.body || items[0].json;\nreturn [{json: { naam: sanitize(b.naam) }}];"
        },
        "id": "815b2131-eed2-405c-8c75-ee61f41088bc",
        "name": "Function: Input valideren",
        "type": "n8n-nodes-base.function",
        "typeVersion": 1,
        "position": [
          224,
          0
        ]
      },
      {
        "parameters": {
          "operation": "executeQuery",
          "query": "DELETE FROM customers WHERE name='{{ $node[\"Function: Input valideren\"].json.naam }}'"
        },
        "id": "9a72c7d6-d0a0-4468-9511-7e472127ef32",
        "name": "MySQL: Klant verwijderen",
        "type": "n8n-nodes-base.mySql",
        "typeVersion": 2,
        "position": [
          1108,
          0
        ],
        "credentials": {
          "mySql": {
            "id": "AdVYD86SBj0ZYuto",
            "name": "MySQL \u2014 erp"
          }
        }
      },
      {
        "parameters": {
          "operation": "executeQuery",
          "query": "SELECT name FROM (SELECT name FROM customers UNION ALL SELECT '__sentinel__') AS t ORDER BY name ASC"
        },
        "id": "62f09aec-25aa-4496-b5d7-685affc2fa8a",
        "name": "MySQL: Alle klanten ophalen",
        "type": "n8n-nodes-base.mySql",
        "typeVersion": 2,
        "position": [
          1332,
          0
        ],
        "credentials": {
          "mySql": {
            "id": "AdVYD86SBj0ZYuto",
            "name": "MySQL \u2014 erp"
          }
        }
      },
      {
        "parameters": {
          "functionCode": "const rows = items.map(i => i.json.name).filter(n => n && n !== '__sentinel__');\nconst naam = $node['Function: Input valideren'].json.naam;\nconst klanten = ['--- Selecteer klant ---', ...rows];\nreturn [{ json: { klanten, klanten_json: JSON.stringify(klanten), type: 'klant',\n  bericht: `Klant '${naam}' verwijderd. ${rows.length} klant(en) in systeem.` }}];"
        },
        "id": "592e6231-1511-4089-87ef-2c792d674bdf",
        "name": "Function: Klantenlijst opbouwen",
        "type": "n8n-nodes-base.function",
        "typeVersion": 1,
        "position": [
          1556,
          0
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "http://192.168.2.17:8123/api/services/input_select/set_options",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Authorization",
                "value": "<redacted-credential>"
              },
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\n  \"entity_id\": \"input_select.factuur_klant\",\n  \"options\": {{ $json.klanten_json }}\n}",
          "options": {
            "response": {
              "response": {
                "fullResponse": true,
                "neverError": true
              }
            }
          }
        },
        "id": "50193d99-a3ff-4d75-918b-d0aa476ba9c6",
        "name": "HTTP: HA input_select bijwerken",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          1780,
          0
        ]
      },
      {
        "parameters": {
          "method": "POST",
          "url": "http://192.168.2.17:8123/api/services/input_text/set_value",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Authorization",
                "value": "<redacted-credential>"
              },
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "specifyBody": "json",
          "jsonBody": "={\n  \"entity_id\": \"input_text.erp_status\",\n  \"value\": \"klant|klant_verwijderd|{{ $node['Function: Klantenlijst opbouwen'].json.bericht }}\"\n}",
          "options": {
            "response": {
              "response": {
                "fullResponse": true,
                "neverError": true
              }
            }
          }
        },
        "id": "1c4a9b36-de79-4da6-b550-f01c8d487473",
        "name": "HTTP: HA terugkoppeling",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4,
        "position": [
          2004,
          0
        ]
      },
      {
        "parameters": {
          "respondWith": "allIncomingItems",
          "options": {}
        },
        "id": "7ab15293-bde3-4080-b896-96968ab92ac2",
        "name": "Respond to Webhook",
        "type": "n8n-nodes-base.respondToWebhook",
        "typeVersion": 1,
        "position": [
          2228,
          0
        ]
      },
      {
        "id": "f1a2b3c4-1111-2222-3333-444455556666",
        "name": "MySQL: Facturen check",
        "type": "n8n-nodes-base.mySql",
        "typeVersion": 2,
        "position": [
          448,
          0
        ],
        "credentials": {
          "mySql": {
            "id": "AdVYD86SBj0ZYuto",
            "name": "MySQL \u2014 erp"
          }
        },
        "parameters": {
          "operation": "executeQuery",
          "query": "SELECT COUNT(*) AS aantal FROM invoices i JOIN customers c ON i.customer_id = c.id WHERE c.name = '{{ $json.naam }}' AND i.status != 'verwijderd'"
        }
      },
      {
        "id": "a1b2c3d4-5555-6666-7777-888899990000",
        "name": "IF: Heeft actieve facturen",
        "type": "n8n-nodes-base.if",
        "typeVersion": 2,
        "position": [
          668,
          0
        ],
        "parameters": {
          "conditions": {
            "options": {
              "caseSensitive": true,
              "leftValue": "",
              "typeValidation": "strict"
            },
            "conditions": [
              {
                "id": "cond1",
                "leftValue": "={{ $json.aantal }}",
                "rightValue": 0,
                "operator": {
                  "type": "number",
                  "operation": "gt"
                }
              }
            ],
            "combinator": "and"
          }
        }
      },
      {
        "id": "b2c3d4e5-aaaa-bbbb-cccc-ddddeeee1111",
        "name": "HTTP: HA foutmelding",
        "type": "n8n-nodes-base.httpRequest",
        "typeVersion": 4.2,
        "position": [
          888,
          -160
        ],
        "parameters": {
          "method": "POST",
          "url": "http://192.168.2.17:8123/api/services/input_text/set_value",
          "sendHeaders": true,
          "headerParameters": {
            "parameters": [
              {
                "name": "Authorization",
                "value": "<redacted-credential>"
              },
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          },
          "sendBody": true,
          "contentType": "raw",
          "body": "={\"entity_id\":\"input_text.erp_status\",\"value\":\"klant|fout|\u26a0\ufe0f Verwijderen niet mogelijk \u2014 verwijder eerst alle facturen van deze klant\"}"
        }
      },
      {
        "id": "ff11ee22-aaaa-bbbb-cccc-dd33ee441234",
        "name": "MySQL: Ontkoppel facturen",
        "type": "n8n-nodes-base.mySql",
        "typeVersion": 2,
        "position": [
          888,
          160
        ],
        "credentials": {
          "mySql": {
            "id": "AdVYD86SBj0ZYuto",
            "name": "MySQL \u2014 erp"
          }
        },
        "parameters": {
          "operation": "executeQuery",
          "query": "UPDATE invoices SET customer_id = NULL WHERE customer_id = (SELECT id FROM customers WHERE name = '{{ $node[\"Function: Input valideren\"].json.naam }}')"
        }
      }
    ],
    "connections": {
      "Webhook: klant-verwijderen": {
        "main": [
          [
            {
              "node": "Function: Input valideren",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Function: Input valideren": {
        "main": [
          [
            {
              "node": "MySQL: Facturen check",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "MySQL: Klant verwijderen": {
        "main": [
          [
            {
              "node": "MySQL: Alle klanten ophalen",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "MySQL: Alle klanten ophalen": {
        "main": [
          [
            {
              "node": "Function: Klantenlijst opbouwen",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Function: Klantenlijst opbouwen": {
        "main": [
          [
            {
              "node": "HTTP: HA input_select bijwerken",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "HTTP: HA input_select bijwerken": {
        "main": [
          [
            {
              "node": "HTTP: HA terugkoppeling",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "HTTP: HA terugkoppeling": {
        "main": [
          [
            {
              "node": "Respond to Webhook",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "MySQL: Facturen check": {
        "main": [
          [
            {
              "node": "IF: Heeft actieve facturen",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "IF: Heeft actieve facturen": {
        "main": [
          [
            {
              "node": "HTTP: HA foutmelding",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "MySQL: Ontkoppel facturen",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "HTTP: HA foutmelding": {
        "main": [
          [
            {
              "node": "Respond to Webhook",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "MySQL: Ontkoppel facturen": {
        "main": [
          [
            {
              "node": "MySQL: Klant verwijderen",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    },
    "authors": "Ruud Hogenberg",
    "name": null,
    "description": null,
    "autosaved": false,
    "workflowPublishHistory": [
      {
        "createdAt": "2026-06-07T18:18:10.225Z",
        "id": 463,
        "workflowId": "REwgrt3cW9JlS2NY",
        "versionId": "9c7a03dd-7571-4990-9dde-80374d96c215",
        "event": "activated",
        "userId": "4e4dfe16-eb75-4c88-ac33-b7c362667bc3"
      },
      {
        "createdAt": "2026-06-07T18:18:10.173Z",
        "id": 462,
        "workflowId": "REwgrt3cW9JlS2NY",
        "versionId": "9c7a03dd-7571-4990-9dde-80374d96c215",
        "event": "deactivated",
        "userId": "4e4dfe16-eb75-4c88-ac33-b7c362667bc3"
      }
    ]
  }
}