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.

2264 lines
114 KiB

1 month ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_ApproveInwardHoldedTXN] Script Date: 7/25/2024 12:15:30 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_ApproveInwardHoldedTXN] (
  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. ,'True'
  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. ,@rewardAmt MONEY
  442. IF @isTxnRealtime IS NULL
  443. SET @isTxnRealtime = 0
  444. SELECT @tranStatus = transtatus
  445. ,@denyAmt = ISNULL(cAmt, 0) - ISNULL(sAgentComm, 0) - ISNULL(agentFxGain, 0)
  446. ,@sRouteId = sRouteId
  447. ,@pinEncrypted = controlNo
  448. ,@ControlNo = dbo.fnaDecryptstring(controlNo)
  449. ,@controlno2 = dbo.fnaDecryptstring(controlNo2)
  450. ,@txncreatedBy = createdBy
  451. ,@COLLMODE = ISNULL(RT.depositType,'ONLINE')
  452. ,@CUSTOMERID = TS.CUSTOMERID
  453. ,@transactionType = rt.trantype
  454. ,@rewardtype = rt.rewardType
  455. ,@rewardAmt = rewardPoints
  456. FROM remitTranTemp RT WITH (NOLOCK)
  457. INNER JOIN TRANSENDERSTEMP TS(NOLOCK) ON TS.TRANID = RT.ID
  458. WHERE RT.id = @id
  459. --IF LEN(@pinEncrypted)<7
  460. --BEGIN
  461. -- select TOP 1 @ControlNo = controlNo from Application_Log.dbo.vwtpapilogs(nolock) where requestedby=@txncreatedBy AND ERRORCODE='999' order by rowid desc
  462. --END
  463. --IF LEN(@ControlNo) < 7
  464. --BEGIN
  465. -- EXEC proc_errorHandler 1, 'Sorry,Cannot Reject Transaction', @id
  466. -- RETURN
  467. --END
  468. --BEGIN TRANSACTION
  469. INSERT INTO tranCancelrequest (
  470. tranId
  471. ,controlNo
  472. ,cancelReason
  473. ,cancelStatus
  474. ,createdBy
  475. ,createdDate
  476. ,tranStatus
  477. ,approvedBy
  478. ,approvedDate
  479. ,scRefund
  480. ,isScRefund
  481. )
  482. SELECT id
  483. ,controlNo
  484. ,@remarks
  485. ,'Approved'
  486. ,@user
  487. ,GETDATE()
  488. ,tranStatus
  489. ,@user
  490. ,GETDATE()
  491. ,cAmt
  492. ,'Y'
  493. FROM remitTranTemp WITH (NOLOCK)
  494. WHERE id = @id
  495. UPDATE remitTranTemp
  496. SET tranStatus = 'Cancel'
  497. ,cancelApprovedBy = @user
  498. ,cancelApprovedDate = GETDATE()
  499. ,cancelApprovedDateLocal = dbo.FNAGetDateInNepalTZ()
  500. ,cancelRequestBy = @user
  501. ,cancelRequestDate = GETDATE()
  502. ,cancelRequestDateLocal = dbo.FNADateFormatTZ(GETDATE(), @user)
  503. ,trnStatusBeforeCnlReq = @tranStatus
  504. ,controlNo = dbo.fnaEncryptstring(@ControlNo)
  505. WHERE id = @id
  506. INSERT INTO cancelTranHistory (
  507. tranId
  508. ,controlNo
  509. ,sCurrCostRate
  510. ,sCurrHoMargin
  511. ,sCurrSuperAgentMargin
  512. ,sCurrAgentMargin
  513. ,pCurrCostRate
  514. ,pCurrHoMargin
  515. ,pCurrSuperAgentMargin
  516. ,pCurrAgentMargin
  517. ,agentCrossSettRate
  518. ,customerRate
  519. ,sAgentSettRate
  520. ,pDateCostRate
  521. ,agentFxGain
  522. ,treasuryTolerance
  523. ,customerPremium
  524. ,schemePremium
  525. ,sharingValue
  526. ,sharingType
  527. ,serviceCharge
  528. ,handlingFee
  529. ,sAgentComm
  530. ,sAgentCommCurrency
  531. ,sSuperAgentComm
  532. ,sSuperAgentCommCurrency
  533. ,pAgentComm
  534. ,pAgentCommCurrency
  535. ,pSuperAgentComm
  536. ,pSuperAgentCommCurrency
  537. ,promotionCode
  538. ,promotionType
  539. ,pMessage
  540. ,sCountry
  541. ,sSuperAgent
  542. ,sSuperAgentName
  543. ,sAgent
  544. ,sAgentName
  545. ,sBranch
  546. ,sBranchName
  547. ,pCountry
  548. ,pSuperAgent
  549. ,pSuperAgentName
  550. ,pAgent
  551. ,pAgentName
  552. ,pBranch
  553. ,pBranchName
  554. ,paymentMethod
  555. ,pBank
  556. ,pBankName
  557. ,pBankBranch
  558. ,pBankBranchName
  559. ,accountNo
  560. ,externalBankCode
  561. ,collMode
  562. ,collCurr
  563. ,tAmt
  564. ,cAmt
  565. ,pAmt
  566. ,payoutCurr
  567. ,relWithSender
  568. ,purposeOfRemit
  569. ,sourceOfFund
  570. ,tranStatus
  571. ,payStatus
  572. ,createdDate
  573. ,createdDateLocal
  574. ,createdBy
  575. ,modifiedDate
  576. ,modifiedDateLocal
  577. ,modifiedBy
  578. ,approvedDate
  579. ,approvedDateLocal
  580. ,approvedBy
  581. ,paidDate
  582. ,paidDateLocal
  583. ,paidBy
  584. ,cancelRequestDate
  585. ,cancelRequestDateLocal
  586. ,cancelRequestBy
  587. ,cancelReason
  588. ,refund
  589. ,cancelCharge
  590. ,cancelApprovedDate
  591. ,cancelApprovedDateLocal
  592. ,cancelApprovedBy
  593. ,blockedDate
  594. ,blockedBy
  595. ,lockedDate
  596. ,lockedDateLocal
  597. ,lockedBy
  598. ,payTokenId
  599. ,tranType
  600. ,ContNo
  601. ,uploadLogId
  602. ,voucherNo
  603. ,controlNo2
  604. ,pBankType
  605. ,trnStatusBeforeCnlReq
  606. ,isSystemReject
  607. ,depositType
  608. ,transactionreference
  609. ,isOnlineTxn
  610. )
  611. SELECT id
  612. ,controlNo
  613. ,sCurrCostRate
  614. ,sCurrHoMargin
  615. ,sCurrSuperAgentMargin
  616. ,sCurrAgentMargin
  617. ,pCurrCostRate
  618. ,pCurrHoMargin
  619. ,pCurrSuperAgentMargin
  620. ,pCurrAgentMargin
  621. ,agentCrossSettRate
  622. ,customerRate
  623. ,sAgentSettRate
  624. ,pDateCostRate
  625. ,agentFxGain
  626. ,treasuryTolerance
  627. ,customerPremium
  628. ,schemePremium
  629. ,sharingValue
  630. ,sharingType
  631. ,serviceCharge
  632. ,handlingFee
  633. ,sAgentComm
  634. ,sAgentCommCurrency
  635. ,sSuperAgentComm
  636. ,sSuperAgentCommCurrency
  637. ,pAgentComm
  638. ,pAgentCommCurrency
  639. ,pSuperAgentComm
  640. ,pSuperAgentCommCurrency
  641. ,promotionCode
  642. ,promotionType
  643. ,pMessage
  644. ,sCountry
  645. ,sSuperAgent
  646. ,sSuperAgentName
  647. ,sAgent
  648. ,sAgentName
  649. ,sBranch
  650. ,sBranchName
  651. ,pCountry
  652. ,pSuperAgent
  653. ,pSuperAgentName
  654. ,pAgent
  655. ,pAgentName
  656. ,pBranch
  657. ,pBranchName
  658. ,paymentMethod
  659. ,pBank
  660. ,pBankName
  661. ,pBankBranch
  662. ,pBankBranchName
  663. ,accountNo
  664. ,externalBankCode
  665. ,collMode
  666. ,collCurr
  667. ,tAmt
  668. ,cAmt
  669. ,pAmt
  670. ,payoutCurr
  671. ,relWithSender
  672. ,purposeOfRemit
  673. ,sourceOfFund
  674. ,tranStatus
  675. ,payStatus
  676. ,createdDate
  677. ,createdDateLocal
  678. ,createdBy
  679. ,modifiedDate
  680. ,modifiedDateLocal
  681. ,modifiedBy
  682. ,approvedDate
  683. ,approvedDateLocal
  684. ,approvedBy
  685. ,paidDate
  686. ,paidDateLocal
  687. ,paidBy
  688. ,cancelRequestDate
  689. ,cancelRequestDateLocal
  690. ,cancelRequestBy
  691. ,@remarks
  692. ,refund
  693. ,cancelCharge
  694. ,GETDATE()
  695. ,dbo.FNADateFormatTZ(GETDATE(), @user)
  696. ,@user
  697. ,blockedDate
  698. ,blockedBy
  699. ,lockedDate
  700. ,lockedDateLocal
  701. ,lockedBy
  702. ,payTokenId
  703. ,tranType
  704. ,ContNo
  705. ,uploadLogId
  706. ,voucherNo
  707. ,controlNo2
  708. ,pBankType
  709. ,trnStatusBeforeCnlReq
  710. ,@isSystemReject
  711. ,depositType
  712. ,transactionreference
  713. ,isOnlineTxn
  714. FROM remitTranTemp
  715. WHERE id = @id
  716. INSERT INTO cancelTranSendersHistory (
  717. tranId
  718. ,customerId
  719. ,membershipId
  720. ,firstName
  721. ,middleName
  722. ,lastName1
  723. ,lastName2
  724. ,fullName
  725. ,country
  726. ,address
  727. ,STATE
  728. ,district
  729. ,zipCode
  730. ,city
  731. ,email
  732. ,homePhone
  733. ,workPhone
  734. ,mobile
  735. ,nativeCountry
  736. ,dob
  737. ,placeOfIssue
  738. ,customerType
  739. ,occupation
  740. ,idType
  741. ,idNumber
  742. ,idPlaceOfIssue
  743. ,issuedDate
  744. ,validDate
  745. ,extCustomerId
  746. ,cwPwd
  747. ,ttName
  748. ,isFirstTran
  749. ,customerRiskPoint
  750. ,countryRiskPoint
  751. ,gender
  752. ,salary
  753. ,companyName
  754. ,address2
  755. ,dcInfo
  756. ,ipAddress
  757. ,notifySms
  758. ,txnTestQuestion
  759. ,txnTestAnswer
  760. )
  761. SELECT tranId
  762. ,customerId
  763. ,membershipId
  764. ,firstName
  765. ,middleName
  766. ,lastName1
  767. ,lastName2
  768. ,fullName
  769. ,country
  770. ,address
  771. ,STATE
  772. ,district
  773. ,zipCode
  774. ,city
  775. ,email
  776. ,homePhone
  777. ,workPhone
  778. ,mobile
  779. ,nativeCountry
  780. ,dob
  781. ,placeOfIssue
  782. ,customerType
  783. ,occupation
  784. ,idType
  785. ,idNumber
  786. ,idPlaceOfIssue
  787. ,issuedDate
  788. ,validDate
  789. ,extCustomerId
  790. ,cwPwd
  791. ,ttName
  792. ,isFirstTran
  793. ,customerRiskPoint
  794. ,countryRiskPoint
  795. ,gender
  796. ,salary
  797. ,companyName
  798. ,address2
  799. ,dcInfo
  800. ,ipAddress
  801. ,notifySms
  802. ,txnTestQuestion
  803. ,txnTestAnswer
  804. FROM transenderstemp WITH (NOLOCK)
  805. WHERE tranId = LTRIM(RTRIM(@id))
  806. INSERT INTO cancelTranReceiversHistory (
  807. tranId
  808. ,customerId
  809. ,membershipId
  810. ,firstName
  811. ,middleName
  812. ,lastName1
  813. ,lastName2
  814. ,fullName
  815. ,country
  816. ,address
  817. ,STATE
  818. ,district
  819. ,zipCode
  820. ,city
  821. ,email
  822. ,homePhone
  823. ,workPhone
  824. ,mobile
  825. ,nativeCountry
  826. ,dob
  827. ,placeOfIssue
  828. ,customerType
  829. ,occupation
  830. ,idType
  831. ,idNumber
  832. ,idPlaceOfIssue
  833. ,issuedDate
  834. ,validDate
  835. ,idType2
  836. ,idNumber2
  837. ,idPlaceOfIssue2
  838. ,issuedDate2
  839. ,validDate2
  840. ,relationType
  841. ,relativeName
  842. ,gender
  843. ,address2
  844. ,dcInfo
  845. ,ipAddress
  846. )
  847. SELECT tranId
  848. ,customerId
  849. ,membershipId
  850. ,firstName
  851. ,middleName
  852. ,lastName1
  853. ,lastName2
  854. ,fullName
  855. ,country
  856. ,address
  857. ,STATE
  858. ,district
  859. ,zipCode
  860. ,city
  861. ,email
  862. ,homePhone
  863. ,workPhone
  864. ,mobile
  865. ,nativeCountry
  866. ,dob
  867. ,placeOfIssue
  868. ,customerType
  869. ,occupation
  870. ,idType
  871. ,idNumber
  872. ,idPlaceOfIssue
  873. ,issuedDate
  874. ,validDate
  875. ,idType2
  876. ,idNumber2
  877. ,idPlaceOfIssue2
  878. ,issuedDate2
  879. ,validDate2
  880. ,relationType
  881. ,relativeName
  882. ,gender
  883. ,address2
  884. ,dcInfo
  885. ,ipAddress
  886. FROM tranReceiversTemp WITH (NOLOCK)
  887. WHERE tranId = LTRIM(RTRIM(@id))
  888. ----reverse deposit mapping
  889. --IF @COLLMODE = 'Bank Deposit'
  890. -- AND @isTxnRealtime = 0
  891. --BEGIN
  892. -- IF EXISTS (
  893. -- SELECT 'x'
  894. -- FROM customer_deposit_logs
  895. -- WHERE customerid = @CUSTOMERID
  896. -- AND approvedby IS NULL
  897. -- )
  898. -- BEGIN
  899. -- UPDATE customer_deposit_logs
  900. -- SET processedby = NULL
  901. -- ,processeddate = NULL
  902. -- ,customerid = NULL
  903. -- WHERE customerid = @CUSTOMERID
  904. -- AND approvedby IS NULL
  905. -- END
  906. --END
  907. --update balance
  908. DECLARE @referralCode VARCHAR(15)
  909. ,@sType CHAR(1)
  910. ,@isOnbehalf CHAR(1)
  911. ,@sAgent INT
  912. ,@senderUserId INT
  913. SELECT @referralCode = PROMOTIONCODE
  914. ,@sAgent = sAgent
  915. ,@cAmt = cAmt
  916. ,@isOnbehalf = (
  917. CASE
  918. WHEN ISNULL(ISONBEHALF, 0) = '1'
  919. THEN 'Y'
  920. ELSE 'N'
  921. END
  922. )
  923. ,@senderUserId = AU.userId
  924. FROM dbo.remitTranTemp RT(NOLOCK)
  925. INNER JOIN applicationUsers AU(NOLOCK) ON AU.userName = RT.createdBy
  926. WHERE controlNo = dbo.fnaEncryptstring(@ControlNo)
  927. IF @COLLMODE = 'Cash Collect'
  928. BEGIN
  929. --select @sAgent,@userId,@referralCode,@cAmt,@isOnbehalf,@ControlNo
  930. EXEC PROC_UPDATE_AVAILABALE_BALANCE @FLAG = 'CANCEL'
  931. ,@S_AGENT = @sAgent
  932. ,@S_USER = @senderUserId
  933. ,@REFERRAL_CODE = @referralCode
  934. ,@C_AMT = @cAmt
  935. ,@ONBEHALF = @isOnbehalf
  936. END
  937. DELETE
  938. FROM remitTranTemp
  939. WHERE id = @id
  940. DELETE
  941. FROM tranSendersTemp
  942. WHERE tranId = @id
  943. DELETE
  944. FROM tranReceiversTemp
  945. WHERE tranId = @id
  946. IF @rewardtype = 'FREE_SC'
  947. BEGIN
  948. UPDATE remitDatalog
  949. SET controlNo = NULL
  950. WHERE ControlNo = @ControlNo or controlNo = @controlNo2
  951. END
  952. ELSE
  953. BEGIN
  954. DELETE
  955. FROM remitDatalog
  956. WHERE tranId = @id
  957. END
  958. SELECT @message = 'Transaction cancel has been done successfully.'
  959. IF @rewardtype = 'REDEEM'
  960. BEGIN
  961. EXEC proc_InsertRewardPoints @Flag = 'CREDIT', @CustomerId = @CUSTOMERID, @rewardPoints = @rewardAmt, @TranId = @id, @type = 'REJECT'
  962. END
  963. EXEC proc_transactionLogs @flag = 'i'
  964. ,@user = @user
  965. ,@tranId = @id
  966. ,@message = @message
  967. ,@msgType = 'Cancel'
  968. IF @branch = 'Mobile'
  969. BEGIN
  970. INSERT INTO pushNotificationHistroy (
  971. customerId
  972. ,body
  973. ,title
  974. ,createDate
  975. ,imageURL
  976. ,sentId
  977. ,Type
  978. ,isReservation
  979. ,isRead
  980. ,isSend
  981. ,category
  982. )
  983. SELECT @customerid
  984. ,'Tran ID : ' + CAST(@id AS VARCHAR) + ' was successfully cancelled.'
  985. ,'CancelTxn'
  986. ,getdate()
  987. ,''
  988. ,@id
  989. ,0
  990. ,0
  991. ,0
  992. ,0
  993. ,'INFO'
  994. END
  995. IF EXists(select * fROM TRU_TranDetail WHERE Tranid=@id)
  996. BEGIN
  997. UPDATE dbo.TRU_TranDetail
  998. SET recordStatus = 'EXPIRED'
  999. WHERE tranid=@id
  1000. and recordStatus IN ( 'PROCESS','DRAFT')
  1001. END
  1002. --IF @@TRANCOUNT > 0
  1003. -- COMMIT TRANSACTION
  1004. IF @transactionType = 'I'
  1005. BEGIN
  1006. IF EXISTS (
  1007. SELECT TOP 1 1
  1008. FROM applicationUsers(NOLOCK)
  1009. WHERE userName = @txncreatedBy
  1010. )
  1011. BEGIN
  1012. UPDATE APPLICATIONUSERS
  1013. SET freeScCounter = CASE
  1014. WHEN ISNULL(freeScCounter, 0) > 0
  1015. THEN ISNULL(freeScCounter, 0) - 1
  1016. ELSE freeScCounter
  1017. END
  1018. WHERE username = @txncreatedBy
  1019. END
  1020. END
  1021. EXEC proc_errorHandler 0
  1022. ,'Transaction Rejected Successfully'
  1023. ,@id
  1024. RETURN
  1025. END
  1026. IF @flag = 'approve'
  1027. BEGIN
  1028. IF NOT EXISTS (
  1029. SELECT 'X'
  1030. FROM remitTranTemp RT WITH (NOLOCK)
  1031. WHERE RT.id = @id
  1032. )
  1033. BEGIN
  1034. EXEC proc_errorHandler 1
  1035. ,'There is no transaction to approve, either it is rejected/approved or not found!!'
  1036. ,@id
  1037. RETURN;
  1038. END
  1039. --IF EXISTS (
  1040. -- SELECT 'X'
  1041. -- FROM remitTranTemp RT WITH (NOLOCK)
  1042. -- WHERE RT.id = @id
  1043. -- AND controlno = 'LLm_IOQMMRMQM'
  1044. -- )
  1045. --BEGIN
  1046. -- EXEC proc_errorHandler 1
  1047. -- ,'You can not approve this txn, please contact HQ!!'
  1048. -- ,@id
  1049. -- RETURN;
  1050. --END
  1051. DECLARE @pBank INT
  1052. ,@paymentMethod VARCHAR(50)
  1053. ,@tranType CHAR(1)
  1054. ,@externalBankCode INT
  1055. ,@createdDate DATETIME
  1056. ,@senderName VARCHAR(100)
  1057. ,@sBranchName VARCHAR(150)
  1058. ,@pAgentComm MONEY
  1059. ,@schemeId INT
  1060. DECLARE @agentFxGain MONEY
  1061. IF @createdBy = @user
  1062. BEGIN
  1063. EXEC proc_errorHandler 1
  1064. ,'Same user cannot approve the Transaction'
  1065. ,@id
  1066. RETURN
  1067. END
  1068. DECLARE @tAmt MONEY
  1069. ,@pAmt MONEY
  1070. ,@introducer VARCHAR(50)
  1071. ,@payoutPartner INT
  1072. ,@serviceCharge MONEY
  1073. ,@pCurrCostRate FLOAT
  1074. ,@pCurrHoMargin FLOAT
  1075. ,@isFirstTran CHAR(1)
  1076. ,@userName VARCHAR(80)
  1077. ,@rewardPoints MONEY
  1078. UPDATE REMITTRANTEMP
  1079. SET agentFxGain = tamt - (ROUND((pamt / pCurrCostRate), 2))
  1080. WHERE ISNULL(psuperagent, 0) <> 394132
  1081. AND id = @id
  1082. SELECT @cAmt = cAmt
  1083. ,@customerId = cm.customerId
  1084. ,@userId = A.userId
  1085. ,@tAmt = r.tAmt
  1086. ,@pAmt = r.pAmt
  1087. ,@createdBy = r.createdBy
  1088. ,@controlNo = dbo.FNADecryptString(controlNo)
  1089. ,@tpControlNo2 = dbo.FNADecryptString(controlNo2)
  1090. ,@sBranch = sBranch
  1091. ,@sBranchName = sBranchName
  1092. ,@pinEncrypted = controlNo
  1093. ,@pBank = pBank
  1094. ,@introducer = promotionCode
  1095. ,@sAgent = sAgent
  1096. ,@paymentMethod = paymentMethod
  1097. ,@tranType = tranType
  1098. ,@sRouteId = sRouteId
  1099. ,@collMode = ISNULL(R.depositType,'ONLINE')
  1100. ,@externalBankCode = externalBankCode
  1101. ,@createdDate = r.createdDate
  1102. ,@senderName = r.senderName
  1103. ,@tranStatus = R.tranStatus
  1104. ,@payoutPartner = R.pSuperAgent
  1105. ,@serviceCharge = R.serviceCharge
  1106. ,@pCurrCostRate = R.pCurrCostRate
  1107. ,@pCurrHoMargin = R.pCurrHoMargin
  1108. ,@agentFxGain = R.agentFxGain
  1109. ,@isFirstTran = ISNULL(T.isFirstTran, 'N')
  1110. ,@pAgentComm = r.pAgentComm
  1111. ,@userName = CM.USERNAME
  1112. ,@isOnbehalf = (
  1113. CASE
  1114. WHEN ISONBEHALF = '1'
  1115. THEN 'Y'
  1116. ELSE 'N'
  1117. END
  1118. )
  1119. ,@downlodedBy = downloadedBy
  1120. ,@rewardPoints = ISNULL(rewardPoints, 0)
  1121. ,@schemeId = ISNULL(r.schemeId,0)
  1122. ,@rewardType = ISNULL(r.rewardType,'')
  1123. FROM remitTranTemp r WITH (NOLOCK)
  1124. INNER JOIN TRANSENDERSTemp T(NOLOCK) ON T.TRANID = R.ID
  1125. LEFT JOIN customerMaster cm(NOLOCK) ON T.customerId = cm.customerId
  1126. LEFT JOIN applicationUsers A(NOLOCK) ON A.USERNAME = R.CREATEDBY
  1127. WHERE r.id = @id
  1128. --IF @collMode = 'Bank Deposit'
  1129. --BEGIN
  1130. -- IF EXISTS (
  1131. -- SELECT 1
  1132. -- FROM CUSTOMER_DEPOSIT_LOGS(NOLOCK)
  1133. -- WHERE CUSTOMERID = @customerId
  1134. -- AND APPROVEDBY IS NULL
  1135. -- )
  1136. -- BEGIN
  1137. -- EXEC proc_errorHandler 1
  1138. -- ,'Customer Deposit Mapping pending for Approval!!'
  1139. -- ,@id
  1140. -- RETURN;
  1141. -- END
  1142. -- SELECT @DENYAMT = DBO.FNAGetCustomerAvailableBalance(@customerId)
  1143. -- --FNAGetCustomerAvailableBalance
  1144. -- IF @DENYAMT < 0
  1145. -- BEGIN
  1146. -- EXEC proc_errorHandler 1
  1147. -- ,'Customer do not have sufficient balance for this transaction!!'
  1148. -- ,@id
  1149. -- RETURN;
  1150. -- END
  1151. --END
  1152. --EXEC proc_errorHandler 0, 'Transaction Approved Successfully', @controlNo
  1153. --RETURN
  1154. DECLARE @kycStatus INT
  1155. SELECT @kycStatus = kycStatus
  1156. FROM TBL_CUSTOMER_KYC(NOLOCK)
  1157. WHERE CUSTOMERID = @customerId
  1158. AND ISDELETED = 0
  1159. --AND kycStatus=11044
  1160. ORDER BY KYC_DATE
  1161. SELECT @parentId = parentId
  1162. FROM agentMaster WITH (NOLOCK)
  1163. WHERE agentId = @sBranch
  1164. SELECT @invicePrintMethod = invoicePrintMethod
  1165. FROM agentMaster A WITH (NOLOCK)
  1166. INNER JOIN agentBusinessFunction B WITH (NOLOCK) ON A.agentId = B.agentId
  1167. WHERE A.agentId = @parentId
  1168. --BEGIN TRANSACTION
  1169. UPDATE remitTranTemp
  1170. SET tranStatus = CASE tranStatus
  1171. WHEN 'Hold'
  1172. THEN 'Payment'
  1173. WHEN 'Compliance Hold'
  1174. THEN 'Compliance'
  1175. WHEN 'OFAC Hold'
  1176. THEN 'OFAC'
  1177. WHEN 'OFAC/Compliance Hold'
  1178. THEN 'OFAC/Compliance'
  1179. WHEN 'Cash Limit Hold'
  1180. THEN 'Cash Limit'
  1181. WHEN 'Cash Limit/Compliance Hold'
  1182. THEN 'Cash Limit/Compliance'
  1183. WHEN 'Cash Limit/OFAC Hold'
  1184. THEN 'Cash Limit/OFAC'
  1185. WHEN 'Cash Limit/OFAC/Compliance Hold'
  1186. THEN 'Cash Limit/OFAC/Compliance'
  1187. ELSE 'Payment'
  1188. END
  1189. ,approvedBy = @user
  1190. ,approvedDate = GETDATE()
  1191. ,approvedDateLocal = GETDATE()
  1192. WHERE id = @id
  1193. print 'here'
  1194. PRINT @id;
  1195. --Return;
  1196. --send email to customers
  1197. --INSERT INTO tempTransactionMailQueue (
  1198. -- controlNo
  1199. -- ,createdDate
  1200. -- ,[status]
  1201. -- ) --tranType is used to know either mail is sent or not, we put 'N' for not sent
  1202. --SELECT rt.controlNo
  1203. -- ,GETDATE()
  1204. -- ,'N'
  1205. --FROM remitTranTemp rt(NOLOCK)
  1206. --WHERE rt.id = @id
  1207. EXEC proc_customerTxnHistory @controlNo = @pinEncrypted
  1208. ----## pish temp into main table
  1209. EXEC proc_remitTranTempToMain @id
  1210. SELECT @TRANID = ID
  1211. FROM REMITTRAN(NOLOCK)
  1212. WHERE controlNo = @pinEncrypted
  1213. --EXEC proc_InsertRewardPoints @tranId = @tranId
  1214. -- ,@customerId = @customerId
  1215. -- ,@rewardPoints = @rewardPoints
  1216. SET @remarks = 'Remittance :' + @controlNo + ' by:' + @senderName + ' from ' + @sBranchName + '-branch on dtd: ' + cast(@createdDate AS VARCHAR)
  1217. SET @txnDate = @createdDate
  1218. --EXEC PROC_CALCULATE_REFERRAL_COMM @COMMISSION_AMT = @serviceCharge
  1219. -- ,@T_AMT = @tAmt
  1220. -- ,@FX = @agentFxGain
  1221. -- ,@IS_NEW_CUSTOMER = @isFirstTran
  1222. -- ,@REFERRAL_CODE = @introducer
  1223. -- ,@PAYOUT_PARTNER = @payoutPartner
  1224. -- ,@CUSTOMER_ID = @customerId
  1225. -- ,@TRAN_ID = @TRANID
  1226. -- ,@S_AGENT = @sAgent
  1227. -- ,@AMOUNT = @cAmt
  1228. -- ,@USER = @user
  1229. -- ,@TRAN_DATE = @txnDate
  1230. -- ,@COLL_MODE = @collMode
  1231. -- ,@P_AGENT_COMM_AMT = @pAgentComm
  1232. PRINT '@collMode';
  1233. PRINT @collMode
  1234. ----INSERT INTO TRANSACTION TABLE(MAP DEPOSIT TXN WITH CUSTOMER)
  1235. INSERT INTO CUSTOMER_TRANSACTIONS (
  1236. customerId
  1237. ,tranDate
  1238. ,particulars
  1239. ,deposit
  1240. ,withdraw
  1241. ,refereceId
  1242. ,head
  1243. ,createdBy
  1244. ,createdDate
  1245. ,bankId
  1246. )
  1247. SELECT @customerId
  1248. ,@txnDate
  1249. ,@remarks
  1250. ,0
  1251. ,@cAmt
  1252. ,@TRANID
  1253. ,'Send Txn: ' + @collMode
  1254. ,@createdBy
  1255. ,@createdDate
  1256. ,@externalBankCode
  1257. --EXEC PROC_UPDATE_AVAILABALE_BALANCE @FLAG='CANCEL',@S_AGENT = @sAgent,@S_USER = @senderUserId,@REFERRAL_CODE = @introducer,@C_AMT = @cAmt,@ONBEHALF =@isOnbehalf
  1258. --INSERT INTO CASH AND VAULT TABLE FOR BRANCH CASH HOLD LIMIT CHECK
  1259. --INSERT INTO CASH AND VAULT TABLE FOR BRANCH CASH HOLD LIMIT CHECK
  1260. --INSERT INTO CASH AND VAULT TABLE FOR BRANCH CASH HOLD LIMIT CHECK
  1261. --INSERT INTO CASH AND VAULT TABLE FOR BRANCH CASH HOLD LIMIT CHECK
  1262. --INSERT INTO CASH AND VAULT TABLE FOR BRANCH CASH HOLD LIMIT CHECK
  1263. IF ISNULL(@kycStatus, 0) <> 11044
  1264. BEGIN
  1265. --UPDATE REMITTRAN
  1266. --SET tranStatus = CASE tranStatus
  1267. -- WHEN 'Payment'
  1268. -- THEN 'Hold'
  1269. -- ELSE tranStatus
  1270. -- END
  1271. --WHERE CONTROLNO = @pinEncrypted
  1272. PRINT @kycStatus
  1273. INSERT INTO tranModifyLog (
  1274. tranId
  1275. ,message
  1276. ,createdBy
  1277. ,createdDate
  1278. ,MsgType
  1279. )
  1280. SELECT @TRANID
  1281. ,'Customer KYC Status not matched(i.e. KYC Completed)'
  1282. ,'system'
  1283. ,GETDATE()
  1284. ,'TXN HOLD: CUSTOMER KYC NOT APPROVED'
  1285. --IF @collMode = 'Bank Deposit'
  1286. --BEGIN
  1287. -- EXEC proc_UpdateCustomerBalance @controlNo = @pinEncrypted
  1288. -- ,@type = 'deduct'
  1289. -- SELECT @DENYAMT = DBO.FNAGetCustomerAvailableBalance(@customerId)
  1290. -- IF @DENYAMT < 0
  1291. -- UPDATE REMITTRAN
  1292. -- SET tranStatus = CASE tranStatus
  1293. -- WHEN 'Payment'
  1294. -- THEN 'Hold'
  1295. -- ELSE tranStatus
  1296. -- END
  1297. -- WHERE CONTROLNO = @pinEncrypted
  1298. -- IF @DENYAMT < 0
  1299. -- INSERT INTO tranModifyLog (
  1300. -- tranId
  1301. -- ,message
  1302. -- ,createdBy
  1303. -- ,createdDate
  1304. -- ,MsgType
  1305. -- )
  1306. -- SELECT @TRANID
  1307. -- ,'Transaction Auto Hold By System: Insufficient Balance seen in system for this customer'
  1308. -- ,'system'
  1309. -- ,GETDATE()
  1310. -- ,'TXN HOLD: Invalid balance'
  1311. -- EXEC PROC_UNTRANSACTED_UPDATE @UPDATE_TYPE = 'TXN-SEND'
  1312. -- ,@CUSTOMER_ID = @customerId
  1313. -- ,@UPDATE_AMT = @cAmt
  1314. -- ,@UPDATE_REF_NUM = @ControlNo
  1315. -- ,@UPDATE_DATE = @createdDate;
  1316. --END
  1317. RETURN;
  1318. END
  1319. --IF @tranType = 'M'
  1320. -- AND @collMode = 'Bank Deposit'
  1321. --BEGIN
  1322. -- EXEC PROC_INSERT_JP_DEPOSIT_TXN_LOG @FLAG = 'I'
  1323. -- ,@TRANID = @id
  1324. -- ,@CUSTOMERID = @customerId
  1325. -- ,@CAMT = @cAmt
  1326. --END
  1327. --For mobile broadcast notification
  1328. IF @tranType = 'M'
  1329. BEGIN
  1330. -- EXEC ProcBroadCastMobile @Flag='txn-approve', @RowId=@TRANID, @ControlNo=@controlNo, @CustomerId=@customerId
  1331. INSERT INTO pushNotificationHistroy (
  1332. customerId
  1333. ,body
  1334. ,title
  1335. ,createDate
  1336. ,imageURL
  1337. ,sentId
  1338. ,Type
  1339. ,isReservation
  1340. ,isRead
  1341. ,isSend
  1342. ,category
  1343. )
  1344. SELECT @customerid
  1345. ,'This is send Txn body Msg'
  1346. ,'SendTxn'
  1347. ,getdate()
  1348. ,''
  1349. ,@tranId
  1350. ,1
  1351. ,0
  1352. ,0
  1353. ,0
  1354. ,'INFO'
  1355. END
  1356. IF @sAgent = '394395'
  1357. AND @paymentMethod = 'Mobile Wallet'
  1358. BEGIN
  1359. UPDATE dbo.remitTran
  1360. SET payStatus = 'POST'
  1361. ,postedBy = @user
  1362. ,postedDate = GETDATE()
  1363. ,postedDateLocal = GETDATE()
  1364. WHERE controlNo = @pinEncrypted
  1365. END
  1366. INSERT INTO PinQueueList (ICN)
  1367. SELECT @pinEncrypted
  1368. --IF @@TRANCOUNT > 0
  1369. -- COMMIT TRANSACTION
  1370. EXEC proc_errorHandler 0
  1371. ,'Transaction Approved Successfully'
  1372. ,@controlNo
  1373. --## generate voucher entry
  1374. EXEC FastMoneyPro_Account.dbo.proc_transactionVoucherEntry @controlNo = @controlNo
  1375. --IF @tranType = 'M'
  1376. --BEGIN
  1377. -- EXEC ProcIntroducerCommissionDetail @TranId = @TRANID
  1378. -- ,@CustomerId = @customerId
  1379. -- ,@User = @User
  1380. -- ,@IsCancel = 0
  1381. -- ,@TranDate = @createdDate
  1382. --END
  1383. RETURN
  1384. END
  1385. IF @flag = 'verifyTxnSendFromTabPage'
  1386. BEGIN
  1387. IF EXISTS (
  1388. SELECT 1
  1389. FROM dbo.remitTranTemp
  1390. WHERE id = @id
  1391. )
  1392. BEGIN
  1393. UPDATE dbo.remitTranTemp
  1394. SET sRouteId = 'IN'
  1395. WHERE id = @id
  1396. EXEC proc_errorHandler 0
  1397. ,'Transaction Verify Successfully'
  1398. ,@id
  1399. RETURN;
  1400. END
  1401. ELSE
  1402. BEGIN
  1403. EXEC proc_errorHandler 1
  1404. ,'Transaction Not Found'
  1405. ,@id
  1406. RETURN;
  1407. END
  1408. END
  1409. IF @flag = 'approve-all'
  1410. BEGIN
  1411. EXEC proc_ApproveHoldedTXN_Sub @user = @user
  1412. ,@idList = @idList
  1413. RETURN
  1414. END
  1415. DECLARE @cdTable VARCHAR(MAX) = ''
  1416. SET @cdTable = '
  1417. LEFT JOIN (
  1418. SELECT
  1419. DISTINCT
  1420. tranId
  1421. ,cb.bankName
  1422. ,cd.countryBankId
  1423. FROM collectionDetails cd WITH(NOLOCK)
  1424. LEFT JOIN countryBanks cb WITH(NOLOCK) ON cd.countryBankId = cb.countryBankId
  1425. INNER JOIN remitTranTemp trn WITH(NOLOCK) ON cd.tranId = trn.id
  1426. AND (trn.tranStatus = ''Hold'' OR trn.tranStatus = ''Compliance Hold'' OR trn.tranStatus = ''OFAC Hold'' )
  1427. AND trn.payStatus = ''Unpaid''
  1428. AND trn.approvedBy IS NULL
  1429. ) cd ON cd.tranId = trn.id '
  1430. IF EXISTS (
  1431. SELECT *
  1432. FROM dbo.sysobjects
  1433. WHERE id = OBJECT_ID(N'[#collModeList]')
  1434. AND type = 'D'
  1435. )
  1436. BEGIN
  1437. DROP TABLE #collModeList
  1438. END
  1439. CREATE TABLE #collModeList (
  1440. tranId INT
  1441. ,hasProcess CHAR(1)
  1442. ,proMode VARCHAR(50)
  1443. )
  1444. DECLARE @tranId1 INT
  1445. IF @flag = 's-admin'
  1446. BEGIN
  1447. IF @sendCountry = 'ALL'
  1448. SET @sendCountry = NULL
  1449. SET @table = '
  1450. SELECT DISTINCT
  1451. trn.id,
  1452. controlNo = DBO.FNADECRYPTSTRING(trn.CONTROLNO),
  1453. controlNo2 = DBO.FNADECRYPTSTRING(trn.CONTROLNO2),
  1454. branchName = am.agentName,
  1455. country = trn.pCountry,
  1456. senderId = sen.customerId,
  1457. sender = sen.firstName + ISNULL('' '' + sen.middleName, '''') + ISNULL('' '' + sen.lastName1, '''') + ISNULL('' '' + sen.lastName2, ''''),
  1458. receiverId = rec.customerId,
  1459. receiver = rec.firstName + ISNULL('' '' + rec.middleName, '''') + ISNULL('' '' + rec.lastName1, '''') + ISNULL('' '' + rec.lastName2, ''''),
  1460. amt = CAST(trn.cAmt AS DECIMAL(18, 2)),
  1461. voucherNo = trn.voucherNo,
  1462. serviceCharge = trn.serviceCharge,
  1463. txnDate = CAST(trn.createdDate AS DATE),
  1464. txncreatedBy = trn.createdBy,
  1465. trn.paymentMethod AS collMode,
  1466. CAST(trn.pAmt AS DECIMAL(10,2)) AS pAmt,
  1467. ISNULL(depositType, '''') AS depositType
  1468. FROM remitTranTemp trn WITH(NOLOCK)
  1469. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1470. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1471. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1472. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1473. WHERE trn.tranStatus IN (''Hold'')
  1474. AND trn.payStatus = ''Unpaid''
  1475. AND trn.approvedBy IS NULL
  1476. --AND trn.verifiedDate IS NULL
  1477. --AND ISNULL(sRouteId, ''0'') IN (''0'', ''M'')
  1478. AND trn.tranType = ''I''
  1479. AND trn.sRouteId = ''IN''
  1480. '
  1481. IF @id IS NOT NULL
  1482. SET @table = @table + ' AND trn.id = ''' + LTRIM(RTRIM(@id)) + ''''
  1483. IF @branch IS NOT NULL
  1484. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1485. IF @country IS NOT NULL
  1486. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1487. IF @sendCountry IS NOT NULL
  1488. SET @table = @table + ' AND trn.sCountry LIKE ''' + @sendCountry + '%'''
  1489. IF @amt IS NOT NULL
  1490. SET @table = @table + ' AND trn.pAmt = ' + CAST(@amt AS VARCHAR(20)) + ''
  1491. IF @voucherNo IS NOT NULL
  1492. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1493. IF @txncreatedBy IS NOT NULL
  1494. SET @table = @table + ' AND trn.createdBy = ''' + @txncreatedBy + ''''
  1495. IF @txnDate IS NOT NULL
  1496. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1497. IF @ControlNo IS NOT NULL
  1498. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + LTRIM(RTRIM(@ControlNo)) + ''')'
  1499. IF @tpControlNo2 IS NOT NULL
  1500. SET @table = @table + ' AND trn.controlNo2 = dbo.fnaEncryptString(''' + LTRIM(RTRIM(@tpControlNo2)) + ''')'
  1501. IF @sendAgent IS NOT NULL
  1502. SET @table = @table + ' AND trn.sAgent = ''' + @sendAgent + ''''
  1503. IF @sendBranch IS NOT NULL
  1504. SET @table = @table + ' AND trn.sBranch = ''' + @sendBranch + ''''
  1505. SET @sql = '
  1506. SELECT
  1507. *
  1508. FROM (
  1509. ' + @table + '
  1510. ) x
  1511. WHERE 1 = 1 '
  1512. IF @sender IS NOT NULL
  1513. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1514. IF @receiver IS NOT NULL
  1515. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1516. PRINT @sql
  1517. EXEC (@sql)
  1518. RETURN
  1519. END
  1520. IF @flag = 's-admin-map'
  1521. BEGIN
  1522. SET @table = '
  1523. SELECT DISTINCT
  1524. trn.id
  1525. ,controlNo = dbo.fnadecryptstring(controlNo)
  1526. ,branch = am.agentName
  1527. ,country = trn.pCountry
  1528. ,senderId = sen.customerId
  1529. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1530. ,receiverId = rec.customerId
  1531. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1532. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1533. ,paymentMethod = case when trn.collMode = ''Bank Deposit'' then ''JP Post'' ELSE trn.collMode END
  1534. ,voucherNo = trn.voucherNo
  1535. ,txnDate = CAST(trn.createdDate AS DATE)
  1536. ,txncreatedBy = trn.createdBy
  1537. ,trn.collMode collMode
  1538. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1539. '
  1540. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1541. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1542. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1543. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1544. WHERE trn.tranStatus IN (''Hold'') AND
  1545. trn.payStatus = ''Unpaid'' AND
  1546. trn.approvedBy IS NULL AND ISNULL(sRouteId,''0'') in(''0'',''M'')
  1547. AND trn.tranType=''I''
  1548. --AND trn.pcountry in (''vietnam'',''nepal'')
  1549. '
  1550. IF @ControlNo IS NOT NULL
  1551. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + @ControlNo + ''')'
  1552. SET @sql = '
  1553. SELECT
  1554. *
  1555. FROM (
  1556. ' + @table + '
  1557. ) x
  1558. WHERE 1 = 1 '
  1559. EXEC (@sql)
  1560. RETURN
  1561. END
  1562. IF @flag = 's-admin-online'
  1563. BEGIN
  1564. SET @table = '
  1565. SELECT DISTINCT
  1566. trn.id
  1567. ,branch = am.agentName
  1568. ,country = trn.pCountry
  1569. ,senderId = sen.customerId
  1570. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1571. ,receiverId = rec.customerId
  1572. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1573. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1574. ,txnDate = CAST(trn.createdDate AS DATE)
  1575. ,txncreatedBy = trn.createdBy
  1576. ,CASE WHEN trn.pAgent=1100 OR trn.pAgent = 1043 THEN 1 ELSE 0 END isThirdPartyTran
  1577. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1578. '
  1579. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1580. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1581. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1582. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1583. WHERE trn.tranStatus IN (''Hold'') AND
  1584. trn.payStatus = ''Unpaid'' AND
  1585. trn.approvedBy IS NULL AND ISNULL(trn.isOnlineTxn,''N'') =''Y''
  1586. AND trn.tranType=''O''
  1587. '
  1588. IF @id IS NOT NULL
  1589. SET @table = @table + ' AND trn.id = ''' + LTRIM(RTRIM(@id)) + ''''
  1590. IF @branch IS NOT NULL
  1591. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1592. IF @country IS NOT NULL
  1593. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1594. IF @sendCountry IS NOT NULL
  1595. SET @table = @table + ' AND trn.sCountry LIKE ''' + @sendCountry + '%'''
  1596. IF @amt IS NOT NULL
  1597. SET @table = @table + ' AND trn.pAmt = ' + CAST(@amt AS VARCHAR(20)) + ''
  1598. IF @voucherNo IS NOT NULL
  1599. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1600. IF @txncreatedBy IS NOT NULL
  1601. SET @table = @table + ' AND trn.createdBy = ''' + @txncreatedBy + ''''
  1602. IF @txnDate IS NOT NULL
  1603. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1604. IF @ControlNo IS NOT NULL
  1605. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + LTRIM(RTRIM(@ControlNo)) + ''')'
  1606. IF @sendAgent IS NOT NULL
  1607. SET @table = @table + ' AND trn.sAgent = ''' + @sendAgent + ''''
  1608. IF @sendBranch IS NOT NULL
  1609. SET @table = @table + ' AND trn.sBranch = ''' + @sendBranch + ''''
  1610. SET @sql = '
  1611. SELECT
  1612. * , STUFF((SELECT '''' + US.voucherNo +'' - ''+ CONVERT(VARCHAR(11),US.voucherDate,6) +'' - ''+ CAST(US.voucherAmt AS VARCHAR)+'' || ''
  1613. FROM bankCollectionVoucherDetail US
  1614. WHERE US.tempTranId = x.id
  1615. FOR XML PATH('''')), 1, 1, '''') [voucherDetail]
  1616. FROM (
  1617. ' + @table + '
  1618. ) x
  1619. WHERE 1 = 1 '
  1620. IF @sender IS NOT NULL
  1621. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1622. IF @receiver IS NOT NULL
  1623. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1624. PRINT @sql
  1625. EXEC (@sql)
  1626. RETURN
  1627. END
  1628. IF @flag = 's-agent'
  1629. BEGIN
  1630. SELECT @isSelfApprove = ISNULL(b.isSelfTxnApprove, 'N')
  1631. FROM agentmaster a WITH (NOLOCK)
  1632. LEFT JOIN agentBusinessFunction b WITH (NOLOCK) ON a.parentId = b.agentId
  1633. WHERE a.agentId = @branchId
  1634. SET @branchList = '
  1635. INNER JOIN (
  1636. SELECT ' + CAST(@branchId AS VARCHAR) + ' agentId '
  1637. IF @userType = 'RH'
  1638. BEGIN
  1639. SET @branchList = @branchList + '
  1640. UNION ALL
  1641. SELECT
  1642. am.agentId
  1643. FROM agentMaster am WITH(NOLOCK)
  1644. INNER JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  1645. WHERE rba.agentId = ' + CAST(@branchId AS VARCHAR) + '
  1646. AND ISNULL(rba.isDeleted, ''N'') = ''N''
  1647. AND ISNULL(rba.isActive, ''N'') = ''Y''
  1648. AND memberAgentId <> ' + CAST(@branchId AS VARCHAR) + ''
  1649. END
  1650. IF @userType = 'AH'
  1651. BEGIN
  1652. SET @branchList = @branchList + '
  1653. UNION ALL
  1654. select agentId from agentMaster with(nolock) where parentId =
  1655. (select parentId from agentmaster with(nolock) where agentId=' + CAST(@branchId AS VARCHAR) + ')
  1656. and agentId <> ' + CAST(@branchId AS VARCHAR) + ''
  1657. END
  1658. SET @branchList = @branchList + '
  1659. ) bl ON trn.sBranch = bl.agentId
  1660. '
  1661. SET @table = '
  1662. SELECT DISTINCT
  1663. trn.id
  1664. ,branch = am.agentName
  1665. ,country = trn.pCountry
  1666. ,senderId = sen.customerId
  1667. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1668. ,receiverId = rec.customerId
  1669. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1670. ,amt = CAST(trn.cAmt AS DECIMAL(18, 3))
  1671. ,voucherNo = trn.voucherNo
  1672. ,trn.createdBy
  1673. ,collMode = ''Cash''
  1674. ,txnDate = CAST(trn.createdDate AS DATE)
  1675. ,txncreatedBy = trn.createdBy
  1676. ,CASE WHEN trn.pAgent = 1100 OR trn.pAgent = 1043 THEN 1 ELSE 0 END isThirdPartyTran
  1677. FROM remitTranTemp trn WITH(NOLOCK)
  1678. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1679. ' + @branchList +
  1680. '
  1681. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1682. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1683. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1684. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1685. trn.payStatus = ''Unpaid'' AND
  1686. trn.approvedBy IS NULL
  1687. '
  1688. IF @txnType IS NOT NULL
  1689. SET @table = @table + ' AND trn.tranType = ''' + @txnType + ''''
  1690. ELSE
  1691. SET @table = @table + ' AND trn.tranType=''I'''
  1692. IF @id IS NOT NULL
  1693. SET @table = @table + ' AND trn.id = ''' + @id + ''''
  1694. IF @branch IS NOT NULL
  1695. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1696. IF @country IS NOT NULL
  1697. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1698. IF @amt IS NOT NULL
  1699. SET @table = @table + ' AND trn.cAmt = ' + CAST(@amt AS VARCHAR(50))
  1700. IF @voucherNo IS NOT NULL
  1701. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1702. IF @txnDate IS NOT NULL
  1703. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1704. IF @isSelfApprove = 'N'
  1705. SET @table = @table + ' AND trn.createdBy <> ''' + @user + ''''
  1706. SET @sql = '
  1707. SELECT
  1708. *
  1709. FROM (
  1710. ' + @table + '
  1711. ) x
  1712. WHERE 1 = 1 '
  1713. IF @txncreatedBy IS NOT NULL
  1714. SET @sql = @sql + ' AND txncreatedBy = ''' + @txncreatedBy + ''''
  1715. IF @sender IS NOT NULL
  1716. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1717. IF @receiver IS NOT NULL
  1718. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1719. --PRINT @sql
  1720. EXEC (@sql)
  1721. RETURN
  1722. END
  1723. IF @flag = 's-agent-self-txn'
  1724. BEGIN
  1725. SET @branchList = '
  1726. INNER JOIN (
  1727. SELECT ' + CAST(@branchId AS VARCHAR) + ' agentId '
  1728. IF @userType = 'RH'
  1729. BEGIN
  1730. SET @branchList = @branchList + '
  1731. UNION ALL
  1732. SELECT
  1733. am.agentId
  1734. FROM agentMaster am WITH(NOLOCK)
  1735. INNER JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  1736. WHERE rba.agentId = ' + CAST(@branchId AS VARCHAR) + '
  1737. AND ISNULL(rba.isDeleted, ''N'') = ''N''
  1738. AND ISNULL(rba.isActive, ''N'') = ''Y'''
  1739. END
  1740. SET @branchList = @branchList + '
  1741. ) bl ON trn.sBranch = bl.agentId
  1742. '
  1743. SET @table = '
  1744. SELECT DISTINCT
  1745. trn.id
  1746. ,branch = am.agentName
  1747. ,country = trn.pCountry
  1748. ,senderId = sen.customerId
  1749. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1750. ,receiverId = rec.customerId
  1751. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1752. ,amt = CAST(trn.cAmt AS DECIMAL(18, 3))
  1753. ,voucherNo = trn.voucherNo
  1754. ,trn.createdBy
  1755. ,collMode = ''''
  1756. ,txnDate = CAST(trn.createdDate AS DATE)
  1757. ,txncreatedBy = trn.createdBy
  1758. FROM remitTranTemp trn WITH(NOLOCK)
  1759. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1760. ' + @branchList +
  1761. '
  1762. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1763. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1764. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1765. --INNER JOIN #collModeList T ON T.tranId = trn.id
  1766. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1767. trn.payStatus = ''Unpaid'' AND
  1768. trn.approvedBy IS NULL
  1769. '
  1770. IF @txnType IS NOT NULL
  1771. SET @table = @table + ' AND trn.tranType = ''' + @txnType + ''''
  1772. ELSE
  1773. SET @table = @table + ' AND trn.tranType=''I'''
  1774. IF @id IS NOT NULL
  1775. SET @table = @table + ' AND trn.id = ''' + @id + ''''
  1776. IF @branch IS NOT NULL
  1777. SET @table = @table + ' AND am.agentId = ''' + @branch + ''''
  1778. IF @country IS NOT NULL
  1779. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1780. IF @amt IS NOT NULL
  1781. SET @table = @table + ' AND trn.cAmt = ' + CAST(@amt AS VARCHAR(50))
  1782. IF @voucherNo IS NOT NULL
  1783. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1784. IF @txnDate IS NOT NULL
  1785. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1786. SET @sqlSelfTxn = '
  1787. SELECT
  1788. *
  1789. FROM (
  1790. ' + @table + ' AND trn.createdBy = ''' + @user + '''
  1791. ) x
  1792. WHERE 1 = 1 '
  1793. IF @sender IS NOT NULL
  1794. SET @sqlSelfTxn = @sqlSelfTxn + ' AND sender LIKE ''' + @sender + '%'''
  1795. IF @receiver IS NOT NULL
  1796. SET @sqlSelfTxn = @sqlSelfTxn + ' AND receiver LIKE ''' + @receiver + '%'''
  1797. EXEC (@sqlSelfTxn)
  1798. RETURN
  1799. END
  1800. IF @flag = 's_txn_summary'
  1801. BEGIN
  1802. SET @branchList = '
  1803. INNER JOIN (
  1804. SELECT ' + CAST(@branchId AS VARCHAR) + ' agentId '
  1805. IF @userType = 'RH'
  1806. BEGIN
  1807. SET @branchList = @branchList + '
  1808. UNION ALL
  1809. SELECT
  1810. am.agentId
  1811. FROM agentMaster am WITH(NOLOCK)
  1812. INNER JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  1813. WHERE rba.agentId = ' + CAST(@branchId AS VARCHAR) + '
  1814. AND ISNULL(rba.isDeleted, ''N'') = ''N''
  1815. AND ISNULL(rba.isActive, ''N'') = ''Y'''
  1816. END
  1817. IF @userType = 'AH'
  1818. BEGIN
  1819. SET @branchList = @branchList + '
  1820. UNION ALL
  1821. select agentId from agentMaster with(nolock) where parentId =
  1822. (select parentId from agentmaster with(nolock) where agentId=' + CAST(@branchId AS VARCHAR) + ')
  1823. and agentId <> ' + CAST(@branchId AS VARCHAR) + ''
  1824. END
  1825. SET @branchList = @branchList + '
  1826. ) bl ON trn.sBranch = bl.agentId
  1827. '
  1828. SET @tablesql = '
  1829. select country,sum(txnCount) txnCount,sum(txnHoldCount) txnHoldCount from
  1830. (
  1831. select country,txnCount,txnHoldCount from
  1832. (
  1833. SELECT
  1834. country = CASE WHEN trn.tranType = ''B'' then pCountry+''(B2B)'' else pCountry end
  1835. ,txnCount = case when trn.createdBy <> ''' + @user + ''' then 1 else 0 end
  1836. ,txnHoldCount = case when trn.createdBy = ''' + @user + ''' then 1 else 0 end
  1837. FROM remitTranTemp trn WITH(NOLOCK)
  1838. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1839. ' + @branchList +
  1840. '
  1841. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1842. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1843. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1844. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1845. trn.payStatus = ''Unpaid'' AND
  1846. trn.approvedBy IS NULL AND trn.tranType IN (''I'',''B'')
  1847. )z
  1848. )x group by country'
  1849. --print(@tablesql)
  1850. EXEC (@tablesql)
  1851. END
  1852. IF @flag = 's_admin_txn_summary'
  1853. BEGIN
  1854. SET @tablesql = '
  1855. SELECT
  1856. sn = row_number() over(order by trn.sCountry)
  1857. ,country = upper(trn.sCountry)
  1858. ,txnCount = count(''x'')
  1859. FROM remitTranTemp trn WITH(NOLOCK)
  1860. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1861. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1862. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1863. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1864. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1865. trn.payStatus = ''Unpaid'' AND
  1866. trn.approvedBy IS NULL AND trn.tranType=''I'' AND
  1867. trn.tranType <> ''O'' AND isOnlineTxn <> ''Y''
  1868. group by trn.sCountry
  1869. '
  1870. EXEC (@tablesql)
  1871. --print @tablesql
  1872. END
  1873. IF @flag = 'OnlineTxn-waitingList'
  1874. BEGIN
  1875. SET @tablesql = '
  1876. SELECT
  1877. sn = row_number() over(order by trn.sCountry)
  1878. ,country = upper(trn.sCountry)
  1879. ,txnCount = count(''x'')
  1880. FROM remitTranTemp trn WITH(NOLOCK)
  1881. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1882. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1883. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1884. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1885. WHERE trn.tranStatus IN (''Hold'',''Compliance Hold'',''OFAC Hold'',''OFAC/Compliance Hold'') AND
  1886. trn.payStatus = ''Unpaid'' AND
  1887. trn.approvedBy IS NULL AND trn.tranType=''O'' AND isOnlineTxn =''Y''
  1888. group by trn.sCountry
  1889. '
  1890. EXEC (@tablesql)
  1891. --print @tablesql
  1892. END
  1893. IF @flag = 'getTxnForApproveByAgent'
  1894. BEGIN
  1895. SET @table = '
  1896. SELECT DISTINCT
  1897. trn.id
  1898. ,controlNo = dbo.fnadecryptstring(controlNo)
  1899. ,branch = am.agentName
  1900. ,country = trn.pCountry
  1901. ,senderId = sen.customerId
  1902. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1903. ,receiverId = rec.customerId
  1904. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1905. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1906. ,trn.paymentMethod
  1907. ,voucherNo = trn.voucherNo
  1908. ,txnDate = CAST(trn.createdDate AS DATE)
  1909. ,txncreatedBy = trn.createdBy
  1910. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1911. '
  1912. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1913. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1914. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1915. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1916. WHERE trn.tranStatus IN (''Hold'') AND
  1917. trn.payStatus = ''Unpaid'' AND
  1918. trn.approvedBy IS NULL AND
  1919. ISNULL(trn.isOnlineTxn,''N'') <>''Y'' AND trn.tranType<>''O''
  1920. AND TRN.COLLMODE = ''CASH COLLECT''
  1921. '
  1922. IF @user IS NOT NULL
  1923. SET @table = @table + ' AND trn.createdBy <> ''' + @user + ''''
  1924. IF @settlingAgentId IS NOT NULL
  1925. SET @table = @table + ' AND trn.sAgent = ''' + CAST(@settlingAgentId AS VARCHAR) + ''''
  1926. IF @id IS NOT NULL
  1927. SET @table = @table + ' AND trn.id = ''' + LTRIM(RTRIM(@id)) + ''''
  1928. IF @country IS NOT NULL
  1929. SET @table = @table + ' AND trn.pCountry LIKE ''' + @country + '%'''
  1930. IF @sendCountry IS NOT NULL
  1931. SET @table = @table + ' AND trn.sCountry LIKE ''' + @sendCountry + '%'''
  1932. IF @amt IS NOT NULL
  1933. SET @table = @table + ' AND trn.pAmt = ' + CAST(@amt AS VARCHAR(20)) + ''
  1934. IF @voucherNo IS NOT NULL
  1935. SET @table = @table + ' AND trn.voucherNo = ''' + @voucherNo + ''''
  1936. IF @txncreatedBy IS NOT NULL
  1937. SET @table = @table + ' AND trn.createdBy = ''' + @txncreatedBy + ''''
  1938. IF @txnDate IS NOT NULL
  1939. SET @table = @table + ' AND CAST(trn.createdDate AS DATE)=''' + @txnDate + ''''
  1940. IF @ControlNo IS NOT NULL
  1941. SET @table = @table + ' AND trn.controlNo = dbo.fnaEncryptString(''' + LTRIM(RTRIM(@ControlNo)) + ''')'
  1942. IF @sendBranch IS NOT NULL
  1943. SET @table = @table + ' AND trn.sBranch = ''' + @sendBranch + ''''
  1944. SET @sql = '
  1945. SELECT
  1946. *
  1947. FROM (
  1948. ' + @table + '
  1949. ) x
  1950. WHERE 1 = 1 '
  1951. IF @sender IS NOT NULL
  1952. SET @sql = @sql + ' AND sender LIKE ''' + @sender + '%'''
  1953. IF @receiver IS NOT NULL
  1954. SET @sql = @sql + ' AND receiver LIKE ''' + @receiver + '%'''
  1955. PRINT @sql
  1956. EXEC (@sql)
  1957. RETURN
  1958. END
  1959. IF @flag = 'getTxnForVerify'
  1960. BEGIN
  1961. SET @table = '
  1962. SELECT DISTINCT
  1963. trn.id
  1964. ,controlNo = dbo.fnadecryptstring(controlNo)
  1965. ,branch = am.agentName
  1966. ,country = trn.pCountry
  1967. ,senderId = sen.customerId
  1968. ,sender = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  1969. ,receiverId = rec.customerId
  1970. ,receiver = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  1971. ,amt = CAST(trn.cAmt AS DECIMAL(18, 2))
  1972. ,trn.paymentMethod
  1973. ,voucherNo = trn.voucherNo
  1974. ,txnDate = CAST(trn.createdDate AS DATE)
  1975. ,txncreatedBy = trn.createdBy
  1976. FROM remitTranTemp trn WITH(NOLOCK) ' + @cdTable +
  1977. '
  1978. LEFT JOIN apiRoutingTable art WITH(NOLOCK) ON trn.pAgent = art.agentId
  1979. INNER JOIN agentMaster am WITH(NOLOCK) ON trn.sBranch = am.agentId
  1980. INNER JOIN tranSendersTemp sen WITH(NOLOCK) ON trn.id = sen.tranId
  1981. INNER JOIN tranReceiversTemp rec WITH(NOLOCK) ON trn.id = rec.tranId
  1982. WHERE trn.tranStatus IN (''Hold'') AND
  1983. trn.payStatus = ''Unpaid'' AND
  1984. trn.approvedBy IS NULL AND ISNULL(sRouteId,''0'') =''1''
  1985. '
  1986. IF @sAgent IS NOT NULL
  1987. BEGIN
  1988. SET @table = @table + ' AND trn.sAgent = ''' + @sendAgent + ''''
  1989. END
  1990. SET @sql = '
  1991. SELECT
  1992. *
  1993. FROM (
  1994. ' + @table + '
  1995. ) x
  1996. WHERE 1 = 1 '
  1997. PRINT @sql
  1998. EXEC (@sql)
  1999. END
  2000. END TRY
  2001. BEGIN CATCH
  2002. --IF @@TRANCOUNT > 0
  2003. -- ROLLBACK TRANSACTION
  2004. SELECT 1 error_code
  2005. ,ERROR_MESSAGE() msg
  2006. ,NULL id
  2007. END CATCH