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.

1081 lines
56 KiB

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