SELECT * FROM TMP_OP_ORDENC

SELECT * FROM TMP_OP_BONUS 
WHERE CUSTIDSS = '20135406245' AND NBRBONUS IN ('701','702','703','704','705','706','707','708','709','710')
ORDER BY CORRNBR,SITEID DESC


DELETE FROM TMP_OP_BONUS 
WHERE CUSTIDSS = '20135406245' AND NBRBONUS IN ('701','702','703','704','705','706','707','708','709','710','711')

sp_helptext OP_Verificar_ExisteVale

select * from OP_Verificar_ExisteVale


SP_HELPTEXT OP_GrabarTmp_Op_BonusProc


sp_helptext OP_EliminarTmp_Op_AdelantoProc 0,505496,702

SELECT * FROM TMP_OP_BONUS WHERE CORRNBR=505496 AND NBRBONUS=702


OP_GrabarValesAProc

-------------------------

ALTER PROCEDURE OP_GrabarValesAProc  
	(@CORRNBR       int,  
 	@DOCTYPEID      UD_DOCTYPEID,  
 	@NBRDOCUMENT    UD_CORRELATIVOS,  
 	@DATEPROCESALES UD_FECHA,
	@TOTALVENTA	UD_MONTO,
	@nuevoVALES     int)  --1 nuevo ; 2 Modificacion
as  
BEGIN  
   -- Declaración de Variables       
-- 498866,12,1000000004,26/07/2006  
  
   DECLARE @custidss  UD_CODCLIENT   
   DECLARE @SITEID    UD_IDSITE   
   DECLARE @NBRBONUS  NUMERIC(10)     
   DECLARE @ERROR     Integer       
   DECLARE @MONTOBONUS NUMERIC (10,2)  
   DECLARE @SALDOBONUS NUMERIC (10,2)  
   DECLARE @ESTADO BIT  
   
--   declare @INVTIDSKU   char(20)  
--   declare @DESCRP      char (50)  
   -- Declaración del Cursor   
  IF @nuevoVALES = 1		--INSERTO VALES DE PAGO ADELANTADO NUEVOS
    BEGIN
   DECLARE OPORDENC 
	   CURSOR FOR  
           SELECT custidss,
		  SITEID,
		  NBRBONUS,
		  MONTOBONUS,
                  USER01,
		  estado
	   FROM TMP_OP_BONUS
	   WHERE CORRNBR=@CORRNBR   
   OPEN OPORDENC  
   FETCH NEXT FROM OPORDENC INTO @custidss,@SITEID,@NBRBONUS,@MONTOBONUS,@SALDOBONUS,@ESTADO
  
      WHILE @@FETCH_STATUS = 0  
           BEGIN            
              INSERT INTO OP_BONUS (DOCTYPEID,NBRDOCUMENT,custidss,SITEID,NBRBONUS,DATEPROCESALES,MONTOBONUS,USER01,estado)   
              VALUES(@DOCTYPEID,@NBRDOCUMENT,@custidss,@SITEID,@NBRBONUS,@DATEPROCESALES,@MONTOBONUS,@SALDOBONUS,@ESTADO)  
  
              SET @ERROR=@@error  
       
                IF (@ERROR!=0)  
                  BEGIN         
                    CLOSE OPORDENC  
                    DEALLOCATE OPORDENC  
                    RETURN(1)    
                  END   
               
   		FETCH NEXT FROM OPORDENC INTO @custidss,@SITEID,@NBRBONUS,@MONTOBONUS,@SALDOBONUS,@ESTADO
           END  
    
      CLOSE OPORDENC  
      DEALLOCATE OPORDENC  
   END
   IF @nuevoVALES = 2 		--ACTUALIZO VALES DE PAGO ADELANTADO NUEVOS
      BEGIN
		UPDATE OP_BONUS SET USER01 = 0, estado = 1
		WHERE DOCTYPEID ='A' AND NBRDOCUMENT = 'A' AND custidss = 'A' AND SITEID = 'A' AND NBRBONUS = 'A'
      END
      RETURN (0)           
END  
