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.

1464 lines
51 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendIRH] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_sendIRH]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_sendIRH] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. CREATE PROC [dbo].[proc_sendIRH] (
  12. @flag VARCHAR(50)
  13. ,@user VARCHAR(30)
  14. ,@txnPWD VARCHAR(100) = NULL
  15. ,@agentRefId VARCHAR(20) = NULL
  16. ,@senderId VARCHAR(50) = NULL
  17. ,@sfName VARCHAR(100) = NULL
  18. ,@smName VARCHAR(100) = NULL
  19. ,@slName VARCHAR(100) = NULL
  20. ,@slName2 VARCHAR(100) = NULL
  21. ,@sIdType VARCHAR(100) = NULL
  22. ,@sIdNo VARCHAR(50) = NULL
  23. ,@sIdValid DATETIME = NULL
  24. ,@sdob DATETIME = NULL
  25. ,@sTel VARCHar(20) = NULL
  26. ,@sMobile varchar(20) = NULL
  27. ,@sNaCountry VARCHAR(50) = NULL
  28. ,@scity VARCHAR(100) = NULL
  29. ,@sPostCode VARCHAR(50) = NULL
  30. ,@sAdd1 VARCHAR(150) = NULL
  31. ,@sAdd2 VARCHAR(150) = NULL
  32. ,@sEmail VARCHAR(100) = NULL
  33. ,@sgender VARCHAR(100) = NULL
  34. ,@smsSend CHAR(1) = NULL
  35. ,@sCompany VARCHAR(100) = NULL
  36. ,@sDcInfo VARCHAR(50) = NULL
  37. ,@sIpAddress VARCHAR(50) = NULL
  38. ,@benId VARCHAR(50) = NULL
  39. ,@rfName VARCHAR(100) = NULL
  40. ,@rmName VARCHAR(100) = NULL
  41. ,@rlName VARCHAR(100) = NULL
  42. ,@rlName2 VARCHAR(100) = NULL
  43. ,@rIdType VARCHAR(100) = NULL
  44. ,@rIdNo VARCHAR(50) = NULL
  45. ,@rIdValid DATETIME = NULL
  46. ,@rdob DATETIME = NULL
  47. ,@rTel VARCHar(20) = NULL
  48. ,@rMobile varchar(20) = NULL
  49. ,@rNaCountry VARCHAR(50) = NULL
  50. ,@rcity VARCHAR(100) = NULL
  51. ,@rPostCode VARCHAR(50) = NULL
  52. ,@rAdd1 VARCHAR(150) = NULL
  53. ,@rAdd2 VARCHAR(150) = NULL
  54. ,@rEmail VARCHAR(100) = NULL
  55. ,@raccountNo VARCHAR(50) = NULL
  56. ,@rgender VARCHAR(100) = NULL
  57. ,@salaryRange VARCHAR(150) = NULL
  58. ,@pCountry VARCHAR(50) = NULL -- pay country
  59. ,@pCountryId INT = NULL -- PAY COUNTRY ID
  60. ,@pSuperAgent INT = NULL --payout Super Agent
  61. ,@deliveryMethod VARCHAR(50) = NULL -- payment mode
  62. ,@deliveryMethodId INT = NULL -- payment mode ID
  63. ,@pBank INT = NULL
  64. ,@pBankName VARCHAR(100) = NULL
  65. ,@pBankBranch INT = NULL
  66. ,@pBankBranchName VARCHAR(100) = NULL
  67. ,@pAgent INT = NULL
  68. ,@pAgentName VARCHAR(100) = NULL
  69. ,@pBranch INT = NULL
  70. ,@pBranchName VARCHAR(100) = NULL
  71. ,@pBankType CHAR(1) = NULL
  72. ,@pCurr VARCHAR(3) = NULL
  73. ,@collCurr VARCHAR(3) = NULL
  74. ,@cAmt MONEY = NULL
  75. ,@pAmt MONEY = NULL
  76. ,@tAmt MONEY = NULL
  77. ,@serviceCharge MONEY = NULL
  78. ,@discount MONEY = NULL
  79. ,@exRate FLOAT = NULL
  80. ,@schemeType VARCHAR(50) = NULL
  81. ,@couponTranNo VARCHAR(20) = NULL
  82. ,@purpose VARCHAR(150) = NULL
  83. ,@sourceOfFund VARCHAR(150) = NULL
  84. ,@relationship VARCHAR(100) = NULL
  85. ,@occupation VARCHAR(100) = NULL
  86. ,@payMsg VARCHAR(1000) = NULL
  87. ,@company VARCHAR(200) = NULL
  88. ,@nCust CHAR(1) = NULL
  89. ,@enrollCust CHAR(1) = NULL
  90. ,@controlNo VARCHAR(20) = NULL
  91. ,@agentId INT = NULL --payout
  92. ,@sCountryId INT = NULL
  93. ,@sCountry VARCHAR(100) = NULL
  94. ,@sBranch INT = NULL
  95. ,@sBranchName VARCHAR(100) = NULL
  96. ,@sAgent INT = NULL
  97. ,@sAgentName VARCHAR(100) = NULL
  98. ,@sSuperAgent INT = NULL
  99. ,@sSuperAgentName VARCHAR(100) = NULL
  100. ,@settlingAgent INT = NULL
  101. ,@branchMapCode VARCHAR(10) = NULL
  102. ,@agentMapCode VARCHAR(10) = NULL
  103. ,@collMode VARCHAR(50) = NULL
  104. ,@id BIGINT = NULL
  105. ,@sessionId VARCHAR(50) = NULL
  106. ,@cancelrequestId INT = NULL
  107. ,@salary VARCHAR(10) = NULL
  108. ,@memberCode VARCHAR(20) = NULL
  109. ,@schemeCode VARCHAR(20) = NULL
  110. ,@cwPwd VARCHAR(10) = NULL
  111. ,@ttName VARCHAR(200) = NULL
  112. ,@ofacRes VARCHAR(MAX) = NULL
  113. ,@ofacReason VARCHAR(200) = NULL
  114. ,@voucherDetails XML = NULL
  115. ,@RBATxnRisk VARCHAR(15) = NULL
  116. ,@RBACustomerRisk VARCHAR(15) = NULL
  117. ,@RBACustomerRiskValue MONEY = NULL
  118. ,@pLocation BIGINT = NULL
  119. ,@pLocationText VARCHAR(100)= NULL
  120. ,@pSubLocation BIGINT = NULL
  121. ,@pSubLocationText VARCHAR(100)= NULL
  122. )
  123. AS
  124. SET NOCOUNT ON;
  125. SET XACT_ABORT ON;
  126. BEGIN TRY
  127. BEGIN
  128. DECLARE
  129. @sCurrCostRate FLOAT
  130. ,@sCurrHoMargin FLOAT
  131. ,@pCurrCostRate FLOAT
  132. ,@pCurrHoMargin FLOAT
  133. ,@sCurrAgentMargin FLOAT
  134. ,@pCurrAgentMargin FLOAT
  135. ,@sCurrSuperAgentMargin FLOAT
  136. ,@pCurrSuperAgentMargin FLOAT
  137. ,@customerRate FLOAT
  138. ,@sAgentSettRate FLOAT
  139. ,@pDateCostRate FLOAT
  140. ,@agentCrossSettRate FLOAT
  141. ,@treasuryTolerance FLOAT
  142. ,@customerPremium FLOAT
  143. ,@schemePremium FLOAT
  144. ,@sharingValue MONEY
  145. ,@sharingType CHAR(1)
  146. ,@sAgentComm MONEY
  147. ,@sAgentCommCurrency VARCHAR(3)
  148. ,@sSuperAgentComm MONEY
  149. ,@sSuperAgentCommCurrency VARCHAR(3)
  150. ,@pAgentComm MONEY
  151. ,@pAgentCommCurrency VARCHAR(3)
  152. ,@pSuperAgentComm MONEY
  153. ,@pSuperAgentCommCurrency VARCHAR(3)
  154. ,@promotionCode INT
  155. ,@promotionType INT
  156. ,@pSuperAgentName VARCHAR(100)
  157. ,@pStateId INT
  158. ,@agentType INT
  159. ,@senderName VARCHAR(100)
  160. ,@pAgentMapCode VARCHAR(10)
  161. ,@pBranchMapCode VARCHAR(10)
  162. ,@F_ANYWHERE CHAR(1)
  163. ,@TRN_TYPE VARCHAR(100)
  164. ,@complienceMessage VARCHAR(500)
  165. ,@complienceErrorCode TINYINT
  166. ,@shortMsg VARCHAR(100)
  167. DECLARE
  168. @xAmt MONEY
  169. ,@baseCurrency VARCHAR(3)
  170. ,@limitBal MONEY
  171. ,@sendingCustType INT
  172. ,@receivingCustType INT
  173. ,@msg VARCHAR(200)
  174. DECLARE @iServiceCharge MONEY, @iTAmt MONEY, @iPAmt MONEY, @iScDiscount MONEY, @iCustomerRate FLOAT, @iCollDetailAmt MONEY
  175. DECLARE @place INT, @currDecimal INT
  176. DECLARE @cisMasterId INT, @compIdResult VARCHAR(300),@perDayCustomerLimit money
  177. DECLARE @controlNoEncrypted VARCHAR(20)
  178. DECLARE @csMasterId INT, @complianceRes VARCHAR(20), @totalRows INT, @count INT, @compFinalRes VARCHAR(20)
  179. DECLARE @csMasterRec TABLE (rowId INT IDENTITY(1,1), masterId INT)
  180. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  181. DECLARE @customerTotalAmt2 MONEY = 0
  182. DECLARE @errorCode CHAR(1) = 0
  183. DECLARE
  184. @tellerBalance MONEY
  185. ,@tellerLimit MONEY
  186. ,@sendPerTransaction MONEY
  187. ,@vaultBalance MONEY
  188. ,@vaultLimit MONEY
  189. IF @salary = 'undefined'
  190. set @salary = null
  191. IF @salaryRange = 'undefined'
  192. set @salaryRange = null
  193. if @pBankBranchName in ('Select','undefined')
  194. set @pBankBranchName = 'Any Branch'
  195. IF @senderId IS NOT NULL
  196. SELECT @senderId = customerId FROM customerMaster WITH(NOLOCK) WHERE idNumber = @senderId
  197. SET @sAgentCommCurrency = 'KRW'
  198. IF @flag = 'acBal' --Get Available Account Balance
  199. BEGIN
  200. SELECT
  201. @pCountryId = am.agentCountryId
  202. FROM applicationUsers au WITH(NOLOCK)
  203. INNER JOIN agentMaster am WITH(NOLOCK) ON au.agentId = am.agentId
  204. WHERE userName = @user
  205. SELECT TOP 1 @collCurr = CM.currencyCode
  206. FROM currencyMaster CM WITH(NOLOCK)
  207. INNER JOIN countryCurrency CC WITH(NOLOCK) ON CM.currencyId = CC.currencyId
  208. WHERE CC.countryId = @pCountryId AND ISNULL(cc.isDeleted,'N') = 'N'
  209. -->> checking per day country send limit
  210. SELECT
  211. @limitBal = D.amount
  212. FROM csMaster M WITH (NOLOCK)
  213. INNER JOIN csDetail D WITH(NOLOCK) ON M.csMasterId = D.csDetailId
  214. WHERE sCountry = @pCountryId
  215. AND ISNULL(M.isActive,'Y') = 'Y' AND ISNULL(D.isActive,'Y')='Y'
  216. IF @agentId IS NULL
  217. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  218. ELSE
  219. SELECT @sBranch = @agentId
  220. SELECT @sAgent = parentId, @agentType = agentType FROM agentMaster WITH(NOLOCK)
  221. WHERE agentId = @sBranch
  222. IF @agentType = 2903
  223. SET @sAgent = @sBranch
  224. SELECT @sSuperAgent = parentId FROM agentMaster WITH(NOLOCK)
  225. WHERE agentId = @sAgent
  226. SELECT @settlingAgent = agentId FROM agentMaster
  227. WHERE agentId = @sBranch AND isSettlingAgent = 'Y'
  228. IF @settlingAgent IS NULL
  229. SELECT @settlingAgent = agentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent AND isSettlingAgent = 'Y'
  230. IF @settlingAgent IS NULL
  231. SELECT @settlingAgent = agentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sSuperAgent AND isSettlingAgent = 'Y'
  232. DECLARE @limit MONEY, @limitCurr VARCHAR(3), @cRateAgent FLOAT
  233. SELECT @limit = ISNULL(dbo.FNAGetLimitBalIRH(@settlingAgent), 0)
  234. SELECT @limitCurr = currency FROM creditLimitInt WITH(NOLOCK)
  235. WHERE agentId = @settlingAgent AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y'
  236. SELECT
  237. availableBal = @limit
  238. ,balCurrency = @collCurr
  239. ,limExpiry = ISNULL(CONVERT(VARCHAR, expiryDate, 101), 'N/A')
  240. ,sCountryLimit = ISNULL(@limitBal,0)
  241. ,sCurr = @collCurr
  242. ,tellerBanalce = 0
  243. ,txnPerDayCustomerLimit = dbo.FNAGetPerDayCustomerLimit(@settlingAgent)
  244. FROM creditLimitInt cl
  245. WHERE agentId = @settlingAgent
  246. END
  247. ELSE IF @flag = 'v' --Validation
  248. BEGIN
  249. IF @nCust='N'
  250. BEGIN
  251. IF ISNULL(@senderId, 0) = 0
  252. BEGIN
  253. EXEC proc_errorHandler 1, 'Please choose Sender', NULL
  254. RETURN
  255. END
  256. END
  257. IF @sfName IS NULL
  258. BEGIN
  259. EXEC proc_errorHandler 1, 'Sender First Name missing', NULL
  260. RETURN
  261. END
  262. IF @sNaCountry IS NULL
  263. BEGIN
  264. EXEC proc_errorHandler 1, ' Sender Native Country missing', NULL
  265. RETURN
  266. END
  267. IF @rfName IS NULL
  268. BEGIN
  269. EXEC proc_errorHandler 1, 'New Receiver First Name missing', NULL
  270. RETURN
  271. END
  272. IF @sIdType = 'Alien Registration Card'
  273. BEGIN
  274. IF LEN(@sIdNo) <> 14 OR @sIdNo NOT LIKE '%-%'
  275. BEGIN
  276. EXEC proc_errorHandler 1, 'Invalid Alian Card number found', NULL
  277. RETURN
  278. END
  279. END
  280. IF ISNULL(@deliveryMethod, '') = ''
  281. BEGIN
  282. EXEC proc_errorHandler 1, 'Please choose payment mode', NULL
  283. RETURN
  284. END
  285. IF @serviceCharge IS NULL
  286. BEGIN
  287. EXEC proc_errorHandler 1, 'Service Charge missing', NULL
  288. RETURN
  289. END
  290. IF ISNULL(@tAmt, 0) = 0
  291. BEGIN
  292. EXEC proc_errorHandler 1, 'Transfer Amount missing', NULL
  293. RETURN
  294. END
  295. IF ISNULL(@exRate, 0) = 0
  296. BEGIN
  297. EXEC proc_errorHandler 1, 'Exchange Rate missing', NULL
  298. RETURN
  299. END
  300. IF ISNULL(@cAmt, 0) = 0
  301. BEGIN
  302. EXEC proc_errorHandler 1, 'Collection Amount is missing. Cannot send transaction', NULL
  303. RETURN
  304. END
  305. IF @serviceCharge > @cAmt
  306. BEGIN
  307. EXEC proc_errorHandler 1, 'Collection Amount is less than service charge.', NULL
  308. RETURN
  309. END
  310. --IF @occupation IS NULL
  311. --BEGIN
  312. -- EXEC proc_errorHandler 1, 'Occupation is missing', NULL
  313. -- RETURN
  314. --END
  315. --*****Payout Agent*****
  316. IF @deliveryMethod = 'Cash Payment'
  317. BEGIN
  318. IF @pBank IS NOT NULL
  319. BEGIN
  320. SELECT @pAgent = @pBank, @pAgentName = @pBankName
  321. IF @pBankBranch IS NOT NULL
  322. SELECT @pBranch = @pBankBranch, @pBranchName = @pBankBranchName
  323. END
  324. END
  325. ELSE IF @deliveryMethod = 'Bank Deposit'
  326. BEGIN
  327. SELECT @pAgent = @pBank, @pAgentName = @pBankName, @pBranch = @pBankBranch, @pBranchName = @pBankBranchName
  328. IF @pBank IS NULL
  329. BEGIN
  330. EXEC proc_errorHandler 1, 'Please select bank', NULL
  331. RETURN
  332. END
  333. IF @raccountNo IS NULL
  334. BEGIN
  335. EXEC proc_errorHandler 1, 'Account number cannot be blank', NULL
  336. RETURN
  337. END
  338. END
  339. IF (@pBankBranch IS NOT NULL)
  340. BEGIN
  341. SELECT @pBank = parentId, @pBankBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  342. SELECT @pBankName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBank
  343. END
  344. --3. Limit Checking---------------------------------------------------------------------------------------------------------------------
  345. SELECT @sendingCustType = customerType FROM dbo.customerMaster WITH(NOLOCK) WHERE customerId = @senderId
  346. SELECT @receivingCustType = customerType FROM dbo.customerMaster WITH(NOLOCK) WHERE customerId = @benId
  347. --Credit Limit Section--------------------------------------------------------------------------------------------------
  348. --SELECT @limitBal = [dbo].FNAGetLimitBalIRH(@settlingAgent)
  349. --SELECT @baseCurrency = currency FROM creditLimitInt WITH(NOLOCK) WHERE agentId = @settlingAgent AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  350. --SELECT @limitBal = dbo.FNAGetExchangeAmount(@collCurr, @sCountryId, @settlingAgent, @limit)
  351. --IF @tAmt > @limitBal
  352. --BEGIN
  353. -- EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', @controlNo
  354. -- RETURN
  355. --END
  356. --IF EXISTS(SELECT 'X' FROM creditLimitInt WITH(NOLOCK)
  357. -- WHERE agentId = @settlingAgent
  358. -- AND expiryDate < GETDATE()
  359. -- AND ISNULL(isActive, 'N') = 'Y'
  360. -- AND ISNULL(isDeleted, 'N') = 'N')
  361. --BEGIN
  362. -- EXEC [proc_errorHandler] 1, 'Your credit limit has been expired. Please contact HO', @controlNo
  363. -- RETURN
  364. --END
  365. --IF((SELECT ISNULL(expiryDate, '1900-01-01') FROM creditLimitInt WITH(NOLOCK)
  366. -- WHERE agentId = @settlingAgent
  367. -- AND ISNULL(isActive, 'N') = 'Y'
  368. -- AND ISNULL(isDeleted, 'N') = 'N')
  369. -- <(SELECT TOP 1 ISNULL(topUpExpiryDate, '1900-01-01') FROM balanceTopUp WITH(NOLOCK)
  370. -- WHERE agentId = @settlingAgent ORDER BY btId DESC))
  371. --BEGIN
  372. -- IF NOT EXISTS(SELECT TOP 1 'X' FROM balanceTopUp WITH(NOLOCK) WHERE agentId = @settlingAgent
  373. -- AND topUpExpiryDate >= ISNULL(GETDATE(), '1900-01-01')
  374. -- ORDER BY btId DESC)
  375. -- BEGIN
  376. -- EXEC [proc_errorHandler] 1, 'Your Top-up has been expired. Please contact HO', @controlNo
  377. -- RETURN
  378. -- END
  379. --END
  380. --END of Credit Limit Section
  381. --4. Exchange Rate Checking
  382. --SET @pAgent=1006
  383. --SET @pSuperAgent=1005
  384. --SET @pBranch=1007
  385. SELECT @exRate=customerRate
  386. ,@sCurrCostRate = sCurrCostRate
  387. ,@sCurrHoMargin = sCurrHoMargin
  388. ,@sCurrAgentMargin = sCurrAgentMargin
  389. ,@pCurrCostRate = pCurrCostRate
  390. ,@pCurrHoMargin = pCurrHoMargin
  391. ,@pCurrAgentMargin = pCurrAgentMargin
  392. FROM dbo.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethodId)
  393. IF @exRate IS NULL
  394. BEGIN
  395. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Exchange Rate not defined', NULL
  396. RETURN
  397. END
  398. --End of Exchange Rate Checking
  399. --5. Service Charge Checking
  400. SELECT @iServiceCharge = ISNULL(amount, -1) FROM [dbo].FNAGetServiceCharge(
  401. @sCountryId, @sSuperAgent, @sAgent, @sBranch,
  402. @pCountryId, @pSuperAgent, @pAgent, @pBranch,
  403. @deliveryMethodId, @cAmt, @collCurr
  404. )
  405. IF @iServiceCharge = -1
  406. BEGIN
  407. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Service Charge is not defined', NULL
  408. RETURN
  409. END
  410. SET @iServiceCharge = ROUND(@iServiceCharge, 2)
  411. IF @iServiceCharge <> @serviceCharge
  412. BEGIN
  413. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Amount detail not match. Please check service charge', NULL
  414. RETURN
  415. END
  416. IF @schemeCode IS NOT NULL
  417. BEGIN
  418. DECLARE @scValue MONEY, @scAction CHAR(2), @scOffer MONEY, @exRateOffer FLOAT, @scDiscount MONEY
  419. END
  420. SET @iCustomerRate = @exRate + ISNULL(@schemePremium, 0)
  421. SET @iTAmt = @cAmt - @iServiceCharge
  422. SELECT @place = place, @currDecimal = currDecimal
  423. FROM currencyPayoutRound WITH(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N'
  424. AND currency = @pCurr AND ISNULL(tranType,@deliveryMethodId) =@deliveryMethodId
  425. SET @currDecimal = ISNULL(@currDecimal, 0)
  426. SET @place = ISNULL(@place, 0)
  427. SET @iPAmt = @iTAmt * @iCustomerRate
  428. SET @iPAmt = ROUND(@iPAmt, @currDecimal, 1)
  429. --IF @place IS NOT NULL
  430. -- SET @iPAmt = ROUND(@iPAmt, -@place, 1)
  431. IF @iPAmt <> @pAmt
  432. BEGIN
  433. EXEC proc_errorHandler 1, 'Amount detail not match. Please re-calculate the amount again.', NULL
  434. RETURN
  435. END
  436. --End of service charge Checking
  437. --START OFAC Checking
  438. DECLARE @receiverName VARCHAR(200)
  439. IF(ISNULL(@senderId, '') = '')
  440. SELECT @senderName = @sfName + ISNULL(' ' + @smName, '') + ISNULL(' ' + @slName, '') + ISNULL(' ' + @slName2, '')
  441. ELSE
  442. SELECT @senderName = firstName + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName1, '') + ISNULL(' ' + lastName2, '')
  443. FROM dbo.customerMaster WITH(NOLOCK) WHERE customerId = @senderId
  444. SELECT @receiverName = @rfName + ISNULL(' ' + @rmName, '') + ISNULL(' ' + @rlName, '') + ISNULL(' ' + @rlName2, '')
  445. DECLARE @receiverOfacRes VARCHAR(MAX)
  446. EXEC proc_ofacTracker @flag = 't', @name = @senderName, @Result = @ofacRes OUTPUT
  447. EXEC proc_ofacTracker @flag = 't', @name = @receiverName, @Result = @receiverOfacRes OUTPUT
  448. DECLARE @result VARCHAR(MAX)
  449. IF ISNULL(@ofacRes, '') <> ''
  450. BEGIN
  451. SET @ofacReason = 'Matched by sender name'
  452. END
  453. IF ISNULL(@receiverOfacRes, '') <> ''
  454. BEGIN
  455. SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes)
  456. SET @ofacReason = 'Matched by receiver name'
  457. END
  458. IF ISNULL(@ofacRes, '') <> '' AND ISNULL(@receiverOfacRes, '') <> ''
  459. BEGIN
  460. SET @ofacReason = 'Matched by both sender name and receiver name'
  461. END
  462. --******************BEGINING OF NEW CUSTOMER CREATION AND ENROLLMENT********************************
  463. DECLARE @sIdTypeId INT
  464. SELECT @sIdTypeId = valueId from staticDataValue WITH(NOLOCK) WHERE detailTitle = @sIdType AND typeID = 1300
  465. SELECT @sfName = UPPER(@sfName), @smName = UPPER(@smName), @slName = UPPER(@slName), @slName2 = UPPER(@slName2)
  466. SELECT @rfName = UPPER(@rfName), @rmName = UPPER(@rmName), @rlName = UPPER(@rlName), @rlName2 = UPPER(@rlName2)
  467. --2. Begining of New customer Creation and enrollment or updating existing customer data---
  468. SET @senderName = @sfName + ISNULL(' ' + @smName, '') + ISNULL(' ' + @slName, '') + ISNULL(' ' + @slName2, '')
  469. SET @receiverName = @rfName + ISNULL(' ' + @rmName, '') + ISNULL(' ' + @rlName, '') + ISNULL(' ' + @rlName2, '')
  470. DECLARE @sNaCountryId INT = (SELECT countryId FROM COUNTRYMASTER (NOLOCK) WHERE COUNTRYNAME = @sNaCountry)
  471. --------#Register Customer if not registered#---------------
  472. EXEC PROC_CHECK_CUSTOMER_REGISTRATION @flag = 'i', @customerName = @senderName, @customerIdNo = @sIdNo, @customerIdType = @sIdTypeId,
  473. @nativeCountryId = @sNaCountryId, @customerId = @senderId OUT, @user = @user, @custAdd = @sAdd1, @custCity = @scity, @custEmail = @sEmail,
  474. @custMobile = @sMobile, @custDOB = @sdob, @custIdValidDate = @sIdValid, @occupation = @occupation, @ipAddress = @sIpAddress
  475. IF @senderId = '0000'
  476. BEGIN
  477. EXEC proc_errorHandler 1, 'Sender Email can not be blank.', NULL
  478. RETURN
  479. END
  480. --START Compliance Checking
  481. DECLARE @complianceRuleId INT, @cAmtUSD MONEY
  482. SELECT
  483. @sCurrCostRate = sCurrCostRate
  484. ,@sCurrHoMargin = sCurrHoMargin
  485. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  486. IF @sCurrCostRate IS NULL
  487. BEGIN
  488. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Exchange Rate not defined!', NULL
  489. RETURN
  490. END
  491. SET @cAmtUSD = @cAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0))
  492. SELECT @sCountry = countryName FROM dbo.countryMaster(nolock) WHERE countryId = @sCountryId
  493. EXEC [proc_complianceRuleDetail]
  494. @flag = 'core'
  495. ,@user = @user
  496. ,@sIdType = @sIdType
  497. ,@sIdNo = @sIdNo
  498. ,@receiverName = @rfName
  499. ,@cAmt = @cAmt
  500. ,@cAmtUSD = @cAmtUSD
  501. ,@customerId = @senderId
  502. ,@pCountryId = @pCountryId
  503. ,@deliveryMethod= @deliveryMethodId
  504. ,@message = @complienceMessage OUTPUT
  505. ,@shortMessage = @shortMsg OUTPUT
  506. ,@errCode = @complienceErrorCode OUTPUT
  507. ,@ruleId = @complianceRuleId OUTPUT
  508. IF(@complienceErrorCode <> 0 OR ISNULL(@ofacRes, '') <> '')
  509. BEGIN
  510. IF @@TRANCOUNT > 0
  511. COMMIT TRANSACTION
  512. IF(@ofacRes <> '')
  513. BEGIN
  514. SET @result = @ofacRes + '|' + ISNULL(@ofacReason, '')
  515. SELECT errorCode = 100, msg = 'WARNING!!! This customer is listed on OFAC List', id = @result
  516. EXEC proc_sendPageLoadData @flag = 'ofac', @user = @user, @blackListIds = @ofacRes
  517. END
  518. IF(@complienceErrorCode = 1)
  519. BEGIN
  520. SELECT 101 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  521. END
  522. IF(@complienceErrorCode = 2)
  523. BEGIN
  524. INSERT remitTranComplianceTemp(csDetailTranId, matchTranId, agentRefId)
  525. SELECT @complianceRuleId, NULL, @agentRefId
  526. SELECT 102 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  527. END
  528. IF (@complienceErrorCode <> 0)
  529. BEGIN
  530. INSERT INTO ComplianceLog(senderName, senderCountry, senderIdType, senderIdNumber, senderMobile, receiverName, receiverCountry, payOutAmt,
  531. complianceId, complianceReason, complainceDetailMessage, createdBy, createdDate)
  532. SELECT @senderName, @sCountry, @sIdType, @sIdNo, @sMobile, @receiverName, @pCountry, @cAmt, @complianceRuleId, @shortMsg, @complienceMessage, @user, GETDATE()
  533. DECLARE @tempRowId INT = @@IDENTITY
  534. SELECT
  535. id
  536. ,csDetailRecId = ''
  537. ,[S.N.] = ROW_NUMBER()OVER(ORDER BY id)
  538. ,[Remarks] = complianceReason
  539. ,[Action] = CASE WHEN @complienceErrorCode=2 THEN 'HOLD' ELSE 'Blocked' END
  540. --,[Matched Tran ID] = ''
  541. FROM ComplianceLog(nolock)
  542. WHERE id = @tempRowId
  543. END
  544. RETURN
  545. END
  546. --END OFAC/Compliance data
  547. EXEC proc_errorHandler 0, 'Validation successful', NULL
  548. --*****Check For Same Name*****
  549. SELECT tranId = rt.id, senderName, sIdType = sen.idType, sIdNo = sen.idNumber, cAmt, pCountry
  550. FROM remitTran rt WITH(NOLOCK)
  551. INNER JOIN tranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  552. WHERE senderName = @senderName AND createdDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101) AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  553. --*****Check For Same Id*****
  554. SELECT tranId = rt.id, senderName, sIdType = sen.idType, sIdNo = sen.idNumber, cAmt, pCountry
  555. FROM remitTran rt WITH(NOLOCK)
  556. INNER JOIN tranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  557. WHERE idType = @sIdType AND idNumber = @sIdNo AND createdDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101) AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  558. END
  559. ELSE IF @flag = 'i' --Send Transaction
  560. BEGIN
  561. --1. Field Validation-----------------------------------------------------------
  562. IF @user IS NULL
  563. BEGIN
  564. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send transaction', NULL
  565. RETURN
  566. END
  567. IF @sIdType = 'Alien Registration Card'
  568. BEGIN
  569. IF LEN(@sIdNo) <> 14 OR @sIdNo NOT LIKE '%-%'
  570. BEGIN
  571. EXEC proc_errorHandler 1, 'Invalid Alian Card number found', NULL
  572. RETURN
  573. END
  574. END
  575. IF NOT EXISTS(SELECT 'X' FROM applicationUsers WITH(NOLOCK) WHERE PWD = DBO.FNAEncryptString(@txnPWD) AND userName = @user)
  576. BEGIN
  577. EXEC proc_errorHandler 1, 'TXN password is invalid !', @user
  578. RETURN
  579. END
  580. IF (ISNULL(@deliveryMethod, '') = ''
  581. OR @serviceCharge IS NULL
  582. OR ISNULL(@cAmt, 0) = 0
  583. OR ISNULL(@tAmt,0) = 0
  584. OR ISNULL(@exRate, 0) = 0)
  585. BEGIN
  586. EXEC proc_errorHandler 1, 'Mandatory Field(s) missing', NULL
  587. RETURN
  588. END
  589. --******************BEGINING OF NEW CUSTOMER CREATION AND ENROLLMENT********************************
  590. SELECT @sIdTypeId = valueId from staticDataValue WITH(NOLOCK) WHERE detailTitle = @sIdType AND typeID = 1300
  591. SELECT @sfName = UPPER(@sfName), @smName = UPPER(@smName), @slName = UPPER(@slName), @slName2 = UPPER(@slName2)
  592. SELECT @rfName = UPPER(@rfName), @rmName = UPPER(@rmName), @rlName = UPPER(@rlName), @rlName2 = UPPER(@rlName2)
  593. --2. Begining of New customer Creation and enrollment or updating existing customer data---
  594. SET @senderName = @sfName + ISNULL(' ' + @smName, '') + ISNULL(' ' + @slName, '') + ISNULL(' ' + @slName2, '')
  595. SET @receiverName = @rfName + ISNULL(' ' + @rmName, '') + ISNULL(' ' + @rlName, '') + ISNULL(' ' + @rlName2, '')
  596. SET @sNaCountryId = (SELECT countryId FROM COUNTRYMASTER (NOLOCK) WHERE COUNTRYNAME = @sNaCountry)
  597. --------#Register Customer if not registered#---------------
  598. EXEC PROC_CHECK_CUSTOMER_REGISTRATION @flag = 'i', @customerName = @senderName, @customerIdNo = @sIdNo, @customerIdType = @sIdTypeId,
  599. @nativeCountryId = @sNaCountryId, @customerId = @senderId OUT, @user = @user, @custAdd = @sAdd1, @custCity = @scity, @custEmail = @sEmail,
  600. @custMobile = @sMobile, @custDOB = @sdob, @custIdValidDate = @sIdValid, @occupation = @occupation, @ipAddress = @sIpAddress
  601. IF @senderId = '0000'
  602. BEGIN
  603. EXEC proc_errorHandler 1, 'Sender Email can not be blank.', NULL
  604. RETURN
  605. END
  606. SET @nCust = 'Y'
  607. IF @nCust = 'N' AND @senderId IS NULL
  608. BEGIN
  609. EXEC proc_errorHandler 1, 'Mandatory Field(s) missing', NULL
  610. RETURN
  611. END
  612. IF ISNULL(@cAmt, 0) = 0
  613. BEGIN
  614. EXEC proc_errorHandler 1, 'Collection Amount is missing', NULL
  615. RETURN
  616. END
  617. IF @serviceCharge > @cAmt
  618. BEGIN
  619. EXEC proc_errorHandler 1, 'Collection Amount is less than service charge.', NULL
  620. RETURN
  621. END
  622. SET @controlNo = '80' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9)
  623. IF EXISTS(SELECT 'X' FROM controlNoList WITH(NOLOCK) WHERE controlNo = @controlNo)
  624. BEGIN
  625. SET @controlNo = '80' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9)
  626. IF EXISTS(SELECT 'X' FROM controlNoList WITH(NOLOCK) WHERE controlNo = @controlNo)
  627. BEGIN
  628. EXEC proc_errorHandler 1, 'Technical error occurred. Please try again', NULL
  629. RETURN
  630. END
  631. END
  632. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  633. IF @deliveryMethod IN ('Cash Payment', 'Door to Door')
  634. BEGIN
  635. IF @deliveryMethod = 'Door to Door'
  636. BEGIN
  637. SET @payMsg = ' [Door To Door Location:' + @pBankBranchName + ', ' + @pBankBranchName + ' ]'
  638. END
  639. IF @pBank IS NOT NULL
  640. BEGIN
  641. IF @pBankBranch IS NOT NULL
  642. SELECT @pBranch = @pBankBranch, @pBranchName = @pBankBranchName
  643. END
  644. END
  645. ELSE IF @deliveryMethod = 'Bank Deposit'
  646. BEGIN
  647. IF @pBank IS NULL
  648. BEGIN
  649. EXEC proc_errorHandler 1, 'Bank is required for Bank Deposit ', NULL
  650. RETURN
  651. END
  652. SELECT @pAgent = @pBank, @pAgentName = @pBankName, @pBranch = @pBankBranch, @pBranchName = @pBankBranchName
  653. END
  654. --3. Check Limit starts
  655. --Credit Limit Section
  656. SELECT @limitBal = dbo.FNAGetLimitBalIRH(@settlingAgent)
  657. IF @tAmt > @limitBal
  658. BEGIN
  659. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', @controlNo
  660. RETURN
  661. END
  662. --End of Credit Limit Section-------------------------------------------------------------------------------------------------------------
  663. --Get Service Charge----------------------------------------------------------------------------------------------------------------------
  664. SELECT @iServiceCharge = ISNULL(amount, -1) FROM [dbo].FNAGetServiceCharge(
  665. @sCountryId, @sSuperAgent, @sAgent, @sBranch,
  666. @pCountryId, @pSuperAgent, @pAgent, @pBranch,
  667. @deliveryMethodId, @cAmt, @collCurr
  668. )
  669. IF @iServiceCharge = -1
  670. BEGIN
  671. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Service Charge is not defined', NULL
  672. RETURN
  673. END
  674. --Earthquake relief fund
  675. DECLARE @scDisc MONEY
  676. IF @iServiceCharge <> @serviceCharge
  677. BEGIN
  678. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Amount detail not match', NULL
  679. RETURN
  680. END
  681. --End-------------------------------------------------------------------------------------------------------------------------------------
  682. --4. Get Exchange Rate Details------------------------------------------------------------------------------------------------------------------
  683. SELECT
  684. @customerRate = customerRate
  685. ,@sCurrCostRate = sCurrCostRate
  686. ,@sCurrHoMargin = sCurrHoMargin
  687. ,@sCurrAgentMargin = sCurrAgentMargin
  688. ,@pCurrCostRate = pCurrCostRate
  689. ,@pCurrHoMargin = pCurrHoMargin
  690. ,@pCurrAgentMargin = pCurrAgentMargin
  691. ,@agentCrossSettRate = agentCrossSettRate
  692. ,@treasuryTolerance = treasuryTolerance
  693. ,@customerPremium = customerPremium
  694. ,@sharingValue = sharingValue
  695. ,@sharingType = sharingType
  696. FROM dbo.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethodId)
  697. IF @customerRate IS NULL
  698. BEGIN
  699. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Exchange Rate not defined', NULL
  700. RETURN
  701. END
  702. SET @serviceCharge = @serviceCharge - ISNULL(@scDiscount, 0)
  703. SET @iServiceCharge = @iServiceCharge - ISNULL(@iScDiscount, 0)
  704. SET @tAmt = @cAmt - @serviceCharge
  705. SET @iCustomerRate = @customerRate + ISNULL(@schemePremium, 0)
  706. SET @iTAmt = @cAmt - @iServiceCharge
  707. SELECT @place = place, @currDecimal = currDecimal
  708. FROM currencyPayoutRound WITH(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N'
  709. AND currency = @pCurr AND ISNULL(tranType,@deliveryMethodId) =@deliveryMethodId
  710. SET @currDecimal = ISNULL(@currDecimal, 0)
  711. SET @iPAmt = @iTAmt * @iCustomerRate
  712. SET @iPAmt = ROUND(@iPAmt, @currDecimal, 1)
  713. --IF @place IS NOT NULL
  714. -- SET @iPAmt = ROUND(@iPAmt, -@place, 1)
  715. IF @iPAmt <> @pAmt
  716. BEGIN
  717. EXEC proc_errorHandler 1, 'Amount detail not match. Please re-calculate the amount again.', NULL
  718. RETURN
  719. END
  720. --6. Commission Calculation Start
  721. DECLARE @agentFxGain MONEY
  722. SET @agentFxGain = ((@tAmt) *(@agentCrossSettRate - (@customerRate + ISNULL(@schemePremium, 0))))/@agentCrossSettRate
  723. --Commission Calculation End
  724. --**********Customer Per Day Limit Checking**********
  725. DECLARE @remitTranTemp TABLE(tranId BIGINT, controlNo VARCHAR(20), cAmt MONEY, receiverName VARCHAR(200), receiverIdType VARCHAR(100), receiverIdNumber VARCHAR(50), dot DATETIME)
  726. DECLARE @moneySendTemp TABLE(tranNo BIGINT, refno VARCHAR(20), paidAmt MONEY, receiverName VARCHAR(200), receiverIdDescription VARCHAR(100), receiverIdDetail VARCHAR(50), dot DATETIME)
  727. INSERT INTO @remitTranTemp(tranId, controlNo, cAmt, receiverName, receiverIdType, receiverIdNumber, dot)
  728. SELECT rt.id, rt.controlNo, rt.cAmt, rt.receiverName, rec.idType, rec.idNumber, rt.createdDateLocal
  729. FROM vwRemitTran rt WITH(NOLOCK)
  730. INNER JOIN vwTranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  731. INNER JOIN vwTranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  732. WHERE sen.idNumber = @sIdNo
  733. AND (tranStatus <> 'CancelRequest' AND tranStatus <> 'Cancel')
  734. AND (rt.approvedDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101) AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  735. OR (approvedBy IS NULL AND cancelApprovedBy IS NULL))
  736. IF EXISTS(SELECT 'X' FROM @remitTranTemp WHERE cAmt = @cAmt
  737. AND (receiverName = @receiverName OR (ISNULL(receiverIdType, '0') = @rIdType AND ISNULL(receiverIdNumber, '0') = @rIdNo))
  738. AND DATEDIFF(MI, dot, GETDATE()) <= 5
  739. )
  740. BEGIN
  741. EXEC proc_errorHandler 1, 'Similar transaction found. You can process similar transaction after 5 minutes.', NULL
  742. RETURN
  743. END
  744. DECLARE @customerTotalSentAmt MONEY = 0, @txnSumTobeDeducted MONEY = 0
  745. SELECT @customerTotalSentAmt = SUM(cAmt) FROM @remitTranTemp
  746. SELECT @customerTotalAmt2 = SUM(paidAmt) FROM @moneySendTemp
  747. SELECT @txnSumTobeDeducted = ISNULL(SUM(paidAmt), 0)
  748. FROM @moneySendTemp mst
  749. INNER JOIN @remitTranTemp rtt ON mst.refno = rtt.controlNo
  750. IF (ISNULL(@customerTotalAmt2, 0) + ISNULL(@customerTotalSentAmt, 0) + @cAmt - @txnSumTobeDeducted) > dbo.FNAGetPerDayCustomerLimit(@settlingAgent)
  751. BEGIN
  752. EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Customer Limit exceeded.', NULL
  753. RETURN
  754. END
  755. -- #########country and occupation risk point
  756. DECLARE @countryRisk INT,@OccupationRisk INT,@isFirstTran CHAR(1)
  757. SET @isFirstTran = CASE WHEN @nCust='Y' THEN 'Y' END
  758. SELECT @sNaCountry = CASE WHEN @nCust='Y' THEN @sNaCountry ELSE nativeCountry END
  759. FROM tranSenders WITH(NOLOCK) WHERE customerId = @senderId
  760. IF NOT EXISTS(SELECT 'Z' FROM tranSenders WITH(NOLOCK) WHERE customerId = @senderId)
  761. SET @isFirstTran ='Y'
  762. SELECT @countryRisk = ISNULL(fatfRating, 0) FROM countryMaster C WITH(NOLOCK) WHERE countryName = @sNaCountry AND ISNULL(C.isActive,'Y') = 'Y' AND ISNULL(C.isDeleted,'N') = 'Y'
  763. SELECT @OccupationRisk = ISNULL(riskFactor,0) FROM occupationMaster WITH(NOLOCK) WHERE occupationId = @occupation AND ISNULL(isActive,'Y')='Y' AND ISNULL(isDeleted,'N')='Y'
  764. --##Get Voucher Details into temp table START##--
  765. SELECT voucherNo = p.value('@voucherNo', 'varchar(30)')
  766. ,voucherDate = p.value('@voucherDate', 'date')
  767. ,voucherAmount = p.value('@voucherAmount', 'varchar(25)')
  768. ,bankId = p.value('@bankId', 'int')
  769. INTO #tempVoucherData
  770. FROM @voucherDetails.nodes('/root/row') AS tmp(p)
  771. --RBA
  772. DECLARE @RBAScoreTxn MONEY, @RBAScoreCustomer MONEY
  773. SELECT
  774. @RBAScoreCustomer = @RBACustomerRiskValue
  775. ,@RBAScoreTxn = CASE WHEN @RBATxnRisk = 'LOW RISK' THEN 40
  776. WHEN @RBATxnRisk = 'MEDIUM RISK' THEN 50
  777. WHEN @RBATxnRisk = 'HIGH RISK' THEN 51
  778. ELSE 100 END
  779. IF @deliveryMethod = 'BANK DEPOSIT'
  780. BEGIN
  781. IF NOT EXISTS(SELECT 'A' FROM agentMaster(nolock) where agentId = @pBank and agenttype =2903 and IsIntl = 1)
  782. begin
  783. EXEC proc_errorHandler 1, 'Invalid bank selected', NULL
  784. return
  785. end
  786. select @pAgent = bankpartnerId from AgentBankMapping(nolock) where bankId = @pBank
  787. SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName,
  788. @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName
  789. FROM dbo.FNAGetBranchFullDetails(@pAgent)
  790. END
  791. --##Get Voucher Details into temp table END##--
  792. IF @pCountry ='VIETNAM'
  793. BEGIN
  794. SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName,
  795. @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName
  796. FROM dbo.FNAGetBranchFullDetails(2090)
  797. SELECT
  798. @pAgentComm = (SELECT amount FROM dbo.FNAGetPayComm
  799. (@sAgent,(SELECT countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @sCountry),
  800. NULL, null, @pCountryId, null, @pAgent, 'USD'
  801. ,@deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, NULL))
  802. ,@pAgentCommCurrency = 'KRW'
  803. END
  804. BEGIN TRANSACTION
  805. INSERT INTO remitTranTemp(
  806. controlNo
  807. ,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin
  808. ,pCurrCostRate,pCurrHoMargin,pCurrSuperAgentMargin,pCurrAgentMargin
  809. ,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate
  810. ,treasuryTolerance,customerPremium,schemePremium,sharingValue
  811. --,sharingType
  812. ,serviceCharge,handlingFee, agentFxGain
  813. ,sAgentComm,sAgentCommCurrency,sSuperAgentComm,sSuperAgentCommCurrency
  814. ,pAgentComm,pAgentCommCurrency,pSuperAgentComm,pSuperAgentCommCurrency
  815. ,promotionCode,promotionType
  816. ,pMessage
  817. ,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName,sCountry
  818. ,pSuperAgent,pSuperAgentName,pAgent,pAgentName,pBranch,pBranchName,pCountry
  819. ,paymentMethod
  820. ,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,pBankType
  821. ,expectedPayoutAgent
  822. ,collMode,collCurr,tAmt,cAmt,pAmt,payoutCurr
  823. ,relWithSender,purposeOfRemit,sourceOfFund
  824. ,tranStatus,payStatus
  825. ,createdDate,createdDateLocal,createdBy
  826. ,tranType,voucherNo
  827. ,senderName
  828. ,receiverName
  829. ,pState
  830. ,pDistrict
  831. )
  832. SELECT
  833. @controlNoEncrypted
  834. ,@sCurrCostRate,@sCurrHoMargin,@sCurrSuperAgentMargin,@sCurrAgentMargin
  835. ,@pCurrCostRate,@pCurrHoMargin,@pCurrSuperAgentMargin,@pCurrAgentMargin
  836. ,@agentCrossSettRate,@customerRate,@sAgentSettRate,@pDateCostRate
  837. ,@treasuryTolerance,@customerPremium,ISNULL(@schemePremium,0),@sharingValue
  838. --,@sharingType
  839. ,@serviceCharge,ISNULL(@scDiscount,0), @agentFxGain
  840. ,@sAgentComm,@sAgentCommCurrency,@sSuperAgentComm,@sSuperAgentCommCurrency
  841. ,@pAgentComm,@pAgentCommCurrency,@pSuperAgentComm,@pSuperAgentCommCurrency
  842. ,@promotionCode,@promotionType
  843. ,@payMsg
  844. ,@sSuperAgent,@sSuperAgentName,@sAgent,@sAgentName,@sBranch,@sBranchName,@sCountry
  845. ,@pSuperAgent,@pSuperAgentName,@pAgent,@pAgentName,@pBranch,@pBranchName,@pCountry
  846. ,@deliveryMethod
  847. ,@pBank,@pBankName,@pBankBranch,@pBankBranchName,@raccountNo,@pBankType
  848. ,@pAgentName
  849. ,@collMode,@collCurr,@tAmt,@cAmt,@pAmt,@pCurr
  850. ,@relationship,@purpose,@sourceOfFund
  851. ,'Hold','Unpaid'
  852. ,DBO.FNADateFormatTZ(GETDATE(), @user),GETDATE(),@user
  853. ,'I',''
  854. ,@senderName
  855. ,@receiverName
  856. ,@pLocation, @pSubLocation
  857. SET @id = SCOPE_IDENTITY()
  858. INSERT INTO bankCollectionVoucherDetail( tempTranId ,voucherNo ,voucherDate ,voucherAmt ,bankId)
  859. SELECT @id, voucherNo, voucherDate, voucherAmount, bankId FROM #tempVoucherData
  860. -- UPDATE BONUS
  861. --UPDATE customerMaster SET lastTranId = @id, bonusPointPending = ISNULL(bonusPointPending,0) + ISNULL(@cAmt,0) WHERE customerId = @senderId
  862. INSERT INTO controlNoList(controlNo)
  863. SELECT @controlNo
  864. INSERT INTO tranSendersTemp(
  865. tranId,customerId,membershipId
  866. ,firstName,middleName,lastName1,lastName2
  867. ,fullName
  868. ,country,[address],address2,zipCode,city,email
  869. ,homePhone,mobile,nativeCountry
  870. ,dob,placeOfIssue,idType,idNumber,validDate
  871. ,occupation
  872. ,countryRiskPoint,customerRiskPoint
  873. ,isFirstTran
  874. ,salary,companyName
  875. ,cwPwd,ttName
  876. ,dcInfo,ipAddress,RBA
  877. )
  878. SELECT
  879. @id,@senderId,@memberCode,@sfName,@smName,@slName,@slName2
  880. ,@senderName,@sCountry
  881. ,@sAdd1,@sAdd2,@sPostCode,@scity,@sEmail,@sTel,@sMobile,@sNaCountry,@sdob
  882. ,@sIdTypeId,@sIdType,@sIdNo,@sIdValid,@occupation,@countryRisk,@RBAScoreCustomer
  883. ,@isFirstTran,@salaryRange
  884. ,@company,@cwPwd,@ttName,@sDcInfo,@sIpAddress, @RBAScoreTxn
  885. INSERT INTO tranReceiversTemp(
  886. tranId,customerId,membershipId
  887. ,firstName,middleName,lastName1,lastName2
  888. ,fullName
  889. ,country,[address],zipCode,city,email
  890. ,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue
  891. ,idType,idNumber,idPlaceOfIssue,issuedDate,validDate,gender
  892. ,STATE,district
  893. )
  894. SELECT
  895. @id,@benId,''
  896. ,@rfName,@rmName,@rlName,@rlName2
  897. ,@receiverName
  898. ,@pCountry,@rAdd1,@rPostCode,@rcity,@rEmail
  899. ,@rTel,@rTel,@rMobile,@rNaCountry,@rdob,NULL
  900. ,@rIdType,@rIdNo,NULL,NULL,@rIdValid,@rgender
  901. ,@pLocationText, @pSubLocationText
  902. EXEC proc_customerTxnHistory @controlNo = @controlNoEncrypted
  903. --**********DEPOSIT DETAIL HANDLING**********
  904. DECLARE @bankSumAmt money, @reSendAmt money, @cashSumAmt money
  905. --10. Compliance----------------------------------------------------------------------------------------------------
  906. IF EXISTS(SELECT 'X' FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @agentRefId)
  907. BEGIN
  908. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId)
  909. SELECT @id, csDetailTranId, matchTranId FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @agentRefId
  910. SET @compFinalRes = 'C'
  911. END
  912. IF EXISTS(SELECT 'X' FROM @remitTranTemp
  913. WHERE dot BETWEEN CONVERT(VARCHAR, GETDATE(), 101) AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  914. AND cAmt = @cAmt AND (receiverName = @receiverName OR (ISNULL(receiverIdType, '0') = @rIdType
  915. AND ISNULL(receiverIdNumber, '0') = @rIdNo)))
  916. BEGIN
  917. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId, reason)
  918. SELECT @id, 0, tranid, 'Suspected duplicate transaction' FROM @remitTranTemp WHERE cAmt = @cAmt AND (receiverName = @receiverName OR (ISNULL(receiverIdType, '0') = @rIdType AND ISNULL(receiverIdNumber, '0') = @rIdNo))
  919. SET @compFinalRes = 'C'
  920. END
  921. ELSE
  922. BEGIN
  923. IF EXISTS(SELECT 'X' FROM @moneySendTemp WHERE paidAmt = @cAmt AND (receiverName = @receiverName OR (ISNULL(receiverIdDescription, '0') = @rIdType AND ISNULL(receiverIdDetail, '0') = @rIdNo)))
  924. BEGIN
  925. INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId, reason)
  926. SELECT @id, 0, tranNo, 'Suspected duplicate transaction from Inficare system' FROM @moneySendTemp WHERE paidAmt = @cAmt AND (receiverName = @receiverName OR (ISNULL(receiverIdDescription, '0') = @rIdType AND ISNULL(receiverIdDetail, '0') = @rIdNo))
  927. SET @compFinalRes = 'C'
  928. END
  929. END
  930. IF(ISNULL(@compFinalRes, '') <> '' OR ISNULL(@ofacRes, '') <> '')
  931. BEGIN
  932. IF(@ofacRes <> '' AND ISNULL(@compFinalRes, '') = '')
  933. BEGIN
  934. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  935. SELECT @id, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  936. UPDATE remitTranTemp SET
  937. tranStatus = 'OFAC Hold'
  938. WHERE controlNo = @controlNoEncrypted
  939. END
  940. ELSE IF(@compFinalRes <> '' AND ISNULL(@ofacRes, '') = '')
  941. BEGIN
  942. UPDATE remitTranTemp SET
  943. tranStatus = 'Compliance Hold'
  944. WHERE controlNo = @controlNoEncrypted
  945. END
  946. ELSE IF(ISNULL(@compFinalRes, '') <> '' AND ISNULL(@ofacRes, '') <> '')
  947. BEGIN
  948. INSERT remitTranOfac(TranId, blackListId, reason, flag)
  949. SELECT @id, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes)
  950. UPDATE remitTranTemp SET
  951. tranStatus = 'OFAC/Compliance Hold'
  952. WHERE controlNo = @controlNoEncrypted
  953. END
  954. END
  955. IF @@TRANCOUNT > 0
  956. COMMIT TRANSACTION
  957. IF(@complianceRes = 'C' OR @ofacRes <> '')
  958. BEGIN
  959. EXEC proc_errorHandler 101, 'Transaction under compliance', @controlNo
  960. RETURN
  961. END
  962. EXEC [proc_errorHandler] 100, 'Transaction has been sent successfully and is waiting for approval', @controlNo
  963. END
  964. ELSE IF @flag = 'exRate' --Get Exchange Rate, Service Charge, Scheme/Offer and amount details
  965. BEGIN
  966. DECLARE @rowId INT
  967. SELECT @scValue = 0, @scOffer = 0, @exRateOffer = 0, @scDiscount = 0
  968. IF @senderId IS NOT NULL
  969. SELECT @senderId = customerId, @sIdNo = idNumber FROM customerMaster WITH(NOLOCK) WHERE idNumber = @senderId
  970. --2. Find Decimal Mask for payout amount rounding
  971. SELECT @pCurr = pCurrency FROM dbo.exRateTreasury WITH(NOLOCK) WHERE pCountry = @pCountryId AND pAgent = @pAgent
  972. IF @pCurr IS NULL
  973. SELECT @pCurr = pCurrency FROM dbo.exRateTreasury WITH(NOLOCK) WHERE pCountry = @pCountryId AND pAgent IS NULL
  974. SELECT @place = place, @currDecimal = currDecimal
  975. FROM currencyPayoutRound WITH(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N'
  976. AND currency = @pCurr AND ISNULL(tranType,@deliveryMethod) = @deliveryMethod
  977. SET @currDecimal = ISNULL(@currDecimal, 0)
  978. IF @pCurr IS NULL
  979. BEGIN
  980. SELECT '1' ErrCode, 'Currency not been defined yet for receiving country' Msg
  981. RETURN
  982. END
  983. SELECT @exRate = dbo.FNAGetCustomerRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  984. IF @exRate IS NULL
  985. BEGIN
  986. SELECT '1' ErrCode, 'Exchange rate not defined yet for receiving currency (' + @pCurr + ')' Msg
  987. RETURN
  988. END
  989. IF ISNULL(@cAmt, 0.00) <> 0.00
  990. BEGIN
  991. SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(
  992. @sCountryId, @sSuperAgent, @sAgent, @sBranch
  993. ,@pCountryId, @pSuperAgent, @pAgent, @pBranch
  994. ,@deliveryMethod, @cAmt, @collCurr
  995. )
  996. IF @serviceCharge IS NULL
  997. BEGIN
  998. SELECT '1' ErrCode, 'Service charge not defined yet for receiving country' Msg
  999. RETURN;
  1000. END
  1001. IF @scAction = 'PD' -- Percent Discount
  1002. BEGIN
  1003. SET @scOffer = (@scValue/100) * @serviceCharge
  1004. SET @scDiscount = (@scValue/100) * @serviceCharge
  1005. END
  1006. ELSE IF @scAction = 'FD' -- Flat Discount
  1007. BEGIN
  1008. SET @scDiscount = @scValue
  1009. END
  1010. ELSE IF @scAction = 'FV' -- Fixed Value
  1011. BEGIN
  1012. SET @scOffer = @scValue
  1013. SET @scDiscount = @serviceCharge - @scValue
  1014. END
  1015. SET @tAmt = @cAmt - @serviceCharge + @scDiscount
  1016. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  1017. SET @pAmt = ROUND(@pAmt, @currDecimal, 1)
  1018. --IF @place IS NOT NULL
  1019. -- SET @pAmt = ROUND(@pAmt, -@place, 1)
  1020. END
  1021. ELSE
  1022. BEGIN
  1023. SET @tAmt = ROUND(@pAmt/(@exRate + @exRateOffer),0)
  1024. SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(
  1025. @sCountryId, @sSuperAgent, @sAgent, @sBranch
  1026. ,@pCountryId, @pSuperAgent, @pAgent, @pBranch
  1027. ,@deliveryMethod, @tAmt, @collCurr
  1028. )
  1029. IF @serviceCharge IS NULL
  1030. BEGIN
  1031. SELECT '1' ErrCode, 'Service charge not defined yet for receiving country' Msg
  1032. RETURN;
  1033. END
  1034. IF @scAction = 'PD'
  1035. BEGIN
  1036. SET @scOffer = (@scValue/100) * @serviceCharge
  1037. SET @scDiscount = (@scValue/100) * @serviceCharge
  1038. END
  1039. ELSE IF @scAction = 'FD'
  1040. BEGIN
  1041. SET @scDiscount = @scValue
  1042. END
  1043. ELSE IF @scAction = 'FV'
  1044. BEGIN
  1045. SET @scOffer = @scValue
  1046. SET @scDiscount = @serviceCharge - @scValue
  1047. END
  1048. SET @cAmt = (@tAmt + @serviceCharge - @scDiscount)
  1049. SET @cAmt = ROUND(@cAmt, @currDecimal)
  1050. --IF @place IS NOT NULL
  1051. -- SET @cAmt = ROUND(@cAmt, -@place)
  1052. END
  1053. --4. Validate Country Sending Limit
  1054. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit', @cAmt = @cAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = @collMode
  1055. ,@deliveryMethod = @deliveryMethod,@sendingCustType = @sendingCustType,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  1056. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  1057. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  1058. IF @errorCode <> '0'
  1059. BEGIN
  1060. SELECT @errorCode ErrCode, @msg Msg
  1061. RETURN;
  1062. END
  1063. --Validate Country Sending Limit END
  1064. --5. Validate Country Receiving Limit
  1065. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit', @cAmt = @cAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = @collMode
  1066. ,@deliveryMethod = @deliveryMethod,@sendingCustType = @sendingCustType,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  1067. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  1068. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  1069. IF @errorCode <> '0'
  1070. BEGIN
  1071. SELECT @errorCode ErrCode, @msg Msg
  1072. RETURN;
  1073. END
  1074. --Validate Country Receiving Limit
  1075. SET @msg = 'Success'
  1076. SELECT
  1077. @errorCode ErrCode, @msg Msg, scCharge = @serviceCharge
  1078. ,exRate = @exRate, place = @place
  1079. ,pCurr = @pCurr, currDecimal = @currDecimal
  1080. ,pAmt =@pAmt, sAmt = @tAmt
  1081. ,disc = 0.00, collAmt = @cAmt
  1082. ,exRateOffer = @exRateOffer, scOffer = @scDiscount, scAction = @scAction, scValue = @scValue, scDiscount = @scDiscount
  1083. END
  1084. ELSE IF @flag = 'customerRate' --Get Customer Rate
  1085. BEGIN
  1086. SELECT TOP 1 @pCurr = CM.currencyCode
  1087. FROM currencyMaster CM WITH (NOLOCK)
  1088. INNER JOIN countryCurrency CC WITH (NOLOCK) ON CM.currencyId = CC.currencyId
  1089. WHERE CC.countryId = @pCountryId
  1090. AND ISNULL(CC.isDeleted, 'N') = 'N'
  1091. IF @pCurr IS NULL
  1092. BEGIN
  1093. SELECT '1' ErrCode, 'Not defined' Msg
  1094. RETURN
  1095. END
  1096. SELECT @exRate = dbo.FNAGetCustomerRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  1097. IF @exRate IS NULL
  1098. BEGIN
  1099. SELECT '1' ErrCode, 'Not defined' Msg
  1100. RETURN
  1101. END
  1102. declare @maxLimit as money,@lCurr as varchar(10)
  1103. SELECT @maxLimit = maxLimitAmt,@lCurr = currency FROM sendTranLimit with(nolock)
  1104. WHERE agentId =@sAgent
  1105. AND ISNULL(receivingCountry, ISNULL(@pCountryId, 0)) = ISNULL(@pCountryId, 0)
  1106. AND ISNULL(tranType, ISNULL(@deliveryMethod, 0)) = ISNULL(@deliveryMethod, 0)
  1107. AND currency = @collCurr AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  1108. SELECT @maxLimit = maxLimitAmt,@lCurr = currency FROM sendTranLimit with(nolock)
  1109. WHERE agentId is null
  1110. AND ISNULL(receivingCountry, ISNULL(@pCountryId, 0)) = ISNULL(@pCountryId, 0)
  1111. AND ISNULL(tranType, ISNULL(@deliveryMethod, 0)) = ISNULL(@deliveryMethod, 0)
  1112. AND currency = @collCurr AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  1113. SELECT '0' ErrCode, @exRate exRate, @pCurr pCurr,@maxLimit limit,@lCurr limitCurr
  1114. END
  1115. ELSE IF @flag = 'CustdayLimit' -- CUSTOMER PER DAY LIMIT
  1116. BEGIN
  1117. DECLARE @txnSum MONEY,@txnCount INT, @tranId INT, @date VARCHAR(20) = CONVERT(varchar(20), GETDATE(),111)
  1118. SELECT
  1119. @limitBal= D.amount FROM csMaster M WITH (NOLOCK)
  1120. INNER JOIN csDetail D WITH(NOLOCK) ON M.csMasterId=D.csDetailId
  1121. WHERE sCountry=@sCountryId
  1122. AND ISNULL(M.isActive,'Y')='Y' AND ISNULL(D.isActive,'Y')='Y'
  1123. SELECT
  1124. @txnSum= ISNULL(SUM(R.cAmt),0),@txnCount=COUNT('x')
  1125. FROM remitTran R WITH (NOLOCK), tranSenders S WITH (NOLOCK)
  1126. WHERE R.id = S.tranId and S.customerId = @senderId
  1127. AND R.approvedDate between @date and @date +' 23:59:59'
  1128. SELECT ISNULL(@limitBal,0) countryBalLimit,ISNULL(@txnSum,0) custDayLimit,
  1129. ISNULL(@txnCount,0) custDayTxn,CAST(GETDATE() as DATE) [txnDate]
  1130. END
  1131. ELSE IF @flag = 'cti' --All transaction information (sender, receiver, payout)
  1132. BEGIN
  1133. SELECT DISTINCT
  1134. c.customerId
  1135. ,c.membershipId
  1136. ,Name = c.firstName + ISNULL(' ' + c.middleName, '') + ISNULL(' ' + c.lastName1, '') + ISNULL(' ' + c.lastName2, '')
  1137. ,c.Country
  1138. ,Address
  1139. ,[State]
  1140. ,Phone = COALESCE(mobile, homePhone, workPhone)
  1141. ,city
  1142. FROM tranSenders c WITH(NOLOCK)
  1143. WHERE c.id = @senderId
  1144. SELECT DISTINCT
  1145. c.customerId
  1146. ,c.membershipId
  1147. ,Name = c.firstName + ISNULL( ' ' + c.middleName, '') + ISNULL( ' ' + c.lastName1, '') + ISNULL( ' ' + c.lastName2, '')
  1148. ,Country
  1149. ,Address
  1150. ,[State]
  1151. ,Phone = COALESCE(mobile, homePhone, workPhone)
  1152. ,city
  1153. FROM tranreceivers c WITH(NOLOCK)
  1154. WHERE c.id = @benId
  1155. IF @agentId > 0
  1156. BEGIN
  1157. SELECT
  1158. DISTINCT
  1159. am.agentId
  1160. ,am.agentCode
  1161. ,name = am.agentName
  1162. ,address = am.agentAddress
  1163. ,city = agentCity
  1164. ,[State] = agentState
  1165. ,Phone = COALESCE(agentMobile1, agentMobile2, agentPhone1, agentPhone2)
  1166. ,Country = @pCountry
  1167. FROM agentMaster am WITH(NOLOCK)
  1168. LEFT JOIN agentCurrency ac WITH(NOLOCK) ON am.agentId = ac.agentId
  1169. WHERE am.agentId = @agentId
  1170. END
  1171. ELSE
  1172. BEGIN
  1173. SELECT
  1174. agentId = NULL
  1175. ,agentCode = NULL
  1176. ,name = 'Any'
  1177. ,address = NULL
  1178. ,city = NULL
  1179. ,state = NULL
  1180. ,Phone = NULL
  1181. ,country = @pCountry
  1182. END
  1183. END
  1184. ELSE IF @flag = 'controlNo'
  1185. BEGIN
  1186. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  1187. SELECT
  1188. senderId = sen.customerId
  1189. ,benId = ben.customerId
  1190. ,pCountry = cm.countryId
  1191. ,deliveryMethod = stm.serviceTypeId
  1192. ,tAmt = trn.tAmt
  1193. ,cAmt = trn.cAmt
  1194. ,pAmt = trn.pAmt
  1195. ,customerRate = trn.customerRate
  1196. ,serviceCharge = trn.serviceCharge
  1197. ,trn.collCurr
  1198. ,trn.payoutCurr
  1199. ,agentId = pBranch
  1200. FROM remitTran trn WITH(NOLOCK)
  1201. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  1202. INNER JOIN tranReceivers ben WITH(NOLOCK) ON trn.id = ben.tranId
  1203. INNER JOIN countryMaster cm WITH(NOLOCK) ON trn.pCountry = cm.countryName
  1204. INNER JOIN serviceTypeMaster stm WITH(NOLOCK) ON trn.paymentMethod = stm.typeTitle
  1205. WHERE controlNo = @controlNoEncrypted
  1206. END
  1207. ELSE IF @flag = 'senderId'
  1208. BEGIN
  1209. SELECT TOP 1
  1210. senderId = sen.customerId
  1211. ,benId = ben.customerId
  1212. ,pCountry = cm.countryId
  1213. ,deliveryMethod = stm.serviceTypeId
  1214. ,tAmt = trn.tAmt
  1215. ,cAmt = trn.cAmt
  1216. ,pAmt = trn.pAmt
  1217. ,customerRate = trn.customerRate
  1218. ,serviceCharge = trn.serviceCharge
  1219. ,trn.collCurr
  1220. ,trn.payoutCurr
  1221. ,agentId = pBranch
  1222. FROM remitTran trn WITH(NOLOCK)
  1223. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  1224. INNER JOIN tranReceivers ben WITH(NOLOCK) ON trn.id = ben.tranId
  1225. INNER JOIN countryMaster cm WITH(NOLOCK) ON trn.pCountry = cm.countryName
  1226. INNER JOIN serviceTypeMaster stm WITH(NOLOCK) ON trn.paymentMethod = stm.typeTitle
  1227. WHERE sen.customerId = @senderId ORDER BY trn.id DESC
  1228. END
  1229. ELSE IF @flag = 'chkSenderIdNo'
  1230. BEGIN
  1231. --IF EXISTS(SELECT 'X' FROM dbo.customerMaster WITH(NOLOCK) WHERE idNumber = @sIdNo AND ISNULL(isDeleted, 'N') = 'N')
  1232. --BEGIN
  1233. -- EXEC proc_errorHandler 1, 'Customer is already registered with this Id Number', NULL
  1234. -- RETURN
  1235. --END
  1236. EXEC proc_errorHandler 0, 'Success', NULL
  1237. END
  1238. END
  1239. END TRY
  1240. BEGIN CATCH
  1241. IF @@TRANCOUNT<>0
  1242. ROLLBACK TRANSACTION
  1243. DECLARE @errorMessage VARCHAR(MAX)
  1244. SET @errorMessage = ERROR_MESSAGE()
  1245. EXEC proc_errorHandler 1, @errorMessage, @user
  1246. END CATCH
  1247. GO