Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @cuit | varchar | 20 | |
| @cliente | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
exec obtener_contraparte_cuit '23945234784',110864291
exec obtener_contraparte_cuit '20177260909',110864291
exec obtener_contraparte_cuit '20177260908',110864291
*/
CREATE OR ALTER PROCEDURE dbo.obtener_contraparte_cuit
@cuit varchar(20),
@cliente int
AS
BEGIN
SET NOCOUNT ON;
declare @id_padron int =0
declare @country varchar(10)
declare @contraparte int =0
declare @estadocontraparte tinyint =0
/*
select top 1 @id_padron = padrones.id_padron,@country = identificadores.country_code,
@contraparte = ln_contrapartes.contraparte,@estadocontraparte=LN_contrapartes.activo
from padrones left join ln_contrapartes on padrones.id_padron=LN_contrapartes.id_padron
left join identificadores on identificadores.identificador = padrones.identificador
where padrones.identificacion=@cuit and LN_contrapartes.cliente=@cliente and padrones.habilitado=1
*/
select top 1 @id_padron = padrones.id_padron,@country = identificadores.country_code,
@contraparte = ln_contrapartes.contraparte,@estadocontraparte=LN_contrapartes.activo
from padrones left join ln_contrapartes on (padrones.id_padron=ln_contrapartes.id_padron and ln_contrapartes.cliente = @cliente and padrones.habilitado=1)
inner join identificadores on (identificadores.identificador = padrones.identificador and identificadores.country_code='AR')
where padrones.identificacion=@cuit
if (isnull(@contraparte,0) > 0) /* YA EXISTE COMO CONTRAPARTE - RECALCULAMOS PERO NO DAMOS DE ALTA */
begin
-- select @id_padron,@country, @contraparte
if (@estadocontraparte = 0) /* LA CONTRAPARTE ESTA INACTIVA */
begin
update ln_contrapartes set activo=1 where contraparte = contraparte /* REACTIVAMOS LA CONTRAPARTE POR LA NUEVA CONSULTA*/
end
exec LN_dashboard_cliente 'judicial', null, null, null, @contraparte
exec LN_dashboard_cliente 'SCORE_ALERTAS_BCRA', null, null, null, @contraparte
select @contraparte as contraparte
end
ELSE /*NO EXISTE COMO CONTRAPARTE ENTONCES LA DAMOS DE ALTA */
BEGIN
-- select @id_padron,@country, @contraparte,@estadocontraparte
IF (@id_padron > 0) /*EL CUIT CONSULTADO EXISTE EN EL PADRON */
BEGIN
insert into LN_contrapartes (id_padron, cliente, country_code, activo, clave, clave_temporal, clave_expira, vigencia_desde, vigencia_hasta, carga_inicial, subcontratista, created, created_by)
values (@id_padron, @cliente, @country, 1, 'sinuso', 0, DATEADD(year,10, getdate()), convert(date,GETDATE()), '2099-12-31', 0, 0, GETDATE(), '130996631')
SET @contraparte = SCOPE_IDENTITY()
declare @familia int =(select top 1 familia from LN_familias where cliente = @cliente and visible = 1)
--> gestion
insert into ln_gestiones(cliente, contraparte, desde, hasta, vigente, created, created_by)
values (@cliente, @contraparte, convert(date,GETDATE()),'2099-12-31', 1, GETDATE(),'130996631')
--> familia
insert into LN_contraparte_familias(contraparte, familia, estado_homologacion, activo, created, created_by)
values (@contraparte, @familia, 'N', 1, GETDATE(),'130996631')
exec LN_dashboard_cliente 'judicial', null, null, null, @contraparte
exec LN_dashboard_cliente 'SCORE_ALERTAS_BCRA', null, null, null, @contraparte
select @contraparte as contraparte
END
ELSE
BEGIN
select 0 as contraparte /* NO EXISTE LA CONTRAPARTE Y TAMPOCO SE LA PUEDE DAR DE ALTA PORQUE NO EXISTE EL CUIT EN PADRON */
END
END
/*
select top 1 @id_padron = id_padron,
@country = identificadores.country_code
from padrones
left join identificadores on identificadores.identificador = padrones.identificador
where identificacion = @cuit and habilitado = 1
if not exists (select * from LN_contrapartes
where LN_contrapartes.cliente = @cliente
and LN_contrapartes.id_padron = @id_padron
and LN_contrapartes.activo = 1
and LN_contrapartes.subcontratista = 0)
begin
--> contraparte
insert into LN_contrapartes (id_padron, cliente, country_code, activo, clave, clave_temporal, clave_expira, vigencia_desde, vigencia_hasta, carga_inicial, subcontratista, created, created_by)
values (@id_padron, @cliente, @country, 1, 'sinuso', 0, DATEADD(year,10, getdate()), convert(date,GETDATE()), '2099-12-31', 0, 0, GETDATE(), '130996631')
SET @contraparte = SCOPE_IDENTITY()
declare @familia int =(select top 1 familia from LN_familias where cliente = @cliente and visible = 1)
--> gestion
insert into ln_gestiones(cliente, contraparte, desde, hasta, vigente, created, created_by)
values (@cliente, @contraparte, convert(date,GETDATE()),'2099-12-31', 1, GETDATE(),'130996631')
--> familia
insert into LN_contraparte_familias(contraparte, familia, estado_homologacion, activo, created, created_by)
values (@contraparte, @familia, 'N', 1, GETDATE(),'130996631')
end
else /* YA EXISTE COMO CONTRAPARTE */
begin
select @contraparte = contraparte
from ln_contrapartes
where cliente = @cliente
and id_padron = @id_padron
end
exec LN_dashboard_cliente 'judicial', null, null, null, @contraparte
exec LN_dashboard_cliente 'SCORE_ALERTAS_BCRA', null, null, null, @contraparte
select @contraparte as contraparte
*/
END
GO
GO
/*
exec obtener_contraparte_cuit '23945234784',110864291
exec obtener_contraparte_cuit '20177260909',110864291
exec obtener_contraparte_cuit '20177260908',110864291
*/
CREATE OR ALTER PROCEDURE dbo.obtener_contraparte_cuit
@cuit varchar(20),
@cliente int
AS
BEGIN
SET NOCOUNT ON;
declare @id_padron int =0
declare @country varchar(10)
declare @contraparte int =0
declare @estadocontraparte tinyint =0
/*
select top 1 @id_padron = padrones.id_padron,@country = identificadores.country_code,
@contraparte = ln_contrapartes.contraparte,@estadocontraparte=LN_contrapartes.activo
from padrones left join ln_contrapartes on padrones.id_padron=LN_contrapartes.id_padron
left join identificadores on identificadores.identificador = padrones.identificador
where padrones.identificacion=@cuit and LN_contrapartes.cliente=@cliente and padrones.habilitado=1
*/
select top 1 @id_padron = padrones.id_padron,@country = identificadores.country_code,
@contraparte = ln_contrapartes.contraparte,@estadocontraparte=LN_contrapartes.activo
from padrones left join ln_contrapartes on (padrones.id_padron=ln_contrapartes.id_padron and ln_contrapartes.cliente = @cliente and padrones.habilitado=1)
inner join identificadores on (identificadores.identificador = padrones.identificador and identificadores.country_code='AR')
where padrones.identificacion=@cuit
if (isnull(@contraparte,0) > 0) /* YA EXISTE COMO CONTRAPARTE - RECALCULAMOS PERO NO DAMOS DE ALTA */
begin
-- select @id_padron,@country, @contraparte
if (@estadocontraparte = 0) /* LA CONTRAPARTE ESTA INACTIVA */
begin
update ln_contrapartes set activo=1 where contraparte = contraparte /* REACTIVAMOS LA CONTRAPARTE POR LA NUEVA CONSULTA*/
end
exec LN_dashboard_cliente 'judicial', null, null, null, @contraparte
exec LN_dashboard_cliente 'SCORE_ALERTAS_BCRA', null, null, null, @contraparte
select @contraparte as contraparte
end
ELSE /*NO EXISTE COMO CONTRAPARTE ENTONCES LA DAMOS DE ALTA */
BEGIN
-- select @id_padron,@country, @contraparte,@estadocontraparte
IF (@id_padron > 0) /*EL CUIT CONSULTADO EXISTE EN EL PADRON */
BEGIN
insert into LN_contrapartes (id_padron, cliente, country_code, activo, clave, clave_temporal, clave_expira, vigencia_desde, vigencia_hasta, carga_inicial, subcontratista, created, created_by)
values (@id_padron, @cliente, @country, 1, 'sinuso', 0, DATEADD(year,10, getdate()), convert(date,GETDATE()), '2099-12-31', 0, 0, GETDATE(), '130996631')
SET @contraparte = SCOPE_IDENTITY()
declare @familia int =(select top 1 familia from LN_familias where cliente = @cliente and visible = 1)
--> gestion
insert into ln_gestiones(cliente, contraparte, desde, hasta, vigente, created, created_by)
values (@cliente, @contraparte, convert(date,GETDATE()),'2099-12-31', 1, GETDATE(),'130996631')
--> familia
insert into LN_contraparte_familias(contraparte, familia, estado_homologacion, activo, created, created_by)
values (@contraparte, @familia, 'N', 1, GETDATE(),'130996631')
exec LN_dashboard_cliente 'judicial', null, null, null, @contraparte
exec LN_dashboard_cliente 'SCORE_ALERTAS_BCRA', null, null, null, @contraparte
select @contraparte as contraparte
END
ELSE
BEGIN
select 0 as contraparte /* NO EXISTE LA CONTRAPARTE Y TAMPOCO SE LA PUEDE DAR DE ALTA PORQUE NO EXISTE EL CUIT EN PADRON */
END
END
/*
select top 1 @id_padron = id_padron,
@country = identificadores.country_code
from padrones
left join identificadores on identificadores.identificador = padrones.identificador
where identificacion = @cuit and habilitado = 1
if not exists (select * from LN_contrapartes
where LN_contrapartes.cliente = @cliente
and LN_contrapartes.id_padron = @id_padron
and LN_contrapartes.activo = 1
and LN_contrapartes.subcontratista = 0)
begin
--> contraparte
insert into LN_contrapartes (id_padron, cliente, country_code, activo, clave, clave_temporal, clave_expira, vigencia_desde, vigencia_hasta, carga_inicial, subcontratista, created, created_by)
values (@id_padron, @cliente, @country, 1, 'sinuso', 0, DATEADD(year,10, getdate()), convert(date,GETDATE()), '2099-12-31', 0, 0, GETDATE(), '130996631')
SET @contraparte = SCOPE_IDENTITY()
declare @familia int =(select top 1 familia from LN_familias where cliente = @cliente and visible = 1)
--> gestion
insert into ln_gestiones(cliente, contraparte, desde, hasta, vigente, created, created_by)
values (@cliente, @contraparte, convert(date,GETDATE()),'2099-12-31', 1, GETDATE(),'130996631')
--> familia
insert into LN_contraparte_familias(contraparte, familia, estado_homologacion, activo, created, created_by)
values (@contraparte, @familia, 'N', 1, GETDATE(),'130996631')
end
else /* YA EXISTE COMO CONTRAPARTE */
begin
select @contraparte = contraparte
from ln_contrapartes
where cliente = @cliente
and id_padron = @id_padron
end
exec LN_dashboard_cliente 'judicial', null, null, null, @contraparte
exec LN_dashboard_cliente 'SCORE_ALERTAS_BCRA', null, null, null, @contraparte
select @contraparte as contraparte
*/
END
GO
Depends On
5Used By
No items found