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.

1855 lines
43 KiB

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