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.

3933 lines
97 KiB

  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendIRH] Script Date: 11/17/2023 10:30:11 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_sendIRH] (
  9. @flag VARCHAR(50)
  10. ,@user VARCHAR(30)
  11. ,@txnPWD VARCHAR(100) = NULL
  12. ,@agentRefId VARCHAR(20) = NULL
  13. ,@senderId VARCHAR(50) = NULL
  14. ,@sfName VARCHAR(100) = NULL
  15. ,@smName VARCHAR(100) = NULL
  16. ,@slName VARCHAR(100) = NULL
  17. ,@slName2 VARCHAR(100) = NULL
  18. ,@sIdType VARCHAR(100) = NULL
  19. ,@sIdNo VARCHAR(50) = NULL
  20. ,@sIdValid DATETIME = NULL
  21. ,@sdob DATETIME = NULL
  22. ,@sTel VARCHAR(20) = NULL
  23. ,@sMobile VARCHAR(20) = NULL
  24. ,@sNaCountry VARCHAR(50) = NULL
  25. ,@scity VARCHAR(100) = NULL
  26. ,@sPostCode VARCHAR(50) = NULL
  27. ,@sAdd1 NVARCHAR(150) = NULL
  28. ,@sAdd2 NVARCHAR(150) = NULL
  29. ,@sEmail VARCHAR(100) = NULL
  30. ,@sgender VARCHAR(100) = NULL
  31. ,@smsSend CHAR(1) = NULL
  32. ,@sCompany VARCHAR(100) = NULL
  33. ,@sDcInfo VARCHAR(50) = NULL
  34. ,@sIpAddress VARCHAR(50) = NULL
  35. ,@benId VARCHAR(50) = NULL
  36. ,@rfName VARCHAR(100) = NULL
  37. ,@rmName VARCHAR(100) = NULL
  38. ,@rlName VARCHAR(100) = NULL
  39. ,@rlName2 VARCHAR(100) = NULL
  40. ,@rIdType VARCHAR(100) = NULL
  41. ,@rIdNo VARCHAR(50) = NULL
  42. ,@rIdValid DATETIME = NULL
  43. ,@rdob DATETIME = NULL
  44. ,@rTel VARCHAR(20) = NULL
  45. ,@rMobile VARCHAR(20) = NULL
  46. ,@rNaCountry VARCHAR(50) = NULL
  47. ,@rcity VARCHAR(100) = NULL
  48. ,@rPostCode VARCHAR(50) = NULL
  49. ,@rAdd1 VARCHAR(150) = NULL
  50. ,@rAdd2 VARCHAR(150) = NULL
  51. ,@rEmail VARCHAR(100) = NULL
  52. ,@raccountNo VARCHAR(50) = NULL
  53. ,@rgender VARCHAR(100) = NULL
  54. ,@salaryRange VARCHAR(150) = NULL
  55. ,@pCountry VARCHAR(50) = NULL -- pay country
  56. ,@pCountryId INT = NULL -- PAY COUNTRY ID
  57. ,@pSuperAgent INT = NULL --payout Super Agent
  58. ,@deliveryMethod VARCHAR(50) = NULL -- payment mode
  59. ,@deliveryMethodId INT = NULL -- payment mode ID
  60. ,@pBank INT = NULL
  61. ,@pBankName VARCHAR(100) = NULL
  62. ,@pBankBranch VARCHAR(30) = NULL
  63. ,@pBankBranchName VARCHAR(100) = NULL
  64. ,@pAgent INT = NULL
  65. ,@pAgentName VARCHAR(100) = NULL
  66. ,@pBranch INT = NULL
  67. ,@pBranchName VARCHAR(100) = NULL
  68. ,@pBankType CHAR(1) = NULL
  69. ,@pCurr VARCHAR(3) = NULL
  70. ,@collCurr VARCHAR(3) = NULL
  71. ,@cAmt MONEY = NULL
  72. ,@pAmt MONEY = NULL
  73. ,@tAmt MONEY = NULL
  74. ,@serviceCharge MONEY = NULL
  75. ,@discount MONEY = NULL
  76. ,@exRate FLOAT = NULL
  77. ,@schemeType VARCHAR(50) = NULL
  78. ,@couponTranNo VARCHAR(20) = NULL
  79. ,@purpose VARCHAR(150) = NULL
  80. ,@sourceOfFund VARCHAR(150) = NULL
  81. ,@relationship VARCHAR(100) = NULL
  82. ,@occupation VARCHAR(100) = NULL
  83. ,@payMsg VARCHAR(1000) = NULL
  84. ,@company VARCHAR(200) = NULL
  85. ,@nCust CHAR(1) = NULL
  86. ,@enrollCust CHAR(1) = NULL
  87. ,@controlNo VARCHAR(20) = NULL
  88. ,@agentId INT = NULL --payout
  89. ,@sCountryId INT = NULL
  90. ,@sCountry VARCHAR(100) = NULL
  91. ,@sBranch INT = NULL
  92. ,@sBranchName VARCHAR(100) = NULL
  93. ,@sAgent INT = NULL
  94. ,@sAgentName VARCHAR(100) = NULL
  95. ,@sSuperAgent INT = NULL
  96. ,@sSuperAgentName VARCHAR(100) = NULL
  97. ,@settlingAgent INT = NULL
  98. ,@branchMapCode VARCHAR(10) = NULL
  99. ,@agentMapCode VARCHAR(10) = NULL
  100. ,@collMode VARCHAR(50) = NULL
  101. ,@id BIGINT = NULL
  102. ,@sessionId VARCHAR(50) = NULL
  103. ,@cancelrequestId INT = NULL
  104. ,@salary VARCHAR(10) = NULL
  105. ,@memberCode VARCHAR(20) = NULL
  106. ,@schemeCode VARCHAR(20) = NULL
  107. ,@cwPwd VARCHAR(10) = NULL
  108. ,@ttName VARCHAR(200) = NULL
  109. ,@ofacRes VARCHAR(MAX) = NULL
  110. ,@ofacReason VARCHAR(200) = NULL
  111. ,@voucherDetails XML = NULL
  112. ,@RBATxnRisk VARCHAR(15) = NULL
  113. ,@RBACustomerRisk VARCHAR(15) = NULL
  114. ,@RBACustomerRiskValue MONEY = NULL
  115. ,@pLocation BIGINT = NULL
  116. ,@pLocationText VARCHAR(100) = NULL
  117. ,@pSubLocation BIGINT = NULL
  118. ,@pSubLocationText VARCHAR(100) = NULL
  119. ,@pTownId VARCHAR(100) = NULL
  120. ,@isManualSc CHAR(1) = NULL
  121. ,@manualSc MONEY = NULL
  122. ,@sCustStreet NVARCHAR(100) = NULL
  123. ,@sCustLocation INT = NULL
  124. ,@sCustomerType INT = NULL
  125. ,@sCustBusinessType INT = NULL
  126. ,@sCustIdIssuedCountry INT = NULL
  127. ,@sCustIdIssuedDate VARCHAR(25) = NULL
  128. ,@receiverId INT = NULL
  129. ,@payoutPartner INT = NULL
  130. ,@customerDepositedBank INT = NULL
  131. ,@introducer VARCHAR(100) = NULL
  132. ,@isOnbehalf VARCHAR(1) = NULL
  133. ,@payerId BIGINT = NULL
  134. ,@payerBranchId BIGINT = NULL
  135. ,@IsFromTabPage CHAR(1) = NULL
  136. ,@customerPassword VARCHAR(20) = NULL
  137. ,@referralCode VARCHAR(20) = NULL
  138. ,@isAdditionalCDDI CHAR(1) = NULL
  139. ,@additionalCDDIXml NVARCHAR(MAX) = NULL
  140. ,@calcBy VARCHAR(10) = NULL
  141. ,@promotionCode INT = NULL
  142. ,@promotionAmount VARCHAR(150) = NULL
  143. ,@relationOther VARCHAR(150) = NULL
  144. ,@purposeOther VARCHAR(150) = NULL
  145. ,@txnRequestFromAgent VARCHAR(10) = NULL
  146. ,@txnRequestRowId BIGINT = NULL
  147. ,@goodsOrigin VARCHAR(200) = NULL
  148. ,@goodsType VARCHAR(200) = NULL
  149. ,@portOfShipment VARCHAR(200) = NULL
  150. ,@visaStatus INT = NULL
  151. ,@trackBy VARCHAR(50) = NULL
  152. ,@partnerId INT = NULL
  153. ,@exRateId VARCHAR(30) = NULL
  154. ,@tpExRate FLOAT = NULL
  155. ,@nameAsPerBank VARCHAR(150) = NULL
  156. ,@calculatedOriginalSc MONEY = NULL
  157. ,@paymentOption VARCHAR(100) = NULL
  158. ,@sitereference VARCHAR(200) = NULL
  159. ,@rewardAmt MONEY = NULL
  160. )
  161. AS
  162. SET NOCOUNT ON;
  163. SET XACT_ABORT ON;
  164. -----------------------------------------
  165. --July 12 --> added flags (questionnaire) for Non Permit Visa
  166. --July 14 --> JME-557 - Add compliance Log for Non Permit Visa
  167. --> replaced hard code with VW_VISA_STATUS_QUESTIONNAIRE
  168. --July 29 --> set pBankName from apibanklist
  169. --Aug 05 --JME-567 ->add col 'receiverNameAlt' changes to show BENEFICIARY NAME AS PER BANK
  170. --SEP 09 --#127 Donga Commission Update for non 24*7
  171. --SEP 21 -->#134 -> Allow edit option of address in Town Area
  172. --Sep 22 -> #109 ->Change the logic to choose highest Rate in case of Nepal
  173. --Sep 23 ->#178 -> Show only Roman in Remittance Statement
  174. --#334 : OFAC screening changes.
  175. --#9776 - Service Charge calcaulation for Validation , @flag = 'v'
  176. -- # 19238 change in @flag = 'exRate' to return exrate on the basis of payment option
  177. -- removed password validation for txn
  178. --------------------------------------------
  179. BEGIN TRY
  180. BEGIN
  181. DECLARE @sCurrCostRate FLOAT
  182. ,@sCurrHoMargin FLOAT
  183. ,@pCurrCostRate FLOAT
  184. ,@pCurrHoMargin FLOAT
  185. ,@sCurrAgentMargin FLOAT
  186. ,@pCurrAgentMargin FLOAT
  187. ,@sCurrSuperAgentMargin FLOAT
  188. ,@pCurrSuperAgentMargin FLOAT
  189. ,@customerRate FLOAT
  190. ,@sAgentSettRate FLOAT
  191. ,@pDateCostRate FLOAT
  192. ,@agentCrossSettRate FLOAT
  193. ,@treasuryTolerance FLOAT
  194. ,@customerPremium FLOAT
  195. ,@schemePremium FLOAT
  196. ,@sharingValue MONEY
  197. ,@sharingType CHAR(1)
  198. ,@sAgentComm MONEY
  199. ,@sAgentCommCurrency VARCHAR(3)
  200. ,@sSuperAgentComm MONEY
  201. ,@sSuperAgentCommCurrency VARCHAR(3)
  202. ,@pAgentComm MONEY
  203. ,@pAgentCommCurrency VARCHAR(3)
  204. ,@pSuperAgentComm MONEY
  205. ,@pSuperAgentCommCurrency VARCHAR(3)
  206. ,@promotionType INT
  207. ,@pSuperAgentName VARCHAR(100)
  208. ,@pStateId INT
  209. ,@agentType INT
  210. ,@senderName VARCHAR(100)
  211. ,@pAgentMapCode VARCHAR(10)
  212. ,@pBranchMapCode VARCHAR(10)
  213. ,@F_ANYWHERE CHAR(1)
  214. ,@TRN_TYPE VARCHAR(100)
  215. ,@complienceMessage VARCHAR(500)
  216. ,@complienceErrorCode TINYINT
  217. ,@shortMsg VARCHAR(100)
  218. DECLARE @xAmt MONEY
  219. ,@baseCurrency VARCHAR(3)
  220. ,@limitBal MONEY
  221. ,@sendingCustType INT
  222. ,@receivingCustType INT
  223. ,@msg VARCHAR(200)
  224. ,@exRateCalByPartner BIT
  225. ,@tranCount INT
  226. ,@schemeCount INT
  227. ,@isEligible CHAR(1) = 'N'
  228. ,@schemeCodeId INT
  229. ,@isFreeSc CHAR(1) = 'N'
  230. ,@calcOriginalSc MONEY = 0 -- added for teller quota
  231. IF @pBankBranch = 'NA'
  232. SET @pBankBranch = NULL
  233. IF ISNULL(@relationship, '') <> 'other (please specify)'
  234. SET @relationOther = NULL
  235. IF ISNULL(@purpose, '') <> 'other (please specify)'
  236. SET @purposeOther = NULL
  237. DECLARE @iServiceCharge MONEY
  238. ,@iTAmt MONEY
  239. ,@iPAmt MONEY
  240. ,@iScDiscount MONEY
  241. ,@iCustomerRate FLOAT
  242. ,@iCollDetailAmt MONEY
  243. DECLARE @place INT
  244. ,@currDecimal INT
  245. DECLARE @cisMasterId INT
  246. ,@compIdResult VARCHAR(300)
  247. ,@perDayCustomerLimit MONEY
  248. DECLARE @controlNoEncrypted VARCHAR(20)
  249. DECLARE @csMasterId INT
  250. ,@complianceRes VARCHAR(20)
  251. ,@totalRows INT
  252. ,@count INT
  253. ,@compFinalRes VARCHAR(20)
  254. DECLARE @csMasterRec TABLE (
  255. rowId INT IDENTITY(1, 1)
  256. ,masterId INT
  257. )
  258. IF ISNULL(@sBranch, 0) = 0
  259. SELECT @sBranch = agentId
  260. FROM applicationUsers WITH (NOLOCK)
  261. WHERE userName = @user
  262. DECLARE @customerTotalAmt2 MONEY = 0
  263. DECLARE @errorCode CHAR(1) = 0
  264. DECLARE @tellerBalance MONEY
  265. ,@tellerLimit MONEY
  266. ,@sendPerTransaction MONEY
  267. ,@vaultBalance MONEY
  268. ,@vaultLimit MONEY
  269. SELECT @sfName = LTRIM(RTRIM(@sfName))
  270. ,@smName = LTRIM(RTRIM(@smName))
  271. ,@slName = LTRIM(RTRIM(@slName))
  272. ,@slName2 = LTRIM(RTRIM(@slName2))
  273. ,@rfName = LTRIM(RTRIM(@rfName))
  274. ,@rmName = LTRIM(RTRIM(@rmName))
  275. ,@rlName = LTRIM(RTRIM(@rlName))
  276. ,@rlName2 = LTRIM(RTRIM(@rlName2))
  277. IF @salary = 'undefined'
  278. SET @salary = NULL
  279. IF @salaryRange = 'undefined'
  280. SET @salaryRange = NULL
  281. IF @pBankBranchName IN (
  282. 'Select'
  283. ,'undefined'
  284. )
  285. SET @pBankBranchName = 'Any Branch'
  286. IF @rIdType IN (
  287. 'Select..'
  288. ,'Select'
  289. )
  290. SET @rIdType = NULL
  291. --CHECK IF SC IS ALLOWED TO EDIT BY USER OR NOT
  292. DECLARE @HAS_RIGHT_EDIT_SC CHAR(1) = 'N'
  293. SELECT @HAS_RIGHT_EDIT_SC = dbo.FNAHasRight(@user, '40101440')
  294. SET @raccountNo = UPPER(REPLACE(@raccountNo, ' ', ''))
  295. IF ISNULL(@isManualSc, 'N') = 'Y'
  296. AND @HAS_RIGHT_EDIT_SC = 'N'
  297. BEGIN
  298. SELECT '1' ErrCode
  299. ,'Invalid attempt to calculate SC manually!' Msg
  300. ,NULL id
  301. RETURN
  302. END
  303. IF @flag = 'v-referral'
  304. BEGIN
  305. DECLARE @IS_ACTIVE BIT
  306. SELECT @IS_ACTIVE = IS_ACTIVE
  307. FROM REFERRAL_AGENT_WISE(NOLOCK)
  308. WHERE REFERRAL_CODE = @introducer
  309. IF @IS_ACTIVE IS NULL
  310. BEGIN
  311. SELECT '1' ErrCode
  312. ,'Invalid referral code!' Msg
  313. ,NULL id
  314. RETURN
  315. END
  316. IF @IS_ACTIVE = 0
  317. BEGIN
  318. SELECT '1' ErrCode
  319. ,'Disabled referral passed!' Msg
  320. ,NULL id
  321. RETURN
  322. END
  323. SELECT '0' ErrCode
  324. ,'Success!' Msg
  325. ,NULL id
  326. RETURN
  327. END
  328. IF @flag IN (
  329. 'V'
  330. ,'I'
  331. )
  332. BEGIN
  333. IF ISNULL(@senderId, 0) = 0
  334. OR (ISNULL(@senderId, '') = '')
  335. BEGIN
  336. SELECT '1' ErrCode
  337. ,'Invalid sender selected, please refresh page and try sending again!' Msg
  338. ,NULL id
  339. RETURN
  340. END
  341. IF NOT EXISTS (
  342. SELECT 'X'
  343. FROM countryIdType CID WITH (NOLOCK)
  344. INNER JOIN staticDataValue SV WITH (NOLOCK) ON CID.IdTypeId = SV.valueId
  345. INNER JOIN (
  346. SELECT IDTYPE
  347. FROM CUSTOMERMASTER(NOLOCK)
  348. WHERE CUSTOMERID = @senderId
  349. ) CM ON CM.IDTYPE = SV.VALUEID
  350. WHERE countryId = 233
  351. AND ISNULL(isDeleted, 'N') <> 'Y'
  352. AND ISNULL(SV.ISACTIVE, 'Y') = 'Y'
  353. AND (
  354. spFlag IS NULL
  355. OR ISNULL(spFlag, 0) = 5200
  356. )
  357. )
  358. BEGIN
  359. SELECT '1' ErrCode
  360. ,'Customer ID type is not valid, please update ID details first!' Msg
  361. ,NULL id
  362. RETURN
  363. END
  364. --CHECKING OF BRANCH/USER CASH HOLD LIMIT
  365. IF EXISTS (
  366. SELECT *
  367. FROM AGENTMASTER
  368. WHERE AGENTID = @SAGENT
  369. AND ISINTL = 1
  370. )
  371. AND ISNULL(@INTRODUCER, '') <> ''
  372. BEGIN
  373. SELECT '1' ErrCode
  374. ,'Agent''s and introducer can not be selected at same time!' Msg
  375. ,NULL id
  376. RETURN
  377. END
  378. DECLARE @RULETYPE CHAR(1)
  379. ,@LIMITERRORCODE INT
  380. ,@BRANCH_ID_FOR_LIMIT VARCHAR(20)
  381. ,@INTRODUCER_LIMIT VARCHAR(20)
  382. IF NOT EXISTS (
  383. SELECT *
  384. FROM APPLICATIONUSERS(NOLOCK)
  385. WHERE USERNAME = @USER
  386. AND AGENTID = @SAGENT
  387. )
  388. AND ISNULL(@INTRODUCER, '') = ''
  389. SET @INTRODUCER_LIMIT = @SAGENT
  390. ELSE IF ISNULL(@INTRODUCER, '') <> ''
  391. SET @INTRODUCER_LIMIT = @INTRODUCER
  392. EXEC PROC_CHECK_BRANCH_USER_CASH_HOLD_LIMIT @USER = @USER
  393. ,@INTRODUCER = @INTRODUCER_LIMIT
  394. ,@CAMT = @CAMT
  395. ,@ERRORCODE = @LIMITERRORCODE OUT
  396. ,@ERRORMSG = @msg OUT
  397. ,@RULETYPE = @RULETYPE OUT
  398. --select @RULETYPE,@ERRORCODE
  399. IF @LIMITERRORCODE <> 0
  400. AND @RULETYPE = 'B'
  401. AND @COLLMODE = 'CASH COLLECT'
  402. BEGIN
  403. SELECT '1' ErrCode
  404. ,'Branch/User cash hold limit is exceeded, please contact head office!' Msg
  405. ,NULL id
  406. RETURN
  407. END
  408. --CHECK IF PAYOUT PARTNER IS ACTIVE OR NOT AND CHECK STATUS
  409. IF @payoutPartner IS NULL
  410. BEGIN
  411. SELECT '1' ErrCode
  412. ,'Payout partner not defined yet for receiving country!' Msg
  413. ,NULL id
  414. RETURN
  415. END
  416. IF NOT EXISTS (
  417. SELECT 1
  418. FROM TblPartnerwiseCountry(NOLOCK)
  419. WHERE AgentId = @payoutPartner
  420. AND IsActive = 1
  421. )
  422. AND @PCOUNTRY <> 'VIETNAM'
  423. BEGIN
  424. SELECT '1' ErrCode
  425. ,'Payout partner is not active please retry by choosing country again!' Msg
  426. ,NULL id
  427. RETURN
  428. END
  429. SELECT @exRateCalByPartner = ISNULL(exRateCalByPartner, 0)
  430. FROM TblPartnerwiseCountry(NOLOCK)
  431. WHERE CountryId = @pCountryId
  432. AND IsActive = 1
  433. AND ISNULL(PaymentMethod, @deliveryMethodId) = @deliveryMethodId
  434. --CHECKING CUSTOMER KYC STATUS
  435. DECLARE @kycStatus INT
  436. SELECT @kycStatus = kycStatus
  437. FROM TBL_CUSTOMER_KYC(NOLOCK)
  438. WHERE CUSTOMERID = @senderId
  439. AND ISDELETED = 0
  440. --AND kycStatus=11044
  441. ORDER BY KYC_DATE
  442. --IF ISNULL(@kycStatus, 0) <> 11044
  443. --BEGIN
  444. -- IF @kycStatus IS NOT NULL
  445. -- SELECT @MSG = 'KYC for selected customer is not completed, it is in status:' + detailTitle
  446. -- FROM staticDataValue(NOLOCK)
  447. -- WHERE valueId = @kycStatus
  448. -- ELSE
  449. -- SELECT @MSG = 'Please complete KYC status first'
  450. -- SELECT '1' ErrCode
  451. -- ,@MSG Msg
  452. -- ,NULL id
  453. -- RETURN
  454. --END
  455. --GET PAYOUT AGENT DETAILS
  456. SELECT @PAGENT = AGENTID
  457. FROM AGENTMASTER(NOLOCK)
  458. WHERE PARENTID = @payoutPartner
  459. AND ISNULL(ISSETTLINGAGENT, 'N') = 'Y';
  460. SELECT @pSuperAgent = sSuperAgent
  461. ,@pSuperAgentName = sSuperAgentName
  462. ,@pAgent = sAgent
  463. ,@pAgentName = sAgentName
  464. ,@pBranch = sBranch
  465. ,@pBranchName = sBranchName
  466. FROM dbo.FNAGetBranchFullDetails(@PAGENT)
  467. SELECT @sSuperAgent = sSuperAgent
  468. ,@sSuperAgentName = sSuperAgentName
  469. ,@sAgent = sAgent
  470. ,@sAgentName = sAgentName
  471. ,@sBranch = sBranch
  472. ,@sBranchName = sBranchName
  473. FROM dbo.FNAGetBranchFullDetails(@sBranch)
  474. END
  475. SET @sAgentCommCurrency = 'JPY'
  476. IF @flag = 'acBal' --Get Available Account Balance
  477. BEGIN
  478. SELECT @pCountryId = am.agentCountryId
  479. FROM applicationUsers au WITH (NOLOCK)
  480. INNER JOIN agentMaster am WITH (NOLOCK) ON au.agentId = am.agentId
  481. WHERE userName = @user
  482. SELECT TOP 1 @collCurr = CM.currencyCode
  483. FROM currencyMaster CM WITH (NOLOCK)
  484. INNER JOIN countryCurrency CC WITH (NOLOCK) ON CM.currencyId = CC.currencyId
  485. WHERE CC.countryId = @pCountryId
  486. AND ISNULL(cc.isDeleted, 'N') = 'N'
  487. AND ISNULL(CC.isDefault, 'N') = 'Y'
  488. -->> checking per day country send limit
  489. SELECT @limitBal = D.amount
  490. FROM csMaster M WITH (NOLOCK)
  491. INNER JOIN csDetail D WITH (NOLOCK) ON M.csMasterId = D.csMasterId --csDetailId CHANGED BY ARJUN
  492. WHERE sCountry = @pCountryId
  493. AND ISNULL(M.isActive, 'Y') = 'Y'
  494. AND ISNULL(D.isActive, 'Y') = 'Y'
  495. IF @agentId IS NULL
  496. SELECT @sBranch = agentId
  497. FROM applicationUsers WITH (NOLOCK)
  498. WHERE userName = @user
  499. ELSE
  500. SELECT @sBranch = @agentId
  501. SELECT @sAgent = parentId
  502. ,@agentType = agentType
  503. FROM agentMaster WITH (NOLOCK)
  504. WHERE agentId = @sBranch
  505. IF @agentType = 2903
  506. SET @sAgent = @sBranch
  507. SELECT @sSuperAgent = parentId
  508. FROM agentMaster WITH (NOLOCK)
  509. WHERE agentId = @sAgent
  510. SELECT @settlingAgent = agentId
  511. FROM agentMaster
  512. WHERE agentId = @sBranch
  513. AND isSettlingAgent = 'Y'
  514. IF @settlingAgent IS NULL
  515. SELECT @settlingAgent = agentId
  516. FROM agentMaster WITH (NOLOCK)
  517. WHERE agentId = @sAgent
  518. AND isSettlingAgent = 'Y'
  519. IF @settlingAgent IS NULL
  520. SELECT @settlingAgent = agentId
  521. FROM agentMaster WITH (NOLOCK)
  522. WHERE agentId = @sSuperAgent
  523. AND isSettlingAgent = 'Y'
  524. DECLARE @limit MONEY
  525. ,@limitCurr VARCHAR(3)
  526. ,@cRateAgent FLOAT
  527. SELECT @limit = ISNULL(dbo.FNAGetLimitBalIRH(@settlingAgent), 0)
  528. SELECT @limitCurr = currency
  529. FROM creditLimitInt WITH (NOLOCK)
  530. WHERE agentId = @settlingAgent
  531. AND ISNULL(isDeleted, 'N') = 'N'
  532. AND ISNULL(isActive, 'N') = 'Y'
  533. SELECT availableBal = @limit
  534. ,balCurrency = @collCurr
  535. ,limExpiry = ISNULL(CONVERT(VARCHAR, expiryDate, 101), 'N/A')
  536. ,sCountryLimit = ISNULL(@limitBal, 0)
  537. ,sCurr = @collCurr
  538. ,tellerBanalce = 0
  539. ,txnPerDayCustomerLimit = dbo.FNAGetPerDayCustomerLimit(@settlingAgent)
  540. FROM creditLimitInt cl
  541. WHERE agentId = @settlingAgent
  542. END
  543. IF @flag = 'acBalByAgentId' --Get Available Account Balance
  544. BEGIN
  545. SET @pCountryId = 233;
  546. --SELECT
  547. -- @pCountryId = am.agentCountryId
  548. --FROM applicationUsers au WITH(NOLOCK)
  549. --INNER JOIN agentMaster am WITH(NOLOCK) ON au.agentId = am.agentId
  550. --WHERE userName = @user
  551. SELECT TOP 1 @collCurr = CM.currencyCode
  552. FROM currencyMaster CM WITH (NOLOCK)
  553. INNER JOIN countryCurrency CC WITH (NOLOCK) ON CM.currencyId = CC.currencyId
  554. WHERE CC.countryId = @pCountryId
  555. AND ISNULL(cc.isDeleted, 'N') = 'N'
  556. AND ISNULL(CC.isDefault, 'N') = 'Y'
  557. -->> checking per day country send limit
  558. SELECT @limitBal = D.amount
  559. FROM csMaster M WITH (NOLOCK)
  560. INNER JOIN csDetail D WITH (NOLOCK) ON M.csMasterId = D.csMasterId --csDetailId CHANGED BY ARJUN
  561. WHERE sCountry = @pCountryId
  562. AND ISNULL(M.isActive, 'Y') = 'Y'
  563. AND ISNULL(D.isActive, 'Y') = 'Y'
  564. --IF @agentId IS NULL
  565. -- SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  566. --ELSE
  567. -- SELECT @sBranch = @agentId
  568. SELECT @sAgent = parentId
  569. ,@agentType = agentType
  570. FROM agentMaster WITH (NOLOCK)
  571. WHERE agentId = @sBranch
  572. IF @agentType = 2903
  573. SET @sAgent = @sBranch
  574. SELECT @sSuperAgent = parentId
  575. FROM agentMaster WITH (NOLOCK)
  576. WHERE agentId = @sAgent
  577. SELECT @settlingAgent = agentId
  578. FROM agentMaster
  579. WHERE agentId = @sBranch
  580. AND isSettlingAgent = 'Y'
  581. IF @settlingAgent IS NULL
  582. SELECT @settlingAgent = agentId
  583. FROM agentMaster WITH (NOLOCK)
  584. WHERE agentId = @sAgent
  585. AND isSettlingAgent = 'Y'
  586. IF @settlingAgent IS NULL
  587. SELECT @settlingAgent = agentId
  588. FROM agentMaster WITH (NOLOCK)
  589. WHERE agentId = @sSuperAgent
  590. AND isSettlingAgent = 'Y'
  591. DECLARE @limitAmt MONEY
  592. ,@limitCurrency VARCHAR(3)
  593. ,@cRateAgentAmt FLOAT
  594. ,@userId INT
  595. ,@user1 VARCHAR(50) = NULL
  596. ,@holdType VARCHAR(10) = NULL
  597. IF EXISTS (
  598. SELECT 1
  599. FROM dbo.applicationUsers
  600. WHERE agentId = @sBranch
  601. AND userName = @user
  602. )
  603. BEGIN
  604. SELECT @user1 = @user
  605. ,@sBranch = NULL
  606. END
  607. --EXEC proc_sendIRH @flag = 'acBalByAgentId', @user = 'anupam', @sBranch = '394393'
  608. --EXEC proc_sendIRH @flag = 'acBalByAgentId', @user = 'anupam', @sBranch = '394392'
  609. SELECT @limitAmt = availableLimit
  610. ,@holdType = CASE
  611. WHEN ruleType = 'H'
  612. THEN 'Hold'
  613. ELSE 'Block'
  614. END
  615. FROM DBO.FNAGetUserCashLimitDetails(@user1, @sBranch)
  616. --SELECT @limitAmt = ISNULL(dbo.proc_checkUserAvailableBalance(@settlingAgent), 0)
  617. SELECT @limitCurrency = 'JPY' -- FROM creditLimitInt WITH(NOLOCK)
  618. --WHERE agentId = @settlingAgent AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y'
  619. SELECT availableBal = @limitAmt
  620. ,balCurrency = @collCurr
  621. ,limExpiry = 'N/A'
  622. ,sCountryLimit = ISNULL(@limitBal, 0)
  623. ,sCurr = @collCurr
  624. ,tellerBanalce = 0
  625. ,txnPerDayCustomerLimit = dbo.FNAGetPerDayCustomerLimit(@settlingAgent)
  626. ,holdType = @holdType
  627. END
  628. IF @flag = 'getReferralBal'
  629. BEGIN
  630. SELECT totalLimit
  631. ,availableLimit
  632. FROM DBO.FNAGetBranchCashLimitDetails(@referralCode, 'R')
  633. END
  634. ELSE IF @flag = 'v' --Validation
  635. BEGIN
  636. DECLARE @AVAILABLEBALANCE MONEY
  637. IF @nCust = 'N'
  638. BEGIN
  639. IF ISNULL(@senderId, 0) = 0
  640. BEGIN
  641. EXEC proc_errorHandler 1
  642. ,'Please choose Sender'
  643. ,NULL
  644. RETURN
  645. END
  646. SELECT @AVAILABLEBALANCE = DBO.FNAGetCustomerAvailableBalance(@senderId)
  647. IF (ISNULL(@AVAILABLEBALANCE, 0) < @CAMT)
  648. AND (@collMode = 'Bank Deposit')
  649. BEGIN
  650. EXEC proc_errorHandler 1
  651. ,'Collect Amount can not be greater then Available Balance!'
  652. ,NULL
  653. RETURN
  654. END
  655. END
  656. IF @sfName IS NULL
  657. BEGIN
  658. EXEC proc_errorHandler 1
  659. ,'Sender First Name missing'
  660. ,NULL
  661. RETURN
  662. END
  663. IF @sNaCountry IS NULL
  664. BEGIN
  665. EXEC proc_errorHandler 1
  666. ,' Sender Native Country missing'
  667. ,NULL
  668. RETURN
  669. END
  670. IF @rfName IS NULL
  671. BEGIN
  672. EXEC proc_errorHandler 1
  673. ,'New Receiver First Name missing'
  674. ,NULL
  675. RETURN
  676. END
  677. IF ISNULL(@deliveryMethod, '') = ''
  678. BEGIN
  679. EXEC proc_errorHandler 1
  680. ,'Please choose payment mode'
  681. ,NULL
  682. RETURN
  683. END
  684. IF @serviceCharge IS NULL
  685. BEGIN
  686. EXEC proc_errorHandler 1
  687. ,'Service Charge missing'
  688. ,NULL
  689. RETURN
  690. END
  691. IF ISNULL(@tAmt, 0) = 0
  692. BEGIN
  693. EXEC proc_errorHandler 1
  694. ,'Transfer Amount missing'
  695. ,NULL
  696. RETURN
  697. END
  698. IF ISNULL(@exRate, 0) = 0
  699. BEGIN
  700. EXEC proc_errorHandler 1
  701. ,'Exchange Rate missing'
  702. ,NULL
  703. RETURN
  704. END
  705. IF ISNULL(@cAmt, 0) = 0
  706. BEGIN
  707. EXEC proc_errorHandler 1
  708. ,'Collection Amount is missing. Cannot send transaction'
  709. ,NULL
  710. RETURN
  711. END
  712. IF @serviceCharge > @cAmt
  713. BEGIN
  714. EXEC proc_errorHandler 1
  715. ,'Collection Amount is less than service charge.'
  716. ,NULL
  717. RETURN
  718. END
  719. --IF @occupation IS NULL
  720. --BEGIN
  721. -- EXEC proc_errorHandler 1, 'Occupation is missing', NULL
  722. -- RETURN
  723. --END
  724. --*****Payout Agent*****
  725. IF @deliveryMethod = 'Bank Deposit'
  726. BEGIN
  727. IF @pBank IS NULL
  728. BEGIN
  729. EXEC proc_errorHandler 1
  730. ,'Please select bank'
  731. ,NULL
  732. RETURN
  733. END
  734. IF @raccountNo IS NULL
  735. BEGIN
  736. EXEC proc_errorHandler 1
  737. ,'Account number cannot be blank'
  738. ,NULL
  739. RETURN
  740. END
  741. END
  742. IF (@pBankBranch IS NOT NULL)
  743. BEGIN
  744. SELECT @pBank = parentId
  745. ,@pBankBranchName = agentName
  746. FROM agentMaster WITH (NOLOCK)
  747. WHERE agentId = @pBankBranch
  748. SELECT @pBankName = agentName
  749. FROM agentMaster WITH (NOLOCK)
  750. WHERE agentId = @pBank
  751. END
  752. DECLARE @visaStatusText VARCHAR(200)
  753. SELECT @sendingCustType = customerType
  754. ,@visaStatus = visaStatus
  755. ,@visaStatusText = SV.detailTitle
  756. FROM dbo.customerMaster CM WITH (NOLOCK)
  757. LEFT JOIN STATICDATAVALUE SV(NOLOCK) ON SV.valueId = CM.visaStatus
  758. WHERE customerId = @senderId
  759. SELECT @receivingCustType = customerType
  760. FROM dbo.customerMaster WITH (NOLOCK)
  761. WHERE customerId = @benId
  762. --4. Exchange Rate Checking
  763. --SET @pAgent=1006
  764. --SET @pSuperAgent=1005
  765. --SET @pBranch=1007
  766. IF @pCountryId = 151
  767. AND @deliveryMethodId = 1
  768. BEGIN
  769. SELECT AgentId
  770. INTO #AgentListValidate
  771. FROM agentMaster(NOLOCK)
  772. WHERE extCode = 'NP ANYWHERE'
  773. SELECT @exRate = customerRate
  774. ,@sCurrCostRate = sCurrCostRate
  775. ,@sCurrHoMargin = sCurrHoMargin
  776. ,@sCurrAgentMargin = sCurrAgentMargin
  777. ,@pCurrCostRate = pCurrCostRate
  778. ,@pCurrHoMargin = pCurrHoMargin
  779. ,@pCurrAgentMargin = pCurrAgentMargin
  780. FROM (
  781. SELECT ROW_NUMBER() OVER (
  782. ORDER BY CUSTOMERRATE DESC
  783. ) ROW_NUM
  784. ,customerRate
  785. ,sCurrCostRate
  786. ,sCurrHoMargin
  787. ,sCurrAgentMargin
  788. ,pCurrCostRate
  789. ,pCurrHoMargin
  790. ,pCurrAgentMargin
  791. ,agentCrossSettRate
  792. ,treasuryTolerance
  793. ,customerPremium
  794. ,sharingValue
  795. ,sharingType
  796. FROM #AgentListValidate A
  797. CROSS APPLY dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, AgentId, @pCurr, @deliveryMethodId)
  798. ) X
  799. WHERE X.ROW_NUM = 1
  800. END
  801. ELSE
  802. BEGIN
  803. SELECT @exRate = customerRate
  804. ,@sCurrCostRate = sCurrCostRate
  805. ,@sCurrHoMargin = sCurrHoMargin
  806. ,@sCurrAgentMargin = sCurrAgentMargin
  807. ,@pCurrCostRate = pCurrCostRate
  808. ,@pCurrHoMargin = pCurrHoMargin
  809. ,@pCurrAgentMargin = pCurrAgentMargin
  810. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  811. END
  812. IF @exRate IS NULL
  813. BEGIN
  814. EXEC proc_errorHandler 1
  815. ,'Transaction cannot be proceed. Exchange Rate not defined'
  816. ,NULL
  817. RETURN
  818. END
  819. --New code added, referral code add #arjun
  820. --EXEC PROC_Customer_LoyaltyV2 @flag = 'check-eligible-v2'
  821. -- ,@isEligible = @isEligible OUT
  822. -- ,@referralCode = @introducer
  823. -- ,@tranCount = @trancount OUT
  824. -- ,@schemeCount = @schemeCount OUT
  825. -- ,@customerId = @senderId
  826. -- ,@createdFrom = 'I'
  827. --End of Exchange Rate Checking
  828. --5. Service Charge Checking
  829. DECLARE @tAmtSC MONEY
  830. --IF EXISTS (
  831. -- SELECT TOP 1 1
  832. -- FROM REFERRAL_AGENT_WISE
  833. -- WHERE REFERRAL_TYPE_CODE IN (
  834. -- 'RB'
  835. -- ,'RC'
  836. -- )
  837. -- AND REFERRAL_CODE = @introducer
  838. -- )
  839. --BEGIN
  840. -- EXEC PROC_Customer_Loyalty @flag = 'check-eligible'
  841. -- ,@isEligible = @isEligible OUT
  842. --END
  843. --EXEC proc_Customer_Loyalty @flag = 'get-tranCount'
  844. -- ,@tranCount = @trancount OUT
  845. -- ,@customerId = @senderId
  846. --SELECT TOP 1 @schemeCount = txnCount
  847. --FROM schemeSetup(NOLOCK)
  848. --ORDER BY createdDate DESC
  849. IF @calcBy = 'cAmt'
  850. BEGIN
  851. IF @isEligible = 'Y'
  852. BEGIN
  853. SET @iServiceCharge = 0
  854. END
  855. ELSE
  856. BEGIN
  857. IF ISNULL(@isManualSc, 'N') = 'N'
  858. BEGIN
  859. SELECT @iServiceCharge = ISNULL(amount, - 1)
  860. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
  861. END
  862. ELSE
  863. BEGIN
  864. SET @iServiceCharge = ISNULL(@manualSc, 0)
  865. print @cAmt
  866. print @tAmt
  867. print @serviceCharge
  868. print @rewardAmt
  869. IF @cAmt <> @tAmt + @serviceCharge - @rewardAmt
  870. BEGIN
  871. EXEC proc_errorHandler 1
  872. ,'Please click on Calculate or Click out side the Service Charge input Box, after editing Service Charge!'
  873. ,NULL
  874. RETURN
  875. END
  876. END
  877. END
  878. END
  879. ELSE
  880. BEGIN
  881. --SET @tAmt = ROUND(@pAmt/(@exRate + @exRateOffer),0)
  882. SET @tAmtSC = CEILING(@pAmt / (@exRate))
  883. IF @isEligible = 'Y'
  884. BEGIN
  885. SET @iServiceCharge = 0
  886. END
  887. ELSE
  888. BEGIN
  889. IF ISNULL(@isManualSc, 'N') = 'N'
  890. BEGIN
  891. SELECT @iServiceCharge = ISNULL(amount, - 1)
  892. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmtSC, @collCurr)
  893. END
  894. ELSE
  895. BEGIN
  896. SET @iServiceCharge = ISNULL(@manualSc, 0)
  897. IF @cAmt <> @tAmt + @iServiceCharge - @rewardAmt
  898. BEGIN
  899. EXEC proc_errorHandler 1
  900. ,'Please click on Calculate or Click out side the Service Charge input Box, after editing Service Charge!'
  901. ,NULL
  902. RETURN
  903. END
  904. END
  905. END
  906. END
  907. IF @iServiceCharge = - 1
  908. AND ISNULL(@isManualSc, 'N') = 'N'
  909. BEGIN
  910. EXEC proc_errorHandler 1
  911. ,'Transaction cannot be proceed. Service Charge is not defined'
  912. ,NULL
  913. RETURN
  914. END
  915. SET @iServiceCharge = ROUND(@iServiceCharge, 2)
  916. IF (@iServiceCharge <> @serviceCharge)
  917. AND (ISNULL(@isManualSc, 'N') = 'N')
  918. BEGIN
  919. EXEC proc_errorHandler 1
  920. ,'Transaction cannot be proceed. Amount detail not match. Please check service charge. Verify'
  921. ,NULL
  922. RETURN
  923. END
  924. IF @schemeCode IS NOT NULL
  925. BEGIN
  926. DECLARE @scValue MONEY
  927. ,@scAction CHAR(2)
  928. ,@scOffer MONEY
  929. ,@exRateOffer FLOAT
  930. ,@scDiscount MONEY
  931. END
  932. SET @iCustomerRate = @exRate + ISNULL(@schemePremium, 0)
  933. IF @pCurr = 'VND'
  934. BEGIN
  935. IF @calcBy = 'cAmt'
  936. BEGIN
  937. SET @iTAmt = @cAmt - @iServiceCharge
  938. SET @iPAmt = @iTAmt * @iCustomerRate
  939. --IF @place IS NOT NULL
  940. -- SET @pAmt = ROUND(@pAmt, -@place, 1)
  941. END
  942. ELSE
  943. BEGIN
  944. SET @iPAmt = @pAmt
  945. END
  946. END
  947. ELSE
  948. BEGIN
  949. SET @iTAmt = @cAmt - @iServiceCharge + @rewardAmt
  950. SELECT @place = place
  951. ,@currDecimal = currDecimal
  952. FROM currencyPayoutRound WITH (NOLOCK)
  953. WHERE ISNULL(isDeleted, 'N') = 'N'
  954. AND currency = @pCurr
  955. AND ISNULL(tranType, @deliveryMethodId) = @deliveryMethodId
  956. SET @currDecimal = ISNULL(@currDecimal, 0)
  957. SET @place = ISNULL(@place, 0)
  958. SET @iPAmt = @iTAmt * @iCustomerRate
  959. --SET @iPAmt = ROUND(@iPAmt, @currDecimal, 1)
  960. --IF @place IS NOT NULL
  961. -- SET @iPAmt = ROUND(@iPAmt, -@place, 1)
  962. END
  963. IF @pAmt - @iPAmt <= 1
  964. SET @iPAmt = @pAmt
  965. IF @iPAmt <> @pAmt
  966. BEGIN
  967. print 'a'
  968. print @iPAmt
  969. print @pAmt
  970. EXEC proc_errorHandler 1
  971. ,'Amount detail not match. Please re-calculate the amount again.'
  972. ,NULL
  973. RETURN
  974. END
  975. --End of service charge Checking
  976. --send agent commission if it is external agent
  977. DECLARE @sSettlementRate FLOAT
  978. ,@pSettlementRate FLOAT
  979. SET @sSettlementRate = @sCurrCostRate + @sCurrHoMargin
  980. SET @pSettlementRate = @pCurrCostRate - @pCurrHoMargin
  981. --START OFAC Checking
  982. DECLARE @receiverName VARCHAR(200)
  983. ,@checkNameBy VARCHAR(10)
  984. ,@matchBy CHAR(1)
  985. SELECT @checkNameBy = TRACK_BY
  986. FROM OFACSETTING(NOLOCK)
  987. IF @checkNameBy IS NULL
  988. SET @checkNameBy = 'OFAC'
  989. IF (ISNULL(@senderId, '') = '')
  990. SELECT @senderName = @sfName + ISNULL(' ' + @smName, '') + ISNULL(' ' + @slName, '') + ISNULL(' ' + @slName2, '')
  991. ELSE
  992. SELECT @senderName = firstName + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName1, '') + ISNULL(' ' + lastName2, '')
  993. FROM dbo.customerMaster WITH (NOLOCK)
  994. WHERE customerId = @senderId
  995. SELECT @receiverName = @rfName + ISNULL(' ' + @rmName, '') + ISNULL(' ' + @rlName, '') + ISNULL(' ' + @rlName2, '')
  996. DECLARE @receiverOfacRes VARCHAR(MAX)
  997. ,@matchPercentage INT
  998. SELECT @matchPercentage = MATCH_PERCENTAGE
  999. FROM OFACSETTING
  1000. IF @checkNameBy = 'OFAC'
  1001. BEGIN
  1002. EXEC proc_ofacTracker @flag = 't'
  1003. ,@name = @senderName
  1004. ,@Result = @ofacRes OUTPUT
  1005. IF @senderName = @receiverName
  1006. BEGIN
  1007. SET @receiverOfacRes = @ofacRes
  1008. END
  1009. ELSE
  1010. BEGIN
  1011. EXEC proc_ofacTracker @flag = 't'
  1012. ,@name = @receiverName
  1013. ,@Result = @receiverOfacRes OUTPUT
  1014. END
  1015. END
  1016. ELSE
  1017. BEGIN
  1018. SELECT @ofacRes = Dowjones.[dbo].[DJ_GET_SUSPICIOUS_NAME_MATCH_IDS_V2](@senderName)
  1019. IF @senderName = @receiverName
  1020. BEGIN
  1021. SET @receiverOfacRes = @ofacRes
  1022. END
  1023. ELSE
  1024. BEGIN
  1025. SELECT @receiverOfacRes = Dowjones.[dbo].[DJ_GET_SUSPICIOUS_NAME_MATCH_IDS_V2](@receiverName)
  1026. END
  1027. END
  1028. DECLARE @result VARCHAR(MAX)
  1029. IF ISNULL(@ofacRes, '') <> ''
  1030. BEGIN
  1031. SET @matchBy = 'S'
  1032. SET @ofacReason = 'Matched by sender name'
  1033. END
  1034. IF ISNULL(@receiverOfacRes, '') <> ''
  1035. BEGIN
  1036. SET @matchBy = 'R'
  1037. IF @senderName <> @receiverName
  1038. SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes)
  1039. SET @ofacReason = 'Matched by receiver name'
  1040. END
  1041. IF ISNULL(@ofacRes, '') <> ''
  1042. AND ISNULL(@receiverOfacRes, '') <> ''
  1043. BEGIN
  1044. SET @matchBy = 'B'
  1045. SET @ofacReason = 'Matched by both sender name and receiver name'
  1046. END
  1047. --******************BEGINING OF NEW CUSTOMER CREATION AND ENROLLMENT********************************
  1048. DECLARE @sIdTypeId INT
  1049. SELECT @sIdTypeId = valueId
  1050. FROM staticDataValue WITH (NOLOCK)
  1051. WHERE detailTitle = @sIdType
  1052. AND typeID = 1300
  1053. SELECT @sfName = UPPER(@sfName)
  1054. ,@smName = UPPER(@smName)
  1055. ,@slName = UPPER(@slName)
  1056. ,@slName2 = UPPER(@slName2)
  1057. SELECT @rfName = UPPER(@rfName)
  1058. ,@rmName = UPPER(@rmName)
  1059. ,@rlName = UPPER(@rlName)
  1060. ,@rlName2 = UPPER(@rlName2)
  1061. --2. Begining of New customer Creation and enrollment or updating existing customer data---
  1062. SET @senderName = @sfName + ISNULL(' ' + @smName, '') + ISNULL(' ' + @slName, '') + ISNULL(' ' + @slName2, '')
  1063. SET @receiverName = @rfName + ISNULL(' ' + @rmName, '') + ISNULL(' ' + @rlName, '') + ISNULL(' ' + @rlName2, '')
  1064. DECLARE @sNaCountryId INT = (
  1065. SELECT countryId
  1066. FROM COUNTRYMASTER(NOLOCK)
  1067. WHERE COUNTRYNAME = @sNaCountry
  1068. )
  1069. --------#Register Receiver if not registered#---------------
  1070. DECLARE @rBankId INT = ISNULL(@pBank, @pAgent)
  1071. DECLARE @rBankBranchId INT = ISNULL(@pBankBranch, '')
  1072. EXEC PROC_CHECK_RECEIVER_REGISTRATION @flag = 'i'
  1073. ,@user = @user
  1074. ,@rfName = @rfName
  1075. ,@rmName = @rmName
  1076. ,@rlName = @rlName
  1077. ,@receiverIdNo = @rIdNo
  1078. ,@receiverIdType = @rIdType
  1079. ,@receiverCountry = @pCountry
  1080. ,@receiverAdd = @rAdd1
  1081. ,@receiverCity = @rcity
  1082. ,@receiverMobile = @rMobile
  1083. ,@receiverPhone = @rTel
  1084. ,@receiverEmail = @rEmail
  1085. ,@receiverId = @receiverId OUT
  1086. ,@customerId = @senderId
  1087. ,@paymentMethodId = @deliveryMethodId
  1088. ,@rBankId = @rBankId
  1089. ,@rBankBranchId = @rBankBranchId
  1090. ,@rAccountNo = @raccountNo
  1091. ,@purpose = @purpose
  1092. ,@relationship = @relationship
  1093. ,@loginBranchId = @sBranch
  1094. ,@relationOther = @relationOther
  1095. ,@purposeOther = @purposeOther
  1096. ,@goodsType = @goodsType
  1097. ,@goodsOrigin = @goodsOrigin
  1098. ,@portOfShipment = @portOfShipment
  1099. --START Compliance Checking
  1100. DECLARE @complianceRuleId INT
  1101. ,@cAmtUSD MONEY
  1102. SELECT @sCurrCostRate = sCurrCostRate
  1103. ,@sCurrHoMargin = sCurrHoMargin
  1104. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  1105. IF @sCurrCostRate IS NULL
  1106. BEGIN
  1107. EXEC proc_errorHandler 1
  1108. ,'Transaction cannot be proceed. Exchange Rate not defined!'
  1109. ,NULL
  1110. RETURN
  1111. END
  1112. SET @sCountry = 'Japan'
  1113. --checking for visa status questionnaire
  1114. DECLARE @isVisaStatusQuestionnaire CHAR(1) = 'N'
  1115. IF EXISTS (
  1116. SELECT *
  1117. FROM VW_VISA_STATUS_QUESTIONNAIRE
  1118. WHERE VISA_ID = @visaStatus
  1119. )
  1120. BEGIN
  1121. SET @isVisaStatusQuestionnaire = 'Y'
  1122. END
  1123. IF ISNULL(@isAdditionalCDDI, 'N') = 'N'
  1124. BEGIN
  1125. CREATE TABLE #TBL_COMPLIANCE_RESULT (
  1126. ERROR_CODE INT
  1127. ,MSG VARCHAR(500)
  1128. ,RULE_ID INT
  1129. ,SHORT_MSG VARCHAR(100)
  1130. ,[TYPE] VARCHAR(10)
  1131. ,IS_D0C_REQUIRED BIT
  1132. )
  1133. INSERT INTO #TBL_COMPLIANCE_RESULT (
  1134. ERROR_CODE
  1135. ,MSG
  1136. ,RULE_ID
  1137. ,SHORT_MSG
  1138. ,[TYPE]
  1139. ,IS_D0C_REQUIRED
  1140. )
  1141. EXEC [PROC_COMPLIANCE_CHECKING_NEW] @flag = 'core'
  1142. ,@user = @user
  1143. ,@sIdType = @sIdType
  1144. ,@sIdNo = @sIdNo
  1145. ,@receiverName = @receiverName
  1146. ,@amount = @tAmt
  1147. ,@customerId = @senderId
  1148. ,@pCountryId = @pCountryId
  1149. ,@deliveryMethod = @deliveryMethodId
  1150. ,@professionId = @occupation
  1151. ,@receiverMobile = @rMobile
  1152. ,@accountNo = @raccountNo
  1153. ,@receiverId = @receiverId
  1154. ,@sNaCountryId = @sNaCountryId
  1155. ,@visaStatus = @visaStatus
  1156. IF EXISTS (
  1157. SELECT *
  1158. FROM #TBL_COMPLIANCE_RESULT
  1159. WHERE ERROR_CODE <> 0
  1160. )
  1161. BEGIN
  1162. --IF(@complienceErrorCode = 1)
  1163. --BEGIN
  1164. -- SELECT 101 errorCode,@shortMsg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  1165. --END
  1166. IF EXISTS (
  1167. SELECT *
  1168. FROM #TBL_COMPLIANCE_RESULT
  1169. WHERE ERROR_CODE IN (
  1170. 2
  1171. ,3
  1172. )
  1173. )
  1174. BEGIN
  1175. DELETE
  1176. FROM remitTranComplianceTemp
  1177. WHERE agentRefId = @agentRefId
  1178. INSERT remitTranComplianceTemp (
  1179. csDetailTranId
  1180. ,matchTranId
  1181. ,agentRefId
  1182. )
  1183. SELECT TOP 1 RULE_ID
  1184. ,NULL
  1185. ,@agentRefId
  1186. FROM #TBL_COMPLIANCE_RESULT
  1187. WHERE ERROR_CODE IN (
  1188. 2
  1189. ,3
  1190. )
  1191. ORDER BY ISNULL(IS_D0C_REQUIRED, 0) DESC
  1192. --SELECT 102 errorCode,@shortMsg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  1193. END
  1194. --IF(@complienceErrorCode = 3)
  1195. --BEGIN
  1196. -- SELECT 103 errorCode,@shortMsg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype
  1197. --END
  1198. DELETE
  1199. FROM ComplianceLog
  1200. WHERE agentRefId = @agentRefId
  1201. INSERT INTO ComplianceLog (
  1202. senderName
  1203. ,senderCountry
  1204. ,senderIdType
  1205. ,senderIdNumber
  1206. ,senderMobile
  1207. ,receiverName
  1208. ,receiverCountry
  1209. ,payOutAmt
  1210. ,complianceId
  1211. ,complianceReason
  1212. ,complainceDetailMessage
  1213. ,createdBy
  1214. ,createdDate
  1215. ,agentRefId
  1216. ,isDocumentRequired
  1217. )
  1218. SELECT @senderName
  1219. ,@sCountry
  1220. ,@sIdType
  1221. ,@sIdNo
  1222. ,@sMobile
  1223. ,@receiverName
  1224. ,@pCountry
  1225. ,@cAmt
  1226. ,RULE_ID
  1227. ,SHORT_MSG
  1228. ,MSG
  1229. ,@user
  1230. ,GETDATE()
  1231. ,@agentRefId
  1232. ,IS_D0C_REQUIRED
  1233. FROM #TBL_COMPLIANCE_RESULT
  1234. IF @isVisaStatusQuestionnaire = 'Y'
  1235. BEGIN
  1236. INSERT INTO ComplianceLog (
  1237. senderName
  1238. ,senderCountry
  1239. ,senderIdType
  1240. ,senderIdNumber
  1241. ,senderMobile
  1242. ,receiverName
  1243. ,receiverCountry
  1244. ,payOutAmt
  1245. ,complianceId
  1246. ,complianceReason
  1247. ,complainceDetailMessage
  1248. ,createdBy
  1249. ,createdDate
  1250. ,agentRefId
  1251. ,isDocumentRequired
  1252. )
  1253. SELECT @senderName
  1254. ,@sCountry
  1255. ,@sIdType
  1256. ,@sIdNo
  1257. ,@sMobile
  1258. ,@receiverName
  1259. ,@pCountry
  1260. ,@cAmt
  1261. ,0
  1262. ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  1263. ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  1264. ,@user
  1265. ,GETDATE()
  1266. ,@agentRefId
  1267. ,0
  1268. END
  1269. END
  1270. --END OFAC/Compliance data
  1271. END
  1272. IF (@ofacRes <> '')
  1273. BEGIN
  1274. IF @checkNameBy = 'OFAC'
  1275. BEGIN
  1276. SET @result = @ofacRes + '|' + ISNULL(@ofacReason, '')
  1277. SELECT errorCode = 100
  1278. ,msg = 'WARNING!!! This customer is listed on OFAC List'
  1279. ,id = @result
  1280. ,extra = @checkNameBy
  1281. EXEC proc_sendPageLoadData @flag = 'ofac'
  1282. ,@user = @user
  1283. ,@blackListIds = @ofacRes
  1284. END
  1285. ELSE
  1286. BEGIN
  1287. SET @result = @ofacRes + '|' + ISNULL(@ofacReason, '')
  1288. SELECT errorCode = 100
  1289. ,msg = 'WARNING!!! This customer is listed on DJ List'
  1290. ,id = @result
  1291. ,extra = @checkNameBy
  1292. EXEC proc_sendPageLoadData @flag = 'ofac'
  1293. ,@user = @user
  1294. ,@blackListIds = @ofacRes
  1295. ,@TRACK_BY = 'DJ'
  1296. END
  1297. END
  1298. SELECT *
  1299. INTO #TEMP_COMPLIANCE
  1300. FROM ComplianceLog CL(NOLOCK)
  1301. WHERE agentRefId = @agentRefId
  1302. AND CAST(CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1303. DECLARE @IS_TXN_IN_COMPLIANCE BIT = 0
  1304. ,@isDocumentRequired CHAR(1) = 'N'
  1305. ,@complianceChecked BIT = 0
  1306. IF EXISTS (
  1307. SELECT *
  1308. FROM #TEMP_COMPLIANCE
  1309. WHERE isDocumentRequired = 1
  1310. )
  1311. BEGIN
  1312. SET @isDocumentRequired = 'Y'
  1313. END
  1314. IF EXISTS (
  1315. SELECT 1
  1316. FROM #TEMP_COMPLIANCE
  1317. )
  1318. BEGIN
  1319. IF EXISTS (
  1320. SELECT 1
  1321. FROM #TEMP_COMPLIANCE CL
  1322. INNER JOIN csDetail CD(NOLOCK) ON CD.csDetailId = CL.complianceId
  1323. WHERE agentRefId = @agentRefId
  1324. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1325. AND nextAction = 'B'
  1326. )
  1327. BEGIN
  1328. SET @IS_TXN_IN_COMPLIANCE = 1
  1329. SELECT errorCode = 101
  1330. ,MSG = 'COMPLIANCE BLOCK'
  1331. ,id = @isVisaStatusQuestionnaire
  1332. ,compApproveRemark = 'COMPLIANCE BLOCK'
  1333. ,vtype = 'compliance'
  1334. ,isDocumentRequired = 'N'
  1335. SELECT id
  1336. ,csDetailRecId = ''
  1337. ,[S.N.] = ROW_NUMBER() OVER (
  1338. ORDER BY id
  1339. )
  1340. ,[Remarks] = complianceReason
  1341. ,[Action] = CASE
  1342. WHEN nextAction = 'H'
  1343. THEN 'HOLD'
  1344. WHEN nextAction = 'B'
  1345. THEN 'Blocked'
  1346. ELSE 'Questionnaire'
  1347. END
  1348. --,[Matched Tran ID] = ''
  1349. FROM #TEMP_COMPLIANCE CL
  1350. LEFT JOIN csDetail CD(NOLOCK) ON CD.csDetailId = CL.complianceId
  1351. WHERE agentRefId = @agentRefId
  1352. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1353. --AND nextAction = 'B'
  1354. ORDER BY CD.period
  1355. END
  1356. IF @IS_TXN_IN_COMPLIANCE = 0
  1357. AND EXISTS (
  1358. SELECT 1
  1359. FROM #TEMP_COMPLIANCE CL
  1360. INNER JOIN csDetail CD(NOLOCK) ON CD.csDetailId = CL.complianceId
  1361. WHERE agentRefId = @agentRefId
  1362. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1363. AND nextAction = 'Q'
  1364. )
  1365. BEGIN
  1366. SET @IS_TXN_IN_COMPLIANCE = 1
  1367. SELECT errorCode = 103
  1368. ,MSG = 'COMPLIANCE HOLD'
  1369. ,id = @isVisaStatusQuestionnaire
  1370. ,compApproveRemark = 'COMPLIANCE HOLD'
  1371. ,vtype = 'compliance'
  1372. ,isDocumentRequired = @isDocumentRequired
  1373. SELECT id
  1374. ,csDetailRecId = ''
  1375. ,[S.N.] = ROW_NUMBER() OVER (
  1376. ORDER BY id
  1377. )
  1378. ,[Remarks] = complianceReason
  1379. ,[Action] = CASE
  1380. WHEN nextAction = 'H'
  1381. THEN 'HOLD'
  1382. WHEN nextAction = 'B'
  1383. THEN 'Blocked'
  1384. ELSE 'Questionnaire'
  1385. END
  1386. --,[Matched Tran ID] = ''
  1387. FROM #TEMP_COMPLIANCE CL
  1388. LEFT JOIN csDetail CD(NOLOCK) ON CD.csDetailId = CL.complianceId
  1389. WHERE agentRefId = @agentRefId
  1390. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1391. --AND nextAction = 'Q'
  1392. ORDER BY CD.period
  1393. END
  1394. IF @IS_TXN_IN_COMPLIANCE = 0
  1395. AND EXISTS (
  1396. SELECT 1
  1397. FROM #TEMP_COMPLIANCE CL
  1398. INNER JOIN csDetail CD(NOLOCK) ON CD.csDetailId = CL.complianceId
  1399. WHERE agentRefId = @agentRefId
  1400. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1401. AND nextAction = 'H'
  1402. )
  1403. BEGIN
  1404. SELECT errorCode = 102
  1405. ,MSG = 'COMPLIANCE QUESTIONNAIRE'
  1406. ,id = @isVisaStatusQuestionnaire
  1407. ,compApproveRemark = 'COMPLIANCE QUESTIONAIRE'
  1408. ,vtype = 'compliance'
  1409. ,isDocumentRequired = @isDocumentRequired
  1410. SELECT id
  1411. ,csDetailRecId = ''
  1412. ,[S.N.] = ROW_NUMBER() OVER (
  1413. ORDER BY id
  1414. )
  1415. ,[Remarks] = complianceReason
  1416. ,[Action] = CASE
  1417. WHEN nextAction = 'H'
  1418. THEN 'HOLD'
  1419. WHEN nextAction = 'B'
  1420. THEN 'Blocked'
  1421. ELSE 'Questionnaire'
  1422. END
  1423. --,[Matched Tran ID] = ''
  1424. FROM #TEMP_COMPLIANCE CL
  1425. LEFT JOIN csDetail CD(NOLOCK) ON CD.csDetailId = CL.complianceId
  1426. WHERE agentRefId = @agentRefId
  1427. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1428. --AND nextAction = 'H'
  1429. ORDER BY CD.period
  1430. END
  1431. IF @IS_TXN_IN_COMPLIANCE = 0
  1432. AND EXISTS (
  1433. SELECT 1
  1434. FROM #TEMP_COMPLIANCE CL
  1435. WHERE agentRefId = @agentRefId
  1436. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1437. AND complianceId = 0
  1438. )
  1439. BEGIN
  1440. SELECT errorCode = 102
  1441. ,MSG = 'COMPLIANCE HOLD'
  1442. ,id = @isVisaStatusQuestionnaire
  1443. ,compApproveRemark = 'COMPLIANCE HOLD'
  1444. ,vtype = 'compliance'
  1445. ,isDocumentRequired = 'N'
  1446. SELECT id
  1447. ,csDetailRecId = ''
  1448. ,[S.N.] = ROW_NUMBER() OVER (
  1449. ORDER BY id
  1450. )
  1451. ,[Remarks] = complianceReason
  1452. ,[Action] = 'Questionnaire'
  1453. --,[Matched Tran ID] = ''
  1454. FROM ComplianceLog CL
  1455. WHERE agentRefId = @agentRefId
  1456. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1457. END
  1458. END
  1459. ELSE
  1460. BEGIN
  1461. IF @isVisaStatusQuestionnaire = 'Y'
  1462. BEGIN
  1463. INSERT remitTranComplianceTemp (
  1464. csDetailTranId
  1465. ,matchTranId
  1466. ,agentRefId
  1467. ,reason
  1468. )
  1469. SELECT TOP 1 0
  1470. ,NULL
  1471. ,@agentRefId
  1472. ,'Questionnaire require due to Visa Status'
  1473. SELECT errorCode = 102
  1474. ,MSG = 'COMPLIANCE HOLD'
  1475. ,id = @isVisaStatusQuestionnaire
  1476. ,compApproveRemark = 'COMPLIANCE HOLD'
  1477. ,vtype = 'compliance'
  1478. ,isDocumentRequired = 'N'
  1479. INSERT INTO ComplianceLog (
  1480. senderName
  1481. ,senderCountry
  1482. ,senderIdType
  1483. ,senderIdNumber
  1484. ,senderMobile
  1485. ,receiverName
  1486. ,receiverCountry
  1487. ,payOutAmt
  1488. ,complianceId
  1489. ,complianceReason
  1490. ,complainceDetailMessage
  1491. ,createdBy
  1492. ,createdDate
  1493. ,agentRefId
  1494. ,isDocumentRequired
  1495. )
  1496. SELECT @senderName
  1497. ,@sCountry
  1498. ,@sIdType
  1499. ,@sIdNo
  1500. ,@sMobile
  1501. ,@receiverName
  1502. ,@pCountry
  1503. ,@cAmt
  1504. ,0
  1505. ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  1506. ,'Compliance Hold/Questionnaire due to Visa Status: ' + @visaStatusText
  1507. ,@user
  1508. ,GETDATE()
  1509. ,@agentRefId
  1510. ,0
  1511. SELECT id
  1512. ,csDetailRecId = ''
  1513. ,[S.N.] = ROW_NUMBER() OVER (
  1514. ORDER BY id
  1515. )
  1516. ,[Remarks] = complianceReason
  1517. ,[Action] = 'Questionnaire'
  1518. --,[Matched Tran ID] = ''
  1519. FROM ComplianceLog CL
  1520. WHERE agentRefId = @agentRefId
  1521. AND CAST(cl.CREATEDDATE AS DATE) = CAST(GETDATE() AS DATE)
  1522. END
  1523. END
  1524. SELECT 0 errorCode
  1525. ,'Validation successful' msg
  1526. ,@senderId id
  1527. ,@receiverId Extra
  1528. --*****Check For Same Name*****
  1529. SELECT dbo.fnadecryptstring(controlno) controlNo
  1530. ,tranId = rt.id
  1531. ,senderName
  1532. ,sIdType = sen.idType
  1533. ,sIdNo = sen.idNumber
  1534. ,cAmt
  1535. ,pCountry
  1536. FROM vwremitTran rt WITH (NOLOCK)
  1537. INNER JOIN vwtranSenders sen WITH (NOLOCK) ON rt.id = sen.tranId
  1538. WHERE senderName = @senderName
  1539. AND createdDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101)
  1540. AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  1541. --*****Check For Same Id*****
  1542. SELECT dbo.fnadecryptstring(controlno) controlNo
  1543. ,tranId = rt.id
  1544. ,senderName
  1545. ,sIdType = sen.idType
  1546. ,sIdNo = sen.idNumber
  1547. ,cAmt
  1548. ,pCountry
  1549. FROM vwremitTran rt WITH (NOLOCK)
  1550. INNER JOIN vwtranSenders sen WITH (NOLOCK) ON rt.id = sen.tranId
  1551. WHERE idType = @sIdType
  1552. AND idNumber = @sIdNo
  1553. AND createdDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101)
  1554. AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  1555. END
  1556. ELSE IF @flag = 'i' --Send Transaction
  1557. BEGIN
  1558. --1. Field Validation-----------------------------------------------------------
  1559. IF @user IS NULL
  1560. BEGIN
  1561. EXEC proc_errorHandler 1
  1562. ,'Your session has expired. Cannot send transaction'
  1563. ,NULL
  1564. RETURN
  1565. END
  1566. --IF ISNULL(@IsFromTabPage, '0') != '1'
  1567. --BEGIN
  1568. -- IF NOT EXISTS (
  1569. -- SELECT 'X'
  1570. -- FROM applicationUsers WITH (NOLOCK)
  1571. -- WHERE PWD = DBO.FNAEncryptString(@txnPWD)
  1572. -- AND userName = @user
  1573. -- )
  1574. -- BEGIN
  1575. -- EXEC proc_errorHandler 1
  1576. -- ,'TXN password is invalid !'
  1577. -- ,@user
  1578. -- RETURN
  1579. -- END
  1580. --END
  1581. IF (
  1582. ISNULL(@deliveryMethod, '') = ''
  1583. OR @serviceCharge IS NULL
  1584. OR ISNULL(@cAmt, 0) = 0
  1585. OR ISNULL(@tAmt, 0) = 0
  1586. OR ISNULL(@exRate, 0) = 0
  1587. )
  1588. BEGIN
  1589. EXEC proc_errorHandler 1
  1590. ,'Mandatory Field(s) missing'
  1591. ,NULL
  1592. RETURN
  1593. END
  1594. IF @customerPassword IS NOT NULL
  1595. BEGIN
  1596. IF NOT EXISTS (
  1597. SELECT 1
  1598. FROM dbo.customerMaster
  1599. WHERE customerId = @senderId
  1600. AND dbo.decryptDb(customerPassword) = @customerPassword
  1601. )
  1602. BEGIN
  1603. EXEC proc_errorHandler 1
  1604. ,'Customer Password is invalid !'
  1605. ,NULL
  1606. RETURN
  1607. END
  1608. END
  1609. --******************BEGINING OF NEW CUSTOMER CREATION AND ENROLLMENT********************************
  1610. SELECT @sIdTypeId = valueId
  1611. FROM staticDataValue WITH (NOLOCK)
  1612. WHERE detailTitle = @sIdType
  1613. AND typeID = 1300
  1614. SELECT @sfName = UPPER(@sfName)
  1615. ,@smName = UPPER(@smName)
  1616. ,@slName = UPPER(@slName)
  1617. ,@slName2 = UPPER(@slName2)
  1618. SELECT @rfName = UPPER(@rfName)
  1619. ,@rmName = UPPER(@rmName)
  1620. ,@rlName = UPPER(@rlName)
  1621. ,@rlName2 = UPPER(@rlName2)
  1622. --2. Begining of New customer Creation and enrollment or updating existing customer data---
  1623. SET @senderName = @sfName + ISNULL(' ' + @smName, '') + ISNULL(' ' + @slName, '') + ISNULL(' ' + @slName2, '')
  1624. SET @receiverName = @rfName + ISNULL(' ' + @rmName, '') + ISNULL(' ' + @rlName, '') + ISNULL(' ' + @rlName2, '')
  1625. SET @sNaCountryId = (
  1626. SELECT countryId
  1627. FROM COUNTRYMASTER(NOLOCK)
  1628. WHERE COUNTRYNAME = @sNaCountry
  1629. )
  1630. SET @nCust = 'Y'
  1631. IF @nCust = 'N'
  1632. AND @senderId IS NULL
  1633. BEGIN
  1634. EXEC proc_errorHandler 1
  1635. ,'Mandatory Field(s) missing'
  1636. ,NULL
  1637. RETURN
  1638. END
  1639. IF @nCust = 'N'
  1640. AND @collMode = 'Bank Deposit'
  1641. BEGIN
  1642. SELECT @AVAILABLEBALANCE = DBO.FNAGetCustomerAvailableBalance(@senderId)
  1643. IF (ISNULL(@AVAILABLEBALANCE, 0) < @CAMT)
  1644. BEGIN
  1645. EXEC proc_errorHandler 1
  1646. ,'Collect Amount can not be greater then Available Balance!'
  1647. ,NULL
  1648. RETURN
  1649. END
  1650. END
  1651. IF ISNULL(@cAmt, 0) = 0
  1652. BEGIN
  1653. EXEC proc_errorHandler 1
  1654. ,'Collection Amount is missing'
  1655. ,NULL
  1656. RETURN
  1657. END
  1658. IF @serviceCharge > @cAmt
  1659. BEGIN
  1660. EXEC proc_errorHandler 1
  1661. ,'Collection Amount is less than service charge.'
  1662. ,NULL
  1663. RETURN
  1664. END
  1665. SET @controlNo = '21' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  1666. IF EXISTS (
  1667. SELECT 'X'
  1668. FROM controlNoList WITH (NOLOCK)
  1669. WHERE controlNo = @controlNo
  1670. )
  1671. BEGIN
  1672. SET @controlNo = '21' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 7)
  1673. IF EXISTS (
  1674. SELECT 'X'
  1675. FROM controlNoList WITH (NOLOCK)
  1676. WHERE controlNo = @controlNo
  1677. )
  1678. BEGIN
  1679. EXEC proc_errorHandler 1
  1680. ,'Technical error occurred. Please try again'
  1681. ,NULL
  1682. RETURN
  1683. END
  1684. END
  1685. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  1686. IF @deliveryMethod IN (
  1687. 'Cash Payment'
  1688. ,'Door to Door'
  1689. )
  1690. BEGIN
  1691. IF @deliveryMethod = 'Door to Door'
  1692. BEGIN
  1693. SET @payMsg = ' [Door To Door Location:' + @pBankBranchName + ', ' + @pBankBranchName + ' ]'
  1694. END
  1695. END
  1696. ELSE IF @deliveryMethod = 'Bank Deposit'
  1697. BEGIN
  1698. IF @pBank IS NULL
  1699. BEGIN
  1700. EXEC proc_errorHandler 1
  1701. ,'Bank is required for Bank Deposit '
  1702. ,NULL
  1703. RETURN
  1704. END
  1705. END
  1706. --3. Check Limit starts
  1707. SELECT @settlingAgent = agentId
  1708. FROM dbo.agentMaster(NOLOCK)
  1709. WHERE agentId = @sBranch
  1710. AND ISNULL(isSettlingAgent, 'N') = 'Y'
  1711. IF @settlingAgent IS NULL
  1712. SELECT @settlingAgent = agentId
  1713. FROM dbo.agentMaster(NOLOCK)
  1714. WHERE agentId = @sAgent
  1715. AND ISNULL(isSettlingAgent, 'N') = 'Y'
  1716. --Credit Limit Section
  1717. IF @collMode = 'Cash Collect'
  1718. BEGIN
  1719. DECLARE @sBranch1 INT
  1720. IF EXISTS (
  1721. SELECT 1
  1722. FROM dbo.applicationUsers
  1723. WHERE agentId = @sBranch
  1724. AND userName = @user
  1725. )
  1726. BEGIN
  1727. SELECT @user1 = @user
  1728. ,@sBranch1 = NULL
  1729. END
  1730. ELSE
  1731. BEGIN
  1732. SET @sBranch1 = @sBranch
  1733. END
  1734. SELECT @limitBal = availableLimit
  1735. ,@holdType = CASE
  1736. WHEN ruleType = 'H'
  1737. THEN 'Hold'
  1738. ELSE 'Block'
  1739. END
  1740. FROM DBO.FNAGetUserCashLimitDetails(@user1, @sBranch1)
  1741. IF @tAmt > @limitBal
  1742. AND @holdType = 'B'
  1743. BEGIN
  1744. EXEC [proc_errorHandler] 1
  1745. ,'Transfer amount exceeds Limit. Please, Check your available limit.'
  1746. ,@controlNo
  1747. RETURN
  1748. END
  1749. END
  1750. --End of Credit Limit Section-------------------------------------------------------------------------------------------------------------
  1751. --Get Service Charge----------------------------------------------------------------------------------------------------------------------
  1752. DECLARE @originalSC MONEY = 0
  1753. SET @sCountryId = 233
  1754. --New code added, referral code add #arjun
  1755. --EXEC PROC_Customer_LoyaltyV2 @flag = 'check-eligible-v2'
  1756. -- ,@isEligible = @isEligible OUT
  1757. -- ,@referralCode = @introducer
  1758. -- ,@tranCount = @trancount OUT
  1759. -- ,@schemeCount = @schemeCount OUT
  1760. -- ,@customerId = @senderId
  1761. -- ,@createdFrom = 'I'
  1762. -- loyalty free sc
  1763. --IF EXISTS (
  1764. -- SELECT TOP 1 1
  1765. -- FROM REFERRAL_AGENT_WISE
  1766. -- WHERE REFERRAL_TYPE_CODE IN (
  1767. -- 'RB'
  1768. -- ,'RC'
  1769. -- )
  1770. -- AND REFERRAL_CODE = @introducer
  1771. -- )
  1772. --BEGIN
  1773. -- EXEC PROC_Customer_Loyalty @flag = 'check-eligible'
  1774. -- ,@isEligible = @isEligible OUT
  1775. --END
  1776. --EXEC proc_Customer_Loyalty @flag = 'get-tranCount'
  1777. -- ,@tranCount = @trancount OUT
  1778. -- ,@customerId = @senderId
  1779. --SELECT TOP 1 @schemeCount = txnCount
  1780. --FROM schemeSetup(NOLOCK)
  1781. --ORDER BY createdDate DESC
  1782. IF @calcBy = 'cAmt'
  1783. BEGIN
  1784. IF @isEligible = 'Y'
  1785. BEGIN
  1786. SET @iServiceCharge = 0
  1787. END
  1788. ELSE
  1789. BEGIN
  1790. IF ISNULL(@isManualSc, 'N') = 'N'
  1791. BEGIN
  1792. SELECT @iServiceCharge = ISNULL(amount, - 1)
  1793. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
  1794. SET @originalSC = @iServiceCharge
  1795. END
  1796. ELSE
  1797. BEGIN
  1798. SET @iServiceCharge = ISNULL(@manualSc, 0)
  1799. SELECT @originalSC = ISNULL(amount, - 1)
  1800. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
  1801. IF @cAmt <> @tAmt + @iServiceCharge - @rewardAmt
  1802. BEGIN
  1803. EXEC proc_errorHandler 1
  1804. ,'Please click on Calculate or Click out side the Service Charge input Box, after editing Service Charge!'
  1805. ,NULL
  1806. RETURN
  1807. END
  1808. END
  1809. END
  1810. END
  1811. ELSE
  1812. BEGIN
  1813. --SET @tAmt = ROUND(@pAmt/(@exRate + @exRateOffer),0)
  1814. SET @tAmt = CEILING(@pAmt / (@exRate + ISNULL(@exRateOffer, 0))) + ISNULL(@rewardAmt,0)
  1815. IF @isEligible = 'Y'
  1816. BEGIN
  1817. SET @iServiceCharge = 0
  1818. END
  1819. ELSE
  1820. BEGIN
  1821. IF ISNULL(@isManualSc, 'N') = 'N'
  1822. BEGIN
  1823. SELECT @iServiceCharge = ISNULL(amount, - 1)
  1824. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmt, @collCurr)
  1825. SET @originalSC = @iServiceCharge
  1826. END
  1827. ELSE
  1828. BEGIN
  1829. SET @iServiceCharge = ISNULL(@manualSc, 0)
  1830. SELECT @originalSC = ISNULL(amount, - 1)
  1831. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmtSC, @collCurr)
  1832. IF @cAmt <> @tAmt + @iServiceCharge - @rewardAmt
  1833. BEGIN
  1834. EXEC proc_errorHandler 1
  1835. ,'Please click on Calculate or Click out side the Service Charge input Box, after editing Service Charge!'
  1836. ,NULL
  1837. RETURN
  1838. END
  1839. END
  1840. END
  1841. END
  1842. -- PRINT @iServiceCharge
  1843. IF @iServiceCharge = - 1
  1844. AND ISNULL(@isManualSc, 'N') = 'N'
  1845. BEGIN
  1846. EXEC proc_errorHandler 1
  1847. ,'Transaction cannot be proceed. Service Charge is not defined'
  1848. ,NULL
  1849. RETURN
  1850. END
  1851. --Earthquake relief fund
  1852. DECLARE @scDisc MONEY
  1853. IF @iServiceCharge <> @serviceCharge
  1854. AND ISNULL(@isManualSc, 'N') = 'N'
  1855. BEGIN
  1856. EXEC proc_errorHandler 1
  1857. ,'Transaction cannot be proceed. Amount detail not match. Service Charge is different.'
  1858. ,NULL
  1859. RETURN
  1860. END
  1861. PRINT 'osc'
  1862. PRINT @originalSc
  1863. PRINT @iServiceCharge
  1864. IF (@iServiceCharge <> @calculatedOriginalSc)
  1865. AND ISNULL(@isManualSc, 'Y') = 'Y'
  1866. BEGIN
  1867. PRINT 'condition matched'
  1868. UPDATE APPLICATIONUSERS
  1869. SET freeScCounter = isnull(freeScCounter, 0) + 1
  1870. WHERE username = @user
  1871. END
  1872. --End-------------------------------------------------------------------------------------------------------------------------------------
  1873. --4. Get Exchange Rate Details------------------------------------------------------------------------------------------------------------------
  1874. IF @pCountryId = 151
  1875. AND @deliveryMethodId = 1
  1876. BEGIN
  1877. SELECT AgentId
  1878. INTO #AgentListSend
  1879. FROM agentMaster(NOLOCK)
  1880. WHERE extCode = 'NP ANYWHERE'
  1881. SELECT @customerRate = customerRate
  1882. ,@sCurrCostRate = sCurrCostRate
  1883. ,@sCurrHoMargin = sCurrHoMargin
  1884. ,@sCurrAgentMargin = sCurrAgentMargin
  1885. ,@pCurrCostRate = pCurrCostRate
  1886. ,@pCurrHoMargin = pCurrHoMargin
  1887. ,@pCurrAgentMargin = pCurrAgentMargin
  1888. ,@agentCrossSettRate = agentCrossSettRate
  1889. ,@treasuryTolerance = treasuryTolerance
  1890. ,@customerPremium = customerPremium
  1891. ,@sharingValue = sharingValue
  1892. ,@sharingType = sharingType
  1893. FROM (
  1894. SELECT ROW_NUMBER() OVER (
  1895. ORDER BY CUSTOMERRATE DESC
  1896. ) ROW_NUM
  1897. ,customerRate
  1898. ,sCurrCostRate
  1899. ,sCurrHoMargin
  1900. ,sCurrAgentMargin
  1901. ,pCurrCostRate
  1902. ,pCurrHoMargin
  1903. ,pCurrAgentMargin
  1904. ,agentCrossSettRate
  1905. ,treasuryTolerance
  1906. ,customerPremium
  1907. ,sharingValue
  1908. ,sharingType
  1909. FROM #AgentListSend A
  1910. CROSS APPLY dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, AgentId, @pCurr, @deliveryMethodId)
  1911. ) X
  1912. WHERE X.ROW_NUM = 1
  1913. END
  1914. ELSE
  1915. BEGIN
  1916. SELECT @customerRate = customerRate
  1917. ,@sCurrCostRate = sCurrCostRate
  1918. ,@sCurrHoMargin = sCurrHoMargin
  1919. ,@sCurrAgentMargin = sCurrAgentMargin
  1920. ,@pCurrCostRate = pCurrCostRate
  1921. ,@pCurrHoMargin = pCurrHoMargin
  1922. ,@pCurrAgentMargin = pCurrAgentMargin
  1923. ,@agentCrossSettRate = agentCrossSettRate
  1924. ,@treasuryTolerance = treasuryTolerance
  1925. ,@customerPremium = customerPremium
  1926. ,@sharingValue = sharingValue
  1927. ,@sharingType = sharingType
  1928. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethodId)
  1929. END
  1930. IF @customerRate IS NULL
  1931. BEGIN
  1932. EXEC proc_errorHandler 1
  1933. ,'Transaction cannot be proceed. Exchange Rate not defined'
  1934. ,NULL
  1935. RETURN
  1936. END
  1937. SET @serviceCharge = @serviceCharge - ISNULL(@scDiscount, 0)
  1938. SET @iServiceCharge = @iServiceCharge - ISNULL(@iScDiscount, 0)
  1939. SET @tAmt = @cAmt - @serviceCharge + @rewardAmt
  1940. SET @iCustomerRate = @customerRate + ISNULL(@schemePremium, 0)
  1941. IF @pCurr = 'VND'
  1942. BEGIN
  1943. IF @calcBy = 'cAmt'
  1944. BEGIN
  1945. SET @iTAmt = @cAmt - @iServiceCharge + @rewardAmt
  1946. SET @iPAmt = @iTAmt * @iCustomerRate
  1947. --IF @place IS NOT NULL
  1948. -- SET @pAmt = ROUND(@pAmt, -@place, 1)
  1949. END
  1950. ELSE
  1951. BEGIN
  1952. SET @iPAmt = @pAmt
  1953. END
  1954. END
  1955. ELSE
  1956. BEGIN
  1957. SET @iTAmt = @cAmt - @iServiceCharge + @rewardAmt
  1958. SELECT @place = place
  1959. ,@currDecimal = currDecimal
  1960. FROM currencyPayoutRound WITH (NOLOCK)
  1961. WHERE ISNULL(isDeleted, 'N') = 'N'
  1962. AND currency = @pCurr
  1963. AND ISNULL(tranType, @deliveryMethodId) = @deliveryMethodId
  1964. SET @currDecimal = ISNULL(@currDecimal, 0)
  1965. SET @place = ISNULL(@place, 0)
  1966. SET @iPAmt = @iTAmt * @iCustomerRate
  1967. --SET @iPAmt = ROUND(@iPAmt, @currDecimal, 1)
  1968. --IF @place IS NOT NULL
  1969. -- SET @iPAmt = ROUND(@iPAmt, -@place, 1)
  1970. END
  1971. SET @iPAmt = @iTAmt * @iCustomerRate
  1972. SET @iPAmt = ROUND(@iPAmt, @currDecimal, 1)
  1973. --IF @place IS NOT NULL
  1974. -- SET @iPAmt = ROUND(@iPAmt, -@place, 1)
  1975. IF @pAmt - @iPAmt <= 1
  1976. SET @iPAmt = @pAmt
  1977. IF @iPAmt <> @pAmt
  1978. BEGIN
  1979. EXEC proc_errorHandler 1
  1980. ,'Amount detail not match. Please re-calculate the amount again.'
  1981. ,NULL
  1982. RETURN
  1983. END
  1984. --6. Commission Calculation Start
  1985. --**********Customer Per Day Limit Checking**********
  1986. DECLARE @remitTranTemp TABLE (
  1987. tranId BIGINT
  1988. ,controlNo VARCHAR(20)
  1989. ,cAmt MONEY
  1990. ,receiverName VARCHAR(200)
  1991. ,receiverIdType VARCHAR(100)
  1992. ,receiverIdNumber VARCHAR(50)
  1993. ,dot DATETIME
  1994. )
  1995. DECLARE @moneySendTemp TABLE (
  1996. tranNo BIGINT
  1997. ,refno VARCHAR(20)
  1998. ,paidAmt MONEY
  1999. ,receiverName VARCHAR(200)
  2000. ,receiverIdDescription VARCHAR(100)
  2001. ,receiverIdDetail VARCHAR(50)
  2002. ,dot DATETIME
  2003. )
  2004. INSERT INTO @remitTranTemp (
  2005. tranId
  2006. ,controlNo
  2007. ,cAmt
  2008. ,receiverName
  2009. ,receiverIdType
  2010. ,receiverIdNumber
  2011. ,dot
  2012. )
  2013. SELECT rt.id
  2014. ,rt.controlNo
  2015. ,rt.cAmt
  2016. ,rt.receiverName
  2017. ,rec.idType
  2018. ,rec.idNumber
  2019. ,rt.createdDateLocal
  2020. FROM vwRemitTran rt WITH (NOLOCK)
  2021. INNER JOIN vwTranSenders sen WITH (NOLOCK) ON rt.id = sen.tranId
  2022. INNER JOIN vwTranReceivers rec WITH (NOLOCK) ON rt.id = rec.tranId
  2023. WHERE sen.idNumber = @sIdNo
  2024. AND (
  2025. tranStatus <> 'CancelRequest'
  2026. AND tranStatus <> 'Cancel'
  2027. )
  2028. AND (
  2029. rt.approvedDate BETWEEN CONVERT(VARCHAR, GETDATE(), 101)
  2030. AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  2031. OR (
  2032. approvedBy IS NULL
  2033. AND cancelApprovedBy IS NULL
  2034. )
  2035. )
  2036. IF EXISTS (
  2037. SELECT 'X'
  2038. FROM @remitTranTemp
  2039. WHERE cAmt = @cAmt
  2040. AND (
  2041. receiverName = @receiverName
  2042. OR (
  2043. ISNULL(receiverIdType, '0') = @rIdType
  2044. AND ISNULL(receiverIdNumber, '0') = @rIdNo
  2045. )
  2046. )
  2047. AND DATEDIFF(MI, dot, GETDATE()) <= 5
  2048. )
  2049. BEGIN
  2050. EXEC proc_errorHandler 1
  2051. ,'Similar transaction found. You can process similar transaction after 5 minutes.'
  2052. ,NULL
  2053. RETURN
  2054. END
  2055. DECLARE @customerTotalSentAmt MONEY = 0
  2056. ,@txnSumTobeDeducted MONEY = 0
  2057. SELECT @customerTotalSentAmt = SUM(cAmt)
  2058. FROM @remitTranTemp
  2059. SELECT @customerTotalAmt2 = SUM(paidAmt)
  2060. FROM @moneySendTemp
  2061. SELECT @txnSumTobeDeducted = ISNULL(SUM(paidAmt), 0)
  2062. FROM @moneySendTemp mst
  2063. INNER JOIN @remitTranTemp rtt ON mst.refno = rtt.controlNo
  2064. IF (ISNULL(@customerTotalAmt2, 0) + ISNULL(@customerTotalSentAmt, 0) + @cAmt - @txnSumTobeDeducted) > dbo.FNAGetPerDayCustomerLimit(@settlingAgent)
  2065. BEGIN
  2066. EXEC proc_errorHandler 1
  2067. ,'Transaction cannot be proceed. Customer Limit exceeded.'
  2068. ,NULL
  2069. RETURN
  2070. END
  2071. -- #########country and occupation risk point
  2072. DECLARE @countryRisk INT
  2073. ,@OccupationRisk INT
  2074. ,@isFirstTran CHAR(1)
  2075. SELECT @sNaCountry = CASE
  2076. WHEN @nCust = 'Y'
  2077. THEN @sNaCountry
  2078. ELSE nativeCountry
  2079. END
  2080. FROM tranSenders WITH (NOLOCK)
  2081. WHERE customerId = @senderId
  2082. IF NOT EXISTS (
  2083. SELECT 'Z'
  2084. FROM tranSenders WITH (NOLOCK)
  2085. WHERE customerId = @senderId
  2086. )
  2087. BEGIN
  2088. IF NOT EXISTS (
  2089. SELECT 'Z'
  2090. FROM tranSendersTEMP WITH (NOLOCK)
  2091. WHERE customerId = @senderId
  2092. )
  2093. SET @isFirstTran = 'Y'
  2094. ELSE
  2095. SET @isFirstTran = 'N'
  2096. END
  2097. SELECT @countryRisk = ISNULL(fatfRating, 0)
  2098. FROM countryMaster C WITH (NOLOCK)
  2099. WHERE countryName = @sNaCountry
  2100. AND ISNULL(C.isActive, 'Y') = 'Y'
  2101. AND ISNULL(C.isDeleted, 'N') = 'Y'
  2102. SELECT @OccupationRisk = ISNULL(riskFactor, 0)
  2103. FROM occupationMaster WITH (NOLOCK)
  2104. WHERE occupationId = @occupation
  2105. AND ISNULL(isActive, 'Y') = 'Y'
  2106. AND ISNULL(isDeleted, 'N') = 'Y'
  2107. --RBA
  2108. DECLARE @RBAScoreTxn MONEY
  2109. ,@RBAScoreCustomer MONEY
  2110. SELECT @RBAScoreCustomer = @RBACustomerRiskValue
  2111. ,@RBAScoreTxn = CASE
  2112. WHEN @RBATxnRisk = 'LOW RISK'
  2113. THEN 40
  2114. WHEN @RBATxnRisk = 'MEDIUM RISK'
  2115. THEN 50
  2116. WHEN @RBATxnRisk = 'HIGH RISK'
  2117. THEN 51
  2118. ELSE 100
  2119. END
  2120. IF @deliveryMethod = 'BANK DEPOSIT'
  2121. BEGIN
  2122. IF NOT EXISTS (
  2123. SELECT 'A'
  2124. FROM API_BANK_LIST(NOLOCK)
  2125. WHERE BANK_ID = @pBank
  2126. AND IS_ACTIVE = 1
  2127. )
  2128. BEGIN
  2129. EXEC proc_errorHandler 1
  2130. ,'Invalid bank selected'
  2131. ,NULL
  2132. RETURN
  2133. END
  2134. END
  2135. --##Get Voucher Details into temp table END##--
  2136. SELECT @pAgentCommCurrency = DBO.FNAGetPayCommCurrency(@sSuperAgent, @sAgent, @sBranch, @SCOUNTRYID, @pSuperAgent, @pBranch, @pCountryId)
  2137. IF (
  2138. LEN(ISNULL(@nameAsPerBank, '')) < 1
  2139. AND @pCountryId = '203'
  2140. AND @pAgent = '394133'
  2141. AND @deliveryMethodId = '2'
  2142. ) -- DONGA Bank Deposit
  2143. BEGIN
  2144. SET @pAgentComm = (@pAmt * 0.17) / 100;
  2145. END
  2146. ELSE
  2147. BEGIN
  2148. SELECT @pAgentComm = amount
  2149. FROM dbo.FNAGetPayComm(@sAgent, @sCountryId, NULL, NULL, @pCountryId, NULL, @pAgent, @pAgentCommCurrency, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, @tAmt, NULL)
  2150. END
  2151. SET @sSettlementRate = @sCurrCostRate + @sCurrHoMargin
  2152. SET @pSettlementRate = @pCurrCostRate - @pCurrHoMargin
  2153. --IF EXISTS (SELECT 'X' FROM agentMaster(nolock) WHERE agentId = @sAgent AND ISNULL(isSettlingAgent, 'N') = 'Y' AND ISNULL(isIntl, 0) = 1 AND isApiPartner = 0 AND ISNULL(ACTASBRANCH, 'N') = 'N')
  2154. --BEGIN
  2155. -- SELECT @sAgentComm = amount, @sAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm(
  2156. -- @sCountryId, @sSuperAgent, @sAgent, @sBranch,
  2157. -- @pCountryId, @pSuperAgent, @pAgent, @pBankBranch,
  2158. -- @collCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, NULL,
  2159. -- @sSettlementRate, @pSettlementRate)
  2160. -- SELECT @sSuperAgentComm = 0, @sSuperAgentCommCurrency = @sAgentCommCurrency
  2161. -- IF (@sAgentComm IS NULL)
  2162. -- BEGIN
  2163. -- EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Commission is not defined', NULL
  2164. -- RETURN
  2165. -- END
  2166. --END
  2167. --ELSE
  2168. --BEGIN
  2169. SELECT @sAgentComm = 0
  2170. ,@sSuperAgentComm = 0
  2171. ,@sSuperAgentCommCurrency = @sAgentCommCurrency
  2172. --END
  2173. IF EXISTS (
  2174. SELECT *
  2175. FROM REFERRAL_AGENT_WISE(NOLOCK)
  2176. WHERE REFERRAL_CODE = @introducer
  2177. AND AGENT_ID <> 0
  2178. )
  2179. BEGIN
  2180. SELECT @sAgent = AM.AGENTID
  2181. ,@sAgentName = AM.AGENTNAME
  2182. ,@sBranch = AM.AGENTID
  2183. ,@sBranchName = AM.AGENTNAME
  2184. FROM REFERRAL_AGENT_WISE R(NOLOCK)
  2185. INNER JOIN AGENTMASTER AM(NOLOCK) ON AM.AGENTID = R.AGENT_ID
  2186. WHERE REFERRAL_CODE = @introducer
  2187. END
  2188. DECLARE @ADDRESS_TBL_ROW_ID BIGINT
  2189. SELECT @sAdd2 = ISNULL(additionalAddress, '')
  2190. ,@visaStatus = visastatus
  2191. ,@ADDRESS_TBL_ROW_ID = district
  2192. ,@sCustStreet = ISNULL(street, rtrim(ltrim(replace(replace(cast(streetunicode AS VARCHAR), '?', ''), '-', ''))))
  2193. ,@sAdd1 = ISNULL(CITY, '') + ', ' + ISNULL(street, rtrim(ltrim(replace(replace(cast(streetunicode AS VARCHAR), '?', ''), '-', ''))))
  2194. FROM customermaster(NOLOCK)
  2195. WHERE customerid = @senderId
  2196. --IF EXISTS(SELECT * FROM REFERRAL_AGENT_WISE (NOLOCK) WHERE REFERRAL_CODE = @introducer AND AGENT_ID <> 0)
  2197. --BEGIN
  2198. -- SELECT @SAGENT = AM.AGENTID, @SAGENTNAME = AM.AGENTNAME
  2199. -- FROM AGENTMASTER AM(NOLOCK)
  2200. -- INNER JOIN REFERRAL_AGENT_WISE R(NOLOCK) ON R.AGENT_ID = AM.AGENTID
  2201. -- WHERE REFERRAL_CODE = @introducer
  2202. --END
  2203. BEGIN TRANSACTION
  2204. IF (
  2205. @pCountry = 'Nepal'
  2206. AND @deliveryMethodId = 1
  2207. )
  2208. BEGIN
  2209. SELECT @pSuperAgent = NULL
  2210. ,@pSuperAgentName = NULL
  2211. ,@PAGENT = NULL
  2212. ,@pAgentName = NULL
  2213. ,@pBranch = NULL
  2214. ,@pBranchName = NULL
  2215. END
  2216. SELECT @pBankName = BANK_NAME
  2217. FROM API_BANK_LIST (NOLOCK)
  2218. WHERE BANK_ID = @pbank;
  2219. INSERT INTO remitTranTemp (
  2220. controlNo
  2221. ,sCurrCostRate
  2222. ,sCurrHoMargin
  2223. ,sCurrSuperAgentMargin
  2224. ,sCurrAgentMargin
  2225. ,pCurrCostRate
  2226. ,pCurrHoMargin
  2227. ,pCurrSuperAgentMargin
  2228. ,pCurrAgentMargin
  2229. ,agentCrossSettRate
  2230. ,customerRate
  2231. ,sAgentSettRate
  2232. ,pDateCostRate
  2233. ,treasuryTolerance
  2234. ,customerPremium
  2235. ,schemePremium
  2236. ,sharingValue
  2237. --,sharingType
  2238. ,serviceCharge
  2239. ,handlingFee
  2240. ,agentFxGain
  2241. ,sAgentComm
  2242. ,sAgentCommCurrency
  2243. ,sSuperAgentComm
  2244. ,sSuperAgentCommCurrency
  2245. ,pAgentComm
  2246. ,pAgentCommCurrency
  2247. ,pSuperAgentComm
  2248. ,pSuperAgentCommCurrency
  2249. ,promotionCode
  2250. ,promotionType
  2251. ,pMessage
  2252. ,sSuperAgent
  2253. ,sSuperAgentName
  2254. ,sAgent
  2255. ,sAgentName
  2256. ,sBranch
  2257. ,sBranchName
  2258. ,sCountry
  2259. ,pSuperAgent
  2260. ,pSuperAgentName
  2261. ,pAgent
  2262. ,pAgentName
  2263. ,pBranch
  2264. ,pBranchName
  2265. ,pCountry
  2266. ,paymentMethod
  2267. ,pBank
  2268. ,pBankName
  2269. ,pBankBranch
  2270. ,pBankBranchName
  2271. ,accountNo
  2272. ,pBankType
  2273. ,expectedPayoutAgent
  2274. ,collMode
  2275. ,collCurr
  2276. ,tAmt
  2277. ,cAmt
  2278. ,pAmt
  2279. ,payoutCurr
  2280. ,relWithSender
  2281. ,purposeOfRemit
  2282. ,sourceOfFund
  2283. ,tranStatus
  2284. ,payStatus
  2285. ,createdDate
  2286. ,createdDateLocal
  2287. ,createdBy
  2288. ,tranType
  2289. ,voucherNo
  2290. ,senderName
  2291. ,receiverName
  2292. ,pState
  2293. ,pDistrict
  2294. ,pLocation
  2295. --NEW
  2296. ,isScMaunal
  2297. ,originalSC
  2298. ,externalBankCode
  2299. ,isOnBehalf
  2300. ,PayerId
  2301. ,PayerBranchId
  2302. ,sRouteId
  2303. ,company
  2304. ,receiverNameAlt
  2305. ,depositType
  2306. ,rewardPoints
  2307. ,rewardType
  2308. ,isBonusUpdated
  2309. )
  2310. SELECT @controlNoEncrypted
  2311. ,@sCurrCostRate
  2312. ,@sCurrHoMargin
  2313. ,@sCurrSuperAgentMargin
  2314. ,@sCurrAgentMargin
  2315. ,@pCurrCostRate
  2316. ,@pCurrHoMargin
  2317. ,@pCurrSuperAgentMargin
  2318. ,@pCurrAgentMargin
  2319. ,@agentCrossSettRate
  2320. ,@customerRate
  2321. ,@sAgentSettRate
  2322. ,@pDateCostRate
  2323. ,@treasuryTolerance
  2324. ,@customerPremium
  2325. ,ISNULL(@schemePremium, 0)
  2326. ,@sharingValue
  2327. --,@sharingType
  2328. ,@serviceCharge
  2329. ,ISNULL(@scDiscount, 0)
  2330. ,0
  2331. ,@sAgentComm
  2332. ,@sAgentCommCurrency
  2333. ,@sSuperAgentComm
  2334. ,@sSuperAgentCommCurrency
  2335. ,@pAgentComm
  2336. ,@pAgentCommCurrency
  2337. ,@pSuperAgentComm
  2338. ,@pSuperAgentCommCurrency
  2339. ,@introducer
  2340. ,@promotionType --@promotionCode REPLACED BY ARJUN
  2341. ,@payMsg
  2342. ,@sSuperAgent
  2343. ,@sSuperAgentName
  2344. ,@sAgent
  2345. ,@sAgentName
  2346. ,@sBranch
  2347. ,@sBranchName
  2348. ,@sCountry
  2349. ,@pSuperAgent
  2350. ,@pSuperAgentName
  2351. ,@pAgent
  2352. ,@pAgentName
  2353. ,@pBranch
  2354. ,@pBranchName
  2355. ,@pCountry
  2356. ,@deliveryMethod
  2357. ,@pBank
  2358. ,@pBankName
  2359. ,@pBankBranch
  2360. ,@pBankBranchName
  2361. ,@raccountNo
  2362. ,@pBankType
  2363. ,@pAgentName
  2364. ,@collMode
  2365. ,@collCurr
  2366. ,@tAmt
  2367. ,@cAmt
  2368. ,@pAmt
  2369. ,@pCurr
  2370. ,@relationship + ISNULL(' :' + @relationOther, '')
  2371. ,@purpose + ISNULL(' :' + @purposeOther, '')
  2372. ,@sourceOfFund
  2373. ,'Hold'
  2374. ,'UNPAID'
  2375. ,DBO.FNADateFormatTZ(GETDATE(), @user)
  2376. ,GETDATE()
  2377. ,@user
  2378. ,'I'
  2379. ,''
  2380. ,@senderName
  2381. ,@receiverName
  2382. ,@pLocation
  2383. ,@pSubLocation
  2384. ,@pTownId
  2385. ,CASE
  2386. WHEN ISNULL(@isManualSc, 'N') = 'Y'
  2387. THEN 1
  2388. ELSE 0
  2389. END
  2390. ,@originalSC
  2391. ,@customerDepositedBank
  2392. ,CASE @isOnbehalf
  2393. WHEN 'Y'
  2394. THEN 1
  2395. ELSE 0
  2396. END
  2397. ,@payerId
  2398. ,@payerBranchId
  2399. ,CASE @IsFromTabPage
  2400. WHEN '1'
  2401. THEN '1'
  2402. ELSE '0'
  2403. END
  2404. ,@exRateId
  2405. ,@nameAsPerBank
  2406. ,@paymentOption
  2407. ,ISNULL(@rewardAmt, 0)
  2408. ,CASE
  2409. WHEN ISNULL(@rewardAmt, 0) > 0
  2410. THEN 'REDEEM'
  2411. ELSE NULL
  2412. END
  2413. ,'N'
  2414. SET @id = SCOPE_IDENTITY()
  2415. INSERT INTO controlNoList (
  2416. controlNo
  2417. ,createdby
  2418. )
  2419. SELECT @controlNo
  2420. ,'C'
  2421. --UPDATE PROMOTIONAL CAMPAIGN
  2422. IF ISNULL(@promotionCode, 0) <> 0
  2423. BEGIN
  2424. EXEC PROC_PROMOTIONAL_CAMPAIGN_COUNTRY_WISE @ID = @id
  2425. ,@promotionCode = @promotionCode
  2426. ,@promotionAmount = @promotionAmount
  2427. END
  2428. INSERT INTO tranSendersTemp (
  2429. tranId
  2430. ,customerId
  2431. ,membershipId
  2432. ,firstName
  2433. ,middleName
  2434. ,lastName1
  2435. ,lastName2
  2436. ,fullName
  2437. ,country
  2438. ,[address]
  2439. ,address2
  2440. ,zipCode
  2441. ,city
  2442. ,email
  2443. ,homePhone
  2444. ,mobile
  2445. ,nativeCountry
  2446. ,dob
  2447. ,placeOfIssue
  2448. ,idType
  2449. ,idNumber
  2450. ,validDate
  2451. ,occupation
  2452. ,countryRiskPoint
  2453. ,customerRiskPoint
  2454. ,isFirstTran
  2455. ,salary
  2456. ,companyName
  2457. ,cwPwd
  2458. ,ttName
  2459. ,dcInfo
  2460. ,ipAddress
  2461. ,RBA
  2462. --NEW
  2463. ,STATE
  2464. ,district --USE FOR STREET
  2465. ,customerType
  2466. --,ttName--USE FOR BUSINESS TYPE
  2467. ,idPlaceOfIssue
  2468. ,visaStatus
  2469. ,issuedDate
  2470. )
  2471. SELECT @id
  2472. ,@senderId
  2473. ,@memberCode
  2474. ,@sfName
  2475. ,@smName
  2476. ,@slName
  2477. ,@slName2
  2478. ,@senderName
  2479. ,@sCountry
  2480. ,@sAdd1
  2481. ,@sAdd2
  2482. ,@sPostCode
  2483. ,@scity
  2484. ,@sEmail
  2485. ,@sTel
  2486. ,@sMobile
  2487. ,@sNaCountry
  2488. ,@sdob
  2489. ,@sIdTypeId
  2490. ,@sIdType
  2491. ,@sIdNo
  2492. ,@sIdValid
  2493. ,@occupation
  2494. ,@countryRisk
  2495. ,@RBAScoreCustomer
  2496. ,@isFirstTran
  2497. ,@salaryRange
  2498. ,@company
  2499. ,@cwPwd
  2500. ,@ADDRESS_TBL_ROW_ID
  2501. ,@sDcInfo
  2502. ,@sIpAddress
  2503. ,@RBAScoreTxn
  2504. ,@sCustLocation
  2505. ,@sCustStreet
  2506. ,@sCustomerType
  2507. --,@sCustBusinessType
  2508. ,@sCustIdIssuedCountry
  2509. ,@visaStatus
  2510. ,@sCustIdIssuedDate
  2511. INSERT INTO tranReceiversTemp (
  2512. tranId
  2513. ,customerId
  2514. ,membershipId
  2515. ,firstName
  2516. ,middleName
  2517. ,lastName1
  2518. ,lastName2
  2519. ,fullName
  2520. ,country
  2521. ,[address]
  2522. ,zipCode
  2523. ,city
  2524. ,email
  2525. ,homePhone
  2526. ,workPhone
  2527. ,mobile
  2528. ,nativeCountry
  2529. ,dob
  2530. ,placeOfIssue
  2531. ,idType
  2532. ,idNumber
  2533. ,idPlaceOfIssue
  2534. ,issuedDate
  2535. ,validDate
  2536. ,gender
  2537. ,STATE
  2538. ,district
  2539. ,accountNo
  2540. ,goodsType
  2541. ,goodsOrigin
  2542. ,portOfShipment
  2543. )
  2544. SELECT @id
  2545. ,@receiverId
  2546. ,''
  2547. ,@rfName
  2548. ,@rmName
  2549. ,@rlName
  2550. ,@rlName2
  2551. ,@receiverName
  2552. ,@pCountry
  2553. ,@rAdd1
  2554. ,@rPostCode
  2555. ,@rcity
  2556. ,@rEmail
  2557. ,@rTel
  2558. ,@rTel
  2559. ,@rMobile
  2560. ,@rNaCountry
  2561. ,@rdob
  2562. ,NULL
  2563. ,@rIdType
  2564. ,@rIdNo
  2565. ,NULL
  2566. ,NULL
  2567. ,@rIdValid
  2568. ,@rgender
  2569. ,@pLocationText
  2570. ,@pSubLocationText
  2571. ,@raccountNo
  2572. ,@goodsType
  2573. ,@goodsOrigin
  2574. ,@portOfShipment
  2575. --New code added, referral code add #arjun
  2576. EXEC PROC_Customer_LoyaltyV2 @flag = 'update-v2'
  2577. ,@customerId = @senderId
  2578. ,@createdFrom = 'I'
  2579. ,@tranId = @id
  2580. ,@createdBy = @user
  2581. ,@controlNo = @controlNo
  2582. ,@isManualSc = @isManualSc
  2583. ,@referralCode = @introducer
  2584. ,@serviceCharge = @iServiceCharge
  2585. DECLARE @NewId uniqueidentifier
  2586. SET @NewId = NEWID()
  2587. INSERT INTO TRU_TranDetail
  2588. (
  2589. refId,
  2590. email,
  2591. createddate,
  2592. orderreference,
  2593. sitereference,
  2594. Tranid,
  2595. customerid,
  2596. token,
  2597. recordStatus
  2598. )
  2599. VALUES
  2600. (
  2601. @NewId
  2602. ,@user
  2603. ,GETDATE()
  2604. ,@controlNo
  2605. ,@sitereference
  2606. ,@id
  2607. ,@senderId
  2608. ,''
  2609. ,'DRAFT'
  2610. )
  2611. -- UPDATE FOR CUSTOMER LOYALTY
  2612. --IF EXISTS (
  2613. -- SELECT TOP 1 1
  2614. -- FROM REFERRAL_AGENT_WISE
  2615. -- WHERE REFERRAL_TYPE_CODE IN (
  2616. -- 'RB'
  2617. -- ,'RC'
  2618. -- )
  2619. -- AND REFERRAL_CODE = @introducer
  2620. -- )
  2621. --BEGIN
  2622. -- IF @isEligible = 'Y'
  2623. -- BEGIN
  2624. -- EXEC PROC_Customer_Loyalty @flag = 'update'
  2625. -- ,@customerId = @SenderId
  2626. -- ,@tranId = @id
  2627. -- ,@createdFrom = 'I'
  2628. -- ,@reqTranCount = @tranCount
  2629. -- ,@schemeCount = @schemeCount
  2630. -- ,@isManualSc = @isManualSc
  2631. -- ,@serviceCharge = @iServiceCharge
  2632. -- ,@createdBy = @user
  2633. -- ,@controlNo = @controlNo
  2634. -- END
  2635. --END
  2636. IF (@iServiceCharge <> @calculatedOriginalSc)
  2637. AND ISNULL(@isManualSc, 'Y') = 'Y'
  2638. BEGIN
  2639. UPDATE remitTranTemp
  2640. SET isScMaunal = 1
  2641. ,originalSC = @calculatedOriginalSc
  2642. ,company = 'M'
  2643. WHERE id = @id
  2644. END
  2645. --SELECT @sourceOfFund = valueId FROM dbo.staticDataValue WHERE detailTitle = @sourceOfFund and typeID = '3900'
  2646. DECLARE @SOURCE INT
  2647. ,@PURPOSEID INT
  2648. ,@RELATION INT
  2649. ,@OCCUPATIONID INT
  2650. SELECT @SOURCE = valueId
  2651. FROM STATICDATAVALUE(NOLOCK)
  2652. WHERE detailTitle = @sourceOfFund
  2653. AND typeID = '3900'
  2654. SELECT @PURPOSEID = valueId
  2655. FROM STATICDATAVALUE(NOLOCK)
  2656. WHERE detailTitle = @purpose
  2657. AND typeID = '3800'
  2658. SELECT @RELATION = valueId
  2659. FROM STATICDATAVALUE(NOLOCK)
  2660. WHERE detailTitle = @relationship
  2661. AND typeID = '2100'
  2662. SELECT @OCCUPATIONID = valueId
  2663. FROM STATICDATAVALUE(NOLOCK)
  2664. WHERE valueId = @occupation
  2665. AND typeID = '2000'
  2666. EXEC PROC_CUSTOMERMODIFYLOG @flag = 'i-fromSendPage'
  2667. ,@user = @user
  2668. ,@customerId = @senderId
  2669. ,@mobileNumber = @sMobile
  2670. ,@monthlyIncome = @salaryRange
  2671. ,@email = @sEmail
  2672. ,@placeofissue = @sCustIdIssuedCountry
  2673. ,@occupation = @OCCUPATIONID
  2674. ,@sourceOfFund = @SOURCE
  2675. UPDATE CUSTOMERMASTER
  2676. SET mobile = ISNULL(@sMobile, mobile)
  2677. ,monthlyincome = ISNULL(@salaryRange, monthlyincome)
  2678. ,email = ISNULL(@sEmail, email)
  2679. ,placeofissue = ISNULL(@sCustIdIssuedCountry, placeofissue)
  2680. ,occupation = ISNULL(@OCCUPATIONID, occupation)
  2681. ,sourceOfFund = ISNULL(@SOURCE, sourceOfFund)
  2682. WHERE CUSTOMERID = @senderId
  2683. EXEC PROC_RECEIVERMODIFYLOGS @flag = 'i-fromSendPage'
  2684. ,@address = @rAdd1
  2685. ,@email = @rEmail
  2686. ,@mobile = @rMobile
  2687. ,@receiverId = @receiverId
  2688. ,@customerId = @senderId
  2689. UPDATE RECEIVERINFORMATION
  2690. SET address = ISNULL(@rAdd1, address)
  2691. ,mobile = ISNULL(@rMobile, mobile)
  2692. ,email = ISNULL(@rEmail, email)
  2693. ,purposeOfRemit = ISNULL(@PURPOSEID, purposeOfRemit)
  2694. ,relationship = ISNULL(@RELATION, relationship)
  2695. ,bankBranchName = ISNULL(@pBankBranchName, bankBranchName)
  2696. WHERE receiverId = @receiverId
  2697. IF @collMode = 'Cash Collect'
  2698. BEGIN
  2699. SELECT @userId = userId
  2700. FROM APPLICATIONUSERS
  2701. WHERE USERNAME = @USER
  2702. EXEC PROC_UPDATE_AVAILABALE_BALANCE @FLAG = 'SEND'
  2703. ,@S_AGENT = @sAgent
  2704. ,@S_USER = @userId
  2705. ,@C_AMT = @cAmt
  2706. ,@REFERRAL_CODE = @introducer
  2707. ,@ONBEHALF = @isOnbehalf
  2708. END
  2709. ELSE
  2710. BEGIN
  2711. EXEC PROC_INSERT_JP_DEPOSIT_TXN_LOG @FLAG = 'I'
  2712. ,@TRANID = @id
  2713. ,@CUSTOMERID = @senderId
  2714. ,@CAMT = @cAmt
  2715. END
  2716. DECLARE @PARTICULARS VARCHAR(200) = 'Send TXN: ' + @controlNo
  2717. EXEC proc_customerTxnHistory @controlNo = @controlNoEncrypted
  2718. DECLARE @XMLDATA XML;
  2719. IF ISNULL(@isAdditionalCDDI, 'N') = 'Y'
  2720. BEGIN
  2721. SET @XMLDATA = CONVERT(XML, REPLACE(@additionalCDDIXml, '&', '&amp;'), 2)
  2722. SELECT ID = p.value('@id', 'varchar(150)')
  2723. ,ANSWER = p.value('@answer', 'varchar(500)')
  2724. INTO #TRANSACTION_COMPLIANCE_CDDI
  2725. FROM @XMLDATA.nodes('/root/row') AS tmp(p);
  2726. INSERT INTO TBL_TXN_COMPLIANCE_CDDI
  2727. SELECT @id
  2728. ,ID
  2729. ,ANSWER
  2730. FROM #TRANSACTION_COMPLIANCE_CDDI
  2731. END
  2732. ----UPDATE BRANCH/AGENT CREDIT LIMIT
  2733. --EXEC Proc_AgentBalanceUpdate_INT @flag = 's',@tAmt = @cAmt ,@settlingAgent = @settlingAgent
  2734. --10. Compliance----------------------------------------------------------------------------------------------------
  2735. IF EXISTS (
  2736. SELECT 'X'
  2737. FROM remitTranComplianceTemp WITH (NOLOCK)
  2738. WHERE agentRefId = @agentRefId
  2739. )
  2740. BEGIN
  2741. INSERT INTO remitTranCompliance (
  2742. TranId
  2743. ,csDetailTranId
  2744. ,matchTranId
  2745. ,reason
  2746. )
  2747. SELECT @id
  2748. ,csDetailTranId
  2749. ,matchTranId
  2750. ,reason
  2751. FROM remitTranComplianceTemp WITH (NOLOCK)
  2752. WHERE agentRefId = @agentRefId
  2753. SET @compFinalRes = 'C'
  2754. UPDATE ComplianceLog
  2755. SET tranId = @id
  2756. WHERE agentRefId = @agentRefId
  2757. END
  2758. IF EXISTS (
  2759. SELECT 'X'
  2760. FROM @remitTranTemp
  2761. WHERE dot BETWEEN CONVERT(VARCHAR, GETDATE(), 101)
  2762. AND CONVERT(VARCHAR, GETDATE(), 101) + ' 23:59:59'
  2763. AND cAmt = @cAmt
  2764. AND (
  2765. receiverName = @receiverName
  2766. OR (
  2767. ISNULL(receiverIdType, '0') = @rIdType
  2768. AND ISNULL(receiverIdNumber, '0') = @rIdNo
  2769. )
  2770. )
  2771. )
  2772. BEGIN
  2773. INSERT INTO remitTranCompliance (
  2774. TranId
  2775. ,csDetailTranId
  2776. ,matchTranId
  2777. ,reason
  2778. )
  2779. SELECT @id
  2780. ,0
  2781. ,tranid
  2782. ,'Suspected duplicate transaction'
  2783. FROM @remitTranTemp
  2784. WHERE cAmt = @cAmt
  2785. AND (
  2786. receiverName = @receiverName
  2787. OR (
  2788. ISNULL(receiverIdType, '0') = @rIdType
  2789. AND ISNULL(receiverIdNumber, '0') = @rIdNo
  2790. )
  2791. )
  2792. SET @compFinalRes = 'C'
  2793. END
  2794. ELSE
  2795. BEGIN
  2796. IF EXISTS (
  2797. SELECT 'X'
  2798. FROM @moneySendTemp
  2799. WHERE paidAmt = @cAmt
  2800. AND (
  2801. receiverName = @receiverName
  2802. OR (
  2803. ISNULL(receiverIdDescription, '0') = @rIdType
  2804. AND ISNULL(receiverIdDetail, '0') = @rIdNo
  2805. )
  2806. )
  2807. )
  2808. BEGIN
  2809. INSERT INTO remitTranCompliance (
  2810. TranId
  2811. ,csDetailTranId
  2812. ,matchTranId
  2813. ,reason
  2814. )
  2815. SELECT @id
  2816. ,0
  2817. ,tranNo
  2818. ,'Suspected duplicate transaction from Inficare system'
  2819. FROM @moneySendTemp
  2820. WHERE paidAmt = @cAmt
  2821. AND (
  2822. receiverName = @receiverName
  2823. OR (
  2824. ISNULL(receiverIdDescription, '0') = @rIdType
  2825. AND ISNULL(receiverIdDetail, '0') = @rIdNo
  2826. )
  2827. )
  2828. SET @compFinalRes = 'C'
  2829. END
  2830. END
  2831. IF (
  2832. ISNULL(@compFinalRes, '') <> ''
  2833. OR ISNULL(@ofacRes, '') <> ''
  2834. )
  2835. BEGIN
  2836. CREATE TABLE #temp (
  2837. sno INT
  2838. ,rmrks NVARCHAR(MAX)
  2839. )
  2840. SELECT @checkNameBy = TRACK_BY
  2841. FROM OFACSETTING(NOLOCK)
  2842. IF ISNULL(@checkNameBy, 'OFAC') = 'OFAC'
  2843. BEGIN
  2844. INSERT INTO #temp (
  2845. sno
  2846. ,rmrks
  2847. )
  2848. EXEC proc_sendPageLoadData @flag = 'ofac'
  2849. ,@user = @user
  2850. ,@blackListIds = @ofacRes
  2851. END
  2852. ELSE
  2853. BEGIN
  2854. INSERT INTO #temp (
  2855. sno
  2856. ,rmrks
  2857. )
  2858. EXEC proc_sendPageLoadData @flag = 'ofac'
  2859. ,@user = @user
  2860. ,@blackListIds = @ofacRes
  2861. ,@TRACK_BY = 'DJ'
  2862. END
  2863. DECLARE @ofacResult NVARCHAR(MAX)
  2864. SET @ofacResult = (
  2865. SELECT *
  2866. FROM #temp
  2867. FOR JSON AUTO
  2868. )
  2869. IF (
  2870. @ofacRes <> ''
  2871. AND ISNULL(@compFinalRes, '') = ''
  2872. )
  2873. BEGIN
  2874. INSERT remitTranOfac (
  2875. TranId
  2876. ,blackListId
  2877. ,reason
  2878. ,flag
  2879. ,TRACK_BY
  2880. ,ofacDetail
  2881. )
  2882. SELECT @id
  2883. ,@ofacRes
  2884. ,@ofacReason
  2885. ,CASE
  2886. WHEN @trackBy = 'OFAC'
  2887. THEN dbo.FNAGetOFAC_Flag(@ofacRes)
  2888. ELSE 'D'
  2889. END
  2890. ,@checkNameBy
  2891. ,@ofacResult
  2892. UPDATE remitTranTemp
  2893. SET tranStatus = 'OFAC Hold'
  2894. WHERE controlNo = @controlNoEncrypted
  2895. END
  2896. ELSE IF (
  2897. @compFinalRes <> ''
  2898. AND ISNULL(@ofacRes, '') = ''
  2899. )
  2900. BEGIN
  2901. UPDATE remitTranTemp
  2902. SET tranStatus = 'Compliance Hold'
  2903. WHERE controlNo = @controlNoEncrypted
  2904. END
  2905. ELSE IF (
  2906. ISNULL(@compFinalRes, '') <> ''
  2907. AND ISNULL(@ofacRes, '') <> ''
  2908. )
  2909. BEGIN
  2910. INSERT remitTranOfac (
  2911. TranId
  2912. ,blackListId
  2913. ,reason
  2914. ,flag
  2915. ,TRACK_BY
  2916. ,ofacDetail
  2917. )
  2918. SELECT @id
  2919. ,@ofacRes
  2920. ,@ofacReason
  2921. ,CASE
  2922. WHEN @trackBy = 'OFAC'
  2923. THEN dbo.FNAGetOFAC_Flag(@ofacRes)
  2924. ELSE 'D'
  2925. END
  2926. ,@checkNameBy
  2927. ,@ofacResult
  2928. UPDATE remitTranTemp
  2929. SET tranStatus = 'OFAC/Compliance Hold'
  2930. WHERE controlNo = @controlNoEncrypted
  2931. END
  2932. END
  2933. IF @LIMITERRORCODE <> 0
  2934. AND @RULETYPE = 'H'
  2935. AND @COLLMODE = 'CASH COLLECT'
  2936. BEGIN
  2937. UPDATE remitTranTemp
  2938. SET tranStatus = CASE
  2939. WHEN tranStatus = 'Compliance Hold'
  2940. THEN 'Cash Limit/Compliance Hold'
  2941. WHEN tranStatus = 'OFAC Hold'
  2942. THEN 'Cash Limit/OFAC Hold'
  2943. WHEN tranStatus = 'OFAC/Compliance Hold'
  2944. THEN 'Cash Limit/OFAC/Compliance Hold'
  2945. ELSE 'Cash Limit Hold'
  2946. END
  2947. WHERE controlNo = @controlNoEncrypted
  2948. INSERT INTO dbo.remitTranCashLimitHold (
  2949. tranId
  2950. ,approvedRemarks
  2951. ,approvedBy
  2952. ,approvedDate
  2953. ,reason
  2954. )
  2955. VALUES (
  2956. @id
  2957. ,-- tranId - bigint
  2958. NULL
  2959. ,-- approvedRemarks - varchar(150)
  2960. NULL
  2961. ,-- approvedBy - varchar(80)
  2962. NULL
  2963. ,-- approvedDate - datetime
  2964. NULL -- reason - varchar(500)
  2965. )
  2966. END
  2967. --New logic for referral
  2968. IF ISNULL(@rewardAmt, 0) > 0
  2969. EXEC proc_InsertRewardPoints @Flag = 'DEBIT', @CustomerId = @senderId, @rewardPoints = @rewardAmt, @TranId = @id
  2970. IF @@TRANCOUNT > 0
  2971. COMMIT TRANSACTION
  2972. IF (
  2973. @complianceRes = 'C'
  2974. OR @ofacRes <> ''
  2975. )
  2976. BEGIN
  2977. SELECT 101 errorCode
  2978. ,'Transaction under compliance' msg
  2979. ,@controlNo id
  2980. ,@id extra
  2981. ,@paymentOption extra2
  2982. ,@NewId extra3
  2983. RETURN
  2984. END
  2985. SELECT 100 errorCode
  2986. ,'Transaction has been sent successfully and is waiting for approval' msg
  2987. ,@controlNo id
  2988. ,@id extra
  2989. ,@paymentOption extra2
  2990. ,@NewId extra3
  2991. END
  2992. ELSE IF @flag = 'exRate' --Get Exchange Rate, Service Charge, Scheme/Offer and amount details
  2993. BEGIN
  2994. IF @partnerId IS NOT NULL --AND @pCountryId = '203'
  2995. SELECT @payoutPartner = AGENTID
  2996. ,@exRateCalByPartner = ISNULL(exRateCalByPartner, 0)
  2997. FROM TblPartnerwiseCountry(NOLOCK)
  2998. WHERE CountryId = @pCountryId
  2999. AND IsActive = 1
  3000. AND ISNULL(PaymentMethod, @deliveryMethod) = @deliveryMethod
  3001. AND AGENTID = @partnerId
  3002. ELSE
  3003. SELECT @payoutPartner = AGENTID
  3004. ,@exRateCalByPartner = ISNULL(exRateCalByPartner, 0)
  3005. FROM TblPartnerwiseCountry(NOLOCK)
  3006. WHERE CountryId = @pCountryId
  3007. AND IsActive = 1
  3008. AND ISNULL(PaymentMethod, @deliveryMethod) = @deliveryMethod
  3009. IF @payoutPartner IS NOT NULL
  3010. BEGIN
  3011. --GET PAYOUT AGENT DETAILS
  3012. SELECT @PAGENT = AGENTID
  3013. FROM AGENTMASTER(NOLOCK)
  3014. WHERE PARENTID = @payoutPartner
  3015. AND ISNULL(ISSETTLINGAGENT, 'N') = 'Y';
  3016. SELECT @pSuperAgent = sSuperAgent
  3017. ,@pSuperAgentName = sSuperAgentName
  3018. ,@pAgent = sAgent
  3019. ,@pAgentName = sAgentName
  3020. ,@pBranch = sBranch
  3021. ,@pBranchName = sBranchName
  3022. FROM dbo.FNAGetBranchFullDetails(@PAGENT)
  3023. END
  3024. ELSE
  3025. BEGIN
  3026. SELECT '1' ErrCode
  3027. ,'Partner not yet mapped for the selected country!' Msg
  3028. ,NULL id
  3029. RETURN
  3030. END
  3031. DECLARE @rowId INT
  3032. SELECT @scValue = 0
  3033. ,@scOffer = 0
  3034. ,@exRateOffer = 0
  3035. ,@scDiscount = 0
  3036. --2. Find Decimal Mask for payout amount rounding
  3037. SELECT @pCurr = pCurrency
  3038. FROM dbo.exRateTreasury WITH (NOLOCK)
  3039. WHERE pCountry = @pCountryId
  3040. AND pAgent = @pAgent
  3041. IF @pCurr IS NULL
  3042. SELECT @pCurr = pCurrency
  3043. FROM dbo.exRateTreasury WITH (NOLOCK)
  3044. WHERE pCountry = @pCountryId
  3045. AND pAgent IS NULL
  3046. SELECT @place = place
  3047. ,@currDecimal = currDecimal
  3048. FROM currencyPayoutRound WITH (NOLOCK)
  3049. WHERE ISNULL(isDeleted, 'N') = 'N'
  3050. AND currency = @pCurr
  3051. AND ISNULL(tranType, @deliveryMethod) = @deliveryMethod
  3052. SET @currDecimal = ISNULL(@currDecimal, 0)
  3053. IF @pCurr IS NULL
  3054. BEGIN
  3055. SELECT '1' ErrCode
  3056. ,'Currency not been defined yet for receiving country' Msg
  3057. ,NULL id
  3058. RETURN
  3059. END
  3060. IF @pCountryId = 151
  3061. AND @deliveryMethod = 1
  3062. BEGIN
  3063. SELECT AgentId
  3064. INTO #AgentList
  3065. FROM agentMaster(NOLOCK)
  3066. WHERE extCode = 'NP ANYWHERE'
  3067. SELECT @exRate = MAX(customerRate)
  3068. FROM #AgentList A
  3069. CROSS APPLY dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, AgentId, @pCurr, @deliveryMethod) FN
  3070. END
  3071. ELSE
  3072. BEGIN
  3073. SELECT @exRate = dbo.FNAGetCustomerRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  3074. END
  3075. IF ISNULL(@exRate, 0) = 0
  3076. BEGIN
  3077. SELECT '1' ErrCode
  3078. ,'Exchange rate not defined yet for receiving currency (' + @pCurr + ')' Msg
  3079. ,NULL id
  3080. RETURN
  3081. END
  3082. IF @tpExRate > 0
  3083. BEGIN
  3084. SET @exRate = @exRate - @tpExRate
  3085. END
  3086. --New code added, referral code add #arjun
  3087. --EXEC PROC_Customer_LoyaltyV2 @flag = 'check-eligible-v2'
  3088. -- ,@isEligible = @isEligible OUT
  3089. -- ,@referralCode = @introducer
  3090. -- ,@tranCount = @trancount OUT
  3091. -- ,@schemeCount = @schemeCount OUT
  3092. -- ,@customerId = @senderId
  3093. -- ,@createdFrom = 'I'
  3094. --IF EXISTS (
  3095. -- SELECT TOP 1 1
  3096. -- FROM REFERRAL_AGENT_WISE
  3097. -- WHERE REFERRAL_TYPE_CODE IN (
  3098. -- 'RB'
  3099. -- ,'RC'
  3100. -- )
  3101. -- AND REFERRAL_CODE = @introducer
  3102. -- )
  3103. --BEGIN
  3104. -- EXEC PROC_Customer_Loyalty @flag = 'check-eligible'
  3105. -- ,@isEligible = @isEligible OUT
  3106. --END
  3107. --EXEC proc_Customer_Loyalty @flag = 'get-tranCount'
  3108. -- ,@tranCount = @trancount OUT
  3109. -- ,@customerId = @senderId
  3110. --SELECT TOP 1 @schemeCount = txnCount
  3111. --FROM schemeSetup(NOLOCK)
  3112. --ORDER BY createdDate DESC
  3113. pRINT @schemeCount;
  3114. pRINT @isEligible;
  3115. pRINT @trancount;
  3116. DECLARE @availableRewardAmt INT
  3117. SELECT @availableRewardAmt = CAST(dbo.[FNA_GET_AVAILABLE_BALANCE_POINTS](@senderId) AS INT)
  3118. IF (@rewardAmt > '0.00')
  3119. BEGIN
  3120. IF (@availableRewardAmt < ISNULL(@rewardAmt, 0))
  3121. BEGIN
  3122. SELECT '1' ErrCode
  3123. ,'You do not have sufficient points to redeem!'
  3124. ,NULL id
  3125. RETURN;
  3126. END
  3127. END
  3128. IF(@rewardAmt > @availableRewardAmt)
  3129. BEGIN
  3130. SELECT '1' ErrCode
  3131. ,'Please enter the valid point. The amount cannot be more than available Reward Amount!' Msg
  3132. ,NULL id
  3133. RETURN
  3134. END
  3135. IF ISNULL(@cAmt, 0.00) <> 0.00
  3136. BEGIN
  3137. IF @isEligible = 'Y'
  3138. BEGIN
  3139. SET @serviceCharge = 0
  3140. SET @isFreeSc = 'Y'
  3141. END
  3142. ELSE
  3143. BEGIN
  3144. SELECT @calcOriginalSc = amount
  3145. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethod, @cAmt, @collCurr)
  3146. IF ISNULL(@isManualSc, 'N') = 'N'
  3147. BEGIN
  3148. SELECT @serviceCharge = amount
  3149. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethod, @cAmt, @collCurr)
  3150. END
  3151. ELSE
  3152. BEGIN
  3153. SET @serviceCharge = ISNULL(@manualSc, 0)
  3154. END
  3155. IF @serviceCharge IS NULL
  3156. AND ISNULL(@isManualSc, 'N') = 'N'
  3157. BEGIN
  3158. SELECT '1' ErrCode
  3159. ,'Service charge not defined yet for receiving country' Msg
  3160. ,NULL id
  3161. RETURN;
  3162. END
  3163. END
  3164. IF @scAction = 'PD' -- Percent Discount
  3165. BEGIN
  3166. SET @scOffer = (@scValue / 100) * @serviceCharge
  3167. SET @scDiscount = (@scValue / 100) * @serviceCharge
  3168. END
  3169. ELSE IF @scAction = 'FD' -- Flat Discount
  3170. BEGIN
  3171. SET @scDiscount = @scValue
  3172. END
  3173. ELSE IF @scAction = 'FV' -- Fixed Value
  3174. BEGIN
  3175. SET @scOffer = @scValue
  3176. SET @scDiscount = @serviceCharge - @scValue
  3177. END
  3178. PRINT @serviceCharge
  3179. SET @tAmt = @cAmt - @serviceCharge + @scDiscount + ISNULL(@rewardAmt,0)
  3180. SET @pAmt = @tAmt * (@exRate + @exRateOffer)
  3181. SET @pAmt = FLOOR(@pAmt)
  3182. END
  3183. ELSE
  3184. BEGIN
  3185. --SET @tAmt = ROUND(@pAmt/(@exRate + @exRateOffer),0)
  3186. SET @tAmt = CEILING(@pAmt / (@exRate + @exRateOffer))
  3187. IF @isEligible = 'Y'
  3188. BEGIN
  3189. SET @serviceCharge = 0
  3190. SET @isFreeSc = 'Y'
  3191. END
  3192. ELSE
  3193. BEGIN
  3194. SELECT @calcOriginalSc = amount
  3195. FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethod, @tAmt, @collCurr)
  3196. IF ISNULL(@isManualSc, 'N') = 'N'
  3197. BEGIN
  3198. SELECT @serviceCharge = @calcOriginalSc --amount
  3199. --FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethod, @tAmt, @collCurr)
  3200. END
  3201. ELSE
  3202. BEGIN
  3203. SET @serviceCharge = ISNULL(@manualSc, 0)
  3204. END
  3205. IF @serviceCharge IS NULL
  3206. BEGIN
  3207. SELECT '1' ErrCode
  3208. ,'Service charge not defined yet for receiving country' Msg
  3209. ,NULL id
  3210. RETURN;
  3211. END
  3212. END
  3213. IF @scAction = 'PD'
  3214. BEGIN
  3215. SET @scOffer = (@scValue / 100) * @serviceCharge
  3216. SET @scDiscount = (@scValue / 100) * @serviceCharge
  3217. END
  3218. ELSE IF @scAction = 'FD'
  3219. BEGIN
  3220. SET @scDiscount = @scValue
  3221. END
  3222. ELSE IF @scAction = 'FV'
  3223. BEGIN
  3224. SET @scOffer = @scValue
  3225. SET @scDiscount = @serviceCharge - @scValue
  3226. END
  3227. SET @cAmt = (@tAmt + @serviceCharge - @scDiscount)
  3228. SET @cAmt = CEILING(@cAmt)
  3229. END
  3230. --New validation negative coll amt due to manual service charge added
  3231. IF @pAmt <= 0
  3232. OR @tAmt <= 0
  3233. OR @cAmt <= 0
  3234. BEGIN
  3235. SELECT '1' ErrCode
  3236. ,'Invalid payout/transfer amount/collect amount found!' Msg
  3237. ,NULL id
  3238. RETURN;
  3239. END
  3240. ----validate cash hold limit of branch/user
  3241. --EXEC PROC_CHECK_BRANCH_USER_CASH_HOLD_LIMIT @USER = @USER, @CAMT = @CAMT, @ERRORCODE = @LIMITERRORCODE OUT
  3242. -- , @ERRORMSG = @msg OUT, @RULETYPE = @RULETYPE OUT
  3243. --IF @LIMITERRORCODE <> 0 AND @RULETYPE = 'B' AND @collMode = 'CASH COLLECT'
  3244. --BEGIN
  3245. -- SELECT '1' ErrCode, 'Branch/User cash hold limit is exceeded, please contact head office!' Msg,NULL id
  3246. -- RETURN
  3247. --END
  3248. --4. Validate Country Sending Limit
  3249. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit'
  3250. ,@cAmt = @cAmt
  3251. ,@pAmt = @pAmt
  3252. ,@sCountryId = @sCountryId
  3253. ,@collMode = @collMode
  3254. ,@deliveryMethod = @deliveryMethod
  3255. ,@sendingCustType = @sendingCustType
  3256. ,@pCountryId = @pCountryId
  3257. ,@pCurr = @pCurr
  3258. ,@collCurr = @collCurr
  3259. ,@pAgent = @pAgent
  3260. ,@sAgent = @sAgent
  3261. ,@sBranch = @sBranch
  3262. ,@msg = @msg OUT
  3263. ,@errorCode = @errorCode OUT
  3264. IF @errorCode <> '0'
  3265. BEGIN
  3266. SELECT @errorCode ErrCode
  3267. ,@msg Msg
  3268. RETURN;
  3269. END
  3270. PRINT @cAmt
  3271. PRINT @pAmt
  3272. PRINT @sCountryId
  3273. PRINT @collMode
  3274. PRINT @deliveryMethod
  3275. --Validate Country Sending Limit END
  3276. --5. Validate Country Receiving Limit
  3277. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit'
  3278. ,@cAmt = @cAmt
  3279. ,@pAmt = @pAmt
  3280. ,@sCountryId = @sCountryId
  3281. ,@collMode = @collMode
  3282. ,@deliveryMethod = @deliveryMethod
  3283. ,@sendingCustType = @sendingCustType
  3284. ,@pCountryId = @pCountryId
  3285. ,@pCurr = @pCurr
  3286. ,@collCurr = @collCurr
  3287. ,@pAgent = @pAgent
  3288. ,@sAgent = @sAgent
  3289. ,@sBranch = @sBranch
  3290. ,@msg = @msg OUT
  3291. ,@errorCode = @errorCode OUT
  3292. IF @errorCode <> '0'
  3293. BEGIN
  3294. SELECT @errorCode ErrCode
  3295. ,@msg Msg
  3296. RETURN;
  3297. END
  3298. --Validate Country Receiving Limit
  3299. SET @msg = 'Success'
  3300. SELECT @errorCode ErrCode
  3301. ,@msg Msg
  3302. ,scCharge = @serviceCharge
  3303. ,exRate = @exRate
  3304. ,place = @place
  3305. ,pCurr = @pCurr
  3306. ,currDecimal = @currDecimal
  3307. ,pAmt = @pAmt
  3308. ,sAmt = @tAmt
  3309. ,place = @place
  3310. ,disc = 0.00
  3311. ,collAmt = @cAmt
  3312. ,exRateOffer = @exRateOffer
  3313. ,scOffer = @scDiscount
  3314. ,scAction = @scAction
  3315. ,scValue = @scValue
  3316. ,scDiscount = @scDiscount
  3317. ,tpExRate = 0
  3318. ,exRateConfirmId = 0
  3319. ,IsFreeSc = @isFreeSc
  3320. ,calcOriginalSc = @calcOriginalSc
  3321. END
  3322. ELSE IF @flag = 'customerRate' --Get Customer Rate
  3323. BEGIN
  3324. SELECT TOP 1 @pCurr = CM.currencyCode
  3325. FROM currencyMaster CM WITH (NOLOCK)
  3326. INNER JOIN countryCurrency CC WITH (NOLOCK) ON CM.currencyId = CC.currencyId
  3327. WHERE CC.countryId = @pCountryId
  3328. AND ISNULL(CC.isDeleted, 'N') = 'N'
  3329. IF @pCurr IS NULL
  3330. BEGIN
  3331. SELECT '1' ErrCode
  3332. ,'Not defined' Msg
  3333. ,NULL id
  3334. RETURN
  3335. END
  3336. SELECT @exRate = dbo.FNAGetCustomerRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  3337. IF @exRate IS NULL
  3338. BEGIN
  3339. SELECT '1' ErrCode
  3340. ,'Not defined' Msg
  3341. ,NULL id
  3342. RETURN
  3343. END
  3344. DECLARE @maxLimit AS MONEY
  3345. ,@lCurr AS VARCHAR(10)
  3346. SELECT @maxLimit = maxLimitAmt
  3347. ,@lCurr = currency
  3348. FROM sendTranLimit WITH (NOLOCK)
  3349. WHERE agentId = @sAgent
  3350. AND ISNULL(receivingCountry, ISNULL(@pCountryId, 0)) = ISNULL(@pCountryId, 0)
  3351. AND ISNULL(tranType, ISNULL(@deliveryMethod, 0)) = ISNULL(@deliveryMethod, 0)
  3352. AND currency = @collCurr
  3353. AND ISNULL(isActive, 'N') = 'Y'
  3354. AND ISNULL(isDeleted, 'N') = 'N'
  3355. SELECT @maxLimit = maxLimitAmt
  3356. ,@lCurr = currency
  3357. FROM sendTranLimit WITH (NOLOCK)
  3358. WHERE agentId IS NULL
  3359. AND ISNULL(receivingCountry, ISNULL(@pCountryId, 0)) = ISNULL(@pCountryId, 0)
  3360. AND ISNULL(tranType, ISNULL(@deliveryMethod, 0)) = ISNULL(@deliveryMethod, 0)
  3361. AND currency = @collCurr
  3362. AND ISNULL(isActive, 'N') = 'Y'
  3363. AND ISNULL(isDeleted, 'N') = 'N'
  3364. SELECT '0' ErrCode
  3365. ,@exRate exRate
  3366. ,@pCurr pCurr
  3367. ,@maxLimit limit
  3368. ,@lCurr limitCurr
  3369. END
  3370. ELSE IF @flag = 'CustdayLimit' -- CUSTOMER PER DAY LIMIT
  3371. BEGIN
  3372. DECLARE @txnSum MONEY
  3373. ,@txnCount INT
  3374. ,@tranId INT
  3375. ,@date VARCHAR(20) = CONVERT(VARCHAR(20), GETDATE(), 111)
  3376. SELECT @limitBal = D.amount
  3377. FROM csMaster M WITH (NOLOCK)
  3378. INNER JOIN csDetail D WITH (NOLOCK) ON M.csMasterId = D.csDetailId
  3379. WHERE sCountry = @sCountryId
  3380. AND ISNULL(M.isActive, 'Y') = 'Y'
  3381. AND ISNULL(D.isActive, 'Y') = 'Y'
  3382. SELECT @txnSum = ISNULL(SUM(R.cAmt), 0)
  3383. ,@txnCount = COUNT('x')
  3384. FROM remitTran R WITH (NOLOCK)
  3385. ,tranSenders S WITH (NOLOCK)
  3386. WHERE R.id = S.tranId
  3387. AND S.customerId = @senderId
  3388. AND R.approvedDate BETWEEN @date
  3389. AND @date + ' 23:59:59'
  3390. SELECT ISNULL(@limitBal, 0) countryBalLimit
  3391. ,ISNULL(@txnSum, 0) custDayLimit
  3392. ,ISNULL(@txnCount, 0) custDayTxn
  3393. ,CAST(GETDATE() AS DATE) [txnDate]
  3394. END
  3395. ELSE IF @flag = 'cti' --All transaction information (sender, receiver, payout)
  3396. BEGIN
  3397. SELECT DISTINCT c.customerId
  3398. ,c.membershipId
  3399. ,Name = c.firstName + ISNULL(' ' + c.middleName, '') + ISNULL(' ' + c.lastName1, '') + ISNULL(' ' + c.lastName2, '')
  3400. ,c.Country
  3401. ,Address
  3402. ,[State]
  3403. ,Phone = COALESCE(mobile, homePhone, workPhone)
  3404. ,city
  3405. FROM tranSenders c WITH (NOLOCK)
  3406. WHERE c.id = @senderId
  3407. SELECT DISTINCT c.customerId
  3408. ,c.membershipId
  3409. ,Name = c.firstName + ISNULL(' ' + c.middleName, '') + ISNULL(' ' + c.lastName1, '') + ISNULL(' ' + c.lastName2, '')
  3410. ,Country
  3411. ,Address
  3412. ,[State]
  3413. ,Phone = COALESCE(mobile, homePhone, workPhone)
  3414. ,city
  3415. FROM tranreceivers c WITH (NOLOCK)
  3416. WHERE c.id = @benId
  3417. IF @agentId > 0
  3418. BEGIN
  3419. SELECT DISTINCT am.agentId
  3420. ,am.agentCode
  3421. ,name = am.agentName
  3422. ,address = am.agentAddress
  3423. ,city = agentCity
  3424. ,[State] = agentState
  3425. ,Phone = COALESCE(agentMobile1, agentMobile2, agentPhone1, agentPhone2)
  3426. ,Country = @pCountry
  3427. FROM agentMaster am WITH (NOLOCK)
  3428. LEFT JOIN agentCurrency ac WITH (NOLOCK) ON am.agentId = ac.agentId
  3429. WHERE am.agentId = @agentId
  3430. END
  3431. ELSE
  3432. BEGIN
  3433. SELECT agentId = NULL
  3434. ,agentCode = NULL
  3435. ,name = 'Any'
  3436. ,address = NULL
  3437. ,city = NULL
  3438. ,STATE = NULL
  3439. ,Phone = NULL
  3440. ,country = @pCountry
  3441. END
  3442. END
  3443. ELSE IF @flag = 'controlNo'
  3444. BEGIN
  3445. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  3446. SELECT senderId = sen.customerId
  3447. ,benId = ben.customerId
  3448. ,pCountry = cm.countryId
  3449. ,deliveryMethod = stm.serviceTypeId
  3450. ,tAmt = trn.tAmt
  3451. ,cAmt = trn.cAmt
  3452. ,pAmt = trn.pAmt
  3453. ,customerRate = trn.customerRate
  3454. ,serviceCharge = trn.serviceCharge
  3455. ,trn.collCurr
  3456. ,trn.payoutCurr
  3457. ,agentId = pBranch
  3458. FROM remitTran trn WITH (NOLOCK)
  3459. INNER JOIN tranSenders sen WITH (NOLOCK) ON trn.id = sen.tranId
  3460. INNER JOIN tranReceivers ben WITH (NOLOCK) ON trn.id = ben.tranId
  3461. INNER JOIN countryMaster cm WITH (NOLOCK) ON trn.pCountry = cm.countryName
  3462. INNER JOIN serviceTypeMaster stm WITH (NOLOCK) ON trn.paymentMethod = stm.typeTitle
  3463. WHERE controlNo = @controlNoEncrypted
  3464. END
  3465. ELSE IF @flag = 'senderId'
  3466. BEGIN
  3467. SELECT TOP 1 senderId = sen.customerId
  3468. ,benId = ben.customerId
  3469. ,pCountry = cm.countryId
  3470. ,deliveryMethod = stm.serviceTypeId
  3471. ,tAmt = trn.tAmt
  3472. ,cAmt = trn.cAmt
  3473. ,pAmt = trn.pAmt
  3474. ,customerRate = trn.customerRate
  3475. ,serviceCharge = trn.serviceCharge
  3476. ,trn.collCurr
  3477. ,trn.payoutCurr
  3478. ,agentId = pBranch
  3479. FROM remitTran trn WITH (NOLOCK)
  3480. INNER JOIN tranSenders sen WITH (NOLOCK) ON trn.id = sen.tranId
  3481. INNER JOIN tranReceivers ben WITH (NOLOCK) ON trn.id = ben.tranId
  3482. INNER JOIN countryMaster cm WITH (NOLOCK) ON trn.pCountry = cm.countryName
  3483. INNER JOIN serviceTypeMaster stm WITH (NOLOCK) ON trn.paymentMethod = stm.typeTitle
  3484. WHERE sen.customerId = @senderId
  3485. ORDER BY trn.id DESC
  3486. END
  3487. ELSE IF @flag = 'chkSenderIdNo'
  3488. BEGIN
  3489. --IF EXISTS(SELECT 'X' FROM dbo.customerMaster WITH(NOLOCK) WHERE idNumber = @sIdNo AND ISNULL(isDeleted, 'N') = 'N')
  3490. --BEGIN
  3491. -- EXEC proc_errorHandler 1, 'Customer is already registered with this Id Number', NULL
  3492. -- RETURN
  3493. --END
  3494. EXEC proc_errorHandler 0
  3495. ,'Success'
  3496. ,NULL
  3497. END
  3498. END
  3499. END TRY
  3500. BEGIN CATCH
  3501. IF @@TRANCOUNT <> 0
  3502. ROLLBACK TRANSACTION
  3503. DECLARE @errorMessage VARCHAR(MAX)
  3504. SET @errorMessage = ERROR_MESSAGE()
  3505. EXEC proc_errorHandler 1
  3506. ,@errorMessage
  3507. ,@user
  3508. END CATCH