{
  "name": "flowsulting · Belege lesen → vorkontieren → gebucht",
  "nodes": [
    {
      "parameters": {
        "format": "resolved",
        "options": {
          "allowUnauthorizedCerts": false
        }
      },
      "id": "belege-t1",
      "name": "Beleg trifft ein",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.text || $json.body }}",
        "attributes": {
          "attributes": [
            {
              "name": "lieferant",
              "description": "Name des Lieferanten",
              "required": true
            },
            {
              "name": "betrag_brutto",
              "description": "Bruttobetrag in Euro",
              "required": true
            },
            {
              "name": "ust_satz",
              "description": "Umsatzsteuersatz",
              "required": true
            },
            {
              "name": "rechnungsnummer",
              "description": "Rechnungsnummer",
              "required": true
            },
            {
              "name": "leistungsdatum",
              "description": "Leistungsdatum ISO",
              "required": true
            }
          ]
        }
      },
      "id": "belege-a1",
      "name": "Beleg lesen & Felder ziehen",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1,
      "position": [
        280,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "version": 2
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.betrag_brutto }}",
              "rightValue": 5000
            }
          ]
        },
        "options": {}
      },
      "id": "belege-b1",
      "name": "Plausibel?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        560,
        0
      ]
    },
    {
      "parameters": {
        "url": "https://api.datev.de/platform/v1/receipts",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {
          "timeout": 15000
        }
      },
      "id": "belege-c1",
      "name": "Vorkontieren & buchen",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        840,
        -200
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "fromEmail": "info@flowsulting.de",
        "toEmail": "buchhaltung@kunde.de",
        "subject": "Beleg braucht 10 Sekunden von Ihnen",
        "emailFormat": "html",
        "html": "={{ $json.html }}",
        "options": {}
      },
      "id": "belege-h1",
      "name": "Zur Klärung vorlegen",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        840,
        200
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "operation": "insert",
        "schema": {
          "__rl": true,
          "value": "public",
          "mode": "list"
        },
        "table": {
          "__rl": true,
          "value": "belege",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "lieferant": "={{ $json.lieferant }}",
            "betrag_brutto": "={{ $json.betrag_brutto }}",
            "rechnungsnummer": "={{ $json.rechnungsnummer }}",
            "leistungsdatum": "={{ $json.leistungsdatum }}",
            "status": "={{ $json.status }}"
          }
        },
        "options": {}
      },
      "id": "belege-d1",
      "name": "Ablegen & auffindbar machen",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1120,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list"
        },
        "options": {
          "temperature": 0.2
        }
      },
      "id": "belege-llm",
      "name": "KI-Modell",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.1,
      "position": [
        280,
        260
      ]
    }
  ],
  "connections": {
    "Beleg trifft ein": {
      "main": [
        [
          {
            "node": "Beleg lesen & Felder ziehen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Beleg lesen & Felder ziehen": {
      "main": [
        [
          {
            "node": "Plausibel?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Plausibel?": {
      "main": [
        [
          {
            "node": "Vorkontieren & buchen",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Zur Klärung vorlegen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Vorkontieren & buchen": {
      "main": [
        [
          {
            "node": "Ablegen & auffindbar machen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Zur Klärung vorlegen": {
      "main": [
        [
          {
            "node": "Ablegen & auffindbar machen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KI-Modell": {
      "ai_languageModel": [
        [
          {
            "node": "Beleg lesen & Felder ziehen",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    {
      "name": "flowsulting"
    },
    {
      "name": "Buchhaltung & Belege"
    }
  ]
}
