Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_contraparte | int | 4 | |
| @ci | tinyint | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_validar_carga_inicial
-- Add the parameters for the stored procedure here
@p_contraparte int,
@ci tinyint OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @lci date
SELECT @ci = isnull(carga_inicial, 0),
@lci = convert(date, limite_carga_inicial)
FROM LN_contrapartes
WHERE contraparte = @p_contraparte
if (@ci = 1 AND @lci < convert(date, getdate()) ) begin
update LN_contrapartes SET carga_inicial = 0
where contraparte = @p_contraparte
end
if (@ci = 1) begin
DECLARE @doc_id int, @tipo_doc int, @estado_doc varchar(1), @vers int, @gest int
SELECT @gest = LN_gestiones.gestion
from LN_gestiones
where vigente = 1
and contraparte = @p_contraparte
and desde <= convert(date,GETDATE()) AND hasta >= convert(date,GETDATE())
DECLARE @cantidad int = 0
DECLARE @cumplidos int = 0
DECLARE @cantidad_verificados int = 0
DECLARE Documentos CURSOR FOR
SELECT LN_docs.doc_id, LN_docs.tipo_doc, LN_docs.estado_doc, LN_docs.doc_version
FROM LN_docs
where contraparte = @p_contraparte
and LN_docs.estado_doc <> 'X'
and ln_docs.aplica = 1
and LN_docs.gestion = @gest
OPEN Documentos
FETCH NEXT FROM Documentos INTO @doc_id, @tipo_doc, @estado_doc, @vers
WHILE @@FETCH_STATUS = 0 BEGIN
SET @cantidad = @cantidad + 1
IF (@estado_doc = 'I' OR @estado_doc = 'V') BEGIN
if (@estado_doc = 'V') begin
SET @cantidad_verificados = @cantidad_verificados + 1
end
SET @cumplidos = @cumplidos + 1
END
FETCH NEXT FROM Documentos INTO @doc_id, @tipo_doc, @estado_doc, @vers
END
CLOSE Documentos
DEALLOCATE Documentos
if (@cantidad = @cumplidos AND @cumplidos = @cantidad_verificados AND @cantidad > 0) begin
set @ci = 0
update LN_contrapartes SET carga_inicial = 0
where contraparte = @p_contraparte
end
end
/*SELECT @ci*/
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_validar_carga_inicial
-- Add the parameters for the stored procedure here
@p_contraparte int,
@ci tinyint OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @lci date
SELECT @ci = isnull(carga_inicial, 0),
@lci = convert(date, limite_carga_inicial)
FROM LN_contrapartes
WHERE contraparte = @p_contraparte
if (@ci = 1 AND @lci < convert(date, getdate()) ) begin
update LN_contrapartes SET carga_inicial = 0
where contraparte = @p_contraparte
end
if (@ci = 1) begin
DECLARE @doc_id int, @tipo_doc int, @estado_doc varchar(1), @vers int, @gest int
SELECT @gest = LN_gestiones.gestion
from LN_gestiones
where vigente = 1
and contraparte = @p_contraparte
and desde <= convert(date,GETDATE()) AND hasta >= convert(date,GETDATE())
DECLARE @cantidad int = 0
DECLARE @cumplidos int = 0
DECLARE @cantidad_verificados int = 0
DECLARE Documentos CURSOR FOR
SELECT LN_docs.doc_id, LN_docs.tipo_doc, LN_docs.estado_doc, LN_docs.doc_version
FROM LN_docs
where contraparte = @p_contraparte
and LN_docs.estado_doc <> 'X'
and ln_docs.aplica = 1
and LN_docs.gestion = @gest
OPEN Documentos
FETCH NEXT FROM Documentos INTO @doc_id, @tipo_doc, @estado_doc, @vers
WHILE @@FETCH_STATUS = 0 BEGIN
SET @cantidad = @cantidad + 1
IF (@estado_doc = 'I' OR @estado_doc = 'V') BEGIN
if (@estado_doc = 'V') begin
SET @cantidad_verificados = @cantidad_verificados + 1
end
SET @cumplidos = @cumplidos + 1
END
FETCH NEXT FROM Documentos INTO @doc_id, @tipo_doc, @estado_doc, @vers
END
CLOSE Documentos
DEALLOCATE Documentos
if (@cantidad = @cumplidos AND @cumplidos = @cantidad_verificados AND @cantidad > 0) begin
set @ci = 0
update LN_contrapartes SET carga_inicial = 0
where contraparte = @p_contraparte
end
end
/*SELECT @ci*/
END
GO