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 ( 746985, 746986, 746987, 746988, 746989, 746990, 746991, 746992, 746993, 746994, 746995, 746996, 746997, 746998, 746999, 747000, 747001, 747002 ) 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: