{
  "name": "Monthly Payslip Generator (WhatsApp & Email)",
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "589ca1e8-04b9-41eb-9cd1-c21d62e0d81a",
              "leftValue": "={{ $('Find “Staff Salary Receipts” Folder in Drive').item.json.id }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        144,
        240
      ],
      "id": "a227490c-c18c-4699-82d3-d4b8e7791f18",
      "name": "Check If Receipt Folder Exists"
    },
    {
      "parameters": {
        "inputDataFieldName": "={{ $('Extract PDF Binary Only').item.binary.Salary_slip }}",
        "name": "={{ $('Normalize Payroll Fields').item.json.name }}_{{ $('Normalize Payroll Fields').item.json.month }}.pdf",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        464,
        160
      ],
      "id": "c68ca57a-dd41-4980-b891-092c742f3061",
      "name": "Upload Receipt PDF (Existing Folder)",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Wt0oCw6BmieLWjfw",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "inputDataFieldName": "={{ $('Extract PDF Binary Only').item.binary.Salary_slip }}",
        "name": "={{ $('Normalize Payroll Fields').item.json.name }}_{{ $('Normalize Payroll Fields').item.json.month }}.pdf",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        576,
        320
      ],
      "id": "439ff7c5-cca4-4cdf-aed5-5426011cad36",
      "name": "Upload Receipt PDF (New Folder)",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Wt0oCw6BmieLWjfw",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={\n  \"ReceiptLink\": \"https://drive.google.com/file/d/{{$json.id}}/view\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        768,
        240
      ],
      "id": "4cc6c24c-cd71-43b6-a777-a96a142809ef",
      "name": "Generate Public Receipt Link"
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "queryString": "Staff Salary Receipts",
        "filter": {
          "driveId": {
            "__rl": true,
            "value": "My Drive",
            "mode": "list",
            "cachedResultName": "My Drive"
          },
          "whatToSearch": "folders"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -48,
        240
      ],
      "id": "747264e6-a559-4039-bc6e-4778be6ca156",
      "name": "Find “Staff Salary Receipts” Folder in Drive",
      "alwaysOutputData": true,
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Wt0oCw6BmieLWjfw",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "resource": "folder",
        "name": "Staff Salary Receipts",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        368,
        320
      ],
      "id": "29a3b9fc-e1d6-443a-b0ac-89a3b5c97054",
      "name": "Create “Staff Salary Receipts” Folder",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Wt0oCw6BmieLWjfw",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "months"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -656,
        -32
      ],
      "id": "3fbf48ba-f25c-49bd-8a66-c8437066fd11",
      "name": "Monthly Payroll Trigger"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1pHk9-GCQ6QqFu1eRoRz4gD1phFmDooHoNAlHYtGATSY",
          "mode": "list",
          "cachedResultName": "Automated Payroll Slip Sender"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Employees"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "status",
              "lookupValue": "Pending"
            },
            {
              "lookupColumn": "month",
              "lookupValue": "={{ $now.format('MMM-y') }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -464,
        -32
      ],
      "id": "ea3ea02c-7ee1-4277-9ea5-fd3210399d5d",
      "name": "Fetch Pending Payroll",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "GojUvCMDXbhY8HrB",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -272,
        -32
      ],
      "id": "8ff9f7ca-4a20-46a5-93d1-df23966d73d2",
      "name": "Process Employees One by One"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "079f48db-b174-44b3-a9cc-0241f7514636",
              "name": "row_number",
              "value": "={{ $json.row_number }}",
              "type": "number"
            },
            {
              "id": "f3c6dabe-add6-4c2a-996c-d45613a1ba24",
              "name": "employee_id",
              "value": "={{ $json.employee_id }}",
              "type": "number"
            },
            {
              "id": "0757813d-c60d-4b26-9c60-3830938274ce",
              "name": "name",
              "value": "={{ $json.name }}",
              "type": "string"
            },
            {
              "id": "66f6a9fe-6bea-4530-a7b5-a0418512c867",
              "name": "email",
              "value": "={{ $json.email }}",
              "type": "string"
            },
            {
              "id": "bf0ecb6b-0189-4182-abc3-f0ed675ff2e2",
              "name": "phone",
              "value": "={{ $json.phone }}",
              "type": "number"
            },
            {
              "id": "8baef260-93c3-4e3f-8e7f-7b0ec69db621",
              "name": "month",
              "value": "={{ $json.month }}",
              "type": "string"
            },
            {
              "id": "79051088-3ea2-4e99-9114-7a9854e3fb27",
              "name": "working_days",
              "value": "={{ $json.working_days }}",
              "type": "number"
            },
            {
              "id": "f4498049-fd6c-453d-a5c1-095c15aa03e2",
              "name": "present_days",
              "value": "={{ $json.present_days }}",
              "type": "number"
            },
            {
              "id": "7c971179-24a4-451d-a09a-389139eb6ee9",
              "name": "Days Off",
              "value": "={{ $json[\"Days Off\"] }}",
              "type": "number"
            },
            {
              "id": "ae580f2b-430b-4a7a-8e50-746b95250a39",
              "name": "Holiday Days",
              "value": "={{ $json[\"Holiday Days\"] }}",
              "type": "number"
            },
            {
              "id": "9633953f-5c6d-42d2-8c14-132ec3f30302",
              "name": "paid_leave",
              "value": "={{ $json.paid_leave }}",
              "type": "number"
            },
            {
              "id": "77811709-04ce-4470-8e6a-dfeb0dee4b97",
              "name": "unpaid_leave",
              "value": "={{ $json.unpaid_leave }}",
              "type": "number"
            },
            {
              "id": "952558c1-f456-47e9-b41a-006e4ca4bf42",
              "name": "salary_per_day",
              "value": "={{ $json.salary_per_day }}",
              "type": "number"
            },
            {
              "id": "c77368ac-fb66-43da-b1aa-c01854626570",
              "name": "basic",
              "value": "={{ $json.basic }}",
              "type": "number"
            },
            {
              "id": "a1dbfee5-cf9a-48ad-89fe-abb360b800de",
              "name": "allowance",
              "value": "={{ $json.allowance }}",
              "type": "number"
            },
            {
              "id": "240e1382-bf4f-441c-8f31-4131489004c0",
              "name": "leave_payout",
              "value": "={{ $json.leave_payout }}",
              "type": "number"
            },
            {
              "id": "2d1d4cc1-46c6-42c2-8fb1-a35a049f127e",
              "name": "leave_deduction",
              "value": "={{ $json.leave_deduction }}",
              "type": "number"
            },
            {
              "id": "c5b82205-b469-45bc-8bf9-5beb0fd07cc3",
              "name": "payroll_tax",
              "value": "={{ $json.payroll_tax }}",
              "type": "number"
            },
            {
              "id": "1aa8f890-b6b3-46d2-9956-73c3fa1d7f72",
              "name": "net_pay",
              "value": "={{ $json.net_pay }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -64,
        -16
      ],
      "id": "25ca8e96-6044-4eee-bd5c-29da39d7c59e",
      "name": "Normalize Payroll Fields"
    },
    {
      "parameters": {
        "jsCode": "return items.map(item => {\n  const d = item.json;\n\n  const html = `\n<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<title>Salary Slip - ${d.month}</title>\n\n<style>\n  body {\n    font-family: Arial, Helvetica, sans-serif;\n    background: #ffffff;\n    padding: 30px;\n    color: #333;\n  }\n  .container {\n    max-width: 800px;\n    margin: auto;\n  }\n  .header {\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    border-bottom: 2px solid #e5e7eb;\n    padding-bottom: 15px;\n  }\n  .company {\n    font-size: 14px;\n    line-height: 1.4;\n  }\n  .net-pay {\n    background: #e8f5e9;\n    padding: 15px 20px;\n    border-radius: 8px;\n    font-size: 20px;\n    font-weight: bold;\n    color: #2e7d32;\n  }\n  h2 {\n    margin: 25px 0 10px;\n  }\n  table {\n    width: 100%;\n    border-collapse: collapse;\n    margin-top: 15px;\n    font-size: 14px;\n  }\n  td, th {\n    padding: 8px 10px;\n    border: 1px solid #e5e7eb;\n  }\n  th {\n    background: #f3f4f6;\n    text-align: left;\n  }\n  .section {\n    margin-top: 25px;\n  }\n  .summary {\n    background: #f0fdf4;\n    border: 2px dashed #81c784;\n    padding: 15px;\n    margin-top: 20px;\n    font-weight: bold;\n  }\n  .footer {\n    margin-top: 30px;\n    font-size: 12px;\n    color: #666;\n  }\n</style>\n</head>\n\n<body>\n<div class=\"container\">\n\n  <div class=\"header\">\n    <div class=\"company\">\n      <strong>Forgent Systems</strong><br>\n      123 Business Street,<br>\n      City, State, ZIP<br>\n      +1 555 555 0100\n    </div>\n    <div class=\"net-pay\">\n      Net Payable Amount:<br>\n      $${d.net_pay.toLocaleString()}\n    </div>\n  </div>\n\n  <h2>Salary Slip - ${d.month}</h2>\n\n  <table>\n    <tr>\n      <td><b>Employee ID</b></td><td>${d.employee_id}</td>\n      <td><b>Working Days</b></td><td>${d.working_days}</td>\n    </tr>\n    <tr>\n      <td><b>Employee Name</b></td><td>${d.name}</td>\n      <td><b>Present Days</b></td><td>${d.present_days}</td>\n    </tr>\n    <tr>\n      <td><b>Department</b></td><td>Backend Development</td>\n      <td><b>Days Off</b></td><td>${d[\"Days Off\"] ?? 0}</td>\n    </tr>\n    <tr>\n      <td><b>Job Title</b></td><td>Jr. Python Developer</td>\n      <td><b>Holiday Days</b></td><td>${d[\"Holiday Days\"] ?? 0}</td>\n    </tr>\n    <tr>\n      <td><b>Paid Leave</b></td><td>${d.paid_leave}</td>\n      <td><b>Unpaid Leave</b></td><td>${d.unpaid_leave}</td>\n    </tr>\n  </table>\n\n  <div class=\"section\">\n    <table>\n      <tr>\n        <th>Earning</th>\n        <th>Amount</th>\n        <th>Deduction</th>\n        <th>Amount</th>\n      </tr>\n      <tr>\n        <td>Basic</td>\n        <td>$${d.basic}</td>\n        <td>Leave Deduction</td>\n        <td>$${d.leave_deduction}</td>\n      </tr>\n      <tr>\n        <td>Special Allowance</td>\n        <td>$${d.allowance}</td>\n        <td>Payroll Tax</td>\n        <td>$${d.payroll_tax}</td>\n      </tr>\n      <tr>\n        <td>Leave Payout</td>\n        <td>$${d.leave_payout}</td>\n        <td></td>\n        <td></td>\n      </tr>\n      <tr>\n        <th>Total Earning</th>\n        <th>$${d.basic + d.allowance + d.leave_payout}</th>\n        <th>Total Deduction</th>\n        <th>$${d.leave_deduction + d.payroll_tax}</th>\n      </tr>\n    </table>\n  </div>\n\n  <div class=\"summary\">\n    Total Net Payable Amount: $${d.net_pay} (US Dollars)\n  </div>\n\n  <div class=\"footer\">\n    Salary: $${d.salary_per_day * d.working_days} ($${d.salary_per_day} Per Day)<br><br>\n    This is a system-generated payslip; no signature is required.\n  </div>\n\n</div>\n</body>\n</html>\n`;\n\n  return {\n    json: {\n      ...d,\n      html\n    }\n  };\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        128,
        -16
      ],
      "id": "7953c404-2da1-40ae-bad5-ae7d9cd3f723",
      "name": "Build Payslip HTML"
    },
    {
      "parameters": {
        "jsCode": "return items.map(item => {\n  const htmlContent = item.json.html;\n\n  // Convert HTML string to Buffer\n  const buffer = Buffer.from(htmlContent, 'utf-8');\n\n  return {\n    json: {\n      ...item.json\n    },\n    binary: {\n      payslip_html: {\n        data: buffer.toString('base64'),\n        mimeType: 'text/html',\n        fileName: `Salary_Slip_${item.json.employee_id}_${item.json.month}.html`\n      }\n    }\n  };\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        304,
        -16
      ],
      "id": "b7a5ad21-95f3-44d5-874b-58f0d950ea23",
      "name": "Create HTML Binary"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.pdfcrowd.com/convert/24.04",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "authorization",
              "value": "Basic bmVqaWc2ODphMTYxMmJiODZjM2NiNTRmMzc4ZTA4MmZmYTEyMDJjMA=="
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "=payslip_html"
            },
            {
              "name": "content_viewport_width",
              "value": "balanced"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "=Salary_slip"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        496,
        -16
      ],
      "id": "700fead8-20bd-414d-b17b-96c29258c63c",
      "name": "Convert Payslip HTML → PDF"
    },
    {
      "parameters": {
        "jsCode": "return items.map(item => {\n  const binaries = item.binary || {};\n\n  // Find the PDF binary by mimeType (BEST PRACTICE)\n  const pdfKey = Object.keys(binaries).find(\n    key => binaries[key].mimeType === 'application/pdf'\n  );\n\n  if (!pdfKey) {\n    throw new Error(\n      'PDF not found. Available binaries: ' + Object.keys(binaries).join(', ')\n    );\n  }\n\n  const pdfBinary = binaries[pdfKey];\n\n  return {\n    json: item.json,\n    binary: {\n      // ⬅️ KEEP THE API KEY NAME EXACTLY\n      [pdfKey]: {\n        ...pdfBinary,\n\n        // OPTIONAL but recommended: fix filename\n        fileName: `${pdfKey}.pdf`\n      }\n    }\n  };\n});\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        688,
        -32
      ],
      "id": "1c56cb18-d67a-489d-a3dd-d59defedf7fa",
      "name": "Extract PDF Binary Only"
    },
    {
      "parameters": {
        "jsCode": "// return items.map(item => {\n//   // Get the binary data from 'Convert Receipt HTML to PDF' node\n//   const pdfNode = $('Extract PDF Binary Only');\n//   const pdfBinary = pdfNode.item.binary;\n  \n//   // Get the PDF binary key (should be the employee name + month + .pdf)\n//   const binaryKey = Object.keys(pdfBinary)[0];\n  \n//   return {\n//     json: {\n//       ...item.json\n//     },\n//     binary: {\n//       [binaryKey]: pdfBinary[binaryKey]\n//     }\n//   };\n// });\n\nreturn items.map(item => {\n  // Get the binary data from 'Keep PDF, Drop HTML' node\n  const pdfNode = $('Extract PDF Binary Only');\n  const pdfBinary = pdfNode.item.binary;\n\n  // Take the existing PDF binary (whatever its original key is)\n  const originalKey = Object.keys(pdfBinary)[0];\n\n  return {\n    json: {\n      ...item.json\n    },\n    binary: {\n      // FORCE binary key name to 'data'\n      data: pdfBinary[originalKey]\n    }\n  };\n});"
      },
      "id": "ab036895-4c0b-4e1d-b2cb-4657dee2430d",
      "name": "Get & Rename PDF Binary to data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        112,
        496
      ]
    },
    {
      "parameters": {
        "operation": "share",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.ReceiptLink }}",
          "mode": "url"
        },
        "permissionsUi": {
          "permissionsValues": {
            "role": "reader",
            "type": "anyone",
            "allowFileDiscovery": true
          }
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        960,
        288
      ],
      "id": "49a7e6c0-6742-433f-9451-76e980c2d5b4",
      "name": "Make PDF Public (Read-Only)",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Wt0oCw6BmieLWjfw",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "from": "+14155238886",
        "to": "=+{{ $('Normalize Payroll Fields').item.json.phone }}",
        "toWhatsapp": true,
        "message": "=Welcome to Forgent Systems.\n\nHi {{ $('Normalize Payroll Fields').item.json.name }},\n\nYour salary slip for {{ $('Normalize Payroll Fields').item.json.month }} has been generated successfully.\n\n💰 Net Pay: ${{ $('Normalize Payroll Fields').item.json.net_pay }}\n\nDownload Receipt here.\n{{ $('Generate Public Receipt Link').item.json.ReceiptLink }}\n\nIf you have any questions, contact the HR team.\n\nThank you,\nHR Department",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        -48,
        496
      ],
      "id": "4b2d0e08-9e8b-4da3-a68a-767563b0b2a5",
      "name": "Send Payslip via WhatsApp",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $('Normalize Payroll Fields').item.json.email }}",
        "subject": "=Salary Slip for {{ $('Normalize Payroll Fields').item.json.month }}",
        "message": "=<div style=\"font-family: Arial, Helvetica, sans-serif; background-color:#f5f7fb; padding:30px;\">\n  <div style=\"max-width:600px; margin:auto; background:#ffffff; border-radius:8px; overflow:hidden;\">\n\n    <!-- Header -->\n    <div style=\"background:#1f2937; padding:20px; color:#ffffff;\">\n      <h2 style=\"margin:0; font-size:20px;\">Salary Slip – {{ $('Normalize Payroll Fields').item.json.month }}</h2>\n      <p style=\"margin:5px 0 0; font-size:14px;\">Forgent Systems</p>\n    </div>\n\n    <!-- Body -->\n    <div style=\"padding:25px; color:#333333;\">\n      <p style=\"font-size:14px;\">Dear <strong>{{ $('Normalize Payroll Fields').item.json.name }}</strong>,</p>\n\n      <p style=\"font-size:14px; line-height:1.6;\">\n        We hope this email finds you well.\n        <br><br>\n        Please find attached your <strong>salary slip for the month of {{ $('Normalize Payroll Fields').item.json.month }}</strong>.\n      </p>\n\n      <!-- Salary Summary -->\n      <div style=\"background:#f9fafb; border:1px solid #e5e7eb; border-radius:6px; padding:15px; margin:20px 0;\">\n        <p style=\"margin:0 0 8px; font-weight:bold;\">Salary Summary</p>\n        <table style=\"width:100%; font-size:14px;\">\n          <tr>\n            <td>Net Pay</td>\n            <td style=\"text-align:right;\"><strong>${{ $('Normalize Payroll Fields').item.json.net_pay }}</strong></td>\n          </tr>\n          <tr>\n            <td>Paid Days</td>\n            <td style=\"text-align:right;\">{{ $('Normalize Payroll Fields').item.json.working_days - $('Normalize Payroll Fields').item.json.unpaid_leave }}</td>\n          </tr>\n        </table>\n      </div>\n\n      <p style=\"font-size:14px; line-height:1.6;\">\n        This is a <strong>system-generated payslip</strong> and does not require a signature.\n        <br><br>\n        If you notice any discrepancies or have questions, please contact the HR department.\n      </p>\n\n      <p style=\"font-size:14px;\">\n        Best regards,<br>\n        <strong>HR Department</strong><br>\n        Forgent Systems\n      </p>\n    </div>\n\n    <!-- Footer -->\n    <div style=\"background:#f3f4f6; padding:15px; text-align:center; font-size:12px; color:#6b7280;\">\n      © {{ new Date().getFullYear() }} Forgent Systems. All rights reserved.\n    </div>\n\n  </div>\n</div>",
        "options": {
          "appendAttribution": false,
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          }
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        288,
        496
      ],
      "id": "236f2cdf-60d9-4a05-b9cb-eb2078a3d316",
      "name": "Send Payslip via Email",
      "webhookId": "e6c36781-3285-40a9-a4ca-4d53e31cb256",
      "credentials": {
        "gmailOAuth2": {
          "id": "emmuhpJGs7nAZSDK",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1pHk9-GCQ6QqFu1eRoRz4gD1phFmDooHoNAlHYtGATSY",
          "mode": "list",
          "cachedResultName": "Automated Payroll Slip Sender"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Employees"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "status": "Sent",
            "Receipt PDF": "={{ $('Generate Public Receipt Link').item.json.ReceiptLink }}",
            "row_number": "={{ $('Normalize Payroll Fields').item.json.row_number }}"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "employee_id",
              "displayName": "employee_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "name",
              "displayName": "name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "email",
              "displayName": "email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "phone",
              "displayName": "phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "month",
              "displayName": "month",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "working_days",
              "displayName": "working_days",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "present_days",
              "displayName": "present_days",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Days Off",
              "displayName": "Days Off",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Holiday Days",
              "displayName": "Holiday Days",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "paid_leave",
              "displayName": "paid_leave",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "unpaid_leave",
              "displayName": "unpaid_leave",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "salary_per_day",
              "displayName": "salary_per_day",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "basic",
              "displayName": "basic",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "allowance",
              "displayName": "allowance",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "leave_payout",
              "displayName": "leave_payout",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "leave_deduction",
              "displayName": "leave_deduction",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "payroll_tax",
              "displayName": "payroll_tax",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "net_pay",
              "displayName": "net_pay",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Receipt PDF",
              "displayName": "Receipt PDF",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        464,
        496
      ],
      "id": "05e309c8-0b78-441a-81fb-83ef6f9bf25b",
      "name": "Store Receipt Link & Mark Payroll as Sent",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "GojUvCMDXbhY8HrB",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Google Sheet\nCreate your own spreadsheet with these tabs/columns, then select it in the Google Sheets nodes:\n- **Automated Payroll Slip Sender → Employees**: `status`, `month`, `Receipt PDF`"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -928,
        -512
      ],
      "id": "f61ebefe-a38a-49bd-aa9d-c6d4e0c68fa9",
      "name": "Sticky Note"
    }
  ],
  "pinData": {},
  "connections": {
    "Check If Receipt Folder Exists": {
      "main": [
        [
          {
            "node": "Upload Receipt PDF (Existing Folder)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create “Staff Salary Receipts” Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Receipt PDF (Existing Folder)": {
      "main": [
        [
          {
            "node": "Generate Public Receipt Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Receipt PDF (New Folder)": {
      "main": [
        [
          {
            "node": "Generate Public Receipt Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Public Receipt Link": {
      "main": [
        [
          {
            "node": "Make PDF Public (Read-Only)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find “Staff Salary Receipts” Folder in Drive": {
      "main": [
        [
          {
            "node": "Check If Receipt Folder Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create “Staff Salary Receipts” Folder": {
      "main": [
        [
          {
            "node": "Upload Receipt PDF (New Folder)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Monthly Payroll Trigger": {
      "main": [
        [
          {
            "node": "Fetch Pending Payroll",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Pending Payroll": {
      "main": [
        [
          {
            "node": "Process Employees One by One",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Employees One by One": {
      "main": [
        [],
        [
          {
            "node": "Normalize Payroll Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Payroll Fields": {
      "main": [
        [
          {
            "node": "Build Payslip HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Payslip HTML": {
      "main": [
        [
          {
            "node": "Create HTML Binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create HTML Binary": {
      "main": [
        [
          {
            "node": "Convert Payslip HTML → PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Payslip HTML → PDF": {
      "main": [
        [
          {
            "node": "Extract PDF Binary Only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Binary Only": {
      "main": [
        [
          {
            "node": "Find “Staff Salary Receipts” Folder in Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get & Rename PDF Binary to data": {
      "main": [
        [
          {
            "node": "Send Payslip via Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Make PDF Public (Read-Only)": {
      "main": [
        [
          {
            "node": "Send Payslip via WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Payslip via WhatsApp": {
      "main": [
        [
          {
            "node": "Get & Rename PDF Binary to data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Payslip via Email": {
      "main": [
        [
          {
            "node": "Store Receipt Link & Mark Payroll as Sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Receipt Link & Mark Payroll as Sent": {
      "main": [
        [
          {
            "node": "Process Employees One by One",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "fe644a73-0452-4647-a8af-00a4a687a954",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "f1c26778ec36097a9722a22c47c5e9c01f00b8862dadd0121ec118026a370fa6"
  },
  "id": "oFqn73qCBPZh9oP2",
  "tags": []
}