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.

1647 lines
79 KiB

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