{
  "name": "ZMGIT Invoice Creator",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://api-m.paypal.com/v1/oauth2/token",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "authorization",
              "value": "Basic QVQxbXZzS0xrNnhPenF0ZVlBUlU5WVpRUG5Relh3aWR1T1pEMTVNWG51UFZwMUNqNDNXVG1DZ0xNS1lsZGkxYnZvQXhTYTBYaGhFdElUUU86RVBHTExQWUV3bm1IRFhwcFd4Vm9ac2JfX2dJcE9GNmxCUW1LTkdMQjJYeFdNZ0dYMGdOMnFwVmw0RldtUEZFTjZZT3hZQXBNaW81ZnhoYzk="
            }
          ]
        },
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "client_credentials"
            }
          ]
        },
        "options": {
          "sendCredentialsOnCrossOriginRedirect": true
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -1472,
        368
      ],
      "id": "f9c13678-2641-49c1-8122-f580287072a4",
      "name": "HTTP Request",
      "executeOnce": false,
      "notesInFlow": true,
      "notes": "Get authorization"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api-m.paypal.com/v2/invoicing/invoices",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "authorization",
              "value": "=Bearer {{ $json.access_token }}"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ \n{\n  \"detail\": $('Code in JavaScript4').item.json.detail,\n  \"invoicer\": $('Code in JavaScript4').item.json.invoicer,\n  \"primary_recipients\": $('Code in JavaScript4').item.json.primary_recipients,\n  \"items\": $('Code in JavaScript4').item.json.items,\n  \"configuration\": $('Code in JavaScript4').item.json.configuration,\n\"amount\": $('Code in JavaScript4').item.json.amount\n}\n}}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -1248,
        368
      ],
      "id": "93d71c45-ab88-4dea-b617-8a89f0b9615f",
      "name": "CreateInvoice",
      "alwaysOutputData": false,
      "retryOnFail": false
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1SReuC5kFxuEswvG4rC3OXFZZw95F-KgQzF5RlL76_Fk",
          "mode": "list",
          "cachedResultName": "ZMGITdb",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SReuC5kFxuEswvG4rC3OXFZZw95F-KgQzF5RlL76_Fk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SReuC5kFxuEswvG4rC3OXFZZw95F-KgQzF5RlL76_Fk/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "Status"
            }
          ]
        },
        "options": {
          "outputFormatting": {
            "values": {
              "general": "FORMATTED_VALUE",
              "date": "FORMATTED_STRING"
            }
          }
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -3040,
        368
      ],
      "id": "ac8e8ee3-a613-4c59-b88b-9d23aef6c7dc",
      "name": "getData",
      "executeOnce": true,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "TgPQC99gvHvEZzvo",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "minutesSaved": 10
      },
      "type": "n8n-nodes-base.timeSaved",
      "typeVersion": 1,
      "position": [
        -1024,
        368
      ],
      "id": "31df4354-f434-4fd0-ba47-0a8277a749fb",
      "name": "Time Saved4"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c91a6f30-3dd5-4753-b20a-2b9baeb67e74",
              "name": "primary_recipients.billing_info.business_name",
              "value": "={{$json.Company}}",
              "type": "string"
            },
            {
              "id": "585e3276-e9f2-4758-84cc-b72d061232c0",
              "name": "primary_recipients.billing_info.email_address",
              "value": "={{$json.ToEmail}}",
              "type": "string"
            },
            {
              "id": "fa76e34e-e1c0-4e68-becc-0eac1b3cfac4",
              "name": "detail.invoice_number",
              "value": "={{$json.InvoiceNum}}",
              "type": "string"
            },
            {
              "id": "d5a80d0f-8639-42a5-bfdc-26ef4b461953",
              "name": "detail.currency_code",
              "value": "={{$json.Currency}}",
              "type": "string"
            },
            {
              "id": "adce7b5e-27e0-48ed-ad8c-54fab2e288b7",
              "name": "detail.invoice_date",
              "value": "={{ $now.toISODate().split('T')[0] }}",
              "type": "string"
            },
            {
              "id": "99363eac-d0fa-475f-9e17-1d34628cf50c",
              "name": "invoices.invoicer.email_address",
              "value": "=zmglobalit.com@gmail.com",
              "type": "string"
            },
            {
              "id": "45c54cd2-7f10-4bc7-8321-1d8ae7c45fcc",
              "name": "primary_recipients.billing_info.full_name",
              "value": "={{ $json.Person}}",
              "type": "string"
            },
            {
              "id": "7bc98f92-231b-46fd-8d5d-bfa769358860",
              "name": "detail.payment_term.due_date",
              "value": "={{ $json.DueDate ? new Date($json.DueDate).toISOString().split('T')[0] : $now.toISODate() }}",
              "type": "string"
            },
            {
              "id": "eefdb4fe-ba1f-44ff-92ba-5f9e5caeec28",
              "name": "configuration.allow_tip",
              "value": "true",
              "type": "string"
            },
            {
              "id": "88a7e0e6-19a1-41eb-b7d8-67a6a2bde647",
              "name": "configuration.partial_payment.allow_partial_payment",
              "value": "false",
              "type": "string"
            },
            {
              "id": "a5179449-c915-4a6e-8c72-96935f92711f",
              "name": "configuration.template_id",
              "value": "TEMP-72A429212V311924E",
              "type": "string"
            },
            {
              "id": "c44aefd5-be78-49b6-add7-75404078d7b5",
              "name": "amount.currency_code",
              "value": "={{$json.Currency}}",
              "type": "string"
            },
            {
              "id": "2ccbe11c-12cb-4e77-b742-e5b3ea5f9c26",
              "name": "invoicer.name.full_name",
              "value": "Ziana Mitchell",
              "type": "string"
            },
            {
              "id": "70641ff7-76d7-438d-a9f5-ba581e2e1508",
              "name": "invoicer.address.address_line_1",
              "value": "2179 Parkdale Ave",
              "type": "string"
            },
            {
              "id": "0a46efde-2e11-4f07-9ac6-16731a439ed8",
              "name": "invoicer.address.admin_area_2",
              "value": "Toledo",
              "type": "string"
            },
            {
              "id": "cae4f01c-ce4a-44e7-97c3-b33996938852",
              "name": "invoicer.address.admin_area_1",
              "value": "OH",
              "type": "string"
            },
            {
              "id": "7a6de885-80a6-40c6-b1cf-26933c22ca2f",
              "name": "invoicer.address.postal_code",
              "value": "43607",
              "type": "string"
            },
            {
              "id": "bd31433c-ba93-4b53-8925-c6d16543e888",
              "name": "invoicer.address.country_code",
              "value": "US",
              "type": "string"
            },
            {
              "id": "69d10251-7426-4da1-81a7-b0c82439f907",
              "name": "invoicer.tax_id",
              "value": "EIN: 86-2365422 ",
              "type": "string"
            },
            {
              "id": "678c090f-8815-4d08-9ebf-b0d69d63f32b",
              "name": "invoicer.logo_url",
              "value": "https://pics.paypal.com/00/s/MjAwWDIwMFhKUEc/p/YzAyZDNiMTQtNTljZS00ZmFhLWJiMzAtM2E2MTY4NjNmNjE3/image_109.JPG",
              "type": "string"
            },
            {
              "id": "0490363f-75d1-465e-bfc7-ac7c84e6968f",
              "name": "invoicer.business_name",
              "value": "ZM Global IT",
              "type": "string"
            },
            {
              "id": "decc5f49-540c-4e3a-86b2-146e2877f7b6",
              "name": "detail.payment_term.term_type",
              "value": "DUE_ON_DATE_SPECIFIED",
              "type": "string"
            },
            {
              "id": "54326a11-9f71-42f8-a559-3669213fd217",
              "name": "detail.note",
              "value": "Thank you for your business! I look forward to working with you again.",
              "type": "string"
            },
            {
              "id": "ed35c9c3-7e35-470e-add0-f6821b244659",
              "name": "detail.terms_and_conditions",
              "value": "If I do more than one project within the same business week (9 AM Monday - 3 PM Friday) I will lump the invoices together into one payment. \\n Each project will have its own reference number listed in the detailed description. Each project will have the date it was assigned prominently displayed. \\n Complete payment is due within 15 days of the date of invoice. Five days after the due date, a $0.50 late fee is applied. Followed by an additional $0.50 late fee for every additional five days late. \\n Invoices and payments are processed through PayPal with email address: zmglobalit.com@gmail.com",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2816,
        368
      ],
      "id": "834b6b46-d3ad-4696-8f56-d95f2fd74461",
      "name": "makeInvoice"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{$json.Notes}}",
                    "rightValue": "Based on pages",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "id": "f5797e4d-6138-4287-8c13-a74faec8923a"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Pages"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "cdd117b6-7c35-4a36-a8db-499c5718ac7d",
                    "leftValue": "={{$json.Notes}}",
                    "rightValue": "Based on docs",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Docs"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "51edcb43-2ca9-4b6d-9406-fbbfa39bc11a",
                    "leftValue": "={{$json.Notes}}",
                    "rightValue": "Based on hours",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Hours"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -2592,
        336
      ],
      "id": "50f140ba-5925-4fb7-8874-40fb0957bdb6",
      "name": "Switch2"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c966c123-4ac9-4dc1-85a8-3ebea03527c5",
              "name": "items.name",
              "value": "={{ $json.Task }}",
              "type": "string"
            },
            {
              "id": "690b52a6-2648-41ed-b1e6-64c7c74a1903",
              "name": "items.quantity",
              "value": "={{$json.Pages}}",
              "type": "string"
            },
            {
              "id": "b5bbef60-73c3-4642-8bdd-8d45821e5479",
              "name": "items.unit_amount.value",
              "value": "={{ parseFloat($json.UnitFee || 0).toFixed(2) }}",
              "type": "string"
            },
            {
              "id": "f8eef969-4d0d-4393-973f-e0214c11a0cd",
              "name": "items.item_date",
              "value": "={{ new Date($json.DateAssigned).toISOString().split('T')[0] }}",
              "type": "string"
            },
            {
              "id": "d4ef2e49-5e46-49d2-acbf-5d9a8ce1ba50",
              "name": "items.description",
              "value": "=PO# {{$json.PONum}}\\n Job# {{$json.JobNum}}\\n Source: {{$json.Source}}\\n Target: {{$json.Target}}\\n Task: {{$json.Task}}\\n Word Count: {{$json.Words}}\\n Pages: {{$json.Pages}}\\n Docs: {{$json.Docs}}\\n Hours: {{$json.Hours}}\\n Fee: {{$json.UnitFee}} = {{ $json.ItemTotal }}\\n Date Assigned: {{ new Date($json.DateAssigned).toISOString().split('T')[0] }}\\n Project Name: {{$json.ProjectName}}\\n Notes: {{ $json.Notes }}",
              "type": "string"
            },
            {
              "id": "48a43562-2fd1-4e62-933f-c248116d6d66",
              "name": "items.unit_of_measure",
              "value": "=QUANTITY",
              "type": "string"
            },
            {
              "id": "bc168511-784c-47b5-be72-a6fc7248992d",
              "name": "items.unit_amount.currency_code",
              "value": "={{ $json.Currency }}",
              "type": "string"
            },
            {
              "id": "a5781d0f-68a3-42b0-86d4-02c07604cec3",
              "name": "amount.value",
              "value": "={{($json.Pages * parseFloat($json.UnitFee || 0)).toFixed(2)}}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "include": "selected",
        "includeFields": "detail, invoicer, primary_recipients, configuration, amount",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2368,
        80
      ],
      "id": "31064a62-e6b5-45dd-bfb1-4a8684588779",
      "name": "Pages1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c966c123-4ac9-4dc1-85a8-3ebea03527c5",
              "name": "items.name",
              "value": "={{ $json.Task }}",
              "type": "string"
            },
            {
              "id": "690b52a6-2648-41ed-b1e6-64c7c74a1903",
              "name": "items.quantity",
              "value": "={{$json.Words}}",
              "type": "string"
            },
            {
              "id": "b5bbef60-73c3-4642-8bdd-8d45821e5479",
              "name": "items.unit_amount.value",
              "value": "={{ parseFloat($json.UnitFee || 0).toFixed(2) }}",
              "type": "string"
            },
            {
              "id": "f8eef969-4d0d-4393-973f-e0214c11a0cd",
              "name": "items.item_date",
              "value": "={{ new Date($json.DateAssigned).toISOString().split('T')[0] }}",
              "type": "string"
            },
            {
              "id": "d4ef2e49-5e46-49d2-acbf-5d9a8ce1ba50",
              "name": "items.description",
              "value": "=PO# {{$json.PONum}}\\n Job# {{$json.JobNum}}\\n Source: {{$json.Source}}\\n Target: {{$json.Target}}\\n Task: {{$json.Task}}\\n Word Count: {{$json.Words}}\\n Pages: {{$json.Pages}}\\n Docs: {{$json.Docs}}\\n Hours: {{$json.Hours}}\\n Fee: {{$json.UnitFee}} = {{ $json.ItemTotal }}\\n Date Assigned: {{ new Date($json.DateAssigned).toISOString().split('T')[0] }}\\n Project Name: {{$json.ProjectName}}\\n Notes: {{ $json.Notes }}",
              "type": "string"
            },
            {
              "id": "48a43562-2fd1-4e62-933f-c248116d6d66",
              "name": "items.unit_of_measure",
              "value": "=QUANTITY",
              "type": "string"
            },
            {
              "id": "56bf7860-ff3c-436e-b656-b6d98f98f956",
              "name": "items.unit_amount.currency_code",
              "value": "={{ $json.Currency }}",
              "type": "string"
            },
            {
              "id": "23411ed8-d277-4a23-bf81-2325570cf923",
              "name": "amount.value",
              "value": "={{($json.Words * parseFloat($json.UnitFee || 0)).toFixed(2)}}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "include": "selected",
        "includeFields": "detail, invoicer, primary_recipients, configuration, amount",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2368,
        656
      ],
      "id": "b264d09a-bc65-4f45-a7f8-758c92442001",
      "name": "Words1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c966c123-4ac9-4dc1-85a8-3ebea03527c5",
              "name": "items.name",
              "value": "={{ $json.Task }}",
              "type": "string"
            },
            {
              "id": "690b52a6-2648-41ed-b1e6-64c7c74a1903",
              "name": "items.quantity",
              "value": "={{$json.Docs}}",
              "type": "string"
            },
            {
              "id": "b5bbef60-73c3-4642-8bdd-8d45821e5479",
              "name": "items.unit_amount.value",
              "value": "={{ parseFloat($json.UnitFee || 0).toFixed(2) }}",
              "type": "string"
            },
            {
              "id": "f8eef969-4d0d-4393-973f-e0214c11a0cd",
              "name": "items.item_date",
              "value": "={{ new Date($json.DateAssigned).toISOString().split('T')[0] }}",
              "type": "string"
            },
            {
              "id": "d4ef2e49-5e46-49d2-acbf-5d9a8ce1ba50",
              "name": "items.description",
              "value": "=PO# {{$json.PONum}}\\n Job# {{$json.JobNum}}\\n Source: {{$json.Source}}\\n Target: {{$json.Target}}\\n Task: {{$json.Task}}\\n Word Count: {{$json.Words}}\\n Pages: {{$json.Pages}}\\n Docs: {{$json.Docs}}\\n Hours: {{$json.Hours}}\\n Fee: {{$json.UnitFee}} = {{ $json.ItemTotal }}\\n Date Assigned: {{ new Date($json.DateAssigned).toISOString().split('T')[0] }}\\n Project Name: {{$json.ProjectName}}\\n Notes: {{ $json.Notes }}",
              "type": "string"
            },
            {
              "id": "48a43562-2fd1-4e62-933f-c248116d6d66",
              "name": "items.unit_of_measure",
              "value": "=QUANTITY",
              "type": "string"
            },
            {
              "id": "e3df28b1-03f3-42c4-8a6d-35f75f1e6daf",
              "name": "items.unit_amount.currency_code",
              "value": "={{ $json.Currency }}",
              "type": "string"
            },
            {
              "id": "4161bd71-c032-42a0-88a7-6f4144dd5908",
              "name": "amount.value",
              "value": "={{($json.Docs * parseFloat($json.UnitFee || 0)).toFixed(2)}}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "include": "selected",
        "includeFields": "detail, invoicer, primary_recipients, configuration, amount",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2368,
        272
      ],
      "id": "92d92feb-6bfd-47b6-8529-eff7056a0ca8",
      "name": "Docs1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c966c123-4ac9-4dc1-85a8-3ebea03527c5",
              "name": "items.name",
              "value": "={{ $json.Task }}",
              "type": "string"
            },
            {
              "id": "690b52a6-2648-41ed-b1e6-64c7c74a1903",
              "name": "items.quantity",
              "value": "={{$json.Hours}}",
              "type": "string"
            },
            {
              "id": "b5bbef60-73c3-4642-8bdd-8d45821e5479",
              "name": "items.unit_amount.value",
              "value": "={{ parseFloat($json.UnitFee || 0).toFixed(2) }}",
              "type": "string"
            },
            {
              "id": "f8eef969-4d0d-4393-973f-e0214c11a0cd",
              "name": "items.item_date",
              "value": "={{ new Date($json.DateAssigned).toISOString().split('T')[0] }}",
              "type": "string"
            },
            {
              "id": "d4ef2e49-5e46-49d2-acbf-5d9a8ce1ba50",
              "name": "items.description",
              "value": "=PO# {{$json.PONum}}\\n Job# {{$json.JobNum}}\\n Source: {{$json.Source}}\\n Target: {{$json.Target}}\\n Task: {{$json.Task}}\\n Word Count: {{$json.Words}}\\n Pages: {{$json.Pages}}\\n Docs: {{$json.Docs}}\\n Hours: {{$json.Hours}}\\n Fee: {{$json.UnitFee}} = {{ $json.ItemTotal }}\\n Date Assigned: {{ new Date($json.DateAssigned).toISOString().split('T')[0] }}\\n Project Name: {{$json.ProjectName}}\\n Notes: {{ $json.Notes }}",
              "type": "string"
            },
            {
              "id": "48a43562-2fd1-4e62-933f-c248116d6d66",
              "name": "items.unit_of_measure",
              "value": "=QUANTITY",
              "type": "string"
            },
            {
              "id": "7a28aa50-3f89-4377-9c23-494ebc211e37",
              "name": "items.unit_amount.currency_code",
              "value": "={{ $json.Currency }}",
              "type": "string"
            },
            {
              "id": "3a73c631-01d6-41d4-80a0-fe13c81ccc47",
              "name": "amount.value",
              "value": "={{($json.Hours * parseFloat($json.UnitFee || 0)).toFixed(2)}}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "include": "selected",
        "includeFields": "detail, invoicer, primary_recipients, configuration, amount",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2368,
        464
      ],
      "id": "71f61443-5d1c-4a4f-884b-e316419cf44e",
      "name": "Hours1"
    },
    {
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "append",
              "field": "items"
            },
            {
              "aggregation": "sum",
              "field": "=amount.value"
            }
          ]
        },
        "fieldsToSplitBy": "detail, invoicer, primary_recipients, configuration, amount.currency_code",
        "options": {
          "outputFormat": "separateItems"
        }
      },
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1.1,
      "position": [
        -1920,
        368
      ],
      "id": "7f8a3b38-bc96-439e-8f97-ff7e6a0884fb",
      "name": "Summarize"
    },
    {
      "parameters": {
        "numberInputs": 4
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        -2144,
        336
      ],
      "id": "2fd862e4-7a52-4975-9fc6-644a4d4f4db2",
      "name": "Merge"
    },
    {
      "parameters": {
        "jsCode": "return $input.all().map(item => {\n  const data = item.json;\n\n  // Helper function to safely parse only if it's a string\n  const safeParse = (val) => (typeof val === 'string' ? JSON.parse(val) : val);\n\n  const cleanedInvoices = {\n    \"detail\": safeParse(data.detail),\n    \"invoicer\": safeParse(data.invoicer),\n    // PayPal REQUIRES an array for primary_recipients\n    \"primary_recipients\": [safeParse(data.primary_recipients)],\n    \"items\": safeParse(data.appended_items) || [],\n    \"configuration\": safeParse(data.configuration),\n    \"amount\":{\"currency_code\": data.amount_currency_code, \"value\": parseFloat(data.sum_amount_value).toFixed(2), \"breakdown\":{\"item_total\": {\"currency_code\": data.amount_currency_code, \"value\": parseFloat(data.sum_amount_value).toFixed(2)}}}\n  };\n\n  // Remove nulls from items if they exist\n  if (Array.isArray(cleanedInvoices.items)) {\n    cleanedInvoices.items = cleanedInvoices.items.filter(i => i !== null);\n  }\n\n  return { json: cleanedInvoices };\n  if (Array.isArray(cleanedInvoices.items)) {\n  cleanedInvoices.items = cleanedInvoices.items.map(item => ({\n    ...item,\n    description: item.description ? item.description.replace(/\\n/g, \"\\\\n\") : \"\"\n  }));\n}\n});\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1696,
        368
      ],
      "id": "91cbedb9-da9f-47ac-b7cd-f27922205661",
      "name": "Code in JavaScript4"
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "hour": 8
            }
          ]
        },
        "documentId": {
          "__rl": true,
          "value": "1SReuC5kFxuEswvG4rC3OXFZZw95F-KgQzF5RlL76_Fk",
          "mode": "list",
          "cachedResultName": "ZMGITdb",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SReuC5kFxuEswvG4rC3OXFZZw95F-KgQzF5RlL76_Fk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1SReuC5kFxuEswvG4rC3OXFZZw95F-KgQzF5RlL76_Fk/edit#gid=0"
        },
        "event": "rowAdded",
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "typeVersion": 1,
      "position": [
        -3264,
        368
      ],
      "id": "b1d00f4a-303d-4f56-9953-781c62c8c750",
      "name": "Google Sheets Trigger",
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "id": "RvW3mDk2kM7qvm0c",
          "name": "Google Sheets Trigger account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "CreateInvoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CreateInvoice": {
      "main": [
        [
          {
            "node": "Time Saved4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "getData": {
      "main": [
        [
          {
            "node": "makeInvoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Time Saved4": {
      "main": [
        []
      ]
    },
    "makeInvoice": {
      "main": [
        [
          {
            "node": "Switch2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch2": {
      "main": [
        [
          {
            "node": "Pages1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Docs1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Hours1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Words1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pages1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Docs1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Hours1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Words1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "Summarize": {
      "main": [
        [
          {
            "node": "Code in JavaScript4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Summarize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript4": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "getData",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false,
    "timeSavedMode": "dynamic",
    "errorWorkflow": "XpIwFbxtOZCVqH80",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "af516ca3-affc-4e81-a923-750cb9daf617",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "de33315ccd8c8df612c54de8ea941ad063e50c03727d03cbfc3a7e6c3875936b"
  },
  "id": "nl7UTOgg63lbcGcA",
  "tags": [
    {
      "updatedAt": "2026-03-14T13:30:15.728Z",
      "createdAt": "2026-03-14T13:30:15.728Z",
      "id": "u2Zf7F4Fj1uPzjeQ",
      "name": "ZMGIT"
    }
  ]
}