2025-07-23 11:15:18 -05:00

118 lines
4.3 KiB
Transact-SQL

use telus;
/*verificar convenios antes del 2024*/
--exec agcm_telus_avaluo_emision_consulta 30398, '2025-01-08'
--exec telus_avaluo_emision_consulta 79914
--select * from agcm_2022_tram_liquidaciones_convenio where lote_id = 12800
--update agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where lote_id = 92434
--select * from avaluo_emision_anual_cabecera where lote_id = 12800 and esta_convenio = 1
--update avaluo_emision_anual_cabecera set esta_convenio = 0 where emision_id IN (1324866)
--select * from rentas_estado WHERE registro_lote_id = 18103
--update rentas_estado set estado = 0 WHERE registro_id = 4201;
--update rentas_estado set estado_registro = 'ACTIVO' WHERE registro_id = 20335;
/*
insert into rentas_estado(registro_lote_id,tipo_renta,estado,usuario_id,ip,pcname,detalle,estado_registro,fecha)
values(58167,0,1,18,'127.0.0.1','localhost','Convenio de pago Portal Ciudadano','ACTIVO', GETDATE())
update rentas_estado set estado_registro = 'ACTIVO' where registro_id = 19246;
*/
if OBJECT_ID('tempdb.dbo.#convenios_revisar') is not null
drop table #convenios_revisar
select id
into #convenios_revisar
from db_olympo_web.dbo.convenios_cabecera where code in('003367');
select b.ClaveCatastral, a.* from agcm_2022_tram_liquidaciones_convenio a
inner join telus_procesos.dbo.agcm_datos_claves_avaluos b on a.lote_id = b.lote_id
where a.id_convenio = (select id from #convenios_revisar) order by lote_id
select * from rentas_estado b
inner join agcm_2022_tram_liquidaciones_convenio a on b.registro_lote_id = a.lote_id
where a.id_convenio = (select id from #convenios_revisar)
and b.estado = 1 and estado_registro= 'ACTIVO'
order by lote_id
select b.* from avaluo_emision_anual_cabecera b
inner join agcm_2022_tram_liquidaciones_convenio a on b.lote_id = a.lote_id
where a.id_convenio = (select id from #convenios_revisar)
and b.esta_convenio = 1
order by b.lote_id
--update avaluo_emision_anual_cabecera set esta_convenio = 0 where emision_id in(1907614, 1990812)and esta_convenio = 1
--update rentas_estado set estado_registro = 'INACTIVO' where tipo_renta=0 and registro_lote_id = 63049 and estado_registro <> 'INACTIVO'
--update agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id = 5688
--GOTO SALIR
DECLARE
@id_tram_liq INT,
@lote_id INT,
@desde INT,
@hasta INT
DECLARE procesar_cursor CURSOR FOR
select --b.ClaveCatastral, a.estado,
a.id, a.lote_id, a.desde, a.hasta from agcm_2022_tram_liquidaciones_convenio a
inner join telus_procesos.dbo.agcm_datos_claves_avaluos b on a.lote_id = b.lote_id
where a.id_convenio = (select id from #convenios_revisar) order by lote_id
--SELECT top 1 registro_id FROM rentas_estado where tipo_renta=0 and registro_lote_id = 67325 and estado = 0 order by registro_id desc
print 'Fecha Hora Inicio'
print getdate()
OPEN procesar_cursor
FETCH NEXT FROM procesar_cursor
INTO @id_tram_liq,@lote_id, @desde, @hasta
WHILE @@FETCH_STATUS = 0
BEGIN
declare @estado_convenio int = 0
update agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO', fecha_actualiza = GETDATE() where id = @id_tram_liq and estado <> 'INACTIVO'
update avaluo_emision_anual_cabecera set esta_convenio = 0 where lote_id = @lote_id and ano_id between @desde and @hasta and esta_convenio = 1 and esta_pagado = 1
set @estado_convenio = isnull((select top 1 estado from rentas_estado where tipo_renta=0 and registro_lote_id = @lote_id and estado_registro = 'ACTIVO' and estado <> 0),0)
print @estado_convenio
if @estado_convenio = 1
begin
update rentas_estado set estado_registro = 'INACTIVO' where tipo_renta=0 and registro_lote_id = @lote_id and estado_registro <> 'INACTIVO'
insert into rentas_estado(registro_lote_id,tipo_renta,estado,usuario_id,ip,pcname,detalle,estado_registro,fecha)
select @lote_id,0,0,18,'127.0.0.1','localhost','Convenio rechazado por inclumplimiento de cuotas mensuales','ACTIVO',GETDATE()
end
/*ELSE
BEGIN
update rentas_estado set estado_registro = 'ACTIVO'
where registro_id in (SELECT top 1 registro_id FROM rentas_estado where tipo_renta=0 and registro_lote_id = @lote_id and estado = 0 order by registro_id desc)
END*/
FETCH NEXT FROM procesar_cursor
INTO @id_tram_liq,@lote_id, @desde, @hasta
END
CLOSE procesar_cursor
DEALLOCATE procesar_cursor;
print 'Fecha Hora Fin'
print getdate()
SALIR: