feat: excluir contratos del envío TNS

- Columna excluir en tabla contratos (migración automática)
- 25 contratos nuevos sembrados con excluir=1 (laboratorios externos, clínicas, médicos particulares)
- load_excluded_set() en contratos.py para consultar el set en runtime
- preview: marca items excluidos y los reporta en el conteo
- send/send-one/send-direct: bloquea envío si contrato está excluido
- automation preview+run: filtra excluidos antes del loop, reporta count
- UI /contratos: columna Envío TNS con toggle Activo/Excluido, fila en rojo si excluida

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-10 15:44:26 -05:00
co-authored by Claude Sonnet 4.6
parent 3baa6e5f75
commit 200a3f550b
5 changed files with 156 additions and 37 deletions
+31 -8
View File
@@ -2,7 +2,7 @@
{% block title %}Contratos{% endblock %}
{% block header %}Contratos{% endblock %}
{% block content %}
<div class="max-w-4xl space-y-6">
<div class="max-w-5xl space-y-6">
<!-- Agregar contrato -->
<div class="bg-white rounded-xl shadow-sm border border-gray-200">
@@ -10,7 +10,7 @@
<h3 class="font-semibold text-gray-800"><i class="fas fa-plus-circle mr-2 text-blue-500"></i>Agregar Contrato</h3>
</div>
<div class="p-6">
<form method="POST" action="/contratos/create" class="grid grid-cols-4 gap-3 items-end">
<form method="POST" action="/contratos/create" class="grid grid-cols-5 gap-3 items-end">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">N° Contrato</label>
<input type="text" name="numero_contrato" required placeholder="Ej: 001"
@@ -36,7 +36,11 @@
<input type="text" name="descripcion" placeholder="Ej: EPS SANITAS"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
</div>
<div class="col-span-4 flex justify-end">
<div class="flex items-end gap-3">
<label class="flex items-center gap-1.5 text-xs text-gray-600 mb-2 cursor-pointer">
<input type="checkbox" name="excluir" value="1" class="rounded">
Excluir TNS
</label>
<button type="submit"
class="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-lg transition-colors">
<i class="fas fa-plus mr-1"></i> Agregar
@@ -63,13 +67,14 @@
<th class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase">NIT Empresa</th>
<th class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase">Tipo Usuario</th>
<th class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase">Descripción</th>
<th class="px-4 py-3 text-center text-xs font-semibold text-gray-500 uppercase">Envío TNS</th>
<th class="px-4 py-3 text-center text-xs font-semibold text-gray-500 uppercase">Acciones</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
{% for c in contratos %}
<tr class="hover:bg-gray-50" id="row-{{ c.id }}">
<td class="px-4 py-3 font-mono font-semibold text-gray-800">{{ c.numero_contrato }}</td>
<tr class="hover:bg-gray-50 {% if c.excluir %}bg-red-50{% endif %}" id="row-{{ c.id }}">
<td class="px-4 py-3 font-mono font-semibold {% if c.excluir %}text-red-500{% else %}text-gray-800{% endif %}">{{ c.numero_contrato }}</td>
<td class="px-4 py-3 text-gray-600">{{ c.nit_empresa }}</td>
<td class="px-4 py-3">
{% set tu = c.tipo_usuario %}
@@ -87,7 +92,20 @@
</td>
<td class="px-4 py-3 text-gray-500">{{ c.descripcion }}</td>
<td class="px-4 py-3 text-center">
<button onclick="openEdit({{ c.id }}, '{{ c.numero_contrato }}', '{{ c.nit_empresa }}', '{{ c.tipo_usuario }}', '{{ c.descripcion }}')"
<form method="POST" action="/contratos/toggle-excluir/{{ c.id }}" class="inline">
{% if c.excluir %}
<button type="submit" class="inline-flex items-center gap-1 px-2.5 py-1 bg-red-100 text-red-700 hover:bg-red-200 rounded-full text-xs font-medium transition-colors">
<i class="fas fa-ban text-xs"></i> Excluido
</button>
{% else %}
<button type="submit" class="inline-flex items-center gap-1 px-2.5 py-1 bg-green-100 text-green-700 hover:bg-green-200 rounded-full text-xs font-medium transition-colors">
<i class="fas fa-check text-xs"></i> Activo
</button>
{% endif %}
</form>
</td>
<td class="px-4 py-3 text-center">
<button onclick="openEdit({{ c.id }}, '{{ c.numero_contrato }}', '{{ c.nit_empresa }}', '{{ c.tipo_usuario }}', '{{ c.descripcion }}', {{ c.excluir }})"
class="text-blue-600 hover:text-blue-800 mr-3 text-xs">
<i class="fas fa-edit"></i> Editar
</button>
@@ -100,7 +118,7 @@
</td>
</tr>
{% else %}
<tr><td colspan="5" class="px-4 py-8 text-center text-gray-400">No hay contratos registrados</td></tr>
<tr><td colspan="6" class="px-4 py-8 text-center text-gray-400">No hay contratos registrados</td></tr>
{% endfor %}
</tbody>
</table>
@@ -143,6 +161,10 @@
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
</div>
</div>
<div class="flex items-center gap-2">
<input type="checkbox" name="excluir" id="edit-excluir" value="1" class="rounded">
<label for="edit-excluir" class="text-sm text-gray-700">Excluir del envío TNS</label>
</div>
<div class="flex justify-end space-x-3 pt-2">
<button type="button" onclick="closeEdit()"
class="px-4 py-2 text-sm text-gray-600 hover:text-gray-800 border border-gray-300 rounded-lg">
@@ -158,12 +180,13 @@
</div>
<script>
function openEdit(id, nc, nit, tu, desc) {
function openEdit(id, nc, nit, tu, desc, excluir) {
document.getElementById('edit-form').action = '/contratos/update/' + id;
document.getElementById('edit-nc').value = nc;
document.getElementById('edit-nit').value = nit;
document.getElementById('edit-tu').value = tu;
document.getElementById('edit-desc').value = desc;
document.getElementById('edit-excluir').checked = excluir === 1;
document.getElementById('edit-modal').classList.remove('hidden');
}
function closeEdit() {