{ "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 }, { "node": "AWS Textract", "type": "main", "index": 0 }, { "node": "Merge", "type": "main", "index": 1 } ] ] }, "AWS Textract": { "main": [ [ { "node": "Code1", "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-03-27T11:07:01.918Z", "id": "7", "name": "Rechnungen -> DATEV", "nodes": [ { "parameters": { "pollTimes": { "item": [ { "mode": "everyMinute" } ] }, "filters": { "labelIds": [ "INBOX" ] } }, "id": "b4421482-9533-4a70-a010-bc37198173de", "name": "Gmail Trigger", "type": "n8n-nodes-base.gmailTrigger", "typeVersion": 1, "position": [ 280, -200 ], "credentials": { "gmailOAuth2": { "id": "16", "name": "Gmail - buchhaltung@lanakk.com" } } }, { "parameters": { "operation": "get", "messageId": "={{$json[\"id\"]}}", "simple": false, "options": { "dataPropertyAttachmentsPrefixName": "attachment_", "downloadAttachments": true } }, "id": "92850b56-b38e-49a1-8fd7-253b022a3fa2", "name": "Gmail", "type": "n8n-nodes-base.gmail", "typeVersion": 2, "position": [ 500, -200 ], "credentials": { "gmailOAuth2": { "id": "16", "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": "d7bbeaa9-8961-4f71-a21c-11009aad9712", "name": "IF", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 720, -200 ] }, { "parameters": { "sendTo": "79e9685d-6952-420b-a9b0-db1950def732@uploadmail.datev.de", "subject": "=Neuer Beleg - {{$now}}", "message": "=", "options": { "attachmentsUi": { "attachmentsBinary": [ { "property": "attachment_0" } ] } } }, "id": "92b1ec51-291e-43bb-9f62-96ab3acb1f6c", "name": "An Datev weiterleiten", "type": "n8n-nodes-base.gmail", "typeVersion": 2, "position": [ 1780, -100 ], "credentials": { "gmailOAuth2": { "id": "16", "name": "Gmail - buchhaltung@lanakk.com" } } }, { "parameters": { "operation": "addLabels", "messageId": "={{$node[\"An Datev weiterleiten\"].json[\"id\"]}}", "labelIds": [ "Label_5013070903895930344" ] }, "id": "94d4e183-8b86-48ea-9a7d-c620ce431b5e", "name": "Datev Label anhängen", "type": "n8n-nodes-base.gmail", "typeVersion": 2, "position": [ 1980, -100 ], "credentials": { "gmailOAuth2": { "id": "16", "name": "Gmail - buchhaltung@lanakk.com" } } }, { "parameters": {}, "id": "a38e57c7-1953-45bd-87cc-c4bd9aaf4e57", "name": "NoOp", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [ 1000, -100 ] }, { "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": "9265ff9e-648b-4c83-90be-ae9cf3d96d9b", "name": "Code", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 1000, -300 ] }, { "parameters": { "setAllData": false, "sourceKey": "=attachment_0", "options": { "keepSource": true } }, "id": "d403f312-afc3-4b99-9344-38764a94d3b1", "name": "Binärdaten zu JSON", "type": "n8n-nodes-base.moveBinaryData", "typeVersion": 1, "position": [ 1220, -300 ] }, { "parameters": { "value": "={{$json.data}}", "dataPropertyName": "hash" }, "id": "a743c51c-d13b-4c7b-a6c6-7dfbc60c0904", "name": "Hash erzeugen", "type": "n8n-nodes-base.crypto", "typeVersion": 1, "position": [ 1440, -300 ] }, { "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": "6b746f53-17e9-49eb-804b-e5e2a8091589", "name": "Dateien ablegen", "type": "n8n-nodes-base.s3", "typeVersion": 1, "position": [ 2720, -320 ], "credentials": { "s3": { "id": "17", "name": "S3 account" } } }, { "parameters": { "binaryPropertyName": "attachment_0" }, "id": "46f3136d-a228-4ce5-9725-88882e967a4c", "name": "AWS Textract", "type": "n8n-nodes-base.awsTextract", "typeVersion": 1, "position": [ 1780, -520 ], "credentials": { "aws": { "id": "15", "name": "AWS account" } }, "continueOnFail": true }, { "parameters": { "mode": "combine", "combinationMode": "mergeByPosition", "options": {} }, "id": "ed97437a-6dca-42ca-86b3-de5ac52b5892", "name": "Merge", "type": "n8n-nodes-base.merge", "typeVersion": 2, "position": [ 2300, -320 ] }, { "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": "a62d461f-f487-4caf-aa38-8a1f2914c412", "name": "Code1", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 1960, -520 ] }, { "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": "17ebb256-c137-4fed-8dbc-4c3163b09dd7", "name": "Code2", "type": "n8n-nodes-base.code", "typeVersion": 1, "position": [ 2520, -520 ] }, { "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": "cd342347-419f-462f-b93f-6eaea901be99", "name": "HTTP Request", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "position": [ 2720, -520 ], "credentials": { "httpHeaderAuth": { "id": "11", "name": "Baserow Header Auth" } } } ], "pinData": {}, "settings": {}, "staticData": { "node:Gmail Trigger": { "lastTimeChecked": 1682337275, "possibleDuplicates": [ "187b31dbf35eda59" ] } }, "tags": [], "triggerCount": 1, "updatedAt": "2023-04-24T11:55:41.000Z", "versionId": "25daa2a4-b5e0-4360-b8bb-1ded9c07453f" }