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.

628 lines
20 KiB

1 year ago
  1. USE FastMoneyPro_Remit
  2. GO
  3. ALTER PROC [dbo].[proc_cancelTran] (
  4. @flag VARCHAR(50)
  5. ,@controlNo VARCHAR(20) = NULL
  6. ,@user VARCHAR(30) = NULL
  7. ,@agentRefId VARCHAR(50) = NULL
  8. ,@tranId INT = NULL
  9. ,@sCountry INT = NULL
  10. ,@sFirstName VARCHAR(30) = NULL
  11. ,@sMiddleName VARCHAR(30) = NULL
  12. ,@sLastName1 VARCHAR(30) = NULL
  13. ,@sLastName2 VARCHAR(30) = NULL
  14. ,@sMemId VARCHAR(30) = NULL
  15. ,@sId BIGINT = NULL
  16. ,@sTranId VARCHAR(50) = NULL
  17. ,@rCountry INT = NULL
  18. ,@rFirstName VARCHAR(30) = NULL
  19. ,@rMiddleName VARCHAR(30) = NULL
  20. ,@rLastName1 VARCHAR(30) = NULL
  21. ,@rLastName2 VARCHAR(30) = NULL
  22. ,@rMemId VARCHAR(30) = NULL
  23. ,@rId BIGINT = NULL
  24. ,@pCountry INT = NULL
  25. ,@customerId INT = NULL
  26. ,@agentId INT = NULL
  27. ,@senderId INT = NULL
  28. ,@benId INT = NULL
  29. ,@cancelReason VARCHAR(200) = NULL
  30. ,@refund CHAR(1) = NULL
  31. ,@sortBy VARCHAR(50) = NULL
  32. ,@sortOrder VARCHAR(5) = NULL
  33. ,@pageSize INT = NULL
  34. ,@pageNumber INT = NULL
  35. )
  36. AS
  37. DECLARE
  38. @tranStatus VARCHAR(20) = NULL,
  39. @payStatus VARCHAR(50) = NULL,
  40. @tranType CHAR(1) = NULL
  41. DECLARE
  42. @select_field_list VARCHAR(MAX)
  43. ,@extra_field_list VARCHAR(MAX)
  44. ,@table VARCHAR(MAX)
  45. ,@sql_filter VARCHAR(MAX)
  46. ,@sAgent INT
  47. ,@tAmt BIGINT
  48. ,@pAmt MONEY
  49. ,@message VARCHAR(200)
  50. SET NOCOUNT ON
  51. SET XACT_ABORT ON
  52. SELECT @pageSize = 1000, @pageNumber = 1
  53. DECLARE
  54. @code VARCHAR(50)
  55. ,@userName VARCHAR(50)
  56. ,@password VARCHAR(50)
  57. ,@lockStatus VARCHAR(20)
  58. DECLARE @controlNoEncrypted VARCHAR(20)
  59. SELECT @controlNoEncrypted = dbo.FNAEncryptString(UPPER(LTRIM(RTRIM(@controlNo))))
  60. IF @flag = 'cancelRequest'
  61. BEGIN
  62. IF @user IS NULL
  63. BEGIN
  64. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send cancel request', NULL
  65. RETURN
  66. END
  67. SELECT
  68. @tranStatus = tranStatus,
  69. @payStatus = payStatus,
  70. @tranId = id,
  71. @lockStatus = lockStatus
  72. FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  73. IF (@tranStatus IS NULL)
  74. BEGIN
  75. EXEC proc_errorHandler 1, 'Transaction not found', @controlNoEncrypted
  76. RETURN
  77. END
  78. SELECT @agentId = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  79. IF @agentId <> (SELECT dbo.FNAGetHOAgentId())
  80. BEGIN
  81. IF EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK)
  82. WHERE controlNo = @controlNoEncrypted AND sBranch <> @agentId)
  83. BEGIN
  84. EXEC proc_errorHandler 1, 'Transaction is not in authorized mode', @controlNoEncrypted
  85. RETURN
  86. END
  87. END
  88. IF (@tranStatus = 'Block')
  89. BEGIN
  90. EXEC proc_errorHandler 1, 'Transaction is blocked. Please Contact HO', @controlNoEncrypted
  91. RETURN
  92. END
  93. IF (@tranStatus = 'Paid')
  94. BEGIN
  95. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  96. RETURN
  97. END
  98. IF (@payStatus = 'Paid')
  99. BEGIN
  100. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  101. RETURN
  102. END
  103. IF (@tranStatus = 'Cancel')
  104. BEGIN
  105. EXEC proc_errorHandler 1, 'Transaction already been cancelled', @controlNoEncrypted
  106. RETURN
  107. END
  108. IF (@tranStatus = 'CancelRequest')
  109. BEGIN
  110. EXEC proc_errorHandler 1, 'Cancel Request has already been sent', @controlNoEncrypted
  111. RETURN
  112. END
  113. BEGIN TRANSACTION
  114. UPDATE remitTran SET
  115. tranStatus = 'CancelRequest' --Transaction Hold
  116. ,cancelRequestBy = @user
  117. ,cancelRequestDate = dbo.FNAGetDateInNepalTZ()
  118. ,cancelRequestDateLocal = dbo.FNAGetDateInNepalTZ()
  119. ,cancelReason = @cancelReason
  120. WHERE controlNo = @controlNoEncrypted
  121. SELECT @message = 'Transaction requested for Cancel. Reason : ''' + @cancelReason + ''''
  122. INSERT INTO tranCancelrequest(tranId,controlNo,cancelReason,cancelStatus,createdBy,createdDate,tranStatus)
  123. SELECT @tranId,@controlNoEncrypted,@cancelReason,'CancelRequest',@user,GETDATE(),@tranStatus
  124. EXEC proc_transactionLogs 'i', @user, @tranId, @message, 'Cancel Request'
  125. IF @@TRANCOUNT > 0
  126. COMMIT TRANSACTION
  127. EXEC proc_errorHandler 0, 'Request for cancel done successfully', @controlNoEncrypted
  128. EXEC proc_addCommentAPI @flag = 'i', @controlNo = @controlNo, @user = @user, @message = @message, @agentRefId = NULL
  129. END
  130. ELSE IF @flag = 'cancel'
  131. BEGIN
  132. DECLARE @TEMPTBL TABLE (ERRORCODE VARCHAR(5), MSG VARCHAR(MAX), ID VARCHAR(50))
  133. -- @refund ='N' TREATED AS NORMAL / FULL RETUND --WHEN RT.Pagent IN( 221226) then (RT.cAmt-rt.serviceCharge)
  134. DECLARE @sBranch INT, @pLocation INT, @pAgentComm MONEY, @cancelCharge MONEY, @returnAmt MONEY
  135. , @idNumber VARCHAR(25),@accountType VARCHAR(20),@txnDate DATETIME, @schemeId VARCHAR(10), @holdTranId BIGINT, @schemePremium FLOAT, @email VARCHAR(100)
  136. , @pAgent BIGINT
  137. SELECT
  138. @tranStatus = RT.tranStatus
  139. ,@sBranch = RT.sBranch
  140. ,@sAgent = RT.sAgent
  141. ,@pLocation = RT.pLocation
  142. ,@tAmt = RT.tAmt
  143. ,@returnAmt = (CASE WHEN ISNULL(@refund,'')='D' OR RT.Pagent IN( 221226,404522) then rt.tAmt else RT.cAmt end) - ISNULL(rt.schemePremium,0)
  144. ,@pAmt = RT.pAmt
  145. ,@tranId = RT.id
  146. ,@customerId = S.customerId
  147. ,@idNumber = S.idNumber
  148. ,@refund = case when RT.Pagent IN( 221226,404522) then 'D' else @refund end
  149. ,@accountType = rt.SrouteId
  150. ,@txnDate = rt.ApprovedDate
  151. ,@schemeId = RT.schemeId
  152. ,@holdTranId = RT.holdTranId
  153. ,@schemePremium = RT.schemePremium
  154. ,@email = S.email
  155. ,@pAgent = RT.pAgent
  156. FROM remitTran RT WITH(NOLOCK)
  157. INNER JOIN tranSenders S WITH(NOLOCK) ON S.tranId = RT.id
  158. WHERE controlNo = @controlNoEncrypted
  159. IF @user IS NULL
  160. BEGIN
  161. EXEC proc_errorHandler 1, 'Your session has expired. Cannot cancel transaction', NULL
  162. RETURN
  163. END
  164. IF (@tranStatus IS NULL)
  165. BEGIN
  166. EXEC proc_errorHandler 1, 'Transaction not found', @controlNoEncrypted
  167. RETURN
  168. END
  169. IF (@tranStatus = 'Paid')
  170. BEGIN
  171. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  172. RETURN
  173. END
  174. IF (@tranStatus = 'Cancel')
  175. BEGIN
  176. EXEC proc_errorHandler 1, 'Transaction already been cancelled', @controlNoEncrypted
  177. RETURN
  178. END
  179. IF (@tranStatus = 'Hold' AND @pAgent NOT IN(590815,590852,393228,601361,601392)) ----EXCLUDE NI BANK
  180. BEGIN
  181. EXEC proc_errorHandler 1, 'Transaction is hold. Transaction must be approved for cancellation.', NULL
  182. RETURN
  183. END
  184. SET @cancelCharge = 0
  185. BEGIN TRANSACTION
  186. UPDATE remitTran SET
  187. tranStatus = 'Cancel'
  188. ,cancelApprovedBy = @user
  189. ,cancelApprovedDate = GETDATE()
  190. ,cancelApprovedDateLocal = GETDATE()
  191. ,cancelReason = @cancelReason
  192. ,refund = @refund
  193. WHERE controlNo = @controlNoEncrypted
  194. IF @@TRANCOUNT > 0
  195. COMMIT TRANSACTION
  196. --SELECT @message = 'Cancel Request Approved'
  197. SELECT @message = @cancelReason
  198. EXEC proc_transactionLogs 'i', @user, @tranId, @message, 'Cancel Approved'
  199. DECLARE @SMSBody VARCHAR(90) = 'Your GME transaction '+@controlNo+' was cancelled. Balance returned to your GME wallet.'
  200. --IF @accountType = 'A' ----##AUTO DEBIT TRANSACTION
  201. -- SET @SMSBody = 'Your GME transaction '+@controlNo+' was cancelled.Balance refunded to your account.'
  202. DECLARE @Mobile VARCHAR(20)
  203. ----## SMS TO IDENTIFY EVERY CUSTOMRE
  204. SELECT @Mobile = mobile
  205. FROM FastMoneyPro_Remit.dbo.customerMaster (nolock)
  206. WHERE customerId = @customerId
  207. EXEC FastMoneyPro_Remit.dbo.proc_CallToSendSMS @FLAG = 'I',@SMSBody = @SMSBody,@MobileNo = @Mobile
  208. DECLARE @ref_num VARCHAR(20),@tran_type CHAR(1) = 'T'
  209. SET @tran_type = CASE WHEN YEAR(@txnDate) = 2018 THEN 'J' ELSE @tran_type END
  210. SELECT TOP 1 @ref_num = t.ref_num FROM FastMoneyPro_Account.dbo.VW_PostedAccountDetail t(nolock)
  211. WHERE field1 = @controlNo AND t.tran_type = @tran_type AND field2='remittance voucher' AND acct_type_code IS NULL
  212. IF @ref_num IS NULL
  213. BEGIN
  214. --## generate voucher entry
  215. INSERT INTO @tempTbl(errorcode, msg, id)
  216. EXEC FastMoneyPro_Account.dbo.proc_transactionVoucherEntry @controlNo= @controlNo
  217. SELECT TOP 1 @ref_num = t.ref_num FROM FastMoneyPro_Account.dbo.VW_PostedAccountDetail t(nolock)
  218. WHERE field1 = @controlNo AND t.tran_type = @tran_type AND field2='remittance voucher' AND acct_type_code IS NULL
  219. END
  220. IF @ref_num is NOT null
  221. BEGIN
  222. IF @accountType = 'A' AND @txnDate < '2019-11-06'
  223. SET @cancelReason =' old Cancellation and refund of '+@controlNo
  224. ELSE
  225. SET @cancelReason =' Cancellation and refund of '+@controlNo
  226. IF @refund = 'N'
  227. BEGIN
  228. INSERT INTO @tempTbl(errorcode, msg, id)
  229. EXEC FastMoneyPro_Account.dbo.proc_CancelTranVoucher @flag = 'TxnWithoutCharge',@refNum = @ref_num,@vType = @tran_type,@user = @user,@remarks = @cancelReason
  230. END
  231. ELSE
  232. BEGIN
  233. ----EXEC FastMoneyPro_Account.dbo.proc_EditVoucher @flag='REVERSE',@refNum =@ref_num,@vType = @tran_type,@User = @user,@remarks = @cancelReason
  234. INSERT INTO @tempTbl(errorcode, msg, id)
  235. EXEC FastMoneyPro_Account.dbo.proc_CancelTranVoucher @flag = 'TxnWithCharge',@refNum = @ref_num,@vType = @tran_type,@user = @user,@remarks = @cancelReason
  236. END
  237. SET @message = ' And voucher reversed successfully'
  238. IF @accountType = 'W' ----##AUTOWALLET TRANSACTION
  239. BEGIN
  240. IF EXISTS(SELECT 'A' FROM customerMaster(NOLOCK) WHERE customerId = @customerId AND approvedDate IS NOT NULL)
  241. BEGIN
  242. UPDATE customermaster SET availableBalance = availableBalance + isnull(@returnAmt,0)
  243. WHERE customerId = @customerId
  244. END
  245. END
  246. ELSE IF @accountType = 'A' AND @txnDate>'2019-11-06'
  247. BEGIN
  248. IF EXISTS(SELECT 'A' FROM customerMaster(NOLOCK) WHERE customerId = @customerId AND approvedDate IS NOT NULL)
  249. BEGIN
  250. UPDATE customermaster SET availableBalance = availableBalance + isnull(@returnAmt,0)
  251. WHERE customerId = @customerId
  252. END
  253. END
  254. END
  255. SET @message = 'Transaction Cancelled '+isnull(@message,'')
  256. /*Reward entry for send txn*/
  257. EXEC PROC_PointMasterDetails @flag='cancel',@customerId=@customerId,@tranId=@tranId
  258. -------START cancel coupon
  259. IF EXISTS(SELECT '1' FROM CouponIssue(NOLOCK) WHERE rowId = @schemeId)
  260. BEGIN
  261. DECLARE @LimitCount int, @CurrentCount int
  262. SELECT @LimitCount = CS.usageLimit,
  263. @CurrentCount = CI.usedCount
  264. FROM CouponIssue(NOLOCK) AS CI
  265. INNER JOIN CouponSetup(NOLOCK) AS CS
  266. ON CI.couponId = CS.rowId
  267. AND CI.rowId = @schemeId
  268. UPDATE CouponIssue SET
  269. usedCount = @CurrentCount - 1,
  270. isActive = 'Y'
  271. WHERE rowId = @schemeId
  272. -------Start insert Coupon History
  273. INSERT INTO CouponHistory (couponIssueId,customerId,actualDiscountValue,usedCount,holdTranId,couponStatus,createdBy,createdDate)
  274. VALUES (@schemeId,@customerId,@schemePremium,@CurrentCount - 1,@holdTranId,'9',@email, GETDATE())
  275. -------End insert Coupon History
  276. END
  277. -------END cancel coupon
  278. EXEC [proc_errorHandler] 0, @message, @tranId
  279. END
  280. ELSE IF @flag = 'cancelReject'
  281. BEGIN
  282. BEGIN TRANSACTION
  283. UPDATE remitTran SET
  284. tranStatus = 'Payment'
  285. WHERE controlNo = @controlNoEncrypted
  286. SELECT @tranId = id FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  287. SELECT @message = 'Cancel Request for this transaction rejected'
  288. EXEC proc_transactionLogs 'i', @user, @tranId, @message, 'Cancel Reject'
  289. IF @@TRANCOUNT > 0
  290. COMMIT TRANSACTION
  291. EXEC proc_errorHandler 0, 'Cancel Request rejected successfully', @controlNoEncrypted
  292. EXEC proc_addCommentAPI @flag = 'i', @controlNo = @controlNo, @user = @user, @message = @message, @agentRefId = NULL
  293. END
  294. ELSE IF @flag = 'detailsAgent'
  295. BEGIN
  296. --SELECT @agentId = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  297. SELECT
  298. @tranStatus = tranStatus,
  299. @payStatus = payStatus
  300. FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  301. IF (@tranStatus IS NOT NULL)
  302. BEGIN
  303. INSERT INTO tranViewHistory(
  304. controlNumber
  305. ,tranViewType
  306. ,createdBy
  307. ,createdDate
  308. )
  309. SELECT
  310. @controlNoEncrypted
  311. ,'C'
  312. ,@user
  313. ,GETDATE()
  314. END
  315. ELSE
  316. BEGIN
  317. EXEC proc_errorHandler 1000, 'No Transaction Found', @controlNoEncrypted
  318. RETURN
  319. END
  320. --IF NOT EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND pBranch = @agentId)
  321. --BEGIN
  322. -- EXEC proc_errorHandler 1, 'Transaction is not in authorized mode', @controlNoEncrypted
  323. -- RETURN
  324. --END
  325. IF (@tranStatus = 'Paid')
  326. BEGIN
  327. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  328. RETURN
  329. END
  330. IF (@payStatus = 'Paid')
  331. BEGIN
  332. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  333. RETURN
  334. END
  335. IF (@tranStatus = 'CancelRequest')
  336. BEGIN
  337. EXEC proc_errorHandler 1, 'Cancel Request has already been sent', @controlNoEncrypted
  338. RETURN
  339. END
  340. IF (@tranStatus = 'Cancel')
  341. BEGIN
  342. EXEC proc_errorHandler 1, 'Transaction already been cancelled', @controlNoEncrypted
  343. RETURN
  344. END
  345. IF (@tranStatus = 'Lock')
  346. BEGIN
  347. EXEC proc_errorHandler 1, 'Transaction is locked. Please contact HO', @controlNoEncrypted
  348. RETURN
  349. END
  350. IF (@tranStatus = 'Block')
  351. BEGIN
  352. EXEC proc_errorHandler 1, 'Transaction is blocked. Please contact HO', @controlNoEncrypted
  353. RETURN
  354. END
  355. --IF (@payStatus = 'Post')
  356. --BEGIN
  357. -- EXEC proc_errorHandler 1, 'Transaction is Post. Please contact Head Office.', @controlNoEncrypted
  358. -- RETURN
  359. --END
  360. EXEC proc_errorHandler 0, 'Transaction Found', @controlNoEncrypted
  361. SELECT
  362. trn.id
  363. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  364. ,sMemId = sen.membershipId
  365. ,sCustomerId = sen.customerId
  366. ,senderName = sen.firstName + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, '')
  367. ,sCountryName = sen.country
  368. ,sStateName = sen.state
  369. ,sDistrict = sen.district
  370. ,sCity = sen.city
  371. ,sAddress = sen.address
  372. ,sContactNo = COALESCE(sen.mobile, sen.homephone, sen.workphone)
  373. ,sIdType = sen.idType
  374. ,sIdNo = sen.idNumber
  375. ,sValidDate = sen.validDate
  376. ,sEmail = sen.email
  377. ,rMemId = rec.membershipId
  378. ,rCustomerId = rec.customerId
  379. ,receiverName = rec.firstName + ISNULL( ' ' + rec.middleName, '') + ISNULL( ' ' + rec.lastName1, '') + ISNULL( ' ' + rec.lastName2, '')
  380. ,rCountryName = rec.country
  381. ,rStateName = rec.state
  382. ,rDistrict = rec.district
  383. ,rCity = rec.city
  384. ,rAddress = rec.address
  385. ,rContactNo = COALESCE(rec.mobile, rec.homephone, rec.workphone)
  386. ,rIdType = rec.idType
  387. ,rIdNo = rec.idNumber
  388. ,sBranchName = trn.sBranchName
  389. ,sAgentName = CASE WHEN trn.sAgent = trn.sBranch THEN trn.sSuperAgentName ELSE trn.sAgentName END
  390. ,sAgentLocation = sLoc.districtName
  391. ,sAgentDistrict = sa.agentDistrict
  392. ,sAgentCity = sa.agentCity
  393. ,sAgentCountry = sa.agentCountry
  394. ,pAgentName = CASE WHEN trn.pAgentName = trn.pBranchName THEN trn.pSuperAgentName ELSE trn.pAgentName END
  395. ,pBranchName = trn.pBranchName
  396. ,pAgentCountry = trn.pCountry
  397. ,pAgentState = trn.pState
  398. ,pAgentDistrict = trn.pDistrict
  399. ,pAgentLocation = pLoc.districtName
  400. ,pAgentCity = pa.agentCity
  401. ,pAgentAddress = pa.agentAddress
  402. ,trn.tAmt
  403. ,trn.serviceCharge
  404. ,handlingFee = ISNULL(trn.handlingFee, 0)
  405. ,trn.cAmt
  406. ,trn.pAmt
  407. ,relationship = ISNULL(trn.relWithSender, '-')
  408. ,purpose = ISNULL(trn.purposeOfRemit, '-')
  409. ,sourceOfFund = ISNULL(trn.sourceOfFund, '-')
  410. ,collMode = trn.collMode
  411. ,trn.collCurr
  412. ,paymentMethod = trn.paymentMethod
  413. ,trn.payoutCurr
  414. ,trn.tranStatus
  415. ,trn.payStatus
  416. ,payoutMsg = ISNULL(trn.pMessage, '-')
  417. ,trn.createdBy
  418. ,trn.createdDate
  419. ,trn.approvedBy
  420. ,trn.approvedDate
  421. FROM remitTran trn WITH(NOLOCK)
  422. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  423. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  424. LEFT JOIN agentMaster sa WITH(NOLOCK) ON trn.sBranch = sa.agentId
  425. LEFT JOIN agentMaster pa WITH(NOLOCK) ON trn.pBranch = pa.agentId
  426. LEFT JOIN api_districtList sLoc WITH(NOLOCK) ON sa.agentLocation = sLoc.districtCode
  427. LEFT JOIN api_districtList pLoc WITH(NOLOCK) ON trn.pLocation = pLoc.districtCode
  428. WHERE trn.controlNo = @controlNoEncrypted
  429. END
  430. ELSE IF @flag = 'cancelReceipt'
  431. BEGIN
  432. DECLARE @AccName NVARCHAR(100),@AccNo VARCHAR(30),@BankName NVARCHAR(100),@bankCode VARCHAR(5),@srouteId CHAR(1)
  433. SELECT @controlNoEncrypted = DBO.fnaDecryptstring(Controlno),@tranStatus= tranStatus,@srouteId = sRouteId FROM remitTran(NOLOCK) WHERE ID = @tranId
  434. IF @tranStatus <>'CANCEL'
  435. BEGIN
  436. SELECT '1' AS ERRORCODE,'Transaction status changed to '+@tranStatus MSG,@controlNoEncrypted as controlNo
  437. RETURN
  438. END
  439. SELECT
  440. controlNo = dbo.FNADecryptString(controlNo)
  441. ,'0' AS ERRORCODE
  442. ,postedBy = trn.sBranchName
  443. ,createdDate
  444. ,cancelDate = cancelApprovedDate
  445. ,sender = sen.firstName + ISNULL(' ' + sen.middleName, '') + ISNULL(' ' + sen.lastName1, '') + ISNULL(' ' + sen.lastName2, '')
  446. ,receiver = rec.firstName + ISNULL(' ' + rec.middleName, '') + ISNULL(' ' + rec.lastName1, '') + ISNULL(' ' + rec.lastName2, '')
  447. ,rContactNo = rec.mobile
  448. ,trn.collCurr
  449. ,trn.cAmt
  450. ,trn.serviceCharge
  451. ,trn.pAmt
  452. ,trn.cancelCharge
  453. ,returnAmt = CASE WHEN refund = 'D' THEN tAmt ELSE cAmt END
  454. FROM remitTran trn WITH(NOLOCK)
  455. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  456. INNER JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  457. WHERE trn.id = @tranId
  458. END
  459. ELSE IF @flag = 's'
  460. BEGIN
  461. SET @table = '(
  462. SELECT
  463. trn.id
  464. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  465. ,sCustomerId = sen.customerId
  466. ,senderName = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  467. ,sCountryName = sen.country
  468. ,sStateName = sen.state
  469. ,sCity = sen.city
  470. ,sAddress = sen.address
  471. ,rCustomerId = rec.customerId
  472. ,receiverName = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  473. ,rCountryName = rec.country
  474. ,rStateName = rec.state
  475. ,rCity = rec.city
  476. ,rAddress = rec.address
  477. FROM remitTran trn WITH(NOLOCK)
  478. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  479. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  480. WHERE trn.tranStatus = ''CancelRequest'' and TranType =''D''
  481. '
  482. SET @sql_filter = ''
  483. IF @controlNo IS NOT NULL
  484. SET @table = @table + ' AND trn.controlNo = ''' + @controlNoEncrypted + ''''
  485. IF @sFirstName IS NOT NULL
  486. SET @table = @table + ' AND sen.firstName LIKE ''' + @sFirstName + '%'''
  487. IF @sMiddleName IS NOT NULL
  488. SET @table = @table + ' AND sen.middleName LIKE ''' + @sMiddleName + '%'''
  489. IF @sLastName1 IS NOT NULL
  490. SET @table = @table + ' AND sen.lastName1 LIKE ''' + @sLastName1 + '%'''
  491. IF @sLastName2 IS NOT NULL
  492. SET @table = @table + ' AND sen.lastName2 LIKE ''' + @sLastName2 + '%'''
  493. IF @sMemId IS NOT NULL
  494. SET @table = @table + ' AND sen.membershipId = ' + CAST(@sMemId AS VARCHAR)
  495. IF @rFirstName IS NOT NULL
  496. SET @table = @table + ' AND rec.firstName LIKE ''' + @rFirstName + '%'''
  497. IF @rMiddleName IS NOT NULL
  498. SET @table = @table + ' AND rec.middleName LIKE ''' + @rMiddleName + '%'''
  499. IF @rLastName1 IS NOT NULL
  500. SET @table = @table + ' AND rec.lastName1 LIKE ''' + @rLastName1 + '%'''
  501. IF @rLastName2 IS NOT NULL
  502. SET @table = @table + ' AND rec.lastName2 LIKE ''' + @rLastName2 + '%'''
  503. IF @rMemId IS NOT NULL
  504. SET @table = @table + ' AND c.membershipId = ' + CAST(@rMemId AS VARCHAR)
  505. SET @select_field_list ='
  506. id
  507. ,controlNo
  508. ,sCustomerId
  509. ,senderName
  510. ,sCountryName
  511. ,sStateName
  512. ,sCity
  513. ,sAddress
  514. ,rCustomerId
  515. ,receiverName
  516. ,rCountryName
  517. ,rStateName
  518. ,rCity
  519. ,rAddress
  520. '
  521. SET @table = @table + ') x'
  522. EXEC dbo.proc_paging
  523. @table
  524. ,@sql_filter
  525. ,@select_field_list
  526. ,@extra_field_list
  527. ,@sortBy
  528. ,@sortOrder
  529. ,@pageSize
  530. ,@pageNumber
  531. END
  532. ELSE IF @flag = 'checkCancleTxn'
  533. BEGIN
  534. SELECT
  535. @tranStatus = tranStatus,
  536. @tranType = tranType,
  537. @tranId = id
  538. FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  539. IF (@tranStatus IS NULL)
  540. BEGIN
  541. EXEC proc_errorHandler 1, 'Invalid transaction', @controlNo
  542. RETURN
  543. END
  544. IF (@tranStatus = 'Cancel')
  545. BEGIN
  546. SELECT errorCode = 0, msg = 'Success', id = @controlNo, extra = @tranType, extra2 = @tranId
  547. RETURN
  548. END
  549. ELSE
  550. BEGIN
  551. EXEC proc_errorHandler 1, 'Invalid transaction', @controlNo
  552. END
  553. END