feat: edit comanda

This commit is contained in:
2025-01-15 16:49:41 -03:00
parent 0d6a164872
commit c19b6e5fca
8 changed files with 62 additions and 2 deletions

View File

@@ -60,7 +60,7 @@ Comandas
</select>
<button type="submit">Abrir</button>
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
<button type="button" onclick="closeModal()" style="background-color:red;">Cancelar</button>
</form>
</article>
</dialog >

View File

@@ -63,9 +63,16 @@ Detalhes {{comanda.name}}
</div>
<div>
<input hidden type="text" id="h-mesaId" value="{{comanda.mesa.id}}">
<span id="name-comanda">Nome: {{comanda.name}} | </span>
<span id="mesa-comanda">Mesa: {{comanda.mesa}}</span>
<img
onclick="openModalAlter()"
src="{% static 'midia/icons/edit.svg' %}"
style="width: 35px; height: 35px; cursor: pointer;">
</img>
</div>
<p id="open-comanda">Aberta em: {{comanda.dt_open|date:"D"}} {{comanda.dt_open|date:"d/m/Y - H:i"}}</p>
@@ -164,6 +171,31 @@ Detalhes {{comanda.name}}
</article>
</dialog>
<dialog id="Modal-alter-comanda">
<article >
<form id="form-comanda" method="post" action="{% url 'editComanda' %}">
{% csrf_token %}
<h2>Editar Comanda</h2>
<input hidden type="text" name="h-comandaId" id="h-comandaId" value="{{comanda.id}}">
<input type="text" id="nameComanda" name="nameComanda" required placeholder="Nome"><br>
<select name="select-mesa" id="select-mesa" >
{% for mesa in mesas %}
<option value="{{mesa.id}}">{{mesa.name}}</option>
{% endfor %}
</select>
<button type="submit">Alterar</button>
<button type="button" onclick="closeModalAlter()" style="background-color:red;">Cancelar</button>
</form>
</article>
</dialog >
<script src="{% static 'comandas/js/viewcomanda.js' %}"></script>
</body>

View File

@@ -8,6 +8,7 @@ urlpatterns = [
path('', views.comandas, name='comandas'),
path('viewcomanda/', views.viewComanda, name='viewcomanda'),
path('createComanda/', views.createComanda, name='createComanda'),
path('editComanda/', views.editComanda, name='editComanda'),

View File

@@ -20,6 +20,7 @@ def viewComanda(request):
comanda_id = int(id)
comanda = Comanda.objects.get(id=comanda_id)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
mesas = Mesa.objects.all()
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
quantidade=Count('product'),
@@ -35,7 +36,7 @@ def viewComanda(request):
for produto in consumo:
total += produto.product.price
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados})
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados,'mesas':mesas})
@group_required(groupName='Garçom')
@@ -47,3 +48,13 @@ def createComanda(request):
comanda.save()
return redirect('comandas')
@group_required(groupName='Garçom')
def editComanda(request):
name = request.POST.get('nameComanda')
comanda = Comanda.objects.get(id=int(request.POST.get('h-comandaId')))
mesa = Mesa.objects.get(id=int(request.POST.get('select-mesa')))
comanda.mesa = mesa
comanda.name = name
comanda.save()
return redirect('comandas')

Binary file not shown.

View File

@@ -3,6 +3,22 @@
function openModal() {
document.getElementById('Modal-add-product').style.display = 'block';
}
function openModalAlter() {
document.getElementById('Modal-alter-comanda').style.display = 'block';
var name = document.getElementById('name-comanda').innerText.replace('Nome: ','').replace(' | ', '')
var mesa = document.getElementById('h-mesaId').value
console.log(name)
console.log(mesa)
var fildName = document.getElementById('nameComanda')
fildName.value = name
var fildMesa = document.getElementById('select-mesa')
fildMesa.value = mesa
}
function closeModalAlter() {
document.getElementById('Modal-alter-comanda').style.display = 'none';
}
function openModalObs(id) {
document.getElementById('modal-obs').style.display = 'block';
idd = document.getElementById('id-temp').value = id;