USP_DATAFORMTEMPLATE_PRELOAD_ADD_PLEDGEFROMOPPORTUNITY

The load procedure used by the edit dataform template "Pledge From Opportunity Add Form"

Parameters

Parameter Parameter Type Mode Description
@OPPORTUNITYID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@SINGLEDESIGNATIONID uniqueidentifier INOUT Designation
@HOUSEHOLDSCANBEDONORS bit INOUT Households can be donors
@AMOUNT money INOUT Amount
@SPLITS xml INOUT Designations
@CONSTITUENTID uniqueidentifier INOUT Constituent
@OPPORTUNITYCONSTITUENT nvarchar(154) INOUT Opportunity constituent
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@PDACCOUNTSYSTEMID uniqueidentifier INOUT Account system
@SHOWACCOUNTSYSTEM bit INOUT ShowSystem
@TRANSACTIONCURRENCYID uniqueidentifier INOUT Transaction currency
@BASEEXCHANGERATEID uniqueidentifier INOUT Exchange rate ID
@EXCHANGERATE decimal(20, 8) INOUT Exchange rate
@ALLOWGLDISTRIBUTIONS bit INOUT

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_PRELOAD_ADD_PLEDGEFROMOPPORTUNITY
(
    @OPPORTUNITYID uniqueidentifier,
    @SINGLEDESIGNATIONID uniqueidentifier = null output,
    @HOUSEHOLDSCANBEDONORS bit = null output,
    @AMOUNT money = null output,
    @SPLITS xml = null output,
    @CONSTITUENTID uniqueidentifier = null output,
    @OPPORTUNITYCONSTITUENT nvarchar(154) = null output,
    @CURRENTAPPUSERID uniqueidentifier = null,
    @PDACCOUNTSYSTEMID uniqueidentifier = null output,
    @SHOWACCOUNTSYSTEM bit = null output,
    @TRANSACTIONCURRENCYID uniqueidentifier = null output,
    @BASEEXCHANGERATEID uniqueidentifier = null output,
    @EXCHANGERATE decimal(20,8) = null output,
  @ALLOWGLDISTRIBUTIONS bit = null output
)
as
    set nocount on;

    -- Leaving SINGLEDESIGNATIONID as null.  No value needs to be set for it since

    -- it existed as a readonly field before the load SP was added.


    declare @OPPORTUNITYTRANSACTIONCURRENCYID uniqueidentifier;

    select 
    @CONSTITUENTID = PROSPECTPLAN.PROSPECTID,
    @OPPORTUNITYCONSTITUENT = NF.NAME,
    @OPPORTUNITYTRANSACTIONCURRENCYID = OPPORTUNITY.TRANSACTIONCURRENCYID
    from 
    dbo.OPPORTUNITY 
    inner join 
    dbo.PROSPECTPLAN on PROSPECTPLAN.ID = OPPORTUNITY.PROSPECTPLANID
    outer apply dbo.UFN_CONSTITUENT_DISPLAYNAME(PROSPECTPLAN.PROSPECTID) NF
    where 
    OPPORTUNITY.ID = @OPPORTUNITYID;

    set @HOUSEHOLDSCANBEDONORS = dbo.UFN_INSTALLATIONINFO_GETHOUSEHOLDSCANBEDONORS()

    if dbo.UFN_VALID_BASICGL_INSTALLED() != 0
    begin
      declare @NUMBEROFACCOUNTSYSTEMSFORUSER smallint;

      set @NUMBEROFACCOUNTSYSTEMSFORUSER = dbo.UFN_PDACCOUNTSYSTEM_GETNUMBEROFSYSTEMSFORUSER(@CURRENTAPPUSERID)
      if @NUMBEROFACCOUNTSYSTEMSFORUSER = 1
        begin
            set @SHOWACCOUNTSYSTEM = 0
            select @PDACCOUNTSYSTEMID =  T1.ID from dbo.UFN_PDACCOUNTSYSTEM_GETSYSTEMIDSFORUSER(@CURRENTAPPUSERID) as T1
        end 
      else
        begin
            set @SHOWACCOUNTSYSTEM = 1
            set @PDACCOUNTSYSTEMID = dbo.UFN_PDACCOUNTSYSTEM_GETDEFAULTSYSTEMIDSFORUSER(@CURRENTAPPUSERID)
        end 
    end
    else
    begin
        set @SHOWACCOUNTSYSTEM = 0
        set @PDACCOUNTSYSTEMID = '4B121C2C-CCE6-440D-894C-EA0DEF80D50B'
    end

    if exists(select PDACCOUNTSYSTEM.ID 
                from dbo.PDACCOUNTSYSTEM
                inner join dbo.CURRENCYSET on PDACCOUNTSYSTEM.CURRENCYSETID = CURRENCYSET.ID
                inner join dbo.CURRENCYSETTRANSACTIONCURRENCY on CURRENCYSET.ID = CURRENCYSETTRANSACTIONCURRENCY.CURRENCYSETID
                where CURRENCYSETTRANSACTIONCURRENCY.CURRENCYID = @OPPORTUNITYTRANSACTIONCURRENCYID
                        and CURRENCYSET.BASECURRENCYID != @OPPORTUNITYTRANSACTIONCURRENCYID
                        and PDACCOUNTSYSTEM.ID = @PDACCOUNTSYSTEMID)
    begin
        set @TRANSACTIONCURRENCYID = @OPPORTUNITYTRANSACTIONCURRENCYID;
        set @BASEEXCHANGERATEID = dbo.UFN_CURRENCYEXCHANGERATE_GETLATEST(@OPPORTUNITYTRANSACTIONCURRENCYID, (select BASECURRENCYID from dbo.PDACCOUNTSYSTEM left join dbo.CURRENCYSET on PDACCOUNTSYSTEM.CURRENCYSETID = CURRENCYSET.ID where PDACCOUNTSYSTEM.ID = @PDACCOUNTSYSTEMID), getdate(), 1, null)
        set @EXCHANGERATE = coalesce((select RATE from dbo.CURRENCYEXCHANGERATE where ID = @BASEEXCHANGERATEID), 1)
    end
    else
    begin
        --Set the transaction currency initially to the base currency of the account system.

        select 
            @TRANSACTIONCURRENCYID = BASECURRENCYID,
            @EXCHANGERATE = 1
        from 
            dbo.PDACCOUNTSYSTEM
            left join dbo.CURRENCYSET on PDACCOUNTSYSTEM.CURRENCYSETID = CURRENCYSET.ID
        where
            PDACCOUNTSYSTEM.ID = @PDACCOUNTSYSTEMID;
    end

    --TYPECODE = 0; APPLICATIONCODE = 0

    set @SPLITS = dbo.UFN_REVENUE_BUILDSPLITSFOROPPORTUNITYGIFTINCURRENCY(@OPPORTUNITYID, 0, 0, @TRANSACTIONCURRENCYID);
    select @AMOUNT = sum(AMOUNT) from dbo.UFN_REVENUE_GETSPLITS_2_FROMITEMLISTXML(@SPLITS);

    -- Check GL business rule for this account system and set to 'Do not post' if needed.

    set @ALLOWGLDISTRIBUTIONS = dbo.UFN_PDACCOUNTSYSTEM_ALLOWGLDISTRIBUTIONS(@PDACCOUNTSYSTEMID);

    return 0;