{
  "name": "10 Schakelaar en dagplafond",
  "nodes": [
    {
      "id": "6ccb3a69-5782-47b3-a396-dade742ed67c",
      "name": "Aangeroepen door een andere flow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        300
      ],
      "parameters": {
        "inputSource": "workflowInputs",
        "workflowInputs": {
          "values": [
            {
              "name": "flow"
            },
            {
              "name": "aantal",
              "type": "number"
            }
          ]
        }
      }
    },
    {
      "id": "27ac5ef3-efc1-43ab-bf0a-e3adb11de16c",
      "name": "Schakelaar lezen",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "schakelaars"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "flow",
              "condition": "eq",
              "keyValue": "={{ $json.flow }}"
            }
          ]
        },
        "returnAll": true
      },
      "alwaysOutputData": true
    },
    {
      "id": "c807f0b5-1147-4750-b023-f262de9d9c00",
      "name": "Beslissen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "jsCode": "// Geen rij = uit. Uit = uit. Boven het dagplafond = uit.\nconst s = $input.first().json; const vraag = $('Aangeroepen door een andere flow').first().json;\nconst vandaag = $now.toFormat('yyyy-MM-dd');\nconst teller = s.teller_datum === vandaag ? (s.teller || 0) : 0;\nconst extra = Number(vraag.aantal) || 1;\nlet mag = !!s.id && s.aan === true;\nlet reden = !s.id ? 'geen schakelaar voor deze flow' : (!s.aan ? (s.noodrem_reden || 'staat uit') : '');\nif (mag && teller + extra > s.per_dag) { mag = false; reden = `dagplafond ${s.per_dag} bereikt`; }\nreturn [{ json: { mag, reden, rij: s.id || null, teller: mag ? teller + extra : teller, vandaag } }];"
      }
    },
    {
      "id": "fe196a23-20b2-4504-bd88-7febf35eb998",
      "name": "Teller bijwerken",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        720,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "schakelaars"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $json.rij }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "teller": "={{ $json.teller }}",
            "teller_datum": "={{ $json.vandaag }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "teller",
              "displayName": "teller",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true
            },
            {
              "id": "teller_datum",
              "displayName": "teller_datum",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "onError": "continueRegularOutput"
    },
    {
      "id": "af4f595d-95e1-4d98-94e0-f940cd517425",
      "name": "Antwoord",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        960,
        300
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "m",
              "name": "mag",
              "value": "={{ $('Beslissen').item.json.mag }}",
              "type": "boolean"
            },
            {
              "id": "r",
              "name": "reden",
              "value": "={{ $('Beslissen').item.json.reden }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "bbaa3c17-fa94-4db2-999f-636cecb90993",
      "name": "Lees mij",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "content": "## Schakelaar en dagplafond\nGetest op 11-11-2026 met n8n 2.47.3.\n\n**Invullen:** tabel *schakelaars* (flow, aan, per_dag, teller_datum, teller, noodrem_reden), één rij per flow.\n\nGeen rij of aan = false: de aanroepende flow stopt, met de reden erbij.",
        "height": 220,
        "width": 520,
        "color": 7
      }
    }
  ],
  "connections": {
    "Aangeroepen door een andere flow": {
      "main": [
        [
          {
            "node": "Schakelaar lezen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schakelaar lezen": {
      "main": [
        [
          {
            "node": "Beslissen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Beslissen": {
      "main": [
        [
          {
            "node": "Teller bijwerken",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Teller bijwerken": {
      "main": [
        [
          {
            "node": "Antwoord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}