- Nueva columna excluir_ventas en tabla contratos (migración automática) - load_excluded_ventas_set() para filtrar en /ventas - Toggle independiente en /contratos para RDA y Ventas por separado - Modal edición con checkbox excluir_ventas - 040 marcado excluir_rda=1, excluir_ventas=0 en seed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
240 lines
16 KiB
HTML
240 lines
16 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}Contratos{% endblock %}
|
|
{% block header %}Contratos{% endblock %}
|
|
{% block content %}
|
|
<div class="max-w-5xl space-y-6">
|
|
|
|
<!-- Agregar contrato -->
|
|
<div class="bg-white rounded-xl shadow-sm border border-gray-200">
|
|
<div class="px-6 py-4 border-b border-gray-200">
|
|
<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-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"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
|
|
</div>
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">NIT Empresa</label>
|
|
<input type="text" name="nit_empresa" placeholder="Ej: 860078828"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
|
|
</div>
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Tipo Usuario</label>
|
|
<select name="tipo_usuario" class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
|
|
<option value="11">11 — Contributivo (EPS)</option>
|
|
<option value="12">12 — Particular</option>
|
|
<option value="07">07 — Póliza / Seguro</option>
|
|
<option value="01">01 — Subsidiado</option>
|
|
<option value="10">10 — No Afiliado</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Descripción</label>
|
|
<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="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
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tabla de contratos -->
|
|
<div class="bg-white rounded-xl shadow-sm border border-gray-200">
|
|
<div class="px-6 py-4 border-b border-gray-200 flex items-center justify-between">
|
|
<h3 class="font-semibold text-gray-800">
|
|
<i class="fas fa-list mr-2 text-gray-500"></i>Contratos registrados
|
|
<span class="ml-2 text-xs bg-gray-100 text-gray-600 px-2 py-0.5 rounded-full">{{ contratos|length }}</span>
|
|
</h3>
|
|
<span class="text-xs text-gray-400">El tipo de usuario se aplica automáticamente al generar RIPS por contrato</span>
|
|
</div>
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full text-sm">
|
|
<thead class="bg-gray-50 border-b border-gray-200">
|
|
<tr>
|
|
<th class="px-4 py-3 text-left text-xs font-semibold text-gray-500 uppercase">N° Contrato</th>
|
|
<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">Excluir RDA</th>
|
|
<th class="px-4 py-3 text-center text-xs font-semibold text-gray-500 uppercase">Excluir Ventas</th>
|
|
<th class="px-4 py-3 text-center text-xs font-semibold text-gray-500 uppercase">Sin Contrato</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 {% 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 %}
|
|
{% if tu == '11' %}
|
|
<span class="px-2 py-0.5 bg-blue-100 text-blue-700 rounded-full text-xs font-medium">11 — Contributivo</span>
|
|
{% elif tu == '12' %}
|
|
<span class="px-2 py-0.5 bg-gray-100 text-gray-700 rounded-full text-xs font-medium">12 — Particular</span>
|
|
{% elif tu == '07' %}
|
|
<span class="px-2 py-0.5 bg-purple-100 text-purple-700 rounded-full text-xs font-medium">07 — Póliza</span>
|
|
{% elif tu == '01' %}
|
|
<span class="px-2 py-0.5 bg-green-100 text-green-700 rounded-full text-xs font-medium">01 — Subsidiado</span>
|
|
{% else %}
|
|
<span class="px-2 py-0.5 bg-yellow-100 text-yellow-700 rounded-full text-xs font-medium">{{ tu }}</span>
|
|
{% endif %}
|
|
</td>
|
|
<td class="px-4 py-3 text-gray-500">{{ c.descripcion }}</td>
|
|
<td class="px-4 py-3 text-center">
|
|
<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">
|
|
<form method="POST" action="/contratos/toggle-excluir-ventas/{{ c.id }}" class="inline">
|
|
{% if c.excluir_ventas %}
|
|
<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-emerald-100 text-emerald-700 hover:bg-emerald-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">
|
|
<form method="POST" action="/contratos/toggle-sin-contrato/{{ c.id }}" class="inline">
|
|
{% if c.sin_contrato %}
|
|
<button type="submit" class="inline-flex items-center gap-1 px-2.5 py-1 bg-yellow-100 text-yellow-700 hover:bg-yellow-200 rounded-full text-xs font-medium transition-colors" title="numeroContrato: null en JSON">
|
|
<i class="fas fa-unlink text-xs"></i> Sin contrato
|
|
</button>
|
|
{% else %}
|
|
<button type="submit" class="inline-flex items-center gap-1 px-2.5 py-1 bg-gray-100 text-gray-400 hover:bg-gray-200 rounded-full text-xs font-medium transition-colors">
|
|
<i class="fas fa-link text-xs"></i> Normal
|
|
</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 }}, {{ c.sin_contrato }}, {{ c.excluir_ventas }})"
|
|
class="text-blue-600 hover:text-blue-800 mr-3 text-xs">
|
|
<i class="fas fa-edit"></i> Editar
|
|
</button>
|
|
<form method="POST" action="/contratos/delete/{{ c.id }}" class="inline"
|
|
onsubmit="return confirm('¿Eliminar contrato {{ c.numero_contrato }}?')">
|
|
<button type="submit" class="text-red-500 hover:text-red-700 text-xs">
|
|
<i class="fas fa-trash"></i> Eliminar
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
{% else %}
|
|
<tr><td colspan="6" class="px-4 py-8 text-center text-gray-400">No hay contratos registrados</td></tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal editar -->
|
|
<div id="edit-modal" class="hidden fixed inset-0 bg-black/40 z-50 flex items-center justify-center">
|
|
<div class="bg-white rounded-xl shadow-xl w-full max-w-lg p-6">
|
|
<h3 class="font-semibold text-gray-800 mb-4"><i class="fas fa-edit mr-2 text-blue-500"></i>Editar Contrato</h3>
|
|
<form method="POST" id="edit-form" class="space-y-4">
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">N° Contrato</label>
|
|
<input type="text" name="numero_contrato" id="edit-nc" required
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
|
|
</div>
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">NIT Empresa</label>
|
|
<input type="text" name="nit_empresa" id="edit-nit"
|
|
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="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Tipo Usuario</label>
|
|
<select name="tipo_usuario" id="edit-tu"
|
|
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500">
|
|
<option value="11">11 — Contributivo (EPS)</option>
|
|
<option value="12">12 — Particular</option>
|
|
<option value="07">07 — Póliza / Seguro</option>
|
|
<option value="01">01 — Subsidiado</option>
|
|
<option value="10">10 — No Afiliado</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label class="block text-xs font-medium text-gray-600 mb-1">Descripción</label>
|
|
<input type="text" name="descripcion" id="edit-desc"
|
|
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 flex-wrap items-center gap-4">
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input type="checkbox" name="excluir" id="edit-excluir" value="1" class="rounded">
|
|
<span class="text-sm text-gray-700">Excluir RDA <span class="text-xs text-red-500">(bloquea transacción/automation)</span></span>
|
|
</label>
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input type="checkbox" name="excluir_ventas" id="edit-excluir-ventas" value="1" class="rounded">
|
|
<span class="text-sm text-gray-700">Excluir Ventas <span class="text-xs text-red-500">(bloquea /ventas)</span></span>
|
|
</label>
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input type="checkbox" name="sin_contrato" id="edit-sin-contrato" value="1" class="rounded">
|
|
<span class="text-sm text-gray-700">Sin contrato <span class="text-xs text-yellow-600">(numeroContrato: null)</span></span>
|
|
</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">
|
|
Cancelar
|
|
</button>
|
|
<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-save mr-1"></i> Guardar
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function openEdit(id, nc, nit, tu, desc, excluir, sinContrato, excluirVentas) {
|
|
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-sin-contrato').checked = sinContrato === 1;
|
|
document.getElementById('edit-excluir-ventas').checked = excluirVentas === 1;
|
|
document.getElementById('edit-modal').classList.remove('hidden');
|
|
}
|
|
function closeEdit() {
|
|
document.getElementById('edit-modal').classList.add('hidden');
|
|
}
|
|
document.getElementById('edit-modal').addEventListener('click', function(e) {
|
|
if (e.target === this) closeEdit();
|
|
});
|
|
</script>
|
|
{% endblock %}
|