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.

1605 lines
37 KiB

  1. ALTER PROC [dbo].[proc_SendTransaction]
  2. @User VARCHAR(100) = NULL
  3. ,@SenderId INT = NULL
  4. ,@sIpAddress VARCHAR(20) = NULL
  5. ,@ReceiverId INT = NULL
  6. ,@rFirstName VARCHAR(50) = NULL
  7. ,@rMiddleName VARCHAR(50) = NULL
  8. ,@rLastName VARCHAR(50) = NULL
  9. ,@rIdType VARCHAR(50) = NULL
  10. ,@rIdNo VARCHAR(30) = NULL
  11. ,@rIdIssue VARCHAR(10) = NULL
  12. ,@rIdExpiry VARCHAR(10) = NULL
  13. ,@rDob VARCHAR(10) = NULL
  14. ,@rMobileNo VARCHAR(20) = NULL
  15. ,@rNativeCountry VARCHAR(50) = NULL
  16. ,@rStateId INT = NULL
  17. ,@rDistrictId INT = NULL
  18. ,@rAddress VARCHAR(100) = NULL
  19. ,@rCity VARCHAR(50) = NULL
  20. ,@rEmail VARCHAR(50) = NULL
  21. ,@rAccountNo VARCHAR(50) = NULL
  22. ,@sCountryId INT = NULL
  23. ,@pCountryId INT = NULL
  24. ,@deliveryMethodId INT = NULL
  25. ,@pBankId BIGINT = NULL
  26. ,@pBranchId BIGINT = NULL
  27. ,@collCurr VARCHAR(3) = NULL
  28. ,@payoutCurr VARCHAR(3) = NULL
  29. ,@collAmt MONEY = NULL
  30. ,@payoutAmt MONEY = NULL
  31. ,@transferAmt MONEY = NULL
  32. ,@exRate MONEY = NULL
  33. ,@calBy CHAR(1) = NULL
  34. ,@tpExRate DECIMAL(30, 12) = NULL
  35. ,@payOutPartnerId BIGINT = NULL
  36. ,@forexSessionId VARCHAR(40) = NULL
  37. ,@kftcLogId BIGINT = NULL
  38. ,@paymentType VARCHAR(20) = NULL
  39. ,@scDiscount MONEY = NULL
  40. ,@PurposeOfRemittance VARCHAR(100) = NULL
  41. ,@SourceOfFund VARCHAR(100) = NULL
  42. ,@PurposeOfRemittanceOther VARCHAR(100) = NULL
  43. ,@SourceOfFundOther VARCHAR(100) = NULL
  44. ,@RelWithSender VARCHAR(200) = NULL
  45. ,@SourceType CHAR(1) = NULL
  46. ,@schemeId BIGINT = NULL
  47. ,@processId VARCHAR(40) = NULL
  48. ,@flag VARCHAR(100)
  49. ,@controlNo VARCHAR(20) = NULL
  50. ,@PartnerPin VARCHAR(20) = NULL
  51. ,@PartnerId VARCHAR(20) = NULL
  52. ,@tranId BIGINT = NULL
  53. ,@errorCode INT = NULL
  54. ,@Message NVARCHAR(500) = NULL
  55. ,@sAdd2 NVARCHAR(150) = NULL
  56. ,@goodsOrigin VARCHAR(100) = NULL
  57. ,@goodsType VARCHAR(100) = NULL
  58. ,@portOfShipment VARCHAR(100) = NULL
  59. ,@discountedFee MONEY = NULL
  60. AS
  61. -----------------------------------------------------------
  62. -- For Broadcast notification , @flag = 'send'
  63. -- #101 - MOBILE CHANGES , #361 - MULTI-LINGUAL
  64. -- #476 - Changes in dotransaction Payment of Import Good
  65. -- #101 - set error code as 19 for unapproved customer
  66. -- Disable ProcBroadCastMobile @Flag='TRANSACTION_SUCCESS'
  67. -- #495 Added condition for @sourceOfFundOther and @purposeOfRemittanceOther
  68. -- Fix issue related with Bank id invalid add @pBankId_O,@payOutPartnerId_O
  69. --#643 Mobile transaction wrongly flag for Questionnaire require due to Visa Status
  70. -- #717 - insert visaStatus in tranSendersTemp
  71. -- check mobileApprovedDate instead of approved date
  72. -- #756 Duplicate pin generated
  73. -- insert into controllist for M
  74. --#767 Relationship displayed blank for mobile transaction.
  75. -- #767 relationship other
  76. -- #790 Change column to store relationship others for Mobile transaction
  77. --#810 Missing sending commission in mobile Txn voucher
  78. --#831 Disabled customer allowed to do Mobile txn
  79. --#820 Donga wrong commission for mobile txn
  80. --#Bug #1192 Sender Expiry not check from Mobile Transaction
  81. -- #1003 - Reward Points, @flag = 'Send'
  82. -- #1498 - TF NO Balance
  83. -- #1590 - Customer Loyalty
  84. -- #11358 - show branch routing number for mobile transaction in search transaction , pbankBranchName
  85. -- #12985 - invalid routing no case
  86. -----------------------------------------------------------
  87. SET NOCOUNT ON;
  88. SET XACT_ABORT ON;
  89. BEGIN TRY
  90. DECLARE @complianceRuleId INT
  91. ,@cAmtUSD MONEY
  92. ,@complienceMessage VARCHAR(1000) = NULL
  93. ,@shortMsg VARCHAR(100) = NULL
  94. ,@complienceErrorCode TINYINT = NULL
  95. ,@compErrorCode INT
  96. ,@discountType VARCHAR(2) = NULL
  97. ,@discountvalue MONEY = NULL
  98. ,@couponType VARCHAR(3) = NULL
  99. ,@discountPercent MONEY = NULL
  100. ,@couponName VARCHAR(20) = NULL
  101. ,@ServiceCharge_Temp MONEY = NULL
  102. ,@schemePremium MONEY = NULL
  103. ,@customerType INT = NULL
  104. ,@msg VARCHAR(MAX) = NULL
  105. ,@pBankId_O BIGINT = @pBankId
  106. ,@payOutPartnerId_O BIGINT = @payOutPartnerId
  107. ,@RelWithSenderOthers VARCHAR(200) = NULL
  108. ,@receiverName VARCHAR(100) = NULL
  109. ,@createdFrom VARCHAR(10) = NULL
  110. ,@tranCount INT = NULL
  111. ,@schemeCount INT = NULL
  112. ,@isEligible CHAR(1) = NULL
  113. ,@schemeCodeId INT = NULL
  114. ,@isFirstTran CHAR(1) = 'N'
  115. ,@introducer VARCHAR(25) = NULL
  116. IF EXISTS (
  117. SELECT *
  118. FROM STATICDATAVALUE(NOLOCK)
  119. WHERE VALUEID = @RelWithSender
  120. AND TYPEID = 2100
  121. AND isActive = 'N'
  122. )
  123. BEGIN
  124. SELECT TOP 1 @receiverName = ISNULL(firstName, '') + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName1, '') + ISNULL(' ' + lastName2, '')
  125. FROM dbo.receiverInformation RI(NOLOCK)
  126. WHERE receiverId = @receiverId
  127. SET @msg = 'Please update the details of receiver [ ' + @receiverName + ' ] before performing transaction!';
  128. EXEC proc_errorHandler 21
  129. ,@msg
  130. ,NULL;
  131. Rollback Transaction
  132. RETURN;
  133. END
  134. IF EXISTS (
  135. SELECT *
  136. FROM STATICDATAVALUE(NOLOCK)
  137. WHERE VALUEID = @PurposeOfRemittance
  138. AND TYPEID = 3800
  139. AND isActive = 'Y'
  140. )
  141. BEGIN
  142. SELECT @PurposeOfRemittance = detailTitle
  143. FROM STATICDATAVALUE(NOLOCK)
  144. WHERE VALUEID = @PurposeOfRemittance
  145. AND TYPEID = 3800
  146. END
  147. IF EXISTS (
  148. SELECT *
  149. FROM STATICDATAVALUE(NOLOCK)
  150. WHERE VALUEID = @sourceOfFund
  151. AND TYPEID = 3900
  152. AND isActive = 'Y'
  153. )
  154. BEGIN
  155. SELECT @sourceOfFund = detailTitle
  156. FROM STATICDATAVALUE(NOLOCK)
  157. WHERE VALUEID = @sourceOfFund
  158. AND TYPEID = 3900
  159. END
  160. SELECT @pcountryId = cm.countryId
  161. ,@RelWithSenderOthers = ISNULL(relationOther, otherRelationDesc)
  162. FROM receiverInformation RI(NOLOCK)
  163. INNER JOIN countryMaster CM(NOLOCK) ON CM.countryName = RI.country
  164. WHERE RI.receiverId = @ReceiverId
  165. IF EXISTS (
  166. SELECT *
  167. FROM STATICDATAVALUE(NOLOCK)
  168. WHERE VALUEID = @RelWithSender
  169. AND TYPEID = 2100
  170. AND isActive = 'Y'
  171. )
  172. BEGIN
  173. IF (@RelWithSender = '11339')
  174. BEGIN
  175. SET @RelWithSender = 'Other (please specify) :' + ISNULL(@RelWithSenderOthers, '');
  176. END
  177. ELSE
  178. BEGIN
  179. SELECT @RelWithSender = detailTitle
  180. FROM STATICDATAVALUE(NOLOCK)
  181. WHERE VALUEID = @RelWithSender
  182. AND TYPEID = 2100
  183. END
  184. END
  185. DECLARE @isRealTime BIT = 0 , @TRANSFER_MODE varchar(10)='';
  186. SELECT @payOutPartnerId = AGENTID
  187. ,@isRealTime = isRealTime
  188. FROM TblPartnerwiseCountry(NOLOCK)
  189. WHERE CountryId = @pCountryId
  190. AND IsActive = 1
  191. AND ISNULL(PaymentMethod, @deliveryMethodId) = @deliveryMethodId
  192. AND IsMobileEnabled = 1
  193. IF @payOutPartnerId IS NULL
  194. BEGIN
  195. EXEC proc_errorHandler 3
  196. ,'Oops, something went wrong! Please perform the transaction again. Route is missing.'
  197. ,NULL
  198. RETURN;
  199. END
  200. IF EXISTS (
  201. SELECT *
  202. FROM API_BANK_LIST_MASTER(NOLOCK)
  203. WHERE MASTER_BANK_ID = @pBankId
  204. AND IS_ACTIVE = '1'
  205. )
  206. BEGIN
  207. SELECT @pBankId = AB.BANK_ID ,@TRANSFER_MODE= ab.TRANSFER_MODE
  208. FROM API_BANK_LIST AB(NOLOCK)
  209. INNER JOIN API_BANK_LIST_MASTER ABM(NOLOCK) ON AB.JME_BANK_CODE = ABM.JME_BANK_CODE
  210. WHERE MASTER_BANK_ID = @pBankId
  211. AND ABM.IS_ACTIVE = '1'
  212. AND AB.API_PARTNER_ID = @payOutPartnerId
  213. END
  214. IF @flag = 'SEND'
  215. BEGIN
  216. IF NOT EXISTS (
  217. SELECT TOP 1 'X'
  218. FROM dbo.customerMaster(NOLOCK)
  219. WHERE username = @user
  220. AND mobileApprovedDate IS NOT NULL
  221. )
  222. BEGIN
  223. EXEC proc_errorHandler 19
  224. ,'You are not authorized to perform transaction, please contact JME Support!'
  225. ,NULL;
  226. RETURN;
  227. END
  228. DECLARE @remittanceAllowed int,@idExpiryDate DATETIME
  229. SELECT @remittanceAllowed = remittanceAllowed,@idExpiryDate=idExpiryDate FROM customerMaster(NOLOCK)
  230. WHERE CUSTOMERID = @SenderId
  231. IF ISNULL(@remittanceAllowed, 0) = '0'
  232. BEGIN
  233. SELECT @MSG = 'You are not authorized to perform transaction, please contact JME Support!'
  234. EXEC proc_errorHandler 19
  235. ,@MSG
  236. ,NULL
  237. RETURN
  238. END
  239. IF @idExpiryDate < GETDATE()
  240. BEGIN
  241. SELECT @MSG = 'Your ID with us has expired. Please upload new ID details in �Renew ID� or contact JME support.'
  242. EXEC proc_errorHandler 22
  243. ,@MSG
  244. ,NULL
  245. RETURN;
  246. END
  247. DECLARE @kycStatus INT
  248. SELECT @kycStatus = kycStatus
  249. FROM TBL_CUSTOMER_KYC(NOLOCK)
  250. WHERE CUSTOMERID = @senderId
  251. AND ISDELETED = 0
  252. --AND kycStatus=11044
  253. ORDER BY KYC_DATE
  254. IF ISNULL(@kycStatus, 0) <> 11044
  255. BEGIN
  256. IF @kycStatus IS NOT NULL
  257. SELECT @MSG = 'KYC for selected customer is not completed, it is in status:' + detailTitle
  258. FROM staticDataValue(NOLOCK)
  259. WHERE valueId = @kycStatus
  260. ELSE
  261. SELECT @MSG = 'Please complete KYC status first'
  262. EXEC proc_errorHandler 2
  263. ,@MSG
  264. ,NULL;
  265. RETURN
  266. END
  267. IF @paymentType IS NULL
  268. SET @paymentType = 'WALLET'
  269. DECLARE @sCurrCostRate FLOAT
  270. ,@sCurrHoMargin FLOAT
  271. ,@pCurrCostRate FLOAT
  272. ,@customerRate MONEY
  273. ,@agentCrossSettRate FLOAT
  274. ,@iServiceCharge MONEY
  275. ,@iTAmt MONEY
  276. ,@iPAmt MONEY
  277. ,@place INT
  278. ,@currDecimal INT
  279. ,@agentAvlLimit MONEY
  280. ,@serviceCharge MONEY
  281. ,@sCountry VARCHAR(50) = 'Japan'
  282. ,@sAgent BIGINT
  283. ,@sAgentName VARCHAR(100)
  284. ,@sBranch INT
  285. ,@sBranchName VARCHAR(100)
  286. ,@sSuperAgent INT
  287. ,@sSuperAgentName VARCHAR(100)
  288. ,@senderName VARCHAR(100)
  289. ,@sIdNo VARCHAR(50)
  290. ,@sIdType VARCHAR(50)
  291. ,@sMobile VARCHAR(15)
  292. ,@pAgent BIGINT
  293. ,@pSuperAgent BIGINT
  294. ,@pSuperAgentName VARCHAR(100)
  295. ,@pAgentName VARCHAR(100)
  296. ,@controlNoEncrypted VARCHAR(30)
  297. ,@tempCompId BIGINT
  298. ,@pBranch INT
  299. ,@pBranchName VARCHAR(100)
  300. ,@pCountry VARCHAR(100)
  301. ,@RcreatedFrom VARCHAR(5)
  302. ,@ROtpVerified BIT
  303. SELECT @sCountryId = 113
  304. ,@sBranch = 394395
  305. SELECT @SenderId = customerId ,
  306. @createdFrom = createdFrom
  307. FROM customerMaster(NOLOCK)
  308. WHERE USERNAME = @User
  309. IF NOT EXISTS(SELECT 1 FROM
  310. (SELECT TOP 1 customerId FROM TRANSENDERS TS (NOLOCK)
  311. inner join remittran (nolock) rt on rt.id = ts.tranId
  312. WHERE customerId = @SenderId AND rt.tranStatus <> 'CANCEL' AND RT.tranType='M'
  313. UNION ALL
  314. SELECT TOP 1 customerId FROM TRANSENDERSTEMP TT (NOLOCK)
  315. inner join remittrantemp (nolock) rt on rt.id = tt.tranId
  316. WHERE customerId = @SenderId AND rt.tranStatus <> 'CANCEL' AND rt.tranType='M'
  317. ) a where customerId = @SenderId
  318. )
  319. BEGIN
  320. SET @isFirstTran = 'Y'
  321. END
  322. SELECT @sAgent = sAgent
  323. ,@sAgentName = sAgentName
  324. ,@sBranch = sBranch
  325. ,@sBranchName = sBranchName
  326. ,@sSuperAgent = sSuperAgent
  327. ,@sSuperAgentName = sSuperAgentName
  328. FROM dbo.FNAGetBranchFullDetails(@sBranch)
  329. SELECT @pCountry = COUNTRYNAME
  330. FROM COUNTRYMASTER(NOLOCK)
  331. WHERE COUNTRYID = @pCountryId
  332. SELECT TOP 1 @pAgent = AM.agentId
  333. --,@pCountryId = AM.agentCountryId
  334. FROM agentMaster AM(NOLOCK)
  335. WHERE AM.parentId = @payOutPartnerId
  336. AND agentType = 2903
  337. AND AM.isSettlingAgent = 'Y'
  338. AND AM.isApiPartner = 1
  339. SELECT @pSuperAgentName = sSuperAgentName
  340. ,@pSuperAgent = sSuperAgent
  341. ,@pAgent = sAgent
  342. ,@pAgentName = sAgentName
  343. FROM dbo.FNAGetBranchFullDetails(@pAgent)
  344. SELECT @pBranch = @pAgent
  345. ,@pBranchName = @pAgentName
  346. DECLARE @StateId INT
  347. ,@DistrictId INT
  348. IF @receiverId IS NOT NULL
  349. BEGIN
  350. IF NOT EXISTS (
  351. SELECT '1'
  352. FROM dbo.receiverInformation(NOLOCK)
  353. WHERE receiverId = @ReceiverId
  354. )
  355. BEGIN
  356. EXEC proc_errorHandler 4
  357. ,'Receiver Data Not Match !'
  358. ,NULL;
  359. RETURN;
  360. END
  361. SELECT TOP 1 @receiverName = ISNULL(firstName, '') + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName1, '') + ISNULL(' ' + lastName2, '')
  362. ,@StateId = AI.STATE_ID
  363. ,@DistrictId = AC.CITY_ID
  364. ,@RcreatedFrom = ISNULL(ri.createdFrom, 'C')
  365. ,@ROtpVerified = ISNULL(ri.isOTPVerified, 0)
  366. FROM dbo.receiverInformation RI(NOLOCK)
  367. LEFT JOIN API_STATE_LIST AI(NOLOCK) ON AI.STATE_NAME = RI.STATE
  368. AND AI.API_PARTNER_ID = @payOutPartnerId
  369. LEFT JOIN API_CITY_LIST AC(NOLOCK) ON AC.STATE_ID = AI.STATE_ID
  370. AND AC.CITY_NAME = RI.DISTRICT
  371. WHERE receiverId = @receiverId
  372. IF(@RcreatedFrom='M' AND @ROtpVerified=0 )
  373. BEGIN
  374. EXEC proc_errorHandler 4
  375. ,'Receiver Data Not Match !'
  376. ,NULL;
  377. RETURN;
  378. END
  379. END
  380. ELSE
  381. SET @receiverName = ISNULL(@rFirstName, '') + ISNULL(' ' + @rMiddleName, '') + ISNULL(' ' + @rLastName, '')
  382. IF @rFirstName IS NULL
  383. AND @receiverId IS NULL
  384. BEGIN
  385. EXEC proc_errorHandler 5
  386. ,'Receiver name cannot be empty'
  387. ,NULL;
  388. RETURN;
  389. END
  390. IF ISNULL(@exRate, 0) = 0
  391. BEGIN
  392. EXEC proc_errorHandler 6
  393. ,'Transaction cannot be proceed.Exchange Rate not defined'
  394. ,NULL
  395. RETURN
  396. END
  397. IF @pAgent IS NULL
  398. BEGIN
  399. EXEC proc_errorHandler 3
  400. ,'Oops, something went wrong.Please perform the transaction again'
  401. ,NULL
  402. RETURN;
  403. END
  404. DECLARE @OccupationId INT
  405. ,@sNaCountryId INT
  406. ,@visaStatusId INT
  407. DECLARE @visaStatusText VARCHAR(200)
  408. SELECT TOP 1 @agentAvlLimit = dbo.FNAGetCustomerAvailableBalance(@SenderId)
  409. ,@senderName = fullName
  410. ,@sIdNo = idNumber
  411. ,@sIdType = idType
  412. ,@sMobile = mobile
  413. ,@customerType = customerType
  414. ,@OccupationId = OCCUPATION
  415. ,@sNaCountryId = NATIVECOUNTRY
  416. ,@visaStatusId = VISASTATUS
  417. ,@visaStatusText = SV.detailTitle
  418. ,@sAdd2 = ISNULL(additionalAddress, '')
  419. FROM customerMaster CM(NOLOCK)
  420. LEFT JOIN STATICDATAVALUE SV(NOLOCK) ON SV.valueId = CM.visaStatus
  421. WHERE username = @User
  422. AND customerId = @SenderId
  423. IF ISNULL(@paymentType, '') NOT IN ('wallet')
  424. BEGIN
  425. EXEC proc_errorHandler 7
  426. ,'Invalid payment method.Please perform the transaction again!'
  427. ,NULL;
  428. RETURN;
  429. END
  430. IF @user IN ('demo.gme@gmeremit.com')
  431. BEGIN
  432. EXEC proc_errorHandler 8
  433. ,'You can not send money through test GME acocunt :('
  434. ,NULL;
  435. RETURN;
  436. END
  437. IF ISNULL(@collAmt, 0) = 0
  438. BEGIN
  439. EXEC proc_errorHandler 9
  440. ,'Collection Amount is missing. Cannot send transaction'
  441. ,NULL;
  442. RETURN;
  443. END;
  444. SET @controlNo = '21' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  445. IF EXISTS (
  446. SELECT TOP 1 'X'
  447. FROM controlNoList WITH (NOLOCK)
  448. WHERE controlNo = @controlNo
  449. )
  450. BEGIN
  451. SET @controlNo = '21' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  452. --SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo);
  453. IF EXISTS (
  454. SELECT TOP 1 'X'
  455. FROM controlNoList WITH (NOLOCK)
  456. WHERE controlNo = @controlNo
  457. )
  458. BEGIN
  459. EXEC proc_errorHandler 10
  460. ,'Technical error occurred. Please try again'
  461. ,NULL;
  462. RETURN;
  463. END
  464. END;
  465. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo);
  466. IF @deliveryMethodId = 2
  467. AND @pCountryId <> '151'
  468. BEGIN
  469. IF NOT EXISTS (
  470. SELECT TOP 1 'A'
  471. FROM api_bank_list(NOLOCK)
  472. WHERE BANK_ID = @pBankId
  473. AND PAYMENT_TYPE_ID IN (
  474. 0
  475. ,2
  476. )
  477. AND IS_ACTIVE = 1
  478. )
  479. BEGIN
  480. EXEC proc_errorHandler 11
  481. ,'Invalid bank selected'
  482. ,NULL
  483. RETURN
  484. END
  485. IF @raccountNo IS NULL
  486. BEGIN
  487. EXEC proc_errorHandler 12
  488. ,'Account number cannot be blank'
  489. ,NULL
  490. RETURN
  491. END
  492. END;
  493. --4. Get Exchange Rate Details------------------------------------------------------------------------------------------------------------------
  494. DECLARE @pCurrHoMargin FLOAT
  495. SELECT @customerRate = customerRate
  496. ,@sCurrCostRate = sCurrCostRate
  497. ,@sCurrHoMargin = sCurrHoMargin
  498. ,@pCurrCostRate = pCurrCostRate
  499. ,@agentCrossSettRate = agentCrossSettRate
  500. ,@serviceCharge = serviceCharge
  501. ,@iPAmt = pAmt
  502. ,@schemeId = schemeId
  503. ,@pCurrHoMargin = pCurrHoMargin
  504. ,@schemeCount = CAST( sharingValue AS INT)
  505. ,@schemeCodeId= schemeId
  506. FROM exRateCalcHistory(NOLOCK)
  507. WHERE FOREX_SESSION_ID = @forexSessionId
  508. AND [USER_ID] = @user
  509. DECLARE @pAgentCommCurrency VARCHAR(3)
  510. ,@pAgentComm MONEY
  511. SELECT @pAgentCommCurrency = DBO.FNAGetPayCommCurrency(@sSuperAgent, @sAgent, @sBranch, @SCOUNTRYID, @pSuperAgent, @pBranch, @pCountryId)
  512. IF (LEN(ISNULL(@TRANSFER_MODE, ''))<1
  513. AND @pCountryId = '203'
  514. AND @pAgent = '394133'
  515. AND @deliveryMethodId = '2'
  516. ) -- DONGA Bank Deposit not real time
  517. BEGIN
  518. SET @pAgentComm = (@payoutAmt * 0.17) / 100;
  519. END
  520. ELSE
  521. BEGIN
  522. SELECT @pAgentComm = amount
  523. FROM dbo.FNAGetPayComm(@sAgent, @sCountryId, NULL, NULL, @pCountryId, NULL, @pAgent, @pAgentCommCurrency, @deliveryMethodId, @collAmt, @payoutAmt, @serviceCharge, @transferAmt, NULL)
  524. END
  525. IF @customerRate IS NULL
  526. BEGIN
  527. EXEC proc_errorHandler 6
  528. ,'Transaction cannot be proceed. Exchange Rate not defined'
  529. ,NULL
  530. RETURN
  531. END
  532. -- Customer Loyalty
  533. EXEC PROC_Customer_LoyaltyV2 @flag = 'check-eligible-v2'
  534. ,@isEligible = @isEligible OUT
  535. ,@referralCode = @introducer
  536. ,@tranCount = @trancount OUT
  537. ,@schemeCount = @schemeCount OUT
  538. ,@customerId = @senderId
  539. ,@createdFrom = 'M'
  540. print '@isEligible.Send' + @isEligible;
  541. print '@@trancount.Send' + CAST(@trancount AS VARCHAR);
  542. IF @isEligible = 'Y'
  543. BEGIN
  544. SET @iServiceCharge = 0
  545. END
  546. ELSE
  547. BEGIN
  548. --Get Service Charge----------------------------------------------------------------------------------------------------------------------
  549. DECLARE @iServiceChargeTemp MONEY
  550. SELECT @iServiceChargeTemp = ISNULL(amount, - 1)
  551. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @collAmt, @collCurr)
  552. --SELECT @iServiceCharge = ISNULL(@iServiceChargeTemp,0) - ISNULL(@discountedFee,0)
  553. IF @iServiceCharge < 0 -- @iServiceCharge = - 1
  554. BEGIN
  555. EXEC proc_errorHandler 13
  556. ,'Transaction cannot be proceed. Service Charge is not defined'
  557. ,NULL
  558. RETURN
  559. END
  560. END
  561. print @iServiceCharge;
  562. print @serviceCharge;
  563. IF ISNULL(@iServiceCharge, 0) <> ISNULL(@serviceCharge, 1)
  564. BEGIN
  565. EXEC proc_errorHandler 14
  566. ,'Transaction cannot be proceed. Amount detail not match'
  567. ,NULL
  568. RETURN
  569. END
  570. --End Service Charge-------------------------------------------------------------------------------------------------------------------------------------
  571. --DECLARE @iMsg VARCHAR(MAX)
  572. IF ISNULL(@exRate, 0) <> ISNULL(@customerRate, 1)
  573. BEGIN
  574. --SET @iMsg = 'Amount detail not match. Please re-calculate the amount again' + CAST(isnull(@exRate,0) AS VARCHAR) + ' : ' + CAST(isnull(@customerRate,1) AS VARCHAR)
  575. EXEC proc_errorHandler 15
  576. ,'Amount detail not match. Please re-calculate the amount again'
  577. ,NULL
  578. RETURN
  579. END
  580. IF dbo.FNA_GET_AVAILABLE_BALANCE_POINTS(@senderId) < ISNULL(@discountedFee, 0)
  581. BEGIN
  582. EXEC proc_errorHandler 1
  583. ,'You do not have sufficient points for redeem!'
  584. ,NULL
  585. RETURN;
  586. END
  587. SELECT @iTAmt = @collAmt - @iServiceCharge + ISNULL(@discountedFee, 0)
  588. SELECT TOP 1 @place = place
  589. ,@currDecimal = currDecimal
  590. FROM currencyPayoutRound(NOLOCK)
  591. WHERE ISNULL(isDeleted, 'N') = 'N'
  592. AND currency = @payoutCurr
  593. AND tranType IS NULL;
  594. SET @currDecimal = ISNULL(@currDecimal, 0)
  595. SET @place = ISNULL(@place, 0)
  596. SET @iPAmt = @iTAmt * @CustomerRate
  597. IF @payoutAmt - @iPAmt <= 1
  598. SET @iPAmt = @payoutAmt
  599. ----## WHILE CALCULATING FROM PAYOUT AMOUNT CONSIDARING 10 VND
  600. IF ISNULL(@iPAmt, 0) <> ISNULL(@payoutAmt, 1)
  601. BEGIN
  602. --SET @Msg = 'Amount detail not match. Please re-calculate the amount again.' + CAST(@iPAmt AS VARCHAR) + ' - ' + CAST(@payoutAmt AS VARCHAR)
  603. EXEC proc_errorHandler 15
  604. ,'Amount detail not match. Please re-calculate the amount again.'
  605. ,NULL
  606. RETURN
  607. END
  608. ----OFAC Checking
  609. DECLARE @receiverOfacRes VARCHAR(MAX)
  610. ,@ofacRes VARCHAR(MAX)
  611. ,@ofacReason VARCHAR(200)
  612. EXEC proc_ofacTracker @flag = 't'
  613. ,@name = @senderName
  614. ,@Result = @ofacRes OUTPUT
  615. EXEC proc_ofacTracker @flag = 't'
  616. ,@name = @receiverName
  617. ,@Result = @receiverOfacRes OUTPUT
  618. DECLARE @result VARCHAR(MAX)
  619. IF ISNULL(@ofacRes, '') <> ''
  620. BEGIN
  621. SET @ofacReason = 'Matched by sender name'
  622. END
  623. IF ISNULL(@receiverOfacRes, '') <> ''
  624. BEGIN
  625. SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes)
  626. SET @ofacReason = 'Matched by receiver name'
  627. END
  628. IF ISNULL(@ofacRes, '') <> ''
  629. AND ISNULL(@receiverOfacRes, '') <> ''
  630. BEGIN
  631. SET @ofacReason = 'Matched by both sender name and receiver name'
  632. END
  633. --Ofac Checking End
  634. DECLARE @agentRefId VARCHAR(50) = NEWID()
  635. ----Compliance Checking 1-> Block, 2-> Hold, 3-> Questionnaire
  636. CREATE TABLE #TBL_COMPLIANCE_RESULT (
  637. ERROR_CODE INT
  638. ,MSG VARCHAR(2000)
  639. ,RULE_ID INT
  640. ,SHORT_MSG VARCHAR(1000)
  641. ,[TYPE] VARCHAR(10)
  642. ,IS_D0C_REQUIRED BIT
  643. )
  644. INSERT INTO #TBL_COMPLIANCE_RESULT (
  645. ERROR_CODE
  646. ,MSG
  647. ,RULE_ID
  648. ,SHORT_MSG
  649. ,[TYPE]
  650. ,IS_D0C_REQUIRED
  651. )
  652. EXEC [PROC_COMPLIANCE_CHECKING_NEW] @flag = 'core'
  653. ,@user = @user
  654. ,@sIdType = @sIdType
  655. ,@sIdNo = @sIdNo
  656. ,@receiverName = @receiverName
  657. ,@amount = @iTAmt
  658. ,@customerId = @senderId
  659. ,@pCountryId = @pCountryId
  660. ,@deliveryMethod = @deliveryMethodId
  661. ,@professionId = @OccupationId
  662. ,@receiverMobile = @rMobileNo
  663. ,@accountNo = @raccountNo
  664. ,@receiverId = @receiverId
  665. ,@sNaCountryId = @sNaCountryId
  666. ,@visaStatus = @visaStatusId
  667. IF EXISTS (
  668. SELECT *
  669. FROM #TBL_COMPLIANCE_RESULT
  670. WHERE ERROR_CODE <> 0
  671. )
  672. BEGIN
  673. IF EXISTS (
  674. SELECT *
  675. FROM #TBL_COMPLIANCE_RESULT
  676. WHERE ERROR_CODE IN (1)
  677. ) --transaction blocked
  678. BEGIN
  679. INSERT INTO ComplianceLog (
  680. senderName
  681. ,senderCountry
  682. ,senderIdType
  683. ,senderIdNumber
  684. ,senderMobile
  685. ,receiverName
  686. ,receiverCountry
  687. ,payOutAmt
  688. ,complianceId
  689. ,complianceReason
  690. ,complainceDetailMessage
  691. ,createdBy
  692. ,createdDate
  693. ,agentRefId
  694. ,isDocumentRequired
  695. )
  696. SELECT @senderName
  697. ,@sCountry
  698. ,@sIdType
  699. ,@sIdNo
  700. ,@sMobile
  701. ,@receiverName
  702. ,@pCountry
  703. ,@collAmt
  704. ,RULE_ID
  705. ,SHORT_MSG
  706. ,MSG
  707. ,@user
  708. ,GETDATE()
  709. ,@agentRefId
  710. ,IS_D0C_REQUIRED
  711. FROM #TBL_COMPLIANCE_RESULT
  712. SELECT @MSG = MSG
  713. FROM #TBL_COMPLIANCE_RESULT
  714. WHERE ERROR_CODE IN (1)
  715. --EXEC proc_errorHandler 1, @MSG, NULL
  716. END
  717. IF EXISTS (
  718. SELECT *
  719. FROM #TBL_COMPLIANCE_RESULT
  720. WHERE ERROR_CODE IN (
  721. 2
  722. ,3
  723. )
  724. ) --transaction hold/questionnaire
  725. BEGIN
  726. DELETE
  727. FROM remitTranComplianceTemp
  728. WHERE agentRefId = @agentRefId
  729. INSERT remitTranComplianceTemp (
  730. csDetailTranId
  731. ,matchTranId
  732. ,agentRefId
  733. )
  734. SELECT RULE_ID
  735. ,NULL
  736. ,@agentRefId
  737. FROM #TBL_COMPLIANCE_RESULT
  738. WHERE ERROR_CODE IN (
  739. 2
  740. ,3
  741. )
  742. ORDER BY ISNULL(IS_D0C_REQUIRED, 0) DESC
  743. END
  744. INSERT INTO ComplianceLog (
  745. senderName
  746. ,senderCountry
  747. ,senderIdType
  748. ,senderIdNumber
  749. ,senderMobile
  750. ,receiverName
  751. ,receiverCountry
  752. ,payOutAmt
  753. ,complianceId
  754. ,complianceReason
  755. ,complainceDetailMessage
  756. ,createdBy
  757. ,createdDate
  758. ,agentRefId
  759. ,isDocumentRequired
  760. )
  761. SELECT @senderName
  762. ,@sCountry
  763. ,@sIdType
  764. ,@sIdNo
  765. ,@sMobile
  766. ,@receiverName
  767. ,@pCountry
  768. ,@collAmt
  769. ,RULE_ID
  770. ,SHORT_MSG
  771. ,MSG
  772. ,@user
  773. ,GETDATE()
  774. ,@agentRefId
  775. ,IS_D0C_REQUIRED
  776. FROM #TBL_COMPLIANCE_RESULT
  777. END
  778. --checking for visa status questionnaire
  779. IF EXISTS (
  780. SELECT *
  781. FROM VW_VISA_STATUS_QUESTIONNAIRE
  782. WHERE VISA_ID = @visaStatusId
  783. )
  784. BEGIN
  785. INSERT INTO ComplianceLog (
  786. senderName
  787. ,senderCountry
  788. ,senderIdType
  789. ,senderIdNumber
  790. ,senderMobile
  791. ,receiverName
  792. ,receiverCountry
  793. ,payOutAmt
  794. ,complianceId
  795. ,complianceReason
  796. ,complainceDetailMessage
  797. ,createdBy
  798. ,createdDate
  799. ,agentRefId
  800. ,isDocumentRequired
  801. )
  802. SELECT @senderName
  803. ,@sCountry
  804. ,@sIdType
  805. ,@sIdNo
  806. ,@sMobile
  807. ,@receiverName
  808. ,@pCountry
  809. ,@collAmt
  810. ,0
  811. ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  812. ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  813. ,@user
  814. ,GETDATE()
  815. ,@agentRefId
  816. ,0
  817. INSERT remitTranComplianceTemp (
  818. csDetailTranId
  819. ,matchTranId
  820. ,agentRefId
  821. ,reason
  822. )
  823. SELECT 0
  824. ,NULL
  825. ,@agentRefId
  826. ,'Questionnaire require due to Visa Status'
  827. END
  828. --**********Customer Per Day Limit Checking**********
  829. DECLARE @remitTranTemp TABLE (
  830. tranId BIGINT
  831. ,controlNo VARCHAR(20)
  832. ,cAmt MONEY
  833. ,receiverName VARCHAR(200)
  834. ,receiverIdType VARCHAR(100)
  835. ,receiverIdNumber VARCHAR(50)
  836. ,dot DATETIME
  837. );
  838. INSERT INTO @remitTranTemp (
  839. tranId
  840. ,controlNo
  841. ,cAmt
  842. ,receiverName
  843. ,receiverIdType
  844. ,receiverIdNumber
  845. ,dot
  846. )
  847. SELECT TOP 10 rt.id
  848. ,rt.controlNo
  849. ,rt.cAmt
  850. ,rt.receiverName
  851. ,rec.idType
  852. ,rec.idNumber
  853. ,rt.createdDate
  854. FROM vwRemitTran rt WITH (NOLOCK)
  855. INNER JOIN vwTranSenders sen WITH (NOLOCK) ON rt.id = sen.tranId
  856. INNER JOIN vwTranReceivers rec WITH (NOLOCK) ON rt.id = rec.tranId
  857. WHERE sen.customerId = @SenderId
  858. AND (
  859. rt.approvedDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101)
  860. AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  861. OR (
  862. approvedBy IS NULL
  863. AND cancelApprovedBy IS NULL
  864. )
  865. )
  866. ORDER BY rt.createdDate DESC
  867. IF EXISTS (
  868. SELECT TOP 1 'X'
  869. FROM @remitTranTemp
  870. WHERE cAmt = @collAmt
  871. AND (receiverName = @receiverName)
  872. AND DATEDIFF(MI, dot, GETDATE()) <= 2
  873. )
  874. BEGIN
  875. EXEC proc_errorHandler 16
  876. ,'Similar transaction found. Please perform the transaction after 2 minutes.'
  877. ,NULL;
  878. Rollback Transaction ;
  879. RETURN;
  880. END;
  881. DECLARE @countryRisk INT
  882. ,@OccupationRisk INT
  883. ,@compFinalRes VARCHAR(5)
  884. -- #########country and occupation risk point
  885. DECLARE @deliveryMethod VARCHAR(30)
  886. ,@pBankName VARCHAR(100)
  887. ,@pBankBranchName VARCHAR(100)
  888. ,@pBankRowId BIGINT
  889. SELECT TOP 1 @pCountry = COUNTRYNAME
  890. FROM countryMaster(NOLOCK)
  891. WHERE countryId = @pCountryId
  892. SELECT TOP 1 @deliveryMethod = typeTitle
  893. FROM serviceTypeMaster(NOLOCK)
  894. WHERE serviceTypeId = @deliveryMethodId
  895. SELECT TOP 1 @pBankName = bank_name
  896. ,@pBankRowId = bank_id
  897. FROM api_bank_list
  898. WHERE bank_id = @pBankId
  899. AND is_Active = 1
  900. SELECT TOP 1 @pBankBranchName = branch_name + isnull(BRANCH_CODE1,'')
  901. FROM api_bank_branch_list
  902. WHERE bank_id = @pBankRowId
  903. AND branch_id = @pBranchId
  904. AND is_Active = 1
  905. DECLARE @VNo VARCHAR(20);
  906. IF @pCountry = 'Nepal'
  907. AND @deliveryMethod = 'CASH PAYMENT'
  908. BEGIN
  909. SELECT @pSuperAgent = NULL
  910. ,@pSuperAgentName = NULL
  911. ,@pAgent = NULL
  912. ,@pAgentName = NULL
  913. SELECT @pBankName = '[ANY WHERE]'
  914. END
  915. DECLARE @PayerId INT = NULL
  916. --GET PAYER DETAILS IN CASE OF TF
  917. IF @payOutPartnerId = 394130
  918. AND @deliveryMethod = 'BANK DEPOSIT'
  919. BEGIN
  920. SELECT @PayerId = PayerId
  921. FROM BankPayerSetup(NOLOCK)
  922. WHERE BankId = @pBankId
  923. AND IsDefault = 1
  924. IF @PayerId IS NULL
  925. BEGIN
  926. EXEC proc_errorHandler 17
  927. ,'No default payer mapped for current bank, please contact JME Support!'
  928. ,NULL;
  929. Rollback Transaction ;
  930. RETURN;
  931. END
  932. END
  933. BEGIN TRANSACTION;
  934. IF @PurposeOfRemittanceOther IS NOT NULL
  935. BEGIN
  936. SET @PurposeOfRemittanceOther = 'Other (please specify) :' + @PurposeOfRemittanceOther
  937. END
  938. IF @SourceOfFundOther IS NOT NULL
  939. BEGIN
  940. SET @SourceOfFundOther = 'Other (please specify) :' + @SourceOfFundOther
  941. END
  942. IF (@pBranchId IS NULL OR @pBranchId='0')
  943. BEGIN
  944. select @pBranchId = bankLocation FROM receiverInformation WHERE receiverId = @ReceiverId
  945. IF(ISNULL(@pBranchId,0)=0 and ( @payOutPartnerId='394414' and @deliveryMethod = 'BANK DEPOSIT'))
  946. BEGIN
  947. SET @msg = 'Please update the Routing Branch of receiver [ ' + @receiverName + ' ] before performing transaction!';
  948. EXEC proc_errorHandler 21
  949. ,@msg
  950. ,NULL;
  951. Rollback Transaction ;
  952. RETURN;
  953. END
  954. END
  955. INSERT INTO remitTranTemp (
  956. controlNo
  957. ,sCurrCostRate
  958. ,sCurrHoMargin
  959. ,pCurrCostRate
  960. ,pCurrHoMargin
  961. ,agentCrossSettRate
  962. ,customerRate
  963. ,serviceCharge
  964. ,handlingFee
  965. ,pAgentComm
  966. ,pAgentCommCurrency
  967. ,promotionCode
  968. ,sSuperAgent
  969. ,sSuperAgentName
  970. ,sAgent
  971. ,sAgentName
  972. ,sBranch
  973. ,sBranchName
  974. ,sCountry
  975. ,pSuperAgent
  976. ,pSuperAgentName
  977. ,pAgent
  978. ,pAgentName
  979. ,pCountry
  980. ,paymentMethod
  981. ,pBank
  982. ,pBankName
  983. ,pBankBranch
  984. ,pBankBranchName
  985. ,accountNo
  986. ,collCurr
  987. ,tAmt
  988. ,cAmt
  989. ,pAmt
  990. ,payoutCurr
  991. ,relWithSender
  992. ,purposeOfRemit
  993. ,sourceOfFund
  994. ,tranStatus
  995. ,payStatus
  996. ,createdDate
  997. ,createdDateLocal
  998. ,createdBy
  999. ,tranType
  1000. ,senderName
  1001. ,receiverName
  1002. ,isOnlineTxn
  1003. ,schemeId
  1004. ,pState
  1005. ,pDistrict
  1006. ,sRouteId
  1007. ,schemePremium
  1008. ,collMode
  1009. ,PAYERID
  1010. ,routedBy
  1011. ,rewardPoints
  1012. ,rewardType
  1013. ,isBonusUpdated
  1014. )
  1015. SELECT TOP 1 @controlNoEncrypted
  1016. ,@sCurrCostRate
  1017. ,@sCurrHoMargin
  1018. ,@pCurrCostRate
  1019. ,@pCurrHoMargin
  1020. ,@agentCrossSettRate
  1021. ,@customerRate
  1022. ,@serviceCharge
  1023. ,ISNULL(@scDiscount, 0)
  1024. ,@pAgentComm
  1025. ,@pAgentCommCurrency
  1026. ,NULL
  1027. ,@sSuperAgent
  1028. ,@sSuperAgentName
  1029. ,@sAgent
  1030. ,@sAgentName
  1031. ,@sBranch
  1032. ,@sBranchName
  1033. ,@sCountry
  1034. ,@pSuperAgent
  1035. ,@pSuperAgentName
  1036. ,@pAgent
  1037. ,@pAgentName
  1038. ,@pCountry
  1039. ,@deliveryMethod
  1040. ,@pBankId
  1041. ,@pBankName
  1042. ,@pBranchId
  1043. ,@pBankBranchName
  1044. ,@raccountNo
  1045. ,@collCurr
  1046. ,@iTAmt
  1047. ,@collAmt
  1048. ,@payoutAmt
  1049. ,@payoutCurr
  1050. ,@RelWithSender
  1051. ,ISNULL(@PurposeOfRemittance, @PurposeOfRemittanceOther)
  1052. ,ISNULL(@sourceOfFund, @SourceOfFundOther)
  1053. ,'Hold'
  1054. ,'Unpaid'
  1055. ,GETDATE()
  1056. ,GETUTCDATE()
  1057. ,@user
  1058. ,'M'
  1059. ,@senderName
  1060. ,@receiverName
  1061. ,'Y'
  1062. ,@schemeId
  1063. ,@StateId
  1064. ,@DistrictId
  1065. ,0
  1066. ,ISNULL(@schemePremium, 0)
  1067. ,'Bank Deposit'
  1068. ,@PayerId
  1069. ,CAST(@payOutPartnerId_O AS VARCHAR) + '|' + CAST(@pBankId_O AS VARCHAR)
  1070. ,ISNULL(@discountedFee, 0)
  1071. ,CASE
  1072. WHEN ISNULL(@discountedFee, 0) > 0
  1073. THEN 'REDEEM'
  1074. ELSE NULL
  1075. END
  1076. ,'N'
  1077. SET @tranId = SCOPE_IDENTITY();
  1078. INSERT INTO tranSendersTemp (
  1079. tranId
  1080. ,customerId
  1081. ,membershipId
  1082. ,firstName
  1083. ,middleName
  1084. ,lastName1
  1085. ,lastName2
  1086. ,fullName
  1087. ,country
  1088. ,[address]
  1089. ,STATE
  1090. ,district
  1091. ,address2
  1092. ,zipCode
  1093. ,city
  1094. ,email
  1095. ,homePhone
  1096. ,workPhone
  1097. ,mobile
  1098. ,nativeCountry
  1099. ,dob
  1100. ,placeOfIssue
  1101. ,idType
  1102. ,idNumber
  1103. ,idPlaceOfIssue
  1104. ,issuedDate
  1105. ,validDate
  1106. ,occupation
  1107. ,countryRiskPoint
  1108. ,customerRiskPoint
  1109. ,ipAddress
  1110. ,visaStatus
  1111. )
  1112. SELECT TOP 1 @tranId
  1113. ,@senderId
  1114. ,membershipId
  1115. ,firstName
  1116. ,middleName
  1117. ,lastName1
  1118. ,lastName2
  1119. ,@senderName
  1120. ,sc.countryName
  1121. ,ISNULL(city, '') + ISNULL(', ' + streetUnicode, '')
  1122. ,STATE
  1123. ,streetUnicode
  1124. ,@sAdd2
  1125. ,zipCode
  1126. ,city
  1127. ,email
  1128. ,homePhone
  1129. ,workPhone
  1130. ,LEFT(mobile, 15)
  1131. ,nativeCountry = nc.countryName
  1132. ,dob
  1133. ,c.placeOfIssue
  1134. ,sdv.detailTitle
  1135. ,c.idNumber
  1136. ,c.placeOfIssue
  1137. ,c.idIssueDate
  1138. ,c.idExpiryDate
  1139. ,c.occupation
  1140. ,@countryRisk
  1141. ,(@countryRisk + @OccupationRisk)
  1142. ,@sIpAddress
  1143. ,c.visaStatus
  1144. FROM (
  1145. SELECT TOP 1 *
  1146. FROM dbo.customerMaster c WITH (NOLOCK)
  1147. WHERE c.customerId = @senderId
  1148. ) C
  1149. LEFT JOIN countryMaster sc WITH (NOLOCK) ON c.country = sc.countryId
  1150. LEFT JOIN countryMaster nc WITH (NOLOCK) ON c.nativeCountry = nc.countryId
  1151. LEFT JOIN staticDataValue sdv WITH (NOLOCK) ON c.idType = sdv.valueId
  1152. IF @ReceiverId IS NULL
  1153. BEGIN
  1154. IF NOT EXISTS (
  1155. SELECT TOP 1 'X'
  1156. FROM receiverInformation(NOLOCK)
  1157. WHERE fullName = @receiverName
  1158. AND customerId = @senderId
  1159. )
  1160. BEGIN
  1161. INSERT INTO receiverInformation (
  1162. customerId
  1163. ,firstName
  1164. ,middleName
  1165. ,lastName1
  1166. ,country
  1167. ,address
  1168. ,city
  1169. ,email
  1170. ,homePhone
  1171. ,mobile
  1172. ,relationship
  1173. ,STATE
  1174. ,district
  1175. ,fullName
  1176. ,nativeCountry
  1177. ,goodsOrigin
  1178. ,goodsType
  1179. ,portOfShipment
  1180. ,relationOther
  1181. )
  1182. SELECT @senderId
  1183. ,@rFirstName
  1184. ,@rMiddleName
  1185. ,@rLastName
  1186. ,@pCountry
  1187. ,@rAddress
  1188. ,@rCity
  1189. ,@rEmail
  1190. ,@rMobileNo
  1191. ,@rMobileNo
  1192. ,@RelWithSender
  1193. ,@rStateId
  1194. ,@rDistrictId
  1195. ,@receiverName
  1196. ,@rNativeCountry
  1197. ,@goodsOrigin
  1198. ,@goodsType
  1199. ,@portOfShipment
  1200. ,@RelWithSenderOthers
  1201. SET @ReceiverId = SCOPE_IDENTITY()
  1202. END;
  1203. --ELSE
  1204. -- BEGIN
  1205. -- SELECT TOP 1 @ReceiverId = receiverId
  1206. -- FROM receiverInformation(nolock)
  1207. -- WHERE fullName = @receiverName AND customerId = @senderId;
  1208. --END;
  1209. END;
  1210. INSERT INTO tranReceiversTemp (
  1211. tranId
  1212. ,customerId
  1213. ,firstName
  1214. ,middleName
  1215. ,lastName1
  1216. ,lastName2
  1217. ,fullName
  1218. ,country
  1219. ,[address]
  1220. ,[state]
  1221. ,district
  1222. ,zipCode
  1223. ,city
  1224. ,email
  1225. ,homePhone
  1226. ,workPhone
  1227. ,mobile
  1228. ,nativeCountry
  1229. ,dob
  1230. ,placeOfIssue
  1231. ,idType
  1232. ,idNumber
  1233. ,idPlaceOfIssue
  1234. ,issuedDate
  1235. ,relationType
  1236. ,validDate
  1237. ,gender
  1238. ,goodsOrigin
  1239. ,goodsType
  1240. ,portOfShipment
  1241. )
  1242. SELECT TOP 1 @tranId
  1243. ,@ReceiverId
  1244. ,firstName
  1245. ,middleName
  1246. ,lastName1
  1247. ,lastName2
  1248. ,@receiverName
  1249. ,@pCountry
  1250. ,[address]
  1251. ,[state]
  1252. ,district
  1253. ,zipCode
  1254. ,city
  1255. ,email
  1256. ,homePhone
  1257. ,workPhone
  1258. ,mobile
  1259. ,NULL
  1260. ,@rDob
  1261. ,NULL
  1262. ,ISNULL(@rIdType, idType)
  1263. ,ISNULL(@rIdNo, idNumber)
  1264. ,NULL
  1265. ,@rIdIssue
  1266. ,@RelWithSender
  1267. ,@rIdExpiry
  1268. ,NULL
  1269. ,@goodsOrigin
  1270. ,@goodsType
  1271. ,@portOfShipment
  1272. FROM receiverInformation(NOLOCK)
  1273. WHERE receiverId = @ReceiverId
  1274. /*For duplicate pin check*/
  1275. INSERT INTO controlNoList (
  1276. controlNo
  1277. ,createdby
  1278. )
  1279. SELECT @controlNo
  1280. ,'M'
  1281. ----IF @paymentType = 'WALLET'
  1282. --EXEC proc_UpdateCustomerBalance @controlNo = @controlNoEncrypted, @type = 'DEDUCT'
  1283. ----## map locked ex rate with transaction for history
  1284. UPDATE exRateCalcHistory
  1285. SET controlNo = @controlNoEncrypted
  1286. ,AGENT_TXN_REF_ID = @tranId
  1287. ,isExpired = 1
  1288. WHERE FOREX_SESSION_ID = @forexSessionId
  1289. -- UPDATE FOR CUSTOMER LOYALTY
  1290. -- EXEC PROC_Customer_Loyalty @flag = 'check-eligible' , @isEligible = @isEligible OUT -- CHECKED ABOVE
  1291. EXEC PROC_Customer_LoyaltyV2 @flag = 'update-v2'
  1292. ,@customerId = @senderId
  1293. ,@createdFrom = 'M'
  1294. ,@tranId = @tranId
  1295. ,@createdBy = @user
  1296. ,@controlNo = @controlNo
  1297. ,@isManualSc = 'N'
  1298. ,@referralCode = @introducer
  1299. ,@serviceCharge = @iServiceCharge
  1300. --------------------------#########------------OFAC/COMPLIANCE INSERT (IF EXISTS)---------------########----------------------
  1301. IF EXISTS (
  1302. SELECT TOP 1 'X'
  1303. FROM remitTranComplianceTemp WITH (NOLOCK)
  1304. WHERE agentRefId = @agentRefId
  1305. )
  1306. BEGIN
  1307. INSERT INTO remitTranCompliance (
  1308. TranId
  1309. ,csDetailTranId
  1310. ,matchTranId
  1311. ,reason
  1312. )
  1313. SELECT @tranId
  1314. ,csDetailTranId
  1315. ,matchTranId
  1316. ,reason
  1317. FROM remitTranComplianceTemp WITH (NOLOCK)
  1318. WHERE agentRefId = @agentRefId
  1319. SET @compFinalRes = 'C'
  1320. END
  1321. UPDATE ComplianceLog
  1322. SET TRANID = @tranId
  1323. WHERE agentRefId = @agentRefId
  1324. IF (
  1325. ISNULL(@compFinalRes, '') <> ''
  1326. OR ISNULL(@ofacRes, '') <> ''
  1327. OR ISNULL(@receiverOfacRes, '') <> ''
  1328. )
  1329. BEGIN
  1330. IF (
  1331. (
  1332. ISNULL(@ofacRes, '') <> ''
  1333. OR ISNULL(@receiverOfacRes, '') <> ''
  1334. )
  1335. AND ISNULL(@compFinalRes, '') = ''
  1336. )
  1337. BEGIN
  1338. IF ISNULL(@ofacRes, '') <> ''
  1339. INSERT remitTranOfac (
  1340. TranId
  1341. ,blackListId
  1342. ,reason
  1343. ,flag
  1344. )
  1345. SELECT @tranId
  1346. ,@ofacRes
  1347. ,@ofacReason
  1348. ,dbo.FNAGetOFAC_Flag(@ofacRes)
  1349. IF ISNULL(@receiverOfacRes, '') <> ''
  1350. INSERT remitTranOfac (
  1351. TranId
  1352. ,blackListId
  1353. ,reason
  1354. ,flag
  1355. )
  1356. SELECT @tranId
  1357. ,@receiverOfacRes
  1358. ,@ofacReason
  1359. ,dbo.FNAGetOFAC_Flag(@receiverOfacRes)
  1360. UPDATE remitTranTemp
  1361. SET tranStatus = 'OFAC Hold'
  1362. WHERE id = @tranId
  1363. END
  1364. ELSE IF (
  1365. @compFinalRes <> ''
  1366. AND (
  1367. ISNULL(@ofacRes, '') = ''
  1368. OR ISNULL(@receiverOfacRes, '') = ''
  1369. )
  1370. )
  1371. BEGIN
  1372. UPDATE remitTranTemp
  1373. SET tranStatus = 'Compliance Hold'
  1374. WHERE id = @tranId
  1375. END
  1376. ELSE IF (
  1377. ISNULL(@compFinalRes, '') <> ''
  1378. AND (
  1379. ISNULL(@ofacRes, '') <> ''
  1380. OR ISNULL(@receiverOfacRes, '') <> ''
  1381. )
  1382. )
  1383. BEGIN
  1384. IF ISNULL(@ofacRes, '') <> ''
  1385. INSERT remitTranOfac (
  1386. TranId
  1387. ,blackListId
  1388. ,reason
  1389. ,flag
  1390. )
  1391. SELECT @tranId
  1392. ,@ofacRes
  1393. ,@ofacReason
  1394. ,dbo.FNAGetOFAC_Flag(@ofacRes)
  1395. IF ISNULL(@receiverOfacRes, '') <> ''
  1396. INSERT remitTranOfac (
  1397. TranId
  1398. ,blackListId
  1399. ,reason
  1400. ,flag
  1401. )
  1402. SELECT @tranId
  1403. ,@receiverOfacRes
  1404. ,@ofacReason
  1405. ,dbo.FNAGetOFAC_Flag(@receiverOfacRes)
  1406. UPDATE remitTranTemp
  1407. SET tranStatus = 'OFAC/Compliance Hold'
  1408. WHERE id = @tranId
  1409. END
  1410. END
  1411. --Compliance checking done
  1412. DECLARE @hasSufficientBalance CHAR(1) = 'Y'
  1413. IF @agentAvlLimit < @payoutAmt
  1414. BEGIN
  1415. SET @hasSufficientBalance = 'N'
  1416. INSERT INTO pushNotificationHistroy(customerId,body,title,createDate,imageURL,sentId,Type,isReservation,isRead,isSend,category, isClickable)
  1417. SELECT @SenderId,'Tran ID : '+CAST(@tranId AS VARCHAR)+' . Your transaction has been processed successfully but your balance is insufficient. Please load your wallet.','Insufficent Balance.',getdate(),'',@tranId,0,0,0,0,'INFO', 'Y'
  1418. END
  1419. --New logic for referral
  1420. IF ISNULL(@discountedFee, 0) > 0
  1421. EXEC proc_InsertRewardPoints @Flag = 'DEBIT', @CustomerId = @senderId, @rewardValue = @discountedFee, @TranId = @tranId
  1422. EXEC proc_InsertRewardPoints @Flag = 'TRANSACTION', @CustomerId = @senderId, @TranId = @tranId
  1423. IF @@TRANCOUNT > 0
  1424. COMMIT TRANSACTION;
  1425. SELECT 0 errorCode
  1426. ,'Transaction has been sent successfully' msg
  1427. ,@tranId id
  1428. ,@controlNo extra
  1429. ,ISNULL(@isRealTime, 0) extra2
  1430. ,@hasSufficientBalance extra3
  1431. RETURN
  1432. -- For BroadCast Notification
  1433. --EXEC ProcBroadCastMobile @Flag='TRANSACTION_SUCCESS', @RowId=@customerId, @ControlNo=@controlNo, @CustomerId= @customerId
  1434. END
  1435. END TRY
  1436. BEGIN CATCH
  1437. IF @@TRANCOUNT <> 0
  1438. ROLLBACK TRANSACTION;
  1439. DECLARE @errorMessage VARCHAR(MAX);
  1440. SET @errorMessage = ERROR_MESSAGE();
  1441. EXEC proc_errorHandler 1
  1442. ,@errorMessage
  1443. ,@user;
  1444. END CATCH