diff --git a/src/api/cobranza_api.py b/src/api/cobranza_api.py index 847d9a0..f3f3b29 100644 --- a/src/api/cobranza_api.py +++ b/src/api/cobranza_api.py @@ -187,10 +187,11 @@ class LoteFila(BaseModel): id: str tipo: str # "saldo" | "sinmora" | "personal" monto: float | None = None + concepto: str | None = None # concepto individual del renglón (opcional) class CobrarLoteBody(BaseModel): - concepto: str + concepto: str = "" # fallback global; cada fila puede traer el suyo filas: list[LoteFila] @@ -562,9 +563,12 @@ async def cobrar_lote(body: CobrarLoteBody, token: str = Query(...)): if not tel_efectivo: omitidos_sin_tel.append(r.get("cliente", fila.id)) continue + # Concepto individual del renglón; cae al global solo si la fila no + # trae uno propio. + concepto_fila = (fila.concepto or "").strip() or body.concepto or "" try: cobro = await _generar_cobro_para_renglon( - numero, r, fila.tipo, fila.monto, body.concepto, + numero, r, fila.tipo, fila.monto, concepto_fila, ) except HTTPException as e: logger.warning("Lote: error en %s: %s", fila.id, e.detail) @@ -577,7 +581,7 @@ async def cobrar_lote(body: CobrarLoteBody, token: str = Query(...)): texto = _mensaje_cobro( cliente=r.get("cliente", ""), vehiculo=r.get("vehiculo", ""), - concepto=body.concepto, + concepto=concepto_fila, monto=cobro["monto"], link=cobro["link"], ) diff --git a/web/cobranza.html b/web/cobranza.html index fd090ed..62745ae 100644 --- a/web/cobranza.html +++ b/web/cobranza.html @@ -1429,8 +1429,9 @@ async function cancelarAbono(idRenglon, idAbono){ function abrirLote(){ if(!renglones.length){ toast("No hay renglones activos"); return; } loteState = { - concepto: "Pago WK Financing", - filas: renglones.map(r => ({ id:r.id, incluido: !!r.telefono, tipo:"saldo", montoPersonal:"" })), + // Autoseleccionar los que YA tienen teléfono efectivo (override O directorio), + // no solo el override local. + filas: renglones.map(r => ({ id:r.id, incluido: !!(r.telefono_efectivo || r.telefono), tipo:"saldo", montoPersonal:"" })), }; renderLote(); document.getElementById("modal").classList.add("open"); @@ -1450,7 +1451,7 @@ function renderLote(){ const r = _findR(f.id); if(!r) return ""; const conI = Number(r.saldo)||0; const sinI = (Number(r.capital)||0) - (Number(r.abonado)||0); - const sinNum = !r.telefono; + const sinNum = !(r.telefono_efectivo || r.telefono); return `
@@ -1468,14 +1469,14 @@ function renderLote(){ : ''}
`; }).join(""); + const selables = loteState.filas.filter(f => { const r = _findR(f.id); return r && (r.telefono_efectivo || r.telefono); }); + const todosSel = selables.length > 0 && selables.every(f => f.incluido); inner.innerHTML = ` -
- - -
Se usa para todos los cobros del lote
+
+ +
- ${rows}
0 seleccionados$0
`; @@ -1483,6 +1484,15 @@ function renderLote(){ } function setLoteTipo(i,t){ loteState.filas[i].tipo = t; renderLote(); } function toggleLote(i){ loteState.filas[i].incluido = !loteState.filas[i].incluido; renderLote(); } +// Selecciona/deselecciona todos los que tienen número (los sin número no se +// pueden enviar, así que quedan fuera de la selección masiva). +function toggleLoteTodos(){ + const tiene = (f) => { const r = _findR(f.id); return !!(r && (r.telefono_efectivo || r.telefono)); }; + const selables = loteState.filas.filter(tiene); + const todosSel = selables.length > 0 && selables.every(f => f.incluido); + loteState.filas.forEach(f => { f.incluido = todosSel ? false : tiene(f); }); + renderLote(); +} function setLotePersonal(i,v){ loteState.filas[i].montoPersonal = v; actualizarLoteSummary(); } function actualizarLoteSummary(){ let total = 0, n = 0; @@ -1501,9 +1511,11 @@ async function enviarLote(){ const filas = incluidas.map(f => ({ id: f.id, tipo: f.tipo, monto: f.tipo === "personal" ? parseFloat(f.montoPersonal) : null, + // Concepto individual de cada renglón (mismo que usa el cobro unitario). + concepto: autoConcepto(_findR(f.id)), })); try { - const res = await api("/cobrar-lote", {method:"POST", body: JSON.stringify({concepto: loteState.concepto, filas})}); + const res = await api("/cobrar-lote", {method:"POST", body: JSON.stringify({filas})}); let msg = `Enviados ${res.enviados}`; if(res.omitidos_sin_telefono && res.omitidos_sin_telefono.length){ msg += ` · ${res.omitidos_sin_telefono.length} sin número omitidos`; @@ -1707,8 +1719,14 @@ const _MESES_CORTO = ["ENE","FEB","MAR","ABR","MAY","JUN","JUL","AGO","SEP","OCT function autoConcepto(r){ const tipo = (r && r.tipo) ? r.tipo.toUpperCase() : "COBRO"; - const tipoMap = {RENTA: "RENTA", VR: "VR", EXTRA: "EXTRA"}; - const tipoStr = tipoMap[tipo] || tipo; + let tipoStr; + if(tipo === "OTRO" && r && r.etiqueta){ + // Cobro personalizado: usa la etiqueta del concepto (ej. TENENCIA). + tipoStr = r.etiqueta.toUpperCase().replace(/\s+/g, "-"); + } else { + const tipoMap = {RENTA: "RENTA", VR: "VR", EXTRA: "EXTRA"}; + tipoStr = tipoMap[tipo] || tipo; + } const cliente = (r && r.cliente ? r.cliente : "CLIENTE").split(/\s+/)[0].toUpperCase(); const d = new Date(); return `WK-${tipoStr}-${cliente}-${_MESES_CORTO[d.getMonth()]}${String(d.getFullYear()).slice(-2)}`;