USP_DATAFORMTEMPLATE_EDIT_PRICELIST

The save procedure used by the edit dataform template "Price List Edit Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@NAME nvarchar(100) IN Name
@DESCRIPTION nvarchar(255) IN Description
@PRICES xml IN Prices
@PROGRAMS xml IN This price list will be saved to these programs

Definition

Copy


                CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_PRICELIST 
                (
                    @ID uniqueidentifier,
                    @CHANGEAGENTID uniqueidentifier = null,
                    @NAME nvarchar(100),
                    @DESCRIPTION nvarchar(255),
                    @PRICES xml,
                    @PROGRAMS xml
                )
                as

                    set nocount on;

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

                    declare @CURRENTDATE datetime
                    set @CURRENTDATE = getdate()

                    begin try
                        declare @DAILYSALEBUTTONPROGRAMS table(PROGRAMID uniqueidentifier, PRICETYPECODEID uniqueidentifier)
                        insert into @DAILYSALEBUTTONPROGRAMS
                        select
                            PROGRAMID,
                            PRICETYPECODEID
                        from dbo.DAILYSALEITEMPROGRAM
                        where PROGRAMID in (select T.c.value('(ID)[1]','uniqueidentifier') from @PROGRAMS.nodes('/PROGRAMS/ITEM') T(c))
                        and PRICETYPECODEID not in (select T.c.value('(PRICETYPECODEID)[1]','uniqueidentifier') from @PRICES.nodes('/PRICES/ITEM') T(c))

                        if exists(select top(1) PROGRAMID from @DAILYSALEBUTTONPROGRAMS) raiserror('BBERR_DAILYSALES_PRICETYPESINUSE', 13, 1)

                        update 
                            dbo.PRICELIST 
                        set
                            NAME = @NAME,
                            DESCRIPTION = @DESCRIPTION,
                            CHANGEDBYID = @CHANGEAGENTID,
                            DATECHANGED = @CURRENTDATE
                        where
                            ID = @ID

                        exec dbo.USP_PRICELIST_GETPRICES_UPDATEFROMXML @ID, @PRICES, @CHANGEAGENTID, @CURRENTDATE;

                        exec dbo.USP_PRICELIST_UPDATEPROGRAMPRICE @ID, @PRICES, @PROGRAMS;    

                        -- Break any links to programs that were connected to this changed price list

                        -- but were removed from the Program list

                        update dbo.PROGRAM set
                            PRICELISTID = null,
                            CHANGEDBYID = @CHANGEAGENTID,
                            DATECHANGED = @CURRENTDATE
                        where 
                            ID not in
                            (
                                select T.c.value('(ID)[1]','uniqueidentifier') from
                                @PROGRAMS.nodes('/PROGRAMS/ITEM') T(c)
                            )
                            and
                            ID in
                            (
                                select PROGRAM.ID as ID
                                from dbo.PROGRAM
                                where PROGRAM.PRICELISTID = @ID
                            )

                    end try
                    begin catch
                        exec dbo.USP_RAISE_ERROR
                        return 1
                    end catch

                return 0;