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.

1715 lines
83 KiB

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