CREATE DATABASE  IF NOT EXISTS `ophthalstock` /*!40100 DEFAULT CHARACTER SET latin1 */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `ophthalstock`;
--
-- Host: 127.0.0.1    Database: ophthalstock
-- ------------------------------------------------------


--
-- Table structure for table `tbl_credit_note_each`
--

CREATE TABLE `tbl_credit_note_each` (
  `aCreditNoteEachId` int NOT NULL AUTO_INCREMENT,
  `nCreditNoteMainId` int DEFAULT NULL,
  `nItemId` int DEFAULT NULL,
  `batchNumber` varchar(45) DEFAULT NULL,
  `serialNumber` varchar(45) DEFAULT NULL,
  `nUserId` int DEFAULT NULL,
  `acceptedDate` datetime DEFAULT NULL,
  `unitPrice` float DEFAULT NULL,
  `totAmount` float DEFAULT NULL,
  `remarks` varchar(45) DEFAULT NULL,
  `creditStatus` int DEFAULT NULL,
  `isActive` int DEFAULT NULL,
  `isDeleted` int DEFAULT NULL,
  `lastModified` datetime DEFAULT NULL,
  `insertedDate` datetime DEFAULT NULL,
  `nMainGrnId` int DEFAULT NULL,
  `nEachGrnId` int DEFAULT NULL,
  `nGrnAvailQtyId` int DEFAULT NULL,
  `acceptedQty` int DEFAULT NULL,
  `itemDiapter` varchar(45) DEFAULT NULL,
  `itemSize` varchar(45) DEFAULT NULL,
  `itemStrength` varchar(45) DEFAULT NULL,
  `itemValume` varchar(45) DEFAULT NULL,
  `poNumber` varchar(45) DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `nPoTypeId` int DEFAULT NULL,
  `nsuppliedmapId` varchar(45) DEFAULT NULL,
  `expiryDate` datetime DEFAULT NULL,
  `nDebitNotemainId` int DEFAULT NULL,
  `ndebitNoteEachId` int DEFAULT NULL,
  `nStoreId` int DEFAULT NULL,
  PRIMARY KEY (`aCreditNoteEachId`),
  KEY `nCreditNoteMainId` (`nCreditNoteMainId`),
  KEY `nItemId` (`nItemId`),
  KEY `nUserId` (`nUserId`),
  KEY `nMainGrnId` (`nMainGrnId`),
  KEY `nEachGrnId` (`nEachGrnId`),
  KEY `nGrnAvailQtyId` (`nGrnAvailQtyId`),
  KEY `nPoTypeId` (`nPoTypeId`),
  CONSTRAINT `tbl_credit_note_each_ibfk_1` FOREIGN KEY (`nCreditNoteMainId`) REFERENCES `tbl_credit_note_main` (`acreditNoteId`),
  CONSTRAINT `tbl_credit_note_each_ibfk_2` FOREIGN KEY (`nItemId`) REFERENCES `tbl_mst_items_details` (`aItemId_pk`),
  CONSTRAINT `tbl_credit_note_each_ibfk_3` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_credit_note_each_ibfk_4` FOREIGN KEY (`nMainGrnId`) REFERENCES `tbl_grn_for_po_orders` (`aGrnId_pk`),
  CONSTRAINT `tbl_credit_note_each_ibfk_5` FOREIGN KEY (`nEachGrnId`) REFERENCES `tbl_grn_for_po_each_item_orders` (`aGrnId_each_pk`),
  CONSTRAINT `tbl_credit_note_each_ibfk_6` FOREIGN KEY (`nGrnAvailQtyId`) REFERENCES `tbl_grn_availqty` (`aGrnAvailQtyId`),
  CONSTRAINT `tbl_credit_note_each_ibfk_7` FOREIGN KEY (`nGrnAvailQtyId`) REFERENCES `tbl_grn_availqty` (`aGrnAvailQtyId`),
  CONSTRAINT `tbl_credit_note_each_ibfk_8` FOREIGN KEY (`nPoTypeId`) REFERENCES `tbl_mst_potypes` (`aPoTypeId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_credit_note_each`
--


--
-- Table structure for table `tbl_credit_note_main`
--

CREATE TABLE `tbl_credit_note_main` (
  `acreditNoteId` int NOT NULL AUTO_INCREMENT,
  `nDebitNoteId` int DEFAULT NULL,
  `nDebitedAmount` int DEFAULT NULL,
  `creditedAmount` varchar(45) DEFAULT NULL,
  `nUserId` int DEFAULT NULL,
  `creditedDate` datetime DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `creditNoteNumber` varchar(45) DEFAULT NULL,
  `noOfItem` int DEFAULT NULL,
  `totQty` int DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `lastModified` datetime DEFAULT CURRENT_TIMESTAMP,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `remarks` varchar(45) DEFAULT NULL,
  `nCreditedStatus` int DEFAULT NULL,
  `nsupplierId` int DEFAULT NULL,
  PRIMARY KEY (`acreditNoteId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_credit_note_main`
--


--
-- Table structure for table `tbl_dailystock_details`
--

CREATE TABLE `tbl_dailystock_details` (
  `aStockIdInt` int NOT NULL AUTO_INCREMENT,
  `nBranchId` int DEFAULT NULL,
  `nItemId` int DEFAULT NULL,
  `nGrnAvailId` int DEFAULT NULL,
  `nSupplierId` int DEFAULT NULL,
  `nItemRateId` int DEFAULT NULL,
  `batchNo` varchar(100) DEFAULT NULL,
  `serialNumber` varchar(100) DEFAULT NULL,
  `expiryDate` datetime DEFAULT NULL,
  `ngrnMainId` int DEFAULT NULL,
  `nGrnEachId` int DEFAULT NULL,
  `openingStock` int DEFAULT NULL,
  `closingStock` int DEFAULT NULL,
  `nStoreId` int DEFAULT NULL,
  `diopter` varchar(10) DEFAULT NULL,
  `size` varchar(10) DEFAULT NULL,
  `strength` varchar(10) DEFAULT NULL,
  `volume` varchar(10) DEFAULT NULL,
  `stockDate` datetime DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `lastModified` datetime DEFAULT CURRENT_TIMESTAMP,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `nUserId` int DEFAULT NULL,
  `soldQty` int DEFAULT '0',
  PRIMARY KEY (`aStockIdInt`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_dailystock_details`
--


--
-- Table structure for table `tbl_debit_note_each`
--

CREATE TABLE `tbl_debit_note_each` (
  `aEachDnId` int NOT NULL AUTO_INCREMENT,
  `nMainDnId` int DEFAULT NULL,
  `poNumber` varchar(45) DEFAULT NULL,
  `grnNumber` varchar(45) DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `nStoreId` int DEFAULT NULL,
  `nPoTypeId` int DEFAULT NULL,
  `nSupplierMapId` int DEFAULT NULL,
  `expiryDate` datetime DEFAULT NULL,
  `nMainGrnId` int DEFAULT NULL,
  `nEachGrnId` int DEFAULT NULL,
  `nMainReturnId` int DEFAULT NULL,
  `nEachReturnId` int DEFAULT NULL,
  `nGrnAvailQtyId` int DEFAULT NULL,
  `nItemId` int DEFAULT NULL,
  `nsupplierId` int DEFAULT NULL,
  `batchNo` varchar(45) DEFAULT NULL,
  `serilNo` varchar(45) DEFAULT NULL,
  `itemDiapter` varchar(45) DEFAULT NULL,
  `itemSize` varchar(45) DEFAULT NULL,
  `itemStrength` varchar(45) DEFAULT NULL,
  `itemVolume` varchar(45) DEFAULT NULL,
  `nUserId` int DEFAULT NULL,
  `retuenDate` datetime DEFAULT NULL,
  `nReturnUserId` int DEFAULT NULL,
  `returnQty` int DEFAULT NULL,
  `unitPrice` float DEFAULT NULL,
  `totTaxAmount` float DEFAULT NULL,
  `totalAmount` float DEFAULT NULL,
  `remarks` varchar(45) DEFAULT NULL,
  `debitStatus` varchar(45) DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`aEachDnId`),
  KEY `nMainDnId` (`nMainDnId`),
  KEY `nStoreId` (`nStoreId`),
  KEY `nBranchId` (`nBranchId`),
  KEY `nPoTypeId` (`nPoTypeId`),
  CONSTRAINT `tbl_debit_note_each_ibfk_1` FOREIGN KEY (`nMainDnId`) REFERENCES `tbl_debit_note_main` (`aMainDNId`),
  CONSTRAINT `tbl_debit_note_each_ibfk_2` FOREIGN KEY (`nStoreId`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `tbl_debit_note_each_ibfk_3` FOREIGN KEY (`nBranchId`) REFERENCES `tblhospitalbranches` (`abranchId`),
  CONSTRAINT `tbl_debit_note_each_ibfk_4` FOREIGN KEY (`nPoTypeId`) REFERENCES `tbl_mst_potypes` (`aPoTypeId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_debit_note_each`
--


--
-- Table structure for table `tbl_debit_note_main`
--

CREATE TABLE `tbl_debit_note_main` (
  `aMainDNId` int NOT NULL AUTO_INCREMENT,
  `DNNumber` varchar(45) DEFAULT NULL,
  `remarks` varchar(45) DEFAULT NULL,
  `debitStatus` int DEFAULT NULL,
  `nReturnUserId` int DEFAULT NULL,
  `noOfItems` int DEFAULT NULL,
  `totQty` int DEFAULT NULL,
  `totAmount` float DEFAULT NULL,
  `totTaxAmount` float DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `returnDate` datetime DEFAULT NULL,
  `nSupplierId` int DEFAULT NULL,
  `isActive` varchar(45) DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aMainDNId`),
  KEY `nReturnUserId` (`nReturnUserId`),
  KEY `nBranchId` (`nBranchId`),
  KEY `nSupplierId` (`nSupplierId`),
  CONSTRAINT `tbl_debit_note_main_ibfk_1` FOREIGN KEY (`nReturnUserId`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_debit_note_main_ibfk_2` FOREIGN KEY (`nBranchId`) REFERENCES `tblhospitalbranches` (`abranchId`),
  CONSTRAINT `tbl_debit_note_main_ibfk_3` FOREIGN KEY (`nSupplierId`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_debit_note_main`
--


--
-- Table structure for table `tbl_depo_hub_mapping_details`
--

CREATE TABLE `tbl_depo_hub_mapping_details` (
  `priId` int NOT NULL AUTO_INCREMENT,
  `operationTypeId` int NOT NULL,
  `depoOrHubId` int NOT NULL,
  `branchId` int NOT NULL,
  `userId` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  PRIMARY KEY (`priId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_depo_hub_mapping_details`
--


--
-- Table structure for table `tbl_grn_availqty`
--

CREATE TABLE `tbl_grn_availqty` (
  `aGrnAvailQtyId` int NOT NULL AUTO_INCREMENT,
  `nMainGrnId` int NOT NULL,
  `nEachGrnId` int NOT NULL,
  `nStoreId` int DEFAULT NULL,
  `nItemId` int DEFAULT NULL,
  `nPotypeId` int DEFAULT NULL,
  `nSupplierId` int DEFAULT NULL,
  `nSupplierMapId` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `grnQty` int DEFAULT '0',
  `transferedQty` int DEFAULT '0',
  `returnedQty` int DEFAULT '0',
  `returnAcceptedQty` int DEFAULT '0',
  `availQty` int DEFAULT '0',
  `returnToSupplier` int DEFAULT '0',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId` int DEFAULT NULL,
  `patientId` int DEFAULT NULL,
  `counsilId` int DEFAULT NULL,
  `surgAppId` int DEFAULT NULL,
  `patName` varchar(250) DEFAULT NULL,
  `patientCode` varchar(250) DEFAULT NULL,
  `reservedById` int DEFAULT NULL,
  `reservedByName` varchar(250) DEFAULT NULL,
  `reservedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isReserved` int DEFAULT '0',
  `surgeryDate` date DEFAULT NULL,
  `consumptionDate` datetime DEFAULT NULL,
  PRIMARY KEY (`aGrnAvailQtyId`),
  UNIQUE KEY `nEachGrnId_UNIQUE` (`nEachGrnId`),
  KEY `fk_nmaingrn_id_idx` (`nMainGrnId`),
  KEY `fk_nstore_id_idx` (`nStoreId`),
  KEY `fk_nitem_id_idx` (`nItemId`),
  KEY `fk_npotype_id_idx` (`nPotypeId`),
  KEY `fk_nsupplier_id_idx` (`nSupplierId`),
  KEY `fk_nsuplliermap_id_idx` (`nSupplierMapId`),
  KEY `fk1_nmaingrn_id_idx` (`nMainGrnId`),
  KEY `fk1_nstore_id_idx` (`nStoreId`),
  KEY `fk1_nitem_id_idx` (`nItemId`),
  KEY `fk1_npotype_id_idx` (`nPotypeId`),
  KEY `fk1_nsupplier_id_idx` (`nSupplierId`),
  KEY `fk1_nsuplliermap_id_idx` (`nSupplierMapId`),
  CONSTRAINT `fk1_neachgrn_Id` FOREIGN KEY (`nEachGrnId`) REFERENCES `tbl_grn_for_po_each_item_orders` (`aGrnId_each_pk`),
  CONSTRAINT `fk1_nitem_Id` FOREIGN KEY (`nItemId`) REFERENCES `tbl_mst_items_details` (`aItemId_pk`),
  CONSTRAINT `fk1_nmaingrn_Id` FOREIGN KEY (`nMainGrnId`) REFERENCES `tbl_grn_for_po_orders` (`aGrnId_pk`),
  CONSTRAINT `fk1_npotype_Id` FOREIGN KEY (`nPotypeId`) REFERENCES `tbl_mst_potypes` (`aPoTypeId`),
  CONSTRAINT `fk1_nstore_id` FOREIGN KEY (`nStoreId`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `fk1_nsuplliermap_Id` FOREIGN KEY (`nSupplierMapId`) REFERENCES `tbl_supplier_item_mapping` (`supplier_item_mappingId`),
  CONSTRAINT `fk1_nsupplier_Id` FOREIGN KEY (`nSupplierId`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_grn_availqty`
--


--
-- Table structure for table `tbl_grn_for_po_each_item_orders`
--

CREATE TABLE `tbl_grn_for_po_each_item_orders` (
  `aGrnId_each_pk` int NOT NULL AUTO_INCREMENT,
  `nGrnId_fk` int DEFAULT NULL,
  `nPoIdCentral_fk` int DEFAULT NULL,
  `nPoEachId` int DEFAULT NULL,
  `nPoIdBranch_fk` int DEFAULT NULL,
  `nPoIdBranch_Central_fk` int DEFAULT NULL,
  `nGrnIdCentral_fk` int DEFAULT NULL,
  `nPoType_fk` int DEFAULT NULL,
  `nSupplierId_fk` int DEFAULT NULL,
  `nStoreId_fk` int DEFAULT NULL,
  `nGrnUserId_fk` int DEFAULT NULL,
  `nItemId_fk` int DEFAULT NULL,
  `freeQty` int DEFAULT '0',
  `orderQty` int DEFAULT '0',
  `receivedQty` int DEFAULT NULL,
  `batchNo` varchar(30) DEFAULT NULL,
  `expiryDate` datetime DEFAULT NULL,
  `serialNumber` varchar(100) DEFAULT NULL,
  `itemAmount` float DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `ngrnBranchId_fk` int DEFAULT NULL,
  `size` varchar(25) DEFAULT NULL,
  `diapter` varchar(25) DEFAULT NULL,
  `strength` varchar(25) DEFAULT NULL,
  `volume` varchar(25) DEFAULT NULL,
  `issuedToBranch` int DEFAULT '0',
  `nSupplierItemMapid` int DEFAULT NULL,
  `nGrnTypeId` int DEFAULT '1',
  `nEachTransferId` int DEFAULT NULL,
  `nMainTransferId` int DEFAULT NULL,
  `nCommercialStatusId` tinyint DEFAULT '0',
  `financeStatusId` int DEFAULT NULL,
  `financeRemarks` text,
  `financeUserId` int DEFAULT NULL,
  `financeDate` datetime DEFAULT NULL,
  `accountsStatusId` int DEFAULT NULL,
  `accountsRemarks` text,
  `accountsUserId` int DEFAULT NULL,
  `accountsDate` datetime DEFAULT NULL,
  `unitPrice` float DEFAULT '0',
  `itemPriceBeforeDiscount` float DEFAULT '0',
  `discountPercentage` float DEFAULT '0',
  `disCountInRupees` float DEFAULT '0',
  `taxableAmount` float DEFAULT '0',
  `taxAmount` float DEFAULT '0',
  `totalAmount` float DEFAULT '0',
  PRIMARY KEY (`aGrnId_each_pk`),
  UNIQUE KEY `nEachTransferId_UNIQUE` (`nEachTransferId`),
  KEY `fk_tbl_grn_for_po_each_item_orders_1_idx` (`nGrnId_fk`),
  KEY `fk_npoidcentral_fk_idx` (`nPoIdCentral_fk`),
  KEY `fk_npoeach_id_idx` (`nPoEachId`),
  KEY `fk_npotype_id_idx` (`nPoType_fk`),
  KEY `fk_nsupplier_id_idx` (`nSupplierId_fk`),
  KEY `fk_nStore_id_idx` (`nStoreId_fk`),
  KEY `fk_nGenUser_id_idx` (`nGrnUserId_fk`),
  KEY `fk_nItem_id_idx` (`nItemId_fk`),
  KEY `fk_nUser_id_idx` (`nUserId_fk`),
  KEY `fk_nGrnType_id_idx` (`nGrnTypeId`),
  KEY `fk_nMainTranfer_id_idx` (`nMainTransferId`),
  KEY `fk_nCommStatus_id_idx` (`nCommercialStatusId`),
  KEY `fk_nFinaceStatus_id_idx` (`financeStatusId`),
  KEY `fk_nfinaceUser_Id_idx` (`financeUserId`),
  KEY `fk_naccountStatus_id_idx` (`accountsStatusId`),
  KEY `fk_accountUser_Id_idx` (`accountsUserId`),
  KEY `fkk_tbl_grn_for_po_each_item_orders_1_idx` (`nGrnId_fk`),
  KEY `fkk_npoidcentral_fk_idx` (`nPoIdCentral_fk`),
  KEY `fkk_npoeach_id_idx` (`nPoEachId`),
  KEY `fkk_npotype_id_idx` (`nPoType_fk`),
  KEY `fkk_nsupplier_id_idx` (`nSupplierId_fk`),
  KEY `fkk_nStore_id_idx` (`nStoreId_fk`),
  KEY `fkk_nGenUser_id_idx` (`nGrnUserId_fk`),
  KEY `fkk_nItem_id_idx` (`nItemId_fk`),
  KEY `fkk_nUser_id_idx` (`nUserId_fk`),
  KEY `fkk_nGrnType_id_idx` (`nGrnTypeId`),
  KEY `fkk_nMainTranfer_id_idx` (`nMainTransferId`),
  KEY `fkk_nCommStatus_id_idx` (`nCommercialStatusId`),
  KEY `fkk_nFinaceStatus_id_idx` (`financeStatusId`),
  KEY `fkk_nfinaceUser_Id_idx` (`financeUserId`),
  KEY `fkk_naccountStatus_id_idx` (`accountsStatusId`),
  KEY `fkk_accountUser_Id_idx` (`accountsUserId`),
  KEY `fk1_tbl_grn_for_po_each_item_orders_1_idx` (`nGrnId_fk`),
  KEY `fk1_npoidcentral_fk_idx` (`nPoIdCentral_fk`),
  KEY `fk1_npoeach_id_idx` (`nPoEachId`),
  KEY `fk1_npotype_id_idx` (`nPoType_fk`),
  KEY `fk1_nsupplier_id_idx` (`nSupplierId_fk`),
  KEY `fk1_nStore_id_idx` (`nStoreId_fk`),
  KEY `fk1_nGenUser_id_idx` (`nGrnUserId_fk`),
  KEY `fk1_nItem_id_idx` (`nItemId_fk`),
  KEY `fk1_nUser_id_idx` (`nUserId_fk`),
  KEY `fk1_nGrnType_id_idx` (`nGrnTypeId`),
  KEY `fk1_nMainTranfer_id_idx` (`nMainTransferId`),
  KEY `fk1_nCommStatus_id_idx` (`nCommercialStatusId`),
  KEY `fk1_nFinaceStatus_id_idx` (`financeStatusId`),
  KEY `fk1_nfinaceUser_Id_idx` (`financeUserId`),
  KEY `fk1_naccountStatus_id_idx` (`accountsStatusId`),
  KEY `fk1_accountUser_Id_idx` (`accountsUserId`),
  CONSTRAINT `fk_ngrn_id` FOREIGN KEY (`nGrnId_fk`) REFERENCES `tbl_grn_for_po_orders` (`aGrnId_pk`),
  CONSTRAINT `fk_nPoidcentral_Id` FOREIGN KEY (`nPoIdCentral_fk`) REFERENCES `tbl_os_po_main_details` (`apoid`),
  CONSTRAINT `fkK_nPoeach_id` FOREIGN KEY (`nPoEachId`) REFERENCES `tbl_os_po_each_item_details` (`apoeachid`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_1` FOREIGN KEY (`nPoType_fk`) REFERENCES `tbl_mst_potypes` (`aPoTypeId`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_2` FOREIGN KEY (`nSupplierId_fk`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_3` FOREIGN KEY (`nStoreId_fk`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_4` FOREIGN KEY (`nGrnUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_5` FOREIGN KEY (`nGrnUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_6` FOREIGN KEY (`nItemId_fk`) REFERENCES `tbl_mst_items_details` (`aItemId_pk`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_7` FOREIGN KEY (`nItemId_fk`) REFERENCES `tbl_mst_items_details` (`aItemId_pk`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_8` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_grn_for_po_each_item_orders_ibfk_9` FOREIGN KEY (`accountsUserId`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_grn_for_po_each_item_orders`
--


--
-- Table structure for table `tbl_grn_for_po_orders`
--

CREATE TABLE `tbl_grn_for_po_orders` (
  `aGrnId_pk` int NOT NULL AUTO_INCREMENT,
  `grnNumber` varchar(50) DEFAULT NULL,
  `nPoIdCentral_fk` int DEFAULT NULL,
  `nPoIdBranch_fk` int DEFAULT NULL,
  `nPoIdBranch_Central_fk` int DEFAULT NULL,
  `nGrnIdCentral_fk` int DEFAULT NULL,
  `sendToBranch` int DEFAULT '0',
  `nPoType_fk` int DEFAULT NULL,
  `nSupplierId_fk` int DEFAULT NULL,
  `nStoreId_fk` int DEFAULT NULL,
  `nGrnUserId_fk` int DEFAULT NULL,
  `grnDate` datetime DEFAULT NULL,
  `dcNumber` varchar(25) DEFAULT NULL,
  `dcDate` datetime DEFAULT NULL,
  `invoiceNumber` varchar(50) DEFAULT NULL,
  `invoiceAmount` float DEFAULT NULL,
  `invoiceTaxAmt` float DEFAULT '0',
  `frightCharges` float DEFAULT NULL,
  `invoicePhotoUploadName` varchar(25) DEFAULT NULL,
  `grnRemarks` text,
  `grnTotalItems` int DEFAULT NULL,
  `grnTotalItemsQty` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `ngrnBranchId_fk` int DEFAULT NULL,
  `issuedToBranch` int DEFAULT '0',
  `centralGRNNum` varchar(25) DEFAULT NULL,
  `centralGrnId` int DEFAULT '0',
  `invoiceDate` datetime DEFAULT NULL,
  `nCommertialStatus` int DEFAULT '0',
  `commercialStatusUpdatedDate` datetime DEFAULT NULL,
  `commercialStatusUpdatedBy` int DEFAULT NULL,
  `statusRemarks` text,
  `centralMainTransferId` int DEFAULT NULL,
  `centralMainGrnId` int DEFAULT '0',
  `accountsStatusId` int DEFAULT NULL,
  `accountsRemarks` text,
  `accountsUserId` int DEFAULT NULL,
  `accountsDate` datetime DEFAULT NULL,
  `isPaid` int DEFAULT '0',
  PRIMARY KEY (`aGrnId_pk`),
  KEY `nPoIdCentral_fk` (`nPoIdCentral_fk`),
  KEY `nPoType_fk` (`nPoType_fk`),
  KEY `nSupplierId_fk` (`nSupplierId_fk`),
  KEY `nStoreId_fk` (`nStoreId_fk`),
  KEY `nGrnUserId_fk` (`nGrnUserId_fk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_grn_for_po_orders_ibfk_1` FOREIGN KEY (`nPoIdCentral_fk`) REFERENCES `tbl_os_po_main_details` (`apoid`),
  CONSTRAINT `tbl_grn_for_po_orders_ibfk_2` FOREIGN KEY (`nPoType_fk`) REFERENCES `tbl_mst_potypes` (`aPoTypeId`),
  CONSTRAINT `tbl_grn_for_po_orders_ibfk_3` FOREIGN KEY (`nSupplierId_fk`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`),
  CONSTRAINT `tbl_grn_for_po_orders_ibfk_4` FOREIGN KEY (`nStoreId_fk`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `tbl_grn_for_po_orders_ibfk_5` FOREIGN KEY (`nGrnUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_grn_for_po_orders_ibfk_6` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_grn_for_po_orders`
--


--
-- Table structure for table `tbl_grn_return_each_details`
--

CREATE TABLE `tbl_grn_return_each_details` (
  `aReturnEachId` int NOT NULL AUTO_INCREMENT,
  `nReturnMainId` int DEFAULT NULL,
  `nStoreId` text,
  `nMainGrnId` int DEFAULT NULL,
  `nEachGrnId` int DEFAULT NULL,
  `returnQty` float DEFAULT NULL,
  `isStockIn` tinyint DEFAULT '0',
  `returnReason` text,
  `returnStatus` tinyint DEFAULT '0',
  `nReturnFromBranchId` int DEFAULT NULL,
  `nReturnToBranchId` int DEFAULT NULL,
  `nReturnToSupplier` int DEFAULT NULL,
  `nReturnType` int DEFAULT NULL,
  `nSupplierMapId` int DEFAULT NULL,
  `returnComments` text,
  `nAuthUserId` int DEFAULT NULL,
  `authDate` datetime DEFAULT NULL,
  `authComments` text,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `itemId` int DEFAULT NULL,
  `supplierId` int DEFAULT NULL,
  PRIMARY KEY (`aReturnEachId`),
  KEY `nReturnMainId` (`nReturnMainId`),
  CONSTRAINT `tbl_grn_return_each_details_ibfk_1` FOREIGN KEY (`nReturnMainId`) REFERENCES `tbl_grn_return_main_details` (`aReturnMainId`),
  CONSTRAINT `tbl_grn_return_each_details_ibfk_2` FOREIGN KEY (`nReturnMainId`) REFERENCES `tbl_grn_return_main_details` (`aReturnMainId`),
  CONSTRAINT `tbl_grn_return_each_details_ibfk_3` FOREIGN KEY (`nReturnMainId`) REFERENCES `tbl_grn_return_main_details` (`aReturnMainId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_grn_return_each_details`
--


--
-- Table structure for table `tbl_grn_return_main_details`
--

CREATE TABLE `tbl_grn_return_main_details` (
  `aReturnMainId` int NOT NULL AUTO_INCREMENT,
  `returnNumber` text,
  `nStoreId` text,
  `nMainGrnId` int DEFAULT NULL,
  `nEachGrnId` int DEFAULT NULL,
  `returnQty` float DEFAULT NULL,
  `returnReason` text,
  `nReturnedUserId` int DEFAULT NULL,
  `nReturnedDate` datetime DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `nReturnToBranchId` int DEFAULT NULL,
  `nReturnToSupplier` int DEFAULT NULL,
  `nReturnType` int DEFAULT NULL,
  `nSupplierMapId` int DEFAULT NULL,
  `returnComments` text,
  `nAuthUserId` int DEFAULT NULL,
  `authDate` datetime DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aReturnMainId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_grn_return_main_details`
--


--
-- Table structure for table `tbl_grn_status_history_log`
--

CREATE TABLE `tbl_grn_status_history_log` (
  `agrnhistoryId` int NOT NULL AUTO_INCREMENT,
  `nGrnForPoMainId` int DEFAULT NULL,
  `nGrnForEachId` int DEFAULT NULL,
  `GrnBy` int DEFAULT NULL,
  `GrnAt` datetime DEFAULT NULL,
  `statusId` int DEFAULT NULL,
  `remarks` varchar(45) DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`agrnhistoryId`),
  KEY `nGrnForPoMainId` (`nGrnForPoMainId`),
  KEY `nGrnForEachId` (`nGrnForEachId`),
  KEY `GrnBy` (`GrnBy`),
  CONSTRAINT `tbl_grn_status_history_log_ibfk_1` FOREIGN KEY (`nGrnForPoMainId`) REFERENCES `tbl_grn_for_po_orders` (`aGrnId_pk`),
  CONSTRAINT `tbl_grn_status_history_log_ibfk_2` FOREIGN KEY (`nGrnForEachId`) REFERENCES `tbl_grn_for_po_each_item_orders` (`aGrnId_each_pk`),
  CONSTRAINT `tbl_grn_status_history_log_ibfk_3` FOREIGN KEY (`GrnBy`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_grn_status_history_log`
--


--
-- Table structure for table `tbl_modules`
--

CREATE TABLE `tbl_modules` (
  `aModuleId` int NOT NULL AUTO_INCREMENT,
  `priority` float NOT NULL,
  `moduleName` varchar(100) DEFAULT NULL,
  `moduleNameForMobile` varchar(100) DEFAULT NULL,
  `isHavingSubModule` int DEFAULT NULL,
  `isMobileOrWeb` int DEFAULT NULL,
  `moduleId` int DEFAULT NULL COMMENT 'Module Id refers to aModuleId of same table',
  `fnOnClick` varchar(250) NOT NULL COMMENT 'This is the function name that will be triggered (in js) on click of a link in jsp',
  `moduleIcon` varchar(45) DEFAULT NULL,
  `fnOnClickForMobile` varchar(250) DEFAULT NULL,
  `moduleIconForMobile` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT NULL,
  `lastModifiedDate` datetime DEFAULT NULL,
  `isActive` int DEFAULT NULL,
  `isDeleted` int DEFAULT NULL,
  `nUserId` int DEFAULT NULL,
  `nHospitalId` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  PRIMARY KEY (`aModuleId`),
  UNIQUE KEY `moduleName_UNIQUE` (`moduleName`),
  KEY `fk_tblModules_1_idx` (`nUserId`),
  CONSTRAINT `fk_tblModules_1` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `tbl_modules`
--

INSERT INTO `tbl_modules` VALUES (1,0,'Verify API',NULL,0,1,NULL,'verifyapi','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(2,1,'Home',NULL,0,1,NULL,'home','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(3,2,'Purchase Orders',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(4,2.1,'Generate Purchase Orders',NULL,2,1,3,'purchaseOrders','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(5,2.2,'GRN',NULL,2,1,3,'grnDetails','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(6,3,'Indents',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(7,3.1,'Generate Indents',NULL,2,1,6,'indent','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(8,3.2,'Stock Issue',NULL,2,1,6,'stockTransfer','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(9,3.3,'Stock Accept',NULL,2,1,6,'stockAcceptanceWithIndent','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(10,4,'Consignments Stock',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,0,0,1,1,1),(11,4.1,'Consignments Purchase Order',NULL,2,1,10,'consignmentStockIn','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(12,4.3,'Consignments Stock Transfer',NULL,2,1,10,'stockTranferToBranch','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(13,4.4,'Consignments Stock Accept',NULL,2,1,10,'stockAcceptanceWoIndent','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(14,7,'Commercials',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,0,0,1,1,1),(15,7.1,'Finance',NULL,2,1,14,'financeDetails','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(16,7.2,'Accounts',NULL,2,1,14,'accountsDetails','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(17,8,'Masters',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(18,8.2,'Add users',NULL,2,1,17,'userRegistration','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(19,8.3,'Add Items',NULL,2,1,17,'itemRegistration','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(20,8.4,'Add Suppliers',NULL,2,1,17,'supplierRegistration','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(21,8.5,'Map Supplier & Items',NULL,2,1,17,'supplierItemRateMap','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(22,5,'Stock Issue To Hospital',NULL,0,1,NULL,'stockToUser','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(23,6,'Inventory',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(24,6.1,'Items In Stock',NULL,2,1,23,'inStock','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(25,6.2,'ROL & ROQ',NULL,2,1,23,'itemLevels','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(26,4.2,'Consignment GRN',NULL,2,1,10,'consignmentGrn','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(27,9,'Goods Returns',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(28,9.1,'Return Items',NULL,2,1,27,'returntoDepo','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(29,9.2,'Return to supplier',NULL,2,1,27,'returntosupplier','fa fa-angle-right',NULL,NULL,NULL,NULL,0,1,1,1,1),(30,10,'Goods Replacement',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,0,0,1,1,1),(31,10.1,'Replace With Depo',NULL,2,1,30,'deporeplacements','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(32,10.2,'Replace With Supplier',NULL,2,1,30,'supplierreplacements','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(33,9.3,'Accept Return Items',NULL,2,1,27,'returnsFromBranch','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(34,11,'Debits & Credits',NULL,1,1,NULL,'','fa fa-shopping-cart',NULL,NULL,NULL,NULL,0,0,1,1,1),(35,11.1,'Debit Notes',NULL,2,1,34,'debitNotes','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(36,11.2,'Credit Notes',NULL,2,1,34,'creditNotes','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(37,12,'Dash Board',NULL,0,1,NULL,'DashBoard','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(38,13,'Stock Consumption',NULL,1,1,NULL,'otStockMgm','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(39,13.1,'Patient Wise Consumption',NULL,2,1,38,'otStockConsumption','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(42,14,'Stock Report',NULL,0,1,NULL,'ocStocksOnDate','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(43,14.1,'Stocks On Date','',2,1,42,'ocStocksOnDate','fa fa-angle-right',NULL,NULL,NULL,NULL,0,1,1,1,1),(44,15,'Reports',NULL,1,1,NULL,' ','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(45,15.1,'GRN Reports',NULL,2,1,44,'grnReports','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(46,15.2,'GRN ItemWise Report',NULL,2,1,44,'grnItemWiseReport','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(47,13.2,'Day Wise Consumption',NULL,2,1,38,'OPDConsumption','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(48,15.3,'Items Availability Report',NULL,2,1,44,'itemsAvailabilityDetails','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(49,8.1,'Branch Registration',NULL,2,1,17,'branchRegistration','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(51,8.6,'Map Branch & Items',NULL,2,1,17,'branchItemRateMap','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(52,15.4,'Grn Wise Consumption',NULL,2,1,44,'grnWiseConsumption','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(53,15.5,'Consumed Consignment Stock',NULL,2,1,44,'consumedConsignmentStock','fa fa-angle-right',NULL,NULL,NULL,NULL,0,0,1,1,1),(54,16,'Supplier Payment',NULL,0,1,NULL,'venderPaymentDetails','fa fa-shopping-cart',NULL,NULL,NULL,NULL,1,0,1,1,1),(55,15.6,'Supplier Payment Report',NULL,2,1,44,'vendorPaymentReport','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(56,17,'Stock Transfer W/O Indent',NULL,0,1,NULL,'stockTransferwoindent','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(57,18,'Stock Accept Without Indent',NULL,0,1,NULL,'stockAcceptanceWithOutIndent','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(58,15.7,'Goods Return Report',NULL,2,1,44,'goodsReturnReport','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(59,8.7,'add HSN Code',NULL,2,1,17,'hsnCodeRegistration','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1),(61,15.9,'Puchase GST Reports',NULL,2,1,44,'purchaseGstReports','fa fa-angle-right',NULL,NULL,NULL,NULL,1,0,1,1,1);

--
-- Table structure for table `tbl_mst_bank`
--

CREATE TABLE `tbl_mst_bank` (
  `aBankId_pk` int NOT NULL,
  `name` varchar(50) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aBankId_pk`),
  KEY `FK_tbl_mst_bank_tbl_user` (`nUserId_fk`),
  CONSTRAINT `FK_tbl_mst_bank_tbl_user` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_bank`
--

INSERT INTO `tbl_mst_bank` VALUES (1,'State Bank of India',NULL,'2018-07-09 10:56:40','2018-07-09 10:56:40',1,0,1),(2,'ICICI Bank',NULL,'2018-07-09 10:56:40','2018-07-09 10:56:40',1,0,1),(3,'Axis Bank',NULL,'2018-07-09 10:56:40','2018-07-09 10:56:40',1,0,1),(4,'Corporation Bank',NULL,'2018-07-09 10:56:40','2018-07-09 10:56:40',1,0,1);

--
-- Table structure for table `tbl_mst_branchflagdescription`
--

CREATE TABLE `tbl_mst_branchflagdescription` (
  `id` int NOT NULL AUTO_INCREMENT,
  `branchTypeName` varchar(250) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_branchflagdescription`
--

INSERT INTO `tbl_mst_branchflagdescription` VALUES (1,'Depo','2019-08-28 14:59:14','2019-08-28 14:59:14',1,0),(2,'Hub','2019-08-28 14:59:14','2019-08-28 14:59:14',1,0),(3,'Branch','2019-08-28 14:59:14','2019-08-28 14:59:14',1,0);

--
-- Table structure for table `tbl_mst_brands`
--

CREATE TABLE `tbl_mst_brands` (
  `aBrandTypeId_pk` int NOT NULL AUTO_INCREMENT,
  `brandName` varchar(100) DEFAULT NULL,
  `nStoreId_fk` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aBrandTypeId_pk`),
  KEY `nStoreId_fk` (`nStoreId_fk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_brands_ibfk_1` FOREIGN KEY (`nStoreId_fk`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `tbl_mst_brands_ibfk_2` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_brands`
--

INSERT INTO `tbl_mst_brands` VALUES (1,'Blade',2,'2019-10-18 12:41:01','2019-10-18 12:41:01',1,0,NULL),(2,'Cannula',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(3,'Cap',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(4,'Capsule',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(5,'Cleaning solution',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(6,'Cotton',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(7,'Drape',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(8,'Eye Drop',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(9,'Gel',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(10,'Gloves',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(11,'Injection',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(12,'Needle',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(13,'Oil',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(14,'Ointment',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(15,'Other',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(16,'Phaco Pack',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(17,'Retina Pack',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(18,'Roll',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(19,'Solution',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(20,'Strips',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(21,'Suture',2,'2019-10-18 12:41:02','2019-10-18 12:41:02',1,0,NULL),(22,'Syringe',2,'2019-10-18 12:41:03','2019-10-18 12:41:03',1,0,NULL),(23,'Tablet',2,'2019-10-18 12:41:03','2019-10-18 12:41:03',1,0,NULL),(24,'Tape',2,'2019-10-18 12:41:03','2019-10-18 12:41:03',1,0,NULL),(25,'Tube',2,'2019-10-18 12:41:03','2019-10-18 12:41:03',1,0,NULL),(26,'Lens',1,'2019-10-18 12:41:03','2019-10-18 12:41:03',1,0,NULL),(27,'	Alcon Laboratories',1,'2020-03-11 13:26:48','2020-03-11 13:26:48',1,0,NULL);

--
-- Table structure for table `tbl_mst_business_type`
--

CREATE TABLE `tbl_mst_business_type` (
  `aBusinessId_pk` int NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint(1) DEFAULT '1',
  `isDeleted` tinyint(1) DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aBusinessId_pk`),
  KEY `FK_tbl_user_tbl_mst_business_type` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_business_type_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_business_type`
--

INSERT INTO `tbl_mst_business_type` VALUES (1,'Manufacturer',NULL,'2018-07-09 10:58:05','2018-07-09 10:58:05',1,0,1),(2,'Supplier',NULL,'2018-07-09 10:58:05','2018-07-09 10:58:05',1,0,1),(3,'Both',NULL,'2018-07-09 10:58:05','2018-07-09 10:58:05',1,0,1),(4,'Others',NULL,'2018-07-09 10:58:05','2018-07-09 10:58:05',1,0,1);

--
-- Table structure for table `tbl_mst_cities`
--

CREATE TABLE `tbl_mst_cities` (
  `aCityId_pk` int NOT NULL AUTO_INCREMENT,
  `nLocationId_fk` int DEFAULT NULL,
  `cityCode` varchar(10) DEFAULT NULL,
  `cityShortCode` varchar(10) DEFAULT NULL,
  `cityName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aCityId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `nLocationId_fk` (`nLocationId_fk`),
  CONSTRAINT `tbl_mst_cities_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_mst_cities_ibfk_2` FOREIGN KEY (`nLocationId_fk`) REFERENCES `tbl_mst_locations` (`aLocationId_pk`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_cities`
--

INSERT INTO `tbl_mst_cities` VALUES (1,1,'99','NDL','New Delhi','2018-07-03 17:27:26','2018-07-03 17:27:26',1,0,1),(2,2,'97','Bha','Bharuch','2018-07-03 17:34:17','2018-07-03 17:34:17',1,0,1),(3,3,'96','Bar','Bardoli','2018-07-03 17:33:36','2018-07-03 17:33:36',1,0,1),(4,1,'95','Fat','Fatehgunj','2018-07-03 17:32:47','2018-07-03 17:32:47',1,0,1),(5,2,'91','Parle','Parle Point','2018-07-09 11:21:45','2018-07-09 11:21:45',1,0,1),(6,3,'91','Ran','Rander Road','2018-07-09 11:21:45','2018-07-09 11:21:45',1,0,1),(7,1,'91','Ud','Udhana','2018-07-09 11:21:45','2018-07-09 11:21:45',1,0,1),(8,2,'91','Sup','Supermart-I','2018-07-09 11:21:45','2018-07-09 11:21:45',1,0,1),(9,3,'91','New','New Railway Road','2018-07-09 11:21:45','2018-07-09 11:21:45',1,0,1);

--
-- Table structure for table `tbl_mst_commercialstatus`
--

CREATE TABLE `tbl_mst_commercialstatus` (
  `aCommercialStatusId` int NOT NULL AUTO_INCREMENT,
  `nCommercialStatus` varchar(50) DEFAULT NULL,
  `nCommercialStatusShortCode` varchar(5) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aCommercialStatusId`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_commercialstatus`
--

INSERT INTO `tbl_mst_commercialstatus` VALUES (0,'No Show','NS','2018-07-20 12:11:49','2018-07-20 12:11:49',1,0,NULL),(1,'Finance Approved','FA','2018-07-20 12:11:49','2018-07-20 12:11:49',1,0,NULL),(2,'Finance Hold','FH','2018-07-20 12:11:49','2018-07-20 12:11:49',1,0,NULL),(3,'Finance Rejected','FR','2018-07-20 12:11:49','2018-07-20 12:11:49',1,0,NULL),(4,'Accounts Approved','AP','2018-07-20 12:11:49','2018-07-20 12:11:49',1,0,NULL),(5,'Accounts Hold','AH','2018-07-20 12:11:49','2018-07-20 12:11:49',1,0,NULL),(6,'Accounts Rejected','AR','2018-07-20 12:11:49','2018-07-20 12:11:49',1,0,NULL);

--
-- Table structure for table `tbl_mst_countries`
--

CREATE TABLE `tbl_mst_countries` (
  `aCountryId_pk` int NOT NULL AUTO_INCREMENT,
  `countryCode` varchar(10) DEFAULT NULL,
  `countryShortCode` varchar(10) DEFAULT NULL,
  `countryName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aCountryId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_countries_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_countries`
--

INSERT INTO `tbl_mst_countries` VALUES (1,'91','IND','INDIA','2018-07-03 13:59:54','2018-07-03 13:59:54',1,0,NULL),(2,'92','USA','UNITED STATES OF AMERICA','2018-07-03 13:59:54','2018-07-03 13:59:54',1,0,NULL),(3,'977','RSA','RUSSIA','2018-07-03 13:59:54','2018-07-03 13:59:54',1,0,NULL),(4,'880','ISR','ISRALE','2018-07-03 13:59:54','2018-07-03 13:59:54',1,0,NULL);

--
-- Table structure for table `tbl_mst_customers`
--

CREATE TABLE `tbl_mst_customers` (
  `aCustomerId_pk` int NOT NULL AUTO_INCREMENT,
  `nSubgroupId_fk` int DEFAULT NULL,
  `customerShortCode` varchar(10) DEFAULT NULL,
  `customerName` varchar(100) DEFAULT NULL,
  `nLocationId_fk` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aCustomerId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `nLocationId_fk` (`nLocationId_fk`),
  CONSTRAINT `tbl_mst_customers_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_mst_customers_ibfk_2` FOREIGN KEY (`nLocationId_fk`) REFERENCES `tbl_mst_locations` (`aLocationId_pk`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_customers`
--


--
-- Table structure for table `tbl_mst_grn_status`
--

CREATE TABLE `tbl_mst_grn_status` (
  `agrnstatusid` int NOT NULL AUTO_INCREMENT,
  `grnsatatusDescription` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`agrnstatusid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_grn_status`
--

INSERT INTO `tbl_mst_grn_status` VALUES (1,'Partially Delivered'),(2,'Delivered');

--
-- Table structure for table `tbl_mst_grntypes`
--

CREATE TABLE `tbl_mst_grntypes` (
  `aGrnTypeId` int NOT NULL AUTO_INCREMENT,
  `grnTypeName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aGrnTypeId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_grntypes`
--

INSERT INTO `tbl_mst_grntypes` VALUES (1,'GRN','2018-11-29 19:55:21','2018-11-29 19:55:21',1,0,NULL),(2,'Indent Stock Acceptance','2018-11-29 19:55:21','2018-11-29 19:55:21',1,0,NULL),(3,'Consignment Stock Acceptance','2018-11-29 19:55:21','2018-11-29 19:55:21',1,0,NULL),(4,'Stock Accept Without Indent','2020-03-16 17:31:53','2020-03-16 17:31:53',1,0,NULL);

--
-- Table structure for table `tbl_mst_groups`
--

CREATE TABLE `tbl_mst_groups` (
  `aGroupId_pk` int NOT NULL AUTO_INCREMENT,
  `groupShortCode` varchar(10) DEFAULT NULL,
  `groupName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aGroupId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_groups_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_groups`
--


--
-- Table structure for table `tbl_mst_hsn_codes`
--

CREATE TABLE `tbl_mst_hsn_codes` (
  `aHsnAutoId_pk` int NOT NULL AUTO_INCREMENT,
  `hsnCode` varchar(15) DEFAULT NULL,
  `gstPercentage` double DEFAULT NULL,
  `sgstPercentage` double DEFAULT NULL,
  `cgstPercentage` double DEFAULT NULL,
  `igstPercentage` double DEFAULT NULL,
  `nCountryId_fk` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aHsnAutoId_pk`),
  KEY `nCountryId_fk` (`nCountryId_fk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_hsn_codes_ibfk_1` FOREIGN KEY (`nCountryId_fk`) REFERENCES `tbl_mst_countries` (`aCountryId_pk`),
  CONSTRAINT `tbl_mst_hsn_codes_ibfk_2` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_hsn_codes`
--

INSERT INTO `tbl_mst_hsn_codes` VALUES (1,'2905',18,9,9,18,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(2,'2912',18,9,9,18,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(3,'3002',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(4,'3003',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(5,'3004',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(6,'3005',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(7,'3006',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(8,'3038',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(9,'3401',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(10,'3808',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(11,'3822',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(12,'3919',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(13,'3923',12,6,6,12,1,'2019-10-18 12:46:11','2019-10-18 12:46:11',1,0,NULL),(14,'4015',12,6,6,12,1,'2019-10-18 12:46:12','2019-10-18 12:46:12',1,0,NULL),(15,'4823',12,6,6,12,1,'2019-10-18 12:46:12','2019-10-18 12:46:12',1,0,NULL),(16,'6210',12,6,6,12,1,'2019-10-18 12:46:12','2019-10-18 12:46:12',1,0,NULL),(17,'9002',12,6,6,12,1,'2019-10-18 12:46:12','2019-10-18 12:46:12',1,0,NULL),(18,'9004',12,6,6,12,1,'2019-10-18 12:46:12','2019-10-18 12:46:12',1,0,NULL),(19,'9018',12,6,6,12,1,'2019-10-18 12:46:12','2019-10-18 12:46:12',1,0,NULL),(20,'9619',12,6,6,12,1,'2019-10-18 12:46:12','2019-10-18 12:46:12',1,0,NULL);

--
-- Table structure for table `tbl_mst_item_category`
--

CREATE TABLE `tbl_mst_item_category` (
  `aCategoryId_pk` int NOT NULL AUTO_INCREMENT,
  `itemCategoryCode` varchar(100) DEFAULT NULL,
  `itemCategoryName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aCategoryId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_item_category_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_item_category`
--

INSERT INTO `tbl_mst_item_category` VALUES (1,'IOLCat','LASIK CONSUMABLES','2018-07-03 14:57:37','2018-07-03 14:57:37',1,0,NULL),(2,'cat','CATARACT MACHINE SPECIFIC CONSUMABLES','2018-07-09 15:38:13','2018-07-09 15:38:13',1,0,NULL),(3,'OINT','RETINA INJECTIONS','2018-07-09 15:38:13','2018-07-09 15:38:13',1,0,NULL),(4,'ret con','RETINA CONSUMABLES','2018-07-09 15:38:13','2018-07-09 15:38:13',1,0,NULL),(5,'surg cons','SURGERY CONSUMABLES','2018-07-09 15:38:13','2018-07-09 15:38:13',1,0,NULL),(6,'ster','STERILIZATION MATERIAL','2018-07-09 15:38:13','2018-07-09 15:38:13',1,0,NULL),(7,'anes','ANESTHESIA','2018-07-09 15:38:13','2018-07-09 15:38:13',1,0,NULL),(8,'enzy','ENZYMATIC SOLUTION','2018-07-09 15:38:13','2018-07-09 15:38:13',1,0,NULL);

--
-- Table structure for table `tbl_mst_item_manufacturers`
--

CREATE TABLE `tbl_mst_item_manufacturers` (
  `aManufacturerId_pk` int NOT NULL AUTO_INCREMENT,
  `manufacturerCode` varchar(10) DEFAULT NULL,
  `manufacturerShortCode` varchar(10) DEFAULT NULL,
  `manufacturerName` varchar(250) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aManufacturerId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_item_manufacturers_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_item_manufacturers`
--

INSERT INTO `tbl_mst_item_manufacturers` VALUES (1,'1','man01','Abbott','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(2,'2','man02','Alcon','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(3,'3','man03','Alkem Laboratories Ltd','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(4,'4','man04','Allergan','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(5,'5','man05','Ansell','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(6,'6','man06','Appasamy','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(7,'7','man07','Aurolab','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(8,'8','man08','Bausch & Lomb','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(9,'9','man09','Biochem','2019-10-18 12:42:56','2019-10-18 12:42:56',1,0,NULL),(10,'10','man10','Cipla','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(11,'11','man11','FDC','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(12,'12','man12','Indoco','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(13,'13','man13','Intas','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(14,'14','man14','Jawa','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(15,'15','man15','Kite Medica','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(16,'16','man16','Martin Brown Bio Sciences','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(17,'17','man17','MRK Healthcare Pvt Ltd','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(18,'18','man18','Neon Laboratories Ltd','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(19,'19','man19','Novartis','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(20,'20','man20','Pfizer','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(21,'21','man21','Pharmatak','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(22,'22','man22','Roche Pharma','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(23,'23','man23','Sanofi','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(24,'24','man24','Shreya Life Sciences Pvt Ltd','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(25,'25','man25','Sun Pharma','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(26,'26','man26','Sunways','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(27,'27','man27','Torque Pharmaceuticals','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(28,'28','man28','Torrent Pharmaceuticals','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(29,'29','man29','Trident Medlife','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(30,'30','man30','Troikaa Pharmaceuticals','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(31,'31','man31','Win-Medicare','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(32,'32','man32','Zydus Cadila','2019-10-18 12:42:57','2019-10-18 12:42:57',1,0,NULL),(33,'33','man33','Alcon','2019-10-18 12:42:58','2019-10-18 12:42:58',1,0,NULL),(34,'34','man34','Abbott Medical Optics','2019-10-18 12:42:58','2019-10-18 12:42:58',1,0,NULL),(35,'35','man35','Appasamy','2019-10-18 12:42:58','2019-10-18 12:42:58',1,0,NULL),(36,'36','man36','manufacturer','2019-10-18 12:42:58','2019-10-18 12:42:58',1,0,NULL);

--
-- Table structure for table `tbl_mst_item_subcategory`
--

CREATE TABLE `tbl_mst_item_subcategory` (
  `aSubcategoryId_pk` int NOT NULL AUTO_INCREMENT,
  `nCategoryId_fk` int DEFAULT NULL,
  `itemSubcatCode` varchar(10) DEFAULT NULL,
  `itemSubcatName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `nHsnId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aSubcategoryId_pk`),
  KEY `nCategoryId_fk` (`nCategoryId_fk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `nHsnId_fk` (`nHsnId_fk`),
  CONSTRAINT `tbl_mst_item_subcategory_ibfk_1` FOREIGN KEY (`nCategoryId_fk`) REFERENCES `tbl_mst_item_category` (`aCategoryId_pk`),
  CONSTRAINT `tbl_mst_item_subcategory_ibfk_2` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_mst_item_subcategory_ibfk_3` FOREIGN KEY (`nHsnId_fk`) REFERENCES `tbl_mst_hsn_codes` (`aHsnAutoId_pk`),
  CONSTRAINT `tbl_mst_item_subcategory_ibfk_4` FOREIGN KEY (`nHsnId_fk`) REFERENCES `tbl_mst_hsn_codes` (`aHsnAutoId_pk`),
  CONSTRAINT `tbl_mst_item_subcategory_ibfk_5` FOREIGN KEY (`nHsnId_fk`) REFERENCES `tbl_mst_hsn_codes` (`aHsnAutoId_pk`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_item_subcategory`
--

INSERT INTO `tbl_mst_item_subcategory` VALUES (1,NULL,'SUB1','IOL','2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL,NULL),(2,NULL,'sub2','OT Stock','2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL,NULL),(3,NULL,'SUB3','OPD Stock','2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL,NULL);

--
-- Table structure for table `tbl_mst_items_details`
--

CREATE TABLE `tbl_mst_items_details` (
  `aItemId_pk` int NOT NULL AUTO_INCREMENT,
  `nStoreId_fk` int DEFAULT NULL,
  `itemCode` varchar(10) DEFAULT NULL,
  `itemShortCode` varchar(30) DEFAULT NULL,
  `itemName` varchar(250) DEFAULT NULL,
  `nItemSubcatId_fk` int DEFAULT NULL,
  `nBrandTypeId_fk` int DEFAULT NULL,
  `strength` varchar(25) DEFAULT NULL,
  `volume` varchar(25) DEFAULT NULL,
  `nItemtypeId_fk` int DEFAULT NULL,
  `nItemtypeMakeId_fk` int DEFAULT NULL,
  `itemDescription` varchar(500) DEFAULT NULL,
  `nItemManufacturerId_fk` int DEFAULT NULL,
  `genericName` text,
  `nHsnCodeId_fk` int DEFAULT NULL,
  `ROL` int DEFAULT NULL,
  `ROQ` int DEFAULT NULL,
  `UNIT` varchar(45) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aItemId_pk`),
  KEY `nStoreId_fk` (`nStoreId_fk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `nItemSubcatId_fk` (`nItemSubcatId_fk`),
  KEY `nBrandTypeId_fk` (`nBrandTypeId_fk`),
  KEY `nItemtypeId_fk` (`nItemtypeId_fk`),
  KEY `nItemtypeMakeId_fk` (`nItemtypeMakeId_fk`),
  KEY `nItemManufacturerId_fk` (`nItemManufacturerId_fk`),
  KEY `nHsnCodeId_fk` (`nHsnCodeId_fk`),
  CONSTRAINT `tbl_mst_items_details_ibfk_1` FOREIGN KEY (`nStoreId_fk`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `tbl_mst_items_details_ibfk_2` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_mst_items_details_ibfk_3` FOREIGN KEY (`nItemSubcatId_fk`) REFERENCES `tbl_mst_item_subcategory` (`aSubcategoryId_pk`),
  CONSTRAINT `tbl_mst_items_details_ibfk_4` FOREIGN KEY (`nBrandTypeId_fk`) REFERENCES `tbl_mst_brands` (`aBrandTypeId_pk`),
  CONSTRAINT `tbl_mst_items_details_ibfk_5` FOREIGN KEY (`nItemtypeId_fk`) REFERENCES `tbl_mst_items_type` (`aItemtypeId_pk`),
  CONSTRAINT `tbl_mst_items_details_ibfk_6` FOREIGN KEY (`nItemtypeMakeId_fk`) REFERENCES `tbl_mst_items_make_type` (`aItemsMakeTypeId_pk`),
  CONSTRAINT `tbl_mst_items_details_ibfk_7` FOREIGN KEY (`nItemManufacturerId_fk`) REFERENCES `tbl_mst_item_manufacturers` (`aManufacturerId_pk`),
  CONSTRAINT `tbl_mst_items_details_ibfk_8` FOREIGN KEY (`nHsnCodeId_fk`) REFERENCES `tbl_mst_hsn_codes` (`aHsnAutoId_pk`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_items_details`
--


--
-- Table structure for table `tbl_mst_items_make_type`
--

CREATE TABLE `tbl_mst_items_make_type` (
  `aItemsMakeTypeId_pk` int NOT NULL AUTO_INCREMENT,
  `itemMakeTypeCode` varchar(10) DEFAULT NULL,
  `itemMakeTypeName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aItemsMakeTypeId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_items_make_type_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_items_make_type`
--

INSERT INTO `tbl_mst_items_make_type` VALUES (1,'IMP1','IMPORTED HYDROPHOBIC  ASPHERIC','2018-07-03 15:40:24','2018-07-03 15:40:24',1,0,NULL),(2,'IMP2','IMPORTED HYDROPHOBIC ASPHERIC YELLOW LENSE','2018-07-03 15:40:24','2018-07-03 15:40:24',1,0,NULL),(3,'IND1','INDIAN HYDROPHILIC SPHERIC','2018-07-03 15:40:24','2018-07-03 15:40:24',1,0,NULL),(4,'IMP3','IMPORTED HYDROPHOBIC SPHERIC','2018-07-03 15:40:24','2018-07-03 15:40:24',1,0,NULL),(5,'IND2','INDIAN HYDROPHILIC SPHERIC','2018-07-03 15:40:24','2018-07-03 15:40:24',1,0,NULL),(6,'IND3','INDIAN HYDROPHOBIC ASPHERIC','2018-07-03 15:40:24','2018-07-03 15:40:24',1,0,NULL);

--
-- Table structure for table `tbl_mst_items_type`
--

CREATE TABLE `tbl_mst_items_type` (
  `aItemtypeId_pk` int NOT NULL AUTO_INCREMENT,
  `itemtypeCode` varchar(10) DEFAULT NULL,
  `itemtypeName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aItemtypeId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_items_type_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_items_type`
--

INSERT INTO `tbl_mst_items_type` VALUES (1,'FLD','FOLDABLE','2018-07-03 15:34:53','2018-07-03 15:34:53',1,0,NULL),(2,'NFLD','NON FOLDABLE','2018-07-03 15:34:53','2018-07-03 15:34:53',1,0,NULL);

--
-- Table structure for table `tbl_mst_locations`
--

CREATE TABLE `tbl_mst_locations` (
  `aLocationId_pk` int NOT NULL AUTO_INCREMENT,
  `locnCode` varchar(10) DEFAULT NULL,
  `locnShortCode` varchar(10) DEFAULT NULL,
  `locnName` varchar(100) DEFAULT NULL,
  `nCountryId_fk` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aLocationId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `nCountryId_fk` (`nCountryId_fk`),
  CONSTRAINT `tbl_mst_locations_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_mst_locations_ibfk_2` FOREIGN KEY (`nCountryId_fk`) REFERENCES `tbl_mst_countries` (`aCountryId_pk`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_locations`
--

INSERT INTO `tbl_mst_locations` VALUES (1,NULL,'bang','banglore',NULL,'2019-12-06 12:27:37','2019-12-06 12:27:37',1,0,NULL),(2,NULL,'mys','mysore',NULL,'2020-03-05 19:34:16','2020-03-05 19:34:16',1,0,NULL);

--
-- Table structure for table `tbl_mst_miscellaneous`
--

CREATE TABLE `tbl_mst_miscellaneous` (
  `aMiscellaneousId` int NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aMiscellaneousId`),
  KEY `FK_tbl_mst_miscellaneous_tbl_user_userId` (`nUserId_fk`),
  CONSTRAINT `FK_tbl_mst_miscellaneous_tbl_user_userId` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_miscellaneous`
--

INSERT INTO `tbl_mst_miscellaneous` VALUES (1,'Consignment',NULL,'2018-07-09 15:42:59','2018-07-09 15:42:59',1,0,NULL);

--
-- Table structure for table `tbl_mst_module_features`
--

CREATE TABLE `tbl_mst_module_features` (
  `aMstModFeatureId` int NOT NULL AUTO_INCREMENT,
  `nModuleId` int DEFAULT NULL,
  `featureName` varchar(100) DEFAULT NULL,
  `isDeleted` tinyint DEFAULT '0',
  `isActive` tinyint DEFAULT '1',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `nUserId` int DEFAULT NULL,
  PRIMARY KEY (`aMstModFeatureId`),
  UNIQUE KEY `featureName` (`featureName`)
) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_module_features`
--

INSERT INTO `tbl_mst_module_features` VALUES (1,4,'PO_INDENT',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(2,8,'GET_BRANCH_INDENT',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(3,4,'AUTHORIZE_LINK',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(4,8,'AUTHORIZE_BTN',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(5,4,'REJECT_BTN',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(6,4,'FORCE_CLOSE_BTN',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(7,8,'CENTRAL_LOGIN',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(8,8,'ORDER_LINK',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(9,8,'PUSH_TO_CENTRAL_BTN',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(10,8,'ORDER_FORCE_CLOSE_BTN',0,1,'2018-08-16 13:10:42','2018-08-16 13:10:42',2),(11,5,'GRN',0,1,'2018-08-16 13:17:09','2018-08-16 13:17:09',2),(12,NULL,'GRN_ONLY_DC',0,1,'2018-08-16 13:17:09','2018-08-16 13:17:09',2),(13,5,'GRN_ONLY_INVOICE',0,1,'2018-08-16 13:17:09','2018-08-16 13:17:09',2),(14,5,'GRN_BOTH_DC_AND_INVOICE',0,1,'2018-08-16 13:17:09','2018-08-16 13:17:09',2),(15,5,'RECEIVED_GOODS',0,1,'2018-08-16 13:17:09','2018-08-16 13:17:09',2),(16,NULL,'GRN_RECEIVEDGOODS_UPDATE',0,1,'2018-08-16 13:17:09','2018-08-16 13:17:09',2),(17,NULL,'INSTOCK',0,1,'2018-08-16 13:17:09','2018-08-16 13:17:09',2),(18,8,'ISSUE_ITEMS_LINK',0,1,'2018-08-16 13:26:14','2018-08-16 13:26:14',2),(19,20,'ISSUE_IOL',0,1,'2018-08-16 13:26:14','2018-08-16 13:26:14',2),(20,20,'ISSUE_OT_STOCK',0,1,'2018-08-16 13:26:14','2018-08-16 13:26:14',2),(21,20,'ISSUE_OPD',0,1,'2018-08-16 13:26:14','2018-08-16 13:26:14',2),(22,8,'TRANSFER_PRINT_DC',0,1,'2018-08-16 13:26:14','2018-08-16 13:26:14',2),(23,8,'ISSUED_ITEMS_LINK',0,1,'2018-08-16 13:26:14','2018-08-16 13:26:14',2),(24,8,'ISSUED_PRINT_DC',0,1,'2018-08-16 13:26:14','2018-08-16 13:26:14',2),(25,4,'PRINT_PO',0,1,'2018-08-22 13:26:14','2018-08-22 13:26:14',2),(26,5,'GRN_BRANCH',0,1,'2018-08-29 13:26:14','2018-08-29 13:26:14',2),(27,5,'AUTO_GRN_BRANCH',0,1,'2018-08-29 13:26:14','2018-08-29 13:26:14',2),(28,37,'DASH_BOARD',0,1,'2018-08-29 13:26:14','2018-08-29 13:26:14',2),(29,7,'IND_PO_INDENT',0,1,'2019-07-26 15:16:34','2019-07-26 15:16:34',NULL),(30,7,'IND_AUTHORIZE_LINK',0,1,'2019-07-26 15:17:06','2019-07-26 15:17:06',NULL),(31,7,'IND_PRINT_PO',0,1,'2019-07-26 15:17:46','2019-07-26 15:17:46',NULL),(32,7,'IND_REJECT_BTN',0,1,'2019-07-26 15:18:20','2019-07-26 15:18:20',NULL),(33,7,'IND_AUTHORIZE_BTN',0,1,'2019-07-26 15:18:39','2019-07-26 15:18:39',NULL),(36,7,'IND_FORCE_CLOSE_BTN',0,1,'2019-07-26 15:19:41','2019-07-26 15:19:41',NULL),(37,11,'CON_PO_INDENT',0,1,'2019-07-26 15:36:21','2019-07-26 15:36:21',NULL),(38,11,'CON_AUTHORIZE_LINK',0,1,'2019-07-26 15:36:21','2019-07-26 15:36:21',NULL),(39,11,'CON_PRINT_PO',0,1,'2019-07-26 15:36:21','2019-07-26 15:36:21',NULL),(40,11,'CON_REJECT_BTN',0,1,'2019-07-26 15:36:21','2019-07-26 15:36:21',NULL),(41,11,'CON_AUTHORIZE_BTN',0,1,'2019-07-26 15:36:21','2019-07-26 15:36:21',NULL),(42,11,'CON_FORCE_CLOSE_BTN',0,1,'2019-07-26 15:36:21','2019-07-26 15:36:21',NULL),(43,26,'CON_GRN',0,1,'2019-07-26 15:44:36','2019-07-26 15:44:36',NULL),(44,26,'CON_RECEIVED_GOODS',0,1,'2019-07-26 15:44:36','2019-07-26 15:44:36',NULL),(45,26,'CON_AUTO_GRN_BRANCH',0,1,'2019-07-26 15:44:36','2019-07-26 15:44:36',NULL),(46,26,'CON_GRN_BRANCH',0,1,'2019-07-26 15:44:36','2019-07-26 15:44:36',NULL),(47,26,'CON_GRN_ONLY_INVOICE',0,1,'2019-07-26 15:44:56','2019-07-26 15:44:56',NULL),(48,26,'CON_GRN_BOTH_DC_AND_INVOICE',0,1,'2019-07-26 15:45:13','2019-07-26 15:45:13',NULL),(49,43,'OCS_BRANCH_SEARCH',0,1,'2019-07-31 17:38:24','2019-07-31 17:38:24',NULL),(50,4,'UPDATE_PO_BTN',0,1,'2019-09-11 15:27:37','2019-09-11 15:27:37',NULL),(51,16,'BRANCGWISE_VENDOR_OUTSTAND',0,1,'2020-01-03 11:29:33','2020-01-03 11:29:33',NULL),(52,16,'VENDOR_PAYMENT',0,1,'2020-01-03 11:29:33','2020-01-03 11:29:33',NULL),(53,16,'VENDOR_PAYMENT_LIST',0,1,'2020-01-03 11:29:33','2020-01-03 11:29:33',NULL),(54,16,'SUPPLIERWISE_VENDOR_OUTSTAND',0,1,'2020-01-03 11:29:33','2020-01-03 11:29:33',NULL),(55,8,'DIRECT_STOCK_ISSUE',0,1,'2024-01-02 15:47:56','2024-01-02 15:47:56',NULL);

--
-- Table structure for table `tbl_mst_paymodes`
--

CREATE TABLE `tbl_mst_paymodes` (
  `id` int NOT NULL AUTO_INCREMENT,
  `payModeName` varchar(250) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_paymodes`
--

INSERT INTO `tbl_mst_paymodes` VALUES (1,'CASH','2019-12-11 11:30:17','2019-12-11 11:30:17',1,0),(2,'NEFT','2019-12-11 11:30:17','2019-12-11 11:30:17',1,0),(3,'IMPS','2019-12-11 11:30:17','2019-12-11 11:30:17',1,0),(4,'REFT','2019-12-11 16:48:22','2019-12-11 16:48:22',1,0),(5,'PhonePy','2019-12-11 18:09:26','2019-12-11 18:09:26',1,0);

--
-- Table structure for table `tbl_mst_postatuses`
--

CREATE TABLE `tbl_mst_postatuses` (
  `aPoStatusId` tinyint NOT NULL DEFAULT '0',
  `poStatusName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aPoStatusId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_postatuses`
--

INSERT INTO `tbl_mst_postatuses` VALUES (1,'Un Authorized','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(2,'Authorized','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(3,'Mail Sent','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(4,'Mail Failed','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(5,'GRN Partial','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(6,'GRN Completed','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(7,'Force CLosed','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(8,'Completed','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(9,'Rejected','2018-11-29 20:14:22','2018-11-29 20:14:22',1,0,NULL),(12,'Parsillycompleted','2019-08-26 19:52:33','2019-08-26 19:52:33',1,0,NULL),(13,'completed','2019-08-26 19:52:33','2019-08-26 19:52:33',1,0,NULL);

--
-- Table structure for table `tbl_mst_potypes`
--

CREATE TABLE `tbl_mst_potypes` (
  `aPoTypeId` int NOT NULL AUTO_INCREMENT,
  `poTypeNAme` varchar(50) DEFAULT NULL,
  `poTypeShortName` varchar(10) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aPoTypeId`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_potypes`
--

INSERT INTO `tbl_mst_potypes` VALUES (0,'CSA','CSA','2018-08-06 19:09:23','2018-08-06 19:09:23',1,0,0),(1,'Billed','BL','2018-07-19 17:11:52','2018-07-19 17:11:52',1,0,NULL),(2,'Consignment Notes','CN','2018-07-19 17:11:52','2018-07-19 17:11:52',1,0,NULL),(3,'Consignment Refill','CR','2018-07-19 17:11:52','2018-07-19 17:11:52',1,0,NULL),(4,'Indent','IN','2018-08-06 19:09:23','2018-08-06 19:09:23',1,0,NULL),(5,'Dispatch','DISP','2024-01-02 15:47:56','2024-01-02 15:47:56',1,0,NULL);

--
-- Table structure for table `tbl_mst_registration_type`
--

CREATE TABLE `tbl_mst_registration_type` (
  `aRegTypeId_pk` int NOT NULL AUTO_INCREMENT,
  `regTypeShortCode` varchar(10) DEFAULT NULL,
  `regTypeName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aRegTypeId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  CONSTRAINT `tbl_mst_registration_type_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_registration_type`
--

INSERT INTO `tbl_mst_registration_type` VALUES (1,'REG','Registered','2018-07-03 20:14:29','2018-07-03 20:14:29',1,0,NULL),(2,'UnReg','Unregistered','2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL),(3,'EXP','Export','2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL),(4,'Deem','Deem Export','2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL);

--
-- Table structure for table `tbl_mst_requesttypes`
--

CREATE TABLE `tbl_mst_requesttypes` (
  `aRequestTypeId` int NOT NULL AUTO_INCREMENT,
  `requestTypeName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aRequestTypeId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_requesttypes`
--

INSERT INTO `tbl_mst_requesttypes` VALUES (1,'Purchase Order','2018-11-29 19:51:42','2018-11-29 19:51:42',1,0,NULL),(2,'Indent','2018-11-29 19:51:42','2018-11-29 19:51:42',1,0,NULL),(3,'Consignment','2018-11-29 19:51:42','2018-11-29 19:51:42',1,0,NULL);

--
-- Table structure for table `tbl_mst_returnstatus`
--

CREATE TABLE `tbl_mst_returnstatus` (
  `areturnstausId` int NOT NULL AUTO_INCREMENT,
  `returnStatus` varchar(50) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`areturnstausId`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_returnstatus`
--

INSERT INTO `tbl_mst_returnstatus` VALUES (0,'WAITING','2018-11-12 12:16:18','2018-11-12 12:16:18',1,0,NULL),(1,'BRANCH APPROVED','2018-11-12 12:16:18','2018-11-12 12:16:18',1,0,NULL),(2,'BRANCH REJECTED','2018-11-12 12:16:18','2018-11-12 12:16:18',1,0,NULL),(3,'DEPO ACCEPTED','2018-11-15 12:39:58','2018-11-15 12:39:58',1,0,NULL),(4,'DEPO REJECTED','2018-11-15 12:39:58','2018-11-15 12:39:58',1,0,NULL),(5,'RETURNED TO SUPPLIER','2018-11-15 15:52:05','2018-11-15 15:52:05',1,0,NULL);

--
-- Table structure for table `tbl_mst_returntypes`
--

CREATE TABLE `tbl_mst_returntypes` (
  `aReturnTypeId` int NOT NULL AUTO_INCREMENT,
  `returnTypeName` varchar(50) DEFAULT NULL,
  `addtoStock` tinyint DEFAULT '0',
  `autoCreateIndent` tinyint DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aReturnTypeId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_returntypes`
--

INSERT INTO `tbl_mst_returntypes` VALUES (1,'RETURN TO DEPO',1,0,'2018-11-15 16:15:07','2018-11-15 16:15:07',1,0,NULL);

--
-- Table structure for table `tbl_mst_stocktransferstatus`
--

CREATE TABLE `tbl_mst_stocktransferstatus` (
  `aStockTrnsfMstId` int NOT NULL AUTO_INCREMENT,
  `statusname` varchar(25) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aStockTrnsfMstId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_stocktransferstatus`
--

INSERT INTO `tbl_mst_stocktransferstatus` VALUES (0,'Waiting','2018-10-16 16:12:15','2018-10-16 16:12:15',1,0,NULL),(1,'Approved','2018-10-16 16:12:15','2018-10-16 16:12:15',1,0,NULL),(2,'Rejected','2018-10-16 16:12:15','2018-10-16 16:12:15',1,0,NULL),(3,'Accepted','2018-10-16 16:12:15','2018-10-16 16:12:15',1,0,NULL),(4,'Not Accepted','2018-10-16 16:12:15','2018-10-16 16:12:15',1,0,NULL);

--
-- Table structure for table `tbl_mst_storecreation`
--

CREATE TABLE `tbl_mst_storecreation` (
  `aStoreId_pk` int NOT NULL AUTO_INCREMENT,
  `storeName` varchar(100) DEFAULT NULL,
  `storeShortCode` varchar(10) DEFAULT NULL,
  `nItemSubCatId_fk` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `storeFlag` int DEFAULT '0',
  `isMandatoryBatchAndExpiry` int DEFAULT '0',
  PRIMARY KEY (`aStoreId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `nItemSubCatId_fk` (`nItemSubCatId_fk`),
  CONSTRAINT `tbl_mst_storecreation_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_mst_storecreation_ibfk_2` FOREIGN KEY (`nItemSubCatId_fk`) REFERENCES `tbl_mst_item_subcategory` (`aSubcategoryId_pk`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_storecreation`
--

INSERT INTO `tbl_mst_storecreation` VALUES (1,'IOL','IOL',1,'2018-07-09 15:30:39','2018-07-09 15:30:39',1,0,NULL,1,1),(2,'OT Stock','OTS',2,'2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL,0,1),(3,'OPD Consumables','OPD',3,'2018-07-03 15:07:12','2018-07-03 15:07:12',1,0,NULL,0,1);

--
-- Table structure for table `tbl_mst_sub_groups`
--

CREATE TABLE `tbl_mst_sub_groups` (
  `aSubgroupId_pk` int NOT NULL AUTO_INCREMENT,
  `subgroupShortCode` varchar(10) DEFAULT NULL,
  `subgroupName` varchar(100) DEFAULT NULL,
  `ngroupId_fk` int DEFAULT NULL,
  `nlocationId_fk` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aSubgroupId_pk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `ngroupId_fk` (`ngroupId_fk`),
  KEY `nlocationId_fk` (`nlocationId_fk`),
  CONSTRAINT `tbl_mst_sub_groups_ibfk_1` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_mst_sub_groups_ibfk_2` FOREIGN KEY (`ngroupId_fk`) REFERENCES `tbl_mst_groups` (`aGroupId_pk`),
  CONSTRAINT `tbl_mst_sub_groups_ibfk_3` FOREIGN KEY (`nlocationId_fk`) REFERENCES `tbl_mst_locations` (`aLocationId_pk`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_sub_groups`
--


--
-- Table structure for table `tbl_mst_supplier`
--

CREATE TABLE `tbl_mst_supplier` (
  `aSupplierId_pk` int NOT NULL AUTO_INCREMENT,
  `code` varchar(20) DEFAULT NULL,
  `company_name` varchar(100) NOT NULL,
  `nBusiness_typeId_fk` varchar(50) NOT NULL,
  `registration_type` varchar(50) NOT NULL,
  `GSTIN` varchar(45) NOT NULL,
  `IGSTN` varchar(45) DEFAULT NULL,
  `emailId` varchar(255) NOT NULL,
  `po_emailId` varchar(255) NOT NULL,
  `pan_no` varchar(30) DEFAULT NULL,
  `drugl_no` varchar(20) DEFAULT NULL,
  `nLocationId_fk` varchar(50) NOT NULL,
  `credit_period` int DEFAULT NULL,
  `com_address` varchar(255) DEFAULT NULL,
  `po_address` varchar(255) DEFAULT NULL,
  `contact_person` varchar(50) DEFAULT NULL,
  `designation` varchar(50) DEFAULT NULL,
  `mobile_no` varchar(10) DEFAULT NULL,
  `phone_no` varchar(15) DEFAULT NULL,
  `alternative_no` varchar(15) DEFAULT NULL,
  `nBankId_fk` int DEFAULT NULL,
  `beneficiary_name` varchar(50) DEFAULT NULL,
  `ac_no` varchar(20) DEFAULT NULL,
  `ifsc` varchar(20) DEFAULT NULL,
  `chequeFavourName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint(1) DEFAULT '1',
  `isDeleted` tinyint(1) DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `TATinDays` int DEFAULT NULL,
  `supplierFlag` int DEFAULT '0',
  `cin` varchar(150) DEFAULT NULL,
  `fax` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`aSupplierId_pk`),
  UNIQUE KEY `code_UNIQUE` (`code`),
  KEY `FK_tbl_mst_supplier_tbl_mst_business_type_business_typeId` (`nBusiness_typeId_fk`),
  KEY `FK_tbl_mst_supplier_tbl_mst_locations_locationId` (`nLocationId_fk`),
  KEY `FK_tbl_mst_supplier_tbl_mst_bank_bankId` (`nBankId_fk`),
  KEY `FK_tbl_mst_supplier_tbl_user_userId` (`nUserId_fk`),
  CONSTRAINT `FK_tbl_mst_supplier_tbl_mst_bank_bankId` FOREIGN KEY (`nBankId_fk`) REFERENCES `tbl_mst_bank` (`aBankId_pk`),
  CONSTRAINT `FK_tbl_mst_supplier_tbl_user_userId` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=110 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_mst_supplier`
--

INSERT INTO `tbl_mst_supplier` VALUES (107,'SUP107','Kadur Depo','1','','577548','577548','','',NULL,NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2020-03-17 10:00:01','2020-03-17 10:00:01',1,0,NULL,NULL,1,NULL,NULL),(108,'SUP108','Kadur Branch 1','1','','577548','577548','','',NULL,NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2020-03-17 10:00:49','2020-03-17 10:00:49',1,0,NULL,NULL,1,NULL,NULL),(109,'SUP109','Kadur Branch 2','1','','577548','577548','','',NULL,NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2020-03-17 10:01:32','2020-03-17 10:01:32',1,0,NULL,NULL,1,NULL,NULL);

--
-- Table structure for table `tbl_mst_transfertypes`
--

CREATE TABLE `tbl_mst_transfertypes` (
  `aTransferTypeId` int NOT NULL AUTO_INCREMENT,
  `transferTypeName` varchar(100) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aTransferTypeId`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_mst_transfertypes`
--

INSERT INTO `tbl_mst_transfertypes` VALUES (1,'Indent Transfer','2018-11-30 20:09:15','2018-11-30 20:09:15',1,0,NULL),(2,'Transfer To User','2018-11-30 20:09:15','2018-11-30 20:09:15',1,0,NULL),(3,'Consignment Transfer','2018-11-30 20:09:15','2018-11-30 20:09:15',1,0,NULL),(4,'Without Indent Transfer','2020-03-16 16:23:36','2020-03-16 16:23:36',1,0,NULL);

--
-- Table structure for table `tbl_os_po_each_item_details`
--

CREATE TABLE `tbl_os_po_each_item_details` (
  `apoeachid` int NOT NULL AUTO_INCREMENT,
  `npoid_fk` int DEFAULT NULL,
  `typeOfRequest` int DEFAULT '1',
  `indentToBranchId` int DEFAULT NULL,
  `item_id_fk` int DEFAULT NULL,
  `item_code` varchar(50) DEFAULT NULL,
  `item_name` tinytext,
  `item_hsn_code` varchar(45) DEFAULT NULL,
  `item_diapter` varchar(25) DEFAULT NULL,
  `item_size` varchar(25) DEFAULT NULL,
  `item_strength` varchar(25) DEFAULT NULL,
  `item_volume` varchar(25) DEFAULT NULL,
  `item_free_qty` int DEFAULT NULL,
  `item_order_qty` int DEFAULT NULL,
  `item_unit_price` float DEFAULT NULL,
  `item_discount_percent` float DEFAULT NULL,
  `item_discount_rs` float DEFAULT NULL,
  `item_gst_percent` float DEFAULT NULL,
  `item_gst_rs` float DEFAULT NULL,
  `item_sgst_percent` float DEFAULT NULL,
  `item_sgst_rs` float DEFAULT NULL,
  `item_cgst_percent` float DEFAULT NULL,
  `item_cgst_rs` float DEFAULT NULL,
  `item_igst_percent` float DEFAULT NULL,
  `item_igst_rs` float DEFAULT NULL,
  `item_total_amt_without_gst` float DEFAULT NULL,
  `item_total_amt_with_gst` float DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `poItemStatusId` tinyint DEFAULT NULL,
  `n_poeachid_from_branch_fk` int DEFAULT NULL,
  `nSupplierItemMapid` int DEFAULT NULL,
  `indentEachid` int DEFAULT NULL,
  `indentPoraiseStatus` int DEFAULT '0',
  `indentPoraiseQty` int DEFAULT '0',
  PRIMARY KEY (`apoeachid`),
  KEY `os_main_po_fk_idx` (`npoid_fk`),
  KEY `typeOfRequest` (`typeOfRequest`),
  KEY `item_id_fk` (`item_id_fk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `poItemStatusId` (`poItemStatusId`),
  KEY `nSupplierItemMapid` (`nSupplierItemMapid`),
  KEY `tbl_os_po_each_item_details_ibfk_7_idx` (`indentPoraiseStatus`),
  CONSTRAINT `os_main_po_fk` FOREIGN KEY (`npoid_fk`) REFERENCES `tbl_os_po_main_details` (`apoid`),
  CONSTRAINT `tbl_os_po_each_item_details_ibfk_1` FOREIGN KEY (`npoid_fk`) REFERENCES `tbl_os_po_main_details` (`apoid`),
  CONSTRAINT `tbl_os_po_each_item_details_ibfk_2` FOREIGN KEY (`typeOfRequest`) REFERENCES `tbl_mst_requesttypes` (`aRequestTypeId`),
  CONSTRAINT `tbl_os_po_each_item_details_ibfk_3` FOREIGN KEY (`item_id_fk`) REFERENCES `tbl_mst_items_details` (`aItemId_pk`),
  CONSTRAINT `tbl_os_po_each_item_details_ibfk_4` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_os_po_each_item_details_ibfk_5` FOREIGN KEY (`poItemStatusId`) REFERENCES `tbl_mst_postatuses` (`aPoStatusId`),
  CONSTRAINT `tbl_os_po_each_item_details_ibfk_6` FOREIGN KEY (`nSupplierItemMapid`) REFERENCES `tbl_supplier_item_mapping` (`supplier_item_mappingId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_os_po_each_item_details`
--


--
-- Table structure for table `tbl_os_po_main_details`
--

CREATE TABLE `tbl_os_po_main_details` (
  `apoid` int NOT NULL AUTO_INCREMENT,
  `typeOfRequest` int DEFAULT '1',
  `indentToBranchId` int DEFAULT NULL,
  `po_number` varchar(30) DEFAULT NULL,
  `instore_fk` int DEFAULT NULL,
  `po_type_fk` int DEFAULT NULL,
  `po_from_branch_fk` int DEFAULT NULL,
  `po_date` datetime DEFAULT NULL,
  `po_raisedby_fk` int DEFAULT NULL,
  `po_billingaddress` text,
  `po_deliveryaddress` text,
  `po_to_supplier_id_fk` int DEFAULT NULL,
  `gstType` int DEFAULT '0',
  `po_expexted_delivery_date` datetime DEFAULT NULL,
  `po_total_items` int DEFAULT NULL,
  `po_total_items_qty` int DEFAULT NULL,
  `po_total_amount` float DEFAULT NULL,
  `po_status` int DEFAULT NULL,
  `po_status_text` varchar(45) DEFAULT NULL,
  `reasonForAuthOrRej` text,
  `po_authorized_by_fk` int DEFAULT NULL,
  `po_authorized_date` datetime DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `n_poid_from_branch_fk` int DEFAULT '0',
  `poRemarkss` text,
  `freight_charge` float DEFAULT '0',
  `discount_amount` float DEFAULT '0',
  `final_total_amount` float DEFAULT '0',
  `tbl_os_po_main_detailscol` int DEFAULT NULL,
  `ngrn_status_id` int DEFAULT NULL,
  `patientId` int DEFAULT NULL,
  `counsilId` int DEFAULT NULL,
  `surgAppId` int DEFAULT NULL,
  `patName` varchar(250) DEFAULT NULL,
  `patientCode` varchar(250) DEFAULT NULL,
  `reservedById` int DEFAULT NULL,
  `reservedByName` varchar(250) DEFAULT NULL,
  `reservedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isReserved` int DEFAULT '0',
  PRIMARY KEY (`apoid`),
  KEY `po_number_idx` (`po_number`),
  KEY `typeOfRequest` (`typeOfRequest`),
  KEY `instore_fk` (`instore_fk`),
  KEY `po_type_fk` (`po_type_fk`),
  KEY `po_from_branch_fk` (`po_from_branch_fk`),
  KEY `po_raisedby_fk` (`po_raisedby_fk`),
  KEY `po_to_supplier_id_fk` (`po_to_supplier_id_fk`),
  KEY `po_authorized_by_fk` (`po_authorized_by_fk`),
  KEY `nUserId_fk` (`nUserId_fk`),
  KEY `n_poid_from_branch_fk` (`n_poid_from_branch_fk`),
  KEY `fk_ngrn_status_id_idx` (`ngrn_status_id`),
  CONSTRAINT `fk_ngrn_status_id` FOREIGN KEY (`ngrn_status_id`) REFERENCES `tbl_mst_grn_status` (`agrnstatusid`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_1` FOREIGN KEY (`typeOfRequest`) REFERENCES `tbl_mst_requesttypes` (`aRequestTypeId`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_2` FOREIGN KEY (`instore_fk`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_3` FOREIGN KEY (`po_type_fk`) REFERENCES `tbl_mst_potypes` (`aPoTypeId`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_4` FOREIGN KEY (`po_from_branch_fk`) REFERENCES `tblhospitalbranches` (`abranchId`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_5` FOREIGN KEY (`po_raisedby_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_6` FOREIGN KEY (`po_to_supplier_id_fk`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_7` FOREIGN KEY (`po_authorized_by_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_8` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_os_po_main_details_ibfk_9` FOREIGN KEY (`n_poid_from_branch_fk`) REFERENCES `tblhospitalbranches` (`abranchId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_os_po_main_details`
--


--
-- Table structure for table `tbl_ot_stock_consumption_each_details`
--

CREATE TABLE `tbl_ot_stock_consumption_each_details` (
  `aOtStockConsumptionEachId` int NOT NULL AUTO_INCREMENT,
  `nMainConsumptionId` int DEFAULT NULL,
  `patientId` int DEFAULT NULL,
  `apptId` int DEFAULT NULL,
  `surgicalAppointmentId` int DEFAULT NULL,
  `inPatientId` int DEFAULT NULL,
  `nGrnAvailId` int DEFAULT NULL,
  `usedQty` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `lastModified` datetime DEFAULT CURRENT_TIMESTAMP,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `nUserId` int DEFAULT NULL,
  `serialNo` varchar(100) DEFAULT NULL,
  `batchNo` varchar(100) DEFAULT NULL,
  `diapter` varchar(45) DEFAULT NULL,
  `size` varchar(45) DEFAULT NULL,
  `strength` varchar(45) DEFAULT NULL,
  `volume` varchar(45) DEFAULT NULL,
  `storeType` int DEFAULT NULL,
  `nItemId` int DEFAULT NULL,
  `itemName` varchar(250) DEFAULT NULL,
  `itemShortCode` varchar(250) DEFAULT NULL,
  `expiryDate` datetime DEFAULT NULL,
  PRIMARY KEY (`aOtStockConsumptionEachId`),
  KEY `nBranchId` (`nBranchId`),
  KEY `nUserId` (`nUserId`),
  KEY `nGrnAvailId` (`nGrnAvailId`),
  KEY `nMainConsumptionId` (`nMainConsumptionId`),
  CONSTRAINT `TBL_OT_STOCK_CONSUMPTION_EACH_DETAILS_ibfk_1` FOREIGN KEY (`nBranchId`) REFERENCES `tblhospitalbranches` (`abranchId`),
  CONSTRAINT `TBL_OT_STOCK_CONSUMPTION_EACH_DETAILS_ibfk_2` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `TBL_OT_STOCK_CONSUMPTION_EACH_DETAILS_ibfk_3` FOREIGN KEY (`nGrnAvailId`) REFERENCES `tbl_grn_availqty` (`aGrnAvailQtyId`),
  CONSTRAINT `TBL_OT_STOCK_CONSUMPTION_EACH_DETAILS_ibfk_4` FOREIGN KEY (`nMainConsumptionId`) REFERENCES `tbl_ot_stock_consumption_main_details` (`aOtStockConsumptionMainId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_ot_stock_consumption_each_details`
--


--
-- Table structure for table `tbl_ot_stock_consumption_main_details`
--

CREATE TABLE `tbl_ot_stock_consumption_main_details` (
  `aOtStockConsumptionMainId` int NOT NULL AUTO_INCREMENT,
  `patientId` int DEFAULT NULL,
  `surgicalAppointmentId` int DEFAULT NULL,
  `inPatientId` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `lastModified` datetime DEFAULT CURRENT_TIMESTAMP,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `nUserId` int DEFAULT NULL,
  `surgeryDate` datetime DEFAULT NULL,
  `patCode` varchar(250) DEFAULT NULL,
  `patName` varchar(250) DEFAULT NULL,
  `surgeryName` varchar(250) DEFAULT NULL,
  `procedureName` text,
  PRIMARY KEY (`aOtStockConsumptionMainId`),
  KEY `nBranchId` (`nBranchId`),
  KEY `nUserId` (`nUserId`),
  CONSTRAINT `TBL_OT_STOCK_CONSUMPTION_MAIN_DETAILS_ibfk_1` FOREIGN KEY (`nBranchId`) REFERENCES `tblhospitalbranches` (`abranchId`),
  CONSTRAINT `TBL_OT_STOCK_CONSUMPTION_MAIN_DETAILS_ibfk_2` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_ot_stock_consumption_main_details`
--


--
-- Table structure for table `tbl_po_status_history_log`
--

CREATE TABLE `tbl_po_status_history_log` (
  `apohistorylogid` int NOT NULL AUTO_INCREMENT,
  `npotypeid` int DEFAULT NULL,
  `createdAt` datetime DEFAULT NULL,
  `createdBy` int DEFAULT NULL,
  `statusId` int DEFAULT NULL,
  `nPoMainId` int DEFAULT NULL,
  `nPoEachItemId` int DEFAULT NULL,
  `nUserId_fk` int DEFAULT NULL,
  `remarks` text,
  `Qty` int DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`apohistorylogid`),
  KEY `fk_nopeach_id_idx` (`nPoEachItemId`),
  KEY `fk_nuser_id_idx` (`nUserId_fk`),
  KEY `fk_npomain_id_idx` (`nPoMainId`),
  KEY `fk_npotype_id_idx` (`npotypeid`),
  CONSTRAINT `fk_npoeach_id` FOREIGN KEY (`nPoEachItemId`) REFERENCES `tbl_os_po_each_item_details` (`apoeachid`),
  CONSTRAINT `fk_npomain_id` FOREIGN KEY (`nPoMainId`) REFERENCES `tbl_os_po_main_details` (`apoid`),
  CONSTRAINT `fk_npotype_id` FOREIGN KEY (`npotypeid`) REFERENCES `tbl_mst_potypes` (`aPoTypeId`),
  CONSTRAINT `fk_user_id` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_po_status_history_log`
--


--
-- Table structure for table `tbl_status_indent_po_raised`
--

CREATE TABLE `tbl_status_indent_po_raised` (
  `id` int NOT NULL AUTO_INCREMENT,
  `Description` varchar(250) DEFAULT NULL,
  `tbl_status_indent_po_raisedcol` varchar(45) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_status_indent_po_raised`
--

INSERT INTO `tbl_status_indent_po_raised` VALUES (1,'indet PoRaised',NULL,'2019-09-05 15:22:29','2019-09-05 15:22:29',1,0),(2,'IndentPoGrnRaised',NULL,'2019-09-05 15:22:29','2019-09-05 15:22:29',1,0),(3,'Po Not Rised',NULL,'2019-09-05 15:22:29','2019-09-05 15:22:29',1,0);

--
-- Table structure for table `tbl_stock_transfer_maindetails`
--

CREATE TABLE `tbl_stock_transfer_maindetails` (
  `aMainStckTrnfrId` int NOT NULL AUTO_INCREMENT,
  `dcNumber` varchar(50) DEFAULT NULL,
  `dcDate` datetime DEFAULT NULL,
  `indentNumber` varchar(50) DEFAULT NULL,
  `branchId` int DEFAULT NULL,
  `transferredToBranchId` int DEFAULT NULL,
  `storeId` int DEFAULT NULL,
  `typeId` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  `stock_transfer_status` int DEFAULT '0',
  PRIMARY KEY (`aMainStckTrnfrId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_stock_transfer_maindetails`
--


--
-- Table structure for table `tbl_stocks_consumption_details`
--

CREATE TABLE `tbl_stocks_consumption_details` (
  `aStockConsumptionId` int NOT NULL AUTO_INCREMENT,
  `nIssedStock_Fk` int DEFAULT NULL,
  `stockAvilableStatus` int DEFAULT NULL,
  `stockAvilableStatus_Value` varchar(100) DEFAULT NULL,
  `nItemId_fk` int DEFAULT NULL,
  `consumedQty` int DEFAULT NULL,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `insertedDate` datetime DEFAULT NULL,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `nUserId` int DEFAULT NULL,
  PRIMARY KEY (`aStockConsumptionId`),
  KEY `Fk_TBLSTC_user_idx` (`nUserId`),
  KEY `Fk_TBLSTC_item_idx` (`nItemId_fk`),
  CONSTRAINT `Fk_TBLSTC_item` FOREIGN KEY (`nItemId_fk`) REFERENCES `tbl_mst_items_details` (`aItemId_pk`),
  CONSTRAINT `Fk_TBLSTC_user` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_stocks_consumption_details`
--


--
-- Table structure for table `tbl_stocks_issued_to_emr`
--

CREATE TABLE `tbl_stocks_issued_to_emr` (
  `issedStock_Pk` int NOT NULL AUTO_INCREMENT,
  `nMainStockTrnsfrId` int DEFAULT NULL,
  `ngrnId_fk` int DEFAULT NULL,
  `ngrnEachId_fk` int DEFAULT NULL,
  `issuedToBranchPoId` int DEFAULT NULL,
  `issuedToBrancheACHPoId` int DEFAULT NULL,
  `nItemId_fk` int DEFAULT NULL,
  `itemName` text,
  `availQty` int DEFAULT NULL,
  `issuedQty` int DEFAULT NULL,
  `iolStatus` tinyint DEFAULT '0',
  `batchNo` varchar(45) DEFAULT NULL,
  `expiryDate` datetime DEFAULT NULL,
  `serialNo` varchar(45) DEFAULT NULL,
  `nStoreId_fk` int DEFAULT NULL,
  `nstockType_fk` tinyint DEFAULT NULL,
  `issuedToUserId` int DEFAULT NULL,
  `issuedUserName` varchar(45) DEFAULT NULL,
  `nbranchid_fk` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT NULL,
  `lastModifiedDate` datetime DEFAULT NULL,
  `isActive` tinyint DEFAULT NULL,
  `isDeleted` tinyint DEFAULT NULL,
  `nUserId_fk` int DEFAULT NULL,
  `nIssuedFromBranchId_fk` int DEFAULT NULL,
  `nIssuedToBranchId_fk` int DEFAULT NULL,
  `nCentralGrnId_fk` int DEFAULT NULL,
  `nCentralGrnEachId_fk` int DEFAULT NULL,
  `centralGrnNumber` text,
  `tranferType` tinyint DEFAULT '1',
  `isApproved` tinyint DEFAULT '0',
  `approvedBy` int DEFAULT NULL,
  `approverRemarks` text,
  `approvedDateTime` datetime DEFAULT NULL,
  PRIMARY KEY (`issedStock_Pk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_stocks_issued_to_emr`
--


--
-- Table structure for table `tbl_supplier_item_mapping`
--

CREATE TABLE `tbl_supplier_item_mapping` (
  `supplier_item_mappingId` int NOT NULL AUTO_INCREMENT,
  `nSupplierId_fk` int NOT NULL,
  `isAtPriority` tinyint DEFAULT '0',
  `nItemId_fk` int NOT NULL,
  `TATinDays` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `purchasePrice` float DEFAULT NULL,
  `nhsnId_fk` float DEFAULT NULL,
  `sellingPrice` float DEFAULT NULL,
  `MRP` float DEFAULT NULL,
  `freeQty` float DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`supplier_item_mappingId`),
  KEY `FK_tbl_supplier_item_mapping_tbl_user_userId` (`nUserId_fk`),
  KEY `FK_tbl_mst_item_tbl_supplier_item_mapping_itemId` (`nItemId_fk`),
  KEY `FK_tbl_mst_supplier_tbl_supplier_item_mapping_supplierId_fk` (`nSupplierId_fk`),
  CONSTRAINT `FK_tbl_mst_item_tbl_supplier_item_mapping_itemId` FOREIGN KEY (`nItemId_fk`) REFERENCES `tbl_mst_items_details` (`aItemId_pk`),
  CONSTRAINT `FK_tbl_mst_supplier_tbl_supplier_item_mapping_supplierId_fk` FOREIGN KEY (`nSupplierId_fk`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`),
  CONSTRAINT `FK_tbl_supplier_item_mapping_tbl_user_userId` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier_item_mapping`
--


--
-- Table structure for table `tbl_supplier_miscellaneous_mapping`
--

CREATE TABLE `tbl_supplier_miscellaneous_mapping` (
  `supplier_miscellaneous_mappingId` int NOT NULL AUTO_INCREMENT,
  `nSupplierId_fk` int NOT NULL,
  `nMiscellaneousId_fk` int NOT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`supplier_miscellaneous_mappingId`),
  KEY `FK_tbl_mst_supplier_tbl_supplier_misc_mapping_supplierId` (`nSupplierId_fk`),
  KEY `FK_tbl_mst_miscellaneous_tbl_supplier_misc_mapping_miscId` (`nMiscellaneousId_fk`),
  CONSTRAINT `FK_tbl_mst_miscellaneous_tbl_supplier_misc_mapping_miscId` FOREIGN KEY (`nMiscellaneousId_fk`) REFERENCES `tbl_mst_miscellaneous` (`aMiscellaneousId`),
  CONSTRAINT `FK_tbl_mst_supplier_tbl_supplier_misc_mapping_supplierId` FOREIGN KEY (`nSupplierId_fk`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier_miscellaneous_mapping`
--


--
-- Table structure for table `tbl_supplier_store_mapping`
--

CREATE TABLE `tbl_supplier_store_mapping` (
  `aSupplierStoreMappingId` int NOT NULL AUTO_INCREMENT,
  `nSupplierId_fk` int NOT NULL,
  `nStoreId_fk` int NOT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `nUserId_fk` int DEFAULT NULL,
  PRIMARY KEY (`aSupplierStoreMappingId`),
  KEY `FK_tbl_mst_storecreation_tbl_supplier_store_mapping_storeId` (`nStoreId_fk`),
  KEY `FK_tbl_mst_supplier_tbl_supplier_store_mapping_supplierId` (`nSupplierId_fk`),
  KEY `FK_tbl_supplier_store_mapping_tbl_user_userId` (`nUserId_fk`),
  CONSTRAINT `FK_tbl_mst_storecreation_tbl_supplier_store_mapping_storeId` FOREIGN KEY (`nStoreId_fk`) REFERENCES `tbl_mst_storecreation` (`aStoreId_pk`),
  CONSTRAINT `FK_tbl_mst_supplier_tbl_supplier_store_mapping_supplierId` FOREIGN KEY (`nSupplierId_fk`) REFERENCES `tbl_mst_supplier` (`aSupplierId_pk`),
  CONSTRAINT `FK_tbl_supplier_store_mapping_tbl_user_userId` FOREIGN KEY (`nUserId_fk`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_supplier_store_mapping`
--


--
-- Table structure for table `tbl_user`
--

CREATE TABLE `tbl_user` (
  `userId` int NOT NULL AUTO_INCREMENT,
  `userName` varchar(100) NOT NULL,
  `password` varchar(250) NOT NULL,
  `fullName` varchar(100) DEFAULT NULL,
  `employeeId` varchar(50) DEFAULT NULL,
  `mobileNumber` varchar(10) DEFAULT NULL,
  `emailId` varchar(100) DEFAULT NULL,
  `nSilkIndustryId` int DEFAULT NULL,
  `imageName` varchar(500) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `isloggedin` int DEFAULT NULL,
  `nHospitalId` int DEFAULT NULL,
  `nBranchId` varchar(250) DEFAULT NULL,
  `isWebOrMobileUser` int DEFAULT NULL,
  `IsCentralOrBranchUser` int DEFAULT NULL,
  `sessionid` tinytext,
  `authkey` tinytext,
  PRIMARY KEY (`userId`),
  KEY `nHospitalId` (`nHospitalId`),
  CONSTRAINT `tbl_user_ibfk_1` FOREIGN KEY (`nHospitalId`) REFERENCES `tblhospitalsdetails` (`aHospitalId`),
  CONSTRAINT `tbl_user_ibfk_2` FOREIGN KEY (`nHospitalId`) REFERENCES `tblhospitalsdetails` (`aHospitalId`)
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `tbl_user`
--

INSERT INTO `tbl_user` VALUES (1,'admin','a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3','sj','1234','9876543210','sj@jps.com',NULL,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

--
-- Table structure for table `tbl_user_branches_map`
--

CREATE TABLE `tbl_user_branches_map` (
  `aUserBrachesId` int NOT NULL AUTO_INCREMENT,
  `nUserId` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `nUserRoleId` int DEFAULT NULL,
  `isDeleted` tinyint DEFAULT '0',
  `isActive` tinyint DEFAULT '1',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`aUserBrachesId`),
  KEY `nUserId` (`nUserId`),
  KEY `nBranchId` (`nBranchId`),
  KEY `tbl_user_branches_map_ibfk_3_idx` (`nUserRoleId`),
  CONSTRAINT `tbl_user_branches_map_ibfk_1` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `tbl_user_branches_map_ibfk_2` FOREIGN KEY (`nBranchId`) REFERENCES `tblhospitalbranches` (`abranchId`),
  CONSTRAINT `tbl_user_branches_map_ibfk_3` FOREIGN KEY (`nBranchId`) REFERENCES `tblhospitalbranches` (`abranchId`),
  CONSTRAINT `tbl_user_branches_map_ibfk_4` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=54 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_user_branches_map`
--

INSERT INTO `tbl_user_branches_map` VALUES (51,1,1,NULL,0,1,'2020-03-17 10:08:05','2020-03-17 10:08:05'),(52,1,2,NULL,0,1,'2020-03-17 10:08:05','2020-03-17 10:08:05'),(53,1,3,NULL,0,1,'2020-03-17 10:08:05','2020-03-17 10:08:05');

--
-- Table structure for table `tbl_user_module_features_map`
--

CREATE TABLE `tbl_user_module_features_map` (
  `aModuleFeatureId` int NOT NULL AUTO_INCREMENT,
  `nModuleId` int DEFAULT NULL,
  `nFeatureId` int DEFAULT NULL,
  `toUserId` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  `nBranchMapId` int DEFAULT NULL,
  `isEnabled` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `isActive` tinyint DEFAULT '1',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `nUserId` int DEFAULT NULL,
  PRIMARY KEY (`aModuleFeatureId`)
) ENGINE=InnoDB AUTO_INCREMENT=2233 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_user_module_features_map`
--

INSERT INTO `tbl_user_module_features_map` VALUES (2104,4,1,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2105,4,3,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2106,4,5,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2107,4,6,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2108,4,25,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2109,4,50,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2110,5,11,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2111,5,13,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2112,5,14,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2113,5,15,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2114,5,26,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2115,5,27,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2116,7,29,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2117,7,30,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2118,7,31,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2119,7,32,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2120,7,33,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2121,7,36,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2122,8,2,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2123,8,4,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2124,8,7,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2125,8,8,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2126,8,9,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2127,8,10,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2128,8,18,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2129,8,22,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2130,8,23,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2131,8,24,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2132,11,37,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2133,11,38,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2134,11,39,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2135,11,40,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2136,11,41,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2137,11,42,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2138,26,43,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2139,26,44,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2140,26,45,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2141,26,46,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2142,26,47,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2143,26,48,1,1,NULL,1,0,1,'2020-03-17 10:08:08','2020-03-17 10:08:08',NULL),(2144,20,19,1,1,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2145,20,20,1,1,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2146,20,21,1,1,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2147,4,1,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2148,4,3,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2149,4,5,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2150,4,6,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2151,4,25,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2152,4,50,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2153,5,11,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2154,5,13,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2155,5,14,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2156,5,15,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2157,5,26,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2158,5,27,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2159,7,29,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2160,7,30,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2161,7,31,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2162,7,32,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2163,7,33,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2164,7,36,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2165,8,2,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2166,8,4,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2167,8,7,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2168,8,8,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2169,8,9,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2170,8,10,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2171,8,18,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2172,8,22,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2173,8,23,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2174,8,24,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2175,11,37,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2176,11,38,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2177,11,39,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2178,11,40,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2179,11,41,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2180,11,42,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2181,26,43,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2182,26,44,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2183,26,45,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2184,26,46,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2185,26,47,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2186,26,48,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2187,20,19,1,2,NULL,1,0,1,'2020-03-17 10:08:09','2020-03-17 10:08:09',NULL),(2188,20,20,1,2,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2189,20,21,1,2,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2190,4,1,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2191,4,3,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2192,4,5,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2193,4,6,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2194,4,25,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2195,4,50,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2196,5,11,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2197,5,13,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2198,5,14,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2199,5,15,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2200,5,26,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2201,5,27,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2202,7,29,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2203,7,30,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2204,7,31,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2205,7,32,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2206,7,33,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2207,7,36,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2208,8,2,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2209,8,4,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2210,8,7,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2211,8,8,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2212,8,9,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2213,8,10,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2214,8,18,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2215,8,22,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2216,8,23,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2217,8,24,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2218,11,37,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2219,11,38,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2220,11,39,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2221,11,40,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2222,11,41,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2223,11,42,1,3,NULL,1,0,1,'2020-03-17 10:08:10','2020-03-17 10:08:10',NULL),(2224,26,43,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2225,26,44,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2226,26,45,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2227,26,46,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2228,26,47,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2229,26,48,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2230,20,19,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2231,20,20,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL),(2232,20,21,1,3,NULL,1,0,1,'2020-03-17 10:08:11','2020-03-17 10:08:11',NULL);

--
-- Table structure for table `tbl_user_module_map`
--

CREATE TABLE `tbl_user_module_map` (
  `aModuleMapId` int NOT NULL AUTO_INCREMENT,
  `nUserId` int DEFAULT NULL,
  `nModuleId` int DEFAULT NULL,
  `marketid` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` int DEFAULT '1',
  `bDeleted` int DEFAULT '0',
  `nLoggedInUserId` int DEFAULT NULL,
  `nHospitalId` int DEFAULT NULL,
  `nBranchId` int DEFAULT NULL,
  PRIMARY KEY (`aModuleMapId`),
  KEY `fk_tblUserModuleMap_1_idx` (`nModuleId`),
  KEY `fk_tblUserModuleMap_2_idx` (`nUserId`),
  KEY `fk_tblUserModuleMap_3_idx` (`nLoggedInUserId`),
  CONSTRAINT `fk_tblUserModuleMap_1` FOREIGN KEY (`nModuleId`) REFERENCES `tbl_modules` (`aModuleId`),
  CONSTRAINT `fk_tblUserModuleMap_2` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`),
  CONSTRAINT `fk_tblUserModuleMap_3` FOREIGN KEY (`nLoggedInUserId`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=1996 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Dumping data for table `tbl_user_module_map`
--

INSERT INTO `tbl_user_module_map` VALUES (1891,1,3,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1892,1,4,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1893,1,5,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1894,1,6,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1895,1,7,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1896,1,8,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1897,1,9,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1898,1,10,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1899,1,11,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1900,1,12,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1901,1,13,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1902,1,26,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1903,1,17,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1904,1,18,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1905,1,19,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1906,1,20,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1907,1,21,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1908,1,49,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1909,1,51,NULL,'2020-03-17 10:08:05','2020-03-17 10:08:05',1,0,NULL,NULL,1),(1910,1,23,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1911,1,24,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1912,1,25,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1913,1,27,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1914,1,28,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1915,1,33,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1916,1,44,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1917,1,45,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1918,1,46,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1919,1,48,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1920,1,52,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1921,1,53,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1922,1,55,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1923,1,56,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1924,1,57,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1925,1,2,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,1),(1926,1,3,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1927,1,4,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1928,1,5,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1929,1,6,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1930,1,7,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1931,1,8,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1932,1,9,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1933,1,10,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1934,1,11,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1935,1,12,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1936,1,13,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1937,1,26,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1938,1,17,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1939,1,18,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1940,1,19,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1941,1,20,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1942,1,21,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1943,1,49,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1944,1,51,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1945,1,23,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1946,1,24,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1947,1,25,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1948,1,27,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1949,1,28,NULL,'2020-03-17 10:08:06','2020-03-17 10:08:06',1,0,NULL,NULL,2),(1950,1,33,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1951,1,44,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1952,1,45,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1953,1,46,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1954,1,48,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1955,1,52,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1956,1,53,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1957,1,55,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1958,1,56,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1959,1,57,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1960,1,2,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,2),(1961,1,3,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1962,1,4,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1963,1,5,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1964,1,6,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1965,1,7,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1966,1,8,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1967,1,9,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1968,1,10,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1969,1,11,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1970,1,12,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1971,1,13,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1972,1,26,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1973,1,17,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1974,1,18,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1975,1,19,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1976,1,20,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1977,1,21,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1978,1,49,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1979,1,51,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1980,1,23,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1981,1,24,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1982,1,25,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1983,1,27,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1984,1,28,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1985,1,33,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1986,1,44,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1987,1,45,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1988,1,46,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1989,1,48,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1990,1,52,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1991,1,53,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1992,1,55,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1993,1,56,NULL,'2020-03-17 10:08:07','2020-03-17 10:08:07',1,0,NULL,NULL,3),(1994,1,57,NULL,'2020-03-17 10:08:08','2020-03-17 10:08:08',1,0,NULL,NULL,3),(1995,1,2,NULL,'2020-03-17 10:08:08','2020-03-17 10:08:08',1,0,NULL,NULL,3);

--
-- Table structure for table `tbl_user_profiledetails`
--

CREATE TABLE `tbl_user_profiledetails` (
  `userpriId` int NOT NULL AUTO_INCREMENT,
  `userfullname` varchar(100) NOT NULL,
  `mobileNumber` varchar(100) DEFAULT NULL,
  `address` text,
  `employeId` varchar(100) DEFAULT NULL,
  `designation` varchar(100) DEFAULT NULL,
  `emailId` varchar(100) DEFAULT NULL,
  `userhospetalbranches` text,
  `userModules` text,
  `userId` int DEFAULT NULL,
  `isbranchORcentraluser` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT NULL,
  `lastModifiedDate` datetime DEFAULT NULL,
  `isActive` int DEFAULT NULL,
  `isDeleted` int DEFAULT NULL,
  `userprefix` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`userpriId`)
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_user_profiledetails`
--

INSERT INTO `tbl_user_profiledetails` VALUES (47,'AUseronetwothree','436456','67/1B, 4th Cross, lavelle Road, Bengaluru, Karnataka 560001225678910\n123456\n67/1B, 4th Cross, lavelle Road, Bengaluru, Karnataka 560001225678910\n123456\n','123456789101112',NULL,'AUseronetwothree@gmail.com','2,4,5,6','',56,1,'2018-07-03 17:10:39','2018-07-03 18:07:43',1,0,'Mr.');

--
-- Table structure for table `tbl_user_roles`
--

CREATE TABLE `tbl_user_roles` (
  `auserRoleId` int NOT NULL AUTO_INCREMENT,
  `nUserId` int DEFAULT NULL,
  `nUsername` varchar(45) NOT NULL,
  `role` varchar(45) NOT NULL,
  `nBranchId` int DEFAULT NULL,
  PRIMARY KEY (`auserRoleId`),
  UNIQUE KEY `uni_username_role` (`role`,`nUsername`,`nBranchId`),
  KEY `nUserId` (`nUserId`),
  CONSTRAINT `tbl_user_roles_ibfk_1` FOREIGN KEY (`nUserId`) REFERENCES `tbl_user` (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tbl_user_roles`
--


--
-- Table structure for table `tbl_user_stores_map`
--

CREATE TABLE `tbl_user_stores_map` (
  `storeMapId` int NOT NULL AUTO_INCREMENT,
  `userId` int DEFAULT NULL,
  `storeId` int DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  `loggedUserId` int DEFAULT NULL,
  PRIMARY KEY (`storeMapId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_user_stores_map`
--

INSERT INTO `tbl_user_stores_map` VALUES (1,1,1,'2024-09-14 09:58:25','2024-09-14 09:58:25',1,0,NULL),(2,1,2,'2024-09-14 09:58:25','2024-09-14 09:58:25',1,0,NULL),(3,1,3,'2024-09-14 09:58:25','2024-09-14 09:58:25',1,0,NULL);

--
-- Table structure for table `tbl_vender_outstand_payment_each_transaction`
--

CREATE TABLE `tbl_vender_outstand_payment_each_transaction` (
  `id` int NOT NULL AUTO_INCREMENT,
  `mainTrancId` int DEFAULT '0',
  `vendorId` int DEFAULT '0',
  `branchId` int DEFAULT '0',
  `paidAmount` float DEFAULT '0',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `userId` int DEFAULT NULL,
  `outStandAmount` float DEFAULT '0',
  `paymentDate` date DEFAULT NULL,
  `paymentModeId` int DEFAULT NULL,
  `paymentRemarks` varchar(250) DEFAULT NULL,
  `isCreditOrDebit` int DEFAULT '0',
  `debitTransactionMainTableId` int DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_vender_outstand_payment_each_transaction`
--


--
-- Table structure for table `tbl_vender_outstand_payment_main_transaction`
--

CREATE TABLE `tbl_vender_outstand_payment_main_transaction` (
  `id` int NOT NULL AUTO_INCREMENT,
  `vendorId` int DEFAULT '0',
  `branchId` int DEFAULT '0',
  `totalCreditAmount` float DEFAULT '0',
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_vender_outstand_payment_main_transaction`
--


--
-- Table structure for table `tbl_vendor_payment_each_details`
--

CREATE TABLE `tbl_vendor_payment_each_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `mainTransId` int DEFAULT NULL,
  `grnId` int DEFAULT NULL,
  `invoiceNo` varchar(250) DEFAULT NULL,
  `invoiceDate` date DEFAULT NULL,
  `invoiceAmount` varchar(45) DEFAULT NULL,
  `venderId` varchar(45) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `branchId` int DEFAULT NULL,
  `userId` int DEFAULT NULL,
  `grnNumber` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `mainTransId_idx` (`mainTransId`),
  CONSTRAINT `mainTransId` FOREIGN KEY (`mainTransId`) REFERENCES `tbl_vendor_payment_main_details` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_vendor_payment_each_details`
--


--
-- Table structure for table `tbl_vendor_payment_main_details`
--

CREATE TABLE `tbl_vendor_payment_main_details` (
  `id` int NOT NULL AUTO_INCREMENT,
  `venderId` int DEFAULT '0',
  `totalInvoiceCount` int DEFAULT '0',
  `crediPeriodInvCount` int DEFAULT '0',
  `totalInvAmt` float DEFAULT '0',
  `crediPeriodInvAmt` float DEFAULT '0',
  `paidAmount` float DEFAULT '0',
  `creditAmount` float DEFAULT '0',
  `paymentDate` date DEFAULT NULL,
  `paymentMode` varchar(250) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` tinyint DEFAULT '1',
  `isDeleted` tinyint DEFAULT '0',
  `branchId` int DEFAULT NULL,
  `userId` int DEFAULT NULL,
  `remarks` varchar(250) DEFAULT NULL,
  `payModeId` int DEFAULT '0',
  `advanceAmtConsumed` float DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tbl_vendor_payment_main_details`
--


--
-- Table structure for table `tblhospitalbranches`
--

CREATE TABLE `tblhospitalbranches` (
  `abranchId` int NOT NULL AUTO_INCREMENT,
  `branchHospName` varchar(1000) DEFAULT NULL,
  `bhospitalOwnerName` varchar(250) DEFAULT NULL,
  `bhospitalAddress` varchar(1000) DEFAULT NULL,
  `bhospitalCity` varchar(100) DEFAULT NULL,
  `bhospitalState` varchar(100) DEFAULT NULL,
  `bhospitalCountry` varchar(100) DEFAULT NULL,
  `bPincode` varchar(50) DEFAULT NULL,
  `bhospitalPhNo` varchar(250) DEFAULT NULL,
  `bhospitalEmergencyNo` varchar(250) DEFAULT NULL,
  `StartTime` time DEFAULT NULL,
  `EndTime` time DEFAULT NULL,
  `WeeklyOff` varchar(250) DEFAULT NULL,
  `branchActive` int DEFAULT '1',
  `nhospitalId` int DEFAULT NULL,
  `nhospitalActive` int DEFAULT '1',
  `tEmailId` varchar(250) DEFAULT NULL,
  `nbranchcode` varchar(250) DEFAULT NULL,
  `regNo` varchar(45) DEFAULT NULL,
  `PANNo` varchar(45) DEFAULT NULL,
  `distCode` varchar(45) DEFAULT NULL,
  `bhospitalDistrict` varchar(50) DEFAULT NULL,
  `bGSTINno` varchar(45) DEFAULT NULL,
  `st_number` varchar(50) DEFAULT NULL,
  `cin_number` varchar(50) DEFAULT NULL,
  `rohini_id` varchar(50) DEFAULT NULL,
  `hospBranch_DeliveryAddress` text,
  `hospBranch_BillingAddress` text,
  `nHospBranch_LocationId` int DEFAULT NULL,
  `po_raise_format` varchar(45) DEFAULT NULL,
  `grnShortCode` varchar(10) DEFAULT NULL,
  `hospetalFlag` int DEFAULT NULL,
  `fax` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`abranchId`),
  KEY `nhospitalId` (`nhospitalId`),
  CONSTRAINT `tblhospitalbranches_ibfk_1` FOREIGN KEY (`nhospitalId`) REFERENCES `tblhospitalsdetails` (`aHospitalId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tblhospitalbranches`
--

INSERT INTO `tblhospitalbranches` VALUES (1,'Branch One',NULL,'Bengaluru',NULL,NULL,NULL,'577548','577548','577548',NULL,NULL,NULL,1,NULL,NULL,NULL,'KDR',NULL,NULL,NULL,NULL,'577548',NULL,NULL,NULL,'Kadur','Kadur',3,'577548','KDR',1,'577548'),(2,'Branch Two',NULL,'Bengaluru',NULL,NULL,NULL,'577548','577548','577548',NULL,NULL,NULL,1,NULL,NULL,NULL,'KDR1',NULL,NULL,NULL,NULL,'577548',NULL,NULL,NULL,'Sakharaayapatna','Sakharaayapatna',3,'577548','KDR1',3,'577548'),(3,'Branch Three',NULL,'Bengaluru',NULL,NULL,NULL,'577548','577548','577548',NULL,NULL,NULL,1,NULL,NULL,NULL,'KDR2',NULL,NULL,NULL,NULL,'577548',NULL,NULL,NULL,'Birur','Birur',3,'577548','Kdr2',3,'577548');

--
-- Table structure for table `tblhospitalsdetails`
--

CREATE TABLE `tblhospitalsdetails` (
  `aHospitalId` int NOT NULL AUTO_INCREMENT,
  `hospitalName` varchar(500) DEFAULT NULL,
  `hospitalOwnerName` varchar(250) DEFAULT NULL,
  `hospitalAddress` varchar(1000) DEFAULT NULL,
  `hospitalCity` varchar(100) DEFAULT NULL,
  `hospitalState` varchar(100) DEFAULT NULL,
  `hospitalCountry` varchar(100) DEFAULT NULL,
  `Pincode` varchar(50) DEFAULT NULL,
  `hospitalPhNo` varchar(250) DEFAULT NULL,
  `hospitalEmergencyNo` varchar(250) DEFAULT NULL,
  `StartTime` varchar(500) DEFAULT NULL,
  `EndTime` varchar(500) DEFAULT NULL,
  `WeeklyOff` varchar(250) DEFAULT NULL,
  `active` int DEFAULT NULL,
  `hospitalEmail` varchar(500) DEFAULT NULL,
  `hospitalType` varchar(500) DEFAULT NULL,
  `hospitalNameBarcode` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`aHospitalId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

--
-- Dumping data for table `tblhospitalsdetails`
--

INSERT INTO `tblhospitalsdetails` VALUES (1,'M N Eye Hospital','Dr ','TN','1','1','1','122018','8867174899','9967174899','09:00:00','21:00:00','',1,'','',NULL);

--
-- Table structure for table `tblhospotalwiseconfigurations`
--

CREATE TABLE `tblhospotalwiseconfigurations` (
  `aConfig_fk` int NOT NULL AUTO_INCREMENT,
  `configKey` varchar(250) DEFAULT NULL,
  `configValue` varchar(1000) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `configDescription` varchar(250) DEFAULT NULL,
  `insertedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `lastModifiedDate` datetime DEFAULT CURRENT_TIMESTAMP,
  `isActive` int DEFAULT '1',
  `isDeleted` int DEFAULT '0',
  PRIMARY KEY (`aConfig_fk`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tblhospotalwiseconfigurations`
--

INSERT INTO `tblhospotalwiseconfigurations` VALUES (1,'IsInvoiceGRNunique','1','1 to make invoice number unique 0 to not','2023-11-07 12:04:22','2023-11-07 12:04:22',1,0),(2,'IsBranchReturntodepo','1','1 to return to supplier and 0 to return to depo','2023-11-07 12:04:22','2023-11-07 12:04:22',1,0),(3,'PlacepfsupplyinGSTReport','Mumbai',NULL,'2024-03-19 17:58:48','2024-03-19 17:58:48',1,0);

--
-- Dumping events for database 'ophthalstock'
--

--
-- Dumping routines for database 'ophthalstock'
--
/*!50003 DROP FUNCTION IF EXISTS `UDF_getAvailableQtyInGrn` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `UDF_getAvailableQtyInGrn`(
grnEachId int
) RETURNS int
BEGIN

RETURN (
/*SELECT 
    IFNULL(TGFPEIO.receivedQty, 0) 
	-- +	IF(TGRED.isStockIn = 1,IFNULL(SUM(TGRED.returnQty), 0),0)
    - (IFNULL(SUM(TSITE.issuedQty), 0) + 
		(IF(TGRED.isStockIn <> 1,IFNULL(SUM(TGRED.returnQty), 0),0)))
FROM
    tbl_grn_for_po_each_item_orders TGFPEIO
        LEFT JOIN
    tbl_stocks_issued_to_emr TSITE ON TGFPEIO.aGrnId_each_pk = TSITE.ngrnEachId_fk
        LEFT JOIN
    tbl_grn_return_each_details TGRED ON TGRED.nEachGrnId = TGFPEIO.aGrnId_each_pk
WHERE
    TGFPEIO.aGrnId_each_pk = grnEachId*/
		SELECT availQty FROM tbl_grn_availqty WHERE nEachGrnId = grnEachId
);
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `UDF_getIndentedItemsTransferPendingQty` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `UDF_getIndentedItemsTransferPendingQty`(
branchId int,
eachPoId int
) RETURNS int
BEGIN
RETURN (
SELECT 
		-- 	 GROUP_CONCAT(TOPEID.apoeachid) AS poEachId  
		-- 	 ,GROUP_CONCAT(TSITE.issuedToBrancheACHPoId) AS poEachIdTransferred
		-- 	  ,IFNULL(TOPEID.item_order_qty,0) AS itemOrderedQty
		-- 	 ,IFNULL(SUM(TSITE.issuedQty),0) AS itemtransferredQty
        --      ,GROUP_CONCAT(TSITE.issedStock_Pk) AS eachTransferId,
            IFNULL(IF(
				IFNULL(SUM(TSITE.issuedQty),0) < IFNULL(TOPEID.item_order_qty,0),
				(IFNULL((TOPEID.item_order_qty),0) - IFNULL(SUM(TSITE.issuedQty),0)),
                0
            ),0) AS itemPendingQty
		FROM tbl_os_po_each_item_details TOPEID 
			
            JOIN tbl_os_po_main_details TOPMD ON TOPMD.apoid = TOPEID.npoid_fk
            JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.issuedToBrancheACHPoId = TOPEID.apoeachid
            AND TSITE.issuedToBrancheACHPoId = eachPoId
		WHERE TOPMD.po_from_branch_fk = branchId
			 	
		GROUP BY TSITE.issuedToBrancheACHPoId
);
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `UDF_getIssuedItemsBalanceQty` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `UDF_getIssuedItemsBalanceQty`(
 eachPoId int
) RETURNS int
BEGIN
RETURN	(SELECT 
		ifnull(TOPEIDFB.item_order_qty,0) - ifnull(SUM(TSITE.issuedQty),0)
        FROM tbl_os_po_each_item_details TOPEIDFB
        JOIN tbl_stocks_issued_to_emr TSITE ON TOPEIDFB.apoeachid = TSITE.issuedToBrancheACHPoId
        WHERE TOPEIDFB.apoeachid = eachPoId
        );
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `UDF_getItemAvailableQtyByItemId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `UDF_getItemAvailableQtyByItemId`(
itemId TEXT,
branchId int,
grnTypeId int
) RETURNS int
BEGIN
RETURN(
   SELECT IF(SUM(TMP.rQty) - SUM(TMP.iQty) < 0, 
			0,
			(SUM(TMP.rQty) - SUM(TMP.iQty))
            ) AS itemAvailQty  FROM
	(SELECT 
		IFNULL((TGFPEIO.receivedQty), 0) AS rQty,
		(IFNULL(SUM(TSITE.issuedQty), 0) +  ifnull(IF(TGRED.isStockIn <> 1,IFNULL(SUM(TGRED.returnQty), 0),0),0),0) AS iQty
			-- ifnull(SUM(TGFPEIO.receivedQty) ,0) - ifnull(SUM(TSITE.issuedQty),0) AS itemAvailQty
			FROM tbl_grn_for_po_each_item_orders TGFPEIO
			LEFT JOIN tbl_stocks_issued_to_emr TSITE ON TGFPEIO.aGrnId_each_pk = TSITE.ngrnEachId_fk
             AND nIssuedFromBranchId_fk= branchId
			LEFT JOIN tbl_grn_return_each_details TGRED ON TGRED.nEachGrnId = TGFPEIO.aGrnId_each_pk
             AND TGRED.nReturnFromBranchId = branchId
			WHERE FIND_IN_SET(TGFPEIO.nItemId_fk,itemId) -- = itemId   
            AND TGFPEIO.ngrnBranchId_fk = branchId
            AND IF(grnTypeId != -1, TGFPEIO.nGrnTypeId = grnTypeId, TRUE)
             GROUP BY TGFPEIO.aGrnId_each_pk 
	) AS TMP);
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `UDF_getMainGrnIdFromGrnNumber` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `UDF_getMainGrnIdFromGrnNumber`(
 grnNumbers varchar(100),
 branchId int
) RETURNS int
BEGIN

RETURN (
	SELECT ifnull(aGrnId_pk,0) as mainGrnNumber FROM tbl_grn_for_po_orders WHERE grnNumber = grnNumbers AND ngrnBranchId_fk = branchId
LIMIT 0,1
);
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `UDF_getPoItemsBalanceQtyWhileGrn` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `UDF_getPoItemsBalanceQtyWhileGrn`(
	mainPoId int,
    eachPoId int
) RETURNS int
BEGIN

RETURN (
SELECT IFNULL(TMP.item_order_qty,0) - IFNULL(TMP.receivedQty,0) AS balanceQty FROM
		(SELECT TGFPEIO.nPoIdCentral_fk, TGFPEIO.nPoEachId, TOPEID.item_order_qty, SUM(TGFPEIO.receivedQty) AS receivedQty FROM tbl_os_po_each_item_details TOPEID
			LEFT JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TOPEID.apoeachid = TGFPEIO.nPoEachId
			WHERE TGFPEIO.nPoIdCentral_fk = mainPoId AND TGFPEIO.nPoEachId = eachPoId
		) AS TMP
);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `getDioSizStrVolDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `getDioSizStrVolDetails`(
IN itemId int,
IN storeId int,
IN stockType int,
IN branchId int
)
BEGIN
declare storeFlagmaster int;
set storeFlagmaster = (select storeFlag from tbl_mst_storecreation where `aStoreId_pk`=storeId);
SELECT * FROM (
SELECT 
		IF(TMS.storeFlag = 1, diapter, strength) AS leftVal,
        IF(TMS.storeFlag = 1, size,volume) AS rightVal,
        UDF_getAvailableQtyInGrn(TGFPOEIO.aGrnId_each_pk) AS availQty
        FROM tbl_grn_for_po_each_item_orders TGFPOEIO
		JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TGFPOEIO.nStoreId_fk

	WHERE 
		nItemId_fk 		= itemId 
        AND nStoreId_fk = storeId
        AND nPoType_fk  = stockType
        AND ngrnBranchId_fk = branchId
       AND UDF_getAvailableQtyInGrn(TGFPOEIO.aGrnId_each_pk) > 0
	GROUP BY 
    IF(storeFlagmaster = 1, concat(diapter, size),concat(strength, volume))
ORDER BY aGrnId_each_pk DESC) AS TMP;
-- WHERE TMP.availQty > 0;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `getItemDetailsByDcId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `getItemDetailsByDcId`(
in dcId int
)
BEGIN

SELECT 
	TOPEID.item_id_fk as itemId,
	TOPEID.item_code AS itemCode,
	TOPEID.item_name AS itemName,
	IF(TGFPEIO.nGrnTypeId=1,TOPEID.item_diapter,TOPEID.item_strength) as diaptOrStrength,
	IF(TGFPEIO.nGrnTypeId=1,TOPEID.item_size,TOPEID.item_volume) as strOrVol,
	TSITE.batchNo as batchNo,
	TSITE.expiryDate AS expDate,
	TSITE.serialNo AS serialNo,
	TSITE.issuedQty AS issuedQty,
	TSITE.availQty AS availQty,
	TGFPEIO.nGrnTypeId AS grnTypeId
 FROM tbl_stocks_issued_to_emr AS TSITE
JOIN tbl_stock_transfer_maindetails AS TSTM ON TSTM.aMainStckTrnfrId = TSITE.nMainStockTrnsfrId
join tbl_grn_for_po_orders AS  TGPO ON TGPO.aGrnId_pk = TSITE.ngrnId_fk
JOIN tbl_grn_for_po_each_item_orders AS TGFPEIO ON TGFPEIO.nGrnId_fk =  TGPO.aGrnId_pk
JOIN tbl_os_po_each_item_details AS TOPEID ON TOPEID.apoeachid = TGFPEIO.nPoEachId
WHERE TSITE.nMainStockTrnsfrId=dcId
group by TOPEID.item_id_fk , diaptOrStrength,strOrVol;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `getVenderOustandingPayment` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `getVenderOustandingPayment`(
in in_branchId int,
in in_supplierId int
)
BEGIN

SELECT 
    sum(ifnull(T1.invoiceAmount,0)+ifnull(T1.frightCharges,0)) as outStandingAmt
FROM
    tbl_grn_for_po_orders T1
        JOIN
    tbl_mst_supplier T2 ON T1.nSupplierId_fk = T2.aSupplierId_pk and T1.isPaid=0 and T1.nPoType_fk=1 
  where   T1.nSupplierId_fk=in_supplierId and  if(in_branchId='-1',true, T1.ngrnBranchId_fk = in_branchId)   
group by T1.nSupplierId_fk   ;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_createGrnReturnEachItemDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_createGrnReturnEachItemDetails`(
in_nReturnMainId int,
 in_nStoreId int, 
 in_nMainGrnId int, 
 in_nEachGrnId int, 
 in_returnQty int,
 in_returnReason text,
	in_returnStatus int, 
	in_nReturnFromBranchId int, 
	in_nReturnToBranchId int,
	in_nReturnType int, 
	in_nSupplierMapId int, 
	in_returnComments text,
	in_nUserId_fk int,
in in_nReturnToSupplierId int,
in in_itemId int,
in in_supplierId int
)
BEGIN
if(UDF_getAvailableQtyInGrn(in_nEachGrnId) >= in_returnQty) then
INSERT INTO tbl_grn_return_each_details
(
	nReturnMainId, nStoreId, nMainGrnId, nEachGrnId, returnQty, returnReason,
	returnStatus, nReturnFromBranchId, nReturnToBranchId, nReturnType, nSupplierMapId, 
    returnComments, nUserId_fk,nReturnToSupplier,itemId,supplierId
) VALUES
(
	in_nReturnMainId, in_nStoreId, in_nMainGrnId, in_nEachGrnId, in_returnQty, in_returnReason,
	in_returnStatus, in_nReturnFromBranchId, in_nReturnToBranchId, in_nReturnType, in_nSupplierMapId, 
    in_returnComments, in_nUserId_fk,in_nReturnToSupplierId,in_itemId,in_supplierId
);
end if;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_CreateOrUpdateLocation` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_CreateOrUpdateLocation`(
in in_locId int,
in in_locationName varchar(250),
in in_locationShortCode varchar(250)
)
BEGIN
Declare flag int;
SET flag = (select count(aLocationId_pk) FROM tbl_mst_locations WHERE locnShortCode = in_locationShortCode);

if(in_locId = -1 && flag = 0) then
INSERT INTO `tbl_mst_locations`
(`locnShortCode`,
`locnName`)
VALUES
(in_locationShortCode,
in_locationName
);
else
UPDATE tbl_mst_locations
SET locnShortCode = in_locationShortCode,
locnName = in_locationName
where aLocationId_pk = in_locId;
END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_createPOHistoryLog` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_createPOHistoryLog`(
in in_npotypeid int,
in in_createdAt datetime,
in in_createdBy int,
in in_statusId int,
in in_poMainId int,
in in_poEachItemId int,
in in_auserId_fk int,
in in_remarks varchar(40),
in in_orderQty int

)
BEGIN
INSERT INTO 
tbl_po_status_history_log
( 
npotypeid,
createdAt,
createdBy,
statusId,
nPoMainId,
nPoEachItemId,
nUserId_fk,
remarks,
Qty
)
VALUES
(
 in_npotypeid ,
 in_createdAt ,
 in_createdBy ,
 in_statusId ,
 in_poMainId ,
 in_poEachItemId ,
 in_auserId_fk ,
 in_remarks,
 in_orderQty
);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_credit_note_each` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_credit_note_each`(
in in_nCreditNoteMainId int,
in in_nItemId int,
in in_batchNumber varchar(45),
in in_serialNumber varchar(45),
in in_nUserId int,
in in_acceptedDate datetime,
in in_unitPrice float,
in in_totAmount float,
in in_remarks varchar(45),
in in_creditStatus int,
in in_nMainGrnId int ,
in in_nEachGrnId int,
in in_nGrnAvailQtyId int,
in in_acceptedQty int,
in in_itemDiapter varchar(45),
in in_itemSize varchar(45),
in in_itemStrength varchar(45),
in in_itemValume varchar(45),
in in_poNumber int,
in in_nBranchId int,
in in_nPoTypeId int,
in in_nsuppliedmapId int,
in in_expiryDate datetime,
in in_nDebitNoteMainId int,
in in_nDebitNoteEachId int,
in in_nStoreId int
)
BEGIN
INSERT INTO tbl_credit_note_each
(
nCreditNoteMainId,
nItemId,
batchNumber,
serialNumber,
nUserId,
acceptedDate,
unitPrice,
totAmount,
remarks,
creditStatus,
nMainGrnId,
nEachGrnId,
nGrnAvailQtyId,
acceptedQty,
itemDiapter,
itemSize,
itemStrength,
itemValume,
poNumber,
nBranchId,
nPoTypeId,
nsuppliedmapId,
expiryDate,
nDebitNoteMainId,
nDebitNoteEachId,
nStoreId
)
VALUES
(
in_nCreditNoteMainId,
in_nItemId,
in_batchNumber,
in_serialNumber,
in_nUserId,
in_acceptedDate,
in_unitPrice,
in_totAmount,
in_remarks,
in_creditStatus,
in_nMainGrnId,
in_nEachGrnId,
in_nGrnAvailQtyId,
in_acceptedQty,
in_itemDiapter,
in_itemSize,
in_itemStrength,
in_itemValume,
in_poNumber,
in_nBranchId,
in_nPoTypeId,
in_nsuppliedmapId,
in_expiryDate,
in_nDebitNoteMainId,
in_nDebitNoteEachId,
in_nStoreId
);

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_credit_note_main` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_credit_note_main`(

in in_nDebitNoteId int,
in in_nDebitedAmount float,
in in_creditedAmount float,
in in_nUserId int,
in in_creditedDate datetime,
in in_nBranchId int,
in in_creditNoteNumber varchar(45),
in in_noOfIteam int,
in in_totQty int,
in in_remarks varchar(45),
in in_nCreditedStatus int,
in in_nsupplierId int,
out InautoMainCnid int,
out CNNumber varchar(50)

)
BEGIN
DECLARE autoMainCnid int;
DECLARE CnNumber_format varchar(150);
INSERT INTO tbl_credit_note_main
(

nDebitNoteId,
nDebitedAmount,
creditedAmount,
nUserId,
creditedDate,
nBranchId,
creditNoteNumber,
noOfItem,
totQty,
remarks,
nCreditedStatus,
nsupplierId
)
VALUES
(

in_nDebitNoteId,
in_nDebitedAmount,
in_creditedAmount,
in_nUserId,
in_creditedDate,
in_nBranchId,
in_creditNoteNumber,
in_noOfIteam,
in_totQty,
in_remarks,
in_nCreditedStatus,
in_nsupplierId
);
set autoMainCnid = last_insert_id();
set CnNumber_format = concat(ifnull(CnNumber_format, 'CN'), '/CN/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoMainCnid);

update tbl_credit_note_main
set creditNoteNumber = CnNumber_format
where acreditNoteId = autoMainCnid;

set InautoMainCnid = autoMainCnid;
set CNNumber = CnNumber_format; 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_debit_note_each` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_debit_note_each`(
in in_nMainDnId int,
in in_nItemId int,
in in_nsupplierId int,
in in_batchNo varchar(45),
in in_serilNo varchar(45),
in in_nUserId int,
in in_retuenAt datetime,
in in_unitPrice float,
in in_totalAmount float,
in in_remarks varchar(45),
in in_status varchar(45),
in in_nReturnUserId int,
in in_nMainGrnId int,
in in_nEachGrnId int,
in in_nGrnAvailQty int,
in in_nMainReturnId int,
in in_nEachReturnId int,
in in_totTaxAmount float,
in in_returnQty int,
in in_itemDiapter varchar(45),
in in_itemSize  varchar(45),
in in_itemStrength  varchar(45),
in in_itemVolume  varchar(45),
in in_poNumber  varchar(45),
in in_grnNumber  varchar(45),
in in_branchId int,
in in_storeId int,
in in_poTypeId int,
in in_supplierMapId int,
in in_expiryDate datetime
)
BEGIN

INSERT INTO tbl_debit_note_each
(

nMainDnId,
nItemId,
nsupplierId,
batchNo,
serilNo,
nUserId,
retuenDate,
unitPrice,
totalAmount,
remarks,
debitStatus,
nReturnUserId,
nMainGrnId,
nEachGrnId,
nGrnAvailQtyId,
nMainReturnId,
nEachReturnId,
totTaxAmount,
returnQty,
itemDiapter,
itemSize,
itemStrength,
itemVolume,
poNumber,
grnNumber,
nBranchId,
nStoreId,
nPoTypeId,
nSupplierMapId,
expiryDate
)
VALUES
(
in_nMainDnId,
in_nItemId,
in_nsupplierId,
in_batchNo,
in_serilNo,
in_nUserId,
in_retuenAt,
in_unitPrice,
in_totalAmount,
in_remarks,
in_status,
in_nReturnUserId,
in_nMainGrnId,
in_nEachGrnId,
in_nGrnAvailQty,
in_nMainReturnId,
in_nEachReturnId,
in_totTaxAmount,
in_returnQty,
in_itemDiapter,
in_itemSize,
in_itemStrength,
in_itemVolume,
in_poNumber,
in_grnNumber,
in_branchId,
in_storeId,
in_poTypeId,
in_supplierMapId,
in_expiryDate
);


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_debit_note_main` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_debit_note_main`(
in in_noOfItems int,
in in_totQty int,
in in_totAmount float,
in in_nUserId_fk int,
in in_returnDate datetime,
in in_nSupplierId int,
in in_DNNumber varchar(45),
in in_remarks varchar(45),
in in_status int,
in in_nReturnUserId int,
in in_totTaxAmount float,
in in_branchId int,
out InautoMainDnid int,
 out DNNumber varchar(50)
)
BEGIN
DECLARE autoMainDnid int;
DECLARE DnNumber_format varchar(150);
INSERT INTO tbl_debit_note_main
(
noOfItems,
totQty,
totAmount,
nUserId_fk,
returnDate,
nSupplierId,
remarks,
DNNumber,
debitStatus,
nReturnUserId,
totTaxAmount,
nBranchId
)
VALUES
(
in_noOfItems,
in_totQty,
in_totAmount,
in_nUserId_fk,
in_returnDate,
in_nSupplierId,
in_DNNumber,
in_remarks,
in_status,
in_nReturnUserId,
in_totTaxAmount,
in_branchId
);
set autoMainDnid = last_insert_id();

set DnNumber_format = concat(ifnull(DnNumber_format, 'DN'), '/DN/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoMainDnid);

update tbl_debit_note_main
set DNNumber = DnNumber_format
where aMainDNId = autoMainDnid;
set InautoMainDnid = autoMainDnid;
set DNNumber = DnNumber_format; 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_grnreturn_eachitemdetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_grnreturn_eachitemdetails`(

in nReturnMainId int,
in nStoreId varchar(30),
in nMainGrnId int,
in  nEachGrnId int,
in returnQty float,
in returnReason varchar(30),
in  returnStatus tinyint,
in nReturnFromBranchId int,
in nReturnToBranchId int,
in  nReturnType int,
in nSupplierId int,
in returnComments varchar(30),
in nAuthUserId int,
in authDate datetime,
in authComments varchar(30),
in insertedDate datetime,
in lastModifiedDate datetime,
in isActive tinyint,
in isDeleted tinyint,
in nUserId_fk int
)
BEGIN
IF(select UDF_getAvailableQtyInGrn(nEachGrnId) > 0) THEN
INSERT INTO tbl_grn_return_each_details
(

nReturnMainId,
nStoreId,
nMainGrnId,
nEachGrnId,
returnQty,
returnReason,
returnStatus,
nReturnFromBranchId,
nReturnToBranchId,
nReturnType,
nSupplierId,
returnComments,
nAuthUserId,
authDate,
authComments,
insertedDate,
lastModifiedDate,
isActive,
isDeleted,
nUserId_fk
)
VALUES
(

nReturnMainId,
nStoreId,
nMainGrnId,
nEachGrnId,
returnQty,
returnReason,
returnStatus,
nReturnFromBranchId,
nReturnToBranchId,
nReturnType,
nSupplierId,
returnComments,
nAuthUserId,
authDate,
authComments,
insertedDate,
lastModifiedDate,
isActive,
isDeleted,
nUserId_fk
);
END if;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_po_eachitemdetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_po_eachitemdetails`(
in npoid_fks int,
in item_id_fks int,
in item_codes varchar(50),
in item_names tinytext,
in item_hsn_codes varchar(50),
in item_order_qtys int,
in item_unit_prices float,
in item_discount_percents float,
in item_discount_rss float,
in item_gst_percents float,
in item_gst_rss float,
in item_sgst_percents float,
in item_sgst_rss float,
in item_cgst_percents float,
in item_cgst_rss float,
in item_igst_percents float, 
in item_igst_rss float,
in item_total_amt_without_gsts float,
in item_total_amt_with_gsts float,
in nUserId_fks int,
in item_diapters varchar(25),
in item_strengths varchar(25),
in item_volumes varchar(25),
in po_statuss int,
in item_free_qtys int,
in item_sizes varchar(25),
in n_poeachid_from_branch_fks int,
in supplierItemMapId int,
in requesType int,
in indentToBranchIds int,
in remarks varchar(40),
in createdAt datetime,
in in_indentEachid int
)
BEGIN
DECLARE autoPOEachid int;
	INSERT INTO tbl_os_po_each_item_details 
	(
	npoid_fk,
	item_id_fk,
	item_code,
	item_name,
	item_hsn_code,
	item_order_qty,
	item_unit_price,
	item_discount_percent,
	item_discount_rs,
	item_gst_percent,
	item_gst_rs,
	item_sgst_percent,
	item_sgst_rs,
	item_cgst_percent,
	item_cgst_rs,
	item_igst_percent,
	item_igst_rs,
	item_total_amt_without_gst,
	item_total_amt_with_gst,
	nUserId_fk,
    item_diapter,
    item_strength,
    item_volume,
    poItemStatusId,
    item_free_qty,
    item_size,
    n_poeachid_from_branch_fk,
    nSupplierItemMapid,
    typeOfRequest,
    indentToBranchId,
    indentEachid
    )
	VALUES
	(
	npoid_fks,
	item_id_fks,
	item_codes,
	item_names,
	item_hsn_codes,
	item_order_qtys,
	item_unit_prices,
	item_discount_percents,
	item_discount_rss,
	item_gst_percents,
	item_gst_rss,
	item_sgst_percents,
	item_sgst_rss,
	item_cgst_percents,
	item_cgst_rss,
	item_igst_percents,
	item_igst_rss,
	item_total_amt_without_gsts,
	item_total_amt_with_gsts,
	nUserId_fks,
    item_diapters,
    item_strengths,
    item_volumes,
    po_statuss,
    item_free_qtys,
    item_sizes,
    n_poeachid_from_branch_fks,
    supplierItemMapId,
    requesType,
    indentToBranchIds,
    in_indentEachid
    ); 
set autoPOEachid = last_insert_id();
INSERT INTO  tbl_po_status_history_log
(
npotypeid,
createdAt,
createdBy,
statusId,
nPoMainId,
nPoEachItemId,
nUserId_fk,
remarks,
Qty
)
VALUES
(
 requesType ,
 createdAt ,
 nUserId_fks ,
 po_statuss ,
 npoid_fks ,
 autoPOEachid ,
 nUserId_fks , 
 remarks ,
 item_order_qtys
);

if(in_indentEachid <> 'null')
then
update tbl_os_po_each_item_details set indentEachid=autoPOEachid ,indentPoraiseStatus=1,indentPoraiseQty=item_order_qtys where apoeachid=in_indentEachid;
end if;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_po_maindetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_po_maindetails`(
in po_numbers varchar(30),
in instore_fks int,
in po_type_fks int,
in po_from_branch_fks int,
in po_dates varchar(30),
in po_raisedby_fks int,
in po_billingaddresss text,
in po_deliveryaddresss text,
in po_to_supplier_id_fks int,
in po_expexted_delivery_dates  varchar(30),
in po_total_itemss int,
in po_total_items_qtys int,
in po_statuss int,
in po_status_texts varchar(30),
in po_authorized_by_fks int,
in po_authorized_dates varchar(30),
in nUserId_fks int,
in po_total_amounts float,
in n_poid_from_branch_fks int,
out autoPOid int,
in gstTypes int,
in poRemarks text,
in requesType int,
in indentToBranchIds int,
in po_fc_amounts float,
in po_discount_amounts float,
in po_final_total_amounts float

)
BEGIN

DECLARE po_num varchar(200);
DECLARE po_bracnh_format varchar(150);

	INSERT INTO tbl_os_po_main_details
		(
		po_number,
		instore_fk,
		po_type_fk,
		po_from_branch_fk,
		po_date,
		po_raisedby_fk,
		po_billingaddress,
		po_deliveryaddress,
		po_to_supplier_id_fk,
		po_expexted_delivery_date,
		po_total_items,
		po_total_items_qty,
        po_total_amount,
		po_status,
		po_status_text,
		-- po_authorized_by_fk,
		-- po_authorized_date,
		nUserId_fk,
        n_poid_from_branch_fk,
        gstType,
        poRemarkss,
        typeOfRequest,
        indentToBranchId,
        freight_charge,
        discount_amount,
        final_total_amount
        )
		VALUES
		(
		po_numbers,
		instore_fks,
		po_type_fks,
		po_from_branch_fks,
		po_dates,
		po_raisedby_fks,
		po_billingaddresss,
		po_deliveryaddresss,
		po_to_supplier_id_fks,
		po_expexted_delivery_dates,
		po_total_itemss,
		po_total_items_qtys,
        po_total_amounts,
		po_statuss,
		po_status_texts,
		-- po_authorized_by_fks,
		-- po_authorized_dates,
		nUserId_fks,
        n_poid_from_branch_fks,
        gstTypes,
        poRemarks,
        requesType,
        indentToBranchIds,
        po_fc_amounts,
        po_discount_amounts ,
        po_final_total_amounts
        );

set autoPOid = last_insert_id();

set po_bracnh_format = (select ifnull(po_raise_format, 'EQ') from tblhospitalbranches where abranchId = po_from_branch_fks);
if(po_type_fks = 1) then
set po_num = concat(ifnull(po_bracnh_format, 'EQ'), '/PO/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoPOid);
else if(po_type_fks = 4) then
set po_num = concat(ifnull(po_bracnh_format, 'EQ'), '/IND/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoPOid);
else
set po_num = concat(ifnull(po_bracnh_format, 'EQ'), '/CPO/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoPOid);
end if;
end if;
update tbl_os_po_main_details
set po_number = po_num
where apoid = autoPOid;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_po_maindetails_Emr` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_po_maindetails_Emr`(
in po_numbers varchar(30),
in instore_fks int,
in po_type_fks int,
in po_from_branch_fks int,
in po_dates varchar(30),
in po_raisedby_fks int,
in po_billingaddresss text,
in po_deliveryaddresss text,
in po_to_supplier_id_fks int,
in po_expexted_delivery_dates  varchar(30),
in po_total_itemss int,  
in po_total_items_qtys int,
in po_statuss int,
in po_status_texts varchar(30),
in po_authorized_by_fks int,
in po_authorized_dates varchar(30),
in nUserId_fks int,
in po_total_amounts float,
in n_poid_from_branch_fks int,
out autoPOid int,
in gstTypes int,
in poRemarks text,
in requesType int,
in indentToBranchIds int,
in po_fc_amounts float,
in po_discount_amounts float,
in po_final_total_amounts float,
in emrpatientId int,
in patientCode varchar(250),
in patientName varchar(250),
in councilId int,
in surgId int,
in reservedById int,
in reservedByName varchar(250),
in isReserved int,
out indentNumber varchar(250)
)
BEGIN

DECLARE po_num varchar(200);
DECLARE po_bracnh_format varchar(150);

	INSERT INTO tbl_os_po_main_details
		(
		po_number,
		instore_fk,
		po_type_fk,
		po_from_branch_fk,
		po_date,
		po_raisedby_fk,
		po_billingaddress,
		po_deliveryaddress,
		po_to_supplier_id_fk,
		po_expexted_delivery_date,
		po_total_items,
		po_total_items_qty,
        po_total_amount,
		po_status,
		po_status_text,
		-- po_authorized_by_fk,
		-- po_authorized_date,
		nUserId_fk,
        n_poid_from_branch_fk,
        gstType,
        poRemarkss,
        typeOfRequest,
        indentToBranchId,
        freight_charge,
        discount_amount,
        final_total_amount,
        patientId,
        counsilId,
        surgAppId,
        patName,
        patientCode,
        reservedById,
        reservedByName,
        isReserved
        )
		VALUES
		(
		po_numbers,
		instore_fks,
		po_type_fks,
		po_from_branch_fks,
		po_dates,
		po_raisedby_fks,
		po_billingaddresss,
		po_deliveryaddresss,
		po_to_supplier_id_fks,
		po_expexted_delivery_dates,
		po_total_itemss,
		po_total_items_qtys,
        po_total_amounts,
		po_statuss,
		po_status_texts,
		-- po_authorized_by_fks,
		-- po_authorized_dates,
		nUserId_fks,
        n_poid_from_branch_fks,
        gstTypes,
        poRemarks,
        requesType,
        indentToBranchIds,
        po_fc_amounts,
        po_discount_amounts ,
        po_final_total_amounts ,
        emrpatientId,
        councilId,
        surgId,
        patientName,
        patientCode,
        reservedById,
        reservedByName,
        isReserved
        );

set autoPOid = last_insert_id();

set po_bracnh_format = (select ifnull(po_raise_format, 'EQ') from tblhospitalbranches where abranchId = po_from_branch_fks);
if(po_type_fks = 1) then
set po_num = concat(ifnull(po_bracnh_format, 'EQ'), '/PO/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoPOid);
else if(po_type_fks = 4) then
set po_num = concat(ifnull(po_bracnh_format, 'EQ'), '/IND/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoPOid);
else if(po_type_fks = 5) then
set po_num = concat(ifnull(po_bracnh_format, 'EQ'), '/DSI/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoPOid);
else 
set po_num = concat(ifnull(po_bracnh_format, 'EQ'), '/CPO/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoPOid);
end if;
end if;
end if;
update tbl_os_po_main_details
set po_number = po_num
where apoid = autoPOid;

set indentNumber = po_num;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_create_returnGrn_maindetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_create_returnGrn_maindetails`(
in in_nStoreId varchar(30),
in in_returnReason varchar(30),
in in_nReturnedUserId int,
in in_nReturnedDate date,
in in_innBranchId int,
in in_nReturnToBranchId int,
in in_nReturnType  int,
in in_nSupplierMapId int,
in in_returnComments varchar(30),
in in_userId int,
in in_nReturnToSupplierId int
)
BEGIN
DECLARE autoRetrnid INT;
DECLARE rern_num varchar(30);
INSERT INTO tbl_grn_return_main_details
(
nStoreId,
returnReason,
nReturnedUserId,
nReturnedDate,
nBranchId,
nReturnToBranchId,
nReturnType,
nSupplierMapId,
returnComments,
nUserId_fk,
nReturnToSupplier
)
VALUES
(
 in_nStoreId,
 in_returnReason,
 in_nReturnedUserId,
 in_nReturnedDate,
 in_innBranchId,
 in_nReturnToBranchId,
 in_nReturnType,
 in_nSupplierMapId,
 in_returnComments,
 in_userId,
 in_nReturnToSupplierId
);
set autoRetrnid = last_insert_id();
set rern_num = concat( 'RERN',  '/', DATE_FORMAT(now(), '%d%m%Y'), '/', autoRetrnid);
update tbl_grn_return_main_details
set returnNumber = rern_num
where aReturnMainId = autoRetrnid;
SELECT autoRetrnid;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_deactivateHSNCodeForMasters` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_deactivateHSNCodeForMasters`(
in in_hsnId int
)
BEGIN


UPDATE `tbl_mst_hsn_codes`
SET
`isActive` = 0 ,
`isDeleted` = 1 , 
`lastModifiedDate` = now()
WHERE `aHsnAutoId_pk` = in_hsnId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_deactivateItemsForMasters` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_deactivateItemsForMasters`(
in in_itemId int
)
BEGIN

UPDATE tbl_mst_items_details 
SET 
    isActive = 0 , lastModifiedDate = NOW() , isDeleted = 1 
WHERE
    aItemId_pk = in_itemId;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_downloadPurchaseGstReport` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_downloadPurchaseGstReport`(
in startDate date,
in endDate date,
in branchId varchar(250)
)
BEGIN

declare placeOfSupply varchar(1000);

set  placeOfSupply = (SELECT configValue FROM tblhospotalwiseconfigurations where configKey = 'PlacepfsupplyinGSTReport');

SELECT 
    TBLPMD.grnNumber AS grnNumber,
    TBLGSD.company_name AS supplierName,
    TBLGSD.GSTIN AS supplierGstnNo,
    placeOfSupply AS state,
    ifnull(TBLPMD.invoiceNumber,'') AS invoiceNumber,
    DATE(TBLPMD.invoiceDate) AS invoiceDate,
    SUM(TBLGED.taxableAmount) AS netvalue,
    SUM(TBLGED.taxAmount / 2) AS sgstValue,
    SUM(TBLGED.taxAmount / 2) AS cgstValue,
    SUM(TBLGED.taxAmount) AS taxValue,
    SUM(TBLGED.totalAmount) AS totalAmount,
    SUM(ifnull(TBLPMD.frightCharges,0)) as otherAmount
FROM
    tbl_grn_for_po_orders TBLPMD
        JOIN 
    tbl_grn_for_po_each_item_orders TBLGED ON TBLGED.nGrnId_fk = TBLPMD.aGrnId_pk
        JOIN
    tbl_mst_supplier TBLGSD ON TBLGSD.aSupplierId_pk = TBLPMD.nSupplierId_fk
WHERE
    DATE(TBLPMD.grnDate) BETWEEN startDate AND endDate
        AND IF(branchId = '-1',
        TRUE,
        TBLPMD.ngrnBranchId_fk = branchId)
GROUP BY TBLGED.nGrnId_fk;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_downloadPurchaseReport` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_downloadPurchaseReport`(
in startDate date,
in endDate date,
in branchId varchar(250)
)
BEGIN


SELECT 
    TBLPMD.grnNumber AS grnNumber,
    TBLGSD.company_name AS supplierName,
    IFNULL(TBLPMD.invoiceNumber, '') AS invoiceNumber,
    DATE(TBLPMD.invoiceDate) AS invoiceDate,
    SUM(TBLGED.totalAmount) AS totalAmount,
    IFNULL(TBLPRUD.fullName, '') AS enteredBy, 
    IFNULL(TBLPCUD.fullName, '') AS confirmedBy,
    DATE(TBLPMD.grnDate) AS entryDate,
    IFNULL(TBLGSD.credit_period, 0) AS creditPerion
FROM
    tbl_grn_for_po_orders TBLPMD
        JOIN
    tbl_grn_for_po_each_item_orders TBLGED ON TBLGED.nGrnId_fk = TBLPMD.aGrnId_pk
        JOIN
    tbl_mst_supplier TBLGSD ON TBLGSD.aSupplierId_pk = TBLPMD.nSupplierId_fk
        JOIN
    tbl_os_po_main_details TBLPOMD ON TBLPOMD.apoid = TBLPMD.nPoIdCentral_fk
        LEFT JOIN
    tbl_user TBLPRUD ON TBLPMD.nUserId_fk = TBLPRUD.userId
        LEFT JOIN
    tbl_user TBLPCUD ON TBLPOMD.po_authorized_by_fk = TBLPCUD.userId
WHERE
    DATE(TBLPMD.grnDate) BETWEEN startDate AND endDate
        AND IF(branchId = '-1',
        TRUE,
        TBLPMD.ngrnBranchId_fk = branchId) AND TBLPMD.nPoType_fk = 1
GROUP BY TBLGED.nGrnId_fk;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_downloadPurchaseReturnReport` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_downloadPurchaseReturnReport`(
in startDate date,
in endDate date,
in branchId varchar(250)
)
BEGIN


SELECT 
    TBLGSD.company_name AS supplierName,
    TBLGSD.GSTIN AS supplierGstnNo,
    IFNULL(TBLGD.invoiceNumber, '') AS invoiceNumber,
    TBLRTR.returnTypeName AS returnCase,
    TBLRID.itemName as itemName , 
    TBLHD.hsnCode AS hsnCode,
    TBLRED.returnQty AS returnQty,
    TBLGED.batchNo AS batchNo,
    TBLRISMD.purchasePrice AS unitPrice,
    (TBLRED.returnQty * TBLRISMD.purchasePrice) AS taxableValue,
    TBLHD.gstPercentage AS gstScheme,
    TBLHD.sgstPercentage AS sgstPer,
    (TBLRED.returnQty * TBLRISMD.purchasePrice * TBLHD.sgstPercentage / 100) AS sgstAmount,
    TBLHD.cgstPercentage AS cgstPer,
    (TBLRED.returnQty * TBLRISMD.purchasePrice * TBLHD.cgstPercentage / 100) AS cgstAmount,
    DATE(TBLRMD.nReturnedDate) AS returnDate
FROM
    tbl_grn_return_main_details TBLRMD
        JOIN
    tbl_grn_return_each_details TBLRED ON TBLRED.nReturnMainId = TBLRMD.aReturnMainId
        JOIN
    tbl_mst_items_details TBLRID ON TBLRID.aItemId_pk = TBLRED.itemId
        JOIN
    tbl_mst_supplier TBLGSD ON TBLGSD.aSupplierId_pk = TBLRED.supplierId
        JOIN
    tbl_supplier_item_mapping TBLRISMD ON TBLRISMD.supplier_item_mappingId = TBLRED.nSupplierMapId
        JOIN
    tbl_mst_hsn_codes TBLHD ON TBLHD.aHsnAutoId_pk = TBLRISMD.nhsnId_fk
        JOIN
    tbl_grn_for_po_orders TBLGD ON TBLGD.aGrnId_pk = TBLRED.nMainGrnId
        JOIN
    tbl_grn_for_po_each_item_orders TBLGED ON TBLGED.aGrnId_each_pk = TBLRED.nEachGrnId
        JOIN
    tbl_mst_returntypes TBLRTR ON TBLRTR.aReturnTypeId = TBLRED.nReturnType
WHERE
    DATE(TBLRMD.nReturnedDate) BETWEEN startDate AND endDate
        AND IF(branchId = '-1',
        TRUE,
        TBLRMD.nBranchId = branchId) 
        
        order by  DATE(TBLRMD.nReturnedDate)
;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getAcceptedItemsDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getAcceptedItemsDetails`(
	in mainGrnId int,
    in grnBranchId int
)
BEGIN
SELECT TMID.aItemId_pk, 
		TMID.itemShortCode, 
        TMID.itemName ,
        TGFPEIO.serialNumber,
        TGFPEIO.batchNo,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        IF(TMS.storeFlag = 1,
			TGFPEIO.diapter,
            TGFPEIO.strength) AS diaStr,
       IF(TMS.storeFlag = 1,
			TGFPEIO.size,
           TGFPEIO.volume) AS SizVol,
        TGFPEIO.diapter,
        TGFPEIO.size, 
        TGFPEIO.strength,
        TGFPEIO.volume,
        TGFPEIO.aGrnId_each_pk AS eachGrnIds,
        TGFPEIO.nGrnId_fk AS mainGrnId,
        TGFPEIO.receivedQty,
        TMS.storeName
        FROM 
	tbl_grn_for_po_each_item_orders TGFPEIO
    JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
    JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk  = TGFPEIO.nStoreId_fk
WHERE TGFPEIO.nGrnId_fk = mainGrnId AND TGFPEIO.ngrnBranchId_fk = grnBranchId
ORDER BY TGFPEIO.nGrnId_fk DESC;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getAllItemsWrtBranchToMoveStock` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getAllItemsWrtBranchToMoveStock`(
in thisDate date,
in branchId int
)
BEGIN
select * from tbl_dailystock_details TDSD
	-- JOIN tbl_supplier_item_mapping TSIM on TSIM.supplier_item_mappingId = TDSD.nItemRateId
WHERE DATE(TDSD.stockDate) = thisDate and  
	IF(branchId = -1, TRUE ,TDSD.nBranchId = branchId)
    and TDSD.closingStock > 0;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getAllItemsWrtBranchToShowStock` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getAllItemsWrtBranchToShowStock`(
in thisDate date,
in toDate date,
in branchId int
)
BEGIN
select 
	TMID.aItemId_pk as itemId,
    TMID.itemShortCode as itemShortCode,
    TMID.itemName as itemName,
    TSIM.supplier_item_mappingId as itemRateMapId,
    TSIM.nSupplierId_fk as supplierId,
    TSIM.purchasePrice as pPrice,
    TSIM.nhsnId_fk as hsnId,
    TSIM.sellingPrice as sPrice,
    TSIM.MRP as mrp,
    TDSD.batchNo as batchNo,
    TDSD.serialNumber as serialNo,
    date(TDSD.expiryDate) as expiryDate,
    date(TDSD.stockDate) as stockDate,
    TDSD.openingStock as openingStock,
    TDSD.closingStock as closingStock,
    TDSD.nStoreId as storeId,
    TMHC.hsnCode as hsnCode,
    TMHC.gstPercentage as gstPerc,
    TMHC.sgstPercentage as sgstPerc,
    TMHC.cgstPercentage as cgstPerc,
    TMHC.igstPercentage as igstPerc,
    TMS.storeName as storeName,
    TDSD.soldQty as  soldQty
 from tbl_dailystock_details TDSD
	 JOIN tbl_supplier_item_mapping TSIM on TSIM.supplier_item_mappingId = TDSD.nItemRateId
	 JOIN tbl_mst_items_details TMID on TMID.aItemId_pk = TSIM.nItemId_fk
     JOIN tbl_mst_storecreation TMS on TMS.aStoreId_pk = TDSD.nStoreId
     JOIN tbl_mst_hsn_codes TMHC on TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
WHERE (DATE(TDSD.stockDate) between thisDate and toDate) and
	IF(branchId = -1, TRUE ,TDSD.nBranchId = branchId)
ORDER BY stockDate, storeName, itemName;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getAllItemsWrtBranchToShowStockSpecificDays` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getAllItemsWrtBranchToShowStockSpecificDays`(
in thisDate date,
in toDate date,
in branchId int
)
BEGIN
select 
	TMID.aItemId_pk as itemId,
    TMID.itemShortCode as itemShortCode,
    TMID.itemName as itemName,
    TSIM.supplier_item_mappingId as itemRateMapId,
    TSIM.nSupplierId_fk as supplierId,
    TSIM.purchasePrice as pPrice,
    TSIM.nhsnId_fk as hsnId,
    TSIM.sellingPrice as sPrice,
    TSIM.MRP as mrp,
    TDSD.batchNo as batchNo,
    TDSD.serialNumber as serialNo,
    date(TDSD.expiryDate) as expiryDate,
    date(TDSD.stockDate) as stockDate,
    -- TDSD.openingStock as openingStock,
    (select SUM(openingStock)  from tbl_dailystock_details TDSD1
		where date(TDSD1.stockDate) = thisDate 
        and TDSD1.nItemRateId = TDSD.nItemRateId
        and IF(branchId = -1, TRUE ,TDSD1.nBranchId = branchId)) as openingStock,
    -- TDSD.closingStock as closingStock,
    (select SUM(closingStock) from tbl_dailystock_details TDSD2
		where date(TDSD2.stockDate) = toDate
        and TDSD2.nItemRateId = TDSD.nItemRateId        
        and IF(branchId = -1, TRUE ,TDSD2.nBranchId = branchId)) as closingStock,
    TDSD.nStoreId as storeId,
    TMHC.hsnCode as hsnCode,
    TMHC.gstPercentage as gstPerc, 
    TMHC.sgstPercentage as sgstPerc,
    TMHC.cgstPercentage as cgstPerc,
    TMHC.igstPercentage as igstPerc,
    TMS.storeName as storeName,
     (select SUM(soldQty) from tbl_dailystock_details TDSD2
		where date(TDSD2.stockDate) = toDate
        and TDSD2.nItemRateId = TDSD.nItemRateId        
        and IF(branchId = -1, TRUE ,TDSD2.nBranchId = branchId)) as soldQty
 from tbl_dailystock_details TDSD
	 JOIN tbl_supplier_item_mapping TSIM on TSIM.supplier_item_mappingId = TDSD.nItemRateId
	 JOIN tbl_mst_items_details TMID on TMID.aItemId_pk = TSIM.nItemId_fk
     JOIN tbl_mst_storecreation TMS on TMS.aStoreId_pk = TDSD.nStoreId
     JOIN tbl_mst_hsn_codes TMHC on TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
WHERE (DATE(TDSD.stockDate) between thisDate and toDate) and
	IF(branchId = -1, TRUE ,TDSD.nBranchId = branchId)
    GROUP BY TDSD.nItemRateId -- itemId
ORDER BY stockDate, storeName, itemName;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getBatchBtItemId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getBatchBtItemId`(
in branchId int,
in storeId int,
in itemId int,
in potype int 
)
BEGIN

SELECT 
    batchNo
FROM
    tbl_grn_for_po_orders TGFPO
        JOIN
    tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
WHERE
    TGFPEIO.nItemId_fk = itemId
        AND TGFPEIO.nStoreId_fk = storeId
        AND TGFPEIO.nPoType_fk = potype
        AND IF(branchId = - 1,
        TRUE,
        TGFPO.ngrnBranchId_fk = branchId)
GROUP BY batchNo;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getBranchDeliveryAddress` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getBranchDeliveryAddress`(
in keyword varchar(25)
)
BEGIN
SELECT 
	abranchId AS branchId,
	branchHospName AS branchName,
    hospBranch_DeliveryAddress AS deliveryAddress
FROM tblhospitalbranches
	WHERE branchHospName LIKE (CONCAT('%',keyword,'%'))
	AND nhospitalActive = 1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getBranchDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getBranchDetails`()
BEGIN
SELECT 
    TBLB.abranchId AS abranchId,
    TBLB.branchHospName AS branchHospName,
    TBLB.nbranchcode AS nbranchcode,
    TBLB.bhospitalAddress AS bhospitalAddress,
    TBLB.bPincode AS bPincode,
    TBLB.bhospitalPhNo AS bhospitalPhNo,
    TBLB.bhospitalEmergencyNo AS bhospitalEmergencyNo,
    TBLB.bGSTINno AS bGSTINno,
    TBLB.hospBranch_DeliveryAddress AS hospBranch_DeliveryAddress,
    TBLB.hospBranch_BillingAddress AS hospBranch_BillingAddress,
    TBLB.nHospBranch_LocationId AS nHospBranch_LocationId,
    TBLL.locnName AS locnName,
    TBLL.locnShortCode AS locnShortCode,
    TBLB.po_raise_format AS po_raise_format,
    TBLB.grnShortCode AS grnShortCode,
    TBLB.hospetalFlag AS hospetalFlag,
    TBLB.fax AS faxNo
FROM
    tblhospitalbranches TBLB
        JOIN
    tbl_mst_locations TBLL ON TBLL.aLocationId_pk = TBLB.nHospBranch_LocationId
    Where TBLB.branchActive = 1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getBranchList` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getBranchList`(
in keyword text
)
BEGIN
SELECT 
    TB.abranchId AS branchId,
    TB.branchHospName AS branchName,
    TB.bhospitalAddress AS hospitalAddress,
    TB.nbranchcode AS branchCode,
    ifnull(TB.hospetalFlag,0) as hospetalFlag
FROM
    tblhospitalbranches TB
WHERE
     TB.branchHospName like concat(keyword,'%') 
     AND branchActive = 1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getCommercialStatusDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getCommercialStatusDetails`(
in in_commStsId int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN
SELECT
		TGFPO.aGrnId_pk,
          GROUP_CONCAT(TGFPOEIO.aGrnId_each_pk) AS eachGrnIds,
        GROUP_CONCAT(TGFPOEIO.nItemId_fk) AS itemsIds,
        TGFPO.grnNumber,
        DATE(TGFPO.grnDate) AS grnDate,
        TGFPO.grnRemarks,      
		TGFPO.statusRemarks as financeRemarks,
        TGFPO.commercialStatusUpdatedBy,
        DATE(TGFPO.commercialStatusUpdatedDate) AS financeDate,
        TMCS.nCommercialStatus AS financeStatus,
        TU.userId,
        TU.userName,
        -- ACCOUNTS
        accountsStatusId,
        accountsRemarks,
        accountsUserId,
        DATE(accountsDate) AS accountsDate,
        TMCS1.nCommercialStatus AS acctsStatus
        
        FROM tbl_grn_for_po_orders TGFPO
    LEFT JOIN tbl_mst_commercialstatus TMCS ON TMCS.aCommercialStatusId = TGFPO.nCommertialStatus
    LEFT JOIN tbl_mst_commercialstatus TMCS1 ON TMCS1.aCommercialStatusId = TGFPO.accountsStatusId
    LEFT JOIN tbl_grn_for_po_each_item_orders TGFPOEIO ON TGFPOEIO.nGrnId_fk = TGFPO.aGrnId_pk
    LEFT JOIN tbl_user TU ON TU.userId = TGFPO.commercialStatusUpdatedBy
    LEFT JOIN tbl_user TU1 ON TU1.userId = TGFPO.accountsUserId
    WHERE 
		CASE
			WHEN in_commStsId <= 3 THEN
				nCommertialStatus = in_commStsId
			WHEN in_commStsId >= 4 THEN
				TGFPO.accountsStatusId = in_commStsId
			ELSE
				''
		END
   order by aGrnId_pk
    LIMIT minlimitRow , maxlimitRow ;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getConsignmentItemsInventory` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getConsignmentItemsInventory`(
in branchId int,
in supplierId int,
in storeTypeId int,
in poTypeId int
)
BEGIN

SELECT 
	TMS.aSupplierId_pk AS supplierId,
	TMS.company_name AS supplierName,
    TMID.itemShortCode,
    TMID.itemName,
    IFNULL(SUM(TSIM.purchasePrice),0) AS itemPurchasePrice,
    IFNULL(SUM(TGA.availQty),0) AS itemAvailQty,
	(IFNULL(SUM(TSIM.purchasePrice),0) *
		IFNULL(SUM(TGA.availQty),0)) AS itemTotalPurchasePrice,
	GROUP_CONCAT(CONCAT('[',TGFPEIO.diapter,']','[',TGFPEIO.size,']','(',IFNULL((TGA.availQty),0),')')) AS diaWise,
    TGA.nBranchId
 FROM tbl_grn_availqty TGA
	JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
	JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGA.nSupplierMapId
    JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGA.nSupplierId
    JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGA.nItemId
WHERE TGA.nPotypeId = poTypeId AND TGA.availQty > 0 AND
IF(supplierId=-1,TRUE,TSIM.nSupplierId_fk = supplierId) AND TGA.nBranchId = branchId
GROUP BY TGA.nItemId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getConsmedConsignmentStocks` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getConsmedConsignmentStocks`(
in fromDate Date,
in toDate Date,
in branchIds varchar(50)
)
BEGIN

SELECT 
    TBLGOD.grnNumber,
    TOPMD.po_number,
    TMS.company_name AS supplierName,
    TTGPIO.batchNo,
    TTGPIO.serialNumber,
    TTGPIO.expiryDate,
    TBLB.branchHospName,
    DATE(TOSCED.lastModified) AS consumeDate
FROM
    tbl_ot_stock_consumption_each_details TOSCED
        JOIN
    tbl_grn_availqty TGA ON TOSCED.nGrnAvailId = TGA.aGrnAvailQtyId
        JOIN
    tbl_grn_for_po_each_item_orders TGPIO ON TGA.nEachGrnId = TGPIO.aGrnId_each_pk
        JOIN
    tbl_stocks_issued_to_emr TSIE ON TSIE.issedStock_Pk = TGPIO.nEachTransferId
        JOIN
    tbl_grn_for_po_each_item_orders TTGPIO ON TTGPIO.aGrnId_each_pk = TSIE.ngrnEachId_fk 
        JOIN
    tbl_grn_for_po_orders TBLGOD ON TBLGOD.aGrnId_pk = TTGPIO.nGrnId_fk
        JOIN
    tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TTGPIO.nSupplierId_fk
        JOIN
    tblhospitalbranches TBLB ON TBLB.abranchId = TOSCED.nBranchId
    join tbl_os_po_main_details TOPMD ON TOPMD.apoid=TBLGOD.nPoIdCentral_fk
    
    where DATE(TOSCED.lastModified) between fromDate and toDate and find_in_set(TTGPIO.ngrnBranchId_fk,branchIds)
;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getConsumedConsignmentStocks` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getConsumedConsignmentStocks`(
in fromDate Date,
in toDate Date,
in branchIds varchar(50)
)
BEGIN

SELECT 
    TBLGOD.grnNumber,
    TOPMD.po_number,
    TMS.company_name AS supplierName,
    TTGPIO.batchNo,
    TTGPIO.serialNumber,
    TTGPIO.expiryDate,
    TBLB.branchHospName AS consumedBranch,
    DATE(TGA.consumptionDate) AS consumeDate,
    TBLSIM.purchasePrice
FROM
    tbl_grn_availqty TGA
        JOIN
    tbl_grn_for_po_each_item_orders TGPIO ON TGA.nEachGrnId = TGPIO.aGrnId_each_pk
        JOIN
    tbl_stocks_issued_to_emr TSIE ON TSIE.issedStock_Pk = TGPIO.nEachTransferId
        JOIN
    tbl_grn_for_po_each_item_orders TTGPIO ON TTGPIO.aGrnId_each_pk = TSIE.ngrnEachId_fk
        JOIN
    tbl_grn_for_po_orders TBLGOD ON TBLGOD.aGrnId_pk = TTGPIO.nGrnId_fk
        JOIN
    tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TTGPIO.nSupplierId_fk
        JOIN
    tblhospitalbranches TBLB ON TBLB.abranchId = TGA.nBranchId
        JOIN
    tbl_os_po_main_details TOPMD ON TOPMD.apoid = TBLGOD.nPoIdCentral_fk
        JOIN
    tblhospitalbranches TBLDB ON TBLDB.abranchId = TTGPIO.ngrnBranchId_fk
       JOIN
	tbl_supplier_item_mapping TBLSIM ON TBLSIM.supplier_item_mappingId = TGPIO.nSupplierItemMapid
WHERE
    DATE(TGA.consumptionDate) BETWEEN fromDate AND toDate
        AND TGA.isReserved = 3
        AND TTGPIO.nGrnTypeId = 3
        AND IF(branchIds = '-1',
        TBLDB.hospetalFlag = 1,
        FIND_IN_SET(TTGPIO.ngrnBranchId_fk, branchIds))
;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getcreditEachDetailsArr` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getcreditEachDetailsArr`(
in in_nCreditNoteMainId int,
in in_creditStatus int
)
BEGIN
SELECT TCNE.aCreditNoteEachId as eachCreditId,
TCNE.nItemId as itemId,
TCNE.nStoreId as storeId,
TMID.itemName as itemName,
TCNE.acceptedQty as itemQty,
TCNE.totAmount as totalAmt,
TCNE.serialNumber as serialNumber,
TCNE.batchNumber as batchNo,
TCNE.expiryDate as expiryDate
FROM tbl_credit_note_each as TCNE
JOIN tbl_credit_note_main as TCNM on TCNM.acreditNoteId = TCNE.nCreditNoteMainId
JOIN tbl_mst_items_details as TMID on TMID.aItemId_pk= TCNE.nItemId
WHERE TCNE.nCreditNoteMainId=in_nCreditNoteMainId AND TCNE.creditStatus = in_creditStatus;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getCreditMainDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getCreditMainDetails`(
in in_creditStatus int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN
SELECT TCNM.creditNoteNumber as creditNumber,
TCNM.acreditNoteId as creditId,
TMS.company_name as supplierName,
TCNM.creditedAmount as totalCreditAmount
FROM tbl_credit_note_main AS TCNM
JOIN tbl_mst_supplier as TMS on TMS.aSupplierId_pk=TCNM.nsupplierId
where TCNM.nCreditedStatus = in_creditStatus
ORDER BY TCNM.acreditNoteId DESC
LIMIT minlimitRow , maxlimitRow ;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getDashBoardAvlQty` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getDashBoardAvlQty`(
	in branchId varchar(45),
	in storeTypeId varchar(45)
)
BEGIN
SELECT SUM(TGA.availQty) as availQty,TGFPEIO.nItemId_fk,TGFPEIO.diapter,TGFPEIO.size, TGFPEIO.strength as strength,TGFPEIO.volume as volume,TMID.itemName as itemName,TMID.aItemId_pk as itemId
FROM tbl_grn_availqty TGA
join tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
join tbl_mst_items_details TMID ON TMID.aItemId_pk=TGA.nItemId
WHERE  TGFPEIO.nStoreId_fk=storeTypeId and TGA.nBranchId=branchId
group by TGFPEIO.nItemId_fk  ,if(storeTypeId=1,TGFPEIO.diapter,TGFPEIO.strength), if(storeTypeId=1,TGFPEIO.size,TGFPEIO.volume) ;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getDataForPRFOnPoId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getDataForPRFOnPoId`(
	in poId int,
    in branchId int,
    in mainGrnId int
)
BEGIN
SELECT  *, SUM(TMP.poAmtWoTaxTmp)  AS poAmtWoTax
	, SUM(TMP.taxAmtTmp)  AS taxAmt
    , SUM(TMP.PoAmtWithTaxTmp)  AS PoAmtWithTax
    , (grnAmtTmp) AS grnAmt
 FROM
(SELECT 	
			TOPMD.apoid,
            TGFPOEIO.nGrnId_fk,
            TGFPOEIO.aGrnId_each_pk,
            TGFPOEIO.nSupplierId_fk,
            TGFPOEIO.nItemId_fk,
            
            TGFPO.invoiceNumber,
            DATE(TGFPO.invoiceDate) AS invoiceDate,
            TGFPO.invoiceAmount,
			DATE(ADDDATE(TGFPO.grnDate, INTERVAL TMS.credit_period day)) AS dueDate,
			TMS.credit_period,
            TOPMD.po_number,
           
           (TGFPOEIO.receivedQty) AS receivedQty,
			-- (TSIM.purchasePrice) * (TGFPOEIO.receivedQty) AS poAmtWoTax,
            (TSIM.purchasePrice) * (TGFPOEIO.receivedQty) AS poAmtWoTaxTmp,
            ((((IFNULL(TSIM.purchasePrice,0))*(IFNULL(TMHC.gstPercentage,0))) / 100)) * (TGFPOEIO.receivedQty) as taxAmtTmp,
            (IFNULL(TSIM.purchasePrice,0) + IFNULL((((IFNULL(TSIM.purchasePrice,0))*(IFNULL(TMHC.gstPercentage,0))) / 100),0)) * (TGFPOEIO.receivedQty) AS PoAmtWithTaxTmp,
            DATE(TOPMD.po_date) AS po_date,
            DATE(TGFPO.grnDate) AS grnDate,
            TGFPO.grnNumber,
            (IFNULL(TGFPO.invoiceAmount,0) + IFNULL(TGFPO.frightCharges,0) + IFNULL(TGFPO.invoiceTaxAmt,0)) AS grnAmtTmp,
            TGFPO.grnRemarks,
            TUP.userfullname,
            TUP.designation,
            TMS.aSupplierId_pk,
            TMS.company_name,
            TMS.com_address,
            TMS.chequeFavourName
            
            
           /* TOPEID.item_id_fk,
            TOPMD.po_to_supplier_id_fk,
           
			-- TMID.itemName,
			TMS.company_name,
            TMS.com_address,
            TSIM.purchasePrice,
            TMHC.gstPercentage,
            (((IFNULL(TSIM.purchasePrice,0))*(IFNULL(TMHC.gstPercentage,0))) / 100) AS taxAmt,
            IFNULL(TSIM.purchasePrice,0) + IFNULL((((IFNULL(TSIM.purchasePrice,0))*(IFNULL(TMHC.gstPercentage,0))) / 100),0) AS PoAmtWithTax
			*/
    FROM  
		tbl_os_po_each_item_details TOPEID
	JOIN tbl_os_po_main_details TOPMD ON TOPMD.apoid = TOPEID.npoid_fk
	JOIN tbl_mst_items_details TMID ON TOPEID.item_id_fk = TMID.aItemId_pk
    JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TMID.nHsnCodeId_fk
    JOIN tbl_grn_for_po_each_item_orders TGFPOEIO ON TGFPOEIO.nPoIdCentral_fk = TOPMD.apoid
    JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.aGrnId_pk = TGFPOEIO.nGrnId_fk
	JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPOEIO.nSupplierItemMapid
		AND TSIM.nItemId_fk =  TGFPOEIO.nItemId_fk AND TSIM.nBranchId = branchId
	JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
    /*JOIN tbl_supplier_item_mapping TSIM ON TSIM.nSupplierId_fk = TGFPOEIO.nSupplierId_fk
		AND TSIM.nItemId_fk =  TGFPOEIO.nItemId_fk AND TSIM.nBranchId = branchId
    JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TOPMD.po_to_supplier_id_fk*/
    JOIN tbl_user_profiledetails TUP ON TUP.userId = TGFPO.nUserId_fk
    WHERE TOPEID.npoid_fk = poId
    AND TGFPOEIO.nGrnId_fk = mainGrnId
   -- AND TOPMD = branchId
    AND TSIM.isActive = 1
    AND TSIM.isDeleted = 0
    GROUP BY TGFPOEIO.aGrnId_each_pk
    ORDER BY item_id_fk ASC) AS TMP;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_GetDcDetailsOnMainTransferId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_GetDcDetailsOnMainTransferId`(
	in mainTransferId int,
    in branchId int ,
    in minlimitRow int,
	in maxlimitRow int
)
BEGIN
SELECT 
			TSTMD.indentNumber,
            TSTMD.dcNumber,
            DATE(TSTMD.dcDate) AS dcDate,
            
            THB.abranchId,
            THB.nbranchcode,
            THB.branchHospName,
            THB.hospBranch_DeliveryAddress,
            
            TSITE.nItemId_fk,
            TSITE.issuedQty,
          --  ifnull(TOPEIDFB.item_order_qty,0) - ifnull(SUM(TSITE.issuedQty),0) AS balanceQty,
			UDF_getIssuedItemsBalanceQty(TOPEIDFB.apoeachid) as balanceQty,
            TSITE.batchNo,
            DATE(TSITE.expiryDate) AS expiryDate,
            if(TSITE.serialNo='undefined','',TSITE.serialNo) as serialNo,
            TSITE.nstockType_fk,
            
            TMID.itemShortCode,
            TMID.itemName,
            if(TSITE.nStoreId_fk = 1
            ,concat(TMID.itemName,IF(ISNULL(TOPEIDFB.item_diapter),'','['+TOPEIDFB.item_diapter+']'),IF(ISNULL(TOPEIDFB.item_size),'','['+TOPEIDFB.item_size+']'))
            ,concat(TMID.itemName,IF(ISNULL(TOPEIDFB.item_strength),'','['+TOPEIDFB.item_strength+']'),IF(ISNULL(TOPEIDFB.item_volume),'','['+TOPEIDFB.item_volume+']'))) AS itemFullName,
            TMID.nHsnCodeId_fk,
            
            TSIM.sellingPrice ,
            
            TMHC.cgstPercentage,
            TMHC.sgstPercentage,
            TMHC.igstPercentage,
            TMHC.gstPercentage,
            
            TOPEIDFB.item_order_qty,
            TOPEIDFB.item_diapter,
            TOPEIDFB.item_size,
            TOPEIDFB.item_strength,
            TOPEIDFB.item_volume,
            
            TMS.storeName,
            TMP.poTypeNAme,
            
            -- TUPD.userName as userfullname,
            -- TUPD.employeId
			'' AS userfullname,
            '' AS employeId
        FROM tbl_stock_transfer_maindetails TSTMD
        JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.nMainStockTrnsfrId = TSTMD.aMainStckTrnfrId
        JOIN tblhospitalbranches THB ON THB.abranchId = TSITE.nIssuedToBranchId_fk
        JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TSITE.nItemId_fk
        JOIN tbl_grn_for_po_each_item_orders TGFPOEIO ON TGFPOEIO.aGrnId_each_pk = TSITE.ngrnEachId_fk
        JOIN tbl_supplier_item_mapping TSIM ON /*TSIM.nItemId_fk = TSITE.nItemId_fk 
			AND TSIM.nSupplierId_fk = TGFPOEIO.nSupplierId_fk*/
            TSIM.supplier_item_mappingId = TGFPOEIO.nSupplierItemMapid  -- AND TSIM.nBranchId = branchId
        JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TMID.nHsnCodeId_fk
      -- ADDed By Akshay
      -- LEFT JOIN tbl_os_po_each_item_details_from_branch TOPEIDFB ON TOPEIDFB.apoeachid = TSITE.issuedToBrancheACHPoId
      -- Updated by Sharath
      LEFT JOIN tbl_os_po_each_item_details TOPEIDFB ON TOPEIDFB.apoeachid = TSITE.issuedToBrancheACHPoId
        JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TSITE.nStoreId_fk
        JOIN tbl_mst_potypes TMP ON TMP.aPoTypeId = TSITE.nstockType_fk
        JOIN tbl_user TUPD ON TUPD.userId = TSITE.nUserId_fk
        
        WHERE TSITE.nMainStockTrnsfrId = mainTransferId
        AND TSITE.nbranchid_fk = branchId
        AND TSITE.isActive = 1
        AND TSITE.isDeleted = 0
        LIMIT minlimitRow , maxlimitRow ;
    --   GROUP BY TSITE.nMainStockTrnsfrId, TSITE.nItemId_fk;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getDcItemsFromCentralForGrnInBranch` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getDcItemsFromCentralForGrnInBranch`(
in dcNo varchar(100)
)
BEGIN
SELECT 
		TSTMD.aMainStckTrnfrId AS centralMainTransferId, 
        TSITE.issedStock_Pk AS centralEachTransferId,        
		TSTMD.dcNumber,
        DATE(TSTMD.dcDate) AS dcDate,
        TSTMD.indentNumber,
        TSITE.batchNo,
        TSITE.nStoreId_fk,
        TSITE.nstockType_fk,        
        DATE(TSITE.expiryDate) AS expiry,
        TSITE.serialNo,
        TSITE.issuedQty,
        TSITE.issuedToBranchPoId AS branchMainPOId,
		TSITE.issuedToBrancheACHPoId AS branchEachPoId,
        TGFPO.aGrnId_pk AS centralGRNId,
        date(TGFPO.grnDate) AS centralGRNDate,
        TGFPO.grnNumber AS centralGrnNumber,
        TGFPEIO.aGrnId_each_pk AS centralEachGrnId,
        TGFPEIO.diapter,
        TGFPEIO.size,
        TGFPEIO.strength,
        TGFPEIO.volume,
        
        TMID.aItemId_pk as itemId,
    TMID.itemCode,
    TMID.itemShortCode,
	/*concat(IFNULL(TMID.itemName,''),
			' ',IFNULL('['+TMIMT.itemMakeTypeName+']','')
            ,' ',IFNULL('['+TMIT.itemtypeName+']',''),''
            ,if( TSITE.nStoreId_fk = 1, 
				concat('[',IFNULL(TGFPEIO.diapter,''),'] [',IFNULL(TGFPEIO.size,''),']')
            ,concat('[',IFNULL(TGFPEIO.strength,''),'] [',IFNULL(TGFPEIO.volume,''),']'))
            ) as itemName,*/
		IFNULL(TMID.itemName,'') AS itemName,
		TMP.poTypeNAme,
        TMS.storeName,
        ifnull((item_order_qty ),0) as orderedQty
		-- ifnull(SUM(TSITE.issuedQty),0) as issuedQty
		,(ifnull((TOPEIDFB.item_order_qty ),0) - ifnull(SUM(TSITE.issuedQty),0)) as balanceQty
        FROM 
	tbl_stock_transfer_maindetails TSTMD
		 JOIN tbl_stocks_issued_to_emr TSITE 		  ON TSITE.nMainStockTrnsfrId = TSTMD.aMainStckTrnfrId
		 JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TSITE.ngrnEachId_fk
		 JOIN tbl_grn_for_po_orders TGFPO 			  ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
		 JOIN tbl_mst_items_details TMID 			  ON TMID.aItemId_pk = TSITE.nItemId_fk
         JOIN tbl_mst_potypes TMP					  ON TMP.aPoTypeId = TSITE.nstockType_fk
         JOIN tbl_mst_storecreation TMS				  ON TMS.aStoreId_pk = TSITE.nStoreId_fk
  --  LEFT JOIN tbl_mst_items_make_type TMIMT 	      ON TMIMT.aItemsMakeTypeId_pk = TMID.nItemtypeMakeId_fk
  --  LEFT JOIN tbl_mst_items_type TMIT 			      ON TMIT.aItemtypeId_pk = TMID.nItemtypeId_fk
    LEFT JOIN tbl_os_po_each_item_details_from_branch TOPEIDFB ON TSITE.issuedToBrancheACHPoId = TOPEIDFB.apoeachid
    WHERE 	 TSTMD.dcNumber = dcNo
    GROUP BY TSITE.issedStock_Pk;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getDcNumbersByIndentNumber` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getDcNumbersByIndentNumber`(
IN indentNumber varchar(100)
)
BEGIN

SELECT 
    concat(tbl_stock_transfer_maindetails.dcNumber,' [',DATE(dcDate),']') AS dcNumber,
    DATE(tbl_stock_transfer_maindetails.dcDate) AS dcDate,
    tbl_stock_transfer_maindetails.dcNumber AS dcNo,
    tbl_stock_transfer_maindetails.aMainStckTrnfrId AS dcId,
    tbl_os_po_main_details.apoid AS indentId
FROM
    tbl_stock_transfer_maindetails
        JOIN
    tbl_os_po_main_details ON tbl_os_po_main_details.po_number = tbl_stock_transfer_maindetails.indentNumber
WHERE
    tbl_stock_transfer_maindetails.indentNumber = indentNumber
    AND tbl_os_po_main_details.typeOfRequest = 2
    AND tbl_stock_transfer_maindetails.stock_transfer_status <> 1;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getDebitNotesItemsDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getDebitNotesItemsDetails`(
in supplierId int,
in debitSts int,
in branchId int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN
SELECT 
		TBNM.aMainDNId AS debitNoteId,
        TBNM.dnNumber AS dnNumber,
        TBNM.noOfItems AS totalItems,
        TBNM.totQty AS totalQty,
        TBNM.totAmount AS totalAmt,
        DATE(TBNM.returnDate) AS returnDate,
        TBNM.nSupplierId AS supplierId,
        TMS.company_name AS supplierName
	FROM tbl_debit_note_main TBNM
		JOIN tbl_debit_note_each TBNE ON TBNE.nMainDnId = TBNM.aMainDNId AND TBNE.debitStatus = debitSts
		JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TBNM.nSupplierId
        WHERE IF(supplierId = -1,TRUE,TBNE.nsupplierId = supplierId) -- AND TBNM.nBranchId = 1
	GROUP BY TBNE.nMainDnId
    LIMIT minlimitRow , maxlimitRow;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getEachBranchPosForDashBoard` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getEachBranchPosForDashBoard`(
	in toBranchId varchar(45),
	in storeTypeId varchar(45),
	in itemId varchar(45),
	in diapter varchar(45),
	in size varchar(45),
    in strength varchar(45),
	in volume varchar(45)
)
BEGIN
	SELECT TOPEID.apoeachid as poEachId,TOPEID.item_name as itemName,TOPEID.item_diapter as diapter,TOPEID.item_size as size,sum(TOPEID.item_order_qty) as orderQty,THB.branchHospName as fromBranch
    ,TOPEID.item_strength as strength,TOPEID.item_volume as volume
	FROM tbl_os_po_each_item_details TOPEID
	join tbl_os_po_main_details TOPMD ON TOPMD.apoid=TOPEID.npoid_fk
    join tblhospitalbranches THB on TOPMD.po_from_branch_fk=THB.abranchId
	WHERE TOPEID.indentToBranchId = toBranchId AND TOPEID.item_id_fk=itemId 
    AND IF(diapter != 0 OR diapter != '', TOPEID.item_diapter= diapter, TRUE)
	AND IF(size != 0 OR size != '', TOPEID.item_size=size, TRUE)
	AND IF(strength != 0 OR strength != '', TOPEID.item_strength=strength,TRUE)
    AND IF(volume != 0 OR volume != '', TOPEID.item_volume=volume,TRUE)
    AND TOPEID.poItemStatusId=2 AND TOPMD.instore_fk=storeTypeId
    GROUP BY THB.branchHospName;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getEachDebitDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getEachDebitDetails`(
in mainDebitId int,
in debitStatus int,
in branchId int
)
BEGIN
 SELECT 
		TBNE.aEachDnId AS eachDebitId
        ,TBNE.nMainDnId AS mainDebitId
        ,TBNE.poNumber AS poNumber
        ,TBNE.grnNumber AS grnNumber
        ,TBNE.nItemId AS itemId
        ,TBNE.nsupplierId AS supplierId
        ,TBNE.batchNo AS batchNo
        ,TBNE.serilNo AS serialNo
        ,DATE(TBNE.expiryDate) AS expiryDate
        ,TBNE.itemDiapter AS diopter
        ,TBNE.itemSize AS size
        ,TBNE.itemStrength AS strength
        ,TBNE.itemVolume AS volume
        ,TBNE.nStoreId AS storeId
        ,TBNE.nPoTypeId AS poTypeId
        ,TBNE.unitPrice AS unitPrice
        ,TBNE.totTaxAmount AS totTaxAmt
        ,TBNE.totalAmount AS totalAmt
        ,TBNE.debitStatus AS debitStatus
		,TBNE.returnQty AS returnQty
        ,TMID.itemShortCode
        ,TMID.itemName
	FROM tbl_debit_note_each TBNE
      JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TBNE.nItemId
	WHERE TBNE.nMainDnId = mainDebitId AND TBNE.debitStatus = debitStatus; -- AND TBNE.nBranchId = 0;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getEachIolItemDetails_toEmr` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getEachIolItemDetails_toEmr`(
in branchId int,
in diaperSearch varchar(45),
in filterItems int
)
BEGIN
SELECT 
        TGFPEIO.aGrnId_each_pk AS grnEachId,
        TGA.aGrnAvailQtyId AS availId,
        TMID.aItemId_pk AS itemId,  
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName,
        IFNULL((TGA.availQty),0) AS availQty,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.batchNo AS batchNo,
        TGFPEIO.strength AS strength,
        TGFPEIO.volume AS volume,
        TGFPEIO.serialNumber AS serialNo,
        TGA.nSupplierMapId AS supplierMapId, 
        TGFPEIO.diapter,
       case TGFPEIO.nGrnTypeId
     when 1 then 'P' 
     when 2 then 'I'
     when 3 then 'C'
     when 4 then 'S'
      end as recevedType
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    WHERE TGA.availQty > 0
    AND DATE(TGFPEIO.expiryDate) >DATE(NOW())
    -- AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1
    AND TGA.nBranchId = branchId and TMID.nStoreId_fk=1 and TGA.isReserved=0 and if(diaperSearch='',true,TGFPEIO.diapter=diaperSearch) and if(filterItems='1',true,TGFPEIO.nGrnTypeId=3)
    GROUP BY  TGA.aGrnAvailQtyId 
    ORDER BY  TMID.aItemId_pk,DATE(TGFPEIO.expiryDate) ASC;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getEachItemDetailsWrtCode` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getEachItemDetailsWrtCode`(
in itemShortCode varchar(100),
in branchId int,
in in_storeId int,
in in_grnAvailableId varchar(250)
)
BEGIN

declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = in_storeId limit 1);


if(in_storeId = '1')
then

if(isMandatoryBatchAndExpiryflag = '1')
then


SELECT 
        TGFPEIO.aGrnId_each_pk AS grnEachId,
        TGA.aGrnAvailQtyId AS availId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName,
        IFNULL((TGA.availQty),0) AS availQty,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.batchNo AS batchNo,
        TGFPEIO.strength AS strength,
        TGFPEIO.volume AS volume,
        TGFPEIO.diapter,
        TGFPEIO.size,
        TGFPEIO.serialNumber AS serialNo,
        TGA.nSupplierMapId AS supplierMapId,
    serialNumber
    /*   ,
    
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
      /* ,
       IHSNCD.hsnCode,
         IHSNCD.gstPercentage,
          IHSNCD.sgstPercentage,
         IHSNCD.cgstPercentage,
         IHSNCD.igstPercentage,
         ISMID.purchasePrice AS  unitPrice ,
    TGFPEIO.nGrnId_fk as grnMainId,
    TGFPEIO.aGrnId_each_pk as eachGrnId,
    TGFPEIO.nPoIdCentral_fk as poMainId,
    TGFPEIO.nPoEachId as poEachId,
    TBLGMD.grnNumber ,
    TGFPEIO.nSupplierId_fk as supplierId */
    
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    /*  JOIN
    tbl_supplier_item_mapping ISMID ON ISMID.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
    JOIN
    tbl_mst_hsn_codes IHSNCD ON IHSNCD.aHsnAutoId_pk = ISMID.nhsnId_fk
    JOIN
    tbl_grn_for_po_orders TBLGMD ON TBLGMD.aGrnId_pk = TGFPEIO.nGrnId_fk */
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
    -- AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)

    GROUP BY  TGA.aGrnAvailQtyId ,TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) , TGFPEIO.serialNumber
    ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;
    
  else
  
  
SELECT 
        TGFPEIO.aGrnId_each_pk AS grnEachId,
        TGA.aGrnAvailQtyId AS availId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName,
        IFNULL((TGA.availQty),0) AS availQty,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.batchNo AS batchNo,
        TGFPEIO.strength AS strength,
        TGFPEIO.volume AS volume,
        TGFPEIO.diapter,
        TGFPEIO.size,
        TGFPEIO.serialNumber AS serialNo,
        TGA.nSupplierMapId AS supplierMapId,
   
    serialNumber
    /*   ,
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid,
       IHSNCD.hsnCode,
         IHSNCD.gstPercentage,
          IHSNCD.sgstPercentage,
         IHSNCD.cgstPercentage,
         IHSNCD.igstPercentage,
         ISMID.purchasePrice AS  unitPrice ,
    TGFPEIO.nGrnId_fk as grnMainId,
    TGFPEIO.aGrnId_each_pk as eachGrnId,
    TGFPEIO.nPoIdCentral_fk as poMainId,
    TGFPEIO.nPoEachId as poEachId,
    TBLGMD.grnNumber ,
    TGFPEIO.nSupplierId_fk as supplierId */
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
   /*     JOIN
    tbl_supplier_item_mapping ISMID ON ISMID.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
    JOIN
    tbl_mst_hsn_codes IHSNCD ON IHSNCD.aHsnAutoId_pk = ISMID.nhsnId_fk
    JOIN
    tbl_grn_for_po_orders TBLGMD ON TBLGMD.aGrnId_pk = TGFPEIO.nGrnId_fk */
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
    -- AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)

    GROUP BY  TGA.aGrnAvailQtyId , TGFPEIO.serialNumber
    ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;
end if;

else 


if(isMandatoryBatchAndExpiryflag = '1')

then 


SELECT 
        TGFPEIO.aGrnId_each_pk AS grnEachId,
        TGA.aGrnAvailQtyId AS availId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName,
        IFNULL((TGA.availQty),0) AS availQty,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.batchNo AS batchNo,
        TGFPEIO.strength AS strength,
        TGFPEIO.volume AS volume,
        TGFPEIO.diapter,
        TGFPEIO.size,
        TGFPEIO.serialNumber AS serialNo,
        TGA.nSupplierMapId AS supplierMapId,

    serialNumber
  /*     ,
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid,
       IHSNCD.hsnCode,
         IHSNCD.gstPercentage,
          IHSNCD.sgstPercentage,
         IHSNCD.cgstPercentage,
         IHSNCD.igstPercentage,
         ISMID.purchasePrice AS  unitPrice ,
    TGFPEIO.nGrnId_fk as grnMainId,
    TGFPEIO.aGrnId_each_pk as eachGrnId,
    TGFPEIO.nPoIdCentral_fk as poMainId,
    TGFPEIO.nPoEachId as poEachId,
    TBLGMD.grnNumber ,
    TGFPEIO.nSupplierId_fk as supplierId */
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    /*    JOIN
    tbl_supplier_item_mapping ISMID ON ISMID.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
    JOIN
    tbl_mst_hsn_codes IHSNCD ON IHSNCD.aHsnAutoId_pk = ISMID.nhsnId_fk
    JOIN
    tbl_grn_for_po_orders TBLGMD ON TBLGMD.aGrnId_pk = TGFPEIO.nGrnId_fk */
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
    -- AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)
 
    GROUP BY  TGA.aGrnAvailQtyId ,TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) 
    ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;
    
    
else


SELECT 
        TGFPEIO.aGrnId_each_pk AS grnEachId,
        TGA.aGrnAvailQtyId AS availId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName,
        IFNULL((TGA.availQty),0) AS availQty,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.batchNo AS batchNo,
        TGFPEIO.strength AS strength,
        TGFPEIO.volume AS volume,
        TGFPEIO.diapter,
        TGFPEIO.size,
        TGFPEIO.serialNumber AS serialNo,
        TGA.nSupplierMapId AS supplierMapId,
    serialNumber 
    
     /*  ,
    
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid,
       IHSNCD.hsnCode,
         IHSNCD.gstPercentage,
          IHSNCD.sgstPercentage,
         IHSNCD.cgstPercentage,
         IHSNCD.igstPercentage,
         ISMID.purchasePrice AS  unitPrice ,
    TGFPEIO.nGrnId_fk as grnMainId,
    TGFPEIO.aGrnId_each_pk as eachGrnId,
    TGFPEIO.nPoIdCentral_fk as poMainId,
    TGFPEIO.nPoEachId as poEachId,
    TBLGMD.grnNumber ,
    TGFPEIO.nSupplierId_fk as supplierId */
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
     /*   JOIN
    tbl_supplier_item_mapping ISMID ON ISMID.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
    JOIN
    tbl_mst_hsn_codes IHSNCD ON IHSNCD.aHsnAutoId_pk = ISMID.nhsnId_fk
    JOIN
    tbl_grn_for_po_orders TBLGMD ON TBLGMD.aGrnId_pk = TGFPEIO.nGrnId_fk */
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
    -- AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)
 
    GROUP BY  TGA.aGrnAvailQtyId 
    ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;    
end if;

end if;



END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getEachItemDetailsWrtCode_byStrenthAndValume` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getEachItemDetailsWrtCode_byStrenthAndValume`(
in itemShortCode varchar(100),
in branchId int,
in strenth int,
in valume int,
in in_storeId int,
in in_grnAvailableId varchar(250)
)
BEGIN



declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = in_storeId limit 1);





if(in_storeId = '1')
then

 
SELECT 
        TGFPEIO.aGrnId_each_pk AS grnEachId,
        TGA.aGrnAvailQtyId AS availId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName,
        IFNULL((TGA.availQty),0) AS availQty,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.batchNo AS batchNo,
        TGFPEIO.strength AS strength,
        TGFPEIO.volume AS volume,
        TGFPEIO.serialNumber AS serialNo,
        TGA.nSupplierMapId AS supplierMapId,
        TBLSC.storeFlag,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
        JOIN tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk = TMID.nStoreId_fk
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
    -- AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
             AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)

    AND TGA.nBranchId = branchId and TGFPEIO.strength=strenth and TGFPEIO.volume=valume
    GROUP BY  TGA.aGrnAvailQtyId,TMID.itemShortCode ,TGFPEIO.strength,TGFPEIO.volume, TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) , TGFPEIO.serialNumber
    ORDER BY DATE(TGFPEIO.expiryDate) ASC;
else 

SELECT 
        TGFPEIO.aGrnId_each_pk AS grnEachId,
        TGA.aGrnAvailQtyId AS availId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName,
        IFNULL((TGA.availQty),0) AS availQty,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.batchNo AS batchNo,
        TGFPEIO.strength AS strength,
        TGFPEIO.volume AS volume,
        TGFPEIO.serialNumber AS serialNo,
        TGA.nSupplierMapId AS supplierMapId,
        TBLSC.storeFlag,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
        JOIN tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk = TMID.nStoreId_fk
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
    -- AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
             AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)

    AND TGA.nBranchId = branchId and TGFPEIO.strength=strenth and TGFPEIO.volume=valume
    GROUP BY  TGA.aGrnAvailQtyId,TMID.itemShortCode ,TGFPEIO.strength,TGFPEIO.volume, TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) 
    ORDER BY DATE(TGFPEIO.expiryDate) ASC;
end if;



END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getExpDateByBatchNumber` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getExpDateByBatchNumber`(
in batchNum varchar(45)
)
BEGIN
SELECT  DATE(TGFPEIO.expiryDate) AS expDate
FROM tbl_grn_for_po_each_item_orders AS TGFPEIO
WHERE TGFPEIO.batchNo =batchNum 
GROUP BY TGFPEIO.expiryDate;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGoodsReturnDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getGoodsReturnDetails`(in startDate date,
in endDate date,
in branchId int,
in storeId int )
BEGIN
SELECT 
    TBLERD.returnQty,
    IFNULL(TBLERD.returnComments, '') AS returnComments,
    DATE(TBLRMD.nReturnedDate) AS returnDate,
    TBLHBD.branchHospName AS branchName,
    TBLMSD.company_name AS supplierName,
    TBLRUD.fullName AS returnUser,
    TBMID.itemName AS itemName,
    TBMID.itemShortCode AS itemCode
FROM
    tbl_grn_return_main_details TBLRMD
        JOIN
    tbl_grn_return_each_details TBLERD ON TBLERD.nReturnMainId = TBLRMD.aReturnMainId
        JOIN
    tblhospitalbranches TBLHBD ON TBLHBD.abranchId = TBLRMD.nBranchId
        JOIN
    tbl_user TBLRUD ON TBLRUD.userId = TBLRMD.nUserId_fk
    JOIN
    tbl_mst_items_details TBMID ON TBMID.aItemId_pk = TBLERD.itemId
    LEFT JOIN
    tbl_mst_supplier TBLMSD ON TBLMSD.aSupplierId_pk = TBLERD.supplierId
WHERE
    DATE(TBLRMD.nReturnedDate) BETWEEN startDate AND endDate
        AND IF(storeId = - 1,
        TRUE,
        TBLRMD.nStoreId = storeId)
        AND IF(branchId = - 1,
        TRUE,
        TBLRMD.nBranchId = branchId)
GROUP BY TBLRMD.aReturnMainId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getGrnDetails`(
in grnId int,
in branchId int,
in storeId int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN
SELECT
        
nPoIdCentral_fk, 
nPoType_fk,
nSupplierId_fk,
nStoreId_fk,
nGrnUserId_fk ,

dcNumber,
dcDate,
invoiceNumber,
invoiceAmount,
invoiceTaxAmt,
invoiceDate,
frightCharges,
invoicePhotoUploadName,
grnRemarks,
grnTotalItems,
grnTotalItemsQty,
sendToBranch,
issuedToBranch,

TOPMD.apoid AS centralPOId,
TOPMDFB.n_po_raised_barcnh_po_autopkid_fk AS branchPOId,

TOPMD.po_number AS branchPoNum,
TOPMDFB.po_number AS centralPoNum,

THBCentral.abranchId as centralBranchId,
THBCentral.branchHospName as centralBranchName,

THBBranch.abranchId as brchBranchId,
THBBranch.branchHospName as brchBranchName,            

TGFPO.aGrnId_pk AS grnId,
TGFPO.grnNumber AS grnNo,

TGFPO.centralGrnId AS centralGrnId,
TGFPO.centralGRNNum AS centralGrnNo

FROM tbl_grn_for_po_orders TGFPO
LEFT JOIN tbl_os_po_main_details TOPMD ON TOPMD.apoid = TGFPO.nPoIdCentral_fk
LEFT JOIN tbl_os_po_main_details_from_branch TOPMDFB ON TOPMDFB.apoid = TOPMD.n_poid_from_branch_fk
LEFT JOIN tblhospitalbranches THBCentral ON THBCentral.abranchId = TOPMD.po_from_branch_fk
LEFT JOIN tblhospitalbranches THBBranch ON THBBranch.abranchId = TOPMDFB.po_from_branch_fk
WHERE TGFPO.aGrnId_pk = grnId
AND TGFPO.isActive = 1
AND TGFPO.isDeleted = 0
AND TGFPO.ngrnBranchId_fk = branchId
 LIMIT minlimitRow , maxlimitRow ;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_GetGrnDetailsForList` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_GetGrnDetailsForList`(
in branchId int,
in requestType int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN
select 
	TOPMD.apoid
	, TOPMD.po_number
	, TOPMD.po_status
    , TOPMD.po_from_branch_fk
    , date(TOPMD.po_date) as po_date
    , TOPMD.po_raisedby_fk
    , TOPMD.po_to_supplier_id_fk
    , TOPMD.po_total_items
    , TOPMD.po_total_items_qty
    , TOPMD.instore_fk
    , TOPMD.po_type_fk
    , TC.branchHospName as branchName
    , TU.userName
    , TMS.code
    , TMS.company_name as supplierName
    , TMS.po_emailId as supplierEmailId 
    , TMS.mobile_no
    , TGFPO.grnNumber
    , TGFPO.aGrnId_pk
    , TGFPO.issuedToBranch
    , if(TGFPO.issuedToBranch = 0, 'No', 'Yes') as issuedToBranchStatus
	, TMP.poTypeNAme
    , TMCS.aCommercialStatusId as commercialStatusId
    , TMCS.nCommercialStatus as commercialStatus
    , TGFPO.statusRemarks as commercialRemrx,
    TMSC.storeName
 FROM tbl_os_po_main_details TOPMD
	JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.nPoIdCentral_fk = TOPMD.apoid
	JOIN tblhospitalbranches TC ON TC.abranchId = TGFPO.ngrnBranchId_fk
    JOIN tbl_user TU ON TU.userId = TGFPO.nGrnUserId_fk
    JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGFPO.nSupplierId_fk
    JOIN tbl_mst_potypes TMP ON TMP.aPoTypeId = TOPMD.po_type_fk
    JOIN tbl_mst_commercialstatus TMCS ON TMCS.aCommercialStatusId = TGFPO.nCommertialStatus
    join tbl_mst_storecreation TMSC ON TMSC.aStoreId_pk=TGFPO.nStoreId_fk
  --  WHERE !FIND_IN_SET(TOPMD.po_status,1)
    WHERE TGFPO.ngrnBranchId_fk = branchId
    AND TGFPO.nPoType_fk = requestType
    ORDER BY TGFPO.aGrnId_pk DESC
     LIMIT minlimitRow , maxlimitRow ;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnGoodsList` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getGrnGoodsList`(
in branchId int,
in storeId int,
in in_Filter int, -- 1=> ITEM ShortCODE  2=> Item Name  3=> GRN No
in in_FilterValue text,
IN stockType INT
)
BEGIN
select * from
(SELECT 	
TGFPEIO.aGrnId_each_pk as eachGrnId,
TGFPEIO.nGrnId_fk as mainGrnId,
	TMID.aItemId_pk as itemId,
    TMID.itemCode,
    TMID.itemShortCode,
    concat(IFNULL(TMID.itemName,''),if(storeId = 1, 
				concat(' [',IFNULL(TOPEID.item_diapter,''),'] [',IFNULL(TOPEID.item_size,''),']')
            ,concat('[',IFNULL(TOPEID.item_strength,''),'] [',IFNULL(TOPEID.item_volume,''),']'))
            ) as itemName,
	/*concat(IFNULL(TMID.itemName,''),
			' ',IFNULL('['+TMIMT.itemMakeTypeName+']','')
            ,' ',IFNULL('['+TMIT.itemtypeName+']',''),''
            ,if(storeId = 1, 
				concat('[',IFNULL(TOPEID.item_diapter,''),'] [',IFNULL(TOPEID.item_size,''),']')
            ,concat('[',IFNULL(TOPEID.item_strength,''),'] [',IFNULL(TOPEID.item_volume,''),']'))
            ) as itemName,	*/
	/*IFNULL(TMID.itemName,'') AS itemName,*/
    TMHC.aHsnAutoId_pk as HSNId,
    TMHC.hsnCode as HSNCode,
    TMHC.cgstPercentage,
    TMHC.sgstPercentage,
    TMHC.igstPercentage,
    TMHC.gstPercentage,   
            
    IFNULL(TOPEID.item_size,'NA') 	 as item_size,
    IFNULL(TOPEID.item_diapter,'NA') as item_diapter,
	IFNULL(TOPEID.item_strength,'NA') as item_strength,
	IFNULL(TOPEID.item_volume,'NA') as item_volume,
    
	(ifnull((TGFPEIO.receivedQty),0) - ifnull(sum(TSITE.issuedQty),0)) as availableQty,
    IFNULL((TGFPEIO.receivedQty),0) as grnQty,
	concat((ifnull((TGFPEIO.receivedQty),0) - ifnull(sum(TSITE.issuedQty),0)),'/',IFNULL((TGFPEIO.receivedQty),0)) AS receivedQty,	
    IFNULL(TGFPEIO.batchNo,'NA') as batchNo,
	IFNULL(DATE(TGFPEIO.expiryDate),'NA') as expiryDate,
	IFNULL(TGFPEIO.serialNumber,'NA') as serialNumber,
    TGFPEIO.nPoType_fk as nPoType_fk,
    
    IFNULL(TSIM.purchasePrice,'') AS purchasePrice,
    IFNULL(TSIM.sellingPrice,'') AS sellingPrice,
    
   concat(TMS.code,' : ',TMS.company_name) AS supplierDetails
	
	from tbl_mst_items_details TMID 
	LEFT JOIN tbl_os_po_each_item_details TOPEID ON TMID.aItemId_pk = TOPEID.item_id_fk
	LEFT JOIN tbl_os_po_main_details TOPMD ON TOPMD.apoid = TOPEID.npoid_fk
-- 	JOIN tbl_mst_items_details TMID2 ON TMID2.aItemId_pk = TOPEID.item_id_fk
-- 	LEFT JOIN tbl_mst_items_make_type TMIMT ON TMIMT.aItemsMakeTypeId_pk = TMID.nItemtypeMakeId_fk
-- 	LEFT JOIN tbl_mst_items_type TMIT ON TMIT.aItemtypeId_pk = TMID.nItemtypeId_fk
	LEFT JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.nPoEachId = TOPEID.apoeachid -- TGFPEIO.nPoIdCentral_fk = TOPEID.npoid_fk
     AND TGFPEIO.ngrnBranchId_fk = branchId
	LEFT JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.ngrnEachId_fk = TGFPEIO.aGrnId_each_pk
    LEFT JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TMID.nHsnCodeId_fk
    LEFT JOIN tbl_supplier_item_mapping TSIM ON TSIM.nItemId_fk = TGFPEIO.nItemId_fk
		AND TSIM.nSupplierId_fk = TGFPEIO.nSupplierId_fk  AND TSIM.nBranchId = branchId
	LEFT JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGFPEIO.nSupplierId_fk
	-- where TOPEID.npoid_fk = poId
	WHERE 
    TMID.nStoreId_fk = storeId
    AND nPoType_fk = stockType
	AND TMID.isActive = 1
	AND TMID.isDeleted = 0  
    AND if(in_Filter = '1',TMID.itemShortCode = in_FilterValue,
			(if(in_Filter = '2',TMID.itemName = in_FilterValue, 
                (if(in_Filter = '3',TGFPEIO.nGrnId_fk = in_FilterValue, 
				  if(in_Filter = '4',TGFPEIO.nGrnId_fk = UDF_getMainGrnIdFromGrnNumber(in_FilterValue,branchId),'1=1')
                  )
				 )
			   )
			 )
		  )
    GROUP BY TGFPEIO.aGrnId_each_pk -- TSITE.ngrnEachId_fk
       /* , TMID.aItemId_pk
		, TGFPEIO.batchNo, DATE(TGFPEIO.expiryDate), TGFPEIO.serialNumber
		, TOPEID.item_diapter
        , TOPEID.item_size
        , TOPEID.item_strength
        , TOPEID.item_volume*/ ) as tmp1
	WHERE tmp1.grnQty > 0
    ORDER BY TMP1.itemShortCode;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnGoodsList_AutoComplete` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getGrnGoodsList_AutoComplete`(
in branchId int,
in storeId int,
in in_Filter int, -- 1=> ITEM ShortCODE  2=> Item Name  3=> GRN No
in in_keyword text,
IN stockType INT
)
BEGIN
SELECT 
    TMID.aItemId_pk as itemId,
    TMID.itemName as itemName,
   -- TMID.itemShortCode as itemShortCode,
        if(in_Filter = 1,TMID.itemShortCode,
			(if(in_Filter = 2,TMID.itemName,'')  )           
            ) as itemShortCode,
    CONCAT(IFNULL(TMID.itemName, ''),
            ' [',
            IFNULL(TMIMT.itemMakeTypeName, ''),
            '] [',
            IFNULL(TMIT.itemtypeName, ''),
            ']') AS itemInfo 
FROM
    tbl_mst_items_details TMID
        LEFT JOIN
    tbl_mst_items_make_type TMIMT ON TMIMT.aItemsMakeTypeId_pk = TMID.nItemtypeMakeId_fk
        LEFT JOIN
    tbl_mst_items_type TMIT ON TMIT.aItemtypeId_pk = TMID.nItemtypeId_fk
WHERE
    TMID.nStoreId_fk = storeId AND TMID.isActive = 1 -- AND TMIMT.isActive = 1
       -- AND TMIT.isActive = 1
        AND if(in_Filter = 1,TMID.itemShortCode LIKE CONCAT(in_keyword, '%') ,
			(if(in_Filter = 2,TMID.itemName LIKE CONCAT(in_keyword, '%'),false))             
            )
        ORDER BY aItemId_pk DESC;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnItemsDetailsWithGrnId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getGrnItemsDetailsWithGrnId`(
in mainGrnId int,
in branchId int
)
BEGIN
SELECT 
		TGFPEIO.aGrnId_each_pk AS grnEachId
        ,TGFPEIO.nItemId_fk AS itemId
        ,TGFPEIO.receivedQty AS receivedQty
        ,TMID.itemName AS itemName
        ,TMC.nCommercialStatus AS commStatus
        ,TGFPEIO.financeRemarks AS financeRemarks
		,TGFPEIO.accountsRemarks AS accountRemark
        ,TGFPO.grnRemarks as grnRemak
        ,TGFPO.invoiceNumber as invoiceNumber
    FROM tbl_grn_for_po_each_item_orders TGFPEIO
		JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
        JOIN tbl_mst_commercialstatus TMC ON TMC.aCommercialStatusId = TGFPEIO.nCommercialStatusId
        JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
		WHERE nGrnId_fk = mainGrnId
        GROUP BY TGFPEIO.aGrnId_each_pk;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnReport` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getGrnReport`(
in fromDate date,
in toDate date,
in branchId int,
in supplierId int,
in storeId int 
)
BEGIN
SELECT 
	DATE(TGFPO.grnDate) AS grnDate,
    TMS.company_name AS supplierName,
    TGFPO.grnNumber as grnNumber,
    TGFPO.invoiceNumber as billNumber,
    TMID.itemShortCode as itemCode,
    TMID.itemName as itemName,
    TGFPEIO.receivedQty as qty,
    -- (IFNULL(TGFPEIO.receivedQty, 0)) * (IFNULL(TSIM.purchasePrice,0)) as grossAmount,
    TGFPEIO.taxableAmount as  grossAmount ,
    TMHC.cgstPercentage as cgstPerc,
-- 	(IFNULL(TGFPEIO.receivedQty, 0)) *  ((IFNULL(TMHC.cgstPercentage,0)/100) * (IFNULL(TSIM.purchasePrice,0))) as cgstAmount,
   TGFPEIO.taxAmount/2 as cgstAmount ,
   -- (IFNULL(TGFPEIO.receivedQty, 0)) * ((IFNULL(TMHC.sgstPercentage,0)/100) * (IFNULL(TSIM.purchasePrice,0))) as sgstAmount,
      TGFPEIO.taxAmount/2 as sgstAmount ,
TBLBD.brandName,
TBLMD.manufacturerName,
TSIM.purchasePrice as purchasePrice,
TSIM.MRP as mrp,
DATE(TGFPEIO.expiryDate) AS expiryDate,
TGFPEIO.disCountInRupees as  disCountInRupees ,
TGFPEIO.batchNo as batchNo,
DATE(TGFPO.invoiceDate) as invoiceDate
    FROM tbl_grn_for_po_orders TGFPO
 JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.nGrnId_fk = TGFPO.aGrnId_pk
 JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
 JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
 JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
 JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
 join tbl_mst_brands TBLBD ON TBLBD.aBrandTypeId_pk=TMID.nBrandTypeId_fk
 join tbl_mst_item_manufacturers TBLMD  on TBLMD.aManufacturerId_pk=TMID.nItemManufacturerId_fk
 WHERE DATE(TGFPO.grnDate) BETWEEN fromDate AND toDate
	AND IF(branchId = -1, TRUE, TGFPO.ngrnBranchId_fk = branchId)
    AND IF(supplierId = -1, TRUE, TSIM.nSupplierId_fk = supplierId)
	AND IF(storeId = -1, TRUE, TGFPEIO.nStoreId_fk = storeId)
 ORDER BY DATE(TGFPO.grnDate);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnSearch_OrderDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getGrnSearch_OrderDetails`(

in grnNo varchar(25),
in grnParam int,
in branchId int,
in requestType int
)
BEGIN


select 
	TOPMD.apoid
	, TOPMD.po_number
	, TOPMD.po_status
    , TOPMD.po_from_branch_fk
    , date(TOPMD.po_date) as po_date
    , TOPMD.po_raisedby_fk
    , TOPMD.po_to_supplier_id_fk
    , TOPMD.po_total_items
    , TOPMD.po_total_items_qty
    , TOPMD.instore_fk
    , TOPMD.po_type_fk
    , TC.branchHospName as branchName
    , TU.userName
    , TMS.code
    , TMS.company_name as supplierName
    , TMS.po_emailId as supplierEmailId 
    , TMS.mobile_no
    , TGFPO.grnNumber
    , TGFPO.aGrnId_pk
    , TGFPO.issuedToBranch
    , if(TGFPO.issuedToBranch = 0, 'No', 'Yes') as issuedToBranchStatus
	, TMP.poTypeNAme
    , TMCS.aCommercialStatusId as commercialStatusId
    , TMCS.nCommercialStatus as commercialStatus
    , TGFPO.statusRemarks as commercialRemrx
 FROM tbl_os_po_main_details TOPMD
	JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.nPoIdCentral_fk = TOPMD.apoid
	JOIN tblhospitalbranches TC ON TC.abranchId = TGFPO.ngrnBranchId_fk
    JOIN tbl_user TU ON TU.userId = TGFPO.nGrnUserId_fk
    JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGFPO.nSupplierId_fk
    JOIN tbl_mst_potypes TMP ON TMP.aPoTypeId = TOPMD.po_type_fk
    JOIN tbl_mst_commercialstatus TMCS ON TMCS.aCommercialStatusId = TGFPO.nCommertialStatus
  --  WHERE !FIND_IN_SET(TOPMD.po_status,1)
    WHERE CASE 
			WHEN grnParam = 3 THEN TGFPO.grnNumber = grnNo 
            WHEN grnParam = 4 THEN DATE(TGFPO.grnDate) = grnNo
            ELSE ''
		END
   AND TGFPO.ngrnBranchId_fk = branchId
    AND TGFPO.nPoType_fk = requestType
    
    ORDER BY TGFPO.aGrnId_pk DESC;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnTrackReport` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getGrnTrackReport`(
in fromDate date,
in toDate date,
in branchId int,
in supplierId int,
in storeId int 
)
BEGIN
SELECT 
	TGFPEIO.aGrnId_each_pk AS grnEachId,
	DATE(TGFPO.grnDate) AS grnDate,
    TMS.company_name AS supplierName,
    TGFPO.grnNumber as grnNumber,
    TGFPO.invoiceNumber as billNumber,
    TMID.itemShortCode as itemCode,
    TMID.itemName as itemName,
    -- TGFPEIO.receivedQty as qty,
    TGA.grnQty AS grnQty,
    TGA.transferedQty AS transferedQty,
    TGA.returnAcceptedQty AS returnFromBranchQty,
    TGA.availQty AS availableQty,
    TGA.returnToSupplier AS returnedToSupplierQty,
TGA.aGrnAvailQtyId AS grnAvailQtyId,
TBLBD.brandName,
TBLMD.manufacturerName
    FROM tbl_grn_for_po_orders TGFPO
 JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.nGrnId_fk = TGFPO.aGrnId_pk
 JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
 JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
 JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
 -- JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
 JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPEIO.aGrnId_each_pk
  join tbl_mst_brands TBLBD ON TBLBD.aBrandTypeId_pk=TMID.nBrandTypeId_fk
 join tbl_mst_item_manufacturers TBLMD  on TBLMD.aManufacturerId_pk=TMID.nItemManufacturerId_fk
 WHERE DATE(TGFPO.grnDate) BETWEEN fromDate AND toDate
	AND IF(branchId = -1, TRUE, TGFPO.ngrnBranchId_fk = branchId)
    AND IF(supplierId = -1, TRUE, TSIM.nSupplierId_fk = supplierId)
	AND IF(storeId = -1, TRUE, TGFPEIO.nStoreId_fk = storeId)
 ORDER BY DATE(TGFPO.grnDate);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getGrnWiseConsumptionDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getGrnWiseConsumptionDetails`(
in startDate date,
in endDate date,
in branchId int,
in storeId int 
)
BEGIN
/*
 * Items GRN during the selected duration
 */
 SELECT *, 
 (TMP.openingStock * TMP.purchasePrice) AS openStockValue,
 (TMP.closingStock * TMP.purchasePrice) AS closeStockValue,
 (TMP.stockPrice + TMP.availTaxAmount) AS stockPriceWithTax,
 (TMP.grnPrice + TMP.grnTaxAmount) AS grnPriceWithTax
 FROM(
	SELECT 
		group_concat(date(TGFPO.grnDate)) AS grnDate,
        TGFPEIO.nSupplierItemMapid,
        TMS.company_name AS supplierName,
        TMS.code AS supplierCode,
        TGFPEIO.nItemId_fk,
        TMID.itemShortCode,
        TMID.itemName,
		TGA.aGrnAvailQtyId,
        IFNULL(SUM(TGA.grnQty),0) AS grnQty,
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        (IFNULL(SUM(TGA.grnQty),0) -IFNULL(SUM(TGA.availQty),0)) AS consumedQty,
        if(( IFNULL(SUM(TGA.grnQty),0) - IFNULL(SUM(TGA.availQty),0)) > 0, 'YES', 'NO') AS isConsumed,
        IFNULL(TSIM.purchasePrice,0) AS purchasePrice,
         (IFNULL(TSIM.purchasePrice,0)) * IFNULL(SUM(TGA.grnQty),0) AS grnPrice,
        (IFNULL(TSIM.purchasePrice,0)) * IFNULL(SUM(TGA.availQty),0) AS stockPrice,
	(select IFNULL(SUM(openingStock),0)  from tbl_dailystock_details TDSD1
		where date(TDSD1.stockDate) = startDate
        and TDSD1.nItemRateId = TGFPEIO.nSupplierItemMapid
        and IF(branchId = -1, TRUE ,TDSD1.nBranchId = branchId)) as openingStock,
    (select IFNULL(SUM(closingStock),0) from tbl_dailystock_details TDSD2
		where date(TDSD2.stockDate) = endDate
        and TDSD2.nItemRateId = TGFPEIO.nSupplierItemMapid       
        and IF(branchId = -1, TRUE ,TDSD2.nBranchId = branchId)) as closingStock,
	TMHC.hsnCode,
    IFNULL(TMHC.gstPercentage,0) AS gstPercentage,
    IFNULL(TMHC.igstPercentage,0) AS igstPercentage,
    IFNULL(TMHC.cgstPercentage,0) AS cgstPercentage,
    IFNULL(TMHC.sgstPercentage,0) AS sgstPercentage,
	IFNULL(SUM(TGA.availQty),0) * TRUNCATE((IFNULL(TSIM.purchasePrice,0)/100.0) * IFNULL(TMHC.gstPercentage,0),2) AS availTaxAmount,
    IFNULL(SUM(TGA.grnQty),0) * TRUNCATE((IFNULL(TSIM.purchasePrice,0)/100.0) * IFNULL(TMHC.gstPercentage,0),2) AS grnTaxAmount,
    TBLSTC.storeName,
IFNULL(TSIM.purchasePrice,0)*(IFNULL(SUM(TGA.grnQty),0) -IFNULL(SUM(TGA.availQty),0)) as consumedPrice,
        TBLBD.brandName,
TBLMD.manufacturerName
    FROM 
		tbl_grn_for_po_orders TGFPO
	JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
    JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPEIO.aGrnId_each_pk
    JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
    JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
    JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
    JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
    join  tbl_mst_storecreation TBLSTC ON TBLSTC.aStoreId_pk=TGFPEIO.nStoreId_fk
	join tbl_mst_brands TBLBD ON TBLBD.aBrandTypeId_pk=TMID.nBrandTypeId_fk
 join tbl_mst_item_manufacturers TBLMD  on TBLMD.aManufacturerId_pk=TMID.nItemManufacturerId_fk
    WHERE DATE(TGFPO.grnDate) BETWEEN startDate AND endDate 
    	AND IF(storeId = -1, TRUE, TGFPEIO.nStoreId_fk = storeId) 
    AND IF(branchId = -1, TRUE ,TGFPO.ngrnBranchId_fk = branchId)
    GROUP BY TGFPEIO.nSupplierItemMapid) AS TMP
    ORDER BY DATE(TMP.grnDate);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getHospetalBranchList` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getHospetalBranchList`(
in operationTypeId int
)
BEGIN

SELECT 
    T1.abranchId as branchId,
    T1.branchHospName as branchName,
    T1.nHospBranch_LocationId as branchLocationId,
    T1.nbranchcode as branchCode,
    T1.grnShortCode as grnCode,
    T1.po_raise_format as poCode,
    T1.fax  as faxNo,
    T1.hospBranch_BillingAddress as billingAddr,
    T1.hospBranch_DeliveryAddress as deliveryAddr,
    T1.bGSTINno as gstinNo,
    T1.bhospitalEmergencyNo as emergencyNo,
    T1.bhospitalPhNo as contactNo,
    T1.bPincode as branchPinCode,
    T2.locnName,
    T1.bhospitalAddress as branchAddr,
    T1.hospetalFlag as operationType ,
    T1.branchHospName as reffbranchName
FROM 
    tblhospitalbranches T1
    LEFT JOIN
    tbl_mst_locations  T2 on T1.nHospBranch_LocationId=T2.aLocationId_pk
WHERE
    branchActive = 1 and if(operationTypeId is null,true,hospetalFlag=operationTypeId) order by T1.abranchId;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getHospitalBranchesList` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getHospitalBranchesList`()
BEGIN
 select abranchId, branchHospName, nbranchcode,hospetalFlag from tblhospitalbranches
 WHERE branchActive = 1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getHospitalConfigDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getHospitalConfigDetails`()
BEGIN
SELECT 
    configKey, configValue
FROM
    tblhospotalwiseconfigurations
WHERE
    isActive = 1;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getIndentItemsDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getIndentItemsDetails`(
in indentNumber text,
in branchId int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN
SELECT 	
		TOPMD.apoid,
				TOPMD.po_number,
				TOPEID.item_id_fk ,
				TMID.itemShortCode,
                TMID.itemName,
                IF(TMS.storeFlag = 1, TOPEID.item_diapter, TOPEID.item_strength) AS dioOrStr,
                IF(TMS.storeFlag = 1, TOPEID.item_size, TOPEID.item_volume) AS SizoRVol,
                TMID.nStoreId_fk,
                TMS.storeShortCode,
                TMS.storeName,
                po_to_supplier_id_fk as supplierId,
                IFNULL(TOPEID.item_order_qty,0) AS itemOrderQty,
              --  IFNULL(UDF_getPoItemsBalanceQtyWhileGrn(TOPMD.apoid, TOPEID.apoeachid),0) AS itemsPending,
                DATE(TOPMD.po_date) AS poDate,
                TUP.userName AS indentedUser,TMS.storeFlag,
                UDF_getIndentedItemsTransferPendingQty(branchId, TOPEID.apoeachid) AS itemsPending,
                TOPEID.apoeachid,
                TOPMD.po_type_fk as poTypeId
		FROM tbl_os_po_main_details TOPMD
			JOIN tbl_os_po_each_item_details TOPEID ON TOPEID.npoid_fk = TOPMD.apoid
            JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TOPEID.item_id_fk
            JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TMID.nStoreId_fk
            JOIN tbl_user TUP ON TUP.userId = TOPEID.nUserId_fk
		WHERE po_number = indentNumber
			AND TOPMD.po_from_branch_fk = branchId
			AND TOPEID.isActive = 1
            AND TOPEID.isDeleted = 0
            AND TOPMD.typeOfRequest = 2
            LIMIT minlimitRow , maxlimitRow ;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getIndentItemsInGrn` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getIndentItemsInGrn`(
in mainGrnId int,
in branchId int,
in poTypeId int
)
BEGIN
SELECT 
		TGFPO.aGrnId_pk AS mainGrnId,
        TOPMD.apoid AS mainPoId,
        TOPMD.po_number AS poNumber,
		TGFPO.grnNumber,
        DATE(TGFPO.grnDate) AS grnDate,
        DATE(TOPMD.po_date) AS poDate,
        TOPMD.nUserId_fk AS poUserId,
        TGFPO.nUserId_fk AS grnUserId,
        TUP1.userName AS indentByUser,
		TUP2.userName AS grnByUser,
        TGFPEIO.aGrnId_each_pk AS eachGrnId,
        TGFPEIO.nStoreId_fk AS storeId,
        TMS.storeName AS storeName,
        TGFPEIO.nItemId_fk AS itemId,
        TMID.itemName,
		IF(TMS.storeFlag = 1, TGFPEIO.diapter, TGFPEIO.strength) AS dioOrStr,
        IF(TMS.storeFlag = 1, TGFPEIO.size, TGFPEIO.volume) AS sizOrVol,
        TGFPEIO.batchNo,
        DATE(TGFPEIO.expiryDate) AS expiryDate,
        TGFPEIO.serialNumber,
        TGFPEIO.receivedQty
	FROM tbl_grn_for_po_orders TGFPO 
		JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
        JOIN tbl_os_po_main_details TOPMD ON TOPMD.apoid = TGFPEIO.nPoIdCentral_fk
        JOIN tbl_user TUP1 ON TUP1.userId = TOPMD.nUserId_fk
        JOIN tbl_user TUP2 ON TUP2.userId = TGFPO.nUserId_fk
        JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
        JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TGFPEIO.nStoreId_fk
    WHERE TGFPEIO.nGrnId_fk = mainGrnId
		AND TGFPEIO.ngrnBranchId_fk = branchId
      and find_in_set(TGFPEIO.nPoType_fk,concat(poTypeId,',','5'))
    GROUP BY TGFPEIO.aGrnId_each_pk;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getInventoryItemsGrnTypeWise` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getInventoryItemsGrnTypeWise`(
in branchId int
)
BEGIN
SELECT 
		GROUP_CONCAT(aGrnId_each_pk) AS grnIds,
        nGrnTypeId AS grnTypeId,
        nStoreId_fk AS storeId,
        TMS.storeName AS storeName,
        nItemId_fk AS itemId,
        COUNT(DISTINCT nItemId_fk) AS itemCnt,
        CASE nGrnTypeId
			WHEN '1' THEN 'GRN ITEMS'
            WHEN '2' THEN 'INDENTED ITEMS'
            WHEN '3' THEN 'CONSIGNMENT ITEMS'
            WHEN '4' THEN 'STOCK ACCEPTED ITEMS'
			ELSE 'NOT_A_CASE'
		END AS itemStockedType
    FROM tbl_grn_for_po_each_item_orders TGFPEIO
		JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TGFPEIO.nStoreId_fk
	WHERE  -- UDF_getAvailableQtyInGrn(aGrnId_each_pk) > 0 AND 
		 !ISNULL(nGrnTypeId) AND         
         TGFPEIO.ngrnBranchId_fk = branchId
	GROUP BY nGrnTypeId, nStoreId_fK-- , nItemId_fk
    ORDER BY grnTypeId, storeId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getIOLAvailabiltyForConsumption` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getIOLAvailabiltyForConsumption`(
in serialNo varchar(50),
in branchId int
)
BEGIN
SELECT
            TGFPOEIO.aGrnId_each_pk AS grnEachId,
            TGFPOEIO.batchNo AS batchNo,
            TMID.aItemId_pk AS itemId, 
            TMID.itemName AS itemName,
            TMID.itemShortCode AS itemShortCode,
            DATE(TGFPOEIO.expiryDate) AS expiryDate,
            TGFPOEIO.serialNumber AS serialNo,
            TGA.aGrnAvailQtyId AS grnQtyId,
            TGA.aGrnAvailQtyId AS availId,
            TGA.availQty AS availQty,
            TGFPOEIO.size AS size,
            TGFPOEIO.diapter AS diapter,
            TGA.nSupplierMapId AS supplierMapId,
            TGA.isReserved,
            ifnull(TGA.patName,'') as patName,
			TBLSC.storeFlag,
			TMID.nStoreId_fk AS storeId
        FROM tbl_grn_for_po_each_item_orders TGFPOEIO
            JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPOEIO.aGrnId_each_pk
            JOIN tbl_mst_items_details TMID  ON TGA.nItemId = TMID.aItemId_pk
             JOIN tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk = TMID.nStoreId_fk
        WHERE 
        DATE(TGFPOEIO.expiryDate) > DATE(NOW()) AND
        TGFPOEIO.serialNumber like concat('%',serialNo) AND TGA.nBranchId = branchId AND TGA.availQty > 0 ;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getIolStock_byBranch` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getIolStock_byBranch`(
in branchIs int
)
BEGIN

SELECT 
    TGFPOEIO.nItemId_fk,
    TMID.itemName,
    TGFPOEIO.batchNo,
    DATE(TGFPOEIO.expiryDate) AS expiryDate,
    TGFPOEIO.serialNumber,
    TGFPOEIO.diapter,
    TGFPOEIO.size
FROM
    tbl_grn_for_po_each_item_orders TGFPOEIO
        JOIN
    tbl_stocks_issued_to_emr TSITO ON TSITO.ngrnEachId_fk = TGFPOEIO.aGrnId_each_pk
        JOIN
    tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPOEIO.nItemId_fk
WHERE
    TSITO.nStoreId_fk = 1
        AND TSITO.iolStatus = 0
        AND TGFPOEIO.ngrnBranchId_fk = branchIs;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getIOLStock_Consumed_Itemsist` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getIOLStock_Consumed_Itemsist`(
in consumMainAid int
)
BEGIN
 

SELECT 
    TOCD.aOtStockConsumptionEachId,
    TOCD.itemName,
    TOCD.itemShortCode,
    DATE(TOCD.expiryDate) AS expiryDate,
    TOCD.serialNo,
    TOCD.nGrnAvailId AS grnEachId,
    batchNo,
    TOCD.diapter,
    TOCD.size, 
    TOCD.nItemId AS itemId,
    TGA.nSupplierMapId AS supplierMapId,
    usedQty  as availQty,
   TOCD.aOtStockConsumptionEachId
FROM
    tbl_ot_stock_consumption_each_details TOCD
        JOIN
    tbl_grn_availqty TGA ON TGA.nEachGrnId = TOCD.nGrnAvailId
    join tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk=TOCD.storeType
WHERE
    nMainConsumptionId = consumMainAid
        AND FIND_IN_SET(TBLSC.storeFlag, '1');

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemAailable_ByItemId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemAailable_ByItemId`(
in initemsId int,
in branchId int
)
BEGIN

SELECT  
        -- TGA.aGrnAvailQtyId AS GENAVAILID,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        TGFPEIO.strength,
        TGFPEIO.volume 
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    WHERE TGA.availQty > 0
    AND DATE(TGFPEIO.expiryDate) > DATE(NOW())
  --  AND TMID.nStoreId_fk = 2
    AND TMID.isActive = 1 
    AND TMID.aItemId_pk = initemsId
    AND TGA.nBranchId = branchId
    GROUP BY TGA.nItemId;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemConsumedListDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemConsumedListDetails`(
in branchId int,
in grnAvailQtyId int
)
BEGIN

SELECT 
    SUM(usedQty) AS usedQty, DATE(insertedDate) AS consumedDate
FROM
    tbl_ot_stock_consumption_each_details
WHERE
    nBranchId = branchId and nGrnAvailId= grnAvailQtyId
GROUP BY nGrnAvailId,date(insertedDate);  

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemDetailsByDcId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getItemDetailsByDcId`(
in dcId int,
in branchId int
)
BEGIN

SELECT 
	TSTM.aMainStckTrnfrId AS mainTransferId,
    TSITE.issedStock_Pk AS eachTransferId,
	TMID.aItemId_pk as itemId,
	TMID.itemShortCode AS itemCode,
	TMID.itemName AS itemName,
	IF(TMS.storeFlag=1,TGFPEIO.diapter,TGFPEIO.strength) as diaptOrStrength,
	IF(TMS.storeFlag=1,TGFPEIO.size,TGFPEIO.volume) as strOrVol,
    TSITE.issuedToBranchPoId AS branchMainPoId,
    TSITE.issuedToBrancheACHPoId AS branchEachPoId,
	TSITE.batchNo as batchNo,
	DATE(TSITE.expiryDate) AS expDate,
	TSITE.serialNo AS serialNo,
	TSITE.issuedQty AS issuedQty,
	-- TSITE.availQty AS availQty,
	TGFPEIO.nGrnTypeId AS grnTypeId,
    UDF_getIndentedItemsTransferPendingQty(branchId, TSITE.issuedToBrancheACHPoId) AS itemPendingQty,
    TOPEID.nSupplierItemMapid AS supplierMapId,
    TGFPEIO.unitPrice,
    TBLIHD.gstPercentage,
	TSITE.nstockType_fk as poTypeId
 FROM tbl_stocks_issued_to_emr AS TSITE
JOIN tbl_stock_transfer_maindetails AS TSTM ON TSTM.aMainStckTrnfrId = TSITE.nMainStockTrnsfrId and TSITE.nMainStockTrnsfrId=dcId
JOIN tbl_grn_for_po_each_item_orders AS TGFPEIO ON TGFPEIO.aGrnId_each_pk =  TSITE.ngrnEachId_fk
JOIN tbl_os_po_each_item_details TOPEID ON TOPEID.apoeachid = TSITE.issuedToBrancheACHPoId
JOIN
tbl_os_po_main_details TBLPOMD ON TBLPOMD.apoid = TOPEID.npoid_fk
JOIN tbl_mst_items_details AS TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TGFPEIO.nStoreId_fk
JOIN
tbl_supplier_item_mapping TBLISMTD ON TBLISMTD.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
JOIN
tbl_mst_hsn_codes TBLIHD ON TBLIHD.aHsnAutoId_pk = TBLISMTD.nhsnId_fk
WHERE  TSITE.nIssuedToBranchId_fk = branchId
GROUP BY TSITE.issedStock_Pk ;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemDetailsWrtCode` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemDetailsWrtCode`(
in itemShortCode varchar(100),
in branchId int,
in in_storeId int,
in in_grnAvailableId varchar(250)
)
BEGIN

declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = in_storeId limit 1);


if(in_storeId = '1')
then
 
 if(isMandatoryBatchAndExpiryflag = '1')
 then
 
SELECT  
        -- TGA.aGrnAvailQtyId AS GENAVAILID,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        TBLSC.storeFlag,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber ,
    
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
    /*   
       IHSNCD.hsnCode,
         IHSNCD.gstPercentage,
          IHSNCD.sgstPercentage,
         IHSNCD.cgstPercentage,
         IHSNCD.igstPercentage,
         ISMID.purchasePrice AS  unitPrice ,
    TGFPEIO.nGrnId_fk as grnMainId,
    TGFPEIO.aGrnId_each_pk as eachGrnId,
    TGFPEIO.nPoIdCentral_fk as poMainId,
    TGFPEIO.nPoEachId as poEachId,
    TBLGMD.grnNumber ,
    TGFPEIO.nSupplierId_fk as supplierId */
    
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
     JOIN tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk = TMID.nStoreId_fk
     /*   JOIN
    tbl_supplier_item_mapping ISMID ON ISMID.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
    JOIN
    tbl_mst_hsn_codes IHSNCD ON IHSNCD.aHsnAutoId_pk = ISMID.nhsnId_fk
    JOIN
    tbl_grn_for_po_orders TBLGMD ON TBLGMD.aGrnId_pk = TGFPEIO.nGrnId_fk */
    
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
  --  AND TMID.nStoreId_fk = 2 
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)
    GROUP BY TGA.nItemId , TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) , TGFPEIO.serialNumber
        ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;
        
        
 else 
 
 
SELECT  
        -- TGA.aGrnAvailQtyId AS GENAVAILID,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        TBLSC.storeFlag,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber,
    
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
       
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
     JOIN tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk = TMID.nStoreId_fk
    
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
  --  AND TMID.nStoreId_fk = 2 
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)
    GROUP BY TGA.nItemId ,  TGFPEIO.serialNumber
        ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;
 
 end if;
 
 
else 

if(isMandatoryBatchAndExpiryflag = '1')
then


SELECT   
        -- TGA.aGrnAvailQtyId AS GENAVAILID,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        TBLSC.storeFlag,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber ,
    
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
       
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
     JOIN tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk = TMID.nStoreId_fk
   
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
  --  AND TMID.nStoreId_fk = 2 
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)
    GROUP BY TGA.nItemId , TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) 
        ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;
        
 else
 
SELECT   
        -- TGA.aGrnAvailQtyId AS GENAVAILID,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        TBLSC.storeFlag,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber ,
    
    TGFPEIO.strength,
    TGFPEIO.volume,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
       
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
     JOIN tbl_mst_storecreation TBLSC ON TBLSC.aStoreId_pk = TMID.nStoreId_fk
     
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
  --  AND TMID.nStoreId_fk = 2 
    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGA.isReserved=0
     AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)
    GROUP BY TGA.nItemId 
        ORDER BY DATE(TGFPEIO.expiryDate) ASC  ;
end if;

end if;


END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemDetailsWrtCode_Autosugest` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemDetailsWrtCode_Autosugest`(
in itemShortCode varchar(100),
in branchId int,
in in_storeId int
)
BEGIN


declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = in_storeId limit 1);



if(in_storeId = '1')
then


SELECT  
    group_concat(TGA.aGrnAvailQtyId) AS grnAvailableId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        TGFPEIO.strength,
        TGFPEIO.volume,
        TGFPEIO.diapter,
        TGFPEIO.size,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber  
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
  
    AND TMID.isActive = 1
    AND TMID.itemName like concat(itemShortCode,'%')
    AND TGA.nBranchId = branchId
    GROUP BY TGA.nItemId ,TGFPEIO.strength,TGFPEIO.volume, TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) , TGFPEIO.serialNumber limit 10;
    
else 


SELECT  
    group_concat(TGA.aGrnAvailQtyId) AS grnAvailableId,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
        TGFPEIO.strength,
        TGFPEIO.volume,
        TGFPEIO.diapter,
        TGFPEIO.size,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
   
    AND TMID.isActive = 1
    AND TMID.itemName like concat(itemShortCode,'%')
    AND TGA.nBranchId = branchId
    GROUP BY TGA.nItemId ,TGFPEIO.strength,TGFPEIO.volume, TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate)  limit 10;
end if;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemDetailsWrtCode_byStrenthAndValume` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemDetailsWrtCode_byStrenthAndValume`(
in itemShortCode varchar(100),
in branchId int,
in strenth int,
in valume int,
in in_storeId int,
in in_grnAvailableId varchar(250)

)
BEGIN

declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = in_storeId limit 1);




if(in_storeId = '1')
then


SELECT  
        -- TGA.aGrnAvailQtyId AS GENAVAILID,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
         AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)

    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGFPEIO.strength=strenth and TGFPEIO.volume=valume
    GROUP BY TGA.nItemId ,TGFPEIO.strength,TGFPEIO.volume, TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) , TGFPEIO.serialNumber;
else 


SELECT  
        -- TGA.aGrnAvailQtyId AS GENAVAILID,
        TMID.aItemId_pk AS itemId, 
        TMID.nStoreId_fk AS storeId,
        TMID.itemShortCode AS itemShortCode,
        TMID.itemName AS itemName, 
        IFNULL(SUM(TGA.availQty),0) AS availQty,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber
    FROM tbl_mst_items_details TMID 
     JOIN tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
     JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    WHERE TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
         AND  find_in_set(TGA.aGrnAvailQtyId,in_grnAvailableId)

    AND TMID.isActive = 1
    AND TMID.itemShortCode = itemShortCode
    AND TGA.nBranchId = branchId and TGFPEIO.strength=strenth and TGFPEIO.volume=valume
    GROUP BY TGA.nItemId ,TGFPEIO.strength,TGFPEIO.volume, TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) ;
end if;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemDetailsWrtItemName_Autosugest` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemDetailsWrtItemName_Autosugest`(
in itemShortCode varchar(100),
in branchId int,
in in_storeId int

)
BEGIN
declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = in_storeId limit 1);
if(in_storeId = '1')
then

if(isMandatoryBatchAndExpiryflag = '1')
then
SELECT 
    group_concat(TGA.aGrnAvailQtyId) AS grnAvailableId,
    TMID.aItemId_pk AS itemId,
    TMID.nStoreId_fk AS storeId,
    TMID.itemShortCode AS itemShortCode,
    TMID.itemName AS itemName,
    IFNULL(SUM(TGA.availQty), 0) AS availQty,
    TGFPEIO.strength,
    TGFPEIO.volume,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
       
    /*   
       IHSNCD.hsnCode,
         IHSNCD.gstPercentage,
          IHSNCD.sgstPercentage,
         IHSNCD.cgstPercentage,
         IHSNCD.igstPercentage,
         ISMID.purchasePrice AS  unitPrice ,
    TGFPEIO.nGrnId_fk as grnMainId,
    TGFPEIO.aGrnId_each_pk as eachGrnId,
    TGFPEIO.nPoIdCentral_fk as poMainId,
    TGFPEIO.nPoEachId as poEachId,
    TBLGMD.grnNumber ,
    TGFPEIO.nSupplierId_fk as supplierId */
FROM
    tbl_mst_items_details TMID
        JOIN
    tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
        JOIN
    tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
  /*   JOIN
    tbl_supplier_item_mapping ISMID ON ISMID.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
     JOIN
    tbl_mst_hsn_codes IHSNCD ON IHSNCD.aHsnAutoId_pk = ISMID.nhsnId_fk
    JOIN
    tbl_grn_for_po_orders TBLGMD ON TBLGMD.aGrnId_pk = TGFPEIO.nGrnId_fk */
WHERE
    TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
        AND TMID.isActive = 1
        AND TMID.itemName LIKE CONCAT(itemShortCode, '%')
        AND TGA.nBranchId = branchId
		
GROUP BY TGA.nItemId , TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate) , TGFPEIO.serialNumber limit 10;

else

SELECT 
    group_concat(TGA.aGrnAvailQtyId) AS grnAvailableId,
    TMID.aItemId_pk AS itemId,
    TMID.nStoreId_fk AS storeId,
    TMID.itemShortCode AS itemShortCode,
    TMID.itemName AS itemName,
    IFNULL(SUM(TGA.availQty), 0) AS availQty,
    TGFPEIO.strength,
    TGFPEIO.volume,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
       

FROM
    tbl_mst_items_details TMID
        JOIN
    tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
        JOIN
    tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    
WHERE
    TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
        AND TMID.isActive = 1
        AND TMID.itemName LIKE CONCAT(itemShortCode, '%')
        AND TGA.nBranchId = branchId
		
GROUP BY TGA.nItemId ,  TGFPEIO.serialNumber limit 10;
end if;

else 
 
 if(isMandatoryBatchAndExpiryflag = '1')
 then 
 SELECT 
    group_concat(TGA.aGrnAvailQtyId) AS grnAvailableId,
    TMID.aItemId_pk AS itemId,
    TMID.nStoreId_fk AS storeId,
    TMID.itemShortCode AS itemShortCode,
    TMID.itemName AS itemName,
    IFNULL(SUM(TGA.availQty), 0) AS availQty,
    TGFPEIO.strength,
    TGFPEIO.volume,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber ,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
       
FROM
    tbl_mst_items_details TMID
        JOIN
    tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
        JOIN
    tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
  
WHERE
    TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
        AND TMID.isActive = 1
        AND TMID.itemName LIKE CONCAT(itemShortCode, '%')
        AND TGA.nBranchId = branchId
		
GROUP BY TGA.nItemId , TGFPEIO.batchNo , DATE(TGFPEIO.expiryDate)  limit 10;

else

SELECT 
    group_concat(TGA.aGrnAvailQtyId) AS grnAvailableId,
    TMID.aItemId_pk AS itemId,
    TMID.nStoreId_fk AS storeId,
    TMID.itemShortCode AS itemShortCode,
    TMID.itemName AS itemName,
    IFNULL(SUM(TGA.availQty), 0) AS availQty,
    TGFPEIO.strength,
    TGFPEIO.volume,
    batchNo,
    DATE(expiryDate) AS expiryDate,
    serialNumber ,
     TGFPEIO.size ,
      TGFPEIO.diapter,
       TGFPEIO.nSupplierItemMapid AS  supplierMapid
       
FROM
    tbl_mst_items_details TMID
        JOIN
    tbl_grn_availqty TGA ON TGA.nItemId = TMID.aItemId_pk AND TGA.nStoreId = in_storeId
        JOIN
    tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
   
WHERE
    TGA.availQty > 0
        AND if(isMandatoryBatchAndExpiryflag = 1 ,DATE(TGFPEIO.expiryDate) > DATE(NOW()),true) 
        AND TMID.isActive = 1
        AND TMID.itemName LIKE CONCAT(itemShortCode, '%')
        AND TGA.nBranchId = branchId
		
GROUP BY TGA.nItemId limit 10;
 end if;

end if;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemIds` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemIds`(
-- out getItemIds text
)
BEGIN
-- set getItemIds =  (select group_concat(aItemId_pk) as itemsIds  from tbl_mst_items_details);
select group_concat(aItemId_pk) as itemsIds  from tbl_mst_items_details;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemReturnDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getItemReturnDetails`(
in eachGrnId int,
in branchId int
)
BEGIN
	SELECT 
		TGRMD.aReturnMainId AS mainReturnId,
		TGRMD.returnNumber AS returnNumber,
		DATE(TGRMD.authDate) AS returnDate,
		TGRED.returnQty as returnQty,
		THB.branchHospName as transferredToBranch,
		THB1.branchHospName as transferredFromBranch        
	FROM tbl_grn_for_po_each_item_orders TGFPEIO
		JOIN tbl_grn_return_each_details TGRED ON TGRED.nEachGrnId = TGFPEIO.aGrnId_each_pk
		JOIN tbl_grn_return_main_details TGRMD ON TGRMD.aReturnMainId = TGRED.nReturnMainId
		JOIN tblhospitalbranches THB ON THB.abranchId = TGRMD.nReturnToBranchId
		JOIN tblhospitalbranches THB1 ON THB1.abranchId = TGRMD.nBranchId
	WHERE TGRED.nEachGrnId = eachGrnId AND TGRMD.nBranchId = branchId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsAvailabilityDetailsForInventory` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getItemsAvailabilityDetailsForInventory`(
in branchId int,
in grnTypeId int
)
BEGIN
SELECT TGFPEIO.nItemId_fk,
				TMS.storeName,
				TMID.itemName,
                TGFPEIO.nGrnTypeId AS grnTypeId,
              --  UDF_getItemAvailableQtyByItemId(TGFPEIO.nItemId_fk, branchId, grnTypeId) AS availQty
                sum(TGA.availQty) AS availQty,
              --  TMS.company_name
              TMB.brandName,
              TMIM.manufacturerName
        FROM 
			tbl_grn_for_po_each_item_orders TGFPEIO
		JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
        JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TGFPEIO.nStoreId_fk
        JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPEIO.aGrnId_each_pk
        -- JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGFPEIO.nSupplierId_fk
        JOIN tbl_mst_brands TMB ON TMB.aBrandTypeId_pk = TMID.nBrandTypeId_fk
        JOIN tbl_mst_item_manufacturers TMIM  ON TMIM.aManufacturerId_pk = TMID.nItemManufacturerId_fk
        WHERE -- TGFPEIO.nItemId_fk = 3 AND
        IF(grnTypeId != -1, TGFPEIO.nGrnTypeId = grnTypeId,TRUE)
        AND TGA.availQty > 0 -- UDF_getItemAvailableQtyByItemId(TGFPEIO.nItemId_fk, branchId, grnTypeId) > 0 
		AND TGFPEIO.ngrnBranchId_fk = branchId AND  TGA.nBranchId = branchId
        GROUP BY TGA.nItemId;-- TGFPEIO.nItemId_fk;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsAvailableQtyQty` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsAvailableQtyQty`(
in grnEachId int
)
BEGIN
	-- select UDF_getAvailableQtyInGrn(grnEachId) as availQty;
    SELECT TGA.availQty AS availQty FROM tbl_grn_availqty TGA
		WHERE TGA.nEachGrnId = grnEachId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsAvailQtyDetailsByItemId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getItemsAvailQtyDetailsByItemId`(
in itemId int,
in branchId int,
in groupOnGrnTypeId int
)
BEGIN
SELECT	
		TMP.grnType,
        TMP.dioStr, 
		TMP.sizOrVol, 
        SUM(TMP.receivedQtys) AS grnQty, 
        -- SUM(TMP.issuedQtys)  AS isuedQty,
        -- IF((SUM(TMP.receivedQtys) - SUM(TMP.issuedQtys) < 0), 0, SUM(TMP.receivedQtys) - SUM(TMP.issuedQtys)) AS availQty
        SUM(TMP.availQty) AS availQty
	FROM 
		(SELECT 
			TGFPO.grnNumber AS grnNumber,
			TGFPEIO.nGrnTypeId AS grnType,
			IF(TMS.storeFlag = 1,TGFPEIO.diapter,TGFPEIO.strength) AS dioStr,
			IF(TMS.storeFlag = 1,TGFPEIO.size,TGFPEIO.volume) AS sizOrVol,
			IFNULL((TGFPEIO.receivedQty),0) AS receivedQtys,
            (TGA.availQty) AS availQty
			-- IFNULL(SUM(TSITE.issuedQty),0) AS issuedQtys
			-- IFNULL() AS availQtys
				FROM tbl_grn_for_po_each_item_orders TGFPEIO
			JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
            JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPEIO.aGrnId_each_pk
            JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TGFPEIO.nStoreId_fk

			-- LEFT JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.ngrnEachId_fk = TGFPEIO.aGrnId_each_pk
			-- 		AND TSITE.nIssuedFromBranchId_fk = branchId
				WHERE TGFPEIO.nItemId_fk = itemId
				AND TGFPEIO.ngrnBranchId_fk = branchId
                
			GROUP BY TGFPEIO.aGrnId_each_pk) AS TMP
    GROUP BY IF(groupOnGrnTypeId = 1,TMP.grnType,true),TMP.dioStr, TMP.sizOrVol;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsdetailsForStockTranferWoIndent` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsdetailsForStockTranferWoIndent`(
IN itemId int,
IN storeId int,
IN stockType int,
IN branchId int,
IN diaStr varchar(10),
IN sizVol varchar(10),
in minlimitRow int,
in maxlimitRow int
)
BEGIN

declare storeFlagmaster int;
set storeFlagmaster = (select storeFlag from tbl_mst_storecreation where `aStoreId_pk`=storeId);
SELECT * FROM (
SELECT
		TGFPO.grnNumber, 
		TGFPOEIO.nGrnId_fk AS mainGrnId,
        TGFPOEIO.aGrnId_each_pk AS eachGrnId,
        TGFPOEIO.batchNo,
        DATE(TGFPOEIO.expiryDate) AS expiryDate,
        TGFPOEIO.serialNumber,
        -- UDF_getAvailableQtyInGrn(TGFPOEIO.aGrnId_each_pk) AS availQty,
        TGA.availQty AS availQty,
        TGFPOEIO.nPoIdCentral_fk AS mainPoId,
        TGFPOEIO.nPoEachId AS eachPoId,
        TGFPOEIO.nSupplierItemMapid AS supplierMapId
	FROM tbl_grn_for_po_orders TGFPO
		JOIN tbl_grn_for_po_each_item_orders TGFPOEIO ON TGFPOEIO.nGrnId_fk = TGFPO.aGrnId_pk
		JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPOEIO.aGrnId_each_pk 
	WHERE 
		TGFPOEIO.nItemId_fk 	 = itemId
        AND TGFPOEIO.nStoreId_fk = storeId
        AND TGFPOEIO.nPoType_fk  = stockType
        AND TGFPOEIO.ngrnBranchId_fk = branchId
        AND 
			IF(storeFlagmaster = 1,
				TGFPOEIO.diapter = diaStr AND TGFPOEIO.size = sizVol,
                TGFPOEIO.strength = diaStr AND TGFPOEIO.volume = sizVol)
                AND TGA.availQty > 0 -- UDF_getAvailableQtyInGrn(TGFPOEIO.aGrnId_each_pk) > 0
		GROUP BY TGFPOEIO.aGrnId_each_pk
        ORDER BY DATE(TGFPOEIO.expiryDate) ASC
        ) AS TMP
        LIMIT minlimitRow , maxlimitRow ;
      --   WHERE TMP.availQty > 0;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsDetailsInBranchIndent` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsDetailsInBranchIndent`(
in poId int,
in storeId int
)
BEGIN
select 
	TOPEIDFB.apoeachid,
    TOPEIDFB.npoid_fk,
	concat(itemShortCode,' : ',TMID.itemName,
    if(storeId = 1,
    concat('[',IFNULL(item_diapter,''),'][',IFNULL(item_size,''),']'),
    concat('[',IFNULL(item_strength,''),'][',IFNULL(item_volume,''),']'))) as itemName,    
    apoeachid, npoid_fk, item_id_fk, item_diapter,
	item_size, item_strength, item_volume,
    ifnull((item_order_qty ),0) as orderedQty,
    ifnull(SUM(TSITE.issuedQty),0) as issuedQty
    ,(ifnull((TOPEIDFB.item_order_qty ),0) - ifnull(SUM(TSITE.issuedQty),0)) as balanceQty,
    TMID.itemName as itemNameSpecific,
    TOPEIDFB.nSupplierItemMapid,
    
     (
    SELECT TMS.aSupplierId_pk FROM 
		tbl_supplier_item_mapping TSIM 
	JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
    WHERE TSIM.nBranchId = TOPEIDFB.indentToBranchId AND TSIM.nItemId_fk = TOPEIDFB.item_id_fk AND TSIM.isAtPriority = 1 and TSIM.isActive=1
    ) as nSupplierId_fk,
    ( 
    SELECT TMS.nLocationId_fk FROM 
		tbl_supplier_item_mapping TSIM 
	JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
    WHERE TSIM.nBranchId = TOPEIDFB.indentToBranchId AND TSIM.nItemId_fk = TOPEIDFB.item_id_fk AND TSIM.isAtPriority = 1 and TSIM.isActive=1
    ) as nLocationId_fk,
    ifnull(TOPMD.po_number,'') as po_number,
      (
    SELECT TMS.company_name FROM 
		tbl_supplier_item_mapping TSIM 
	JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
    WHERE TSIM.nBranchId = TOPEIDFB.indentToBranchId AND TSIM.nItemId_fk = TOPEIDFB.item_id_fk AND TSIM.isAtPriority = 1 and TSIM.isActive=1
    ) as supplierName,
    TOPEIDFB.indentPoraiseStatus
	-- 0 as poRaisedQty
	-- from tbl_os_po_each_item_details_from_branch TOPEIDFB
    FROM tbl_os_po_each_item_details TOPEIDFB -- NEWLY ADDED
    JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TOPEIDFB.item_id_fk
    LEFT JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.issuedToBrancheACHPoId = TOPEIDFB.apoeachid
    LEFT JOIN (select indentEachid,npoid_fk as mainPoid from  tbl_os_po_each_item_details) ITOPID ON ITOPID.indentEachid=TOPEIDFB.apoeachid
   left join tbl_os_po_main_details TOPMD on TOPMD.apoid=ITOPID.mainPoid
    WHERE TOPEIDFB.npoid_fk = poId
    AND TOPEIDFB.isActive 	= 1
    AND TOPEIDFB.isDeleted  = 0
    AND TOPEIDFB.typeOfRequest = 2 -- NEWLY ADDED
     group by  TOPEIDFB.apoeachid;
  --  group by if(storeId = 1, concat(item_diapter, item_size), concat(item_strength, item_volume));
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsForAutoSuggestion` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getItemsForAutoSuggestion`(
in storeId int,
in itemName varchar(25)
)
BEGIN
SELECT 
		TMID.aItemId_pk AS itemId
		,TMID.itemShortCode
        ,TMID.itemName
		FROM tbl_mst_items_details TMID 
	WHERE 
		TMID.isActive = 1 
	AND TMID.isDeleted = 0
    AND TMID.nStoreId_fk = storeId
    AND TMID.itemName LIKE CONCAT(itemName,'%');
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsForIOL` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsForIOL`(
in branchId int,
in storeId int,
in rolType int
)
BEGIN
SELECT * FROM (
SELECT 
			TMID.aItemId_pk,
			TMID.itemShortCode,
            TMID.itemName,
            IFNULL(SUM(TGFPEIO.receivedQty),0) AS grnItemsQty,
            IFNULL(SUM(TSITE.issuedQty),0) AS issuedQty,
            IF(
				IFNULL(SUM(TGFPEIO.receivedQty),0) - IFNULL(SUM(TSITE.issuedQty),0) > 0 ,
                IFNULL(SUM(TGFPEIO.receivedQty),0) - IFNULL(SUM(TSITE.issuedQty),0) ,
                0
                )
            AS availQty,
            (IFNULL(SUM(TSITE.issuedQty),0)/30) * 10 AS ROL,
            IF(
				IFNULL(IFNULL(SUM(TGFPEIO.receivedQty),0) - IFNULL(SUM(TSITE.issuedQty),0),0) <= (ROUND(IFNULL(SUM(TSITE.issuedQty),0)/30) * 10),
                '1',
                '2'
            ) AS isReachedROL,
             IF(
				IFNULL(IFNULL(SUM(TGFPEIO.receivedQty),0) - IFNULL(SUM(TSITE.issuedQty),0),0) <= (ROUND(IFNULL(SUM(TSITE.issuedQty),0)/30) * 10),
                'Reached',
                'Not_Reached'
            ) AS isReachedROLText,
            IFNULL(IFNULL(SUM(TGFPEIO.receivedQty),0) - IFNULL(SUM(TSITE.issuedQty),0),0) - ROUND(IFNULL(SUM(TSITE.issuedQty),0)/30) * 10
             AS qtyToReachROL,
             IFNULL(SUM(TSITE.issuedQty),0) AS ROQ,
            TMS.storeName
            
		FROM tbl_mst_items_details TMID
	JOIN tbl_grn_for_po_each_item_orders TGFPEIO
		ON TGFPEIO.nItemId_fk = TMID.aItemId_pk
	JOIN tbl_mst_storecreation TMS 
		ON TMS.aStoreId_pk = TGFPEIO.nStoreId_fk
	JOIN tbl_stocks_issued_to_emr TSITE
		ON TSITE.nItemId_fk = TMID.aItemId_pk
	
	WHERE TGFPEIO.nStoreId_fk <> 1
			AND TGFPEIO.nStoreId_fk = storeId
			-- AND DATEDIFF(DATE(NOW()), DATE(TGFPEIO.insertedDate)) <= 30
             AND DATE(TSITE.insertedDate) <= 
             DATE(NOW()) 
             AND DATE(TSITE.insertedDate) >= DATE_SUB(DATE(NOW()), INTERVAL 30 DAY)
            AND TGFPEIO.ngrnBranchId_fk = branchId
	GROUP BY TGFPEIO.nItemId_fk) AS TMP
    WHERE TMP.isReachedROL = rolType
    ORDER BY TMP.isReachedROL;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsForReturn` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getItemsForReturn`(
in branchId int,
in storeId int,
in itemId int,
in batchNo varchar(25),
in poType int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN

declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = storeId limit 1);




SELECT 
		TGFPO.aGrnId_pk AS mainGrnId
        ,TGFPO.nSupplierId_fk AS supplierId
        ,TGFPEIO.aGrnId_each_pk AS eachGrnId
        ,TGFPEIO.nMainTransferId AS mainTransferId
        ,TGFPEIO.nEachTransferId AS eachTransferId
		,TGFPO.grnNumber
        ,TMS.company_name
        ,TGFPEIO.nSupplierItemMapid AS supplierItemMapId
        ,TGFPEIO.serialNumber
        ,DATE(TGFPEIO.expiryDate) AS expiryDate
        ,TGFPEIO.batchNo 
        ,IF(TMSC.storeFlag=1,TGFPEIO.diapter,TGFPEIO.strength) AS dioStr
        ,IF(TMSC.storeFlag=1,TGFPEIO.size,TGFPEIO.volume) AS sizVol
		-- ,UDF_getItemAvailableQtyByItemId(itemId, branchId, -1) AS availQty
        -- ,UDF_getAvailableQtyInGrn(TGFPEIO.aGrnId_each_pk) AS availQty
        ,TGA.availQty  AS availQty
        ,TGA.availQty  AS retQty
        ,THB1.abranchId AS grnBranchId
        ,THB1.branchHospName AS grnBranch
        ,THB2.abranchId AS receivedFromBranchId
        ,THB2.branchHospName AS receivedFromBranch
        ,THB2.nbranchcode AS receivedFromBranchCode
        --
        ,IFNULL(TSIM.purchasePrice,0) AS purchasePrice,
		TMID.nHsnCodeId_fk AS HSNId,
		TMHC.hsnCode,
        TMID.aItemId_pk AS itemId,
		IFNULL(TMHC.sgstPercentage,0) AS sgstPercentage,
		IFNULL(TMHC.cgstPercentage,0) AS cgstPercentage,
		IFNULL(TMHC.igstPercentage,0) AS igstPercentage,
		IFNULL(TMHC.gstPercentage,0)  AS gstPercentage,
		(IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0) AS taxAmt,
        (IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) AS itemPrice
       ,TMID.itemName as itemName
      
      FROM tbl_grn_for_po_orders TGFPO
		JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.nGrnId_fk = TGFPO.aGrnId_pk
        JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPEIO.aGrnId_each_pk
        
        -- JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGFPO.nSupplierId_fk
        LEFT JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.issedStock_Pk = TGFPEIO.nEachTransferId
        JOIN tblhospitalbranches THB1 ON THB1.abranchId = TGFPEIO.ngrnBranchId_fk
        LEFT JOIN tblhospitalbranches THB2 ON THB2.abranchId = TSITE.nIssuedFromBranchId_fk
        -- 
        JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk

		JOIN tbl_mst_storecreation TMSC ON TMSC.aStoreId_pk = TGFPEIO.nStoreId_fk

        -- JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO	.nSupplierItemMapid
		JOIN tbl_supplier_item_mapping TSIM ON 
         -- CONSIGNMENT STOCK ACCEPTANCE RETURN WITH SUPPLIER MAP ID = NULL
			/*IF(TGFPEIO.nPoType_fk = 0
				,TRUE
				,TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid)*/
		TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
		JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk -- TGFPO.nSupplierId_fk
        		JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
	WHERE TGFPEIO.nItemId_fk = itemId
			AND TGFPEIO.ngrnBranchId_fk = branchId

            AND if(isMandatoryBatchAndExpiryflag = 1,TGFPEIO.batchNo = batchNo,true) 
              AND TGFPEIO.nPoType_fk = poType 
              
              AND TGFPEIO.nStoreId_fk = storeId and  TGA.availQty > 0
          --  AND (TGFPEIO.nPoType_fk = poType OR TGFPEIO.nPoType_fk = 0) -- CONSIGNMENT STOCK ACCEPTANCE RETURN WITH PO TYPE ID = 0
          --  AND TSITE.nIssuedFromBranchId_fk = 0;
          GROUP BY TGFPEIO.aGrnId_each_pk
	ORDER BY receivedFromBranchId, eachGrnId DESC
   LIMIT minlimitRow , maxlimitRow ;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsForReturnByMonths` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsForReturnByMonths`(
in branchId int,
in storeId int,
in expiryDate date,
in minlimitRow int,
in maxlimitRow int
)
BEGIN

declare isMandatoryBatchAndExpiryflag int;

set  isMandatoryBatchAndExpiryflag = (select isMandatoryBatchAndExpiry from tbl_mst_storecreation  where isActive = 1 and aStoreId_pk = storeId limit 1);



SELECT 
		TGFPO.aGrnId_pk AS mainGrnId
        ,TGFPO.nSupplierId_fk AS supplierId
        ,TGFPEIO.aGrnId_each_pk AS eachGrnId
        ,TGFPEIO.nMainTransferId AS mainTransferId
        ,TGFPEIO.nEachTransferId AS eachTransferId
		,TGFPO.grnNumber
        ,TMS.company_name
        ,TGFPEIO.nSupplierItemMapid AS supplierItemMapId
        ,TGFPEIO.serialNumber
        ,DATE(TGFPEIO.expiryDate) AS expiryDate
        ,TGFPEIO.batchNo 
        ,IF(TMSC.storeFlag=1,TGFPEIO.diapter,TGFPEIO.strength) AS dioStr
        ,IF(TMSC.storeFlag=1,TGFPEIO.size,TGFPEIO.volume) AS sizVol
		-- ,UDF_getItemAvailableQtyByItemId(itemId, branchId, -1) AS availQty
        -- ,UDF_getAvailableQtyInGrn(TGFPEIO.aGrnId_each_pk) AS availQty
        ,TGA.availQty  AS availQty
        ,TGA.availQty  AS retQty
        ,THB1.abranchId AS grnBranchId
        ,THB1.branchHospName AS grnBranch
        ,THB2.abranchId AS receivedFromBranchId
        ,THB2.branchHospName AS receivedFromBranch
        ,THB2.nbranchcode AS receivedFromBranchCode
        --
        ,IFNULL(TSIM.purchasePrice,0) AS purchasePrice,
		TMID.nHsnCodeId_fk AS HSNId,
		TMHC.hsnCode,
        TMID.aItemId_pk AS itemId,
		IFNULL(TMHC.sgstPercentage,0) AS sgstPercentage,
		IFNULL(TMHC.cgstPercentage,0) AS cgstPercentage,
		IFNULL(TMHC.igstPercentage,0) AS igstPercentage,
		IFNULL(TMHC.gstPercentage,0)  AS gstPercentage,
		(IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0) AS taxAmt,
        (IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) AS itemPrice,
        TMID.itemName as itemName
        FROM tbl_grn_for_po_orders TGFPO
		JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.nGrnId_fk = TGFPO.aGrnId_pk
        JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPEIO.aGrnId_each_pk
        
        -- JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGFPO.nSupplierId_fk
        LEFT JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.issedStock_Pk = TGFPEIO.nEachTransferId
        JOIN tblhospitalbranches THB1 ON THB1.abranchId = TGFPEIO.ngrnBranchId_fk
        LEFT JOIN tblhospitalbranches THB2 ON THB2.abranchId = TSITE.nIssuedFromBranchId_fk
        -- 
        JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk

		JOIN tbl_mst_storecreation TMSC ON TMSC.aStoreId_pk = TGFPEIO.nStoreId_fk

        -- JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO	.nSupplierItemMapid
		JOIN tbl_supplier_item_mapping TSIM ON 
         -- CONSIGNMENT STOCK ACCEPTANCE RETURN WITH SUPPLIER MAP ID = NULL
			/*IF(TGFPEIO.nPoType_fk = 0
				,TRUE
				,TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid)*/
		TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
		JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk -- TGFPO.nSupplierId_fk
        		JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
	WHERE 
    if(isMandatoryBatchAndExpiryflag=1,DATE(TGFPEIO.expiryDate) < expiryDate and DATE(TGFPEIO.expiryDate) > DATE(NOW()),true)
     AND
			 TGFPEIO.ngrnBranchId_fk = branchId
                           AND TGFPEIO.nStoreId_fk = storeId and TGA.availQty > 0

          --  AND (TGFPEIO.nPoType_fk = poType OR TGFPEIO.nPoType_fk = 0) -- CONSIGNMENT STOCK ACCEPTANCE RETURN WITH PO TYPE ID = 0
          --  AND TSITE.nIssuedFromBranchId_fk = 0;
          GROUP BY TGFPEIO.aGrnId_each_pk
	ORDER BY receivedFromBranchId, eachGrnId DESC
   LIMIT minlimitRow , maxlimitRow ;
   
   
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsForReturningToSupplier` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsForReturningToSupplier`(
-- in supplierId int,
in returnStatusId int,
in storeId int,
in returnTypeId int,
in branchId int
)
BEGIN
SELECT 
		 GROUP_CONCAT(DISTINCT TGRED.nReturnMainId) AS returnMainId
        ,GROUP_CONCAT(DISTINCT TGRED.aReturnEachId) AS eachReturnId
		,GROUP_CONCAT(DISTINCT TGFPO.grnNumber) AS branchGrnNumber
        ,GROUP_CONCAT(DISTINCT TGFPO1.grnNumber) AS depoGrnNumber
        ,SUM(TGRED.returnQty) AS totalRetQty
        ,COUNT(DISTINCT TGRED.returnQty) AS totalItemsCnt
        ,TMS.aSupplierId_pk AS supplierId
        ,TMS.company_name AS supplierName
        ,GROUP_CONCAT(DISTINCT THB.branchHospName) AS branchHospName
        ,IFNULL(TMHC.sgstPercentage,0) AS sgstPercentage
		,IFNULL(TMHC.cgstPercentage,0) AS cgstPercentage
		,IFNULL(TMHC.igstPercentage,0) AS igstPercentage
		,IFNULL(TMHC.gstPercentage,0)  AS gstPercentage
		,(IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0) AS taxAmt
        ,(IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) AS itemPrice
        ,ROUND((IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) * (IFNULL(SUM(TGRED.returnQty),0)),2) AS totalPrice
        ,TMID.itemName
        ,TMID.aItemId_pk AS itemId
    FROM 
		tbl_grn_return_each_details TGRED 
	#Branch Details
    JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGRED.nEachGrnId
    JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
    #Intermediate for Depo & Branch
    JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.issedStock_Pk = TGFPEIO.nEachTransferId
    #Depo Details
    JOIN tbl_grn_for_po_each_item_orders TGFPEIO1 ON TGFPEIO1.aGrnId_each_pk = TSITE.ngrnEachId_fk
    JOIN tbl_grn_for_po_orders TGFPO1 ON TGFPO1.aGrnId_pk = TGFPEIO1.nGrnId_fk
    
    JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO1.nSupplierItemMapid
    JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
    JOIN tblhospitalbranches THB ON THB.abranchId = TGRED.nReturnFromBranchId
    #Item Amount Details
    JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
    JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk  = TMID.nHsnCodeId_fk
	
    WHERE -- TGFPEIO.nItemId_fk = 53
      TGRED.returnStatus  = returnStatusId
        AND TMID.nStoreId_fk    = storeId
        AND FIND_IN_SET(TGRED.nReturnType,returnTypeId)
        AND TGRED.nReturnToBranchId = branchId
  --  AND TMS.aSupplierId_pk = 0
  --  GROUP BY THB.abranchId, TGRED.nReturnMainId
	GROUP BY TMS.aSupplierId_pk
    ORDER BY TGRED.aReturnEachId DESC;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsForReturnToSupplier` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsForReturnToSupplier`(
in supplierId int,
in branchId int
)
BEGIN
SELECT 
				TOPMD.po_number
                ,TGFPO.grnNumber
				,TGA.aGrnAvailQtyId AS grnAvailId
				,GROUP_CONCAT(DISTINCT TGA.nMainGrnId) AS grnMainId
                ,GROUP_CONCAT(DISTINCT TGA.nEachGrnId) AS grnEachId
                ,TMS.company_name AS supplierName
                ,TMID.itemName
                ,TGFPEIO.serialNumber AS serialNumber
                ,TGFPEIO.batchNo AS batchNo
                ,DATE(TGFPEIO.expiryDate) AS expiryDate
				,SUM(IFNULL(returnToSupplier,0)) AS returnQty
                ,IFNULL(TMHC.sgstPercentage,0) AS sgstPercentage
		,IFNULL(TMHC.cgstPercentage,0) AS cgstPercentage
		,IFNULL(TMHC.igstPercentage,0) AS igstPercentage
		,IFNULL(TMHC.gstPercentage,0)  AS gstPercentage
		,(IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0) AS taxAmt
        ,(IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) AS itemPrice
        ,ROUND((IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) * (IFNULL(SUM(IFNULL(returnToSupplier,0)),0)),2) AS totalPrice
		,TGA.nEachGrnId AS eachGrnId
        ,TGA.nMainGrnId AS mainGrnId
        ,TGA.nPotypeId AS poTypeId
        ,TGA.nStoreId AS storeId
        ,TGFPEIO.diapter
        ,TGFPEIO.size
        ,TGFPEIO.strength
        ,TGFPEIO.volume
        ,TGA.nItemId AS itemId
        ,TGA.nSupplierId AS supplierId
        ,TGA.nSupplierMapId AS supplierMapId
			FROM tbl_grn_availqty TGA 
        JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGA.nSupplierMapId
        JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TGA.nSupplierId
         #Item Amount Details
		JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGA.nItemId
		JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk  = TMID.nHsnCodeId_fk
        #GRN Details
        JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
        JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
        #Po Details
        JOIN tbl_os_po_main_details TOPMD ON TOPMD.apoid = TGFPEIO.nPoIdCentral_fk
			WHERE TGA.nSupplierId = supplierId  
            AND TGA.returnToSupplier > 0
            AND TGA.nBranchId = branchId
		GROUP BY TGA.nItemId, TGA.aGrnAvailQtyId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsInGrnByMainGrnId` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsInGrnByMainGrnId`(
in mainGrnId int,
in grnBranchId int
)
BEGIN
SELECT 
		 TMID.aItemId_pk
         ,TMID.itemShortCode
         ,TMID.itemName
        ,TGA.grnQty
        ,TGA.transferedQty
        ,TGA.returnedQty
        ,TGA.availQty
        ,TGFPEIO.diapter
        ,TGFPEIO.size
        ,TGFPEIO.strength
        ,TGFPEIO.volume
        ,TGFPEIO.nStoreId_fk
        ,TGFPEIO.batchNo
        ,TGFPEIO.serialNumber
        ,DATE(TGFPEIO.expiryDate) AS expiryDate,
        TBLSTC.storeFlag
    FROM tbl_grn_availqty TGA
		JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
        JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
		join  tbl_mst_storecreation TBLSTC ON TBLSTC.aStoreId_pk=TGFPEIO.nStoreId_fk
	WHERE TGA.nMainGrnId = mainGrnId AND TGA.nBranchId = grnBranchId;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsListForAudit` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsListForAudit`(
in branchId int,
in storeId int,
in displayWrt int
)
BEGIN


SELECT 
	TGFPO.aGrnId_pk AS mainGrnId
	,TGFPEIO.aGrnId_each_pk AS eachGrnId
    ,TGFPO.grnNumber AS grnNumber
    ,TMID.aItemId_pk AS itemId
    ,TMID.itemShortCode AS itemShortCode
    ,TMID.itemName AS itemName
    ,IFNULL(TGA.grnQty,0) AS grnQty
    ,IFNULL(TGA.availQty,0) AS availableQty
    ,IFNULL(TSIM.purchasePrice,0) AS pPrice
    ,IFNULL(TMHC.hsnCode,0) AS hsnCode
    ,IFNULL(TMHC.gstPercentage,0) AS gstPerc
    ,FORMAT((IFNULL(TGA.availQty,0) * IFNULL(TSIM.purchasePrice,0)),2) AS itemPrice
 FROM tbl_grn_availqty TGA
	JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGA.nEachGrnId
    JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
    JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
    JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO.nSupplierItemMapid
    JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk = TSIM.nhsnId_fk
WHERE TGA.nBranchId = branchId AND TGA.nStoreId = storeId
GROUP BY IF(displayWrt = 1, TGFPEIO.aGrnId_each_pk, TGA.nItemId);
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsOverAllCountInventory` */;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sproc_getItemsOverAllCountInventory`(
in branchId int
)
BEGIN
SELECT nItemId_fk, 
		nStoreId_fk AS storeId, 
        TMS.storeName AS storeName,
		IFNULL(COUNT(DISTINCT nItemId_fk),0) AS itemsCnt,
		IFNULL(SUM(receivedQty),0) AS grnQty,
       --  IFNULL((UDF_getItemAvailableQtyByItemId(GROUP_CONCAT(DISTINCT nItemId_fk), branchId, -1)),0) AS availQty,
       SUM(TGA.availQty) AS availQty,
       GROUP_CONCAT(DISTINCT nItemId_fk) AS itemIds
        FROM
		tbl_grn_for_po_each_item_orders TGFEPIO
        JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFEPIO.aGrnId_each_pk 
        JOIN tbl_mst_storecreation TMS ON TMS.aStoreId_pk = TGFEPIO.nStoreId_fk
	WHERE ngrnBranchId_fk = branchId
		-- AND UDF_getItemAvailableQtyByItemId(GROUP_CONCAT(nItemId_fk ), branchId, -1) > 0
	GROUP BY  nStoreId_fk
    ORDER BY  nStoreId_fk;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsStockDetails` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsStockDetails`(
in itemId int,
in storeId int,
in diopterVal varchar(10),
in sizeVal varchar(10),
in strengthVal varchar(10),
in volumeVal varchar(10),
in branchId int,
in minlimitRow int,
in maxlimitRow int
)
BEGIN
SELECT TMP.* FROM 
(SELECT 
	ifnull(TGFPEIO.receivedQty,0) as grnQty,
   -- ifnull(SUM(TSITE.issuedQty),0) as issuedQtyToAllBranches,
	0  as issuedQtyToAllBranches,
    0 as issuedQtyToRequestBranch,
	/*if((ifnull(TGFPEIO.receivedQty,0) - ifnull(sum(TSITE.issuedQty),0)) > 0
		,(ifnull(TGFPEIO.receivedQty,0) - ifnull(sum(TSITE.issuedQty),0))
		, 0) as availableQty, */
	 TGA.availQty AS availableQty,
	TGFPO.grnNumber,
	TGFPEIO.*, TGA.isReserved ,
    ifnull(TBLPMD.po_number,'') as  po_number,
    TBLID.npoid_fk  as indentPoid,
    TBLID.poItemStatusId as indentStatusId
    from 
	tbl_grn_for_po_orders TGFPO
 JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.nGrnId_fk = TGFPO.aGrnId_pk
 JOIN tbl_grn_availqty TGA ON TGA.nEachGrnId = TGFPEIO.aGrnId_each_pk 
LEFT JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.ngrnEachId_fk = TGFPEIO.aGrnId_each_pk
left Join tbl_os_po_each_item_details TGFPED ON TGFPED.apoeachid=TGFPEIO.nPoEachId
left join tbl_os_po_each_item_details TBLID  on TBLID.apoeachid=TGFPED.indentEachid and TBLID.poItemStatusId <>13
left join tbl_os_po_main_details TBLPMD on TBLPMD.apoid=TBLID.npoid_fk
WHERE TGFPEIO.nItemId_fk = itemId 
	AND	IF(storeId = 1 , (TGFPEIO.diapter = diopterVal AND TGFPEIO.size = sizeVal)
        ,TGFPEIO.strength = strengthVal AND TGFPEIO.volume = volumeVal)
	AND TGFPEIO.ngrnBranchId_fk = branchId

GROUP BY TGFPEIO.nItemId_fk, TGFPEIO.aGrnId_each_pk) AS TMP
WHERE TMP.availableQty > 0
order by expiryDate 

 LIMIT minlimitRow , maxlimitRow ; 
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsToReturnSupplierReturnedFromBranch` */;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `sproc_getItemsToReturnSupplierReturnedFromBranch`(
in returnStatusId int,
in storeId int,
in returnTypeId int,
in branchId int,
in supplierId int,
in itemId int
)
BEGIN
SELECT 
		 GROUP_CONCAT(DISTINCT TGRED.nReturnMainId) AS returnMainId
        ,GROUP_CONCAT(DISTINCT TGRED.aReturnEachId) AS eachReturnId
		,GROUP_CONCAT(DISTINCT TGFPO.grnNumber) AS branchGrnNumber
        ,GROUP_CONCAT(DISTINCT TGFPO1.grnNumber) AS depoGrnNumber
        ,SUM(TGRED.returnQty) AS totalRetQty
        ,COUNT(DISTINCT TGRED.returnQty) AS totalItemsCnt
        ,TMS.company_name AS supplierName
        ,GROUP_CONCAT(DISTINCT THB.branchHospName) AS branchHospName
        ,IFNULL(TMHC.sgstPercentage,0) AS sgstPercentage
		,IFNULL(TMHC.cgstPercentage,0) AS cgstPercentage
		,IFNULL(TMHC.igstPercentage,0) AS igstPercentage
		,IFNULL(TMHC.gstPercentage,0)  AS gstPercentage
		,(IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0) AS taxAmt
        ,(IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) AS itemPrice
        ,ROUND((IFNULL(TSIM.purchasePrice,0) + (IFNULL(TMHC.gstPercentage,0)/100.0) * IFNULL(TSIM.purchasePrice,0)) * (IFNULL(SUM(TGRED.returnQty),0)),2) AS totalPrice
        ,TMID.itemName
        ,TGFPEIO1.serialNumber
        ,TGFPEIO1.batchNo
        ,DATE(TGFPEIO1.expiryDate) AS expiryDate
    FROM 
		tbl_grn_return_each_details TGRED 
	#Branch Details
    JOIN tbl_grn_for_po_each_item_orders TGFPEIO ON TGFPEIO.aGrnId_each_pk = TGRED.nEachGrnId
    JOIN tbl_grn_for_po_orders TGFPO ON TGFPO.aGrnId_pk = TGFPEIO.nGrnId_fk
    #Intermediate for Depo & Branch
    JOIN tbl_stocks_issued_to_emr TSITE ON TSITE.issedStock_Pk = TGFPEIO.nEachTransferId
    #Depo Details
    JOIN tbl_grn_for_po_each_item_orders TGFPEIO1 ON TGFPEIO1.aGrnId_each_pk = TSITE.ngrnEachId_fk
    JOIN tbl_grn_for_po_orders TGFPO1 ON TGFPO1.aGrnId_pk = TGFPEIO1.nGrnId_fk
    
    JOIN tbl_supplier_item_mapping TSIM ON TSIM.supplier_item_mappingId = TGFPEIO1.nSupplierItemMapid
    JOIN tbl_mst_supplier TMS ON TMS.aSupplierId_pk = TSIM.nSupplierId_fk
    JOIN tblhospitalbranches THB ON THB.abranchId = TGRED.nReturnFromBranchId
    #Item Amount Details
    JOIN tbl_mst_items_details TMID ON TMID.aItemId_pk = TGFPEIO.nItemId_fk
    JOIN tbl_mst_hsn_codes TMHC ON TMHC.aHsnAutoId_pk  = TMID.nHsnCodeId_fk
	
    WHERE  TGFPEIO.nItemId_fk = itemId
		AND TGRED.returnStatus  = returnStatusId
        AND TMID.nStoreId_fk    = storeId
        AND FIND_IN_SET(TGRED.nReturnType,returnTypeId)
        AND TGRED.nReturnToBranchId = branchId
    AND TMS.aSupplierId_pk = supplierId
    GROUP BY THB.abranchId, TGRED.nReturnMainId, TGFPEIO1.aGrnId_each_pk
    ORDER BY TGRED.aReturnEachId DESC;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `sproc_getItemsTransferredDetails` */;
