{
  "name": "Invoice Payment Reminder — Auto WhatsApp + Email",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "id": "f1b2c3d4-0001-4000-8000-000000000001",
      "name": "Schedule — Setiap Hari Jam 9",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "=GANTI_DENGAN_SPREADSHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Invoices"
        },
        "filters": {
          "conditions": [
            {
              "id": "filter1",
              "leftValue": "={{ $json.status }}",
              "rightValue": "unpaid",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ]
        }
      },
      "id": "f1b2c3d4-0002-4000-8000-000000000002",
      "name": "Google Sheets — Ambil Invoice Belum Bayar",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Cek apakah sudah jatuh tempo\nconst items = $input.all();\nconst today = new Date();\nconst results = [];\n\nfor (const item of items) {\n  const dueDate = new Date(item.json.due_date);\n  const diffDays = Math.floor((today - dueDate) / (1000 * 60 * 60 * 24));\n\n  let reminder_type = null;\n  if (diffDays === 0) reminder_type = 'due_today';\n  else if (diffDays === 3) reminder_type = 'overdue_3days';\n  else if (diffDays === 7) reminder_type = 'overdue_7days';\n\n  if (reminder_type) {\n    results.push({\n      json: { ...item.json, reminder_type, days_overdue: diffDays }\n    });\n  }\n}\n\nreturn results;"
      },
      "id": "f1b2c3d4-0003-4000-8000-000000000003",
      "name": "Code — Filter Jatuh Tempo",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.client_email }}",
        "subject": "=Pengingat Invoice #{{ $json.invoice_no }} — {{ $json.reminder_type === \"due_today\" ? \"Jatuh Tempo Hari Ini\" : \"Sudah Lewat \" + $json.days_overdue + \" Hari\" }}",
        "message": "=Yth. {{ $json.client_name }},\n\nIni adalah pengingat untuk invoice #{{ $json.invoice_no }}:\n\nLayanan: {{ $json.service }}\nTotal: Rp {{ $json.amount }}\nJatuh Tempo: {{ $json.due_date }}\n\nMohon untuk segera melakukan pembayaran.\n\nTerima kasih,\n[NAMA_BISNIS_ANDA]"
      },
      "id": "f1b2c3d4-0004-4000-8000-000000000004",
      "name": "Email — Kirim Pengingat",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1000,
        300
      ]
    }
  ],
  "connections": {
    "Schedule — Setiap Hari Jam 9": {
      "main": [
        [
          {
            "node": "Google Sheets — Ambil Invoice Belum Bayar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets — Ambil Invoice Belum Bayar": {
      "main": [
        [
          {
            "node": "Code — Filter Jatuh Tempo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code — Filter Jatuh Tempo": {
      "main": [
        [
          {
            "node": "Email — Kirim Pengingat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateId": "mcsyauqi-invoice-reminder-06"
  }
}