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.

980 lines
46 KiB

  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_cancelTran] Script Date: 12/18/2023 12:10:38 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_cancelTran] (
  9. @flag VARCHAR(50)
  10. ,@controlNo VARCHAR(20) = NULL
  11. ,@user VARCHAR(30) = NULL
  12. ,@agentRefId VARCHAR(50) = NULL
  13. ,@tranId INT = NULL
  14. ,@sCountry INT = NULL
  15. ,@sFirstName VARCHAR(30) = NULL
  16. ,@sMiddleName VARCHAR(30) = NULL
  17. ,@sLastName1 VARCHAR(30) = NULL
  18. ,@sLastName2 VARCHAR(30) = NULL
  19. ,@sMemId VARCHAR(30) = NULL
  20. ,@sId BIGINT = NULL
  21. ,@sTranId VARCHAR(50) = NULL
  22. ,@rCountry INT = NULL
  23. ,@rFirstName VARCHAR(30) = NULL
  24. ,@rMiddleName VARCHAR(30) = NULL
  25. ,@rLastName1 VARCHAR(30) = NULL
  26. ,@rLastName2 VARCHAR(30) = NULL
  27. ,@rMemId VARCHAR(30) = NULL
  28. ,@rId BIGINT = NULL
  29. ,@pCountry INT = NULL
  30. ,@customerId INT = NULL
  31. ,@agentId INT = NULL
  32. ,@senderId INT = NULL
  33. ,@benId INT = NULL
  34. ,@cancelReason VARCHAR(200) = NULL
  35. ,@refund CHAR(1) = NULL
  36. ,@sortBy VARCHAR(50) = NULL
  37. ,@sortOrder VARCHAR(5) = NULL
  38. ,@pageSize INT = NULL
  39. ,@pageNumber INT = NULL
  40. )
  41. AS
  42. --#298 Trim white space of Control number and TranId
  43. -- #5968 - free service charge - teller quota , @flag = 'cancel'
  44. DECLARE @tranStatus VARCHAR(20) = NULL
  45. ,@payStatus VARCHAR(50) = NULL
  46. ,@tranType CHAR(1) = NULL
  47. DECLARE @select_field_list VARCHAR(MAX)
  48. ,@extra_field_list VARCHAR(MAX)
  49. ,@table VARCHAR(MAX)
  50. ,@sql_filter VARCHAR(MAX)
  51. ,@sAgent INT
  52. ,@tAmt MONEY
  53. ,@pAmt MONEY
  54. ,@message VARCHAR(200)
  55. ------------------------------------------
  56. --#134 -> Allow edit option of address in Town Area
  57. --#11715 Restrict Cancel if Cancel approve date exists
  58. ------------------------------------------
  59. SET NOCOUNT ON
  60. SET XACT_ABORT ON
  61. SELECT @pageSize = 1000
  62. ,@pageNumber = 1
  63. DECLARE @code VARCHAR(50)
  64. ,@userName VARCHAR(50)
  65. ,@password VARCHAR(50)
  66. ,@lockStatus VARCHAR(20)
  67. ,@holdTranId BIGINT
  68. DECLARE @controlNoEncrypted VARCHAR(20)
  69. SELECT @controlNoEncrypted = dbo.FNAEncryptString(UPPER(LTRIM(RTRIM(@controlNo))))
  70. IF @flag = 'cancelRequest-admin'
  71. BEGIN
  72. IF @user IS NULL
  73. BEGIN
  74. EXEC proc_errorHandler 1
  75. ,'Your session has expired. Cannot send cancel request'
  76. ,NULL
  77. RETURN
  78. END
  79. SELECT @tranStatus = tranStatus
  80. ,@payStatus = payStatus
  81. ,@tranId = id
  82. ,@lockStatus = lockStatus
  83. FROM remitTran WITH (NOLOCK)
  84. WHERE controlNo = @controlNoEncrypted
  85. IF (@tranStatus IS NULL)
  86. BEGIN
  87. EXEC proc_errorHandler 1
  88. ,'Transaction not found'
  89. ,@controlNoEncrypted
  90. RETURN
  91. END
  92. IF (@tranStatus = 'Block')
  93. BEGIN
  94. EXEC proc_errorHandler 1
  95. ,'Transaction is blocked. Please Contact HO'
  96. ,@controlNoEncrypted
  97. RETURN
  98. END
  99. IF (@tranStatus = 'Paid')
  100. BEGIN
  101. EXEC proc_errorHandler 1
  102. ,'Transaction has already been paid'
  103. ,@controlNoEncrypted
  104. RETURN
  105. END
  106. IF (@payStatus = 'Paid')
  107. BEGIN
  108. EXEC proc_errorHandler 1
  109. ,'Transaction has already been paid'
  110. ,@controlNoEncrypted
  111. RETURN
  112. END
  113. IF (@tranStatus = 'Cancel' or @payStatus='Cancel')
  114. BEGIN
  115. EXEC proc_errorHandler 1
  116. ,'Transaction has already been cancelled'
  117. ,@controlNoEncrypted
  118. RETURN
  119. END
  120. IF (@tranStatus in('Cancel Request','CancelRequest') or @paystatus in('CancelRequest','Cancel Request'))
  121. BEGIN
  122. EXEC proc_errorHandler 1
  123. ,'Cancel Request has already been sent'
  124. ,@controlNoEncrypted
  125. RETURN
  126. END
  127. BEGIN TRANSACTION
  128. UPDATE remitTran
  129. SET tranStatus = 'CancelRequest' --Transaction Hold
  130. ,trnStatusBeforeCnlReq = tranStatus
  131. ,cancelRequestBy = @user
  132. ,cancelRequestDate = GETDATE()
  133. ,cancelRequestDateLocal = GETDATE()
  134. ,cancelReason = @cancelReason
  135. WHERE controlNo = @controlNoEncrypted
  136. SELECT @message = 'Transaction requested for Cancel. Reason : ''' + @cancelReason + ''''
  137. INSERT INTO tranCancelrequest (
  138. tranId
  139. ,controlNo
  140. ,cancelReason
  141. ,cancelStatus
  142. ,createdBy
  143. ,createdDate
  144. ,tranStatus
  145. )
  146. SELECT @tranId
  147. ,@controlNoEncrypted
  148. ,@cancelReason
  149. ,'CancelRequest'
  150. ,@user
  151. ,GETDATE()
  152. ,@tranStatus
  153. EXEC proc_transactionLogs 'i'
  154. ,@user
  155. ,@tranId
  156. ,@message
  157. ,'Cancel Request'
  158. IF @@TRANCOUNT > 0
  159. COMMIT TRANSACTION
  160. EXEC proc_errorHandler 0
  161. ,'Request for cancel done successfully'
  162. ,@controlNoEncrypted
  163. EXEC proc_addCommentAPI @flag = 'i'
  164. ,@controlNo = @controlNo
  165. ,@user = @user
  166. ,@message = @message
  167. ,@agentRefId = NULL
  168. END
  169. ELSE IF @flag = 'cancelRequest'
  170. BEGIN
  171. IF @user IS NULL
  172. BEGIN
  173. EXEC proc_errorHandler 1
  174. ,'Your session has expired. Cannot send cancel request'
  175. ,NULL
  176. RETURN
  177. END
  178. SELECT @tranStatus = tranStatus
  179. ,@payStatus = payStatus
  180. ,@tranId = id
  181. ,@lockStatus = lockStatus
  182. FROM remitTran WITH (NOLOCK)
  183. WHERE controlNo = @controlNoEncrypted
  184. IF (@tranStatus IS NULL)
  185. BEGIN
  186. EXEC proc_errorHandler 1
  187. ,'Transaction not found'
  188. ,@controlNoEncrypted
  189. RETURN
  190. END
  191. SELECT @agentId = agentId
  192. FROM applicationUsers WITH (NOLOCK)
  193. WHERE userName = @user
  194. IF @agentId <> (
  195. SELECT dbo.FNAGetHOAgentId()
  196. )
  197. BEGIN
  198. IF EXISTS (
  199. SELECT 'X'
  200. FROM remitTran WITH (NOLOCK)
  201. WHERE controlNo = @controlNoEncrypted
  202. AND sBranch <> @agentId
  203. )
  204. BEGIN
  205. EXEC proc_errorHandler 1
  206. ,'Transaction is not in authorized mode'
  207. ,@controlNoEncrypted
  208. RETURN
  209. END
  210. END
  211. IF (@tranStatus = 'Block')
  212. BEGIN
  213. EXEC proc_errorHandler 1
  214. ,'Transaction is blocked. Please Contact HO'
  215. ,@controlNoEncrypted
  216. RETURN
  217. END
  218. IF (@tranStatus = 'Paid')
  219. BEGIN
  220. EXEC proc_errorHandler 1
  221. ,'Transaction has already been paid'
  222. ,@controlNoEncrypted
  223. RETURN
  224. END
  225. IF (@payStatus = 'Paid')
  226. BEGIN
  227. EXEC proc_errorHandler 1
  228. ,'Transaction has already been paid'
  229. ,@controlNoEncrypted
  230. RETURN
  231. END
  232. IF (@tranStatus = 'Cancel' or @payStatus='Cancel')
  233. BEGIN
  234. EXEC proc_errorHandler 1
  235. ,'Transaction has already been cancelled'
  236. ,@controlNoEncrypted
  237. RETURN
  238. END
  239. IF (@tranStatus in('Cancel Request','CancelRequest') or @paystatus in('CancelRequest','Cancel Request'))
  240. BEGIN
  241. EXEC proc_errorHandler 1
  242. ,'Cancel Request has already been sent'
  243. ,@controlNoEncrypted
  244. RETURN
  245. END
  246. BEGIN TRANSACTION
  247. UPDATE remitTran
  248. SET tranStatus = 'CancelRequest' --Transaction Hold
  249. ,trnStatusBeforeCnlReq = tranStatus
  250. ,cancelRequestBy = @user
  251. ,cancelRequestDate = GETDATE()
  252. ,cancelRequestDateLocal = GETDATE()
  253. ,cancelReason = @cancelReason
  254. WHERE controlNo = @controlNoEncrypted
  255. SELECT @message = 'Transaction requested for Cancel. Reason : ''' + @cancelReason + ''''
  256. INSERT INTO tranCancelrequest (
  257. tranId
  258. ,controlNo
  259. ,cancelReason
  260. ,cancelStatus
  261. ,createdBy
  262. ,createdDate
  263. ,tranStatus
  264. )
  265. SELECT @tranId
  266. ,@controlNoEncrypted
  267. ,@cancelReason
  268. ,'CancelRequest'
  269. ,@user
  270. ,GETDATE()
  271. ,@tranStatus
  272. EXEC proc_transactionLogs 'i'
  273. ,@user
  274. ,@tranId
  275. ,@message
  276. ,'Cancel Request'
  277. IF @@TRANCOUNT > 0
  278. COMMIT TRANSACTION
  279. EXEC proc_errorHandler 0
  280. ,'Request for cancel done successfully'
  281. ,@controlNoEncrypted
  282. EXEC proc_addCommentAPI @flag = 'i'
  283. ,@controlNo = @controlNo
  284. ,@user = @user
  285. ,@message = @message
  286. ,@agentRefId = NULL
  287. END
  288. ELSE IF @flag = 'cancel'
  289. BEGIN
  290. -- @refund ='N' TREATED AS NORMAL / FULL RETUND --WHEN RT.Pagent IN( 221226) then (RT.cAmt-rt.serviceCharge)
  291. DECLARE @sBranch INT
  292. ,@pLocation INT
  293. ,@pAgentComm MONEY
  294. ,@cancelCharge MONEY
  295. ,@returnAmt MONEY
  296. ,@idNumber VARCHAR(25)
  297. ,@accountType VARCHAR(20)
  298. ,@cAmt MONEY
  299. ,@userId INT
  300. ,@collMode VARCHAR(20)
  301. DECLARE @referralCode VARCHAR(15)
  302. ,@sType CHAR(1)
  303. ,@isOnbehalf CHAR(1)
  304. ,@date1 DATETIME
  305. ,@date2 DATETIME
  306. ,@createDate DATETIME
  307. ,@deviceType VARCHAR(25)
  308. ,@fcmId NVARCHAR(300)
  309. ,@rewardType NVARCHAR(25)
  310. ,@txncreatedBy NVARCHAR(30)
  311. ,@cancelapprovedDate DATETIME
  312. ,@rewardAmt MONEY
  313. SELECT @tranStatus = RT.tranStatus
  314. ,@paystatus= RT.paystatus
  315. ,@sBranch = RT.sBranch
  316. ,@userId = A.userId
  317. ,@sAgent = RT.sAgent
  318. ,@pLocation = RT.pLocation
  319. ,@tAmt = RT.tAmt
  320. ,@returnAmt = CASE
  321. WHEN ISNULL(@refund, '') = 'D'
  322. OR RT.Pagent IN (221226)
  323. THEN rt.tAmt
  324. ELSE RT.cAmt
  325. END
  326. ,@pAmt = RT.pAmt
  327. ,@tranId = RT.id
  328. ,@customerId = S.customerId
  329. ,@idNumber = S.idNumber
  330. ,@refund = CASE
  331. WHEN RT.Pagent IN (221226)
  332. THEN 'D'
  333. ELSE @refund
  334. END
  335. ,@accountType = rt.SrouteId
  336. ,@cAmt = rt.cAmt
  337. ,@collMode = RT.COLLMODE
  338. ,@createDate = RT.createdDate
  339. ,@referralCode = PROMOTIONCODE
  340. ,@isOnbehalf = (
  341. CASE
  342. WHEN ISONBEHALF = '1'
  343. THEN 'Y'
  344. ELSE 'N'
  345. END
  346. )
  347. ,@controlNo = dbo.decryptdb(rt.controlNo)
  348. ,@tranType = rt.tranType
  349. ,@holdTranId = rt.holdTranId
  350. ,@rewardType = rt.rewardType
  351. ,@txncreatedBy = rt.createdBy
  352. ,@cancelapprovedDate= rt.cancelApprovedDate
  353. ,@rewardAmt = rewardPoints
  354. FROM remitTran RT WITH (NOLOCK)
  355. INNER JOIN tranSenders S WITH (NOLOCK) ON S.tranId = RT.id
  356. LEFT JOIN applicationUsers A(NOLOCK) ON A.USERNAME = RT.CREATEDBY
  357. WHERE controlNo = @controlNoEncrypted
  358. SELECT @fcmId = deviceid
  359. ,@deviceType = DeviceType
  360. FROM mobile_userRegistration(NOLOCK)
  361. WHERE customerid = @customerId
  362. IF @cancelapprovedDate IS NOT NULL
  363. BEGIN
  364. EXEC proc_errorHandler 1
  365. ,'Cancel ApprovedDate already exists. Cannot cancel transaction'
  366. ,NULL
  367. RETURN
  368. END
  369. IF @user IS NULL
  370. BEGIN
  371. EXEC proc_errorHandler 1
  372. ,'Your session has expired. Cannot cancel transaction'
  373. ,NULL
  374. RETURN
  375. END
  376. IF (@tranStatus IS NULL)
  377. BEGIN
  378. EXEC proc_errorHandler 1
  379. ,'Transaction not found'
  380. ,@controlNoEncrypted
  381. RETURN
  382. END
  383. IF (@tranStatus = 'Paid')
  384. BEGIN
  385. EXEC proc_errorHandler 1
  386. ,'Transaction has already been paid'
  387. ,@controlNoEncrypted
  388. RETURN
  389. END
  390. IF (@tranStatus = 'Cancel' or @paystatus='Cancel')
  391. BEGIN
  392. EXEC proc_errorHandler 1
  393. ,'Transaction has already been cancelled'
  394. ,@controlNoEncrypted
  395. RETURN
  396. END
  397. IF (@tranStatus in('Cancel Request','CancelRequest') or @paystatus in('CancelRequest','Cancel Request'))
  398. BEGIN
  399. EXEC proc_errorHandler 1
  400. ,'Transaction is in Cancel Request. Unable to Direct cancel.'
  401. ,@controlNoEncrypted
  402. RETURN
  403. END
  404. IF (@tranStatus = 'Hold')
  405. BEGIN
  406. EXEC proc_errorHandler 1
  407. ,'Transaction is hold. Transaction must be approved for cancellation.'
  408. ,NULL
  409. RETURN
  410. END
  411. SET @cancelCharge = 0
  412. BEGIN TRANSACTION
  413. UPDATE remitTran
  414. SET tranStatus = 'Cancel'
  415. ,cancelApprovedBy = @user
  416. ,cancelApprovedDate = GETDATE()
  417. ,cancelApprovedDateLocal = GETDATE()
  418. ,cancelReason = @cancelReason
  419. ,refund = @refund
  420. WHERE controlNo = @controlNoEncrypted
  421. --SELECT @message = 'Cancel Request Approved'
  422. SELECT @message = @cancelReason
  423. EXEC proc_InsertRewardPoints @Flag = 'CREDIT', @CustomerId = @customerId, @rewardPoints = @rewardAmt, @TranId = @tranId, @type = 'CANCEL'
  424. EXEC proc_transactionLogs 'i'
  425. ,@user
  426. ,@tranId
  427. ,@message
  428. ,'Cancel Approved'
  429. --update balance
  430. --select @sAgent,@userId,@referralCode,@cAmt,@isOnbehalf,@controlNoEncrypted
  431. IF @collMode = 'Cash collect'
  432. BEGIN
  433. EXEC PROC_UPDATE_AVAILABALE_BALANCE @FLAG = 'CANCEL'
  434. ,@S_AGENT = @sAgent
  435. ,@S_USER = @userId
  436. ,@REFERRAL_CODE = @referralCode
  437. ,@C_AMT = @cAmt
  438. ,@ONBEHALF = @isOnbehalf
  439. END
  440. IF @collMode = 'Bank Deposit'
  441. BEGIN
  442. EXEC proc_UpdateCustomerBalance @controlNo = @controlNoEncrypted
  443. END
  444. EXEC PROC_CANCEL_TXN_CASH @TRAN_ID = @tranId
  445. IF @@TRANCOUNT > 0
  446. COMMIT TRANSACTION
  447. DECLARE @ref_num VARCHAR(20)
  448. SELECT TOP 1 @ref_num = t.ref_num
  449. FROM FastMoneyPro_Account.dbo.tran_master t(NOLOCK)
  450. WHERE field1 = @controlNo
  451. AND t.tran_type = 'j'
  452. AND field2 = 'Remittance Voucher'
  453. IF @ref_num IS NOT NULL
  454. BEGIN
  455. SET @cancelReason = ' Cancellation and refund of ' + @controlNo
  456. DECLARE @tempTbl TABLE (
  457. errorcode VARCHAR(5)
  458. ,msg VARCHAR(max)
  459. ,id VARCHAR(50)
  460. )
  461. INSERT INTO @tempTbl (
  462. errorcode
  463. ,msg
  464. ,id
  465. )
  466. EXEC FastMoneyPro_Account.dbo.proc_CancelTranVoucher @flag = 'REVERSE'
  467. ,@refNum = @ref_num
  468. ,@vType = 'J'
  469. ,@refund = 'N'
  470. ,@user = @user
  471. ,@remarks = @cancelReason
  472. END
  473. SET @message = 'Transaction Cancelled ' + isnull(@message, '')
  474. IF @tranType = 'I'
  475. BEGIN
  476. IF EXISTS (
  477. SELECT TOP 1 1
  478. FROM applicationUsers(NOLOCK)
  479. WHERE userName = @txncreatedBy
  480. )
  481. BEGIN
  482. UPDATE APPLICATIONUSERS
  483. SET freeScCounter = CASE
  484. WHEN ISNULL(freeScCounter, 0) > 0
  485. THEN ISNULL(freeScCounter, 0) - 1
  486. ELSE freeScCounter
  487. END
  488. WHERE username = @txncreatedBy
  489. END
  490. END
  491. IF @rewardType = 'FREE_SC'
  492. BEGIN
  493. UPDATE remitDatalog
  494. SET controlNo = NULL
  495. WHERE ControlNo = @ControlNo
  496. END
  497. ELSE
  498. BEGIN
  499. DELETE
  500. FROM remitDatalog
  501. WHERE tranId = @holdTranId
  502. END
  503. EXEC [proc_errorHandler] 0
  504. ,@message
  505. ,@tranId
  506. EXEC PROC_UNTRANSACTED_UPDATE @UPDATE_TYPE = 'CANCEL'
  507. ,@UPDATE_REF_NUM = @controlNo
  508. END
  509. ELSE IF @flag = 'cancelReject'
  510. BEGIN
  511. BEGIN TRANSACTION
  512. UPDATE remitTran
  513. SET tranStatus = 'Payment'
  514. WHERE controlNo = @controlNoEncrypted
  515. SELECT @tranId = id
  516. FROM remitTran WITH (NOLOCK)
  517. WHERE controlNo = @controlNoEncrypted
  518. SELECT @message = 'Cancel Request for this transaction rejected'
  519. EXEC proc_transactionLogs 'i'
  520. ,@user
  521. ,@tranId
  522. ,@message
  523. ,'Cancel Reject'
  524. IF @@TRANCOUNT > 0
  525. COMMIT TRANSACTION
  526. EXEC proc_errorHandler 0
  527. ,'Cancel Request rejected successfully'
  528. ,@controlNoEncrypted
  529. EXEC proc_addCommentAPI @flag = 'i'
  530. ,@controlNo = @controlNo
  531. ,@user = @user
  532. ,@message = @message
  533. ,@agentRefId = NULL
  534. END
  535. ELSE IF @flag = 'detailsAgent'
  536. BEGIN
  537. SELECT @agentId = agentId
  538. FROM applicationUsers WITH (NOLOCK)
  539. WHERE userName = @user
  540. SELECT @tranStatus = tranStatus
  541. ,@payStatus = payStatus
  542. FROM remitTran WITH (NOLOCK)
  543. WHERE controlNo = LTRIM(RTRIM(@controlNoEncrypted))
  544. IF (@tranStatus IS NOT NULL)
  545. BEGIN
  546. INSERT INTO tranViewHistory (
  547. controlNumber
  548. ,tranViewType
  549. ,createdBy
  550. ,createdDate
  551. )
  552. SELECT @controlNoEncrypted
  553. ,'C'
  554. ,@user
  555. ,GETDATE()
  556. END
  557. ELSE
  558. BEGIN
  559. EXEC proc_errorHandler 1000
  560. ,'No Transaction Found'
  561. ,@controlNoEncrypted
  562. RETURN
  563. END
  564. IF NOT EXISTS (
  565. SELECT 'X'
  566. FROM remitTran WITH (NOLOCK)
  567. WHERE controlNo = LTRIM(RTRIM(@controlNoEncrypted))
  568. AND sBranch = @agentId
  569. )
  570. BEGIN
  571. EXEC proc_errorHandler 1
  572. ,'Transaction is not in authorized mode'
  573. ,@controlNoEncrypted
  574. RETURN
  575. END
  576. IF (@tranStatus = 'Paid')
  577. BEGIN
  578. EXEC proc_errorHandler 1
  579. ,'Transaction has already been paid'
  580. ,@controlNoEncrypted
  581. RETURN
  582. END
  583. IF (@payStatus = 'Paid')
  584. BEGIN
  585. EXEC proc_errorHandler 1
  586. ,'Transaction has already been paid'
  587. ,@controlNoEncrypted
  588. RETURN
  589. END
  590. IF (@tranStatus = 'CancelRequest')
  591. BEGIN
  592. EXEC proc_errorHandler 1
  593. ,'Cancel Request has already been sent'
  594. ,@controlNoEncrypted
  595. RETURN
  596. END
  597. IF (@tranStatus = 'Cancel')
  598. BEGIN
  599. EXEC proc_errorHandler 1
  600. ,'Transaction has already been cancelled'
  601. ,@controlNoEncrypted
  602. RETURN
  603. END
  604. IF (@tranStatus = 'Lock')
  605. BEGIN
  606. EXEC proc_errorHandler 1
  607. ,'Transaction is locked. Please contact HO'
  608. ,@controlNoEncrypted
  609. RETURN
  610. END
  611. IF (@tranStatus = 'Block')
  612. BEGIN
  613. EXEC proc_errorHandler 1
  614. ,'Transaction is blocked. Please contact HO'
  615. ,@controlNoEncrypted
  616. RETURN
  617. END
  618. --IF (@payStatus = 'Post')
  619. --BEGIN
  620. -- EXEC proc_errorHandler 1, 'Transaction is Post. Please contact Head Office.', @controlNoEncrypted
  621. -- RETURN
  622. --END
  623. EXEC proc_errorHandler 0
  624. ,'Transaction Found'
  625. ,@controlNoEncrypted
  626. SELECT trn.id
  627. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  628. ,sMemId = sen.membershipId
  629. ,sCustomerId = sen.customerId
  630. ,senderName = sen.firstName + ISNULL(' ' + sen.middleName, '') + ISNULL(' ' + sen.lastName1, '') + ISNULL(' ' + sen.lastName2, '')
  631. ,sCountryName = sen.country
  632. ,sStateName = sen.STATE
  633. ,sDistrict = sen.district
  634. ,sCity = sen.city
  635. ,sAddress = dbo.FNAGetCustomerAddress(trn.id, 'TXN-SEARCH')
  636. ,sContactNo = COALESCE(sen.mobile, sen.homephone, sen.workphone)
  637. ,sIdType = sen.idType
  638. ,sIdNo = sen.idNumber
  639. ,sValidDate = sen.validDate
  640. ,sEmail = sen.email
  641. ,rMemId = rec.membershipId
  642. ,rCustomerId = rec.customerId
  643. ,receiverName = rec.firstName + ISNULL(' ' + rec.middleName, '') + ISNULL(' ' + rec.lastName1, '') + ISNULL(' ' + rec.lastName2, '')
  644. ,rCountryName = rec.country
  645. ,rStateName = rec.STATE
  646. ,rDistrict = rec.district
  647. ,rCity = rec.city
  648. ,rAddress = rec.address
  649. ,rContactNo = COALESCE(rec.mobile, rec.homephone, rec.workphone)
  650. ,rIdType = rec.idType
  651. ,rIdNo = rec.idNumber
  652. ,sBranchName = trn.sBranchName
  653. ,sAgentName = CASE
  654. WHEN trn.sAgent = trn.sBranch
  655. THEN trn.sSuperAgentName
  656. ELSE trn.sAgentName
  657. END
  658. ,sAgentLocation = sLoc.districtName
  659. ,sAgentDistrict = sa.agentDistrict
  660. ,sAgentCity = sa.agentCity
  661. ,sAgentCountry = sa.agentCountry
  662. ,pAgentName = CASE
  663. WHEN trn.pAgentName = trn.pBranchName
  664. THEN trn.pSuperAgentName
  665. ELSE trn.pAgentName
  666. END
  667. ,pBranchName = trn.pBranchName
  668. ,pAgentCountry = trn.pCountry
  669. ,pAgentState = trn.pState
  670. ,pAgentDistrict = trn.pDistrict
  671. ,pAgentLocation = pLoc.districtName
  672. ,pAgentCity = pa.agentCity
  673. ,pAgentAddress = pa.agentAddress
  674. ,trn.tAmt
  675. ,trn.serviceCharge
  676. ,handlingFee = ISNULL(trn.handlingFee, 0)
  677. ,trn.cAmt
  678. ,trn.pAmt
  679. ,relationship = ISNULL(trn.relWithSender, '-')
  680. ,purpose = ISNULL(trn.purposeOfRemit, '-')
  681. ,sourceOfFund = ISNULL(trn.sourceOfFund, '-')
  682. ,collMode = trn.collMode
  683. ,trn.collCurr
  684. ,paymentMethod = trn.paymentMethod
  685. ,trn.payoutCurr
  686. ,trn.tranStatus
  687. ,trn.payStatus
  688. ,payoutMsg = ISNULL(trn.pMessage, '-')
  689. ,trn.createdBy
  690. ,trn.createdDate
  691. ,trn.approvedBy
  692. ,trn.approvedDate
  693. FROM remitTran trn WITH (NOLOCK)
  694. LEFT JOIN tranSenders sen WITH (NOLOCK) ON trn.id = sen.tranId
  695. LEFT JOIN tranReceivers rec WITH (NOLOCK) ON trn.id = rec.tranId
  696. LEFT JOIN agentMaster sa WITH (NOLOCK) ON trn.sBranch = sa.agentId
  697. LEFT JOIN agentMaster pa WITH (NOLOCK) ON trn.pBranch = pa.agentId
  698. LEFT JOIN api_districtList sLoc WITH (NOLOCK) ON sa.agentLocation = sLoc.districtCode
  699. LEFT JOIN api_districtList pLoc WITH (NOLOCK) ON trn.pLocation = pLoc.districtCode
  700. WHERE trn.controlNo = LTRIM(RTRIM(@controlNoEncrypted))
  701. END
  702. ELSE IF @flag = 'cancelReceipt'
  703. BEGIN
  704. DECLARE @AccName NVARCHAR(100)
  705. ,@AccNo VARCHAR(30)
  706. ,@BankName NVARCHAR(100)
  707. SELECT @controlNoEncrypted = DBO.fnaDecryptstring(Controlno)
  708. FROM remitTran(NOLOCK)
  709. WHERE holdtranid = LTRIM(RTRIM(@tranId))
  710. SELECT TOP 1 @tAmt = TRAN_AMT
  711. FROM FastMoneyPro_Account.dbo.TRAN_MASTER(NOLOCK)
  712. WHERE acc_num = '100241027580'
  713. AND field1 = LTRIM(RTRIM(@controlNoEncrypted))
  714. AND field2 = 'Remittance Voucher'
  715. AND acct_type_code = 'Reverse'
  716. SELECT @AccName = accountName
  717. ,@AccNo = accountNum
  718. ,@BankName = bankName
  719. FROM DBO.[FNA_KFTC_CUST_DETAILBY_TXN](@tranId)
  720. SELECT controlNo = dbo.FNADecryptString(controlNo)
  721. ,postedBy = trn.sBranchName
  722. ,createdDate
  723. ,cancelDate = cancelApprovedDate
  724. ,sender = sen.firstName + ISNULL(' ' + sen.middleName, '') + ISNULL(' ' + sen.lastName1, '') + ISNULL(' ' + sen.lastName2, '')
  725. ,receiver = rec.firstName + ISNULL(' ' + rec.middleName, '') + ISNULL(' ' + rec.lastName1, '') + ISNULL(' ' + rec.lastName2, '')
  726. ,rContactNo = rec.mobile
  727. ,trn.collCurr
  728. ,trn.cAmt
  729. ,trn.serviceCharge
  730. ,trn.pAmt
  731. ,trn.cancelCharge
  732. --,returnAmt = trn.cAmt - ISNULL(trn.cancelCharge,0)
  733. ,returnAmt = ISNULL(@tAmt, trn.cAmt)
  734. ,@AccName AccName
  735. ,@AccNo AccNo
  736. ,@BankName BankName
  737. FROM remitTran trn WITH (NOLOCK)
  738. INNER JOIN tranSenders sen WITH (NOLOCK) ON trn.id = sen.tranId
  739. INNER JOIN tranReceivers rec WITH (NOLOCK) ON trn.id = rec.tranId
  740. WHERE trn.holdtranid = @tranId
  741. END
  742. ELSE IF @flag = 's'
  743. BEGIN
  744. SET @table = '(
  745. SELECT
  746. trn.id
  747. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  748. ,sCustomerId = sen.customerId
  749. ,senderName = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  750. ,sCountryName = sen.country
  751. ,sStateName = sen.state
  752. ,sCity = sen.city
  753. ,sAddress = sen.address
  754. ,rCustomerId = rec.customerId
  755. ,receiverName = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  756. ,rCountryName = rec.country
  757. ,rStateName = rec.state
  758. ,rCity = rec.city
  759. ,rAddress = rec.address
  760. FROM remitTran trn WITH(NOLOCK)
  761. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  762. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  763. WHERE trn.tranStatus = ''CancelRequest'' and TranType =''D''
  764. '
  765. SET @sql_filter = ''
  766. IF @controlNo IS NOT NULL
  767. SET @table = @table + ' AND trn.controlNo = ''' + LTRIM(RTRIM(@controlNoEncrypted)) + ''''
  768. IF @sFirstName IS NOT NULL
  769. SET @table = @table + ' AND sen.firstName LIKE ''' + @sFirstName + '%'''
  770. IF @sMiddleName IS NOT NULL
  771. SET @table = @table + ' AND sen.middleName LIKE ''' + @sMiddleName + '%'''
  772. IF @sLastName1 IS NOT NULL
  773. SET @table = @table + ' AND sen.lastName1 LIKE ''' + @sLastName1 + '%'''
  774. IF @sLastName2 IS NOT NULL
  775. SET @table = @table + ' AND sen.lastName2 LIKE ''' + @sLastName2 + '%'''
  776. IF @sMemId IS NOT NULL
  777. SET @table = @table + ' AND sen.membershipId = ' + CAST(@sMemId AS VARCHAR)
  778. IF @rFirstName IS NOT NULL
  779. SET @table = @table + ' AND rec.firstName LIKE ''' + @rFirstName + '%'''
  780. IF @rMiddleName IS NOT NULL
  781. SET @table = @table + ' AND rec.middleName LIKE ''' + @rMiddleName + '%'''
  782. IF @rLastName1 IS NOT NULL
  783. SET @table = @table + ' AND rec.lastName1 LIKE ''' + @rLastName1 + '%'''
  784. IF @rLastName2 IS NOT NULL
  785. SET @table = @table + ' AND rec.lastName2 LIKE ''' + @rLastName2 + '%'''
  786. IF @rMemId IS NOT NULL
  787. SET @table = @table + ' AND c.membershipId = ' + CAST(@rMemId AS VARCHAR)
  788. SET @select_field_list = '
  789. id
  790. ,controlNo
  791. ,sCustomerId
  792. ,senderName
  793. ,sCountryName
  794. ,sStateName
  795. ,sCity
  796. ,sAddress
  797. ,rCustomerId
  798. ,receiverName
  799. ,rCountryName
  800. ,rStateName
  801. ,rCity
  802. ,rAddress
  803. '
  804. SET @table = @table + ') x'
  805. EXEC dbo.proc_paging @table
  806. ,@sql_filter
  807. ,@select_field_list
  808. ,@extra_field_list
  809. ,@sortBy
  810. ,@sortOrder
  811. ,@pageSize
  812. ,@pageNumber
  813. END
  814. ELSE IF @flag = 'checkCancleTxn'
  815. BEGIN
  816. SELECT @tranStatus = tranStatus
  817. ,@tranType = tranType
  818. ,@tranId = id
  819. FROM remitTran WITH (NOLOCK)
  820. WHERE controlNo = LTRIM(RTRIM(@controlNoEncrypted))
  821. IF (@tranStatus IS NULL)
  822. BEGIN
  823. EXEC proc_errorHandler 1
  824. ,'Invalid transaction'
  825. ,@controlNo
  826. RETURN
  827. END
  828. IF (@tranStatus = 'Cancel')
  829. BEGIN
  830. SELECT errorCode = 0
  831. ,msg = 'Success'
  832. ,id = @controlNo
  833. ,extra = @tranType
  834. ,extra2 = @tranId
  835. RETURN
  836. END
  837. ELSE
  838. BEGIN
  839. EXEC proc_errorHandler 1
  840. ,'Invalid transaction'
  841. ,@controlNo
  842. END
  843. END