Actualizar backend/core/data_manager.py
This commit is contained in:
@@ -699,13 +699,21 @@ class DataManager:
|
||||
print(f"❌ Error facturas cobranza: {e}")
|
||||
return []
|
||||
|
||||
def traer_vendedor_cod_detalle(self, matriculas):
|
||||
def traer_vendedor_cod_detalle(self, matriculas, ano=None, mes=None):
|
||||
"""Dada una lista de num_matricula (POR RETIRAR, pocas), devuelve por cada una:
|
||||
{num_matricula, dsc_vendedor, cod_detalle}. Consulta directa y ligera
|
||||
(filtra solo esas matrículas). NO toca cobranza ni sus cachés."""
|
||||
mats = [str(m).strip() for m in (matriculas or []) if str(m).strip()]
|
||||
if not mats:
|
||||
return {}
|
||||
corte_venc = "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)"
|
||||
except Exception:
|
||||
corte_venc = "CAST(GETDATE() AS DATE)"
|
||||
try:
|
||||
conn = self.get_connection()
|
||||
cursor = conn.cursor()
|
||||
@@ -733,7 +741,7 @@ class DataManager:
|
||||
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,
|
||||
AND c.fch_vencimiento < {corte_venc}) AS num_cuotas_vencidas,
|
||||
(SELECT MIN(c.fch_vencimiento)
|
||||
FROM sgede_cronograma_matricula c
|
||||
WHERE c.cod_localidad = m.cod_localidad
|
||||
@@ -741,7 +749,7 @@ class DataManager:
|
||||
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,
|
||||
AND c.fch_vencimiento < {corte_venc}) AS fch_venc_mas_antigua,
|
||||
(SELECT SUM(c.imp_total_pagado)
|
||||
FROM sgede_cronograma_matricula c
|
||||
WHERE c.cod_localidad = m.cod_localidad
|
||||
@@ -751,7 +759,16 @@ class DataManager:
|
||||
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
|
||||
AND c.num_refinanciamiento = 1), 0) AS inv_neta,
|
||||
m.cod_moneda AS cod_moneda,
|
||||
ISNULL((SELECT TOP 1 comp.imp_tc
|
||||
FROM vtaca_comprobante comp
|
||||
INNER JOIN sgevi_cuotas_x_comprobante cxc
|
||||
ON comp.cod_localidad = cxc.cod_localidad
|
||||
AND comp.num_correlativo = cxc.num_correlativo
|
||||
WHERE cxc.cod_localidad_c = m.cod_localidad
|
||||
AND cxc.num_matricula = m.num_matricula
|
||||
ORDER BY comp.fch_emision DESC), 1) AS imp_tc
|
||||
FROM sgeca_matricula m
|
||||
INNER JOIN sgema_alumno a ON m.cod_alumno = a.cod_alumno
|
||||
WHERE m.num_matricula IN ({placeholders})
|
||||
@@ -762,6 +779,13 @@ class DataManager:
|
||||
conn.close()
|
||||
out = {}
|
||||
for f in filas:
|
||||
_moneda = str(f.get("cod_moneda") or "SOL").strip().upper()
|
||||
try: _tc = float(f.get("imp_tc") or 1.0)
|
||||
except: _tc = 1.0
|
||||
if _moneda != "DOL" or _tc <= 0: _tc = 1.0
|
||||
_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
|
||||
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(),
|
||||
@@ -769,8 +793,8 @@ class DataManager:
|
||||
"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],
|
||||
"imp_total_pagado": float(f.get("imp_total_pagado") or 0),
|
||||
"inv_neta": float(f.get("inv_neta") or 0),
|
||||
"imp_total_pagado": round(_pag, 2),
|
||||
"inv_neta": round(_inv, 2),
|
||||
}
|
||||
return out
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user