CREATE PROCEDURE SP_InsProcTMP_IN_INTRAITEM
(
    @CORRNBR           int,
    @SITEID            UD_IDSITE,
    @TYPEDOCID         UD_TYPEMOVEID,
    @SEQUENCE          smallint,
    @INVTIDSKU         UD_IDCORPORATIVO,
    @INVTIDBARR        UD_CODIGOBARRA              = NULL,
    @QTY               numeric(10, 3),
    @TAXIGV            numeric(4, 2)               = NULL,
    @STDCOSTPEN        numeric(8, 4),
    @STDCOSTUSD        numeric(8, 4),
    @STKFISI           bit,
    @INTRDATE          smalldatetime,
    @INTRDATEPROCE     smalldatetime,
    @RLSED             bit,
    @TAXISC            numeric(4, 2),
    @USER1             UD_USER1                    = NULL,
    @USER2             UD_USER2                    = NULL,
    @USER3             UD_USER3                    = NULL,
    @USER4             UD_USER5                    = NULL,
    @USER5             UD_USER5                    = NULL,
    @USER6             UD_USER6                    = NULL,
    @USER7             UD_USER7                    = NULL,
    @USER8             UD_USER8                    = NULL,
    @USER9             UD_USER9                    = NULL)
AS
BEGIN
    BEGIN TRAN

    INSERT INTO TMP_IN_INTRAITEM(CORRNBR,
                                 SITEID,
                                 TYPEDOCID,
                                 SEQUENCE,
                                 INVTIDSKU,
                                 INVTIDBARR,
                                 QTY,
                                 TAXIGV,
                                 STDCOSTPEN,
                                 STDCOSTUSD,
                                 STKFISI,
                                 INTRDATE,
                                 INTRDATEPROCE,
                                 RLSED,
                                 TAXISC,
                                 USER1,
                                 USER2,
                                 USER3,
                                 USER4,
                                 USER5,
                                 USER6,
                                 USER7,
                                 USER8,
                                 USER9 
                                 )
    VALUES(@CORRNBR,
           @SITEID,
           @TYPEDOCID,
           @SEQUENCE,
           @INVTIDSKU,
           @INVTIDBARR,
           @QTY,
           @TAXIGV,
           @STDCOSTPEN,
           @STDCOSTUSD,
           @STKFISI,
           @INTRDATE,
           @INTRDATEPROCE,
           @RLSED,
           @TAXISC,
           @USER1,
           @USER2,
           @USER3,
           @USER4,
           @USER5,
           @USER6,
           @USER7,
           @USER8,
           @USER9 
           )

    IF (@@error!=0)
    BEGIN
        RAISERROR  20000 'SP_InsProcTMP_IN_INTRAITEM: Cannot insert because primary key value not found in TMP_IN_INTRAITEM '
        ROLLBACK TRAN
        RETURN(1)
    
    END

    COMMIT TRAN

END
