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: