USP_DATAFORMTEMPLATE_ADD_PRICELISTCOPY
The save procedure used by the add dataform template "Price List Copy Add Data Form".
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | INOUT | The output parameter indicating the ID of the record added. |
@CONTEXTID | uniqueidentifier | IN | Input parameter indicating the context ID for the record being added. |
@NAME | nvarchar(100) | IN | Name |
@DESCRIPTION | nvarchar(255) | IN | Description |
@PRICES | xml | IN | Prices |
@PROGRAMS | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the procedure. |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_PRICELISTCOPY
(
@ID uniqueidentifier = null output,
@CONTEXTID uniqueidentifier,
@NAME nvarchar(100) = '',
@DESCRIPTION nvarchar(255) = '',
@PRICES xml = null,
@PROGRAMS xml = null,
@CHANGEAGENTID uniqueidentifier = null
)
as
set nocount on;
if @ID is null
set @ID = newid()
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()
begin try
-- Check for any daily sales buttons that would be gutted by the change.
-- This was in PriceList.Edit but not here...
if exists(
select
ID
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))
)
begin
raiserror('BBERR_DAILYSALES_PRICETYPESINUSE', 13, 1)
end
insert into dbo.PRICELIST
(
ID,
NAME,
DESCRIPTION,
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED
)
values
(
@ID,
@NAME,
@DESCRIPTION,
@CHANGEAGENTID,
@CHANGEAGENTID,
@CURRENTDATE,
@CURRENTDATE
)
declare @NEWPRICES table (
NEWPRICEID uniqueidentifier,
FACEPRICE money,
PRICETYPECODEID uniqueidentifier,
SEQUENCE int
)
-- Create new PRICEIDs
insert into @NEWPRICES
select
newid(),
T.c.value('(FACEPRICE)[1]','money') AS 'FACEPRICE',
T.c.value('(PRICETYPECODEID)[1]','uniqueidentifier') AS 'PRICETYPECODEID',
T.c.value('(SEQUENCE)[1]','int') AS 'SEQUENCE'
from @PRICES.nodes('/PRICES/ITEM') T(c)
-- Add new PRICEs from id we created in @NEWPRICES
insert into dbo.PRICE
(
ID,
PRICELISTID,
PRICETYPECODEID,
FACEPRICE,
SEQUENCE,
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED
)
(
select
PL.NEWPRICEID,
@ID,
PL.PRICETYPECODEID,
PL.FACEPRICE,
SEQUENCE,
@CHANGEAGENTID,
@CHANGEAGENTID,
@CURRENTDATE,
@CURRENTDATE
from
@NEWPRICES PL
)
exec dbo.USP_PRICELIST_UPDATEPROGRAMPRICE @ID, @PRICES, @PROGRAMS;
end try
begin catch
exec dbo.USP_RAISE_ERROR
return 1
end catch
return 0