USP_DISCOUNTGROUPSIZE_DELETE

Executes the "Discount Group Size: Delete" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being deleted.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the delete.
@GROUPSIZEDISCOUNTID uniqueidentifier IN

Definition

Copy


CREATE procedure dbo.USP_DISCOUNTGROUPSIZE_DELETE
(
    @ID uniqueidentifier,        -- This is the DISCOUNTID for the GROUPSIZEDISCOUNTID; platform needs something called ID, and the PostActionEvent on the Discount page won't find the new page context ID if the GROUPSIZEDISCOUNTID's ID is the action's context ID.    

    @CHANGEAGENTID uniqueidentifier,
    @GROUPSIZEDISCOUNTID uniqueidentifier = null
)
as begin

    declare @GROUPSIZE int;
    select
        @GROUPSIZE = GROUPSIZE
    from dbo.GROUPSIZEDISCOUNT
    where ID = @GROUPSIZEDISCOUNTID;

    if (
        select count(*)
        from dbo.GROUPSIZEDISCOUNT
        where DISCOUNTID = @ID
    ) <= 1
    begin
        raiserror('BBERR_ONEGROUPREQUIRED', 13, 1);
        return 1;
    end

    -- Since this deletion may affect how historical order balances would be recalculated after a refund, we have to copy the whole thing.


    declare @CLONEID uniqueidentifier;
    exec dbo.USP_DISCOUNT_CLONE @ID, @CLONEID output;

    -- Delete copied record if applicable (clone didn't happen if no orders were sold with this discount).

    if @ID <> @CLONEID
    begin
        set @GROUPSIZEDISCOUNTID = (select ID from dbo.GROUPSIZEDISCOUNT where DISCOUNTID = @CLONEID and GROUPSIZE = @GROUPSIZE);
    end

    exec USP_GROUPSIZEDISCOUNT_DELETEBYID_WITHCHANGEAGENTID @GROUPSIZEDISCOUNTID, @CHANGEAGENTID;

    -- Update the DISCOUNT record to invalidate the cache for sales.

    update dbo.DISCOUNT
    set CHANGEDBYID = @CHANGEAGENTID, DATECHANGED = getdate()
    where ID = @ID;

    return 0;
end