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.

189 lines
23 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_archiveTxns_step2] 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_archiveTxns_step2]
  9. AS
  10. SET XACT_ABORT ON;
  11. SET NOCOUNT ON;
  12. PRINT CONVERT(VARCHAR, GETDATE(), 109)
  13. BEGIN TRY
  14. BEGIN TRANSACTION
  15. EXEC proc_PrintLog 'STEP - 2, Moving Data - Started', 'tranCancelrequest'
  16. INSERT INTO FastMoneyPro_remit_Archive.dbo.tranCancelrequest(
  17. id,tranId,controlNo,cancelReason,cancelStatus,scRefund,createdDate,createdBy,approvedDate,approvedBy,approvedRemarks
  18. ,teller,refundDate,assignTellerDate,assignTellerBy,tranStatus,isScRefund
  19. )
  20. SELECT
  21. id,tranId,controlNo,cancelReason,cancelStatus,scRefund,createdDate,createdBy,approvedDate,approvedBy,approvedRemarks
  22. ,teller,refundDate,assignTellerDate,assignTellerBy,tranStatus,isScRefund
  23. FROM tranCancelrequest rt WITH(NOLOCK)
  24. INNER JOIN archiveTxnQueue trt ON rt.tranId = trt.t_id
  25. --EXEC proc_PrintLog 'Deleting...',NULL
  26. --DELETE rt FROM tranCancelrequest rt INNER JOIN archiveTxnQueue trt ON rt.controlNo= trt.t_controlNo
  27. --EXEC proc_PrintLog 'tranCancelrequest', 'tranModifyLog'
  28. --INSERT INTO FastMoneyPro_remit_Archive.dbo.tranModifyLog(
  29. -- rowId,tranId,controlNo,message,createdBy,createdDate,fileType,MsgType,dcInfo,status,resolvedBy,resolvedDate,fieldName
  30. -- ,fieldValue,oldValue,ScChargeMod
  31. --)
  32. --SELECT
  33. -- rowId,tranId,controlNo,message,createdBy,createdDate,fileType,MsgType,dcInfo,status,resolvedBy,resolvedDate,fieldName
  34. -- ,fieldValue,oldValue,ScChargeMod
  35. --FROM tranModifyLog rt WITH(NOLOCK)
  36. --INNER JOIN archiveTxnQueue trt ON rt.controlNo= trt.t_controlNo or rt.tranId = trt.t_holdTranId
  37. --EXEC proc_PrintLog 'Deleting...',NULL
  38. --DELETE rt FROM tranModifyLog rt INNER JOIN archiveTxnQueue trt ON rt.controlNo= trt.t_controlNo
  39. EXEC proc_PrintLog 'tranModifyLog', 'tranViewHistory'
  40. INSERT INTO FastMoneyPro_remit_Archive.dbo.tranViewHistory(
  41. id,controlNumber,tranViewType,agentId,createdBy,createdDate,dcInfo,tranId,remarks,ipAddress
  42. )
  43. SELECT
  44. id,controlNumber,tranViewType,agentId,createdBy,createdDate,dcInfo,tranId,remarks,ipAddress
  45. FROM tranViewHistory rt WITH(NOLOCK)
  46. INNER JOIN archiveTxnQueue trt ON rt.controlNumber= trt.t_controlNo
  47. --EXEC proc_PrintLog 'Deleting...',NULL
  48. --DELETE rt FROM tranViewHistory rt INNER JOIN archiveTxnQueue trt ON rt.controlNumber= trt.t_controlNo
  49. EXEC proc_PrintLog 'tranViewHistory', 'cancelTranHistory'
  50. INSERT INTO FastMoneyPro_remit_Archive.dbo.cancelTranHistory(
  51. id,tranId,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate,pCurrHoMargin
  52. ,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  53. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm
  54. ,sAgentCommCurrency,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm
  55. ,pSuperAgentCommCurrency,promotionCode,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent
  56. ,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName,pAgent,pAgentName,pBranch,pBranchName
  57. ,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode,collCurr,tAmt
  58. ,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  59. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal
  60. ,paidBy,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,cancelReason,refund,cancelCharge,cancelApprovedDate
  61. ,cancelApprovedDateLocal,cancelApprovedBy,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,sendEOD
  62. ,payEOD,cancelEOD,tranType,ContNo,uploadLogId,company,voucherNo,controlNo2,pBankType,trnStatusBeforeCnlReq,senderName
  63. ,receiverName,expectedPayoutAgent,routedBy,routedDate,incrRpt
  64. )
  65. SELECT
  66. id,tranId,controlNo,sCurrCostRate,sCurrHoMargin,sCurrSuperAgentMargin,sCurrAgentMargin,pCurrCostRate,pCurrHoMargin
  67. ,pCurrSuperAgentMargin,pCurrAgentMargin,agentCrossSettRate,customerRate,sAgentSettRate,pDateCostRate,agentFxGain
  68. ,treasuryTolerance,customerPremium,schemePremium,sharingValue,sharingType,serviceCharge,handlingFee,sAgentComm
  69. ,sAgentCommCurrency,sSuperAgentComm,sSuperAgentCommCurrency,pAgentComm,pAgentCommCurrency,pSuperAgentComm
  70. ,pSuperAgentCommCurrency,promotionCode,promotionType,pMessage,sCountry,sSuperAgent,sSuperAgentName,sAgent
  71. ,sAgentName,sBranch,sBranchName,pCountry,pSuperAgent,pSuperAgentName,pAgent,pAgentName,pBranch,pBranchName
  72. ,paymentMethod,pBank,pBankName,pBankBranch,pBankBranchName,accountNo,externalBankCode,collMode,collCurr,tAmt
  73. ,cAmt,pAmt,payoutCurr,relWithSender,purposeOfRemit,sourceOfFund,tranStatus,payStatus,createdDate,createdDateLocal
  74. ,createdBy,modifiedDate,modifiedDateLocal,modifiedBy,approvedDate,approvedDateLocal,approvedBy,paidDate,paidDateLocal
  75. ,paidBy,cancelRequestDate,cancelRequestDateLocal,cancelRequestBy,cancelReason,refund,cancelCharge,cancelApprovedDate
  76. ,cancelApprovedDateLocal,cancelApprovedBy,blockedDate,blockedBy,lockedDate,lockedDateLocal,lockedBy,payTokenId,sendEOD
  77. ,payEOD,cancelEOD,tranType,ContNo,uploadLogId,company,voucherNo,controlNo2,pBankType,trnStatusBeforeCnlReq,senderName
  78. ,receiverName,expectedPayoutAgent,routedBy,routedDate,incrRpt
  79. FROM cancelTranHistory rt WITH(NOLOCK)
  80. INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  81. --EXEC proc_PrintLog 'Deleting...',NULL
  82. --DELETE rt FROM cancelTranHistory rt INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  83. EXEC proc_PrintLog 'cancelTranHistory', 'cancelTranReceiversHistory'
  84. INSERT INTO FastMoneyPro_remit_Archive.dbo.cancelTranReceiversHistory(
  85. id,tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district
  86. ,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,idNumber
  87. ,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,validDate2,relationType,relativeName
  88. ,gender,address2,dcInfo,ipAddress
  89. )
  90. SELECT
  91. id,tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district
  92. ,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,idNumber
  93. ,idPlaceOfIssue,issuedDate,validDate,idType2,idNumber2,idPlaceOfIssue2,issuedDate2,validDate2,relationType,relativeName
  94. ,gender,address2,dcInfo,ipAddress
  95. FROM cancelTranReceiversHistory rt WITH(NOLOCK)
  96. INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  97. --EXEC proc_PrintLog 'Deleting...',NULL
  98. --DELETE rt FROM cancelTranReceiversHistory rt INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  99. EXEC proc_PrintLog 'cancelTranReceiversHistory', 'cancelTranSendersHistory'
  100. INSERT INTO FastMoneyPro_remit_Archive.dbo.cancelTranSendersHistory(
  101. id,tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district
  102. ,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,idNumber
  103. ,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,gender
  104. ,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer
  105. )
  106. SELECT
  107. id,tranId,customerId,membershipId,firstName,middleName,lastName1,lastName2,fullName,country,address,STATE,district
  108. ,zipCode,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,occupation,idType,idNumber
  109. ,idPlaceOfIssue,issuedDate,validDate,extCustomerId,cwPwd,ttName,isFirstTran,customerRiskPoint,countryRiskPoint,gender
  110. ,salary,companyName,address2,dcInfo,ipAddress,notifySms,txnTestQuestion,txnTestAnswer
  111. FROM cancelTranSendersHistory rt WITH(NOLOCK)
  112. INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  113. --EXEC proc_PrintLog 'Deleting...',NULL
  114. --DELETE rt FROM cancelTranSendersHistory rt INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  115. EXEC proc_PrintLog 'cancelTranSendersHistory', 'errPaidTran'
  116. INSERT INTO FastMoneyPro_remit_Archive.dbo.errPaidTran(
  117. eptId,tranId,oldSettlingAgent,oldPBranch,oldPBranchName,oldPSuperAgentComm,oldPSuperAgentCommCurrency,oldPAgentComm
  118. ,oldPAgentCommCurrency,oldPaidDate,newSettlingAgent,newPBranch,newPBranchName,newPSuperAgent,newPSuperAgentName
  119. ,newPAgent,newPAgentName,newPSuperAgentComm,newPSuperAgentCommCurrency,newPAgentComm,newPAgentCommCurrency,payoutAmt
  120. ,narration,createdBy,createdDate,modifiedBy,modifiedDate,approvedBy,approvedDate,newPaidBy,newPaidDate,rIdType,rIdNo
  121. ,expiryType,issueDate,validDate,placeOfIssue,mobileNo,rRelativeType,rRelativeName,tranStatus,isDeleted
  122. ,newDeliveryMethod,payRemarks
  123. )
  124. SELECT
  125. eptId,tranId,oldSettlingAgent,oldPBranch,oldPBranchName,oldPSuperAgentComm,oldPSuperAgentCommCurrency,oldPAgentComm
  126. ,oldPAgentCommCurrency,oldPaidDate,newSettlingAgent,newPBranch,newPBranchName,newPSuperAgent,newPSuperAgentName
  127. ,newPAgent,newPAgentName,newPSuperAgentComm,newPSuperAgentCommCurrency,newPAgentComm,newPAgentCommCurrency,payoutAmt
  128. ,narration,createdBy,createdDate,modifiedBy,modifiedDate,approvedBy,approvedDate,newPaidBy,newPaidDate,rIdType,rIdNo
  129. ,expiryType,issueDate,validDate,placeOfIssue,mobileNo,rRelativeType,rRelativeName,tranStatus,isDeleted
  130. ,newDeliveryMethod,payRemarks
  131. FROM errPaidTran rt WITH(NOLOCK)
  132. INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  133. --EXEC proc_PrintLog 'Deleting...',NULL
  134. --DELETE rt FROM errPaidTran rt INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  135. EXEC proc_PrintLog 'errPaidTran', 'errPaidTranHistory'
  136. INSERT INTO FastMoneyPro_remit_Archive.dbo.errPaidTranHistory(
  137. rowId,eptId,tranId,oldSettlingAgent,oldPBranch,oldPBranchName,oldPSuperAgentComm,oldPSuperAgentCommCurrency
  138. ,oldPAgentComm,oldPAgentCommCurrency,oldPaidDate,newSettlingAgent,newPBranch,newPBranchName,newPSuperAgent
  139. ,newPSuperAgentName,newPAgent,newPAgentName,newPSuperAgentComm,newPSuperAgentCommCurrency,newPAgentComm
  140. ,newPAgentCommCurrency,payoutAmt,narration,createdBy,createdDate,approvedBy,approvedDate,modType,newDeliveryMethod
  141. )
  142. SELECT
  143. rowId,eptId,tranId,oldSettlingAgent,oldPBranch,oldPBranchName,oldPSuperAgentComm,oldPSuperAgentCommCurrency
  144. ,oldPAgentComm,oldPAgentCommCurrency,oldPaidDate,newSettlingAgent,newPBranch,newPBranchName,newPSuperAgent
  145. ,newPSuperAgentName,newPAgent,newPAgentName,newPSuperAgentComm,newPSuperAgentCommCurrency,newPAgentComm
  146. ,newPAgentCommCurrency,payoutAmt,narration,createdBy,createdDate,approvedBy,approvedDate,modType,newDeliveryMethod
  147. FROM errPaidTranHistory rt WITH(NOLOCK)
  148. INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  149. --EXEC proc_PrintLog 'Deleting...',NULL
  150. --DELETE rt FROM errPaidTranHistory rt INNER JOIN archiveTxnQueue trt ON rt.tranId= trt.t_id
  151. EXEC proc_PrintLog 'errPaidTranHistory', 'STEP - 2, Moving Data - Completed'
  152. COMMIT TRANSACTION
  153. SELECT '0' errorCode, CAST((SELECT COUNT(*) FROM archiveTxnQueue) AS VARCHAR) + ' Transaction(s) archived successfully: Step:2' msg, NULL id
  154. END TRY
  155. BEGIN CATCH
  156. IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
  157. SELECT '1' rrrorCode, ERROR_MESSAGE() msg, NULL id
  158. END CATCH
  159. GO