DROP PROCEDURE SP_InsProcIN_INTRAITEMParaToma
GO
CREATE PROCEDURE SP_InsProcIN_INTRAITEMParaToma
(
    @SITEID            UD_IDSITE,
    @BATNBR            char(10),
    @TYPEDOCID         UD_TYPEDOC,
    @SEQUENCE          smallint,
    @INVTIDSKU         UD_IDCORPORATIVO,
    @INVTIDBARR        UD_CODIGOBARRA              = NULL,
    @QTY               UD_STOCK,
    @TAXIGV            numeric(4, 2)               = NULL,
    @STDCOSTPEN        UD_COSTO,
    @STDCOSTUSD        UD_COSTO,
    @STKFISI           bit,
    @INTRDATE          smalldatetime,
    @INTRDATEPROCE     smalldatetime,
    @RLSED             bit,
    @TAXISC            numeric(4, 2),
    @STDCOSTPENOLD     UD_COSTO,	
    @STDCOSTUSDOLD     UD_COSTO,
    @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

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

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

    RETURN(0)

END