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.

2197 lines
110 KiB

9 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_ApproveHoldedTXN] Script Date: 12/29/2023 11:24:14 AM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_ApproveHoldedTXN] (
  9. @flag VARCHAR(50)
  10. ,@user VARCHAR(130)
  11. ,@userType VARCHAR(10) = NULL
  12. ,@branch VARCHAR(50) = NULL
  13. ,@id VARCHAR(40) = NULL
  14. ,@country VARCHAR(50) = NULL
  15. ,@sender VARCHAR(50) = NULL
  16. ,@receiver VARCHAR(50) = NULL
  17. ,@amt MONEY = NULL
  18. ,@bank VARCHAR(50) = NULL
  19. ,@voucherNo VARCHAR(50) = NULL
  20. ,@branchId INT = NULL
  21. ,@pin VARCHAR(50) = NULL
  22. ,@errorCode VARCHAR(10) = NULL
  23. ,@msg VARCHAR(500) = NULL
  24. ,@idList XML = NULL
  25. ,@txnDate VARCHAR(20) = NULL
  26. ,@txncreatedBy VARCHAR(50) = NULL
  27. ,@xml VARCHAR(MAX) = NULL
  28. ,@remarks VARCHAR(MAX) = NULL
  29. ,@settlingAgentId INT = NULL
  30. ,@ControlNo VARCHAR(50) = NULL
  31. ,@txnType VARCHAR(1) = NULL
  32. ,@sendCountry VARCHAR(50) = NULL
  33. ,@sendAgent VARCHAR(50) = NULL
  34. ,@sendBranch VARCHAR(50) = NULL
  35. ,@approvedFrom VARCHAR(10) = NULL
  36. ,@tpControlNo1 VARCHAR(30) = NULL
  37. ,@tpControlNo2 VARCHAR(30) = NULL
  38. ,@isTxnRealtime BIT = NULL
  39. ,@isSystemReject BIT = NULL
  40. ,@cancelReason VARCHAR(150) = NULL
  41. ,@cancelDate VARCHAR(20) = NULL
  42. ,@downlodedBy VARCHAR(50) = NULL
  43. )
  44. AS
  45. --#298 Trim white space of Control number and TranId
  46. --#101 - Mobile Changes
  47. -- #652 - collected by ddl in verify transaction
  48. --#618: Bank Deposit details not displayed.
  49. -- #1135 pushNotificationHistroy
  50. -- #739 Ime pay
  51. BEGIN TRY
  52. DECLARE @table VARCHAR(MAX)
  53. ,@sql VARCHAR(MAX)
  54. ,@sqlSelfTxn VARCHAR(MAX)
  55. ,@sRouteId VARCHAR(5)
  56. ,@collMode VARCHAR(100)
  57. SET NOCOUNT ON;
  58. SET XACT_ABORT ON;
  59. DECLARE @pinEncrypted VARCHAR(50) = dbo.FNAEncryptString(@pin)
  60. ,@cAmt MONEY
  61. ,@userId INT
  62. ,@createdBy VARCHAR(50)
  63. ,@tranStatus VARCHAR(50)
  64. ,@message VARCHAR(200)
  65. ,@sBranch BIGINT
  66. ,@invicePrintMethod VARCHAR(50)
  67. ,@parentId BIGINT
  68. ,@tablesql AS VARCHAR(MAX)
  69. ,@branchList VARCHAR(MAX)
  70. ,@denyAmt MONEY
  71. ,@C2CAgentID VARCHAR(30) = '1045'
  72. ,@REAgentID VARCHAR(30) = '1100'
  73. ,@transactionType CHAR(1) = NULL
  74. ,@controlNo2 VARCHAR(20)
  75. IF @pin IS NULL
  76. BEGIN
  77. SELECT @pin = dbo.FNADecryptString(controlNo)
  78. ,@pinEncrypted = controlNo
  79. FROM remitTranTemp WITH (NOLOCK)
  80. WHERE id = @id
  81. END
  82. ELSE
  83. BEGIN
  84. SET @pinEncrypted = dbo.FNAEncryptString(UPPER(LTRIM(RTRIM(@pin))))
  85. END
  86. DECLARE @PinList TABLE (
  87. id VARCHAR(50)
  88. ,pin VARCHAR(50)
  89. ,hasProcess CHAR(1)
  90. ,isOFAC CHAR(1)
  91. ,errorMsg VARCHAR(MAX)
  92. ,tranId INT
  93. ,createdBy VARCHAR(50)
  94. )
  95. DECLARE @TempcompTable TABLE (
  96. errorCode INT
  97. ,msg VARCHAR(MAX)
  98. ,id VARCHAR(50)
  99. )
  100. DECLARE @isSelfApprove VARCHAR(1)
  101. IF @flag = 'provider'
  102. BEGIN
  103. DECLARE @pAgent INT
  104. SELECT @pAgent = pAgent
  105. FROM remitTranTemp WITH (NOLOCK)
  106. WHERE id = @id
  107. IF @pAgent IS NULL
  108. BEGIN
  109. SELECT @pAgent = pAgent
  110. FROM vwremitTran WITH (NOLOCK)
  111. WHERE id = @id
  112. END
  113. SELECT @pAgent pAgent
  114. RETURN
  115. END
  116. IF @flag = 'get-info'
  117. BEGIN
  118. IF NOT EXISTS (
  119. SELECT *
  120. FROM REMITTRANTEMP(NOLOCK)
  121. WHERE ID = @id
  122. )
  123. BEGIN
  124. EXEC proc_errorHandler 1
  125. ,'Transaction Not Found!'
  126. ,@id
  127. RETURN
  128. END
  129. DECLARE @partnerId INT
  130. ,@isRealTime BIT
  131. ,@pcountry INT
  132. SELECT @partnerId = pSuperAgent
  133. ,@pcountry = CM.COUNTRYID
  134. ,@controlNo = DBO.DECRYPTDB(CONTROLNO)
  135. FROM REMITTRANTEMP(NOLOCK) RTT
  136. INNER JOIN COUNTRYMASTER CM(NOLOCK) ON CM.COUNTRYNAME = RTT.PCOUNTRY
  137. WHERE ID = @id
  138. SELECT @isRealTime = CASE
  139. WHEN @partnerId = '394397'
  140. THEN 0
  141. ELSE isRealTime
  142. END
  143. FROM TblPartnerwiseCountry(NOLOCK)
  144. WHERE AgentId = @partnerId
  145. AND COUNTRYID = @pcountry
  146. SELECT 0
  147. ,@partnerId
  148. ,@controlNo
  149. ,@isRealTime
  150. ,[provide] = CASE
  151. WHEN @partnerId = '393880'
  152. THEN 'jmenepal'
  153. WHEN @partnerId = '394130'
  154. THEN 'transfast'
  155. WHEN @partnerId = '394132'
  156. THEN 'donga'
  157. WHEN @partnerId = '394397'
  158. THEN 'gmenepal'
  159. ELSE 'unknown'
  160. END
  161. END
  162. IF @flag = 'get-info-imepay'
  163. BEGIN
  164. IF NOT EXISTS (
  165. SELECT *
  166. FROM REMITTRANTEMP(NOLOCK)
  167. WHERE ID = @id
  168. )
  169. BEGIN
  170. EXEC proc_errorHandler 1
  171. ,'Transaction Not Found!'
  172. ,@id
  173. RETURN
  174. END
  175. SELECT @partnerId = pSuperAgent
  176. ,@pcountry = CM.COUNTRYID
  177. ,@controlNo = DBO.DECRYPTDB(CONTROLNO)
  178. ,@controlNo2 = DBO.DECRYPTDB(CONTROLNO2)
  179. FROM REMITTRANTEMP(NOLOCK) RTT
  180. INNER JOIN COUNTRYMASTER CM(NOLOCK) ON CM.COUNTRYNAME = RTT.PCOUNTRY
  181. WHERE ID = @id
  182. IF EXISTS (
  183. SELECT 'X'
  184. FROM remitTranTemp RT(NOLOCK)
  185. INNER JOIN API_BANK_LIST AB(NOLOCK) ON AB.BANK_ID = RT.PBANK
  186. WHERE RT.ID = @id
  187. AND AB.BANK_CODE1 IN ( 'IMEPAY','KHALTI')
  188. AND RT.paymentMethod = 'MOBILE WALLET'
  189. )
  190. BEGIN
  191. --mark realtime to confirm in approve click
  192. SELECT 0
  193. ,'Success'
  194. ,@controlNo
  195. ,@controlNo2
  196. ,@partnerId
  197. ,'False'
  198. END
  199. ELSE
  200. BEGIN
  201. SELECT 0
  202. ,'Success'
  203. ,@controlNo
  204. ,@controlNo2
  205. ,@partnerId
  206. ,'False'
  207. END
  208. END
  209. IF @flag = 'get-info-c-no'
  210. BEGIN
  211. DECLARE @ControlNoEnc VARCHAR(30) = DBO.FNAENCRYPTSTRING(@controlNo)
  212. ,@payStatus VARCHAR(50)
  213. ,@tranId BIGINT
  214. ,@lockStatus VARCHAR(50)
  215. SELECT @partnerId = pSuperAgent
  216. ,@pcountry = CM.COUNTRYID
  217. ,@controlNo = DBO.DECRYPTDB(CONTROLNO)
  218. ,@tranStatus = tranStatus
  219. ,@payStatus = payStatus
  220. ,@tranId = id
  221. ,@lockStatus = lockStatus
  222. ,@cancelDate = ISNULL(cancelRequestDate, GETDATE())
  223. FROM VWREMITTRAN(NOLOCK) RTT
  224. INNER JOIN COUNTRYMASTER CM(NOLOCK) ON CM.COUNTRYNAME = RTT.PCOUNTRY
  225. WHERE controlNo = @ControlNoEnc
  226. SELECT @isRealTime = isRealTime
  227. FROM TblPartnerwiseCountry(NOLOCK)
  228. WHERE AgentId = @partnerId
  229. AND COUNTRYID = @pcountry
  230. IF (@tranStatus IS NULL)
  231. BEGIN
  232. EXEC proc_errorHandler 1
  233. ,'Transaction not found'
  234. ,@ControlNoEnc
  235. RETURN
  236. END
  237. IF (@tranStatus = 'Block')
  238. BEGIN
  239. EXEC proc_errorHandler 1
  240. ,'Transaction is blocked. Please Contact HO'
  241. ,@ControlNoEnc
  242. RETURN
  243. END
  244. IF (@tranStatus = 'Paid')
  245. BEGIN
  246. EXEC proc_errorHandler 1
  247. ,'Transaction has already been paid'
  248. ,@ControlNoEnc
  249. RETURN
  250. END
  251. IF (@payStatus = 'Paid')
  252. BEGIN
  253. EXEC proc_errorHandler 1
  254. ,'Transaction has already been paid'
  255. ,@ControlNoEnc
  256. RETURN
  257. END
  258. IF (@tranStatus = 'Cancel')
  259. BEGIN
  260. EXEC proc_errorHandler 1
  261. ,'Transaction has already been cancelled'
  262. ,@ControlNoEnc
  263. RETURN
  264. END
  265. SELECT 0
  266. ,@partnerId
  267. ,@controlNo
  268. ,@isRealTime
  269. ,[provide] = CASE
  270. WHEN @partnerId = '393880'
  271. THEN 'jmenepal'
  272. WHEN @partnerId = '394130'
  273. THEN 'transfast'
  274. WHEN @partnerId = '394132'
  275. THEN 'donga'
  276. WHEN @partnerId = '394428'
  277. THEN 'Cebuana'
  278. ELSE 'unknown'
  279. END
  280. END
  281. IF @flag = 'cancel-request'
  282. BEGIN
  283. SET @ControlNoEnc = DBO.FNAENCRYPTSTRING(@controlNo)
  284. SELECT @partnerId = pSuperAgent
  285. ,@pcountry = CM.COUNTRYID
  286. ,@controlNo = DBO.DECRYPTDB(CONTROLNO)
  287. ,@tranStatus = tranStatus
  288. ,@payStatus = payStatus
  289. ,@tranId = id
  290. ,@lockStatus = lockStatus
  291. ,@cancelDate = ISNULL(cancelRequestDate, GETDATE())
  292. FROM VWREMITTRAN(NOLOCK) RTT
  293. INNER JOIN COUNTRYMASTER CM(NOLOCK) ON CM.COUNTRYNAME = RTT.PCOUNTRY
  294. WHERE controlNo = @ControlNoEnc
  295. IF (@tranStatus IS NULL)
  296. BEGIN
  297. EXEC proc_errorHandler 1
  298. ,'Transaction not found'
  299. ,@ControlNoEnc
  300. RETURN
  301. END
  302. IF (@tranStatus = 'Block')
  303. BEGIN
  304. EXEC proc_errorHandler 1
  305. ,'Transaction is blocked. Please Contact HO'
  306. ,@ControlNoEnc
  307. RETURN
  308. END
  309. IF (@tranStatus = 'Paid')
  310. BEGIN
  311. EXEC proc_errorHandler 1
  312. ,'Transaction has already been paid'
  313. ,@ControlNoEnc
  314. RETURN
  315. END
  316. IF (@payStatus = 'Paid')
  317. BEGIN
  318. EXEC proc_errorHandler 1
  319. ,'Transaction has already been paid'
  320. ,@ControlNoEnc
  321. RETURN
  322. END
  323. IF (@tranStatus = 'Cancel')
  324. BEGIN
  325. EXEC proc_errorHandler 1
  326. ,'Transaction has already been cancelled'
  327. ,@ControlNoEnc
  328. RETURN
  329. END
  330. IF (@tranStatus = 'CancelRequest')
  331. BEGIN
  332. EXEC proc_errorHandler 1
  333. ,'Cancel Request has already been sent'
  334. ,@ControlNoEnc
  335. RETURN
  336. END
  337. --BEGIN TRANSACTION
  338. IF EXISTS (
  339. SELECT *
  340. FROM REMITTRANTEMP(NOLOCK)
  341. WHERE controlNo = @ControlNoEnc
  342. )
  343. BEGIN
  344. UPDATE remitTranTEMP
  345. SET tranStatus = 'CancelRequest' --Transaction Hold
  346. ,trnStatusBeforeCnlReq = tranStatus
  347. ,cancelRequestBy = @user
  348. ,cancelRequestDate = GETDATE()
  349. ,cancelRequestDateLocal = GETDATE()
  350. ,cancelReason = @cancelReason
  351. WHERE controlNo = @ControlNoEnc
  352. END
  353. ELSE
  354. BEGIN
  355. UPDATE remitTran
  356. SET tranStatus = 'CancelRequest' --Transaction Hold
  357. ,trnStatusBeforeCnlReq = tranStatus
  358. ,cancelRequestBy = @user
  359. ,cancelRequestDate = GETDATE()
  360. ,cancelRequestDateLocal = GETDATE()
  361. ,cancelReason = @cancelReason
  362. WHERE controlNo = @ControlNoEnc
  363. END
  364. SELECT @message = 'Transaction requested for Cancel. Reason : ''' + @cancelReason + ''''
  365. INSERT INTO tranCancelrequest (
  366. tranId
  367. ,controlNo
  368. ,cancelReason
  369. ,cancelStatus
  370. ,createdBy
  371. ,createdDate
  372. ,tranStatus
  373. )
  374. SELECT @tranId
  375. ,@ControlNoEnc
  376. ,@cancelReason
  377. ,'CancelRequest'
  378. ,@user
  379. ,GETDATE()
  380. ,@tranStatus
  381. --IF @@TRANCOUNT > 0
  382. -- COMMIT TRANSACTION
  383. EXEC proc_errorHandler 0
  384. ,'Request for cancel done successfully'
  385. ,@ControlNoEnc
  386. EXEC proc_addCommentAPI @flag = 'i'
  387. ,@controlNo = @controlNo
  388. ,@user = @user
  389. ,@message = @message
  390. ,@agentRefId = NULL
  391. EXEC proc_transactionLogs 'i'
  392. ,@user
  393. ,@tranId
  394. ,@message
  395. ,'Cancel Request'
  396. END
  397. IF @flag = 'get-info-for-compliance'
  398. BEGIN
  399. IF NOT EXISTS (
  400. SELECT *
  401. FROM REMITTRAN(NOLOCK)
  402. WHERE ID = @id
  403. )
  404. BEGIN
  405. EXEC proc_errorHandler 1
  406. ,'Transaction Not Found!'
  407. ,@id
  408. RETURN
  409. END
  410. SELECT @partnerId = pSuperAgent
  411. ,@controlNo = DBO.DECRYPTDB(CONTROLNO)
  412. FROM REMITTRAN(NOLOCK)
  413. WHERE ID = @id
  414. SELECT @isRealTime = CASE
  415. WHEN @partnerId = '394397'
  416. THEN 0
  417. ELSE isRealTime
  418. END
  419. FROM TblPartnerwiseCountry(NOLOCK)
  420. WHERE AgentId = @partnerId
  421. SELECT 0
  422. ,@partnerId
  423. ,@controlNo
  424. ,@isRealTime
  425. END
  426. IF @flag = 'reject'
  427. BEGIN
  428. IF NOT EXISTS (
  429. SELECT 'X'
  430. FROM remitTranTemp RT WITH (NOLOCK)
  431. WHERE RT.id = @id
  432. )
  433. BEGIN
  434. EXEC proc_errorHandler 1
  435. ,'There is no transaction to reject, either it is approved/rejected or not found!!'
  436. ,@id
  437. RETURN;
  438. END
  439. DECLARE @customerId BIGINT
  440. ,@rewardtype NVARCHAR(25)
  441. IF @isTxnRealtime IS NULL
  442. SET @isTxnRealtime = 0
  443. SELECT @tranStatus = transtatus
  444. ,@denyAmt = ISNULL(cAmt, 0) - ISNULL(sAgentComm, 0) - ISNULL(agentFxGain, 0)
  445. ,@sRouteId = sRouteId
  446. ,@pinEncrypted = controlNo
  447. ,@ControlNo = dbo.fnaDecryptstring(controlNo)
  448. ,@controlno2 = dbo.fnaDecryptstring(controlNo2)
  449. ,@txncreatedBy = createdBy
  450. ,@COLLMODE = ISNULL(RT.depositType,'ONLINE')
  451. ,@CUSTOMERID = TS.CUSTOMERID
  452. ,@transactionType = rt.trantype
  453. ,@rewardtype = rt.rewardType
  454. FROM remitTranTemp RT WITH (NOLOCK)
  455. INNER JOIN TRANSENDERSTEMP TS(NOLOCK) ON TS.TRANID = RT.ID
  456. WHERE RT.id = @id
  457. --IF LEN(@pinEncrypted)<7
  458. --BEGIN
  459. -- select TOP 1 @ControlNo = controlNo from Application_Log.dbo.vwtpapilogs(nolock) where requestedby=@txncreatedBy AND ERRORCODE='999' order by rowid desc
  460. --END
  461. --IF LEN(@ControlNo) < 7
  462. --BEGIN
  463. -- EXEC proc_errorHandler 1, 'Sorry,Cannot Reject Transaction', @id
  464. -- RETURN
  465. --END
  466. --BEGIN TRANSACTION
  467. INSERT INTO tranCancelrequest (
  468. tranId
  469. ,controlNo
  470. ,cancelReason
  471. ,cancelStatus
  472. ,createdBy
  473. ,createdDate
  474. ,tranStatus
  475. ,approvedBy
  476. ,approvedDate
  477. ,scRefund
  478. ,isScRefund
  479. )
  480. SELECT id
  481. ,controlNo
  482. ,@remarks
  483. ,'Approved'
  484. ,@user
  485. ,GETDATE()
  486. ,tranStatus
  487. ,@user
  488. ,GETDATE()
  489. ,cAmt
  490. ,'Y'
  491. FROM remitTranTemp WITH (NOLOCK)
  492. WHERE id = @id
  493. UPDATE remitTranTemp
  494. SET tranStatus = 'Cancel'
  495. ,cancelApprovedBy = @user
  496. ,cancelApprovedDate = GETDATE()
  497. ,cancelApprovedDateLocal = dbo.FNAGetDateInNepalTZ()
  498. ,cancelRequestBy = @user
  499. ,cancelRequestDate = GETDATE()
  500. ,cancelRequestDateLocal = dbo.FNADateFormatTZ(GETDATE(), @user)
  501. ,trnStatusBeforeCnlReq = @tranStatus
  502. ,controlNo = dbo.fnaEncryptstring(@ControlNo)
  503. WHERE id = @id
  504. INSERT INTO cancelTranHistory (
  505. tranId
  506. ,controlNo
  507. ,sCurrCostRate
  508. ,sCurrHoMargin
  509. ,sCurrSuperAgentMargin
  510. ,sCurrAgentMargin
  511. ,pCurrCostRate
  512. ,pCurrHoMargin
  513. ,pCurrSuperAgentMargin
  514. ,pCurrAgentMargin
  515. ,agentCrossSettRate
  516. ,customerRate
  517. ,sAgentSettRate
  518. ,pDateCostRate
  519. ,agentFxGain
  520. ,treasuryTolerance
  521. ,customerPremium
  522. ,schemePremium
  523. ,sharingValue
  524. ,sharingType
  525. ,serviceCharge
  526. ,handlingFee
  527. ,sAgentComm
  528. ,sAgentCommCurrency
  529. ,sSuperAgentComm
  530. ,sSuperAgentCommCurrency
  531. ,pAgentComm
  532. ,pAgentCommCurrency
  533. ,pSuperAgentComm
  534. ,pSuperAgentCommCurrency
  535. ,promotionCode
  536. ,promotionType
  537. ,pMessage
  538. ,sCountry
  539. ,sSuperAgent
  540. ,sSuperAgentName
  541. ,sAgent
  542. ,sAgentName
  543. ,sBranch
  544. ,sBranchName
  545. ,pCountry
  546. ,pSuperAgent
  547. ,pSuperAgentName
  548. ,pAgent
  549. ,pAgentName
  550. ,pBranch
  551. ,pBranchName
  552. ,paymentMethod
  553. ,pBank
  554. ,pBankName
  555. ,pBankBranch
  556. ,pBankBranchName
  557. ,accountNo
  558. ,externalBankCode
  559. ,collMode
  560. ,collCurr
  561. ,tAmt
  562. ,cAmt
  563. ,pAmt
  564. ,payoutCurr
  565. ,relWithSender
  566. ,purposeOfRemit
  567. ,sourceOfFund
  568. ,tranStatus
  569. ,payStatus
  570. ,createdDate
  571. ,createdDateLocal
  572. ,createdBy
  573. ,modifiedDate
  574. ,modifiedDateLocal
  575. ,modifiedBy
  576. ,approvedDate
  577. ,approvedDateLocal
  578. ,approvedBy
  579. ,paidDate
  580. ,paidDateLocal
  581. ,paidBy
  582. ,cancelRequestDate
  583. ,cancelRequestDateLocal
  584. ,cancelRequestBy
  585. ,cancelReason
  586. ,refund
  587. ,cancelCharge
  588. ,cancelApprovedDate
  589. ,cancelApprovedDateLocal
  590. ,cancelApprovedBy
  591. ,blockedDate
  592. ,blockedBy
  593. ,lockedDate
  594. ,lockedDateLocal
  595. ,lockedBy
  596. ,payTokenId
  597. ,tranType
  598. ,ContNo
  599. ,uploadLogId
  600. ,voucherNo
  601. ,controlNo2
  602. ,pBankType
  603. ,trnStatusBeforeCnlReq
  604. ,isSystemReject
  605. ,depositType
  606. ,transactionreference
  607. ,isOnlineTxn
  608. )
  609. SELECT id
  610. ,controlNo
  611. ,sCurrCostRate
  612. ,sCurrHoMargin
  613. ,sCurrSuperAgentMargin
  614. ,sCurrAgentMargin
  615. ,pCurrCostRate
  616. ,pCurrHoMargin
  617. ,pCurrSuperAgentMargin
  618. ,pCurrAgentMargin
  619. ,agentCrossSettRate
  620. ,customerRate
  621. ,sAgentSettRate
  622. ,pDateCostRate
  623. ,agentFxGain
  624. ,treasuryTolerance
  625. ,customerPremium
  626. ,schemePremium
  627. ,sharingValue
  628. ,sharingType
  629. ,serviceCharge
  630. ,handlingFee
  631. ,sAgentComm
  632. ,sAgentCommCurrency
  633. ,sSuperAgentComm
  634. ,sSuperAgentCommCurrency
  635. ,pAgentComm
  636. ,pAgentCommCurrency
  637. ,pSuperAgentComm
  638. ,pSuperAgentCommCurrency
  639. ,promotionCode
  640. ,promotionType
  641. ,pMessage
  642. ,sCountry
  643. ,sSuperAgent
  644. ,sSuperAgentName
  645. ,sAgent
  646. ,sAgentName
  647. ,sBranch
  648. ,sBranchName
  649. ,pCountry
  650. ,pSuperAgent
  651. ,pSuperAgentName
  652. ,pAgent
  653. ,pAgentName
  654. ,pBranch
  655. ,pBranchName
  656. ,paymentMethod
  657. ,pBank
  658. ,pBankName
  659. ,pBankBranch
  660. ,pBankBranchName
  661. ,accountNo
  662. ,externalBankCode
  663. ,collMode
  664. ,collCurr
  665. ,tAmt
  666. ,cAmt
  667. ,pAmt
  668. ,payoutCurr
  669. ,relWithSender
  670. ,purposeOfRemit
  671. ,sourceOfFund
  672. ,tranStatus
  673. ,payStatus
  674. ,createdDate
  675. ,createdDateLocal
  676. ,createdBy
  677. ,modifiedDate
  678. ,modifiedDateLocal
  679. ,modifiedBy
  680. ,approvedDate
  681. ,approvedDateLocal
  682. ,approvedBy
  683. ,paidDate
  684. ,paidDateLocal
  685. ,paidBy
  686. ,cancelRequestDate
  687. ,cancelRequestDateLocal
  688. ,cancelRequestBy
  689. ,@remarks
  690. ,refund
  691. ,cancelCharge
  692. ,GETDATE()
  693. ,dbo.FNADateFormatTZ(GETDATE(), @user)
  694. ,@user
  695. ,blockedDate
  696. ,blockedBy
  697. ,lockedDate
  698. ,lockedDateLocal
  699. ,lockedBy
  700. ,payTokenId
  701. ,tranType
  702. ,ContNo
  703. ,uploadLogId
  704. ,voucherNo
  705. ,controlNo2
  706. ,pBankType
  707. ,trnStatusBeforeCnlReq
  708. ,@isSystemReject
  709. ,depositType
  710. ,transactionreference
  711. ,isOnlineTxn
  712. FROM remitTranTemp
  713. WHERE id = @id
  714. INSERT INTO cancelTranSendersHistory (
  715. tranId
  716. ,customerId
  717. ,membershipId
  718. ,firstName
  719. ,middleName
  720. ,lastName1
  721. ,lastName2
  722. ,fullName
  723. ,country
  724. ,address
  725. ,STATE
  726. ,district
  727. ,zipCode
  728. ,city
  729. ,email
  730. ,homePhone
  731. ,workPhone
  732. ,mobile
  733. ,nativeCountry
  734. ,dob
  735. ,placeOfIssue
  736. ,customerType
  737. ,occupation
  738. ,idType
  739. ,idNumber
  740. ,idPlaceOfIssue
  741. ,issuedDate
  742. ,validDate
  743. ,extCustomerId
  744. ,cwPwd
  745. ,ttName
  746. ,isFirstTran
  747. ,customerRiskPoint
  748. ,countryRiskPoint
  749. ,gender
  750. ,salary
  751. ,companyName
  752. ,address2
  753. ,dcInfo
  754. ,ipAddress
  755. ,notifySms
  756. ,txnTestQuestion
  757. ,txnTestAnswer
  758. )
  759. SELECT tranId
  760. ,customerId
  761. ,membershipId
  762. ,firstName
  763. ,middleName
  764. ,lastName1
  765. ,lastName2
  766. ,fullName
  767. ,country
  768. ,address
  769. ,STATE
  770. ,district
  771. ,zipCode
  772. ,city
  773. ,email
  774. ,homePhone
  775. ,workPhone
  776. ,mobile
  777. ,nativeCountry
  778. ,dob
  779. ,placeOfIssue
  780. ,customerType
  781. ,occupation
  782. ,idType
  783. ,idNumber
  784. ,idPlaceOfIssue
  785. ,issuedDate
  786. ,validDate
  787. ,extCustomerId
  788. ,cwPwd
  789. ,ttName
  790. ,isFirstTran
  791. ,customerRiskPoint
  792. ,countryRiskPoint
  793. ,gender
  794. ,salary
  795. ,companyName
  796. ,address2
  797. ,dcInfo
  798. ,ipAddress
  799. ,notifySms
  800. ,txnTestQuestion
  801. ,txnTestAnswer
  802. FROM transenderstemp WITH (NOLOCK)
  803. WHERE tranId = LTRIM(RTRIM(@id))
  804. INSERT INTO cancelTranReceiversHistory (
  805. tranId
  806. ,customerId
  807. ,membershipId
  808. ,firstName
  809. ,middleName
  810. ,lastName1
  811. ,lastName2
  812. ,fullName
  813. ,country
  814. ,address
  815. ,STATE
  816. ,district
  817. ,zipCode
  818. ,city
  819. ,email
  820. ,homePhone
  821. ,workPhone
  822. ,mobile
  823. ,nativeCountry
  824. ,dob
  825. ,placeOfIssue
  826. ,customerType
  827. ,occupation
  828. ,idType
  829. ,idNumber
  830. ,idPlaceOfIssue
  831. ,issuedDate
  832. ,validDate
  833. ,idType2
  834. ,idNumber2
  835. ,idPlaceOfIssue2
  836. ,issuedDate2
  837. ,validDate2
  838. ,relationType
  839. ,relativeName
  840. ,gender
  841. ,address2
  842. ,dcInfo
  843. ,ipAddress
  844. )
  845. SELECT tranId
  846. ,customerId
  847. ,membershipId
  848. ,firstName
  849. ,middleName
  850. ,lastName1
  851. ,lastName2
  852. ,fullName
  853. ,country
  854. ,address
  855. ,STATE
  856. ,district
  857. ,zipCode
  858. ,city
  859. ,email
  860. ,homePhone
  861. ,workPhone
  862. ,mobile
  863. ,nativeCountry
  864. ,dob
  865. ,placeOfIssue
  866. ,customerType
  867. ,occupation
  868. ,idType
  869. ,idNumber
  870. ,idPlaceOfIssue
  871. ,issuedDate
  872. ,validDate
  873. ,idType2
  874. ,idNumber2
  875. ,idPlaceOfIssue2
  876. ,issuedDate2
  877. ,validDate2
  878. ,relationType
  879. ,relativeName
  880. ,gender
  881. ,address2
  882. ,dcInfo
  883. ,ipAddress
  884. FROM tranReceiversTemp WITH (NOLOCK)
  885. WHERE tranId = LTRIM(RTRIM(@id))
  886. ----reverse deposit mapping
  887. --IF @COLLMODE = 'Bank Deposit'
  888. -- AND @isTxnRealtime = 0
  889. --BEGIN
  890. -- IF EXISTS (
  891. -- SELECT 'x'
  892. -- FROM customer_deposit_logs
  893. -- WHERE customerid = @CUSTOMERID
  894. -- AND approvedby IS NULL
  895. -- )
  896. -- BEGIN
  897. -- UPDATE customer_deposit_logs
  898. -- SET processedby = NULL
  899. -- ,processeddate = NULL
  900. -- ,customerid = NULL
  901. -- WHERE customerid = @CUSTOMERID
  902. -- AND approvedby IS NULL
  903. -- END
  904. --END
  905. --update balance
  906. DECLARE @referralCode VARCHAR(15)
  907. ,@sType CHAR(1)
  908. ,@isOnbehalf CHAR(1)
  909. ,@sAgent INT
  910. ,@senderUserId INT
  911. SELECT @referralCode = PROMOTIONCODE
  912. ,@sAgent = sAgent
  913. ,@cAmt = cAmt
  914. ,@isOnbehalf = (
  915. CASE
  916. WHEN ISNULL(ISONBEHALF, 0) = '1'
  917. THEN 'Y'
  918. ELSE 'N'
  919. END
  920. )
  921. ,@senderUserId = AU.userId
  922. FROM dbo.remitTranTemp RT(NOLOCK)
  923. INNER JOIN applicationUsers AU(NOLOCK) ON AU.userName = RT.createdBy
  924. WHERE controlNo = dbo.fnaEncryptstring(@ControlNo)
  925. IF @COLLMODE = 'Cash Collect'
  926. BEGIN
  927. --select @sAgent,@userId,@referralCode,@cAmt,@isOnbehalf,@ControlNo
  928. EXEC PROC_UPDATE_AVAILABALE_BALANCE @FLAG = 'CANCEL'
  929. ,@S_AGENT = @sAgent
  930. ,@S_USER = @senderUserId
  931. ,@REFERRAL_CODE = @referralCode
  932. ,@C_AMT = @cAmt
  933. ,@ONBEHALF = @isOnbehalf
  934. END
  935. DELETE
  936. FROM remitTranTemp
  937. WHERE id = @id
  938. DELETE
  939. FROM tranSendersTemp
  940. WHERE tranId = @id
  941. DELETE
  942. FROM tranReceiversTemp
  943. WHERE tranId = @id
  944. IF @rewardtype = 'FREE_SC'
  945. BEGIN
  946. UPDATE remitDatalog
  947. SET controlNo = NULL
  948. WHERE ControlNo = @ControlNo or controlNo = @controlNo2
  949. END
  950. ELSE
  951. BEGIN
  952. DELETE
  953. FROM remitDatalog
  954. WHERE tranId = @id
  955. END
  956. SELECT @message = 'Transaction cancel has been done successfully.'
  957. EXEC proc_transactionLogs @flag = 'i'
  958. ,@user = @user
  959. ,@tranId = @id
  960. ,@message = @message
  961. ,@msgType = 'Cancel'
  962. IF @branch = 'Mobile'
  963. BEGIN
  964. INSERT INTO pushNotificationHistroy (
  965. customerId
  966. ,body
  967. ,title
  968. ,createDate
  969. ,imageURL
  970. ,sentId
  971. ,Type
  972. ,isReservation
  973. ,isRead
  974. ,isSend
  975. ,category
  976. )
  977. SELECT @customerid
  978. ,'Tran ID : ' + CAST(@id AS VARCHAR) + ' was successfully cancelled.'
  979. ,'CancelTxn'
  980. ,getdate()
  981. ,''
  982. ,@id
  983. ,0
  984. ,0
  985. ,0
  986. ,0
  987. ,'INFO'
  988. END
  989. IF EXists(select * fROM TRU_TranDetail WHERE Tranid=@id)
  990. BEGIN
  991. UPDATE dbo.TRU_TranDetail
  992. SET recordStatus = 'EXPIRED'
  993. WHERE tranid=@id
  994. and recordStatus IN ( 'PROCESS','DRAFT')
  995. END
  996. --IF @@TRANCOUNT > 0
  997. -- COMMIT TRANSACTION
  998. IF @transactionType = 'I'
  999. BEGIN
  1000. IF EXISTS (
  1001. SELECT TOP 1 1
  1002. FROM applicationUsers(NOLOCK)
  1003. WHERE userName = @txncreatedBy
  1004. )
  1005. BEGIN
  1006. UPDATE APPLICATIONUSERS
  1007. SET freeScCounter = CASE
  1008. WHEN ISNULL(freeScCounter, 0) > 0
  1009. THEN ISNULL(freeScCounter, 0) - 1
  1010. ELSE freeScCounter
  1011. END
  1012. WHERE username = @txncreatedBy
  1013. END
  1014. END
  1015. EXEC proc_errorHandler 0
  1016. ,'Transaction Rejected Successfully'
  1017. ,@id
  1018. RETURN
  1019. END
  1020. IF @flag = 'approve'
  1021. BEGIN
  1022. IF NOT EXISTS (
  1023. SELECT 'X'
  1024. FROM remitTranTemp RT WITH (NOLOCK)
  1025. WHERE RT.id = @id
  1026. )
  1027. BEGIN
  1028. EXEC proc_errorHandler 1
  1029. ,'There is no transaction to approve, either it is rejected/approved or not found!!'
  1030. ,@id
  1031. RETURN;
  1032. END
  1033. --IF EXISTS (
  1034. -- SELECT 'X'
  1035. -- FROM remitTranTemp RT WITH (NOLOCK)
  1036. -- WHERE RT.id = @id
  1037. -- AND controlno = 'LLm_IOQMMRMQM'
  1038. -- )
  1039. --BEGIN
  1040. -- EXEC proc_errorHandler 1
  1041. -- ,'You can not approve this txn, please contact HQ!!'
  1042. -- ,@id
  1043. -- RETURN;
  1044. --END
  1045. DECLARE @pBank INT
  1046. ,@paymentMethod VARCHAR(50)
  1047. ,@tranType CHAR(1)
  1048. ,@externalBankCode INT
  1049. ,@createdDate DATETIME
  1050. ,@senderName VARCHAR(100)
  1051. ,@sBranchName VARCHAR(150)
  1052. ,@pAgentComm MONEY
  1053. DECLARE @agentFxGain MONEY
  1054. IF @createdBy = @user
  1055. BEGIN
  1056. EXEC proc_errorHandler 1
  1057. ,'Same user cannot approve the Transaction'
  1058. ,@id
  1059. RETURN
  1060. END
  1061. DECLARE @tAmt MONEY
  1062. ,@pAmt MONEY
  1063. ,@introducer VARCHAR(50)
  1064. ,@payoutPartner INT
  1065. ,@serviceCharge MONEY
  1066. ,@pCurrCostRate FLOAT
  1067. ,@pCurrHoMargin FLOAT
  1068. ,@isFirstTran CHAR(1)
  1069. ,@userName VARCHAR(80)
  1070. ,@rewardPoints MONEY
  1071. UPDATE REMITTRANTEMP
  1072. SET agentFxGain = tamt - (ROUND((pamt / pCurrCostRate), 2))
  1073. WHERE ISNULL(psuperagent, 0) <> 394132
  1074. AND id = @id
  1075. SELECT @cAmt = cAmt
  1076. ,@customerId = cm.customerId
  1077. ,@userId = A.userId
  1078. ,@tAmt = r.tAmt
  1079. ,@pAmt = r.pAmt
  1080. ,@createdBy = r.createdBy
  1081. ,@controlNo = dbo.FNADecryptString(controlNo)
  1082. ,@sBranch = sBranch
  1083. ,@sBranchName = sBranchName
  1084. ,@pinEncrypted = controlNo
  1085. ,@pBank = pBank
  1086. ,@introducer = promotionCode
  1087. ,@sAgent = sAgent
  1088. ,@paymentMethod = paymentMethod
  1089. ,@tranType = tranType
  1090. ,@sRouteId = sRouteId
  1091. ,@collMode = ISNULL(R.depositType,'ONLINE')
  1092. ,@externalBankCode = externalBankCode
  1093. ,@createdDate = r.createdDate
  1094. ,@senderName = r.senderName
  1095. ,@tranStatus = R.tranStatus
  1096. ,@payoutPartner = R.pSuperAgent
  1097. ,@serviceCharge = R.serviceCharge
  1098. ,@pCurrCostRate = R.pCurrCostRate
  1099. ,@pCurrHoMargin = R.pCurrHoMargin
  1100. ,@agentFxGain = R.agentFxGain
  1101. ,@isFirstTran = ISNULL(T.isFirstTran, 'N')
  1102. ,@pAgentComm = r.pAgentComm
  1103. ,@userName = CM.USERNAME
  1104. ,@isOnbehalf = (
  1105. CASE
  1106. WHEN ISONBEHALF = '1'
  1107. THEN 'Y'
  1108. ELSE 'N'
  1109. END
  1110. )
  1111. ,@downlodedBy = downloadedBy
  1112. ,@rewardPoints = ISNULL(rewardPoints, 0)
  1113. FROM remitTranTemp r WITH (NOLOCK)
  1114. INNER JOIN TRANSENDERSTemp T(NOLOCK) ON T.TRANID = R.ID
  1115. LEFT JOIN customerMaster cm(NOLOCK) ON T.customerId = cm.customerId
  1116. LEFT JOIN applicationUsers A(NOLOCK) ON A.USERNAME = R.CREATEDBY
  1117. WHERE r.id = @id
  1118. --IF @collMode = 'Bank Deposit'
  1119. --BEGIN
  1120. -- IF EXISTS (
  1121. -- SELECT 1
  1122. -- FROM CUSTOMER_DEPOSIT_LOGS(NOLOCK)
  1123. -- WHERE CUSTOMERID = @customerId
  1124. -- AND APPROVEDBY IS NULL
  1125. -- )
  1126. -- BEGIN
  1127. -- EXEC proc_errorHandler 1
  1128. -- ,'Customer Deposit Mapping pending for Approval!!'
  1129. -- ,@id
  1130. -- RETURN;
  1131. -- END
  1132. -- SELECT @DENYAMT = DBO.FNAGetCustomerAvailableBalance(@customerId)
  1133. -- --FNAGetCustomerAvailableBalance
  1134. -- IF @DENYAMT < 0
  1135. -- BEGIN
  1136. -- EXEC proc_errorHandler 1
  1137. -- ,'Customer do not have sufficient balance for this transaction!!'
  1138. -- ,@id
  1139. -- RETURN;
  1140. -- END
  1141. --END
  1142. --EXEC proc_errorHandler 0, 'Transaction Approved Successfully', @controlNo
  1143. --RETURN
  1144. DECLARE @kycStatus INT
  1145. SELECT @kycStatus = kycStatus
  1146. FROM TBL_CUSTOMER_KYC(NOLOCK)
  1147. WHERE CUSTOMERID = @customerId
  1148. AND ISDELETED = 0
  1149. --AND kycStatus=11044
  1150. ORDER BY KYC_DATE
  1151. SELECT @parentId = parentId
  1152. FROM agentMaster WITH (NOLOCK)
  1153. WHERE agentId = @sBranch
  1154. SELECT @invicePrintMethod = invoicePrintMethod
  1155. FROM agentMaster A WITH (NOLOCK)
  1156. INNER JOIN agentBusinessFunction B WITH (NOLOCK) ON A.agentId = B.agentId
  1157. WHERE A.agentId = @parentId
  1158. --BEGIN TRANSACTION
  1159. UPDATE remitTranTemp
  1160. SET tranStatus = CASE tranStatus
  1161. WHEN 'Hold'
  1162. THEN 'Payment'
  1163. WHEN 'Compliance Hold'
  1164. THEN 'Compliance'
  1165. WHEN 'OFAC Hold'
  1166. THEN 'OFAC'
  1167. WHEN 'OFAC/Compliance Hold'
  1168. THEN 'OFAC/Compliance'
  1169. WHEN 'Cash Limit Hold'
  1170. THEN 'Cash Limit'
  1171. WHEN 'Cash Limit/Compliance Hold'
  1172. THEN 'Cash Limit/Compliance'
  1173. WHEN 'Cash Limit/OFAC Hold'
  1174. THEN 'Cash Limit/OFAC'
  1175. WHEN 'Cash Limit/OFAC/Compliance Hold'
  1176. THEN 'Cash Limit/OFAC/Compliance'
  1177. ELSE 'Payment'
  1178. END
  1179. ,approvedBy = @user
  1180. ,approvedDate = GETDATE()
  1181. ,approvedDateLocal = GETDATE()
  1182. WHERE id = @id
  1183. PRINT @id;
  1184. -- Return;
  1185. --send email to customers
  1186. --INSERT INTO tempTransactionMailQueue (
  1187. -- controlNo
  1188. -- ,createdDate
  1189. -- ,[status]
  1190. -- ) --tranType is used to know either mail is sent or not, we put 'N' for not sent
  1191. --SELECT rt.controlNo
  1192. -- ,GETDATE()
  1193. -- ,'N'
  1194. --FROM remitTranTemp rt(NOLOCK)
  1195. --WHERE rt.id = @id
  1196. EXEC proc_customerTxnHistory @controlNo = @pinEncrypted
  1197. ----## pish temp into main table
  1198. EXEC proc_remitTranTempToMain @id
  1199. SELECT @TRANID = ID
  1200. FROM REMITTRAN(NOLOCK)
  1201. WHERE controlNo = @pinEncrypted
  1202. --EXEC proc_InsertRewardPoints @tranId = @tranId
  1203. -- ,@customerId = @customerId
  1204. -- ,@rewardPoints = @rewardPoints
  1205. SET @remarks = 'Remittance :' + @controlNo + ' by:' + @senderName + ' from ' + @sBranchName + '-branch on dtd: ' + cast(@createdDate AS VARCHAR)
  1206. SET @txnDate = @createdDate
  1207. --EXEC PROC_CALCULATE_REFERRAL_COMM @COMMISSION_AMT = @serviceCharge
  1208. -- ,@T_AMT = @tAmt
  1209. -- ,@FX = @agentFxGain
  1210. -- ,@IS_NEW_CUSTOMER = @isFirstTran
  1211. -- ,@REFERRAL_CODE = @introducer
  1212. -- ,@PAYOUT_PARTNER = @payoutPartner
  1213. -- ,@CUSTOMER_ID = @customerId
  1214. -- ,@TRAN_ID = @TRANID
  1215. -- ,@S_AGENT = @sAgent
  1216. -- ,@AMOUNT = @cAmt
  1217. -- ,@USER = @user
  1218. -- ,@TRAN_DATE = @txnDate
  1219. -- ,@COLL_MODE = @collMode
  1220. -- ,@P_AGENT_COMM_AMT = @pAgentComm
  1221. PRINT '@collMode';
  1222. PRINT @collMode
  1223. ----INSERT INTO TRANSACTION TABLE(MAP DEPOSIT TXN WITH CUSTOMER)
  1224. INSERT INTO CUSTOMER_TRANSACTIONS (
  1225. customerId
  1226. ,tranDate
  1227. ,particulars
  1228. ,deposit
  1229. ,withdraw
  1230. ,refereceId
  1231. ,head
  1232. ,createdBy
  1233. ,createdDate
  1234. ,bankId
  1235. )
  1236. SELECT @customerId
  1237. ,@txnDate
  1238. ,@remarks
  1239. ,0
  1240. ,@cAmt
  1241. ,@TRANID
  1242. ,'Send Txn: ' + @collMode
  1243. ,@createdBy
  1244. ,@createdDate
  1245. ,@externalBankCode
  1246. IF ISNULL(@kycStatus, 0) <> 11044
  1247. BEGIN
  1248. --UPDATE REMITTRAN
  1249. --SET tranStatus = CASE tranStatus
  1250. -- WHEN 'Payment'
  1251. -- THEN 'Hold'
  1252. -- ELSE tranStatus
  1253. -- END
  1254. --WHERE CONTROLNO = @pinEncrypted
  1255. PRINT @kycStatus
  1256. INSERT INTO tranModifyLog (
  1257. tranId
  1258. ,message
  1259. ,createdBy
  1260. ,createdDate
  1261. ,MsgType
  1262. )
  1263. SELECT @TRANID
  1264. ,'Customer KYC Status not matched(i.e. KYC Completed)'
  1265. ,'system'
  1266. ,GETDATE()
  1267. ,'TXN HOLD: CUSTOMER KYC NOT APPROVED'
  1268. RETURN;
  1269. END
  1270. IF @tranType = 'M'
  1271. BEGIN
  1272. -- EXEC ProcBroadCastMobile @Flag='txn-approve', @RowId=@TRANID, @ControlNo=@controlNo, @CustomerId=@customerId
  1273. INSERT INTO pushNotificationHistroy (
  1274. customerId
  1275. ,body
  1276. ,title
  1277. ,createDate
  1278. ,imageURL
  1279. ,sentId
  1280. ,Type
  1281. ,isReservation
  1282. ,isRead
  1283. ,isSend
  1284. ,category
  1285. )
  1286. SELECT @customerid
  1287. ,'This is send Txn body Msg'
  1288. ,'SendTxn'
  1289. ,getdate()
  1290. ,''
  1291. ,@tranId
  1292. ,1
  1293. ,0
  1294. ,0
  1295. ,0
  1296. ,'INFO'
  1297. END
  1298. IF @sAgent = '394395'
  1299. AND @paymentMethod = 'Mobile Wallet'
  1300. BEGIN
  1301. UPDATE dbo.remitTran
  1302. SET payStatus = 'POST'
  1303. ,postedBy = @user
  1304. ,postedDate = GETDATE()
  1305. ,postedDateLocal = GETDATE()
  1306. WHERE controlNo = @pinEncrypted
  1307. END
  1308. INSERT INTO PinQueueList (ICN)
  1309. SELECT @pinEncrypted
  1310. --IF @@TRANCOUNT > 0
  1311. -- COMMIT TRANSACTION
  1312. EXEC proc_errorHandler 0
  1313. ,'Transaction Approved Successfully'
  1314. ,@controlNo
  1315. --## generate voucher entry
  1316. EXEC FastMoneyPro_Account.dbo.proc_transactionVoucherEntry @controlNo = @controlNo
  1317. --IF @tranType = 'M'
  1318. --BEGIN
  1319. -- EXEC ProcIntroducerCommissionDetail @TranId = @TRANID
  1320. -- ,@CustomerId = @customerId
  1321. -- ,@User = @User
  1322. -- ,@IsCancel = 0
  1323. -- ,@TranDate = @createdDate
  1324. --END
  1325. RETURN
  1326. END
  1327. IF @flag = 'verifyTxnSendFromTabPage'
  1328. BEGIN
  1329. IF EXISTS (
  1330. SELECT 1
  1331. FROM dbo.remitTranTemp
  1332. WHERE id = @id
  1333. )
  1334. BEGIN
  1335. UPDATE dbo.remitTranTemp
  1336. SET sRouteId = '0'
  1337. WHERE id = @id
  1338. EXEC proc_errorHandler 0
  1339. ,'Transaction Verify Successfully'
  1340. ,@id
  1341. RETURN;
  1342. END
  1343. ELSE
  1344. BEGIN
  1345. EXEC proc_errorHandler 1
  1346. ,'Transaction Not Found'
  1347. ,@id
  1348. RETURN;
  1349. END
  1350. END
  1351. IF @flag = 'approve-all'
  1352. BEGIN
  1353. EXEC proc_ApproveHoldedTXN_Sub @user = @user
  1354. ,@idList = @idList
  1355. RETURN
  1356. END
  1357. DECLARE @cdTable VARCHAR(MAX) = ''
  1358. SET @cdTable = '
  1359. LEFT JOIN (
  1360. SELECT
  1361. DISTINCT
  1362. tranId
  1363. ,cb.bankName
  1364. ,cd.countryBankId
  1365. FROM collectionDetails cd WITH(NOLOCK)
  1366. LEFT JOIN countryBanks cb WITH(NOLOCK) ON cd.countryBankId = cb.countryBankId
  1367. INNER JOIN remitTranTemp trn WITH(NOLOCK) ON cd.tranId = trn.id
  1368. AND (trn.tranStatus = ''Hold'' OR trn.tranStatus = ''Compliance Hold'' OR trn.tranStatus = ''OFAC Hold'' )
  1369. AND trn.payStatus = ''Unpaid''
  1370. AND trn.approvedBy IS NULL
  1371. ) cd ON cd.tranId = trn.id '
  1372. IF EXISTS (
  1373. SELECT *
  1374. FROM dbo.sysobjects
  1375. WHERE id = OBJECT_ID(N'[#collModeList]')
  1376. AND type = 'D'
  1377. )
  1378. BEGIN
  1379. DROP TABLE #collModeList
  1380. END
  1381. CREATE TABLE #collModeList (
  1382. tranId INT
  1383. ,hasProcess CHAR(1)
  1384. ,proMode VARCHAR(50)
  1385. )
  1386. DECLARE @tranId1 INT
  1387. IF @flag = 's-admin'
  1388. BEGIN
  1389. SET @table = '
  1390. SELECT DISTINCT
  1391. trn.id
  1392. ,controlNo = ''<a href="/Remit/Transaction/Reports/SearchTransaction.aspx?commentFlag=N&showBankDetail=N&tranId=''+CAST(trn.id AS VARCHAR)+''">''+DBO.FNADECRYPTSTRING(trn.CONTROLNO)+''</a>''
  1393. ,branchName = am.agentName
  1394. ,country = trn.pCountry
  1395. ,senderId = sen.customerId
  1396. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1397. ,receiverId = rec.customerId
  1398. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1399. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1400. --,paymentMethod = case when trn.collMode = ''Bank Deposit'' then ''JP Post'' ELSE trn.collMode END
  1401. ,voucherNo = trn.voucherNo
  1402. ,txnDate = CAST(trn.createdDate AS DATE)
  1403. ,txncreatedBy = trn.createdBy
  1404. ,trn.paymentMethod collMode
  1405. ,tranType = CASE
  1406. WHEN (trn.tranType = ''M'' AND trn.isOnlineTxn = ''M'') THEN ''Mobile''
  1407. WHEN (trn.tranType = ''M'' AND trn.isOnlineTxn = ''O'') THEN ''Web''
  1408. WHEN trn.tranType = ''I'' THEN ''CR Panel''
  1409. ELSE trn.tranType END
  1410. ,CAST(trn.pAmt AS DECIMAL(10,2)) AS pAmt
  1411. ,ISNULL(depositType,'''') depositType
  1412. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1413. '
  1414. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1415. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1416. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1417. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1418. WHERE trn.tranStatus IN (''Hold'') AND
  1419. trn.payStatus = ''Unpaid'' AND
  1420. trn.approvedBy IS NULL AND trn.verifiedDate IS NOT NULL AND ISNULL(sRouteId,''0'') in(''0'',''M'')
  1421. AND trn.tranType=''I''
  1422. --AND trn.pcountry in (''vietnam'',''nepal'')
  1423. '
  1424. IF @id IS NOT NULL
  1425. SET @table = @table + ' AND trn.id = ''' + LTRIM(RTRIM(@id)) + ''''
  1426. IF @branch IS NOT NULL
  1427. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1428. IF @country IS NOT NULL
  1429. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1430. IF @sendCountry IS NOT NULL
  1431. SET @table = @table + ' AND trn.sCountry LIKE ''' + @sendCountry + '%'''
  1432. IF @amt IS NOT NULL
  1433. SET @table = @table + ' AND trn.pAmt = ' + CAST(@amt AS VARCHAR(20)) + ''
  1434. IF @voucherNo IS NOT NULL
  1435. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1436. IF @txncreatedBy IS NOT NULL
  1437. SET @table = @table + ' AND trn.createdBy = ''' + @txncreatedBy + ''''
  1438. IF @txnDate IS NOT NULL
  1439. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1440. IF @ControlNo IS NOT NULL
  1441. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + LTRIM(RTRIM(@ControlNo)) + ''')'
  1442. IF @sendAgent IS NOT NULL
  1443. SET @table = @table + ' AND trn.sAgent = ''' + @sendAgent + ''''
  1444. IF @sendBranch IS NOT NULL
  1445. SET @table = @table + ' AND trn.sBranch = ''' + @sendBranch + ''''
  1446. SET @sql = '
  1447. SELECT
  1448. *
  1449. FROM (
  1450. ' + @table + '
  1451. ) x
  1452. WHERE 1 = 1 '
  1453. IF @sender IS NOT NULL
  1454. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1455. IF @receiver IS NOT NULL
  1456. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1457. PRINT @sql
  1458. EXEC (@sql)
  1459. RETURN
  1460. END
  1461. IF @flag = 's-admin-map'
  1462. BEGIN
  1463. SET @table = '
  1464. SELECT DISTINCT
  1465. trn.id
  1466. ,controlNo = dbo.fnadecryptstring(controlNo)
  1467. ,branch = am.agentName
  1468. ,country = trn.pCountry
  1469. ,senderId = sen.customerId
  1470. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1471. ,receiverId = rec.customerId
  1472. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1473. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1474. ,paymentMethod = case when trn.collMode = ''Bank Deposit'' then ''JP Post'' ELSE trn.collMode END
  1475. ,voucherNo = trn.voucherNo
  1476. ,txnDate = CAST(trn.createdDate AS DATE)
  1477. ,txncreatedBy = trn.createdBy
  1478. ,trn.collMode collMode
  1479. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1480. '
  1481. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1482. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1483. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1484. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1485. WHERE trn.tranStatus IN (''Hold'') AND
  1486. trn.payStatus = ''Unpaid'' AND
  1487. trn.approvedBy IS NULL AND ISNULL(sRouteId,''0'') in(''0'',''M'')
  1488. AND trn.tranType=''I''
  1489. --AND trn.pcountry in (''vietnam'',''nepal'')
  1490. '
  1491. IF @ControlNo IS NOT NULL
  1492. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + @ControlNo + ''')'
  1493. SET @sql = '
  1494. SELECT
  1495. *
  1496. FROM (
  1497. ' + @table + '
  1498. ) x
  1499. WHERE 1 = 1 '
  1500. EXEC (@sql)
  1501. RETURN
  1502. END
  1503. IF @flag = 's-admin-online'
  1504. BEGIN
  1505. SET @table = '
  1506. SELECT DISTINCT
  1507. trn.id
  1508. ,branch = am.agentName
  1509. ,country = trn.pCountry
  1510. ,senderId = sen.customerId
  1511. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1512. ,receiverId = rec.customerId
  1513. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1514. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1515. ,txnDate = CAST(trn.createdDate AS DATE)
  1516. ,txncreatedBy = trn.createdBy
  1517. ,CASE WHEN trn.pAgent=1100 OR trn.pAgent = 1043 THEN 1 ELSE 0 END isThirdPartyTran
  1518. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1519. '
  1520. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1521. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1522. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1523. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1524. WHERE trn.tranStatus IN (''Hold'') AND
  1525. trn.payStatus = ''Unpaid'' AND
  1526. trn.approvedBy IS NULL AND ISNULL(trn.isOnlineTxn,''N'') =''Y''
  1527. AND trn.tranType=''O''
  1528. '
  1529. IF @id IS NOT NULL
  1530. SET @table = @table + ' AND trn.id = ''' + LTRIM(RTRIM(@id)) + ''''
  1531. IF @branch IS NOT NULL
  1532. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1533. IF @country IS NOT NULL
  1534. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1535. IF @sendCountry IS NOT NULL
  1536. SET @table = @table + ' AND trn.sCountry LIKE ''' + @sendCountry + '%'''
  1537. IF @amt IS NOT NULL
  1538. SET @table = @table + ' AND trn.pAmt = ' + CAST(@amt AS VARCHAR(20)) + ''
  1539. IF @voucherNo IS NOT NULL
  1540. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1541. IF @txncreatedBy IS NOT NULL
  1542. SET @table = @table + ' AND trn.createdBy = ''' + @txncreatedBy + ''''
  1543. IF @txnDate IS NOT NULL
  1544. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1545. IF @ControlNo IS NOT NULL
  1546. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + LTRIM(RTRIM(@ControlNo)) + ''')'
  1547. IF @sendAgent IS NOT NULL
  1548. SET @table = @table + ' AND trn.sAgent = ''' + @sendAgent + ''''
  1549. IF @sendBranch IS NOT NULL
  1550. SET @table = @table + ' AND trn.sBranch = ''' + @sendBranch + ''''
  1551. SET @sql = '
  1552. SELECT
  1553. * , STUFF((SELECT '''' + US.voucherNo +'' - ''+ CONVERT(VARCHAR(11),US.voucherDate,6) +'' - ''+ CAST(US.voucherAmt AS VARCHAR)+'' || ''
  1554. FROM bankCollectionVoucherDetail US
  1555. WHERE US.tempTranId = x.id
  1556. FOR XML PATH('''')), 1, 1, '''') [voucherDetail]
  1557. FROM (
  1558. ' + @table + '
  1559. ) x
  1560. WHERE 1 = 1 '
  1561. IF @sender IS NOT NULL
  1562. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1563. IF @receiver IS NOT NULL
  1564. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1565. PRINT @sql
  1566. EXEC (@sql)
  1567. RETURN
  1568. END
  1569. IF @flag = 's-agent'
  1570. BEGIN
  1571. SELECT @isSelfApprove = ISNULL(b.isSelfTxnApprove, 'N')
  1572. FROM agentmaster a WITH (NOLOCK)
  1573. LEFT JOIN agentBusinessFunction b WITH (NOLOCK) ON a.parentId = b.agentId
  1574. WHERE a.agentId = @branchId
  1575. SET @branchList = '
  1576. INNER JOIN (
  1577. SELECT ' + CAST(@branchId AS VARCHAR) + ' agentId '
  1578. IF @userType = 'RH'
  1579. BEGIN
  1580. SET @branchList = @branchList + '
  1581. UNION ALL
  1582. SELECT
  1583. am.agentId
  1584. FROM agentMaster am WITH(NOLOCK)
  1585. INNER JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  1586. WHERE rba.agentId = ' + CAST(@branchId AS VARCHAR) + '
  1587. AND ISNULL(rba.isDeleted, ''N'') = ''N''
  1588. AND ISNULL(rba.isActive, ''N'') = ''Y''
  1589. AND memberAgentId <> ' + CAST(@branchId AS VARCHAR) + ''
  1590. END
  1591. IF @userType = 'AH'
  1592. BEGIN
  1593. SET @branchList = @branchList + '
  1594. UNION ALL
  1595. select agentId from agentMaster with(nolock) where parentId =
  1596. (select parentId from agentmaster with(nolock) where agentId=' + CAST(@branchId AS VARCHAR) + ')
  1597. and agentId <> ' + CAST(@branchId AS VARCHAR) + ''
  1598. END
  1599. SET @branchList = @branchList + '
  1600. ) bl ON trn.sBranch = bl.agentId
  1601. '
  1602. SET @table = '
  1603. SELECT DISTINCT
  1604. trn.id
  1605. ,branch = am.agentName
  1606. ,country = trn.pCountry
  1607. ,senderId = sen.customerId
  1608. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1609. ,receiverId = rec.customerId
  1610. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1611. ,amt = CAST(trn.cAmt AS DECIMAL(18, 3))
  1612. ,voucherNo = trn.voucherNo
  1613. ,trn.createdBy
  1614. ,collMode = ''Cash''
  1615. ,txnDate = CAST(trn.createdDate AS DATE)
  1616. ,txncreatedBy = trn.createdBy
  1617. ,CASE WHEN trn.pAgent = 1100 OR trn.pAgent = 1043 THEN 1 ELSE 0 END isThirdPartyTran
  1618. FROM remitTranTemp trn WITH(NOLOCK)
  1619. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1620. ' + @branchList +
  1621. '
  1622. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1623. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1624. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1625. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1626. trn.payStatus = ''Unpaid'' AND
  1627. trn.approvedBy IS NULL
  1628. '
  1629. IF @txnType IS NOT NULL
  1630. SET @table = @table + ' AND trn.tranType = ''' + @txnType + ''''
  1631. ELSE
  1632. SET @table = @table + ' AND trn.tranType=''I'''
  1633. IF @id IS NOT NULL
  1634. SET @table = @table + ' AND trn.id = ''' + @id + ''''
  1635. IF @branch IS NOT NULL
  1636. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1637. IF @country IS NOT NULL
  1638. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1639. IF @amt IS NOT NULL
  1640. SET @table = @table + ' AND trn.cAmt = ' + CAST(@amt AS VARCHAR(50))
  1641. IF @voucherNo IS NOT NULL
  1642. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1643. IF @txnDate IS NOT NULL
  1644. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1645. IF @isSelfApprove = 'N'
  1646. SET @table = @table + ' AND trn.createdBy <> ''' + @user + ''''
  1647. SET @sql = '
  1648. SELECT
  1649. *
  1650. FROM (
  1651. ' + @table + '
  1652. ) x
  1653. WHERE 1 = 1 '
  1654. IF @txncreatedBy IS NOT NULL
  1655. SET @sql = @sql + ' AND txncreatedBy = ''' + @txncreatedBy + ''''
  1656. IF @sender IS NOT NULL
  1657. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1658. IF @receiver IS NOT NULL
  1659. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1660. --PRINT @sql
  1661. EXEC (@sql)
  1662. RETURN
  1663. END
  1664. IF @flag = 's-agent-self-txn'
  1665. BEGIN
  1666. SET @branchList = '
  1667. INNER JOIN (
  1668. SELECT ' + CAST(@branchId AS VARCHAR) + ' agentId '
  1669. IF @userType = 'RH'
  1670. BEGIN
  1671. SET @branchList = @branchList + '
  1672. UNION ALL
  1673. SELECT
  1674. am.agentId
  1675. FROM agentMaster am WITH(NOLOCK)
  1676. INNER JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  1677. WHERE rba.agentId = ' + CAST(@branchId AS VARCHAR) + '
  1678. AND ISNULL(rba.isDeleted, ''N'') = ''N''
  1679. AND ISNULL(rba.isActive, ''N'') = ''Y'''
  1680. END
  1681. SET @branchList = @branchList + '
  1682. ) bl ON trn.sBranch = bl.agentId
  1683. '
  1684. SET @table = '
  1685. SELECT DISTINCT
  1686. trn.id
  1687. ,branch = am.agentName
  1688. ,country = trn.pCountry
  1689. ,senderId = sen.customerId
  1690. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1691. ,receiverId = rec.customerId
  1692. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1693. ,amt = CAST(trn.cAmt AS DECIMAL(18, 3))
  1694. ,voucherNo = trn.voucherNo
  1695. ,trn.createdBy
  1696. ,collMode = ''''
  1697. ,txnDate = CAST(trn.createdDate AS DATE)
  1698. ,txncreatedBy = trn.createdBy
  1699. FROM remitTranTemp trn WITH(NOLOCK)
  1700. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1701. ' + @branchList +
  1702. '
  1703. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1704. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1705. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1706. --INNER JOIN #collModeList T ON T.tranId = trn.id
  1707. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1708. trn.payStatus = ''Unpaid'' AND
  1709. trn.approvedBy IS NULL
  1710. '
  1711. IF @txnType IS NOT NULL
  1712. SET @table = @table + ' AND trn.tranType = ''' + @txnType + ''''
  1713. ELSE
  1714. SET @table = @table + ' AND trn.tranType=''I'''
  1715. IF @id IS NOT NULL
  1716. SET @table = @table + ' AND trn.id = ''' + @id + ''''
  1717. IF @branch IS NOT NULL
  1718. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1719. IF @country IS NOT NULL
  1720. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1721. IF @amt IS NOT NULL
  1722. SET @table = @table + ' AND trn.cAmt = ' + CAST(@amt AS VARCHAR(50))
  1723. IF @voucherNo IS NOT NULL
  1724. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1725. IF @txnDate IS NOT NULL
  1726. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1727. SET @sqlSelfTxn = '
  1728. SELECT
  1729. *
  1730. FROM (
  1731. ' + @table + ' AND trn.createdBy = ''' + @user + '''
  1732. ) x
  1733. WHERE 1 = 1 '
  1734. IF @sender IS NOT NULL
  1735. SET @sqlSelfTxn = @sqlSelfTxn + ' AND sender LIKE ''' + @sender + '%'''
  1736. IF @receiver IS NOT NULL
  1737. SET @sqlSelfTxn = @sqlSelfTxn + ' AND receiver LIKE ''' + @receiver + '%'''
  1738. EXEC (@sqlSelfTxn)
  1739. RETURN
  1740. END
  1741. IF @flag = 's_txn_summary'
  1742. BEGIN
  1743. SET @branchList = '
  1744. INNER JOIN (
  1745. SELECT ' + CAST(@branchId AS VARCHAR) + ' agentId '
  1746. IF @userType = 'RH'
  1747. BEGIN
  1748. SET @branchList = @branchList + '
  1749. UNION ALL
  1750. SELECT
  1751. am.agentId
  1752. FROM agentMaster am WITH(NOLOCK)
  1753. INNER JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  1754. WHERE rba.agentId = ' + CAST(@branchId AS VARCHAR) + '
  1755. AND ISNULL(rba.isDeleted, ''N'') = ''N''
  1756. AND ISNULL(rba.isActive, ''N'') = ''Y'''
  1757. END
  1758. IF @userType = 'AH'
  1759. BEGIN
  1760. SET @branchList = @branchList + '
  1761. UNION ALL
  1762. select agentId from agentMaster with(nolock) where parentId =
  1763. (select parentId from agentmaster with(nolock) where agentId=' + CAST(@branchId AS VARCHAR) + ')
  1764. and agentId <> ' + CAST(@branchId AS VARCHAR) + ''
  1765. END
  1766. SET @branchList = @branchList + '
  1767. ) bl ON trn.sBranch = bl.agentId
  1768. '
  1769. SET @tablesql = '
  1770. select country,sum(txnCount) txnCount,sum(txnHoldCount) txnHoldCount from
  1771. (
  1772. select country,txnCount,txnHoldCount from
  1773. (
  1774. SELECT
  1775. country = CASE WHEN trn.tranType = ''B'' then pCountry+''(B2B)'' else pCountry end
  1776. ,txnCount = case when trn.createdBy <> ''' + @user + ''' then 1 else 0 end
  1777. ,txnHoldCount = case when trn.createdBy = ''' + @user + ''' then 1 else 0 end
  1778. FROM remitTranTemp trn WITH(NOLOCK)
  1779. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1780. ' + @branchList +
  1781. '
  1782. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1783. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1784. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1785. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1786. trn.payStatus = ''Unpaid'' AND
  1787. trn.approvedBy IS NULL AND trn.tranType IN (''I'',''B'')
  1788. )z
  1789. )x group by country'
  1790. --print(@tablesql)
  1791. EXEC (@tablesql)
  1792. END
  1793. IF @flag = 's_admin_txn_summary'
  1794. BEGIN
  1795. SET @tablesql = '
  1796. SELECT
  1797. sn = row_number() over(order by trn.sCountry)
  1798. ,country = upper(trn.sCountry)
  1799. ,txnCount = count(''x'')
  1800. FROM remitTranTemp trn WITH(NOLOCK)
  1801. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1802. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1803. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1804. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1805. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1806. trn.payStatus = ''Unpaid'' AND
  1807. trn.approvedBy IS NULL AND trn.tranType=''I'' AND
  1808. trn.tranType <> ''O'' AND isOnlineTxn <> ''Y''
  1809. group by trn.sCountry
  1810. '
  1811. EXEC (@tablesql)
  1812. --print @tablesql
  1813. END
  1814. IF @flag = 'OnlineTxn-waitingList'
  1815. BEGIN
  1816. SET @tablesql = '
  1817. SELECT
  1818. sn = row_number() over(order by trn.sCountry)
  1819. ,country = upper(trn.sCountry)
  1820. ,txnCount = count(''x'')
  1821. FROM remitTranTemp trn WITH(NOLOCK)
  1822. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1823. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1824. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1825. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1826. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1827. trn.payStatus = ''Unpaid'' AND
  1828. trn.approvedBy IS NULL AND trn.tranType=''O'' AND isOnlineTxn =''Y''
  1829. group by trn.sCountry
  1830. '
  1831. EXEC (@tablesql)
  1832. --print @tablesql
  1833. END
  1834. IF @flag = 'getTxnForApproveByAgent'
  1835. BEGIN
  1836. SET @table = '
  1837. SELECT DISTINCT
  1838. trn.id
  1839. ,controlNo = dbo.fnadecryptstring(controlNo)
  1840. ,branch = am.agentName
  1841. ,country = trn.pCountry
  1842. ,senderId = sen.customerId
  1843. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1844. ,receiverId = rec.customerId
  1845. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1846. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1847. ,trn.paymentMethod
  1848. ,voucherNo = trn.voucherNo
  1849. ,txnDate = CAST(trn.createdDate AS DATE)
  1850. ,txncreatedBy = trn.createdBy
  1851. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1852. '
  1853. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1854. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1855. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1856. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1857. WHERE trn.tranStatus IN (''Hold'') AND
  1858. trn.payStatus = ''Unpaid'' AND
  1859. trn.approvedBy IS NULL AND
  1860. ISNULL(trn.isOnlineTxn,''N'') <>''Y'' AND trn.tranType<>''O''
  1861. AND TRN.COLLMODE = ''CASH COLLECT''
  1862. '
  1863. IF @user IS NOT NULL
  1864. SET @table = @table + ' AND trn.createdBy <> ''' + @user + ''''
  1865. IF @settlingAgentId IS NOT NULL
  1866. SET @table = @table + ' AND trn.sAgent = ''' + CAST(@settlingAgentId AS VARCHAR) + ''''
  1867. IF @id IS NOT NULL
  1868. SET @table = @table + ' AND trn.id = ''' + LTRIM(RTRIM(@id)) + ''''
  1869. IF @country IS NOT NULL
  1870. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1871. IF @sendCountry IS NOT NULL
  1872. SET @table = @table + ' AND trn.sCountry LIKE ''' + @sendCountry + '%'''
  1873. IF @amt IS NOT NULL
  1874. SET @table = @table + ' AND trn.pAmt = ' + CAST(@amt AS VARCHAR(20)) + ''
  1875. IF @voucherNo IS NOT NULL
  1876. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1877. IF @txncreatedBy IS NOT NULL
  1878. SET @table = @table + ' AND trn.createdBy = ''' + @txncreatedBy + ''''
  1879. IF @txnDate IS NOT NULL
  1880. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1881. IF @ControlNo IS NOT NULL
  1882. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + LTRIM(RTRIM(@ControlNo)) + ''')'
  1883. IF @sendBranch IS NOT NULL
  1884. SET @table = @table + ' AND trn.sBranch = ''' + @sendBranch + ''''
  1885. SET @sql = '
  1886. SELECT
  1887. *
  1888. FROM (
  1889. ' + @table + '
  1890. ) x
  1891. WHERE 1 = 1 '
  1892. IF @sender IS NOT NULL
  1893. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1894. IF @receiver IS NOT NULL
  1895. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1896. PRINT @sql
  1897. EXEC (@sql)
  1898. RETURN
  1899. END
  1900. IF @flag = 'getTxnForVerify'
  1901. BEGIN
  1902. SET @table = '
  1903. SELECT DISTINCT
  1904. trn.id
  1905. ,controlNo = dbo.fnadecryptstring(controlNo)
  1906. ,branch = am.agentName
  1907. ,country = trn.pCountry
  1908. ,senderId = sen.customerId
  1909. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1910. ,receiverId = rec.customerId
  1911. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1912. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1913. ,trn.paymentMethod
  1914. ,voucherNo = trn.voucherNo
  1915. ,txnDate = CAST(trn.createdDate AS DATE)
  1916. ,txncreatedBy = trn.createdBy
  1917. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1918. '
  1919. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1920. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1921. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1922. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1923. WHERE trn.tranStatus IN (''Hold'') AND
  1924. trn.payStatus = ''Unpaid'' AND
  1925. trn.approvedBy IS NULL AND ISNULL(sRouteId,''0'') =''1''
  1926. '
  1927. IF @sAgent IS NOT NULL
  1928. BEGIN
  1929. SET @table = @table + ' AND trn.sAgent = ''' + @sendAgent + ''''
  1930. END
  1931. SET @sql = '
  1932. SELECT
  1933. *
  1934. FROM (
  1935. ' + @table + '
  1936. ) x
  1937. WHERE 1 = 1 '
  1938. PRINT @sql
  1939. EXEC (@sql)
  1940. END
  1941. END TRY
  1942. BEGIN CATCH
  1943. --IF @@TRANCOUNT > 0
  1944. -- ROLLBACK TRANSACTION
  1945. --throw;
  1946. SELECT 1 error_code
  1947. ,ERROR_MESSAGE() msg
  1948. ,NULL id
  1949. END CATCH