USP_GIFTFEE_GETGIFTFEESTRUCTURE_CUSTOMUPDATEFROMXML
Updates the Gift Fee Structure table from the xml passed to it from the grid.
Parameters
| Parameter | Parameter Type | Mode | Description | 
|---|---|---|---|
| @XML | xml | IN | |
| @CHANGEAGENTID | uniqueidentifier | IN | |
| @CHANGEDATE | datetime | IN | |
| @CURRENTAPPUSERID | uniqueidentifier | IN | 
Definition
 Copy 
                                    
            CREATE procedure [dbo].[USP_GIFTFEE_GETGIFTFEESTRUCTURE_CUSTOMUPDATEFROMXML] 
            (
                @XML xml,
                @CHANGEAGENTID uniqueidentifier = null,
                @CHANGEDATE datetime = null,
                @CURRENTAPPUSERID uniqueidentifier = null
            )
            as
                set nocount on;
                if @CHANGEAGENTID is null
                    exec USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
                if @CHANGEDATE is null 
                    set @CHANGEDATE = getdate();
                -- build a temporary table containing the values from the XML
                declare @TempTbl table (
                   [ID] uniqueidentifier,
                   [FEE] numeric(6, 2),
                   [FROMAMOUNT] money)
                insert into @TempTbl select 
                    [ID],
                    [FEE],
                    [FROMAMOUNT]
                from dbo.UFN_GIFTFEE_GETGIFTFEESTRUCTURE_FROMITEMLISTXML(@XML);
                update @TempTbl set ID = newid() where (ID is null) or (ID = '00000000-0000-0000-0000-000000000000');
                if @@Error <> 0
                    return 1;
                declare @contextCache varbinary(128);
                declare @e int;
                -- cache current context information 
                set @contextCache = CONTEXT_INFO();
                -- set CONTEXT_INFO to @CHANGEAGENTID 
                if not @CHANGEAGENTID is null
                    set CONTEXT_INFO @CHANGEAGENTID;                
                -- delete any items that no longer exist in the XML table
                delete from dbo.[GIFTFEESTRUCTURE] where [GIFTFEESTRUCTURE].ID in 
                    (select ID from dbo.UFN_GIFTFEE_GETGIFTFEESTRUCTURE()
                    EXCEPT select ID from @TempTbl)    
                select @e=@@error;
                -- reset CONTEXT_INFO to previous value 
                if not @contextCache is null
                    set CONTEXT_INFO @contextCache;
                if @e <> 0
                    return 2;
                -- update the items that exist in the XML table and the db
                update [GIFTFEESTRUCTURE]
                        set [GIFTFEESTRUCTURE].[ID]=temp.[ID],
                        [GIFTFEESTRUCTURE].[FROMAMOUNT]=temp.[FROMAMOUNT],
                        [GIFTFEESTRUCTURE].[FEE]=temp.[FEE],
                        [GIFTFEESTRUCTURE].CHANGEDBYID = @CHANGEAGENTID,
                        [GIFTFEESTRUCTURE].DATECHANGED = @CHANGEDATE
                    from dbo.[GIFTFEESTRUCTURE] inner join @TempTbl as temp on [GIFTFEESTRUCTURE].ID = temp.ID
                    where ([GIFTFEESTRUCTURE].[ID]<>temp.[ID]) or 
                        ([GIFTFEESTRUCTURE].[ID] is null and temp.[ID] is not null) or 
                        ([GIFTFEESTRUCTURE].[ID] is not null and temp.[ID] is null) or 
                        ([GIFTFEESTRUCTURE].[FROMAMOUNT]<>temp.[FROMAMOUNT]) or 
                        ([GIFTFEESTRUCTURE].[FROMAMOUNT] is null and temp.[FROMAMOUNT] is not null) or 
                        ([GIFTFEESTRUCTURE].[FROMAMOUNT] is not null and temp.[FROMAMOUNT] is null) or
                        ([GIFTFEESTRUCTURE].[FEE]<>temp.[FEE]) or 
                        ([GIFTFEESTRUCTURE].[FEE] is null and temp.[FEE] is not null) or 
                        ([GIFTFEESTRUCTURE].[FEE] is not null and temp.[FEE] is null)
                    if @@Error <> 0
                        return 3;    
                    -- insert new items
                    insert into [GIFTFEESTRUCTURE](
                        [ID],
                        [FROMAMOUNT],
                        [FEE],
                        ADDEDBYID, 
                        CHANGEDBYID, 
                        DATEADDED, 
                        DATECHANGED)
                    select 
                        [ID],
                        [FROMAMOUNT], 
                        [FEE],
                        @CHANGEAGENTID, 
                        @CHANGEAGENTID, 
                        @CHANGEDATE, 
                        @CHANGEDATE
                    from @TempTbl as temp
                    where not exists (select ID from dbo.[GIFTFEESTRUCTURE] as DATA where DATA.ID = TEMP.ID)
                    if @@Error <> 0
                        return 4;
                    return 0;