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.

1781 lines
87 KiB

6 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_SendTransaction] Script Date: 4/2/2024 11:29:50 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 VARCHAR(100) = 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. DECLARE @promoValue INT
  623. IF @requestedBy='online'
  624. BEGIN
  625. IF ISNUMERIC(ISNULL(@discountedFee,0)) = 1
  626. BEGIN
  627. SET @isPromoCode = 'N'
  628. IF ((@discountedFee > '0.00') AND @isPromoCode = 'N')
  629. BEGIN
  630. IF dbo.FNA_GET_AVAILABLE_BALANCE_POINTS(@senderId) < ISNULL(@discountedFee, 0)
  631. BEGIN
  632. EXEC proc_errorHandler 1
  633. ,'You do not have sufficient points for redeem!'
  634. ,NULL
  635. RETURN;
  636. END
  637. END
  638. END
  639. ELSE
  640. BEGIN
  641. SET @isPromoCode = 'Y'
  642. SELECT @promoRowId = promoRowId FROM exRateCalcHistory WHERE FOREX_SESSION_ID = @forexSessionId
  643. SELECT @promoValue = PROMOTION_VALUE, @promoCode = PROMOTIONAL_CODE FROM TBL_PROMOTIONAL_CAMAPAIGN WHERE ROW_ID = @promoRowId
  644. SET @discountedFee = @promoValue
  645. END
  646. END
  647. ELSE
  648. BEGIN
  649. IF ISNUMERIC(ISNULL(@discountedFee,0)) = 1
  650. BEGIN
  651. SELECT @promoRowId = promoRowId FROM exRateCalcHistory WHERE FOREX_SESSION_ID = @forexSessionId;
  652. IF(ISNUMERIC(@promoRowId)=1 AND EXISTS(select 'X' FROM TBL_PROMOTIONAL_CAMAPAIGN WHERE ROW_ID = @promoRowId))
  653. BEGIN
  654. SET @isPromoCode = 'Y'
  655. SELECT @promoValue = PROMOTION_VALUE, @promoCode = PROMOTIONAL_CODE FROM TBL_PROMOTIONAL_CAMAPAIGN WHERE ROW_ID = @promoRowId
  656. SET @discountedFee = @promoValue
  657. END
  658. ELSE
  659. BEGIN
  660. SET @isPromoCode = 'N'
  661. IF ((@discountedFee > '0.00') AND @isPromoCode = 'N')
  662. BEGIN
  663. IF dbo.FNA_GET_AVAILABLE_BALANCE_POINTS(@senderId) < ISNULL(@discountedFee, 0)
  664. BEGIN
  665. EXEC proc_errorHandler 1
  666. ,'You do not have sufficient points for redeem!'
  667. ,NULL
  668. RETURN;
  669. END
  670. END
  671. END
  672. END
  673. END
  674. PRINT '@collAmt';
  675. PRINT @collAmt;
  676. PRINT '@iServiceCharge';
  677. PRINT @iServiceCharge;
  678. PRINT '@discountedFee';
  679. PRINT @discountedFee;
  680. PRINT '@@CustomerRate';
  681. PRINT @CustomerRate;
  682. SELECT @iTAmt = @collAmt - @iServiceCharge + ISNULL(@discountedFee, 0)
  683. SELECT TOP 1 @place = place
  684. ,@currDecimal = currDecimal
  685. FROM currencyPayoutRound(NOLOCK)
  686. WHERE ISNULL(isDeleted, 'N') = 'N'
  687. AND currency = @payoutCurr
  688. AND tranType IS NULL;
  689. SET @currDecimal = ISNULL(@currDecimal, 0)
  690. SET @place = ISNULL(@place, 0)
  691. SET @iPAmt = @iTAmt * @CustomerRate
  692. IF @payoutAmt - @iPAmt <= 1
  693. SET @iPAmt = @payoutAmt
  694. ----## WHILE CALCULATING FROM PAYOUT AMOUNT CONSIDARING 10 VND
  695. IF ISNULL(@iPAmt, 0) <> ISNULL(@payoutAmt, 1)
  696. BEGIN
  697. PRINT @iPAmt;
  698. PRINT @payoutAmt;
  699. --SET @Msg = 'Amount detail not match. Please re-calculate the amount again.' + CAST(@iPAmt AS VARCHAR) + ' - ' + CAST(@payoutAmt AS VARCHAR)
  700. EXEC proc_errorHandler 15
  701. ,'PAmount detail not match. Please re-calculate the amount again.'
  702. ,NULL
  703. RETURN
  704. END
  705. ----OFAC Checking
  706. DECLARE @receiverOfacRes VARCHAR(MAX)
  707. ,@ofacRes VARCHAR(MAX)
  708. ,@ofacReason VARCHAR(200)
  709. EXEC proc_ofacTracker @flag = 't'
  710. ,@name = @senderName
  711. ,@Result = @ofacRes OUTPUT
  712. EXEC proc_ofacTracker @flag = 't'
  713. ,@name = @receiverName
  714. ,@Result = @receiverOfacRes OUTPUT
  715. DECLARE @result VARCHAR(MAX)
  716. IF ISNULL(@ofacRes, '') <> ''
  717. BEGIN
  718. SET @ofacReason = 'Matched by sender name'
  719. END
  720. IF ISNULL(@receiverOfacRes, '') <> ''
  721. BEGIN
  722. SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes)
  723. SET @ofacReason = 'Matched by receiver name'
  724. END
  725. IF ISNULL(@ofacRes, '') <> ''
  726. AND ISNULL(@receiverOfacRes, '') <> ''
  727. BEGIN
  728. SET @ofacReason = 'Matched by both sender name and receiver name'
  729. END
  730. --Ofac Checking End
  731. DECLARE @agentRefId VARCHAR(50) = NEWID()
  732. ----Compliance Checking 1-> Block, 2-> Hold, 3-> Questionnaire
  733. CREATE TABLE #TBL_COMPLIANCE_RESULT (
  734. ERROR_CODE INT
  735. ,MSG VARCHAR(2000)
  736. ,RULE_ID INT
  737. ,SHORT_MSG VARCHAR(1000)
  738. ,[TYPE] VARCHAR(10)
  739. ,IS_D0C_REQUIRED BIT
  740. )
  741. INSERT INTO #TBL_COMPLIANCE_RESULT (
  742. ERROR_CODE
  743. ,MSG
  744. ,RULE_ID
  745. ,SHORT_MSG
  746. ,[TYPE]
  747. ,IS_D0C_REQUIRED
  748. )
  749. EXEC [PROC_COMPLIANCE_CHECKING_NEW] @flag = 'core'
  750. ,@user = @user
  751. ,@sIdType = @sIdType
  752. ,@sIdNo = @sIdNo
  753. ,@receiverName = @receiverName
  754. ,@amount = @iTAmt
  755. ,@customerId = @senderId
  756. ,@pCountryId = @pCountryId
  757. ,@deliveryMethod = @deliveryMethodId
  758. ,@professionId = @OccupationId
  759. ,@receiverMobile = @rMobileNo
  760. ,@accountNo = @raccountNo
  761. ,@receiverId = @receiverId
  762. ,@sNaCountryId = @sNaCountryId
  763. ,@visaStatus = @visaStatusId
  764. IF EXISTS (
  765. SELECT *
  766. FROM #TBL_COMPLIANCE_RESULT
  767. WHERE ERROR_CODE <> 0
  768. )
  769. BEGIN
  770. IF EXISTS (
  771. SELECT *
  772. FROM #TBL_COMPLIANCE_RESULT
  773. WHERE ERROR_CODE IN (1)
  774. ) --transaction blocked
  775. BEGIN
  776. INSERT INTO ComplianceLog (
  777. senderName
  778. ,senderCountry
  779. ,senderIdType
  780. ,senderIdNumber
  781. ,senderMobile
  782. ,receiverName
  783. ,receiverCountry
  784. ,payOutAmt
  785. ,complianceId
  786. ,complianceReason
  787. ,complainceDetailMessage
  788. ,createdBy
  789. ,createdDate
  790. ,agentRefId
  791. ,isDocumentRequired
  792. )
  793. SELECT @senderName
  794. ,@sCountry
  795. ,@sIdType
  796. ,@sIdNo
  797. ,@sMobile
  798. ,@receiverName
  799. ,@pCountry
  800. ,@collAmt
  801. ,RULE_ID
  802. ,SHORT_MSG
  803. ,MSG
  804. ,@user
  805. ,GETDATE()
  806. ,@agentRefId
  807. ,IS_D0C_REQUIRED
  808. FROM #TBL_COMPLIANCE_RESULT
  809. SELECT @MSG = MSG
  810. FROM #TBL_COMPLIANCE_RESULT
  811. WHERE ERROR_CODE IN (1)
  812. --EXEC proc_errorHandler 1, @MSG, NULL
  813. END
  814. IF EXISTS (
  815. SELECT *
  816. FROM #TBL_COMPLIANCE_RESULT
  817. WHERE ERROR_CODE IN (
  818. 2
  819. ,3
  820. )
  821. ) --transaction hold/questionnaire
  822. BEGIN
  823. DELETE
  824. FROM remitTranComplianceTemp
  825. WHERE agentRefId = @agentRefId
  826. INSERT remitTranComplianceTemp (
  827. csDetailTranId
  828. ,matchTranId
  829. ,agentRefId
  830. )
  831. SELECT RULE_ID
  832. ,NULL
  833. ,@agentRefId
  834. FROM #TBL_COMPLIANCE_RESULT
  835. WHERE ERROR_CODE IN (
  836. 2
  837. ,3
  838. )
  839. ORDER BY ISNULL(IS_D0C_REQUIRED, 0) DESC
  840. END
  841. INSERT INTO ComplianceLog (
  842. senderName
  843. ,senderCountry
  844. ,senderIdType
  845. ,senderIdNumber
  846. ,senderMobile
  847. ,receiverName
  848. ,receiverCountry
  849. ,payOutAmt
  850. ,complianceId
  851. ,complianceReason
  852. ,complainceDetailMessage
  853. ,createdBy
  854. ,createdDate
  855. ,agentRefId
  856. ,isDocumentRequired
  857. )
  858. SELECT @senderName
  859. ,@sCountry
  860. ,@sIdType
  861. ,@sIdNo
  862. ,@sMobile
  863. ,@receiverName
  864. ,@pCountry
  865. ,@collAmt
  866. ,RULE_ID
  867. ,SHORT_MSG
  868. ,MSG
  869. ,@user
  870. ,GETDATE()
  871. ,@agentRefId
  872. ,IS_D0C_REQUIRED
  873. FROM #TBL_COMPLIANCE_RESULT
  874. END
  875. ----checking for visa status questionnaire
  876. --IF EXISTS (
  877. -- SELECT *
  878. -- FROM VW_VISA_STATUS_QUESTIONNAIRE
  879. -- WHERE VISA_ID = @visaStatusId
  880. -- )
  881. --BEGIN
  882. -- INSERT INTO ComplianceLog (
  883. -- senderName
  884. -- ,senderCountry
  885. -- ,senderIdType
  886. -- ,senderIdNumber
  887. -- ,senderMobile
  888. -- ,receiverName
  889. -- ,receiverCountry
  890. -- ,payOutAmt
  891. -- ,complianceId
  892. -- ,complianceReason
  893. -- ,complainceDetailMessage
  894. -- ,createdBy
  895. -- ,createdDate
  896. -- ,agentRefId
  897. -- ,isDocumentRequired
  898. -- )
  899. -- SELECT @senderName
  900. -- ,@sCountry
  901. -- ,@sIdType
  902. -- ,@sIdNo
  903. -- ,@sMobile
  904. -- ,@receiverName
  905. -- ,@pCountry
  906. -- ,@collAmt
  907. -- ,0
  908. -- ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  909. -- ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  910. -- ,@user
  911. -- ,GETDATE()
  912. -- ,@agentRefId
  913. -- ,0
  914. -- INSERT remitTranComplianceTemp (
  915. -- csDetailTranId
  916. -- ,matchTranId
  917. -- ,agentRefId
  918. -- ,reason
  919. -- )
  920. -- SELECT 0
  921. -- ,NULL
  922. -- ,@agentRefId
  923. -- ,'Questionnaire require due to Visa Status'
  924. --END
  925. --**********Customer Per Day Limit Checking**********
  926. DECLARE @remitTranTemp TABLE (
  927. tranId BIGINT
  928. ,controlNo VARCHAR(20)
  929. ,cAmt MONEY
  930. ,receiverName VARCHAR(200)
  931. ,receiverIdType VARCHAR(100)
  932. ,receiverIdNumber VARCHAR(50)
  933. ,dot DATETIME
  934. );
  935. --INSERT INTO @remitTranTemp (
  936. -- tranId
  937. -- ,controlNo
  938. -- ,cAmt
  939. -- ,receiverName
  940. -- ,receiverIdType
  941. -- ,receiverIdNumber
  942. -- ,dot
  943. -- )
  944. --SELECT TOP 10 rt.id
  945. -- ,rt.controlNo
  946. -- ,rt.cAmt
  947. -- ,rt.receiverName
  948. -- ,rec.idType
  949. -- ,rec.idNumber
  950. -- ,rt.createdDate
  951. --FROM vwRemitTran rt WITH (NOLOCK)
  952. --INNER JOIN vwTranSenders sen WITH (NOLOCK) ON rt.id = sen.tranId
  953. --INNER JOIN vwTranReceivers rec WITH (NOLOCK) ON rt.id = rec.tranId
  954. --WHERE sen.customerId = @SenderId
  955. -- AND (
  956. -- rt.approvedDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101)
  957. -- AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  958. -- OR (
  959. -- approvedBy IS NULL
  960. -- AND cancelApprovedBy IS NULL
  961. -- )
  962. -- )
  963. --ORDER BY rt.createdDate DESC
  964. --IF EXISTS (
  965. -- SELECT TOP 1 'X'
  966. -- FROM @remitTranTemp
  967. -- WHERE cAmt = @collAmt
  968. -- AND (receiverName = @receiverName)
  969. -- AND DATEDIFF(MI, dot, GETDATE()) <= 2
  970. -- )
  971. --BEGIN
  972. -- EXEC proc_errorHandler 16
  973. -- ,'Similar transaction found. Please perform the transaction after 2 minutes.'
  974. -- ,NULL;
  975. -- Rollback Transaction ;
  976. -- RETURN;
  977. --END;
  978. DECLARE @countryRisk INT
  979. ,@OccupationRisk INT
  980. ,@compFinalRes VARCHAR(5)
  981. -- #########country and occupation risk point
  982. DECLARE @deliveryMethod VARCHAR(30)
  983. ,@pBankName VARCHAR(100)
  984. ,@pBankBranchName VARCHAR(100)
  985. ,@pBankRowId BIGINT
  986. SELECT TOP 1 @pCountry = COUNTRYNAME
  987. FROM countryMaster(NOLOCK)
  988. WHERE countryId = @pCountryId
  989. SELECT TOP 1 @deliveryMethod = typeTitle
  990. FROM serviceTypeMaster(NOLOCK)
  991. WHERE serviceTypeId = @deliveryMethodId
  992. SELECT TOP 1 @pBankName = bank_name
  993. ,@pBankRowId = bank_id
  994. FROM api_bank_list
  995. WHERE bank_id = @pBankId
  996. AND is_Active = 1
  997. PRINT '@pBankId'
  998. PRINT @pBankId
  999. PRINT '@pBankName'
  1000. PRINT @pBankName
  1001. SELECT TOP 1 @pBankBranchName = branch_name + isnull(BRANCH_CODE1,'')
  1002. FROM api_bank_branch_list
  1003. WHERE bank_id = @pBankRowId
  1004. AND branch_id = @pBranchId
  1005. AND is_Active = 1
  1006. DECLARE @VNo VARCHAR(20);
  1007. --IF @pCountry = 'Nepal'
  1008. -- AND @deliveryMethod = 'CASH PAYMENT'
  1009. --BEGIN
  1010. -- SELECT @pSuperAgent = NULL
  1011. -- ,@pSuperAgentName = NULL
  1012. -- ,@pAgent = NULL
  1013. -- ,@pAgentName = NULL
  1014. -- SELECT @pBankName = '[ANY WHERE]'
  1015. --END
  1016. DECLARE @PayerId INT = NULL
  1017. --GET PAYER DETAILS IN CASE OF TF
  1018. IF @payOutPartnerId = 394130
  1019. AND @deliveryMethod = 'BANK DEPOSIT'
  1020. BEGIN
  1021. SELECT @PayerId = PayerId
  1022. FROM BankPayerSetup(NOLOCK)
  1023. WHERE BankId = @pBankId
  1024. AND IsDefault = 1
  1025. IF @PayerId IS NULL
  1026. BEGIN
  1027. EXEC proc_errorHandler 17
  1028. ,'No default payer mapped for current bank, please contact IME London Support!'
  1029. ,NULL;
  1030. Rollback Transaction ;
  1031. RETURN;
  1032. END
  1033. END
  1034. BEGIN TRANSACTION;
  1035. IF @PurposeOfRemittanceOther IS NOT NULL
  1036. BEGIN
  1037. SET @PurposeOfRemittanceOther = 'Other (please specify) :' + @PurposeOfRemittanceOther
  1038. END
  1039. IF @SourceOfFundOther IS NOT NULL
  1040. BEGIN
  1041. SET @SourceOfFundOther = 'Other (please specify) :' + @SourceOfFundOther
  1042. END
  1043. IF (@pBranchId IS NULL OR @pBranchId='0')
  1044. BEGIN
  1045. select @pBranchId = bankLocation FROM receiverInformation WHERE receiverId = @ReceiverId
  1046. IF(ISNULL(@pBranchId,0)=0 and ( @payOutPartnerId='394414' and @deliveryMethod = 'BANK DEPOSIT'))
  1047. BEGIN
  1048. SET @msg = 'Please update the Routing Branch of receiver [ ' + @receiverName + ' ] before performing transaction!';
  1049. EXEC proc_errorHandler 21
  1050. ,@msg
  1051. ,NULL;
  1052. Rollback Transaction ;
  1053. RETURN;
  1054. END
  1055. END
  1056. PRINT 'Aaaaa'
  1057. INSERT INTO remitTranTemp (
  1058. controlNo
  1059. ,sCurrCostRate
  1060. ,sCurrHoMargin
  1061. ,pCurrCostRate
  1062. ,pCurrHoMargin
  1063. ,agentCrossSettRate
  1064. ,customerRate
  1065. ,serviceCharge
  1066. ,handlingFee
  1067. ,pAgentComm
  1068. ,pAgentCommCurrency
  1069. ,promotionCode
  1070. ,sSuperAgent
  1071. ,sSuperAgentName
  1072. ,sAgent
  1073. ,sAgentName
  1074. ,sBranch
  1075. ,sBranchName
  1076. ,sCountry
  1077. ,pSuperAgent
  1078. ,pSuperAgentName
  1079. ,pAgent
  1080. ,pAgentName
  1081. ,pCountry
  1082. ,paymentMethod
  1083. ,pBank
  1084. ,pBankName
  1085. ,pBankBranch
  1086. ,pBankBranchName
  1087. ,accountNo
  1088. ,collCurr
  1089. ,tAmt
  1090. ,cAmt
  1091. ,pAmt
  1092. ,payoutCurr
  1093. ,relWithSender
  1094. ,purposeOfRemit
  1095. ,sourceOfFund
  1096. ,tranStatus
  1097. ,payStatus
  1098. ,createdDate
  1099. ,createdDateLocal
  1100. ,createdBy
  1101. ,tranType
  1102. ,senderName
  1103. ,receiverName
  1104. ,isOnlineTxn
  1105. --,schemeId
  1106. ,pState
  1107. ,pDistrict
  1108. ,sRouteId
  1109. ,schemePremium
  1110. ,collMode
  1111. ,PAYERID
  1112. ,routedBy
  1113. ,rewardPoints
  1114. ,rewardType
  1115. ,isBonusUpdated
  1116. ,depositType
  1117. ,customerPremium
  1118. ,schemeId
  1119. )
  1120. SELECT TOP 1 @controlNoEncrypted
  1121. ,@sCurrCostRate
  1122. ,@sCurrHoMargin
  1123. ,@pCurrCostRate
  1124. ,@pCurrHoMargin
  1125. ,@agentCrossSettRate
  1126. ,@customerRate
  1127. ,@serviceCharge
  1128. ,ISNULL(@scDiscount, 0)
  1129. ,@pAgentComm
  1130. ,@pAgentCommCurrency
  1131. ,NULL
  1132. ,@sSuperAgent
  1133. ,@sSuperAgentName
  1134. ,@sAgent
  1135. ,@sAgentName
  1136. ,@sBranch
  1137. ,@sBranchName
  1138. ,@sCountry
  1139. ,@pSuperAgent
  1140. ,@pSuperAgentName
  1141. ,@pAgent
  1142. ,@pAgentName
  1143. ,@pCountry
  1144. ,@deliveryMethod
  1145. ,@pBankId
  1146. ,@pBankName
  1147. ,@pBranchId
  1148. ,ISNULL(@pBankBranchName,'Headoffice')
  1149. ,@raccountNo
  1150. ,@collCurr
  1151. ,@iTAmt
  1152. ,@collAmt
  1153. ,@payoutAmt
  1154. ,@payoutCurr
  1155. ,@RelWithSender
  1156. ,ISNULL(@PurposeOfRemittance, @PurposeOfRemittanceOther)
  1157. ,ISNULL(@sourceOfFund, @SourceOfFundOther)
  1158. ,'Hold'
  1159. ,'Unpaid'
  1160. ,GETDATE()
  1161. ,GETUTCDATE()
  1162. ,@user
  1163. ,'M'
  1164. ,@senderName
  1165. ,@receiverName
  1166. ,CASE WHEN @requestedBy='online' THEN 'O' WHEN @requestedBy='mobile' THEN 'M' ELSE 'N' END
  1167. --,0
  1168. ,@StateId
  1169. ,@DistrictId
  1170. ,0
  1171. ,ISNULL(@schemePremium, 0)
  1172. ,'Bank Deposit'
  1173. ,@PayerId
  1174. ,CAST(@payOutPartnerId_O AS VARCHAR) + '|' + CAST(@pBankId_O AS VARCHAR)
  1175. ,ISNULL(@discountedFee, 0)
  1176. --,CASE
  1177. -- WHEN ISNULL(@discountedFee, 0) > 0
  1178. -- THEN 'REDEEM'
  1179. -- ELSE NULL
  1180. -- END
  1181. ,CASE
  1182. WHEN (ISNULL(@discountedFee, 0) > 0 AND @isPromoCode = 'Y')
  1183. THEN ISNULL(@promoCode,'PROMOCODE')
  1184. WHEN (ISNULL(@discountedFee, 0) > 0 AND @isPromoCode = 'N')
  1185. THEN 'REDEEM'
  1186. ELSE NULL
  1187. END
  1188. ,'N'
  1189. ,@schemeId
  1190. ,@customerPremium
  1191. ,@promoRowId
  1192. --RETURN
  1193. PRINT '@tranId'
  1194. SET @tranId = SCOPE_IDENTITY();
  1195. PRINT '@tranId'
  1196. INSERT INTO tranSendersTemp (
  1197. tranId
  1198. ,customerId
  1199. ,membershipId
  1200. ,firstName
  1201. ,middleName
  1202. ,lastName1
  1203. ,lastName2
  1204. ,fullName
  1205. ,country
  1206. ,[address]
  1207. ,STATE
  1208. ,district
  1209. ,address2
  1210. ,zipCode
  1211. ,city
  1212. ,email
  1213. ,homePhone
  1214. ,workPhone
  1215. ,mobile
  1216. ,nativeCountry
  1217. ,dob
  1218. ,placeOfIssue
  1219. ,idType
  1220. ,idNumber
  1221. ,idPlaceOfIssue
  1222. ,issuedDate
  1223. ,validDate
  1224. ,occupation
  1225. ,countryRiskPoint
  1226. ,customerRiskPoint
  1227. ,ipAddress
  1228. ,visaStatus
  1229. )
  1230. SELECT TOP 1 @tranId
  1231. ,@senderId
  1232. ,membershipId
  1233. ,firstName
  1234. ,middleName
  1235. ,lastName1
  1236. ,lastName2
  1237. ,@senderName
  1238. ,sc.countryName
  1239. ,ISNULL(city, '') + ISNULL(', ' + streetUnicode, '')
  1240. ,STATE
  1241. ,streetUnicode
  1242. ,@sAdd2
  1243. ,zipCode
  1244. ,city
  1245. ,email
  1246. ,homePhone
  1247. ,workPhone
  1248. ,LEFT(mobile, 15)
  1249. ,nativeCountry = nc.countryName
  1250. ,dob
  1251. ,c.placeOfIssue
  1252. ,sdv.detailTitle
  1253. ,c.idNumber
  1254. ,c.placeOfIssue
  1255. ,c.idIssueDate
  1256. ,c.idExpiryDate
  1257. ,c.occupation
  1258. ,@countryRisk
  1259. ,(@countryRisk + @OccupationRisk)
  1260. ,@sIpAddress
  1261. ,c.visaStatus
  1262. FROM (
  1263. SELECT TOP 1 *
  1264. FROM dbo.customerMaster c WITH (NOLOCK)
  1265. WHERE c.customerId = @senderId
  1266. ) C
  1267. LEFT JOIN countryMaster sc WITH (NOLOCK) ON c.country = sc.countryId
  1268. LEFT JOIN countryMaster nc WITH (NOLOCK) ON c.nativeCountry = nc.countryId
  1269. LEFT JOIN staticDataValue sdv WITH (NOLOCK) ON c.idType = sdv.valueId
  1270. IF @ReceiverId IS NULL
  1271. BEGIN
  1272. IF NOT EXISTS (
  1273. SELECT TOP 1 'X'
  1274. FROM receiverInformation(NOLOCK)
  1275. WHERE fullName = @receiverName
  1276. AND customerId = @senderId
  1277. )
  1278. BEGIN
  1279. INSERT INTO receiverInformation (
  1280. customerId
  1281. ,firstName
  1282. ,middleName
  1283. ,lastName1
  1284. ,country
  1285. ,address
  1286. ,city
  1287. ,email
  1288. ,homePhone
  1289. ,mobile
  1290. ,relationship
  1291. ,STATE
  1292. ,district
  1293. ,fullName
  1294. ,nativeCountry
  1295. ,goodsOrigin
  1296. ,goodsType
  1297. ,portOfShipment
  1298. ,relationOther
  1299. )
  1300. SELECT @senderId
  1301. ,@rFirstName
  1302. ,@rMiddleName
  1303. ,@rLastName
  1304. ,@pCountry
  1305. ,@rAddress
  1306. ,@rCity
  1307. ,@rEmail
  1308. ,@rMobileNo
  1309. ,@rMobileNo
  1310. ,@RelWithSender
  1311. ,@rStateId
  1312. ,@rDistrictId
  1313. ,@receiverName
  1314. ,@rNativeCountry
  1315. ,@goodsOrigin
  1316. ,@goodsType
  1317. ,@portOfShipment
  1318. ,@RelWithSenderOthers
  1319. SET @ReceiverId = SCOPE_IDENTITY()
  1320. END;
  1321. --ELSE
  1322. -- BEGIN
  1323. -- SELECT TOP 1 @ReceiverId = receiverId
  1324. -- FROM receiverInformation(nolock)
  1325. -- WHERE fullName = @receiverName AND customerId = @senderId;
  1326. --END;
  1327. END;
  1328. INSERT INTO tranReceiversTemp (
  1329. tranId
  1330. ,customerId
  1331. ,firstName
  1332. ,middleName
  1333. ,lastName1
  1334. ,lastName2
  1335. ,fullName
  1336. ,country
  1337. ,[address]
  1338. ,[state]
  1339. ,district
  1340. ,zipCode
  1341. ,city
  1342. ,email
  1343. ,homePhone
  1344. ,workPhone
  1345. ,mobile
  1346. ,nativeCountry
  1347. ,dob
  1348. ,placeOfIssue
  1349. ,idType
  1350. ,idNumber
  1351. ,idPlaceOfIssue
  1352. ,issuedDate
  1353. ,relationType
  1354. ,validDate
  1355. ,gender
  1356. ,goodsOrigin
  1357. ,goodsType
  1358. ,portOfShipment
  1359. )
  1360. SELECT TOP 1 @tranId
  1361. ,@ReceiverId
  1362. ,firstName
  1363. ,middleName
  1364. ,lastName1
  1365. ,lastName2
  1366. ,@receiverName
  1367. ,@pCountry
  1368. ,[address]
  1369. ,[state]
  1370. ,district
  1371. ,zipCode
  1372. ,city
  1373. ,email
  1374. ,homePhone
  1375. ,workPhone
  1376. ,mobile
  1377. ,NULL
  1378. ,@rDob
  1379. ,NULL
  1380. ,ISNULL(@rIdType, idType)
  1381. ,ISNULL(@rIdNo, idNumber)
  1382. ,NULL
  1383. ,@rIdIssue
  1384. ,@RelWithSender
  1385. ,@rIdExpiry
  1386. ,NULL
  1387. ,@goodsOrigin
  1388. ,@goodsType
  1389. ,@portOfShipment
  1390. FROM receiverInformation(NOLOCK)
  1391. WHERE receiverId = @ReceiverId
  1392. /*For duplicate pin check*/
  1393. INSERT INTO controlNoList (
  1394. controlNo
  1395. ,createdby
  1396. )
  1397. SELECT @controlNo
  1398. ,'M'
  1399. ----IF @paymentType = 'WALLET'
  1400. --EXEC proc_UpdateCustomerBalance @controlNo = @controlNoEncrypted, @type = 'DEDUCT'
  1401. ----## map locked ex rate with transaction for history
  1402. UPDATE exRateCalcHistory
  1403. SET controlNo = @controlNoEncrypted
  1404. ,AGENT_TXN_REF_ID = @tranId
  1405. ,isExpired = 1
  1406. WHERE FOREX_SESSION_ID = @forexSessionId
  1407. -- UPDATE FOR CUSTOMER LOYALTY
  1408. -- EXEC PROC_Customer_Loyalty @flag = 'check-eligible' , @isEligible = @isEligible OUT -- CHECKED ABOVE
  1409. --EXEC PROC_Customer_LoyaltyV2 @flag = 'update-v2'
  1410. -- ,@customerId = @senderId
  1411. -- ,@createdFrom = 'M'
  1412. -- ,@tranId = @tranId
  1413. -- ,@createdBy = @user
  1414. -- ,@controlNo = @controlNo
  1415. -- ,@isManualSc = 'N'
  1416. -- ,@referralCode = @introducer
  1417. -- ,@serviceCharge = @iServiceCharge
  1418. --------------------------#########------------OFAC/COMPLIANCE INSERT (IF EXISTS)---------------########----------------------
  1419. IF EXISTS (
  1420. SELECT TOP 1 'X'
  1421. FROM remitTranComplianceTemp WITH (NOLOCK)
  1422. WHERE agentRefId = @agentRefId
  1423. )
  1424. BEGIN
  1425. INSERT INTO remitTranCompliance (
  1426. TranId
  1427. ,csDetailTranId
  1428. ,matchTranId
  1429. ,reason
  1430. )
  1431. SELECT @tranId
  1432. ,csDetailTranId
  1433. ,matchTranId
  1434. ,reason
  1435. FROM remitTranComplianceTemp WITH (NOLOCK)
  1436. WHERE agentRefId = @agentRefId
  1437. SET @compFinalRes = 'C'
  1438. END
  1439. PRINT 'Aa'
  1440. UPDATE ComplianceLog
  1441. SET TRANID = @tranId
  1442. WHERE agentRefId = @agentRefId
  1443. IF (
  1444. ISNULL(@compFinalRes, '') <> ''
  1445. OR ISNULL(@ofacRes, '') <> ''
  1446. OR ISNULL(@receiverOfacRes, '') <> ''
  1447. )
  1448. BEGIN
  1449. IF (
  1450. (
  1451. ISNULL(@ofacRes, '') <> ''
  1452. OR ISNULL(@receiverOfacRes, '') <> ''
  1453. )
  1454. AND ISNULL(@compFinalRes, '') = ''
  1455. )
  1456. BEGIN
  1457. IF ISNULL(@ofacRes, '') <> ''
  1458. INSERT remitTranOfac (
  1459. TranId
  1460. ,blackListId
  1461. ,reason
  1462. ,flag
  1463. )
  1464. SELECT @tranId
  1465. ,@ofacRes
  1466. ,@ofacReason
  1467. ,dbo.FNAGetOFAC_Flag(@ofacRes)
  1468. IF ISNULL(@receiverOfacRes, '') <> ''
  1469. INSERT remitTranOfac (
  1470. TranId
  1471. ,blackListId
  1472. ,reason
  1473. ,flag
  1474. )
  1475. SELECT @tranId
  1476. ,@receiverOfacRes
  1477. ,@ofacReason
  1478. ,dbo.FNAGetOFAC_Flag(@receiverOfacRes)
  1479. UPDATE remitTranTemp
  1480. SET tranStatus = 'OFAC Hold'
  1481. WHERE id = @tranId
  1482. END
  1483. ELSE IF (
  1484. @compFinalRes <> ''
  1485. AND (
  1486. ISNULL(@ofacRes, '') = ''
  1487. OR ISNULL(@receiverOfacRes, '') = ''
  1488. )
  1489. )
  1490. BEGIN
  1491. UPDATE remitTranTemp
  1492. SET tranStatus = 'Compliance Hold'
  1493. WHERE id = @tranId
  1494. END
  1495. ELSE IF (
  1496. ISNULL(@compFinalRes, '') <> ''
  1497. AND (
  1498. ISNULL(@ofacRes, '') <> ''
  1499. OR ISNULL(@receiverOfacRes, '') <> ''
  1500. )
  1501. )
  1502. BEGIN
  1503. IF ISNULL(@ofacRes, '') <> ''
  1504. INSERT remitTranOfac (
  1505. TranId
  1506. ,blackListId
  1507. ,reason
  1508. ,flag
  1509. )
  1510. SELECT @tranId
  1511. ,@ofacRes
  1512. ,@ofacReason
  1513. ,dbo.FNAGetOFAC_Flag(@ofacRes)
  1514. IF ISNULL(@receiverOfacRes, '') <> ''
  1515. INSERT remitTranOfac (
  1516. TranId
  1517. ,blackListId
  1518. ,reason
  1519. ,flag
  1520. )
  1521. SELECT @tranId
  1522. ,@receiverOfacRes
  1523. ,@ofacReason
  1524. ,dbo.FNAGetOFAC_Flag(@receiverOfacRes)
  1525. UPDATE remitTranTemp
  1526. SET tranStatus = 'OFAC/Compliance Hold'
  1527. WHERE id = @tranId
  1528. END
  1529. END
  1530. --Compliance checking done
  1531. DECLARE @hasSufficientBalance CHAR(1) = 'Y'
  1532. --IF @agentAvlLimit < @payoutAmt
  1533. --BEGIN
  1534. --SET @hasSufficientBalance = 'N'
  1535. --INSERT INTO pushNotificationHistroy(customerId,body,title,createDate,imageURL,sentId,Type,isReservation,isRead,isSend,category, isClickable)
  1536. --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'
  1537. --END
  1538. PRINT 'A'
  1539. IF @schemeId='ONLINE'
  1540. BEGIN
  1541. SET @hasSufficientBalance='N';
  1542. END
  1543. ELSE
  1544. BEGIN
  1545. DECLARE @NewId uniqueidentifier
  1546. SET @NewId = NEWID()
  1547. INSERT INTO TRU_TranDetail
  1548. (
  1549. refId,
  1550. email,
  1551. createddate,
  1552. orderreference,
  1553. sitereference,
  1554. Tranid,
  1555. customerid,
  1556. token,
  1557. recordStatus
  1558. )
  1559. VALUES
  1560. (
  1561. @NewId,
  1562. @user
  1563. ,GETDATE()
  1564. ,@controlNo
  1565. ,@sitereference
  1566. ,@tranid
  1567. ,@senderId
  1568. ,@token
  1569. ,'DRAFT'
  1570. )
  1571. END
  1572. --New logic for referral
  1573. IF (ISNULL(@discountedFee, 0) > 0 AND @isPromoCode = 'N')
  1574. EXEC proc_InsertRewardPoints @Flag = 'DEBIT', @CustomerId = @senderId, @rewardPoints = @discountedFee, @TranId = @tranId
  1575. --EXEC proc_InsertRewardPoints @Flag = 'TRANSACTION', @CustomerId = @senderId, @TranId = @tranId
  1576. IF @@TRANCOUNT > 0
  1577. COMMIT TRANSACTION;
  1578. SELECT 0 errorCode
  1579. ,'Transaction has been sent successfully' msg
  1580. ,@tranId id
  1581. ,@controlNo extra
  1582. ,ISNULL(@schemeId, 0) extra1
  1583. ,@hasSufficientBalance extra3
  1584. ,@NewId extra4
  1585. RETURN
  1586. -- For BroadCast Notification
  1587. --EXEC ProcBroadCastMobile @Flag='TRANSACTION_SUCCESS', @RowId=@customerId, @ControlNo=@controlNo, @CustomerId= @customerId
  1588. END
  1589. END TRY
  1590. BEGIN CATCH
  1591. IF @@TRANCOUNT <> 0
  1592. ROLLBACK TRANSACTION;
  1593. DECLARE @errorMessage VARCHAR(MAX);
  1594. SET @errorMessage = ERROR_MESSAGE();
  1595. EXEC proc_errorHandler 1
  1596. ,@errorMessage
  1597. ,@user;
  1598. END CATCH