Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
4| Name | Data Type | Length | Description |
|---|---|---|---|
| @action | varchar | 20 | |
| @p_contraparte | int | 4 | |
| @p_user_id | int | 4 | |
| @p_automatico | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
EXEC LN_actualizar_legajo_AGB 147088, NULL,NULL
SELECT LN_CONTRAPARTE_SUB_SET.contraparte,LN_CONTRAPARTE_SUB_SET.set_doc, ln_gestiones.gestion,ln_gestiones.cliente,
ln_gestiones.desde,ln_gestiones.hasta
FROM LN_CONTRAPARTE_SUB_SET inner join ln_gestiones on LN_CONTRAPARTE_SUB_SET.contraparte=ln_gestiones.contraparte
where LN_CONTRAPARTE_SUB_SET.activo = 1 and ln_gestiones.vigente = 1
and convert(date,getdate()) between ln_gestiones.desde and ln_gestiones.hasta
DELETE LN_DOCS WHERE CONTRAPARTE = 147088 AND TIPO_DOC = 1048
SELECT * FROM LN_DOCS WHERE CONTRAPARTE = 147088
SELECT * FROM LN_CONTRAPARTES WHERE CONTRAPARTE = 147088
SELECT * FROM PADRONES WHERE ID_PADRON = 37202918
select * from LN_CONTRAPARTE_SUB_SET
select * from ln_gestiones where contraparte = 147088
exec LN_contraparte_sub_docs 'ALTA',147088,1
*/
/*
ADMINISTRAR LOS SET DE DOCUMENTOS ADICIONALES QUE DEBEN GENERARSE A LAS CONTRAPARTES
*/
CREATE OR ALTER PROCEDURE dbo.LN_contraparte_sub_docs_11012023
@action varchar(20),
@p_contraparte int,
@p_user_id int,
@p_automatico int = 0 /* 0: lo pidieron a mano, 1: si disparó automáticamente */
AS
BEGIN
SET NOCOUNT ON;
/*AGREGAMOS UN SET DE DECOUMENTOS ADICIONAL A LA CONTRAPARTE / GESTION */
declare @existe int =0
declare @activo bit =0
declare @idsub int=0
declare @p_set_doc_padre int
declare @p_set_doc int
declare @p_gestion int
declare @p_cliente int
select @p_gestion = gestion
from ln_gestiones
where contraparte = @p_contraparte
and vigente = 1 and desde <= getdate() and hasta >= getdate()
select @p_cliente = cliente
from ln_contrapartes
where contraparte = @p_contraparte
select @p_set_doc_padre = set_doc
from ln_familias
where familia = (select familia from ln_contraparte_familias where contraparte = @p_contraparte)
select top 1 @p_set_doc = set_doc_hijo from LN_set_sub_docs where set_doc_padre = @p_set_doc_padre order by prioridad_set
set @existe = 0
select @existe=1,@activo=activo,@idsub=idContraparteSubSet
from LN_CONTRAPARTE_SUB_SET where contraparte = @p_contraparte and gestion = @p_gestion and set_doc=@p_set_doc
/* SI ES ALTA Y NO EXISTE LO INSERTAMOS */
if (@action='ALTA' and @existe = 0)
BEGIN
INSERT INTO LN_CONTRAPARTE_SUB_SET (contraparte,gestion,set_doc,activo,created,created_by)
values (@p_contraparte,@p_gestion,@p_set_doc,1,getdate(),@p_user_id)
END
/* SI ES ALTA PERO EXISTE COMO ACTIVO 0 HACEMOS UN UPDATE */
if (@action='ALTA' and @existe = 1 AND @activo=0)
BEGIN
begin
update LN_CONTRAPARTE_SUB_SET set activo =1 ,modified=getdate(),modified_by=@p_user_id where contraparte = @p_contraparte and gestion = @p_gestion and set_doc=@p_set_doc and idContraparteSubSet=@idsub
end
END
if (@action='BAJA')
BEGIN
begin
update LN_CONTRAPARTE_SUB_SET set activo =0 ,modified=getdate(),modified_by=@p_user_id where contraparte = @p_contraparte and gestion = @p_gestion and set_doc=@p_set_doc and idContraparteSubSet=@idsub
end
END
--if (@action='ALTA')
if (@action='ALTA' and (@existe = 0 or @activo=0)) /* 8/4/22: Solo lo hace si no existía o estaba como inactivo, porque si ya esta pedido no vuelve a pedir */
begin
--EXEC LN_actualizar_legajo_AGB @p_contraparte, NULL,NULL /* pasamos el fuente de LN_actualizar_legajo_AGB a LN_actualizar_legajo
EXEC LN_actualizar_legajo @p_contraparte, NULL,NULL
if (@p_automatico = 1) /* 8/4/22: Se puede disparar automáticamente */
EXEC insertar_trazabilidad 'Solicitar DDR: Automático', @p_cliente, 'AGREGAR_SUB_SET_DOC', 'FI', @p_contraparte, @p_user_id
else
EXEC insertar_trazabilidad 'Solicitar DDR: SI', @p_cliente, 'AGREGAR_SUB_SET_DOC', 'FI', @p_contraparte, @p_user_id
end
if (@action='BAJA')
begin
EXEC LN_actualizar_legajo @p_contraparte, NULL,NULL
EXEC insertar_trazabilidad 'Solicitar DDR: NO', @p_cliente, 'SACAR_SUB_SET_DOC', 'FI', @p_contraparte, @p_user_id
end
END
/*
select * from LN_CONTRAPARTE_SUB_SET where contraparte =147069
select * from LN_contraparte_familias where contraparte = 147088
select * from ln_familias where familia = 368
select * from LN_set_sub_docs where set_doc_padre = 80
select * from ln_indicadores where etiqueta = 'Solicitar DDR'
select * from clientes where cli_codigo = 222
update ln_contraparte_indicadores set valor_texto = null where indicador = 396 and contraparte = 147069
select * from ln_contraparte_indicadores where indicador = 396 and contraparte = 147069
select * from ln_docs where contraparte = 147069
delete from ln_docs where contraparte = 147069 and tipo_doc = 1048
select * from LN_CONTRAPARTE_SUB_SET where contraparte =147069
*/
GO
GO
/*
EXEC LN_actualizar_legajo_AGB 147088, NULL,NULL
SELECT LN_CONTRAPARTE_SUB_SET.contraparte,LN_CONTRAPARTE_SUB_SET.set_doc, ln_gestiones.gestion,ln_gestiones.cliente,
ln_gestiones.desde,ln_gestiones.hasta
FROM LN_CONTRAPARTE_SUB_SET inner join ln_gestiones on LN_CONTRAPARTE_SUB_SET.contraparte=ln_gestiones.contraparte
where LN_CONTRAPARTE_SUB_SET.activo = 1 and ln_gestiones.vigente = 1
and convert(date,getdate()) between ln_gestiones.desde and ln_gestiones.hasta
DELETE LN_DOCS WHERE CONTRAPARTE = 147088 AND TIPO_DOC = 1048
SELECT * FROM LN_DOCS WHERE CONTRAPARTE = 147088
SELECT * FROM LN_CONTRAPARTES WHERE CONTRAPARTE = 147088
SELECT * FROM PADRONES WHERE ID_PADRON = 37202918
select * from LN_CONTRAPARTE_SUB_SET
select * from ln_gestiones where contraparte = 147088
exec LN_contraparte_sub_docs 'ALTA',147088,1
*/
/*
ADMINISTRAR LOS SET DE DOCUMENTOS ADICIONALES QUE DEBEN GENERARSE A LAS CONTRAPARTES
*/
CREATE OR ALTER PROCEDURE dbo.LN_contraparte_sub_docs_11012023
@action varchar(20),
@p_contraparte int,
@p_user_id int,
@p_automatico int = 0 /* 0: lo pidieron a mano, 1: si disparó automáticamente */
AS
BEGIN
SET NOCOUNT ON;
/*AGREGAMOS UN SET DE DECOUMENTOS ADICIONAL A LA CONTRAPARTE / GESTION */
declare @existe int =0
declare @activo bit =0
declare @idsub int=0
declare @p_set_doc_padre int
declare @p_set_doc int
declare @p_gestion int
declare @p_cliente int
select @p_gestion = gestion
from ln_gestiones
where contraparte = @p_contraparte
and vigente = 1 and desde <= getdate() and hasta >= getdate()
select @p_cliente = cliente
from ln_contrapartes
where contraparte = @p_contraparte
select @p_set_doc_padre = set_doc
from ln_familias
where familia = (select familia from ln_contraparte_familias where contraparte = @p_contraparte)
select top 1 @p_set_doc = set_doc_hijo from LN_set_sub_docs where set_doc_padre = @p_set_doc_padre order by prioridad_set
set @existe = 0
select @existe=1,@activo=activo,@idsub=idContraparteSubSet
from LN_CONTRAPARTE_SUB_SET where contraparte = @p_contraparte and gestion = @p_gestion and set_doc=@p_set_doc
/* SI ES ALTA Y NO EXISTE LO INSERTAMOS */
if (@action='ALTA' and @existe = 0)
BEGIN
INSERT INTO LN_CONTRAPARTE_SUB_SET (contraparte,gestion,set_doc,activo,created,created_by)
values (@p_contraparte,@p_gestion,@p_set_doc,1,getdate(),@p_user_id)
END
/* SI ES ALTA PERO EXISTE COMO ACTIVO 0 HACEMOS UN UPDATE */
if (@action='ALTA' and @existe = 1 AND @activo=0)
BEGIN
begin
update LN_CONTRAPARTE_SUB_SET set activo =1 ,modified=getdate(),modified_by=@p_user_id where contraparte = @p_contraparte and gestion = @p_gestion and set_doc=@p_set_doc and idContraparteSubSet=@idsub
end
END
if (@action='BAJA')
BEGIN
begin
update LN_CONTRAPARTE_SUB_SET set activo =0 ,modified=getdate(),modified_by=@p_user_id where contraparte = @p_contraparte and gestion = @p_gestion and set_doc=@p_set_doc and idContraparteSubSet=@idsub
end
END
--if (@action='ALTA')
if (@action='ALTA' and (@existe = 0 or @activo=0)) /* 8/4/22: Solo lo hace si no existía o estaba como inactivo, porque si ya esta pedido no vuelve a pedir */
begin
--EXEC LN_actualizar_legajo_AGB @p_contraparte, NULL,NULL /* pasamos el fuente de LN_actualizar_legajo_AGB a LN_actualizar_legajo
EXEC LN_actualizar_legajo @p_contraparte, NULL,NULL
if (@p_automatico = 1) /* 8/4/22: Se puede disparar automáticamente */
EXEC insertar_trazabilidad 'Solicitar DDR: Automático', @p_cliente, 'AGREGAR_SUB_SET_DOC', 'FI', @p_contraparte, @p_user_id
else
EXEC insertar_trazabilidad 'Solicitar DDR: SI', @p_cliente, 'AGREGAR_SUB_SET_DOC', 'FI', @p_contraparte, @p_user_id
end
if (@action='BAJA')
begin
EXEC LN_actualizar_legajo @p_contraparte, NULL,NULL
EXEC insertar_trazabilidad 'Solicitar DDR: NO', @p_cliente, 'SACAR_SUB_SET_DOC', 'FI', @p_contraparte, @p_user_id
end
END
/*
select * from LN_CONTRAPARTE_SUB_SET where contraparte =147069
select * from LN_contraparte_familias where contraparte = 147088
select * from ln_familias where familia = 368
select * from LN_set_sub_docs where set_doc_padre = 80
select * from ln_indicadores where etiqueta = 'Solicitar DDR'
select * from clientes where cli_codigo = 222
update ln_contraparte_indicadores set valor_texto = null where indicador = 396 and contraparte = 147069
select * from ln_contraparte_indicadores where indicador = 396 and contraparte = 147069
select * from ln_docs where contraparte = 147069
delete from ln_docs where contraparte = 147069 and tipo_doc = 1048
select * from LN_CONTRAPARTE_SUB_SET where contraparte =147069
*/
GO
Depends On
8Used By
No items found