{
  "name": "FlowPantry - Chase missing W-9s and build your 1099 list before January (Google Sheets + email)",
  "nodes": [
    {
      "id": "345e2f25-1299-4239-882f-8adedfe83f49",
      "name": "Every Monday 9 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "weeksInterval": 1,
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 9
            }
          ]
        }
      }
    },
    {
      "id": "70bc2b91-1528-44bc-a283-f8ac7364f05e",
      "name": "Your settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        300
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "f494e233-2938-4b76-a89b-c200425e6645",
              "name": "BUSINESS_NAME",
              "value": "YOUR BUSINESS",
              "type": "string"
            },
            {
              "id": "66cc16c8-4689-4800-9a20-3d7c0b9aed7a",
              "name": "OWNER_EMAIL",
              "value": "you@yourdomain.com",
              "type": "string"
            },
            {
              "id": "5aecb034-1a7a-4215-97b0-4617d1cee8ab",
              "name": "FROM_EMAIL",
              "value": "YOUR BUSINESS <billing@yourdomain.com>",
              "type": "string"
            },
            {
              "id": "6584927f-28b4-42c3-930a-aae96241db18",
              "name": "W9_UPLOAD_URL",
              "value": "https://YOUR-SECURE-UPLOAD-LINK",
              "type": "string"
            },
            {
              "id": "7c6510f1-6b49-4831-b24f-9dd12457b5cc",
              "name": "TAX_YEAR",
              "value": 2026,
              "type": "number"
            },
            {
              "id": "f6d42bde-0ef5-416d-b1fd-f815165c9d90",
              "name": "THRESHOLD",
              "value": 2000,
              "type": "number"
            },
            {
              "id": "a7fade2c-a0d0-4b31-b799-1e6a4dabcb39",
              "name": "CHASE_FROM",
              "value": 0,
              "type": "number"
            },
            {
              "id": "f9a1a340-788d-47ee-ae77-386822b3de07",
              "name": "REMIND_EVERY_DAYS",
              "value": 7,
              "type": "number"
            },
            {
              "id": "510d60e4-1c87-45bb-b4b2-daa23a78e74c",
              "name": "MAX_REMINDERS",
              "value": 4,
              "type": "number"
            },
            {
              "id": "290db97e-f570-4bc8-9236-3cf28683a94c",
              "name": "EXCLUDE_METHODS",
              "value": "card,credit,debit,paypal,venmo,stripe,square",
              "type": "string"
            },
            {
              "id": "f223fdc7-1cc1-48ee-8b93-e0a652d6005a",
              "name": "FILING_DEADLINE",
              "value": "2027-02-01",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "include": "all",
        "options": {}
      }
    },
    {
      "id": "960a43bb-511a-49ba-953b-755aaddfd55d",
      "name": "Read vendors",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        480,
        300
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "filtersUI": {},
        "options": {}
      },
      "executeOnce": true
    },
    {
      "id": "02aa1be8-c17b-4e79-b1d2-458fb4d1fcaf",
      "name": "Read payments",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        720,
        300
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "filtersUI": {},
        "options": {}
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "163ae941-f6d3-47c3-befe-5311972d8bc3",
      "name": "Who needs a W-9",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        300
      ],
      "parameters": {
        "jsCode": "// Decides, for every vendor on your list, what happens this week. Runs once for all items.\n// Never reads or stores tax ID numbers: it only tracks whether a W-9 is on file.\nconst s = $('Your settings').first().json;\nconst today = (typeof $now !== 'undefined' && $now && $now.toISODate) ? $now.toISODate() : new Date().toISOString().slice(0, 10);\nconst year = Number(s.TAX_YEAR) || Number(today.slice(0, 4));\nconst threshold = Number(s.THRESHOLD ?? 2000);\nconst chaseFrom = Number(s.CHASE_FROM ?? 0);\nconst every = Number(s.REMIND_EVERY_DAYS ?? 7);\nconst maxRem = Number(s.MAX_REMINDERS ?? 4);\nconst excl = String(s.EXCLUDE_METHODS || '').toLowerCase().split(',').map(x => x.trim()).filter(Boolean);\nconst deadline = String(s.FILING_DEADLINE || '');\n\nconst norm = v => String(v ?? '').trim();\nconst key = v => norm(v).toLowerCase().replace(/\\s+/g, ' ');\nconst get = (row, name) => { const want = key(name); for (const k of Object.keys(row || {})) if (key(k) === want) return row[k]; return ''; };\nconst yes = v => /^(y|yes|true|x|✓|✔|1|done|received|on file)$/i.test(norm(v));\nconst money = v => { if (typeof v === 'number') return v; const t = norm(v).replace(/[$,\\s]/g, ''); const neg = /^\\(.*\\)$/.test(t); const n = parseFloat(t.replace(/[()]/g, '')); return isNaN(n) ? 0 : (neg ? -n : n); };\nfunction toISO(v) {\n  if (typeof v === 'number' && v > 20000 && v < 80000) { const d = new Date(Date.UTC(1899, 11, 30) + v * 86400000); return d.toISOString().slice(0, 10); } // Sheets serial\n  const t = norm(v); let m;\n  if ((m = t.match(/^(\\d{4})-(\\d{1,2})-(\\d{1,2})/))) return `${m[1]}-${m[2].padStart(2, '0')}-${m[3].padStart(2, '0')}`;\n  if ((m = t.match(/^(\\d{1,2})\\/(\\d{1,2})\\/(\\d{2,4})/))) { const y = m[3].length === 2 ? '20' + m[3] : m[3]; return `${y}-${m[1].padStart(2, '0')}-${m[2].padStart(2, '0')}`; }\n  return '';\n}\nconst days = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(a + 'T00:00:00Z')) / 86400000);\nconst round2 = n => Math.round(n * 100) / 100;\n\n// 1) Total this year's payments per vendor, split into \"counts toward 1099-NEC\" and \"card / payment app\" (1099-K side).\nconst totals = {}; const unknown = {};\nfor (const it of $input.all()) {\n  const p = it.json || {};\n  const v = key(get(p, 'Vendor')); if (!v) continue;\n  const d = toISO(get(p, 'Date')); if (!d || Number(d.slice(0, 4)) !== year) continue;\n  const amt = money(get(p, 'Amount')); if (!amt) continue;\n  const method = key(get(p, 'Method'));\n  const t = (totals[v] = totals[v] || { reportable: 0, excluded: 0, count: 0 });\n  if (method && excl.some(x => method.includes(x))) t.excluded += amt; else t.reportable += amt;\n  t.count++;\n}\n\n// 2) Walk the vendor list.\nconst out = []; const seen = new Set();\nfor (const it of $('Read vendors').all()) {\n  const r = it.json || {};\n  const name = norm(get(r, 'Vendor')); if (!name) continue;\n  const k = key(name); seen.add(k);\n  const email = norm(get(r, 'Email'));\n  const w9 = yes(get(r, 'W-9 on file'));\n  const cls = key(get(r, 'Tax classification'));\n  const legal = yes(get(r, 'Legal services'));\n  const skip = yes(get(r, 'Skip'));\n  const sent = Math.max(0, parseInt(norm(get(r, 'Reminders sent')) || '0', 10) || 0);\n  const last = toISO(get(r, 'Last W-9 reminder'));\n  const t = totals[k];\n  const sheetYtd = norm(get(r, 'Paid YTD'));\n  const reportable = round2(t ? t.reportable : money(sheetYtd));\n  const excluded = round2(t ? t.excluded : 0);\n  const source = t ? 'Payments tab' : (sheetYtd ? 'Paid YTD column' : 'none');\n  const corp = /\\b(c|s)[ -]?corp(oration)?\\b|\\bcorporation\\b|\\bllc\\s*[-–:(]?\\s*[cs]\\)?$/.test(cls);\n  let action, reason;\n  if (skip) { action = 'skip'; reason = 'Marked Skip'; }\n  else if (w9) {\n    if (corp && !legal) { action = 'no_1099_corp'; reason = 'W-9 says corporation; payments to corporations generally are not reported (legal services are the exception)'; }\n    else if (reportable >= threshold) { action = '1099_needed'; reason = `Paid $${reportable.toFixed(2)} (non-card) in ${year}, at or over $${threshold}`; }\n    else { action = 'under_threshold'; reason = `Paid $${reportable.toFixed(2)} (non-card) in ${year}, under $${threshold}`; }\n  }\n  else if (reportable < chaseFrom) { action = 'not_yet'; reason = `Paid $${reportable.toFixed(2)}, under your CHASE_FROM of $${chaseFrom}`; }\n  else if (!email) { action = 'no_email'; reason = 'No W-9 and no email address on the sheet'; }\n  else if (sent >= maxRem) { action = 'escalate'; reason = `No W-9 after ${sent} reminders`; }\n  else if (last && days(last, today) < every) { action = 'wait'; reason = `Reminded ${days(last, today)} day(s) ago`; }\n  else { action = 'remind'; reason = sent ? `Reminder ${sent + 1} of ${maxRem}` : 'First request'; }\n\n  const n = sent + 1;\n  const biz = s.BUSINESS_NAME || 'our business';\n  const subject = sent ? `Reminder: W-9 needed for ${biz} (${n} of ${maxRem})` : `W-9 request from ${biz}`;\n  const text = [\n    `Hi ${name},`, '',\n    `${sent ? 'Quick reminder: we' : 'We'} still need a current Form W-9 from you for our ${year} records${reportable >= threshold ? ' and 1099 reporting' : ''}.`, '',\n    `1. Blank form from the IRS: https://www.irs.gov/pub/irs-pdf/fw9.pdf`,\n    `2. Upload the signed form here: ${s.W9_UPLOAD_URL}`, '',\n    'Please do not email your Social Security number or EIN, and please do not reply with the form attached. Use the upload link instead.',\n    'If you already sent it, just reply \"sent\" and we will update our records.', '',\n    `Thanks,`, biz,\n  ].join('\\n');\n  out.push({ json: {\n    row_number: r.row_number, Vendor: name, Email: email, action, reason,\n    urgent: !w9 && !skip && reportable >= threshold,\n    reportable_ytd: reportable, card_app_ytd: excluded, payments_source: source,\n    reminders_sent: sent, next_reminder_count: n, last_reminder: last, today, tax_year: year,\n    email_subject: subject, email_text: text,\n  } });\n}\n// 3) People you paid who aren't on the vendor list at all.\nfor (const [k, t] of Object.entries(totals)) if (!seen.has(k) && t.reportable > 0) unknown[k] = round2(t.reportable);\nif (out.length) out[0].json.unlisted_payees = unknown;\nelse if (Object.keys(unknown).length) out.push({ json: { action: 'none', unlisted_payees: unknown, today, tax_year: year } });\nreturn out;"
      }
    },
    {
      "id": "67fb32f3-adaa-4cdc-90bf-16193cf88973",
      "name": "Send a reminder?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1200,
        200
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "012d3f5d-ce7c-4733-b657-10118278c153",
              "leftValue": "={{ $json.action }}",
              "rightValue": "remind",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "d78ec74b-17b3-415c-a65b-536e2d1d7c91",
      "name": "Email vendor: W-9 request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        100
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.resend.com/emails",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ from: $('Your settings').first().json.FROM_EMAIL, to: $json.Email, subject: $json.email_subject, text: $json.email_text, reply_to: $('Your settings').first().json.OWNER_EMAIL }) }}",
        "options": {}
      }
    },
    {
      "id": "8feb4ad9-6f9c-437f-a2ba-dbb947824a3e",
      "name": "Mark reminder sent",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1680,
        100
      ],
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('Send a reminder?').item.json.row_number }}",
            "Reminders sent": "={{ $('Send a reminder?').item.json.next_reminder_count }}",
            "Last W-9 reminder": "={{ $('Send a reminder?').item.json.today }}"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            },
            {
              "id": "Reminders sent",
              "displayName": "Reminders sent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Last W-9 reminder",
              "displayName": "Last W-9 reminder",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "ce67caea-318e-472d-ac92-0141f3c19c74",
      "name": "Build weekly digest",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1200,
        460
      ],
      "parameters": {
        "jsCode": "// One weekly summary email for you. Returns nothing when there's nothing to report.\nconst s = $('Your settings').first().json;\nconst all = $input.all().map(i => i.json);\nconst first = all[0] || {};\nconst today = first.today || new Date().toISOString().slice(0, 10);\nconst year = first.tax_year;\nconst deadline = String(s.FILING_DEADLINE || '');\nconst daysLeft = deadline ? Math.round((Date.parse(deadline + 'T00:00:00Z') - Date.parse(today + 'T00:00:00Z')) / 86400000) : null;\nconst $$ = n => '$' + Number(n || 0).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });\nconst by = a => all.filter(v => v.action === a);\nconst urgent = all.filter(v => v.urgent);\nconst remind = by('remind'), waiting = by('wait'), esc = by('escalate'), noEmail = by('no_email');\nconst need = by('1099_needed');\nconst unlisted = Object.entries(first.unlisted_payees || {});\nconst T = $$(s.THRESHOLD).replace('.00', '');\nconst line = v => `- ${v.Vendor}: ${$$(v.reportable_ytd)} non-card in ${year}${v.card_app_ytd ? ` (+ ${$$(v.card_app_ytd)} by card/payment app, not counted)` : ''}${/^(1099_needed|under_threshold|no_1099_corp)$/.test(v.action) ? '' : '. ' + v.reason}`;\nconst sec = (h, list, f = line) => list.length ? [`${h} (${list.length})`, ...list.map(f), ''] : [];\nconst body = [\n  `W-9 / 1099 check for ${s.BUSINESS_NAME}, ${today}.`,\n  daysLeft !== null ? `${daysLeft} days until the 1099-NEC deadline (${deadline}): file with the IRS and give each contractor their copy.` : '',\n  '',\n  ...sec(`MISSING W-9, already at or over ${T}`, urgent),\n  ...sec('Out of reminders: call or text them', esc),\n  ...sec('No email on the sheet: add one or ask in person', noEmail),\n  ...sec('W-9 requests going out today', remind, v => `- ${v.Vendor} <${v.Email}>: ${v.reason}`),\n  ...sec('Waiting on a W-9 (reminded recently)', waiting),\n  ...sec(`Likely need a ${year} 1099-NEC (W-9 on file, at or over ${T})`, need),\n  ...(unlisted.length ? [`Paid but not on your vendor list (${unlisted.length})`, ...unlisted.map(([k, a]) => `- ${k}: ${$$(a)}`), ''] : []),\n  'Card and payment-app payments are left out: those belong on the processor\\'s Form 1099-K, not your 1099-NEC. Corporations are skipped unless you marked Legal services. Your CPA has the final say on who gets a 1099.',\n].filter((x, i, a) => !(x === '' && a[i - 1] === '')).join('\\n');\nconst anything = urgent.length + esc.length + noEmail.length + remind.length + waiting.length + need.length + unlisted.length;\nif (!anything) return [];\nconst needYou = new Set([...urgent, ...esc, ...noEmail].map(v => v.Vendor)).size;\nconst subj = `W-9 check: ${needYou} need you, ${remind.length} request(s) sent, ${need.length} likely 1099(s)`;\nreturn [{ json: { subject: subj, text: body } }];"
      }
    },
    {
      "id": "5b6f16f8-9f84-4529-ba7a-4284bd7f0479",
      "name": "Email me: W-9 digest",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        460
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.resend.com/emails",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ from: $('Your settings').first().json.FROM_EMAIL, to: $('Your settings').first().json.OWNER_EMAIL, subject: $json.subject, text: $json.text }) }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Every Monday 9 AM": {
      "main": [
        [
          {
            "node": "Your settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Your settings": {
      "main": [
        [
          {
            "node": "Read vendors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read vendors": {
      "main": [
        [
          {
            "node": "Read payments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read payments": {
      "main": [
        [
          {
            "node": "Who needs a W-9",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Who needs a W-9": {
      "main": [
        [
          {
            "node": "Send a reminder?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Build weekly digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a reminder?": {
      "main": [
        [
          {
            "node": "Email vendor: W-9 request",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Email vendor: W-9 request": {
      "main": [
        [
          {
            "node": "Mark reminder sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build weekly digest": {
      "main": [
        [
          {
            "node": "Email me: W-9 digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "versionId": "dc31b408-12b4-4684-8b7d-a9aad96472d8",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
