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.

104 lines
4.3 KiB

1 year ago
  1. SET QUOTED_IDENTIFIER ON
  2. SET ANSI_NULLS ON
  3. GO
  4. /*
  5. DeleteCustomer @email='mahendrapandit10@gmail.com'
  6. SELECT * FROM dbo.customerMaster(NOLOCK) AS CM WHERE email='mahendrapandit10@gmail.com'
  7. SELECT * FROM dbo.customerMaster_Deleted(NOLOCK) AS CM WHERE email='mahendrapandit10@gmail.com'
  8. */
  9. ALTER PROC [dbo].[DeleteCustomer](@email VARCHAR(100))
  10. AS
  11. SET NOCOUNT ON;
  12. SET XACT_ABORT ON;
  13. BEGIN
  14. DECLARE @customerId BIGINT=NULL, @balance MONEY=NULL, @txnCnt BIGINT=0,@virtualAccount VARCHAR(50)
  15. SELECT
  16. @balance=CM.availableBalance,@customerId=CM.customerId ,@virtualAccount=CM.walletAccountNo
  17. FROM dbo.customerMaster(NOLOCK) AS CM WHERE CM.email=@email
  18. IF @customerId IS NULL
  19. BEGIN
  20. DECLARE @isDeleted BIT = 0
  21. IF EXISTS(SELECT 'x' FROM dbo.CustomerMasterTemp(NOLOCK) WHERE username = @email)
  22. BEGIN
  23. DELETE FROM dbo.CustomerMasterTemp WHERE username = @email
  24. SET @isDeleted = 1
  25. END
  26. IF EXISTS(SELECT 'x' FROM dbo.mobile_userRegistration (NOLOCK) WHERE username = @email)
  27. BEGIN
  28. DELETE FROM dbo.mobile_userRegistration WHERE username = @email
  29. SET @isDeleted = 1
  30. END
  31. IF @isDeleted = 1
  32. BEGIN
  33. SELECT 0,'Customer deleted from temp or user reg' Msg, NULL Id
  34. RETURN
  35. END
  36. SELECT 1,'cannot delete the customer.CustomerId is null' Msg, NULL Id
  37. RETURN
  38. END
  39. IF ISNULL(@balance,0)<>0
  40. BEGIN
  41. SELECT 1,'cannot delete the customer. Balance Not equal to Zero' Msg, NULL Id
  42. RETURN
  43. END
  44. SELECT @txnCnt=COUNT('x') FROM dbo.tranSenders(NOLOCK) AS TS WHERE TS.customerId=@customerId
  45. IF @txnCnt>0
  46. BEGIN
  47. SELECT 1,'cannot delete the customer. Has done Txn' Msg, NULL Id
  48. RETURN
  49. END
  50. BEGIN TRAN
  51. INSERT INTO customerMaster_Deleted
  52. (
  53. customerId,membershipId,firstName,middleName,lastName1,lastName2,country,address,state,zipCode,district,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  54. occupation,isBlackListed,createdBy,createdDate,modifiedBy,modifiedDate,approvedBy,approvedDate,isDeleted,lastTranId,relationId,relativeName,address2,fullName,postalCode,idExpiryDate,
  55. idType,idNumber,telNo,companyName,gender,salaryRange,bonusPointPending,Redeemed,bonusPoint,todaysSent,todaysNoOfTxn,agentId,branchId,memberIDissuedDate,memberIDissuedByUser,
  56. memberIDissuedAgentId,memberIDissuedBranchId,totalSent,idIssueDate,onlineUser,customerPassword,customerStatus,isActive,islocked,sessionId,lastLoginTs,howDidYouHear,ansText,
  57. ansEmail,state2,ipAddress,marketingSubscription,paidTxn,firstTxnDate,verifyDoc1,verifyDoc2,verifiedBy,verifiedDate,verifyDoc3,isForcedPwdChange,bankName,bankAccountNo,walletAccountNo,
  58. availableBalance,obpId,CustomerBankName,referelCode,isEmailVerified,verificationCode,SelfieDoc,HasDeclare,AuditDate,AuditBy,SchemeStartDate,invalidAttemptCount
  59. )
  60. SELECT
  61. customerId,membershipId,firstName,middleName,lastName1,lastName2,country,address,state,zipCode,district,city,email,homePhone,workPhone,mobile,nativeCountry,dob,placeOfIssue,customerType,
  62. occupation,isBlackListed,createdBy,createdDate,modifiedBy,modifiedDate,approvedBy,approvedDate,isDeleted,lastTranId,relationId,relativeName,address2,fullName,postalCode,idExpiryDate,
  63. idType,idNumber,telNo,companyName,gender,salaryRange,bonusPointPending,Redeemed,bonusPoint,todaysSent,todaysNoOfTxn,agentId,branchId,memberIDissuedDate,memberIDissuedByUser,
  64. memberIDissuedAgentId,memberIDissuedBranchId,totalSent,idIssueDate,onlineUser,customerPassword,customerStatus,isActive,islocked,sessionId,lastLoginTs,howDidYouHear,ansText,
  65. ansEmail,state2,ipAddress,marketingSubscription,paidTxn,firstTxnDate,verifyDoc1,verifyDoc2,verifiedBy,verifiedDate,verifyDoc3,isForcedPwdChange,bankName,bankAccountNo,walletAccountNo,
  66. availableBalance,obpId,CustomerBankName,referelCode,isEmailVerified,verificationCode,SelfieDoc,HasDeclare,AuditDate,AuditBy,SchemeStartDate,invalidAttemptCount
  67. FROM dbo.customerMaster(NOLOCK) AS CM
  68. WHERE CM.customerId=@customerId
  69. DELETE FROM dbo.customerMaster WHERE customerId=@customerId
  70. DELETE FROM dbo.mobile_userRegistration WHERE username = @email
  71. DELETE FROM FastMoneyPro_Account.dbo.ac_master WHERE acct_num=@virtualAccount AND ISNULL(clr_bal_amt,0.0)=0.0
  72. COMMIT TRAN
  73. --SELECT * FROM dbo.customerMaster(NOLOCK) AS CM WHERE CM.email=@email
  74. IF @@TRANCOUNT<>0
  75. BEGIN
  76. SELECT '1','Error Occured while deleting customer' Msg, NULL Id
  77. RETURN
  78. END
  79. SELECT '0','Customer Deleted' Msg , NULL Id
  80. RETURN
  81. END
  82. GO