Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
2| Name | Data Type | Length | Description |
|---|---|---|---|
| @fecha_desde | date | 3 | |
| @fecha_hasta | date | 3 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
/*
Los registros de Central de Deudores que se cargan desde el cd, estan en la tabla cendeu_temp
Cuando se termina de cargar el cd, entonces, buscamos los cuits de monitoreo que haya en cendeu_tamp
*/
/*
[monitoreos_batch_cendeu_temp] '2018-04-15','2018-04-06'
delete from monitoreos_resultados_temp
select * from monitoreos_resultados_temp
*/
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_cendeu_temp
@fecha_desde date = null,
@fecha_hasta date = null
AS
BEGIN
SET NOCOUNT ON;
declare @hoy date = getdate()
declare @fecha_archivo date
declare @cant bigint = 0,
@r_id_cendeu int,
@r_cuit varchar(20),
@r_situacion char(2)
declare @html table (nombre varchar(100), periodo varchar(20), situacion varchar(2), total decimal(20,2))
declare @html_txt varchar(max)
if (@fecha_desde is null)
begin
set @fecha_desde = GETDATE() - 1
set @fecha_hasta = @fecha_desde
end
if (@fecha_hasta is null)
begin
set @fecha_hasta = @fecha_desde
end
set @fecha_archivo = @fecha_hasta
/*
Cuando se carga deuda, puede ser que el dia de hoy todavia este corriendo porque esto por cron se larga a las 22 hs.
Entonces, los dias de procesamiento de deuda, mandamos las novedades del dia anterior, para asegurarnos que esten las 24 hs completas
y no perder los registros cargados entre las 22 y las 24 hs.
*/
if (@fecha_hasta = @hoy)
begin
set @fecha_hasta = GETDATE() - 1
set @fecha_archivo = @hoy
end
if (@fecha_desde = @hoy)
begin
set @fecha_desde = GETDATE() - 1
end
/**/
set @cant = (select COUNT(*) from cendeu_temp where convert(date,created) between @fecha_desde and @fecha_hasta)
if (@cant > 0)
begin
-- recorre por monitoreo
DECLARE bn2 CURSOR
FOR
select distinct cuit
from monitoreos
where visible = 1
and isnull(seccion_mantenimiento,'10') = '10'
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @fecha_hasta)
OPEN bn2
Fetch next from bn2 INTO @r_cuit
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
DECLARE cendeuc2 CURSOR
FOR
select id_cendeu, situacion
from cendeu_temp
where iden = @r_cuit
and vigente = 1
and (convert(date,created) between @fecha_desde and @fecha_hasta)
OPEN cendeuc2
FETCH next from cendeuc2 INTO @r_id_cendeu, @r_situacion
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (CONVERT(int,@r_situacion) = 1)
begin
FETCH next from cendeuc2 INTO @r_id_cendeu, @r_situacion
continue
end
insert into @html
exec dbo.obtener_info_novedades @r_cuit,@r_id_cendeu,'cendeu_temp',null
set @html_txt = (select
'<td>' + nombre + '</td>' +
'<td>' + periodo + '</td>' +
'<td>' + situacion + '</td>' +
'<td align=right>' + replace (FORMAT(total,'### ### ### ### ### ###.00'),'.',',') + '</td>'
from @html)
delete from @html
--insert into monitoreos_resultados_temp
insert into monitoreos_resultados
(id_tabla, tabla, cuit, seccion_mantenimiento, fecha, novedad, tipo_novedad,html)
values (@r_id_cendeu, 'cendeu_temp', @r_cuit, '10', @fecha_archivo, 1, 'Bancos', @html_txt);
update monitoreos
set fecha_ultimo_procesamiento = @fecha_archivo,
fecha_modificacion = @fecha_archivo
where cuit = @r_cuit
and isnull(seccion_mantenimiento,10) = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @fecha_hasta)
and (fecha_desde is null or fecha_desde <= @fecha_hasta)
FETCH next from cendeuc2 INTO @r_id_cendeu, @r_situacion
END
CLOSE cendeuc2
DEALLOCATE cendeuc2
FETCH next from bn2 INTO @r_cuit
END
CLOSE bn2
DEALLOCATE bn2
end
END
GO
GO
/*
Los registros de Central de Deudores que se cargan desde el cd, estan en la tabla cendeu_temp
Cuando se termina de cargar el cd, entonces, buscamos los cuits de monitoreo que haya en cendeu_tamp
*/
/*
[monitoreos_batch_cendeu_temp] '2018-04-15','2018-04-06'
delete from monitoreos_resultados_temp
select * from monitoreos_resultados_temp
*/
CREATE OR ALTER PROCEDURE dbo.monitoreos_batch_cendeu_temp
@fecha_desde date = null,
@fecha_hasta date = null
AS
BEGIN
SET NOCOUNT ON;
declare @hoy date = getdate()
declare @fecha_archivo date
declare @cant bigint = 0,
@r_id_cendeu int,
@r_cuit varchar(20),
@r_situacion char(2)
declare @html table (nombre varchar(100), periodo varchar(20), situacion varchar(2), total decimal(20,2))
declare @html_txt varchar(max)
if (@fecha_desde is null)
begin
set @fecha_desde = GETDATE() - 1
set @fecha_hasta = @fecha_desde
end
if (@fecha_hasta is null)
begin
set @fecha_hasta = @fecha_desde
end
set @fecha_archivo = @fecha_hasta
/*
Cuando se carga deuda, puede ser que el dia de hoy todavia este corriendo porque esto por cron se larga a las 22 hs.
Entonces, los dias de procesamiento de deuda, mandamos las novedades del dia anterior, para asegurarnos que esten las 24 hs completas
y no perder los registros cargados entre las 22 y las 24 hs.
*/
if (@fecha_hasta = @hoy)
begin
set @fecha_hasta = GETDATE() - 1
set @fecha_archivo = @hoy
end
if (@fecha_desde = @hoy)
begin
set @fecha_desde = GETDATE() - 1
end
/**/
set @cant = (select COUNT(*) from cendeu_temp where convert(date,created) between @fecha_desde and @fecha_hasta)
if (@cant > 0)
begin
-- recorre por monitoreo
DECLARE bn2 CURSOR
FOR
select distinct cuit
from monitoreos
where visible = 1
and isnull(seccion_mantenimiento,'10') = '10'
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @fecha_hasta)
OPEN bn2
Fetch next from bn2 INTO @r_cuit
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
DECLARE cendeuc2 CURSOR
FOR
select id_cendeu, situacion
from cendeu_temp
where iden = @r_cuit
and vigente = 1
and (convert(date,created) between @fecha_desde and @fecha_hasta)
OPEN cendeuc2
FETCH next from cendeuc2 INTO @r_id_cendeu, @r_situacion
WHILE (@@FETCH_STATUS <> -1 )
BEGIN
if (CONVERT(int,@r_situacion) = 1)
begin
FETCH next from cendeuc2 INTO @r_id_cendeu, @r_situacion
continue
end
insert into @html
exec dbo.obtener_info_novedades @r_cuit,@r_id_cendeu,'cendeu_temp',null
set @html_txt = (select
'<td>' + nombre + '</td>' +
'<td>' + periodo + '</td>' +
'<td>' + situacion + '</td>' +
'<td align=right>' + replace (FORMAT(total,'### ### ### ### ### ###.00'),'.',',') + '</td>'
from @html)
delete from @html
--insert into monitoreos_resultados_temp
insert into monitoreos_resultados
(id_tabla, tabla, cuit, seccion_mantenimiento, fecha, novedad, tipo_novedad,html)
values (@r_id_cendeu, 'cendeu_temp', @r_cuit, '10', @fecha_archivo, 1, 'Bancos', @html_txt);
update monitoreos
set fecha_ultimo_procesamiento = @fecha_archivo,
fecha_modificacion = @fecha_archivo
where cuit = @r_cuit
and isnull(seccion_mantenimiento,10) = 10
and (fecha_vigencia_mantenimiento is null or fecha_vigencia_mantenimiento >= @fecha_hasta)
and (fecha_desde is null or fecha_desde <= @fecha_hasta)
FETCH next from cendeuc2 INTO @r_id_cendeu, @r_situacion
END
CLOSE cendeuc2
DEALLOCATE cendeuc2
FETCH next from bn2 INTO @r_cuit
END
CLOSE bn2
DEALLOCATE bn2
end
END
GO
Depends On
3Used By
No items found