{
  "name": "Invoice Generator from Google Sheets",
  "nodes": [
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "value": "your-spreadsheet-id"
        },
        "sheetName": {
          "value": "Invoices"
        },
        "options": {
          "range": "A:H"
        }
      },
      "id": "b0c1d2e3-f4a5-6789-bcde-890123457bc3",
      "name": "Read Invoice Data",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.2,
      "position": [250, 300]
    },
    {
      "parameters": {
        "jsCode": "const row = $input.first().json;\nconst html = `<!DOCTYPE html>\n<html><head><style>\n  body { font-family: Arial; padding: 40px; }\n  .header { display: flex; justify-content: space-between; margin-bottom: 30px; }\n  table { width: 100%; border-collapse: collapse; margin: 20px 0; }\n  th, td { border: 1px solid #ddd; padding: 10px; text-align: left; }\n  th { background: #2563eb; color: white; }\n  .total { font-size: 1.3em; font-weight: bold; text-align: right; margin-top: 20px; }\n</style></head><body>\n  <div class=\"header\">\n    <div><h1>INVOICE</h1><p>#${row.invoiceNumber}</p></div>\n    <div><p>Date: ${row.date}</p><p>Due: ${row.dueDate}</p></div>\n  </div>\n  <p><strong>Bill To:</strong> ${row.clientName}<br>${row.clientEmail}</p>\n  <table><tr><th>Description</th><th>Qty</th><th>Price</th><th>Total</th></tr>\n  <tr><td>${row.description}</td><td>${row.quantity}</td><td>$${row.unitPrice}</td><td>$${row.quantity * row.unitPrice}</td></tr></table>\n  <div class=\"total\">Total: $${row.quantity * row.unitPrice}</div>\n</body></html>`;\nreturn [{json: { html, clientEmail: row.clientEmail, invoiceNumber: row.invoiceNumber, total: row.quantity * row.unitPrice }}];"
      },
      "id": "c1d2e3f4-a5b6-7890-cdef-901234568cd4",
      "name": "Generate HTML Invoice",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [500, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.html2pdf.app/v1/generate",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {"name": "Content-Type", "value": "application/json"}
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"html\": \"{{ $json.html }}\", \"apiKey\": \"your-api-key\"}",
        "options": {
          "response": {"response": {"responseFormat": "file"}}
        }
      },
      "id": "d2e3f4a5-b6c7-8901-defa-012345679de5",
      "name": "Convert to PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [750, 300]
    },
    {
      "parameters": {
        "sendTo": "={{ $('Generate HTML Invoice').item.json.clientEmail }}",
        "subject": "=Invoice #{{ $('Generate HTML Invoice').item.json.invoiceNumber }} - ${{ $('Generate HTML Invoice').item.json.total }}",
        "message": "<p>Please find your invoice attached.</p><p>Thank you for your business!</p>",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [{"property": "data"}]
          }
        }
      },
      "id": "e3f4a5b6-c7d8-9012-efab-123456780ef6",
      "name": "Email Invoice",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1000, 300]
    }
  ],
  "connections": {
    "Read Invoice Data": {
      "main": [[{"node": "Generate HTML Invoice", "type": "main", "index": 0}]]
    },
    "Generate HTML Invoice": {
      "main": [[{"node": "Convert to PDF", "type": "main", "index": 0}]]
    },
    "Convert to PDF": {
      "main": [[{"node": "Email Invoice", "type": "main", "index": 0}]]
    }
  },
  "settings": {"executionOrder": "v1"},
  "staticData": null,
  "tags": []
}
