{ "active": true, "connections": { "Gmail Trigger": { "main": [ [ { "node": "Gmail", "type": "main", "index": 0 } ] ] }, "Gmail": { "main": [ [ { "node": "IF", "type": "main", "index": 0 } ] ] }, "IF": { "main": [ [ { "node": "Code", "type": "main", "index": 0 } ], [ { "node": "NoOp", "type": "main", "index": 0 } ] ] }, "An Datev weiterleiten": { "main": [ [ { "node": "Datev Label anhängen", "type": "main", "index": 0 } ] ] }, "Code": { "main": [ [ { "node": "Binärdaten zu JSON", "type": "main", "index": 0 } ] ] }, "Binärdaten zu JSON": { "main": [ [ { "node": "Hash erzeugen", "type": "main", "index": 0 } ] ] }, "Hash erzeugen": { "main": [ [ { "node": "An Datev weiterleiten", "type": "main", "index": 0 } ] ] }, "Merge": { "main": [ [ { "node": "Dateien ablegen", "type": "main", "index": 0 }, { "node": "Code2", "type": "main", "index": 0 } ] ] }, "Code1": { "main": [ [ { "node": "Merge", "type": "main", "index": 0 } ] ] }, "Code2": { "main": [ [ { "node": "HTTP Request", "type": "main", "index": 0 } ] ] } }, "createdAt": "2023-08-25T09:10:33.270Z", "id": "1", "meta": null, "name": "Rechnungen -> DATEV", "nodes": [ { "parameters": { "pollTimes": { "item": [ { "mode": "everyMinute" } ] }, "filters": { "labelIds": [ "INBOX" ] } }, "id": "08aeeb55-7ea6-4e23-a9c4-2838a5249f2d", "name": "Gmail Trigger", "type": "n8n-nodes-base.gmailTrigger", "typeVersion": 1, "position": [ -860, 740 ], "credentials": { "gmailOAuth2": { "id": "1", "name": "Gmail - buchhaltung@lanakk.com" } } }, { "parameters": { "operation": "get", "messageId": "={{$json[\"id\"]}}", "simple": false, "options": { "dataPropertyAttachmentsPrefixName": "attachment_", "downloadAttachments": true } }, "id": "a194d44b-9610-4e7d-b8db-a4a09d2b8a30", "name": "Gmail", "type": "n8n-nodes-base.gmail", "typeVersion": 2, "position": [ -640, 740 ], "credentials": { "gmailOAuth2": { "id": "1", "name": "Gmail - buchhaltung@lanakk.com" } } }, { "parameters": { "conditions": { "string": [ { "value1": "={{$jmespath($binary, \"*.[fileExtension]\")}}", "operation": "contains", "value2": "pdf" }, { "value1": "={{$json[\"labelIds\"][1]}}", "operation": "notEqual", "value2": "SENT" } ] } }, "id": "554ad5d4-6891-47ec-a5a5-79cc01bedbcb", "name": "IF", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ -420, 740 ] }, { "parameters": { "sendTo": "79e9685d-6952-420b-a9b0-db1950def732@uploadmail.datev.de", "subject": "=Neuer Beleg - {{$now}}", "message": "=", "options": { "attachmentsUi": { "attachmentsBinary": [ { "property": "attachment_0" } ] } } }, "id": "05a0a406-d2b2-4043-accb-25d611f415c6", "name": "An Datev weiterleiten", "type": "n8n-nodes-base.gmail", "typeVersion": 2, "position": [ 640, 840 ], "credentials": { "gmailOAuth2": { "id": "1", "name": "Gmail - buchhaltung@lanakk.com" } } }, { "parameters": { "operation": "addLabels", "messageId": "={{$node[\"An Datev weiterleiten\"].json[\"id\"]}}", "labelIds": [ "Label_5013070903895930344" ] }, "id": "e4ca31e0-3ffe-4d2e-8250-2145e7dda8a6", "name": "Datev Label anhängen", "type": "n8n-nodes-base.gmail", "typeVersion": 2, "position": [ 840, 840 ], "credentials": { "gmailOAuth2": { "id": "1", "name": "Gmail - buchhaltung@lanakk.com" } } }, { "parameters": {}, "id": "0b60c6c7-bbe1-45be-8674-266fde0d9ea6", "name": "NoOp", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ -140, 840 ] }, { "parameters": { "jsCode": "\nitems = [];\n\nfor (const item of $input.all()) {\n for (let i = 0; i < Object.keys(item.binary).length; i++) {\n let newItem = {\n \"json\": {},\n \"binary\": {}\n };\n if (item.binary[\"attachment_\" +i].fileExtension != \"pdf\"){\n continue;\n }\n newItem.json = item.json;\n newItem.binary.attachment_0 = item.binary[\"attachment_\" +i];\n items.push(newItem);\n }\n}\n\nreturn items;" }, "id": "1772cb30-9bb7-48b3-b990-e9fa05e82a64", "name": "Code", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ -140, 640 ] }, { "parameters": { "setAllData": false, "sourceKey": "=attachment_0", "options": { "keepSource": true } }, "id": "646f92c1-2af7-46fe-9b3f-51bb17ba303f", "name": "Binärdaten zu JSON", "type": "n8n-nodes-base.moveBinaryData", "typeVersion": 1, "position": [ 80, 640 ] }, { "parameters": { "value": "={{$json.data}}", "dataPropertyName": "hash" }, "id": "cf623347-4b7e-4d61-a877-ee7aab89c28f", "name": "Hash erzeugen", "type": "n8n-nodes-base.crypto", "typeVersion": 1, "position": [ 300, 640 ] }, { "parameters": { "operation": "upload", "bucketName": "rechnungen", "fileName": "={{$json.hash}}.{{$binary.attachment_0.fileExtension}}", "binaryPropertyName": "=attachment_0", "additionalFields": {}, "tagsUi": { "tagsValues": [ { "key": "MONAT", "value": "={{ $json[\"month\"] }}" }, { "key": "JAHR", "value": "={{ $json[\"year\"] }}" }, { "key": "REFERENZ", "value": "={{ $json[\"INVOICE_RECEIPT_ID\"] }}" }, { "key": "TYP", "value": "={{ $json[\"docType\"] }}" } ] } }, "id": "706ea9d9-acdc-4670-a47c-f32cec6d0a60", "name": "Dateien ablegen", "type": "n8n-nodes-base.s3", "typeVersion": 1, "position": [ 1580, 620 ], "credentials": { "s3": { "id": "2", "name": "S3 account" } } }, { "parameters": { "mode": "combine", "combinationMode": "mergeByPosition", "options": {} }, "id": "563526af-cb42-4857-b593-64ff7558515d", "name": "Merge", "type": "n8n-nodes-base.merge", "typeVersion": 2, "position": [ 1160, 620 ] }, { "parameters": { "jsCode": "function getMonthAndYear(dateString) {\n const dateArray = dateString.split('.');\n const monthAbbreviations = ['JAN', 'FEB', 'MAR', 'APR', 'MAI', 'JUN', 'JUL', 'AUG', 'SEP', 'OKT', 'NOV', 'DEZ'];\n const monthIndex = parseInt(dateArray[1]) - 1;\n const month = monthAbbreviations[monthIndex];\n let year = dateArray[2];\n \n if (year.length === 2) {\n year = '20' + year;\n }\n\n return { month: month, year: year };\n}\n\nfor (const item of $input.all()) {\n let period = getMonthAndYear(item.json.INVOICE_RECEIPT_DATE);\n item.json.month = period.month;\n item.json.year = period.year;\n\n if (!item.json.INVOICE_RECEIPT_ID) {\n item.json.INVOICE_RECEIPT_ID = \"UNBEKANNT\";\n item.json.docType = \"UNBEKANNT\";\n continue;\n }\n\n if (!item.json.TAX) {\n item.json.TAX = 0; \n }\n \n item.json.docType = \"RECHNUNG\";\n}\n\nreturn $input.all();" }, "id": "74ec1239-4f1a-4d2c-a724-0dd229d85168", "name": "Code1", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 820, 420 ] }, { "parameters": { "jsCode": "const monthId = {\n 'JAN': 3852,\n 'FEB': 3853,\n 'MAR': 3854,\n 'APR': 3855,\n 'MAI': 3856,\n 'JUN': 3857,\n 'JUL': 3858,\n 'AUG': 3859,\n 'SEP': 3860,\n 'OKT': 3861,\n 'NOV': 3862,\n 'DEZ': 3863\n};\n\nconst yearId = {\n '2015': 3864,\n '2016': 3865,\n '2017': 3866,\n '2018': 3867,\n '2019': 3868,\n '2020': 3869,\n '2021': 3870,\n '2022': 3871,\n '2023': 3872,\n '2024': 3873\n};\nfor (const item of $input.all()) {\n item.json.month = monthId[item.json.month];\n item.json.year = yearId[item.json.year];\n item.json.SUBTOTAL = item.json.SUBTOTAL.replace(',','.');\n item.json.TAX = item.json.TAX.replace(',','.');\n dateParts = item.json.INVOICE_RECEIPT_DATE.split('.');\n item.json.INVOICE_RECEIPT_DATE = `${dateParts[2]}-${dateParts[1].padStart(2, '0')}-${dateParts[0].padStart(2, '0')}`;\n}\n\nreturn $input.all();" }, "id": "cad2d889-f42a-4a45-a662-360aeedd1526", "name": "Code2", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 1380, 420 ], "continueOnFail": true }, { "parameters": { "method": "POST", "url": "https://db.lanakk.com/api/database/rows/table/840/", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "user_field_names", "value": "true" } ] }, "sendBody": true, "bodyParameters": { "parameters": [ { "name": "Datum", "value": "={{ $json.INVOICE_RECEIPT_DATE }}" }, { "name": "Monat", "value": "={{ $json.month }}" }, { "name": "Jahr", "value": "={{ $json.year }}" }, { "name": "Belegnummer", "value": "={{ $json.INVOICE_RECEIPT_ID }}" }, { "name": "Betrag", "value": "={{ $json.SUBTOTAL }}" }, { "name": "MwST", "value": "={{ $json.TAX }}" }, { "name": "Dateiname", "value": "={{ $json.hash }}.pdf" } ] }, "options": {} }, "id": "7b86214e-4545-43eb-a49d-b5e9fb595f41", "name": "HTTP Request", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 1580, 420 ], "credentials": { "httpHeaderAuth": { "id": "11", "name": "Baserow Header Auth" } } } ], "pinData": {}, "settings": {}, "staticData": { "node:Gmail Trigger": { "possibleDuplicates": [ "19127dc526fd63dc" ], "lastTimeChecked": 1722950635 } }, "tags": [], "triggerCount": 1, "updatedAt": "2024-08-06T13:24:41.000Z", "versionId": "d5336b9a-260a-4f88-862e-edbbb760acb2" }