USP_DATAFORMTEMPLATE_EDIT_DISCOUNTGROUPSIZE
The save procedure used by the edit dataform template "Discount Group Size Edit Data 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. |
@GROUPSIZES | xml | IN | Size restrictions |
@CALCULATIONTYPECODE | tinyint | IN | Calculation type |
Definition
Copy
CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_DISCOUNTGROUPSIZE
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier,
@GROUPSIZES xml,
@CALCULATIONTYPECODE tinyint
)
as
set nocount on;
if @CHANGEAGENTID is null
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;
declare @CURRENTDATE datetime = getdate();
declare @CLONEID uniqueidentifier;
exec dbo.USP_DISCOUNT_CLONE @ID, @CLONEID output;
-- After we clone, all the ID's in GROUPSIZES xml are invalid. The easy fix is to change the ID's and update as before (causing a delete and re-add).
set @GROUPSIZES = (
select newid() as ID, GROUPSIZE, AMOUNT, [PERCENT]
from dbo.UFN_DISCOUNT_GETGROUPSIZES_FROMITEMLISTXML(@GROUPSIZES)
for xml path('ITEM'),type,elements,root('GROUPSIZES'),BINARY BASE64
)
begin try
update dbo.[DISCOUNT]
set [CALCULATIONTYPECODE] = @CALCULATIONTYPECODE,
[DATECHANGED] = @CURRENTDATE,
[CHANGEDBYID] = @CHANGEAGENTID
where [ID] = @CLONEID
exec dbo.USP_DISCOUNT_GETGROUPSIZES_UPDATEFROMXML @CLONEID, @GROUPSIZES, @CHANGEAGENTID, @CURRENTDATE;
--This will trigger validation of all amount and percent fields
--if only the calculationtypecode is changed
update dbo.[GROUPSIZEDISCOUNT]
set [DATECHANGED] = @CURRENTDATE,
[CHANGEDBYID] = @CHANGEAGENTID
where [DISCOUNTID] = @CLONEID
end try
begin catch
exec dbo.USP_RAISE_ERROR;
return 1;
end catch
return 0;