USP_PROGRAMDISCOUNT_COPY

Copies discount/s from one program to another.

Parameters

Parameter Parameter Type Mode Description
@SOURCEPROGRAMID uniqueidentifier IN
@DESTINATIONPROGRAMID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN

Definition

Copy


            create procedure dbo.USP_PROGRAMDISCOUNT_COPY
            (
                @SOURCEPROGRAMID uniqueidentifier,
                @DESTINATIONPROGRAMID uniqueidentifier,
                @CHANGEAGENTID uniqueidentifier = null
            )
            with execute as caller
            as
                set nocount on;

                -- Cannot copy if the source program does not have discounts associated with it

                if not exists (select ID from dbo.PROGRAMDISCOUNT where PROGRAMID = @SOURCEPROGRAMID)
                    raiserror('The source program does not have any discounts.',13,1);

                declare @CURRENTDATE datetime;
                set @CURRENTDATE = getdate();

                if @CHANGEAGENTID is null
                    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

                insert into dbo.PROGRAMDISCOUNT
                (
                    ID,
                    PROGRAMID,
                    DISCOUNTID,
                    ADDEDBYID,
                    CHANGEDBYID,
                    DATEADDED,
                    DATECHANGED
                )
                select
                    newid(),
                    @DESTINATIONPROGRAMID,
                    DISCOUNTID,
                    @CHANGEAGENTID,
                    @CHANGEAGENTID,
                    @CURRENTDATE,
                    @CURRENTDATE
                from dbo.PROGRAMDISCOUNT
                where
                    PROGRAMID = @SOURCEPROGRAMID;

                return 0;