{
  "name": "Pobieranie dokument\u00f3w",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -2576,
        224
      ],
      "id": "b40d1f74-f920-4ced-bc73-9418d408d64a",
      "name": "When clicking \u2018Execute workflow\u2019"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://prebaw.creditagricole/api/Authentication/Login",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n\"Login\":\"hackaton\",\n\"Password\":\"hackaton2\"\n}",
        "options": {
          "allowUnauthorizedCerts": true,
          "redirect": {
            "redirect": {
              "followRedirects": false
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -160,
        352
      ],
      "id": "7258ce00-a4f8-4dc2-93ef-211323ba80e0",
      "name": "HTTP Request1",
      "alwaysOutputData": true,
      "executeOnce": false,
      "retryOnFail": false,
      "waitBetweenTries": 100
    },
    {
      "parameters": {
        "url": "=https://prebaw.creditagricole/api/file/1/{{ $('insert_do_pobrania').item.json[\"8GIC\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "BearerTokenCookieName",
              "value": "={{ $json.data }}"
            }
          ]
        },
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -144,
        624
      ],
      "id": "a4d9bd66-2c5a-48ee-b988-dfd6e6b8b729",
      "name": "HTTP Request2",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -2576,
        48
      ],
      "id": "3760faee-0d2d-4f01-9388-7c3e2e70deae",
      "name": "Schedule Trigger",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -1712,
        160
      ],
      "id": "14a2c058-3816-40c5-bf37-80f2341f397e",
      "name": "Loop Over Items",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "content": "## ETAP nr1   (zamokowany warunek czasu dla latwiejszego testowania - to pokazu na zywo nalezy zmienic na wartosc zmiennej z pierwszego kroku\nOdpytujemy BAW aby wyszuka\u0107 odpowiednie dokumenty. Iterujemy po wynikach i zapisujemy wyniki do bazy\n\nWhere [BAW].[dbo].[Document].CreationDate > '2024-11-20T14:52:00.000Z'\n  \n   Wybieramy tylko opublikowane doksy  AND [BAW].[dbo].[Document].IsPublished = 1\n\n   W ybieramy tylko doksy kt\u00f3rych liczba wersji w systemie jest wieksza niz 1  AND TRY_CONVERT(decimal(10,2), [BAW].[dbo].[Document].DocumentVersion) > 1\n\n   Ogranicamy wyniki do plikow typu docx   AND [BAW].[dbo].[AttachmentLink].isWordDocument = 1\n\n   Wybieramy tylko doksy o wybranym typie procedura 60 przewodnik 59 regulamin 28 polityka 75 strategia 76 ew. instrukcja powiazana z WB 25 , wniosek 74, zalacznik inny 35   -   wycinamy zarzadzenia 3\n  AND [BAW].[dbo].[Document].LegalActType IN (60, 59, 28, 75, 76)",
        "height": 592,
        "width": 1552
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -2176,
        -160
      ],
      "id": "bfbd1bd0-7931-4697-81e9-f052a62d62ea",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Triger cron /manual start\n\n\nFlow odpala sie co 30min",
        "height": 672,
        "width": 288
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -2624,
        -144
      ],
      "id": "085aec4a-ae26-401d-b814-5ef4504561f3",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT TOP (200) [BAW].[dbo].[Document].[Id]\n\t  ,[BAW].[dbo].[Document].[DocumentVersion]\n\t  ,[BAW].[dbo].[Document].[LegalActType]\n      ,[BAW].[dbo].[Document].[ActDate]\n\t  ,[BAW].[dbo].[Document].[ActNumber]\n      ,[BAW].[dbo].[Document].[CreationDate]\n\t  ,[BAW].[dbo].[Document].[PublishedDate]\n\t  ,[BAW].[dbo].[Document].[ValidTo]\n      ,[BAW].[dbo].[Document].[DocumentProceedingStatus]\n      ,[BAW].[dbo].[Document].[IsPublished]\n      ,[BAW].[dbo].[Document].[IsRemoved]\n      ,[BAW].[dbo].[Document].[IsSigned]\n      ,[BAW].[dbo].[Document].[LegalActStatus]   \n      ,[BAW].[dbo].[Document].[Title]\n      ,[BAW].[dbo].[Document].[UpdateDate]\n      ,[BAW].[dbo].[Document].[ValidFrom]\n      ,[BAW].[dbo].[Document].[UnifiedDocumentId]\n      ,[BAW].[dbo].[Document].[WasEverPublished]\n      ,[BAW].[dbo].[Document].[UniqueSharedIdentifier]    \n      ,[BAW].[dbo].[Document].[IsConfidential]\n      ,[BAW].[dbo].[Document].[WasConfidential]\n      ,[BAW].[dbo].[Document].[SystemValidTo]\n      ,[BAW].[dbo].[Document].[PermissionType]\n      ,[BAW].[dbo].[Document].[IsSetPermission]\n      ,[BAW].[dbo].[Document].[LastEditDate]\n\t  ,[BAW].[dbo].[AttachmentLink].id as [id_pliku]\n\t  ,[BAW].[dbo].[AttachmentLink].AttachmentNumber as [AttachmentNumber]\n\t  ,[BAW].[dbo].[AttachmentLink].[CreationDate] as [CreationDateFile]\n\t  ,[BAW].[dbo].[AttachmentLink].[OrginalFileName]\n\t  ,[BAW].[dbo].[AttachmentLink].[FileIdentiefier]\n      ,[BAW].[dbo].[AttachmentLink].[FileName]\n\t  ,[BAW].[dbo].[AttachmentLink].[IsWordDocument]\n\t  ,[BAW].[dbo].[AttachmentLink].[LanguageVersion]\n      ,[BAW].[dbo].[AttachmentLink].[OriginalWordFileId]\n\t  ,[BAW].[dbo].[AttachmentLink].[ParentFileIdentiefier]\n      ,[BAW].[dbo].[AttachmentLink].[ParentId]\n\t  ,[BAW].[dbo].[AttachmentLink].[UniqueSharedIdentifier]\n  FROM [BAW].[dbo].[Document]\n  LEFT JOIN [BAW].[dbo].[AttachmentLink] \n  ON [BAW].[dbo].[Document].Id = [AttachmentLink].DocumentID\n  Where [BAW].[dbo].[Document].CreationDate > '2024-11-20T14:52:00.000Z'\n  \n  /******#Wybieramy tylko opublikowane doksy******/\n  AND [BAW].[dbo].[Document].IsPublished = 1\n\n   /******#Wybieramy tylko doksy kt\u00f3rych liczba wersji w systemie jest wieksza niz 1******/\n   AND TRY_CONVERT(decimal(10,2), [BAW].[dbo].[Document].DocumentVersion) > 1\n\n   /******#Ogranicamy wyniki do plikow typu docx ******/\n   AND [BAW].[dbo].[AttachmentLink].isWordDocument = 1\n\n   /****** #Wybieramy tylko doksy o wybranym typie procedura 60 przewodnik 59 regulamin 28 polityka 75 strategia 76 ew. instrukcja powiazana z WB 25 , wniosek 74, zalacznik inny 35   -   wycinamy zarzadzenia 3******/\n  AND [BAW].[dbo].[Document].LegalActType IN (60, 59, 28, 75, 76)"
      },
      "type": "n8n-nodes-base.microsoftSql",
      "typeVersion": 1.1,
      "position": [
        -2128,
        160
      ],
      "id": "5cc2caa0-d872-403b-bfb1-1c976761326b",
      "name": "Select_no_1",
      "credentials": {
        "microsoftSql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "/****** Krok w kt\u00f3rym pobieramy ID pierwotnego pliku  ******/\nSELECT TOP (100) [Id]\n      ,[CreationDate]\n      ,[MasterDocumentId]\n      ,[SlaverDocumentId]\n      ,[Type]\n      ,[UniqueSharedIdentifier]\n      ,[RelationNumber]\n  FROM [BAW].[dbo].[DocumentRelation]\n  where MasterDocumentId = {{$json.iUw3}}\n  and Type = 16"
      },
      "type": "n8n-nodes-base.microsoftSql",
      "typeVersion": 1.1,
      "position": [
        -1984,
        608
      ],
      "id": "f61ff47d-201c-47e2-8f83-013d2adda1ab",
      "name": "Select_no_2",
      "alwaysOutputData": true,
      "credentials": {
        "microsoftSql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "search",
        "tableName": "Table1",
        "searchColumn": "baw_file_id",
        "searchTerm": "={{'Loop Over Items'.item,$json.id_pliku}}",
        "options": {
          "insensitive": true,
          "convert": true
        }
      },
      "type": "n8n-nodes-base.seaTable",
      "typeVersion": 2,
      "position": [
        -1456,
        176
      ],
      "id": "070fda50-3c66-4fd0-a5d0-edbea0084a2d",
      "name": "Check_if_exist",
      "alwaysOutputData": true,
      "executeOnce": false,
      "credentials": {
        "seaTableApi": {
          "name": "<your credential>"
        }
      },
      "disabled": true
    },
    {
      "parameters": {
        "tableName": "Table1",
        "apply_default": true,
        "columnsUi": {
          "columnValues": [
            {
              "columnName": "Dock_name",
              "columnValue": "={{ $('Loop Over Items').item.json.OrginalFileName }}"
            },
            {
              "columnName": "is_handled_by_n8n",
              "columnValue": "0"
            },
            {
              "columnName": "baw_file_id",
              "columnValue": "={{ $('Loop Over Items').item.json.id_pliku }}"
            },
            {
              "columnName": "Dock_version",
              "columnValue": "={{ $('Loop Over Items').item.json.DocumentVersion }}"
            },
            {
              "columnName": "baw_doc_date",
              "columnValue": "={{ $('Loop Over Items').item.json.CreationDateFile }}"
            },
            {
              "columnName": "baw_dock_id",
              "columnValue": "={{ $('Loop Over Items').item.json.Id }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.seaTable",
      "typeVersion": 2,
      "position": [
        -768,
        80
      ],
      "id": "82115d01-9633-418b-bc79-a8f1ce248831",
      "name": "Insert_into_db",
      "alwaysOutputData": true,
      "credentials": {
        "seaTableApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "get_first_versiondock",
        "apply_default": true,
        "columnsUi": {
          "columnValues": [
            {
              "columnName": "first_ver_id",
              "columnValue": "={{ $json.SlaverDocumentId }}"
            },
            {
              "columnName": "baw_dock_id",
              "columnValue": "={{ $json.MasterDocumentId }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.seaTable",
      "typeVersion": 2,
      "position": [
        -1632,
        608
      ],
      "id": "3c026c9d-e1b7-48ae-8297-6137b6305831",
      "name": "Insert_into_db2",
      "alwaysOutputData": true,
      "credentials": {
        "seaTableApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "items[0].json.globalStorage = {\n    zmienna_mok: $input.first().json.Id,\n    Czas_odciecia: $now\n};\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1936,
        160
      ],
      "id": "40891629-e5df-4c77-a5df-34b714834c1d",
      "name": "Variable js"
    },
    {
      "parameters": {
        "jsCode": "items[0].json.globalStorage = {\n    id_pierwszej_wersji: $input.first().json.SlaverDocumentId,\n};\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1824,
        608
      ],
      "id": "87ba1ea9-788a-45c7-87e0-e98c9f49e1e1",
      "name": "Variable_js2",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "amount": 2
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -608,
        208
      ],
      "id": "5f4581a7-9bce-481a-a647-79e9cbe67e3c",
      "name": "Wait",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "content": "## ETAP 2\nPobieramy i zapisujemy w naszej bazie ID pierwszego doka i sprawdzamy dwie ostatnie wersje tego dokumentu",
        "height": 336,
        "width": 1552
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -2176,
        480
      ],
      "id": "379ef632-4827-4c28-8c0c-bbc2ca8a8e21",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "adb78c00-bbbd-4ec2-9e6c-d1cf4a309800",
              "leftValue": "={{ $json.inserted_row_count }}",
              "rightValue": "0",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -1456,
        608
      ],
      "id": "c243f6cf-d1a6-475b-a359-3430d5236c4c",
      "name": "If1",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "/****** sprawdzenie pierwtnego pliku  ******/\nSELECT TOP (2) [BAW].[dbo].[DocumentRelation].[Id]\n      ,[BAW].[dbo].[DocumentRelation].[CreationDate]\n      ,[BAW].[dbo].[DocumentRelation].[MasterDocumentId]\n      ,[BAW].[dbo].[DocumentRelation].[SlaverDocumentId]\n      ,[BAW].[dbo].[DocumentRelation].[Type]\n      ,[BAW].[dbo].[DocumentRelation].[UniqueSharedIdentifier]\n      ,[BAW].[dbo].[DocumentRelation].[RelationNumber]\n\t\t,[BAW].[dbo].[AttachmentLink].id as [id_pliku]\n\t\t,[BAW].[dbo].[AttachmentLink].[CreationDate] as [CreationDateFile]\n\t\t,[BAW].[dbo].[AttachmentLink].[FileIdentiefier]\n      \t,[BAW].[dbo].[AttachmentLink].[FileName]\n\t\t,[BAW].[dbo].[AttachmentLink].[IsWordDocument]\n\t\t,[BAW].[dbo].[AttachmentLink].[LanguageVersion]\n      \t,[BAW].[dbo].[AttachmentLink].[OrginalFileName]\n\t\t,[BAW].[dbo].[AttachmentLink].[UniqueSharedIdentifier]\n\t  ,[BAW].[dbo].[Document].Id AS ID_dokumentu_w_BAW\n\t  ,[BAW].[dbo].[Document].DocumentVersion AS WERSJA_DOKUMENTU\n\t  ,CONCAT('https://prebaw.creditagricole/api/file/1/', [BAW].[dbo].[AttachmentLink].id) as LinkDOPliku\n\n  FROM [BAW].[dbo].[DocumentRelation]\n  LEFT JOIN [BAW].[dbo].[AttachmentLink] \n\tON [BAW].[dbo].[DocumentRelation].MasterDocumentId = [AttachmentLink].DocumentID\n\n  LEFT JOIN [BAW].[dbo].[Document]\n\tON [AttachmentLink].DocumentID = [BAW].[dbo].[Document].Id \n\n  WHERE [BAW].[dbo].[DocumentRelation].SlaverDocumentId = 22170\n  AND [BAW].[dbo].[DocumentRelation].Type = 16\n  AND [BAW].[dbo].[AttachmentLink].[IsWordDocument] = 1\n  \n  ORDER BY CreationDate DESC\n"
      },
      "type": "n8n-nodes-base.microsoftSql",
      "typeVersion": 1.1,
      "position": [
        -1216,
        672
      ],
      "id": "ff3f809d-dbe1-4352-82cd-c893955e5dfd",
      "name": "Select_no3",
      "credentials": {
        "microsoftSql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "items[0].json.globalStorage = {\n  id_pliku_Last: $input.first().json.id_pliku,\n  id_pliku_pre: $input.all()[1].json.id_pliku,\n  link_pliku_Last: $input.first().json.LinkDOPliku,\n  link_pliku_pre: $input.all()[1].json.LinkDOPliku\n};\nreturn items;;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1024,
        672
      ],
      "id": "8cf11507-7316-49cd-b369-3dc9817f5bb1",
      "name": "Variable_js3"
    },
    {
      "parameters": {
        "content": "## ETAP 3 - Oznaczenie rekordow jako przeprocesowane / pozniej do przeniesienia na koniec flow\n",
        "width": 1552
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -2176,
        864
      ],
      "id": "646673e7-6e88-41b9-a81d-56dc9d2085e7",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "## Wystawienie plikow\n",
        "height": 896,
        "width": 288
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -240,
        -64
      ],
      "id": "fde18597-9290-4842-a94b-14ee200317e7",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "tableName": "error_log",
        "columnsUi": {
          "columnValues": [
            {
              "columnName": "Error_message",
              "columnValue": "='Dokument '{{ $json.id }} by\u0142 ju\u017c procesowany. Rekord zosta\u0142 pomini\u0119ty w tej iteracji."
            }
          ]
        }
      },
      "type": "n8n-nodes-base.seaTable",
      "typeVersion": 2,
      "position": [
        -1040,
        240
      ],
      "id": "cdc38b17-b5f5-496d-b281-97a4efa9586b",
      "name": "Event_log",
      "alwaysOutputData": false,
      "credentials": {
        "seaTableApi": {
          "name": "<your credential>"
        }
      },
      "disabled": true
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "97975db6-f26e-4d09-a815-c6fad21374df",
                    "leftValue": "={{ $input.item.json }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "empty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "new"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $input.item.json }}",
                    "rightValue": "",
                    "operator": {
                      "type": "object",
                      "operation": "notEmpty",
                      "singleValue": true
                    },
                    "id": "4e72d6b1-a197-4dbc-947c-58d43d50e338"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "exist"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -1248,
        176
      ],
      "id": "40ede656-4ccd-454b-b49a-1bf837a168d2",
      "name": "Switch",
      "disabled": true
    },
    {
      "parameters": {
        "fieldToSplitOut": "['8GIC']",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -160,
        80
      ],
      "id": "cb82bff9-07e7-4702-9a93-6a263e6ac429",
      "name": "Split Out",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "tableName": "error_log",
        "columnsUi": {
          "columnValues": [
            {
              "columnName": "Error_message",
              "columnValue": "='Dla niektorych dokumentow nie znaleziono dokumentow pierwotnych"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.seaTable",
      "typeVersion": 2,
      "position": [
        -1056,
        496
      ],
      "id": "2086ba0b-eb6e-4527-847e-c0e20237b621",
      "name": "Event_log1",
      "alwaysOutputData": false,
      "credentials": {
        "seaTableApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const currentTime = new Date();\nconst newTime = new Date(currentTime.getTime() + 90 * 60000);\n// Formatowanie wyniku (opcjonalne)\nconst formattedTime = newTime.toISOString(); // Format: 2023-10-05T12:30:00.000Z\n\nreturn [{ json: { originalTime: currentTime, minus30Minutes: newTime, formatted: formattedTime } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2320,
        160
      ],
      "id": "94cb766d-6554-46dd-bc6f-d20850e680ef",
      "name": "Obliczanie_zakresu_czasu"
    },
    {
      "parameters": {
        "tableName": "dock_to_process_info",
        "apply_default": true,
        "columnsUi": {
          "columnValues": [
            {
              "columnName": "first_ver_ID",
              "columnValue": "={{ $json.SlaverDocumentId }}"
            },
            {
              "columnName": "dock_id",
              "columnValue": "={{ $json.MasterDocumentId }}"
            },
            {
              "columnName": "dock_version",
              "columnValue": "={{ $json.WERSJA_DOKUMENTU }}"
            },
            {
              "columnName": "file_id",
              "columnValue": "={{ $json.id_pliku }}"
            },
            {
              "columnName": "dock_name",
              "columnValue": "={{ $json.OrginalFileName }}"
            },
            {
              "columnName": "dock_link",
              "columnValue": "={{ $json.LinkDOPliku }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.seaTable",
      "typeVersion": 2,
      "position": [
        -816,
        672
      ],
      "id": "be900cb4-6d9b-4a3e-a188-d25faa6965bb",
      "name": "insert_do_pobrania",
      "alwaysOutputData": true,
      "credentials": {
        "seaTableApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "filePath": "C:\\documents\\old_document.docx",
        "dataPropertyName": "old_file"
      },
      "id": "8ac0ec4b-f3ae-4aa6-a127-9e7d433da79e",
      "name": "Read Old Document",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        288,
        1392
      ],
      "retryOnFail": true
    },
    {
      "parameters": {
        "filePath": "C:\\documents\\new_document.docx",
        "dataPropertyName": "new_file"
      },
      "id": "ada7325b-21bc-4668-aeb3-2148eac7316b",
      "name": "Read New Document",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        288,
        1600
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://217.182.76.146/api/documents/upload",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "old_document",
              "inputDataFieldName": "data1"
            },
            {
              "name": "new_document",
              "inputDataFieldName": "data0"
            }
          ]
        },
        "options": {
          "timeout": 120000
        }
      },
      "id": "dc089642-d7fe-4685-8fbf-987c89b5bb05",
      "name": "Upload Documents",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        736,
        368
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://217.182.76.146/api/process",
        "sendBody": true,
        "contentType": "json",
        "jsonBody": "={\n  \"document_pair_id\": \"{{ $json.document_pair_id }}\"\n}",
        "options": {}
      },
      "id": "94d52ed2-6e52-4a36-ae5d-cacf090e87b4",
      "name": "Start Processing",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        928,
        368
      ]
    },
    {
      "parameters": {
        "amount": 3,
        "unit": "seconds"
      },
      "id": "94741f96-d80f-43e9-8e20-c680c5a0cc9f",
      "name": "Wait 3 Seconds",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1136,
        368
      ]
    },
    {
      "parameters": {
        "url": "=http://217.182.76.146/api/status/{{ $('Start Processing').item.json.process_id }}",
        "options": {}
      },
      "id": "f3a6fc67-822c-40bd-8991-ee1466a60258",
      "name": "Check Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1328,
        368
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "operation": "equals",
              "value2": "completed"
            }
          ]
        }
      },
      "id": "1a85f879-2a31-4b9b-97e5-ba782086db7a",
      "name": "Is Completed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1536,
        368
      ]
    },
    {
      "parameters": {
        "amount": 2,
        "unit": "seconds"
      },
      "id": "88ca94d5-84a5-4e1e-8452-a756d6116a3e",
      "name": "Wait 2 Seconds",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1536,
        560
      ]
    },
    {
      "parameters": {
        "url": "=http://217.182.76.146/api/result/{{ $('Start Processing').item.json.process_id }}/full",
        "options": {}
      },
      "id": "781e1d94-2a54-4d85-9325-945ffdef3ab0",
      "name": "Get Full Result",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1728,
        256
      ]
    },
    {
      "parameters": {
        "url": "=http://217.182.76.146/api/result/{{ $('Start Processing').item.json.process_id }}/modified",
        "options": {}
      },
      "id": "7b1368b4-fa01-4de0-b5c9-800ab49ace40",
      "name": "Get Modified",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1936,
        256
      ]
    },
    {
      "parameters": {
        "url": "=http://217.182.76.146/api/result/{{ $('Start Processing').item.json.process_id }}/added",
        "options": {}
      },
      "id": "get-added-new",
      "name": "Get Added",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2128,
        256
      ]
    },
    {
      "parameters": {
        "url": "=http://217.182.76.146/api/result/{{ $('Start Processing').item.json.process_id }}/deleted",
        "options": {}
      },
      "id": "get-deleted-new",
      "name": "Get Deleted",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2320,
        256
      ]
    },
    {
      "parameters": {
        "jsCode": "// \u0141\u0105czenie wszystkich wynik\u00f3w w jeden obiekt JSON\nconst fullResult = $('Get Full Result').first().json;\nconst modifiedResult = $('Get Modified').first().json;\nconst addedResult = $('Get Added').first().json;\nconst deletedResult = $('Get Deleted').first().json;\n\nconst finalResult = {\n  metadata: {\n    process_id: fullResult.process_id,\n    document_pair_id: fullResult.document_pair_id,\n    generated_at: fullResult.generated_at,\n    timestamp: new Date().toISOString()\n  },\n  statistics: fullResult.statistics,\n  full_document: {\n    paragraphs: fullResult.paragraphs,\n    tables: fullResult.tables || []\n  },\n  changes_summary: {\n    modified: {\n      count: modifiedResult.total_count,\n      items: modifiedResult.modified_sentences\n    },\n    added: {\n      count: addedResult.total_count,\n      items: addedResult.added_sentences\n    },\n    deleted: {\n      count: deletedResult.total_count,\n      items: deletedResult.deleted_sentences\n    }\n  }\n};\n\nreturn { json: finalResult };"
      },
      "id": "combine-all-results",
      "name": "Combine All Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2512,
        256
      ]
    },
    {
      "parameters": {
        "jsCode": "// Podsumowanie ko\u0144cowe\nconst stats = $json.statistics;\nconst summary = $json.changes_summary;\n\nreturn {\n  json: {\n    success: true,\n    message: \"Dokument pomy\u015blnie przetworzony!\",\n    process_id: $json.metadata.process_id,\n    total_changes: stats.modified + stats.added + stats.deleted,\n    modified_count: summary.modified.count,\n    added_count: summary.added.count,\n    deleted_count: summary.deleted.count,\n    change_percentage: stats.change_percentage,\n    complete_json: $json\n  }\n};"
      },
      "id": "final-summary-new",
      "name": "Final Summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2704,
        256
      ]
    },
    {
      "parameters": {
        "jsCode": "// Pobierz complete_json z poprzedniego node\nconst jsonData = $json.complete_json;\n\n// BANKOWE KOLORY (oficjalna paleta)\nconst COLORS = {\n  bg: '#F2F2F2',\n  duckBlue: '#009597',\n  greenDark: '#70A300',\n  green: '#81BC00',\n  greenLight: '#DAF60E',\n  grayBankDark: '#7E93A3',\n  grayBankLight: '#BEC9D3',\n  red: '#ED1B2F',\n  textDark: '#595959',\n  grayMedium: '#A6A6A6'\n};\n\n// Template HTML z bankowymi kolorami\nconst htmlContent = `<!DOCTYPE html>\n<html lang=\"pl\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Raport Por\u00f3wnania Dokument\u00f3w - BAW</title>\n    <style>\n        * { margin: 0; padding: 0; box-sizing: border-box; }\n        body {\n            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;\n            background-color: ${COLORS.bg};\n            color: ${COLORS.textDark};\n            padding: 20px;\n            line-height: 1.6;\n        }\n        .container {\n            max-width: 1400px;\n            margin: 0 auto;\n            background: white;\n            border-radius: 8px;\n            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);\n            padding: 30px;\n        }\n        h1 {\n            color: ${COLORS.duckBlue};\n            border-bottom: 3px solid ${COLORS.duckBlue};\n            padding-bottom: 10px;\n            margin-bottom: 30px;\n        }\n        h2 {\n            color: ${COLORS.greenDark};\n            margin-top: 30px;\n            margin-bottom: 15px;\n            padding-bottom: 5px;\n            border-bottom: 2px solid ${COLORS.greenDark};\n        }\n        h3 { color: ${COLORS.duckBlue}; margin-top: 20px; margin-bottom: 10px; }\n        .summary-box {\n            background: linear-gradient(135deg, ${COLORS.duckBlue} 0%, ${COLORS.greenDark} 50%, ${COLORS.green} 100%);\n            color: white;\n            padding: 30px;\n            border-radius: 8px;\n            margin: 30px 0;\n            text-align: center;\n            box-shadow: 0 4px 15px rgba(0, 149, 151, 0.3);\n        }\n        .summary-box h3 { color: white; border: none; margin: 0 0 20px 0; }\n        .summary-stats { display: flex; justify-content: space-around; flex-wrap: wrap; }\n        .summary-stat { padding: 10px 20px; }\n        .summary-stat-value { font-size: 48px; font-weight: bold; }\n        .summary-stat-label { font-size: 14px; opacity: 0.9; text-transform: uppercase; }\n        .statistics {\n            display: grid;\n            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\n            gap: 20px;\n            margin: 30px 0;\n        }\n        .stat-card {\n            background: white;\n            border-left: 4px solid ${COLORS.duckBlue};\n            padding: 20px;\n            border-radius: 4px;\n            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);\n            transition: transform 0.2s, box-shadow 0.2s;\n        }\n        .stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); }\n        .stat-card.modified { border-left-color: ${COLORS.red}; }\n        .stat-card.added { border-left-color: ${COLORS.greenDark}; }\n        .stat-card.deleted { border-left-color: ${COLORS.red}; }\n        .stat-card.unchanged { border-left-color: ${COLORS.grayBankDark}; }\n        .stat-label { font-size: 14px; color: ${COLORS.grayMedium}; text-transform: uppercase; letter-spacing: 1px; }\n        .stat-value { font-size: 36px; font-weight: bold; color: ${COLORS.textDark}; margin-top: 5px; }\n        .paragraph { margin: 20px 0; padding: 20px; border-radius: 4px; border-left: 5px solid ${COLORS.grayMedium}; transition: box-shadow 0.2s; }\n        .paragraph:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); }\n        .paragraph.unchanged { background: #fafafa; border-left-color: ${COLORS.grayBankLight}; }\n        .paragraph.modified { background: #fff3f3; border-left-color: ${COLORS.red}; }\n        .paragraph.added { background: #f0f8e8; border-left-color: ${COLORS.greenDark}; }\n        .paragraph.deleted { background: #fff3f3; border-left-color: ${COLORS.red}; opacity: 0.7; }\n        .paragraph-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }\n        .paragraph-index { font-weight: bold; color: ${COLORS.textDark}; }\n        .paragraph-type { padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: bold; text-transform: uppercase; }\n        .paragraph-type.unchanged { background: ${COLORS.grayBankDark}; color: white; }\n        .paragraph-type.modified { background: ${COLORS.red}; color: white; }\n        .paragraph-type.added { background: ${COLORS.greenDark}; color: white; }\n        .paragraph-type.deleted { background: ${COLORS.red}; color: white; }\n        .changes { margin-top: 15px; padding: 15px; background: white; border-radius: 4px; border: 1px solid ${COLORS.grayBankLight}; }\n        .change-label { font-weight: bold; margin-bottom: 10px; color: ${COLORS.duckBlue}; }\n        .change-text { line-height: 1.8; }\n        .change-equal { color: ${COLORS.textDark}; }\n        .change-delete { background: #ffebee; color: ${COLORS.red}; text-decoration: line-through; padding: 2px 4px; border-radius: 2px; }\n        .change-insert { background: #e8f5e9; color: ${COLORS.greenDark}; font-weight: bold; padding: 2px 4px; border-radius: 2px; }\n        .table-container { margin: 20px 0; overflow-x: auto; }\n        table { width: 100%; border-collapse: collapse; margin: 15px 0; }\n        th, td { padding: 12px; text-align: left; border: 1px solid ${COLORS.grayMedium}; }\n        th { background: ${COLORS.duckBlue}; color: white; font-weight: bold; }\n        td { background: white; }\n        td.modified-cell { background: #fff3f3; border-color: ${COLORS.red}; }\n        .filters { margin: 20px 0; padding: 20px; background: #fafafa; border-radius: 4px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; border: 1px solid ${COLORS.grayBankLight}; }\n        .filter-label { font-weight: bold; color: ${COLORS.textDark}; }\n        .filter-btn { padding: 8px 16px; border: 2px solid ${COLORS.duckBlue}; background: white; color: ${COLORS.duckBlue}; border-radius: 4px; cursor: pointer; transition: all 0.3s; font-weight: 500; }\n        .filter-btn.active { background: ${COLORS.duckBlue}; color: white; }\n        .filter-btn:hover { background: ${COLORS.duckBlue}; color: white; transform: translateY(-1px); box-shadow: 0 2px 5px rgba(0, 149, 151, 0.3); }\n        .metadata { background: #fafafa; padding: 20px; border-radius: 4px; margin: 20px 0; border: 1px solid ${COLORS.grayBankLight}; }\n        .metadata-row { display: flex; padding: 8px 0; border-bottom: 1px solid ${COLORS.grayBankLight}; }\n        .metadata-row:last-child { border-bottom: none; }\n        .metadata-label { font-weight: bold; width: 200px; color: ${COLORS.duckBlue}; }\n        .metadata-value { color: ${COLORS.textDark}; }\n        @media print {\n            body { background: white; }\n            .filters { display: none; }\n            .summary-box, .paragraph { break-inside: avoid; }\n        }\n        @media (max-width: 768px) {\n            .container { padding: 15px; }\n            .summary-stats { flex-direction: column; }\n            .summary-stat { margin: 10px 0; }\n        }\n    </style>\n</head>\n<body>\n    <div class=\"container\">\n        <h1>\ud83d\udcca Raport Por\u00f3wnania Dokument\u00f3w</h1>\n        <div class=\"summary-box\">\n            <h3>Podsumowanie Por\u00f3wnania</h3>\n            <div class=\"summary-stats\">\n                <div class=\"summary-stat\"><div class=\"summary-stat-value\" id=\"totalChanges\">0</div><div class=\"summary-stat-label\">\u0141\u0105cznie Zmian</div></div>\n                <div class=\"summary-stat\"><div class=\"summary-stat-value\" id=\"modifiedCount\">0</div><div class=\"summary-stat-label\">Zmodyfikowane</div></div>\n                <div class=\"summary-stat\"><div class=\"summary-stat-value\" id=\"addedCount\">0</div><div class=\"summary-stat-label\">Dodane</div></div>\n                <div class=\"summary-stat\"><div class=\"summary-stat-value\" id=\"deletedCount\">0</div><div class=\"summary-stat-label\">Usuni\u0119te</div></div>\n            </div>\n        </div>\n        <h2>\u2139\ufe0f Informacje</h2><div class=\"metadata\" id=\"metadata\"></div>\n        <h2>\ud83d\udcc8 Statystyki</h2><div class=\"statistics\" id=\"statistics\"></div>\n        <h2>\ud83d\udcdd Paragrafy</h2>\n        <div class=\"filters\">\n            <span class=\"filter-label\">Poka\u017c:</span>\n            <button class=\"filter-btn active\" onclick=\"filterParagraphs('all')\">Wszystkie</button>\n            <button class=\"filter-btn\" onclick=\"filterParagraphs('modified')\">Zmodyfikowane</button>\n            <button class=\"filter-btn\" onclick=\"filterParagraphs('added')\">Dodane</button>\n            <button class=\"filter-btn\" onclick=\"filterParagraphs('deleted')\">Usuni\u0119te</button>\n            <button class=\"filter-btn\" onclick=\"filterParagraphs('unchanged')\">Niezmienione</button>\n        </div>\n        <div id=\"paragraphs\"></div>\n        <h2>\ud83d\udccb Tabele</h2><div id=\"tables\"></div>\n    </div>\n    <script>\n        const fullData = ${JSON.stringify(jsonData)};\n        let currentFilter = 'all';\n        window.addEventListener('DOMContentLoaded', () => { displayResults(); });\n        function displayResults() { displayMetadata(); displaySummary(); displayStatistics(); displayParagraphs(); displayTables(); }\n        function displayMetadata() {\n            const metadata = document.getElementById('metadata');\n            const stats = fullData.statistics;\n            metadata.innerHTML = \\`<div class=\"metadata-row\"><div class=\"metadata-label\">Process ID:</div><div class=\"metadata-value\">\\${fullData.process_id}</div></div><div class=\"metadata-row\"><div class=\"metadata-label\">Document Pair ID:</div><div class=\"metadata-value\">\\${fullData.document_pair_id}</div></div><div class=\"metadata-row\"><div class=\"metadata-label\">Wygenerowano:</div><div class=\"metadata-value\">\\${new Date(fullData.generated_at).toLocaleString('pl-PL')}</div></div><div class=\"metadata-row\"><div class=\"metadata-label\">Wszystkich paragraf\u00f3w:</div><div class=\"metadata-value\">\\${stats.total_paragraphs}</div></div><div class=\"metadata-row\"><div class=\"metadata-label\">Tabel:</div><div class=\"metadata-value\">\\${stats.tables_count || 0}</div></div>\\`;\n        }\n        function displaySummary() {\n            const stats = fullData.statistics;\n            document.getElementById('totalChanges').textContent = stats.total_changes || 0;\n            document.getElementById('modifiedCount').textContent = stats.modified_paragraphs || 0;\n            document.getElementById('addedCount').textContent = stats.added_paragraphs || 0;\n            document.getElementById('deletedCount').textContent = stats.deleted_paragraphs || 0;\n        }\n        function displayStatistics() {\n            const stats = fullData.statistics;\n            const container = document.getElementById('statistics');\n            container.innerHTML = \\`<div class=\"stat-card\"><div class=\"stat-label\">Wszystkie</div><div class=\"stat-value\">\\${stats.total_paragraphs || 0}</div></div><div class=\"stat-card unchanged\"><div class=\"stat-label\">Niezmienione</div><div class=\"stat-value\">\\${stats.unchanged_paragraphs || 0}</div></div><div class=\"stat-card modified\"><div class=\"stat-label\">Zmodyfikowane</div><div class=\"stat-value\">\\${stats.modified_paragraphs || 0}</div></div><div class=\"stat-card added\"><div class=\"stat-label\">Dodane</div><div class=\"stat-value\">\\${stats.added_paragraphs || 0}</div></div><div class=\"stat-card deleted\"><div class=\"stat-label\">Usuni\u0119te</div><div class=\"stat-value\">\\${stats.deleted_paragraphs || 0}</div></div><div class=\"stat-card\"><div class=\"stat-label\">Zmodyfikowane Kom\u00f3rki</div><div class=\"stat-value\">\\${stats.modified_cells || 0}</div></div>\\`;\n        }\n        function displayParagraphs() {\n            const container = document.getElementById('paragraphs');\n            const paragraphs = fullData.paragraphs || [];\n            let html = '';\n            paragraphs.forEach(para => {\n                if (currentFilter !== 'all' && para.type !== currentFilter) return;\n                html += \\`<div class=\"paragraph \\${para.type}\" data-type=\"\\${para.type}\"><div class=\"paragraph-header\"><span class=\"paragraph-index\">Paragraf #\\${para.index}</span><span class=\"paragraph-type \\${para.type}\">\\${getTypeName(para.type)}</span></div><div class=\"paragraph-content\"><strong>Tre\u015b\u0107:</strong><br>\\${escapeHtml(para.text)}</div>\\`;\n                if (para.type === 'modified' && para.changes) {\n                    html += \\`<div class=\"changes\"><div class=\"change-label\">Zmiany:</div><div class=\"change-text\">\\${renderChanges(para.changes)}</div></div>\\`;\n                    if (para.old_text) html += \\`<div style=\"margin-top: 15px;\"><strong>Stara tre\u015b\u0107:</strong><br><em style=\"color: #999;\">\\${escapeHtml(para.old_text)}</em></div>\\`;\n                }\n                if (para.type === 'deleted' && para.old_text) html += \\`<div style=\"margin-top: 15px;\"><strong>Usuni\u0119ta tre\u015b\u0107:</strong><br><em style=\"color: #999;\">\\${escapeHtml(para.old_text)}</em></div>\\`;\n                html += \\`</div>\\`;\n            });\n            if (html === '') html = '<p style=\"text-align: center; color: #999; padding: 40px;\">Brak paragraf\u00f3w do wy\u015bwietlenia</p>';\n            container.innerHTML = html;\n        }\n        function displayTables() {\n            const container = document.getElementById('tables');\n            const tables = fullData.tables || [];\n            if (tables.length === 0) { container.innerHTML = '<p style=\"text-align: center; color: #999; padding: 20px;\">Brak tabel w dokumencie</p>'; return; }\n            let html = '';\n            tables.forEach((table, idx) => {\n                html += \\`<h3>Tabela #\\${table.index}</h3><div class=\"table-container\"><table>\\`;\n                if (table.rows && table.rows.length > 0) {\n                    html += '<thead><tr>';\n                    table.rows[0].forEach(cell => { html += \\`<th>\\${escapeHtml(cell)}</th>\\`; });\n                    html += '</tr></thead><tbody>';\n                    for (let i = 1; i < table.rows.length; i++) {\n                        html += '<tr>';\n                        table.rows[i].forEach((cell, colIdx) => {\n                            const isModified = isTableCellModified(table, i, colIdx);\n                            html += \\`<td class=\"\\${isModified ? 'modified-cell' : ''}\">\\${escapeHtml(cell)}</td>\\`;\n                        });\n                        html += '</tr>';\n                    }\n                    html += '</tbody></table>';\n                    if (table.changes && table.changes.length > 0) {\n                        html += '<div class=\"changes\" style=\"margin-top: 10px;\"><div class=\"change-label\">Zmiany w tabeli:</div><ul>';\n                        table.changes.forEach(change => { html += \\`<li>Wiersz \\${change.row_index}, Kolumna \\${change.col_index}: <span class=\"change-delete\">\\${escapeHtml(change.old_value)}</span> \u2192 <span class=\"change-insert\">\\${escapeHtml(change.new_value)}</span></li>\\`; });\n                        html += '</ul></div>';\n                    }\n                }\n                html += '</div>';\n            });\n            container.innerHTML = html;\n        }\n        function isTableCellModified(table, rowIdx, colIdx) { if (!table.changes) return false; return table.changes.some(change => change.row_index === rowIdx && change.col_index === colIdx); }\n        function renderChanges(changes) {\n            let html = '';\n            changes.forEach(change => {\n                const text = escapeHtml(change.text);\n                if (change.operation === 'delete') html += \\`<span class=\"change-delete\">\\${text}</span>\\`;\n                else if (change.operation === 'insert') html += \\`<span class=\"change-insert\">\\${text}</span>\\`;\n                else html += \\`<span class=\"change-equal\">\\${text}</span>\\`;\n            });\n            return html;\n        }\n        function filterParagraphs(type) {\n            currentFilter = type;\n            document.querySelectorAll('.filter-btn').forEach(btn => { btn.classList.remove('active'); });\n            event.target.classList.add('active');\n            displayParagraphs();\n        }\n        function getTypeName(type) { const names = {'unchanged': 'Niezmieniony', 'modified': 'Zmodyfikowany', 'added': 'Dodany', 'deleted': 'Usuni\u0119ty'}; return names[type] || type; }\n        function escapeHtml(text) { if (!text) return ''; const div = document.createElement('div'); div.textContent = text; return div.innerHTML; }\n    </script>\n</body>\n</html>`;\n\nreturn {\n  json: {\n    success: true,\n    message: 'HTML report wygenerowany z bankowymi kolorami',\n    filename: `report_${$json.process_id}.html`,\n    colors_used: 'Oficjalna paleta bankowa Credit Agricole'\n  },\n  binary: {\n    data: Buffer.from(htmlContent, 'utf-8'),\n    fileName: `comparison_report_${$json.process_id}.html`,\n    mimeType: 'text/html',\n    fileExtension: 'html'\n  }\n};"
      },
      "id": "generate-html-report-new",
      "name": "Generate HTML Report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2904,
        256
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a5be2152-b7b0-4f5a-8c79-0a94acfe1a75",
              "name": "File_1",
              "value": "=fileName = {{ $binary.data}}_item_{{ $itemIndex }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1056,
        1200
      ],
      "id": "33518954-3600-493f-99c0-78a700230097",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "jsCode": "const newItems = [];\n\nfor (const item of items) {\n  // je\u015bli masz w jednym itemie oba pliki pod r\u00f3\u017cnymi kluczami w odpowiedzi HTTP, odpowiednio je wydziel\n  if (item.binary && item.binary.data) {\n    // przyk\u0142adowo robimy duplikat binary i nadajemy w\u0142asne key\n    const plik1 = {\n      json: {},\n      binary: {\n        file1: item.binary.data  // pierwszy plik\n      }\n    };\n    const plik2 = {\n      json: {},\n      binary: {\n        file2: item.binary.data2 // drugi plik; tu musisz wskaza\u0107 drugi field\n      }\n    };\n    newItems.push(plik1, plik2);\n  }\n}\n\nreturn newItems;\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1104,
        1360
      ],
      "id": "670607c8-020a-47fd-8ece-ede4390b53cc",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "jsCode": "const results = [];\nfor (const item of items) {\n  if (item.binary.file1) {\n    results.push({ json: {}, binary: { data: item.binary.file1 } });\n  }\n  if (item.binary.file2) {\n    results.push({ json: {}, binary: { data: item.binary.file2 } });\n  }\n}\nreturn results;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -816,
        1360
      ],
      "id": "4723d593-5355-498b-bf79-d0233fd29fa8",
      "name": "Code in JavaScript1"
    },
    {
      "parameters": {
        "path": "=/Testy/{{ $binary.data.fileName.replace('.docx', '_' + $itemIndex +'.docx') }}",
        "binaryData": true
      },
      "type": "n8n-nodes-base.dropbox",
      "typeVersion": 1,
      "position": [
        -576,
        1312
      ],
      "id": "154019d7-d3f4-4f35-b34a-ab983be28020",
      "name": "Upload a file",
      "credentials": {
        "dropboxApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "path": "/Testy/Zal_1_Procedura_CA_110_2020_0.docx",
        "binaryPropertyName": "new_file"
      },
      "type": "n8n-nodes-base.dropbox",
      "typeVersion": 1,
      "position": [
        32,
        1728
      ],
      "id": "99974419-67c4-4aee-9b64-5fd9696b2caa",
      "name": "Download a file",
      "credentials": {
        "dropboxApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        960,
        736
      ],
      "id": "7a2f7f19-94ba-4f74-ba8e-567dbc38dfc8",
      "name": "Merge"
    },
    {
      "parameters": {},
      "id": "1878afb1-1a60-4a7a-aa07-9c4f15fa8dc3",
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -112,
        1824
      ]
    },
    {
      "parameters": {
        "operation": "download",
        "path": "/Testy/Zal_1_Procedura_CA_110_2020_1.docx",
        "binaryPropertyName": "old_file"
      },
      "type": "n8n-nodes-base.dropbox",
      "typeVersion": 1,
      "position": [
        96,
        1936
      ],
      "id": "62bf988a-2571-4bf7-a654-59c9a42d7960",
      "name": "Download a file1",
      "credentials": {
        "dropboxApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn [\n  {\n    json:{},\n    binary: {\n      data0: items[0].binary.data,\n      data1: items[1].binary.data,\n      \n    },\n  },\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        352,
        384
      ],
      "id": "8e7a97ef-9ae2-4ccc-9e18-f6d7385d305b",
      "name": "Code in JavaScript2"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Przeanalizuj za\u0142\u0105czony plik z wynikami por\u00f3wnania dokument\u00f3w.\n\nPlik JSON zawiera:\n- statistics: zagregowane statystyki zmian\n- paragraphs: lista wszystkich paragraf\u00f3w z nowego dokumentu oraz usuni\u0119tych ze starego\n- tables: lista tabel ze zmianami w kom\u00f3rkach\n\nKa\u017cdy paragraf ma:\n- index: pozycja\n- text: aktualna tre\u015b\u0107 (z nowego dokumentu)\n- type: unchanged/modified/added/deleted\n- old_text: poprzednia tre\u015b\u0107 (dla modified i deleted)\n- changes: szczeg\u00f3\u0142owe zmiany s\u0142owo po s\u0142owie (dla modified)\n\nPrzygotuj szczeg\u00f3\u0142owy raport zawieraj\u0105cy:\n\n1. EXECUTIVE SUMMARY\n   - \u0141\u0105cznie zmian: [liczba]\n   - Charakterystyka: [g\u0142\u00f3wnie co?]\n   - Ocena: [istotne/drobne]\n\n2. ZMIANY KRYTYCZNE\n   Lista zmian wymagaj\u0105cych natychmiastowej uwagi (definicje, liczby, wymagania prawne)\n   Format: Paragraf #X: [opis] | Stare: [...] | Nowe: [...] | Wp\u0142yw: [...]\n\n3. ZMIANY ISTOTNE\n   Lista wa\u017cnych zmian (nazwy, terminy, procedury)\n   Format: Paragraf #X: [opis zmiany]\n\n4. ZMIANY MNIEJSZE\n   Lista mniejszych zmian (stylistyka, formatowanie)\n\n5. DODANE TRE\u015aCI\n   Lista nowych paragraf\u00f3w (type=\"added\")\n   Format: Paragraf #X: [tre\u015b\u0107]\n\n6. USUNI\u0118TE TRE\u015aCI\n   Lista usuni\u0119tych paragraf\u00f3w (type=\"deleted\")\n   Format: Paragraf #X: [tre\u015b\u0107]\n\n7. ZMIANY W TABELACH\n   Lista zmian w kom\u00f3rkach tabel\n   Format: Tabela #X, Wiersz Y, Kolumna Z: [stara] \u2192 [nowa]\n\n8. REKOMENDACJE\n   - Dzia\u0142ania do podj\u0119cia\n   - Obszary wymagaj\u0105ce weryfikacji\n   - Potencjalne ryzyka\n\nZwr\u00f3\u0107 szczeg\u00f3ln\u0105 uwag\u0119 na:\n- Zmiany w liczbach i warto\u015bciach liczbowych\n- Zmiany w nazwach departament\u00f3w, r\u00f3l, stanowisk\n- Zmiany w definicjach i terminach\n- Zmiany w wymaganiach i procedurach\n- Usuni\u0119te wymagania (potencjalne problemy compliance)\n- Dodane wymagania (nowe obowi\u0105zki)\n\n\nPlik JSON:\nWej\u015bcie:\n{{ JSON.stringify($json.data) }}",
        "options": {
          "passthroughBinaryImages": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        3344,
        464
      ],
      "id": "0febf816-1899-4094-aa38-0c5445fe99f0",
      "name": "AI Agent1"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "azure-gpt-5-chat",
          "mode": "list",
          "cachedResultName": "azure-gpt-5-chat"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        3424,
        688
      ],
      "id": "b5c0e394-d357-4594-89c3-feccf7db5f86",
      "name": "OpenAI Chat Model3",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "GPT - analiza dw\u00f3ch wersji dokumentu i przygotowanie raportu zmian.",
        "height": 112,
        "width": 166,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3360,
        336
      ],
      "typeVersion": 1,
      "id": "0fd854c5-0f41-402d-bfa7-01cddf3a1e11",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "operation": "fromJson",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        2912,
        480
      ],
      "id": "e1c483ef-98b9-4eaf-8f54-206afa7dd080",
      "name": "Extract from File1"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Przeanalizuj plik JSON, kt\u00f3ry zawiera por\u00f3wnanie starej i nowej wersji dokumentu. \nSkup si\u0119 wy\u0142\u0105cznie na zmianach o merytorycznym znaczeniu. Pomi\u0144 zmiany stylistyczne, redakcyjne, formatowanie oraz drobne korekty j\u0119zykowe.\n\nTwoim zadaniem jest przygotowanie kr\u00f3tkiego podsumowania zarz\u0105dczego w formie kilku wypunktowanych sekcji:\n\n1. **Najwa\u017cniejsze zmiany** \u2013 maksymalnie 5\u20137 punkt\u00f3w, ka\u017cdy kr\u00f3tko opisuje zmian\u0119 i wskazuje jej typ (np. nowy obowi\u0105zek, zmiana warto\u015bci liczbowej, usuni\u0119cie wymogu, zmiana terminu).\n2. **Potencjalny wp\u0142yw** \u2013 jedno\u2013dwa zdania przy ka\u017cdej zmianie, opisuj\u0105ce mo\u017cliwe konsekwencje biznesowo/prawne.\n3. **Obszary wymagaj\u0105ce decyzji lub weryfikacji** \u2013 lista kluczowych miejsc w dokumencie, gdzie potrzebne jest zatwierdzenie, analiza ryzyka lub zmiana procedur.\n\n**Dodatkowe zasady:**\n- Grupuj podobne zmiany razem (np. wszystkie zmiany dotycz\u0105ce termin\u00f3w w jednym punkcie).\n- Nie przytaczaj pe\u0142nych paragraf\u00f3w ani d\u0142ugich cytat\u00f3w, podawaj tylko zwi\u0119z\u0142y opis.\n- Je\u015bli zmiana dotyczy liczb lub warto\u015bci \u2013 podaj star\u0105 i now\u0105 warto\u015b\u0107 w jednym zdaniu.\n- Je\u017celi nie ma \u017cadnych istotnych zmian \u2013 zwr\u00f3\u0107 komunikat \u201eBrak zmian merytorycznych wp\u0142ywaj\u0105cych na procesy lub obowi\u0105zki\u201d.\n\nPlik JSON:\n{{ JSON.stringify($json.data) }}",
        "options": {
          "passthroughBinaryImages": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        3408,
        -96
      ],
      "id": "35bc9b5e-fb45-43bc-8f21-0745501c92b3",
      "name": "AI Agent2"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "azure-gpt-5-chat",
          "mode": "list",
          "cachedResultName": "azure-gpt-5-chat"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        3488,
        128
      ],
      "id": "ba7904a5-610b-4467-8e1d-ddfbd0b2cf9a",
      "name": "OpenAI Chat Model5",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "GPT - analiza dw\u00f3ch wersji dokumentu i przygotowanie raportu zmian.",
        "height": 112,
        "width": 166,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3424,
        -224
      ],
      "typeVersion": 1,
      "id": "674b4d93-1325-41b3-b4c5-6d52bffbf5e7",
      "name": "Sticky Note7"
    },
    {
      "parameters": {
        "operation": "download",
        "path": "/Testy/Results_reklamacje.json"
      },
      "type": "n8n-nodes-base.dropbox",
      "typeVersion": 1,
      "position": [
        2496,
        480
      ],
      "id": "2af32e91-10d2-4844-82df-4ab7c15836a3",
      "name": "Download a file2",
      "credentials": {
        "dropboxApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Obliczanie_zakresu_czasu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Obliczanie_zakresu_czasu",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Check_if_exist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select_no_1": {
      "main": [
        [
          {
            "node": "Variable js",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select_no_2": {
      "main": [
        [
          {
            "node": "Variable_js2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check_if_exist": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert_into_db": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Variable js": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Variable_js2": {
      "main": [
        [
          {
            "node": "Insert_into_db2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Select_no_2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert_into_db2": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Event_log1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Select_no3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select_no3": {
      "main": [
        [
          {
            "node": "Variable_js3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Variable_js3": {
      "main": [
        [
          {
            "node": "insert_do_pobrania",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "Code in JavaScript2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Insert_into_db",
            "type": "main",
            "index": 0
          },
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          },
          {
            "node": "Event_log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Obliczanie_zakresu_czasu": {
      "main": [
        [
          {
            "node": "Select_no_1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "insert_do_pobrania": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Old Document": {
      "main": [
        []
      ]
    },
    "Read New Document": {
      "main": [
        []
      ]
    },
    "Upload Documents": {
      "main": [
        [
          {
            "node": "Start Processing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start Processing": {
      "main": [
        [
          {
            "node": "Wait 3 Seconds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 3 Seconds": {
      "main": [
        [
          {
            "node": "Check Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Status": {
      "main": [
        [
          {
            "node": "Is Completed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Completed?": {
      "main": [
        [
          {
            "node": "Get Full Result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 2 Seconds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 Seconds": {
      "main": [
        [
          {
            "node": "Check Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Full Result": {
      "main": [
        [
          {
            "node": "Get Modified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Modified": {
      "main": [
        [
          {
            "node": "Get Added",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Added": {
      "main": [
        [
          {
            "node": "Get Deleted",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Deleted": {
      "main": [
        [
          {
            "node": "Combine All Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine All Results": {
      "main": [
        [
          {
            "node": "Final Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Final Summary": {
      "main": [
        [
          {
            "node": "Generate HTML Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        []
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload a file": {
      "main": [
        []
      ]
    },
    "Download a file": {
      "main": [
        []
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "Download a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download a file1": {
      "main": [
        []
      ]
    },
    "Code in JavaScript2": {
      "main": [
        [
          {
            "node": "Upload Documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File1": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI Agent2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model5": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent2",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download a file2": {
      "main": [
        [
          {
            "node": "Extract from File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b84c6b0c-bee0-4a63-a584-cf4bc413f743",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "fqmBPbK8WcXEvmEP",
  "tags": []
}