{
  "name": "Balance_report",
  "nodes": [
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "start_date"
            },
            {
              "name": "end_date"
            },
            {
              "name": "tenant_id"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        360,
        -140
      ],
      "id": "c723893e-39f8-4c7d-ad0b-96ebfa9fe1c9",
      "name": "Input"
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "balances",
        "matchType": "allFilters",
        "filters": {
          "conditions": [
            {
              "keyName": "created_at",
              "condition": "gte",
              "keyValue": "={{ $json.start_date }}"
            },
            {
              "keyName": "created_at",
              "condition": "lte",
              "keyValue": "={{ $json.end_date }}"
            },
            {
              "keyName": "tenant_id",
              "condition": "eq",
              "keyValue": "={{ $json.tenant_id }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        540,
        -140
      ],
      "id": "9b289e1e-7f86-40a8-8161-55e47d1605e7",
      "name": "Get balances",
      "alwaysOutputData": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "balances",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        700,
        -140
      ],
      "id": "5e56bd54-bfdf-46d9-9356-f758d438f8b3",
      "name": "Aggregate"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1e063775-4ab9-432e-a43f-36f89d6aea98",
              "name": "total",
              "value": "={{ $json.balances.map(it => it.value || 0).sum() }}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        880,
        -140
      ],
      "id": "3f9ebe11-ed97-4d93-bad8-935528964636",
      "name": "Calculate"
    }
  ],
  "connections": {
    "Input": {
      "main": [
        [
          {
            "node": "Get balances",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get balances": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Calculate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ea25b273-0e9b-4f01-aa0f-f65e89840c32",
  "id": "2CeyQ8TAGuYuaDxV",
  "tags": []
}