diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_DeleteLicense.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_DeleteLicense.sql new file mode 100644 index 0000000..8f83c7e --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_DeleteLicense.sql @@ -0,0 +1,74 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_DeleteLicense]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_DeleteLicense] +GO + +CREATE PROCEDURE [dbo].[usp_DeleteLicense] + @iLicenseId int +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + BEGIN TRY + BEGIN TRANSACTION + DECLARE @iLicenseTypeId TINYINT + DECLARE @cGetDetail CURSOR + DECLARE @iSiteId INT + DECLARE @iUserId INT + DECLARE @sErrorStatus CHAR(2) + + SET @sErrorStatus = 'ok' + SET @iLicenseTypeId = (SELECT LicenseTypeId FROM License WHERE Id = @iLicenseId) + + -- check if license is site license + IF @iLicenseTypeId = 3 + BEGIN + -- delete records from tables which store information about building level account + SET @cGetDetail = CURSOR FAST_FORWARD FOR SELECT SiteId FROM SiteToLicenseEdition WHERE LicenseEditionId IN (SELECT Id FROM LicenseToEdition WHERE LicenseId = @iLicenseId) + OPEN @cGetDetail + FETCH NEXT FROM @cGetDetail INTO @iSiteId + WHILE @@FETCH_STATUS = 0 + BEGIN + DELETE FROM AIAUserToSite WHERE SiteId = @iSiteId + DELETE FROM SiteToLicenseEdition WHERE SiteId = @iSiteId + DELETE FROM Site WHERE Id = @iSiteId + + FETCH NEXT FROM @cGetDetail INTO @iSiteId + END + CLOSE @cGetDetail + END + -- delete records from tables which store information about user + SET @cGetDetail = CURSOR FAST_FORWARD FOR SELECT Userid FROM AIAUserToLicenseEdition WHERE LicenseEditionId IN (SELECT Id FROM LicenseToEdition WHERE LicenseId = @iLicenseId) + OPEN @cGetDetail + FETCH NEXT FROM @cGetDetail INTO @iUserId + WHILE @@FETCH_STATUS = 0 + BEGIN + DELETE FROM AIAUserToLicenseEdition WHERE Userid = @iUserId + DELETE FROM LoginDetail WHERE UserId = @iUserId + DELETE FROM SessionManager WHERE UserId = @iUserId + DELETE FROM IncorrectLoginAttempts WHERE UserId = @iUserId + DELETE FROM UserGroupToAIAUser WHERE UserId = @iUserId + DELETE FROM AIAUser WHERE Id = @iUserId + + FETCH NEXT FROM @cGetDetail INTO @iUserId + END + CLOSE @cGetDetail + -- delete records from tables which store information about the license + DELETE FROM UserGroup WHERE LicenseId = @iLicenseId + DELETE FROM LicenseToEdition WHERE LicenseId = @iLicenseId + DELETE FROM SingleUserDetail WHERE LicenseId = @iLicenseId + DELETE FROM LicenseSubscriptionDetail WHERE LicenseId = @iLicenseId + DELETE FROM License WHERE Id = @iLicenseId + + COMMIT TRANSACTION + SELECT @sErrorStatus as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + SELECT Error_Message() as SPStatus + END CATCH + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetAccountTypeList.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetAccountTypeList.sql new file mode 100644 index 0000000..8624f3c --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetAccountTypeList.sql @@ -0,0 +1,25 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_EC_GetAccountTypeList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_EC_GetAccountTypeList] +GO + +CREATE PROCEDURE [dbo].[usp_EC_GetAccountTypeList] + -- Add the parameters for the stored procedure here +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here +select Id,Title +from AccountType where IsActive=1 + +END + + + + + + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetCountryList.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetCountryList.sql new file mode 100644 index 0000000..ce24028 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetCountryList.sql @@ -0,0 +1,23 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_EC_GetCountryList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_EC_GetCountryList] +GO + +CREATE PROCEDURE [dbo].[usp_EC_GetCountryList] + -- Add the parameters for the stored procedure here +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + +SELECT Id, CountryName +FROM Country +ORDER BY (case CountryCode when 'US' THEN 0 ELSE Id END) + +END + + + + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetSecurityQuestionList.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetSecurityQuestionList.sql new file mode 100644 index 0000000..2c1583c --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetSecurityQuestionList.sql @@ -0,0 +1,24 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_EC_GetSecurityQuestionList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_EC_GetSecurityQuestionList] +GO + +CREATE PROCEDURE [dbo].[usp_EC_GetSecurityQuestionList] + -- Add the parameters for the stored procedure here +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here +select Id,Title +from SecurityQuestion + +END + + + + + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetStateList.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetStateList.sql new file mode 100644 index 0000000..25697b7 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_EC_GetStateList.sql @@ -0,0 +1,23 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_EC_GetStateList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_EC_GetStateList] +GO + +CREATE PROCEDURE [dbo].[usp_EC_GetStateList] + -- Add the parameters for the stored procedure here +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here +select Id,StateName +from State + +END + + + + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetBlockedUserByAccNoAndType.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetBlockedUserByAccNoAndType.sql new file mode 100644 index 0000000..8a292ef --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetBlockedUserByAccNoAndType.sql @@ -0,0 +1,37 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetBlockedUserByAccNoAndType]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetBlockedUserByAccNoAndType] +GO + +CREATE PROCEDURE [dbo].[usp_GetBlockedUserByAccNoAndType] + -- Add the parameters for the stored procedure here + @iUserTypeId tinyint, @iLicenseId int +AS +BEGIN + -- returns the metadata + IF 1=0 BEGIN + SET FMTONLY OFF + END + SELECT DISTINCT + AIAUser.Id, + AIAUser.FirstName, + AIAUser.LastName, + AIAUser.LoginId, + AIAUser.Password, + AIAUser.EmailId, + ISNULL(License.AccountNumber,'') AccountNumber, + IncorrectLoginAttempts.LoginTime + FROM + IncorrectLoginAttempts + INNER JOIN AIAUser ON IncorrectLoginAttempts.UserId = AIAUser.Id + INNER JOIN UserType ON AIAUser.UserTypeId = UserType.Id + LEFT JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + LEFT JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + LEFT JOIN License ON LicenseToEdition.LicenseId = License.Id + WHERE + IncorrectLoginAttempts.CntIncorrectLogins >= 5 + AND UserType.Priority >= (SELECT UserType.Priority FROM UserType WHERE UserType.Id=@iUserTypeId) + AND ((@iLicenseId =0) OR (License.Id = @iLicenseId)) + AND License.IsActive = 1 +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetCancelledLicenses.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetCancelledLicenses.sql new file mode 100644 index 0000000..5bacdcc --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetCancelledLicenses.sql @@ -0,0 +1,163 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetCancelledLicenses]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetCancelledLicenses] +GO + +CREATE PROCEDURE [dbo].[usp_GetCancelledLicenses] + -- Add the parameters for the stored procedure here + @sFromDate varchar(20), @sToDate varchar(20), @iStartPrice numeric(14,2), @iEndPrice numeric(14,2), @iLicenseTypeId tinyint, + @iAccountTypeId tinyint , @sZip varchar(20) = '', @iStateId int, @iCountryId int,@pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + SET NOCOUNT ON; + DECLARE @dtFromDate DATETIME + DECLARE @dtToDate DATETIME + DECLARE @cGetLicenseID CURSOR + DECLARE @iLicenseId INT + DECLARE @iLicenseSubscriptionDetail INT + DECLARE @sAccountNumber VARCHAR(50) + DECLARE @sLicenseeName VARCHAR(100) + DECLARE @sLicenseType VARCHAR(50) + DECLARE @sInstitutionName VARCHAR(100) + DECLARE @dtStartDate DATETIME + DECLARE @dtEndDate DATETIME + DECLARE @dtLicenseCreationDate DATETIME + DECLARE @mSubscriptionPrice MONEY + DECLARE @sAccountType VARCHAR(50) + DECLARE @sEdition VARCHAR(200) + DECLARE @iCardNumber INT + + + -- convert the datatype of fromdate & todate parameter to datetime + SELECT @dtFromDate = CONVERT(DATETIME,@sFromDate) + SELECT @dtToDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sToDate))) + + -- create a temporary table to store the desired results of cancelled licenses on the basis of parameter + CREATE TABLE #CancelledLicenseReport + ( + AccountNumber VARCHAR(50), + LicenseeName VARCHAR(100), + LicenseType VARCHAR(50), + InstitutionName VARCHAR(100), + Edition VARCHAR(200), + ValidFrom DATETIME, + ValidThrough DATETIME, + LicenseCreationDate DATETIME, + Price MONEY, + AccountType VARCHAR(50), + CardNumber INT + ) + + -- define the forward only, read-only cursor + SET @cGetLicenseID = CURSOR FAST_FORWARD + FOR + SELECT LicenseSubscriptionDetail.LicenseId, MAX(LicenseSubscriptionDetail.Id) + FROM LicenseSubscriptionDetail + INNER JOIN License ON License.Id = LicenseSubscriptionDetail.LicenseId + WHERE (License.CancellationDate BETWEEN @dtFromDate AND @dtToDate) AND + (TotalAmount >= (CASE WHEN @iStartPrice > 0 THEN @iStartPrice ELSE 0 END)) + AND (TotalAmount <= (CASE WHEN @iEndPrice = 0 THEN 0 WHEN @iEndPrice > 0 THEN @iEndPrice ELSE 9999999999 END)) + GROUP BY LicenseSubscriptionDetail.LicenseId + --HAVING (MAX(SubscriptionValidThrough) BETWEEN @dtFromDate AND @dtToDate) + + -- open & fetch the cursor variables into the local variables + OPEN @cGetLicenseID + FETCH NEXT FROM @cGetLicenseID INTO @iLicenseId, @iLicenseSubscriptionDetail + -- start of while loop + WHILE @@FETCH_STATUS = 0 + BEGIN + + SET @sEdition = '' + -- fetch the accountnumber, licenseename, licensetype, startdate, enddate, subscriptionprice, accountype of a license + SELECT @sAccountNumber = AccountNumber, @sLicenseeName = LicenseeName, @sLicenseType = LicenseType, + @sInstitutionName = InstitutionName, + @dtStartDate = SubscriptionValidFrom, @dtEndDate = SubscriptionValidThrough, + @dtLicenseCreationDate = CreationDate, + @mSubscriptionPrice = TotalAmount, @sAccountType = AccountType, @iCardNumber = CardNumber + FROM + ( + SELECT AccountNumber, (LicenseeFirstName+' '+LicenseeLastName) as LicenseeName, + LicenseType.Title as LicenseType, License.InstitutionName, + AccountType.Title as AccountType, LicenseSubscriptionDetail.TotalAmount, + LicenseSubscriptionDetail.SubscriptionValidFrom, LicenseSubscriptionDetail.SubscriptionValidThrough, + License.CreationDate, + DATEDIFF(dd,GETDATE(),License.CancellationDate) as DaysRemaining, (CASE WHEN License.CardNumber > 0 THEN License.CardNumber END) as CardNumber + FROM License + INNER JOIN LicenseType ON License.LicenseTypeId = LicenseType.Id + INNER JOIN AccountType ON License.AccountTypeId = AccountType.Id + INNER JOIN State ON License.StateId = State.Id + INNER JOIN Country ON License.CountryId = Country.Id + INNER JOIN LicenseSubscriptionDetail ON License.Id = LicenseSubscriptionDetail.LicenseId + WHERE License.IsActive = 0 + AND License.LicenseTypeId = (CASE WHEN @iLicenseTypeId > 0 THEN @iLicenseTypeId ELSE License.LicenseTypeId END) + AND License.AccountTypeId = (CASE WHEN @iAccountTypeId > 0 THEN @iAccountTypeId ELSE License.AccountTypeId END) + AND State.Id = (CASE WHEN @iStateId > 0 THEN @iStateId ELSE State.Id END) + AND Country.Id = (CASE WHEN @iCountryId > 0 THEN @iCountryId ELSE Country.Id END) + AND License.Zip = (CASE WHEN LEN(@sZip)>0 THEN @sZip ELSE License.Zip END) + AND LicenseSubscriptionDetail.Id = @iLicenseSubscriptionDetail + AND License.LicenseTypeId <> 5 + ) t1 + + -- check whether the above query returns any row + IF @@Rowcount > 0 + BEGIN + -- fetch all the editions mapped as a string with a license + SELECT @sEdition = Edition.Title + '; ' + @sEdition + FROM LicenseToEdition INNER JOIN Edition + ON LicenseToEdition.EditionId = Edition.Id + WHERE LicenseToEdition.LicenseId = @iLicenseId + -- remove the trailing comma-separator from the edition-string + --AMI SET @sEdition = SUBSTRING(@sEdition,1,LEN(@sEdition)-1); + IF LEN(@sEdition)> 1 + -- remove the trailing comma-separator from the edition-string + SET @sEdition = SUBSTRING(@sEdition,1,LEN(@sEdition)-1) + ELSE + SET @sEdition = @sEdition + + -- insert into the temporary table + INSERT INTO #CancelledLicenseReport + (AccountNumber,LicenseeName,LicenseType,InstitutionName,Edition,ValidFrom,ValidThrough,LicenseCreationDate,Price,AccountType,CardNumber) + VALUES(@sAccountNumber,@sLicenseeName,@sLicenseType,@sInstitutionName,@sEdition,@dtStartDate,@dtEndDate,@dtLicenseCreationDate,@mSubscriptionPrice,@sAccountType,@iCardNumber) + END + -- fetch the next record from cursor + FETCH NEXT FROM @cGetLicenseID INTO @iLicenseId,@iLicenseSubscriptionDetail + -- end of while loop + END + -- close the cursor to free up resources + CLOSE @cGetLicenseID + DEALLOCATE @cGetLicenseID + + -- Selecting the desired result from temporary table + --SELECT AccountNumber, LicenseeName, LicenseType,InstitutionName,AccountType, Edition, CONVERT(VARCHAR,ValidFrom,101) as StartDate, + -- CONVERT(VARCHAR,ValidThrough,101) as EndDate,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice, CardNumber + --FROM #CancelledLicenseReport ORDER BY AccountNumber + + + SELECT RowNum, AccountNumber, LicenseeName, LicenseType,InstitutionName,AccountType, Edition, StartDate, + EndDate,LicenseCreationDate,SubscriptionPrice, CardNumber + from ( + SELECT ROW_NUMBER() OVER (ORDER BY AccountNumber) AS RowNum, AccountNumber, LicenseeName, LicenseType,InstitutionName,AccountType, Edition, CONVERT(VARCHAR,ValidFrom,101) as StartDate, + CONVERT(VARCHAR,ValidThrough,101) as EndDate,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice, CardNumber + FROM #CancelledLicenseReport) as Tempt + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo + ORDER BY AccountNumber + + --Calculate total number of records + select @recordCount = count(ResultTable.AccountNumber) + from ( + SELECT AccountNumber, LicenseeName, LicenseType,InstitutionName,AccountType, Edition, CONVERT(VARCHAR,ValidFrom,101) as StartDate, + CONVERT(VARCHAR,ValidThrough,101) as EndDate,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice, CardNumber + FROM #CancelledLicenseReport) as ResultTable + + + -- Dropping the temporary table + DROP TABLE #CancelledLicenseReport +END + + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetCustomerSummary.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetCustomerSummary.sql new file mode 100644 index 0000000..845816c --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetCustomerSummary.sql @@ -0,0 +1,188 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetCustomerSummary]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetCustomerSummary] +GO + +CREATE PROCEDURE [dbo].[usp_GetCustomerSummary] + -- Add the parameters for the stored procedure here + @sAccoutNumber varchar(50)='', @sLicenseeFullName varchar(100)='', @iStartPrice numeric(14,2), @iEndPrice numeric(14,2), + @iLicenseType tinyint, @iAccountType tinyint, @sZip varchar(20) = '', @iState int, + @iCountry int,@pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + SET NOCOUNT ON + DECLARE @cGetLicenseDetails CURSOR + DECLARE @iLicenseId INT + DECLARE @sAccountNumber VARCHAR(50) + DECLARE @sLicenseeName VARCHAR(100) + DECLARE @iLicenseTypeId TINYINT + DECLARE @sLicenseType VARCHAR(50) + DECLARE @dtStartDate DATETIME + DECLARE @dtEndDate DATETIME + DECLARE @sAccountType VARCHAR(50) + DECLARE @iAccountTypeId TINYINT + DECLARE @sLicenseStatus VARCHAR(8) + DECLARE @sEdition VARCHAR(200) + DECLARE @bExists bit + DECLARE @sLicenseState VARCHAR(50) + DECLARE @sLicenseZip VARCHAR(20) + DECLARE @sLicenseCountry VARCHAR(50) + DECLARE @sInstitutionName VARCHAR(100) + DECLARE @dtLicenseCreationDate DATETIME + DECLARE @mSubscriptionPrice MONEY + DECLARE @iLicenseSubscriptionId INT + DECLARE @sEmailId VARCHAR(100) + DECLARE @iCardNumber INT + + -- create a temporary table to store the desired results of licenses on the basis of parameter + CREATE TABLE #CustomerReport + ( + AccountNumber VARCHAR(50), + LicenseeName VARCHAR(100), + LicenseType VARCHAR(50), + Edition VARCHAR(200), + Email VARCHAR(100), + ValidFrom DATETIME, + ValidThrough DATETIME, + AccountType VARCHAR(50), + LicenseStatus VARCHAR(8), + Price MONEY, + LicenseState VARCHAR(50), + LicenseZip VARCHAR(20), + LicenseCountry VARCHAR(50), + InstitutionName VARCHAR(100), + LicenseCreationDate DATETIME, + CardNumber INT + ) + + SET @sLicenseeFullName = REPLACE(@sLicenseeFullName,' ',' OR ') + + -- define the forward only, read-only cursor + SET @cGetLicenseDetails = CURSOR FAST_FORWARD + FOR + SELECT License.Id, License.AccountNumber, (License.LicenseeFirstName+' '+License.LicenseeLastName), + License.LicenseTypeId, License.AccountTypeId, License.EmailId, + (CASE License.IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) as LicenseStatus, + State.StateName, License.Zip, Country.CountryName, + License.InstitutionName,License.CreationDate, + (CASE WHEN License.CardNumber > 0 THEN License.CardNumber END) as CardNumber + FROM License WITH (NOLOCK) + INNER JOIN State WITH (NOLOCK) ON License.StateId = State.Id + INNER JOIN Country WITH (NOLOCK) ON License.CountryId = Country.Id + WHERE + License.AccountNumber = (CASE WHEN LEN(@sAccoutNumber)>0 THEN @sAccoutNumber ELSE License.AccountNumber END) + AND License.LicenseTypeId = (CASE WHEN @iLicenseType > 0 THEN @iLicenseType ELSE License.LicenseTypeId END) + AND License.AccountTypeId = (CASE WHEN @iAccountType > 0 THEN @iAccountType ELSE License.AccountTypeId END) + AND State.Id = (CASE WHEN @iState > 0 THEN @iState ELSE State.Id END) + AND Country.Id = (CASE WHEN @iCountry > 0 THEN @iCountry ELSE Country.Id END) + AND License.Zip = (CASE WHEN LEN(@sZip)>0 THEN @sZip ELSE License.Zip END) + + -- open & fetch the cursor variables into the local variables + OPEN @cGetLicenseDetails + FETCH NEXT FROM @cGetLicenseDetails INTO @iLicenseId, @sAccountNumber, @sLicenseeName, + @iLicenseTypeId, @iAccountTypeId, @sEmailId, @sLicenseStatus, @sLicenseState, @sLicenseZip, @sLicenseCountry,@sInstitutionName,@dtLicenseCreationDate, @iCardNumber + + -- start of while loop + WHILE @@FETCH_STATUS = 0 + BEGIN + + SET @sEdition = '' + SET @bExists = 1 + -- fetch the latest license start/end date of a license on the basis of Subscription Start & End price if any + SELECT @dtStartDate = MAX(LicenseSubscriptionDetail.SubscriptionValidFrom), + @dtEndDate = MAX(LicenseSubscriptionDetail.SubscriptionValidThrough), + @iLicenseSubscriptionId = MAX(LicenseSubscriptionDetail.Id) + FROM LicenseSubscriptionDetail WITH (NOLOCK) + WHERE LicenseSubscriptionDetail.LicenseId = @iLicenseId + AND (TotalAmount >= (CASE WHEN @iStartPrice > 0 THEN @iStartPrice ELSE 0 END)) + AND (TotalAmount <= (CASE WHEN @iEndPrice = 0 THEN 0 WHEN @iEndPrice > 0 THEN @iEndPrice ELSE 9999999999 END)) + GROUP BY LicenseSubscriptionDetail.LicenseId + + + -- check whether the above query returns any row + IF @@Rowcount > 0 + BEGIN + + -- check whether the name of licensse matches the name entered by user + + IF LEN(@sLicenseeFullName) > 0 + BEGIN + SELECT @bExists = 1 + FROM License WITH (NOLOCK) + WHERE Id = @iLicenseId AND (LicenseeFirstName LIKE '%'+@sLicenseeFullName+'%' OR LicenseeLastName LIKE '%'+@sLicenseeFullName+'%') --CONTAINS((LicenseeFirstName,LicenseeLastName) + IF @@Rowcount = 0 + BEGIN + SET @bExists = 0 + END + END + + -- check whether the above query returns any row + IF @bExists = 1 + BEGIN + -- fetch the licensetype of the license + SELECT @sLicenseType = LicenseType.Title FROM LicenseType WITH (NOLOCK) + WHERE LicenseType.Id = @iLicenseTypeId + -- fetch the accounttype of the license + SELECT @sAccountType = AccountType.Title FROM AccountType WITH (NOLOCK) + WHERE AccountType.Id = @iAccountTypeId + + -- fetch all the editions mapped as a string with a license + SELECT @sEdition = Edition.Title + '; ' + @sEdition + FROM LicenseToEdition WITH (NOLOCK) INNER JOIN Edition WITH (NOLOCK) + ON LicenseToEdition.EditionId = Edition.Id + WHERE LicenseToEdition.LicenseId = @iLicenseId + + IF LEN(@sEdition)> 1 + -- remove the trailing comma-separator from the edition-string + SET @sEdition = SUBSTRING(@sEdition,1,LEN(@sEdition)-1) + ELSE + SET @sEdition = @sEdition + + -- fetch the price of the license + SELECT @mSubscriptionPrice = TotalAmount FROM LicenseSubscriptionDetail WITH (NOLOCK) + WHERE Id = @iLicenseSubscriptionId + + -- insert into the temporary table + INSERT INTO #CustomerReport + (AccountNumber, LicenseeName, LicenseType, Edition, Email, ValidFrom, ValidThrough, AccountType, LicenseStatus, Price, LicenseState, LicenseZip, LicenseCountry, InstitutionName, LicenseCreationDate, CardNumber) + VALUES(@sAccountNumber, @sLicenseeName, @sLicenseType, @sEdition, @sEmailId, @dtStartDate, @dtEndDate, @sAccountType, @sLicenseStatus, @mSubscriptionPrice, @sLicenseState, @sLicenseZip, @sLicenseCountry,@sInstitutionName,@dtLicenseCreationDate, @iCardNumber) + END + END + -- fetch the next record from cursor + FETCH NEXT FROM @cGetLicenseDetails INTO @iLicenseId, @sAccountNumber, @sLicenseeName, + @iLicenseTypeId, @iAccountTypeId, @sEmailId, @sLicenseStatus, @sLicenseState, @sLicenseZip, @sLicenseCountry, @sInstitutionName, @dtLicenseCreationDate, @iCardNumber + -- end of while loop + END + -- close the cursor to free up resources + CLOSE @cGetLicenseDetails + DEALLOCATE @cGetLicenseDetails + + -- Selecting the desired result from temporary table + SELECT RowNum, AccountNumber, LicenseeName, LicenseType, AccountType, Edition, Email, StartDate, + EndDate, LicenseStatus, Price, + LicenseZip, LicenseState, LicenseCountry,InstitutionName,LicenseCreationDate , CardNumber + from ( + SELECT ROW_NUMBER() OVER (ORDER BY AccountNumber) AS RowNum, AccountNumber, LicenseeName, LicenseType, AccountType, Edition, Email, CONVERT(VARCHAR,ValidFrom,101) as StartDate, + CONVERT(VARCHAR,ValidThrough,101) as EndDate, LicenseStatus, CONVERT(NUMERIC(14,2),Price) as Price, + LicenseZip, LicenseState, LicenseCountry,InstitutionName, CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate , CardNumber + FROM #CustomerReport WITH (NOLOCK) ) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo + ORDER BY AccountNumber + + --Calculate total number of records + select @recordCount = count(ResultTable.AccountNumber) + from ( + SELECT AccountNumber, LicenseeName, LicenseType, AccountType, Edition, Email, CONVERT(VARCHAR,ValidFrom,101) as StartDate, + CONVERT(VARCHAR,ValidThrough,101) as EndDate, LicenseStatus, CONVERT(NUMERIC(14,2),Price) as Price, + LicenseZip, LicenseState, LicenseCountry,InstitutionName, CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate , CardNumber + FROM #CustomerReport WITH (NOLOCK) ) as ResultTable + + -- Dropping the temporary table + DROP TABLE #CustomerReport +END + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetDiscountCodes.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetDiscountCodes.sql new file mode 100644 index 0000000..e67ecb3 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetDiscountCodes.sql @@ -0,0 +1,41 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetDiscountCodes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetDiscountCodes] +GO +CREATE PROCEDURE [dbo].[usp_GetDiscountCodes] + -- Add the parameters for the stored procedure here + @sDiscountCode VARCHAR(255) = '', @sStartDate VARCHAR(20) = '', @sEndDate VARCHAR(20) = '', @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + DECLARE @dtStartDate DATETIME, @dtEndDate DATETIME + + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtEndDate = CONVERT(DATETIME,@sEndDate) + + --Get the records on the basis of parameters page length and page number rows + select LD.Id, LD.DiscountCode, LD.Percentage, LD.StartDate, LD.EndDate, LD.Status + from + (Select ROW_NUMBER() OVER (ORDER BY Id) AS RowNo, Id, DiscountCode, Percentage, CONVERT(VARCHAR(10),StartDate,101) as StartDate, + CONVERT(VARCHAR(10),EndDate,101) as EndDate, (CASE IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) AS Status + FROM Discount WHERE StartDate >= (CASE WHEN LEN(@sStartDate) > 0 THEN @dtStartDate ELSE StartDate END) + AND EndDate <= (CASE WHEN LEN(@sEndDate) > 0 THEN @dtEndDate ELSE EndDate END) + AND DiscountCode like (CASE WHEN LEN(@sDiscountCode) > 0 THEN '%' + @sDiscountCode + '%' ELSE DiscountCode END)) + as LD + where + RowNo > @pageLength * (@pageNo - 1) AND + RowNo <= @pageLength * @pageNo + +--Calculate total number of records +select @recordCount = count(ResultTable.Id) from +(Select Id, DiscountCode, Percentage, CONVERT(VARCHAR(10),StartDate,101) as StartDate, +CONVERT(VARCHAR(10),EndDate,101) as EndDate, (CASE IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) AS Status +FROM Discount WHERE StartDate >= (CASE WHEN LEN(@sStartDate) > 0 THEN @dtStartDate ELSE StartDate END) +AND EndDate <= (CASE WHEN LEN(@sEndDate) > 0 THEN @dtEndDate ELSE EndDate END) +AND DiscountCode like (CASE WHEN LEN(@sDiscountCode) > 0 THEN '%' + @sDiscountCode + '%' ELSE DiscountCode END)) as ResultTable; + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetDiscountReport.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetDiscountReport.sql new file mode 100644 index 0000000..4f73992 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetDiscountReport.sql @@ -0,0 +1,88 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetDiscountReport]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetDiscountReport] +GO + +CREATE PROCEDURE [dbo].[usp_GetDiscountReport] + -- Add the parameters for the stored procedure here + @sStartDate VARCHAR(20) = '', @sEndDate VARCHAR(20) = '', @intDiscountID INT, + @sAccoutNumber VARCHAR(16)='', @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + + IF 1=0 BEGIN + SET FMTONLY OFF + END + + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + DECLARE @dtStartDate DATETIME, @dtEndDate DATETIME + + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate))) + IF LEN(@sAccoutNumber) > 0 + BEGIN + + Select RowNum, DiscountCode, Percentage, StartDate, EndDate, DiscountStatus, TotalLicenses + from ( + SELECT ROW_NUMBER() OVER (ORDER BY Discount.StartDate) AS RowNum , Discount.DiscountCode, Discount.Percentage, CONVERT(VARCHAR(10),Discount.StartDate,101) as StartDate, + CONVERT(VARCHAR(10),Discount.EndDate,101) as EndDate, + (CASE Discount.IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) AS DiscountStatus, + COUNT(DiscountToLicense.LicenseId) AS TotalLicenses + FROM Discount INNER JOIN DiscountToLicense ON Discount.Id = DiscountToLicense.DiscountId + INNER JOIN License ON License.Id = DiscountToLicense.LicenseId + WHERE Discount.StartDate >= (CASE WHEN LEN(@sStartDate) > 0 THEN @dtStartDate ELSE Discount.StartDate END) + AND Discount.EndDate <= (CASE WHEN LEN(@sEndDate) > 0 THEN @dtEndDate ELSE Discount.EndDate END) + AND Discount.Id = (CASE WHEN @intDiscountID > 0 THEN @intDiscountID ELSE Discount.Id END) + AND License.AccountNumber = @sAccoutNumber + GROUP BY Discount.DiscountCode, Discount.Percentage, Discount.StartDate, Discount.EndDate, Discount.IsActive) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo order by StartDate + + --Calculate total number of records + select @recordCount = count(ResultTable.DiscountCode) from ( + SELECT Discount.DiscountCode, Discount.Percentage, CONVERT(VARCHAR(10),Discount.StartDate,101) as StartDate, + CONVERT(VARCHAR(10),Discount.EndDate,101) as EndDate, + (CASE Discount.IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) AS DiscountStatus, + COUNT(DiscountToLicense.LicenseId) AS TotalLicenses + FROM Discount INNER JOIN DiscountToLicense ON Discount.Id = DiscountToLicense.DiscountId + INNER JOIN License ON License.Id = DiscountToLicense.LicenseId + WHERE Discount.StartDate >= (CASE WHEN LEN(@sStartDate) > 0 THEN @dtStartDate ELSE Discount.StartDate END) + AND Discount.EndDate <= (CASE WHEN LEN(@sEndDate) > 0 THEN @dtEndDate ELSE Discount.EndDate END) + AND Discount.Id = (CASE WHEN @intDiscountID > 0 THEN @intDiscountID ELSE Discount.Id END) + AND License.AccountNumber = @sAccoutNumber + GROUP BY Discount.DiscountCode, Discount.Percentage, Discount.StartDate, Discount.EndDate, Discount.IsActive) as ResultTable; + + END + ELSE + BEGIN + + Select RowNum, DiscountCode, Percentage, StartDate, EndDate, DiscountStatus, TotalLicenses + from ( + SELECT ROW_NUMBER() OVER (ORDER BY Discount.StartDate) AS RowNum , Discount.DiscountCode, Discount.Percentage, CONVERT(VARCHAR(10),Discount.StartDate,101) as StartDate, + CONVERT(VARCHAR(10),Discount.EndDate,101) as EndDate, + (CASE Discount.IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) AS DiscountStatus, + COUNT(DiscountToLicense.LicenseId) AS TotalLicenses + FROM Discount LEFT JOIN DiscountToLicense ON Discount.Id = DiscountToLicense.DiscountId + WHERE Discount.StartDate >= (CASE WHEN LEN(@sStartDate) > 0 THEN @dtStartDate ELSE Discount.StartDate END) + AND Discount.EndDate <= (CASE WHEN LEN(@sEndDate) > 0 THEN @dtEndDate ELSE Discount.EndDate END) + AND Discount.Id = (CASE WHEN @intDiscountID > 0 THEN @intDiscountID ELSE Discount.Id END) + GROUP BY Discount.DiscountCode, Discount.Percentage, Discount.StartDate, Discount.EndDate, Discount.IsActive) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo order by StartDate + + --Calculate total number of records + select @recordCount = count(ResultTable.DiscountCode) from ( + SELECT Discount.DiscountCode, Discount.Percentage, CONVERT(VARCHAR(10),Discount.StartDate,101) as StartDate, + CONVERT(VARCHAR(10),Discount.EndDate,101) as EndDate, + (CASE Discount.IsActive WHEN 1 THEN 'Active' ELSE 'Inactive' END) AS DiscountStatus, + COUNT(DiscountToLicense.LicenseId) AS TotalLicenses + FROM Discount LEFT JOIN DiscountToLicense ON Discount.Id = DiscountToLicense.DiscountId + WHERE Discount.StartDate >= (CASE WHEN LEN(@sStartDate) > 0 THEN @dtStartDate ELSE Discount.StartDate END) + AND Discount.EndDate <= (CASE WHEN LEN(@sEndDate) > 0 THEN @dtEndDate ELSE Discount.EndDate END) + AND Discount.Id = (CASE WHEN @intDiscountID > 0 THEN @intDiscountID ELSE Discount.Id END) + GROUP BY Discount.DiscountCode, Discount.Percentage, Discount.StartDate, Discount.EndDate, Discount.IsActive) as ResultTable; + + END + +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetExpiringLicenses.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetExpiringLicenses.sql new file mode 100644 index 0000000..d4329ba --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetExpiringLicenses.sql @@ -0,0 +1,161 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetExpiringLicenses]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetExpiringLicenses] +GO + +CREATE PROCEDURE [dbo].[usp_GetExpiringLicenses] --'2010-01-01','2020-01-01',0,1,0,0,'',0,0,1,10,0 + -- Add the parameters for the stored procedure here + @sFromDate varchar(20), @sToDate varchar(20), @iStartPrice numeric(14,2), @iEndPrice numeric(14,2), + @iLicenseTypeId int, @iAccountTypeId int, @sZip varchar(20)=null, @iStateId int, @iCountryId int + ,@pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + + IF 1=0 BEGIN + SET FMTONLY OFF + END + + -- SET NOCOUNT ON added to prevent extra result sets from + SET NOCOUNT ON; + DECLARE @dtFromDate DATETIME + DECLARE @dtToDate DATETIME + DECLARE @cGetLicenseId CURSOR + DECLARE @iLicenseId INT + DECLARE @iLicenseSubscriptionDetail INT + DECLARE @sAccountNumber VARCHAR(50) + DECLARE @sLicenseeName VARCHAR(100) + DECLARE @sLicenseType VARCHAR(50) + DECLARE @sInstitutionName VARCHAR(100) + DECLARE @dtLicenseCreationDate DATETIME + DECLARE @dtStartDate DATETIME + DECLARE @dtEndDate DATETIME + DECLARE @mSubscriptionPrice MONEY + DECLARE @sAccountType VARCHAR(50) + DECLARE @sEdition VARCHAR(200) + DECLARE @iDaysRemaining INT + DECLARE @iCardNumber INT + + -- convert the datatype of fromdate & todate parameter to datetime + SELECT @dtFromDate = CONVERT(DATETIME,@sFromDate) + SELECT @dtToDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sToDate))) + + -- create a temporary table to store the desired results of license which are going to be expire on the basis of parameter + CREATE TABLE #ExpiringLicenseReport + ( + AccountNumber VARCHAR(50), + LicenseeName VARCHAR(100), + LicenseType VARCHAR(50), + InstitutionName VARCHAR(100), + Edition VARCHAR(200), + ValidFrom DATETIME, + ValidThrough DATETIME, + LicenseCreationDate DATETIME, + Price MONEY, + AccountType VARCHAR(50), + DaysRemaining INT, + CardNumber INT + ) + + -- define the forward only, read-only cursor + SET @cGetLicenseId = CURSOR FAST_FORWARD + FOR + SELECT LicenseSubscriptionDetail.LicenseId, MAX(LicenseSubscriptionDetail.Id) + FROM LicenseSubscriptionDetail WHERE + (TotalAmount >= (CASE WHEN @iStartPrice > 0 THEN @iStartPrice ELSE 0 END)) + AND (TotalAmount <= (CASE WHEN @iEndPrice = 0 THEN 0 WHEN @iEndPrice > 0 THEN @iEndPrice ELSE 9999999999 END)) + GROUP BY LicenseSubscriptionDetail.LicenseId + HAVING (MAX(SubscriptionValidThrough) BETWEEN @dtFromDate AND @dtToDate) + + -- open & fetch the cursor variables into the local variables + OPEN @cGetLicenseId + FETCH NEXT FROM @cGetLicenseId INTO @iLicenseId, @iLicenseSubscriptionDetail + -- start of while loop + WHILE @@FETCH_STATUS = 0 + BEGIN + + SET @sEdition = '' + -- fetch the accountnumber, licenseename, licensetype, startdate, enddate, subscriptionprice, accountype & days remaining to expire for a license + SELECT @sAccountNumber = AccountNumber, @sLicenseeName = LicenseeName, @sLicenseType = LicenseType, + @sInstitutionName = InstitutionName, @dtLicenseCreationDate = CreationDate, + @dtStartDate = SubscriptionValidFrom, @dtEndDate = SubscriptionValidThrough, + @mSubscriptionPrice = TotalAmount, @sAccountType = AccountType, @iDaysRemaining = DaysRemaining, @iCardNumber = CardNumber + FROM + ( + SELECT AccountNumber, (LicenseeFirstName+' '+LicenseeLastName) as LicenseeName, + LicenseType.Title as LicenseType, AccountType.Title as AccountType, + License.InstitutionName,License.CreationDate, + LicenseSubscriptionDetail.TotalAmount, + LicenseSubscriptionDetail.SubscriptionValidFrom, LicenseSubscriptionDetail.SubscriptionValidThrough, + DATEDIFF(dd,GETDATE(),LicenseSubscriptionDetail.SubscriptionValidThrough) as DaysRemaining, (CASE WHEN License.CardNumber > 0 THEN License.CardNumber END) as CardNumber + FROM License + INNER JOIN LicenseType ON License.LicenseTypeId = LicenseType.Id + INNER JOIN AccountType ON License.AccountTypeId = AccountType.Id + INNER JOIN LicenseSubscriptionDetail ON License.Id = LicenseSubscriptionDetail.LicenseId + INNER JOIN State ON License.StateId = State.Id + INNER JOIN Country ON License.CountryId = Country.Id + WHERE License.IsActive = 1 + AND License.LicenseTypeId = (CASE WHEN @iLicenseTypeId > 0 THEN @iLicenseTypeId ELSE License.LicenseTypeId END) + AND License.AccountTypeId = (CASE WHEN @iAccountTypeId > 0 THEN @iAccountTypeId ELSE License.AccountTypeId END) + AND State.Id = (CASE WHEN @iStateId > 0 THEN @iStateId ELSE State.Id END) + AND Country.Id = (CASE WHEN @iCountryId > 0 THEN @iCountryId ELSE Country.Id END) + AND (@sZip is NULL or License.Zip = (CASE WHEN LEN(@sZip)>0 THEN @sZip ELSE License.Zip END)) + AND LicenseSubscriptionDetail.Id = @iLicenseSubscriptionDetail + AND License.LicenseTypeId <> 5 + ) t1 + WHERE DaysRemaining>=0 + -- check whether the above query returns any row + IF @@Rowcount > 0 + BEGIN + -- fetch all the editions mapped as a string with a license + SELECT @sEdition = Edition.Title + '; ' + @sEdition + FROM LicenseToEdition INNER JOIN Edition + ON LicenseToEdition.EditionId = Edition.Id + WHERE LicenseToEdition.LicenseId = @iLicenseId + -- remove the trailing comma-separator from the edition-string + SET @sEdition = SUBSTRING(@sEdition,1,LEN(@sEdition)-1); + + -- insert into the temporary table + INSERT INTO #ExpiringLicenseReport + (AccountNumber, LicenseeName, LicenseType,InstitutionName, Edition, ValidFrom, ValidThrough,LicenseCreationDate, Price, AccountType, DaysRemaining,CardNumber) + VALUES(@sAccountNumber,@sLicenseeName,@sLicenseType,@sInstitutionName,@sEdition,@dtStartDate,@dtEndDate,@dtLicenseCreationDate, @mSubscriptionPrice,@sAccountType,@iDaysRemaining,@iCardNumber) + END + -- fetch the next record from cursor + FETCH NEXT FROM @cGetLicenseId INTO @iLicenseId,@iLicenseSubscriptionDetail + -- end of while loop + END + -- close the cursor to free up resources + CLOSE @cGetLicenseId + DEALLOCATE @cGetLicenseId + + -- Selecting the desired result from temporary table + --SELECT AccountNumber,LicenseeName,LicenseType,InstitutionName,Edition, + --CONVERT(VARCHAR,ValidFrom,101) as StartDate,CONVERT(VARCHAR,ValidThrough,101) as EndDate, + --CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, + --CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice,AccountType,DaysRemaining, CardNumber + --FROM #ExpiringLicenseReport ORDER BY AccountNumber + + + SELECT RowNum, AccountNumber,LicenseeName,LicenseType,InstitutionName,Edition, + StartDate,EndDate,LicenseCreationDate,SubscriptionPrice,AccountType,DaysRemaining, CardNumber + from ( + SELECT ROW_NUMBER() OVER (ORDER BY AccountNumber) AS RowNum, AccountNumber,LicenseeName,LicenseType,InstitutionName,Edition, + CONVERT(VARCHAR,ValidFrom,101) as StartDate,CONVERT(VARCHAR,ValidThrough,101) as EndDate, + CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, + CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice,AccountType,DaysRemaining, CardNumber + FROM #ExpiringLicenseReport) as Tempt + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo + ORDER BY AccountNumber + + --Calculate total number of records + select @recordCount = count(ResultTable.AccountNumber) + from ( + SELECT AccountNumber,LicenseeName,LicenseType,InstitutionName,Edition, + CONVERT(VARCHAR,ValidFrom,101) as StartDate,CONVERT(VARCHAR,ValidThrough,101) as EndDate, + CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, + CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice,AccountType,DaysRemaining, CardNumber + FROM #ExpiringLicenseReport ) as ResultTable + + -- Dropping the temporary table + DROP TABLE #ExpiringLicenseReport +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetExportedImageDetails.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetExportedImageDetails.sql new file mode 100644 index 0000000..2f0badb --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetExportedImageDetails.sql @@ -0,0 +1,58 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetExportedImageDetails]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetExportedImageDetails] +GO + +CREATE PROCEDURE [dbo].[usp_GetExportedImageDetails] + @sStartDate varchar(20) = '', @sEndDate varchar(20) = '', @sAccoutNumber varchar(50)='', @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + Select RowNum, LicenseId, ExportedDate, ImageName, AccountNumber, OriginalFileName, Title, ModuleName, ExportLimit, UserName, imageCount + from ( + SELECT ROW_NUMBER() OVER (ORDER BY LID.LicenseId) AS RowNum , LID.LicenseId, + LID.ExportedDate, + LID.ImageName, + L.AccountNumber, + LID.OriginalFileName, + LID.Title, + LID.ModuleName, + (SELECT TOP(1) LSD.NoofImages FROM LicenseSubscriptionDetail LSD WHERE LSD.LicenseId = LID.LicenseId order by LSD.SubscriptionValidFrom desc) as ExportLimit, + USR.FirstName + ' '+ USR.LastName as UserName, + (SELECT COUNT(LID1.Id) FROM LicenseImageExportDetail LID1 WHERE LID1.LicenseId = LID.LicenseId group by LID1.LicenseId) as imageCount + FROM + LicenseImageExportDetail LID + LEFT JOIN License L ON LID.LicenseId =L.Id + INNER JOIN AIAUser USR ON LID.UserId = USR.Id + WHERE + ((LEN(@sStartDate)=0) OR (LID.ExportedDate >= (CONVERT(DATETIME,@sStartDate)))) AND + ((LEN(@sEndDate)=0) OR (LID.ExportedDate <= (DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate)))))) AND + ((LEN(@sAccoutNumber)=0) OR (AccountNumber LIKE '%'+@sAccoutNumber+'%'))) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo order by LicenseId + + --Calculate total number of records + select @recordCount = count(ResultTable.LicenseId) from ( + SELECT LID.LicenseId, + LID.ExportedDate, + LID.ImageName, + L.AccountNumber, + LID.OriginalFileName, + LID.Title, + LID.ModuleName, + (SELECT TOP(1) LSD.NoofImages FROM LicenseSubscriptionDetail LSD WHERE LSD.LicenseId = LID.LicenseId order by LSD.SubscriptionValidFrom desc) as ExportLimit, + USR.FirstName + ' '+ USR.LastName as UserName, + (SELECT COUNT(LID1.Id) FROM LicenseImageExportDetail LID1 WHERE LID1.LicenseId = LID.LicenseId group by LID1.LicenseId) as imageCount + FROM + LicenseImageExportDetail LID + LEFT JOIN License L ON LID.LicenseId =L.Id + INNER JOIN AIAUser USR ON LID.UserId = USR.Id + WHERE + ((LEN(@sStartDate)=0) OR (LID.ExportedDate >= (CONVERT(DATETIME,@sStartDate)))) AND + ((LEN(@sEndDate)=0) OR (LID.ExportedDate <= (DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate)))))) AND + ((LEN(@sAccoutNumber)=0) OR (AccountNumber LIKE '%'+@sAccoutNumber+'%'))) as ResultTable; + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetModuleStatusByLicenseId.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetModuleStatusByLicenseId.sql new file mode 100644 index 0000000..435ae9e --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetModuleStatusByLicenseId.sql @@ -0,0 +1,23 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetModuleStatusByLicenseId]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetModuleStatusByLicenseId] +GO + +CREATE PROCEDURE [dbo].[usp_GetModuleStatusByLicenseId] + -- Add the parameters for the stored procedure here + @iLicenseId int +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + -- Insert statements for procedure here + SELECT ResourceModule.Id,ResourceModule.Title,ModuleToLicense.Status + FROM ResourceModule + INNER JOIN ModuleToLicense ON ResourceModule.Id = ModuleToLicense.ModuleId + WHERE ModuleToLicense.LicenseId = @iLicenseId +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetNetAdSummaryReport.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetNetAdSummaryReport.sql new file mode 100644 index 0000000..77d5463 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetNetAdSummaryReport.sql @@ -0,0 +1,183 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetNetAdSummaryReport]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetNetAdSummaryReport] +GO + +CREATE PROCEDURE [dbo].[usp_GetNetAdSummaryReport] --'2015-05-01','2018-05-01',0,0,0,1,100,1000 + -- Add the parameters for the stored procedure here + -- FromDate & ToDate are mandatory + @sFromDate varchar(20), @sToDate varchar(20), @iStartPrice numeric(14,2), @iEndPrice numeric(14,2), @iLicenseTypeId tinyint, + @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + + IF 1=0 BEGIN + SET FMTONLY OFF + END + + -- SET NOCOUNT ON added to prevent extra result sets from + SET NOCOUNT ON; + DECLARE @dtFromDate DATETIME + DECLARE @dtToDate DATETIME + DECLARE @cGetSummary CURSOR + DECLARE @iLicenseId INT + DECLARE @iLicenseSubscriptioId INT + DECLARE @iActiveSubscription INT + DECLARE @iRenewSubscription INT + DECLARE @iCancelSubscription INT + DECLARE @iNetAdSubscription INT + DECLARE @sLicenseType VARCHAR(50) + DECLARE @sInstitutionname VARCHAR(100) + DECLARE @dtLicenseCreationDate DATETIME + DECLARE @sAccountType VARCHAR(50) + DECLARE @IsActive BIT + DECLARE @sRenew BIT + + -- set the default parameters to 0 + SET @iActiveSubscription = 0 + SET @iRenewSubscription = 0 + SET @iCancelSubscription = 0 + + -- convert the datatype of fromdate & todate parameter to datetime + SELECT @dtFromDate = CONVERT(DATETIME,@sFromDate) + SELECT @dtToDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sToDate))) + + -- create a temporary table to store the first-level of result shown in the netad subscription report on the basis of parameter + CREATE TABLE #NetAdSummaryReport + ( + LicenseType VARCHAR(50), + AccountType VARCHAR(50), + InstitutionName VARCHAR(100), + LicenseCreationDate DATETIME, + IsActive BIT, + IsRenew BIT + ) + CREATE CLUSTERED INDEX IK_NetAdSummaryReport_1 ON #NetAdSummaryReport (LicenseType, AccountType) + CREATE NONCLUSTERED INDEX IK_NetAdSummaryReport_2 ON #NetAdSummaryReport (IsActive) + + -- create a temporary table + CREATE TABLE #NetAdResult + ( + LicenseType VARCHAR(50), + AccountType VARCHAR(50), + InstitutionName VARCHAR(100), + LicenseCreationDate DATETIME, + ActiveSubscription INT, + RenewSubscription INT, + InActiveSubscription INT, + NetAdSubscription INT + ) + + -- define the forward only, read-only cursor + SET @cGetSummary = CURSOR FAST_FORWARD + FOR + SELECT License.Id, LicenseSubscriptionDetail.Id + FROM LicenseSubscriptionDetail + INNER JOIN License ON LicenseSubscriptionDetail.LicenseId = License.Id WHERE + ((License.CancellationDate BETWEEN @dtFromDate AND @dtToDate AND License.IsActive = 0 ) + OR (License.CreationDate BETWEEN @dtFromDate AND @dtToDate ) + OR (RenewalDate BETWEEN @dtFromDate AND @dtToDate)) + AND License.LicenseTypeId = (CASE WHEN @iLicenseTypeId > 0 THEN @iLicenseTypeId ELSE License.LicenseTypeId END) + AND (TotalAmount >= (CASE WHEN @iStartPrice > 0 THEN @iStartPrice ELSE 0 END)) + AND (TotalAmount <= (CASE WHEN @iEndPrice = 0 THEN 0 WHEN @iEndPrice > 0 THEN @iEndPrice ELSE 9999999999 END)) + AND License.LicenseTypeId <> 5 + GROUP BY License.Id, LicenseSubscriptionDetail.Id + + + -- open & fetch the cursor variables into the local variables + OPEN @cGetSummary + FETCH NEXT FROM @cGetSummary INTO @iLicenseId, @iLicenseSubscriptioId + -- start of while loop + WHILE @@FETCH_STATUS = 0 + BEGIN + + -- fetch the licensetype, accountype & the status of a license + SELECT @sLicenseType = LicenseType.Title, @sAccountType = AccountType.Title, + @sInstitutionname = License.InstitutionName, @dtLicenseCreationDate = License.CreationDate, + @IsActive = License.IsActive, + @sRenew = (CASE WHEN LicenseSubscriptionDetail.RenewalDate IS NULL THEN 0 ELSE 1 END) + FROM License + INNER JOIN LicenseType ON License.LicenseTypeId = LicenseType.Id + INNER JOIN AccountType ON License.AccountTypeId = AccountType.Id + INNER JOIN LicenseSubscriptionDetail ON LicenseSubscriptionDetail.LicenseId = License.Id + WHERE License.Id = @iLicenseId + AND LicenseSubscriptionDetail.Id = @iLicenseSubscriptioId + + + -- check whether the above query returns any row + IF @@Rowcount > 0 + BEGIN + + IF @IsActive = 1 + BEGIN + IF @sRenew = 1 + BEGIN + SET @iRenewSubscription = @iRenewSubscription + 1 + END + ELSE + BEGIN + SET @iActiveSubscription = @iActiveSubscription + 1 + END + END + ELSE + BEGIN + IF @sRenew = 1 + BEGIN + SET @iRenewSubscription = @iRenewSubscription + 1 + END + ELSE + BEGIN + SET @iCancelSubscription = @iCancelSubscription + 1 + END + END + + -- insert into the temporary table + INSERT INTO #NetAdSummaryReport + (LicenseType,AccountType,InstitutionName,LicenseCreationDate,IsActive,IsRenew) + VALUES(@sLicenseType,@sAccountType,@sInstitutionname,@dtLicenseCreationDate,@IsActive,@sRenew) + END + -- fetch the next record from cursor + FETCH NEXT FROM @cGetSummary INTO @iLicenseId, @iLicenseSubscriptioId + -- end of while loop + END + -- close the cursor to free up resources + CLOSE @cGetSummary + DEALLOCATE @cGetSummary + + -- Selecting the desired result from temporary table + INSERT INTO #NetAdResult (LicenseType, AccountType,InstitutionName,LicenseCreationDate,ActiveSubscription, RenewSubscription, InActiveSubscription, + NetAdSubscription) + SELECT LicenseType,AccountType,MAX(InstitutionName) as InstitutionName, MAX(LicenseCreationDate) as LicenseCreationDate,(SELECT COUNT(1) FROM #NetAdSummaryReport + WHERE LicenseType = N1.LicenseType AND AccountType = N1.AccountType AND IsActive = 1 AND IsRenew = 0) as ActiveSubscription, + (SELECT COUNT(1) FROM #NetAdSummaryReport + WHERE LicenseType = N1.LicenseType AND AccountType = N1.AccountType AND IsRenew = 1) as RenewSubscription, + (SELECT COUNT(1) FROM #NetAdSummaryReport + WHERE LicenseType = N1.LicenseType AND AccountType = N1.AccountType AND IsActive = 0 AND IsRenew = 0) as InActiveSubscription, + ((SELECT COUNT(1) FROM #NetAdSummaryReport + WHERE LicenseType = N1.LicenseType AND AccountType = N1.AccountType AND IsActive = 1 AND IsRenew = 0) + (SELECT COUNT(1) FROM #NetAdSummaryReport + WHERE LicenseType = N1.LicenseType AND AccountType = N1.AccountType AND IsRenew = 1) - (SELECT COUNT(1) FROM #NetAdSummaryReport + WHERE LicenseType = N1.LicenseType AND AccountType = N1.AccountType AND IsActive = 0)) as NetAdSubscription + FROM #NetAdSummaryReport N1 GROUP BY LicenseType,AccountType + + -- to show the sum of active, renew, cancel & netad subscriptions + if((Select COUNT(*) from #NetAdResult)>0) + begin + INSERT INTO #NetAdResult (LicenseType,LicenseCreationDate, ActiveSubscription, RenewSubscription, InActiveSubscription, + NetAdSubscription) SELECT 'Total','9999-01-01', @iActiveSubscription, @iRenewSubscription, @iCancelSubscription, + (@iActiveSubscription+@iRenewSubscription-@iCancelSubscription) + End + + Select RowNum, LicenseType, AccountType,InstitutionName,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, ActiveSubscription, RenewSubscription, InActiveSubscription, + NetAdSubscription + from ( + SELECT ROW_NUMBER() OVER (ORDER BY LicenseCreationDate Asc) AS RowNum ,LicenseType, AccountType,InstitutionName,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, ActiveSubscription, RenewSubscription, InActiveSubscription, + NetAdSubscription FROM #NetAdResult) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo order by LicenseCreationDate desc + + --Calculate total number of records + select @recordCount = count(ResultTable.NetAdSubscription) from (SELECT LicenseType, AccountType,InstitutionName,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, ActiveSubscription, RenewSubscription, InActiveSubscription, + NetAdSubscription FROM #NetAdResult) as ResultTable; + + -- Dropping the temporary tables + DROP TABLE #NetAdSummaryReport + DROP TABLE #NetAdResult +END diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSearchUsers.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSearchUsers.sql new file mode 100644 index 0000000..cd08938 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSearchUsers.sql @@ -0,0 +1,191 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetSearchUsers]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetSearchUsers] +GO + +Create PROCEDURE [dbo].[usp_GetSearchUsers]--'','','','',0,0,0,1,10,0 + -- Add the parameters for the stored procedure here + @sFirstName varchar(100) = '', @sLastName varchar(100) = '', @sEmailId varchar(100) = '', + @sAccoutNumber varchar(100) ='', @iUserTypeId int, @iAccountTypeId int, @iLoginUserType int, + @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + + DECLARE @SQL NVARCHAR(MAX) + -- create a temporary table to store the desired results of user on the basis of parameter + CREATE TABLE #UserResult + ( + RowNums int IDENTITY PRIMARY KEY, + Id INT, + FirstName VARCHAR(100), + LastName VARCHAR(100), + LoginId VARCHAR(50), + EmailId VARCHAR(50), + UserTypeTitle VARCHAR(50), + Password VARCHAR(50), + CreationDate DATETIME, + ModifiedDate DATETIME, + AccountNumber VARCHAR(50) DEFAULT '', + AccountTypeTitle VARCHAR(50) DEFAULT '', + EditionType VARCHAR(50) DEFAULT '', + UserStatus VARCHAR(8), + UserTypeId INT, + EditionTypeId INT DEFAULT '' + ) + /*SET @sFirstName = REPLACE(@sFirstName,' ',' OR ') + SET @sLastName = REPLACE(@sLastName,' ',' OR ')*/ + SET @SQL = '' + IF LEN(@sAccoutNumber) > 0 OR @iAccountTypeId > 0 + BEGIN + -- fetch account number, state, zip, country of the license to which the user is belonged + + SET @SQL = 'INSERT INTO #UserResult (Id, FirstName, LastName, LoginId, EmailId, UserTypeTitle, Password, CreationDate, + ModifiedDate, AccountNumber, AccountTypeTitle, EditionType, UserStatus, UserTypeId, EditionTypeId) + SELECT AIAUser.Id, ISNULL(AIAUser.FirstName,''''), ISNULL(AIAUser.LastName,''''), AIAUser.LoginId, ISNULL(AIAUser.EmailId,'''') as EmailId, + UserType.Title as UserTypeTitle, AIAUser.Password, AIAUser.CreationDate, ISNULL(AIAUser.ModifiedDate,'''') as ModifiedDate, + ISNULL(License.AccountNumber,'''') as AccountNumber, ISNULL(AccountType.Title,'''') as AccountTypeTitle, + ISNULL(Edition.Title,'''') as EditionType, + (CASE AIAUser.IsActive WHEN 1 THEN ''Active'' ELSE ''Inactive'' END) as UserStatus, + UserType.Id as UserTypeId, ISNULL(Edition.Id,'''') as EditionTypeId + FROM AIAUser + INNER JOIN UserType ON UserType.Id = AIAUser.UserTypeId + INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id + INNER JOIN AccountType ON AccountType.Id = License.AccountTypeId + INNER JOIN Edition ON Edition.Id = LicenseToEdition.EditionId + WHERE + License.IsActive = 1 + AND UserType.Priority >' +CONVERT(VARCHAR(20),@iLoginUserType) + + IF LEN(@sAccoutNumber)>0 + BEGIN + SET @SQL = @SQL + ' AND License.AccountNumber = '''+@sAccoutNumber+'''' + END + IF @iAccountTypeId > 0 + BEGIN + SET @SQL = @SQL + ' AND License.AccountTypeId = '''+CONVERT(VARCHAR(20),@iAccountTypeId)+'''' + END + IF LEN(@sFirstName)>0 + BEGIN + SET @SQL = @SQL + ' AND (AIAUser.FirstName LIKE ''%'+@sFirstName+'%'')' --CONTAINS(AIAUser.FirstName, '''+@sFirstName+''')' + END + IF LEN(@sLastName)>0 + BEGIN + SET @SQL = @SQL + ' AND (AIAUser.LastName LIKE ''%'+@sLastName+'%'')'--CONTAINS(AIAUser.LastName, '''+@sLastName+''')' + END + IF LEN(@sEmailId)>0 + BEGIN + SET @SQL = @SQL + ' AND AIAUser.EmailId = '''+@sEmailId+'''' + END + IF @iUserTypeId>0 + BEGIN + SET @SQL = @SQL + ' AND AIAUser.UserTypeId = '''+CONVERT(VARCHAR(20),@iUserTypeId)+'''' + END + -- select @SQL + EXEC SP_EXECUTESQL @SQL + + END + ELSE + BEGIN + + SET @SQL = 'INSERT INTO #UserResult (Id, FirstName, LastName, LoginId, EmailId, UserTypeTitle, Password, CreationDate, + ModifiedDate, UserStatus, UserTypeId) + SELECT AIAUser.Id, ISNULL(AIAUser.FirstName,''''), ISNULL(AIAUser.LastName,''''), + AIAUser.LoginId, ISNULL(AIAUser.EmailId,''''), UserType.Title, AIAUser.Password, AIAUser.CreationDate, + ISNULL(AIAUser.ModifiedDate,''''), (CASE AIAUser.IsActive WHEN 1 THEN ''Active'' ELSE ''Inactive'' END), + UserType.Id + FROM AIAUser + INNER JOIN UserType ON UserType.Id = AIAUser.UserTypeId + WHERE UserType.Title in (''General Admin'')' + + IF LEN(@sFirstName)>0 + BEGIN + SET @SQL = @SQL + ' AND (AIAUser.FirstName LIKE ''%'+@sFirstName+'%'')'--CONTAINS(AIAUser.FirstName, '''+@sFirstName+''')' + END + IF LEN(@sLastName)>0 + BEGIN + SET @SQL = @SQL + ' AND (AIAUser.LastName LIKE ''%'+@sLastName+'%'')'--CONTAINS(AIAUser.LastName, '''+@sLastName+''')' + END + IF LEN(@sEmailId)>0 + BEGIN + SET @SQL = @SQL + ' AND AIAUser.EmailId = '''+@sEmailId+'''' + END + IF @iUserTypeId>0 + BEGIN + SET @SQL = @SQL + ' AND AIAUser.UserTypeId = '''+CONVERT(VARCHAR(20),@iUserTypeId)+'''' + END + -- select @SQL + EXEC SP_EXECUTESQL @SQL + + -- fetch account number, state, zip, country of the license to which the user is belonged + SET @SQL = 'INSERT INTO #UserResult (Id, FirstName, LastName, LoginId, EmailId, UserTypeTitle, Password, CreationDate, + ModifiedDate, AccountNumber, AccountTypeTitle, EditionType, UserStatus, UserTypeId, EditionTypeId) + SELECT AIAUser.Id, ISNULL(AIAUser.FirstName,''''), ISNULL(AIAUser.LastName,''''), AIAUser.LoginId, ISNULL(AIAUser.EmailId,''''), + UserType.Title, AIAUser.Password, AIAUser.CreationDate, ISNULL(AIAUser.ModifiedDate,''''), + License.AccountNumber, AccountType.Title, Edition.Title, + (CASE AIAUser.IsActive WHEN 1 THEN ''Active'' ELSE ''Inactive'' END), UserType.Id, Edition.Id + FROM AIAUser + INNER JOIN UserType ON UserType.Id = AIAUser.UserTypeId + INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id + INNER JOIN AccountType ON AccountType.Id = License.AccountTypeId + INNER JOIN Edition ON Edition.Id = LicenseToEdition.EditionId + WHERE + UserType.Title NOT IN (''Super Admin'',''General Admin'') + AND License.IsActive = 1' + + IF LEN(@sAccoutNumber)>0 + BEGIN + SET @SQL = @SQL + ' AND License.AccountNumber = '''+@sAccoutNumber+'''' + END + IF @iAccountTypeId > 0 + BEGIN + SET @SQL = @SQL + ' AND License.AccountTypeId = '''+CONVERT(VARCHAR(20),@iAccountTypeId)+'''' + END + IF LEN(@sFirstName)>0 + BEGIN + SET @SQL = @SQL + ' AND (AIAUser.FirstName LIKE ''%'+@sFirstName+'%'')'--CONTAINS(AIAUser.FirstName, '''+@sFirstName+''')' + END + IF LEN(@sLastName)>0 + BEGIN + SET @SQL = @SQL + ' AND (AIAUser.LastName LIKE ''%'+@sLastName+'%'')'--CONTAINS(AIAUser.LastName, '''+@sLastName+''')' + END + IF LEN(@sEmailId)>0 + BEGIN + SET @SQL = @SQL + ' AND AIAUser.EmailId = '''+@sEmailId+'''' + END + IF @iUserTypeId>0 + BEGIN + SET @SQL = @SQL + ' AND AIAUser.UserTypeId = '''+CONVERT(VARCHAR(20),@iUserTypeId)+'''' + END + --select @SQL + EXEC SP_EXECUTESQL @SQL + + END + -- Selecting the desired result from temporary table + Select RowNum,Id, FirstName, LastName,LoginId, EmailId,UserTypeTitle, Password, CreationDate, + ModifiedDate, AccountNumber, AccountTypeTitle, EditionType, UserStatus, UserTypeId,EditionTypeId + from ( + SELECT ROW_NUMBER() OVER (ORDER BY Id) AS RowNum ,Id, FirstName, LastName, LoginId, EmailId, UserTypeTitle, Password, CreationDate, + ModifiedDate, AccountNumber, AccountTypeTitle, EditionType, UserStatus, UserTypeId, EditionTypeId FROM #UserResult) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo order by Id --RowNum BETWEEN @pageNo AND (@pageNo - 1) * @pageLength +--SELECT RowNum, Id, FirstName, LastName, LoginId, EmailId, UserTypeTitle, Password, CreationDate, +-- ModifiedDate, AccountNumber, AccountTypeTitle, EditionType, UserStatus, UserTypeId, EditionTypeId FROM #UserResult +-- where RowNum > (@pageLength * (@pageNo - 1)) AND (RowNo <= (@pageLength * @pageNo)) order by RowNum + -- order by Id + -- order by Id OFFSET ((@pageNo - 1) * @pageLength) ROWS FETCH NEXT @pageLength ROWS ONLY; + + + + --Calculate total number of records + select @recordCount = count(ResultTable.Id) from (SELECT Id, FirstName, LastName, LoginId, EmailId, UserTypeTitle, Password, CreationDate, + ModifiedDate, AccountNumber, AccountTypeTitle, EditionType, UserStatus, UserTypeId, EditionTypeId FROM #UserResult) as ResultTable; + + -- Dropping the temporary table + DROP TABLE #UserResult +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSiteAccoutDetail.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSiteAccoutDetail.sql new file mode 100644 index 0000000..24bb37e --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSiteAccoutDetail.sql @@ -0,0 +1,51 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetSiteAccoutDetail]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetSiteAccoutDetail] +GO + +CREATE PROCEDURE [dbo].[usp_GetSiteAccoutDetail] + -- Add the parameters for the stored procedure here + @strAccountNumber varchar(50)='', @pageNo int, @pageLength int, @recordCount int out + +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + --Get the records on the basis of parameters page length and page number rows + select LD.Id, LD.SiteIp, LD.Title, LD.SiteIPTo, LD.SiteMasterIPTo, LD.CreationDate, LD.ModifiedDate, LD.InstituteName, + LD.Department, LD.UserId, LD.FirstName, LD.EmailId + from + (Select ROW_NUMBER() OVER (ORDER BY Site.Id) AS RowNo, + Site.Id,Site.SiteIp,Site.Title,ISNULL(Site.SiteIPTo,'') as SiteIPTo,ISNULL(Site.SiteMasterIPTo,'') as SiteMasterIPTo, + CONVERT(VARCHAR,Site.CreationDate,101) as CreationDate, + CONVERT(VARCHAR,Site.ModifiedDate,101) as ModifiedDate, + Site.InstituteName,Site.Department, AIAUser.Id as UserId,AIAUser.FirstName,AIAUser.EmailId + From ((Site INNER JOIN AIAUserToSite on Site.Id=AIAUserToSite.SiteId) + INNER JOIN AIAUser on AIAUserToSite.UserId = AIAUser.Id) + Where Site.IsActive=1 and Site.id in + (Select SiteID From SiteToLicenseEdition Where LicenseEditionId in + (Select Id From LicenseToEdition Where LicenseId in + (Select Id From License Where LicenseTypeId=3 and AccountNumber=@strAccountNumber)))) + as LD + where + RowNo > @pageLength * (@pageNo - 1) AND + RowNo <= @pageLength * @pageNo + + --Calculate total number of records + select @recordCount = count(ResultTable.Id) from + (Select Site.Id,Site.SiteIp,Site.Title,ISNULL(Site.SiteIPTo,'') as SiteIPTo,ISNULL(Site.SiteMasterIPTo,'') as SiteMasterIPTo, + CONVERT(VARCHAR,Site.CreationDate,101) as CreationDate, + CONVERT(VARCHAR,Site.ModifiedDate,101) as ModifiedDate, + Site.InstituteName,Site.Department, AIAUser.Id as UserId,AIAUser.FirstName,AIAUser.EmailId + From ((Site INNER JOIN AIAUserToSite on Site.Id=AIAUserToSite.SiteId) + INNER JOIN AIAUser on AIAUserToSite.UserId = AIAUser.Id) + Where Site.IsActive=1 and Site.id in + (Select SiteID From SiteToLicenseEdition Where LicenseEditionId in + (Select Id From LicenseToEdition Where LicenseId in + (Select Id From License Where LicenseTypeId=3 and AccountNumber=@strAccountNumber)))) as ResultTable; + +END + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSiteLicenseUsageReport.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSiteLicenseUsageReport.sql new file mode 100644 index 0000000..2936271 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSiteLicenseUsageReport.sql @@ -0,0 +1,56 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetSiteLicenseUsageReports]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetSiteLicenseUsageReports] +GO + +CREATE PROCEDURE [dbo].[usp_GetSiteLicenseUsageReports] + -- Add the parameters for the stored procedure here + @sFromDate varchar(20), @sToDate varchar(20), @sAccoutNumber varchar(50)='', @iEditionId tinyint = 0, + @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + SET NOCOUNT ON + DECLARE @dtFromDate DATETIME + DECLARE @dtToDate DATETIME + + -- convert the datatype of fromdate & todate parameter to datetime + SELECT @dtFromDate = CONVERT(DATETIME,@sFromDate) + SELECT @dtToDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sToDate))) + + Select RowNum,AccountNumber, EditionTitle, ReferalUrl, InstitutionName, LicenseCreationDate,TotalLogins,LastLogin + from ( + SELECT ROW_NUMBER() OVER (ORDER BY UserLoginLog.AccountNumber) AS RowNum , UserLoginLog.AccountNumber, Edition.Title AS EditionTitle, UserLoginLog.ReferalUrl, + (SELECT License.InstitutionName FROM License WHERE License.AccountNumber = UserLoginLog.AccountNumber) as InstitutionName, + (SELECT CONVERT(VARCHAR,License.CreationDate,101) FROM License WHERE License.AccountNumber = UserLoginLog.AccountNumber) as LicenseCreationDate, + COUNT(DISTINCT UserLoginLog.LogDate) AS TotalLogins, + CONVERT(VARCHAR,MAX(UserLoginLog.LogDate),101) AS LastLogin FROM + UserLoginLog INNER JOIN Edition ON UserLoginLog.Edition = CAST(Edition.Id AS NVARCHAR) + WHERE UserLoginLog.FailureId IS NULL + AND UserLoginLog.LogDate BETWEEN @dtFromDate AND @dtToDate + AND UserLoginLog.AccountNumber = (CASE WHEN LEN(@sAccoutNumber) > 0 THEN @sAccoutNumber ELSE UserLoginLog.AccountNumber END) + AND Edition.IsActive = 1 + AND Edition.Id = (CASE WHEN @iEditionId > 0 THEN @iEditionId ELSE Edition.Id END) + GROUP BY UserLoginLog.AccountNumber, Edition.Title, UserLoginLog.ReferalUrl) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo order by AccountNumber + + + --Calculate total number of records + select @recordCount = count(ResultTable.AccountNumber) from ( + SELECT UserLoginLog.AccountNumber, Edition.Title AS EditionTitle, UserLoginLog.ReferalUrl, + (SELECT License.InstitutionName FROM License WHERE License.AccountNumber = UserLoginLog.AccountNumber) as InstitutionName, + (SELECT CONVERT(VARCHAR,License.CreationDate,101) FROM License WHERE License.AccountNumber = UserLoginLog.AccountNumber) as LicenseCreationDate, + COUNT(DISTINCT UserLoginLog.LogDate) AS TotalLogins, + CONVERT(VARCHAR,MAX(UserLoginLog.LogDate),101) AS LastLogin FROM + UserLoginLog INNER JOIN Edition ON UserLoginLog.Edition = CAST(Edition.Id AS NVARCHAR) + WHERE UserLoginLog.FailureId IS NULL + AND UserLoginLog.LogDate BETWEEN @dtFromDate AND @dtToDate + AND UserLoginLog.AccountNumber = (CASE WHEN LEN(@sAccoutNumber) > 0 THEN @sAccoutNumber ELSE UserLoginLog.AccountNumber END) + AND Edition.IsActive = 1 + AND Edition.Id = (CASE WHEN @iEditionId > 0 THEN @iEditionId ELSE Edition.Id END) + GROUP BY UserLoginLog.AccountNumber, Edition.Title, UserLoginLog.ReferalUrl) as ResultTable; + +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSubscribedLicenses.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSubscribedLicenses.sql new file mode 100644 index 0000000..d4108bd --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetSubscribedLicenses.sql @@ -0,0 +1,160 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetSubscribedLicenses]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetSubscribedLicenses] +GO + +CREATE PROCEDURE [dbo].[usp_GetSubscribedLicenses] + -- Add the parameters for the stored procedure here + @sFromDate varchar(20), @sToDate varchar(20), @iStartPrice numeric(14,2), @iEndPrice numeric(14,2), @iLicenseTypeId tinyint, + @iAccountTypeId tinyint, @sZip varchar(20) = '', @iStateId int, @iCountryId int,@pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + SET NOCOUNT ON; + DECLARE @dtFromDate DATETIME + DECLARE @dtToDate DATETIME + DECLARE @cGetLicenseID CURSOR + DECLARE @iLicenseId INT + DECLARE @iLicenseSubscriptionDetail INT + DECLARE @sAccountNumber VARCHAR(50) + DECLARE @sLicenseeName VARCHAR(100) + DECLARE @sLicenseType VARCHAR(50) + DECLARE @sInstitutionName VARCHAR(100) + DECLARE @dtStartDate DATETIME + DECLARE @dtEndDate DATETIME + DECLARE @dtLicenseCreationDate DATETIME + DECLARE @mSubscriptionPrice MONEY + DECLARE @sAccountType VARCHAR(50) + DECLARE @sEdition VARCHAR(200) + DECLARE @iCardNumber INT + + + -- convert the datatype of fromdate & todate parameter to datetime + SELECT @dtFromDate = CONVERT(DATETIME,@sFromDate) + SELECT @dtToDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sToDate))) + + -- create a temporary table to store the desired results of subscribed licenses on the basis of parameter + CREATE TABLE #SubscribedLicenseReport + ( + AccountNumber VARCHAR(50), + LicenseeName VARCHAR(100), + LicenseType VARCHAR(50), + InstitutionName VARCHAR(100), + Edition VARCHAR(200), + ValidFrom DATETIME, + ValidThrough DATETIME, + LicenseCreationDate DATETIME, + Price MONEY, + AccountType varchar(50), + CardNumber INT + ) + + -- define the forward only, read-only cursor + SET @cGetLicenseID = CURSOR FAST_FORWARD + FOR + SELECT LicenseSubscriptionDetail.LicenseId, MAX(LicenseSubscriptionDetail.Id) + FROM LicenseSubscriptionDetail WHERE + (TotalAmount >= (CASE WHEN @iStartPrice > 0 THEN @iStartPrice ELSE 0 END)) + AND (TotalAmount <= (CASE WHEN @iEndPrice = 0 THEN 0 WHEN @iEndPrice > 0 THEN @iEndPrice ELSE 9999999999 END)) + GROUP BY LicenseSubscriptionDetail.LicenseId + HAVING (MAX(SubscriptionValidFrom) BETWEEN @dtFromDate AND @dtToDate) + + -- open & fetch the cursor variables into the local variables + OPEN @cGetLicenseID + FETCH NEXT FROM @cGetLicenseID INTO @iLicenseId, @iLicenseSubscriptionDetail + -- start of while loop + WHILE @@FETCH_STATUS = 0 + BEGIN + + SET @sEdition = '' + + -- fetch the accountnumber, licenseename, licensetype, accountype of a license + SELECT @sAccountNumber = AccountNumber, @sLicenseeName = (LicenseeFirstName+' '+LicenseeLastName), + @sLicenseType = LicenseType.Title, @sAccountType = AccountType.Title, + @iCardNumber = (CASE WHEN License.CardNumber > 0 THEN License.CardNumber END), + @sInstitutionName = License.InstitutionName,@dtLicenseCreationDate = License.CreationDate + FROM License + INNER JOIN LicenseType ON License.LicenseTypeId = LicenseType.Id + INNER JOIN AccountType ON License.AccountTypeId = AccountType.Id + INNER JOIN State ON License.StateId = State.Id + INNER JOIN Country ON License.CountryId = Country.Id + WHERE License.Id = @iLicenseId AND License.IsActive = 1 + AND License.LicenseTypeId = (CASE WHEN @iLicenseTypeId > 0 THEN @iLicenseTypeId ELSE License.LicenseTypeId END) + AND License.AccountTypeId = (CASE WHEN @iAccountTypeId > 0 THEN @iAccountTypeId ELSE License.AccountTypeId END) + AND State.Id = (CASE WHEN @iStateId > 0 THEN @iStateId ELSE State.Id END) + AND Country.Id = (CASE WHEN @iCountryId > 0 THEN @iCountryId ELSE Country.Id END) + AND License.Zip = (CASE WHEN LEN(@sZip)>0 THEN @sZip ELSE License.Zip END) + AND License.LicenseTypeId <> 5 + + -- check whether the above query returns any row + IF @@Rowcount > 0 + BEGIN + -- fetch startdate, enddate, subscriptionprice of a license + SELECT @mSubscriptionPrice = LicenseSubscriptionDetail.TotalAmount, + @dtStartDate = LicenseSubscriptionDetail.SubscriptionValidFrom, + @dtEndDate = LicenseSubscriptionDetail.SubscriptionValidThrough + FROM LicenseSubscriptionDetail + WHERE LicenseSubscriptionDetail.Id = @iLicenseSubscriptionDetail + + -- fetch all the editions mapped as a string with a license + SELECT @sEdition = Edition.Title + '; ' + @sEdition + FROM LicenseToEdition INNER JOIN Edition + ON LicenseToEdition.EditionId = Edition.Id + WHERE LicenseToEdition.LicenseId = @iLicenseId + -- remove the trailing comma-separator from the edition-string + -- AMI SET @sEdition = SUBSTRING(@sEdition,1,LEN(@sEdition)-1); + IF LEN(@sEdition)> 1 + -- remove the trailing comma-separator from the edition-string + SET @sEdition = SUBSTRING(@sEdition,1,LEN(@sEdition)-1) + ELSE + SET @sEdition = @sEdition + + -- insert into the temporary table + INSERT INTO #SubscribedLicenseReport + (AccountNumber, LicenseeName, LicenseType, InstitutionName, Edition, ValidFrom, ValidThrough,LicenseCreationDate, Price, AccountType,CardNumber) + VALUES(@sAccountNumber,@sLicenseeName,@sLicenseType,@sInstitutionName,@sEdition,@dtStartDate,@dtEndDate,@dtLicenseCreationDate,@mSubscriptionPrice,@sAccountType,@iCardNumber) + END + -- fetch the next record from cursor + FETCH NEXT FROM @cGetLicenseID INTO @iLicenseId,@iLicenseSubscriptionDetail + -- end of while loop + END + -- close the cursor to free up resources + CLOSE @cGetLicenseID + DEALLOCATE @cGetLicenseID + + -- Selecting the desired result from temporary table + --SELECT AccountNumber, LicenseeName, LicenseType,InstitutionName, AccountType, Edition, + --CONVERT(VARCHAR,ValidFrom,101) as StartDate, CONVERT(VARCHAR,ValidThrough,101) as EndDate, + --CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, + --CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice,CardNumber + --FROM #SubscribedLicenseReport ORDER BY AccountNumber + + + SELECT RowNum, AccountNumber, LicenseeName, LicenseType,InstitutionName, AccountType, Edition, + StartDate, EndDate, + LicenseCreationDate, + SubscriptionPrice,CardNumber + from ( + SELECT ROW_NUMBER() OVER (ORDER BY AccountNumber) AS RowNum, AccountNumber, LicenseeName, LicenseType,InstitutionName, AccountType, Edition, + CONVERT(VARCHAR,ValidFrom,101) as StartDate, CONVERT(VARCHAR,ValidThrough,101) as EndDate, + CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, + CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice,CardNumber + FROM #SubscribedLicenseReport) as Tempt + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo + ORDER BY AccountNumber + + select @recordCount = count(ResultTable.AccountNumber) + from ( + SELECT AccountNumber, LicenseeName, LicenseType,InstitutionName, AccountType, Edition, + CONVERT(VARCHAR,ValidFrom,101) as StartDate, CONVERT(VARCHAR,ValidThrough,101) as EndDate, + CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, + CONVERT(NUMERIC(14,2),Price) as SubscriptionPrice,CardNumber + FROM #SubscribedLicenseReport) as ResultTable + + -- Dropping the temporary table + DROP TABLE #SubscribedLicenseReport +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetUsageReport.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetUsageReport.sql new file mode 100644 index 0000000..34f51e3 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetUsageReport.sql @@ -0,0 +1,143 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetUsageReport]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetUsageReport] +GO + +CREATE PROCEDURE [dbo].[usp_GetUsageReport] + -- Add the parameters for the stored procedure here + -- FromDate & ToDate are mandatory parameters + @sFromDate varchar(20), @sToDate varchar(20), @sAccoutNumber varchar(50)='', + @sZip varchar(20) = '', @iState int, @iCountry int, + @pageNo int, @pageLength int, @recordCount int out +AS +BEGIN + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + SET NOCOUNT ON + DECLARE @cGetUserDetails CURSOR + DECLARE @iUserId INT + DECLARE @sAccountNumber VARCHAR(50) + DECLARE @iCardNumber INT + DECLARE @sLoginId VARCHAR(50) + DECLARE @sFirstName VARCHAR(100) + DECLARE @sLastName VARCHAR(100) + DECLARE @sUserType VARCHAR(50) + DECLARE @dtFromDate DATETIME + DECLARE @dtToDate DATETIME + DECLARE @dtLicenseCreationDate DATETIME + DECLARE @sLicenseState VARCHAR(50) + DECLARE @sLicenseZip VARCHAR(20) + DECLARE @sLicenseCountry VARCHAR(50) + DECLARE @sInstitutionName VARCHAR(100) + DECLARE @iTotalLogins INT + DECLARE @dtLastLogin DATETIME + + -- convert the datatype of fromdate & todate parameter to datetime + SELECT @dtFromDate = CONVERT(DATETIME,@sFromDate) + SELECT @dtToDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sToDate))) + + -- create a temporary table to store the results of users logged into the system within a particular time period + CREATE TABLE #UsageReport + ( + LoginId VARCHAR(50), + FirstName VARCHAR(100), + LastName VARCHAR(100), + AccountNumber VARCHAR(50), + CardNumber INT, + UserType VARCHAR(50), + LicenseCreationDate DATETIME, + LicenseState VARCHAR(50), + LicenseZip VARCHAR(20), + LicenseCountry VARCHAR(50), + InstitutionName VARCHAR(100), + TotalLogins INT, + LastLoginDate DATETIME + ) + + -- define the forward only, read-only cursor + SET @cGetUserDetails = CURSOR FAST_FORWARD + FOR + SELECT LoginDetail.UserId, COUNT(1) as TotalLogins, MAX(LoginDetail.LoginTime) + FROM LoginDetail WHERE + (LoginTime) BETWEEN @dtFromDate AND @dtToDate + GROUP BY LoginDetail.UserId + + -- open & fetch the cursor variables into the local variables + OPEN @cGetUserDetails + FETCH NEXT FROM @cGetUserDetails INTO @iUserId, @iTotalLogins, @dtLastLogin + -- start of while loop + WHILE @@FETCH_STATUS = 0 + BEGIN + -- fetch account number, state, zip, country of the license to which the user is belonged + SELECT @sAccountNumber = License.AccountNumber, + @dtLicenseCreationDate = License.CreationDate, + @sInstitutionName = License.InstitutionName, + @sLicenseState = State.StateName, + @sLicenseZip = License.Zip, + @sLicenseCountry = Country.CountryName, + @iCardNumber = (CASE WHEN License.CardNumber > 0 THEN License.CardNumber END) + FROM AIAUserToLicenseEdition + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id + INNER JOIN State ON License.StateId = State.Id + INNER JOIN Country ON License.CountryId = Country.Id + WHERE AIAUserToLicenseEdition.UserId = @iUserId + AND License.IsActive = 1 + AND License.AccountNumber = (CASE WHEN LEN(@sAccoutNumber)>0 THEN @sAccoutNumber ELSE License.AccountNumber END) + AND State.Id = (CASE WHEN @iState > 0 THEN @iState ELSE State.Id END) + AND Country.Id = (CASE WHEN @iCountry > 0 THEN @iCountry ELSE Country.Id END) + AND License.Zip = (CASE WHEN LEN(@sZip)>0 THEN @sZip ELSE License.Zip END) + --AND License.LicenseTypeId <> 5 + --AND License.Country = (CASE WHEN LEN(@sCountry)>0 THEN @sCountry ELSE License.Country END) + + -- check whether the above query returns any row + IF @@Rowcount > 0 + BEGIN + -- fetch loginid, firstname, lastname, usertype of the user + SELECT @sLoginId = AIAUser.LoginId, @sFirstName = AIAUser.Firstname, + @sLastName = AIAUser.LastName, @sUserType = UserType.Title + FROM AIAUser + INNER JOIN UserType ON AIAUser.UserTypeId = UserType.Id + WHERE AIAUser.Id = @iUserId + AND AIAUser.IsActive = 1 + + IF @@Rowcount > 0 + BEGIN + -- insert into the temporary table + INSERT INTO #UsageReport + (LoginId, FirstName, LastName, AccountNumber,CardNumber ,UserType,LicenseCreationDate, LicenseState, LicenseZip, + LicenseCountry,InstitutionName, TotalLogins, LastLoginDate) + VALUES(@sLoginId, @sFirstName, @sLastName, @sAccountNumber, @iCardNumber, @sUserType,@dtLicenseCreationDate, + @sLicenseState, @sLicenseZip, @sLicenseCountry,@sInstitutionName, @iTotalLogins, @dtLastLogin) + END + END + -- fetch the next record from cursor + FETCH NEXT FROM @cGetUserDetails INTO @iUserId, @iTotalLogins, @dtLastLogin + -- end of while loop + END + -- close the cursor to free up resources + CLOSE @cGetUserDetails + DEALLOCATE @cGetUserDetails + + -- Selecting the desired result from temporary table + --SELECT LoginId, FirstName, LastName, AccountNumber, CardNumber,UserType,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, LicenseZip, LicenseState, + --LicenseCountry,InstitutionName, TotalLogins, CONVERT(VARCHAR,LastLoginDate,101) as LastLogin FROM #UsageReport ORDER BY AccountNumber + + Select RowNum,LoginId, FirstName, LastName, AccountNumber, CardNumber,UserType,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, LicenseZip, LicenseState, + LicenseCountry,InstitutionName, TotalLogins, LastLogin + from ( + SELECT ROW_NUMBER() OVER (ORDER BY LoginId) AS RowNum ,LoginId, FirstName, LastName, AccountNumber, CardNumber,UserType,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, LicenseZip, LicenseState, + LicenseCountry,InstitutionName, TotalLogins, CONVERT(VARCHAR,LastLoginDate,101) as LastLogin FROM #UsageReport) as usr + WHERE RowNum > @pageLength * (@pageNo - 1) AND RowNum <= @pageLength * @pageNo order by AccountNumber + + + --Calculate total number of records + select @recordCount = count(ResultTable.LoginId) from (SELECT LoginId, FirstName, LastName, AccountNumber, CardNumber,UserType,CONVERT(VARCHAR,LicenseCreationDate,101) as LicenseCreationDate, LicenseZip, LicenseState, + LicenseCountry,InstitutionName, TotalLogins, CONVERT(VARCHAR,LastLoginDate,101) as LastLogin FROM #UsageReport) as ResultTable; + -- Dropping the temporary table + DROP TABLE #UsageReport +END + + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetUserTyeByAccountNumber.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetUserTyeByAccountNumber.sql new file mode 100644 index 0000000..ee351f0 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_GetUserTyeByAccountNumber.sql @@ -0,0 +1,53 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetUserTyeByAccountNumber]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetUserTyeByAccountNumber] +GO + +CREATE PROCEDURE [dbo].[usp_GetUserTyeByAccountNumber] + -- Add the parameters for the stored procedure here + @iUserTypeId tinyint, @iLicenseId int +AS +BEGIN + -- returns the metadata + IF 1=0 BEGIN + SET FMTONLY OFF + END + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + DECLARE @sUserType varchar(50) + DECLARE @sLicenseType varchar(50) + -- create a temporary table to store the usertype according to the role and accountnumber + CREATE TABLE #UserTypeToAccountNumber + ( + Id tinyint, + Title varchar(50) + ) + + --SELECT @sUserType = Title FROM UserType WHERE Id = @iUserTypeId + + IF @iLicenseId = 0 + BEGIN + IF @iUserTypeId = 1 + BEGIN + INSERT INTO #UserTypeToAccountNumber SELECT Id, Title FROM UserType WHERE Title = 'General Admin' AND IsActive = 1 + END + END + ELSE + BEGIN + SELECT @sLicenseType = LicenseType.Title FROM License INNER JOIN LicenseType ON LicenseType.Id = License.LicenseTypeId + WHERE License.Id = @iLicenseId + IF @sLicenseType = 'Site License' + BEGIN + INSERT INTO #UserTypeToAccountNumber SELECT Id, Title FROM UserType WHERE Title IN ('Client Admin', 'District Admin') + END + ELSE IF @sLicenseType = 'Concurrent License' + BEGIN + INSERT INTO #UserTypeToAccountNumber SELECT Id, Title FROM UserType WHERE Title IN ('Client Admin', 'Concurrent User') ORDER BY Priority ASC + END + END + SELECT Id,Title FROM #UserTypeToAccountNumber + -- Dropping the temporary table + DROP TABLE #UserTypeToAccountNumber +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertAIAUser.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertAIAUser.sql new file mode 100644 index 0000000..bd4d1d8 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertAIAUser.sql @@ -0,0 +1,103 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_InsertAIAUser]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_InsertAIAUser] +GO + +CREATE PROCEDURE [dbo].[usp_InsertAIAUser] + -- Add the parameters for the stored procedure here + @sLoginId varchar(50), @sPassword varchar(50), @sFirstname varchar(50), @sLastname varchar(50), + @iUserTypeId tinyint, @sEmailId varchar(50), @iSecurityQuesId tinyint, @sSecurityAnswer varchar(50)='', + @iCreatorId int, @iLicenseId int, @iEditionId tinyint,@Status int out +AS +BEGIN + + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + BEGIN TRY + BEGIN TRANSACTION + DECLARE @iLicenseEditionId int + + DECLARE @iAIAUserId int + DECLARE @iActive tinyint + DECLARE @dtCurrentDate datetime + DECLARE @sErrorStatus char(2) + DECLARE @sInvalidLicenseToEdition varchar(100) + -- to store the user type id of general admin + DECLARE @iGAUserTypeId tinyint + -- to store the role id of general admin + DECLARE @iGARoleId tinyint + set @Status = 0; + -- set the parameters to default values + SET @iActive = 1 + SET @dtCurrentDate = getdate() + SET @sErrorStatus = 'oks' + SET @sInvalidLicenseToEdition = 'Edition does not exists for this license.' + + -- fetch the usertype id of the general admin + SELECT @iGAUserTypeId = Id FROM UserType WHERE Title = 'General Admin' + -- fetch the role id of the general admin + SELECT @iGARoleId = Id FROM Role WHERE Title = 'General Admin Role' + + IF @iSecurityQuesId = 0 + BEGIN + SET @iSecurityQuesId = NULL + END + IF LEN(@sSecurityAnswer) = 0 + BEGIN + SET @sSecurityAnswer = NULL + END + -- insert the user detail in AIAUser + if (Select count(*) from AIAUser Where LoginId=@sLoginId)>0 + begin + set @Status=1 -- UserName Already Exist + end + else if (Select count(*) from AIAUser Where EmailId=@sEmailId)>0 + begin + set @Status=2 -- Email Id Already Exist + end + else + begin + INSERT INTO AIAUser(LoginId, Password, Firstname, Lastname, UserTypeId, EmailId, IsActive, SecurityQuestionId, + SecurityAnswer, CreatorId, CreationDate, ModifierId, ModifiedDate) VALUES(@sLoginId, @sPassword, @sFirstname, + @sLastname, @iUserTypeId, @sEmailId, @iActive, @iSecurityQuesId, @sSecurityAnswer, + @iCreatorId, @dtCurrentDate, @iCreatorId, @dtCurrentDate) + SET @iAIAUserId = SCOPE_IDENTITY() + -- if user type is general admin then inserts map its role with newly generated UserId + IF @iUserTypeId = @iGAUserTypeId + BEGIN + -- insert the mapping of user with role into AIAUserActivity + INSERT INTO AIAUserActivity(UserId, RoleId) VALUES(@iAIAUserId, @iGARoleId) + END + ELSE + BEGIN + -- select the id of edition mapped with the license id + SELECT @iLicenseEditionId = LicenseToEdition.Id FROM LicenseToEdition + WHERE LicenseToEdition.LicenseId = @iLicenseId AND LicenseToEdition.EditionId = @iEditionId + IF @@ROWCOUNT = 0 + BEGIN + RAISERROR(@sInvalidLicenseToEdition,16,61) + END + -- insert the mapping of user with license edition into AIAUserToLicenseEdition + INSERT INTO AIAUserToLicenseEdition(UserId, LicenseEditionId) VALUES(@iAIAUserId, @iLicenseEditionId) + END + set @Status=3 + End + + COMMIT TRANSACTION + --Print @Status + --SELECT @sErrorStatus as SPStatus + SELECT @Status as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + --set @Status=4 + --SELECT @Status as SPStatus + --SELECT Error_Message() as SPStatus + + END CATCH + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertNewDiscount.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertNewDiscount.sql new file mode 100644 index 0000000..8539bc1 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertNewDiscount.sql @@ -0,0 +1,53 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_InsertNewDiscount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_InsertNewDiscount] +GO + +CREATE PROCEDURE [dbo].[usp_InsertNewDiscount] + -- Add the parameters for the stored procedure here + @dPercentage DECIMAL(5,2), @sStartDate VARCHAR(20), @sEndDate VARCHAR(20), @sDiscountCode VARCHAR(255)='' +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + BEGIN TRY + BEGIN TRANSACTION + DECLARE @iDiscountId INT, @iDiscountExists INT + DECLARE @iActive TINYINT + DECLARE @dtStartDate DATETIME, @dtEndDate DATETIME + DECLARE @sErrorStatus CHAR(2) + + SET @iActive = 1 + SET @sErrorStatus = 'ok' + + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate))) + + INSERT INTO Discount (Percentage, StartDate, EndDate, IsActive) + VALUES(@dPercentage, @dtStartDate, @dtEndDate, @iActive) + -- to get the last inserted discount id identity value in the current session + SET @iDiscountId = SCOPE_IDENTITY() + + IF @sDiscountCode = '' + BEGIN + SET @sDiscountCode = 'InteractiveAnatomy'+RIGHT('000'+CAST(@iDiscountId AS VARCHAR(10)), 3) + SET @iDiscountExists = (SELECT Id FROM Discount WHERE DiscountCode = @sDiscountCode) + IF @iDiscountExists > 0 + BEGIN + UPDATE Discount SET IsActive = 0 WHERE Id = @iDiscountExists + END + END + UPDATE Discount SET DiscountCode = @sDiscountCode WHERE Id = @iDiscountId + + COMMIT + SELECT @sErrorStatus as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + SELECT Error_Message() as SPStatus + END CATCH + +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertNewLicenseAccount.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertNewLicenseAccount.sql new file mode 100644 index 0000000..aa3c12a --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertNewLicenseAccount.sql @@ -0,0 +1,164 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_InsertNewLicenseAccount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_InsertNewLicenseAccount] +GO + +CREATE PROCEDURE [dbo].[usp_InsertNewLicenseAccount] + -- Add the parameters for the stored procedure here + @sAccountNumber varchar(50), @sLicenseeFname varchar(50), @sLicenseeLname varchar(50), + @iLicenseTypeId tinyint, @iAccountTypeId tinyint, @sInstitutionName varchar(100)='', @sAddress1 varchar(100)='', + @sAddress2 varchar(100)='', @sCity varchar(50)='', @sZip varchar(20)='', @iStateId int, @iCountryId int, + @sPhone varchar(30) = '', @sEmailId varchar(50), @iTotalLogins int, @sStartDate varchar(20), + @sEndDate varchar(20), @sMasterIP varchar(100) = '', @sEditionList varchar(256), @iPrice numeric(14,2),@sProductKey varchar(50), + @sSiteIPTo varchar(100) = '',@sSiteMasterIPTo varchar(100) = '',@iNoofImages int +AS +BEGIN + + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + BEGIN TRY + BEGIN TRANSACTION + DECLARE @cEditionLogins CURSOR + DECLARE @iLicenseId INT + DECLARE @iSiteId INT + DECLARE @iLicenseEditionId INT + DECLARE @iIsDistrictSiteAccount TINYINT + DECLARE @iActive TINYINT + DECLARE @iIsMasterIP TINYINT + DECLARE @iModesty TINYINT + DECLARE @dtStartDate DATETIME + DECLARE @dtEndDate DATETIME + DECLARE @sErrorStatus CHAR(2) + DECLARE @dtCurrentDate DATETIME + DECLARE @sitem VARCHAR(100) + DECLARE @sRecordDelimiter CHAR(1) + DECLARE @sEditionLoginDelimiter CHAR(1) + DECLARE @sCountryCode VARCHAR(10) + DECLARE @iIsInsEditionSelected TINYINT + DECLARE @iIsLibEditionSelected TINYINT + DECLARE @iIsAcademicLibEditionSelected TINYINT + + -- set the parameters to default values + SET @iActive = 1 + SET @iIsMasterIP = 1 + SET @iIsDistrictSiteAccount = 0 + SET @iModesty = 0 + SET @sRecordDelimiter = '|' + SET @sEditionLoginDelimiter = '-' + SET @dtCurrentDate = getdate() + SET @sErrorStatus = 'ok' + SET @iIsInsEditionSelected = 0; + SET @iIsLibEditionSelected = 0; + SET @iIsAcademicLibEditionSelected = 0; + + IF @iStateId = 0 + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + -- set the state to Other if the country is Non-US + SET @sCountryCode = (SELECT CountryCode from Country WHERE Id = @iCountryId) + IF @sCountryCode != 'US' + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate))) + + INSERT INTO License(AccountNumber, LicenseeFirstName, LicenseeLastName, LicenseTypeId, AccountTypeId, + InstitutionName, EmailId, Address1, Address2, City, Zip, StateId, CountryId, Phone, TotalLogins, IsActive, + IsDistrictSiteLicense, CreationDate,ProductId) VALUES (@sAccountNumber, @sLicenseeFname, @sLicenseeLname, @iLicenseTypeId, + @iAccountTypeId, @sInstitutionName, @sEmailId, @sAddress1, @sAddress2, @sCity, @sZip, @iStateId, @iCountryId, + @sPhone, @iTotalLogins, @iActive, @iIsDistrictSiteAccount, @dtCurrentDate,@sProductKey) + -- to get the last inserted license id identity value in the current session + SET @iLicenseId = SCOPE_IDENTITY() + + INSERT INTO LicenseSubscriptionDetail(LicenseId, SubscriptionValidFrom, SubscriptionValidThrough, + TotalAmount, AmountPaid,NoofImages) VALUES(@iLicenseId, @dtStartDate, @dtEndDate, @iPrice, @iPrice,@iNoofImages) + + -- check if license is site license + IF @iLicenseTypeId = 3 + BEGIN + INSERT INTO Site (SiteIP, Title, InstituteName, Address1, Address2, City, Zip, Phone, + StateId, CountryId, IsMaster, IsActive, CreationDate, SiteIPTo, SiteMasterIpTo) + VALUES(@sMasterIP, @sMasterIP, @sInstitutionName, @sAddress1, @sAddress2, @sCity, @sZip, @sPhone, + @iStateId, @iCountryId, @iIsMasterIP, @iActive, @dtCurrentDate,@sSiteIPTo, @sSiteMasterIPTo) + -- to get the last inserted site id identity value in the current session + SET @iSiteId = SCOPE_IDENTITY() + END + + SET @cEditionLogins = CURSOR FAST_FORWARD FOR SELECT item FROM dbo.fnSplit(@sEditionList,@sRecordDelimiter) + OPEN @cEditionLogins + FETCH NEXT FROM @cEditionLogins INTO @sitem + WHILE @@FETCH_STATUS = 0 + BEGIN + INSERT INTO LicenseToEdition(LicenseId, EditionId, TotalLogins, IsModesty) + SELECT @iLicenseId, SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1), + SUBSTRING(@sitem,CHARINDEX(@sEditionLoginDelimiter,@sitem)+1,LEN(@sitem)), @iModesty + + -- chekc if selected edition is instructor or library edition + IF SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1) <= 4 + BEGIN + SET @iIsInsEditionSelected = 1; + END + IF SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1) > 4 + BEGIN + SET @iIsLibEditionSelected = 1; + END + IF SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1) = 9 + BEGIN + SET @iIsAcademicLibEditionSelected = 1; + END + + -- check if license is site license + IF @iLicenseTypeId = 3 + BEGIN + -- to get the last inserted licenseedition id identity value in the current session + SET @iLicenseEditionId = SCOPE_IDENTITY() + INSERT INTO SiteToLicenseEdition (SiteId, LicenseEditionId, IsModesty) VALUES (@iSiteId, @iLicenseEditionId, @iModesty) + END + FETCH NEXT FROM @cEditionLogins INTO @sitem + END + + IF @iIsInsEditionSelected = 1 AND @iIsLibEditionSelected = 1 + BEGIN + -- insert All resource module of license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id in (8,9,10) then 0 else 1 end as Status FROM ResourceModule WHERE ResourceModule.Id <> 13; + END + ELSE IF @iIsInsEditionSelected = 1 AND @iIsLibEditionSelected = 0 + BEGIN + -- insert All resource module of license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id > 7 then 0 else 1 end as Status FROM ResourceModule WHERE ResourceModule.Id <> 13; + END + ELSE IF @iIsInsEditionSelected = 0 AND @iIsLibEditionSelected = 1 + BEGIN + -- insert All resource module of license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id < 11 and ResourceModule.id <> 6 then 0 else 1 end as Status FROM ResourceModule WHERE ResourceModule.Id <> 13; + END + + IF @iIsAcademicLibEditionSelected = 1 + BEGIN + -- insert ADAM Image Resouce to license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, 1 as Status FROM ResourceModule WHERE ResourceModule.Id = 13; + END + ELSE + BEGIN + -- insert ADAM Image Resouce to license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, 0 as Status FROM ResourceModule WHERE ResourceModule.Id = 13; + END + + + COMMIT TRANSACTION + SELECT @sErrorStatus as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + SELECT Error_Message() as SPStatus + END CATCH + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertSingleLicenseAccount.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertSingleLicenseAccount.sql new file mode 100644 index 0000000..ed7a79c --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertSingleLicenseAccount.sql @@ -0,0 +1,166 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_InsertSingleLicenseAccount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_InsertSingleLicenseAccount] +GO + +CREATE PROCEDURE [dbo].[usp_InsertSingleLicenseAccount] + -- Add the parameters for the stored procedure here + @sAccountNumber varchar(50), @sLicenseeFname varchar(50), @sLicenseeLname varchar(50), @iAccountTypeId tinyint, + @sInstitutionName varchar(100)='', @sAddress1 varchar(100)='', @sAddress2 varchar(100)='', @sCity varchar(50)='', + @sZip varchar(20)='', @iStateId int, @iCountryId int, @sPhone varchar(30)='', @sEmailId varchar(50), @iTotalLogins int, + @sStartDate varchar(20), @sEndDate varchar(20), @sEditionList varchar(256), @iPrice numeric(14,2),@sProductKey varchar(50), + @sLoginId varchar(50), @sPassword varchar(50), @iSecurityQuesId tinyint, @sSecurityAnswer varchar(50), @iCreatorId int,@iNoofImages int +AS +BEGIN + + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + BEGIN TRY + BEGIN TRANSACTION + DECLARE @cEditionLogins CURSOR + DECLARE @iLicenseId INT + DECLARE @iSiteId INT + DECLARE @iLicenseEditionId INT + DECLARE @iIsDistrictSiteAccount TINYINT + DECLARE @iLicenseTypeId TINYINT + DECLARE @iUserTypeId TINYINT + DECLARE @iAIAUserId INT + DECLARE @iActive TINYINT + DECLARE @iIsMasterIP TINYINT + DECLARE @iModesty TINYINT + DECLARE @dtStartDate DATETIME + DECLARE @dtEndDate DATETIME + DECLARE @sErrorStatus CHAR(2) + DECLARE @dtCurrentDate DATETIME + DECLARE @sitem VARCHAR(100) + DECLARE @sRecordDelimiter CHAR(1) + DECLARE @sEditionLoginDelimiter CHAR(1) + DECLARE @sCountryCode VARCHAR(10) + DECLARE @iIsInsEditionSelected TINYINT + DECLARE @iIsLibEditionSelected TINYINT + DECLARE @iIsAcademicLibEditionSelected TINYINT + + -- set the parameters to default values + SET @iActive = 1 + SET @iIsDistrictSiteAccount = 0 + SET @iModesty = 0 + SET @sRecordDelimiter = '|' + SET @sEditionLoginDelimiter = '-' + SET @dtCurrentDate = getdate() + SET @sErrorStatus = 'ok' + SET @iIsInsEditionSelected = 0; + SET @iIsLibEditionSelected = 0; + SET @iIsAcademicLibEditionSelected = 0; + + IF @iStateId = 0 + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + -- set the state to Other if the country is Non-US + SET @sCountryCode = (SELECT CountryCode from Country WHERE Id = @iCountryId) + IF @sCountryCode != 'US' + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + IF @iSecurityQuesId = 0 + BEGIN + SET @iSecurityQuesId = NULL + END + IF LEN(@sSecurityAnswer) = 0 + BEGIN + SET @sSecurityAnswer = NULL + END + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate))) + + -- fetch the licensetypeid of the single license + SELECT @iLicenseTypeId = Id from LicenseType WHERE Title = 'Single License' + -- fetch the usertypeid of the single user + SELECT @iUserTypeId = Id from UserType WHERE Title = 'Single User' + + + INSERT INTO License(AccountNumber, LicenseeFirstName, LicenseeLastName, LicenseTypeId, AccountTypeId, + InstitutionName, EmailId, Address1, Address2, City, Zip, StateId, CountryId, Phone, TotalLogins, IsActive, + IsDistrictSiteLicense, CreationDate,ProductId) VALUES (@sAccountNumber, @sLicenseeFname, @sLicenseeLname, @iLicenseTypeId, + @iAccountTypeId, @sInstitutionName, @sEmailId, @sAddress1, @sAddress2, @sCity, @sZip, @iStateId, @iCountryId, + @sPhone, @iTotalLogins, @iActive, @iIsDistrictSiteAccount, @dtCurrentDate,@sProductKey) + -- to get the last inserted license id identity value in the current session + SET @iLicenseId = SCOPE_IDENTITY() + + INSERT INTO LicenseSubscriptionDetail(LicenseId, SubscriptionValidFrom, SubscriptionValidThrough, + TotalAmount, AmountPaid,NoofImages) VALUES(@iLicenseId, @dtStartDate, @dtEndDate, @iPrice, @iPrice ,@iNoofImages) + + SET @cEditionLogins = CURSOR FAST_FORWARD FOR SELECT item FROM dbo.fnSplit(@sEditionList,@sRecordDelimiter) + OPEN @cEditionLogins + FETCH NEXT FROM @cEditionLogins INTO @sitem + WHILE @@FETCH_STATUS = 0 + BEGIN + INSERT INTO LicenseToEdition(LicenseId, EditionId, TotalLogins, IsModesty) + SELECT @iLicenseId, SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1), + SUBSTRING(@sitem,CHARINDEX(@sEditionLoginDelimiter,@sitem)+1,LEN(@sitem)), @iModesty + + -- chekc if selected edition is instructor or library edition + IF SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1) <= 4 + BEGIN + SET @iIsInsEditionSelected = 1; + END + IF SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1) > 4 + BEGIN + SET @iIsLibEditionSelected = 1; + END + IF SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1) = 9 + BEGIN + SET @iIsAcademicLibEditionSelected = 1; + END + + FETCH NEXT FROM @cEditionLogins INTO @sitem + END + SET @iLicenseEditionId = SCOPE_IDENTITY() + INSERT INTO AIAUser(LoginId, Password, Firstname, Lastname, UserTypeId, EmailId, IsActive, SecurityQuestionId, SecurityAnswer, + CreatorId, CreationDate, ModifierId, ModifiedDate) VALUES(@sLoginId, @sPassword, @sLicenseeFname, @sLicenseeLname, + @iUserTypeId, @sEmailId, @iActive, @iSecurityQuesId, @sSecurityAnswer, @iCreatorId, @dtCurrentDate, @iCreatorId, @dtCurrentDate) + SET @iAIAUserId = SCOPE_IDENTITY() + + INSERT INTO AIAUserToLicenseEdition(UserId, LicenseEditionId) VALUES(@iAIAUserId, @iLicenseEditionId) + + IF @iIsInsEditionSelected = 1 AND @iIsLibEditionSelected = 1 + BEGIN + -- insert All resource module of license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id in (8,9,10) then 0 else 1 end as Status FROM ResourceModule WHERE ResourceModule.Id <> 13; + END + ELSE IF @iIsInsEditionSelected = 1 AND @iIsLibEditionSelected = 0 + BEGIN + -- insert All resource module of license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id > 7 then 0 else 1 end as Status FROM ResourceModule WHERE ResourceModule.Id <> 13; + END + ELSE IF @iIsInsEditionSelected = 0 AND @iIsLibEditionSelected = 1 + BEGIN + -- insert All resource module of license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id < 11 and ResourceModule.id <> 6 then 0 else 1 end as Status FROM ResourceModule WHERE ResourceModule.Id <> 13; + END + + IF @iIsAcademicLibEditionSelected = 1 + BEGIN + -- insert ADAM Image Resouce to license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, 1 as Status FROM ResourceModule WHERE ResourceModule.Id = 13; + END + ELSE + BEGIN + -- insert ADAM Image Resouce to license + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, 0 as Status FROM ResourceModule WHERE ResourceModule.Id = 13; + END + + COMMIT TRANSACTION + SELECT @sErrorStatus as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + SELECT Error_Message() as SPStatus + END CATCH + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertTestLicenseAccount.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertTestLicenseAccount.sql new file mode 100644 index 0000000..d10912d --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_InsertTestLicenseAccount.sql @@ -0,0 +1,110 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_InsertTestLicenseAccount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_InsertTestLicenseAccount] +GO + +CREATE PROCEDURE [dbo].[usp_InsertTestLicenseAccount] + -- Add the parameters for the stored procedure here + @sAccountNumber varchar(50), @sLicenseeFname varchar(50), @sLicenseeLname varchar(50), @sLoginId varchar(50), @sPassword varchar(50), + @sEmailId varchar(50), @iAccountTypeId tinyint, @iEditionId tinyint, @sAddress varchar(100)='', @sCity varchar(50)='', + @sZip varchar(20)='', @iStateId int, @iCountryId int, @sPhone varchar(30)='', @sStartDate varchar(20), @sEndDate varchar(20), @iCreatorId int ,@iNoofImages int +AS +BEGIN + + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + BEGIN TRY + BEGIN TRANSACTION + DECLARE @iLicenseId int + DECLARE @iLicenseEditionId int + DECLARE @iAIAUserId int + DECLARE @iLicenseTypeId tinyint + DECLARE @iUserTypeId tinyint + DECLARE @iAmount tinyint + DECLARE @iTotalLogins tinyint + DECLARE @iActive tinyint + DECLARE @iModesty tinyint + DECLARE @dtStartDate datetime + DECLARE @dtEndDate datetime + DECLARE @sErrorStatus char(2) + DECLARE @dtCurrentDate datetime + DECLARE @sCountryCode VARCHAR(10) + + -- set the parameters to default values + SET @iTotalLogins = 1 + SET @iActive = 1 + SET @iAmount = 0 + SET @iModesty = 0 + SET @dtCurrentDate = getdate() + SET @sErrorStatus = 'ok' + + IF @iStateId = 0 + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + -- set the state to Other if the country is Non-US + SET @sCountryCode = (SELECT CountryCode from Country WHERE Id = @iCountryId) + IF @sCountryCode != 'US' + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + + -- fetch the licensetypeid of the test account license + SELECT @iLicenseTypeId = Id from LicenseType WHERE Title = 'Test Account License' + -- fetch the usertypeid of the test account user + SELECT @iUserTypeId = Id from UserType WHERE Title = 'Test Account' + + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate))) + + INSERT INTO License(AccountNumber, LicenseeFirstName, LicenseeLastName, LicenseTypeId, AccountTypeId, + EmailId, Address1, City, Zip, StateId, CountryId, Phone, TotalLogins, IsActive, IsDistrictSiteLicense, + CreationDate) VALUES (@sAccountNumber, @sLicenseeFname, @sLicenseeLname, @iLicenseTypeId, @iAccountTypeId, + @sEmailId, @sAddress, @sCity, @sZip, @iStateId, @iCountryId, @sPhone, @iTotalLogins, @iActive, 0, @dtCurrentDate ) + -- to get the last inserted identity value in the current session + SET @iLicenseId = SCOPE_IDENTITY() + + INSERT INTO LicenseSubscriptionDetail(LicenseId, SubscriptionValidFrom, SubscriptionValidThrough, + TotalAmount, AmountPaid, AmountPending ,NoofImages) VALUES(@iLicenseId, @dtStartDate, @dtEndDate, @iAmount, @iAmount, @iAmount ,@iNoofImages) + + IF @iEditionId <= 4 + BEGIN + -- insert All resource module of license for Instructor Edition + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id > 7 then 0 else 1 end as Status FROM ResourceModule; + END + ELSE IF @iEditionId = 8 + BEGIN + -- insert All resource module of license for Library Edition + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id < 11 and ResourceModule.id <> 6 or ResourceModule.id = 13 then 0 else 1 end as Status FROM ResourceModule; + END + ELSE IF @iEditionId = 9 + BEGIN + -- insert All resource module of license for Library Edition + INSERT INTO ModuleToLicense SELECT @iLicenseId as LicenseId,ResourceModule.Id as ModuleId, CASE when ResourceModule.id < 11 and ResourceModule.id <> 6 then 0 else 1 end as Status FROM ResourceModule; + END + + INSERT INTO LicenseToEdition(LicenseId, EditionId, TotalLogins, IsModesty) + VALUES(@iLicenseId, @iEditionId, @iTotalLogins, @iModesty) + SET @iLicenseEditionId = SCOPE_IDENTITY() + + INSERT INTO AIAUser(LoginId, Password, Firstname, Lastname, UserTypeId, EmailId, IsActive, + CreatorId, CreationDate, ModifierId, ModifiedDate) VALUES(@sLoginId, @sPassword, @sLicenseeFname, @sLicenseeLname, + @iUserTypeId, @sEmailId, @iActive, @iCreatorId, @dtCurrentDate, @iCreatorId, @dtCurrentDate) + SET @iAIAUserId = SCOPE_IDENTITY() + + INSERT INTO AIAUserToLicenseEdition(UserId, LicenseEditionId) VALUES(@iAIAUserId, @iLicenseEditionId) + + COMMIT TRANSACTION + SELECT @sErrorStatus as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + SELECT Error_Message() as SPStatus + END CATCH + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateAiaUserPassword.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateAiaUserPassword.sql new file mode 100644 index 0000000..b5b0f25 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateAiaUserPassword.sql @@ -0,0 +1,30 @@ + if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_UpdateAiaUserPassword]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_UpdateAiaUserPassword] +GO + +CREATE PROCEDURE [dbo].[usp_UpdateAiaUserPassword] + -- Add the parameters for the stored procedure here + @Id int, + @NewPassword VARCHAR(50), + @Status bit out +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + set @Status = 0; + BEGIN TRY + BEGIN TRANSACTION + UPDATE AIAUser SET Password= @NewPassword,ModifiedDate=getdate() where Id = @Id; + COMMIT TRANSACTION + set @Status = 1; + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + END CATCH + +END + + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateDiscount.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateDiscount.sql new file mode 100644 index 0000000..91cd7e7 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateDiscount.sql @@ -0,0 +1,37 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_UpdateDiscount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_UpdateDiscount] +GO + +CREATE PROCEDURE [dbo].[usp_UpdateDiscount] + -- Add the parameters for the stored procedure here + @iDiscountId INT, @dPercentage DECIMAL(5,2), @sStartDate VARCHAR(20), @sEndDate VARCHAR(20), @iActive TINYINT, @sDiscountCode VARCHAR(255)='' +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + BEGIN TRY + BEGIN TRANSACTION + DECLARE @dtStartDate DATETIME, @dtEndDate DATETIME + DECLARE @sErrorStatus CHAR(2) + + SET @sErrorStatus = 'ok' + + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate))) + + UPDATE Discount SET Percentage = @dPercentage, StartDate = @dtStartDate, EndDate = @dtEndDate, + IsActive = @iActive, DiscountCode = @sDiscountCode WHERE Id = @iDiscountId + + COMMIT + SELECT @sErrorStatus as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + SELECT Error_Message() as SPStatus + END CATCH + +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateLicenseAccount.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateLicenseAccount.sql new file mode 100644 index 0000000..cd05ecf --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateLicenseAccount.sql @@ -0,0 +1,155 @@ + +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_UpdateLicenseAccount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_UpdateLicenseAccount] +GO + +CREATE PROCEDURE [dbo].[usp_UpdateLicenseAccount] + -- Add the parameters for the stored procedure here + @iLicenseId int, @sLicenseeFname varchar(50), @sLicenseeLname varchar(50), + @iLicenseTypeId tinyint, @iAccountTypeId tinyint, @sInstitutionName varchar(100)='', @sAddress1 varchar(100)='', + @sAddress2 varchar(100)='', @sCity varchar(50)='', @sZip varchar(20)='', @iStateId int, @iCountryId int, + @sPhone varchar(30) = '', @sEmailId varchar(50), @iIsActive tinyint, @iTotalLogins int = 0, @iIsRennew tinyint, + @sStartDate varchar(20), @sEndDate varchar(20), @sRenewDate varchar(20), @sMasterIP varchar(100) = '', + @sEditionList varchar(256), @iPrice numeric(14,2), @sProductKey varchar(50), @sSiteIPTo varchar(100) = '', @sSiteMasterIPTo varchar(100) = '', + @iNoofImages int +AS +BEGIN + + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + BEGIN TRY + BEGIN TRANSACTION + DECLARE @cEditionLogins CURSOR + DECLARE @iSiteId INT + DECLARE @iLicenseEditionId INT + DECLARE @iModesty TINYINT + DECLARE @dtStartDate DATETIME + DECLARE @dtEndDate DATETIME + DECLARE @dtRenewDate DATETIME + DECLARE @sErrorStatus CHAR(2) + DECLARE @dtCurrentDate DATETIME + DECLARE @sitem VARCHAR(100) + DECLARE @sRecordDelimiter CHAR(1) + DECLARE @sEditionLoginDelimiter CHAR(1) + DECLARE @sPaymentMode VARCHAR(10) + DECLARE @iLicenseSubscriptionId INT + DECLARE @iSubscriptionId SMALLINT + DECLARE @dtCancellationDate DATETIME + DECLARE @iEditionExists TINYINT + DECLARE @sCountryCode VARCHAR(10) + + -- set the parameters to default values + SET @iModesty = 0 + SET @sRecordDelimiter = '|' + SET @sEditionLoginDelimiter = '-' + SET @iSubscriptionId = NULL + SET @dtCancellationDate = NULL + SET @dtCurrentDate = getdate() + SET @sPaymentMode = 'CASH' + SET @sErrorStatus = 'ok' + + IF @iStateId = 0 + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + + -- set the state to Other if the country is Non-US + SET @sCountryCode = (SELECT CountryCode from Country WHERE Id = @iCountryId) + IF @sCountryCode != 'US' + BEGIN + SET @iStateId = (SELECT Id FROM State WHERE StateName='Other') + END + + -- convert the datatype of startdate & enddate parameter to datetime + SELECT @dtStartDate = CONVERT(DATETIME,@sStartDate) + SELECT @dtRenewDate = CONVERT(DATETIME,@sRenewDate) + SELECT @dtEndDate = DATEADD(ms,-3,DATEADD(DAY,1,CONVERT(DATETIME,@sEndDate))) + -- if user inactive the license then set the cancellation date to current date + IF @iIsActive = 0 + BEGIN + SET @dtCancellationDate = @dtCurrentDate + END + + UPDATE License SET LicenseeFirstName = @sLicenseeFname, LicenseeLastName = @sLicenseeLname, + AccountTypeId = @iAccountTypeId, InstitutionName = @sInstitutionName, EmailId = @sEmailId, + Address1 = @sAddress1, Address2 = @sAddress2, City = @sCity, Zip = @sZip, StateId = @iStateId, + CountryId = @iCountryId, Phone = @sPhone, TotalLogins = @iTotalLogins, IsActive = @iIsActive, + ModifiedDate = @dtCurrentDate, CancellationDate = @dtCancellationDate, ProductId = @sProductKey WHERE Id = @iLicenseId + + SET @iLicenseSubscriptionId = (SELECT MAX(Id) FROM LicenseSubscriptionDetail WHERE LicenseId = @iLicenseId) + -- if the subscription of license is renew + IF @iIsRennew = 1 + BEGIN + -- check if license is single license + IF @iLicenseTypeId = 2 + BEGIN + SET @iSubscriptionId = (SELECT SubscriptionPlanId FROM LicenseSubscriptionDetail WHERE Id = @iLicenseSubscriptionId) + END + INSERT INTO LicenseSubscriptionDetail(LicenseId, SubscriptionPlanId, SubscriptionValidFrom, + SubscriptionValidThrough, RenewalDate, PaymentMode, TotalAmount, AmountPaid,NoofImages) + VALUES(@iLicenseId, @iSubscriptionId, @dtStartDate, @dtEndDate, @dtRenewDate, @sPaymentMode, @iPrice, @iPrice,@iNoofImages) + UPDATE License SET NoOfRenewals = NoOfRenewals + 1 WHERE Id = @iLicenseId + END + ELSE + BEGIN + UPDATE LicenseSubscriptionDetail SET SubscriptionValidFrom = @dtStartDate, + SubscriptionValidThrough = @dtEndDate, TotalAmount = @iPrice, AmountPaid = @iPrice , NoofImages =@iNoofImages + WHERE Id = @iLicenseSubscriptionId + END + + -- check if license is site license + IF @iLicenseTypeId = 3 + BEGIN + + SET @iSiteId = (SELECT DISTINCT Max(Site.Id) FROM LicenseToEdition + INNER JOIN SiteToLicenseEdition ON LicenseToEdition.Id = SiteToLicenseEdition.LicenseEditionId + INNER JOIN Site ON SiteToLicenseEdition.SiteId = Site.Id + WHERE LicenseToEdition.LicenseId=@iLicenseId AND Site.IsMaster=1 AND Site.IsActive=1) + + UPDATE Site SET SiteIP = @sMasterIP, Title = @sMasterIP, ModifiedDate = @dtCurrentDate, + SiteIPTo = @sSiteIPTo, SiteMasterIPTo = @sSiteMasterIPTo + WHERE Id = @iSiteId + END + + SET @cEditionLogins = CURSOR FAST_FORWARD FOR SELECT item FROM dbo.fnSplit(@sEditionList,@sRecordDelimiter) + OPEN @cEditionLogins + FETCH NEXT FROM @cEditionLogins INTO @sitem + WHILE @@FETCH_STATUS = 0 + BEGIN + SET @iEditionExists = (SELECT 1 FROM LicenseToEdition WHERE LicenseId = @iLicenseId AND EditionId = SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1)) + + IF @iEditionExists IS NULL OR @iEditionExists = 0 + BEGIN + INSERT INTO LicenseToEdition(LicenseId, EditionId, TotalLogins, IsModesty) + SELECT @iLicenseId, SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1), + SUBSTRING(@sitem,CHARINDEX(@sEditionLoginDelimiter,@sitem)+1,LEN(@sitem)), @iModesty + -- check if license is site license + IF @iLicenseTypeId = 3 + BEGIN + -- to get the last inserted licenseedition id identity value in the current session + SET @iLicenseEditionId = SCOPE_IDENTITY() + INSERT INTO SiteToLicenseEdition (SiteId, LicenseEditionId, IsModesty) VALUES (@iSiteId, @iLicenseEditionId, @iModesty) + END + END + ELSE + BEGIN + UPDATE LicenseToEdition SET TotalLogins = SUBSTRING(@sitem,CHARINDEX(@sEditionLoginDelimiter,@sitem)+1,LEN(@sitem)) + WHERE LicenseId = @iLicenseId + AND EditionId = SUBSTRING(@sitem,1,CHARINDEX(@sEditionLoginDelimiter,@sitem)-1) + END + FETCH NEXT FROM @cEditionLogins INTO @sitem + END + + COMMIT TRANSACTION + SELECT @sErrorStatus as SPStatus + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + SELECT Error_Message() as SPStatus + END CATCH + +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateUserProfile.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateUserProfile.sql new file mode 100644 index 0000000..515f829 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/dbo.usp_UpdateUserProfile.sql @@ -0,0 +1,31 @@ +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_UpdateUserProfile]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_UpdateUserProfile] +GO +CREATE PROCEDURE [dbo].[usp_UpdateUserProfile] + -- Add the parameters for the stored procedure here + @Id int, + @FirstName VARCHAR(100), + @LastName VARCHAR(100), + @EmailId varchar(50), + @Status int out +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + set @Status = 0; + BEGIN TRY + BEGIN TRANSACTION + UPDATE AIAUser SET FirstName= @FirstName, LastName= @LastName, EmailId = @EmailId + where Id = @Id; + COMMIT TRANSACTION + set @Status = 1; + END TRY + BEGIN CATCH + IF @@TRANCOUNT > 0 + ROLLBACK TRANSACTION + END CATCH + +END + diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/usp_GetSiteAccountAdmin.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/usp_GetSiteAccountAdmin.sql new file mode 100644 index 0000000..e83c2b0 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/usp_GetSiteAccountAdmin.sql @@ -0,0 +1,41 @@ +USE [AIADatabaseV5] +GO +/****** Object: StoredProcedure [dbo].[usp_GetSiteAccountAdmin] Script Date: 2/1/2018 12:15:55 PM ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: magic +-- Create date: 5/6/2018 +-- Description: Fetch building level accounts client admins for corresponding given Account Number. +-- ============================================= + +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetSiteAccountAdmin]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetSiteAccountAdmin] +GO + +CREATE PROCEDURE [dbo].[usp_GetSiteAccountAdmin] + -- Add the parameters for the stored procedure here + @AccountNumber varchar(50)='' + +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + SELECT AIAUser.Id, AIAUser.Password, AIAUser.LoginId, AIAUser.FirstName, AIAUser.UserTypeId, AIAUser.LastName, AIAUser.EmailId, AIAUser.IsActive, + AIAUser.SecurityQuestionId, AIAUser.SecurityAnswer, AIAUser.CreatorId, AIAUser.CreationDate, AIAUser.ModifierId, AIAUser.ModifiedDate, + AIAUser.DeactivationDate + FROM AIAUser + INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId + INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id + INNER JOIN License ON LicenseToEdition.LicenseId = License.Id + WHERE (AIAUser.IsActive = 1) AND (License.AccountNumber = @AccountNumber) AND (AIAUser.UserTypeId = 4); + +END + + + +GO diff --git a/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/usp_GetSiteAccountSites.sql b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/usp_GetSiteAccountSites.sql new file mode 100644 index 0000000..44a20c5 --- /dev/null +++ b/500-DBDump/AIA-StoredProcedures/ADMIN-ANGULAR-VERSION-PROCS/usp_GetSiteAccountSites.sql @@ -0,0 +1,67 @@ +USE [AIADatabaseV5] +GO +/****** Object: StoredProcedure [dbo].[usp_GetSiteAccountSites] Script Date: 2/1/2018 12:15:55 PM ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +-- ============================================= +-- Author: magic +-- Create date: 5/6/2018 +-- Description: Fetch building level accounts details for corresponding given Account Number. +-- ============================================= + +if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetSiteAccountSites]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) +drop procedure [dbo].[usp_GetSiteAccountSites] +GO + +CREATE PROCEDURE [dbo].[usp_GetSiteAccountSites] + -- Add the parameters for the stored procedure here + @strAccountNumber varchar(50)='', @pageNo int, @pageLength int, @recordCount int out + +AS +BEGIN + -- SET NOCOUNT ON added to prevent extra result sets from + -- interfering with SELECT statements. + SET NOCOUNT ON; + + --Get the records on the basis of parameters page length and page number rows + select LD.Id, LD.SiteIp, LD.Title, LD.SiteIPTo, LD.SiteMasterIPTo, LD.CreationDate, LD.ModifiedDate, LD.InstituteName, + LD.Department, LD.UserId, LD.FirstName, LD.EmailId + from + (Select ROW_NUMBER() OVER (ORDER BY Site.Id) AS RowNo, + Site.Id,Site.SiteIp,Site.Title,ISNULL(Site.SiteIPTo,'') as SiteIPTo,ISNULL(Site.SiteMasterIPTo,'') as SiteMasterIPTo, + CONVERT(VARCHAR,Site.CreationDate,101) as CreationDate, + CONVERT(VARCHAR,Site.ModifiedDate,101) as ModifiedDate, + Site.InstituteName, Site.Department, AIAUser.Id as UserId,AIAUser.FirstName,AIAUser.EmailId + from License join LicenseToEdition on License.Id = LicenseToEdition.LicenseId + join SiteToLicenseEdition on LicenseToEdition.Id = SiteToLicenseEdition.LicenseEditionId + join AIAUserToLicenseEdition on SiteToLicenseEdition.LicenseEditionId = AIAUserToLicenseEdition.LicenseEditionId + join AIAUserToSite on SiteToLicenseEdition.SiteId = AIAUserToSite.SiteId + join Site on SiteToLicenseEdition.SiteId = Site.Id + join AIAUser on AIAUserToLicenseEdition.UserId = AIAUser.Id + where Site.IsActive=1 and License.AccountNumber=@strAccountNumber) + as LD + where + RowNo > @pageLength * (@pageNo - 1) AND + RowNo <= @pageLength * @pageNo + + --Calculate total number of records + select @recordCount = count(ResultTable.Id) from + (Select Site.Id,Site.SiteIp,Site.Title,ISNULL(Site.SiteIPTo,'') as SiteIPTo,ISNULL(Site.SiteMasterIPTo,'') as SiteMasterIPTo, + CONVERT(VARCHAR,Site.CreationDate,101) as CreationDate, + CONVERT(VARCHAR,Site.ModifiedDate,101) as ModifiedDate, + Site.InstituteName, Site.Department, AIAUser.Id as UserId,AIAUser.FirstName,AIAUser.EmailId + from License join LicenseToEdition on License.Id = LicenseToEdition.LicenseId + join SiteToLicenseEdition on LicenseToEdition.Id = SiteToLicenseEdition.LicenseEditionId + join AIAUserToLicenseEdition on SiteToLicenseEdition.LicenseEditionId = AIAUserToLicenseEdition.LicenseEditionId + join AIAUserToSite on SiteToLicenseEdition.SiteId = AIAUserToSite.SiteId + join Site on SiteToLicenseEdition.SiteId = Site.Id + join AIAUser on AIAUserToLicenseEdition.UserId = AIAUser.Id + where Site.IsActive=1 and License.AccountNumber=@strAccountNumber) as ResultTable; + +END + + + +GO