USP_DATAFORMTEMPLATE_ADD_TICKETPRINTINFO_INITIAL

The save procedure used by the add dataform template "Order Generate Initial Ticket Instances Data Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@ORDERID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@WORKSTATIONID uniqueidentifier IN
@PROGRAMID uniqueidentifier IN
@WORKSTATIONMACHINENAME nvarchar(255) IN

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_TICKETPRINTINFO_INITIAL
(
    @ID uniqueidentifier = null output,
    @ORDERID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @CURRENTAPPUSERID uniqueidentifier = null,
    @WORKSTATIONID uniqueidentifier = null,
    @PROGRAMID uniqueidentifier = null,
    @WORKSTATIONMACHINENAME nvarchar(255) = null
)
as

set nocount on;

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

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

declare @CURRENTDATETIMEOFFSET datetimeoffset
set @CURRENTDATETIMEOFFSET = dbo.UFN_TIMEZONEENTRY_GETSYSTEMDEFAULTDATEWITHTIMEOFFSET(getutcdate(), 1)

begin try
    if @WORKSTATIONID is null and (@WORKSTATIONMACHINENAME is not null or @WORKSTATIONMACHINENAME <> '') begin
        set @WORKSTATIONID = dbo.UFN_WORKSTATION_GETIDBYMACHINENAME(@WORKSTATIONMACHINENAME);
    end

    -- Be careful and make sure that the newid() function is used
    -- for this insert since multiple tickets may be created.
    insert into dbo.TICKETPRINTINFO
    (
        ID,
        TICKETID,
        APPUSERID,
        WORKSTATIONID,
        PRINTDATEWITHTIMEOFFSET,
        ADDEDBYID,
        CHANGEDBYID,
        DATEADDED,
        DATECHANGED
    )
    select
        newid(),
        TICKET.ID,
        @CURRENTAPPUSERID,
        @WORKSTATIONID,
        @CURRENTDATETIMEOFFSET,
        @CHANGEAGENTID,
        @CHANGEAGENTID,
        @CURRENTDATE,
        @CURRENTDATE
    from
        dbo.TICKET
        inner join dbo.SALESORDERITEM SOI on SOI.ID = TICKET.SALESORDERITEMTICKETID
    where
        SOI.SALESORDERID = @ORDERID
        and TICKET.PROGRAMID = @PROGRAMID;

    return 0;
end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0