diff --git a/backend/core/data_manager.py b/backend/core/data_manager.py index 5ff5584..ee961bb 100644 --- a/backend/core/data_manager.py +++ b/backend/core/data_manager.py @@ -707,13 +707,16 @@ class DataManager: if not mats: return {} corte_venc = "CAST(GETDATE() AS DATE)" + ini_mes = "CAST(GETDATE() AS DATE)" if ano and mes: try: _a, _m = int(ano), int(mes) _na, _nm = (_a + 1, 1) if _m == 12 else (_a, _m + 1) corte_venc = f"CAST('{_na:04d}-{_nm:02d}-01' AS DATE)" + ini_mes = f"CAST('{_a:04d}-{_m:02d}-01' AS DATE)" except Exception: corte_venc = "CAST(GETDATE() AS DATE)" + ini_mes = "CAST(GETDATE() AS DATE)" try: conn = self.get_connection() cursor = conn.cursor() @@ -742,14 +745,33 @@ class DataManager: AND c.cod_tipo_cuota = 'ARM' AND c.cod_estado <> 'CAN' AND c.fch_vencimiento < {corte_venc}) AS num_cuotas_vencidas, - (SELECT MIN(c.fch_vencimiento) + STUFF((SELECT ' - ' + CONVERT(varchar(10), c.fch_vencimiento, 103) 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 < {corte_venc}) AS fch_venc_mas_antigua, + AND c.fch_vencimiento < {corte_venc} + ORDER BY c.fch_vencimiento + FOR XML PATH('')), 1, 3, '') AS fch_venc_mas_antigua, + ISNULL((SELECT SUM(c.imp_total - ISNULL(c.imp_dscto,0) - ISNULL(c.imp_total_pagado,0)) + 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 < {ini_mes}), 0) AS monto_venc_ant, + ISNULL((SELECT SUM(c.imp_total - ISNULL(c.imp_dscto,0) - ISNULL(c.imp_total_pagado,0)) + 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 >= {ini_mes} + AND c.fch_vencimiento < {corte_venc}), 0) AS monto_venc_cur, (SELECT SUM(c.imp_total_pagado) FROM sgede_cronograma_matricula c WHERE c.cod_localidad = m.cod_localidad @@ -786,15 +808,19 @@ class DataManager: _mult = _tc if _moneda == "DOL" else 1.0 _pag = float(f.get("imp_total_pagado") or 0) * _mult _inv = float(f.get("inv_neta") or 0) * _mult + _mva = float(f.get("monto_venc_ant") or 0) * _mult + _mvc = float(f.get("monto_venc_cur") or 0) * _mult out[str(f.get("num_matricula", "")).strip()] = { "dsc_vendedor": str(f.get("dsc_vendedor") or "").strip(), "cod_detalle": str(f.get("cod_detalle") or "").strip(), "dsc_alumno": str(f.get("dsc_alumno") or "").strip(), "num_cuotas_pagadas": int(f.get("num_cuotas_pagadas") or 0), "num_cuotas_vencidas": int(f.get("num_cuotas_vencidas") or 0), - "fch_venc_mas_antigua": str(f.get("fch_venc_mas_antigua") or "")[:10], + "fch_venc_mas_antigua": str(f.get("fch_venc_mas_antigua") or ""), "imp_total_pagado": round(_pag, 2), "inv_neta": round(_inv, 2), + "monto_venc_ant": round(_mva, 2) if _mva > 0 else 0, + "monto_venc_cur": round(_mvc, 2) if _mvc > 0 else 0, } return out except Exception as e: