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.

1012 lines
74 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_cancelTranRsp] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE proc [dbo].[proc_cancelTranRsp] (
  9. @flag VARCHAR(50)
  10. ,@controlNo VARCHAR(20) = NULL
  11. ,@user VARCHAR(100) = NULL
  12. ,@agentId INT = NULL
  13. ,@cancelReason VARCHAR(200) = NULL
  14. ,@scRefund VARCHAR(50) = NULL
  15. ,@tranId INT = NULL
  16. ,@Branch VARCHAR(200) = NULL
  17. ,@branchId INT = NULL
  18. ,@createdBy VARCHAR(100) = NULL
  19. ,@sortBy VARCHAR(50) = NULL
  20. ,@sortOrder VARCHAR(5) = NULL
  21. ,@pageSize INT = NULL
  22. ,@pageNumber INT = NULL
  23. )
  24. AS
  25. SET NOCOUNT ON
  26. SET XACT_ABORT ON
  27. DECLARE
  28. @select_field_list VARCHAR(MAX)
  29. ,@extra_field_list VARCHAR(MAX)
  30. ,@table VARCHAR(MAX)
  31. ,@sql_filter VARCHAR(MAX)
  32. SELECT @pageSize = 1000, @pageNumber = 1
  33. DECLARE
  34. @controlNoEncrypted VARCHAR(50)
  35. ,@tranStatus VARCHAR(50)
  36. ,@message VARCHAR(MAX)
  37. ,@serviceCharge MONEY
  38. ,@cAmt MONEY
  39. ,@tAmt MONEY
  40. ,@userType VARCHAR(2)
  41. ,@txnSentBy VARCHAR(50)
  42. ,@tranIdType VARCHAR(1)
  43. ,@cancelReason1 VARCHAR(500)
  44. ,@tellerBalance AS MONEY
  45. ,@DT1 DATETIME
  46. ,@irhRefund MONEY
  47. DECLARE @TransStatusNep VARCHAR(20), @TransPayStatusNep VARCHAR(20),@msg VARCHAR(200)
  48. DECLARE @moneySendTranStatus VARCHAR(50), @moneySendPayStatus VARCHAR(50), @remitTranStatus VARCHAR(50)
  49. SELECT @controlNoEncrypted = dbo.FNAEncryptString(UPPER(LTRIM(RTRIM(@controlNo))))
  50. DECLARE @DT DATETIME = GETDATE()
  51. IF @flag = 'searchAgent'
  52. BEGIN
  53. IF @user IS NULL
  54. BEGIN
  55. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send cancel request.', NULL
  56. RETURN
  57. END
  58. SELECT @agentId = agentId,@userType=userType
  59. FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  60. IF @tranId IS NOT NULL
  61. BEGIN
  62. IF LEN(@tranId) = 8
  63. SELECT
  64. @tranStatus = tranStatus
  65. ,@tranId = id
  66. ,@txnSentBy = createdBy
  67. ,@controlNoEncrypted = controlNo
  68. FROM vwRemitTran WITH(NOLOCK) WHERE ISNULL(CAST(holdTranId AS VARCHAR(50)),CAST(id AS VARCHAR(50))) = CAST(@tranId AS VARCHAR(50))
  69. ELSE
  70. SELECT
  71. @tranStatus = tranStatus
  72. ,@tranId = id
  73. ,@txnSentBy = createdBy
  74. ,@controlNoEncrypted = controlNo
  75. FROM vwRemitTran WITH(NOLOCK) WHERE CAST(id AS VARCHAR(50)) = CAST(@tranId AS VARCHAR(50))
  76. END
  77. IF @controlNo IS NOT NULL
  78. BEGIN
  79. SELECT
  80. @tranStatus = tranStatus
  81. ,@tranId = id
  82. ,@txnSentBy = createdBy
  83. ,@controlNoEncrypted = controlNo
  84. FROM vwRemitTran WITH(NOLOCK) WHERE controlNo =@controlNoEncrypted
  85. END
  86. IF (@tranStatus IS NOT NULL)
  87. BEGIN
  88. INSERT INTO tranViewHistory(
  89. controlNumber
  90. ,tranViewType
  91. ,createdBy
  92. ,createdDate
  93. )
  94. SELECT
  95. @controlNoEncrypted
  96. ,'C'
  97. ,@user
  98. ,GETDATE()
  99. END
  100. ELSE
  101. BEGIN
  102. EXEC proc_errorHandler 1000, 'No Transaction Found', @controlNoEncrypted
  103. RETURN
  104. END
  105. IF NOT EXISTS(SELECT 'X' FROM vwRemitTran WITH(NOLOCK)
  106. WHERE controlNo = @controlNoEncrypted AND sBranch = @agentId)
  107. BEGIN
  108. EXEC proc_errorHandler 1, 'Transaction is not in authorized mode', @controlNoEncrypted
  109. RETURN
  110. END
  111. IF (@tranStatus = 'Cancel')
  112. BEGIN
  113. EXEC proc_errorHandler 1, 'Transaction already been cancelled', @controlNoEncrypted
  114. RETURN
  115. END
  116. IF (@tranStatus = 'CANCELLED')
  117. BEGIN
  118. EXEC proc_errorHandler 1, 'Transaction already been cancelled.', @controlNoEncrypted
  119. RETURN
  120. END
  121. IF (@tranStatus = 'Cancel Processing')
  122. BEGIN
  123. EXEC proc_errorHandler 1, 'Transaction already been Cancel Processing.', @controlNoEncrypted
  124. RETURN
  125. END
  126. IF (@tranStatus = 'ModificationRequest')
  127. BEGIN
  128. EXEC proc_errorHandler 1, 'Transaction already been requested for modification.', @controlNoEncrypted
  129. RETURN
  130. END
  131. IF (@tranStatus = 'Lock')
  132. BEGIN
  133. EXEC proc_errorHandler 1, 'Transaction is locked. Please contact HO', @controlNoEncrypted
  134. RETURN
  135. END
  136. IF (@tranStatus = 'Block')
  137. BEGIN
  138. EXEC proc_errorHandler 1, 'Transaction is blocked. Please contact HO', @controlNoEncrypted
  139. RETURN
  140. END
  141. IF EXISTS(SELECT 'X' FROM trancancelrequest WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND cancelStatus <> 'Rejected')
  142. BEGIN
  143. EXEC proc_errorHandler 1, 'Transaction is already requested for cancel.', @controlNoEncrypted
  144. RETURN
  145. END
  146. SET @tranStatus = @tranStatus+'|'+dbo.FNADecryptString(@controlNoEncrypted)
  147. EXEC proc_errorHandler 0, 'Transaction Found', @tranStatus
  148. END
  149. ELSE IF @flag = 'request'
  150. BEGIN
  151. IF @user IS NULL
  152. BEGIN
  153. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send cancel request.', NULL
  154. RETURN
  155. END
  156. SELECT
  157. @tranStatus = CASE WHEN payStatus='Post' THEN 'Post' WHEN paystatus ='Paid' THEN 'Paid' ELSE tranStatus END
  158. ,@tranId = id
  159. ,@txnSentBy = createdBy
  160. ,@controlNoEncrypted = controlNo
  161. FROM vwRemitTran WITH(NOLOCK)
  162. WHERE controlNo = @controlNoEncrypted
  163. IF (@tranStatus IS NULL)
  164. BEGIN
  165. EXEC proc_errorHandler 1, 'Transaction not found.', @controlNoEncrypted
  166. RETURN
  167. END
  168. SELECT @agentId = agentId,@userType=userType
  169. FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  170. IF @agentId <> (SELECT dbo.FNAGetHOAgentId())
  171. BEGIN
  172. IF EXISTS(SELECT 'X' FROM vwRemitTran WITH(NOLOCK)
  173. WHERE controlNo = @controlNoEncrypted AND sBranch <> @agentId)
  174. BEGIN
  175. EXEC proc_errorHandler 1, 'Transaction is not in authorized mode.', @controlNoEncrypted
  176. RETURN
  177. END
  178. END
  179. IF (@tranStatus = 'Cancel')
  180. BEGIN
  181. EXEC proc_errorHandler 1, 'Transaction already been cancelled', @controlNoEncrypted
  182. RETURN
  183. END
  184. IF (@tranStatus = 'CANCELLED')
  185. BEGIN
  186. EXEC proc_errorHandler 1, 'Transaction already been cancelled.', @controlNoEncrypted
  187. RETURN
  188. END
  189. IF (@tranStatus = 'Cancel Processing')
  190. BEGIN
  191. EXEC proc_errorHandler 1, 'Transaction already been Cancel Processing.', @controlNoEncrypted
  192. RETURN
  193. END
  194. IF (@tranStatus = 'ModificationRequest')
  195. BEGIN
  196. EXEC proc_errorHandler 1, 'Transaction already been requested for modification.', @controlNoEncrypted
  197. RETURN
  198. END
  199. IF (@tranStatus = 'Lock')
  200. BEGIN
  201. EXEC proc_errorHandler 1, 'Transaction is locked. Please contact HO', @controlNoEncrypted
  202. RETURN
  203. END
  204. IF (@tranStatus = 'Block')
  205. BEGIN
  206. EXEC proc_errorHandler 1, 'Transaction is blocked. Please contact HO', @controlNoEncrypted
  207. RETURN
  208. END
  209. BEGIN TRANSACTION
  210. IF EXISTS(SELECT 'X' FROM remitTranTemp WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted)
  211. BEGIN
  212. UPDATE remitTranTemp SET
  213. tranStatus = 'CancelRequest'
  214. ,cancelRequestBy = @user
  215. ,cancelRequestDate = GETDATE()
  216. ,cancelRequestDateLocal = dbo.FNADateFormatTZ(GETDATE(), @user)
  217. ,trnStatusBeforeCnlReq = @tranStatus
  218. WHERE controlNo = @controlNoEncrypted
  219. END
  220. ELSE
  221. BEGIN
  222. UPDATE remitTran SET
  223. tranStatus = 'CancelRequest'
  224. ,cancelRequestBy = @user
  225. ,cancelRequestDate = GETDATE()
  226. ,cancelRequestDateLocal = dbo.FNADateFormatTZ(GETDATE(), @user)
  227. ,trnStatusBeforeCnlReq = @tranStatus
  228. WHERE controlNo = @controlNoEncrypted
  229. END
  230. INSERT INTO tranCancelrequest(tranId,controlNo,cancelReason,cancelStatus,createdBy,createdDate,tranStatus)
  231. SELECT @tranId,@controlNoEncrypted,@cancelReason,'CancelRequest',@user,GETDATE(),@tranStatus
  232. --########### TO UPDATE THE STATUS IN INFICARE AND AC DB
  233. SELECT @message = 'Transaction requested for Cancel. Reason : ''' + @cancelReason + ''''
  234. EXEC proc_transactionLogs @flag = 'i',@user = @user,@tranId = @tranId,
  235. @message = @message, @msgType = 'Cancel Request', @controlNo = @controlNoEncrypted
  236. IF @@TRANCOUNT > 0
  237. COMMIT TRANSACTION
  238. EXEC proc_errorHandler 0, 'Transaction has been requested for cancel successfully', @controlNoEncrypted
  239. END
  240. ELSE IF @flag = 's'-->> List Payament Transaction Cancel Request
  241. BEGIN
  242. SET @table = '(
  243. SELECT
  244. id = ISNULL(trn.holdTranId,trn.Id)
  245. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  246. ,senderName = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  247. ,receiverName = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  248. ,Branch = trn.sBranchName
  249. ,cAmt
  250. ,pAmt
  251. ,ServiceCharge
  252. ,A.createdBy
  253. ,A.createdDate
  254. ,A.scRefund
  255. FROM vwRemitTran trn WITH(NOLOCK)
  256. INNER JOIN tranCancelrequest A WITH(NOLOCK) ON A.tranId=trn.id
  257. LEFT JOIN vwtranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  258. LEFT JOIN vwtranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  259. WHERE trn.tranStatus = ''CancelRequest'' AND ISNULL(A.tranStatus,'''')<>''Hold''
  260. '
  261. SET @sql_filter = ''
  262. IF @controlNo IS NOT NULL
  263. SET @table = @table + ' AND trn.controlNo = ''' + @controlNoEncrypted + ''''
  264. IF @Branch IS NOT NULL
  265. SET @table = @table + ' AND trn.sBranchName LIKE ''' + @Branch + '%'''
  266. IF @createdBy IS NOT NULL
  267. SET @table = @table + ' AND A.createdBy LIKE ''' + @createdBy + '%'''
  268. SET @select_field_list ='
  269. id
  270. ,controlNo
  271. ,senderName
  272. ,receiverName
  273. ,Branch
  274. ,cAmt
  275. ,pAmt
  276. ,ServiceCharge
  277. ,createdBy
  278. ,createdDate
  279. ,scRefund
  280. '
  281. SET @table = @table + ') x'
  282. EXEC dbo.proc_paging
  283. @table
  284. ,@sql_filter
  285. ,@select_field_list
  286. ,@extra_field_list
  287. ,@sortBy
  288. ,@sortOrder
  289. ,@pageSize
  290. ,@pageNumber
  291. END
  292. ELSE IF @flag = 's1'-->> List Unapproved Transaction Cancel Request
  293. BEGIN
  294. SELECT @userType = USERTYPE FROM applicationUsers WITH(NOLOCK) WHERE userName =@user
  295. SET @table = '(
  296. SELECT
  297. id = ISNULL(trn.holdTranId,trn.Id)
  298. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  299. ,senderName = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  300. ,receiverName = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  301. ,Branch = trn.sBranchName
  302. ,cAmt
  303. ,pAmt
  304. ,ServiceCharge
  305. ,A.createdBy
  306. ,A.createdDate
  307. ,A.scRefund
  308. ,trn.trnStatusBeforeCnlReq
  309. FROM vwRemitTran trn WITH(NOLOCK)
  310. INNER JOIN tranCancelrequest A WITH(NOLOCK) ON A.controlNo=trn.controlNo
  311. LEFT JOIN vwTranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  312. LEFT JOIN vwTranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  313. WHERE trn.tranStatus = ''CancelRequest''
  314. '
  315. SET @sql_filter = ''
  316. IF @userType IS NULL
  317. SET @table = @table + ' AND 1 = 2'
  318. IF @userType <>'HO'
  319. SET @table = @table + ' AND A.tranStatus=''Hold'''
  320. IF @controlNo IS NOT NULL
  321. SET @table = @table + ' AND trn.controlNo = ''' + @controlNoEncrypted + ''''
  322. IF @tranId IS NOT NULL
  323. SET @table = @table + ' AND trn.id = ''' + CAST(@tranId AS VARCHAR) + ''''
  324. IF @Branch IS NOT NULL
  325. SET @table = @table + ' AND trn.sBranchName LIKE ''' + @Branch + '%'''
  326. IF @createdBy IS NOT NULL
  327. SET @table = @table + ' AND A.createdBy LIKE ''' + @createdBy + '%'''
  328. SET @select_field_list ='
  329. id
  330. ,controlNo
  331. ,senderName
  332. ,receiverName
  333. ,Branch
  334. ,cAmt
  335. ,pAmt
  336. ,ServiceCharge
  337. ,createdBy
  338. ,createdDate
  339. ,scRefund
  340. ,trnStatusBeforeCnlReq
  341. '
  342. SET @table = @table + ') x'
  343. EXEC dbo.proc_paging
  344. @table
  345. ,@sql_filter
  346. ,@select_field_list
  347. ,@extra_field_list
  348. ,@sortBy
  349. ,@sortOrder
  350. ,@pageSize
  351. ,@pageNumber
  352. END
  353. ELSE IF @flag = 's1Agent'-->> List Unapproved Transaction Cancel Request FOR AGENT PANEL
  354. BEGIN
  355. SELECT @userType = USERTYPE FROM applicationUsers WITH(NOLOCK) WHERE userName =@user
  356. SET @table = '(
  357. SELECT
  358. id = ISNULL(trn.holdTranId,trn.Id)
  359. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  360. ,senderName = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  361. ,receiverName = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  362. ,Branch = trn.sBranchName
  363. ,cAmt
  364. ,pAmt
  365. ,ServiceCharge
  366. ,A.createdBy
  367. ,A.createdDate
  368. ,A.scRefund
  369. FROM remitTran trn WITH(NOLOCK)
  370. INNER JOIN tranCancelrequest A WITH(NOLOCK) ON A.tranId=trn.id
  371. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  372. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  373. WHERE trn.tranStatus = ''CancelRequest'' AND A.tranStatus=''Hold''
  374. '
  375. SET @sql_filter = ''
  376. IF @userType NOT IN ('HO','RH')
  377. SET @table = @table + ' AND 1 = 2'
  378. IF @controlNo IS NOT NULL
  379. SET @table = @table + ' AND trn.controlNo = ''' + @controlNoEncrypted + ''''
  380. IF @Branch IS NOT NULL
  381. SET @table = @table + ' AND trn.sBranchName LIKE ''' + @Branch + '%'''
  382. IF @createdBy IS NOT NULL
  383. SET @table = @table + ' AND A.createdBy LIKE ''' + @createdBy + '%'''
  384. IF @userType = 'RH'
  385. BEGIN
  386. SET @table = @table +' AND A.createdBy IN( SELECT userName
  387. FROM applicationUsers WHERE agentId IN (
  388. SELECT am.agentId
  389. FROM agentMaster am WITH(NOLOCK)
  390. LEFT JOIN regionalBranchAccessSetup rba ON am.agentId = rba.memberAgentId
  391. WHERE (rba.agentId = '''+CAST(@agentid AS VARCHAR)+''' AND
  392. ISNULL(rba.isDeleted, ''N'') = ''N''
  393. AND ISNULL(rba.isActive, ''N'') = ''Y'')
  394. OR am.agentId = '''+CAST(@agentid AS VARCHAR)+'''
  395. ) AND userName <> '''+@user+'''
  396. )'
  397. END
  398. SET @select_field_list ='
  399. id
  400. ,controlNo
  401. ,senderName
  402. ,receiverName
  403. ,Branch
  404. ,cAmt
  405. ,pAmt
  406. ,ServiceCharge
  407. ,createdBy
  408. ,createdDate
  409. ,scRefund
  410. '
  411. SET @table = @table + ') x'
  412. EXEC dbo.proc_paging
  413. @table
  414. ,@sql_filter
  415. ,@select_field_list
  416. ,@extra_field_list
  417. ,@sortBy
  418. ,@sortOrder
  419. ,@pageSize
  420. ,@pageNumber
  421. END
  422. ELSE IF @flag = 'approve'
  423. BEGIN
  424. DECLARE @holdTranId BIGINT
  425. DECLARE @pCountry VARCHAR(100)
  426. IF @user IS NULL
  427. BEGIN
  428. EXEC proc_errorHandler 1, 'Your session has expired. Cannot cancel transaction', NULL
  429. RETURN
  430. END
  431. SELECT
  432. @tranId = a.id,
  433. @serviceCharge = a.serviceCharge,
  434. @tAmt = a.tAmt,
  435. @cAmt = a.cAmt,
  436. @createdBy = a.createdBy,
  437. @tranStatus = b.tranStatus,
  438. @remitTranStatus = a.tranStatus,
  439. @cancelReason1 = b.cancelReason,
  440. @agentId = a.sAgent,
  441. @holdTranId = a.holdTranId,
  442. @irhRefund = ISNULL(a.cAmt,0) - ISNULL(a.sAgentComm,0) - ISNULL(agentFxGain,0),
  443. @pCountry = a.pCountry
  444. FROM vwRemitTran a WITH(NOLOCK)
  445. INNER JOIN tranCancelrequest b WITH(NOLOCK) ON a.controlNo=b.controlNo
  446. WHERE a.controlNo = @controlNoEncrypted AND b.approvedDate IS NULL
  447. IF (@tranStatus IS NULL)
  448. BEGIN
  449. EXEC proc_errorHandler 1, 'Transaction not found', @controlNoEncrypted
  450. RETURN
  451. END
  452. IF (@tranStatus = 'Cancel')
  453. BEGIN
  454. EXEC proc_errorHandler 1, 'Transaction already been cancelled', @controlNoEncrypted
  455. RETURN
  456. END
  457. IF (@tranStatus = 'CANCELLED')
  458. BEGIN
  459. EXEC proc_errorHandler 1, 'Transaction already been cancelled.', @controlNoEncrypted
  460. RETURN
  461. END
  462. IF (@tranStatus = 'Cancel Processing')
  463. BEGIN
  464. EXEC proc_errorHandler 1, 'Transaction already been cancelled.', @controlNoEncrypted
  465. RETURN
  466. END
  467. IF (@tranStatus = 'ModificationRequest')
  468. BEGIN
  469. EXEC proc_errorHandler 1, 'Transaction already been requested for modification.', @controlNoEncrypted
  470. RETURN
  471. END
  472. IF (@tranStatus = 'Lock')
  473. BEGIN
  474. EXEC proc_errorHandler 1, 'Transaction is locked. Please contact HO', @controlNoEncrypted
  475. RETURN
  476. END
  477. IF (@tranStatus = 'Block')
  478. BEGIN
  479. EXEC proc_errorHandler 1, 'Transaction is blocked. Please contact HO', @controlNoEncrypted
  480. RETURN
  481. END
  482. BEGIN TRANSACTION
  483. -->> UPDATE CANCEL HISTORY TABLE
  484. UPDATE
  485. tranCancelrequest SET
  486. cancelStatus = 'Approved'
  487. ,scRefund = @irhRefund
  488. ,approvedBy = @user
  489. ,approvedDate = GETDATE()
  490. ,approvedRemarks = @cancelReason
  491. ,isScRefund = @scRefund
  492. WHERE controlNo = @controlNoEncrypted
  493. -->> FOR API
  494. IF @tranStatus NOT LIKE '%HOLD%' OR @holdTranId IS NULL
  495. BEGIN
  496. -->> UPDATE REMITTRAN
  497. UPDATE remitTran SET
  498. tranStatus = 'Cancel'
  499. ,cancelApprovedBy = @user
  500. ,cancelApprovedDate = GETDATE()
  501. ,cancelApprovedDateLocal = GETDATE()
  502. WHERE controlNo = @controlNoEncrypted
  503. UPDATE creditLimit SET todaysCancelled = ISNULL(todaysCancelled,0) + @irhRefund
  504. WHERE agentId=@agentId
  505. END
  506. IF @tranStatus LIKE '%HOLD%' AND @holdTranId IS NOT NULL
  507. BEGIN
  508. -->> UPDATE REMITTRAN
  509. UPDATE remitTranTemp SET
  510. tranStatus = 'Cancel'
  511. ,cancelApprovedBy = @user
  512. ,cancelApprovedDate = GETDATE()
  513. ,cancelApprovedDateLocal = GETDATE()
  514. WHERE controlNo = @controlNoEncrypted
  515. INSERT INTO cancelTranHistory(
  516. tranId,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate
  517. ,pCurrHoMargin,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  518. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm,sAgentCommCurrency
  519. ,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm,pSuperAgentCommCurrency,promotionCode
  520. ,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName
  521. ,pAgent,pAgentName,pBranch,pBranchName,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode
  522. ,collCurr,tAmt,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  523. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal,paidBy
  524. ,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,cancelReason,refund,cancelCharge,cancelApprovedDate,cancelApprovedDateLocal
  525. ,cancelApprovedBy,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,tranType,ContNo
  526. ,uploadLogId,voucherNo,controlNo2,pBankType,trnStatusBeforeCnlReq,senderName,receiverName
  527. )
  528. SELECT
  529. id,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate
  530. ,pCurrHoMargin,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  531. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm,sAgentCommCurrency
  532. ,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm,pSuperAgentCommCurrency,promotionCode
  533. ,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName
  534. ,pAgent,pAgentName,pBranch,pBranchName,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode
  535. ,collCurr,tAmt,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  536. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal,paidBy
  537. ,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,@cancelReason1,refund,cancelCharge,GETDATE(),GETDATE()
  538. ,@user,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,tranType,ContNo
  539. ,uploadLogId,voucherNo,controlNo2,pBankType,trnStatusBeforeCnlReq,senderName,receiverName
  540. FROM remitTranTemp WHERE controlNo = @controlNoEncrypted
  541. INSERT INTO cancelTranSendersHistory
  542. (tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district,
  543. zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,
  544. idNumber,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,
  545. gender,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer)
  546. SELECT tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district,
  547. zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,
  548. idNumber,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,
  549. gender,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer
  550. FROM transenderstemp WITH(NOLOCK) WHERE tranId = @tranId
  551. INSERT INTO cancelTranReceiversHistory
  552. (tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,
  553. STATE,district,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  554. occupation,idType,idNumber,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,
  555. validDate2,relationType,relativeName,gender,address2,dcInfo,ipAddress)
  556. SELECT tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,
  557. STATE,district,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  558. occupation,idType,idNumber,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,
  559. validDate2,relationType,relativeName,gender,address2,dcInfo,ipAddress
  560. FROM tranReceiversTemp WITH(NOLOCK) WHERE tranId = @tranId
  561. DELETE FROM remitTranTemp WHERE controlNo = @controlNoEncrypted
  562. DELETE FROM tranSendersTemp WHERE tranId = @tranId
  563. DELETE FROM tranReceiversTemp WHERE tranId = @tranId
  564. UPDATE creditLimit SET todaysSent = ISNULL(todaysSent,0) - @irhRefund
  565. WHERE agentId=@agentId
  566. END
  567. SELECT @message = 'Transaction Cancel Request Approved'
  568. EXEC proc_transactionLogs 'i', @user, @tranId, @message, 'Transaction Cancel Approved'
  569. IF @@TRANCOUNT > 0
  570. COMMIT TRANSACTION
  571. EXEC [proc_errorHandler] 0, 'Transaction Cancel Request Approved successfully', @tranId
  572. END
  573. ELSE IF @flag='reject'
  574. BEGIN
  575. SELECT
  576. @tranStatus = CASE WHEN tranStatus ='Post' THEN 'Payment' ELSE transtatus END
  577. ,@tranId = id
  578. FROM tranCancelrequest WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  579. IF @user IS NULL
  580. BEGIN
  581. EXEC proc_errorHandler 1, 'Your session has expired. Cannot cancel transaction', NULL
  582. RETURN
  583. END
  584. IF (@tranStatus = 'Cancel')
  585. BEGIN
  586. EXEC proc_errorHandler 1, 'Transaction already been cancelled', @controlNoEncrypted
  587. RETURN
  588. END
  589. BEGIN TRANSACTION
  590. IF @tranStatus LIKE '%HOLD%'
  591. BEGIN
  592. UPDATE remitTranTemp SET
  593. tranStatus = @tranStatus
  594. ,cancelRequestBy = NULL
  595. ,cancelRequestDate = NULL
  596. ,cancelRequestDateLocal = NULL
  597. WHERE controlNo = @controlNoEncrypted
  598. END
  599. ELSE
  600. BEGIN
  601. UPDATE remitTran SET
  602. tranStatus = @tranStatus
  603. ,cancelRequestBy = NULL
  604. ,cancelRequestDate = NULL
  605. ,cancelRequestDateLocal = NULL
  606. WHERE controlNo = @controlNoEncrypted
  607. END
  608. UPDATE tranCancelrequest SET
  609. cancelStatus = 'Rejected'
  610. ,approvedBy = @user
  611. ,approvedDate = GETDATE()
  612. ,approvedRemarks = @cancelReason
  613. WHERE controlNo = @controlNoEncrypted
  614. SELECT @message = 'Transaction Cancel Request Rejected'
  615. EXEC proc_transactionLogs @flag = 'i',@user = @user,@tranId = @tranId,
  616. @message = @message, @msgType = 'Transaction Cancel Rejected', @controlNo = @controlNoEncrypted
  617. IF @@TRANCOUNT > 0
  618. COMMIT TRANSACTION
  619. EXEC [proc_errorHandler] 0, 'Transaction Cancel Request Rejected Successfully', @tranId
  620. END
  621. ELSE IF @flag = 'cancelReceipt'
  622. BEGIN
  623. SELECT @tranStatus = tranStatus FROM tranCancelrequest WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  624. IF @tranStatus LIKE '%Hold%'
  625. BEGIN
  626. SELECT
  627. controlNo = dbo.FNADecryptString(trn.controlNo)
  628. ,sBranch = trn.sBranchName
  629. ,sBranchId = trn.sBranch
  630. ,createdBy = trn.createdBy
  631. ,sendDate = trn.createdDate
  632. ,cancelAppDate = req.approvedDate
  633. ,cancelReqDate = req.createdDate
  634. ,cancelReqBy = req.createdBy
  635. ,cancelReason = req.cancelReason
  636. ,sender = sen.firstName + ISNULL(' ' + sen.middleName, '') + ISNULL(' ' + sen.lastName1, '') + ISNULL(' ' + sen.lastName2, '')
  637. ,receiver = rec.firstName + ISNULL(' ' + rec.middleName, '') + ISNULL(' ' + rec.lastName1, '') + ISNULL(' ' + rec.lastName2, '')
  638. ,rContactNo = rec.mobile
  639. ,trn.collCurr
  640. ,trn.cAmt
  641. ,trn.serviceCharge
  642. ,trn.pAmt
  643. ,pCurr = trn.payoutCurr
  644. ,cancelCharge = ISNULL(trn.cancelCharge ,0)
  645. ,returnAmt = req.scRefund
  646. FROM cancelTranHistory trn WITH(NOLOCK)
  647. INNER JOIN tranCancelrequest req WITH(NOLOCK) ON trn.tranId=req.tranId
  648. INNER JOIN cancelTranSendersHistory sen WITH(NOLOCK) ON trn.tranId = sen.tranId
  649. INNER JOIN cancelTranReceiversHistory rec WITH(NOLOCK) ON trn.tranId = rec.tranId
  650. WHERE trn.controlNo = @controlNoEncrypted
  651. END
  652. ELSE
  653. BEGIN
  654. SELECT
  655. controlNo = dbo.FNADecryptString(trn.controlNo)
  656. ,sBranch = trn.sBranchName
  657. ,sBranchId = trn.sBranch
  658. ,createdBy = trn.createdBy
  659. ,sendDate = trn.createdDate
  660. ,cancelAppDate = req.approvedDate
  661. ,cancelReqDate = req.createdDate
  662. ,cancelReqBy = req.createdBy
  663. ,cancelReason = req.cancelReason
  664. ,sender = sen.firstName + ISNULL(' ' + sen.middleName, '') + ISNULL(' ' + sen.lastName1, '') + ISNULL(' ' + sen.lastName2, '')
  665. ,receiver = rec.firstName + ISNULL(' ' + rec.middleName, '') + ISNULL(' ' + rec.lastName1, '') + ISNULL(' ' + rec.lastName2, '')
  666. ,rContactNo = rec.mobile
  667. ,trn.collCurr
  668. ,trn.cAmt
  669. ,trn.serviceCharge
  670. ,trn.pAmt
  671. ,pCurr = trn.payoutCurr
  672. ,cancelCharge = ISNULL(trn.cancelCharge ,0)
  673. ,returnAmt = req.scRefund
  674. FROM remitTran trn WITH(NOLOCK)
  675. INNER JOIN tranCancelrequest req WITH(NOLOCK) ON trn.id=req.tranId
  676. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  677. INNER JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  678. WHERE trn.controlNo = @controlNoEncrypted
  679. END
  680. END
  681. ELSE IF(@flag='displayRequest')
  682. BEGIN
  683. SELECT cancelReason
  684. FROM tranCancelrequest T WITH(NOLOCK)
  685. WHERE controlNo=@controlNoEncrypted AND approvedDate IS NULL
  686. AND cancelStatus='CancelRequest'
  687. END
  688. ELSE IF @flag = 'sAgentpending'-->> List Unapproved Transaction Cancel Request (Agent Panel)
  689. BEGIN
  690. SELECT @userType = USERTYPE FROM applicationUsers WHERE userName =@user
  691. SET @table = '(
  692. SELECT
  693. RT.sAgentName
  694. ,RT.sBranchName
  695. ,A.createdBy
  696. ,controlNo = ''<a href="#" onclick="OpenInNewWindow('''''+dbo.FNAGetURL()+'AgentPanel/Reports/SearchTransaction/TransactionDetail.aspx?searchBy=controlNo&searchValue='' + dbo.FNADecryptString(RT.controlNo) + '''''')">'' + dbo.FNADecryptString(RT.controlNo) + ''</a>''
  697. ,RT.cAmt
  698. ,CONVERT(VARCHAR,A.createdDate,101) createdDate
  699. ,RT.sBranch
  700. ,filterControlNo = dbo.FNADecryptString(RT.controlNo)
  701. FROM vwRemitTran RT WITH(NOLOCK)
  702. INNER JOIN tranCancelrequest A WITH(NOLOCK) ON A.controlNo=RT.controlNo
  703. WHERE RT.tranStatus = ''CancelRequest''
  704. ) x'
  705. SET @sql_filter = ''
  706. IF @controlNo IS NOT NULL
  707. SET @sql_filter = @sql_filter+ ' AND filterControlNo ='''+@controlNo+''''
  708. IF @branchId IS NOT NULL
  709. SET @sql_filter = @sql_filter+ ' AND sBranch ='''+CAST(@branchId AS VARCHAR)+''''
  710. IF @createdBy IS NOT NULL
  711. SET @sql_filter= @sql_filter + ' AND createdBy='''+@createdBy+''''
  712. SET @select_field_list ='
  713. sAgentName
  714. ,sBranchName
  715. ,createdBy
  716. ,controlNo
  717. ,cAmt
  718. ,createdDate
  719. ,filterControlNo
  720. '
  721. EXEC dbo.proc_paging
  722. @table
  723. ,@sql_filter
  724. ,@select_field_list
  725. ,''
  726. ,@sortBy
  727. ,@sortOrder
  728. ,@pageSize
  729. END
  730. IF @flag = 'radioButton'
  731. BEGIN
  732. SELECT 'hold' VALUE,'HOLD' textValue
  733. UNION ALL
  734. SELECT 'paid' VALUE, 'PAID' textValue
  735. UNION ALL
  736. SELECT 'confirm' VALUE, 'CONFIRM' textValue
  737. END
  738. ELSE IF @flag = 'cancelTxnAdmin'
  739. BEGIN
  740. SELECT
  741. @tranId = ISNULL(a.holdTranId,a.id),
  742. @serviceCharge = a.serviceCharge,
  743. @tAmt = a.tAmt,
  744. @cAmt = a.cAmt,
  745. @createdBy = a.createdBy,
  746. @tranStatus = a.tranStatus,
  747. @irhRefund = ISNULL(a.cAmt,0) - ISNULL(a.sAgentComm,0) - ISNULL(agentFxGain,0),
  748. @agentId = a.sAgent,
  749. @pCountry = a.pCountry
  750. FROM vwRemitTran a WITH(NOLOCK)
  751. WHERE a.controlNo = @controlNoEncrypted
  752. IF @user IS NULL
  753. BEGIN
  754. EXEC proc_errorHandler 1, 'Your session has expired. Cannot cancel transaction.', NULL
  755. RETURN
  756. END
  757. IF (@tranStatus IS NULL)
  758. BEGIN
  759. EXEC proc_errorHandler 1, 'Transaction not found.', @controlNoEncrypted
  760. RETURN
  761. END
  762. IF (@tranStatus = 'Cancel')
  763. BEGIN
  764. EXEC proc_errorHandler 1, 'Transaction already been cancelled.', @controlNoEncrypted
  765. RETURN
  766. END
  767. IF (@tranStatus = 'CancelRequest')
  768. BEGIN
  769. EXEC proc_errorHandler 1, 'Transaction already been cancel request.', @controlNoEncrypted
  770. RETURN
  771. END
  772. IF (@tranStatus = 'Block')
  773. BEGIN
  774. EXEC proc_errorHandler 1, 'Transaction is blocked.', @controlNoEncrypted
  775. RETURN
  776. END
  777. IF EXISTS(SELECT 'x' FROM trancancelrequest WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND cancelStatus <> 'Rejected')
  778. BEGIN
  779. EXEC proc_errorHandler 1, 'Transaction is already requested for cancel.', @controlNoEncrypted
  780. RETURN
  781. END
  782. BEGIN TRANSACTION
  783. INSERT INTO tranCancelrequest(tranId,controlNo,cancelReason,cancelStatus,
  784. createdBy,createdDate,tranStatus,approvedBy,approvedDate,scRefund,isScRefund)
  785. SELECT @tranId,@controlNoEncrypted,@cancelReason,'Approved',@user,GETDATE(),@tranStatus,@user,GETDATE(),
  786. CASE WHEN @scRefund ='Y' THEN @cAmt ELSE @tAmt END,@scRefund
  787. IF @tranStatus IN ('Payment','Paid')
  788. BEGIN
  789. UPDATE remitTran SET
  790. tranStatus = 'Cancel'
  791. ,cancelRequestBy = @user
  792. ,cancelRequestDate = GETDATE()
  793. ,cancelRequestDateLocal = GETDATE()
  794. ,cancelApprovedBy = @user
  795. ,cancelApprovedDate = GETDATE()
  796. ,cancelApprovedDateLocal = GETDATE()
  797. ,trnStatusBeforeCnlReq = @tranStatus
  798. WHERE controlNo = @controlNoEncrypted
  799. SET @DT1 = GETDATE()
  800. UPDATE creditLimit SET todaysCancelled = ISNULL(todaysCancelled,0)+ @irhRefund
  801. WHERE agentId=@agentId
  802. END
  803. IF @tranStatus LIKE '%HOLD%'
  804. BEGIN
  805. UPDATE remitTranTemp SET
  806. tranStatus = 'Cancel'
  807. ,cancelApprovedBy = @user
  808. ,cancelApprovedDate = GETDATE()
  809. ,cancelApprovedDateLocal = GETDATE()
  810. ,cancelRequestBy = @user
  811. ,cancelRequestDate = GETDATE()
  812. ,cancelRequestDateLocal = GETDATE()
  813. ,trnStatusBeforeCnlReq = @tranStatus
  814. WHERE controlNo = @controlNoEncrypted
  815. INSERT INTO cancelTranHistory(
  816. tranId,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate
  817. ,pCurrHoMargin,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  818. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm,sAgentCommCurrency
  819. ,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm,pSuperAgentCommCurrency,promotionCode
  820. ,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName
  821. ,pAgent,pAgentName,pBranch,pBranchName,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode
  822. ,collCurr,tAmt,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  823. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal,paidBy
  824. ,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,cancelReason,refund,cancelCharge,cancelApprovedDate,cancelApprovedDateLocal
  825. ,cancelApprovedBy,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,tranType,ContNo
  826. ,uploadLogId,voucherNo,controlNo2,pBankType,trnStatusBeforeCnlReq,senderName,receiverName
  827. )
  828. SELECT
  829. id,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate
  830. ,pCurrHoMargin,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  831. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm,sAgentCommCurrency
  832. ,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm,pSuperAgentCommCurrency,promotionCode
  833. ,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName
  834. ,pAgent,pAgentName,pBranch,pBranchName,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode
  835. ,collCurr,tAmt,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  836. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal,paidBy
  837. ,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,@cancelReason1,refund,cancelCharge,GETDATE(),GETDATE()
  838. ,@user,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,tranType,ContNo
  839. ,uploadLogId,voucherNo,controlNo2,pBankType,trnStatusBeforeCnlReq,senderName,receiverName
  840. FROM remitTranTemp WHERE controlNo = @controlNoEncrypted
  841. INSERT INTO cancelTranSendersHistory
  842. (tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district,
  843. zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,
  844. idNumber,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,
  845. gender,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer)
  846. SELECT tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district,
  847. zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,
  848. idNumber,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,
  849. gender,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer
  850. FROM transenderstemp WITH(NOLOCK) WHERE tranId = @tranId
  851. INSERT INTO cancelTranReceiversHistory
  852. (tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,
  853. STATE,district,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  854. occupation,idType,idNumber,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,
  855. validDate2,relationType,relativeName,gender,address2,dcInfo,ipAddress)
  856. SELECT tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,
  857. STATE,district,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  858. occupation,idType,idNumber,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,
  859. validDate2,relationType,relativeName,gender,address2,dcInfo,ipAddress
  860. FROM tranReceiversTemp WITH(NOLOCK) WHERE tranId = @tranId
  861. DELETE FROM remitTranTemp WHERE controlNo = @controlNoEncrypted
  862. DELETE FROM tranSendersTemp WHERE tranId = @tranId
  863. DELETE FROM tranReceiversTemp WHERE tranId = @tranId
  864. UPDATE creditLimit SET todaysSent = ISNULL(todaysSent,0) - @irhRefund
  865. WHERE agentId=@agentId
  866. END
  867. SELECT @message = 'Transaction cancel has been done successfully.'
  868. EXEC proc_transactionLogs 'i', @user, @tranId, @message, 'Transaction Cancel Approved'
  869. IF @@TRANCOUNT > 0
  870. COMMIT TRANSACTION
  871. EXEC [proc_errorHandler] 0, 'Transaction cancel has been done successfully', @tranId
  872. END
  873. GO