{
  "name": "LOGYCA - Sales Daily Summary",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 1
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO sales_daily_summary (date, total_sales, last_updated)\nSELECT s.date, SUM(s.total) AS total_sales, CURRENT_TIMESTAMP\nFROM sales s\nINNER JOIN jobs j ON s.job_id = j.id\nWHERE j.status = 'COMPLETED'\nGROUP BY s.date\nON CONFLICT (date)\nDO UPDATE SET\n    total_sales = EXCLUDED.total_sales,\n    last_updated = CURRENT_TIMESTAMP;",
        "options": {}
      },
      "id": "postgres-upsert",
      "name": "Upsert Daily Summary",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        500,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Upsert Daily Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2026-04-01T15:00:00.000Z",
  "versionId": "1"
}