{
  "name": "Safock template: Overdue invoice reminders",
  "nodes": [
    {
      "parameters": {
        "content": "## Overdue invoice reminders\nBy Safock (safock.com). Free to use and adapt.\n\n1. Keep a Google Sheet tab named **Invoices** with columns: invoice_number, client_name, client_email, amount, currency, due_date (YYYY-MM-DD), status, last_reminder.\n2. Connect Google Sheets and Gmail, and replace REPLACE_WITH_SHEET_ID in both sheet nodes.\n3. Runs every weekday at 9:00. Unpaid invoices past their due date get a polite reminder at most once every 7 days, and last_reminder is written back so nobody is chased twice.\n\nEdit the email text in **Send reminder** before switching the workflow on.",
        "height": 360,
        "width": 460
      },
      "id": "51e3cdf6-4c42-4dd0-a5be-2ad349bd5e86",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -500,
        -140
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1-5"
            }
          ]
        }
      },
      "id": "b901f00c-9be0-47b6-8f13-a504119724e3",
      "name": "Weekdays at 9:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Invoices",
          "mode": "name"
        },
        "options": {}
      },
      "id": "329ee843-97d0-450b-8e4f-5a73f2097dce",
      "name": "Read invoices",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Keep unpaid invoices that are past due and have not had a reminder in 7 days.\nconst DAY = 24 * 60 * 60 * 1000;\nconst today = new Date();\nreturn $input.all().filter((item) => {\n  const row = item.json;\n  if (String(row.status || '').trim().toLowerCase() === 'paid') return false;\n  const due = new Date(row.due_date);\n  if (Number.isNaN(due.getTime()) || due >= today) return false;\n  if (!row.client_email) return false;\n  const last = row.last_reminder ? new Date(row.last_reminder) : null;\n  return !last || Number.isNaN(last.getTime()) || today - last >= 7 * DAY;\n});"
      },
      "id": "01a24daa-1d63-411e-b35c-f1e26784d868",
      "name": "Find overdue",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.client_email }}",
        "subject": "=Reminder: invoice {{ $json.invoice_number }} is past due",
        "emailType": "text",
        "message": "=Hi {{ $json.client_name }},\n\nA quick reminder that invoice {{ $json.invoice_number }} for {{ $json.currency }} {{ $json.amount }} was due on {{ $json.due_date }}.\n\nIf it is already on its way, thank you and please ignore this note. If anything is holding it up, just reply and we will sort it out.\n\nBest regards",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "17ffecff-6895-4a50-845c-971324e43712",
      "name": "Send reminder",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        660,
        0
      ],
      "webhookId": "7d11674c-2765-4ec8-871e-009117defe97"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Invoices",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "invoice_number": "={{ $('Find overdue').item.json.invoice_number }}",
            "last_reminder": "={{ $today.toFormat('yyyy-LL-dd') }}"
          },
          "matchingColumns": [
            "invoice_number"
          ],
          "schema": []
        },
        "options": {}
      },
      "id": "91c1e445-7b18-4153-947c-cf81c31a284a",
      "name": "Log reminder date",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        880,
        0
      ]
    }
  ],
  "connections": {
    "Weekdays at 9:00": {
      "main": [
        [
          {
            "node": "Read invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read invoices": {
      "main": [
        [
          {
            "node": "Find overdue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find overdue": {
      "main": [
        [
          {
            "node": "Send reminder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send reminder": {
      "main": [
        [
          {
            "node": "Log reminder date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
