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.

1168 lines
57 KiB

3 months ago
3 months ago
3 months ago
3 months ago
7 months ago
3 months ago
7 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
7 months ago
3 months ago
3 months ago
3 months ago
7 months ago
3 months ago
7 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
7 months ago
7 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
7 months ago
3 months ago
7 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
7 months ago
3 months ago
7 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_get_exRate_master] Script Date: 6/14/2024 8:48:04 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 VARCHAR(50) = NULL
  35. ,@isPromoCode CHAR(1) = NULL
  36. )
  37. AS
  38. SET NOCOUNT ON;
  39. SET XACT_ABORT ON;
  40. -----------------------------------------
  41. --Sep 22 -> #109 ->Change the logic to choose highest Rate in case of Nepal
  42. -- #101 , #361 - Mobile Changes for Multi-Lingual
  43. -- #1526 - Post production fixes for Redeem & Earn
  44. -- #1590 - Customer Loyalty
  45. -- #5968 - sc revised
  46. -- #18600 - change in @flag = 'false' for exRate
  47. -- #27928 added validation for debit card payment
  48. --------------------------------------------
  49. BEGIN
  50. DECLARE @scValue MONEY
  51. ,@scAction CHAR(2)
  52. ,@scOffer MONEY
  53. ,@exRateOffer FLOAT
  54. ,@scDiscount MONEY
  55. DECLARE @place INT
  56. ,@currDecimal INT
  57. ,@collMode VARCHAR(30)
  58. ,@sendingCustType VARCHAR(30)
  59. ,@msg VARCHAR(150)
  60. ,@errorCode INT
  61. DECLARE @exRateCalByPartner BIT
  62. ,@pSuperAgent INT
  63. ,@serviceCharge MONEY
  64. ,@serviceChargetmp MONEY
  65. ,@tAmt MONEY
  66. ,@pSuperAgentName VARCHAR(100)
  67. ,@pBranch INT
  68. DECLARE @pAgentName VARCHAR(100)
  69. ,@pBranchName VARCHAR(100)
  70. ,@exRate FLOAT
  71. ,@pCurrHoMargin FLOAT
  72. ,@FOREX_SESSION_ID VARCHAR(40)
  73. DECLARE @tranCount INT = 0
  74. ,@schemeCount INT = 0
  75. ,@schemeAppliedMsg VARCHAR(100) = ''
  76. ,@isFirstTran CHAR(1) = 'N'
  77. ,@createdFrom CHAR(1) = NULL
  78. ,@isEligible CHAR(1) = 'N'
  79. ,@introducer VARCHAR(25) = NULL
  80. --IF @ProcessFor IN ('send')
  81. --BEGIN
  82. IF ISNULL(@user, 'onlinedefault') <> 'onlinedefault' --OR @user is not null
  83. BEGIN
  84. PRINT 'a'
  85. IF @senderId IS NULL
  86. OR @senderId = 0
  87. BEGIN
  88. SET @senderId = (
  89. SELECT customerId
  90. FROM customermaster(NOLOCK)
  91. WHERE username = @user
  92. )
  93. END
  94. --EXEC PROC_Customer_LoyaltyV2 @flag = 'check-eligible-v2'
  95. -- ,@isEligible = @isEligible OUT
  96. -- ,@referralCode = @introducer
  97. -- ,@tranCount = @trancount OUT
  98. -- ,@schemeCount = @schemeCount OUT
  99. -- ,@customerId = @senderId
  100. -- ,@createdFrom = 'M'
  101. IF NOT EXISTS (
  102. SELECT 1
  103. FROM (
  104. SELECT TOP 1 customerId
  105. FROM TRANSENDERS TS(NOLOCK)
  106. INNER JOIN remittran(NOLOCK) rt ON rt.id = ts.tranId
  107. WHERE customerId = @SenderId
  108. AND rt.tranStatus <> 'CANCEL' --AND rt.tranType='M'
  109. UNION ALL
  110. SELECT TOP 1 customerId
  111. FROM TRANSENDERSTEMP TT(NOLOCK)
  112. INNER JOIN remittrantemp(NOLOCK) rt ON rt.id = tt.tranId
  113. WHERE customerId = @SenderId
  114. AND rt.tranStatus <> 'CANCEL' --AND rt.tranType='M'
  115. ) a
  116. WHERE customerId = @SenderId
  117. )
  118. BEGIN
  119. SET @isFirstTran = 'Y'
  120. END
  121. END
  122. PRINT '@isFirstTran' + '-> ' + @isFirstTran
  123. SELECT @createdFrom = serviceUsedFor
  124. FROM customerMaster(NOLOCK)
  125. WHERE customerId = @senderId
  126. PRINT '@senderId'
  127. PRINT @senderId;
  128. SET @sCountryId = 233
  129. SET @sAgent = '394395';
  130. IF ISNULL(@pCountryId, 0) = 0
  131. SELECT @pCountryId = countryId
  132. FROM countryMaster(NOLOCK)
  133. WHERE COUNTRYNAME = @pCountry
  134. IF @flag = 'False'
  135. AND @ProcessFor IN ('dashboard')
  136. BEGIN
  137. SELECT @payoutPartner = AGENTID
  138. ,@exRateCalByPartner = ISNULL(exRateCalByPartner, 0)
  139. FROM TblPartnerwiseCountry(NOLOCK)
  140. WHERE CountryId = @pCountryId
  141. AND IsActive = 1
  142. AND ISNULL(IsMobileEnabled, 0) = 1
  143. AND ISNULL(PaymentMethod, @deliveryMethodId) = @deliveryMethodId
  144. END
  145. ELSE
  146. BEGIN
  147. SELECT @payoutPartner = AGENTID
  148. ,@exRateCalByPartner = ISNULL(exRateCalByPartner, 0)
  149. FROM TblPartnerwiseCountry(NOLOCK)
  150. WHERE CountryId = @pCountryId
  151. AND IsActive = 1
  152. AND ISNULL(PaymentMethod, @deliveryMethodId) = @deliveryMethodId
  153. END
  154. PRINT '@payoutPartner'
  155. PRINT @payoutPartner;
  156. IF @payoutPartner IS NOT NULL
  157. BEGIN
  158. --GET PAYOUT AGENT DETAILS
  159. SELECT @PAGENT = AGENTID
  160. FROM AGENTMASTER(NOLOCK)
  161. WHERE PARENTID = @payoutPartner
  162. AND ISNULL(ISSETTLINGAGENT, 'N') = 'Y';
  163. SELECT @pSuperAgent = sSuperAgent
  164. ,@pSuperAgentName = sSuperAgentName
  165. ,@pAgent = sAgent
  166. ,@pAgentName = sAgentName
  167. ,@pBranch = sBranch
  168. ,@pBranchName = sBranchName
  169. FROM dbo.FNAGetBranchFullDetails(@PAGENT)
  170. END
  171. ELSE
  172. BEGIN
  173. SELECT '1' ErrorCode
  174. ,'Partner not yet mapped for the selected country!' Msg
  175. ,NULL id
  176. RETURN
  177. END
  178. DECLARE @rowId INT
  179. SELECT @scValue = 0
  180. ,@scOffer = 0
  181. ,@exRateOffer = 0
  182. ,@scDiscount = 0
  183. SELECT @place = place
  184. ,@currDecimal = currDecimal
  185. FROM currencyPayoutRound WITH (NOLOCK)
  186. WHERE ISNULL(isDeleted, 'N') = 'N'
  187. AND currency = @pCurr
  188. AND ISNULL(tranType, @deliveryMethodId) = @deliveryMethodId
  189. SET @currDecimal = ISNULL(@currDecimal, 0)
  190. IF @pCurr IS NULL
  191. BEGIN
  192. SELECT '2' ErrorCode
  193. ,'Currency not been defined yet for receiving country' Msg
  194. ,NULL id
  195. RETURN
  196. END
  197. --pRINT @pAgent;
  198. IF @flag = 'false'
  199. BEGIN
  200. IF @pCountryId = 151
  201. AND @deliveryMethodId = 1
  202. BEGIN
  203. SELECT AgentId
  204. INTO #AgentList
  205. FROM agentMaster(NOLOCK)
  206. WHERE extCode = 'NP ANYWHERE'
  207. SELECT @exRate = customerRate
  208. ,@pCurrHoMargin = pCurrHoMargin
  209. FROM (
  210. SELECT ROW_NUMBER() OVER (
  211. ORDER BY CUSTOMERRATE DESC
  212. ) ROW_NUM
  213. ,CUSTOMERRATE
  214. ,pCurrHoMargin
  215. FROM #AgentList A
  216. CROSS APPLY dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, AgentId, @pCurr, @deliveryMethodId) FN
  217. ) X
  218. WHERE X.ROW_NUM = 1
  219. END
  220. ELSE
  221. BEGIN
  222. PRINT @sCountryId;
  223. PRINT '@sAgent';
  224. PRINT @sAgent;
  225. PRINT '@sBranch';
  226. PRINT @sBranch;
  227. PRINT @collCurr;
  228. PRINT @pCountryId;
  229. PRINT @pCurr;
  230. PRINT @deliveryMethodId;
  231. PRINT '@pAgent';
  232. PRINT @pAgent;
  233. SELECT @exRate = customerRate
  234. ,@pCurrHoMargin = pCurrHoMargin
  235. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  236. END
  237. IF ISNULL(@exRate, 0) = 0
  238. BEGIN
  239. SELECT '3' ErrorCode
  240. ,'Exchange rate not defined yet for receiving currency (' + @pCurr + ')' Msg
  241. ,NULL id
  242. RETURN
  243. END
  244. IF @tpExRate > 0
  245. AND @isFirstTran = 'N'
  246. BEGIN
  247. SET @exRate = @exRate - @tpExRate
  248. END
  249. ELSE
  250. BEGIN
  251. DECLARE @rate FLOAT
  252. ,@promRate FLOAT
  253. SELECT @rate = ISNULL(margin, 0)
  254. ,@promRate = ISNULL(purchaseRate, 0)
  255. FROM countryWiseExchangeRate
  256. WHERE depositType = 'ONLINE'
  257. AND countryId = @pCountryId
  258. PRINT ' @rate'
  259. PRINT @rate
  260. PRINT '@promRate'
  261. PRINT @promRate
  262. IF @isFirstTran = 'Y'
  263. SET @exRate = @exRate - (ISNULL(@rate, 0) + ISNULL(@promRate, 0))
  264. ELSE
  265. SET @exRate = @exRate - ISNULL(@rate, 0)
  266. END
  267. --IF(ISNULL(@discountedFee,0)> 0)
  268. --BEGIN
  269. -- IF dbo.FNA_GET_AVAILABLE_BALANCE_POINTS(@senderId) < ISNULL(@discountedFee, 0)
  270. -- BEGIN
  271. -- SELECT '1' ErrorCode
  272. -- ,'You do not have sufficient Reward Amount!' Msg
  273. -- ,NULL id
  274. -- RETURN
  275. -- END
  276. --END
  277. DECLARE @ValidationResult TABLE (
  278. IS_VALID VARCHAR(50)
  279. ,ROW_ID INT
  280. ,PROMOTIONAL_CODE VARCHAR(50)
  281. ,PROMOTIONAL_MSG VARCHAR(255)
  282. ,
  283. -- PROMOTION_TYPE INT,
  284. PROMOTION_VALUE MONEY
  285. ,MIN_SENDING_AMT MONEY
  286. ,START_DT DATETIME
  287. ,END_DT DATETIME
  288. )
  289. DECLARE @availableRewardAmt INT
  290. ,@row_id INT
  291. ,@promoValue MONEY
  292. ,@minSendAmt MONEY
  293. ,@startDate DATETIME
  294. ,@endDate DATETIME
  295. ,@errMsg VARCHAR(100)
  296. ,@promoCode VARCHAR(100)
  297. SELECT @availableRewardAmt = CAST(dbo.[FNA_GET_AVAILABLE_BALANCE_POINTS](@senderId) AS INT)
  298. DECLARE @minCollAmt MONEY
  299. ,@maxRewardAmt MONEY
  300. SELECT @maxRewardAmt = CAST(detailTitle AS MONEY)
  301. FROM staticDataValue
  302. WHERE typeID = '10200'
  303. AND detailDesc = 'MAX_REWARD_AMT'
  304. SELECT @minCollAmt = CAST(detailTitle AS MONEY)
  305. FROM staticDataValue
  306. WHERE typeID = '10200'
  307. AND detailDesc = 'MIN_COLL_AMT_FOR_REWARD'
  308. IF ISNUMERIC(ISNULL(@discountedFee, 0)) = 1
  309. BEGIN
  310. SET @isPromoCode = 'N'
  311. IF (ISNULL(@discountedFee, 0) > 0)
  312. BEGIN
  313. IF (@availableRewardAmt < ISNULL(@discountedFee, 0))
  314. BEGIN
  315. SELECT '1' ErrorCode
  316. ,'You do not have sufficient Rewards!'
  317. ,NULL id
  318. RETURN;
  319. END
  320. END
  321. IF (ISNULL(@discountedFee, 0) > ISNULL(@availableRewardAmt, 0))
  322. BEGIN
  323. SELECT '1' ErrorCode
  324. ,'Please enter the valid point. The amount cannot be more than available Reward Amount!' Msg
  325. ,NULL id
  326. RETURN
  327. END
  328. DECLARE @discountedFeeMoney MONEY = CAST(@discountedFee AS MONEY)
  329. IF (
  330. @discountedFeeMoney > '0.00'
  331. AND @cAmt < @minCollAmt
  332. AND @discountedFeeMoney > @maxRewardAmt
  333. )
  334. BEGIN
  335. SELECT '8' ErrorCode
  336. ,'The maximum reward amount per transaction is ' + CAST(@maxRewardAmt AS VARCHAR(20)) + ' Pounds and the minimum amount that can be sent for each transaction is ' + CAST(@minCollAmt AS VARCHAR(20)) + ' Pounds' Msg
  337. ,NULL id
  338. RETURN;
  339. END
  340. END
  341. ELSE
  342. BEGIN
  343. SET @isPromoCode = 'Y'
  344. PRINT 'promo'
  345. PRINT @pCountryId
  346. INSERT INTO @ValidationResult (
  347. IS_VALID
  348. ,ROW_ID
  349. ,PROMOTIONAL_CODE
  350. ,PROMOTIONAL_MSG
  351. ,PROMOTION_VALUE
  352. ,MIN_SENDING_AMT
  353. ,START_DT
  354. ,END_DT
  355. )
  356. EXEC proc_CheckPromoValidity @flag = 'chk-validity'
  357. ,@countryId = @pCountryId
  358. ,@pmode = @deliveryMethodId
  359. ,@promoCode = @discountedFee
  360. --select * FROM @ValidationResult;
  361. --RETURN;
  362. IF EXISTS (
  363. SELECT 'X'
  364. FROM @ValidationResult
  365. WHERE IS_VALID = 'VALID'
  366. )
  367. BEGIN
  368. SELECT @row_id = ROW_ID
  369. ,@promoValue = PROMOTION_VALUE
  370. ,@minSendAmt = MIN_SENDING_AMT
  371. ,@startDate = START_DT
  372. ,@endDate = END_DT
  373. FROM @ValidationResult
  374. WHERE IS_VALID = 'VALID'
  375. SET @promoCode = @discountedFee
  376. SET @discountedFee = @promoValue
  377. IF (@cAmt < @minSendAmt)
  378. BEGIN
  379. SELECT '8' ErrorCode
  380. ,'The minimum amount per transaction should be ' + CAST(@minSendAmt AS VARCHAR(20)) + ' Pounds to use Promo Code' Msg
  381. ,NULL id
  382. RETURN;
  383. END
  384. END
  385. ELSE
  386. BEGIN
  387. SELECT @errMsg = PROMOTIONAL_MSG
  388. FROM @ValidationResult
  389. WHERE IS_VALID = 'INVALID'
  390. SELECT '1' ErrorCode
  391. ,@errMsg Msg
  392. RETURN
  393. END
  394. END
  395. --PRINT '@isFirstTran:' + CAST( @isFirstTran AS VARCHAR);
  396. --PRINT '@isEligible:' + CAST( @isEligible AS VARCHAR);
  397. -- PRINT '@tranCount:' + CAST( @tranCount AS VARCHAR);
  398. -- PRINT '@@schemeCount:' + CAST( @schemeCount AS VARCHAR);
  399. IF @calBy = 'C'
  400. BEGIN
  401. BEGIN
  402. IF ISNULL(@isManualSc, 'N') = 'N'
  403. BEGIN
  404. PRINT '@serviceChargetmp';
  405. SELECT @serviceChargetmp = isnull(amount, 0)
  406. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
  407. PRINT @serviceChargetmp
  408. IF (@discountedFee < '0.00')
  409. --AND (@serviceChargetmp < @discountedFee)
  410. BEGIN
  411. SELECT '8' ErrorCode
  412. ,'Redeem Amount cannot be less than zero' Msg
  413. ,NULL id
  414. RETURN;
  415. END
  416. ELSE
  417. BEGIN
  418. --SELECT @serviceCharge = @serviceChargetmp - ISNULL(@discountedFee, 0)
  419. SELECT @serviceCharge = @serviceChargetmp
  420. END
  421. END
  422. ELSE
  423. BEGIN
  424. SET @serviceCharge = ISNULL(@manualSc, 0)
  425. END
  426. IF @serviceCharge IS NULL
  427. AND ISNULL(@isManualSc, 'N') = 'N'
  428. BEGIN
  429. SELECT '4' ErrorCode
  430. ,'Service charge not defined yet for receiving country' Msg
  431. ,NULL id
  432. RETURN;
  433. END
  434. END
  435. IF @scAction = 'PD' -- Percent Discount
  436. BEGIN
  437. SET @scOffer = (@scValue / 100) * @serviceCharge
  438. SET @scDiscount = (@scValue / 100) * @serviceCharge
  439. END
  440. ELSE IF @scAction = 'FD' -- Flat Discount
  441. BEGIN
  442. SET @scDiscount = @scValue
  443. END
  444. ELSE IF @scAction = 'FV' -- Fixed Value
  445. BEGIN
  446. SET @scOffer = @scValue
  447. SET @scDiscount = @serviceCharge - @scValue
  448. END
  449. --IF (@discountedFee > @serviceCharge)
  450. -- BEGIN
  451. -- SELECT '8' ErrorCode
  452. -- ,'Redeem Amount cannot be higher than Transfer fee.' Msg
  453. -- ,NULL id
  454. -- RETURN;
  455. -- END
  456. SET @tAmt = @cAmt - @serviceCharge + @scDiscount + ISNULL(@discountedFee, 0)
  457. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  458. --PRINT @pAmt;
  459. --SET @pAmt = FLOOR(@pAmt)
  460. SET @tAmt = Cast(Round(@tAmt, 2, 0) AS DECIMAL(18, 2));
  461. SET @pAmt = Cast(Round(@pAmt, 2, 0) AS DECIMAL(18, 2));
  462. --PRINT @pAmt;
  463. END
  464. ELSE
  465. BEGIN
  466. --SET @tAmt = CEILING(@pAmt/(@exRate + @exRateOffer), 0)
  467. --SET @tAmt = CEILING(@pAmt / (@exRate + @exRateOffer))
  468. SET @tAmt = @pAmt / (@exRate + @exRateOffer);
  469. BEGIN
  470. IF ISNULL(@isManualSc, 'N') = 'N'
  471. BEGIN
  472. SELECT @serviceChargetmp = isnull(amount, 0)
  473. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmt, @collCurr)
  474. IF (@discountedFee < '0.00')
  475. --AND (@serviceChargetmp < @discountedFee)
  476. BEGIN
  477. SELECT '8' ErrorCode
  478. ,'Redeem Amount cannot be less than zero' Msg
  479. ,NULL id
  480. RETURN;
  481. END
  482. ELSE
  483. BEGIN
  484. SELECT @serviceCharge = @serviceChargetmp;
  485. END
  486. END
  487. ELSE
  488. BEGIN
  489. SET @serviceCharge = ISNULL(@manualSc, 0)
  490. END
  491. IF @serviceCharge IS NULL
  492. BEGIN
  493. SELECT '4' ErrorCode
  494. ,'Service charge not defined yet for receiving country' Msg
  495. ,NULL id
  496. RETURN;
  497. END
  498. END
  499. IF @scAction = 'PD'
  500. BEGIN
  501. SET @scOffer = (@scValue / 100) * @serviceCharge
  502. SET @scDiscount = (@scValue / 100) * @serviceCharge
  503. END
  504. ELSE IF @scAction = 'FD'
  505. BEGIN
  506. SET @scDiscount = @scValue
  507. END
  508. ELSE IF @scAction = 'FV'
  509. BEGIN
  510. SET @scOffer = @scValue
  511. SET @scDiscount = @serviceCharge - @scValue
  512. END
  513. PRINT '@discountedFee'
  514. PRINT @discountedFee
  515. PRINT @serviceCharge
  516. --IF (@discountedFee > @serviceCharge)
  517. -- BEGIN
  518. -- SELECT '8' ErrorCode
  519. -- ,'Redeem Amount cannot be higher than Transfer fee.' Msg
  520. -- ,NULL id
  521. -- RETURN;
  522. -- END
  523. SET @cAmt = (@tAmt + @serviceCharge - @scDiscount) - ISNULL(@discountedFee, 0)
  524. SET @tAmt = Cast(Round(@tAmt, 2, 0) AS DECIMAL(18, 2));
  525. SET @cAmt = Cast(Round(@cAmt, 2, 0) AS DECIMAL(18, 2))
  526. --SET @cAmt = CEILING(@cAmt)
  527. END
  528. IF (
  529. @discountedFeeMoney > '0.00'
  530. AND @discountedFeeMoney > @maxRewardAmt
  531. )
  532. BEGIN
  533. SELECT '8' ErrorCode
  534. ,'The maximum reward amount per transaction is ' + CAST(@maxRewardAmt AS VARCHAR(20)) + ' Pounds' Msg
  535. ,NULL id
  536. RETURN;
  537. END
  538. IF (
  539. @discountedFeeMoney > '0.00'
  540. AND @cAmt < @minCollAmt
  541. )
  542. BEGIN
  543. SELECT '8' ErrorCode
  544. ,'The minimum amount that can be sent for each transaction is ' + CAST(@minCollAmt AS VARCHAR(20)) + ' Pounds' Msg
  545. ,NULL id
  546. RETURN;
  547. END
  548. --4. Validate Country Sending Limit
  549. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit'
  550. ,@cAmt = @cAmt
  551. ,@pAmt = @pAmt
  552. ,@sCountryId = @sCountryId
  553. ,@collMode = @collMode
  554. ,@deliveryMethod = @deliveryMethodId
  555. ,@sendingCustType = @sendingCustType
  556. ,@pCountryId = @pCountryId
  557. ,@pCurr = @pCurr
  558. ,@collCurr = @collCurr
  559. ,@pAgent = @pAgent
  560. ,@sAgent = @sAgent
  561. ,@sBranch = @sBranch
  562. ,@msg = @msg OUT
  563. ,@errorCode = @errorCode OUT
  564. IF @errorCode <> '0'
  565. BEGIN
  566. SELECT @errorCode ErrorCode
  567. ,@msg Msg
  568. RETURN;
  569. END
  570. --Validate Country Sending Limit END
  571. --5. Validate Country Receiving Limit
  572. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit'
  573. ,@cAmt = @cAmt
  574. ,@pAmt = @pAmt
  575. ,@sCountryId = @sCountryId
  576. ,@collMode = @collMode
  577. ,@deliveryMethod = @deliveryMethodId
  578. ,@sendingCustType = @sendingCustType
  579. ,@pCountryId = @pCountryId
  580. ,@pCurr = @pCurr
  581. ,@collCurr = @collCurr
  582. ,@pAgent = @pAgent
  583. ,@sAgent = @sAgent
  584. ,@sBranch = @sBranch
  585. ,@msg = @msg OUT
  586. ,@errorCode = @errorCode OUT
  587. IF @errorCode <> '0'
  588. BEGIN
  589. SELECT @errorCode ErrorCode
  590. ,@msg Msg
  591. RETURN;
  592. END
  593. DECLARE @maxAmt MONEY
  594. SELECT @maxAmt = maxAmt
  595. FROM countryWiseExchangeRate
  596. WHERE depositType = 'DEBIT_CARD'
  597. AND countryId = @pCountryId
  598. IF (
  599. @schemeId = 'DEBIT_CARD'
  600. AND @cAmt > @maxAmt
  601. )
  602. BEGIN
  603. SELECT '3' ErrorCode
  604. ,'You cannot send more than ' + CAST(@maxAmt AS VARCHAR) + ' GBP via Debit Card. Please select Online Banking to complete the transaction or we will automatically redirect to Bank Transfer.' Msg
  605. ,NULL id
  606. RETURN
  607. END
  608. IF ISNULL(@ProcessFor, '') = 'send'
  609. BEGIN
  610. SET @FOREX_SESSION_ID = NEWID()
  611. ----## lock ex rate for individual txn
  612. UPDATE exRateCalcHistory
  613. SET isExpired = 1
  614. WHERE CUSTOMER_ID = @senderId
  615. AND isExpired = 0
  616. PRINT @serviceCharge;
  617. INSERT INTO exRateCalcHistory (
  618. CUSTOMER_ID
  619. ,[USER_ID]
  620. ,FOREX_SESSION_ID
  621. ,serviceCharge
  622. ,pAmt
  623. ,customerRate
  624. ,sCurrCostRate
  625. ,sCurrHoMargin
  626. ,sCurrAgentMargin
  627. ,pCurrCostRate
  628. ,pCurrHoMargin
  629. ,pCurrAgentMargin
  630. ,agentCrossSettRate
  631. ,createdDate
  632. ,isExpired
  633. ,tAmt
  634. ,schemeId
  635. ,discountedFee
  636. ,sharingValue
  637. ,customerPremium
  638. ,promoRowId
  639. )
  640. SELECT @senderId
  641. ,@user
  642. ,@FOREX_SESSION_ID
  643. ,@serviceCharge
  644. ,@pAmt
  645. ,@exRate
  646. ,1
  647. ,0
  648. ,0
  649. ,@pCurrHoMargin + @exRate
  650. ,@pCurrHoMargin
  651. ,0
  652. ,@exRate
  653. ,GETDATE()
  654. ,0
  655. ,@tAmt
  656. ,@schemeId
  657. ,ISNULL(@discountedFee, 0)
  658. ,@schemeCount
  659. ,@tpExRate
  660. ,@row_id
  661. END
  662. SET @msg = 'Success'
  663. PRINT @promRate
  664. PRINT @isFirstTran
  665. PRINT '@promRate1'
  666. IF (
  667. @promRate > 0
  668. AND @isFirstTran = 'Y'
  669. )
  670. SET @schemeAppliedMsg = 'Enjoy premium rate due to First Transaction!';
  671. DECLARE @promotionalRate FLOAT
  672. SELECT @rate = ISNULL(margin, 0)
  673. ,@promRate = ISNULL(purchaseRate, 0)
  674. FROM countryWiseExchangeRate
  675. WHERE depositType = ISNULL(@schemeId, 'ONLINE')
  676. AND countryId = @pCountryId
  677. SET @promotionalRate = @exRate - (ISNULL(@rate, 0) + ISNULL(@promRate, 0))
  678. DECLARE @promoPAmt MONEY
  679. IF @user = NULL
  680. OR @user IS NULL
  681. BEGIN
  682. SET @promoPAmt = @tAmt * (@promotionalRate + @exRateOffer)
  683. END
  684. SELECT @errorCode ErrorCode
  685. ,@msg Msg
  686. ,scCharge = @serviceCharge
  687. ,exRate = CASE
  688. WHEN @user = NULL
  689. OR @user IS NULL
  690. THEN @promotionalRate
  691. ELSE @exRate
  692. END
  693. ,place = @place
  694. ,pCurr = @pCurr
  695. ,currDecimal = @currDecimal
  696. ,pAmt = CASE
  697. WHEN @user = NULL
  698. OR @user IS NULL
  699. THEN @promoPAmt
  700. ELSE @pAmt
  701. END
  702. ,sAmt = @tAmt
  703. ,place = @place
  704. ,disc = 0.00
  705. ,collAmt = @cAmt
  706. ,exRateOffer = @exRateOffer
  707. ,scOffer = @scDiscount
  708. ,scAction = @scAction
  709. ,scValue = @scValue
  710. ,scDiscount = @scDiscount
  711. ,tpExRate = 0
  712. ,amountLimitPerDay = 0
  713. ,amountLimitPerTran = 0
  714. ,customerTotalSentAmt = 0
  715. ,exRateDisplay = @exRate
  716. ,EXRATEID = @FOREX_SESSION_ID
  717. ,maxAmountLimitPerTran = 0
  718. ,minAmountLimitPerTran = 0
  719. ,PerTxnMinimumAmt = 0
  720. ,schemeAppliedMsg = @schemeAppliedMsg
  721. ,schemeId = @schemeId
  722. ,tpPCurr = @pCurr
  723. ,collCurr = @collCurr
  724. ,ForexSessionId = @FOREX_SESSION_ID
  725. --,discountedFee = CASE WHEN @isPromoCode = 'N' THEN ISNULL(@discountedFee, 0)
  726. -- WHEN @isPromoCode = 'Y' THEN @promoCode
  727. -- ELSE ISNULL(@discountedFee, 0)
  728. -- END
  729. ,discountedFee = ISNULL(@discountedFee, 0)
  730. ,isPromoCode = @isPromoCode
  731. ,promoRowId = @row_id
  732. ,promoCode = @promoCode
  733. ,@promotionalRate promotionalRate
  734. END
  735. ELSE IF @FLAG = 'true'
  736. BEGIN
  737. IF ISNULL(@tpExRate, 0) = 0
  738. BEGIN
  739. SELECT '5' ErrorCode
  740. ,'Third Party Exchange rate fetching error for currency (' + @pCurr + ')' Msg
  741. RETURN
  742. END
  743. DECLARE @exRateDonga FLOAT
  744. ,@exRateBRAC FLOAT
  745. PRINT @sCountryId;
  746. PRINT @sCountryId;
  747. PRINT @sAgent;
  748. PRINT @sBranch;
  749. PRINT @collCurr;
  750. PRINT @pCountryId;
  751. PRINT @pAgent;
  752. PRINT @pCurr;
  753. PRINT @deliveryMethodId;
  754. SELECT @pCurrHoMargin = pCurrHoMargin
  755. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  756. SELECT @exRate = @tpExRate - ISNULL(@pCurrHoMargin, 0)
  757. IF ISNULL(@exRate, 0) = 0
  758. BEGIN
  759. SELECT '3' ErrorCode
  760. ,'Exchange rate not defined yet for receiving currency (' + @pCurr + ')' Msg
  761. ,NULL id
  762. RETURN
  763. END
  764. IF @user = 'onlinedefault'
  765. AND @pCountryId = 203
  766. BEGIN
  767. SELECT @exRateDonga = dbo.FNAGetCustomerRate(113, 0, 394395, 'JPY', 203, 394133, 'VND', 1)
  768. IF @exRateDonga > @exRate
  769. SET @exRate = @exRateDonga
  770. END
  771. IF @user = 'onlinedefault'
  772. AND @pCountryId = 16
  773. BEGIN
  774. SELECT @exRateBRAC = dbo.FNAGetCustomerRate(113, 0, 394395, 'JPY', 16, 394414, 'BDT', 1)
  775. IF @exRateBRAC > @exRate
  776. SET @exRate = @exRateBRAC
  777. END
  778. IF @calBy = 'C'
  779. BEGIN
  780. IF (
  781. @tranCount = @schemeCount
  782. AND ISNULL(@user, 'onlinedefault') <> 'onlinedefault'
  783. -- AND ISNULL(@ProcessFor, '') = 'send'
  784. AND @isEligible = 'Y'
  785. )
  786. OR (@isFirstTran = 'Y')
  787. BEGIN
  788. SET @serviceCharge = 0
  789. IF @isFirstTran = 'Y'
  790. BEGIN
  791. SET @schemeAppliedMsg = 'Enjoy zero (0) service charge due to First Transaction!';
  792. END
  793. ELSE
  794. SET @schemeAppliedMsg = 'Enjoy zero (0) service charge due to Loyalty Scheme!';
  795. END
  796. ELSE
  797. BEGIN
  798. IF ISNULL(@isManualSc, 'N') = 'N'
  799. BEGIN
  800. SELECT @serviceChargetmp = ISNULL(amount, 0)
  801. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
  802. --IF (@discountedFee > '0.00')
  803. -- AND (@serviceChargetmp < @discountedFee)
  804. --BEGIN
  805. -- SELECT '8' ErrorCode
  806. -- ,'Redeem points can not be more than service charge' Msg
  807. -- ,NULL id
  808. -- RETURN;
  809. --END
  810. --ELSE
  811. --BEGIN
  812. -- SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
  813. --END
  814. END
  815. ELSE
  816. BEGIN
  817. SET @serviceCharge = ISNULL(@manualSc, 0)
  818. END
  819. IF @serviceCharge IS NULL
  820. AND ISNULL(@isManualSc, 'N') = 'N'
  821. BEGIN
  822. SELECT '4' ErrorCode
  823. ,'Service charge not defined yet for receiving country' Msg
  824. ,NULL id
  825. RETURN;
  826. END
  827. END
  828. IF @scAction = 'PD' -- Percent Discount
  829. BEGIN
  830. SET @scOffer = (@scValue / 100) * @serviceCharge
  831. SET @scDiscount = (@scValue / 100) * @serviceCharge
  832. END
  833. ELSE IF @scAction = 'FD' -- Flat Discount
  834. BEGIN
  835. SET @scDiscount = @scValue
  836. END
  837. ELSE IF @scAction = 'FV' -- Fixed Value
  838. BEGIN
  839. SET @scOffer = @scValue
  840. SET @scDiscount = @serviceCharge - @scValue
  841. END
  842. SET @tAmt = @cAmt - @serviceCharge + @scDiscount + ISNULL(@discountedFee, 0)
  843. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  844. --SET @pAmt = FLOOR(@pAmt)
  845. END
  846. ELSE
  847. BEGIN
  848. --SET @tAmt = CEILING(@pAmt / (@exRate + @exRateOffer))
  849. SET @tAmt = @pAmt / (@exRate + @exRateOffer)
  850. IF ISNULL(@isManualSc, 'N') = 'N'
  851. BEGIN
  852. SELECT @serviceChargetmp = isnull(amount, 0)
  853. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmt, @collCurr)
  854. --IF (@discountedFee > '0.00')
  855. -- AND (@serviceCharge < @discountedFee)
  856. --BEGIN
  857. -- SELECT '8' ErrorCode
  858. -- ,'Redeem points can not be more than service charge' Msg
  859. -- ,NULL id
  860. -- RETURN;
  861. --END
  862. --ELSE
  863. --BEGIN
  864. -- SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
  865. --END
  866. END
  867. ELSE
  868. BEGIN
  869. SET @serviceCharge = ISNULL(@manualSc, 0)
  870. END
  871. IF @serviceCharge IS NULL
  872. BEGIN
  873. SELECT '4' ErrorCode
  874. ,'Service charge not defined yet for receiving country' Msg
  875. ,NULL id
  876. RETURN;
  877. END
  878. IF @scAction = 'PD'
  879. BEGIN
  880. SET @scOffer = (@scValue / 100) * @serviceCharge
  881. SET @scDiscount = (@scValue / 100) * @serviceCharge
  882. END
  883. ELSE IF @scAction = 'FD'
  884. BEGIN
  885. SET @scDiscount = @scValue
  886. END
  887. ELSE IF @scAction = 'FV'
  888. BEGIN
  889. SET @scOffer = @scValue
  890. SET @scDiscount = @serviceCharge - @scValue
  891. END
  892. SET @cAmt = (@tAmt + @serviceCharge - @scDiscount) + ISNULL(@discountedFee, 0)
  893. --SET @cAmt = ROUND(@cAmt, @currDecimal)
  894. --New logic for calculating new tAmt and pAmt after adding discount fee
  895. SET @tAmt = @tAmt + ISNULL(@discountedFee, 0)
  896. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  897. --SET @pAmt = FLOOR(@pAmt)
  898. END
  899. --4. Validate Country Sending Limit
  900. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit'
  901. ,@cAmt = @cAmt
  902. ,@pAmt = @pAmt
  903. ,@sCountryId = @sCountryId
  904. ,@collMode = @collMode
  905. ,@deliveryMethod = @deliveryMethodId
  906. ,@sendingCustType = @sendingCustType
  907. ,@pCountryId = @pCountryId
  908. ,@pCurr = @pCurr
  909. ,@collCurr = @collCurr
  910. ,@pAgent = @pAgent
  911. ,@sAgent = @sAgent
  912. ,@sBranch = @sBranch
  913. ,@msg = @msg OUT
  914. ,@errorCode = @errorCode OUT
  915. IF @errorCode <> '0'
  916. BEGIN
  917. SELECT @errorCode ErrorCode
  918. ,@msg Msg
  919. RETURN;
  920. END
  921. --Validate Country Sending Limit END
  922. --5. Validate Country Receiving Limit
  923. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit'
  924. ,@cAmt = @cAmt
  925. ,@pAmt = @pAmt
  926. ,@sCountryId = @sCountryId
  927. ,@collMode = @collMode
  928. ,@deliveryMethod = @deliveryMethodId
  929. ,@sendingCustType = @sendingCustType
  930. ,@pCountryId = @pCountryId
  931. ,@pCurr = @pCurr
  932. ,@collCurr = @collCurr
  933. ,@pAgent = @pAgent
  934. ,@sAgent = @sAgent
  935. ,@sBranch = @sBranch
  936. ,@msg = @msg OUT
  937. ,@errorCode = @errorCode OUT
  938. IF @errorCode <> '0'
  939. BEGIN
  940. SELECT @errorCode ErrorCode
  941. ,@msg Msg
  942. RETURN;
  943. END
  944. --Validate Country Receiving Limit
  945. IF ISNULL(@ProcessFor, '') = 'send'
  946. BEGIN
  947. SET @FOREX_SESSION_ID = NEWID()
  948. ----## lock ex rate for individual txn
  949. UPDATE exRateCalcHistory
  950. SET isExpired = 1
  951. WHERE CUSTOMER_ID = @senderId
  952. AND isExpired = 0
  953. INSERT INTO exRateCalcHistory (
  954. CUSTOMER_ID
  955. ,[USER_ID]
  956. ,FOREX_SESSION_ID
  957. ,serviceCharge
  958. ,pAmt
  959. ,customerRate
  960. ,sCurrCostRate
  961. ,sCurrHoMargin
  962. ,sCurrAgentMargin
  963. ,pCurrCostRate
  964. ,pCurrHoMargin
  965. ,pCurrAgentMargin
  966. ,agentCrossSettRate
  967. ,createdDate
  968. ,isExpired
  969. ,tAmt
  970. ,schemeId
  971. ,discountedFee
  972. ,sharingValue
  973. )
  974. SELECT @senderId
  975. ,@user
  976. ,@FOREX_SESSION_ID
  977. ,@serviceCharge
  978. ,@pAmt
  979. ,@exRate
  980. ,1
  981. ,0
  982. ,0
  983. ,@pCurrHoMargin + @exRate
  984. ,@pCurrHoMargin
  985. ,0
  986. ,@exRate
  987. ,GETDATE()
  988. ,0
  989. ,@tAmt
  990. ,@schemeId
  991. ,ISNULL(@discountedFee, 0)
  992. ,@schemeCount
  993. END
  994. SET @msg = 'Success'
  995. PRINT @promRate
  996. PRINT @isFirstTran
  997. PRINT '@promRate1'
  998. IF (
  999. @promRate > 0
  1000. AND @isFirstTran = 'Y'
  1001. )
  1002. SET @schemeAppliedMsg = 'Enjoy premium rate due to First Transaction!';
  1003. SELECT @errorCode ErrorCode
  1004. ,@msg Msg
  1005. ,scCharge = @serviceCharge
  1006. ,exRate = @exRate
  1007. ,place = @place
  1008. ,pCurr = @pCurr
  1009. ,currDecimal = @currDecimal
  1010. ,pAmt = @pAmt
  1011. ,sAmt = @tAmt
  1012. ,place = @place
  1013. ,disc = 0.00
  1014. ,collAmt = @cAmt
  1015. ,exRateOffer = @exRateOffer
  1016. ,scOffer = @scDiscount
  1017. ,scAction = @scAction
  1018. ,scValue = @scValue
  1019. ,scDiscount = @scDiscount
  1020. ,tpExRate = @tpExRate
  1021. ,amountLimitPerDay = 0
  1022. ,amountLimitPerTran = 0
  1023. ,customerTotalSentAmt = 0
  1024. ,exRateDisplay = @exRate
  1025. ,EXRATEID = @FOREX_SESSION_ID
  1026. ,maxAmountLimitPerTran = 0
  1027. ,minAmountLimitPerTran = 0
  1028. ,PerTxnMinimumAmt = 0
  1029. ,schemeAppliedMsg = @schemeAppliedMsg
  1030. ,schemeId = @schemeId
  1031. ,tpPCurr = @pCurr
  1032. ,collCurr = @collCurr
  1033. ,ForexSessionId = @FOREX_SESSION_ID
  1034. ,discountedFee = ISNULL(@discountedFee, 0)
  1035. END
  1036. END