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.

1760 lines
68 KiB

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