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.

180 lines
13 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_exchangeRateSystem_Rpt] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. /*
  9. EXEC proc_exchangeRateSystem_Rpt @user = 'admin' ,@cCountry =NULL ,@pCountry = NULL,
  10. @cAgent = NULL, @pAgent = NULL,
  11. @cAgentGroup =NULL, @pAgentGroup =NULL,
  12. @cBranch =NULL, @pBranch = NULL,
  13. @cBranchGroup =NULL, @pBranchGroup = NULL
  14. SELECT * FROM spExRate
  15. */
  16. CREATE procEDURE [dbo].[proc_exchangeRateSystem_Rpt]
  17. @flag AS VARCHAR(50)=NULL
  18. , @user AS VARCHAR(50)=NULL
  19. , @cCountry AS VARCHAR(50)=NULL
  20. , @pCountry AS VARCHAR(50)=NULL
  21. , @cAgent AS VARCHAR(50)=NULL
  22. , @pAgent AS VARCHAR(50)=NULL
  23. , @cAgentGroup AS VARCHAR(50)=NULL
  24. , @pAgentGroup AS VARCHAR(50)=NULL
  25. , @cBranch AS VARCHAR(50)=NULL
  26. , @pBranch AS VARCHAR(50)=NULL
  27. , @cBranchGroup AS VARCHAR(50)=NULL
  28. , @pBranchGroup AS VARCHAR(50)=NULL
  29. , @pageNumber AS VARCHAR(50)=NULL
  30. , @pageSize AS VARCHAR(50)=NULL
  31. AS
  32. SET NOCOUNT ON;
  33. --SET @TODATE = @TODATE + ' 23:59:59'
  34. DECLARE
  35. @NUM INT
  36. ,@ROWNUM INT
  37. ,@CLOSEAMT MONEY
  38. ,@REPORTHEAD VARCHAR(40)
  39. ,@maxReportViewDays INT
  40. SET @NUM=0
  41. SET @pageSize = ISNULL(@pageSize,500)
  42. SET @pageNumber = ISNULL(@pageNumber,1)
  43. SELECT @maxReportViewDays=ISNULL(maxReportViewDays,60) FROM applicationUsers WHERE userName = @user
  44. SELECT ROW_NUMBER() OVER(ORDER BY EX.spExRateId) [S.N.]
  45. ,ISNULL(cast(tranType as varchar),'Any') [Tran Type]
  46. ,B.countryName Collection_Country
  47. ,ISNULL(CAST(CASE WHEN cAgent IS NULL THEN cAgentGroup else cAgent END AS VARCHAR),'All') [Collection_Agent/Group]
  48. ,ISNULL(CAST(CASE WHEN cBranch IS NULL THEN cBranchGroup else cBranch END AS VARCHAR),'All') [Collection_Branch/Group]
  49. ,B1.countryName Payment_Country
  50. ,ISNULL(CAST(CASE WHEN pAgent IS NULL THEN pAgentGroup else pAgent END AS VARCHAR),'All') [Payment_Agent/Group]
  51. ,ISNULL(CAST(CASE WHEN pBranch IS NULL THEN pBranchGroup else pBranch END AS VARCHAR),'All') [Payment_Branch/Group]
  52. ,cCurrency [Collection Rate_Currency]
  53. ,cRate [Collection Rate_Rate]
  54. ,cCurrHOMargin [Collection Rate_HO Margin]
  55. ,cRate-cCurrHOMargin [Collection Rate_Agent Offer]
  56. ,cCurrAgentMargin [Collection Rate_Agent Margin]
  57. ,cRate-cCurrHOMargin+cCurrAgentMargin [Collection Rate_Customer Offer]
  58. ,pCurrency [Payment Rate_Currency]
  59. ,pRate [Payment Rate_Rate]
  60. ,pCurrHOMargin [Payment Rate_HO Margin]
  61. ,pRate-pCurrHOMargin [Payment Rate_Agent Offer]
  62. ,pCurrAgentMargin [Payment Rate_Agent Margin]
  63. ,pRate-pCurrHOMargin+pCurrAgentMargin [Payment Rate_Customer Offer]
  64. ,(pRate-pCurrHOMargin)/(cRate-cCurrHOMargin) [Sattlement Rate]
  65. ,(pRate-pCurrHOMargin+pCurrAgentMargin)/(cRate-cCurrHOMargin+cCurrAgentMargin) [Customer Rate]
  66. ,CAST(HIS.createdDate AS VARCHAR) +':'+HIS.createdBy+'</br>'+CAST(HIS.approvedDate AS VARCHAR)+':'+HIS.approvedBy [Last Update/Approve]
  67. FROM spExRate EX WITH(NOLOCK) INNER JOIN countryMaster B WITH(NOLOCK) ON EX.cCountry=B.countryId
  68. INNER JOIN countryMaster B1 WITH(NOLOCK) ON EX.pCountry=B1.countryId
  69. LEFT JOIN
  70. (
  71. select a.rowId,a.spExRateId,b.createdBy,b.createdDate,b.approvedBy,b.approvedDate from
  72. (
  73. select max(rowId) rowId,spExRateId from spExRateHistory where approvedDate is not null
  74. group by spExRateId
  75. )a
  76. inner join
  77. (
  78. select * from spExRateHistory
  79. )b on a.rowId=b.rowId
  80. )HIS ON HIS.spExRateId=EX.spExRateId
  81. WHERE EX.cCountry =ISNULL(@cCountry,EX.cCountry)
  82. AND ISNULL(EX.cCountry,'') =ISNULL(@cCountry,ISNULL(EX.cCountry,''))
  83. AND ISNULL(EX.pCountry,'') =ISNULL(@pCountry,ISNULL(EX.pCountry,''))
  84. AND ISNULL(EX.cAgent,'') =ISNULL(@cAgent,ISNULL(EX.cAgent,''))
  85. AND ISNULL(EX.pAgent,'') =ISNULL(@pAgent,ISNULL(EX.pAgent,''))
  86. AND ISNULL(EX.cAgentGroup,'') =ISNULL(@cAgentGroup,ISNULL(EX.cAgentGroup,''))
  87. AND ISNULL(EX.pAgentGroup,'') =ISNULL(@pAgentGroup,ISNULL(EX.pAgentGroup,''))
  88. AND ISNULL(EX.cBranch,'') =ISNULL(@cBranch,ISNULL(EX.cBranch,''))
  89. AND ISNULL(EX.pBranch,'') =ISNULL(@pBranch,ISNULL(EX.pBranch,''))
  90. AND ISNULL(EX.cBranchGroup,'') =ISNULL(@cBranchGroup,ISNULL(EX.cBranchGroup,''))
  91. AND ISNULL(EX.pBranchGroup,'') =ISNULL(@pBranchGroup,ISNULL(EX.pBranchGroup,''))
  92. AND EX.approvedDate IS NOT NULL
  93. EXEC proc_errorHandler '0', 'Report has been prepared successfully.', @cAgent
  94. if @cCountry is null
  95. set @cCountry='All'
  96. else
  97. select @cCountry=countryName from countryMaster where countryId=@cCountry
  98. if @pCountry is null
  99. set @pCountry='All'
  100. else
  101. select @pCountry=countryName from countryMaster where countryId=@pCountry
  102. if @cAgent is null
  103. set @cAgent='All'
  104. else
  105. select @cAgent=agentName from agentMaster where agentId=@cAgent
  106. if @pAgent is null
  107. set @pAgent='All'
  108. else
  109. select @pAgent=agentName from agentMaster where agentId=@pAgent
  110. if @cAgentGroup is null
  111. set @cAgentGroup='All'
  112. else
  113. select @cAgentGroup=detailTitle from staticDataValue where valueId=@cAgentGroup
  114. if @pAgentGroup is null
  115. set @pAgentGroup='All'
  116. else
  117. select @pAgentGroup=detailTitle from staticDataValue where valueId=@pAgentGroup
  118. if @pBranch is null
  119. set @pBranch='All'
  120. else
  121. select @pBranch=agentName from agentMaster where agentId=@pBranch
  122. if @cBranch is null
  123. set @cBranch='All'
  124. else
  125. select @cBranch=agentName from agentMaster where agentId=@cBranch
  126. if @cBranchGroup is null
  127. set @cBranchGroup='All'
  128. else
  129. select @cBranchGroup=detailTitle from staticDataValue where valueId=@cBranchGroup
  130. if @pBranchGroup is null
  131. set @pBranchGroup='All'
  132. else
  133. select @pBranchGroup=detailTitle from staticDataValue where valueId=@pBranchGroup
  134. select 'Collection Country' head,@cCountry value
  135. union all
  136. select 'Collection Agent' head,@cAgent value
  137. union all
  138. select 'Collection Agent Group' head,@cAgentGroup value
  139. union all
  140. select 'Collection Branch' head,@cBranch value
  141. union all
  142. select 'Collection Branch Group' head,@cBranchGroup value
  143. union all
  144. select 'Payment Country' head,@pCountry value
  145. union all
  146. select 'Payment Agent' head,@pAgent value
  147. union all
  148. select 'Payment Agent Group' head,@pAgentGroup value
  149. union all
  150. select 'Payment Branch' head,@pBranch value
  151. union all
  152. select 'Payment Branch Group' head,@pBranchGroup value
  153. SELECT 'Exchange Rate System Report' title
  154. GO