verificaciones lol

This commit is contained in:
2026-03-24 23:01:55 -03:00
parent e611d566cc
commit cd576fbf1e
3 changed files with 56 additions and 7 deletions

View File

@@ -332,7 +332,7 @@ def register_admin_routes(app):
r_completa = r + (items, total_calculado, comision_total) r_completa = r + (items, total_calculado, comision_total)
rendiciones_completas.append(r_completa) 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() workers = c.fetchall()
c.execute("SELECT id, name FROM modulos ORDER BY name") 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') worker_id = request.form.get('worker_id')
modulo_id = request.form.get('modulo_id') # Asegúrate de tener el input hidden en el HTML 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 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 worker_comision = 1 if request.form.get('worker_comision') else 0
companion_comision = 1 if request.form.get('companion_comision') else 0 companion_comision = 1 if request.form.get('companion_comision') else 0

View File

@@ -1,5 +1,5 @@
{% extends "macros/base.html" %} {% 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 %} {% block title %}Historial de Rendiciones{% endblock %}
@@ -70,6 +70,7 @@
</table> </table>
</div> </div>
</div> </div>
{{ alert_modal(id='errorPersonaModal', title='Error de Validación', message='') }}
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
@@ -141,6 +142,23 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const editModals = document.querySelectorAll('[id^="editRendicion"]'); 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 = "<strong>Error:</strong> 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 => { editModals.forEach(modal => {
// Inicializar badges al abrir // Inicializar badges al abrir
@@ -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.");
}
});
});
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -364,7 +364,10 @@
<label class="small text-muted mb-0 mt-2 d-block">Trabajador</label> <label class="small text-muted mb-0 mt-2 d-block">Trabajador</label>
<select class="form-select form-select-sm" name="worker_id" onchange="updateComisionToggle(this, 'wc_{{ rendicion[0] }}')" required> <select class="form-select form-select-sm" name="worker_id" onchange="updateComisionToggle(this, 'wc_{{ rendicion[0] }}')" required>
{% for w in workers %} {% for w in workers %}
<option value="{{ w[0] }}" data-tipo="{{ w[2] }}" {% if w[0] == rendicion[11] %}selected{% endif %}>{{ w[1] }}</option> {# w[3] es el modulo_id que agregamos en el paso anterior #}
{% if w[3] == rendicion[13] %}
<option value="{{ w[0] }}" data-tipo="{{ w[2] }}" {% if w[0] == rendicion[11] %}selected{% endif %}>{{ w[1] }}</option>
{% endif %}
{% endfor %} {% endfor %}
</select> </select>
<div class="d-flex justify-content-between align-items-center mt-1"> <div class="d-flex justify-content-between align-items-center mt-1">
@@ -381,7 +384,9 @@
<select class="form-select form-select-sm" name="companion_id" onchange="toggleCompDiv({{ rendicion[0] }}, this)"> <select class="form-select form-select-sm" name="companion_id" onchange="toggleCompDiv({{ rendicion[0] }}, this)">
<option value="" data-tipo="">Sin acompañante</option> <option value="" data-tipo="">Sin acompañante</option>
{% for w in workers %} {% for w in workers %}
<option value="{{ w[0] }}" data-tipo="{{ w[2] }}" {% if w[0] == rendicion[12] %}selected{% endif %}>{{ w[1] }}</option> {% if w[3] == rendicion[13] %}
<option value="{{ w[0] }}" data-tipo="{{ w[2] }}" {% if w[0] == rendicion[12] %}selected{% endif %}>{{ w[1] }}</option>
{% endif %}
{% endfor %} {% endfor %}
</select> </select>
<div class="d-flex justify-content-between align-items-center mt-1" id="comp_com_div_{{ rendicion[0] }}" {% if not rendicion[12] %}style="display:none;"{% endif %}> <div class="d-flex justify-content-between align-items-center mt-1" id="comp_com_div_{{ rendicion[0] }}" {% if not rendicion[12] %}style="display:none;"{% endif %}>
@@ -482,7 +487,7 @@
<h5 class="card-title mb-0">Comisiones</h5> <h5 class="card-title mb-0">Comisiones</h5>
</div> </div>
<p class="text-muted small flex-grow-1">Cálculo de comisiones generadas por los trabajadores en este módulo.</p> <p class="text-muted small flex-grow-1">Cálculo de comisiones generadas por los trabajadores en este módulo.</p>
<a href="{{ url_for('report_modulo_comisiones', modulo_id=modulo_id) }}" class="btn btn-outline-success w-100 mt-3">Generar Reporte</a> <a href="{{ url_for('report_modulo_comisiones', modulo_id=modulo_id) }}" class="btn btn-success w-100 mt-3">Generar Reporte</a>
</div> </div>
</div> </div>
</div> </div>