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.

206 lines
11 KiB

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