spTransactions_MarkSignupAsProcessed
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@SignupID | int | IN | |
@BackOfficeID | int | IN | |
@BackOfficeSysID | int | IN |
Definition
Copy
CREATE Procedure [dbo].[spTransactions_MarkSignupAsProcessed](
@SignupID int,
@BackOfficeID int,
@BackOfficeSysID int)
as
begin
set nocount on
begin transaction
declare @UserID int
declare @BackOfficeSystemPeopleID int
declare @BackOfficeSystemUsersID int
select @UserID = ID from dbo.ClientUsers inner join dbo.SignUpTransactions on ClientUsers.[ID] = SignUpTransactions.UserID where SignUpTransactions.SignupTransactionsID = @SignupID
exec [dbo].[spGetBackOfficeSystemPeopleID] @BackOfficeID, @BackOfficeSysID, @BackOfficeSystemPeopleID OUTPUT
exec [dbo].[spGetBackOfficeSystemUsersID] @UserID, @BackOfficeSystemPeopleID, @BackOfficeSystemUsersID OUTPUT
--Update any sent emails
update dbo.EmailJob_Recipient set BackOfficeSystemPeopleID=@BackOfficeSystemPeopleID, UpdateDate=getutcdate() where UserID=@UserID
-- Update user - no longer provisional
update ClientUsers set ClientUsers.IsProvisional = 0, UpdateDate = getutcdate() from dbo.ClientUsers where ClientUsers.[ID] = @UserID
-- Mark tran as processed
update dbo.SignupTransactions set processed_date=getutcdate() where SignupTransactionsID=@SignupID
-- update profileupdatetxns with corresponding backofficeid
update dbo.ProfileUpdateTransactions set backofficeid = @backofficeid where addedbyuserid = @userid and isnull(backofficeid,0)=0
--sterling CR311435-111208
--need to ensure that only one row per newsletter exists in the email_subscriptions table for this user
declare @Temp table(id int, listID int, UserID2 int, BOSPID int, UpdateDate datetime)
insert into @Temp
select id, emaillistid, userid, backofficesystempeopleid, updatedate
from emaillist_subscription
where userid = @userid or backofficesystempeopleid = @BackOfficeSystemPeopleID
update @Temp
set BOSPID = isnull((select backofficepeopleid from vwbackofficelinkedusers where userid = userid2), 0)
where BOSPID = 0
update @Temp
set UserID2 = (select userid from vwbackofficelinkedusers where backofficepeopleid = BOSPID)
where UserID2 is null
delete from @Temp where userid2 is null or BOSPID = 0
delete from emaillist_subscription
where id in (select t.id from @Temp t inner join @Temp t2 on t.listid = t2.listid and t.updatedate < t2.updatedate)
update emaillist_subscription set backofficesystempeopleid = BOSPID, userid = userid2
from @Temp t
where t.id = emaillist_subscription.id
commit
end