{
  "name": "flowsulting · Offene Posten erkennen → freundlich mahnen",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 7 * * 1-5"
            }
          ]
        }
      },
      "id": "mahnwesen-t1",
      "name": "Täglich 07:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "url": "https://api.lexoffice.io/v1/voucherlist?voucherType=invoice&voucherStatus=open",
        "method": "GET",
        "options": {
          "timeout": 15000
        }
      },
      "id": "mahnwesen-a1",
      "name": "Offene Posten holen",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        280,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "erinnerung",
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "erinnerung",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.stufe }}",
                    "rightValue": "erinnerung"
                  }
                ]
              }
            },
            {
              "outputKey": "mahnung",
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "mahnung",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.stufe }}",
                    "rightValue": "mahnung"
                  }
                ]
              }
            },
            {
              "outputKey": "letzte",
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "letzte",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.stufe }}",
                    "rightValue": "letzte"
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "id": "mahnwesen-b1",
      "name": "Wie lange überfällig?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        560,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "Schreibe eine Zahlungserinnerung. Stufe: {{ $json.stufe }}. Kunde: {{ $json.kunde }} (Beziehung: {{ $json.beziehung }}). Freundlich bleiben, Betrag und Frist klar nennen, keine Drohung.",
        "messages": {}
      },
      "id": "mahnwesen-a2",
      "name": "Tonlage wählen",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.5,
      "position": [
        840,
        0
      ]
    },
    {
      "parameters": {
        "fromEmail": "info@flowsulting.de",
        "toEmail": "={{ $json.kunde_email }}",
        "subject": "Zahlungserinnerung zu Rechnung {{ $json.nummer }}",
        "emailFormat": "html",
        "html": "={{ $json.html }}",
        "options": {}
      },
      "id": "mahnwesen-e1",
      "name": "Erinnerung senden",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1120,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "operation": "insert",
        "schema": {
          "__rl": true,
          "value": "public",
          "mode": "list"
        },
        "table": {
          "__rl": true,
          "value": "mahnlauf",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "kunde": "={{ $json.kunde }}",
            "nummer": "={{ $json.nummer }}",
            "stufe": "={{ $json.stufe }}",
            "betrag": "={{ $json.betrag }}"
          }
        },
        "options": {}
      },
      "id": "mahnwesen-d1",
      "name": "Stufe protokollieren",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1400,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list"
        },
        "options": {
          "temperature": 0.2
        }
      },
      "id": "mahnwesen-llm",
      "name": "KI-Modell",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.1,
      "position": [
        840,
        260
      ]
    }
  ],
  "connections": {
    "Täglich 07:00": {
      "main": [
        [
          {
            "node": "Offene Posten holen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Offene Posten holen": {
      "main": [
        [
          {
            "node": "Wie lange überfällig?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wie lange überfällig?": {
      "main": [
        [
          {
            "node": "Tonlage wählen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tonlage wählen": {
      "main": [
        [
          {
            "node": "Erinnerung senden",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Erinnerung senden": {
      "main": [
        [
          {
            "node": "Stufe protokollieren",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KI-Modell": {
      "ai_languageModel": [
        [
          {
            "node": "Tonlage wählen",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    {
      "name": "flowsulting"
    },
    {
      "name": "Buchhaltung & Belege"
    }
  ]
}
