You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.0 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_branchUserList] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_branchUserList]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_branchUserList] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. /*
  12. [proc_agentMaster] @flag = 'bc', @agentId = '1'
  13. [proc_agentMaster] @flag = 's', @user = 'admin', @parentId = 1
  14. */
  15. CREATE PROC [dbo].[proc_branchUserList]
  16. @flag VARCHAR(50) = NULL
  17. ,@user VARCHAR(30) = NULL
  18. ,@agentId INT = NULL
  19. ,@isActAsBranch VARCHAR(10) = NULL
  20. ,@agentType INT = NULL
  21. ,@parentId INT = NULL
  22. ,@agentName VARCHAR(100) = NULL
  23. ,@userName VARCHAR(100) = NULL
  24. ,@sortBy VARCHAR(50) = NULL
  25. ,@sortOrder VARCHAR(5) = NULL
  26. ,@pageSize INT = NULL
  27. ,@pageNumber INT = NULL
  28. AS
  29. SET NOCOUNT ON
  30. DECLARE @glcode VARCHAR(10), @acct_num VARCHAR(20);
  31. CREATE TABLE #tempACnum (acct_num VARCHAR(20));
  32. SET XACT_ABORT ON
  33. BEGIN TRY
  34. CREATE TABLE #msg(errorCode INT, msg VARCHAR(100), id INT)
  35. DECLARE
  36. @sql VARCHAR(MAX)
  37. ,@oldValue VARCHAR(MAX)
  38. ,@newValue VARCHAR(MAX)
  39. ,@tableName VARCHAR(50)
  40. ,@logIdentifier VARCHAR(100)
  41. ,@logParamMain VARCHAR(100)
  42. ,@tableAlias VARCHAR(100)
  43. ,@modType VARCHAR(6)
  44. ,@module INT
  45. ,@select_field_list VARCHAR(MAX)
  46. ,@extra_field_list VARCHAR(MAX)
  47. ,@table VARCHAR(MAX)
  48. ,@sql_filter VARCHAR(MAX)
  49. ,@ApprovedFunctionId INT
  50. SELECT
  51. @logIdentifier = 'userId'
  52. ,@logParamMain = 'applicationUsers'
  53. ,@tableAlias = 'Application User'
  54. ,@module = 20
  55. ,@ApprovedFunctionId = 20101030
  56. IF @flag = 'su'
  57. BEGIN
  58. IF @isActAsBranch ='Y' and @agentType = '2903' -- ## private agents
  59. BEGIN
  60. SET @table = '(
  61. select userId = a.userId
  62. ,agentId = a.agentId
  63. ,userName = a.userName
  64. ,userFullName = isnull(firstName,'''')+'' ''+isnull(middleName,'''')+'' ''+isnull(lastName,'''')
  65. ,address = address
  66. ,countryName = c.countryName
  67. ,agentName = b.agentName
  68. ,agentCode = a.agentCode
  69. ,employeeId = a.employeeId
  70. ,lockStatus = CASE WHEN ISNULL(a.isLocked, ''N'') = ''N'' THEN ''N | <a href="#" onclick="UnlockUser('' + CAST(a.userId AS VARCHAR) + '')">Lock</a>''
  71. WHEN ISNULL(a.isLocked, ''N'') = ''Y'' THEN ''Y | <a href="#" onclick="UnlockUser('' + CAST(a.userId AS VARCHAR) + '')">Unlock</a>'' END
  72. from applicationUsers a with(nolock) inner join agentMaster b with(nolock) on a.agentId=b.agentId
  73. left join countryMaster c with(nolock) on c.countryId=a.countryId
  74. where userName=''' + @user + ''' and isnull(a.isActive,''Y'') = ''Y''
  75. ) x '
  76. END
  77. ELSE IF @agentType = '2904' -- ## Consolidate Bank & Finance
  78. BEGIN
  79. SET @table = '(
  80. select userId = a.userId
  81. ,agentId = a.agentId
  82. ,userName = a.userName
  83. ,userFullName = isnull(firstName,'''') + isnull('' '' + middleName,'''')+ isnull('' '' + lastName,'''')
  84. ,address = address
  85. ,countryName = c.countryName
  86. ,agentName = b.agentName
  87. ,agentCode = a.agentCode
  88. ,employeeId = a.employeeId
  89. ,lockStatus = CASE WHEN ISNULL(a.isLocked, ''N'') = ''N'' THEN ''N'' | <a href="#" onclick="UnlockUser('' + CAST(a.userId AS VARCHAR) + '')">Lock</a>''
  90. WHEN ISNULL(a.isLocked, ''N'') = ''Y'' THEN ''Y'' | <a href="#" onclick="UnlockUser('' + CAST(a.userId AS VARCHAR) + '')">Unlock</a>'' END
  91. from applicationUsers a with(nolock) inner join
  92. (
  93. SELECT agentId,agentName from agentMaster where parentId=''' + CAST(@parentId AS VARCHAR) + '''
  94. )b on a.agentId=b.agentId
  95. left join countryMaster c with(nolock) on c.countryId=a.countryId
  96. where isnull(a.isActive,''Y'') = ''Y''
  97. ) x'
  98. END
  99. --PRINT (@table)
  100. IF @sortBy IS NULL
  101. SET @sortBy = 'userId'
  102. IF @sortOrder IS NULL
  103. SET @sortOrder = 'ASC'
  104. SET @sql_filter = ''
  105. IF @agentName IS NOT NULL
  106. SET @sql_filter = @sql_filter + ' and agentName LIKE ''%' + @agentName + '%'''
  107. IF @userName IS NOT NULL
  108. SET @sql_filter = @sql_filter + ' and userName LIKE ''%' + @userName + '%'''
  109. SET @select_field_list ='
  110. userId
  111. ,agentId
  112. ,userName
  113. ,userFullName
  114. ,address
  115. ,countryName
  116. ,agentName
  117. ,agentCode
  118. ,employeeId
  119. ,lockStatus
  120. '
  121. --select @table
  122. --return;
  123. EXEC dbo.proc_paging
  124. @table
  125. ,@sql_filter
  126. ,@select_field_list
  127. ,@extra_field_list
  128. ,@sortBy
  129. ,@sortOrder
  130. ,@pageSize
  131. ,@pageNumber
  132. END
  133. END TRY
  134. BEGIN CATCH
  135. IF @@TRANCOUNT > 0
  136. ROLLBACK TRANSACTION
  137. SELECT 1 error_code, ERROR_MESSAGE() mes, null id
  138. END CATCH
  139. GO