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.

131 lines
4.7 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_GetUSDAmountFromCollKRWAmt] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_GetUSDAmountFromCollKRWAmt]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_GetUSDAmountFromCollKRWAmt] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. CREATE proc [dbo].[proc_GetUSDAmountFromCollKRWAmt]
  12. @flag VARCHAR(30),
  13. @user VARCHAR(150) = NULL,
  14. @pCountryId INT,
  15. @pCurr VARCHAR(5),
  16. @deliveryMethod VARCHAR(20),
  17. @cAmt MONEY,
  18. @pAmt MONEY = NULL,
  19. @calBy CHAR(1),
  20. @pCountry VARCHAR(50)
  21. AS
  22. SET NOCOUNT ON ;
  23. DECLARE @payOutPartner BIGINT
  24. DECLARE @sCountryId INT = 118,@sAgent INT = 2080,@sSuperAgent INT = 1008 ,@sBranch INT ,@collCurr VARCHAR(5) = 'KRW'
  25. DECLARE @scValue MONEY,@exRateOffer MONEY,@scDiscount MONEY ,@AmountLimitPerTran MONEY,@AmountLimitPerDay MONEY
  26. DECLARE @place INT,@currDecimal INT,@exRate FLOAT,@serviceCharge MONEY,@tAmt MONEY
  27. DECLARE @pSuperAgent INT,@pSuperAgentName VARCHAR(200),@pAgent BIGINT,@pAgentName VARCHAR(200),@pBranch INT,@pBranchName VARCHAR(200)
  28. DECLARE @errorCode INT,@msg VARCHAR(MAX)
  29. SELECT @pCountryId = countryId FROM countryMaster(NOLOCK) WHERE countryName = @pCountry
  30. SELECT @payOutPartner = AgentId FROM TblPartnerwiseCountry (NOLOCK)
  31. WHERE COUNTRYID = @pCountryId
  32. AND ISNULL(PaymentMethod, @deliveryMethod) = @deliveryMethod
  33. AND IsActive = 1
  34. SELECT TOP 1 @pAgent = AM.agentId
  35. FROM agentMaster AM(NOLOCK)
  36. WHERE AM.parentId = @payOutPartner AND agentType=2903 AND AM.isSettlingAgent = 'Y' AND AM.isApiPartner = 1
  37. SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName,
  38. @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName
  39. FROM dbo.FNAGetBranchFullDetails(@pAgent)
  40. IF @flag = 'getUSDAmountFromCAmt'
  41. BEGIN
  42. IF @pCurr IS NULL
  43. BEGIN
  44. SELECT '1' ErrorCode ,
  45. 'Currency not been defined yet for receiving country' Msg ,
  46. amountLimitPerDay = @AmountLimitPerDay ,
  47. customerTotalSentAmt = 0 ,
  48. maxAmountLimitPerTran = @AmountLimitPerTran ,
  49. PerTxnMinimumAmt = @AmountLimitPerDay;
  50. RETURN;
  51. END;
  52. SELECT @exRate =
  53. dbo.FNAGetCustomerRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent, @pCurr,@deliveryMethod);
  54. IF @exRate IS NULL
  55. BEGIN
  56. SELECT '1' ErrorCode ,
  57. 'Exchange rate not defined yet for receiving currency ('+ @pCurr + ')' Msg ,
  58. amountLimitPerDay = @AmountLimitPerDay ,
  59. customerTotalSentAmt = 0 ,
  60. maxAmountLimitPerTran = @AmountLimitPerTran ,
  61. PerTxnMinimumAmt = @AmountLimitPerDay;
  62. RETURN;
  63. END;
  64. IF @calBy = 'C'
  65. BEGIN
  66. IF @pCountryId = 36
  67. BEGIN
  68. SET @pAmt = @cAmt * @exRate
  69. SELECT @serviceCharge = amount
  70. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  71. @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,@collCurr);
  72. END
  73. ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2
  74. BEGIN
  75. SELECT @serviceCharge = amount
  76. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  77. @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,'USD');
  78. END
  79. ELSE
  80. BEGIN
  81. SELECT @serviceCharge = amount
  82. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  83. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,@cAmt,@collCurr);
  84. END
  85. IF @serviceCharge IS NULL
  86. BEGIN
  87. SELECT '1' ErrorCode ,
  88. 'Service charge not defined yet for receiving country' Msg ,
  89. amountLimitPerDay = @AmountLimitPerDay ,
  90. customerTotalSentAmt = 0 ,
  91. maxAmountLimitPerTran = @AmountLimitPerTran ,
  92. PerTxnMinimumAmt = @AmountLimitPerDay;
  93. RETURN;
  94. END;
  95. SET @tAmt = @cAmt - @serviceCharge;
  96. END;
  97. DECLARE @complianceRuleId INT, @cAmtUSD MONEY,@sCurrCostRate MONEY,@sCurrHoMargin MONEY,@tAmtUSD MONEY
  98. SELECT
  99. @sCurrCostRate = sCurrCostRate
  100. ,@sCurrHoMargin = sCurrHoMargin
  101. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  102. IF @sCurrCostRate IS NULL
  103. BEGIN
  104. SELECT @errorCode = '1', @msg = 'Transaction cannot be proceed. Exchange Rate not defined!'
  105. RETURN
  106. END
  107. SET @tAmtUSD = @tAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0))
  108. SET @tAmtUSD = ROUND(@tAmtUSD,2)
  109. SELECT 0 ErrorCode, Msg = @msg,Id = @tAmtUSD
  110. END
  111. GO