DROP PROCEDURE TMP_OP_DEPOSITSITEDETInsProc
GO
CREATE PROCEDURE TMP_OP_DEPOSITSITEDETInsProc
(
    @CORRNBR		   INT,	
    @SITEID                UD_IDSITE,
    @DATEPROCE		   UD_FECHA,
    @CUSTIDSS 		   UD_CODCLIENT,
    @REFERENCE             numeric(10, 0),
    @DEPOSITPASSWORD       char(20),
    @DATEDEPOSIT           UD_FECHA,
    @CURYID                UD_CURYID,
    @CURYRATE              UD_CURYRATE,
    @TOTALPEN              UD_MONTO,
    @TOTALUSD              UD_MONTO,
    @DEBEHABER             UD_DEBE_HABER,
    @USERID                UD_USERID

)
AS
BEGIN
    BEGIN TRAN

	  DECLARE @SEQUENCE INT
	  DECLARE @DOCSUMMARYTYPEID      char(2)

	  SET @SEQUENCE=(SELECT COUNT(*)+1 FROM TMP_OP_DEPOSITSITEDET WHERE CORRNBR=@CORRNBR) 
	  SET @DOCSUMMARYTYPEID=(SELECT DOCSUMMARYTYPEID FROM OP_DOCSUMMARY WHERE SITEID=@SITEID AND NBRDOCSUMMARY=@REFERENCE)

          INSERT INTO TMP_OP_DEPOSITSITEDET(CORRNBR,SITEID,DATEPROCE,SEQUENCE,CUSTIDSS,DEPOSITPASSWORD,DATEDEPOSIT,CURYID,CURYRATE,TOTALPEN,TOTALUSD,DEBEHABER,STATUS,USERID)
          VALUES(@CORRNBR,@SITEID,@DATEPROCE,@SEQUENCE,@CUSTIDSS,@DEPOSITPASSWORD,@DATEDEPOSIT,@CURYID,@CURYRATE,@TOTALPEN,@TOTALUSD,@DEBEHABER,0,@USERID)

    IF (@@error!=0)
    BEGIN
        RAISERROR  20000 'Error insertando en TMP_OP_DEPOSITSITEDET'
        ROLLBACK TRAN
        RETURN(1)
    
    END

    SELECT @SEQUENCE AS SECUENCIA	
	
    COMMIT TRAN

END

go

DROP PROCEDURE TMP_OP_NBRDOCSUMMARYInsProc
GO
CREATE PROCEDURE TMP_OP_NBRDOCSUMMARYInsProc
(
    @CORRNBR		   INT,	
    @SITEID                UD_IDSITE,
    @DATEPROCE		   UD_FECHA,
    @SEQUENCE		   UD_REGISTRO,
    @DOCSUMMARYTYPEID      CHAR(2),
    @NBRDOCSUMMARY	   CHAR(10)

)
AS
BEGIN
    BEGIN TRAN


          INSERT INTO TMP_OP_NBRDOCSUMMARY(CORRNBR,SITEID,DATEPROCE,SEQUENCE,DOCSUMMARYTYPEID,NBRDOCSUMMARY)
          VALUES(@CORRNBR,@SITEID,@DATEPROCE,@SEQUENCE,@DOCSUMMARYTYPEID,@NBRDOCSUMMARY)

    IF (@@error!=0)
    BEGIN
        RAISERROR  20000 'Error insertando en TMP_OP_NBRDOCSUMMARY'
        ROLLBACK TRAN
        RETURN(1)
    
    END

    COMMIT TRAN

END

