Adicionados os campos mínimos do Banco de Dados, precisa melhorar interface e controle de acesso que será posterior nessa branch mesmo
This commit is contained in:
124
templates/editar_venda.html
Normal file
124
templates/editar_venda.html
Normal file
@@ -0,0 +1,124 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}Editar Venda{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h1 class="mb-4">Editar Venda</h1>
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<form method="POST" class="needs-validation" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="militante_id" class="form-label">Militante</label>
|
||||
<select class="form-select" id="militante_id" name="militante_id" required>
|
||||
<option value="">Selecione um militante</option>
|
||||
{% for militante in militantes %}
|
||||
<option value="{{ militante.id }}" {% if militante.id == venda.militante_id %}selected{% endif %}>{{ militante.nome }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="invalid-feedback">
|
||||
Por favor, selecione o militante.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="material_id" class="form-label">Material</label>
|
||||
<select class="form-select" id="material_id" name="material_id" required>
|
||||
<option value="">Selecione um material</option>
|
||||
{% for material in materiais %}
|
||||
<option value="{{ material.id }}" data-preco="{{ material.preco }}" {% if material.id == venda.material_id %}selected{% endif %}>{{ material.nome }} - R$ {{ "%.2f"|format(material.preco) }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="invalid-feedback">
|
||||
Por favor, selecione o material.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="quantidade" class="form-label">Quantidade</label>
|
||||
<input type="number" class="form-control" id="quantidade" name="quantidade" min="1" value="{{ venda.quantidade }}" required>
|
||||
<div class="invalid-feedback">
|
||||
Por favor, insira a quantidade.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="valor_total" class="form-label">Valor Total</label>
|
||||
<input type="number" class="form-control" id="valor_total" name="valor_total" step="0.01" value="{{ venda.valor_total }}" readonly required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="data_venda" class="form-label">Data da Venda</label>
|
||||
<input type="date" class="form-control" id="data_venda" name="data_venda" value="{{ venda.data_venda.strftime('%Y-%m-%d') }}" required>
|
||||
<div class="invalid-feedback">
|
||||
Por favor, insira a data da venda.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between">
|
||||
<button type="submit" class="btn btn-success">Salvar</button>
|
||||
<a href="{{ url_for('listar_vendas') }}" class="btn btn-outline-secondary">Voltar</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Validação do formulário
|
||||
(function () {
|
||||
'use strict'
|
||||
|
||||
var forms = document.querySelectorAll('.needs-validation')
|
||||
|
||||
Array.prototype.slice.call(forms)
|
||||
.forEach(function (form) {
|
||||
form.addEventListener('submit', function (event) {
|
||||
if (!form.checkValidity()) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
}
|
||||
|
||||
form.classList.add('was-validated')
|
||||
}, false)
|
||||
})
|
||||
})()
|
||||
|
||||
// Cálculo do valor total
|
||||
document.getElementById('material_id').addEventListener('change', function() {
|
||||
calcularValorTotal();
|
||||
});
|
||||
|
||||
document.getElementById('quantidade').addEventListener('input', function() {
|
||||
calcularValorTotal();
|
||||
});
|
||||
|
||||
function calcularValorTotal() {
|
||||
const materialSelect = document.getElementById('material_id');
|
||||
const quantidadeInput = document.getElementById('quantidade');
|
||||
const valorTotalInput = document.getElementById('valor_total');
|
||||
|
||||
if (materialSelect.value && quantidadeInput.value) {
|
||||
const preco = parseFloat(materialSelect.options[materialSelect.selectedIndex].dataset.preco);
|
||||
const quantidade = parseFloat(quantidadeInput.value);
|
||||
const valorTotal = preco * quantidade;
|
||||
|
||||
valorTotalInput.value = valorTotal.toFixed(2);
|
||||
} else {
|
||||
valorTotalInput.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Calcular valor total inicial
|
||||
calcularValorTotal();
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user