{
  "name": "AI-Based Medicine Stock Monitoring & Expiry Alert System",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -144,
        48
      ],
      "id": "539613df-7c1d-48d3-a1fb-3b35344fcc2d",
      "name": "Daily Inventory Check Trigger"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        64,
        48
      ],
      "id": "d759c9c6-d36d-4437-ab75-fc9f5275c1eb",
      "name": "Fetch Inventory Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const today = new Date();\n\nreturn items.map(item => {\n  const expiry = new Date(item.json.expiry_date);\n  const diffDays = (expiry - today) / (1000 * 60 * 60 * 24);\n\n  item.json.expiring_soon = diffDays <= 30 && diffDays > 0 ? \"yes\" : \"no\";\n  item.json.status = diffDays < 0 ? \"expired\" : \"active\";\n\n  return item;\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        272,
        48
      ],
      "id": "9747634b-6614-4468-955a-e503f6e71650",
      "name": "Calculate Expiry Status"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "2c61c24b-da08-445e-b1fe-ee07433d2a4b",
              "leftValue": "={{$json.quantity}}",
              "rightValue": "={{$json.min_stock}}",
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        480,
        48
      ],
      "id": "59a80323-ac42-4111-9a57-0dc952dbebee",
      "name": "Check Low Stock"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "c3f80226-8826-4adb-bf36-2aab9a5d7f9f",
              "leftValue": "={{$json.expiring_soon}}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        720,
        128
      ],
      "id": "c6dd7f11-0cbb-44db-afc4-f8f8cff5d603",
      "name": "Check Expiring Soon"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "b54577ca-7957-4bc4-ae0a-98f963fd3e0b",
              "leftValue": "={{$json.status}}",
              "rightValue": "expired",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        992,
        256
      ],
      "id": "255f475c-24e8-4975-a9f9-1b9a657e9d14",
      "name": "Check Expired Medicines"
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+918849216727",
        "message": "=❌ Expired Medicine\n\n{{$json.medicine_name}}\nDo NOT sell!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1232,
        80
      ],
      "id": "1a6c4329-c42a-4f33-8ba2-68f6a90cb835",
      "name": "Send Expired Medicine Alert",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+918849216727",
        "message": "=⚠️ Expiring Soon\n\n{{$json.medicine_name}}\nExpiry: {{$json.expiry_date}}",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        976,
        -32
      ],
      "id": "848c6263-b51a-40bb-a714-6bbda99cfccc",
      "name": "Send Expiry Medicine Alert",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+918849216727",
        "message": "=⚠️ Low Stock Alert\n\n{{$json.medicine_name}}\nRemaining: {{$json.quantity}}",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        720,
        -128
      ],
      "id": "5cfc704c-17ec-464c-b227-8b52a5ca0aa3",
      "name": "Send Low Stock Medicine Alert",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const avg_sales = 10;\nconst lead_time = 5;\n\nreturn items.map(item => {\n  item.json.reorder_qty = avg_sales * lead_time;\n  return item;\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1216,
        368
      ],
      "id": "3ac04614-e17e-42c2-9f7c-1f96b70148b1",
      "name": "Calculate Reorder Quantity"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "batch_no": "={{ $json.batch_no }}",
            "status": "={{ $json.status }}",
            "expiring_soon": "={{ $json.expiring_soon }}",
            "reorder_qty": "={{ $json.reorder_qty }}",
            "last_update": "={{ $now.format('yyyy-MM-dd') }}"
          },
          "matchingColumns": [
            "batch_no"
          ],
          "schema": [
            {
              "id": "medicine_name",
              "displayName": "medicine_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "batch_no",
              "displayName": "batch_no",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "min_stock",
              "displayName": "min_stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "purchase_date",
              "displayName": "purchase_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "expiry_date",
              "displayName": "expiry_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "purchase_price",
              "displayName": "purchase_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "selling_price",
              "displayName": "selling_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "medicine_type",
              "displayName": "medicine_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "supplier_name",
              "displayName": "supplier_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "location",
              "displayName": "location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "expiring_soon",
              "displayName": "expiring_soon",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "reorder_qty",
              "displayName": "reorder_qty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "last_update",
              "displayName": "last_update",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "displayName": "notes",
              "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": [
        1424,
        368
      ],
      "id": "5f605d31-d2a3-44f6-9760-8fdf018ea255",
      "name": "Update Inventory Status",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "formTitle": "Medicine Sale Entry",
        "formDescription": "Record medicine sales and automatically update inventory levels. This form ensures accurate stock tracking and helps detect low stock after each sale.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Medicine Name",
              "placeholder": "Medicine Name"
            },
            {
              "fieldLabel": "Batch Number",
              "placeholder": "Batch Number"
            },
            {
              "fieldLabel": "Quantity Sold",
              "fieldType": "number",
              "placeholder": "Quantity Sold"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        -160,
        704
      ],
      "id": "be4d273e-b517-4481-8bac-dd6dd4af7084",
      "name": "Medicine Sale Form Trigger",
      "webhookId": "bd0802ec-ad99-4f45-986e-813f476249b8"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d686184c-0221-49a9-9a1d-93bcfb718cb0",
              "name": "medicine_name",
              "value": "={{$json.medicine_name}}",
              "type": "string"
            },
            {
              "id": "62defa96-0b61-4c34-8a1a-c952702e6054",
              "name": "batch_no",
              "value": "={{$json.batch_no}}",
              "type": "string"
            },
            {
              "id": "0559f727-ea09-4acf-8c70-f3d2cf83f0b0",
              "name": "quantity_sold",
              "value": "={{$json.quantity_sold}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        48,
        704
      ],
      "id": "e6471df2-5f63-4816-85e6-8101d64495ae",
      "name": "Prepare Sale Data"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "batch_no",
              "lookupValue": "={{$json.batch_no}}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        256,
        704
      ],
      "id": "dd9ba46d-f86c-44e8-a5e0-20fbc317a55a",
      "name": "Fetch Medicine Record",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return items.map(item => {\n  const currentQty = Number(item.json.quantity);\n  const soldQty = Number($json.quantity_sold);\n\n  item.json.quantity = currentQty - soldQty;\n\n  return item;\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        464,
        704
      ],
      "id": "0c11aec1-80b2-403a-b416-0e9eff597605",
      "name": "Calculate Updated Stock"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "batch_no": "{{$json.batch_no}}",
            "quantity": "={{$json.quantity}}",
            "last_update": "={{ $now.format('yyyy-MM-dd') }}"
          },
          "matchingColumns": [
            "batch_no"
          ],
          "schema": [
            {
              "id": "medicine_name",
              "displayName": "medicine_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "batch_no",
              "displayName": "batch_no",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "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": "purchase_date",
              "displayName": "purchase_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "expiry_date",
              "displayName": "expiry_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "purchase_price",
              "displayName": "purchase_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "selling_price",
              "displayName": "selling_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "medicine_type",
              "displayName": "medicine_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "supplier_name",
              "displayName": "supplier_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "location",
              "displayName": "location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "expiring_soon",
              "displayName": "expiring_soon",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "reorder_qty",
              "displayName": "reorder_qty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "last_update",
              "displayName": "last_update",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "notes",
              "displayName": "notes",
              "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": [
        672,
        704
      ],
      "id": "28b139fd-e34f-4683-8989-8a2267864190",
      "name": "Update Stock in Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "9eeca5f8-4e09-4240-8e94-5e5d9d3506b5",
              "leftValue": "={{$json.quantity}}",
              "rightValue": "={{$json.min_stock}}",
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        880,
        704
      ],
      "id": "239f30fb-c009-4996-afe2-b81c22571c91",
      "name": "Check Low Stock After Sale"
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+918849216727",
        "message": "=⚠️ Low Stock After Sale\n\n{{$json.medicine_name}}\nRemaining: {{$json.quantity}}",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1120,
        624
      ],
      "id": "fae6e89b-3328-44c1-8bb2-ebf53b05d3e1",
      "name": "Send Low Stock Alert",
      "credentials": {
        "twilioApi": {
          "id": "vTM9zbcO5mzo9dps",
          "name": "Twilio account 3"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        704,
        1216
      ],
      "id": "255a128b-9b07-4988-b39f-cee74d66443b",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -160,
        1088
      ],
      "id": "96828caa-c9a8-4be5-bb69-8f3422932e37",
      "name": "Daily Reorder Check Trigger"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        48,
        1088
      ],
      "id": "53604092-87a5-4e6d-9869-802d7cfab70a",
      "name": "Fetch Inventory Data1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const avg_daily_sales = 10;\nconst lead_time = 5;\n\nreturn items.map(item => {\n  const reorderQty = avg_daily_sales * lead_time;\n\n  item.json.reorder_qty = reorderQty;\n\n  return item;\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        256,
        1088
      ],
      "id": "cffc7169-e3d8-4ec8-a436-1d614e16644a",
      "name": "Prepare Inventory Data"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "d99833b0-2931-4576-bf7d-c3b222832127",
              "leftValue": "={{$json.quantity}}",
              "rightValue": "={{$json.min_stock}}",
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        464,
        1088
      ],
      "id": "61313e4a-a2c8-4dc1-b3ba-f287cb696881",
      "name": "Check Reorder Requirement"
    },
    {
      "parameters": {
        "jsCode": "const avg_sales = 10;\nconst lead_time = 5;\n\nreturn items.map(item => {\n  item.json.reorder_qty = avg_sales * lead_time;\n  return item;\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        704,
        976
      ],
      "id": "b3619c6a-8d74-4179-8cdf-9e352958e954",
      "name": "Calculate Reorder Quantity1"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "batch_no": "={{$json.batch_no}}",
            "reorder_qty": "={{$json.reorder_qty}}",
            "last_update": "={{$now.format('yyyy-MM-dd')}}"
          },
          "matchingColumns": [
            "batch_no"
          ],
          "schema": [
            {
              "id": "medicine_name",
              "displayName": "medicine_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "batch_no",
              "displayName": "batch_no",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "quantity",
              "displayName": "quantity",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "min_stock",
              "displayName": "min_stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "purchase_date",
              "displayName": "purchase_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "expiry_date",
              "displayName": "expiry_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "purchase_price",
              "displayName": "purchase_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "selling_price",
              "displayName": "selling_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "medicine_type",
              "displayName": "medicine_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "supplier_name",
              "displayName": "supplier_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "location",
              "displayName": "location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "expiring_soon",
              "displayName": "expiring_soon",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "reorder_qty",
              "displayName": "reorder_qty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "last_update",
              "displayName": "last_update",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "displayName": "notes",
              "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": [
        912,
        976
      ],
      "id": "5b4103c6-ffe6-4d85-9ada-9f96a69b7e4b",
      "name": "Update Reorder Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "formTitle": "Pharmacy Medicine Entry",
        "formDescription": "Add new medicine or update stock details. This form helps track inventory, expiry dates, and ensures timely alerts for low stock and expiring medicines.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Medicine Name",
              "placeholder": "Medicine Name",
              "requiredField": true
            },
            {
              "fieldLabel": "Batch Number",
              "placeholder": "Batch Number",
              "requiredField": true
            },
            {
              "fieldLabel": "Quantity",
              "placeholder": "Quantity",
              "requiredField": true
            },
            {
              "fieldLabel": "Expiry Date",
              "fieldType": "date",
              "requiredField": true
            },
            {
              "fieldLabel": "Minimum Stock Level",
              "fieldType": "number",
              "placeholder": "Minimum Stock Level",
              "requiredField": true
            },
            {
              "fieldLabel": "Supplier Name",
              "placeholder": "Supplier Name"
            },
            {
              "fieldLabel": "Purchase Date",
              "fieldType": "date"
            },
            {
              "fieldLabel": "Purchase Price (Per Unit)",
              "fieldType": "number",
              "placeholder": "Purchase Price (Per Unit)"
            },
            {
              "fieldLabel": "Selling Price (Per Unit)",
              "fieldType": "number",
              "placeholder": "Selling Price (Per Unit)"
            },
            {
              "fieldLabel": "Medicine Type",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Tablet"
                  },
                  {
                    "option": "Syrup"
                  },
                  {
                    "option": "Injection"
                  },
                  {
                    "option": "Capsule"
                  },
                  {
                    "option": "Cream"
                  },
                  {
                    "option": "Other"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Storage Location",
              "placeholder": "Storage Location"
            },
            {
              "fieldLabel": "Notes",
              "fieldType": "textarea",
              "placeholder": "Notes"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        -144,
        -336
      ],
      "id": "05c28642-99ff-454a-8e26-73247e14ea9d",
      "name": "Medicine Entry Form Trigger",
      "webhookId": "39b4191d-526d-4d72-a866-c0a2cf0939fb"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "medicine_name": "={{ $json['Medicine Name'] }}",
            "batch_no": "={{ $json['Batch Number'] }}",
            "quantity": "={{ $json.Quantity }}",
            "min_stock": "={{ $json['Minimum Stock Level'] }}",
            "purchase_date": "={{ $json['Purchase Date'] }}",
            "expiry_date": "={{ $json['Expiry Date'] }}",
            "purchase_price": "={{ $json['Purchase Price (Per Unit)'] }}",
            "selling_price": "={{ $json['Selling Price (Per Unit)'] }}",
            "medicine_type": "={{ $json['Medicine Type'] }}",
            "supplier_name": "={{ $json['Supplier Name'] }}",
            "location": "={{ $json['Storage Location'] }}",
            "notes": "={{ $json.Notes }}",
            "last_update": "={{ $now.format('yyyy-MM-dd') }}",
            "status": "active",
            "expiring_soon": "no",
            "reorder_qty": "0"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "medicine_name",
              "displayName": "medicine_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "batch_no",
              "displayName": "batch_no",
              "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": "min_stock",
              "displayName": "min_stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "purchase_date",
              "displayName": "purchase_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "expiry_date",
              "displayName": "expiry_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "purchase_price",
              "displayName": "purchase_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "selling_price",
              "displayName": "selling_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "medicine_type",
              "displayName": "medicine_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "supplier_name",
              "displayName": "supplier_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "location",
              "displayName": "location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "expiring_soon",
              "displayName": "expiring_soon",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "reorder_qty",
              "displayName": "reorder_qty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "last_update",
              "displayName": "last_update",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "notes",
              "displayName": "notes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        64,
        -336
      ],
      "id": "969eac11-fcbd-4cca-8ec7-8720c0a7650a",
      "name": "Save Medicine to Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "wQXWIxCRV7ybbbNL",
          "name": "heet - Google Sheets"
        }
      }
    },
    {
      "parameters": {
        "content": "## Google Sheet\nhttps://docs.google.com/spreadsheets/d/1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg/edit?gid=0#gid=0",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -576,
        -560
      ],
      "id": "ce1a2d92-64d0-44c1-ad9e-224bb5b8e705",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Medicine Inventory Input & Stock Management Automation",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -576,
        -336
      ],
      "id": "6bfb1db8-dee2-43be-a36f-d95c41ddceb7",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Daily Medicine Expiry Monitoring & Low Stock Alert Automation",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -576,
        48
      ],
      "id": "273f59e8-d132-46b4-8b28-5e97c87fec41",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Medicine Sales Entry & Real-Time Stock Update Automation",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -576,
        672
      ],
      "id": "4a1c5321-9629-45dc-80a5-a8d5a1ec4718",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Smart Reorder Calculation & Inventory Reporting Automation",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        1088
      ],
      "id": "fb8c0d8a-ef8f-4990-8e56-fdb10806f82d",
      "name": "Sticky Note4"
    }
  ],
  "pinData": {},
  "connections": {
    "Daily Inventory Check Trigger": {
      "main": [
        [
          {
            "node": "Fetch Inventory Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Inventory Data": {
      "main": [
        [
          {
            "node": "Calculate Expiry Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Expiry Status": {
      "main": [
        [
          {
            "node": "Check Low Stock",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Low Stock": {
      "main": [
        [
          {
            "node": "Send Low Stock Medicine Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check Expiring Soon",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Expiring Soon": {
      "main": [
        [
          {
            "node": "Send Expiry Medicine Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check Expired Medicines",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Expired Medicines": {
      "main": [
        [
          {
            "node": "Send Expired Medicine Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Calculate Reorder Quantity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Reorder Quantity": {
      "main": [
        [
          {
            "node": "Update Inventory Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Medicine Sale Form Trigger": {
      "main": [
        [
          {
            "node": "Prepare Sale Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Sale Data": {
      "main": [
        [
          {
            "node": "Fetch Medicine Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Medicine Record": {
      "main": [
        [
          {
            "node": "Calculate Updated Stock",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Updated Stock": {
      "main": [
        [
          {
            "node": "Update Stock in Inventory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Stock in Inventory": {
      "main": [
        [
          {
            "node": "Check Low Stock After Sale",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Low Stock After Sale": {
      "main": [
        [
          {
            "node": "Send Low Stock Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Reorder Check Trigger": {
      "main": [
        [
          {
            "node": "Fetch Inventory Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Inventory Data1": {
      "main": [
        [
          {
            "node": "Prepare Inventory Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Inventory Data": {
      "main": [
        [
          {
            "node": "Check Reorder Requirement",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Reorder Requirement": {
      "main": [
        [
          {
            "node": "Calculate Reorder Quantity1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Reorder Quantity1": {
      "main": [
        [
          {
            "node": "Update Reorder Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Medicine Entry Form Trigger": {
      "main": [
        [
          {
            "node": "Save Medicine to Inventory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "dd1dbc66-ae52-4faf-8efe-2b2864ca7aaf",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "9272721148ea09184b6bbb7ce6219dab088562dd450e2df8280d57c2e34c7d84"
  },
  "id": "3QN2dz47GjUJTuXq",
  "tags": []
}