{
  "name": "12 Business overview (helper for the agent)",
  "nodes": [
    {
      "id": "3ee74422-c582-4d7c-9223-cd8486e65af3",
      "name": "Called by the agent",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        300
      ],
      "parameters": {
        "inputSource": "passthrough"
      }
    },
    {
      "id": "6a23f163-4468-45a6-9c3f-1726d3b12bcd",
      "name": "All invoices",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "invoices"
        },
        "returnAll": true
      },
      "alwaysOutputData": true,
      "executeOnce": true
    },
    {
      "id": "3cf1ef23-df86-401c-9891-c038380dc07e",
      "name": "All quotes",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        480,
        300
      ],
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": "quotes"
        },
        "returnAll": true
      },
      "alwaysOutputData": true,
      "executeOnce": true
    },
    {
      "id": "ef22e320-d0ed-4cad-839f-bbff2f30dd54",
      "name": "Calculate overview",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        300
      ],
      "parameters": {
        "jsCode": "// All the math happens here, in code: the language model only has to phrase the answer.\nconst today = new Date(); const day = 864e5;\nconst inv = $('All invoices').all().map(i => i.json).filter(f => f.invoice_number);\nconst q = $('All quotes').all().map(i => i.json).filter(o => o.client);\nconst open = inv.filter(f => f.status === 'open').map(f => ({ invoice_number: f.invoice_number, client: f.client, amount: f.amount,\n  due_date: f.due_date.slice(0, 10), days_overdue: Math.max(0, Math.floor((today - new Date(f.due_date)) / day)) }));\nconst pending = q.filter(o => o.status === 'sent').map(o => ({ client: o.client, description: o.description, amount: o.amount,\n  sent_at: (o.sent_at || '').slice(0, 10), reminded: !!o.reminded_at }));\nconst clients = [...new Set([...inv.map(f => f.client), ...q.map(o => o.client)])].sort().map(k => ({\n  client: k,\n  open_invoices: open.filter(f => f.client === k), paid_invoices: inv.filter(f => f.client === k && f.status === 'paid').map(f => f.invoice_number),\n  pending_quotes: pending.filter(o => o.client === k), accepted_quotes: q.filter(o => o.client === k && o.status === 'accepted').map(o => o.description) }));\nconst sum = a => a.reduce((s, x) => s + x.amount, 0);\nconst overdue = open.filter(f => f.days_overdue > 0).sort((a, b) => b.days_overdue - a.days_overdue);\nreturn [{ json: {\n  today: today.toISOString().slice(0, 10),\n  open_invoices: open, total_open_invoices: sum(open),\n  overdue_invoices: overdue, total_overdue: sum(overdue),\n  pending_quotes: pending, total_pending_quotes: sum(pending),\n  per_client: clients,\n  known_fields: 'invoice number, client, email, amount, due date, status, description; no phone numbers or addresses'\n} }];"
      },
      "notes": "Adding up and comparing dates is code, not AI",
      "notesInFlow": true
    },
    {
      "id": "308b3981-bf04-4198-b801-8cfda3daef5d",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "content": "## Business overview (helper for the agent)\nTested on November 11, 2026, with n8n 2.47.3.\n\n**Fill in:** the *invoices* and *quotes* tables.\n\nAdds up totals and works out days overdue so the language model doesn't have to.",
        "height": 220,
        "width": 520,
        "color": 7
      }
    }
  ],
  "connections": {
    "Called by the agent": {
      "main": [
        [
          {
            "node": "All invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "All invoices": {
      "main": [
        [
          {
            "node": "All quotes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "All quotes": {
      "main": [
        [
          {
            "node": "Calculate overview",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}