8
n8n 中文网amn8n.com

使用 PDF Vector 和 Google Drive 的自动化收据处理与税务分类

中级

这是一个Invoice Processing, AI Summarization, Multimodal AI领域的自动化工作流,包含 9 个节点。主要使用 Code, GoogleDrive, GoogleSheets, ManualTrigger, PdfVector 等节点。 使用 PDF Vector 和 Google Drive 的自动化收据处理与税务分类

前置要求
  • Google Drive API 凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "placeholder"
  },
  "nodes": [
    {
      "id": "overview-note",
      "name": "收据概览",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        50,
        50
      ],
      "parameters": {
        "color": 5,
        "width": 350,
        "height": 180,
        "content": "## 🧾 收据与税务追踪器"
      },
      "typeVersion": 1
    },
    {
      "id": "input-note",
      "name": "输入来源",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        450,
        450
      ],
      "parameters": {
        "width": 250,
        "height": 150,
        "content": "## 📸 收据输入"
      },
      "typeVersion": 1
    },
    {
      "id": "tax-note",
      "name": "税务类别",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        850,
        450
      ],
      "parameters": {
        "color": 4,
        "width": 260,
        "height": 160,
        "content": "## 💰 税务逻辑"
      },
      "typeVersion": 1
    },
    {
      "id": "manual-trigger",
      "name": "手动触发器",
      "type": "n8n-nodes-base.manualTrigger",
      "notes": "Process receipt",
      "position": [
        250,
        300
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "google-drive",
      "name": "Google Drive - 获取收据",
      "type": "n8n-nodes-base.googleDrive",
      "notes": "Retrieve receipt from Drive",
      "position": [
        450,
        300
      ],
      "parameters": {
        "fileId": "={{ $json.fileId }}",
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "pdfvector-extract",
      "name": "PDF Vector - 提取收据",
      "type": "n8n-nodes-pdfvector.pdfVector",
      "notes": "Extract receipt data",
      "position": [
        650,
        300
      ],
      "parameters": {
        "prompt": "Extract all receipt information from this document or image including merchant name and address, transaction date and time, all items with descriptions and prices, subtotal, tax amount and rate, tip if applicable, total amount, payment method, and any loyalty or membership numbers. Use OCR if this is a scanned receipt or image.",
        "schema": "{\"type\":\"object\",\"properties\":{\"merchant\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"address\":{\"type\":\"string\"},\"phone\":{\"type\":\"string\"},\"taxId\":{\"type\":\"string\"}}},\"transaction\":{\"type\":\"object\",\"properties\":{\"date\":{\"type\":\"string\"},\"time\":{\"type\":\"string\"},\"receiptNumber\":{\"type\":\"string\"},\"cashier\":{\"type\":\"string\"}}},\"items\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"description\":{\"type\":\"string\"},\"quantity\":{\"type\":\"number\"},\"unitPrice\":{\"type\":\"number\"},\"totalPrice\":{\"type\":\"number\"},\"taxable\":{\"type\":\"boolean\"}}}},\"financial\":{\"type\":\"object\",\"properties\":{\"subtotal\":{\"type\":\"number\"},\"taxRate\":{\"type\":\"number\"},\"taxAmount\":{\"type\":\"number\"},\"tip\":{\"type\":\"number\"},\"total\":{\"type\":\"number\"},\"currency\":{\"type\":\"string\"}}},\"payment\":{\"type\":\"object\",\"properties\":{\"method\":{\"type\":\"string\"},\"lastFourDigits\":{\"type\":\"string\"},\"authCode\":{\"type\":\"string\"}}},\"loyalty\":{\"type\":\"object\",\"properties\":{\"memberNumber\":{\"type\":\"string\"},\"pointsEarned\":{\"type\":\"number\"},\"pointsBalance\":{\"type\":\"number\"}}}},\"required\":[\"merchant\",\"financial\"],\"additionalProperties\":false}",
        "resource": "document",
        "inputType": "file",
        "operation": "extract",
        "binaryPropertyName": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "pdfvector-categorize",
      "name": "PDF Vector - 税务分类",
      "type": "n8n-nodes-pdfvector.pdfVector",
      "notes": "Categorize for taxes",
      "position": [
        850,
        300
      ],
      "parameters": {
        "prompt": "Based on this receipt document or image, determine: 1) The most appropriate tax category (meals, travel, supplies, equipment, etc.), 2) Whether this is likely tax deductible for business, 3) If this is a meal receipt, what percentage would typically be deductible, 4) Any special considerations for tax purposes. Process any image format using OCR if needed.",
        "resource": "document",
        "inputType": "file",
        "operation": "ask",
        "binaryPropertyName": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "process-expense",
      "name": "处理费用数据",
      "type": "n8n-nodes-base.code",
      "notes": "Validate and categorize",
      "position": [
        1050,
        300
      ],
      "parameters": {
        "jsCode": "// Process receipt data and tax categorization\nconst receiptData = $node['PDF Vector - Extract Receipt'].json.data;\nconst taxCategory = $node['PDF Vector - Tax Categorization'].json.answer;\n\n// Validate financial calculations\nlet validationErrors = [];\nif (receiptData.items && receiptData.items.length > 0) {\n  const calculatedSubtotal = receiptData.items.reduce((sum, item) => sum + (item.totalPrice || 0), 0);\n  if (Math.abs(calculatedSubtotal - receiptData.financial.subtotal) > 0.02) {\n    validationErrors.push('Item totals do not match subtotal');\n  }\n}\n\n// Calculate tax consistency\nconst expectedTax = receiptData.financial.subtotal * (receiptData.financial.taxRate / 100);\nif (Math.abs(expectedTax - receiptData.financial.taxAmount) > 0.02) {\n  validationErrors.push('Tax calculation inconsistency');\n}\n\n// Determine expense category and deductibility\nlet expenseCategory = 'Other';\nlet deductiblePercentage = 100;\nlet taxNotes = '';\n\nif (taxCategory.toLowerCase().includes('meal')) {\n  expenseCategory = 'Meals & Entertainment';\n  deductiblePercentage = 50; // Typical meal deduction\n  taxNotes = 'Business meal - 50% deductible';\n} else if (taxCategory.toLowerCase().includes('travel')) {\n  expenseCategory = 'Travel';\n  deductiblePercentage = 100;\n  taxNotes = 'Business travel expense';\n} else if (taxCategory.toLowerCase().includes('supplies')) {\n  expenseCategory = 'Office Supplies';\n  deductiblePercentage = 100;\n  taxNotes = 'Business supplies';\n}\n\n// Create processed expense record\nconst processedExpense = {\n  // Receipt data\n  merchant: receiptData.merchant.name,\n  date: receiptData.transaction.date,\n  amount: receiptData.financial.total,\n  currency: receiptData.financial.currency || 'USD',\n  \n  // Tax information\n  expenseCategory,\n  deductiblePercentage,\n  deductibleAmount: (receiptData.financial.total * deductiblePercentage / 100).toFixed(2),\n  taxNotes,\n  \n  // Original data\n  originalReceipt: receiptData,\n  aiCategorization: taxCategory,\n  \n  // Validation\n  isValid: validationErrors.length === 0,\n  validationErrors,\n  \n  // Metadata\n  processedAt: new Date().toISOString(),\n  taxYear: new Date(receiptData.transaction.date).getFullYear()\n};\n\nreturn [{ json: processedExpense }];"
      },
      "typeVersion": 2
    },
    {
      "id": "save-spreadsheet",
      "name": "保存到费用表",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "Track in spreadsheet",
      "position": [
        1250,
        300
      ],
      "parameters": {
        "data": "={{ [[$json.date, $json.merchant, $json.expenseCategory, $json.amount, $json.deductibleAmount, $json.deductiblePercentage + '%', $json.taxNotes, $json.processedAt]] }}",
        "range": "A:H",
        "sheetId": "{{ $json.taxYear }}-expenses",
        "operation": "append"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Google Drive - Get Receipt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Expense Data": {
      "main": [
        [
          {
            "node": "Save to Expense Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive - Get Receipt": {
      "main": [
        [
          {
            "node": "PDF Vector - Extract Receipt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PDF Vector - Extract Receipt": {
      "main": [
        [
          {
            "node": "PDF Vector - Tax Categorization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PDF Vector - Tax Categorization": {
      "main": [
        [
          {
            "node": "Process Expense Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 发票处理, AI 摘要总结, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量9
分类3
节点类型6
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
PDF Vector

PDF Vector

@pdfvector

A fully featured PDF APIs for developers - Parse any PDF or Word document, extract structured data, and access millions of academic papers - all through simple APIs.

外部链接
在 n8n.io 查看

分享此工作流