USP_REVENUESPLIT_PULLSOLICITORSFROMOPPORTUNITY
Adds solicitors for a given revenue split record based on the given opportunity and the solicitor credit rules.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@REVENUESPLITID | uniqueidentifier | IN | |
@OPPORTUNITYID | uniqueidentifier | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CURRENTDATE | datetime | IN |
Definition
Copy
CREATE procedure USP_REVENUESPLIT_PULLSOLICITORSFROMOPPORTUNITY
(
@REVENUESPLITID uniqueidentifier,
@OPPORTUNITYID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier,
@CURRENTDATE datetime
)
as begin
set nocount on;
declare @PROSPECTPLANID uniqueidentifier
declare @AMOUNT money
declare @PREVIOUSOPPORTUNITYID uniqueidentifier
select
@PROSPECTPLANID = PROSPECTPLANID
from
dbo.OPPORTUNITY
where
ID = @OPPORTUNITYID
select
@AMOUNT = REVENUESPLIT.AMOUNT,
@PREVIOUSOPPORTUNITYID = REVENUEOPPORTUNITY.OPPORTUNITYID
from
dbo.REVENUESPLIT
left join dbo.REVENUEOPPORTUNITY on REVENUEOPPORTUNITY.ID = REVENUESPLIT.ID
where
REVENUESPLIT.ID = @REVENUESPLITID
-- Load the default solicitors for the split if it:
-- 1. has no solicitors -- No longer true, WI #397224 now has active solicitors being overwritten by new defaulted solicitors
-- 2. had a null opportunity before, or had an opportunity change.
-- 3. is of a type that's active
if (@PREVIOUSOPPORTUNITYID is not null and @PREVIOUSOPPORTUNITYID = @OPPORTUNITYID)
return
if (dbo.UFN_SOLICITORCREDITRULES_ACTIVEFORREVENUESPLIT(@REVENUESPLITID) <> 1)
return
if((select count(ID) from dbo.UFN_PROSPECTPLAN_GETFUNDRAISERSANDCREDITS_2(@PROSPECTPLANID, @OPPORTUNITYID) as SOLICITORS) > 0)
begin
declare @contextCache varbinary(128);
-- cache current context information
set @contextCache = context_info();
-- set CONTEXT_INFO to @CHANGEAGENTID
if not @CHANGEAGENTID is null
set context_info @CHANGEAGENTID;
-- delete active solicitors before inserting new defaulted solicitors
delete from dbo.REVENUESOLICITOR where REVENUESPLITID = @REVENUESPLITID;
-- reset CONTEXT_INFO to previous value
if not @contextCache is null
set context_info @contextCache;
end
insert into dbo.REVENUESOLICITOR
(
REVENUESPLITID,
CONSTITUENTID,
AMOUNT,
SEQUENCE,
DATEADDED,
DATECHANGED,
ADDEDBYID,
CHANGEDBYID
)
select
@REVENUESPLITID,
SOLICITORS.ID,
(SOLICITORS.CREDITPERCENTAGE * @AMOUNT) / 100.0,
SOLICITORS.SEQUENCE,
@CURRENTDATE,
@CURRENTDATE,
@CHANGEAGENTID,
@CHANGEAGENTID
from
dbo.UFN_PROSPECTPLAN_GETFUNDRAISERSANDCREDITS_2(@PROSPECTPLANID, @OPPORTUNITYID) as SOLICITORS
end