{
  "name": "07 \u2014 Faktura \u2192 archiwum + powiadomienie + status w CRM (klinweb.pl)",
  "nodes": [
    {
      "parameters": {
        "content": "## Faktura \u2192 zapis w strukturze folder\u00f3w + powiadomienie + CRM\nSzablon KlinWeb. Wyzwalacz: nowa faktura w systemie fakturowania (webhook z fakturownia.pl / wFirma / inFakt). Pod\u0142\u0105cz Google Drive, Slack i API CRM. \u015acie\u017cka archiwum: `klient/rok/miesi\u0105c`.",
        "height": 140,
        "width": 760,
        "color": 4
      },
      "id": "note-a2",
      "name": "Sticky Note a2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -180
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "invoice-created",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "n2-webhook",
      "name": "Nowa faktura (Webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b1",
              "name": "folder",
              "value": "={{ $json.client_name }}/{{ $now.format(\"yyyy\") }}/{{ $now.format(\"MM\") }}",
              "type": "string"
            },
            {
              "id": "b2",
              "name": "numer",
              "value": "={{ $json.invoice_number }}",
              "type": "string"
            },
            {
              "id": "b3",
              "name": "kwota",
              "value": "={{ $json.gross_amount }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "n2-set",
      "name": "\u015acie\u017cka i metadane",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.pdf_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "n2-http",
      "name": "Pobierz PDF faktury",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "operation": "upload",
        "name": "=Faktura-{{ $(\"\u015acie\u017cka i metadane\").item.json.numer }}.pdf",
        "driveId": {
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "mode": "list",
          "value": "root"
        },
        "options": {}
      },
      "id": "n2-drive",
      "name": "Zapis w Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "mode": "name",
          "value": "ksiegowosc"
        },
        "text": "=\ud83d\udcc4 Nowa faktura {{ $(\"\u015acie\u017cka i metadane\").item.json.numer }} na {{ $(\"\u015acie\u017cka i metadane\").item.json.kwota }} z\u0142 \u2014 zarchiwizowana.",
        "otherOptions": {}
      },
      "id": "n2-slack",
      "name": "Powiadom ksi\u0119gowo\u015b\u0107",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        880,
        -100
      ]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "=https://api.twoj-crm.pl/v1/deals/{{ $(\"Nowa faktura (Webhook)\").item.json.deal_id }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"invoice_status\": \"issued\",\n  \"invoice_number\": \"{{ $(\"\u015acie\u017cka i metadane\").item.json.numer }}\"\n}",
        "options": {}
      },
      "id": "n2-crm",
      "name": "Status p\u0142atno\u015bci w CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        100
      ]
    }
  ],
  "connections": {
    "Nowa faktura (Webhook)": {
      "main": [
        [
          {
            "node": "\u015acie\u017cka i metadane",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u015acie\u017cka i metadane": {
      "main": [
        [
          {
            "node": "Pobierz PDF faktury",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pobierz PDF faktury": {
      "main": [
        [
          {
            "node": "Zapis w Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Zapis w Google Drive": {
      "main": [
        [
          {
            "node": "Powiadom ksi\u0119gowo\u015b\u0107",
            "type": "main",
            "index": 0
          },
          {
            "node": "Status p\u0142atno\u015bci w CRM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    {
      "name": "klinweb.pl"
    },
    {
      "name": "szablon-PL"
    }
  ]
}