USP_DATAFORMTEMPLATE_ADD_MERCHANDISEPRODUCTBULKLABELPRINT

The save procedure used by the add dataform template "Merchandise Item Bulk Label Print Add Data Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@PRODUCTLABELS xml IN Labels to print
@EXPORT bit IN Export to file
@LABELPRINTFORMATCODE tinyint IN Label print format

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_MERCHANDISEPRODUCTBULKLABELPRINT
(
    @ID uniqueidentifier = null output,
    @CHANGEAGENTID uniqueidentifier = null,    
    @PRODUCTLABELS xml = null,
    @EXPORT bit = null,
    @LABELPRINTFORMATCODE tinyint = 0    
)
as

set nocount on;

if not exists (select * from @PRODUCTLABELS.nodes('/PRODUCTLABELS/ITEM') T(item) where T.item.value('(QUANTITYTOPRINT)[1]','integer') > 0)
begin
    if @EXPORT <> 0
        raiserror('ERR_MERCHANDISEPRODUCTLABELPRINT_QUANTITYEXPORT', 13, 1);
    else
        raiserror('ERR_MERCHANDISEPRODUCTLABELPRINT_QUANTITYPRINT', 13, 1);

    return 1
end    

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

    insert into dbo.MERCHANDISEPRODUCTLABLEPRINTHISTORY
        (ID,
        MERCHANDISEPRODUCTID,
        MERCHANDISEPRODUCTINSTANCEID,
        ITEMDETAILS,
        PRINTSESSIONID,
        QUANTITY,
        BARCODE,
        SALEPRICE,
        ISEXPORT,
        LABELPRINTFORMATCODE,
        ADDEDBYID,
        CHANGEDBYID,
        DATEADDED,
        DATECHANGED)
    select
        newid(),
        MERCHANDISEPRODUCTINSTANCE.MERCHANDISEPRODUCTID,
        T.item.value('(ID)[1]','uniqueidentifier'),
        MERCHANDISEPRODUCTINSTANCE.ITEMDETAILS,
        @ID,
        T.item.value('(QUANTITYTOPRINT)[1]','integer'),
        MERCHANDISEPRODUCTINSTANCE.BARCODE,
        MERCHANDISEPRODUCTINSTANCE.SALEPRICE,
        @EXPORT,
        @LABELPRINTFORMATCODE,
        @CHANGEAGENTID,
        @CHANGEAGENTID,
        @CURRENTDATE,        
        @CURRENTDATE
    from 
        @PRODUCTLABELS.nodes('/PRODUCTLABELS/ITEM') T(item) inner join dbo.MERCHANDISEPRODUCTINSTANCE on
            T.item.value('(ID)[1]','uniqueidentifier') = MERCHANDISEPRODUCTINSTANCE.ID
    where
        T.item.value('(QUANTITYTOPRINT)[1]','integer') > 0

end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0