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

    SELECT TOP 1 @proximoFolio = 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 folio, establecer a 0
    IF @proximoFolio IS NULL
    BEGIN
        SET @proximoFolio = 0;
    END
END;
