From cd576fbf1ea8891676815674fb66d151a4777620 Mon Sep 17 00:00:00 2001 From: Shiro-Nek0 Date: Tue, 24 Mar 2026 23:01:55 -0300 Subject: [PATCH] verificaciones lol --- routes_admin.py | 6 +++-- templates/admin_rendiciones.html | 46 ++++++++++++++++++++++++++++++-- templates/macros/modals.html | 11 +++++--- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/routes_admin.py b/routes_admin.py index 0434099..80c1918 100644 --- a/routes_admin.py +++ b/routes_admin.py @@ -332,7 +332,7 @@ def register_admin_routes(app): r_completa = r + (items, total_calculado, comision_total) rendiciones_completas.append(r_completa) - c.execute("SELECT id, name, tipo FROM workers WHERE is_admin = 0 ORDER BY name") + c.execute("SELECT id, name, tipo, modulo_id FROM workers WHERE is_admin = 0 ORDER BY name") workers = c.fetchall() c.execute("SELECT id, name FROM modulos ORDER BY name") @@ -372,7 +372,9 @@ def register_admin_routes(app): worker_id = request.form.get('worker_id') modulo_id = request.form.get('modulo_id') # Asegúrate de tener el input hidden en el HTML companion_id = request.form.get('companion_id') or None - + if companion_id and worker_id == companion_id: + flash("Error: No puedes asignarte a ti mismo como acompañante.", "danger") + return redirect(url_for('admin_rendiciones')) worker_comision = 1 if request.form.get('worker_comision') else 0 companion_comision = 1 if request.form.get('companion_comision') else 0 diff --git a/templates/admin_rendiciones.html b/templates/admin_rendiciones.html index b7b39d1..0232c32 100644 --- a/templates/admin_rendiciones.html +++ b/templates/admin_rendiciones.html @@ -1,5 +1,5 @@ {% extends "macros/base.html" %} -{% from 'macros/modals.html' import rendicion_detail_modal, confirm_modal, edit_rendicion_modal %} +{% from 'macros/modals.html' import alert_modal, rendicion_detail_modal, confirm_modal, edit_rendicion_modal %} {% block title %}Historial de Rendiciones{% endblock %} @@ -70,6 +70,7 @@ +{{ alert_modal(id='errorPersonaModal', title='Error de Validación', message='') }} {% endblock %} {% block scripts %} @@ -141,7 +142,24 @@ document.addEventListener('DOMContentLoaded', function() { const editModals = document.querySelectorAll('[id^="editRendicion"]'); - + const editForms = document.querySelectorAll('form[action*="/admin/rendiciones/edit/"]'); + const errorModalEl = document.getElementById('errorPersonaModal'); + const errorModal = new bootstrap.Modal(errorModalEl); + const errorBody = document.getElementById('errorPersonaModalBody'); + + editForms.forEach(form => { + form.addEventListener('submit', function(e) { + const workerId = this.querySelector('select[name="worker_id"]').value; + const companionId = this.querySelector('select[name="companion_id"]').value; + + if (companionId && workerId === companionId) { + e.preventDefault(); + errorBody.innerHTML = "Error: El trabajador titular y el acompañante no pueden ser la misma persona. Por favor, selecciona a alguien más."; + errorModal.show(); + } + }); + }); + editModals.forEach(modal => { // Inicializar badges al abrir modal.addEventListener('show.bs.modal', function() { @@ -163,5 +181,29 @@ }); }); }); + + function validarNombresDiferentes(rendicionId) { + const workerSelect = document.querySelector(`select[name="worker_id"]`); + const companionSelect = document.querySelector(`select[name="companion_id"]`); + + if (companionSelect.value && workerSelect.value === companionSelect.value) { + alert("Error: El trabajador titular y el acompañante no pueden ser la misma persona."); + return false; + } + return true; + } + + // Vincula esta validación al evento submit del formulario de edición + document.querySelectorAll('form[action*="edit_rendicion"]').forEach(form => { + form.addEventListener('submit', function(e) { + const workerSelect = this.querySelector('select[name="worker_id"]'); + const companionSelect = this.querySelector('select[name="companion_id"]'); + + if (companionSelect.value && workerSelect.value === companionSelect.value) { + e.preventDefault(); + alert("Un trabajador no puede ser su propio acompañante. Por favor, corrige la selección."); + } + }); + }); {% endblock %} \ No newline at end of file diff --git a/templates/macros/modals.html b/templates/macros/modals.html index 79ce5f2..0f31344 100644 --- a/templates/macros/modals.html +++ b/templates/macros/modals.html @@ -364,7 +364,10 @@
@@ -381,7 +384,9 @@
@@ -482,7 +487,7 @@
Comisiones

Cálculo de comisiones generadas por los trabajadores en este módulo.

- Generar Reporte + Generar Reporte