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.

1875 lines
90 KiB

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