
CREATE PROCEDURE [dbo].[sp_VenFoliosCajaProximoRangoOfflineRead]
    @folio INT,
    @sucursal INT,
    @caja INT,
	@tipoDoc INT,
    @proximoRango BIGINT OUTPUT
AS
BEGIN
    SET NOCOUNT ON;

    SELECT TOP 1 @proximoRango = FOLIOINI
    FROM venfolioscaja 
    WHERE folioini > @folio 
    AND sucursal = @sucursal 
    AND CAJA = @caja
	AND tipoDoc = @tipoDoc
    ORDER BY FOLIOINI ASC;

    -- Si no se encuentra un próximo rango, establecer a 0
    IF @proximoRango IS NULL
    BEGIN
        SET @proximoRango = 0;
    END
END;
