drop proc op_grabar_cashdrop_PROC 
go
create proc op_grabar_cashdrop_PROC 
(
@CORR 		integer,
@BATNBR		ud_correl_Deposit,
@site 		ud_idsite,
@turno		tinyint,
@fecha 		smalldatetime,
@fechaproc 	smalldatetime,
@vendedor 	ud_idvendedor,
@user 		ud_userid
 )  
as
declare @BATNBRDEPOSIT ud_correl_Deposit
declare @SEQUENCE	ud_registro
declare @CARDID		char(2)
declare @TOTAL		ud_monto
declare @CUSTIDSS	ud_codclient
declare @CURYID		ud_curyid
declare @DEPOSITTYPEID  char(1)

BEGIN TRAN
-------------------------------------------------------------------------------------
--GRABANDO CABEZERA OP_DEPOSIT
INSERT INTO OP_DEPOSIT(BATNBRDEPOSIT,SITEID,SALESPERSONTURN,OPDATE,
                       DATEPROCE,STATUS,SALESPERID,USERID)
    VALUES(@BATNBR,@site,@turno,@fecha,@fechaproc,0,@vendedor,@user )

    IF (@@error!=0)
    BEGIN
        RAISERROR  20000 'ERROR GRABANDO EN OP_DEPOSIT '
        ROLLBACK TRAN
        RETURN(1)
 
    END
-------------------------------------------------------------------------------------
--GRABANDO DETALLE OP_DEPOSITDET
DECLARE detalle_cursor CURSOR FOR
		SELECT BATNBRDEPOSIT,SEQUENCE,CARDID,TOTAL,CUSTIDSS,CURYID,DEPOSITTYPEID  
		FROM tmp_op_depositdet where CORRNBR=@CORR

OPEN detalle_cursor 

FETCH NEXT FROM detalle_cursor into @BATNBRDEPOSIT,@SEQUENCE,@CARDID,@TOTAL,@CUSTIDSS,@CURYID,@DEPOSITTYPEID

WHILE @@FETCH_STATUS = 0
BEGIN

    INSERT INTO OP_DEPOSITDET(BATNBRDEPOSIT,SITEID,SEQUENCE,CARDID,TOTAL,CUSTIDSS,CURYID,DEPOSITTYPEID )
    VALUES(@BATNBRDEPOSIT,@SITE,@SEQUENCE,@CARDID,@TOTAL,@CUSTIDSS,@CURYID,@DEPOSITTYPEID  )

    IF (@@error!=0)
    BEGIN
        RAISERROR  20000 'ERROR GRABANDO EN OP_DEPOSITDET '
	CLOSE detalle_cursor 
	DEALLOCATE detalle_cursor 
        ROLLBACK TRAN
        RETURN(1)
    END

   FETCH NEXT FROM detalle_cursor into @BATNBRDEPOSIT,@SEQUENCE,@CARDID,@TOTAL,@CUSTIDSS,@CURYID,@DEPOSITTYPEID  
END

COMMIT TRAN

CLOSE detalle_cursor 
DEALLOCATE detalle_cursor 

go
-- op_grabar_cashdrop_PROC 872,9,'00057',0,'01/01/01','02/02/02','GUS','DUFFGGU'

SELECT * FROM tmp_op_depositdet 
SELECT * FROM op_deposit
SELECT * FROM op_depositdet 
