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.

101 lines
7.7 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendSmsEmailBankGauranteeExpire] 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_sendSmsEmailBankGauranteeExpire](
  9. @flag VARCHAR(30)=NULL
  10. )AS
  11. SET XACT_ABORT ON
  12. SET NOCOUNT ON
  13. BEGIN
  14. DECLARE @currDate date,@before15Days date
  15. SET @currDate=convert(date,GETDATE(),101)
  16. SET @before15Days=convert(date,DATEADD(DAY,-15,@currDate),101)
  17. ---select @currDate,@before15Days
  18. IF OBJECT_ID('tempdb..#smsTemp') IS NOT NULL
  19. DROP TABLE #smsTemp
  20. IF OBJECT_ID('tempdb..#notSend') IS NOT NULL
  21. DROP TABLE #notSend
  22. IF OBJECT_ID('tempdb..#tempbank') IS NOT NULL
  23. DROP TABLE #tempbank
  24. --select * from SMSQueue where msg like '%bank Guarantee%'
  25. --delete from SMSQueue where msg like '%bank Guarantee%'
  26. SELECT DISTINCT agentId,sentDate INTO #smsTemp FROM SMSQueue (NOLOCK) WHERE msg like '%bank Guarantee%'
  27. SELECT * INTO #notSend FROM
  28. (
  29. SELECT
  30. bank.agentId agentId
  31. ,bank.guaranteeNo guaranteeNo
  32. ,bank.bgId bgId
  33. ,bank.amount amount
  34. ,bank.bankName bankName
  35. ,CONVERT(date,bank.issuedDate,101) issuedDate
  36. ,CONVERT(date,bank.expiryDate,101) expiryDate
  37. ,CONVERT(date,bank.followUpDate,101) followUpDate
  38. ,sms.agentId as smsAgentId
  39. FROM bankGuarantee (NOLOCK) bank
  40. left join #smsTemp sms on bank.agentId=sms.agentId
  41. WHERE sms.agentId is null OR dateDiff(DAY,sentDate,getdate())>=7
  42. --AND other condition Goes here
  43. ) x
  44. SELECT
  45. agentName= am.agentName
  46. ,agentId=am.agentId
  47. ,branchId=am.agentId
  48. ,[Guarantee No.] = bg.guaranteeNo
  49. ,Amount = bg.amount
  50. ,BankName = bg.bankName
  51. ,issuedDate = convert(date,bg.issuedDate,101)
  52. ,expiryDate = convert(date,bg.expiryDate,101)
  53. ,followUpDate = convert(date,bg.followUpDate,101)
  54. ,agentMobile=am.agentMobile1
  55. ,agentEmail=am.agentEmail1
  56. ,smsMsg='Dear IME Agent, Your Bank Guarantee is going to expire on '+convert(varchar,bg.expiryDate,101)+'. Kindly proceed to renew.IME Ltd'
  57. ,emailMsg='Dear IME Agent <strong>'+am.agentName+'</strong>,
  58. <br /><br />Your Bank Guarantee is going to expire on <strong>'+convert(varchar,bg.expiryDate,101)+'</strong>. <br/>Kindly proceed to renew.
  59. <br />Please contact IME Sales Department for further support and assistance.<br/>IME Ltd<br/><br/><br/><br/><br/><br/><br/><br/>'
  60. INTO #tempbank
  61. FROM dbo.agentMaster am WITH(NOLOCK)
  62. INNER JOIN #notSend bg WITH(NOLOCK) ON am.agentid = bg.agentId
  63. WHERE am.isSettlingAgent = 'Y'
  64. AND (agentType = 2903 or agentType =2904)
  65. and am.agentCountry ='Nepal'
  66. and am.parentId <> 5576
  67. AND followUpDate=@currDate OR convert(date,DATEADD(DAY,-15,expiryDate),101)=@currDate
  68. --select @currDate,@before15Days
  69. INSERT INTO SMSQueue(mobileNo,msg,createdDate,createdBy,country,agentId,branchId)
  70. SELECT agentMobile,smsMsg,GETDATE(),'admin','Nepal',agentId,branchId FROM #tempbank
  71. --WHERE followUpDate=@currDate OR convert(varchar,DATEADD(DAY,-15,expiryDate),101)=@currDate
  72. INSERT INTO SMSQueue(email,subject,msg,createdDate,createdBy,country,agentId,branchId)
  73. SELECT agentEmail,'Bank Guarantee Expiry Notification',emailMsg,GETDATE(),'admin','Nepal',agentId,branchId FROM #tempbank
  74. --WHERE followUpDate=@currDate OR convert(varchar,DATEADD(DAY,-15,expiryDate),101)=@currDate
  75. --add record to email admins
  76. DECLARE @adminEmailText NVARCHAR(MAX);
  77. SELECT @adminEmailText = COALESCE(@adminEmailText + '<br/>', '') + emailMsg
  78. FROM #tempbank
  79. INSERT INTO SMSQueue(email,subject,msg,createdDate,createdBy,country,agentId,branchId)
  80. SELECT email,'Bank Guarantee Expiry Notification',@adminEmailText as emailMsg,GETDATE() createdDate,'admin' createdBy,'Nepal' country,agent agentId,agent branchId
  81. FROM SystemEmailSetup
  82. WHERE isbankGuaranteeExpiry='Yes'
  83. AND isnull(isDeleted,'N')='N'
  84. END
  85. GO