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.

137 lines
10 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_serviceChargeReport] 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_serviceChargeReport @flag = 'master', @user = 'admin', @agent = null, @branch = null, @pCountry = null
  10. */
  11. CREATE proc [dbo].[proc_serviceChargeReport]
  12. @flag VARCHAR(50) = NULL
  13. ,@user VARCHAR(30)
  14. ,@branch INT = NULL
  15. ,@sCountry INT = NULL
  16. ,@agent INT = NULL
  17. ,@pCountry INT = NULL
  18. ,@ruleId INT = NULL
  19. ,@sortBy VARCHAR(50) = NULL
  20. ,@sortOrder VARCHAR(5) = NULL
  21. ,@pageSize INT = NULL
  22. ,@pageNumber INT = NULL
  23. AS
  24. SET NOCOUNT ON
  25. SET XACT_ABORT ON
  26. BEGIN TRY
  27. IF @flag = 'master'
  28. BEGIN
  29. --DECLARE @serviceChargeRuleBranchWise TABLE(ruleId INT)
  30. --DECLARE @serviceChargeRuleAgentWise TABLE(ruleId INT)
  31. --DECLARE @serviceChargeRule TABLE(ruleId INT)
  32. --INSERT @serviceChargeRuleBranchWise
  33. --SELECT ruleId FROM agentCommissionRule WITH(NOLOCK)
  34. -- WHERE ruleType = 'sc' AND agentId = @branch AND ISNULL(isActive, 'N') = 'Y'
  35. --INSERT @serviceChargeRuleAgentWise
  36. --SELECT ruleId FROM agentCommissionRule WITH(NOLOCK)
  37. -- WHERE ruleType = 'sc' AND agentId = isnull(@agent,agentId) AND ISNULL(isActive, 'N') = 'Y'
  38. --IF EXISTS(SELECT 'X' FROM sscMaster ssm WITH(NOLOCK)
  39. --INNER JOIN @serviceChargeRuleBranchWise scr ON ssm.sscMasterId = scr.ruleId
  40. --WHERE rCountry = isnull(@pCountry,rCountry) AND ISNULL(ssm.isActive, 'N') = 'Y')
  41. --BEGIN
  42. -- INSERT @serviceChargeRule
  43. -- SELECT * FROM @serviceChargeRuleBranchWise
  44. --END
  45. --ELSE
  46. --BEGIN
  47. -- INSERT @serviceChargeRule
  48. -- SELECT * FROM @serviceChargeRuleAgentWise
  49. --END
  50. --SELECT
  51. -- ssm.sscMasterId
  52. -- ,sCountryName = ISNULL(cm.countryName, 'All')
  53. -- ,sAgentName = sam.agentName
  54. -- ,paymentMethod = ISNULL(stm.typeTitle, 'All')
  55. -- ,baseCurrency
  56. --FROM sscMaster ssm WITH(NOLOCK)
  57. --INNER JOIN @serviceChargeRule scr ON ssm.sscMasterId = scr.ruleId
  58. --inner join agentCommissionRule acomr with(nolock) on acomr.ruleId = ssm.sscMasterId
  59. --inner JOIN countryMaster cm WITH(NOLOCK) ON ssm.sCountry = cm.countryId
  60. --inner JOIN agentMaster sam WITH(NOLOCK) ON acomr.agentId = sam.agentId
  61. --LEFT JOIN serviceTypeMaster stm WITH(NOLOCK) ON ssm.tranType = stm.serviceTypeId
  62. --WHERE rCountry = ISNULL(@pCountry,rCountry) AND ISNULL(ssm.isActive, 'N') = 'Y'
  63. --and acomr.ruleType = 'sc'
  64. ----select * from agentCommissionRule
  65. ----select * from sscMaster
  66. if @sCountry is not null -->> admin panel
  67. begin
  68. select
  69. sc.sscMasterId
  70. ,scCode = sc.code
  71. ,sCountryName = cm.countryName
  72. ,sAgentName = am.agentName +', Payout Agent:'+isnull(am1.agentName,'All')
  73. ,paymentMethod = ISNULL(stm.typeTitle, 'All')
  74. ,baseCurrency = sc.baseCurrency
  75. from agentCommissionRule a with(nolock)
  76. inner join sscMaster sc with(nolock) on a.ruleId = sc.sscMasterId
  77. inner join agentMaster am with(nolock) on a.agentId = am.agentId
  78. left join serviceTypeMaster stm WITH(NOLOCK) ON sc.tranType = stm.serviceTypeId
  79. left join countryMaster cm with(nolock) on cm.countryId = sc.sCountry
  80. left join agentMaster am1 with(nolock) on sc.rAgent = am1.agentId
  81. where a.ruleType = 'sc' and isnull(a.isActive,'Y') = 'Y'
  82. and sc.sCountry = isnull(@sCountry,sc.sCountry)
  83. and a.agentId = isnull(@agent,a.agentId)
  84. order by am.agentName
  85. end
  86. else
  87. begin
  88. select
  89. sc.sscMasterId
  90. ,scCode = sc.code
  91. ,sCountryName = cm.countryName
  92. ,pAgentName = ISNULL(am1.agentName,'All')
  93. ,paymentMethod = ISNULL(stm.typeTitle, 'All')
  94. ,baseCurrency = sc.baseCurrency
  95. from agentCommissionRule a with(nolock)
  96. inner join sscMaster sc with(nolock) on a.ruleId = sc.sscMasterId
  97. inner join agentMaster am with(nolock) on a.agentId = am.agentId
  98. left join serviceTypeMaster stm WITH(NOLOCK) ON sc.tranType = stm.serviceTypeId
  99. left join countryMaster cm with(nolock) on cm.countryId = sc.sCountry
  100. left join agentMaster am1 with(nolock) on sc.rAgent = am1.agentId
  101. where a.ruleType = 'sc'
  102. and isnull(a.isActive,'Y') = 'Y'
  103. and isnull(sc.isActive,'Y') = 'Y'
  104. and a.agentId = isnull(@agent,a.agentId)
  105. order by am.agentName
  106. end
  107. END
  108. ELSE IF @flag = 'detail'
  109. BEGIN
  110. SELECT
  111. fromAmt
  112. ,toAmt
  113. ,serviceFee = CASE WHEN pcnt = 0 THEN minAmt ELSE pcnt END
  114. ,feeType = CASE WHEN pcnt = 0 THEN 'Flat' ELSE 'Percent' END
  115. FROM sscDetail WITH(NOLOCK) WHERE sscMasterId = @ruleId AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y'
  116. ORDER BY fromAmt ASC
  117. END
  118. END TRY
  119. BEGIN CATCH
  120. IF @@TRANCOUNT > 0
  121. ROLLBACK TRANSACTION
  122. DECLARE @errorMessage VARCHAR(MAX)
  123. SET @errorMessage = ERROR_MESSAGE()
  124. EXEC proc_errorHandler 1, @errorMessage, NULL
  125. END CATCH
  126. GO