{
  "name": "Retail Shop Daily Sales & Inventory Management System",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Retail Sale Entry Form",
        "formDescription": "Enter product sale details to automatically update inventory, track sales, and manage stock in real-time. This form ensures accurate billing and helps maintain daily business records.`",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Customer Name",
              "placeholder": "Customer Name",
              "requiredField": true
            },
            {
              "fieldLabel": "Phone Number",
              "fieldType": "number",
              "placeholder": "Phone Number",
              "requiredField": true
            },
            {
              "fieldLabel": "Product Name",
              "placeholder": "Product Name"
            },
            {
              "fieldLabel": "Quantity",
              "fieldType": "number",
              "placeholder": "Quantity"
            },
            {
              "fieldLabel": "Price",
              "fieldType": "number"
            },
            {
              "fieldLabel": "Payment Method",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Card"
                  },
                  {
                    "option": "UPI"
                  },
                  {
                    "option": "Cash"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Additional Notes",
              "placeholder": "Additional Notes"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        0,
        0
      ],
      "id": "9598dc9e-71d6-4c7a-95c3-26ec362e687b",
      "name": "Sale Form Trigger",
      "webhookId": "5adcce22-fc98-4758-ae97-a326998d352d"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "product",
              "lookupValue": "={{ $json[\"Product Name\"] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        208,
        0
      ],
      "id": "208e824c-ea0f-4475-bfa5-89a0fe99df44",
      "name": "Fetch Product from Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "1bf38a20-0bee-45ca-9fc7-f47145e1090d",
              "leftValue": "={{ $json.product }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        416,
        0
      ],
      "id": "6e479f08-36b0-4dba-8443-989be9c35764",
      "name": "Validate Product Exists"
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "=whatsapp:+{{ $json.phone_number }}",
        "message": "=❌ Product not found in inventory!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        656,
        144
      ],
      "id": "74f0cae5-1239-4b17-9a7d-cf9e1dd4b149",
      "name": "Product Not Found Alert",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const stock = $json.stock;\nconst qty = $('Sale Form Trigger').item.json['Quantity'];\nconst price = $json.price;\nconst min_stock = $json.min_stock;\n\nconst new_stock = stock - qty;\nconst total = qty * price;\n\nreturn [{\n  json: {\n    product: $json.product,\n    quantity: qty,\n    price: price,\n    total: total,\n    new_stock: new_stock,\n    min_stock: min_stock,\n    payment_method: $('Sale Form Trigger').item.json['Payment Method'],\n    customer: $('Sale Form Trigger').item.json['Customer Name'],\n    phone_number: $('Sale Form Trigger').item.json['Phone Number'],\n    date: new Date().toISOString().split('T')[0],\n    time: new Date().toLocaleTimeString()\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        640,
        -96
      ],
      "id": "58029847-6bce-480d-aef5-bf7d639489e8",
      "name": "Calculate Sale, Total & Stock"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "44cf3d14-abf4-451d-b529-554f3c3748e6",
              "leftValue": "={{ $json.new_stock }}",
              "rightValue": "={{ $json.min_stock }}",
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        832,
        -96
      ],
      "id": "b3a999ed-2b1c-498d-9d03-ca7219b5e1ab",
      "name": "Check Low Stock Threshold"
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "=whatsapp:+918849216727",
        "message": "=⚠️ Low Stock Alert!\n\nProduct: {{$json.product}}  \nRemaining Stock: {{$json.new_stock}}\n\nPlease restock soon.",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1056,
        -256
      ],
      "id": "43012701-00fc-4b9b-9468-41f73c077322",
      "name": "Low Stock Alert (Manager)",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "product": "={{ $json.product }}",
            "stock": "={{ $json.new_stock }}"
          },
          "matchingColumns": [
            "product"
          ],
          "schema": [
            {
              "id": "product",
              "displayName": "product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "stock",
              "displayName": "stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "min_stock",
              "displayName": "min_stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1056,
        48
      ],
      "id": "de634736-5d8f-4859-820e-7a5d528d11ef",
      "name": "Update Inventory Stock 1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "product": "={{ $json.product }}",
            "stock": "={{ $json.new_stock }}"
          },
          "matchingColumns": [
            "product"
          ],
          "schema": [
            {
              "id": "product",
              "displayName": "product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "stock",
              "displayName": "stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "min_stock",
              "displayName": "min_stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1248,
        -256
      ],
      "id": "0be56209-a127-493b-b7e7-3ec9e0698e01",
      "name": "Update Inventory Stock",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 63639717,
          "mode": "list",
          "cachedResultName": "sales",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=63639717"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "customer_name": "={{ $('Check Low Stock Threshold').item.json.customer }}",
            "phone_number": "={{ $('Check Low Stock Threshold').item.json.phone_number }}",
            "product": "={{ $('Check Low Stock Threshold').item.json.product }}",
            "quantity": "={{ $('Check Low Stock Threshold').item.json.quantity }}",
            "price": "={{ $('Check Low Stock Threshold').item.json.price }}",
            "total": "={{ $('Check Low Stock Threshold').item.json.total }}",
            "time": "={{ $('Check Low Stock Threshold').item.json.time }}",
            "date": "={{ $('Check Low Stock Threshold').item.json.date }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "customer_name",
              "displayName": "customer_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "phone_number",
              "displayName": "phone_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "product",
              "displayName": "product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "total",
              "displayName": "total",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "time",
              "displayName": "time",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "displayName": "date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1472,
        -256
      ],
      "id": "f1320298-9595-403d-b0c0-d76b6ee55611",
      "name": "Save Sale Record",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 63639717,
          "mode": "list",
          "cachedResultName": "sales",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=63639717"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "customer_name": "={{ $('Check Low Stock Threshold').item.json.customer }}",
            "phone_number": "={{ $('Check Low Stock Threshold').item.json.phone_number }}",
            "product": "={{ $('Check Low Stock Threshold').item.json.product }}",
            "quantity": "={{ $('Check Low Stock Threshold').item.json.quantity }}",
            "price": "={{ $('Check Low Stock Threshold').item.json.price }}",
            "total": "={{ $('Check Low Stock Threshold').item.json.total }}",
            "time": "={{ $('Check Low Stock Threshold').item.json.time }}",
            "date": "={{ $('Check Low Stock Threshold').item.json.date }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "customer_name",
              "displayName": "customer_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "phone_number",
              "displayName": "phone_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "product",
              "displayName": "product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "total",
              "displayName": "total",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "time",
              "displayName": "time",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "displayName": "date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1280,
        48
      ],
      "id": "fb273b1e-7ef1-41da-bf56-7a54fbae21e0",
      "name": "Save Sale Record 1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "=whatsapp:+{{ $json.phone_number }}",
        "message": "=🧾 Thank you {{$json.customer_name}}!\n\nYour purchase is confirmed ✅\n\nProduct: {{$json.product}}  \nQuantity: {{$json.quantity}}  \nTotal: ₹{{$json.total}}  \nPayment: {{ $('Calculate Sale, Total & Stock').item.json.payment_method }}\n\n📅 {{$json.date}} ⏰ {{$json.time}}\n\n🙏 Visit again!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1680,
        -256
      ],
      "id": "9fc60403-3367-400a-b2dc-d26cc58208a2",
      "name": "Send Customer Receipt",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "=whatsapp:+{{ $json.phone_number }}",
        "message": "=🧾 Thank you {{$json.customer_name}}!\n\nYour purchase is confirmed ✅\n\nProduct: {{$json.product}}  \nQuantity: {{$json.quantity}}  \nTotal: ₹{{$json.total}}  \nPayment: {{ $('Calculate Sale, Total & Stock').item.json.payment_method }}\n\n📅 {{$json.date}} ⏰ {{$json.time}}\n\n🙏 Visit again!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1488,
        48
      ],
      "id": "fbbbb7a4-4d72-4a6c-a1ad-09d21c491842",
      "name": "Send Customer Receipt 1",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        928,
        -960
      ],
      "id": "d8e053c1-95a5-4999-bd38-cab82cb87ead",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "formTitle": "Inventory Management Form",
        "formDescription": "Add new products to your inventory by entering stock details, minimum stock level, and pricing. This helps maintain accurate stock records and ensures timely restocking alerts.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Product Name",
              "placeholder": "Product Name",
              "requiredField": true
            },
            {
              "fieldLabel": "Stock",
              "fieldType": "number",
              "placeholder": "Stock",
              "requiredField": true
            },
            {
              "fieldLabel": "Minimum Stock",
              "fieldType": "number",
              "placeholder": "Minimum Stock",
              "requiredField": true
            },
            {
              "fieldLabel": "Price (per unit)",
              "fieldType": "number",
              "placeholder": "Price (per unit)",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        32,
        -832
      ],
      "id": "5e728891-72ff-4856-b15b-8f85478eb09a",
      "name": "Inventory Form Trigger",
      "webhookId": "ea55c219-3e70-4a40-830e-26aea69a2017"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=0"
        },
        "filtersUI": {
          "values": []
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        240,
        -832
      ],
      "id": "c1cf710d-fc05-4216-9f15-4f6de79978e0",
      "name": "Fetch Inventory Records",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const formProduct = $('Inventory Form Trigger').item.json[\"Product Name\"];\n\nlet exists = false;\n\nfor (const item of items) {\n  if (item.json.product === formProduct) {\n    exists = true;\n    break;\n  }\n}\n\nreturn [\n  {\n    json: {\n      exists: exists\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        448,
        -832
      ],
      "id": "9e131337-f8ba-4c9a-bb71-c794e75300c9",
      "name": "Check Product Exists"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "e98e7a31-aa83-4642-8e5b-44cc25cc541c",
              "leftValue": "={{ $json.exists }}",
              "rightValue": "=",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        656,
        -832
      ],
      "id": "08040e15-f881-4182-ac25-ceaadb8c26c4",
      "name": "Is Product Duplicate?"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "product": "={{ $('Inventory Form Trigger').item.json[\"Product Name\"] }}",
            "stock": "={{ $('Inventory Form Trigger').item.json[\"Stock\"] }}",
            "min_stock": "={{ $('Inventory Form Trigger').item.json[\"Minimum Stock\"] }}",
            "price": "={{ $('Inventory Form Trigger').item.json[\"Price (per unit)\"] }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "product",
              "displayName": "product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "stock",
              "displayName": "stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "min_stock",
              "displayName": "min_stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        928,
        -736
      ],
      "id": "95bdf146-e259-4baa-ac34-790616f741af",
      "name": "Save New Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "formTitle": "Stock Update / Restock Form",
        "formDescription": "Add new stock for existing products. The system will automatically increase the current stock and update the total inventory count.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Product Name",
              "placeholder": "Product Name",
              "requiredField": true
            },
            {
              "fieldLabel": "New Stock Quantity",
              "fieldType": "number",
              "placeholder": "New Stock Quantity",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        0,
        -400
      ],
      "id": "3f69a2df-e22c-4919-bef5-de2b8b5b2a81",
      "name": "Stock Update Form Trigger",
      "webhookId": "690fac54-e9f7-4504-976c-ddf0ff0661c0"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "product",
              "lookupValue": "={{ $json[\"Product Name\"] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        208,
        -400
      ],
      "id": "8b7e0f9e-0830-4ead-bb0d-cde63b5e63f5",
      "name": "Fetch Product from Inventory1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "4bfd6e44-e557-4a58-86ee-70745ee52f4c",
              "leftValue": "={{ $json.product }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        416,
        -400
      ],
      "id": "63a75137-0338-4935-bd32-ddc06ab19317",
      "name": "Validate Product Exists1"
    },
    {
      "parameters": {
        "jsCode": "const old_stock = Number($json.stock);\n\nconst new_stock = Number($('Stock Update Form Trigger').item.json[\"New Stock Quantity\"]);\n\nconst updated_stock = old_stock + new_stock;\n\nreturn [\n  {\n    json: {\n      product: $json.product,\n      updated_stock: updated_stock\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        688,
        -528
      ],
      "id": "2fb383bf-769e-4e8a-93d0-96a20e99a974",
      "name": "Calculate Updated Stock"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "product": "={{ $json.product }}",
            "stock": "={{ $json.updated_stock }}"
          },
          "matchingColumns": [
            "product"
          ],
          "schema": [
            {
              "id": "product",
              "displayName": "product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "stock",
              "displayName": "stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "min_stock",
              "displayName": "min_stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        896,
        -528
      ],
      "id": "535e0f7d-d5ad-4ab7-816a-0e62a9935157",
      "name": "Update Inventory Stock1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 21
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        384
      ],
      "id": "e4437b9b-e582-421a-bed9-e61133f430b3",
      "name": "Daily Summary Scheduler"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 63639717,
          "mode": "list",
          "cachedResultName": "sales",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=63639717"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "date",
              "lookupValue": "={{ new Date().toISOString().split('T')[0] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        208,
        384
      ],
      "id": "5836c4df-e590-45dd-baf9-c04b5dc27ec3",
      "name": "Fetch Today Sales Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "let total = 0;\nlet orders = items.length;\nlet productCount = {};\n\nitems.forEach(item => {\n  const sale = item.json;\n\n  total += Number(sale.total);\n\n  const product = sale.product;\n  productCount[product] = (productCount[product] || 0) + 1;\n});\n\n// Find top product\nlet top_product = Object.keys(productCount).reduce((a, b) =>\n  productCount[a] > productCount[b] ? a : b\n);\n\nreturn [{\n  json: {\n    total_sales: total,\n    orders: orders,\n    top_product: top_product,\n    date: new Date().toISOString().split('T')[0]\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        416,
        384
      ],
      "id": "f3b67838-e144-460b-96f5-22d3de823912",
      "name": "Calculate Daily Sales Summary"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 317076457,
          "mode": "list",
          "cachedResultName": "daily_summary",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit#gid=317076457"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "date": "={{ $json.date }}",
            "total_sales": "={{ $json.total_sales }}",
            "orders": "={{ $json.orders }}",
            "top_product": "={{ $json.top_product }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "date",
              "displayName": "date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "total_sales",
              "displayName": "total_sales",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "orders",
              "displayName": "orders",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "top_product",
              "displayName": "top_product",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        624,
        384
      ],
      "id": "682ff604-30f7-4e13-b3df-8c0f2663ad47",
      "name": "Save Daily Summary",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "=whatsapp:+918849216727",
        "message": "=📊 Daily Sales Report\n\nDate: {{$json.date}}\n\nTotal Sales: ₹{{$json.total_sales}}\nTotal Orders: {{$json.orders}}\nTop Product: {{$json.top_product}}\n\n🔥 Good Job!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        816,
        384
      ],
      "id": "781dd975-cc11-408b-98ff-355481483596",
      "name": "Send Daily Report (Manager)",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "content": "## Google Sheet\nhttps://docs.google.com/spreadsheets/d/1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU/edit?gid=0#gid=0",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -400,
        -1136
      ],
      "id": "a96aa720-1b35-4d96-93e1-07d8712c1a4c",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Inventory Management & Product Setup Automation",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -384,
        -832
      ],
      "id": "9e4db99f-9bd0-45e8-af06-2a95f4e89e27",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Inventory Restock & Stock Update Automation",
        "height": 112,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -384,
        -400
      ],
      "id": "48fb56a3-03d8-4957-afde-b33cbf384f56",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Retail Sales & Billing Automation System",
        "height": 112,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -384,
        0
      ],
      "id": "4d701751-6349-4df2-9535-e1a67a965460",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Daily Sales Summary & Reporting Automation",
        "height": 112,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -384,
        384
      ],
      "id": "32ce0719-b350-49c4-81aa-1d9a893381d7",
      "name": "Sticky Note4"
    }
  ],
  "pinData": {},
  "connections": {
    "Sale Form Trigger": {
      "main": [
        [
          {
            "node": "Fetch Product from Inventory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Product from Inventory": {
      "main": [
        [
          {
            "node": "Validate Product Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Product Exists": {
      "main": [
        [
          {
            "node": "Calculate Sale, Total & Stock",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Product Not Found Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Sale, Total & Stock": {
      "main": [
        [
          {
            "node": "Check Low Stock Threshold",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Low Stock Threshold": {
      "main": [
        [
          {
            "node": "Low Stock Alert (Manager)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Inventory Stock 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Low Stock Alert (Manager)": {
      "main": [
        [
          {
            "node": "Update Inventory Stock",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Inventory Stock 1": {
      "main": [
        [
          {
            "node": "Save Sale Record 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Inventory Stock": {
      "main": [
        [
          {
            "node": "Save Sale Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Sale Record": {
      "main": [
        [
          {
            "node": "Send Customer Receipt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Sale Record 1": {
      "main": [
        [
          {
            "node": "Send Customer Receipt 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inventory Form Trigger": {
      "main": [
        [
          {
            "node": "Fetch Inventory Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Inventory Records": {
      "main": [
        [
          {
            "node": "Check Product Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Product Exists": {
      "main": [
        [
          {
            "node": "Is Product Duplicate?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Product Duplicate?": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save New Inventory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Stock Update Form Trigger": {
      "main": [
        [
          {
            "node": "Fetch Product from Inventory1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Product from Inventory1": {
      "main": [
        [
          {
            "node": "Validate Product Exists1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Product Exists1": {
      "main": [
        [
          {
            "node": "Calculate Updated Stock",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Updated Stock": {
      "main": [
        [
          {
            "node": "Update Inventory Stock1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Summary Scheduler": {
      "main": [
        [
          {
            "node": "Fetch Today Sales Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Today Sales Data": {
      "main": [
        [
          {
            "node": "Calculate Daily Sales Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Daily Sales Summary": {
      "main": [
        [
          {
            "node": "Save Daily Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Daily Summary": {
      "main": [
        [
          {
            "node": "Send Daily Report (Manager)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "45555158-a128-4d33-be43-feaaf2722234",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "9272721148ea09184b6bbb7ce6219dab088562dd450e2df8280d57c2e34c7d84"
  },
  "id": "ImBjJNwirxA7oTRD",
  "tags": []
}