{
  "name": "04 · Daily Ops Digest — nightly owner report",
  "nodes": [
    {
      "parameters": {
        "content": "# 04 · Daily Ops Digest\n\n**The problem:** most owners aren't standing in the store. They find out about a bad day the next morning, too late to react.\n\n**What this does:** every night after closing, one message to the owner's phone: today's sales vs target, top movers, cash position, what needs a decision tomorrow.\n\n**Why it sells:** it's the workflow an owner *actually reads*, and it makes every other automation visible.\n\nBuilt by **Maui Tech Hub** · mauitechhub.com/workflows",
        "height": 420,
        "width": 400,
        "color": 7
      },
      "id": "c56483f1-30bb-40c0-a00f-6e20f336de47",
      "name": "NOTE",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -420,
        -60
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 23 * * *"
            }
          ]
        }
      },
      "id": "0ad8cefb-d9f0-4548-8b20-95ce9586f9e8",
      "name": "Nightly 11pm",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        100
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "YOUR_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "DailySales",
          "mode": "name"
        },
        "options": {}
      },
      "id": "e2a7eef2-78dc-4909-a987-e239b6a6b325",
      "name": "Read Daily Numbers",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        240,
        100
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Turn the day's rows into a message an owner reads in 20 seconds.\nconst CURRENCY = 'KD';        // <- change to '$', '£', '€', 'AED' ...\nconst rows = $input.all().map(i => i.json);\nconst today = new Date().toISOString().slice(0,10);\nconst day = rows.filter(r => String(r.Date ?? r.date ?? '').startsWith(today));\nconst pick = day.length ? day : rows.slice(-20);\nconst num = (r,k) => Number(r[k] ?? r[k.toLowerCase()] ?? 0);\nconst sales = pick.reduce((s,r)=>s+num(r,'Sales'),0);\nconst target = pick.reduce((s,r)=>s+num(r,'Target'),0);\nconst cash = pick.reduce((s,r)=>s+num(r,'Cash'),0);\nconst card = pick.reduce((s,r)=>s+num(r,'Card'),0);\nconst footfall = pick.reduce((s,r)=>s+num(r,'Footfall'),0);\nconst pct = target ? ((sales/target-1)*100) : 0;\nconst arrow = sales>=target ? '▲' : '▼';\nlet m = '*DAILY DIGEST — '+today+'*\\n\\n';\nm += `*Sales:  ${CURRENCY} ${sales.toFixed(3)}*\\n`;\nif (target) m += `Target: ${CURRENCY} ${target.toFixed(3)}  ${arrow} ${pct.toFixed(1)}%\\n`;\nm += `\\nCash ${CURRENCY} ${cash.toFixed(3)} · Card ${CURRENCY} ${card.toFixed(3)}\\n`;\nif (footfall) m += `Footfall ${footfall} · Avg basket ${CURRENCY} `\n    + (footfall? (sales/footfall).toFixed(3):'0') + '\\n';\nif (target && pct < -10) m += '\\n⚠️ *Under target. Check staffing + stockouts tomorrow.*';\nif (target && pct > 10)  m += '\\n✅ *Strong day. Note what worked.*';\nreturn [{ json: { message: m, sales: +sales.toFixed(3),\n  target: +target.toFixed(3), vs_target_pct: +pct.toFixed(1) } }];"
      },
      "id": "d290bcb8-21c2-47bd-8eff-01fdaea80101",
      "name": "Compose Digest",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        100
      ]
    },
    {
      "parameters": {
        "chatId": "YOUR_OWNER_CHAT_ID",
        "text": "={{ $json.message }}",
        "additionalFields": {}
      },
      "id": "f236f3a2-d53f-4c78-83ce-cdfafbcb75cd",
      "name": "Send to Owner",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        760,
        100
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "DigestLog",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        },
        "options": {}
      },
      "id": "9499f19c-dafa-491c-86e6-37ef29c2dace",
      "name": "Keep History",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        760,
        320
      ]
    }
  ],
  "connections": {
    "Nightly 11pm": {
      "main": [
        [
          {
            "node": "Read Daily Numbers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Daily Numbers": {
      "main": [
        [
          {
            "node": "Compose Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose Digest": {
      "main": [
        [
          {
            "node": "Send to Owner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to Owner": {
      "main": [
        [
          {
            "node": "Keep History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "instanceId": "mauitechhub-retail-ops"
  }
}