{
  "name": "Retail Sales & Inventory Manager",
  "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": "Mobile Wallet"
                  },
                  {
                    "option": "Cash"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Additional Notes",
              "placeholder": "Additional Notes"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        0,
        0
      ],
      "id": "4ae8f93b-cf49-46ed-bb6e-1224c512cf83",
      "name": "Sale Form Trigger",
      "webhookId": "2da59204-13a3-48a6-a8af-5a54aa564620"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "product",
              "lookupValue": "={{ $json[\"Product Name\"] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        208,
        0
      ],
      "id": "a6827694-f34a-4a3e-95ed-ebff16e75988",
      "name": "Fetch Product from Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "b23eb3eb-2549-410a-ad4d-0244f26350e8",
      "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": "1a165017-098c-4e1d-8e80-49ccf40046b6",
      "name": "Product Not Found Alert",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "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": "21f0eb01-13f5-45c5-b135-acdea9de43b2",
      "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": "66a41e2b-8920-49ae-88c2-63f8813e68dd",
      "name": "Check Low Stock Threshold"
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "=whatsapp:+15555550101",
        "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": "d70c26bd-3463-4170-a120-84d76f5a6d2b",
      "name": "Low Stock Alert (Manager)",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory"
        },
        "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": "e92c4372-4bee-42ef-acf6-991e2bf5385a",
      "name": "Update Inventory Stock 1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory"
        },
        "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": "5637c3f7-8e7a-490b-9c9d-875bda03bb59",
      "name": "Update Inventory Stock",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": 63639717,
          "mode": "list",
          "cachedResultName": "sales"
        },
        "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": "135cfd6e-c704-43aa-9ea6-e9f129e9c5e4",
      "name": "Save Sale Record",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": 63639717,
          "mode": "list",
          "cachedResultName": "sales"
        },
        "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": "3c96713a-427c-4c8f-aea0-15e25b149187",
      "name": "Save Sale Record 1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "72c3375a-dba5-4b07-9379-5afcc244e839",
      "name": "Send Customer Receipt",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "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": "0c7b790a-9826-4fd3-8506-6e1f245ebd0b",
      "name": "Send Customer Receipt 1",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        928,
        -960
      ],
      "id": "2b681892-3e31-498c-b519-ff49c1e97fe4",
      "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": "34f534bf-bffa-4a1d-ac5d-f560d281d62b",
      "name": "Inventory Form Trigger",
      "webhookId": "f6276e28-a53a-4fda-89bd-e46524681244"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory"
        },
        "filtersUI": {
          "values": []
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        240,
        -832
      ],
      "id": "5764994d-e797-450f-b3bf-bdb2ec6aa530",
      "name": "Fetch Inventory Records",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "a11d3d57-689f-44a0-8905-a3c71cdd153b",
      "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": "10aa984a-9364-4ce7-91c1-037dc40a9118",
      "name": "Is Product Duplicate?"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory"
        },
        "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": "150bdca2-4507-4be6-a235-74d94b05c021",
      "name": "Save New Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "e298504a-d3f3-4007-b56a-5b46ad3fae4f",
      "name": "Stock Update Form Trigger",
      "webhookId": "c408ecf1-3744-44f7-bb21-9f454096624b"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "product",
              "lookupValue": "={{ $json[\"Product Name\"] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        208,
        -400
      ],
      "id": "cde72a8d-382a-40c5-a547-fdc11ab0804e",
      "name": "Fetch Product from Inventory1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "37ef4d1a-4f94-4662-a98b-e9cb284590fd",
      "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": "1cd3c23a-30d2-4c7f-801d-fd6fac04f930",
      "name": "Calculate Updated Stock"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "inventory"
        },
        "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": "28012364-fe6f-4b10-9014-34eb1ad3c8c4",
      "name": "Update Inventory Stock1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 21
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        384
      ],
      "id": "6feb8771-22a4-4b3c-a35c-e56415d54646",
      "name": "Daily Summary Scheduler"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": 63639717,
          "mode": "list",
          "cachedResultName": "sales"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "date",
              "lookupValue": "={{ new Date().toISOString().split('T')[0] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        208,
        384
      ],
      "id": "2ebffc0a-38fc-4ee9-980d-67b1b488285f",
      "name": "Fetch Today Sales Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "22a22825-ecbc-4aad-a000-fbd40ad558ef",
      "name": "Calculate Daily Sales Summary"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1LiPgLWid-5boOdHBbBUu7taFcjNqkvUKiLWd7mwm1WU",
          "mode": "list",
          "cachedResultName": "Retail Shop Daily Sales Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": 317076457,
          "mode": "list",
          "cachedResultName": "daily_summary"
        },
        "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": "96f43d9d-a763-440d-9b76-e270fac9a8e0",
      "name": "Save Daily Summary",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "=whatsapp:+15555550101",
        "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": "f7f681fa-37e5-4206-8b25-92b6fb7aca3e",
      "name": "Send Daily Report (Manager)",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Google Sheet\nCreate your own spreadsheet with these tabs/columns, then select it in the Google Sheets nodes:\n- **Retail Shop Daily Sales Sheet → inventory**: `product`, `stock`, `min_stock`, `price`\n- **Retail Shop Daily Sales Sheet → sales**: `customer_name`, `phone_number`, `product`, `quantity`, `price`, `total`, `time`, `date`\n- **Retail Shop Daily Sales Sheet → daily_summary**: `date`, `total_sales`, `orders`, `top_product`",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -400,
        -1136
      ],
      "id": "1f3b7700-2a0e-4d83-ab63-236984c078de",
      "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": "1c190c16-540c-4a22-9e39-20e0cfea292d",
      "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": "5d07bb46-8a47-415c-96b3-f2bc6c489238",
      "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": "9fa8107f-e7c5-4d81-972c-09c4edf2b9f3",
      "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": "f99da074-ff4f-4873-9feb-dd1cde52664f",
      "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": "5b78fddc-13f7-4730-b309-e8796375084e",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "f1c26778ec36097a9722a22c47c5e9c01f00b8862dadd0121ec118026a370fa6"
  },
  "id": "eDWo5dWBRd8Brzhp",
  "tags": []
}