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.

93 lines
6.2 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_payCommissionReport] 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. proc_payCommissionReport @flag = 's', @user = 'admin', @sortBy = 'exRateTreasuryId', @sortOrder = 'ASC', @pageSize = '10', @pageNumber = '1'
  10. */
  11. CREATE proc [dbo].[proc_payCommissionReport]
  12. @flag VARCHAR(50) = NULL
  13. ,@user VARCHAR(30) = NULL
  14. ,@sCountry INT = NULL
  15. ,@sAgent INT = NULL
  16. ,@sBranch INT = NULL
  17. ,@rCountry INT = NULL
  18. ,@rAgent INT = NULL
  19. ,@rBranch INT = NULL
  20. ,@ruleId INT = NULL
  21. ,@sortBy VARCHAR(50) = NULL
  22. ,@sortOrder VARCHAR(5) = NULL
  23. ,@pageSize INT = NULL
  24. ,@pageNumber INT = NULL
  25. AS
  26. SET NOCOUNT ON
  27. SET XACT_ABORT ON
  28. BEGIN TRY
  29. IF @flag = 'master'
  30. BEGIN
  31. DECLARE @serviceChargeRuleBranchWise TABLE(ruleId INT)
  32. DECLARE @serviceChargeRuleAgentWise TABLE(ruleId INT)
  33. DECLARE @serviceChargeRule TABLE(ruleId INT)
  34. INSERT @serviceChargeRuleBranchWise
  35. SELECT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE ruleType = 'cp' AND agentId = @rBranch AND ISNULL(isActive, 'N') = 'Y'
  36. INSERT @serviceChargeRuleAgentWise
  37. SELECT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE ruleType = 'cp' AND agentId = @rAgent AND ISNULL(isActive, 'N') = 'Y'
  38. IF EXISTS(SELECT 'X' FROM scPayMaster ssm WITH(NOLOCK)
  39. INNER JOIN @serviceChargeRuleBranchWise scr ON ssm.scPayMasterId = scr.ruleId
  40. WHERE rCountry = @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.scPayMasterId
  52. ,pCountryName = ISNULL(cm.countryName, 'All')
  53. ,pAgentName = ISNULL(pam.agentName, 'All')
  54. ,paymentMethod = ISNULL(stm.typeTitle, 'All')
  55. ,baseCurrency
  56. FROM scPayMaster ssm WITH(NOLOCK)
  57. INNER JOIN @serviceChargeRule scr ON ssm.scPayMasterId = scr.ruleId
  58. LEFT JOIN countryMaster cm WITH(NOLOCK) ON ssm.rCountry = cm.countryId
  59. LEFT JOIN agentMaster pam WITH(NOLOCK) ON ssm.rAgent = pam.agentId
  60. LEFT JOIN serviceTypeMaster stm WITH(NOLOCK) ON ssm.tranType = stm.serviceTypeId
  61. WHERE rCountry = @rCountry AND ISNULL(ssm.isActive, 'N') = 'Y'
  62. END
  63. ELSE IF @flag = 'detail'
  64. BEGIN
  65. SELECT
  66. fromAmt
  67. ,toAmt
  68. ,serviceFee = CASE WHEN pcnt = 0 THEN minAmt ELSE pcnt END
  69. ,feeType = CASE WHEN pcnt = 0 THEN 'Flat' ELSE 'Percent' END
  70. FROM scPayDetail WITH(NOLOCK) WHERE scPayMasterId = @ruleId AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y'
  71. ORDER BY fromAmt ASC
  72. END
  73. END TRY
  74. BEGIN CATCH
  75. IF @@TRANCOUNT > 0
  76. ROLLBACK TRANSACTION
  77. DECLARE @errorMessage VARCHAR(MAX)
  78. SET @errorMessage = ERROR_MESSAGE()
  79. EXEC proc_errorHandler 1, @errorMessage, NULL
  80. END CATCH
  81. GO