{
  "name": "Wochenbericht mit Kennzahlen und KI-Kommentar",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 7 * * 1"
            }
          ]
        }
      },
      "id": "3abb00e8-a114-534f-b17d-9a746fab3ed7",
      "name": "Montags 7 Uhr",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -440,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2002553d-29b7-5fd6-a5a0-cc6d6755679b",
              "name": "ki_endpunkt",
              "value": "https://api.openai.com/v1/chat/completions",
              "type": "string"
            },
            {
              "id": "fb06734c-d821-5271-8b83-4c408d7c17a4",
              "name": "ki_modell",
              "value": "gpt-5-mini",
              "type": "string"
            },
            {
              "id": "5e439a53-625a-59ca-a9c5-a5e743a7bc59",
              "name": "absender",
              "value": "automation@ihre-firma.de",
              "type": "string"
            },
            {
              "id": "043ee028-fb3c-55f8-a6d4-cfc570aa2f85",
              "name": "csv_url",
              "value": "https://docs.google.com/spreadsheets/d/IHRE-ID/export?format=csv",
              "type": "string"
            },
            {
              "id": "aa159ff3-7c3f-51e8-bf2a-8638f68e5ee0",
              "name": "bericht_an",
              "value": "chef@ihre-firma.de",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {
          "includeBinary": true
        }
      },
      "id": "ab3dc0b9-bedb-5a86-a94c-fc6d4f10d193",
      "name": "Konfiguration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -200,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Konfiguration').first().json.csv_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "f0c204eb-f448-5818-a02e-9f786d18d92e",
      "name": "Tabelle laden (CSV)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        40,
        0
      ]
    },
    {
      "parameters": {
        "operation": "csv",
        "binaryPropertyName": "data",
        "options": {
          "headerRow": true
        }
      },
      "id": "8cc868aa-1fdd-508b-8bc7-189411062449",
      "name": "CSV lesen",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Kennzahlen aus der Tabelle berechnen (Spalten: datum, umsatz, auftraege, anfragen)\nconst rows = $input.all().map((i) => i.json);\nconst n = (v) => Number(String(v ?? '').replace(/\\./g, '').replace(',', '.')) || 0;\nconst sum = (k) => rows.reduce((a, r) => a + n(r[k]), 0);\nconst umsatz = sum('umsatz');\nconst auftraege = sum('auftraege');\nconst anfragen = sum('anfragen');\nreturn [{ json: {\n  zeilen: rows.length,\n  umsatz: Math.round(umsatz),\n  auftraege,\n  anfragen,\n  abschlussquote: anfragen ? Math.round((auftraege / anfragen) * 100) : null,\n  durchschnitt_auftrag: auftraege ? Math.round(umsatz / auftraege) : null,\n} }];"
      },
      "id": "aaa88ff1-4ab3-5c35-b50c-63cacdef1adf",
      "name": "Kennzahlen berechnen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Konfiguration').first().json.ki_endpunkt }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: $('Konfiguration').first().json.ki_modell, response_format: { type: 'json_object' }, messages: [ { role: 'system', content: \"Du schreibst f\\u00fcr die Gesch\\u00e4ftsf\\u00fchrung eines deutschen Betriebs einen n\\u00fcchternen Wochenkommentar zu Kennzahlen. Antworte nur mit JSON: {kommentar (max. 5 S\\u00e4tze, Sie-Form, keine Spekulation), auffaelligkeiten (Liste)}.\" }, { role: 'user', content: 'Kennzahlen dieser Woche: ' + JSON.stringify($json) } ] }) }}",
        "options": {
          "timeout": 60000
        }
      },
      "id": "aaba5e1c-6f4e-5e14-a344-360c01413061",
      "name": "KI: Kurzkommentar",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Antwort des Sprachmodells (JSON) auslesen\nreturn $input.all().map((item, i) => {\n  const raw = item.json.choices?.[0]?.message?.content ?? '{}';\n  let data = {};\n  try { data = JSON.parse(raw); } catch (e) { data = { fehler: 'Antwort war kein JSON', roh: raw }; }\n  return { json: { ...data } };\n});"
      },
      "id": "2587a0e9-27d3-5997-b2d8-5bcc1143da3c",
      "name": "Antwort auslesen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        920,
        0
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{ $('Konfiguration').first().json.absender }}",
        "toEmail": "={{ $('Konfiguration').first().json.bericht_an }}",
        "subject": "=Wochenbericht: {{ $('Kennzahlen berechnen').first().json.umsatz }} € Umsatz",
        "emailFormat": "text",
        "text": "=Kennzahlen der Woche\n\nUmsatz: {{ $('Kennzahlen berechnen').first().json.umsatz }} €\nAufträge: {{ $('Kennzahlen berechnen').first().json.auftraege }}\nAnfragen: {{ $('Kennzahlen berechnen').first().json.anfragen }}\nAbschlussquote: {{ $('Kennzahlen berechnen').first().json.abschlussquote }} %\nØ Auftrag: {{ $('Kennzahlen berechnen').first().json.durchschnitt_auftrag }} €\n\n{{ $json.kommentar }}\n\nAuffälligkeiten: {{ $json.auffaelligkeiten }}",
        "options": {}
      },
      "id": "cfcdcf36-dc49-5a10-9d74-c68b2c0fe2d8",
      "name": "Bericht senden",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1140,
        0
      ]
    },
    {
      "parameters": {
        "content": "## Wochenbericht per E-Mail\nVorlage von roiwerk.com\n\n1. Tabelle mit den Spalten datum, umsatz, auftraege, anfragen als CSV bereitstellen (Google Sheets: Datei > Freigeben > Im Web veröffentlichen > CSV)\n2. URL und Empfänger in **Konfiguration** eintragen\n3. KI-Zugang hinterlegen (oder den KI-Node löschen, dann kommt nur die Zahlenübersicht)\n\nFür echte Dashboards: Power BI oder ein eigenes Web-Dashboard.",
        "height": 340,
        "width": 420
      },
      "id": "d958a664-e602-572c-bd9a-b9efed00cc47",
      "name": "Hinweis",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -260,
        -420
      ]
    }
  ],
  "connections": {
    "Montags 7 Uhr": {
      "main": [
        [
          {
            "node": "Konfiguration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Konfiguration": {
      "main": [
        [
          {
            "node": "Tabelle laden (CSV)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tabelle laden (CSV)": {
      "main": [
        [
          {
            "node": "CSV lesen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CSV lesen": {
      "main": [
        [
          {
            "node": "Kennzahlen berechnen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kennzahlen berechnen": {
      "main": [
        [
          {
            "node": "KI: Kurzkommentar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KI: Kurzkommentar": {
      "main": [
        [
          {
            "node": "Antwort auslesen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Antwort auslesen": {
      "main": [
        [
          {
            "node": "Bericht senden",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "https://roiwerk.com/vorlagen/n8n-workflow-vorlagen"
  },
  "tags": []
}