{
  "id": "p1InvoiceInbox01",
  "name": "P1 Invoice inbox",
  "nodes": [
    {
      "id": "cc2aad0f-a4ae-4788-87bb-2fdbd18afbbf",
      "name": "Human: input",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -110,
        -170
      ],
      "parameters": {
        "content": "## Human: input\nA person uploads the documents in the form.",
        "width": 320,
        "height": 330,
        "color": 6
      }
    },
    {
      "id": "c22d04c8-0f6d-41a1-8f38-9f72fd768f29",
      "name": "Human in the loop: review",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        4880,
        530
      ],
      "parameters": {
        "content": "## Human in the loop: review\nA person approves or rejects each invoice that is not auto-approved and may correct GL account and cost bearer.",
        "width": 480,
        "height": 330,
        "color": 6
      }
    },
    {
      "id": "10609b61-6612-43ab-8984-10283e6b5c1e",
      "name": "Human: result",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2490,
        -430
      ],
      "parameters": {
        "content": "## Human: result\nThe same person sees the results table in the browser.",
        "width": 320,
        "height": 330,
        "color": 6
      }
    },
    {
      "id": "f9f423c6-8505-402b-8ef2-cba213c52633",
      "position": [
        0,
        0
      ],
      "name": "Upload",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "parameters": {
        "formTitle": "Invoice inbox",
        "formDescription": "Upload supplier invoices (PDF). Each invoice is read, checked and gets a booking proposal.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Invoices",
              "fieldName": "files",
              "fieldType": "file",
              "multipleFiles": true,
              "acceptFileTypes": ".pdf",
              "requiredField": true
            }
          ]
        },
        "options": {
          "path": "invoice-inbox",
          "appendAttribution": false
        }
      },
      "webhookId": "ae9022d3-386e-4db1-88f4-10d407ecbca8"
    },
    {
      "id": "488436dd-efb0-4fd5-8baf-bdfb6771e929",
      "position": [
        260,
        0
      ],
      "name": "Read document",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkReadDocument1",
          "cachedResultName": "read document (OCR)",
          "cachedResultUrl": "/workflow/blkReadDocument1"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "notes": "One item per invoice with its text"
    },
    {
      "id": "f805d5b2-a0e0-45b4-87bc-a8825a7f9fa5",
      "position": [
        520,
        0
      ],
      "name": "Question: is it an invoice?",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "205da60f-8d32-4e68-8f5e-2f7095910f5d",
              "name": "state",
              "value": "={{ $json.text.slice(0, 2500) }}",
              "type": "string"
            },
            {
              "id": "5595a688-e0e3-4085-8e8b-0f7fc6ee9fab",
              "name": "questions",
              "value": "{\n  \"docType\": {\n    \"type\": \"choice\",\n    \"instructions\": \"What kind of document is this?\",\n    \"criteria\": {\n      \"invoice\": \"an invoice, bill or statement of charges asking for payment\",\n      \"credit_note\": \"a credit note reducing an earlier invoice\",\n      \"reminder\": \"a payment reminder or dunning letter\",\n      \"other\": \"anything else, for example a contract, letter or report\"\n    }\n  }\n}",
              "type": "object"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "f565d6c3-7044-490e-8ba3-d90dd9dfad50",
      "position": [
        780,
        0
      ],
      "name": "Ask Jev: is it an invoice?",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkDecideJev0001",
          "cachedResultName": "decide (Jev)",
          "cachedResultUrl": "/workflow/blkDecideJev0001"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      }
    },
    {
      "id": "604d3796-a903-4637-86c3-8975aacc696e",
      "position": [
        1040,
        0
      ],
      "name": "Skip this document?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "e4d16116-8225-4b08-8634-7511e3059312",
              "leftValue": "={{ $json.answers.docType.value }}",
              "rightValue": "invoice",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            },
            {
              "id": "6e00dbc0-43f5-4183-8248-263bc7eebdf2",
              "leftValue": "={{ $json.answers.docType.confidence }}",
              "rightValue": 0.6,
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "or"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "notes": "Filter early: true (not an invoice, or Jev less than 60% sure) skips extraction, checks and booking. Change the 0.6 here."
    },
    {
      "id": "470ddbed-e50e-4a05-8135-fd07f0461926",
      "position": [
        1300,
        0
      ],
      "name": "Fields to extract",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0673692f-4251-4105-88a1-5f6901e03c6e",
              "name": "schema",
              "value": "invoice",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "5f1e36e8-7887-4cfd-84e2-8c740d34450b",
      "position": [
        1560,
        0
      ],
      "name": "Extract invoice fields",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkExtractFields",
          "cachedResultName": "extract fields (LLM)",
          "cachedResultUrl": "/workflow/blkExtractFields"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "notes": "LLM reads supplier, number, amounts, addressee"
    },
    {
      "id": "cab311a4-4640-4440-83ed-410ae8f0dc9d",
      "position": [
        1820,
        0
      ],
      "name": "One invoice at a time",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "notes": "One at a time: output \"loop\" runs the steps for one item, output \"done\" continues when all are through."
    },
    {
      "id": "a940fb99-8e99-43c1-8f71-6b0cee35042c",
      "position": [
        2080,
        -260
      ],
      "name": "All results",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "parameters": {
        "mode": "append"
      },
      "notes": "Invoices from the loop plus documents that are not invoices"
    },
    {
      "id": "17850a64-7372-4002-8e92-c2fcb2513d44",
      "position": [
        2340,
        -260
      ],
      "name": "Results table",
      "type": "n8n-nodes-base.html",
      "typeVersion": 1.2,
      "parameters": {
        "operation": "convertToHtmlTable",
        "options": {
          "customStyling": true,
          "tableAttributes": "style=\"border-collapse:collapse;font-size:14px;margin:0 auto\"",
          "headerAttributes": "style=\"background:#f2f2f2;border:1px solid #ccc;padding:6px 8px;text-align:left;vertical-align:top\"",
          "cellAttributes": "style=\"border:1px solid #ccc;padding:6px 8px;text-align:left;vertical-align:top\""
        }
      }
    },
    {
      "id": "cdf26cd0-473b-492a-81bd-97612240aef8",
      "position": [
        2600,
        -260
      ],
      "name": "Show result",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "=<div style=\"font-family:system-ui,sans-serif\"><h2 style=\"text-align:center\">Invoice inbox: result</h2>{{ $json.table }}</div>"
      },
      "webhookId": "5a202a5e-595a-40e7-80d2-73f93c39228d"
    },
    {
      "id": "c70c14b8-5e29-49d1-8d3b-0da328bce6f3",
      "position": [
        1300,
        -260
      ],
      "name": "Skip: not an invoice",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0cc542a4-fe1f-4fb4-81d7-560650e98167",
              "name": "Supplier",
              "value": "",
              "type": "string"
            },
            {
              "id": "d9290e36-6ac4-49aa-81f8-461534341ec0",
              "name": "Invoice",
              "value": "={{ $json.fileName }}",
              "type": "string"
            },
            {
              "id": "f7cba47a-3722-4a5b-8f20-95cce9639ea0",
              "name": "Amount",
              "value": "",
              "type": "string"
            },
            {
              "id": "2e44d40e-c070-4e53-8761-7de3fcfd2093",
              "name": "GL account",
              "value": "",
              "type": "string"
            },
            {
              "id": "2897cde5-8760-4568-877a-599d6dee1f35",
              "name": "Cost bearer",
              "value": "",
              "type": "string"
            },
            {
              "id": "a98fd38b-0be7-4532-8ff5-f279921e9709",
              "name": "Status",
              "value": "review",
              "type": "string"
            },
            {
              "id": "653a1d7a-44bb-4c67-8525-677aa6450c18",
              "name": "Decision",
              "value": "not an invoice",
              "type": "string"
            },
            {
              "id": "7947f3d7-63b4-4a06-8e21-57db9c08c8dd",
              "name": "Reason",
              "value": "=Jev: {{ $json.answers.docType.value }} ({{ ($json.answers.docType.confidence * 100).round() }}% sure); not extracted or booked",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "notes": "Same columns as \"Result row\", so it fits into the results table"
    },
    {
      "id": "a46dd258-ff71-476e-8daf-f41841c507a3",
      "position": [
        2080,
        300
      ],
      "name": "Invoice",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f74eb2ce-28e5-4cdd-8556-647d79b8cacc",
              "name": "fileName",
              "value": "={{ $json.fileName }}",
              "type": "string"
            },
            {
              "id": "16c428a5-5d9b-4bdf-8047-593bca7d8657",
              "name": "docType",
              "value": "={{ $json.answers.docType.value }}",
              "type": "string"
            },
            {
              "id": "d830ac4a-1bde-4435-8ff6-885c04d3f70b",
              "name": "vendor",
              "value": "={{ $json.record.vendor }}",
              "type": "string"
            },
            {
              "id": "4a45c169-ba97-424a-8772-77e13f1bb2b0",
              "name": "vendorKeyword",
              "value": "={{ $json.record.vendorKeyword }}",
              "type": "string"
            },
            {
              "id": "5f833b4b-40bc-4588-8461-c7532504472f",
              "name": "invoiceNumber",
              "value": "={{ $json.record.invoiceNumber }}",
              "type": "string"
            },
            {
              "id": "dec2ee48-9dfd-461a-817c-e83405edd3b9",
              "name": "invoiceDate",
              "value": "={{ $json.record.invoiceDate }}",
              "type": "string"
            },
            {
              "id": "07daa840-7de1-47f8-87a6-8e65742951e6",
              "name": "dueDate",
              "value": "={{ $json.record.dueDate }}",
              "type": "string"
            },
            {
              "id": "52e32a44-5a4d-4a9a-8206-386d100e2772",
              "name": "currency",
              "value": "={{ $json.record.currency }}",
              "type": "string"
            },
            {
              "id": "d81f6684-79fd-40cf-822f-c8b793a673e8",
              "name": "net",
              "value": "={{ $json.record.net }}",
              "type": "number"
            },
            {
              "id": "7e525f3c-eac9-45ec-89be-4afa6386f457",
              "name": "vat",
              "value": "={{ $json.record.vat }}",
              "type": "number"
            },
            {
              "id": "f74ed655-f8b8-4667-8fcd-dacdadbfa6a4",
              "name": "vatRate",
              "value": "={{ $json.record.vatRate ?? 0 }}",
              "type": "number"
            },
            {
              "id": "b0c8d016-c1dd-4502-8948-aa6c74ea6168",
              "name": "gross",
              "value": "={{ $json.record.gross }}",
              "type": "number"
            },
            {
              "id": "71dfd551-cf73-4481-8bc1-281dd8e7762d",
              "name": "addressee",
              "value": "={{ $json.record.addressee }}",
              "type": "string"
            },
            {
              "id": "5029b81b-53b6-4759-892b-94770b55c3f4",
              "name": "addresseeType",
              "value": "={{ $json.record.addresseeType }}",
              "type": "string"
            },
            {
              "id": "a8257672-1f3f-45ef-8fee-d89c72c6e351",
              "name": "vendorCategory",
              "value": "={{ $json.record.vendorCategory }}",
              "type": "string"
            },
            {
              "id": "a2808989-79b9-4649-8062-c736600bde92",
              "name": "vendorCountry",
              "value": "={{ $json.record.vendorCountry }}",
              "type": "string"
            },
            {
              "id": "b362fa22-f9e2-491c-88a7-c2a0e0755032",
              "name": "dealRelated",
              "value": "={{ $json.record.dealRelated ? 'yes' : 'no' }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "notes": "The fields of this invoice; later steps read them with $('Invoice')"
    },
    {
      "id": "364d3f71-29d1-45ed-83dc-d6af791888b1",
      "position": [
        2340,
        300
      ],
      "name": "Already received?",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "invoices",
          "cachedResultName": "invoices"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "invoiceNumber",
              "condition": "eq",
              "keyValue": "={{ $json.invoiceNumber }}"
            }
          ]
        },
        "limit": 1
      },
      "alwaysOutputData": true,
      "notes": "Duplicate check: same invoice number already in the invoices table"
    },
    {
      "id": "c9d90374-d1c3-4224-8bbd-5abed409b9b4",
      "position": [
        2600,
        300
      ],
      "name": "Supplier history",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "parameters": {
        "resource": "row",
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "invoice_history",
          "cachedResultName": "invoice_history"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "vendor",
              "condition": "ilike",
              "keyValue": "=%{{ $('Invoice').first().json.vendorKeyword }}%"
            }
          ]
        },
        "limit": 10,
        "orderBy": true,
        "orderByColumn": "invoice_date",
        "orderByDirection": "DESC"
      },
      "alwaysOutputData": true,
      "executeOnce": true,
      "notes": "The last 10 booked invoices of this supplier"
    },
    {
      "id": "c3cf1b6c-328b-40dc-899f-f18f46ade355",
      "position": [
        2860,
        300
      ],
      "name": "Usual amount",
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1.1,
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "average",
              "field": "amount_net"
            }
          ]
        },
        "options": {}
      },
      "notes": "Average net amount of the earlier invoices (average_amount_net)"
    },
    {
      "id": "f0796951-3077-4628-8151-c2951949aaa0",
      "position": [
        3120,
        300
      ],
      "name": "Booking row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "194335a3-85c4-4828-84a2-f856684fa777",
              "name": "dataset",
              "value": "invoice-history",
              "type": "string"
            },
            {
              "id": "2eaf5862-b152-4729-8a5a-4e06b2e34f20",
              "name": "target",
              "value": "gl_account",
              "type": "string"
            },
            {
              "id": "b411089e-2b12-47f1-80d4-dbb98b7943b3",
              "name": "row.vendor",
              "value": "={{ $('Supplier history').first().json.vendor ?? $('Invoice').first().json.vendor }}",
              "type": "string"
            },
            {
              "id": "5b57fa4f-c814-4901-814c-4976596e8aca",
              "name": "row.vendor_category",
              "value": "={{ $('Supplier history').first().json.vendor_category ?? $('Invoice').first().json.vendorCategory }}",
              "type": "string"
            },
            {
              "id": "a0c634c6-4d97-4866-82f3-23133ed054f8",
              "name": "row.vendor_country",
              "value": "={{ $('Supplier history').first().json.vendor_country ?? $('Invoice').first().json.vendorCountry }}",
              "type": "string"
            },
            {
              "id": "46cb30f7-390a-40b6-8df7-44a1e2959f6d",
              "name": "row.addressee",
              "value": "={{ $('Invoice').first().json.addresseeType }}",
              "type": "string"
            },
            {
              "id": "8f8421fa-06d2-4373-8a14-98e177cb6768",
              "name": "row.currency",
              "value": "={{ $('Invoice').first().json.currency }}",
              "type": "string"
            },
            {
              "id": "c1c71b5d-479a-4d25-8b3d-a5d7854057ed",
              "name": "row.amount_net",
              "value": "={{ $('Invoice').first().json.net }}",
              "type": "number"
            },
            {
              "id": "b1aaff77-2d0c-4749-85cd-9b1268b61326",
              "name": "row.vat_rate",
              "value": "={{ $('Invoice').first().json.vatRate }}",
              "type": "number"
            },
            {
              "id": "ac2b3c9e-bf3f-481e-8ac0-b54cbe093151",
              "name": "row.deal_related",
              "value": "={{ $('Invoice').first().json.dealRelated }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "notes": "One row in the columns of the invoice history; supplier category and country as booked before"
    },
    {
      "id": "cc76bb07-fd57-43af-8f49-9412918ea234",
      "position": [
        3380,
        300
      ],
      "name": "Predict GL account",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkPredictTabPFN",
          "cachedResultName": "predict (tabular foundation model, Prior Labs API)",
          "cachedResultUrl": "/workflow/blkPredictTabPFN"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "notes": "TabPFN (Prior Labs, own key), learned from invoice-history; without an account: pick predict (tabular foundation model), TabICLv2 on the workshop laptop"
    },
    {
      "id": "eac82802-cffa-47e5-8c4f-a8178d7f2e36",
      "position": [
        3640,
        300
      ],
      "name": "Question: cost bearer",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d7c7516e-f309-4cf6-83b6-9b7f74117f4c",
              "name": "target",
              "value": "cost_bearer",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "notes": "Same row, other column to predict"
    },
    {
      "id": "bfc62b7c-67df-41fb-852d-084c661d7d2c",
      "position": [
        3900,
        300
      ],
      "name": "Predict cost bearer",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "blkPredictTabPFN",
          "cachedResultName": "predict (tabular foundation model, Prior Labs API)",
          "cachedResultUrl": "/workflow/blkPredictTabPFN"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "notes": "TabPFN (Prior Labs, own key), learned from invoice-history; without an account: pick predict (tabular foundation model), TabICLv2 on the workshop laptop"
    },
    {
      "id": "321b17a5-3172-4d73-8d0f-dac8143729ae",
      "position": [
        4160,
        300
      ],
      "name": "Route",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "parameters": {
        "mode": "rules",
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "122b8e0b-f005-4424-8290-6f0c003d3dac",
                    "leftValue": "={{ $('Already received?').first().json.invoiceNumber }}",
                    "rightValue": "",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "duplicate"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "ca44bbc8-3a23-4d0d-8f3c-a352ed64836e",
                    "leftValue": "={{ $('Invoice').first().json.addresseeType }}",
                    "rightValue": "Portfolio",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "portfolio company"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "625af8bc-8a50-45c5-8124-a01d8a0f6377",
                    "leftValue": "={{ $('Usual amount').first().json.average_amount_net }}",
                    "rightValue": "",
                    "operator": {
                      "type": "number",
                      "operation": "exists",
                      "singleValue": true
                    }
                  },
                  {
                    "id": "b66f3d4c-b35e-4121-8426-1654a2daa7cf",
                    "leftValue": "={{ $('Invoice').first().json.net }}",
                    "rightValue": "={{ $('Usual amount').first().json.average_amount_net * 4 }}",
                    "operator": {
                      "type": "number",
                      "operation": "gt"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "unusual amount"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "18e4cd2e-aacf-4889-8f32-c9e050e6d353",
                    "leftValue": "={{ $('Predict GL account').first().json.predictions[0].probability }}",
                    "rightValue": 0.7,
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "GL account uncertain"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "80b0e975-037b-4411-8b63-0e2c6f5415ce",
                    "leftValue": "={{ $json.predictions[0].probability }}",
                    "rightValue": 0.7,
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "cost bearer uncertain"
            }
          ]
        },
        "looseTypeValidation": true,
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "ok"
        }
      },
      "notes": "First match wins: change the order, the factor 4 or the 0.7 threshold here"
    },
    {
      "id": "6f93b790-de19-4147-813c-cb469f5ba436",
      "position": [
        4680,
        300
      ],
      "name": "Needs a human?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "ca0149f1-9849-4a36-8ce8-b844b5712cbb",
              "leftValue": "={{ $json.status }}",
              "rightValue": "ok",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "notes": "true: review or escalate goes to a person first; false: auto-approved"
    },
    {
      "id": "8983f017-3945-407e-87f9-cc1b333cb3da",
      "position": [
        4940,
        700
      ],
      "name": "Review invoice",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "parameters": {
        "operation": "page",
        "defineForm": "fields",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Decision",
              "fieldName": "decision",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Approve"
                  },
                  {
                    "option": "Reject"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldLabel": "GL account (SKR04)",
              "fieldName": "glAccount",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "6300"
                  },
                  {
                    "option": "6400"
                  },
                  {
                    "option": "6600"
                  },
                  {
                    "option": "6650"
                  },
                  {
                    "option": "6815"
                  },
                  {
                    "option": "6825"
                  },
                  {
                    "option": "6826"
                  },
                  {
                    "option": "6827"
                  },
                  {
                    "option": "6830"
                  },
                  {
                    "option": "6837"
                  },
                  {
                    "option": "6855"
                  }
                ]
              },
              "defaultValue": "={{ $('Predict GL account').first().json.predictions[0].value }}",
              "requiredField": true
            },
            {
              "fieldLabel": "Cost bearer",
              "fieldName": "costBearer",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Fund"
                  },
                  {
                    "option": "ManCo"
                  },
                  {
                    "option": "Portfolio recharge"
                  }
                ]
              },
              "defaultValue": "={{ $('Predict cost bearer').first().json.predictions[0].value }}",
              "requiredField": true
            },
            {
              "fieldLabel": "Comment",
              "fieldName": "comment",
              "fieldType": "text"
            }
          ]
        },
        "options": {
          "formTitle": "=Review: {{ $('Invoice').first().json.vendor }} {{ $('Invoice').first().json.invoiceNumber }}",
          "formDescription": "=Amount: {{ $('Invoice').first().json.currency }} {{ $('Invoice').first().json.gross }} gross, {{ $('Invoice').first().json.net }} net. Addressed to {{ $('Invoice').first().json.addressee }}.\nWhy you see it: {{ $json.reason }}.\nProposal: GL account {{ $('Predict GL account').first().json.predictions[0].value }} ({{ ($('Predict GL account').first().json.predictions[0].probability * 100).round() }}% sure), cost bearer {{ $('Predict cost bearer').first().json.predictions[0].value }} ({{ ($('Predict cost bearer').first().json.predictions[0].probability * 100).round() }}% sure).",
          "buttonLabel": "Save decision"
        }
      },
      "webhookId": "59b62907-fd8f-43a1-8476-9b581ae0224e",
      "notes": "A person approves or rejects; GL account and cost bearer start with the proposal"
    },
    {
      "id": "781d247c-c7d1-458f-8484-932f5bac6399",
      "position": [
        5200,
        700
      ],
      "name": "Reviewer decision",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "52da68ba-51ba-419d-8475-4d5ff3247bf4",
              "name": "status",
              "value": "={{ $json.decision == 'Approve' ? 'approved' : 'rejected' }}",
              "type": "string"
            },
            {
              "id": "0ce5bde4-6b7d-4240-85b2-0a59d10fa83f",
              "name": "decision",
              "value": "={{ $('Needs a human?').first().json.decision }}",
              "type": "string"
            },
            {
              "id": "0b1181a7-1293-4ffd-8c6f-527048ae4169",
              "name": "reason",
              "value": "={{ $('Needs a human?').first().json.reason }}",
              "type": "string"
            },
            {
              "id": "c4671cb2-ebee-4886-8772-0856be44649b",
              "name": "glAccount",
              "value": "={{ $json.glAccount }}",
              "type": "string"
            },
            {
              "id": "a344fa3c-04e0-4945-8bf0-a8379f632973",
              "name": "costBearer",
              "value": "={{ $json.costBearer }}",
              "type": "string"
            },
            {
              "id": "3f93fa97-1794-4614-8546-05396ef61123",
              "name": "reviewDecision",
              "value": "={{ $json.decision }}",
              "type": "string"
            },
            {
              "id": "5eb95650-9784-4c1d-8056-55404cde87c9",
              "name": "reviewComment",
              "value": "={{ $json.comment }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "notes": "What the person decided; the reason why it was shown stays"
    },
    {
      "id": "a5fc703e-ff7d-4504-83c9-7fd0ce2dfcae",
      "position": [
        5460,
        300
      ],
      "name": "Save invoice",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "invoices",
          "cachedResultName": "invoices"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "fileName": "={{ $('Invoice').first().json.fileName }}",
            "vendor": "={{ $('Invoice').first().json.vendor }}",
            "invoiceNumber": "={{ $('Invoice').first().json.invoiceNumber }}",
            "invoiceDate": "={{ $('Invoice').first().json.invoiceDate }}",
            "dueDate": "={{ $('Invoice').first().json.dueDate }}",
            "currency": "={{ $('Invoice').first().json.currency }}",
            "net": "={{ $('Invoice').first().json.net }}",
            "vat": "={{ $('Invoice').first().json.vat }}",
            "gross": "={{ $('Invoice').first().json.gross }}",
            "addressee": "={{ $('Invoice').first().json.addressee }}",
            "glAccount": "={{ $json.glAccount ?? $('Predict GL account').first().json.predictions[0].value }}",
            "glProbability": "={{ $('Predict GL account').first().json.predictions[0].probability }}",
            "costBearer": "={{ $json.costBearer ?? $('Predict cost bearer').first().json.predictions[0].value }}",
            "costBearerProbability": "={{ $('Predict cost bearer').first().json.predictions[0].probability }}",
            "status": "={{ $json.status }}",
            "decision": "={{ $json.decision }}",
            "reasons": "={{ $json.reason }}",
            "reviewDecision": "={{ $json.reviewDecision }}",
            "reviewComment": "={{ $json.reviewComment }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "fileName",
              "displayName": "fileName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "vendor",
              "displayName": "vendor",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "invoiceNumber",
              "displayName": "invoiceNumber",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "invoiceDate",
              "displayName": "invoiceDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "dueDate",
              "displayName": "dueDate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "currency",
              "displayName": "currency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "net",
              "displayName": "net",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "vat",
              "displayName": "vat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "gross",
              "displayName": "gross",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "addressee",
              "displayName": "addressee",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "glAccount",
              "displayName": "glAccount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "glProbability",
              "displayName": "glProbability",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "costBearer",
              "displayName": "costBearer",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "costBearerProbability",
              "displayName": "costBearerProbability",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "decision",
              "displayName": "decision",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "reasons",
              "displayName": "reasons",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "reviewDecision",
              "displayName": "reviewDecision",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "reviewComment",
              "displayName": "reviewComment",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      }
    },
    {
      "id": "905fd527-8b1e-40fe-87b9-0beadd523d0a",
      "position": [
        5720,
        300
      ],
      "name": "Booked?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "cd724b3f-a0fa-4129-8f6a-b9f50bc8926e",
              "leftValue": "={{ $json.status }}",
              "rightValue": "rejected",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "notes": "true: ok or approved by a person, so it also goes into the invoice history"
    },
    {
      "id": "cf8013f8-4f7d-4438-8fe7-ce9b6c171e49",
      "position": [
        5980,
        600
      ],
      "name": "Add to history",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "invoice_history",
          "cachedResultName": "invoice_history"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "invoice_id": "={{ $('Save invoice').first().json.invoiceNumber }}",
            "invoice_date": "={{ $('Save invoice').first().json.invoiceDate }}",
            "vendor": "={{ $('Booking row').first().json.row.vendor }}",
            "vendor_category": "={{ $('Booking row').first().json.row.vendor_category }}",
            "vendor_country": "={{ $('Booking row').first().json.row.vendor_country }}",
            "addressee": "={{ $('Booking row').first().json.row.addressee }}",
            "currency": "={{ $('Booking row').first().json.row.currency }}",
            "amount_net": "={{ $('Booking row').first().json.row.amount_net }}",
            "vat_rate": "={{ $('Booking row').first().json.row.vat_rate }}",
            "deal_related": "={{ $('Booking row').first().json.row.deal_related }}",
            "description": "={{ $('Save invoice').first().json.fileName }}",
            "gl_account": "={{ $('Save invoice').first().json.glAccount }}",
            "cost_bearer": "={{ $('Save invoice').first().json.costBearer }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "invoice_id",
              "displayName": "invoice_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "invoice_date",
              "displayName": "invoice_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "vendor",
              "displayName": "vendor",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "vendor_category",
              "displayName": "vendor_category",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "vendor_country",
              "displayName": "vendor_country",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "addressee",
              "displayName": "addressee",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "currency",
              "displayName": "currency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "amount_net",
              "displayName": "amount_net",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "vat_rate",
              "displayName": "vat_rate",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "deal_related",
              "displayName": "deal_related",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "description",
              "displayName": "description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "gl_account",
              "displayName": "gl_account",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "cost_bearer",
              "displayName": "cost_bearer",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      }
    },
    {
      "id": "19b39458-319b-4e75-8d44-951288ff01c0",
      "position": [
        6240,
        300
      ],
      "name": "Result row",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "80cd6ac2-b536-4062-8319-2bdc8bd27aa5",
              "name": "Supplier",
              "value": "={{ $('Save invoice').first().json.vendor }}",
              "type": "string"
            },
            {
              "id": "180d5d58-81eb-4bea-8a09-e95a690a6f0a",
              "name": "Invoice",
              "value": "={{ $('Save invoice').first().json.invoiceNumber }}",
              "type": "string"
            },
            {
              "id": "3c98d2c9-3ae8-4903-842d-f694a4083bec",
              "name": "Amount",
              "value": "={{ $('Save invoice').first().json.currency }} {{ $('Save invoice').first().json.gross }}",
              "type": "string"
            },
            {
              "id": "28264635-c04b-4621-8b53-e6fae8afb41c",
              "name": "GL account",
              "value": "={{ $('Save invoice').first().json.glAccount }} ({{ ($('Save invoice').first().json.glProbability * 100).round() }}%)",
              "type": "string"
            },
            {
              "id": "2f31be26-a673-4e22-8e9d-2c5ce55f8c52",
              "name": "Cost bearer",
              "value": "={{ $('Save invoice').first().json.costBearer }} ({{ ($('Save invoice').first().json.costBearerProbability * 100).round() }}%)",
              "type": "string"
            },
            {
              "id": "6cc699f3-5916-46e9-8900-06540ebf0599",
              "name": "Status",
              "value": "={{ $('Save invoice').first().json.status }}",
              "type": "string"
            },
            {
              "id": "b4a9c48f-71f1-42b7-86d9-1e6a94669cf9",
              "name": "Decision",
              "value": "={{ $('Save invoice').first().json.decision }}",
              "type": "string"
            },
            {
              "id": "3ed0d674-cc69-424e-8f25-a8c5145fabbe",
              "name": "Reason",
              "value": "={{ $('Save invoice').first().json.reasons }} {{ $('Save invoice').first().json.reviewComment }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "notes": "One row of the results table; the columns are the fields set here"
    },
    {
      "id": "9b9173f0-0086-415a-8b17-c7218d6ee46b",
      "position": [
        4420,
        -75
      ],
      "name": "Escalate: duplicate",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "47d4e94f-39f6-4eae-8f84-3ef2ee05df10",
              "name": "status",
              "value": "escalate",
              "type": "string"
            },
            {
              "id": "57d2e450-e1c3-4d2e-8a5f-001f3686ca60",
              "name": "decision",
              "value": "duplicate, do not pay",
              "type": "string"
            },
            {
              "id": "2551d7fc-f374-4379-8214-294890760d3a",
              "name": "reason",
              "value": "=duplicate: {{ $('Invoice').first().json.invoiceNumber }} from this supplier was already received",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "f12ac532-016d-43f8-8e3b-13593f211ded",
      "position": [
        4420,
        75
      ],
      "name": "Review: portfolio company",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "aaa5fe25-a01b-4ce2-86fb-ca9cc20703ff",
              "name": "status",
              "value": "review",
              "type": "string"
            },
            {
              "id": "c6bd03de-9189-4925-88d4-78638085a027",
              "name": "decision",
              "value": "review",
              "type": "string"
            },
            {
              "id": "bcce283b-521c-4d71-8cf6-812c23f3923b",
              "name": "reason",
              "value": "=addressed to the portfolio company {{ $('Invoice').first().json.addressee }}: recharge, not a fund or ManCo cost",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "f9836ca3-1321-49cd-8bd7-695492a8364b",
      "position": [
        4420,
        225
      ],
      "name": "Review: unusual amount",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a226107d-c229-432b-8d3c-edec90017e21",
              "name": "status",
              "value": "review",
              "type": "string"
            },
            {
              "id": "8d404a3e-8f64-4b0b-8493-cc5423ce5b88",
              "name": "decision",
              "value": "review",
              "type": "string"
            },
            {
              "id": "84f12ef6-0ae6-4527-821e-9a17d270dfb3",
              "name": "reason",
              "value": "=unusual amount: net {{ $('Invoice').first().json.net }} against an average of {{ $('Usual amount').first().json.average_amount_net.round() }} for this supplier",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "5298b455-7d05-4bde-88e0-05a5373e19c5",
      "position": [
        4420,
        375
      ],
      "name": "Review: GL account uncertain",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e440e340-61bb-4e44-8754-3a3e7e55426f",
              "name": "status",
              "value": "review",
              "type": "string"
            },
            {
              "id": "797515c4-1d30-488e-8bab-70b531f31653",
              "name": "decision",
              "value": "review",
              "type": "string"
            },
            {
              "id": "f15148f5-550f-4cd0-8b63-013365161e41",
              "name": "reason",
              "value": "=GL account uncertain: {{ $('Predict GL account').first().json.predictions[0].value }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "0584936c-23ab-44d3-86c7-3ddc44476c8f",
      "position": [
        4420,
        525
      ],
      "name": "Review: cost bearer uncertain",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "402f092f-de2a-4543-8cae-7ef6da3e0b3f",
              "name": "status",
              "value": "review",
              "type": "string"
            },
            {
              "id": "b5a7d826-e6b7-4966-82c1-9ab761034510",
              "name": "decision",
              "value": "review",
              "type": "string"
            },
            {
              "id": "3b872628-e8ef-472d-801c-06198563ed3e",
              "name": "reason",
              "value": "=cost bearer uncertain: {{ $json.predictions[0].value }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "414cfb73-87d4-4510-8b9b-e69fdd36afe0",
      "position": [
        4420,
        675
      ],
      "name": "OK: auto-approve",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a868ae7a-5c8e-4b6e-8ab7-f200a265a4e0",
              "name": "status",
              "value": "ok",
              "type": "string"
            },
            {
              "id": "709eabea-c3f5-4d24-8fbb-0928a8d44a48",
              "name": "decision",
              "value": "auto-approved",
              "type": "string"
            },
            {
              "id": "af6d2ed7-0507-4675-8357-2263a1bacf07",
              "name": "reason",
              "value": "all checks passed",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "bc7295c9-4209-4946-8a3f-12930476580f",
      "position": [
        0,
        -470
      ],
      "name": "About",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "parameters": {
        "content": "## P1 Invoice inbox (Jev + TabPFN)\nRead each document, Jev checks it is an invoice (others go straight to the results as \"not an invoice\"), the LLM extracts the fields. Then one invoice at a time: look it up in the invoices table (duplicate), compare the amount with the supplier's average (more than 4x is unusual), TabPFN (Prior Labs, own free key) proposes GL account and cost bearer, the Route node decides. Everything not auto-approved goes to a person (Review invoice, a further form page) before it is saved; ok and approved invoices are added to the invoice history, so the next prediction learns from them. No code: change the rules in Route.",
        "width": 660,
        "height": 260,
        "color": 7
      }
    }
  ],
  "connections": {
    "Upload": {
      "main": [
        [
          {
            "node": "Read document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read document": {
      "main": [
        [
          {
            "node": "Question: is it an invoice?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Question: is it an invoice?": {
      "main": [
        [
          {
            "node": "Ask Jev: is it an invoice?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask Jev: is it an invoice?": {
      "main": [
        [
          {
            "node": "Skip this document?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fields to extract": {
      "main": [
        [
          {
            "node": "Extract invoice fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract invoice fields": {
      "main": [
        [
          {
            "node": "One invoice at a time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "All results": {
      "main": [
        [
          {
            "node": "Results table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Results table": {
      "main": [
        [
          {
            "node": "Show result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Invoice": {
      "main": [
        [
          {
            "node": "Already received?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Already received?": {
      "main": [
        [
          {
            "node": "Supplier history",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supplier history": {
      "main": [
        [
          {
            "node": "Usual amount",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Usual amount": {
      "main": [
        [
          {
            "node": "Booking row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Booking row": {
      "main": [
        [
          {
            "node": "Predict GL account",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Predict GL account": {
      "main": [
        [
          {
            "node": "Question: cost bearer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Question: cost bearer": {
      "main": [
        [
          {
            "node": "Predict cost bearer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Predict cost bearer": {
      "main": [
        [
          {
            "node": "Route",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Review invoice": {
      "main": [
        [
          {
            "node": "Reviewer decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save invoice": {
      "main": [
        [
          {
            "node": "Booked?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip this document?": {
      "main": [
        [
          {
            "node": "Skip: not an invoice",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fields to extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip: not an invoice": {
      "main": [
        [
          {
            "node": "All results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One invoice at a time": {
      "main": [
        [
          {
            "node": "All results",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route": {
      "main": [
        [
          {
            "node": "Escalate: duplicate",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Review: portfolio company",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Review: unusual amount",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Review: GL account uncertain",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Review: cost bearer uncertain",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OK: auto-approve",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Escalate: duplicate": {
      "main": [
        [
          {
            "node": "Needs a human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Review: portfolio company": {
      "main": [
        [
          {
            "node": "Needs a human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Review: unusual amount": {
      "main": [
        [
          {
            "node": "Needs a human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Review: GL account uncertain": {
      "main": [
        [
          {
            "node": "Needs a human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Review: cost bearer uncertain": {
      "main": [
        [
          {
            "node": "Needs a human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OK: auto-approve": {
      "main": [
        [
          {
            "node": "Needs a human?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs a human?": {
      "main": [
        [
          {
            "node": "Review invoice",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reviewer decision": {
      "main": [
        [
          {
            "node": "Save invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Booked?": {
      "main": [
        [
          {
            "node": "Add to history",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Result row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to history": {
      "main": [
        [
          {
            "node": "Result row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Result row": {
      "main": [
        [
          {
            "node": "One invoice at a time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true
  }
}
