{
  "name": "Expense Log",
  "version": 1,
  "nodes": [
    {
      "localID": 0,
      "typeID": "trigger.keyboard_shortcut",
      "customName": "Hotkey",
      "isDisabled": false,
      "x": 60.0,
      "y": 110.0,
      "config": {
        "shortcut": "ctrl+option+e",
        "consumeKey": true,
        "customArgs": {}
      }
    },
    {
      "localID": 1,
      "typeID": "action.form",
      "customName": "Log an expense",
      "isDisabled": false,
      "x": 380.0,
      "y": 110.0,
      "config": {
        "fields": [
          {
            "id": "14cb0d6d-ec27-4c47-ac8c-aecf87858367",
            "name": "amount",
            "label": "Amount",
            "type": "number",
            "required": true,
            "placeholder": "12.50",
            "validation": {
              "min": 0.01
            }
          },
          {
            "id": "2bca778d-8de6-47b6-b576-9c3481d32c06",
            "name": "category",
            "label": "Category",
            "type": "select",
            "required": true,
            "options": [
              "Groceries",
              "Eating out",
              "Transport",
              "Household",
              "Work",
              "Other"
            ],
            "defaultValue": "Groceries"
          },
          {
            "id": "643a5850-1de8-49ac-a094-c405e2bb71c8",
            "name": "note",
            "label": "Note",
            "type": "text",
            "required": false,
            "placeholder": "What was it?"
          },
          {
            "id": "7793f01d-db6d-4fc9-8bc3-5cba434f405e",
            "name": "receipt",
            "label": "Receipt",
            "type": "file",
            "required": false,
            "helpText": "Optional. The path is stored, not the file."
          }
        ],
        "formTitle": "Log an expense",
        "formDescription": "",
        "submitLabel": "Save",
        "rememberValues": "never",
        "customArgs": {}
      }
    },
    {
      "localID": 2,
      "typeID": "action.database_insert",
      "customName": "Save expense",
      "isDisabled": false,
      "x": 700.0,
      "y": 110.0,
      "config": {
        "databaseId": "SMOKE_DB",
        "databaseName": "SMOKE_DB",
        "table": "expenses",
        "fields": [
          {
            "column": "amount",
            "value": "{{amount}}"
          },
          {
            "column": "category",
            "value": "{{category}}"
          },
          {
            "column": "note",
            "value": "{{note}}"
          },
          {
            "column": "receipt",
            "value": "{{receipt}}"
          }
        ],
        "autoCreate": true,
        "conflict": "abort"
      }
    },
    {
      "localID": 3,
      "typeID": "action.notification",
      "customName": "Saved",
      "isDisabled": false,
      "x": 1020.0,
      "y": 110.0,
      "config": {
        "title": "Expense saved",
        "body": "{{amount}} in {{category}}, row {{rowId}}.",
        "actionURL": "",
        "forceDisplay": false
      }
    },
    {
      "localID": 4,
      "typeID": "trigger.schedule",
      "customName": "Every morning",
      "isDisabled": false,
      "x": 60.0,
      "y": 400.0,
      "config": {
        "mode": "calendar",
        "weekdays": "mon,tue,wed,thu,fri,sat,sun",
        "time": "09:00",
        "customArgs": {}
      }
    },
    {
      "localID": 5,
      "typeID": "action.database_sql",
      "customName": "Last month by category",
      "isDisabled": false,
      "x": 380.0,
      "y": 400.0,
      "config": {
        "databaseId": "SMOKE_DB",
        "databaseName": "SMOKE_DB",
        "sql": "-- Runs every morning; returns a row only on the 1st.\nSELECT month,\n       SUM(n) AS entries,\n       printf('%.2f', SUM(spent)) AS total,\n       group_concat('<tr><td>' || category || '</td><td>' || n || '</td><td>'\n                    || printf('%.2f', spent) || '</td></tr>', '') AS table_rows\nFROM (\n  SELECT strftime('%Y-%m', created_at, 'localtime') AS month,\n         category, COUNT(*) AS n, SUM(amount) AS spent\n  FROM expenses\n  WHERE strftime('%d', {{scheduledFor}}, 'localtime') = '01'\n    AND strftime('%Y-%m', created_at, 'localtime')\n      = strftime('%Y-%m', {{scheduledFor}}, 'localtime', 'start of month', '-1 month')\n  GROUP BY category\n  ORDER BY spent DESC\n)\nGROUP BY month"
      }
    },
    {
      "localID": 6,
      "typeID": "condition.compare",
      "customName": "The 1st?",
      "isDisabled": false,
      "x": 700.0,
      "y": 400.0,
      "config": {
        "rules": [
          {
            "field": "count",
            "operator": "greater_than",
            "value": "0",
            "negate": false
          }
        ],
        "logic": "and",
        "caseInsensitive": false
      }
    },
    {
      "localID": 7,
      "typeID": "transformer.html_template",
      "customName": "Report page",
      "isDisabled": false,
      "x": 1020.0,
      "y": 400.0,
      "config": {
        "html": "<!doctype html>\n<html>\n<head>\n<style>\n  body { font: 14px -apple-system; margin: 28px; color: #1d1d1f; }\n  h1 { font-size: 20px; margin: 0 0 4px; }\n  p { color: #6e6e73; margin: 0 0 18px; }\n  table { border-collapse: collapse; width: 100%; }\n  th, td { padding: 7px 8px; border-bottom: 1px solid #e5e5ea; text-align: left; }\n  th:not(:first-child), td:not(:first-child) { text-align: right; }\n  tfoot td { font-weight: 600; border-bottom: 0; }\n  button { margin-top: 20px; }\n</style>\n</head>\n<body>\n  <h1>Expenses for {{records.0.month}}</h1>\n  <p>{{records.0.entries}} entries</p>\n  <table>\n    <thead><tr><th>Category</th><th>Entries</th><th>Spent</th></tr></thead>\n    <tbody>{{records.0.table_rows}}</tbody>\n    <tfoot><tr><td>Total</td><td></td><td>{{records.0.total}}</td></tr></tfoot>\n  </table>\n  <button onclick=\"watchflows.dismiss()\">Done</button>\n</body>\n</html>",
        "outputKey": "html"
      }
    },
    {
      "localID": 8,
      "typeID": "action.html_view",
      "customName": "Show report",
      "isDisabled": false,
      "x": 1340.0,
      "y": 400.0,
      "config": {
        "html": "{{html}}",
        "title": "Expenses",
        "windowMode": "window",
        "chrome": "titleBar",
        "width": 520,
        "height": 460,
        "closeIsDismiss": true,
        "timeoutMinutes": 240
      }
    },
    {
      "localID": 9,
      "typeID": "note",
      "customName": "Log section",
      "isDisabled": false,
      "x": 30.0,
      "y": 50.0,
      "config": {
        "backdrop": true,
        "color": "#81C784",
        "text": "Log an expense",
        "_width": 1250.0,
        "_height": 230.0
      }
    },
    {
      "localID": 10,
      "typeID": "note",
      "customName": "Report section",
      "isDisabled": false,
      "x": 30.0,
      "y": 340.0,
      "config": {
        "backdrop": true,
        "color": "#64B5F6",
        "text": "Monthly report",
        "_width": 1570.0,
        "_height": 230.0
      }
    }
  ],
  "connections": [
    {
      "sourceLocalID": 0,
      "sourcePortID": "outlet_output",
      "targetLocalID": 1,
      "targetPortID": "inlet_input"
    },
    {
      "sourceLocalID": 1,
      "sourcePortID": "outlet_output",
      "targetLocalID": 2,
      "targetPortID": "inlet_input"
    },
    {
      "sourceLocalID": 2,
      "sourcePortID": "outlet_output",
      "targetLocalID": 3,
      "targetPortID": "inlet_input"
    },
    {
      "sourceLocalID": 4,
      "sourcePortID": "outlet_output",
      "targetLocalID": 5,
      "targetPortID": "inlet_input"
    },
    {
      "sourceLocalID": 5,
      "sourcePortID": "outlet_output",
      "targetLocalID": 6,
      "targetPortID": "inlet_input"
    },
    {
      "sourceLocalID": 6,
      "sourcePortID": "outlet_yes",
      "targetLocalID": 7,
      "targetPortID": "inlet_input"
    },
    {
      "sourceLocalID": 7,
      "sourcePortID": "outlet_output",
      "targetLocalID": 8,
      "targetPortID": "inlet_input"
    }
  ],
  "background": {
    "type": "image",
    "ref": {
      "type": "bundled",
      "id": "steel"
    },
    "fit": "cover"
  }
}
