Commit Graph
249 Commits
Author SHA1 Message Date
Lizandro GuarnizoandClaude Sonnet 4.6 eed3c8abd6 fix(print): ocultar sidebar y eliminar fondos de color al imprimir
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-04 15:49:24 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 400e6ff60b feat(docs): sección de documentación completa en /docs
- Nueva ruta /docs con manual de usuario, arquitectura y referencia técnica
- Sidebar con navegación sticky y resaltado de sección activa
- 23 secciones: objetivo, arquitectura, todos los módulos, JSONs de referencia,
  lógica de formas de pago, exclusiones y soporte
- Link "Documentación" en el sidebar de navegación principal

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-04 15:45:25 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 cfba7a657f fix(contratos): ampliar contenedor a max-w-full para mostrar columna Acciones
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-30 16:45:49 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 91dbcc8135 feat(contratos): gestión de códigos de pago + asignación por contrato
- Nueva tabla SQLite codigos_pago (codigo, nombre) con seed CIAC/CR/MU
- Columna cod_forma_pago en contratos (override por contrato)
- Página contratos: tarjeta para agregar/eliminar códigos, select inline por fila
- generar_factura_venta acepta forma_pago_override; si asignado lo usa, sino auto CIAC/CR
- Rutas: /codigos-pago/create, /codigos-pago/delete, /set-forma-pago

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-30 16:43:13 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 551dec9c11 feat(ventas): codFormaPago dinámico CIAC/CR según total + fechaVence por DIASVENC
- SQL trae fd.DIASVENC en ambas queries de ventas
- total==0 → codFormaPago=CIAC, plazoDias=0, fechaVence=fechaFactura
- total>0  → codFormaPago=CR,   plazoDias=DIASVENC, fechaVence=FECHAFACT+DIASVENC días

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-30 16:10:33 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 6a54b61a2e fix: ventas JSON codFormaPago=MU, codBanco=""
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 20:06:59 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 64682de147 fix: ventas JSON uses FECHAFACT (billing date) instead of FECHA_RECEPCION
- generar_factura_venta: fecha = FECHAFACT with fallback to FECHA_RECEPCION
- _SQL_VENTAS_BY_FACTURA: add JOIN FACTURA_DIAN to fetch FECHAFACT for send-one

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 19:35:18 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 f4f135ba29 fix: add ?codigosucursal to Ventas/Crear URL in ventas.py
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 19:07:27 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b5b6258270 fix: add sucursal 00 to ventas JSON
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 19:03:52 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 2053d8a36f fix: codTercero uses full NIT with dash format (e.g. 900123456-7)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 18:28:39 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 58dc364502 fix: ventas JSON - remove precioExcento, include NIT verification digit in codTercero
- Remove precioExcento field from detallePedido (not required by TNS)
- codTercero now uses full NIT without dash (e.g. 900123456-7 -> 9001234567)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 18:27:58 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 22e42463c7 fix: ventas page uses same SQL as automation (FACTURA_DIAN + FECHAFACT)
- Hardcode _SQL_VENTAS and _SQL_VENTAS_BY_FACTURA matching automation.py
- Remove stored query selector from UI — ventas always queries CMXC by billing date
- send-one now fetches factura directly by PREFIJO+NUM_FACTURA (no date range requery)
- Remove query_id dependency from all endpoints and JS formParams

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 17:28:05 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c0e66989ca fix: ventas page only shows CMXC records, remove duplicate column
- _query_rows now always filters by PREFIJO='CMXC' (unless user specifies another prefix in the factura field)
- Removed redundant first column IDRECEP from ventas table (factura_key and factura were identical)
- Renamed header to just Factura

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 17:23:16 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 8ed8f0999f fix: refactor ventas page to group by factura instead of idrecepcion
- _agrupar now keys by PREFIJO-NUM_FACTURA so all services of a factura are grouped together
- _is_sent checks by factura key instead of idrecepcion
- send-one and send endpoints accept/return factura_key instead of idrecepcion
- ventas.html JS updated: factura_key used throughout (filaHtml, marcarFila, enviarUno, enviarTodosPendientes, verDetalle)
- DOM element IDs sanitized with _safeId() to handle dashes in keys like CMXC-309
- onclick handlers now pass string keys with proper quoting

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 17:08:20 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c1925ef6da fix: cast FECHAFACT to TIMESTAMP for BETWEEN comparison
FACTURA_DIAN.FECHAFACT is DATE type, incompatible with datetime strings.
CAST to TIMESTAMP allows comparison with :fecha_ini/:fecha_fin params.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 16:55:17 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 33bd25c6c8 fix: reenviar-venta now fetches all receptions of the factura
Previously used IDRECEPCION to fetch only one reception's services.
Now resolves PREFIJO+NUM_FACTURA from the reception, then fetches all
receptions sharing that factura so the full detallePedido is sent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 16:46:38 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 090890fa46 fix: filter ventas by FECHAFACT (billing date) instead of FECHA_RECEPCION
Joins FACTURA_DIAN to get the actual invoice date. Receptions spread
across multiple days now appear together when their factura was billed
on the selected date. Excludes annulled invoices (ANULADA != 'F').

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 16:45:18 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 9dd234e124 debug: add /debug-fb/facturas endpoint to search by NUM_FACTURA range
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 16:13:02 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 55bb34a1fa chore: remove debug fields from preview response, simplify ventas filter
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 16:00:47 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 7ac17e29a9 fix: remove duplicate agrupar_por_factura that was overriding the correct one
The second definition (for RIPS 2.0 transacción grouping) was never called
but silently overrode the CMXC ventas grouper, causing grupos_vta to always
be empty (values were dicts, not lists, so isinstance(v, list) was False).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:45:56 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 8747ff950e ui: show ventas generation errors as toast in preview
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:38:47 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c463c6ecc3 debug: catch generar_factura_venta exceptions in preview, expose in response
Instead of crashing with 500, catches the error and exposes it in
ventas_gen_errors field so it can be diagnosed from the browser.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:31:23 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 29ab01e729 debug: add /debug-fb/preview-ventas GET endpoint to trace filter logic
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:29:05 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 0e837e4a2d debug: run actual _SQL_VENTAS query in /debug-fb/cmxc to compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:26:54 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 9e6f1171c6 debug: show SQLite contratos excluir_ventas state in /debug-fb/cmxc
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:25:16 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 27b15b184c debug: add /debug-fb/cmxc endpoint for direct Firebird CMXC query
Shows IDRECEPCION, PREFIJO, NUM_FACTURA, CODCONTRATO, N_EXAMENES
for all CMXC receptions on a given date.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:21:32 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 b8bee68d6a debug: expose ventas filter info in preview response
ventas_raw = filas de Firebird antes de filtrar
ventas_grupos_total = grupos por factura antes del filtro
ventas_filtradas = grupos excluidos con motivo (sin_factura / excluido_ventas)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:10:59 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 c58ecc1757 fix: defensive grouping filter in preview and run ventas endpoints
Replace dict comprehension with explicit loop so that non-list or empty
grupo values are safely skipped, preventing KeyError: 0 on v[0].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 15:05:09 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 3a0964e4ec fix: generar_factura_venta uses PREFIJO from row, not config default
codigoPrefijo in ventas JSON must be the actual Firebird PREFIJO
(e.g. "CMXC"), not the prefijo_tns_default config value which is
intended for RDA/transaccion. Falls back to default_prefijo if row
has no PREFIJO.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 09:59:40 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 ae90eaf71c config: increase scheduler ventana from 10 to 60 minutes
Doctors can order exams up to ~45 min after the patient is registered
at reception. With 10 min window the exam sync missed those cases.
60 min ensures late-ordered exams are always captured and pushed to
WhatsApp Lab via upsert.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 09:44:26 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 408325192a fix: use FECHA_RECEPCION for exam query in scheduler, not HORAINICIORECEPCION
HORAINICIORECEPCION is a TIME field that can be NULL or outside the
2-minute window even when FECHA_RECEPCION matches, causing patients
to sync without their exams. Using the same FECHA_RECEPCION filter
for both queries ensures consistency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-28 09:32:42 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 7f2dffc63e fix: group ventas by NUM_FACTURA, not IDRECEPCION
A single CMXC invoice (e.g. CMXC-307) can have multiple receptions.
Previously each reception was sent as a separate ventas, causing TNS
to accept the first and reject the rest with "ya existe" — leaving
only 1/N of the services registered.

Now agrupar_por_factura groups all receptions sharing the same
NUM_FACTURA into one ventas JSON with all their services in
detallePedido. One factura = one send.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-27 17:36:21 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 531fb29122 fix: group terceros by cedula not fecha-as-factura
For terceros, _guardar_envio stores the automation date in the factura
field (not a patient id), so COALESCE(factura, cedula) still collapsed
all terceros into one row. Now GROUP BY uses cedula for tipo=terceros
and factura for transaccion/ventas. Template hides the date in the
factura column for terceros rows.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-26 21:45:14 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 4b70f6f2fa fix: resumen - group terceros by cedula, prioritize success over warning
GROUP BY COALESCE(factura, cedula) fixes terceros (factura=NULL)
collapsing into one row — each paciente now gets its own row.
CASE WHEN in estado_final explicitly prioritizes success > warning > error
instead of relying on alphabetical MAX which returned warning over success.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-26 21:34:45 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 6e9ee32646 fix: group resumen by factura+tipo only, not cedula
Grouping by cedula caused envíos with null/different cedula to split
into separate groups, making success envíos invisible — factura 4989
showed error persistente despite having a success send.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-26 18:09:42 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 ab2ef167f9 feat: add Resumen Diario TNS page as submodule
Groups envios by factura+tipo per day and shows estado_final
(exitoso if any send succeeded, error persistente if all failed).
Supports inline reenvío and JSON detail modal. Added to sidebar
under Historial TNS and as TNS submodule link.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-26 17:59:42 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 3859095f17 fix: contrato 050 tipo_usuario 11 → 12 (particular)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-25 10:33:33 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 f0c4436622 fix: separar routing CMXC (Ventas) vs LHXC (RDA) por prefijo en SQL
- _SQL_PACIENTES y _SQL_RDA: excluyen PREFIJO = 'CMXC'
- _SQL_VENTAS: solo trae PREFIJO = 'CMXC'
- Contrato 050: excluir_ventas=0 para permitir CMXC+050 en Ventas

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-25 08:48:42 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 ebc24bd480 feat: agregar contrato 050 (PARTICULAR COLEGAS) — va a RDA, no a Ventas
Contrato 050 agrupa ~30 laboratorios y clínicas externas (CMXC/LHXC).
Debe enviarse a RDA pero no a Ventas.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-25 08:37:14 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 02b0defef5 fix: ventas CMXC usan NIT_EMPRESA como codTercero en lugar del código de paciente
Las facturas de venta de contratos externos (ej. CMXC) deben ir a nombre
de la empresa referente (NIT sin dígito de verificación), no del paciente.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 19:08:02 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 cefc8b664b fix: automation.html usa status string (success/warning/error) no booleano ok
- Fila warning: amarillo, sin botón reenviar
- Tab 'Ya existe' en filtros para ver solo warnings
- Filtros basados en status en lugar de ok boolean
- Toast muestra conteo correcto de 3 estados

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 11:02:20 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 6a452cd950 feat: sistema de 3 estados (success/warning/error) para envíos TNS
- _parse_tns_resp retorna 'success'|'warning'|'error' en lugar de bool
- 'ya existe/registrado/autorización' → warning (sin reenvío, no es error real)
- errores reales → error (con reenvío)
- Guarda JSON crudo completo en respuesta_api
- logs.html: badge amarillo para warning, verde para success, rojo para error
- Filtro de historial incluye opción 'warning'
- reenvío en logs.py solo disponible para status='error'
- reenvío en logs.py usa misma lógica _parse_tns_resp y soporta ventas

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 10:45:15 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 a37c1bb7d6 fix: _parse_tns_resp distingue status booleano (TNS) de entero HTTP (ASP.NET)
bool(400) era True en Python, haciendo que errores de validación de ASP.NET
(status:400, errors:{campo:[msg]}) se guardaran como success. Ahora:
- status bool → ok directamente
- status int → ok si < 400
- errors dict → mensaje legible "campo: mensaje"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 10:34:55 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 2525e053bf fix: agregar codigosucursal al endpoint de ventas en automation
TNS requiere ?codigosucursal= en /v2/facturacion/Ventas/Crear igual que en RdaPaciente/Insertar.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-24 10:21:05 -05:00
Lizandro Guarnizo 6950e5aaed tmp: debug script exploración muestras pendientes Firebird 2026-07-23 12:17:10 -05:00
Lizandro Guarnizo fff34d2003 tmp: debug script para verificar TIPOIDENT en Firebird 2026-07-23 12:09:56 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 59ee62591c chore: bajar intervalo scheduler a 20 segundos
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 12:00:09 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 78e9c31d90 fix: usar FECHA_RECEPCION en SQL del scheduler en lugar de filtro Python por HORAINICIORECEPCION
El filtro Python era frágil: si HORAINICIORECEPCION era NULL o tenía formato inesperado, los pacientes no se capturaban. Ahora el filtro de ventana de tiempo va directo en Firebird usando DATEADD sobre FECHA_RECEPCION, que siempre está poblado.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 11:38:11 -05:00
Lizandro GuarnizoandClaude Sonnet 4.6 cffeae7e94 fix: parallelize WA sync and surface scheduler errors in historial
- whatsapp_sync: send patients concurrently (asyncio.gather + semaphore=10) instead of sequentially — eliminates long waits with many patients
- envios_erp: auto-refresh historial every 60s when scheduler tab is active
- main: wrap scheduler job to catch exceptions and log them to sync_wa_log so failures are visible in historial

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 11:34:30 -05:00
Lizandro Guarnizo 5ca97159b4 tmp: debug query paciente 88272630 en Firebird 2026-07-22 23:22:27 -05:00