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.

197 lines
5.1 KiB

1 year ago
  1. ALTER PROC [dbo].[mobile_proc_GetCalculation] (
  2. @flag VARCHAR(25),
  3. @accessCode VARCHAR(MAX) = NULL,
  4. @sCurrCode VARCHAR(50) = NULL, --@sCurrCode='KRW'
  5. @pCurrCode VARCHAR(50)=NULL, --@pCurrCode='NPR'
  6. @agentTxnRefId VARCHAR(50) = NULL,
  7. @currentRate FLOAT = NULL,
  8. @serviceCharge MONEY = NULL,
  9. @pAmt MONEY = NULL,
  10. @cAmt MONEY = NULL,
  11. @tAmt MONEY = NULL,
  12. @pCountryId VARCHAR(50) = NULL,
  13. @sendMoney BIT = NULL
  14. )
  15. AS
  16. SET NOCOUNT ON;
  17. SET XACT_ABORT ON;
  18. BEGIN TRY
  19. DECLARE @sAgent INT = 394395
  20. DECLARE @sCountryId INT,
  21. @sSuperAgent INT,
  22. @sBranch INT,
  23. @userId VARCHAR(100),
  24. @agentCode VARCHAR(50),
  25. @customerId INT,
  26. @rewardPoint MONEY
  27. IF NOT EXISTS(SELECT 'x' FROM agentMaster(NOLOCK) WHERE agentid=@sAgent)
  28. BEGIN
  29. SELECT '1' errorCode, 'Sending agent not found' Msg, NULL ID
  30. RETURN
  31. END
  32. SELECT @sCountryId = agentCountryId
  33. ,@sSuperAgent = parentId
  34. ,@sBranch = agentid
  35. ,@agentCode = agentCode
  36. FROM agentMaster (NOLOCK) where agentid = @sAgent
  37. IF @flag='getSAgentDetais'
  38. BEGIN
  39. IF @sendMoney=1
  40. BEGIN
  41. SELECT @userId=ur.username FROM dbo.mobile_userRegistration (NOLOCK) ur
  42. WHERE ur.accessCode=@accessCode
  43. END
  44. SELECT errorCode = '0'
  45. ,sAgent = @sAgent
  46. ,sBranch = @sBranch
  47. ,sCountryId = @sCountryId
  48. ,sSuperAgent = @sSuperAgent
  49. ,userId = @userId
  50. RETURN;
  51. END
  52. IF @flag='exRate'
  53. BEGIN
  54. DECLARE @exchangeRateId VARCHAR(40) = LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  55. SELECT @userId=username,@customerId=customerId FROM mobile_userRegistration where accessCode=@accessCode
  56. IF ISNULL(@customerId,'')=''
  57. BEGIN
  58. SELECT '1' errorCode, 'Invalid access code!' Msg, NULL ID
  59. RETURN
  60. END
  61. SELECT @rewardPoint = dbo.FNACalcBonusPoint(@tAmt,@serviceCharge)
  62. INSERT INTO exRateCalcHistory (
  63. AGENT_CODE
  64. ,[USER_ID]
  65. ,AGENT_TXN_REF_ID
  66. ,FOREX_SESSION_ID
  67. ,serviceCharge
  68. ,pAmt
  69. ,customerRate
  70. ,sCurrCostRate
  71. ,sCurrHoMargin
  72. ,sCurrAgentMargin
  73. ,pCurrCostRate
  74. ,pCurrHoMargin
  75. ,pCurrAgentMargin
  76. ,agentCrossSettRate
  77. ,treasuryTolerance
  78. ,customerPremium
  79. ,sharingValue
  80. ,sharingType
  81. ,createdDate
  82. ,isExpired
  83. )
  84. SELECT
  85. @agentCode
  86. ,@userId
  87. ,@agentTxnRefId
  88. ,@exchangeRateId
  89. ,@serviceCharge
  90. ,@pAmt
  91. ,@currentRate
  92. ,''
  93. ,''
  94. ,''
  95. ,''
  96. ,''
  97. ,''
  98. ,''
  99. ,''
  100. ,''
  101. ,''
  102. ,''
  103. ,GETDATE()
  104. ,'N'
  105. SELECT
  106. errorCode = '0'
  107. ,[from] = @sCurrCode
  108. ,[to] = @pCurrCode
  109. ,currentRate = @currentRate
  110. ,transferFee = CAST(@serviceCharge AS DECIMAL)
  111. ,exchangeRateRefId = @exchangeRateId
  112. ,transferLimit = '2000000'
  113. ,transactionLimit = '3'
  114. ,rewardPoint = CAST(ROUND(@rewardPoint,0) AS DECIMAL)
  115. ,maximumTransferAmountPerTransaction = '20000'
  116. ,minimumTransferAmountPerTransaction = '10000'
  117. ,pAmt = ROUND(@pAmt,2)
  118. ,cAmt = CAST(@cAmt AS DECIMAL)
  119. ,tAmt = ROUND(@tAmt,0)
  120. FROM customerMaster cm(NOLOCK) WHERE cm.customerId=@customerId
  121. END
  122. IF @flag='get-exRate'
  123. BEGIN
  124. DECLARE @exRate FLOAT,@pCurr VARCHAR(50);
  125. SELECT TOP 1 @pCurr=cm.currencyCode FROM dbo.countryCurrency cc(NOLOCK)
  126. INNER JOIN dbo.currencyMaster cm(NOLOCK) ON cm.currencyId = cc.currencyId
  127. WHERE countryId = @pCountryId
  128. SELECT @exRate =
  129. dbo.FNAGetCustomerRate('113',@sAgent,@sBranch,'JPY',@pCountryId,'', @pCurr,'');
  130. IF @exRate IS NULL
  131. BEGIN
  132. SELECT '1' ErrorCode ,'Exchange rate not defined yet for receiving currency ('+ @pCurr + ')' Msg
  133. RETURN;
  134. END;
  135. SELECT @exRate;
  136. END
  137. IF @flag='get-exRateDetails'
  138. BEGIN
  139. SELECT cm.countryId,cm.countryName,countryCode
  140. FROM dbo.countryMaster cm(NOLOCK)
  141. WHERE cm.isOperativeCountry='Y'
  142. AND cm.operationType = 'R'
  143. ORDER BY cm.countryName
  144. SELECT cc.countryId,cm.currencyCode AS currencyCode,cmas.countryName AS countryName, cmas.countryCode AS countryCode
  145. FROM countrycurrency cc(NOLOCK)
  146. INNER JOIN currencyMaster cm(NOLOCK) ON cm.currencyId = cc.currencyId
  147. INNER JOIN dbo.countryMaster cmas(NOLOCK) ON cmas.countryId=cc.countryId
  148. WHERE cmas.isOperativeCountry = 'Y'
  149. AND ISNULL(cc.isDefault,'N') <>'N'
  150. AND ISNULL(cc.isDeleted,'N')='N'
  151. AND cmas.operationType = 'R'
  152. ORDER BY countryName
  153. select c.countryId,c.receivingMode AS payoutmethodId,m.typeTitle AS payoutName,'' AS bussinessDescription
  154. from countryReceivingMode c(nolock)
  155. INNER join serviceTypeMaster m(nolock) on m.serviceTypeId = c.receivingMode
  156. order by payoutmethodId
  157. SELECT '0' errorCode, 'Success' Msg ,NULL ID
  158. END
  159. END TRY
  160. BEGIN CATCH
  161. IF @@TRANCOUNT > 0 ROLLBACK TRAN
  162. DECLARE @errorLogId BIGINT
  163. INSERT INTO Logs (errorPage, errorMsg, errorDetails, createdBy, createdDate)
  164. SELECT 'API SP Error','Technical Error : ' + ERROR_MESSAGE() MESSAGE,'mobile_proc_GetCalculation',@accessCode, GETDATE()
  165. SET @errorLogId = SCOPE_IDENTITY()
  166. SELECT '1' errorCode, 'Technical Error : ' + ERROR_MESSAGE() Msg, @errorLogId ID
  167. END CATCH