{
  "name": "Total timesheet hours per client with the Code node in JavaScript and Python",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        96
      ],
      "name": "When clicking ‘Execute workflow’",
      "id": "st-01"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "return [\n  { worker: 'Ana Ruiz', client: 'Kessler Logistics', hours: 7.5 },\n  { worker: 'Ben Carter', client: 'Northgate Dental', hours: 8 },\n  { worker: 'Ana Ruiz', client: 'Kessler Logistics', hours: 8 },\n  { worker: 'Chloe Park', client: 'Alder & Finch Law', hours: 6 },\n  { worker: 'Ben Carter', client: 'Northgate Dental', hours: 4.5 },\n  { worker: 'Dev Malhotra', client: 'Kessler Logistics', hours: 8 },\n  { worker: 'Chloe Park', client: 'Alder & Finch Law', hours: 7 },\n].map((json) => ({ json }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        224,
        96
      ],
      "name": "Sample timesheet",
      "id": "st-02"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const totals = {};\nfor (const item of $input.all()) {\n  const row = item.json;\n  totals[row.client] = (totals[row.client] || 0) + row.hours;\n}\nreturn Object.entries(totals).map(([client, hours]) => ({\n  json: { client, hours, invoice: hours * 42 },\n}));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        448,
        0
      ],
      "name": "Total hours by client",
      "id": "st-03"
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "pythonNative",
        "pythonCode": "totals = {}\nfor item in _items:\n    row = item[\"json\"]\n    totals[row[\"client\"]] = totals.get(row[\"client\"], 0) + row[\"hours\"]\n\nreturn [\n    {\"json\": {\"client\": client, \"hours\": hours, \"invoice\": hours * 42}}\n    for client, hours in totals.items()\n]"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        448,
        192
      ],
      "name": "Same job in Python",
      "id": "st-04"
    },
    {
      "parameters": {
        "content": "## Total timesheet hours by client\nOne Code node replaces a pivot table. The JavaScript and Python nodes do the same job: keep the one you like.",
        "height": 416,
        "width": 608,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -32,
        -96
      ],
      "name": "Overview",
      "id": "st-05"
    },
    {
      "parameters": {
        "content": "## How to set up\n1. Click **Execute workflow**.\n2. Open both Code nodes: the outputs match.\n3. Keep the language you can read and delete the other node.\n4. Change `42` to your hourly rate.\n5. Swap **Sample timesheet** for Google Sheets.\n\nNo credentials needed. Python needs no imports.\n\nFree step-by-step lesson: https://learn.ynteractive.com/content/n8n-code-node-javascript-python",
        "height": 420,
        "width": 360,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -420,
        -96
      ],
      "name": "Setup note",
      "id": "st-06"
    },
    {
      "parameters": {
        "content": "**1. Sample timesheet**\nSeven made-up rows: worker, client, hours.",
        "height": 150,
        "width": 200,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        164,
        330
      ],
      "name": "Note 1",
      "id": "st-07"
    },
    {
      "parameters": {
        "content": "**2a. JavaScript**\nReads all items with `$input.all()`, totals hours per client, returns one item per client.",
        "height": 150,
        "width": 220,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        640,
        -40
      ],
      "name": "Note 2",
      "id": "st-08"
    },
    {
      "parameters": {
        "content": "**2b. Python**\nSame job. Input is `_items`; no imports needed.",
        "height": 150,
        "width": 220,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        640,
        160
      ],
      "name": "Note 3",
      "id": "st-09"
    }
  ],
  "connections": {
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Sample timesheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sample timesheet": {
      "main": [
        [
          {
            "node": "Total hours by client",
            "type": "main",
            "index": 0
          },
          {
            "node": "Same job in Python",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
