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.

1732 lines
84 KiB

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