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.

178 lines
10 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_agentMasterTempReport] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE procEDURE [dbo].[proc_agentMasterTempReport](
  9. @functionID VARCHAR(100)
  10. ,@user VARCHAR(30)
  11. ,@pageFrom INT
  12. ,@pageTo INT
  13. ,@branch INT
  14. ,@agent INT
  15. ,@fxml XML = NULL
  16. ,@qxml XML = NULL
  17. ,@dxml XML = NULL
  18. ,@downloadAll CHAR(1) = NULL
  19. )AS
  20. SET NOCOUNT ON
  21. SET @pageFrom = ISNULL(NULLIF(@pageFrom, 0), 1)
  22. SET @pageTo = ISNULL(@pageTo, @pageFrom)
  23. DECLARE @pageSize INT = 50
  24. IF @functionID='20168100'
  25. BEGIN
  26. DECLARE @fromDate VARCHAR(50),
  27. @toDate varchar(20),
  28. @templateId varchar(20),
  29. @rptType varchar(50),
  30. @fields varchar(max),
  31. @sql varchar(max),
  32. @agentStatus varchar(10),
  33. @agentGrp varchar(10)
  34. SELECT
  35. @fromDate = p.value('@fromdate','VARCHAR(50)')
  36. ,@toDate = p.value('@todate','VARCHAR(50)')
  37. ,@rptType = p.value('@reporttype','VARCHAR(50)')
  38. ,@templateId = p.value('@templateid','VARCHAR(50)')
  39. ,@agentStatus = p.value('@agentstatus','varchar(50)')
  40. ,@agentGrp = p.value('@agentgrp','varchar(50)')
  41. FROM @fxml.nodes('/root/row') AS tmp(p)
  42. SELECT @fields = fieldsAlias FROM ReportTemplate with(nolock) WHERE id = @templateId
  43. SET @sql='
  44. SELECT
  45. '+@fields+'
  46. FROM DBO.vw_agentMaster vam WITH(NOLOCK)
  47. WHERE [Created Date] between '''+@fromDate+''' and '''+@toDate+' 23:59:59'''
  48. IF @agentStatus IS NOT NULL AND @agentStatus IN ('Unblock','Block')
  49. --SET @sql = @sql+ ' AND [Agent Block] ='''+@agentStatus+''' and agentBlock1 = '''+@agentStatus+''' '
  50. SET @sql = @sql+ ' AND [Agent Block] ='''+@agentStatus+''''
  51. IF @agentStatus IS NOT NULL AND @agentStatus IN ('Active','Inactive')
  52. --SET @sql = @sql+ ' AND [Is Active] ='''+@agentStatus+''' and isActive1 = '''+@agentStatus+''''
  53. SET @sql = @sql+ ' AND [Is Active] ='''+@agentStatus+''''
  54. IF @agentGrp IS NOT NULL
  55. SET @sql = @sql+ ' AND agentGrp ='''+@agentGrp+''''
  56. if @rptType ='all-dom'
  57. SET @sql = @sql+ ' AND (agentType = 2904 or (agentType = 2903 and actAsBranch = ''Y'') )
  58. AND isnull(isDeleted,''N'')=''N''
  59. AND parentId <> 5576
  60. AND agentCountry = ''Nepal'''
  61. if @rptType ='all-int'
  62. SET @sql = @sql+ ' AND (agentType = 2904 or (agentType = 2903 and actAsBranch = ''Y'') )
  63. AND isnull(isDeleted,''N'')=''N''
  64. AND parentId <> 5576
  65. AND agentCountry <> ''Nepal'''
  66. if @rptType ='all-sending-dom'
  67. SET @sql = @sql+ ' AND (agentType = 2904 or (agentType = 2903 and actAsBranch = ''Y'') )
  68. AND isnull(isDeleted,''N'')=''N''
  69. AND parentId <> 5576
  70. AND agentCountry = ''Nepal''
  71. AND isnull(agentRole ,''B'') <> ''R'''
  72. if @rptType ='all-sending-int'
  73. SET @sql = @sql+ ' AND (agentType = 2904 or (agentType = 2903 and actAsBranch = ''Y'') )
  74. AND isnull(isDeleted,''N'')=''N''
  75. AND parentId <> 5576
  76. AND agentCountry <> ''Nepal''
  77. AND isnull(agentRole ,''B'') <> ''R'''
  78. if @rptType ='all-sending'
  79. SET @sql = @sql+ ' AND (agentType = 2904 or (agentType = 2903 and actAsBranch = ''Y'') )
  80. AND isnull(isDeleted,''N'')=''N''
  81. AND parentId <> 5576
  82. AND isnull(agentRole ,''B'') <> ''R'''
  83. if @rptType ='all-paying'
  84. SET @sql = @sql+ ' AND (agentType = 2904 or (agentType = 2903 and actAsBranch = ''Y'') )
  85. AND isnull(isDeleted,''N'')=''N''
  86. AND parentId <> 5576
  87. AND isnull(agentRole ,''B'') <> ''S'''
  88. if @rptType ='private-agent'
  89. SET @sql = @sql+ ' AND agentType = 2903
  90. AND actAsBranch = ''Y''
  91. AND isnull(isDeleted,''N'')=''N''
  92. AND parentId <> 5576
  93. AND agentCountry=''Nepal'''
  94. if @rptType ='bank-finance'
  95. SET @sql = @sql+ ' AND agentType = 2904
  96. AND isnull(isDeleted,''N'')=''N''
  97. AND parentId <> 5576
  98. AND agentCountry=''Nepal'''
  99. if @rptType ='college'
  100. SET @sql = @sql+ ' AND agentType = 2903
  101. AND actAsBranch = ''Y''
  102. AND isnull(isDeleted,''N'')=''N''
  103. AND parentId = 5576
  104. AND agentCountry=''Nepal'''
  105. IF @downloadAll = 'y'
  106. BEGIN
  107. SET @sql = '
  108. SELECT
  109. ROW_NUMBER() OVER (ORDER BY [AGENT NAME]) AS [S.N.],*
  110. FROM
  111. (
  112. '+@sql+'
  113. )X '
  114. SET @sql =@sql +'
  115. ORDER BY [AGENT NAME]'
  116. END
  117. ELSE
  118. BEGIN
  119. SET @sql = '
  120. SELECT
  121. *
  122. FROM (
  123. SELECT
  124. ROW_NUMBER() OVER (ORDER BY [AGENT NAME]) AS [S.N.],*
  125. FROM
  126. (
  127. '+@sql+'
  128. )X
  129. )x WHERE [S.N.] BETWEEN (('+CAST(@pageFrom AS VARCHAR)+' - 1) * '+CAST(@pageSize AS VARCHAR)+' + 1) AND '+CAST(@pageTo AS VARCHAR)+' * '+CAST(@pageSize AS VARCHAR)+''
  130. SET @sql =@sql +'
  131. ORDER BY [AGENT NAME]'
  132. END
  133. PRINT(@sql)
  134. EXEC(@sql)
  135. UPDATE #params SET
  136. ReportTitle='Agent Master Report'
  137. ,Filters= 'From Date =' +@fromDate+'|To Date='+@toDate
  138. ,NoHeader = CASE WHEN @pageFrom > 1 THEN 1 ELSE 0 END
  139. ,IncludeSerialNo=0
  140. ,PageNumber=@pageFrom
  141. ,PageSize=@pageSize
  142. ,LoadMode = 2
  143. SELECT * FROM #params
  144. RETURN
  145. END
  146. GO