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.

96 lines
7.4 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendCommissionRpt] 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_sendCommissionRpt @flag = 'master', @user = 'admin',
  10. @sCountryId = '181', @sAgent = null, @rCountryId = '151', @rAgent = null
  11. */
  12. CREATE proc [dbo].[proc_sendCommissionRpt]
  13. @flag VARCHAR(50) = NULL
  14. ,@user VARCHAR(30) = NULL
  15. ,@sCountryId INT = NULL
  16. ,@sAgent INT = NULL
  17. ,@rCountryId INT = NULL
  18. ,@rAgent INT = NULL
  19. ,@ruleId INT = NULL
  20. AS
  21. SET NOCOUNT ON
  22. SET XACT_ABORT ON
  23. BEGIN TRY
  24. IF @flag = 'master'
  25. BEGIN
  26. --DECLARE @serviceChargeRule TABLE(ruleId INT)
  27. --INSERT @serviceChargeRule
  28. --SELECT ruleId FROM agentCommissionRule WITH(NOLOCK)
  29. --WHERE ruleType = 'cs'
  30. -- AND agentId = @sAgent
  31. -- AND ISNULL(isActive, 'N') = 'Y'
  32. ----select * from @serviceChargeRule
  33. --SELECT
  34. -- ssm.scSendMasterId
  35. -- ,pCountryName = ISNULL(cm.countryName, 'All')
  36. -- ,pAgentName = ISNULL(pam.agentName, 'All')+'<span style="color:Red;"> ('+ssm.code+') </span>'
  37. -- ,paymentMethod = ISNULL(stm.typeTitle, 'All')
  38. -- ,baseCurrency
  39. --FROM scSendMaster ssm WITH(NOLOCK)
  40. --INNER JOIN @serviceChargeRule scr ON ssm.scSendMasterId = scr.ruleId
  41. --LEFT JOIN countryMaster cm WITH(NOLOCK) ON ssm.rCountry = cm.countryId
  42. --LEFT JOIN agentMaster pam WITH(NOLOCK) ON ssm.rAgent = pam.agentId
  43. --LEFT JOIN serviceTypeMaster stm WITH(NOLOCK) ON ssm.tranType = stm.serviceTypeId
  44. --WHERE isnull(rCountry,'') = ISNULL(@rCountryId,isnull(rCountry,''))
  45. -- AND ISNULL(ssm.isActive, 'N') = 'Y'
  46. -- AND isnull(rAgent,'') = ISNULL(@rAgent,isnull(rAgent,''))
  47. SELECT scs.scSendMasterId
  48. ,pCountryName = ISNULL(cm.countryName, 'All')+' | Sending Country: '+isnull(cm1.countryName,'All')
  49. ,pAgentName = isnull(am.agentName,'All')+' | Sending Agent:'+ isnull(am1.agentName,'All')
  50. ,paymentMethod = ISNULL(stm.typeTitle, 'All')
  51. ,baseCurrency =baseCurrency
  52. FROM agentCommissionRule acr WITH(NOLOCK)
  53. inner join scSendMaster scs with(nolock) on acr.ruleId = scs.scSendMasterId
  54. inner join countryMaster cm with(nolock) on cm.countryId = scs.rCountry
  55. inner join countryMaster cm1 with(nolock) on cm1.countryId = scs.sCountry
  56. left join agentMaster am with(nolock) on am.agentId = scs.rAgent
  57. left join agentMaster am1 with(nolock) on am1.agentId = acr.agentId
  58. left join serviceTypeMaster stm WITH(NOLOCK) ON scs.tranType = stm.serviceTypeId
  59. WHERE ruleType = 'cs'
  60. and isnull(scs.rCountry,'') = ISNULL(@rCountryId,isnull(scs.rCountry,''))
  61. and isnull(scs.sCountry,'') = ISNULL(@sCountryId,isnull(scs.sCountry,''))
  62. AND ISNULL(scs.isActive, 'N') = 'Y'
  63. AND ISNULL(acr.isActive, 'N') = 'Y'
  64. AND isnull(scs.rAgent,'') = ISNULL(@rAgent,isnull(scs.rAgent,''))
  65. END
  66. ELSE IF @flag = 'detail'
  67. BEGIN
  68. SELECT
  69. country = isnull(cm.countryName,'All')
  70. ,fromAmt
  71. ,toAmt
  72. ,commission = CASE WHEN pcnt = 0 THEN minAmt ELSE pcnt END
  73. ,feeType = CASE WHEN pcnt = 0 THEN 'Flat' ELSE 'Percent' END
  74. FROM scSenddetail d WITH(NOLOCK) inner join scSendMaster m with(nolock) on d.scSendMasterId = m.scSendMasterId
  75. left join countryMaster cm with(nolock) on cm.countryId = m.rCountry
  76. WHERE d.scSendMasterId = @ruleId AND ISNULL(d.isDeleted, 'N') = 'N' AND ISNULL(d.isActive, 'N') = 'Y'
  77. ORDER BY fromAmt ASC
  78. END
  79. END TRY
  80. BEGIN CATCH
  81. IF @@TRANCOUNT > 0
  82. ROLLBACK TRANSACTION
  83. DECLARE @errorMessage VARCHAR(MAX)
  84. SET @errorMessage = ERROR_MESSAGE()
  85. EXEC proc_errorHandler 1, @errorMessage, NULL
  86. END CATCH
  87. GO