DROP PROCEDURE IN_INTRAHEADUpdProc
GO
CREATE PROCEDURE IN_INTRAHEADUpdProc
(
    @SITEID            UD_IDSITE,
    @BATNBR            char(10),
    @TYPEDOCID         UD_TYPEMOVEID,
    @VENDIDSS          UD_IDVENDOR,
    @DOCTYPEID         UD_DOCTYPEID,
    @DOCSTATUSID       char(2),
    @REFNBR            char(10),
    @CURYRATE          numeric(6, 4),
    @TOCURYID          char(3),
    @FROMCURYID        char(3),
    @SITEPROCES        UD_IDSITE,
    @NBRORDER          char(10)                 = NULL,
    @DATENBRORDER      smalldatetime            = NULL,
    @USERIDORDER       UD_USERID                = NULL,
    @INTRDATE          smalldatetime,
    @INTRDATEPROCE     smalldatetime,
    @SITEDEST          UD_IDSITE,
    @INTRTOTPEN        numeric(9, 2),
    @INTRTAXPEN        numeric(9, 2),
    @INTRTOTUSD        numeric(9, 2),
    @INTRTAXUSD        numeric(9, 2),
    @PERPOST           char(6),
    @RLSED             bit,
    @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,
    @TSTAMP            timestamp)
AS
BEGIN
    BEGIN TRAN

    UPDATE IN_INTRAHEAD
       SET VENDIDSS           = @VENDIDSS,
           DOCTYPEID          = @DOCTYPEID,
           DOCSTATUSID        = @DOCSTATUSID,
           REFNBR             = @REFNBR,
           CURYRATE           = @CURYRATE,
           TOCURYID           = @TOCURYID,
           FROMCURYID         = @FROMCURYID,
           SITEPROCES         = @SITEPROCES,
           NBRORDER           = @NBRORDER,
           DATENBRORDER       = @DATENBRORDER,
           USERIDORDER        = @USERIDORDER,
           INTRDATE           = @INTRDATE,
           INTRDATEPROCE      = @INTRDATEPROCE,
           SITEDEST           = @SITEDEST,
           INTRTOTPEN         = @INTRTOTPEN,
           INTRTAXPEN         = @INTRTAXPEN,
           INTRTOTUSD         = @INTRTOTUSD,
           INTRTAXUSD         = @INTRTAXUSD,
           PERPOST            = @PERPOST,
           RLSED              = @RLSED,
           USER1              = @USER1,
           USER2              = @USER2,
           USER3              = @USER3,
           USER4              = @USER4,
           USER5              = @USER5,
           USER6              = @USER6,
           USER7              = @USER7,
           USER8              = @USER8,
           USER9              = @USER9
     WHERE SITEID    = @SITEID
       AND BATNBR    = @BATNBR
       AND TYPEDOCID = @TYPEDOCID

    IF (@@error!=0)
    BEGIN
        RAISERROR  20001 'IN_INTRAHEADUpdProc: Cannot update  in IN_INTRAHEAD '
        ROLLBACK TRAN
        RETURN(1)
    
    END

    COMMIT TRAN

    RETURN(0)
END
