feat: moderniza a página de listagem de cotas
This commit is contained in:
27
app.py
27
app.py
@@ -439,9 +439,30 @@ def nova_cota():
|
|||||||
@require_login
|
@require_login
|
||||||
@require_permission(Permission.VIEW_CELL_REPORTS)
|
@require_permission(Permission.VIEW_CELL_REPORTS)
|
||||||
def listar_cotas():
|
def listar_cotas():
|
||||||
"""Lista todas as cotas"""
|
"""Rota para listar cotas mensais"""
|
||||||
cotas = db_session.query(CotaMensal).all()
|
try:
|
||||||
return render_template("listar_cotas.html", cotas=cotas)
|
# Buscar cotas com informações do militante
|
||||||
|
cotas = db_session.query(CotaMensal)\
|
||||||
|
.join(Militante)\
|
||||||
|
.order_by(CotaMensal.data_vencimento.desc())\
|
||||||
|
.all()
|
||||||
|
|
||||||
|
# Calcular status das cotas
|
||||||
|
hoje = datetime.now().date()
|
||||||
|
for cota in cotas:
|
||||||
|
if cota.pago:
|
||||||
|
cota.status = 'paga'
|
||||||
|
elif cota.data_vencimento < hoje:
|
||||||
|
cota.status = 'atrasada'
|
||||||
|
else:
|
||||||
|
cota.status = 'pendente'
|
||||||
|
|
||||||
|
return render_template("listar_cotas.html", cotas=cotas)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f"Erro ao listar cotas: {str(e)}")
|
||||||
|
flash("Erro ao carregar lista de cotas. Por favor, tente novamente.", "danger")
|
||||||
|
return redirect(url_for("home"))
|
||||||
|
|
||||||
# Rota para criar um novo pagamento
|
# Rota para criar um novo pagamento
|
||||||
@app.route("/pagamentos/novo", methods=["GET", "POST"])
|
@app.route("/pagamentos/novo", methods=["GET", "POST"])
|
||||||
|
|||||||
@@ -1,31 +1,318 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}Listar Militantes{% endblock %}
|
{% block title %}Cotas{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Cotas Mensais</h1>
|
<div class="row mb-4">
|
||||||
<a href="{{ url_for('nova_cota') }}">Adicionar Nova Cota</a>
|
<div class="col-12">
|
||||||
<table border="1">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<thead>
|
<h1 class="mb-0">
|
||||||
<tr>
|
<i class="fas fa-dollar-sign me-2"></i>Cotas
|
||||||
<th>ID</th>
|
</h1>
|
||||||
<th>Militante ID</th>
|
<a href="{{ url_for('nova_cota') }}" class="btn btn-primary">
|
||||||
<th>Valor Antigo</th>
|
<i class="fas fa-plus me-2"></i>Nova Cota
|
||||||
<th>Valor Novo</th>
|
</a>
|
||||||
<th>Data de Alteração</th>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
</thead>
|
</div>
|
||||||
<tbody>
|
|
||||||
{% for cota in cotas %}
|
<div class="card shadow-sm">
|
||||||
<tr>
|
<div class="card-body">
|
||||||
<td>{{ cota.id }}</td>
|
<div class="row mb-4">
|
||||||
<td>{{ cota.militante_id }}</td>
|
<div class="col-md-6">
|
||||||
<td>R$ {{ cota.valor_antigo }}</td>
|
<div class="input-group">
|
||||||
<td>R$ {{ cota.valor_novo }}</td>
|
<span class="input-group-text">
|
||||||
<td>{{ cota.data_alteracao }}</td>
|
<i class="fas fa-search"></i>
|
||||||
</tr>
|
</span>
|
||||||
{% endfor %}
|
<input type="text" class="form-control" id="searchInput" placeholder="Pesquisar cotas...">
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
</div>
|
||||||
<a href="{{ url_for('home') }}">Home</a>
|
<div class="col-md-6">
|
||||||
|
<div class="d-flex justify-content-end gap-2">
|
||||||
|
<div class="btn-group">
|
||||||
|
<button type="button" class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown">
|
||||||
|
<i class="fas fa-filter me-1"></i>Filtrar
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li><a class="dropdown-item" href="#" data-filter="todos">Todas</a></li>
|
||||||
|
<li><a class="dropdown-item" href="#" data-filter="pagas">Pagas</a></li>
|
||||||
|
<li><a class="dropdown-item" href="#" data-filter="pendentes">Pendentes</a></li>
|
||||||
|
<li><a class="dropdown-item" href="#" data-filter="atrasadas">Atrasadas</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn btn-outline-secondary" id="btnExportar">
|
||||||
|
<i class="fas fa-download me-1"></i>Exportar
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover" id="cotasTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-sort="militante">Militante <i class="fas fa-sort"></i></th>
|
||||||
|
<th data-sort="valor">Valor <i class="fas fa-sort"></i></th>
|
||||||
|
<th data-sort="data_vencimento">Vencimento <i class="fas fa-sort"></i></th>
|
||||||
|
<th data-sort="status">Status <i class="fas fa-sort"></i></th>
|
||||||
|
<th class="text-end">Ações</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for cota in cotas %}
|
||||||
|
<tr data-cota="{{ cota.id }}" data-status="{{ cota.status }}">
|
||||||
|
<td data-militante="{{ cota.militante.nome }}">{{ cota.militante.nome }}</td>
|
||||||
|
<td data-valor="{{ cota.valor_novo }}">R$ {{ "%.2f"|format(cota.valor_novo) }}</td>
|
||||||
|
<td data-data_vencimento="{{ cota.data_vencimento }}">{{ cota.data_vencimento.strftime('%d/%m/%Y') }}</td>
|
||||||
|
<td data-status="{{ cota.status }}">
|
||||||
|
<span class="badge {{ 'bg-success' if cota.status == 'paga' else 'bg-warning' if cota.status == 'pendente' else 'bg-danger' }}">
|
||||||
|
{{ cota.status.title() }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td class="text-end">
|
||||||
|
<div class="btn-group">
|
||||||
|
<a href="{{ url_for('editar_cota', id=cota.id) }}"
|
||||||
|
class="btn btn-sm btn-outline-primary"
|
||||||
|
title="Editar">
|
||||||
|
<i class="fas fa-edit"></i>
|
||||||
|
</a>
|
||||||
|
<button type="button"
|
||||||
|
class="btn btn-sm btn-outline-danger"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#deleteModal"
|
||||||
|
data-cota-id="{{ cota.id }}"
|
||||||
|
data-cota-info="{{ cota.militante.nome }} - R$ {{ "%.2f"|format(cota.valor_novo) }}"
|
||||||
|
title="Excluir">
|
||||||
|
<i class="fas fa-trash"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between align-items-center mt-4">
|
||||||
|
<div class="text-muted">
|
||||||
|
Mostrando <span id="countCotas">{{ cotas|length }}</span> cotas
|
||||||
|
</div>
|
||||||
|
<nav aria-label="Navegação de páginas">
|
||||||
|
<ul class="pagination mb-0">
|
||||||
|
<li class="page-item disabled" id="prevPage">
|
||||||
|
<a class="page-link" href="#"><i class="fas fa-chevron-left"></i></a>
|
||||||
|
</li>
|
||||||
|
<li class="page-item active"><a class="page-link" href="#">1</a></li>
|
||||||
|
<li class="page-item"><a class="page-link" href="#">2</a></li>
|
||||||
|
<li class="page-item"><a class="page-link" href="#">3</a></li>
|
||||||
|
<li class="page-item" id="nextPage">
|
||||||
|
<a class="page-link" href="#"><i class="fas fa-chevron-right"></i></a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal de Confirmação de Exclusão -->
|
||||||
|
<div class="modal fade" id="deleteModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Confirmar Exclusão</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>Tem certeza que deseja excluir a cota de <strong id="cotaInfo"></strong>?</p>
|
||||||
|
<p class="text-danger mb-0">Esta ação não pode ser desfeita.</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||||
|
<form action="" method="POST" id="deleteForm" class="d-inline">
|
||||||
|
<button type="submit" class="btn btn-danger">
|
||||||
|
<i class="fas fa-trash me-2"></i>Excluir
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Configuração do modal de exclusão
|
||||||
|
const deleteModal = document.getElementById('deleteModal');
|
||||||
|
deleteModal.addEventListener('show.bs.modal', function(event) {
|
||||||
|
const button = event.relatedTarget;
|
||||||
|
const cotaId = button.getAttribute('data-cota-id');
|
||||||
|
const cotaInfo = button.getAttribute('data-cota-info');
|
||||||
|
|
||||||
|
document.getElementById('cotaInfo').textContent = cotaInfo;
|
||||||
|
document.getElementById('deleteForm').action = `/cotas/excluir/${cotaId}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pesquisa em tempo real
|
||||||
|
const searchInput = document.getElementById('searchInput');
|
||||||
|
searchInput.addEventListener('input', function() {
|
||||||
|
const searchTerm = this.value.toLowerCase();
|
||||||
|
const rows = document.querySelectorAll('#cotasTable tbody tr');
|
||||||
|
let visibleCount = 0;
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
const text = row.textContent.toLowerCase();
|
||||||
|
const isVisible = text.includes(searchTerm);
|
||||||
|
row.style.display = isVisible ? '' : 'none';
|
||||||
|
if (isVisible) visibleCount++;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('countCotas').textContent = visibleCount;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filtros
|
||||||
|
const filterButtons = document.querySelectorAll('[data-filter]');
|
||||||
|
filterButtons.forEach(button => {
|
||||||
|
button.addEventListener('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const filter = this.getAttribute('data-filter');
|
||||||
|
const rows = document.querySelectorAll('#cotasTable tbody tr');
|
||||||
|
let visibleCount = 0;
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
const status = row.getAttribute('data-status');
|
||||||
|
let isVisible = true;
|
||||||
|
|
||||||
|
if (filter === 'pagas') {
|
||||||
|
isVisible = status === 'paga';
|
||||||
|
} else if (filter === 'pendentes') {
|
||||||
|
isVisible = status === 'pendente';
|
||||||
|
} else if (filter === 'atrasadas') {
|
||||||
|
isVisible = status === 'atrasada';
|
||||||
|
}
|
||||||
|
|
||||||
|
row.style.display = isVisible ? '' : 'none';
|
||||||
|
if (isVisible) visibleCount++;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('countCotas').textContent = visibleCount;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ordenação
|
||||||
|
const headers = document.querySelectorAll('#cotasTable th[data-sort]');
|
||||||
|
headers.forEach(header => {
|
||||||
|
header.addEventListener('click', function() {
|
||||||
|
const column = this.getAttribute('data-sort');
|
||||||
|
const tbody = document.querySelector('#cotasTable tbody');
|
||||||
|
const rows = Array.from(tbody.querySelectorAll('tr'));
|
||||||
|
const isAsc = !this.classList.contains('sort-asc');
|
||||||
|
|
||||||
|
// Remover classes de ordenação de todos os headers
|
||||||
|
headers.forEach(h => {
|
||||||
|
h.classList.remove('sort-asc', 'sort-desc');
|
||||||
|
h.querySelector('i').className = 'fas fa-sort';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Adicionar classe de ordenação ao header clicado
|
||||||
|
this.classList.add(isAsc ? 'sort-asc' : 'sort-desc');
|
||||||
|
this.querySelector('i').className = `fas fa-sort-${isAsc ? 'up' : 'down'}`;
|
||||||
|
|
||||||
|
// Ordenar linhas
|
||||||
|
rows.sort((a, b) => {
|
||||||
|
const aVal = a.querySelector(`td[data-${column}]`).getAttribute(`data-${column}`);
|
||||||
|
const bVal = b.querySelector(`td[data-${column}]`).getAttribute(`data-${column}`);
|
||||||
|
return isAsc ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reposicionar linhas
|
||||||
|
rows.forEach(row => tbody.appendChild(row));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Exportar para CSV
|
||||||
|
document.getElementById('btnExportar').addEventListener('click', function() {
|
||||||
|
const rows = document.querySelectorAll('#cotasTable tbody tr:not([style*="display: none"])');
|
||||||
|
const headers = ['Militante', 'Valor', 'Vencimento', 'Status'];
|
||||||
|
let csv = headers.join(',') + '\n';
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
const cols = row.querySelectorAll('td');
|
||||||
|
const values = [
|
||||||
|
cols[0].textContent,
|
||||||
|
cols[1].textContent,
|
||||||
|
cols[2].textContent,
|
||||||
|
cols[3].textContent.trim()
|
||||||
|
].map(val => `"${val}"`);
|
||||||
|
csv += values.join(',') + '\n';
|
||||||
|
});
|
||||||
|
|
||||||
|
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = URL.createObjectURL(blob);
|
||||||
|
link.setAttribute('download', 'cotas.csv');
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_css %}
|
||||||
|
<style>
|
||||||
|
/* Estilo para colunas ordenáveis */
|
||||||
|
th[data-sort] {
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
th[data-sort] i {
|
||||||
|
margin-left: 5px;
|
||||||
|
color: #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
th[data-sort].sort-asc i,
|
||||||
|
th[data-sort].sort-desc i {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animação para linhas da tabela */
|
||||||
|
#cotasTable tbody tr {
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cotasTable tbody tr:hover {
|
||||||
|
background-color: rgba(0,0,0,0.02);
|
||||||
|
transform: translateX(5px);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Estilo para badges */
|
||||||
|
.badge {
|
||||||
|
font-weight: 500;
|
||||||
|
padding: 0.5em 0.8em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Estilo para botões de ação */
|
||||||
|
.btn-group .btn {
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-group .btn i {
|
||||||
|
width: 16px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsividade */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.btn-group {
|
||||||
|
display: flex;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-group .btn {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user