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.

928 lines
45 KiB

10 months ago
1 year ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
12 months ago
12 months ago
12 months ago
10 months ago
10 months ago
1 year ago
10 months ago
10 months ago
10 months ago
10 months ago
12 months ago
1 year ago
12 months ago
1 year ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
1 year ago
1 year ago
1 year ago
11 months ago
10 months ago
10 months ago
11 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_get_exRate_master] Script Date: 11/26/2023 10:22:18 AM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_get_exRate_master] (
  9. @flag VARCHAR(20)
  10. ,@user VARCHAR(100) = NULL
  11. ,@sCountryId INT = NULL
  12. ,@sAgent INT = NULL
  13. ,@sSuperAgent INT = NULL
  14. ,@sBranch INT = NULL
  15. ,@senderId BIGINT = NULL
  16. ,@collCurr VARCHAR(5) = NULL
  17. ,@pCountryId INT = NULL
  18. ,@pCountry VARCHAR(50) = NULL
  19. ,@pAgent INT = NULL
  20. ,@pCurr VARCHAR(5) = NULL
  21. ,@deliveryMethodId INT = NULL
  22. ,@cAmt MONEY = NULL
  23. ,@pAmt MONEY = NULL
  24. ,@calBy CHAR(1) = NULL
  25. ,@couponCode VARCHAR(30) = NULL
  26. ,@schemeId VARCHAR(10) = NULL
  27. ,@payOutPartner INT = NULL
  28. ,@paymentType VARCHAR(50) = NULL
  29. ,@cardOnline VARCHAR(10) = NULL
  30. ,@tpExRate FLOAT = NULL
  31. ,@isManualSc CHAR(1) = NULL
  32. ,@manualSc MONEY = NULL
  33. ,@ProcessFor VARCHAR(20) = NULL
  34. ,@discountedFee MONEY = NULL
  35. )
  36. AS
  37. SET NOCOUNT ON;
  38. SET XACT_ABORT ON;
  39. -----------------------------------------
  40. --Sep 22 -> #109 ->Change the logic to choose highest Rate in case of Nepal
  41. -- #101 , #361 - Mobile Changes for Multi-Lingual
  42. -- #1526 - Post production fixes for Redeem & Earn
  43. -- #1590 - Customer Loyalty
  44. -- #5968 - sc revised
  45. -- #18600 - change in @flag = 'false' for exRate
  46. --------------------------------------------
  47. BEGIN
  48. DECLARE @scValue MONEY
  49. ,@scAction CHAR(2)
  50. ,@scOffer MONEY
  51. ,@exRateOffer FLOAT
  52. ,@scDiscount MONEY
  53. DECLARE @place INT
  54. ,@currDecimal INT
  55. ,@collMode VARCHAR(30)
  56. ,@sendingCustType VARCHAR(30)
  57. ,@msg VARCHAR(150)
  58. ,@errorCode INT
  59. DECLARE @exRateCalByPartner BIT
  60. ,@pSuperAgent INT
  61. ,@serviceCharge MONEY
  62. ,@serviceChargetmp MONEY
  63. ,@tAmt MONEY
  64. ,@pSuperAgentName VARCHAR(100)
  65. ,@pBranch INT
  66. DECLARE @pAgentName VARCHAR(100)
  67. ,@pBranchName VARCHAR(100)
  68. ,@exRate FLOAT
  69. ,@pCurrHoMargin FLOAT
  70. ,@FOREX_SESSION_ID VARCHAR(40)
  71. DECLARE @tranCount INT = 0
  72. ,@schemeCount INT = 0
  73. ,@schemeAppliedMsg VARCHAR(100) = ''
  74. ,@isFirstTran CHAR(1) = 'N'
  75. ,@createdFrom CHAR(1) = NULL
  76. ,@isEligible CHAR(1) = 'N'
  77. ,@introducer VARCHAR(25) = NULL
  78. --IF @ProcessFor IN ('send')
  79. --BEGIN
  80. IF ISNULL(@user, 'onlinedefault') <> 'onlinedefault' --OR @user is not null
  81. BEGIN
  82. PRINT 'a'
  83. IF @senderId IS NULL OR @senderId=0
  84. BEGIN
  85. SET @senderId = (
  86. SELECT customerId
  87. FROM customermaster(NOLOCK)
  88. WHERE username = @user
  89. )
  90. END
  91. --EXEC PROC_Customer_LoyaltyV2 @flag = 'check-eligible-v2'
  92. -- ,@isEligible = @isEligible OUT
  93. -- ,@referralCode = @introducer
  94. -- ,@tranCount = @trancount OUT
  95. -- ,@schemeCount = @schemeCount OUT
  96. -- ,@customerId = @senderId
  97. -- ,@createdFrom = 'M'
  98. --IF NOT EXISTS (
  99. -- SELECT 1
  100. -- FROM (
  101. -- SELECT TOP 1 customerId
  102. -- FROM TRANSENDERS TS(NOLOCK)
  103. -- INNER JOIN remittran(NOLOCK) rt ON rt.id = ts.tranId
  104. -- WHERE customerId = @SenderId
  105. -- AND rt.tranStatus <> 'CANCEL' AND rt.tranType='M'
  106. -- UNION ALL
  107. -- SELECT TOP 1 customerId
  108. -- FROM TRANSENDERSTEMP TT(NOLOCK)
  109. -- INNER JOIN remittrantemp(NOLOCK) rt ON rt.id = tt.tranId
  110. -- WHERE customerId = @SenderId
  111. -- AND rt.tranStatus <> 'CANCEL' AND rt.tranType='M'
  112. -- ) a
  113. -- WHERE customerId = @SenderId
  114. -- )
  115. -- BEGIN
  116. -- SET @isFirstTran = 'Y'
  117. -- END
  118. END
  119. print '@isFirstTran' + '-> ' + @isFirstTran
  120. SELECT @createdFrom = serviceUsedFor
  121. FROM customerMaster(NOLOCK)
  122. WHERE customerId = @senderId
  123. PRINT '@senderId'
  124. PRINT @senderId;
  125. SET @sCountryId = 233
  126. SET @sAgent='394395';
  127. IF ISNULL(@pCountryId, 0) = 0
  128. SELECT @pCountryId = countryId
  129. FROM countryMaster(NOLOCK)
  130. WHERE COUNTRYNAME = @pCountry
  131. IF @flag = 'False'
  132. AND @ProcessFor IN ('dashboard')
  133. BEGIN
  134. SELECT @payoutPartner = AGENTID
  135. ,@exRateCalByPartner = ISNULL(exRateCalByPartner, 0)
  136. FROM TblPartnerwiseCountry(NOLOCK)
  137. WHERE CountryId = @pCountryId
  138. AND IsActive = 1
  139. AND ISNULL(IsMobileEnabled, 0) = 1
  140. AND ISNULL(PaymentMethod, @deliveryMethodId) = @deliveryMethodId
  141. END
  142. ELSE
  143. BEGIN
  144. SELECT @payoutPartner = AGENTID
  145. ,@exRateCalByPartner = ISNULL(exRateCalByPartner, 0)
  146. FROM TblPartnerwiseCountry(NOLOCK)
  147. WHERE CountryId = @pCountryId
  148. AND IsActive = 1
  149. AND ISNULL(PaymentMethod, @deliveryMethodId) = @deliveryMethodId
  150. END
  151. PRINT '@payoutPartner'
  152. PRINT @payoutPartner;
  153. IF @payoutPartner IS NOT NULL
  154. BEGIN
  155. --GET PAYOUT AGENT DETAILS
  156. SELECT @PAGENT = AGENTID
  157. FROM AGENTMASTER(NOLOCK)
  158. WHERE PARENTID = @payoutPartner
  159. AND ISNULL(ISSETTLINGAGENT, 'N') = 'Y';
  160. SELECT @pSuperAgent = sSuperAgent
  161. ,@pSuperAgentName = sSuperAgentName
  162. ,@pAgent = sAgent
  163. ,@pAgentName = sAgentName
  164. ,@pBranch = sBranch
  165. ,@pBranchName = sBranchName
  166. FROM dbo.FNAGetBranchFullDetails(@PAGENT)
  167. END
  168. ELSE
  169. BEGIN
  170. SELECT '1' ErrorCode
  171. ,'Partner not yet mapped for the selected country!' Msg
  172. ,NULL id
  173. RETURN
  174. END
  175. DECLARE @rowId INT
  176. SELECT @scValue = 0
  177. ,@scOffer = 0
  178. ,@exRateOffer = 0
  179. ,@scDiscount = 0
  180. SELECT @place = place
  181. ,@currDecimal = currDecimal
  182. FROM currencyPayoutRound WITH (NOLOCK)
  183. WHERE ISNULL(isDeleted, 'N') = 'N'
  184. AND currency = @pCurr
  185. AND ISNULL(tranType, @deliveryMethodId) = @deliveryMethodId
  186. SET @currDecimal = ISNULL(@currDecimal, 0)
  187. IF @pCurr IS NULL
  188. BEGIN
  189. SELECT '2' ErrorCode
  190. ,'Currency not been defined yet for receiving country' Msg
  191. ,NULL id
  192. RETURN
  193. END
  194. --pRINT @pAgent;
  195. IF @flag = 'false'
  196. BEGIN
  197. IF @pCountryId = 151
  198. AND @deliveryMethodId = 1
  199. BEGIN
  200. SELECT AgentId
  201. INTO #AgentList
  202. FROM agentMaster(NOLOCK)
  203. WHERE extCode = 'NP ANYWHERE'
  204. SELECT @exRate = customerRate
  205. ,@pCurrHoMargin = pCurrHoMargin
  206. FROM (
  207. SELECT ROW_NUMBER() OVER (
  208. ORDER BY CUSTOMERRATE DESC
  209. ) ROW_NUM
  210. ,CUSTOMERRATE
  211. ,pCurrHoMargin
  212. FROM #AgentList A
  213. CROSS APPLY dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, AgentId, @pCurr, @deliveryMethodId) FN
  214. ) X
  215. WHERE X.ROW_NUM = 1
  216. END
  217. ELSE
  218. BEGIN
  219. PRINT @sCountryId;
  220. PRINT '@sAgent';
  221. PRINT @sAgent;
  222. PRINT '@sBranch';
  223. PRINT @sBranch;
  224. PRINT @collCurr;
  225. PRINT @pCountryId;
  226. PRINT @pCurr;
  227. PRINT @deliveryMethodId;
  228. pRINT '@pAgent';
  229. PRINT @pAgent;
  230. SELECT @exRate = customerRate
  231. ,@pCurrHoMargin = pCurrHoMargin
  232. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  233. END
  234. IF ISNULL(@exRate, 0) = 0
  235. BEGIN
  236. SELECT '3' ErrorCode
  237. ,'Exchange rate not defined yet for receiving currency (' + @pCurr + ')' Msg
  238. ,NULL id
  239. RETURN
  240. END
  241. IF @tpExRate > 0
  242. BEGIN
  243. SET @exRate = @exRate - @tpExRate
  244. END
  245. ELSE
  246. BEGIN
  247. SELECT @tpExRate= ISNULL(detaildesc,0) FROM
  248. staticDataValue where typeID='8109' and valueid='11447' -- ONLINE
  249. SET @exRate = @exRate - @tpExRate
  250. END
  251. IF(ISNULL(@discountedFee,0)> 0)
  252. BEGIN
  253. IF dbo.FNA_GET_AVAILABLE_BALANCE_POINTS(@senderId) < ISNULL(@discountedFee, 0)
  254. BEGIN
  255. SELECT '1' ErrorCode
  256. ,'You do not have sufficient Reward Amount!' Msg
  257. ,NULL id
  258. RETURN
  259. END
  260. END
  261. --IF (@discountedFee > '0.00' AND @discountedFee <'5.00')
  262. -- BEGIN
  263. -- SELECT '8' ErrorCode
  264. -- ,'Redeem Amount can not be less than 5 Pounds' Msg
  265. -- ,NULL id
  266. -- RETURN;
  267. -- END
  268. --PRINT '@isFirstTran:' + CAST( @isFirstTran AS VARCHAR);
  269. --PRINT '@isEligible:' + CAST( @isEligible AS VARCHAR);
  270. -- PRINT '@tranCount:' + CAST( @tranCount AS VARCHAR);
  271. -- PRINT '@@schemeCount:' + CAST( @schemeCount AS VARCHAR);
  272. IF @calBy = 'C'
  273. BEGIN
  274. BEGIN
  275. IF ISNULL(@isManualSc, 'N') = 'N'
  276. BEGIN
  277. PRINT '@serviceChargetmp';
  278. SELECT @serviceChargetmp = isnull(amount, 0)
  279. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
  280. PRINT @serviceChargetmp
  281. IF (@discountedFee < '0.00')
  282. --AND (@serviceChargetmp < @discountedFee)
  283. BEGIN
  284. SELECT '8' ErrorCode
  285. ,'Redeem Amount cannot be less than zero' Msg
  286. ,NULL id
  287. RETURN;
  288. END
  289. ELSE
  290. BEGIN
  291. --SELECT @serviceCharge = @serviceChargetmp - ISNULL(@discountedFee, 0)
  292. SELECT @serviceCharge = @serviceChargetmp
  293. END
  294. END
  295. ELSE
  296. BEGIN
  297. SET @serviceCharge = ISNULL(@manualSc, 0)
  298. END
  299. IF @serviceCharge IS NULL
  300. AND ISNULL(@isManualSc, 'N') = 'N'
  301. BEGIN
  302. SELECT '4' ErrorCode
  303. ,'Service charge not defined yet for receiving country' Msg
  304. ,NULL id
  305. RETURN;
  306. END
  307. END
  308. IF @scAction = 'PD' -- Percent Discount
  309. BEGIN
  310. SET @scOffer = (@scValue / 100) * @serviceCharge
  311. SET @scDiscount = (@scValue / 100) * @serviceCharge
  312. END
  313. ELSE IF @scAction = 'FD' -- Flat Discount
  314. BEGIN
  315. SET @scDiscount = @scValue
  316. END
  317. ELSE IF @scAction = 'FV' -- Fixed Value
  318. BEGIN
  319. SET @scOffer = @scValue
  320. SET @scDiscount = @serviceCharge - @scValue
  321. END
  322. IF (@discountedFee > @serviceCharge)
  323. BEGIN
  324. SELECT '8' ErrorCode
  325. ,'Redeem Amount cannot be higher than Transfer fee.' Msg
  326. ,NULL id
  327. RETURN;
  328. END
  329. SET @tAmt = @cAmt - @serviceCharge + @scDiscount + ISNULL(@discountedFee, 0)
  330. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  331. --PRINT @pAmt;
  332. --SET @pAmt = FLOOR(@pAmt)
  333. SET @pAmt=Cast(Round(@pAmt,2,1) as decimal(18,2));
  334. --PRINT @pAmt;
  335. END
  336. ELSE
  337. BEGIN
  338. --SET @tAmt = CEILING(@pAmt/(@exRate + @exRateOffer), 0)
  339. --SET @tAmt = CEILING(@pAmt / (@exRate + @exRateOffer))
  340. SET @tAmt = @pAmt / (@exRate + @exRateOffer);
  341. BEGIN
  342. IF ISNULL(@isManualSc, 'N') = 'N'
  343. BEGIN
  344. SELECT @serviceChargetmp = isnull(amount, 0)
  345. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmt, @collCurr)
  346. IF (@discountedFee > 0)
  347. AND ( @discountedFee >@serviceChargetmp)
  348. BEGIN
  349. SELECT '8' ErrorCode
  350. ,'Redeem Amount cannot be greater than service fee' Msg
  351. ,NULL id
  352. RETURN;
  353. END
  354. ELSE
  355. BEGIN
  356. SELECT @serviceCharge = @serviceChargetmp;
  357. END
  358. END
  359. ELSE
  360. BEGIN
  361. SET @serviceCharge = ISNULL(@manualSc, 0)
  362. END
  363. IF @serviceCharge IS NULL
  364. BEGIN
  365. SELECT '4' ErrorCode
  366. ,'Service charge not defined yet for receiving country' Msg
  367. ,NULL id
  368. RETURN;
  369. END
  370. END
  371. IF @scAction = 'PD'
  372. BEGIN
  373. SET @scOffer = (@scValue / 100) * @serviceCharge
  374. SET @scDiscount = (@scValue / 100) * @serviceCharge
  375. END
  376. ELSE IF @scAction = 'FD'
  377. BEGIN
  378. SET @scDiscount = @scValue
  379. END
  380. ELSE IF @scAction = 'FV'
  381. BEGIN
  382. SET @scOffer = @scValue
  383. SET @scDiscount = @serviceCharge - @scValue
  384. END
  385. PRINT '@discountedFee'
  386. PRINT @discountedFee
  387. PRINT @serviceCharge
  388. IF (@discountedFee > @serviceCharge)
  389. BEGIN
  390. SELECT '8' ErrorCode
  391. ,'Redeem Amount cannot be higher than Transfer fee.' Msg
  392. ,NULL id
  393. RETURN;
  394. END
  395. SET @cAmt = (@tAmt + @serviceCharge - @scDiscount) - ISNULL(@discountedFee, 0)
  396. SET @cAmt =Cast(Round(@cAmt,2,1) as decimal(18,2))
  397. --SET @cAmt = CEILING(@cAmt)
  398. END
  399. --4. Validate Country Sending Limit
  400. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit'
  401. ,@cAmt = @cAmt
  402. ,@pAmt = @pAmt
  403. ,@sCountryId = @sCountryId
  404. ,@collMode = @collMode
  405. ,@deliveryMethod = @deliveryMethodId
  406. ,@sendingCustType = @sendingCustType
  407. ,@pCountryId = @pCountryId
  408. ,@pCurr = @pCurr
  409. ,@collCurr = @collCurr
  410. ,@pAgent = @pAgent
  411. ,@sAgent = @sAgent
  412. ,@sBranch = @sBranch
  413. ,@msg = @msg OUT
  414. ,@errorCode = @errorCode OUT
  415. IF @errorCode <> '0'
  416. BEGIN
  417. SELECT @errorCode ErrorCode
  418. ,@msg Msg
  419. RETURN;
  420. END
  421. --Validate Country Sending Limit END
  422. --5. Validate Country Receiving Limit
  423. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit'
  424. ,@cAmt = @cAmt
  425. ,@pAmt = @pAmt
  426. ,@sCountryId = @sCountryId
  427. ,@collMode = @collMode
  428. ,@deliveryMethod = @deliveryMethodId
  429. ,@sendingCustType = @sendingCustType
  430. ,@pCountryId = @pCountryId
  431. ,@pCurr = @pCurr
  432. ,@collCurr = @collCurr
  433. ,@pAgent = @pAgent
  434. ,@sAgent = @sAgent
  435. ,@sBranch = @sBranch
  436. ,@msg = @msg OUT
  437. ,@errorCode = @errorCode OUT
  438. IF @errorCode <> '0'
  439. BEGIN
  440. SELECT @errorCode ErrorCode
  441. ,@msg Msg
  442. RETURN;
  443. END
  444. IF ISNULL(@ProcessFor, '') = 'send'
  445. BEGIN
  446. SET @FOREX_SESSION_ID = NEWID()
  447. ----## lock ex rate for individual txn
  448. UPDATE exRateCalcHistory
  449. SET isExpired = 1
  450. WHERE CUSTOMER_ID = @senderId
  451. AND isExpired = 0
  452. PRINT @serviceCharge;
  453. INSERT INTO exRateCalcHistory (
  454. CUSTOMER_ID
  455. ,[USER_ID]
  456. ,FOREX_SESSION_ID
  457. ,serviceCharge
  458. ,pAmt
  459. ,customerRate
  460. ,sCurrCostRate
  461. ,sCurrHoMargin
  462. ,sCurrAgentMargin
  463. ,pCurrCostRate
  464. ,pCurrHoMargin
  465. ,pCurrAgentMargin
  466. ,agentCrossSettRate
  467. ,createdDate
  468. ,isExpired
  469. ,tAmt
  470. ,schemeId
  471. ,discountedFee
  472. ,sharingValue
  473. ,customerPremium
  474. )
  475. SELECT @senderId
  476. ,@user
  477. ,@FOREX_SESSION_ID
  478. ,@serviceCharge
  479. ,@pAmt
  480. ,@exRate
  481. ,1
  482. ,0
  483. ,0
  484. ,@pCurrHoMargin + @exRate
  485. ,@pCurrHoMargin
  486. ,0
  487. ,@exRate
  488. ,GETDATE()
  489. ,0
  490. ,@tAmt
  491. ,@schemeId
  492. ,ISNULL(@discountedFee, 0)
  493. ,@schemeCount
  494. ,@tpExRate
  495. END
  496. SET @msg = 'Success'
  497. SELECT @errorCode ErrorCode
  498. ,@msg Msg
  499. ,scCharge = @serviceCharge
  500. ,exRate = @exRate
  501. ,place = @place
  502. ,pCurr = @pCurr
  503. ,currDecimal = @currDecimal
  504. ,pAmt = @pAmt
  505. ,sAmt = @tAmt
  506. ,place = @place
  507. ,disc = 0.00
  508. ,collAmt = @cAmt
  509. ,exRateOffer = @exRateOffer
  510. ,scOffer = @scDiscount
  511. ,scAction = @scAction
  512. ,scValue = @scValue
  513. ,scDiscount = @scDiscount
  514. ,tpExRate = 0
  515. ,amountLimitPerDay = 0
  516. ,amountLimitPerTran = 0
  517. ,customerTotalSentAmt = 0
  518. ,exRateDisplay = @exRate
  519. ,EXRATEID = @FOREX_SESSION_ID
  520. ,maxAmountLimitPerTran = 0
  521. ,minAmountLimitPerTran = 0
  522. ,PerTxnMinimumAmt = 0
  523. ,schemeAppliedMsg = @schemeAppliedMsg
  524. ,schemeId = @schemeId
  525. ,tpPCurr = @pCurr
  526. ,collCurr = @collCurr
  527. ,ForexSessionId = @FOREX_SESSION_ID
  528. ,discountedFee = ISNULL(@discountedFee, 0)
  529. END
  530. ELSE IF @FLAG = 'true'
  531. BEGIN
  532. IF ISNULL(@tpExRate, 0) = 0
  533. BEGIN
  534. SELECT '5' ErrorCode
  535. ,'Third Party Exchange rate fetching error for currency (' + @pCurr + ')' Msg
  536. RETURN
  537. END
  538. DECLARE @exRateDonga FLOAT, @exRateBRAC FLOAT
  539. PRINT @sCountryId;
  540. PRINT @sCountryId;
  541. PRINT @sAgent;
  542. PRINT @sBranch;
  543. PRINT @collCurr;
  544. PRINT @pCountryId;
  545. PRINT @pAgent;
  546. PRINT @pCurr;
  547. PRINT @deliveryMethodId;
  548. SELECT @pCurrHoMargin = pCurrHoMargin
  549. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  550. SELECT @exRate = @tpExRate - ISNULL(@pCurrHoMargin, 0)
  551. IF ISNULL(@exRate, 0) = 0
  552. BEGIN
  553. SELECT '3' ErrorCode
  554. ,'Exchange rate not defined yet for receiving currency (' + @pCurr + ')' Msg
  555. ,NULL id
  556. RETURN
  557. END
  558. IF @user = 'onlinedefault'
  559. AND @pCountryId = 203
  560. BEGIN
  561. SELECT @exRateDonga = dbo.FNAGetCustomerRate(113, 0, 394395, 'JPY', 203, 394133, 'VND', 1)
  562. IF @exRateDonga > @exRate
  563. SET @exRate = @exRateDonga
  564. END
  565. IF @user = 'onlinedefault'
  566. AND @pCountryId = 16
  567. BEGIN
  568. SELECT @exRateBRAC = dbo.FNAGetCustomerRate(113, 0, 394395, 'JPY', 16, 394414, 'BDT', 1)
  569. IF @exRateBRAC > @exRate
  570. SET @exRate = @exRateBRAC
  571. END
  572. IF @calBy = 'C'
  573. BEGIN
  574. IF (
  575. @tranCount = @schemeCount
  576. AND ISNULL(@user, 'onlinedefault') <> 'onlinedefault'
  577. -- AND ISNULL(@ProcessFor, '') = 'send'
  578. AND @isEligible = 'Y'
  579. )
  580. OR (@isFirstTran = 'Y')
  581. BEGIN
  582. SET @serviceCharge = 0
  583. IF @isFirstTran = 'Y'
  584. BEGIN
  585. SET @schemeAppliedMsg = 'Enjoy zero (0) service charge due to First Transaction!';
  586. END
  587. ELSE
  588. SET @schemeAppliedMsg = 'Enjoy zero (0) service charge due to Loyalty Scheme!';
  589. END
  590. ELSE
  591. BEGIN
  592. IF ISNULL(@isManualSc, 'N') = 'N'
  593. BEGIN
  594. SELECT @serviceChargetmp = ISNULL(amount, 0)
  595. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
  596. --IF (@discountedFee > '0.00')
  597. -- AND (@serviceChargetmp < @discountedFee)
  598. --BEGIN
  599. -- SELECT '8' ErrorCode
  600. -- ,'Redeem points can not be more than service charge' Msg
  601. -- ,NULL id
  602. -- RETURN;
  603. --END
  604. --ELSE
  605. --BEGIN
  606. -- SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
  607. --END
  608. END
  609. ELSE
  610. BEGIN
  611. SET @serviceCharge = ISNULL(@manualSc, 0)
  612. END
  613. IF @serviceCharge IS NULL
  614. AND ISNULL(@isManualSc, 'N') = 'N'
  615. BEGIN
  616. SELECT '4' ErrorCode
  617. ,'Service charge not defined yet for receiving country' Msg
  618. ,NULL id
  619. RETURN;
  620. END
  621. END
  622. IF @scAction = 'PD' -- Percent Discount
  623. BEGIN
  624. SET @scOffer = (@scValue / 100) * @serviceCharge
  625. SET @scDiscount = (@scValue / 100) * @serviceCharge
  626. END
  627. ELSE IF @scAction = 'FD' -- Flat Discount
  628. BEGIN
  629. SET @scDiscount = @scValue
  630. END
  631. ELSE IF @scAction = 'FV' -- Fixed Value
  632. BEGIN
  633. SET @scOffer = @scValue
  634. SET @scDiscount = @serviceCharge - @scValue
  635. END
  636. SET @tAmt = @cAmt - @serviceCharge + @scDiscount + ISNULL(@discountedFee, 0)
  637. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  638. --SET @pAmt = FLOOR(@pAmt)
  639. END
  640. ELSE
  641. BEGIN
  642. --SET @tAmt = CEILING(@pAmt / (@exRate + @exRateOffer))
  643. SET @tAmt = @pAmt / (@exRate + @exRateOffer)
  644. IF ISNULL(@isManualSc, 'N') = 'N'
  645. BEGIN
  646. SELECT @serviceChargetmp = isnull(amount, 0)
  647. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmt, @collCurr)
  648. --IF (@discountedFee > '0.00')
  649. -- AND (@serviceCharge < @discountedFee)
  650. --BEGIN
  651. -- SELECT '8' ErrorCode
  652. -- ,'Redeem points can not be more than service charge' Msg
  653. -- ,NULL id
  654. -- RETURN;
  655. --END
  656. --ELSE
  657. --BEGIN
  658. -- SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
  659. --END
  660. END
  661. ELSE
  662. BEGIN
  663. SET @serviceCharge = ISNULL(@manualSc, 0)
  664. END
  665. IF @serviceCharge IS NULL
  666. BEGIN
  667. SELECT '4' ErrorCode
  668. ,'Service charge not defined yet for receiving country' Msg
  669. ,NULL id
  670. RETURN;
  671. END
  672. IF @scAction = 'PD'
  673. BEGIN
  674. SET @scOffer = (@scValue / 100) * @serviceCharge
  675. SET @scDiscount = (@scValue / 100) * @serviceCharge
  676. END
  677. ELSE IF @scAction = 'FD'
  678. BEGIN
  679. SET @scDiscount = @scValue
  680. END
  681. ELSE IF @scAction = 'FV'
  682. BEGIN
  683. SET @scOffer = @scValue
  684. SET @scDiscount = @serviceCharge - @scValue
  685. END
  686. SET @cAmt = (@tAmt + @serviceCharge - @scDiscount)+ ISNULL(@discountedFee, 0)
  687. --SET @cAmt = ROUND(@cAmt, @currDecimal)
  688. --New logic for calculating new tAmt and pAmt after adding discount fee
  689. SET @tAmt = @tAmt + ISNULL(@discountedFee, 0)
  690. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  691. --SET @pAmt = FLOOR(@pAmt)
  692. END
  693. --4. Validate Country Sending Limit
  694. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit'
  695. ,@cAmt = @cAmt
  696. ,@pAmt = @pAmt
  697. ,@sCountryId = @sCountryId
  698. ,@collMode = @collMode
  699. ,@deliveryMethod = @deliveryMethodId
  700. ,@sendingCustType = @sendingCustType
  701. ,@pCountryId = @pCountryId
  702. ,@pCurr = @pCurr
  703. ,@collCurr = @collCurr
  704. ,@pAgent = @pAgent
  705. ,@sAgent = @sAgent
  706. ,@sBranch = @sBranch
  707. ,@msg = @msg OUT
  708. ,@errorCode = @errorCode OUT
  709. IF @errorCode <> '0'
  710. BEGIN
  711. SELECT @errorCode ErrorCode
  712. ,@msg Msg
  713. RETURN;
  714. END
  715. --Validate Country Sending Limit END
  716. --5. Validate Country Receiving Limit
  717. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit'
  718. ,@cAmt = @cAmt
  719. ,@pAmt = @pAmt
  720. ,@sCountryId = @sCountryId
  721. ,@collMode = @collMode
  722. ,@deliveryMethod = @deliveryMethodId
  723. ,@sendingCustType = @sendingCustType
  724. ,@pCountryId = @pCountryId
  725. ,@pCurr = @pCurr
  726. ,@collCurr = @collCurr
  727. ,@pAgent = @pAgent
  728. ,@sAgent = @sAgent
  729. ,@sBranch = @sBranch
  730. ,@msg = @msg OUT
  731. ,@errorCode = @errorCode OUT
  732. IF @errorCode <> '0'
  733. BEGIN
  734. SELECT @errorCode ErrorCode
  735. ,@msg Msg
  736. RETURN;
  737. END
  738. --Validate Country Receiving Limit
  739. IF ISNULL(@ProcessFor, '') = 'send'
  740. BEGIN
  741. SET @FOREX_SESSION_ID = NEWID()
  742. ----## lock ex rate for individual txn
  743. UPDATE exRateCalcHistory
  744. SET isExpired = 1
  745. WHERE CUSTOMER_ID = @senderId
  746. AND isExpired = 0
  747. INSERT INTO exRateCalcHistory (
  748. CUSTOMER_ID
  749. ,[USER_ID]
  750. ,FOREX_SESSION_ID
  751. ,serviceCharge
  752. ,pAmt
  753. ,customerRate
  754. ,sCurrCostRate
  755. ,sCurrHoMargin
  756. ,sCurrAgentMargin
  757. ,pCurrCostRate
  758. ,pCurrHoMargin
  759. ,pCurrAgentMargin
  760. ,agentCrossSettRate
  761. ,createdDate
  762. ,isExpired
  763. ,tAmt
  764. ,schemeId
  765. ,discountedFee
  766. ,sharingValue
  767. )
  768. SELECT @senderId
  769. ,@user
  770. ,@FOREX_SESSION_ID
  771. ,@serviceCharge
  772. ,@pAmt
  773. ,@exRate
  774. ,1
  775. ,0
  776. ,0
  777. ,@pCurrHoMargin + @exRate
  778. ,@pCurrHoMargin
  779. ,0
  780. ,@exRate
  781. ,GETDATE()
  782. ,0
  783. ,@tAmt
  784. ,@schemeId
  785. ,ISNULL(@discountedFee, 0)
  786. ,@schemeCount
  787. END
  788. SET @msg = 'Success'
  789. SELECT @errorCode ErrorCode
  790. ,@msg Msg
  791. ,scCharge = @serviceCharge
  792. ,exRate = @exRate
  793. ,place = @place
  794. ,pCurr = @pCurr
  795. ,currDecimal = @currDecimal
  796. ,pAmt = @pAmt
  797. ,sAmt = @tAmt
  798. ,place = @place
  799. ,disc = 0.00
  800. ,collAmt = @cAmt
  801. ,exRateOffer = @exRateOffer
  802. ,scOffer = @scDiscount
  803. ,scAction = @scAction
  804. ,scValue = @scValue
  805. ,scDiscount = @scDiscount
  806. ,tpExRate = @tpExRate
  807. ,amountLimitPerDay = 0
  808. ,amountLimitPerTran = 0
  809. ,customerTotalSentAmt = 0
  810. ,exRateDisplay = @exRate
  811. ,EXRATEID = @FOREX_SESSION_ID
  812. ,maxAmountLimitPerTran = 0
  813. ,minAmountLimitPerTran = 0
  814. ,PerTxnMinimumAmt = 0
  815. ,schemeAppliedMsg = @schemeAppliedMsg
  816. ,schemeId = @schemeId
  817. ,tpPCurr = @pCurr
  818. ,collCurr = @collCurr
  819. ,ForexSessionId = @FOREX_SESSION_ID
  820. ,discountedFee = ISNULL(@discountedFee, 0)
  821. END
  822. END