{
  "name": "Pharmacy Stock & Expiry Monitor",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -144,
        48
      ],
      "id": "9e11a8de-75f4-4bad-a1e0-500825f9d977",
      "name": "Daily Inventory Check Trigger"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        64,
        48
      ],
      "id": "ff72cc99-0025-4fb5-a189-6d4386d56120",
      "name": "Fetch Inventory Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "018e5c2e-8c6f-41b8-9b19-03352c695104",
      "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": "a1fe3872-3253-47e3-99e8-c4ae3bfa5e80",
      "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": "2d697d34-a096-40be-8f5f-0c424158cd8a",
      "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": "73d5f792-3c4d-4ad7-923a-16c3dd425952",
      "name": "Check Expired Medicines"
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+15555550101",
        "message": "=❌ Expired Medicine\n\n{{$json.medicine_name}}\nDo NOT sell!",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1232,
        80
      ],
      "id": "8bfc6187-f370-411a-a4a8-c1ed8da0f545",
      "name": "Send Expired Medicine Alert",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+15555550101",
        "message": "=⚠️ Expiring Soon\n\n{{$json.medicine_name}}\nExpiry: {{$json.expiry_date}}",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        976,
        -32
      ],
      "id": "54b1420e-e1bc-4f03-be89-4051d3aef1b7",
      "name": "Send Expiry Medicine Alert",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+15555550101",
        "message": "=⚠️ Low Stock Alert\n\n{{$json.medicine_name}}\nRemaining: {{$json.quantity}}",
        "options": {}
      },
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        720,
        -128
      ],
      "id": "c03a982d-356a-4aac-b52e-35052dce29d7",
      "name": "Send Low Stock Medicine Alert",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "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": "e24250b3-2661-4684-8ce0-1c00f43cf375",
      "name": "Calculate Reorder Quantity"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "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": "1af96377-4fff-445b-a88f-4c267dca4ffa",
      "name": "Update Inventory Status",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "522bd97f-a9c1-476b-8002-adf3d34301b5",
      "name": "Medicine Sale Form Trigger",
      "webhookId": "a0c423c8-0f0f-4910-9793-e78dd78b7205"
    },
    {
      "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": "d5069204-908d-48a0-9e70-4c21ac85fbcb",
      "name": "Prepare Sale Data"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "batch_no",
              "lookupValue": "={{$json.batch_no}}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        256,
        704
      ],
      "id": "c7b12f3b-dbfa-4953-9571-b0bf0407a5b3",
      "name": "Fetch Medicine Record",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "de4f0176-87f9-4c06-a91c-30b024d06e87",
      "name": "Calculate Updated Stock"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "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": "b9c4c42d-3570-4f5e-af01-465e8c7e1cd6",
      "name": "Update Stock in Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "f6f310bd-4b41-4017-80bf-857ecd39d6eb",
      "name": "Check Low Stock After Sale"
    },
    {
      "parameters": {
        "from": "whatsapp:+14155238886",
        "to": "whatsapp:+15555550101",
        "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": "a39202a0-0f09-45af-9e61-197fa10cf2e1",
      "name": "Send Low Stock Alert",
      "credentials": {
        "twilioApi": {
          "id": "xmQ7NblKKLEiOZwC",
          "name": "Twilio account"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        704,
        1216
      ],
      "id": "10795d07-7d95-4a3b-b365-316b80069475",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -160,
        1088
      ],
      "id": "2c8f331d-52df-4dca-b876-b3455a3975cf",
      "name": "Daily Reorder Check Trigger"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        48,
        1088
      ],
      "id": "4cb18d23-bc59-4124-bb09-ac18592b9a2c",
      "name": "Fetch Inventory Data1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "80db60c6-b494-404d-b137-4c88353bce7c",
      "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": "6040da7c-e335-431e-8f3f-7833f0bbc746",
      "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": "773fed13-5653-47de-850c-929d578abad6",
      "name": "Calculate Reorder Quantity1"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "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": "47c14683-d86e-4bc5-a725-77f463df4ed9",
      "name": "Update Reorder Data",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "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": "77a3aa9d-b110-4bdf-85f4-b5ad06555aeb",
      "name": "Medicine Entry Form Trigger",
      "webhookId": "17da4e2d-2207-4ca6-9835-4d965e5fd8b7"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1RBSmIl1u0h4iQ_RiWZKPM1xUiKRLR6QLRRrLYduBixg",
          "mode": "list",
          "cachedResultName": "Pharmacy Inventory Sheet"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1"
        },
        "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": "9a9dd5d1-19d3-48e0-b426-2f9371cf59a3",
      "name": "Save Medicine to Inventory",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Pkc8jJJZleMSmXoy",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Google Sheet\nCreate your own spreadsheet with these tabs/columns, then select it in the Google Sheets nodes:\n- **Pharmacy Inventory Sheet → Sheet1**: `batch_no`, `status`, `expiring_soon`, `reorder_qty`, `last_update`, `quantity`, `medicine_name`, `min_stock`, `purchase_date`, `expiry_date`, `purchase_price`, `selling_price`, `medicine_type`, `supplier_name`, `location`, `notes`",
        "height": 144,
        "width": 320
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -576,
        -560
      ],
      "id": "b90e950d-7458-4ffd-b15e-a1844cd87879",
      "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": "8936a40e-d639-4347-901d-74d7585c0b11",
      "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": "3a70cbe6-d44d-4710-bc6b-bbce8e90f3b2",
      "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": "5c1a6e8a-2f68-4ed5-a521-f09a66a3ff6c",
      "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": "fe223976-5478-4e42-a003-05f7ef187cff",
      "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": "160d5a15-445d-47e0-8bed-ff746f39a186",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "f1c26778ec36097a9722a22c47c5e9c01f00b8862dadd0121ec118026a370fa6"
  },
  "id": "SGFvXkCxeGvsaRhx",
  "tags": []
}