{
 "name": "Overdue invoice reminders from Google Sheets + Gmail (AutomateRecipes)",
 "nodes": [
  {
   "parameters": {
    "rule": {
     "interval": [
      {
       "field": "cronExpression",
       "expression": "0 9 * * 1-5"
      }
     ]
    }
   },
   "id": "cc862927-fb68-51cf-ad22-6b90104c2c91",
   "name": "Every weekday 9:00",
   "type": "n8n-nodes-base.scheduleTrigger",
   "typeVersion": 1.2,
   "position": [
    0,
    0
   ]
  },
  {
   "parameters": {},
   "id": "17ef7b1a-39a9-5cd2-a758-16f72393456d",
   "name": "Run manually (test)",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    200
   ]
  },
  {
   "parameters": {
    "documentId": {
     "__rl": true,
     "mode": "url",
     "value": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit"
    },
    "sheetName": {
     "__rl": true,
     "mode": "name",
     "value": "Invoices"
    },
    "options": {}
   },
   "id": "097f416e-ad68-581e-9c3e-182e11fefd61",
   "name": "Google Sheets: read invoices",
   "type": "n8n-nodes-base.googleSheets",
   "typeVersion": 4.5,
   "position": [
    220,
    100
   ]
  },
  {
   "parameters": {
    "jsCode": "// Sheet columns: Invoice, Client, Email, Amount, DueDate (YYYY-MM-DD), Status\nconst rows=$input.all().map(i=>i.json);\nconst sample=[{Invoice:'INV-101',Client:'Acme',Email:'billing@example.com',Amount:'1200',DueDate:'2026-01-01',Status:'Unpaid'},{Invoice:'INV-102',Client:'Beta',Email:'pay@example.org',Amount:'300',DueDate:'2999-01-01',Status:'Unpaid'},{Invoice:'INV-103',Client:'Gamma',Email:'g@example.net',Amount:'90',DueDate:'2026-01-01',Status:'Paid'}];\nconst data=rows.some(r=>r.Invoice)?rows:sample; // sample only when the sheet node is skipped in a test\nconst today=new Date();today.setHours(0,0,0,0);\nreturn data.filter(r=>String(r.Status).toLowerCase()!=='paid'&&r.Email&&new Date(r.DueDate)<today).map(r=>({json:{...r,daysLate:Math.floor((today-new Date(r.DueDate))/864e5)}}));"
   },
   "id": "71ef7831-218e-58de-800a-fe2c209cc864",
   "name": "Pick overdue unpaid",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    440,
    100
   ]
  },
  {
   "parameters": {
    "sendTo": "={{ $json.Email }}",
    "subject": "=Friendly reminder: invoice {{ $json.Invoice }} is {{ $json.daysLate }} days overdue",
    "emailType": "text",
    "message": "=Hi {{ $json.Client }},\n\nA quick reminder that invoice {{ $json.Invoice }} for {{ $json.Amount }} was due on {{ $json.DueDate }}. If you've already paid, please ignore this.\n\nThank you!",
    "options": {}
   },
   "id": "a482dd53-64c6-5d0c-b29e-16dea79c7d87",
   "name": "Gmail: send reminder",
   "type": "n8n-nodes-base.gmail",
   "typeVersion": 2.1,
   "position": [
    660,
    100
   ]
  }
 ],
 "connections": {
  "Every weekday 9:00": {
   "main": [
    [
     {
      "node": "Google Sheets: read invoices",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Run manually (test)": {
   "main": [
    [
     {
      "node": "Google Sheets: read invoices",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Google Sheets: read invoices": {
   "main": [
    [
     {
      "node": "Pick overdue unpaid",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Pick overdue unpaid": {
   "main": [
    [
     {
      "node": "Gmail: send reminder",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "active": false,
 "settings": {
  "executionOrder": "v1"
 },
 "pinData": {}
}