{
  "name": "Resumo diário de vendas",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "9ea2d696-779c-475c-bc28-de3108fb0ca9",
      "name": "Todos os dias 8h",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "ESCOLHE_A_FOLHA"
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "options": {}
      },
      "id": "77729184-e00c-4dbb-b759-1a0ccc7aa327",
      "name": "Ler vendas",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const ontem = $now.minus({days:1}).toFormat('yyyy-MM-dd');\nconst v = $input.all().map(i => i.json).filter(r => String(r.Data).startsWith(ontem));\nconst total = v.reduce((s, r) => s + Number(String(r.Valor).replace(',', '.')) || s, 0);\nreturn [{ json: { ontem, n: v.length, total: total.toFixed(2) } }];"
      },
      "id": "5a18ef88-fff1-40d4-8d86-4797123a2462",
      "name": "Calcular ontem",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "sendTo": "o-teu-email@exemplo.pt",
        "subject": "=Vendas de {{ $json.ontem }}: {{ $json.total }} €",
        "emailType": "text",
        "message": "=Bom dia!\n\nOntem ({{ $json.ontem }}) houve {{ $json.n }} vendas, total {{ $json.total }} €.",
        "options": {}
      },
      "id": "dd20e019-e4fc-41bf-8fc2-53541de52026",
      "name": "Enviar resumo",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        720,
        0
      ]
    }
  ],
  "connections": {
    "Todos os dias 8h": {
      "main": [
        [
          {
            "node": "Ler vendas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ler vendas": {
      "main": [
        [
          {
            "node": "Calcular ontem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calcular ontem": {
      "main": [
        [
          {
            "node": "Enviar resumo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Lisbon"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "automacoespme"
  },
  "tags": []
}