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.

3358 lines
168 KiB

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