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.

1790 lines
142 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_Online_sendTxnTP] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_Online_sendTxn]
  9. (
  10. @flag VARCHAR(50) ,
  11. @user VARCHAR(100) ,
  12. @senderId VARCHAR(50) = NULL ,
  13. @sIpAddress VARCHAR(50) = NULL ,
  14. @benId VARCHAR(50) = NULL ,
  15. @rfName VARCHAR(100) = NULL ,
  16. @sIdType VARCHAR(100) =NULL,
  17. @sIdNo VARCHAR(100) =NULL,
  18. @sMobile VARCHAR(50) = NULL ,
  19. @rIdType VARCHAR(100) = NULL ,
  20. @rIdNo VARCHAR(50) = NULL ,
  21. @rIdValid DATETIME = NULL ,
  22. @rdob DATETIME = NULL ,
  23. @rTel VARCHAR(20) = NULL ,
  24. @rMobile VARCHAR(20) = NULL ,
  25. @rNaCountry VARCHAR(50) = NULL ,
  26. @rcity VARCHAR(100) = NULL ,
  27. @rAdd1 VARCHAR(150) = NULL ,
  28. @rEmail VARCHAR(100) = NULL ,
  29. @raccountNo VARCHAR(50) = NULL ,
  30. @pCountry VARCHAR(50) = NULL -- pay country
  31. ,@pCountryId INT = NULL -- PAY COUNTRY ID
  32. ,@deliveryMethod VARCHAR(50) = NULL -- payment mode
  33. ,@deliveryMethodId INT = NULL -- payment mode ID
  34. ,@pBank INT = NULL ,
  35. @pBankName VARCHAR(100) = NULL ,
  36. @pBankBranch INT = NULL ,
  37. @pBankBranchName VARCHAR(100) = NULL ,
  38. @pAgent INT = NULL ,
  39. @pAgentName VARCHAR(100) = NULL ,
  40. @pBranch INT = NULL ,
  41. @pBranchName VARCHAR(100) = NULL ,
  42. @pBankType CHAR(1) = NULL ,
  43. @pSuperAgent INT = NULL ,
  44. @pCurr VARCHAR(3) = NULL ,
  45. @collCurr VARCHAR(3) = NULL ,
  46. @cAmt MONEY = NULL ,
  47. @pAmt MONEY = NULL ,
  48. @tAmt MONEY = NULL ,
  49. @serviceCharge MONEY = NULL ,
  50. @discount MONEY = NULL ,
  51. @exRate DECIMAL(12,9) = NULL ,
  52. @purpose VARCHAR(150) = NULL ,
  53. @sourceOfFund VARCHAR(150) = NULL ,
  54. @relationship VARCHAR(100) = NULL ,
  55. @occupation VARCHAR(100) = NULL ,
  56. @payMsg VARCHAR(1000) = NULL ,
  57. @controlNo VARCHAR(20) = NULL ,
  58. @sCountryId INT = NULL ,
  59. @sCountry VARCHAR(100) = NULL ,
  60. @sBranch INT = NULL ,
  61. @sBranchName VARCHAR(100) = NULL ,
  62. @sAgent INT = NULL ,
  63. @sAgentName VARCHAR(100) = NULL ,
  64. @sSuperAgent INT = NULL ,
  65. @sSuperAgentName VARCHAR(100) = NULL ,
  66. @settlingAgent INT = NULL ,
  67. @branchMapCode VARCHAR(10) = NULL ,
  68. @agentMapCode VARCHAR(10) = NULL ,
  69. @collMode VARCHAR(50) = NULL ,
  70. @depositMode VARCHAR(50) = NULL, -- DEPOSIT MODE CASH OR BANK
  71. @calBy CHAR(1) = NULL ,
  72. @scDiscount MONEY = NULL ,
  73. @cardOnline VARCHAR(50) = NULL ,
  74. @memberShipId VARCHAR(50) = NULL ,
  75. @agentRefId VARCHAR(50) = NULL ,
  76. @couponCode VARCHAR(20) = NULL ,
  77. @schemeId BIGINT = NULL ,
  78. @tranId VARCHAR(50) = NULL ,
  79. @ScOrderNo BIGINT = NULL ,
  80. @unitaryBankAccountNo VARCHAR(50) = NULL ,
  81. @RState VARCHAR(10) = NULL,
  82. @RStateText VARCHAR(150) = NULL,
  83. @RLocation VARCHAR(20) = NULL,
  84. @RLocationText VARCHAR(150) = NULL,
  85. @VoucherXML XML=NULL,
  86. @tpRefNo VARCHAR(20) = NULL,
  87. @tpTranId VARCHAR(20) = NULL,
  88. @payOutPartner BIGINT = NULL,
  89. @FOREX_SESSION_ID VARCHAR(40) = NULL,
  90. @kftcLogId BIGINT = NULL,
  91. @paymentType VARCHAR(20) = NULL
  92. )
  93. AS
  94. SET NOCOUNT ON;
  95. SET XACT_ABORT ON;
  96. IF @paymentType IS NULL
  97. set @paymentType ='wallet'
  98. IF @paymentType='autodebit'
  99. BEGIN
  100. DECLARE @DATE DATETIME, @NextDate datetime
  101. select @DATE = CAST(GETDATE() AS DATE)
  102. SELECT @NextDate = DATEADD(DAY,1,@DATE)
  103. SELECT @DATE = @DATE+' 23:20:00',@NextDate = @NextDate+' 00:40:00'
  104. IF GETDATE() BETWEEN @DATE AND @NextDate
  105. BEGIN
  106. SELECT '1' ErrorCode ,'KFTC service is not available between 11:30 PM to 12:30 AM' Msg ,NULL ID
  107. RETURN
  108. END
  109. END
  110. BEGIN TRY
  111. BEGIN
  112. DECLARE @sCurrCostRate FLOAT ,
  113. @sCurrHoMargin FLOAT ,
  114. @pCurrCostRate FLOAT ,
  115. @pCurrHoMargin FLOAT ,
  116. @sCurrAgentMargin FLOAT ,
  117. @pCurrAgentMargin FLOAT ,
  118. @sCurrSuperAgentMargin FLOAT ,
  119. @pCurrSuperAgentMargin FLOAT ,
  120. @customerRate DECIMAL(15,10) ,
  121. @sAgentSettRate FLOAT ,
  122. @pDateCostRate FLOAT ,
  123. @agentCrossSettRate FLOAT ,
  124. @treasuryTolerance FLOAT ,
  125. @customerPremium FLOAT ,
  126. @schemePremium MONEY = NULL,
  127. @sharingValue MONEY ,
  128. @sharingType CHAR(1) ,
  129. @sAgentComm MONEY ,
  130. @sAgentCommCurrency VARCHAR(3) ,
  131. @sSuperAgentComm MONEY ,
  132. @sSuperAgentCommCurrency VARCHAR(3) ,
  133. @pAgentComm MONEY ,
  134. @pAgentCommCurrency VARCHAR(3) ,
  135. @pCommissionType CHAR(1) ,
  136. @pSuperAgentComm MONEY ,
  137. @pSuperAgentCommCurrency VARCHAR(3) ,
  138. @pSuperAgentName VARCHAR(100),
  139. @pStateId INT,
  140. @senderName VARCHAR(100) ,
  141. @id INT ,
  142. @customerStatus VARCHAR(20) ,
  143. @idExpiryDate DATETIME,
  144. @customerType INT;
  145. DECLARE @errorCode CHAR(1)= '0' ,@agentAvlLimit MONEY;
  146. DECLARE @rowId INT;
  147. DECLARE @scValue MONEY ,
  148. @exRateOffer MONEY ,
  149. @scAction VARCHAR(5) ,
  150. @AmountLimitPerTran MONEY ,
  151. @AmountLimitPerDay MONEY ,
  152. @todaysTotalSent MONEY ,
  153. @tranMinimum MONEY ,
  154. @tranMaximum MONEY
  155. DECLARE @ad FLOAT;
  156. DECLARE @xAmt MONEY ,
  157. @sendingCustType INT ,
  158. @msg VARCHAR(MAX);
  159. DECLARE @iServiceCharge MONEY ,
  160. @iTAmt MONEY ,
  161. @iPAmt MONEY ,
  162. @iCAmt MONEY ,
  163. @iCustomerRate FLOAT
  164. DECLARE @place INT ,
  165. @currDecimal INT;
  166. DECLARE @controlNoEncrypted VARCHAR(20);
  167. DECLARE @csMasterId INT ,
  168. @count INT ,
  169. @compFinalRes VARCHAR(20);
  170. DECLARE @GMTDate VARCHAR(50);
  171. DECLARE @createdDate DATETIME;
  172. DECLARE @SENDERS_IDENTITY_TYPE VARCHAR(50);
  173. SET @GMTDate = dbo.FNAGMTOnline(GETDATE(), @user);
  174. SELECT @sAgent = sAgent, @sAgentName = sAgentName, @sBranch = sBranch, @sBranchName = sBranchName,
  175. @sSuperAgent = sSuperAgent, @sSuperAgentName = sSuperAgentName
  176. FROM dbo.FNAGetBranchFullDetails(@sBranch)
  177. IF @pCountryId IS NULL
  178. SELECT TOP 1 @pCountryId = countryId FROM countryMaster (NOLOCK) WHERE countryName = @pCountry
  179. IF @pCountry LIKE '%?%'
  180. SELECT TOP 1 @pCountry = COUNTRYNAME FROM COUNTRYMASTER (NOLOCK) WHERE COUNTRYID = @pCountryId
  181. SELECT @pBank = @pAgent,
  182. @pBankName = @pAgentName,
  183. @pBankBranch = @pBranch ,
  184. @pBankBranchName = CASE WHEN @pBranchName IS NULL THEN (SELECT TOP 1 agentName FROM agentMaster(NOLOCK) WHERE agentId = @pBranch) ELSE @pBranchName END;
  185. SELECT @pAgent = null ,
  186. @pAgentName = NULL ,
  187. @pBranch = NULL ,
  188. @pBranchName = NULL;
  189. DECLARE @discountType VARCHAR(2) = null, @discountvalue money =null, @couponType VARCHAR(3) = NULL, @discountPercent money = null, @couponName VARCHAR(20) = NULL
  190. SET @sCountryId = 118
  191. SET @sCountry = 'South Korea'
  192. SET @sAgentCommCurrency = 'KRW'
  193. if @pCountryId in(151) AND @deliveryMethod <> 'MOBILE WALLET'
  194. begin
  195. set @pAgent = @payOutPartner
  196. end
  197. else
  198. begin
  199. SELECT TOP 1 @pAgent = AM.agentId
  200. FROM agentMaster AM(NOLOCK)
  201. WHERE AM.parentId = @payOutPartner AND agentType=2903 AND AM.isSettlingAgent = 'Y' AND AM.isApiPartner = 1
  202. end
  203. DECLARE @SWIFTCODE VARCHAR(20)
  204. SELECT TOP 1 @SWIFTCODE = SWIFTCODE FROM AGENTMASTER(NOLOCK) WHERE agentId = @pBank AND agentType='2903' AND isActive='Y' AND agentCountryId IN('16','203','218','174')
  205. IF @SWIFTCODE IN('BNGC00000039','BNGB00000060','BNGB00000020')--dutchBangla
  206. SET @pAgent = '393864'
  207. ELSE IF @SWIFTCODE IN ('BNGC0000002','BNGB00000048')--agrani
  208. SET @pAgent = '404526'
  209. ELSE IF @SWIFTCODE IN('BNGC00000040','BNGB00000049')--islami
  210. SET @pAgent = '566853'
  211. --ELSE IF @SWIFTCODE = 'PHC0000003' ----## IF CEBUEANA LHUILLIER
  212. -- SET @pAgent = 601392
  213. --ELSE IF @SWIFTCODE IN ('VN00000040','VN00000006','VN00000005','VN00000003') AND @deliveryMethod='2' ----## IF Eximbank
  214. -- SET @pAgent = 601361
  215. ELSE IF @SWIFTCODE = 'THB00000023' ----## K BANK THAILAND
  216. SELECT @pAgent = 224389
  217. --ELSE IF @pBank = 566989 ----## Islami Bank Bangladesh Limited(EXRATE FROM LOCAL SETUP)
  218. -- SELECT @pAgent = 566853
  219. SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName,
  220. @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName
  221. FROM dbo.FNAGetBranchFullDetails(@pAgent)
  222. IF @flag = 'exRate' --Get Exchange Rate, Service Charge, Scheme/Offer and amount details
  223. BEGIN
  224. IF @payOutPartner IN (224388,2140,393227,415207) and @pCurr <>'USD' --## TANGLO,MTRADE
  225. BEGIN
  226. SELECT '1' ErrorCode ,
  227. 'Oops, something went wrong.Please perform the transaction again!' Msg ,
  228. amountLimitPerDay = @AmountLimitPerDay ,
  229. customerTotalSentAmt = @todaysTotalSent ,
  230. maxAmountLimitPerTran = @tranMaximum ,
  231. PerTxnMinimumAmt = @tranMinimum;
  232. RETURN;
  233. END;
  234. SELECT TOP 1
  235. @senderId = customerId ,
  236. @idExpiryDate = idExpiryDate ,
  237. @createdDate = createdDate,
  238. @sIdNo = idNumber,
  239. @sIdType = idType,
  240. @agentAvlLimit = dbo.FNAGetCustomerACBal(@user),
  241. @customerStatus = CASE WHEN customerStatus IS NULL THEN 'pending' ELSE 'verified' END,
  242. @todaysTotalSent = ISNULL(todaysSent, 0),
  243. @customerType = customerType
  244. FROM customerMaster WITH ( NOLOCK ) WHERE email = @user;
  245. SELECT TOP 1 @sIdType = detailTitle FROM staticDataValue(NOLOCK) WHERE valueId = @sIdType
  246. SELECT @scValue = 0 ,
  247. @exRateOffer = 0 ,
  248. @scDiscount = 0 ,
  249. @AmountLimitPerTran = 3000,
  250. @AmountLimitPerDay = 20000
  251. -- IF ( @idExpiryDate < GETDATE() AND @sIdType <> 'National ID')
  252. -- BEGIN
  253. -- SELECT TOP 1 '1' ErrorCode ,
  254. -- 'Your provided photo id has been expired. Please contact GME Support Team by writing email to support@gmeremit.com or call on +44 (0) 20 8861 2264.' Msg ,
  255. -- amountLimitPerDay = @AmountLimitPerDay ,
  256. -- customerTotalSentAmt = @todaysTotalSent ,
  257. -- maxAmountLimitPerTran = @tranMaximum ,
  258. -- PerTxnMinimumAmt = @tranMinimum;
  259. -- RETURN;
  260. --END;
  261. SELECT TOP 1 @place = place ,
  262. @currDecimal = currDecimal
  263. FROM currencyPayoutRound(NOLOCK)
  264. WHERE ISNULL(isDeleted, 'N') = 'N'
  265. AND currency = @pCurr AND (tranType IS NULL OR tranType = @deliveryMethod);
  266. SET @currDecimal = ISNULL(@currDecimal,0)
  267. IF @pCurr IS NULL
  268. BEGIN
  269. SELECT '1' ErrorCode ,
  270. 'Currency not been defined yet for receiving country' Msg ,
  271. amountLimitPerDay = @AmountLimitPerDay ,
  272. customerTotalSentAmt = @todaysTotalSent ,
  273. maxAmountLimitPerTran = @tranMaximum ,
  274. PerTxnMinimumAmt = @tranMinimum;
  275. RETURN;
  276. END;
  277. SELECT @exRate =
  278. dbo.FNAGetCustomerRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent, @pCurr,@deliveryMethod);
  279. IF @exRate IS NULL
  280. BEGIN
  281. SELECT '1' ErrorCode ,
  282. 'Exchange rate not defined yet for receiving currency ('+ @pCurr + ')' Msg ,
  283. amountLimitPerDay = @AmountLimitPerDay ,
  284. customerTotalSentAmt = @todaysTotalSent ,
  285. maxAmountLimitPerTran = @tranMaximum ,
  286. PerTxnMinimumAmt = @tranMinimum;
  287. RETURN;
  288. END;
  289. ----- Calculation service charge using coupon
  290. -- IF EXISTS (SELECT '1'
  291. -- FROM CouponIssue(NOLOCK) AS CI
  292. -- INNER JOIN CouponSetup(NOLOCK) AS CS
  293. -- ON CI.couponId = CS.rowId
  294. -- WHERE CI.customerId = @senderId
  295. -- AND CI.endDate >= GETDATE()
  296. -- AND CI.isActive = 'Y'
  297. -- AND CS.endDate >= GETDATE()
  298. -- AND CS.isActive = 'Y'
  299. -- AND CS.couponType = '1'
  300. -- AND (ISNULL(CS.usageLimit,0) = 0
  301. -- OR ISNULL(CS.usageLimit,0) > ISNULL(CI.usedCount,0))
  302. -- )
  303. --BEGIN
  304. SELECT TOP(1) @discountType = CS.discountType,
  305. @couponName = CS.couponName,
  306. @discountvalue = CS.discountValue,
  307. @schemeId = CI.rowId, -- ADD coponIssue ID
  308. @couponType = CS.couponType
  309. FROM CouponIssue(NOLOCK) CI
  310. INNER JOIN CouponSetup(NOLOCK) CS
  311. ON CI.couponId = CS.rowId
  312. WHERE CI.isActive = 'Y'
  313. AND CI.endDate >= GETDATE()
  314. AND CS.endDate >= GETDATE()
  315. AND CS.isActive = 'Y'
  316. AND CS.couponType = '1'
  317. AND CI.customerId = @senderId
  318. AND (ISNULL(CS.usageLimit,0) = 0
  319. OR CS.usageLimit > CI.usedCount)
  320. ORDER BY CI.rowId ASC
  321. -- @discountType 1: PERCENTAGE, 2: MONEY
  322. IF @discountType ='2'
  323. BEGIN
  324. SET @scDiscount = @discountvalue
  325. END
  326. --END
  327. IF @calBy = 'C'
  328. BEGIN
  329. IF @pCountryId = 36
  330. BEGIN
  331. SET @pAmt = @cAmt * @exRate
  332. SELECT @serviceCharge = amount
  333. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  334. @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,@collCurr);
  335. END
  336. --ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2
  337. --BEGIN
  338. -- SET @pAmt = @cAmt * @exRate
  339. -- SELECT @serviceCharge = amount
  340. -- FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  341. -- @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,'USD');
  342. --END
  343. ELSE
  344. BEGIN
  345. SELECT @serviceCharge = amount
  346. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  347. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,@cAmt,@collCurr);
  348. END
  349. IF @serviceCharge IS NULL
  350. BEGIN
  351. SELECT '1' ErrorCode ,
  352. 'Service charge not defined yet for receiving country' Msg ,
  353. amountLimitPerDay = @AmountLimitPerDay ,
  354. customerTotalSentAmt = @todaysTotalSent ,
  355. maxAmountLimitPerTran = @tranMaximum ,
  356. PerTxnMinimumAmt = @tranMinimum;
  357. RETURN;
  358. END;
  359. -- @discountType 1: PERCENTAGE, 2: MONEY
  360. IF @discountType = '1'
  361. BEGIN
  362. SET @discountPercent = @discountvalue
  363. SET @discountvalue = @serviceCharge * (@discountvalue/100)
  364. SET @scDiscount = @discountvalue
  365. END
  366. SET @tAmt = @cAmt - @serviceCharge;
  367. SET @pAmt = ( @cAmt-@serviceCharge ) * @exRate
  368. SET @pAmt = ROUND(@pAmt,@currDecimal)
  369. END;
  370. ELSE
  371. IF @calBy = 'P'
  372. BEGIN
  373. SET @tAmt = @pAmt / @exRate
  374. IF @pCountryId = 36
  375. BEGIN
  376. SELECT @serviceCharge = amount
  377. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  378. @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,@collCurr);
  379. END
  380. --ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2
  381. --BEGIN
  382. -- SELECT @serviceCharge = amount
  383. -- FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  384. -- @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,'USD');
  385. --END
  386. ELSE
  387. BEGIN
  388. SELECT @serviceCharge = amount
  389. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  390. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,
  391. @tAmt, @collCurr);
  392. END
  393. IF @serviceCharge IS NULL
  394. BEGIN
  395. SELECT '1' ErrorCode ,
  396. 'Service charge not defined yet for receiving country' Msg ,
  397. amountLimitPerDay = @AmountLimitPerDay ,
  398. customerTotalSentAmt = @todaysTotalSent ,
  399. maxAmountLimitPerTran = @tranMaximum ,
  400. PerTxnMinimumAmt = @tranMinimum;
  401. RETURN;
  402. END;
  403. -- @discountType 1: PERCENTAGE, 2: MONEY
  404. IF @discountType = '1'
  405. BEGIN
  406. SET @discountPercent = @discountvalue
  407. SET @discountvalue = @serviceCharge * (@discountvalue/100)
  408. SET @scDiscount = @discountvalue
  409. END
  410. SET @tAmt = ROUND(@tAmt, 0);
  411. SET @cAmt = ( @tAmt + @serviceCharge );
  412. SET @cAmt = ROUND(@cAmt, 0);
  413. END;
  414. /* Easy Remit limit check */
  415. IF @customerType = '11048'
  416. BEGIN
  417. IF ISNULL(@cAmt, 0) > 1000000
  418. BEGIN
  419. SELECT '1' ErrorCode ,
  420. 'You cannot remit more than one million(KRW).' Msg ,
  421. amountLimitPerDay = @AmountLimitPerDay ,
  422. customerTotalSentAmt = @todaysTotalSent ,
  423. maxAmountLimitPerTran = @tranMaximum ,
  424. PerTxnMinimumAmt = @tranMinimum
  425. RETURN
  426. END
  427. END
  428. IF @serviceCharge > @cAmt
  429. BEGIN
  430. SELECT '1' ErrorCode ,
  431. 'COLLECTION AMOUNT SHOULD BE MORE THAN SERVICE CHARGE' Msg ,
  432. amountLimitPerDay = @AmountLimitPerDay ,
  433. customerTotalSentAmt = @todaysTotalSent ,
  434. maxAmountLimitPerTran = @tranMaximum ,
  435. PerTxnMinimumAmt = @tranMinimum;
  436. RETURN;
  437. END;
  438. --4. Validate Country Sending Limit
  439. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit', @cAmt = @tAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = @collMode
  440. ,@deliveryMethod = @deliveryMethod,@sendingCustType = @sendingCustType,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  441. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  442. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  443. IF @errorCode <> '0'
  444. BEGIN
  445. SELECT @errorCode ErrorCode ,
  446. @msg Msg ,
  447. amountLimitPerDay = @AmountLimitPerDay ,
  448. customerTotalSentAmt = @todaysTotalSent ,
  449. maxAmountLimitPerTran = @tranMaximum ,
  450. PerTxnMinimumAmt = @tranMinimum;
  451. RETURN;
  452. END
  453. --Validate Country Sending Limit END
  454. --5. Validate Country Receiving Limit
  455. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit', @cAmt = @tAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = @collMode
  456. ,@deliveryMethod = @deliveryMethod,@sendingCustType = @sendingCustType,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  457. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  458. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  459. IF @errorCode <> '0'
  460. BEGIN
  461. SELECT @errorCode ErrorCode ,
  462. @msg Msg ,
  463. amountLimitPerDay = @AmountLimitPerDay ,
  464. customerTotalSentAmt = @todaysTotalSent ,
  465. maxAmountLimitPerTran = @tranMaximum ,
  466. PerTxnMinimumAmt = @tranMinimum;
  467. RETURN;
  468. END
  469. --Validate Country Receiving Limit
  470. --End of Limit Checking------------------------------------------------------------------------------------------------------------
  471. SET @msg = 'Success';
  472. IF ISNULL(@paymentType,'wallet') = 'wallet'
  473. BEGIN
  474. IF ISNULL(@agentAvlLimit, 1) < ISNULL(@cAmt, 0)
  475. BEGIN
  476. SELECT '1' ErrorCode
  477. ,'You donot have sufficient balance to do the transaction' Msg ,
  478. amountLimitPerDay = @AmountLimitPerDay ,
  479. customerTotalSentAmt = @todaysTotalSent ,
  480. maxAmountLimitPerTran = @tranMaximum ,
  481. PerTxnMinimumAmt = @tranMinimum;
  482. RETURN;
  483. END;
  484. END
  485. ---------Compliance Checking Begin--------------------------------
  486. DECLARE @complianceRuleId INT, @cAmtUSD MONEY
  487. SELECT
  488. @sCurrCostRate = sCurrCostRate
  489. ,@sCurrHoMargin = sCurrHoMargin
  490. ,@pCurrCostRate = pCurrCostRate
  491. ,@pCurrHoMargin = pCurrHoMargin
  492. ,@pCurrAgentMargin = pCurrAgentMargin
  493. ,@agentCrossSettRate = agentCrossSettRate
  494. ,@treasuryTolerance = treasuryTolerance
  495. ,@customerPremium = customerPremium
  496. ,@sharingValue = sharingValue
  497. ,@sharingType = sharingType
  498. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  499. IF @sCurrCostRate IS NULL
  500. BEGIN
  501. SELECT @errorCode = '1', @msg = 'Transaction cannot be proceed. Exchange Rate not defined!'
  502. RETURN
  503. END
  504. SET @cAmtUSD = @tAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0))
  505. DECLARE
  506. @receiverName VARCHAR(50) = NULL
  507. ,@complienceMessage varchar(1000) =NULL
  508. ,@shortMsg varchar(100) =NULL
  509. ,@complienceErrorCode TINYINT = NULL
  510. EXEC [proc_complianceRuleDetail]
  511. @flag = 'sender-limit'
  512. ,@user = @user
  513. ,@sIdType = @sIdType
  514. ,@sIdNo = @sIdNo
  515. ,@cAmt = @tAmt
  516. ,@cAmtUSD = @cAmtUSD
  517. ,@customerId = @senderId
  518. ,@pCountryId = @pCountryId
  519. ,@deliveryMethod= @deliveryMethod
  520. ,@message = @complienceMessage OUTPUT
  521. ,@shortMessage = @shortMsg OUTPUT
  522. ,@errCode = @complienceErrorCode OUTPUT
  523. ,@ruleId = @complianceRuleId OUTPUT
  524. DECLARE @compErrorCode INT
  525. IF(@complienceErrorCode <> 0)
  526. BEGIN
  527. IF(@complienceErrorCode = 1)
  528. BEGIN
  529. SET @compErrorCode=101
  530. --SELECT 101 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  531. END
  532. ELSE
  533. BEGIN
  534. SET @compErrorCode=102
  535. INSERT remitTranComplianceTemp(csDetailTranId, matchTranId, agentRefId)
  536. SELECT @complianceRuleId, NULL, @agentRefId
  537. --SELECT 102 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  538. END
  539. INSERT INTO ComplianceLog(senderName, senderCountry, senderIdType, senderIdNumber, senderMobile, receiverName
  540. , receiverCountry,payOutAmt,complianceId,complianceReason,complainceDetailMessage,createdBy,createdDate,logType)
  541. SELECT @senderName, @sCountry, @sIdType, @sIdNo, @sMobile, @receiverName
  542. , @pCountry, @cAmt, @complianceRuleId, @shortMsg, @complienceMessage, @user, GETDATE(),'sender-limit'
  543. END
  544. IF @complienceErrorCode = '1'
  545. BEGIN
  546. SELECT @compErrorCode ErrorCode ,
  547. @complienceErrorCode Id ,
  548. @shortMsg Msg ,
  549. '' vtype ,
  550. amountLimitPerDay = @AmountLimitPerDay ,
  551. customerTotalSentAmt = @todaysTotalSent ,
  552. maxAmountLimitPerTran = @tranMaximum ,
  553. PerTxnMinimumAmt = @tranMinimum;
  554. RETURN;
  555. END;
  556. ----------Compliance Validation End---------------------------------
  557. --Bank compare
  558. --DECLARE @bankName VARCHAR(25) = 'Bank', @bankRate MONEY, @bankPayout MONEY, @bankFee MONEY
  559. -- , @bankSave MONEY, @bankTransafer MONEY
  560. --SELECT @bankRate = customerRate, @bankFee = serviceCharge FROM bankTransferSettings(NOLOCK)
  561. --SELECT @bankTransafer = @cAmt - @bankFee
  562. --SELECT @bankPayout = @bankTransafer * @bankRate
  563. --SELECT @bankSave = @pAmt - @bankPayout
  564. SET @FOREX_SESSION_ID = NEWID()
  565. ----## lock ex rate for individual txn
  566. INSERT INTO exRateCalcHistory (
  567. CUSTOMER_ID,[USER_ID],FOREX_SESSION_ID,serviceCharge,pAmt,customerRate,sCurrCostRate,sCurrHoMargin
  568. ,sCurrAgentMargin,pCurrCostRate,pCurrHoMargin,pCurrAgentMargin,agentCrossSettRate,treasuryTolerance,customerPremium
  569. ,sharingValue,sharingType,createdDate,isExpired,tAmt,schemeId,CALC_BY
  570. )
  571. SELECT
  572. @senderId,@user,@FOREX_SESSION_ID,@serviceCharge,@pAmt,@exRate,@sCurrCostRate,@sCurrHoMargin
  573. ,@sCurrAgentMargin,@pCurrCostRate,@pCurrHoMargin,@pCurrAgentMargin ,@agentCrossSettRate,@treasuryTolerance ,@customerPremium
  574. ,@sharingValue,@sharingType,GETDATE(),0,@tAmt,@schemeId,@calBy
  575. SELECT ErrorCode = @errorCode ,
  576. Msg = @msg ,
  577. Id = NULL,
  578. scCharge = @serviceCharge ,
  579. exRateDisplay = ROUND(@exRate , 4, -1),
  580. exRate = CAST(@exRate AS DECIMAL(12,9)),
  581. place = @place ,
  582. pCurr = @pCurr ,
  583. currDecimal = @currDecimal ,
  584. pAmt = @pAmt ,
  585. sAmt = ROUND(@tAmt, 0) ,
  586. disc = 0.00 ,
  587. --bank data
  588. bankTransafer = 0.00,
  589. bankPayout = 0.00,
  590. bankRate = 0.00,
  591. bankFee = 0.00,
  592. bankSave = 0.00,
  593. bankName = '',
  594. collAmt = @cAmt ,
  595. collCurr = @collCurr,
  596. exRateOffer = @exRateOffer ,
  597. scOffer = @scDiscount ,
  598. scAction = @scAction ,
  599. scValue = @scValue ,
  600. scDiscount = @scDiscount ,
  601. amountLimitPerTran = @AmountLimitPerTran ,
  602. amountLimitPerDay = @AmountLimitPerDay ,
  603. customerTotalSentAmt = ISNULL(@todaysTotalSent,0) ,
  604. minAmountLimitPerTran = @tranMinimum ,
  605. maxAmountLimitPerTran = @tranMaximum ,
  606. PerTxnMinimumAmt = '',
  607. tpExRate = @exRate,
  608. tpPCurr = @pCurr,
  609. schemeAppliedMsg = '',
  610. schemeId = ISNULL(@schemeId,''),
  611. EXRATEID = @FOREX_SESSION_ID,
  612. couponType = ISNULL(@couponType,''),
  613. discountType = ISNULL(@discountType,''),
  614. discountvalue = ISNULL(@scDiscount,''),
  615. ISNULL(@discountPercent,'') AS discountPercent,
  616. ISNULL(@couponName,'') AS couponName
  617. END;
  618. IF @flag = 'i' --Send Transaction
  619. BEGIN
  620. IF @user in('demo.gme@gmeremit.com')
  621. BEGIN
  622. EXEC proc_errorHandler 1,'You can not send money through test GME acocunt :(', NULL;
  623. RETURN;
  624. END
  625. ELSE IF @SWIFTCODE IS NOT NULL ----## AGRANI BANK LTD/DUTCH BANGLA BANK/Islami Bank Bangladesh Limited/@payOutPartner = mtrade JUST TO CHECK SETUP EXISTS ON TblPartnerwiseCountry OR NOT(EXRATE FROM LOCAL SETUP)
  626. SELECT TOP 1 @payOutPartner = AgentId FROM TblPartnerwiseCountry(NOLOCK) WHERE CountryId = @pCountryId AND ISNULL(PaymentMethod,@deliveryMethodId) = @deliveryMethodId and IsActive = 1
  627. IF NOT EXISTS(SELECT TOP 1 '' FROM TblPartnerwiseCountry(NOLOCK)
  628. WHERE AgentId = @payOutPartner and CountryId = @pCountryId
  629. AND ISNULL(PaymentMethod,@deliveryMethodId) = @deliveryMethodId and IsActive = 1
  630. )
  631. BEGIN
  632. EXEC proc_errorHandler 1,'Oops, something went wrong.Please perform the transaction again!!' ,null
  633. RETURN;
  634. END
  635. IF @pAgent IS NULL
  636. BEGIN
  637. EXEC proc_errorHandler 1,'Oops, something went wrong.Please perform the transaction again' ,null
  638. RETURN;
  639. END
  640. IF NOT EXISTS (SELECT TOP 1 'X' FROM dbo.customerMaster(nolock) WHERE email = @user and approvedDate is not null)
  641. BEGIN
  642. EXEC proc_errorHandler 1,'You are not authorized to perform transaction :(', NULL;
  643. RETURN;
  644. END
  645. IF ISNULL(@paymentType,'') NOT IN ('wallet', 'autodebit')
  646. BEGIN
  647. EXEC proc_errorHandler 1,'Invalid payment method.Please perform the transaction again!', NULL;
  648. RETURN;
  649. END
  650. SELECT TOP 1 @SENDERS_IDENTITY_TYPE = CASE WHEN idType = '1302'THEN 'P' WHEN idType = '7316' THEN 'N' END ,
  651. @sIdNo = idNumber ,
  652. @senderName = isnull(fullName, firstname),
  653. @agentAvlLimit = ISNULL(availableBalance, 0)
  654. FROM customerMaster (NOLOCK)
  655. WHERE customerId = @senderId;
  656. IF @rfName IS NULL
  657. BEGIN
  658. EXEC proc_errorHandler 1,'Receiver First Name missing', NULL;
  659. RETURN;
  660. END;
  661. IF @rAdd1 IS NULL
  662. BEGIN
  663. EXEC proc_errorHandler 1,'Receiver Address missing', NULL;
  664. RETURN;
  665. END;
  666. IF ISNULL(@deliveryMethod, '') = ''
  667. BEGIN
  668. EXEC proc_errorHandler 1,'Please choose payment mode', NULL;
  669. RETURN;
  670. END;
  671. IF @serviceCharge IS NULL
  672. BEGIN
  673. EXEC proc_errorHandler 1, 'Service Charge missing',NULL;
  674. RETURN;
  675. END;
  676. IF ISNULL(@tAmt, 0) = 0
  677. BEGIN
  678. EXEC proc_errorHandler 1,'Transfer Amount missing', NULL;
  679. RETURN;
  680. END;
  681. IF ISNULL(@exRate, 0) = 0
  682. BEGIN
  683. EXEC proc_errorHandler 1, 'Exchange Rate missing',NULL;
  684. RETURN;
  685. END;
  686. IF ISNULL(@cAmt, 0) = 0
  687. BEGIN
  688. EXEC proc_errorHandler 1, 'Collection Amount is missing. Cannot send transaction',NULL;
  689. RETURN;
  690. END;
  691. SET @controlNo = '80' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9);
  692. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo);
  693. IF EXISTS (SELECT TOP 1 'X' FROM pinQueueList WITH(NOLOCK) WHERE icn = @controlNoEncrypted)
  694. BEGIN
  695. SET @controlNo = '80' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9);
  696. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo);
  697. IF EXISTS(SELECT TOP 1 'X' FROM pinQueueList WITH(NOLOCK) WHERE icn = @controlNoEncrypted)
  698. BEGIN
  699. EXEC proc_errorHandler 1, 'Technical error occurred. Please try again',NULL;
  700. RETURN;
  701. END
  702. END;
  703. IF @deliveryMethod = 'Bank Deposit'
  704. BEGIN
  705. IF NOT EXISTS(SELECT TOP 1 'A' FROM agentMaster(nolock) where agentId = @pBank and agenttype =2903 and IsIntl = 1)
  706. BEGIN
  707. EXEC proc_errorHandler 1, 'Invalid bank selected', NULL
  708. return
  709. END
  710. IF EXISTS(SELECT TOP 1 'A' FROM AgentBankMapping(NOLOCK) WHERE bankId = @pBank AND @pcountryId = 151)
  711. BEGIN
  712. SELECT TOP 1 @pAgent = bankpartnerId from AgentBankMapping(NOLOCK) WHERE bankId = @pBank
  713. SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName,
  714. @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName
  715. FROM dbo.FNAGetBranchFullDetails(@pAgent)
  716. END
  717. END;
  718. SELECT TOP 1 @pAgentCommCurrency = commissionCurrency
  719. FROM SCPAYMASTER(NOLOCK)
  720. where rCountry = @pCountryId
  721. and ISNULL(tranType,@deliveryMethodId) = @deliveryMethodId
  722. and rsAgent = @pSuperAgent
  723. SET @pAgentCommCurrency = CASE WHEN @pAgent = 221271 THEN @pCurr ELSE @pAgentCommCurrency END
  724. SELECT @pAgentComm = (SELECT amount FROM dbo.[FNAGetPayComm](@sAgent, @sCountryId, NULL, NULL, @pCountryId, NULL, @pAgent, @pAgentCommCurrency
  725. , @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, NULL))
  726. --Get Service Charge----------------------------------------------------------------------------------------------------------------------
  727. IF @pCountryId = 36 ----## FOR CAMBODIA
  728. BEGIN
  729. SELECT @iServiceCharge = ISNULL(amount, -1)
  730. FROM [dbo].FNAGetServiceCharge(
  731. @sCountryId, @sSuperAgent, @sAgent, @sBranch,
  732. @pCountryId, @pSuperAgent, @pAgent, NULL,
  733. @deliveryMethodId, @pAmt, @collCurr
  734. )
  735. END
  736. --ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethodId = 2
  737. --BEGIN
  738. -- SELECT @iServiceCharge = amount
  739. -- FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  740. -- @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethodId,@pAmt,'USD');
  741. --END
  742. ELSE
  743. BEGIN
  744. SELECT @iServiceCharge = ISNULL(amount, -1)
  745. FROM [dbo].FNAGetServiceCharge(
  746. @sCountryId, @sSuperAgent, @sAgent, @sBranch,
  747. @pCountryId, @pSuperAgent, @pAgent, @pBranch,
  748. @deliveryMethodId, @cAmt, @collCurr
  749. )
  750. END
  751. IF @iServiceCharge = -1
  752. BEGIN
  753. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Service Charge is not defined', NULL
  754. RETURN
  755. END
  756. IF isnull(@iServiceCharge,0) <> isnull(@serviceCharge,1)
  757. BEGIN
  758. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Amount detail not match', NULL
  759. RETURN
  760. END
  761. SELECT @iServiceCharge = @serviceCharge , @customerRate = @exRate;
  762. --End Service Charge-------------------------------------------------------------------------------------------------------------------------------------
  763. --4. Get Exchange Rate Details------------------------------------------------------------------------------------------------------------------
  764. SELECT
  765. @customerRate = customerRate
  766. ,@sCurrCostRate = sCurrCostRate
  767. ,@sCurrHoMargin = sCurrHoMargin
  768. ,@sCurrAgentMargin = sCurrAgentMargin
  769. ,@pCurrCostRate = pCurrCostRate
  770. ,@pCurrHoMargin = pCurrHoMargin
  771. ,@pCurrAgentMargin = pCurrAgentMargin
  772. ,@agentCrossSettRate = agentCrossSettRate
  773. ,@treasuryTolerance = treasuryTolerance
  774. ,@customerPremium = customerPremium
  775. ,@sharingValue = sharingValue
  776. ,@sharingType = sharingType
  777. FROM dbo.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethodId)
  778. IF @customerRate IS NULL
  779. BEGIN
  780. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Exchange Rate not defined', NULL
  781. RETURN
  782. END
  783. SELECT
  784. @customerRate = customerRate
  785. ,@sCurrCostRate = sCurrCostRate
  786. ,@sCurrHoMargin = sCurrHoMargin
  787. ,@sCurrAgentMargin = sCurrAgentMargin
  788. ,@pCurrCostRate = pCurrCostRate
  789. ,@pCurrHoMargin = pCurrHoMargin
  790. ,@pCurrAgentMargin = pCurrAgentMargin
  791. ,@agentCrossSettRate = agentCrossSettRate
  792. ,@treasuryTolerance = treasuryTolerance
  793. ,@customerPremium = customerPremium
  794. ,@sharingValue = sharingValue
  795. ,@sharingType = sharingType
  796. ,@serviceCharge = serviceCharge
  797. ,@iPAmt = pAmt
  798. ,@schemeId = schemeId
  799. FROM exRateCalcHistory(NOLOCK)
  800. WHERE FOREX_SESSION_ID = @FOREX_SESSION_ID AND [USER_ID] = @user
  801. ------------Find Coupon---------------
  802. IF ISNULL(@schemeId,'') <> ''
  803. BEGIN
  804. --IF EXISTS (SELECT '1'
  805. -- FROM CouponIssue(NOLOCK) AS CI
  806. -- INNER JOIN CouponSetup(NOLOCK) AS CS
  807. -- ON CI.couponId = CS.rowId
  808. -- WHERE CI.rowId = @schemeId
  809. -- AND CI.endDate >= GETDATE()
  810. -- AND CI.isActive = 'Y'
  811. -- AND CS.endDate >= GETDATE()
  812. -- AND CS.isActive = 'Y'
  813. -- AND CS.couponType = '1'
  814. -- AND (ISNULL(CS.usageLimit,0) = 0
  815. -- OR ISNULL(CS.usageLimit,0) > ISNULL(CI.usedCount,0))
  816. -- )
  817. -- BEGIN
  818. DECLARE @CurrentCount int = 0
  819. SELECT TOP(1)
  820. @discountvalue = CS.discountValue,
  821. @CurrentCount = ISNULL(CI.usedCount,0),
  822. @discountType = CS.discountType
  823. FROM CouponIssue(NOLOCK) CI
  824. INNER JOIN CouponSetup(NOLOCK) CS
  825. ON CI.couponId = CS.rowId
  826. WHERE CI.isActive = 'Y'
  827. AND CI.endDate >= GETDATE()
  828. AND CS.endDate >= GETDATE()
  829. AND CS.isActive = 'Y'
  830. AND CS.couponType = '1'
  831. AND CI.rowId = @schemeId
  832. AND (ISNULL(CS.usageLimit,0) = 0
  833. OR CS.usageLimit > CI.usedCount)
  834. ORDER BY CI.rowId ASC
  835. IF @discountType = '1'
  836. BEGIN
  837. SET @schemePremium = @serviceCharge * (@discountvalue/100)
  838. END
  839. ELSE IF @discountType ='2'
  840. BEGIN
  841. SET @schemePremium = @discountvalue
  842. END
  843. --END
  844. ELSE
  845. BEGIN
  846. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Coupon Checked. But, Can Not Find Coupon', NULL
  847. RETURN
  848. END
  849. END
  850. IF @paymentType = 'wallet'
  851. BEGIN
  852. IF ISNULL(@agentAvlLimit, 1) < ISNULL(@cAmt, 0)
  853. BEGIN
  854. EXEC proc_errorHandler 1,'You donot have sufficient balance to do the transaction!', NULL;
  855. RETURN;
  856. END;
  857. END
  858. ELSE IF @paymentType = 'autodebit'
  859. BEGIN
  860. DECLARE @tranAmt MONEY = NULL
  861. SELECT TOP 1 @tranAmt = tranAmt
  862. FROM KFTC_CUSTOMER_TRANSFER (NOLOCK)
  863. WHERE rowId = @kftcLogId
  864. IF @tranAmt IS NULL
  865. BEGIN
  866. EXEC proc_errorHandler 1,'Invalid auto debit request.Please perform the transaction again!', NULL;
  867. RETURN;
  868. END
  869. IF @tranAmt <> @cAmt - ISNULL(@schemePremium,0)
  870. BEGIN
  871. EXEC proc_errorHandler 1,'Invalid transaction amount. Please contact GME Support!', NULL;
  872. RETURN;
  873. END
  874. END
  875. --ELSE
  876. --BEGIN
  877. -- EXEC proc_errorHandler 1,'Invalid payment method.Please perform the transaction again!', NULL;
  878. -- RETURN;
  879. --END
  880. IF @customerRate IS NULL
  881. BEGIN
  882. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Exchange Rate not defined', NULL
  883. RETURN
  884. END
  885. IF @pCurr IN ('VND','IDR','MNT')
  886. BEGIN
  887. SET @customerRate = CAST(@customerRate AS DECIMAL(15,10))
  888. END
  889. --DECLARE @iMsg VARCHAR(MAX)
  890. IF ISNULL(@exRate,0) <> ISNULL(@customerRate,1)
  891. BEGIN
  892. --SET @iMsg = 'Amount detail not match. Please re-calculate the amount again' + CAST(isnull(@exRate,0) AS VARCHAR) + ' : ' + CAST(isnull(@customerRate,1) AS VARCHAR)
  893. EXEC proc_errorHandler 1, 'Amount detail not match. Please re-calculate the amount again', NULL
  894. RETURN
  895. END
  896. IF @benId IS NOT NULL
  897. BEGIN
  898. IF NOT EXISTS(SELECT TOP 1 'A' FROM receiverInformation (NOLOCK) WHERE customerId = @senderId AND receiverId = @benId)
  899. BEGIN
  900. EXEC proc_errorHandler 1,'Invalid receiver Id!', NULL;
  901. RETURN;
  902. END
  903. END
  904. DECLARE @scDisc MONEY
  905. SELECT @iCustomerRate = @exRate, @iTAmt = @cAmt - @iServiceCharge
  906. SELECT TOP 1 @place = place, @currDecimal = currDecimal
  907. FROM currencyPayoutRound WITH(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N'
  908. AND currency = @pCurr AND (tranType IS NULL OR tranType = @deliveryMethodId)
  909. SET @currDecimal = ISNULL(@currDecimal, 0)
  910. SET @place = ISNULL(@place, 0)
  911. --SET @iPAmt = ROUND(@iTAmt * @iCustomerRate, @currDecimal)
  912. ------## WHILE CALCULATING FROM PAYOUT AMOUNT CONSIDARING 10 VND
  913. --IF @pCurr IN ('VND','IDR','MNT') AND ISNULL(@iPAmt,0) < ISNULL(@pAmt,1)+10
  914. --BEGIN
  915. -- SET @iPAmt = @pAmt
  916. --END
  917. IF ISNULL(@iPAmt,0) <> ISNULL(@pAmt,1)
  918. BEGIN
  919. --SET @iMsg = 'Amount detail not match. Please re-calculate the amount again.' + CAST(@iPAmt AS VARCHAR) + ' - ' + CAST(@pAmt AS VARCHAR)
  920. EXEC proc_errorHandler 1, 'Amount detail not match. Please re-calculate the amount again.', NULL
  921. RETURN
  922. END
  923. --OFAC Checking
  924. DECLARE @receiverOfacRes VARCHAR(MAX), @ofacRes VARCHAR(MAX), @ofacReason VARCHAR(200)
  925. EXEC proc_ofacTracker @flag = 't', @name = @senderName, @Result = @ofacRes OUTPUT
  926. EXEC proc_ofacTracker @flag = 't', @name = @rfName, @Result = @receiverOfacRes OUTPUT
  927. DECLARE @result VARCHAR(MAX)
  928. IF ISNULL(@ofacRes, '') <> ''
  929. BEGIN
  930. SET @ofacReason = 'Matched by sender name'
  931. END
  932. IF ISNULL(@receiverOfacRes, '') <> ''
  933. BEGIN
  934. SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes)
  935. SET @ofacReason = 'Matched by receiver name'
  936. END
  937. IF ISNULL(@ofacRes, '') <> '' AND ISNULL(@receiverOfacRes, '') <> ''
  938. BEGIN
  939. SET @ofacReason = 'Matched by both sender name and receiver name'
  940. END
  941. --Ofac Checking End
  942. ----@camt = (@tAmt+@serviceCharge)
  943. SET @cAmtUSD = @tAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0))
  944. --Compliance Checking
  945. EXEC [proc_complianceRuleDetail]
  946. @flag = 'receiver-limit'
  947. ,@user = @user
  948. ,@sIdType = @sIdType
  949. ,@sIdNo = @sIdNo
  950. ,@receiverName = @rfName
  951. ,@cAmt = @tAmt
  952. ,@cAmtUSD = @cAmtUSD
  953. ,@customerId = @senderId
  954. ,@pCountryId = @pCountryId
  955. ,@receiverMobile = @rMobile
  956. ,@deliveryMethod = @deliveryMethodId
  957. ,@message = @complienceMessage OUTPUT
  958. ,@shortMessage = @shortMsg OUTPUT
  959. ,@errCode = @complienceErrorCode OUTPUT
  960. ,@ruleId = @complianceRuleId OUTPUT
  961. IF(@complienceErrorCode <> 0)
  962. BEGIN
  963. IF(@complienceErrorCode = 1)
  964. BEGIN
  965. SET @compErrorCode=101
  966. --SELECT 101 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  967. END
  968. ELSE
  969. BEGIN
  970. SET @compErrorCode=102
  971. INSERT remitTranComplianceTemp(csDetailTranId, matchTranId, agentRefId)
  972. SELECT @complianceRuleId, NULL, @agentRefId
  973. --SELECT 102 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  974. END
  975. INSERT INTO ComplianceLog(senderName, senderCountry, senderIdType, senderIdNumber, senderMobile, receiverName
  976. , receiverCountry,payOutAmt,complianceId,complianceReason,complainceDetailMessage,createdBy,createdDate,logType)
  977. SELECT @senderName, @sCountry, @sIdType, @sIdNo, @sMobile, @receiverName
  978. , @pCountry, @cAmt, @complianceRuleId, @shortMsg, @complienceMessage, @user, GETDATE(),'receiver-limit'
  979. DECLARE @tempCompId BIGINT = @@IDENTITY
  980. END
  981. IF @complienceErrorCode = 1
  982. BEGIN
  983. EXEC proc_errorHandler 1, @shortMsg, NULL
  984. RETURN;
  985. END;
  986. --Compliance checking end
  987. --**********Customer Per Day Limit Checking**********
  988. DECLARE @remitTranTemp TABLE (
  989. tranId BIGINT,controlNo VARCHAR(20),cAmt MONEY,receiverName VARCHAR(200) ,
  990. receiverIdType VARCHAR(100),receiverIdNumber VARCHAR(50),dot DATETIME
  991. );
  992. INSERT INTO @remitTranTemp( tranId ,controlNo ,cAmt ,receiverName ,receiverIdType ,receiverIdNumber ,dot )
  993. SELECT TOP 1 rt.id ,rt.controlNo ,rt.cAmt ,rt.receiverName ,rec.idType ,rec.idNumber ,rt.createdDateLocal
  994. FROM vwRemitTran rt WITH(NOLOCK)
  995. INNER JOIN vwTranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  996. INNER JOIN vwTranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  997. AND sen.customerId = @senderId
  998. AND ( rt.approvedDate BETWEEN CONVERT(VARCHAR,GETDATE(),101) AND CONVERT(VARCHAR,GETDATE(),101)+ ' 23:59:59'
  999. OR ( approvedBy IS NULL AND cancelApprovedBy IS NULL )
  1000. );
  1001. IF EXISTS ( SELECT TOP 1 'X' FROM @remitTranTemp
  1002. WHERE cAmt = @cAmt
  1003. AND ( receiverName = @rfName ) AND DATEDIFF(MI, dot, GETDATE()) <= 2
  1004. )
  1005. BEGIN
  1006. EXEC proc_errorHandler 1, 'Similar transaction found. Please perform the transaction after 2 minutes.', NULL;
  1007. RETURN;
  1008. END;
  1009. -- #########country and occupation risk point
  1010. DECLARE @countryRisk INT ,@OccupationRisk INT
  1011. DECLARE @VNo VARCHAR(20);
  1012. IF @pCountryId=151 AND ISNULL(@pBank,'')<>1056 AND @deliveryMethod <> 'MOBILE WALLET' --- if pcountry is nepal and pagent is not global ime bank then set this value to null
  1013. BEGIN
  1014. SELECT @pAgent=NULL,@pAgentName=NULL--, @pAgentComm=NULL, @pAgentCommCurrency=NULL
  1015. END
  1016. BEGIN TRANSACTION;
  1017. INSERT INTO remitTranTempOnline
  1018. (
  1019. controlNo ,sCurrCostRate ,sCurrHoMargin ,sCurrSuperAgentMargin ,sCurrAgentMargin ,pCurrCostRate ,pCurrHoMargin ,pCurrSuperAgentMargin ,
  1020. pCurrAgentMargin ,agentCrossSettRate ,customerRate ,sAgentSettRate ,pDateCostRate ,treasuryTolerance ,customerPremium ,schemePremium ,sharingValue ,
  1021. sharingType ,serviceCharge ,handlingFee ,sAgentComm ,sAgentCommCurrency ,sSuperAgentComm ,sSuperAgentCommCurrency ,pAgentComm ,pAgentCommCurrency ,
  1022. pCommissionType ,pSuperAgentComm ,pSuperAgentCommCurrency ,promotionCode ,pMessage ,sSuperAgent ,sSuperAgentName ,sAgent ,sAgentName ,sBranch ,
  1023. sBranchName ,sCountry ,pSuperAgent ,pSuperAgentName ,pAgent ,pAgentName ,pBranch ,pBranchName ,pCountry ,paymentMethod ,pBank ,pBankName ,pBankBranch ,pBankBranchName ,
  1024. accountNo ,pBankType ,expectedPayoutAgent ,collMode ,collCurr ,tAmt ,cAmt ,pAmt ,payoutCurr ,relWithSender ,purposeOfRemit ,sourceOfFund ,tranStatus ,payStatus ,createdDate ,
  1025. createdDateLocal ,createdBy ,tranType ,voucherNo ,senderName ,receiverName ,calBy ,isOnlineTxn ,schemeId ,ScOrderNo ,UnitaryBankAccountNo,pState,pDistrict,
  1026. sRouteId
  1027. )
  1028. SELECT
  1029. @controlNoEncrypted ,@sCurrCostRate ,@sCurrHoMargin ,@sCurrSuperAgentMargin ,@sCurrAgentMargin ,@pCurrCostRate ,@pCurrHoMargin ,@pCurrSuperAgentMargin ,
  1030. @pCurrAgentMargin ,@agentCrossSettRate ,@customerRate ,@sAgentSettRate ,@pDateCostRate ,@treasuryTolerance ,@customerPremium ,ISNULL(@schemePremium, 0) ,
  1031. @sharingValue , @sharingType , @serviceCharge ,ISNULL(@scDiscount, 0) ,@sAgentComm ,@sAgentCommCurrency ,@sSuperAgentComm ,@sSuperAgentCommCurrency ,@pAgentComm ,@pAgentCommCurrency ,
  1032. @pCommissionType , @pSuperAgentComm ,@pSuperAgentCommCurrency ,@agentRefId ,@payMsg ,@sSuperAgent , @sSuperAgentName ,@sAgent ,@sAgentName ,@sBranch ,@sBranchName ,@sCountry , @pSuperAgent ,
  1033. @pSuperAgentName , @pAgent , @pAgentName , @pBranch ,@pBranchName ,@pCountry ,@deliveryMethod ,@pBank , @pBankName ,@pBankBranch ,@pBankBranchName ,@raccountNo ,@pBankType , @pAgentName ,@collMode , @collCurr ,@tAmt , @cAmt ,
  1034. @pAmt , @pCurr , @relationship , @purpose ,@sourceOfFund ,'Hold' ,'Unpaid' ,@GMTDate ,
  1035. GETDATE() , @user ,ISNULL(@pBankType,'O') , @VNo , @senderName , @rfName ,@calBy , 'Y' ,@schemeId ,@ScOrderNo ,@unitaryBankAccountNo,@RLocation,@RState,
  1036. CASE WHEN @paymentType = 'wallet' THEN 'w' WHEN @paymentType = 'autodebit' THEN 'a' END
  1037. SET @id = SCOPE_IDENTITY();
  1038. INSERT INTO tranSendersTempOnline
  1039. ( tranId , customerId ,membershipId ,firstName , middleName ,lastName1 ,lastName2 ,
  1040. fullName ,country ,[address] ,address2 ,zipCode ,city ,email ,homePhone ,
  1041. workPhone ,mobile ,nativeCountry ,dob ,placeOfIssue ,idType ,idNumber ,idPlaceOfIssue ,
  1042. issuedDate ,validDate ,occupation ,countryRiskPoint ,customerRiskPoint ,
  1043. ipAddress
  1044. )
  1045. SELECT TOP 1
  1046. @id ,@senderId ,membershipId ,firstName ,middleName ,lastName1 ,lastName2 ,
  1047. @senderName ,sc.countryName ,[address] ,address2 ,zipCode ,city ,email ,homePhone ,
  1048. workPhone ,LEFT(mobile, 15) ,nativeCountry = nc.countryName ,dob ,c.placeOfIssue ,sdv.detailTitle ,c.idNumber ,c.placeOfIssue ,
  1049. c.idIssueDate ,c.idExpiryDate ,om.detailTitle ,@countryRisk ,( @countryRisk + @OccupationRisk ) ,
  1050. @sIpAddress
  1051. FROM (SELECT TOP 1 * FROM dbo.customerMaster c WITH ( NOLOCK ) WHERE c.customerId = @senderId) C
  1052. LEFT JOIN countryMaster sc WITH ( NOLOCK ) ON c.country = sc.countryId
  1053. LEFT JOIN countryMaster nc WITH ( NOLOCK ) ON c.nativeCountry = nc.countryId
  1054. LEFT JOIN staticDataValue sdv WITH ( NOLOCK ) ON c.idType = sdv.valueId
  1055. LEFT JOIN occupationMaster om WITH ( NOLOCK ) ON c.occupation = om.occupationId
  1056. --WHERE c.customerId = @senderId;
  1057. DECLARE @fName VARCHAR(100) ,
  1058. @mName VARCHAR(100) ,
  1059. @lName VARCHAR(100) ,
  1060. @lName2 VARCHAR(100);
  1061. SELECT @fName =firstName,
  1062. @mName =middleName,
  1063. @lName =lastName1,
  1064. @lName2 =lastName2
  1065. FROM dbo.FNASplitName(@rfName);
  1066. DECLARE @firstName VARCHAR(100)
  1067. DECLARE @midName VARCHAR(100)
  1068. DECLARE @lastName VARCHAR(100)
  1069. DECLARE @lastName2 VARCHAR(100)
  1070. DECLARE @payCountry VARCHAR(100)
  1071. DECLARE @recAdd1 VARCHAR(100)
  1072. DECLARE @reccity VARCHAR(100)
  1073. DECLARE @recEmail VARCHAR(100)
  1074. DECLARE @recTel VARCHAR(100)
  1075. DECLARE @recMobile VARCHAR(100)
  1076. DECLARE @recRelationship VARCHAR(100)
  1077. DECLARE @recState VARCHAR(100)
  1078. declare @recDistrict VARCHAR(100)
  1079. IF @benId IS NULL
  1080. BEGIN
  1081. IF NOT EXISTS ( SELECT TOP 1 'X'
  1082. FROM receiverInformation(nolock)
  1083. WHERE ISNULL(firstName, '') = ISNULL(@fName, '')
  1084. AND ISNULL(middleName, '') = ISNULL(@mName, '')
  1085. AND ISNULL(lastName1, '') = ISNULL(@lName, '')
  1086. AND ISNULL(lastName2, '') = ISNULL(@lName2, '')
  1087. AND customerId = @senderId )
  1088. BEGIN
  1089. INSERT INTO receiverInformation
  1090. ( customerId ,firstName,middleName,lastName1,lastName2 ,country ,address ,city ,email ,homePhone
  1091. ,workPhone ,mobile ,relationship,state,district)
  1092. SELECT @senderId ,firstName,middleName,lastName1,lastName2,@pCountry,@rAdd1,@rCity,@rEmail,@rTel
  1093. ,@rTel,@rMobile,@relationship,@RLocationText,@RStateText
  1094. FROM dbo.FNASplitName(@rfName);
  1095. SET @benId = @@IDENTITY;
  1096. END;
  1097. ELSE
  1098. BEGIN
  1099. SELECT TOP 1 @benId = receiverId
  1100. FROM receiverInformation(nolock)
  1101. WHERE ISNULL(firstName, '') = @fName
  1102. AND ISNULL(middleName, '') = @mName
  1103. AND ISNULL(lastName1, '') = @lName
  1104. AND ISNULL(lastName2, '') = @lName2
  1105. AND customerId = @senderId;
  1106. END;
  1107. END;
  1108. DECLARE @rNativCountry VARCHAR(100)
  1109. IF @benId IS NOT NULL
  1110. BEGIN
  1111. SELECT @firstName =firstName
  1112. ,@midName =middleName
  1113. ,@lastName =lastName1
  1114. ,@lastName2 =lastName2
  1115. ,@payCountry =country
  1116. ,@recAdd1 =address
  1117. ,@reccity =city
  1118. ,@recEmail =email
  1119. ,@recTel =homePhone
  1120. ,@recMobile =mobile
  1121. ,@recRelationship =relationship
  1122. ,@recState =state
  1123. ,@recDistrict =district
  1124. ,@rNativCountry =nativeCountry
  1125. FROM dbo.receiverInformation(nolock)
  1126. WHERE receiverId = @benId
  1127. UPDATE dbo.receiverInformation
  1128. SET firstName =ISNULL( @fName ,@firstName)
  1129. , middleName =ISNULL( @mName ,@midName)
  1130. , lastName1 =ISNULL( @lName ,@lastName)
  1131. , lastName2 =ISNULL( @lName2 ,@lastName2)
  1132. , country =ISNULL( @pCountry ,@payCountry)
  1133. , address =ISNULL( @rAdd1 ,@recAdd1)
  1134. , city =ISNULL( @rCity ,@reccity)
  1135. , state =isnull( @RLocationText,@recState)
  1136. , district =isnull(@RStateText ,@recDistrict)
  1137. , email =ISNULL( @rEmail ,@recEmail)
  1138. , homePhone =ISNULL( @rTel ,@recTel)
  1139. , workPhone =ISNULL( @rTel ,@recTel)
  1140. , mobile =ISNULL( @rMobile ,@recMobile)
  1141. , relationship =ISNULL( @relationship,@recRelationship)
  1142. WHERE receiverId = @benId
  1143. END
  1144. INSERT INTO tranReceiversTempOnline( tranId ,customerId ,membershipId ,firstName ,middleName ,lastName1 ,lastName2 ,fullName ,
  1145. country ,[address] ,[state] ,district ,zipCode ,city ,email ,homePhone ,workPhone ,mobile ,nativeCountry ,dob ,
  1146. placeOfIssue ,idType ,idNumber ,idPlaceOfIssue ,issuedDate ,relationType,validDate ,gender
  1147. )
  1148. SELECT @id ,@benId ,NULL ,firstName ,middleName ,lastName1 ,lastName2 ,@rfName ,
  1149. @pCountry ,@rAdd1 ,@RLocationText ,@RStateText ,null ,@rCity, @rEmail ,@rTel ,@rTel ,@rMobile ,@rNativCountry ,@rdob ,
  1150. NULL ,@rIdType ,@rIdNo ,NULL ,NULL ,@relationship,@rIdValid ,NULL
  1151. FROM dbo.FNASplitName(@rfName);
  1152. INSERT INTO collectionDetailsOnline
  1153. ( tranId ,collMode ,countryBankId ,amt ,collDate ,narration ,branchId ,createdBy ,createdDate
  1154. )
  1155. SELECT @id ,@collMode ,0 ,@cAmt ,@GMTDate ,'online' ,NULL ,@senderId ,GETDATE();
  1156. EXEC proc_online_temp_to_main @id = @id OUTPUT,@voucherDetails= @VoucherXML
  1157. --IF @paymentType = 'wallet'
  1158. EXEC proc_UpdateCustomerBalance @controlNo = @controlNoEncrypted, @type = 'deduct'
  1159. IF @paymentType = 'autodebit'
  1160. UPDATE KFTC_CUSTOMER_TRANSFER SET tranId = @id WHERE rowId = @kftcLogId
  1161. ----## map locked ex rate with transaction for history
  1162. UPDATE exRateCalcHistory set controlNo = @controlNoEncrypted,AGENT_TXN_REF_ID=@id where FOREX_SESSION_ID = @FOREX_SESSION_ID
  1163. --------------------------#########------------OFAC/COMPLIANCE INSERT (IF EXISTS)---------------########----------------------
  1164. IF EXISTS(SELECT TOP 1 'X' FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @agentRefId)
  1165. BEGIN
  1166. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId)
  1167. SELECT TOP 1 @id, csDetailTranId, matchTranId FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @agentRefId
  1168. SET @compFinalRes = 'C'
  1169. END
  1170. IF(ISNULL(@compFinalRes, '') <> '' OR ISNULL(@ofacRes, '') <> '' OR ISNULL(@receiverOfacRes, '') <> '')
  1171. BEGIN
  1172. IF @pCountryId IN (36)
  1173. BEGIN
  1174. SET @complienceMessage = ISNULL('Compliance: ' + @shortMsg, '') + ISNULL('Ofac: ' + @ofacRes, '') + ISNULL(' ' + @receiverOfacRes, '')
  1175. INSERT INTO ComplianceLog(senderName, senderCountry, senderIdType, senderIdNumber, senderMobile, receiverName
  1176. , receiverCountry,payOutAmt,complianceId,complianceReason,complainceDetailMessage,createdBy,createdDate,logType)
  1177. SELECT @senderName, @sCountry, @sIdType, @sIdNo, @sMobile, @receiverName
  1178. , @pCountry, @cAmt, @complianceRuleId, @shortMsg, @complienceMessage, @user, GETDATE(),'reject_log'
  1179. SET @tempCompId = @@IDENTITY
  1180. SET @msg = 'Your transaction is under Compliance/OFAC Please refer ' + CAST(ISNULL(@tempCompId, 0) AS VARCHAR) + ' code to HEAD OFFICE';
  1181. EXEC proc_errorHandler 1, @msg, NULL;
  1182. EXEC proc_ApproveHoldedTXN @flag = 'reject', @user = @user , @id = @id
  1183. COMMIT TRANSACTION
  1184. RETURN
  1185. END
  1186. IF((ISNULL(@ofacRes, '') <> '' OR ISNULL(@receiverOfacRes, '') <> '') AND ISNULL(@compFinalRes, '') = '')
  1187. BEGIN
  1188. IF ISNULL(@ofacRes, '') <> ''
  1189. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  1190. SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  1191. IF ISNULL(@receiverOfacRes, '') <> ''
  1192. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  1193. SELECT @tranId, @receiverOfacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@receiverOfacRes)
  1194. UPDATE remitTranTemp SET
  1195. tranStatus = 'OFAC Hold'
  1196. WHERE id = @id
  1197. END
  1198. ELSE IF(@compFinalRes <> '' AND (ISNULL(@ofacRes, '') = '' OR ISNULL(@receiverOfacRes, '') = ''))
  1199. BEGIN
  1200. UPDATE remitTranTemp SET
  1201. tranStatus = 'Compliance Hold'
  1202. WHERE id = @id
  1203. END
  1204. ELSE IF(ISNULL(@compFinalRes, '') <> '' AND (ISNULL(@ofacRes, '') <> '' OR ISNULL(@receiverOfacRes, '') <> ''))
  1205. BEGIN
  1206. IF ISNULL(@ofacRes, '') <> ''
  1207. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  1208. SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  1209. IF ISNULL(@receiverOfacRes, '') <> ''
  1210. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  1211. SELECT @tranId, @receiverOfacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@receiverOfacRes)
  1212. UPDATE remitTranTemp SET
  1213. tranStatus = 'OFAC/Compliance Hold'
  1214. WHERE id = @id
  1215. END
  1216. END
  1217. --Compliance checking
  1218. -------START update used coupon status
  1219. ---  8ptXD \.
  1220. IF EXISTS(SELECT TOP 1 '1' FROM CouponIssue(NOLOCK) WHERE rowId = @schemeId AND isActive = 'Y' )
  1221. BEGIN
  1222. UPDATE CouponIssue
  1223. SET usedCount = @CurrentCount +1
  1224. WHERE rowId = @schemeId
  1225. AND customerId = @senderId
  1226. AND GETDATE() BETWEEN startDate AND endDate AND isActive = 'Y'
  1227. -------Start insert Coupon History
  1228. INSERT INTO CouponHistory (couponIssueId,customerId,actualDiscountValue,usedCount,holdTranId,couponStatus,createdBy,createdDate)
  1229. VALUES (@schemeId,@senderId,@schemePremium,@CurrentCount + 1,@id,'1',@user, GETDATE())
  1230. -------End insert Coupon History
  1231. END
  1232. -------END update used coupon status
  1233. IF @@TRANCOUNT > 0
  1234. COMMIT TRANSACTION;
  1235. SElect 0 errorCode, 'Transaction has been sent successfully' msg, @id id, @controlNo extra;
  1236. IF @pCountryId <> 36
  1237. exec [proc_ApproveHoldedTXN] @flag = 'approve', @id = @id,@user = 'admin'
  1238. RETURN
  1239. END;
  1240. ELSE IF @flag = 'approve-wing'
  1241. BEGIN
  1242. select @id = id, @deliveryMethod = paymentMethod from remitTranTemp (nolock) where controlno = dbo.FNAEncryptString(@controlNo)
  1243. if @deliveryMethod <> 'Mobile Wallet'
  1244. update remitTranTemp set controlno = dbo.FNAEncryptString(@tpRefNo),controlNo2 = dbo.FNAEncryptString(@controlNo) where id = @id
  1245. IF EXISTS(
  1246. select 'A' from remittran(nolock) where controlno = dbo.FNAEncryptString(@tpRefNo) AND pCountry = 'Cambodia' AND pAgent = 221226 -- AND DATEDIFF(DAY,createddate,GETDATE()) > 30
  1247. )
  1248. BEGIN
  1249. UPDATE remittran SET controlno = dbo.FNAEncryptString(@tpRefNo+'A') where controlno = dbo.FNAEncryptString(@tpRefNo)
  1250. UPDATE PINQUEUELIST SET ICN = dbo.FNAEncryptString(@tpRefNo+'A') WHERE ICN = dbo.FNAEncryptString(@tpRefNo)
  1251. UPDATE FastMoneyPro_Account.DBO.tran_master set field1 = @tpRefNo+'A' where field1 = @tpRefNo and field2 = 'remittance Voucher'
  1252. END
  1253. EXEC [proc_ApproveHoldedTXN] @flag = 'approve', @id = @id,@user = 'admin'
  1254. SELECT @id = id FROM remitTran (NOLOCK)
  1255. WHERE controlno = case when @deliveryMethod = 'Mobile Wallet' then dbo.FNAEncryptString(@controlNo) else dbo.FNAEncryptString(@tpRefNo) end
  1256. AND paystatus = 'UNPAID'
  1257. IF @id IS NOT NULL
  1258. BEGIN
  1259. UPDATE remitTran SET controlno = case when @deliveryMethod = 'Mobile Wallet' then dbo.FNAEncryptString(@controlNo) else dbo.FNAEncryptString(@tpRefNo) end
  1260. ,controlNo2 = dbo.FNAEncryptString(@controlNo)
  1261. ,ContNo = @tpTranId
  1262. ,paystatus = 'Post'
  1263. ,postedBy = @user
  1264. ,postedDate = getdate()
  1265. ,postedDateLocal = getdate()
  1266. WHERE id = @id AND paystatus = 'UNPAID'
  1267. END
  1268. SELECT 0 ErrorCode,'Transaction has been sent successfully' Msg, @id id, case when @deliveryMethod = 'Mobile Wallet' then @controlNo else @tpRefNo end extra
  1269. END;
  1270. ELSE IF @flag = 'showLimit'
  1271. BEGIN
  1272. SELECT [paymentType] = sdv.detailTitle ,
  1273. limit.id ,
  1274. currency ,
  1275. sendingLimit = CAST(CAST(maximum AS DECIMAL(10,2)) AS VARCHAR) ,
  1276. cm.countryName ,
  1277. limitType = CASE WHEN ISNULL(limitType,'T') = 'T' THEN 'Per Transactioin' ELSE 'Per Day' END
  1278. FROM onlineCustomerLimitSetup limit WITH ( NOLOCK )
  1279. INNER JOIN staticDataValue sdv WITH ( NOLOCK ) ON sdv.valueId = limit.payBy
  1280. INNER JOIN countryMaster cm WITH ( NOLOCK ) ON cm.countryId = limit.receivingCountry
  1281. AND customerVerification = @customerStatus
  1282. AND limitType = 'T' AND limit.receivingCountry = '151';
  1283. END;
  1284. ELSE IF @flag ='lastTxnsOfBank'
  1285. BEGIN
  1286. select top 3 value= 'rFullName='+isnull(receiverName,'')+'=v-::-cmbAgent='+isnull(CAST(pBank AS VARCHAR),'')+
  1287. '=d-::-cmbAgentName='+isnull(pBankName,'')+'=v-::-hddBranch='+cast(isnull(pBankBranch,'') as varchar)+
  1288. '=v-::-hddBranchName='+isnull(pBankBranchName,'')+'=v-::-txtAccountNo='+isnull(rt.accountNo,'')+
  1289. '=v-::-receiverrelation='+isnull(rt.relWithSender,'')+'=d-::-RAddress='+isnull(address,'')+'=v-::-rState='+isnull([STATE],'')+
  1290. '=v-::-rCity='+isnull(city,'')+'=v-::-receiverMobile='+ isnull(mobile,'')+'=v-::-receiverEmail='+isnull(email,'')+
  1291. '=v-::-rTelephone='+isnull(homePhone,'')+'=v-::-ddllstReceiver='+isnull(cast(ts.customerId as varchar),'')+'=d'
  1292. ,[text]= isnull(receiverName,'')+' | '+isnull(pBankName,'')+' | '+isnull(rt.accountNo,'')
  1293. from dbo.vwRemitTran rt WITH(NOLOCK)
  1294. LEFT JOIN dbo.vwTranReceivers ts WITH(NOLOCK) ON ts.tranId = rt.id
  1295. WHERE tranType='O' AND rt.createdBy = @user
  1296. AND isnull(paymentMethod,'CASH PAYMENT') = 'BANK DEPOSIT'
  1297. AND rt.pCountry = @pCountry
  1298. ORDER BY rt.holdTranId desc
  1299. RETURN
  1300. END
  1301. ELSE IF @flag = 'isProVoucherUsed'
  1302. BEGIN
  1303. IF NOT EXISTS ( SELECT TOP 1 'x' FROM remitTran(nolock) WHERE promotionCode IS NOT NULL AND createdBy = @user )
  1304. BEGIN
  1305. SELECT '1' errorCode , 'Promotional Code already used.' , NULL;
  1306. END;
  1307. ELSE
  1308. BEGIN
  1309. SELECT '0' errorCode , 'Promotional Code not used.' , NULL;
  1310. END;
  1311. END;
  1312. ELSE IF @flag = 'getTtranDetail'
  1313. BEGIN
  1314. SELECT TOP 1 cm.countryId , rt.pCountry, rt.tAmt, rt.pAmt, rt.payoutCurr, rt.pAgentName, rt.purposeOfRemit,
  1315. rt.sourceOfFund, rt.pBankName, rt.pBankBranchName, rt.serviceCharge, rt.collCurr,
  1316. customerRate =CASE WHEN rt.pAgent IN (224389,2129) THEN 0 ELSE rt.customerRate END,
  1317. pAgentId = rt.pAgent,pBranchId =rt.pBranch,rt.cAmt,rt.pBank,rt.pBankBranch,payoutMethod = rt.paymentMethod,
  1318. paymentMethod = s.serviceTypeId,
  1319. rt.receiverName ,tr.address , tr.[state], tr.city , tr.mobile , tr.email , phone = tr.homePhone ,
  1320. relationship = rt.relWithSender , cAmt = CAST(cAmt AS DECIMAL(10, 2)) , collCurr ,
  1321. collMode ,
  1322. pAgent = CAST(pBank AS VARCHAR) + ISNULL('|' + pBankType, '') ,
  1323. pAgentName = pBankName ,
  1324. pBranch = pBankBranch ,
  1325. pBranchName = pBankBranchName ,
  1326. rt.accountNo ,
  1327. RI.receiverId,
  1328. tr.firstName,
  1329. tr.middleName,
  1330. tr.lastName1,
  1331. tr.state,
  1332. tr.city,
  1333. tr.address,
  1334. tr.country,
  1335. tr.relationType,
  1336. tr.mobile,
  1337. tr.email
  1338. FROM RemitTran rt WITH ( NOLOCK )
  1339. INNER JOIN countryMaster cm WITH ( NOLOCK ) ON rt.pCountry = cm.countryName AND rt.id = @tranId
  1340. INNER JOIN TranReceivers tr WITH ( NOLOCK ) ON tr.tranId = rt.id
  1341. INNER JOIN serviceTypeMaster s(nolock) on s.typeTitle = rt.paymentMethod
  1342. LEFT JOIN dbo.receiverInformation RI (NOLOCK) ON RI.receiverId = tr.customerId
  1343. --WHERE rt.id = @tranId;
  1344. END;
  1345. ELSE IF @flag = 'mostRecentTxn'
  1346. BEGIN
  1347. DECLARE @totalSend MONEY, @totalSendText VARCHAR(200), @YearStart DATE, @YearEnd DATETIME,@vYearlyLimit MONEY
  1348. SELECT @YearStart = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)
  1349. ,@YearEnd = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, -1)+' 23:59:59'
  1350. SELECT @totalSend = SUM(ROUND(R.tAmt/(R.sCurrCostRate+R.sCurrHoMargin), 2, 0))
  1351. FROM REMITTRAN R(NOLOCK)
  1352. INNER JOIN TRANSENDERS T(NOLOCK) ON T.TRANID = R.ID
  1353. AND T.CUSTOMERID = @senderId
  1354. AND R.TRANSTATUS <> 'Cancel'
  1355. AND R.approvedDate BETWEEN @YearStart AND @YearEnd
  1356. SELECT @vYearlyLimit = amount
  1357. FROM dbo.csDetail CD(NOLOCK)
  1358. INNER JOIN csMaster CM(NOLOCK) ON CM.csMasterId = CD.csMasterId
  1359. WHERE CD.period = 365
  1360. AND CD.condition = 4600
  1361. AND ISNULL(CD.isActive, 'Y') = 'Y'
  1362. AND ISNULL(CD.isDeleted, 'N') = 'N'
  1363. AND ISNULL(CD.isEnable, 'Y') = 'Y'
  1364. AND ISNULL(CM.isActive, 'Y') = 'Y'
  1365. AND ISNULL(CM.isDeleted, 'N') = 'N'
  1366. SET @totalSendText = 'Remaining sending limit for the year '+FORMAT(GETDATE(),'yyyy')+' = USD '+FORMAT((@vYearlyLimit - ISNULL(@totalSend, 0)),'0,00');
  1367. SELECT DISTINCT TOP 3
  1368. R.id ,
  1369. createdDate = CONVERT(VARCHAR, createdDate, 101) ,
  1370. receiverName ,
  1371. paymentMethod ,
  1372. cAmt = CAST(cAmt AS DECIMAL(10, 2)) ,
  1373. tranStatus ,
  1374. collCurr,pCountry
  1375. FROM REMITTRAN R ( NOLOCK ) -- needs to be remitTran For Every Successful Transaction
  1376. INNER JOIN TRANSENDERS T(NOLOCK) ON T.TRANID = R.ID
  1377. AND T.CUSTOMERID = @senderId
  1378. AND R.TRANSTATUS <> 'Cancel'
  1379. ORDER BY R.ID DESC;
  1380. SELECT totalSendText = @totalSendText
  1381. END
  1382. ELSE IF @flag = 'txnSummary'
  1383. BEGIN
  1384. SELECT DISTINCT
  1385. id ,
  1386. holdTranId,
  1387. createdDate = CONVERT(VARCHAR, createdDate, 101) ,
  1388. receiverName ,
  1389. paymentMethod ,
  1390. cAmt = CAST(cAmt AS DECIMAL(10, 2)) ,
  1391. tranStatus ,
  1392. collCurr
  1393. FROM dbo.vwRemitTran WITH ( NOLOCK ) -- needs to be remitTran For Every Successful Transaction
  1394. where createdby = @user AND sAgent=@sAgent --needs to retrieve for the specific sending agent
  1395. --WHERE tranType = 'O'
  1396. -- AND createdBy = @user -- for sepecific user for now commented
  1397. ORDER BY holdTranId DESC;
  1398. END;
  1399. ELSE IF @flag = 'hasScheme'
  1400. BEGIN
  1401. DECLARE @todayDate DATETIME;
  1402. SET @todayDate = GETDATE();
  1403. IF EXISTS ( SELECT TOP 1 'X' FROM dbo.schemeSetup WITH ( NOLOCK )
  1404. WHERE @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1405. AND ISNULL(isActive, 'N') = 'Y'
  1406. AND ISNULL(isDeleted, 'N') = 'N' )
  1407. BEGIN
  1408. IF @schemeId IS NULL
  1409. SELECT @schemeId = rowId
  1410. FROM dbo.schemeSetup WITH ( NOLOCK )
  1411. WHERE
  1412. rCountry = @pCountryId
  1413. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1414. AND ISNULL(isActive, 'N') = 'Y'
  1415. AND ISNULL(isDeleted, 'N') = 'N'
  1416. AND ISNULL(couponCode, 'x') = @couponCode;
  1417. IF @schemeId IS NULL
  1418. SELECT @schemeId = rowId
  1419. FROM dbo.schemeSetup WITH ( NOLOCK )
  1420. WHERE
  1421. rCountry = @pCountryId
  1422. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1423. AND ISNULL(isActive, 'N') = 'Y'
  1424. AND ISNULL(isDeleted, 'N') = 'N';
  1425. IF @schemeId IS NULL
  1426. SELECT @schemeId = rowId
  1427. FROM dbo.schemeSetup WITH ( NOLOCK )
  1428. WHERE
  1429. rCountry IS NULL
  1430. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1431. AND ISNULL(isActive, 'N') = 'Y'
  1432. AND ISNULL(isDeleted, 'N') = 'N';
  1433. IF @schemeId IS NULL
  1434. SELECT
  1435. @schemeId = rowId
  1436. FROM
  1437. dbo.schemeSetup WITH ( NOLOCK )
  1438. WHERE
  1439. rCountry = @pCountryId
  1440. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1441. AND ISNULL(isActive, 'N') = 'Y'
  1442. AND ISNULL(isDeleted, 'N') = 'N';
  1443. IF @schemeId IS NULL
  1444. SELECT
  1445. @schemeId = rowId
  1446. FROM
  1447. dbo.schemeSetup WITH ( NOLOCK )
  1448. WHERE
  1449. rCountry IS NULL
  1450. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1451. AND ISNULL(isActive, 'N') = 'Y'
  1452. AND ISNULL(isDeleted, 'N') = 'N';
  1453. END;
  1454. IF EXISTS ( SELECT 'X'
  1455. FROM
  1456. dbo.schemeSetup WITH ( NOLOCK )
  1457. WHERE
  1458. @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1459. AND ISNULL(isActive, 'N') = 'Y'
  1460. AND ISNULL(isDeleted, 'N') = 'N' )
  1461. BEGIN
  1462. IF @schemeId IS NULL
  1463. SELECT
  1464. @schemeId = rowId
  1465. FROM
  1466. dbo.schemeSetup WITH ( NOLOCK )
  1467. WHERE
  1468. rCountry = @pCountryId
  1469. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1470. AND ISNULL(isActive, 'N') = 'Y'
  1471. AND ISNULL(isDeleted, 'N') = 'N';
  1472. IF @schemeId IS NULL
  1473. SELECT
  1474. @schemeId = rowId
  1475. FROM
  1476. dbo.schemeSetup WITH ( NOLOCK )
  1477. WHERE
  1478. rCountry IS NULL
  1479. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1480. AND ISNULL(isActive, 'N') = 'Y'
  1481. AND ISNULL(isDeleted, 'N') = 'N';
  1482. END;
  1483. IF EXISTS ( SELECT
  1484. 'X'
  1485. FROM
  1486. dbo.schemeSetup WITH ( NOLOCK )
  1487. WHERE
  1488. @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1489. AND ISNULL(isActive, 'N') = 'Y'
  1490. AND ISNULL(isDeleted, 'N') = 'N' )
  1491. BEGIN
  1492. IF @schemeId IS NULL
  1493. SELECT
  1494. @schemeId = rowId
  1495. FROM
  1496. dbo.schemeSetup WITH ( NOLOCK )
  1497. WHERE
  1498. rCountry = @pCountryId
  1499. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1500. AND ISNULL(isActive, 'N') = 'Y'
  1501. AND ISNULL(isDeleted, 'N') = 'N';
  1502. IF @schemeId IS NULL
  1503. SELECT
  1504. @schemeId = rowId
  1505. FROM
  1506. dbo.schemeSetup WITH ( NOLOCK )
  1507. WHERE
  1508. rCountry IS NULL
  1509. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1510. AND ISNULL(isActive, 'N') = 'Y'
  1511. AND ISNULL(isDeleted, 'N') = 'N';
  1512. END;
  1513. IF @schemeId IS NOT NULL
  1514. BEGIN
  1515. DECLARE @multipleSchemeId INT;
  1516. SELECT
  1517. @multipleSchemeId = rowId
  1518. FROM
  1519. dbo.schemeSetup WITH ( NOLOCK )
  1520. WHERE
  1521. rCountry = @pCountryId
  1522. AND @todayDate BETWEEN schemeStartDate AND schemeEndDate
  1523. AND ISNULL(isActive, 'N') = 'Y'
  1524. AND ISNULL(isDeleted, 'N') = 'N'
  1525. AND couponCode = @couponCode;
  1526. IF @multipleSchemeId IS NOT NULL
  1527. SELECT '0' errorCode , 'Scheme is Available.' msg , @multipleSchemeId id;
  1528. ELSE
  1529. SELECT '0' errorCode , 'Scheme is Available.' msg , @schemeId id;
  1530. END;
  1531. ELSE
  1532. BEGIN
  1533. SELECT '1' errorCode , 'Scheme is NOT Available.' msg , @schemeId id;
  1534. END;
  1535. END;
  1536. ELSE IF @flag = 'checkSingleTxn'
  1537. BEGIN
  1538. IF ( SELECT TOP 1 approvedDate FROM customerMaster WITH ( NOLOCK ) WHERE customerId = @user AND ISNULL(onlineUser, 'N') = 'Y' ) IS NULL
  1539. BEGIN
  1540. SELECT '1' ErrorCode ,
  1541. 'Sorry! Your customer verification is in pending.
  1542. Kindly visit to our nearest agent/branch to verify your document.' Msg,
  1543. @user Id;
  1544. RETURN;
  1545. END;
  1546. ELSE IF (SELECT TOP 1 availableBalance FROM dbo.customerMaster WITH (NOLOCK) WHERE customerId=@user AND ISNULL(onlineUser,'N')='Y') IS NULL
  1547. BEGIN
  1548. SELECT '1' ErrorCode, 'Sorry! You have no balance in your GME Wallet' Msg, @user Id;
  1549. RETURN;
  1550. END
  1551. ELSE
  1552. BEGIN
  1553. SELECT '0' ErrorCode ,'You are authorised to send transaction.' Msg , @user Id;
  1554. RETURN;
  1555. END;
  1556. END;
  1557. END;
  1558. END TRY
  1559. BEGIN CATCH
  1560. IF @@TRANCOUNT <> 0
  1561. ROLLBACK TRANSACTION;
  1562. DECLARE @errorMessage VARCHAR(MAX);
  1563. SET @errorMessage = ERROR_MESSAGE();
  1564. EXEC proc_errorHandler 1, @errorMessage, @user;
  1565. END CATCH
  1566. GO