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.

270 lines
22 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[ws_int_proc_CancelTransaction] 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].[ws_int_proc_CancelTransaction](
  9. @AGENT_CODE VARCHAR(50),
  10. @USER_ID VARCHAR(50),
  11. @PASSWORD VARCHAR(50),
  12. @PINNO VARCHAR(20),
  13. @AGENT_SESSION_ID VARCHAR(150),
  14. @CANCEL_REASON VARCHAR(500)
  15. )
  16. AS
  17. SET NOCOUNT ON
  18. SET XACT_ABORT ON
  19. BEGIN TRY
  20. DECLARE @apiRequestId BIGINT
  21. INSERT INTO requestApiLogOther(
  22. AGENT_CODE
  23. ,USER_ID
  24. ,PASSWORD
  25. ,REFNO
  26. ,AGENT_SESSION_ID
  27. ,CANCEL_REASON
  28. ,METHOD_NAME
  29. ,REQUEST_DATE
  30. )
  31. SELECT
  32. @AGENT_CODE
  33. ,@USER_ID
  34. ,@PASSWORD
  35. ,@PINNO
  36. ,@AGENT_SESSION_ID
  37. ,@CANCEL_REASON
  38. ,'ws_int_proc_CancelTransaction'
  39. ,GETDATE()
  40. SET @apiRequestId = SCOPE_IDENTITY()
  41. DECLARE @errCode INT, @controlNoEnc VARCHAR(50), @DT DATETIME
  42. DECLARE @autMsg VARCHAR(500)
  43. SET @DT = GETDATE()
  44. SET @controlNoEnc = dbo.FNAEncryptString(@PINNO)
  45. EXEC ws_int_proc_checkAuthntication @USER_ID,@PASSWORD,@AGENT_CODE,@errCode OUT, @autMsg OUT
  46. DECLARE @errorTable TABLE(
  47. AGENT_SESSION_ID VARCHAR(150),PINNO VARCHAR(50),AGENT_TXNID INT,COLLECT_AMT MONEY,COLLECT_CURRENCY VARCHAR(3)
  48. ,EXCHANGE_RATE MONEY,SERVICE_CHARGE MONEY,PAYOUTAMT MONEY,PAYOUTCURRENCY VARCHAR(3),TXN_DATE DATETIME
  49. )
  50. INSERT INTO @errorTable (AGENT_SESSION_ID, PINNO)
  51. SELECT @AGENT_SESSION_ID, @PINNO
  52. IF(@errCode = 1 )
  53. BEGIN
  54. SELECT '1002' CODE, ISNULL(@autMsg,'Authentication Fail') MESSAGE, * FROM @errorTable
  55. RETURN
  56. END
  57. IF EXISTS(SELECT 'X' FROM applicationUsers WITH (NOLOCK) WHERE userName = @USER_ID AND forceChangePwd = 'Y')
  58. BEGIN
  59. SELECT '1002' CODE, 'You logged on first time,must first change your password and try again!' MESSAGE, * FROM @errorTable
  60. RETURN
  61. END
  62. IF @PINNO IS NULL
  63. BEGIN
  64. SELECT '1001' CODE, 'PINNO Field is Empty' MESSAGE, * FROM @errorTable
  65. RETURN;
  66. END
  67. IF @CANCEL_REASON IS NULL
  68. BEGIN
  69. SELECT '1001' CODE, 'CANCEL REASON Field is Empty' MESSAGE, * FROM @errorTable
  70. RETURN;
  71. END
  72. IF @AGENT_SESSION_ID IS NULL
  73. BEGIN
  74. SELECT '1001' CODE, 'AGENT SESSION ID Field is Empty' MESSAGE, * FROM @errorTable
  75. RETURN;
  76. END
  77. DECLARE
  78. @sCountryId INT
  79. ,@sAgent INT
  80. ,@sBranch INT
  81. ,@tranId INT
  82. ,@tranStatus VARCHAR(50)
  83. ,@payStatus VARCHAR(50)
  84. ,@serviceCharge MONEY
  85. ,@tAmt MONEY
  86. ,@cAmt MONEY
  87. ,@createdBy VARCHAR(50)
  88. ,@txnSbranch INT
  89. ,@txnSAgent INT
  90. ,@pCountry VARCHAR(50)
  91. SELECT
  92. @sCountryId = countryId,
  93. @sBranch = sb.agentId,
  94. @sAgent = sb.parentId
  95. FROM applicationUsers au WITH(NOLOCK)
  96. LEFT JOIN agentMaster sb WITH(NOLOCK) ON au.agentId = sb.agentId
  97. WHERE userName = @USER_ID
  98. AND ISNULL(sb.isActive,'N') = 'Y'
  99. DECLARE @cancelReason1 VARCHAR(500)
  100. SELECT
  101. @tranId = id,
  102. @serviceCharge = serviceCharge,
  103. @tAmt = tAmt,
  104. @cAmt = cAmt,
  105. @createdBy = createdBy,
  106. @tranStatus = tranStatus,
  107. @payStatus = payStatus,
  108. @txnSbranch = sBranch,
  109. @txnSAgent = sAgent,
  110. @pCountry = pCountry
  111. FROM remitTran WITH(NOLOCK)
  112. WHERE controlNo = dbo.FNAEncryptString(@PINNO)
  113. IF (@tranStatus IS NULL)
  114. BEGIN
  115. SELECT '2003' CODE, 'RefNo: '+ @PINNO + ' Not Found or can not cancel. Please contact Headoffice' MESSAGE
  116. ,* FROM @errorTable
  117. RETURN
  118. END
  119. IF @sAgent <> @txnSAgent
  120. BEGIN
  121. SELECT '1003' CODE, 'You are not allow to cancel this transaction' MESSAGE, * FROM @errorTable
  122. RETURN
  123. END
  124. IF (@tranStatus = 'Cancel')
  125. BEGIN
  126. SELECT '2003' CODE, 'Transaction already been cancelled' MESSAGE, * FROM @errorTable
  127. RETURN
  128. END
  129. IF (@tranStatus = 'Lock')
  130. BEGIN
  131. SELECT '2003' CODE, 'Transaction is locked. Please contact HO' MESSAGE, * FROM @errorTable
  132. RETURN
  133. END
  134. IF (@tranStatus = 'Block')
  135. BEGIN
  136. SELECT '2003' CODE, 'Transaction is blocked. Please contact HO' MESSAGE, * FROM @errorTable
  137. RETURN
  138. END
  139. IF (@payStatus = 'Post')
  140. BEGIN
  141. SELECT '2001' CODE, 'Transaction is not in Authorized Mode' MESSAGE, * FROM @errorTable
  142. RETURN
  143. END
  144. IF (@tranStatus = 'Paid')
  145. BEGIN
  146. SELECT '2001' CODE, 'Transaction is not in Authorized Mode' MESSAGE, * FROM @errorTable
  147. RETURN
  148. END
  149. BEGIN TRANSACTION
  150. UPDATE remitTran SET
  151. tranStatus = 'Cancel'
  152. ,cancelRequestDate = GETDATE()
  153. ,cancelRequestDateLocal = dbo.FNADateFormatTZ(GETDATE(), @USER_ID)
  154. ,cancelRequestBy = @USER_ID
  155. ,cancelReason = @CANCEL_REASON
  156. ,cancelApprovedBy = @USER_ID
  157. ,cancelApprovedDate = dbo.FNADateFormatTZ(GETDATE(), @USER_ID)
  158. ,cancelApprovedDateLocal = GETDATE()
  159. WHERE id = @tranId
  160. -->> UPDATE CANCEL HISTORY TABLE SELECT * FROM tranCancelrequest
  161. INSERT INTO tranCancelrequest(tranId,controlNo,cancelReason,cancelStatus,createdBy,createdDate,approvedBy,approvedDate,approvedRemarks)
  162. SELECT @tranId, dbo.FNAEncryptString(@PINNO), @CANCEL_REASON, 'Approved', @USER_ID, GETDATE(), @USER_ID, GETDATE(), @CANCEL_REASON
  163. DELETE FROM @errorTable
  164. INSERT INTO @errorTable (AGENT_SESSION_ID,PINNO,AGENT_TXNID,COLLECT_AMT,COLLECT_CURRENCY,EXCHANGE_RATE,SERVICE_CHARGE,PAYOUTAMT,PAYOUTCURRENCY,TXN_DATE)
  165. SELECT @AGENT_SESSION_ID,@PINNO,'123456',cAmt,collCurr,customerRate,serviceCharge,pAmt,payoutCurr,createdDateLocal
  166. FROM remitTran WITH (NOLOCK) WHERE id = @tranId
  167. IF @tranStatus LIKE '%HOLD%'
  168. BEGIN
  169. INSERT INTO cancelTranHistory(
  170. tranId,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate
  171. ,pCurrHoMargin,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  172. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm,sAgentCommCurrency
  173. ,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm,pSuperAgentCommCurrency,promotionCode
  174. ,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName
  175. ,pAgent,pAgentName,pBranch,pBranchName,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode
  176. ,collCurr,tAmt,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  177. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal,paidBy
  178. ,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,cancelReason,refund,cancelCharge,cancelApprovedDate,cancelApprovedDateLocal
  179. ,cancelApprovedBy,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,tranType,ContNo
  180. ,uploadLogId,voucherNo,controlNo2,pBankType,senderName,receiverName
  181. )
  182. SELECT
  183. id,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate
  184. ,pCurrHoMargin,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  185. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm,sAgentCommCurrency
  186. ,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm,pSuperAgentCommCurrency,promotionCode
  187. ,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName
  188. ,pAgent,pAgentName,pBranch,pBranchName,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode
  189. ,collCurr,tAmt,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  190. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal,paidBy
  191. ,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,@cancelReason1,refund,cancelCharge,dbo.FNADateFormatTZ(GETDATE(), @USER_ID),GETDATE()
  192. ,@USER_ID,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,tranType,ContNo
  193. ,uploadLogId,voucherNo,controlNo2,pBankType,senderName,receiverName
  194. FROM remitTran WITH (NOLOCK) WHERE id = @tranId
  195. INSERT INTO cancelTranSendersHistory
  196. (tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district,
  197. zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,
  198. idNumber,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,
  199. gender,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer)
  200. SELECT tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district,
  201. zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,
  202. idNumber,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,
  203. gender,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer
  204. FROM transenders WITH(NOLOCK) WHERE tranId = @tranId
  205. INSERT INTO cancelTranReceiversHistory
  206. (tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,
  207. STATE,district,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  208. occupation,idType,idNumber,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,
  209. validDate2,relationType,relativeName,gender,address2,dcInfo,ipAddress)
  210. SELECT tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,
  211. STATE,district,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  212. occupation,idType,idNumber,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,
  213. validDate2,relationType,relativeName,gender,address2,dcInfo,ipAddress
  214. FROM tranReceivers WITH(NOLOCK) WHERE tranId = @tranId
  215. DELETE FROM remitTran WHERE id = @tranId
  216. DELETE FROM tranSenders WHERE tranId = @tranId
  217. DELETE FROM tranReceivers WHERE tranId = @tranId
  218. END
  219. COMMIT TRANSACTION
  220. SELECT 0 CODE, 'success' MESSAGE, * FROM @errorTable
  221. UPDATE requestApiLogOther SET
  222. errorCode = '0'
  223. ,errorMsg = 'Success'
  224. WHERE rowId = @apiRequestId
  225. END TRY
  226. BEGIN CATCH
  227. IF @@TRANCOUNT > 0
  228. ROLLBACK TRAN
  229. SELECT '9001' CODE, 'Technical Error : ' + ERROR_MESSAGE() MESSAGE, * FROM @errorTable
  230. INSERT INTO Logs (errorPage, errorMsg, errorDetails, createdBy, createdDate)
  231. SELECT 'API SP Error','Technical Error : ' + ERROR_MESSAGE() MESSAGE,'ws_proc_CancelTransaction','admin', GETDATE()
  232. END CATCH
  233. GO