{
  "name": "Muhasebe Otomasyonu",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Excel",
        "formFields": {
          "values": [
            {
              "fieldLabel": "banka",
              "fieldType": "checkbox",
              "fieldOptions": {
                "values": [
                  {
                    "option": "ziraat"
                  },
                  {
                    "option": "garanti"
                  },
                  {
                    "option": "yap\u0131kredi"
                  }
                ]
              }
            },
            {
              "fieldLabel": "data",
              "fieldType": "file"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        -32,
        -16
      ],
      "id": "f60d4f60-ffa0-446e-8e24-fd4dbb9b968e",
      "name": "On form submission"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.banka[0] }}\n",
                    "rightValue": "yap\u0131kredi",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "id": "630e1252-9f71-44ad-90ad-22cc9193fa5e"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "yap\u0131kredi"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "ac422f6a-fee8-46b3-82c8-3e3d2c33733f",
                    "leftValue": "={{ $json.banka[0] }}\n",
                    "rightValue": "ziraat",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "ziraat"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "fff0b43c-c1a5-439c-80f8-ee13054f6717",
                    "leftValue": "={{ $json.banka[0] }}\n",
                    "rightValue": "garanti",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "garanti"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        176,
        -32
      ],
      "id": "ce996d67-f353-44ce-ac3d-5f79d272e6e6",
      "name": "Switch"
    },
    {
      "parameters": {
        "operation": "xls",
        "options": {
          "headerRow": true,
          "range": "A11:Z99"
        }
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        432,
        -176
      ],
      "id": "9b5acc54-0aad-4289-bfdc-fecef08f3c6a",
      "name": "yap\u0131kredi"
    },
    {
      "parameters": {
        "operation": "xls",
        "options": {
          "headerRow": true,
          "range": "A12:Z99"
        }
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        432,
        -16
      ],
      "id": "69b0b2e5-94bf-4a95-8f18-c8cca1f69512",
      "name": "ziraat"
    },
    {
      "parameters": {
        "operation": "xls",
        "options": {
          "headerRow": true,
          "range": "A15:Z99"
        }
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        432,
        144
      ],
      "id": "18170302-307d-422f-9a44-8dca33efc2c1",
      "name": "garanti"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk",
          "mode": "list",
          "cachedResultName": "Ta\u00e7 Ambalaj Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sayfa1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Banka": "yapikredi",
            "Tarih": "={{ $json.Tarih }}",
            "Saat": "={{ $json.Saat }}",
            "Banka \u0130\u015flem T\u00fcr\u00fc": "={{ $json['\u0130\u015flem'] }}",
            "Kanal": "={{ $json.Kanal }}",
            "Referans No": "={{ $json['Referans No'] }}",
            "A\u00e7\u0131klama": "={{ $json['A\u00e7\u0131klama'] }}",
            "Bakiye": "={{ $json.Bakiye }}",
            "Para Birimi": "={{ $json['D\u00f6viz Cinsi'] === 'TL' ? 'TRY' : $json['D\u00f6viz Cinsi'] }}\n",
            "Tutar": "={{ Math.round(Number(String($json['\u0130\u015flem Tutar\u0131']).replace(/[\\r\\n\"]/g,'').trim()) * 100) / 100 * (Number(String($json['\u0130\u015flem Tutar\u0131']).replace(/[\\r\\n\"]/g,'').trim()) < 0 ? -1 : 1) }}\n",
            "\u0130\u015flem Y\u00f6n\u00fc": "={{ $json['\u0130\u015flem Tutar\u0131'] < 0 ? '\u00c7\u0131k\u0131\u015f' : 'Giri\u015f' }}",
            "Hesap Ad\u0131": "Yap\u0131Kredi-1",
            "Tarih-Saat": "={{ $json.Saat ? ($json.Tarih + ' ' + $json.Saat) : ($json.Tarih + ' 00:00:00') }}\n"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Banka",
              "displayName": "Banka",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Hesap Ad\u0131",
              "displayName": "Hesap Ad\u0131",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tarih",
              "displayName": "Tarih",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Saat",
              "displayName": "Saat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tarih-Saat",
              "displayName": "Tarih-Saat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Banka \u0130\u015flem T\u00fcr\u00fc",
              "displayName": "Banka \u0130\u015flem T\u00fcr\u00fc",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Kanal",
              "displayName": "Kanal",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Referans No",
              "displayName": "Referans No",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "A\u00e7\u0131klama",
              "displayName": "A\u00e7\u0131klama",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "\u0130\u015flem Y\u00f6n\u00fc",
              "displayName": "\u0130\u015flem Y\u00f6n\u00fc",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tutar",
              "displayName": "Tutar",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Para Birimi",
              "displayName": "Para Birimi",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Bakiye",
              "displayName": "Bakiye",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        688,
        -176
      ],
      "id": "992fe0bb-13e9-4127-a871-712019f73792",
      "name": "Append row in sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk",
          "mode": "list",
          "cachedResultName": "Ta\u00e7 Ambalaj Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sayfa1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Tarih": "={{ String($json.Tarih).replaceAll('/','.') }}\n",
            "Saat": "=",
            "Banka \u0130\u015flem T\u00fcr\u00fc": "=",
            "Kanal": "=",
            "Referans No": "={{ $json['Fi\u015f No'] }}\n",
            "A\u00e7\u0131klama": "={{ $json['A\u00e7\u0131klama'] }}",
            "Bakiye": "={{ $json.Bakiye }}",
            "Para Birimi": "=TRY\n",
            "Tutar": "={{ Math.abs($json['\u0130\u015flem Tutar\u0131']) }}",
            "\u0130\u015flem Y\u00f6n\u00fc": "={{ $json['\u0130\u015flem Tutar\u0131'] < 0 ? '\u00c7\u0131k\u0131\u015f' : 'Giri\u015f' }}",
            "Hesap Ad\u0131": "Ziraat-1",
            "Tarih-Saat": "={{ $json.Saat ? ($json.Tarih + ' ' + $json.Saat) : ($json.Tarih + ' 00:00:00') }}\n",
            "Banka": "ziraat"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Banka",
              "displayName": "Banka",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Hesap Ad\u0131",
              "displayName": "Hesap Ad\u0131",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tarih",
              "displayName": "Tarih",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Saat",
              "displayName": "Saat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tarih-Saat",
              "displayName": "Tarih-Saat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Banka \u0130\u015flem T\u00fcr\u00fc",
              "displayName": "Banka \u0130\u015flem T\u00fcr\u00fc",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Kanal",
              "displayName": "Kanal",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Referans No",
              "displayName": "Referans No",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "A\u00e7\u0131klama",
              "displayName": "A\u00e7\u0131klama",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "\u0130\u015flem Y\u00f6n\u00fc",
              "displayName": "\u0130\u015flem Y\u00f6n\u00fc",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tutar",
              "displayName": "Tutar",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Para Birimi",
              "displayName": "Para Birimi",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Bakiye",
              "displayName": "Bakiye",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        816,
        -16
      ],
      "id": "e1268d59-3d7d-4668-a297-9ca2dd0bb67e",
      "name": "Append row in sheet1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "function normalizeDateTR(v) {\n  if (!v) return null;\n  let s = String(v).trim().replaceAll('/', '.');\n  if (!/^\\d{1,2}\\.\\d{1,2}\\.\\d{4}$/.test(s)) return null;\n\n  // 1 haneli g\u00fcn/ay gelirse 0 ekleyelim (1.1.2026 -> 01.01.2026)\n  const [d, m, y] = s.split('.');\n  const dd = d.padStart(2, '0');\n  const mm = m.padStart(2, '0');\n  return `${dd}.${mm}.${y}`;\n}\n\nfunction normalizeTRNumber(v) {\n  if (v === null || v === undefined) return null;\n\n  // E\u011fer zaten number geldiyse (Excel bazen b\u00f6yle veriyor)\n  if (typeof v === 'number') {\n    // 2 ondal\u0131k kural\u0131: \u00e7ok b\u00fcy\u00fck ve \"kuru\u015f kaym\u0131\u015f\" gibi g\u00f6r\u00fcn\u00fcyorsa /100 d\u00fczelt\n    // Heuristik: mutlak de\u011fer >= 1000000 ve tam say\u0131 ise, ama ger\u00e7ek tutar normalde k\u00fcsuratl\u0131 olabilir.\n    // \u00d6zellikle 133750,41 -> 13375041 d\u00f6n\u00fc\u015f\u00fcm\u00fcn\u00fc burada yakal\u0131yoruz.\n    const abs = Math.abs(v);\n\n    // E\u011fer de\u011fer tam say\u0131 ve son 2 haneyi kuru\u015f kabul edersek mant\u0131kl\u0131 olur\n    // \u00d6rn: 13375041 -> 133750.41 ( /100 )\n    if (Number.isInteger(v) && abs >= 1000000) {\n      return v / 100;\n    }\n    return v;\n  }\n\n  // String ise TR format parse\n  let s = String(v).replace(/[\\r\\n\"]/g, '').trim();\n  if (!s) return null;\n\n  // bo\u015fluklar\u0131 da temizle\n  s = s.replace(/\\s/g, '');\n\n  // 1.700.000,50 -> 1700000.50\n  // 133.750,41 -> 133750.41\n  // -500.000 -> -500000\n  const normalized = s.replace(/\\./g, '').replace(/,/g, '.');\n  const n = Number(normalized);\n  return Number.isFinite(n) ? n : null;\n}\n\nconst out = [];\n\nfor (const item of $input.all()) {\n  const r = item.json;\n\n  const tarih = normalizeDateTR(r[\"Tarih\"]);\n  if (!tarih) continue;\n\n  const tutar = normalizeTRNumber(r[\"\u0130\u015flem Tutar\u0131\"]);\n  if (tutar === null) continue;\n\n  const bakiye = normalizeTRNumber(r[\"Bakiye\"]);\n\n  out.push({\n    json: {\n      ...r,\n      Tarih: tarih,\n      \"\u0130\u015flem Tutar\u0131\": tutar,\n      Bakiye: bakiye\n    }\n  });\n}\n\nreturn out;\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        640,
        -16
      ],
      "id": "a70520cc-ab08-4d7d-aca8-8a5b44e26d7d",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk",
          "mode": "list",
          "cachedResultName": "Ta\u00e7 Ambalaj Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sayfa1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Banka": "garanti",
            "Tarih": "={{ $json.Tarih }}",
            "Saat": "=",
            "Banka \u0130\u015flem T\u00fcr\u00fc": "={{ $json.Etiket }}",
            "Kanal": "=",
            "Referans No": "={{ $json['Dekont No'] }}\n",
            "A\u00e7\u0131klama": "={{ $json['A\u00e7\u0131klama'] }}",
            "Bakiye": "={{ $json.Bakiye }}",
            "Para Birimi": "=TRY\n",
            "Tutar": "={{ Math.round(Number(String($json['Tutar']).replace(/[\\r\\n\"]/g,'').trim()) * 100) / 100 * (Number(String($json['Tutar']).replace(/[\\r\\n\"]/g,'').trim()) < 0 ? -1 : 1) }}\n",
            "\u0130\u015flem Y\u00f6n\u00fc": "={{ Number($json.Tutar) < 0 ? '\u00c7\u0131k\u0131\u015f' : 'Giri\u015f' }}\n",
            "Hesap Ad\u0131": "garanti-1",
            "Tarih-Saat": "={{ $json.Saat ? ($json.Tarih + ' ' + $json.Saat) : ($json.Tarih + ' 00:00:00') }}\n"
          },
          "matchingColumns": [
            "Bakiye"
          ],
          "schema": [
            {
              "id": "Banka",
              "displayName": "Banka",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Hesap Ad\u0131",
              "displayName": "Hesap Ad\u0131",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tarih",
              "displayName": "Tarih",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Saat",
              "displayName": "Saat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tarih-Saat",
              "displayName": "Tarih-Saat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Banka \u0130\u015flem T\u00fcr\u00fc",
              "displayName": "Banka \u0130\u015flem T\u00fcr\u00fc",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Kanal",
              "displayName": "Kanal",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Referans No",
              "displayName": "Referans No",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "A\u00e7\u0131klama",
              "displayName": "A\u00e7\u0131klama",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "\u0130\u015flem Y\u00f6n\u00fc",
              "displayName": "\u0130\u015flem Y\u00f6n\u00fc",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tutar",
              "displayName": "Tutar",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Para Birimi",
              "displayName": "Para Birimi",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Bakiye",
              "displayName": "Bakiye",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        672,
        144
      ],
      "id": "1dc0f4c6-e1b2-481e-abd2-d598ee725f81",
      "name": "Append row in sheet2",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -80,
        448
      ],
      "id": "26da089e-df44-421a-b040-adeac4cb76a3",
      "name": "When clicking \u2018Execute workflow\u2019"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk",
          "mode": "list",
          "cachedResultName": "Ta\u00e7 Ambalaj Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sayfa1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/17nuoo3vJEItOKHkEp6Qb7VoAs6FL3WrJLmKwmvT5qpk/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        128,
        448
      ],
      "id": "32169fa2-b534-4e65-a088-18eb348b9142",
      "name": "master_excel",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={\n  \"Banka\": \"{{ $json.Banka }}\",\n  \"Hesap Ad\u0131\": \"{{ $json['Hesap Ad\u0131'] }}\",\n  \"Tarih\": \"{{ $json.Tarih }}\",\n  \"Saat\": \"{{ $json.Saat }}\",\n  \"Tarih-Saat\": \"{{ $json['Tarih-Saat'] }}\",\n  \"Banka \u0130\u015flem T\u00fcr\u00fc\": \"{{ $json['Banka \u0130\u015flem T\u00fcr\u00fc'] }}\",\n  \"Kanal\": \"{{ $json.Kanal }}\",\n  \"Referans No\": \"{{ $json['Referans No'] }}\",\n  \"A\u00e7\u0131klama\": \"{{ $json['A\u00e7\u0131klama'] }}\",\n  \"\u0130\u015flem Y\u00f6n\u00fc\": \"{{ $json['\u0130\u015flem Y\u00f6n\u00fc'] }}\",\n  \"Tutar\": {{ $json.Tutar }},\n  \"Para Birimi\": \"{{ $json['Para Birimi'] }}\",\n  \"Bakiye\": {{ $json.Bakiye }}\n}",
        "options": {
          "systemMessage": "You are a financial transaction classification and reconciliation agent.\n\nYour job: given ONE bank transaction record (fields provided in the input JSON), you must produce a STRICT JSON output that:\n1) Classifies the transaction into a standardized category\n2) Extracts and normalizes the counterparty name (if any)\n3) Detects bank fees/commissions/taxes\n4) Flags whether this record is likely part of an interbank transfer (bank-to-bank movement) and provides matching hints\n5) Produces confidence scores and short reasoning notes\n\nIMPORTANT RULES\n- Use ONLY the information inside the input JSON. Do NOT assume any external facts.\n- Output MUST be valid JSON only. No markdown, no extra text.\n- If you are unsure, set category to \"other\" and reduce confidence.\n- Never invent a counterparty. If missing/unknown, use null.\n\nINPUT FIELDS (exact names)\n- Banka\n- Hesap Ad\u0131\n- Tarih\n- Saat\n- Tarih-Saat\n- Banka \u0130\u015flem T\u00fcr\u00fc\n- Kanal\n- Referans No\n- A\u00e7\u0131klama\n- \u0130\u015flem Y\u00f6n\u00fc\n- Tutar\n- Para Birimi\n- Bakiye\n\nNORMALIZATION\n- Normalize all detected party names to uppercase Turkish-friendly ASCII where possible (keep \u015e/\u0130/\u011e/\u00dc/\u00d6/\u00c7 if present; otherwise do not try to \u201ccorrect\u201d spelling).\n- Trim extra spaces, remove repeated punctuation, remove obvious bank boilerplate words when extracting party names (e.g., \"G\u00d6ND:\", \"GONDEREN\", \"ALICI\", \"A\u00c7IKLAMA\", \"REF\", \"IBAN\", \"EFT\", \"HAVALE\", \"FAST\") but keep the core company/person name.\n- If A\u00e7\u0131klama contains \u201cM\u00dcKERRER \u00d6DEMEN\u0130N \u0130ADES\u0130 / MUKERRER ODEMENIN IAD\u2026\u201d treat it as a refund/return, and set sub_tag accordingly.\n\nCATEGORIES (choose ONE)\n- incoming_customer_payment\n- outgoing_supplier_payment\n- interbank_transfer\n- cash_withdrawal\n- cash_deposit\n- card_purchase\n- pos_collection\n- fuel\n- tax_fee\n- bank_fee_commission\n- payroll\n- refund_return\n- loan_installment\n- credit_card_payment\n- fx_exchange\n- investment\n- other\n\nSUB_TAGS (optional, choose 0+)\nExamples: \"duplicate_payment_refund\", \"eft\", \"havale\", \"fast\", \"pos\", \"commission\", \"bsmv\", \"kkdf\", \"interest\", \"salary\", \"fuel_station\", \"invoice_payment\", \"rent\", \"subscription\"\n\nINTERBANK TRANSFER DETECTION (very important)\nMark \"possible_interbank_transfer\": true if ANY of these patterns fit:\n- Banka \u0130\u015flem T\u00fcr\u00fc or A\u00e7\u0131klama contains EFT/HAVALE/FAST and counterparty looks like YOUR OTHER BANK / your own name / same business name\n- A\u00e7\u0131klama includes phrases like \"HESAPLAR ARASI\", \"KENDI HESABIM\", \"BANKALAR ARASI\", \"VIRMAN\", \"TRANSFER\"\n- The record looks like self-transfer: counterparty is missing, generic, or equals Hesap Ad\u0131\n\nIf you mark possible_interbank_transfer true, also output \"match_hint\" containing:\n- amount (Tutar)\n- currency (Para Birimi)\n- time_window_hours: 36\n- direction_hint: if \u0130\u015flem Y\u00f6n\u00fc indicates outgoing, then you expect an incoming record elsewhere with same amount; if incoming, expect an outgoing elsewhere.\n\nDIRECTION HANDLING\n- Determine \"direction\": \"in\" or \"out\" from \u0130\u015flem Y\u00f6n\u00fc.\n  If \u0130\u015flem Y\u00f6n\u00fc is unclear, infer from Banka \u0130\u015flem T\u00fcr\u00fc/A\u00e7\u0131klama keywords, otherwise set \"unknown\".\n\nCOUNTERPARTY EXTRACTION\n- Extract \"counterparty_name\" primarily from A\u00e7\u0131klama.\n- If A\u00e7\u0131klama includes \"G\u00d6ND:\" / \"GOND:\" / \"GONDEREN:\" => that is the sender name (counterparty).\n- If A\u00e7\u0131klama includes \"ALICI:\" => that is the receiver name (counterparty).\n- If none, try Banka \u0130\u015flem T\u00fcr\u00fc and Kanal for hints; otherwise null.\n\nOUTPUT JSON SCHEMA (MUST FOLLOW)\n{\n  \"source\": {\n    \"bank\": string,\n    \"account_name\": string,\n    \"reference_no\": string|null,\n    \"datetime\": string|null\n  },\n  \"transaction\": {\n    \"direction\": \"in\"|\"out\"|\"unknown\",\n    \"amount\": number,\n    \"currency\": string|null,\n    \"balance\": number|null\n  },\n  \"classification\": {\n    \"category\": string,\n    \"sub_tags\": [string],\n    \"confidence\": number\n  },\n  \"counterparty\": {\n    \"name\": string|null,\n    \"type\": \"customer\"|\"supplier\"|\"bank\"|\"government\"|\"person\"|\"unknown\"|null,\n    \"confidence\": number\n  },\n  \"interbank_reconciliation\": {\n    \"possible_interbank_transfer\": boolean,\n    \"match_hint\": {\n      \"amount\": number,\n      \"currency\": string|null,\n      \"time_window_hours\": number,\n      \"expected_opposite_direction\": \"in\"|\"out\"|\"unknown\"\n    } | null\n  },\n  \"signals\": {\n    \"is_fee_or_commission\": boolean,\n    \"is_tax\": boolean,\n    \"is_fuel\": boolean,\n    \"is_refund\": boolean\n  },\n  \"notes\": string\n}\n\nQUALITY BAR\n- confidence is 0.0\u20131.0\n- Provide short, concrete notes based on actual keywords found (max 200 chars)."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        336,
        448
      ],
      "id": "3c4d2249-0ee5-43e9-989d-72ebdc10f485",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        336,
        624
      ],
      "id": "b58596a5-92cc-4037-b4f9-90667fc958ef",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// n8n Code node (JavaScript)\n// Input: items[0].json.output  (string) OR items[0].json (varies)\n// Output: parsed JSON as item.json\n\nfunction stripFences(s) {\n  if (typeof s !== \"string\") return s;\n  // remove ```json ... ``` or ``` ... ```\n  return s\n    .replace(/^\\s*```(?:json)?\\s*/i, \"\")\n    .replace(/\\s*```\\s*$/i, \"\")\n    .trim();\n}\n\nreturn items.map((item) => {\n  const raw = item.json.output ?? item.json?.data ?? item.json;\n  const cleaned = stripFences(raw);\n\n  try {\n    const parsed = typeof cleaned === \"string\" ? JSON.parse(cleaned) : cleaned;\n    return { json: parsed };\n  } catch (e) {\n    // if still not valid JSON, return diagnostic\n    return {\n      json: {\n        parse_error: true,\n        error_message: String(e),\n        raw_output: raw,\n        cleaned_output: cleaned\n      }\n    };\n  }\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        688,
        448
      ],
      "id": "2c408d2e-ba2d-403c-9f39-54f22d92d83a",
      "name": "Code in JavaScript1"
    }
  ],
  "connections": {
    "On form submission": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "yap\u0131kredi",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ziraat",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "garanti",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "yap\u0131kredi": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ziraat": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Append row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "garanti": {
      "main": [
        [
          {
            "node": "Append row in sheet2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "master_excel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "master_excel": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "49569d69-36f2-4be6-8159-a8f5a162080d",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "3cYTeUi7mWkEWJpovUzLT",
  "tags": []
}