From 6f828020a24abb0dcb037d0a5463fbb99ab7dfa3 Mon Sep 17 00:00:00 2001 From: Administrator Date: Wed, 2 Sep 2026 11:11:21 -0500 Subject: [PATCH] Actualizar backend/core/data_manager.py --- backend/core/data_manager.py | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/backend/core/data_manager.py b/backend/core/data_manager.py index 836a75a..939a20b 100644 --- a/backend/core/data_manager.py +++ b/backend/core/data_manager.py @@ -677,6 +677,68 @@ class DataManager: print(f"❌ Error cronograma cobranza: {e}") return [] + def traer_vendedor_cod_detalle(self, matriculas): + """Para el apartado RETIROS: por cada num_matricula (solo las POR RETIRAR), + trae dsc_vendedor, cod_detalle, dsc_alumno, N° cuotas pagadas/vencidas, + fecha de vencimiento más antigua, imp_total_pagado e inv_neta. Consulta ligera.""" + try: + mats = [str(m).strip() for m in (matriculas or []) if str(m).strip()] + if not mats: + return {} + placeholders = ",".join(["?"] * len(mats)) + query = f""" + SELECT m.num_matricula, + (SELECT t.dsc_apellido_paterno + ' ' + SUBSTRING(t.dsc_apellido_materno,1,1) + '. ' + t.dsc_nombres + FROM rhuma_trabajador t WHERE t.cod_trabajador = m.cod_vendedor) AS dsc_vendedor, + m.cod_periodo AS cod_detalle, + (a.dsc_apellido_paterno + ' ' + a.dsc_apellido_materno + ', ' + a.dsc_nombres) AS dsc_alumno, + (SELECT COUNT(1) FROM sgede_cronograma_matricula c + WHERE c.cod_localidad=m.cod_localidad AND c.num_matricula=m.num_matricula + AND c.num_refinanciamiento=m.num_refinanciamiento + AND c.cod_tipo_cuota='ARM' AND c.cod_estado='CAN') AS num_cuotas_pagadas, + (SELECT COUNT(1) FROM sgede_cronograma_matricula c + WHERE c.cod_localidad=m.cod_localidad AND c.num_matricula=m.num_matricula + AND c.num_refinanciamiento=m.num_refinanciamiento + AND c.cod_tipo_cuota='ARM' AND c.cod_estado<>'CAN' + AND c.fch_vencimiento < CAST(GETDATE() AS DATE)) AS num_cuotas_vencidas, + (SELECT MIN(c.fch_vencimiento) FROM sgede_cronograma_matricula c + WHERE c.cod_localidad=m.cod_localidad AND c.num_matricula=m.num_matricula + AND c.num_refinanciamiento=m.num_refinanciamiento + AND c.cod_tipo_cuota='ARM' AND c.cod_estado<>'CAN' + AND c.fch_vencimiento < CAST(GETDATE() AS DATE)) AS fch_venc_mas_antigua, + (SELECT SUM(c.imp_total_pagado) FROM sgede_cronograma_matricula c + WHERE c.cod_localidad=m.cod_localidad AND c.num_matricula=m.num_matricula + AND c.num_refinanciamiento=m.num_refinanciamiento) AS imp_total_pagado, + ISNULL((SELECT SUM(c.imp_total - ISNULL(c.imp_dscto,0)) FROM sgede_cronograma_matricula c + WHERE c.cod_localidad=m.cod_localidad AND c.num_matricula=m.num_matricula + AND c.num_refinanciamiento=1),0) AS inv_neta + FROM sgeca_matricula m + INNER JOIN sgema_alumno a ON m.cod_alumno = a.cod_alumno + WHERE m.num_matricula IN ({placeholders}) + """ + conn = self.get_connection() + cursor = conn.cursor() + cursor.execute(query, mats) + out = {} + for row in cursor.fetchall(): + mat = str(row[0]).strip() + fvenc = row[6] + out[mat] = { + "dsc_vendedor": (row[1] or "").strip() if row[1] else "", + "cod_detalle": row[2] if row[2] is not None else "", + "dsc_alumno": (row[3] or "").strip() if row[3] else "", + "num_cuotas_pagadas": int(row[4] or 0), + "num_cuotas_vencidas": int(row[5] or 0), + "fch_venc_mas_antigua": (str(fvenc)[:10] if fvenc else ""), + "imp_total_pagado": float(row[7] or 0), + "inv_neta": float(row[8] or 0), + } + conn.close() + return out + except Exception as e: + print(f"❌ Error traer_vendedor_cod_detalle: {e}") + return {} + def ejecutar_consulta_facturas_cobranza(self, ano): clave = str(ano) en_cache = self._cache_facturas.get(clave)