cambios de laz

This commit is contained in:
Darwin Quiroz 2024-11-21 11:39:26 -05:00
parent 61663e7f7f
commit 258596fe5b
11 changed files with 1047 additions and 27 deletions

View File

@ -7,7 +7,7 @@ if OBJECT_ID('tempdb.dbo.#convenios_revisar') is not null
select id
into #convenios_revisar
from db_olympo_web.dbo.convenios_cabecera where code in('002031');
from db_olympo_web.dbo.convenios_cabecera where code in('002658');
declare
@cuotas_pagadas int,
@ -116,17 +116,18 @@ order by x.recaudacion_id_mg;
goto salir
/*verificar si hay pagos no procesados*/
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where lote_id = 2338 and recaudacion_id_mg = 0
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas_detalle where lote_id = 2338 and recaudacion_id_mg = 0
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where lote_id = 7910 and recaudacion_id_mg = 0
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas_detalle where lote_id = 7910 and recaudacion_id_mg = 0
select * from agcm_2023_recaudacion_id_convenio where lote_id = 2338
select * from agcm_2023_recaudacion_id_convenio where lote_id = 7910
--delete db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where lote_id = 2338 and recaudacion_id_mg = 0
/*Ver recaudaciones de usuario portal ciudadano, con el que se procesan las recaudaciones de convenios*/
select * from recaudacion_registro_pago where lote_id = 18353
select sum(valor_pago) from recaudacion_registro_pago where lote_id = 36888
and usuario_id = 430
order by recaudacion_id desc
--order by recaudacion_id desc
SALIR:

View File

@ -7,7 +7,7 @@ if OBJECT_ID('tempdb.dbo.#convenios_revisar') is not null
select id
into #convenios_revisar
from db_olympo_web.dbo.convenios_cabecera where code in('002031');
from db_olympo_web.dbo.convenios_cabecera where code in('002658');
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
@ -20,26 +20,21 @@ select * from rentas_estado b
and b.estado = 1 and estado_registro= 'ACTIVO'
order by lote_id
select * from avaluo_emision_anual_cabecera b
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(1950676)and esta_convenio = 1
--update avaluo_emision_anual_cabecera set esta_convenio = 0 where emision_id in(1947170,1947170)and esta_convenio = 1
--update rentas_estado set estado_registro = 'INACTIVO' where tipo_renta=0 and registro_lote_id = 56354 and estado_registro <> 'INACTIVO'
--update agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id = 1916
--update agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id = 5688
GOTO SALIR
@ -98,3 +93,4 @@ print 'Fecha Hora Fin'
print getdate()
SALIR:

View File

@ -0,0 +1,133 @@
use telus;
/*verificar convenios antes del 2024*/
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('002658');
declare
@cuotas_pagadas int,
@total_lotes int,
@clave_verificar VARCHAR(max) = '',
@lote_id INT
set @lote_id = (select lote_id from telus_procesos.dbo.agcm_datos_claves_avaluos where ClaveCatastral = @clave_verificar);
set @cuotas_pagadas = (select count(*) from db_olympo_web.dbo.convenios_detalle de where agreement_id in(select id from #convenios_revisar) and all_paid = 1);
print 'Cuotas pagadas: ' + CAST(@cuotas_pagadas as VARCHAR(MAX));
if OBJECT_ID('tempdb.dbo.#lotes_convenio_re') is not null
drop table #lotes_convenio_re
select
DISTINCT
--top 10
lote_id
into #lotes_convenio_re
from agcm_2022_tram_liquidaciones_convenio lc where lc.id_convenio in(select id from #convenios_revisar);
set @total_lotes = (select COUNT(*) from #lotes_convenio_re);
print 'Claves catastrales: ' + CAST(@total_lotes as VARCHAR(MAX));
/*
/*INFORME DE PAGOS REALIZADOS EN OLYMPO*/
select max(pd.agreement_id) as id_convenio, max(pc.date) as fecha_pago, max(pc.code) as code, pd.id, pd.vouchers_id, pd.value_paid,pd.penalty_fee,pd.penalty_agreement, pd.to_paid
from db_olympo_web.dbo.convenios_pagos_detalle pd
inner join db_olympo_web.dbo.convenios_pagos_cabecera as pc on pc.id = pd.vouchers_id
where pd.agreement_id in (select id from #convenios_revisar) and vouchers_id is not null
group by pd.vouchers_id, pd.to_paid, pd.value_paid,pd.penalty_fee,pd.penalty_agreement,pd.id
order by pd.vouchers_id;
*/
if OBJECT_ID('tempdb.dbo.#infome_pagadas') is not null
drop table #infome_pagadas
select lm.titulo,MAX(cast(lm.observacion as Varchar(max))) AS obs, idpago as vouchers_id, MAX(c.fecha_pago) as fecha_pago, MAX(c.fecha_registro) as fecha_registro, MAX(c.lote_id) as lote_id, recaudacion_id_mg,sum(valor_pagar_unitario) as valor_pagado
into #infome_pagadas
from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas c
left join telus.dbo.agcm_2022_tram_liquidaciones_convenio l on l.id = c.id_tranliqui
left join db_olympo_web.dbo.liquidaciones_main lm on l.id_liquidacion = lm.id
where c.id_convenio_olympo in (select id from #convenios_revisar)
group by l.id_liquidacion,lm.titulo, idpago, recaudacion_id_mg
if OBJECT_ID('tempdb.dbo.#infome_pagadas_detalle') is not null
drop table #infome_pagadas_detalle
select
MAX(lm.titulo) as titulo,MAX(cast(lm.observacion as Varchar(max))) AS obs,
vouchers_id, c.id_convenio_olympo, MAX(c.fecha_pago) as fecha_pago, MAX(c.fecha_registro) as fecha_registro, MAX(c.lote_id) as lote_id, recaudacion_id_mg,valor_pagar_unitario as valor_pagado
into #infome_pagadas_detalle
from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas_detalle c
inner join db_olympo_web.dbo.convenios_pagos_detalle pd on c.idpago = pd.id
left join telus.dbo.agcm_2022_tram_liquidaciones_convenio l on l.id = c.id_tranliqui
left join db_olympo_web.dbo.liquidaciones_main lm on l.id_liquidacion = lm.id
where c.id_convenio_olympo in (select id from #convenios_revisar)
group by --l.id_liquidacion,lm.titulo,
pd.vouchers_id, recaudacion_id_mg,valor_pagar_unitario, c.id_convenio_olympo
SELECT x.titulo,
--x.obs,
x.vouchers_id, x.fecha_pago, x.fecha_registro, x.lote_id,da.ClaveCatastral, x.recaudacion_id_mg, valor_pagado ,
(select count(*) from agcm_2023_recaudacion_id_convenio where lote_id = x.lote_id) pagos_olympo
FROM #infome_pagadas x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
--where da.ClaveCatastral like '%'+ @clave_verificar
order by x.recaudacion_id_mg;
SELECT
x.titulo,
--x.obs,
x.vouchers_id,x.fecha_pago, x.fecha_registro, x.lote_id,da.ClaveCatastral, x.recaudacion_id_mg, valor_pagado,
(select count(*) from agcm_2023_recaudacion_id_convenio where lote_id = x.lote_id) pagos_olympo
FROM #infome_pagadas_detalle x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
--where da.ClaveCatastral like '%'+ @clave_verificar
order by x.recaudacion_id_mg;
/*INFORME DUPLICADAS*/
SELECT
count(*) as duplicados
FROM #infome_pagadas_detalle x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
where x.vouchers_id in (select vouchers_id from #infome_pagadas)
SELECT
x.titulo,
--x.obs,
x.vouchers_id,x.fecha_pago, x.fecha_registro, x.lote_id,da.ClaveCatastral, x.recaudacion_id_mg as recaudacion_id, valor_pagado
FROM #infome_pagadas_detalle x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
where x.vouchers_id in (select vouchers_id from #infome_pagadas)
--and recaudacion_id_mg not in(select distinct recaudacion_id_mg from #infome_pagadas)
order by x.recaudacion_id_mg;
goto salir
/*verificar si hay pagos no procesados*/
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where lote_id = 7910 and recaudacion_id_mg = 0
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas_detalle where lote_id = 7910 and recaudacion_id_mg = 0
select * from agcm_2023_recaudacion_id_convenio where lote_id = 7910
--delete db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where lote_id = 2338 and recaudacion_id_mg = 0
/*Ver recaudaciones de usuario portal ciudadano, con el que se procesan las recaudaciones de convenios*/
select sum(valor_pago) from recaudacion_registro_pago where lote_id = 36888
and usuario_id = 430
order by recaudacion_id desc
SALIR:

View File

@ -7,12 +7,21 @@ BEGIN
SET NOCOUNT ON;
-- ANTES DE PROCESA EJECUTAR EL PROCEDIMIENTO EXEC agcm_2023_tram_actualiza_valores_claves_convenio
SET @par_id_convenio = (select id from db_olympo_web.dbo.convenios_cabecera where code in('002031'));
-- VERIFICAR CONVENIO ESTADO
SET @par_id_convenio = (select id from db_olympo_web.dbo.convenios_cabecera where code in('002303'));
--select * from telus.dbo.agcm_2022_tram_liquidaciones_convenio where id_convenio in(@par_id_convenio)
--SELECT * FROM liquidaciones_main x where x.id = 726643
--update telus.dbo.agcm_2022_tram_liquidaciones_convenio set estado = 'ACTIVO' where id_liquidacion = 726643;
--update telus.dbo.agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id_convenio in(@par_id_convenio)
--update telus.dbo.agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id_convenio in(@par_id_convenio)
--GOTO SALIR
/*
select * from telus.dbo.agcm_2022_tram_liquidaciones_convenio where id_convenio in(@par_id_convenio)
GOTO SALIR
*/
declare @convenio_id int = 0--1008 --739 --1109--739
declare @fimain int =1, @tomain int =0
@ -65,11 +74,6 @@ BEGIN
and a.id not in(select id_pago_olympo from telus.dbo.agcm_2023_tram_id_pagos_olympo_omitir) -- Se agregó
order by a.id
/*
select * from #con
GOTO SALIR
*/
delete x from #con x, agcm_2023_recaudacion_cuotas y
where y.idpago=x.idpagCab and x.to_paid=y.valor_pagar_unitario
@ -85,6 +89,7 @@ BEGIN
/*
SELECT ROW_NUMBER() over(order by a.id) as fila, a.* into #con FROM convenios_pagos_cabecera a
WHERE a.id IN (

View File

@ -0,0 +1,96 @@
use telus;
/*verificar convenios antes del 2024*/
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('002538');
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(1947170,1947170)and esta_convenio = 1
--update rentas_estado set estado_registro = 'INACTIVO' where tipo_renta=0 and registro_lote_id = 56354 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:

View File

@ -0,0 +1,133 @@
use telus;
/*verificar convenios antes del 2024*/
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('002658');
declare
@cuotas_pagadas int,
@total_lotes int,
@clave_verificar VARCHAR(max) = '',
@lote_id INT
set @lote_id = (select lote_id from telus_procesos.dbo.agcm_datos_claves_avaluos where ClaveCatastral = @clave_verificar);
set @cuotas_pagadas = (select count(*) from db_olympo_web.dbo.convenios_detalle de where agreement_id in(select id from #convenios_revisar) and all_paid = 1);
print 'Cuotas pagadas: ' + CAST(@cuotas_pagadas as VARCHAR(MAX));
if OBJECT_ID('tempdb.dbo.#lotes_convenio_re') is not null
drop table #lotes_convenio_re
select
DISTINCT
--top 10
lote_id
into #lotes_convenio_re
from agcm_2022_tram_liquidaciones_convenio lc where lc.id_convenio in(select id from #convenios_revisar);
set @total_lotes = (select COUNT(*) from #lotes_convenio_re);
print 'Claves catastrales: ' + CAST(@total_lotes as VARCHAR(MAX));
/*
/*INFORME DE PAGOS REALIZADOS EN OLYMPO*/
select max(pd.agreement_id) as id_convenio, max(pc.date) as fecha_pago, max(pc.code) as code, pd.id, pd.vouchers_id, pd.value_paid,pd.penalty_fee,pd.penalty_agreement, pd.to_paid
from db_olympo_web.dbo.convenios_pagos_detalle pd
inner join db_olympo_web.dbo.convenios_pagos_cabecera as pc on pc.id = pd.vouchers_id
where pd.agreement_id in (select id from #convenios_revisar) and vouchers_id is not null
group by pd.vouchers_id, pd.to_paid, pd.value_paid,pd.penalty_fee,pd.penalty_agreement,pd.id
order by pd.vouchers_id;
*/
if OBJECT_ID('tempdb.dbo.#infome_pagadas') is not null
drop table #infome_pagadas
select lm.titulo,MAX(cast(lm.observacion as Varchar(max))) AS obs, idpago as vouchers_id, MAX(c.fecha_pago) as fecha_pago, MAX(c.fecha_registro) as fecha_registro, MAX(c.lote_id) as lote_id, recaudacion_id_mg,sum(valor_pagar_unitario) as valor_pagado
into #infome_pagadas
from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas c
left join telus.dbo.agcm_2022_tram_liquidaciones_convenio l on l.id = c.id_tranliqui
left join db_olympo_web.dbo.liquidaciones_main lm on l.id_liquidacion = lm.id
where c.id_convenio_olympo in (select id from #convenios_revisar)
group by l.id_liquidacion,lm.titulo, idpago, recaudacion_id_mg
if OBJECT_ID('tempdb.dbo.#infome_pagadas_detalle') is not null
drop table #infome_pagadas_detalle
select
MAX(lm.titulo) as titulo,MAX(cast(lm.observacion as Varchar(max))) AS obs,
vouchers_id, c.id_convenio_olympo, MAX(c.fecha_pago) as fecha_pago, MAX(c.fecha_registro) as fecha_registro, MAX(c.lote_id) as lote_id, recaudacion_id_mg,valor_pagar_unitario as valor_pagado
into #infome_pagadas_detalle
from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas_detalle c
inner join db_olympo_web.dbo.convenios_pagos_detalle pd on c.idpago = pd.id
left join telus.dbo.agcm_2022_tram_liquidaciones_convenio l on l.id = c.id_tranliqui
left join db_olympo_web.dbo.liquidaciones_main lm on l.id_liquidacion = lm.id
where c.id_convenio_olympo in (select id from #convenios_revisar)
group by --l.id_liquidacion,lm.titulo,
pd.vouchers_id, recaudacion_id_mg,valor_pagar_unitario, c.id_convenio_olympo
SELECT x.titulo,
--x.obs,
x.vouchers_id, x.fecha_pago, x.fecha_registro, x.lote_id,da.ClaveCatastral, x.recaudacion_id_mg, valor_pagado ,
(select count(*) from agcm_2023_recaudacion_id_convenio where lote_id = x.lote_id) pagos_olympo
FROM #infome_pagadas x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
--where da.ClaveCatastral like '%'+ @clave_verificar
order by x.recaudacion_id_mg;
SELECT
x.titulo,
--x.obs,
x.vouchers_id,x.fecha_pago, x.fecha_registro, x.lote_id,da.ClaveCatastral, x.recaudacion_id_mg, valor_pagado,
(select count(*) from agcm_2023_recaudacion_id_convenio where lote_id = x.lote_id) pagos_olympo
FROM #infome_pagadas_detalle x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
--where da.ClaveCatastral like '%'+ @clave_verificar
order by x.recaudacion_id_mg;
/*INFORME DUPLICADAS*/
SELECT
count(*) as duplicados
FROM #infome_pagadas_detalle x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
where x.vouchers_id in (select vouchers_id from #infome_pagadas)
SELECT
x.titulo,
--x.obs,
x.vouchers_id,x.fecha_pago, x.fecha_registro, x.lote_id,da.ClaveCatastral, x.recaudacion_id_mg as recaudacion_id, valor_pagado
FROM #infome_pagadas_detalle x
inner join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
where x.vouchers_id in (select vouchers_id from #infome_pagadas)
--and recaudacion_id_mg not in(select distinct recaudacion_id_mg from #infome_pagadas)
order by x.recaudacion_id_mg;
goto salir
/*verificar si hay pagos no procesados*/
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where lote_id = 7910 and recaudacion_id_mg = 0
select * from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas_detalle where lote_id = 7910 and recaudacion_id_mg = 0
select * from agcm_2023_recaudacion_id_convenio where lote_id = 7910
--delete db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where lote_id = 2338 and recaudacion_id_mg = 0
/*Ver recaudaciones de usuario portal ciudadano, con el que se procesan las recaudaciones de convenios*/
select sum(valor_pago) from recaudacion_registro_pago where lote_id = 36888
and usuario_id = 430
--order by recaudacion_id desc
SALIR:

View File

@ -0,0 +1,106 @@
use telus;
if OBJECT_ID('tempdb.dbo.#reintegrar') is not null
drop table #reintegrar
/*OBTENEMOS LOS RECAUDACION IDS A REINTEGRAR DE ACUERDO AL ANÁLISIS DEL SCRIPT 001 VERIFICAR CONVENIO*/
select * into #reintegrar from recaudacion_registro_pago where usuario_id = 430
and recaudacion_id in (
728498,
728499,
728500,
728501,
728502,
728503,
728504,
728505,
734004,
734005
)
order by recaudacion_id desc
select pg.recaudacion_id
from recaudacion_registro_pago pg
inner join #reintegrar r on r.recaudacion_id = pg.recaudacion_id
where pg.usuario_id = 430
order by pg.recaudacion_id desc
--GOTO SALIR
/*OJO: VERIFICAR SI NO HAY PAGOS ENTRE EL PAGO INICIAL Y LOS PAGOS DUPLICADOS*/
/*SI APLICA LOS REINTEGROS DESCOMENTAR DESDE LAS LINEAS 29 HASTA LA 35 DEL PROCEDIMIENTO [dbo].[telus_recaudacion_registro_pago_reintegro]*/
DECLARE
@rec_id INT,
@estado INT;
DECLARE reintegrar_cursor CURSOR FOR
select pg.recaudacion_id
from recaudacion_registro_pago pg
inner join #reintegrar r on r.recaudacion_id = pg.recaudacion_id
where pg.usuario_id = 430
order by pg.recaudacion_id desc
OPEN reintegrar_cursor
FETCH NEXT FROM reintegrar_cursor
INTO @rec_id
WHILE @@FETCH_STATUS = 0
BEGIN
if OBJECT_ID('tempdb.dbo.#response_table') is not null
drop table #response_table
create table #response_table (estado int);
PRINT '-------------------------'
print 'reintegrando: ' + cast(@rec_id as varchar);
insert into #response_table
exec [dbo].[telus_recaudacion_registro_pago_reintegro] 430, @rec_id, 'Se reintegra ya que se verificó que se duplicaron las recaudaciones en el sistema MantaGIS';
SET @estado = (select estado from #response_table)
if @estado > 0
begin
print CAST(@estado AS VARCHAR) + ' ' + CAST(@rec_id AS VARCHAR);
delete from agcm_2023_recaudacion_id_convenio where recaudacion_id = @rec_id;
delete from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas_detalle where recaudacion_id_mg = @rec_id;
delete from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas where recaudacion_id_mg = @rec_id;
end
else
print 'NO SE PUDO REINTEGRAR ' + CAST(@estado AS VARCHAR) + ' ' + CAST(@rec_id AS VARCHAR)
FETCH NEXT FROM reintegrar_cursor
INTO @rec_id
END
CLOSE reintegrar_cursor
DEALLOCATE reintegrar_cursor;
--informe reintegro;
SELECT da.ClaveCatastral, x.* FROM recaudacion_reintegro_registro_pago x
left join telus_procesos.dbo.agcm_datos_claves_avaluos da on x.lote_id = da.lote_id
inner join #reintegrar ri on ri.recaudacion_id = x.recaudacion_id
GOTO SALIR
select * from recaudacion_reintegro_registro_pago rp
inner join recaudacion_reintegro_registro_pago_lote rpl on rp.recaudacion_id = rpl.recaudacion_id
inner join #reintegrar r on rp.recaudacion_id = r.recaudacion_id
/* verificar las costas y ver si el tributo está pagado */
select * from avaluo_emision_anual_cabecera where lote_id = 2338 order by emision_id desc
--update avaluo_emision_anual_cabecera set costa_valor = 0, esta_pagado = 1 where lote_id = 2338 and emision_id = 1425501
SALIR:

View File

@ -0,0 +1,445 @@
USE [db_olympo_web]
BEGIN
declare @par_id_convenio int = 0;
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- ANTES DE PROCESA EJECUTAR EL PROCEDIMIENTO EXEC agcm_2023_tram_actualiza_valores_claves_convenio
-- VERIFICAR CONVENIO ESTADO
SET @par_id_convenio = (select id from db_olympo_web.dbo.convenios_cabecera where code in('002658'));
--select * from telus.dbo.agcm_2022_tram_liquidaciones_convenio where id_convenio in(@par_id_convenio)
--SELECT * FROM liquidaciones_main x where x.id = 726643
--update telus.dbo.agcm_2022_tram_liquidaciones_convenio set estado = 'ACTIVO' where id_liquidacion = 726643;
--update telus.dbo.agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id_convenio in(@par_id_convenio)
--update telus.dbo.agcm_2022_tram_liquidaciones_convenio set estado = 'INACTIVO' where id_convenio in(@par_id_convenio)
--GOTO SALIR
declare @convenio_id int = 0--1008 --739 --1109--739
declare @fimain int =1, @tomain int =0
if OBJECT_ID('tempdb.dbo.#conmain') is not null
drop table #conmain
select ROW_NUMBER() over(order by a.id_convenio) as fila,a.id_convenio,count(*) Total
into #conmain
from telus.dbo.agcm_2022_tram_liquidaciones_convenio a
where (a.estado='ACTIVO' )
and a.id_convenio in(@par_id_convenio)
group by a.id_convenio
order by a.id_convenio
print @@ROWCOUNT
create index IX_LO_FI_con on #conmain(fila,id_convenio)
/*
select * from #conmain
GOTO SALIR
*/
set @tomain = (select count(*) from #conmain)
print CONVERT(varchar(20), GETDATE(), 131)
--
declare @estadopagos table(idpago int, mensaje varchar(max),lote_id int)
declare @cantidadxconvenio int =0
declare @cantidadxconvenioID varchar(max)='NO PROCESADO'
--
while @fimain <=@tomain
begin
set @convenio_id = (select a.id_convenio from #conmain a where a.fila=@fimain)
print '@convenio_id'
print @convenio_id
print CONVERT(varchar(20), GETDATE(), 131)
print '===================='
if OBJECT_ID('tempdb.dbo.#con') is not null
drop table #con
SELECT ROW_NUMBER() over(order by a.id) as fila,a.id as idpagCab, a.date,x.* into #con FROM convenios_pagos_cabecera a,convenios_pagos_detalle x
WHERE a.id = x.vouchers_id and x.agreement_id IN (
SELECT y.id FROM convenios_cabecera y where y.id=@convenio_id
) and x.tax_id=3 -- Impuesto Predial
and a.state='approved'
and x.id not in(
select xxy.idpago from agcm_2023_recaudacion_cuotas_detalle xxy
)
and a.id not in(
select xxyz.idpago from agcm_2023_recaudacion_cuotas xxyz
)
and a.id not in(select id_pago_olympo from telus.dbo.agcm_2023_tram_id_pagos_olympo_omitir) -- Se agreg<65>
order by a.id
delete x from #con x, agcm_2023_recaudacion_cuotas y
where y.idpago=x.idpagCab and x.to_paid=y.valor_pagar_unitario
DECLARE @contador INT = 0;
UPDATE #con SET fila = @contador, @contador = @contador + 1;
/*
select * from #con
GOTO SALIR
*/
/*
SELECT ROW_NUMBER() over(order by a.id) as fila, a.* into #con FROM convenios_pagos_cabecera a
WHERE a.id IN (
SELECT x.vouchers_id FROM convenios_pagos_detalle x
WHERE x.agreement_id IN (
SELECT y.id FROM convenios_cabecera y where y.id=@convenio_id
) and x.tax_id=3 -- Impuesto Predial
) and a.state='approved'
and a.id not in(
select xx.idpago from db_olympo_web.dbo.agcm_2023_recaudacion_cuotas xx
)
and a.id not in(select id_pago_olympo from telus.dbo.agcm_2023_tram_id_pagos_olympo_omitir) -- Se agreg<65>
order by a.id
*/
print @@ROWCOUNT
-- select * from #con order by create_date
declare @fila int =1,@total int=0
declare @fecha date,@fecha_convenio date, @id int, @idliqui int
--
declare @valorpagado numeric(18,2)=0
declare @tbredis table(fila int identity(1,1),idpago int,fecha_pago date,lote_id int,valorconveniototal numeric(18,3),
valorconvenio numeric(18,3),factor numeric(18,8),valor_pagar_total numeric(18,2),valor_pagar_unitario numeric(18,2),
id_tranliqui int,id_convenio_olympo int,recaudacion_id_mg varchar(max),aniodesde int,aniohasta int)
declare @idfila int=0,@toidfila int =0
declare @resrecau int
declare @idusuariorec int
set @idusuariorec = (select top 1 a.usuario_id from telus.dbo.agcm_2023_usuarios_ocultos_recaudacion a)
--
declare @kardexDeu table (emision_id int, lote_id int,rubro_id int,ano_id int,base_imponible numeric (25,2),rubro varchar (max), saldo numeric (11,2) ,valor_porcentaje numeric (11,2))
declare @deudafinal numeric(18,2)
declare @aniodesde int, @aniohasta int
declare @deudafinaldesdehasta numeric(18,2)
--
declare @msgproc varchar(100) = 'PROCESADO'
--
set @total = (select count(*) from #con)
while @fila<=@total
begin
BEGIN TRANSACTION;
Begin Try
declare
@par_valor_pagado numeric(11,2)=0,
@par_lote_id int=0,
@card varchar(max)=''
,@NumeroTransaccion varchar(max)=''
,@id_tranliqui int =0
select @fecha = a.date, @id=a.id from #con a where a.fila=@fila
select @valorpagado = a.to_paid, @idliqui = a.collection_id from convenios_pagos_detalle a where a.id = @id and a.tax_id=3
print '@valorpagado'
print @valorpagado
print '@idliqui'
print @idliqui
--delete from @tbredis
-- Insertar para recorrer Tabla de Lotes
insert into @tbredis
select @id,@fecha,a.lote_id,0,a.valor,0,@valorpagado,0,a.id,a.id_convenio,0,a.desde,a.hasta
from telus.dbo.agcm_2022_tram_liquidaciones_convenio a where a.id_convenio=@convenio_id and
a.id_liquidacion=@idliqui and (a.estado='ACTIVO' ) --or a.estado='PROCESARPAGO'
-- Actualizar valor de deuda seg<65>n la clave que tenga prioridad
select * from @tbredis
Rollback;
goto SALIR
print @@ROWCOUNT
set @idfila = (select count(*) from @tbredis a where a.idpago=@id)
if @idfila = 0
begin
print '========INACTIVO lINea 141==================='
set @msgproc = 'NO PROCESADO, CONVENIO INACTIVO: ' + cast(@convenio_id as varchar)+' Liquidacion: '+ cast(@idliqui as varchar)
goto CONTINUAR
end
set @idfila = (select min(a.fila) from @tbredis a where a.idpago=@id)
set @toidfila = (select max(a.fila) from @tbredis a where a.idpago=@id)
declare @fifima int = @idfila
declare @buslo int = 0
/*
update @tbredis set valorconvenio=163.14 where fila=1
update @tbredis set valorconvenio=200 where fila=2
update @tbredis set valor_pagar_total=400
*/
while @idfila<=@toidfila
begin
if @idfila=@fifima
begin
update @tbredis set valorconveniototal = (select sum(valorconvenio) from @tbredis where idpago=@id)
where idpago=@id
-- Prioritario
set @buslo = isnull((select top 1 a.lote_id from telus.dbo.agcm_2023_tram_lotes_prioridad a,@tbredis b
where a.lote_id=b.lote_id and a.id_convenio=b.id_convenio_olympo and a.estado='ACTIVO' order by a.lote_id),0)
print '@buslo'
print @buslo
print @par_lote_id
declare @filasafectadas int =0
update x set factor = x.valorconvenio / x. valorconveniototal
from @tbredis x where x.idpago=@id
--select * from @tbredis
end
if @buslo>0 and @idfila=@fifima
begin
declare @fatoresuno int =0
update x set x.factor = 1
from @tbredis x where x.idpago=@id and x.valor_pagar_total<=x.valorconvenio and x.lote_id in(
select a.lote_id from telus.dbo.agcm_2023_tram_lotes_prioridad a,@tbredis b
where a.lote_id=b.lote_id and a.id_convenio=b.id_convenio_olympo and a.estado='ACTIVO'
) and x.factor<>1
set @filasafectadas = @@ROWCOUNT
-- select * from @tbredis
print 'Filas afectadas'
print @filasafectadas
declare @tbcalcu table(lote_id int,id_convenio_olympo int,idpago int,fx numeric(18,8),fxd numeric(18,8))
if @filasafectadas=0
begin
declare @fx numeric(18,8)= 0
declare @fxdi numeric(18,8)= 0
declare @fxsum numeric(18,8)= 0
-- select * from @tbredis
insert into @tbcalcu (lote_id,id_convenio_olympo,idpago,fx)
select x.lote_id,x.id_convenio_olympo,x.idpago,( x.valorconvenio/x.valor_pagar_total) as fx
from @tbredis x,telus.dbo.agcm_2023_tram_lotes_prioridad y where x.idpago=@id and x.valor_pagar_total>x.valorconvenio and x.lote_id=y.lote_id and y.estado='ACTIVO'
and y.id_convenio=x.id_convenio_olympo and x.valor_pagar_total>0 order by y.lote_id
update @tbcalcu set fxd = 1 - (select sum(fx) from @tbcalcu where idpago=@id) where idpago=@id
set @fxsum = isnull((select sum(x.factor)
from @tbredis x where x.idpago=@id and x.lote_id not in (select lote_id from @tbcalcu)),0)
print '@fxsum'
print @fxsum
set @fxdi = (select max(fxd) from @tbcalcu where idpago=@id)
--select * from @tbcalcu
/*
set @fx = isnull((select ((100 * x.valorconvenio)/x.valor_pagar_total)/100
from @tbredis x,telus.dbo.agcm_2023_tram_lotes_prioridad y where x.idpago=@id and x.valor_pagar_total>x.valorconvenio and x.lote_id=y.lote_id and y.estado='ACTIVO' and y.id_convenio=x.id_convenio_olympo and x.valor_pagar_total>0),0)
*/
/*
print 'nsi'
set @fxdi = 1 - @fx
*/
update x set x.factor = y.fx from @tbredis x,@tbcalcu y where x.lote_id=y.lote_id and x.id_convenio_olympo= y.id_convenio_olympo and x.idpago=y.idpago and y.idpago=@id
update x set x.factor = (x.factor * @fxdi)/@fxsum from @tbredis x where x.lote_id not in(select lote_id from @tbcalcu) and x.idpago=@id
--select * from @tbcalcu
--select * from @tbredis
--GOTO SALIR
delete from @tbcalcu
end
else
begin
update x set x.factor=0 from @tbredis x where x.idpago=@id and x.factor<>1
set @filasafectadas = (select count(*) from @tbredis a where a.factor=1)
if @filasafectadas >1
begin
print 'Nuevo proceso'
update x set x.factor=0 from @tbredis x where x.idpago=@id and x.factor=1 and x.fila not in(
select min(y.fila) from @tbredis y where y.idpago=@id and y.factor=1
)
end
end
end -- FIn IF
update x set x.valor_pagar_unitario = x.factor * x.valor_pagar_total
from @tbredis x where x.idpago=@id
-- ===================================================
-- Procesar Pago
select @par_valor_pagado=a.valor_pagar_unitario,@par_lote_id=a.lote_id,
@card ='Recaudaci<EFBFBD>n Facilidad de Pago. Control #'+cast(a.id_convenio_olympo as varchar(30)) ,
@NumeroTransaccion = cast(a.idpago as varchar(30)),
@aniodesde=a.aniodesde,@aniohasta=a.aniohasta,@id_tranliqui=a.id_tranliqui
from @tbredis a
where a.fila=@idfila
-- Verificaci<63>n si existe Pago
declare @noproxy int = isnull((select x.fila from agcm_2023_recaudacion_cuotas_detalle x where x.lote_id=@par_lote_id and x.idpago=@id and x.fecha_pago=@fecha and x.recaudacion_id_mg<>'0'),0)
print '@noproxy'
print @noproxy
set @msgproc = 'PROCESADO'
if @noproxy>0
begin
print '========PAGO YA FUE PROCESADO==================='
set @msgproc = 'NO PROCESADO, PAGO EFECTUADO CON ANTERIORIDAD'
goto CONTINUARLOTE
end
if @par_valor_pagado=0
begin
print '========PAGO En CERO==================='
set @msgproc = 'NO PROCESADO, PAGO EN CERO'
goto CONTINUARLOTE
end
/*
select * from @tbredis
print 'VER VALORCITO'
print @par_valor_pagado
print @par_lote_id
print '===================FECHA=============='
print @fecha
select @msgproc
Rollback;
goto SALIR
*/
-- Ejecutar Pago
print '========PROCESANDO PAGO==================='
--exec telus.dbo.agcm_2023_telus_recaudacion_registro_pago_convenios @idusuariorec,4,@par_valor_pagado,@par_valor_pagado,0,@par_lote_id,-2,null,null,null,@card ,@id,@fecha
exec telus.dbo.akla_2024_telus_recaudacion_registro_pago_convenios @idusuariorec,4,@par_valor_pagado,@par_valor_pagado,0,@par_lote_id,-2,null,null,null,@card, @id, @fecha,1,@fecha_convenio
print '========FIN PROCESANDO PAGO==================='
/*
select @idusuariorec,4,@par_valor_pagado,@par_valor_pagado,0,@par_lote_id,-2,null,null,null,@card ,@id,@fecha
Rollback;
--set @fila = 100
goto SALIR
*/
--
set @resrecau = isnull((select a.recaudacion_id from telus.dbo.agcm_2023_recaudacion_id_convenio a where a.pago_id_ol=@id and a.lote_id=@par_lote_id),0)
print 'XXXXXXXXXXXXXXXXXXXXXXXX'
print @resrecau
if @resrecau = 0
begin
print '========EL PAGO no FUE PROCESADO==================='
set @msgproc = 'NO PROCESADO, ERROR EN EL PAGO'
goto CONTINUARLOTE
end
set @msgproc = 'PROCESADO'
-- ==============================================
update @tbredis set recaudacion_id_mg=@resrecau where fila=@idfila
-- Final
declare @fefe date = getdate()
insert into @kardexDeu
exec telus.dbo.agcm_telus_avaluo_emision_consulta @par_lote_id,@fefe
set @deudafinal = isnull((select sum(a.saldo+a.valor_porcentaje) from @kardexDeu a where a.ano_id between @aniodesde and @aniohasta),0)
if @deudafinal=0
BEGIN
update x Set x.estado='INACTIVO',x.fecha_actualiza=getdate()
from telus.dbo.agcm_2022_tram_liquidaciones_convenio x
where x.id=@id_tranliqui
Update x set x.esta_convenio=0
from telus.dbo.avaluo_emision_anual_cabecera x
where x.esta_convenio=1 and x.ano_id between @aniodesde and @aniohasta
and x.lote_id=@par_lote_id
-- exec telus_avaluo_emision_anual_cabecera_actualizar_saldo
update x set x.estado_registro='INACTIVO'
from telus.dbo.rentas_estado x
where x.tipo_renta=0 and x.registro_lote_id=@par_lote_id and x.estado_registro='ACTIVO'
insert into telus.dbo.rentas_estado(registro_lote_id,tipo_renta,estado,usuario_id,ip,pcname,detalle,estado_registro,fecha)
select @par_lote_id,0,0,18,'127.0.0.1','localhost','Facilidad de Pago satisfactoria. '+@card,'ACTIVO',GETDATE()
if @buslo>0
begin
update telus.dbo.agcm_2023_tram_lotes_prioridad set estado='INACTIVO' where lote_id=@par_lote_id and estado='ACTIVO'
end
end
else
begin
update x Set x.valor=@deudafinal,x.fecha_actualiza=getdate()
from telus.dbo.agcm_2022_tram_liquidaciones_convenio x
where x.id=@id_tranliqui and x.lote_id=@par_lote_id
end
delete from @kardexDeu
set @cantidadxconvenioID = 'PROCESADO'
CONTINUARLOTE:
insert into @estadopagos
select @id,@msgproc+': lote_id=' + cast(@par_lote_id as varchar) + ' => ' + @card,@par_lote_id
--set @msgproc = 'FIN RECORRIDO DE LOTES'
print cast(@idfila as varchar) + ' de ' + cast(@toidfila as varchar) + ' lotes, lote_id = ' +cast(@par_lote_id as varchar)+ ' @id_tranliqui:'+cast(@id_tranliqui as varchar)
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/*
if @par_lote_id = 95989
begin
select * from @tbredis
select * from @estadopagos
print 'VER VALORCITO'
print @par_valor_pagado
print @par_lote_id
select @msgproc
Rollback;
goto SALIR
end
*/
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
set @idfila = @idfila + 1
set @par_lote_id = 0
set @card =''
end --Fin While Recorre Claves
-- ===================================================
set @cantidadxconvenio = @cantidadxconvenio + 1
CONTINUAR:
print @fecha
print @valorpagado
print @idliqui
print 'FILA: ' + cast(@fila as varchar) + ' ID PAgo: '+cast(@id as varchar )
PRINT '====================================================='
PRINT '====================================================='
/*
insert into @estadopagos
select @id,@msgproc+': lote_id=' + cast(@par_lote_id as varchar) + ' => ' + @card,@par_lote_id
*/
COMMIT;-- TRAN Pago
End try
Begin Catch
Rollback;-- TRAN Pago
insert into @estadopagos
select @id,'NO PROCESADO: ' + ERROR_MESSAGE() + ' -> ' +ERROR_PROCEDURE() +' ->' +cast(ERROR_LINE() as varchar),0
End Catch
set @fila = @fila + 1
/*
IF @id=4681591
set @fila = 100
*/
end -- End While
--select * from @estadopagos
if OBJECT_ID('tempdb.dbo.#inser') is not null
drop table #inser
select *
into #inser
from @tbredis
--select * from #inser
delete x from #inser x,agcm_2023_recaudacion_cuotas_detalle y
where x.lote_id=y.lote_id and x.fecha_pago=y.fecha_pago and x.idpago=y.idpago
delete x from #inser x,@estadopagos y
where x.idpago=y.idpago and y.mensaje like 'NO PROCESADO%' and x.lote_id=y.lote_id
insert into agcm_2023_recaudacion_cuotas_detalle(idpago,fecha_pago,lote_id,valorconveniototal,valorconvenio,factor,valor_pagar_total,
valor_pagar_unitario,id_tranliqui,id_convenio_olympo,recaudacion_id_mg,aniodesde,aniohasta)
select idpago,fecha_pago,lote_id,valorconveniototal,valorconvenio,factor,valor_pagar_total,
valor_pagar_unitario,id_tranliqui,id_convenio_olympo,recaudacion_id_mg,aniodesde,aniohasta from #inser a
/*
drop table #con
drop table #inser
*/
print '****************************************************************************************'
print cast(@fimain as varchar) + ' de ' +cast(@tomain as varchar)
set @fimain = @fimain + 1
insert into tmp_proceso_convenios(convenio_id,cantidadpago,estado)
select @convenio_id,@cantidadxconvenio,@cantidadxconvenioID
set @cantidadxconvenioID = ''
set @cantidadxconvenio = 0
end-- Fin While General
print CONVERT(varchar(20), GETDATE(), 131)
insert into agcm_2023_log_estado_pagos(idpago,mensaje)
select idpago,mensaje from @estadopagos
/*
select * from @estadopagos
select * from agcm_2023_recaudacion_cuotas
*/
drop table #con
drop table #inser
drop table #conmain
SALIR:
print '----------------------------------------------------------------------'
print 'FINALIZADO'
print '----------------------------------------------------------------------'
END

View File

@ -0,0 +1,96 @@
use telus;
/*verificar convenios antes del 2024*/
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('002538');
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(1947170,1947170)and esta_convenio = 1
--update rentas_estado set estado_registro = 'INACTIVO' where tipo_renta=0 and registro_lote_id = 56354 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:

View File

@ -22,3 +22,12 @@ select collection_dividend_id,
where cvl.agreement_id = 2761
group by cvl.collection_dividend_id, cll_c.id
order by cvl.collection_dividend_id
SELECT x.* FROM public.cll_vouchers_line x,cll_dividend_line y,cll_collection z
WHERE x.collection_dividend_id = y.id
and y.cll_collection_id =z.id
and z.create_uid =43
and x.tax_id =3
and x.vouchers_id = 9859195
ORDER BY z.id,x.agreement_id