{
  "id": "zfjbXMrH4jEkZcti",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automated Daily Cash Flow & Expense Report for Finance Professionals",
  "tags": [],
  "nodes": [
    {
      "id": "906bf96e-e9fd-480d-850a-ea04667fba76",
      "name": "Daily at 6 PM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "notes": "\u23f0 DAILY TRIGGER\nRuns every day at 6:00 PM\nGenerates end-of-day report",
      "position": [
        -928,
        -208
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "13babc7a-eaef-4484-b2a7-a9d98a7c7936",
      "name": "Get Cash Inflows",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "\ud83d\udcb5 FETCH INFLOWS\nRetrieves all incoming payments\nToday's deposits & revenue",
      "position": [
        -704,
        -304
      ],
      "parameters": {
        "url": "https://api.accounting.com/transactions",
        "options": {}
      },
      "typeVersion": 4.1
    },
    {
      "id": "8c87a527-7f6a-4806-80a5-63cb76a755f4",
      "name": "Get Cash Outflows",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "\ud83d\udcb8 FETCH OUTFLOWS\nRetrieves all outgoing payments\nToday's expenses & bills",
      "position": [
        -704,
        0
      ],
      "parameters": {
        "url": "https://api.accounting.com/transactions",
        "options": {}
      },
      "typeVersion": 4.1
    },
    {
      "id": "4a48cf32-59d4-4048-ae7c-0134ee0f2663",
      "name": "Calculate Inflows",
      "type": "n8n-nodes-base.code",
      "notes": "\ud83e\uddee CALCULATE INFLOWS\nSums total incoming cash\nGroups by category\nCounts transactions",
      "position": [
        -480,
        -304
      ],
      "parameters": {
        "jsCode": "// Process Inflows\nconst inflows = $input.first().json;\nlet totalInflow = 0;\nconst inflowsByCategory = {};\n\nif (Array.isArray(inflows)) {\n  inflows.forEach(transaction => {\n    totalInflow += parseFloat(transaction.amount || 0);\n    const category = transaction.category || 'Other';\n    if (!inflowsByCategory[category]) {\n      inflowsByCategory[category] = 0;\n    }\n    inflowsByCategory[category] += parseFloat(transaction.amount || 0);\n  });\n}\n\nreturn {\n  total_inflow: totalInflow.toFixed(2),\n  inflow_categories: inflowsByCategory,\n  inflow_count: Array.isArray(inflows) ? inflows.length : 0,\n  date: new Date().toISOString().split('T')[0]\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "47798a32-d2a6-4a71-b0fb-74c382417b45",
      "name": "Calculate Outflows",
      "type": "n8n-nodes-base.code",
      "notes": "\ud83e\uddee CALCULATE OUTFLOWS\nSums total outgoing cash\nGroups by expense category\nCounts transactions",
      "position": [
        -480,
        -112
      ],
      "parameters": {
        "jsCode": "// Process Outflows\nconst outflows = $input.first().json;\nlet totalOutflow = 0;\nconst outflowsByCategory = {};\n\nif (Array.isArray(outflows)) {\n  outflows.forEach(transaction => {\n    totalOutflow += parseFloat(transaction.amount || 0);\n    const category = transaction.category || 'Other';\n    if (!outflowsByCategory[category]) {\n      outflowsByCategory[category] = 0;\n    }\n    outflowsByCategory[category] += parseFloat(transaction.amount || 0);\n  });\n}\n\nreturn {\n  total_outflow: totalOutflow.toFixed(2),\n  outflow_categories: outflowsByCategory,\n  outflow_count: Array.isArray(outflows) ? outflows.length : 0,\n  date: new Date().toISOString().split('T')[0]\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "a5ac7f5d-5c0e-4aa1-a0ea-924aba958ce2",
      "name": "Merge Data",
      "type": "n8n-nodes-base.merge",
      "notes": "\ud83d\udd00 COMBINE DATA\nMerges inflows + outflows\nPrepares for final report",
      "position": [
        -256,
        -208
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combinationMode": "mergeByPosition"
      },
      "typeVersion": 2.1
    },
    {
      "id": "cf3299a5-67c9-4970-948e-7613f2dfbd07",
      "name": "Calculate Net Cash Flow",
      "type": "n8n-nodes-base.code",
      "notes": "\ud83d\udcca NET CALCULATION\nTotal Inflow - Total Outflow\nDetermines cash position\nPositive or Negative status",
      "position": [
        -32,
        -208
      ],
      "parameters": {
        "jsCode": "const data = $input.all();\nconst inflow = data[0].json;\nconst outflow = data[1].json;\n\nconst totalInflow = parseFloat(inflow.total_inflow || 0);\nconst totalOutflow = parseFloat(outflow.total_outflow || 0);\nconst netCashFlow = totalInflow - totalOutflow;\n\nreturn {\n  date: inflow.date,\n  total_inflow: totalInflow.toFixed(2),\n  total_outflow: totalOutflow.toFixed(2),\n  net_cash_flow: netCashFlow.toFixed(2),\n  inflow_categories: inflow.inflow_categories,\n  outflow_categories: outflow.outflow_categories,\n  inflow_count: inflow.inflow_count,\n  outflow_count: outflow.outflow_count,\n  cash_flow_status: netCashFlow >= 0 ? 'Positive' : 'Negative'\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "10370491-a9fb-4325-b6f0-4d81f071393a",
      "name": "Save to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "\ud83d\udcbe SAVE TO SHEETS\nSheet: Daily_Cash_Flow\nDoc ID: 9x8w7v6u5t4s3r2q\nHistorical tracking",
      "position": [
        192,
        -304
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [],
          "mappings": [
            {
              "value": "={{ $json.date }}",
              "column": "Date"
            },
            {
              "value": "={{ $json.total_inflow }}",
              "column": "Total_Inflow"
            },
            {
              "value": "={{ $json.total_outflow }}",
              "column": "Total_Outflow"
            },
            {
              "value": "={{ $json.net_cash_flow }}",
              "column": "Net_Cash_Flow"
            },
            {
              "value": "={{ $json.cash_flow_status }}",
              "column": "Status"
            },
            {
              "value": "={{ $json.inflow_count }}",
              "column": "Inflow_Count"
            },
            {
              "value": "={{ $json.outflow_count }}",
              "column": "Outflow_Count"
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": "Daily_Cash_Flow",
        "documentId": "9x8w7v6u5t4s3r2q",
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "90770fcd-1953-46f9-872b-1da928eca718",
      "name": "Generate HTML Report",
      "type": "n8n-nodes-base.code",
      "notes": "\ud83d\udcc4 CREATE REPORT\nBuilds HTML formatted report\nIncludes all categories\nSummary + detailed breakdown",
      "position": [
        208,
        48
      ],
      "parameters": {
        "jsCode": "const data = $input.first().json;\n\n// Build category breakdown HTML\nlet inflowHTML = '';\nfor (const [category, amount] of Object.entries(data.inflow_categories)) {\n  inflowHTML += `<tr><td>${category}</td><td>$${parseFloat(amount).toFixed(2)}</td></tr>`;\n}\n\nlet outflowHTML = '';\nfor (const [category, amount] of Object.entries(data.outflow_categories)) {\n  outflowHTML += `<tr><td>${category}</td><td>$${parseFloat(amount).toFixed(2)}</td></tr>`;\n}\n\nconst statusColor = data.cash_flow_status === 'Positive' ? 'green' : 'red';\n\nconst htmlReport = `\n<!DOCTYPE html>\n<html>\n<head>\n  <style>\n    body { font-family: Arial, sans-serif; max-width: 800px; margin: 20px auto; }\n    h1 { color: #333; border-bottom: 3px solid #4CAF50; padding-bottom: 10px; }\n    h2 { color: #666; margin-top: 30px; }\n    table { width: 100%; border-collapse: collapse; margin: 20px 0; }\n    th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }\n    th { background-color: #4CAF50; color: white; }\n    .summary { background: #f5f5f5; padding: 20px; border-radius: 8px; margin: 20px 0; }\n    .positive { color: green; font-weight: bold; }\n    .negative { color: red; font-weight: bold; }\n  </style>\n</head>\n<body>\n  <h1>Daily Cash Flow Report</h1>\n  <p><strong>Date:</strong> ${data.date}</p>\n  \n  <div class=\"summary\">\n    <h2>Summary</h2>\n    <p><strong>Total Inflows:</strong> $${data.total_inflow} (${data.inflow_count} transactions)</p>\n    <p><strong>Total Outflows:</strong> $${data.total_outflow} (${data.outflow_count} transactions)</p>\n    <p><strong>Net Cash Flow:</strong> <span style=\"color: ${statusColor};\">$${data.net_cash_flow}</span></p>\n    <p><strong>Status:</strong> <span style=\"color: ${statusColor};\">${data.cash_flow_status}</span></p>\n  </div>\n  \n  <h2>Cash Inflows by Category</h2>\n  <table>\n    <tr><th>Category</th><th>Amount</th></tr>\n    ${inflowHTML}\n    <tr style=\"background: #f0f0f0; font-weight: bold;\"><td>Total</td><td>$${data.total_inflow}</td></tr>\n  </table>\n  \n  <h2>Cash Outflows by Category</h2>\n  <table>\n    <tr><th>Category</th><th>Amount</th></tr>\n    ${outflowHTML}\n    <tr style=\"background: #f0f0f0; font-weight: bold;\"><td>Total</td><td>$${data.total_outflow}</td></tr>\n  </table>\n</body>\n</html>\n`;\n\nreturn {\n  html_report: htmlReport,\n  ...data\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "0bcbdaaf-97ff-440a-b3d9-5f6978183791",
      "name": "Email Report",
      "type": "n8n-nodes-base.emailSend",
      "notes": "\ud83d\udce7 EMAIL DELIVERY\nTo: finance@company.com, cfo@company.com\nCC: accounting@company.com\nPDF attachment included",
      "position": [
        640,
        -304
      ],
      "parameters": {
        "options": {
          "ccEmail": "user@example.com",
          "attachments": "data:application/pdf;base64,={{ $json.pdf_base64 }}"
        },
        "subject": "Daily Cash Flow Report - {{ $now.format('MMM dd, yyyy') }}",
        "toEmail": "user@example.com, user@example.com",
        "fromEmail": "user@example.com"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "3b4e8178-5819-4299-a509-429cbdc09e7e",
      "name": "Backup to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "notes": "\u2601\ufe0f CLOUD BACKUP\nGoogle Drive storage\nFolder: /finance/reports/\nAutomatic archiving",
      "position": [
        704,
        48
      ],
      "parameters": {
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "f6b32c5f-8fcf-4896-9c45-53147eed217d",
      "name": "Post to Slack",
      "type": "n8n-nodes-base.slack",
      "notes": "\ud83d\udcac SLACK NOTIFICATION\nChannel: #daily-reports\nChannel ID: C98765ZYXWV\nQuick summary for team",
      "position": [
        448,
        48
      ],
      "parameters": {
        "text": "\ud83d\udcca *Daily Cash Flow Report*\n\n*Date:* {{ $json.date }}\n\n\ud83d\udcb5 *Total Inflows:* ${{ $json.total_inflow }}\n\ud83d\udcb8 *Total Outflows:* ${{ $json.total_outflow }}\n\ud83d\udcc8 *Net Cash Flow:* ${{ $json.net_cash_flow }}\n\n*Status:* {{ $json.cash_flow_status }}\n\nFull report emailed to finance team.",
        "user": {
          "__rl": true,
          "mode": "username",
          "value": ""
        },
        "select": "user",
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "81ba9fe8-c157-4f81-a1ad-b5704b4b52c8",
      "name": "Convert to PDF",
      "type": "n8n-nodes-pdfmonkey.pdfMonkey",
      "position": [
        416,
        -304
      ],
      "parameters": {
        "documentTemplateId": "=mnhu765rfcxse456yuj"
      },
      "credentials": {
        "pdfMonkeyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5b07dccd-f3c4-49df-a158-5a7349d6a4cb",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -976,
        -336
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\u23f0 Triggers daily at 6 PM\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4576e612-833e-457e-9700-03453ab42433",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -736,
        -400
      ],
      "parameters": {
        "width": 160,
        "height": 240,
        "content": "\ud83d\udcb5 Fetches cash inflows (deposits, revenue)\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "8f251823-583f-49f5-9d47-ef91165a33c5",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -736,
        -96
      ],
      "parameters": {
        "width": 160,
        "height": 240,
        "content": "\ud83d\udcb8 Fetches cash outflows (expenses, bills)\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "8ae88b52-3252-4f56-979a-2b731758521b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -512,
        -416
      ],
      "parameters": {
        "width": 160,
        "height": 496,
        "content": "\ud83e\uddee Calculates totals by category for both\n"
      },
      "typeVersion": 1
    },
    {
      "id": "7bcaaee4-8a25-45f2-81c1-9e585fe57b20",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        -320
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\ud83d\udd00 Merges the data together\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e238c7cd-1035-43eb-8479-4ce1dd7cd97b",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        -320
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\ud83d\udcca Calculates net cash flow (Inflow - Outflow)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "94c331d0-66f9-445e-82e3-6e135519abf7",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -432
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\ud83d\udcbe Saves to Google Sheets for tracking\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d40e3e31-de41-40ea-ba8f-1fe904f18d0a",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        -432
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\ud83d\udce7 Emails to finance team with PDF attached\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cf304fc3-f19f-4285-9f38-6fe0712ba9bb",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        -112
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\ud83d\udcc4 Generates formatted HTML report\n"
      },
      "typeVersion": 1
    },
    {
      "id": "dcf2d893-d7a3-40d6-b39f-48d4692cfc23",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -432
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\ud83d\udcd1 Converts to professional PDF\n"
      },
      "typeVersion": 1
    },
    {
      "id": "67edc76d-3a9a-4e0a-b7d0-9286151e0629",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        -112
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\ud83d\udcac Posts summary to Slack"
      },
      "typeVersion": 1
    },
    {
      "id": "d62323f3-c4ca-4580-86a8-61e2a3dcd5e4",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        656,
        -112
      ],
      "parameters": {
        "width": 160,
        "height": 272,
        "content": "\u2601\ufe0f Backs up to Google Drive\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "110ed3b3-c47a-4dc3-9557-960a5948cb40",
  "connections": {
    "Merge Data": {
      "main": [
        [
          {
            "node": "Calculate Net Cash Flow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily at 6 PM": {
      "main": [
        [
          {
            "node": "Get Cash Inflows",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Cash Outflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Slack": {
      "main": [
        [
          {
            "node": "Backup to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to PDF": {
      "main": [
        [
          {
            "node": "Email Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Cash Inflows": {
      "main": [
        [
          {
            "node": "Calculate Inflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Inflows": {
      "main": [
        [
          {
            "node": "Merge Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Cash Outflows": {
      "main": [
        [
          {
            "node": "Calculate Outflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Outflows": {
      "main": [
        [
          {
            "node": "Merge Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Generate HTML Report": {
      "main": [
        [
          {
            "node": "Post to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Google Sheets": {
      "main": [
        [
          {
            "node": "Convert to PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Net Cash Flow": {
      "main": [
        [
          {
            "node": "Save to Google Sheets",
            "type": "main",
            "index": 0
          },
          {
            "node": "Generate HTML Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}