feat: add valor comanda a conta do cliente

This commit is contained in:
2025-01-16 16:31:13 -03:00
parent cf73dba143
commit b403e5fc72
8 changed files with 55 additions and 25 deletions

View File

@@ -52,7 +52,8 @@ Comandas
{% csrf_token %}
<h2>Abrir Comanda</h2>
<input type="text" id="name-comanda" name="name-comanda" required placeholder="Nome"><br>
<select name="select-mesa" >
<select name="select-mesa" required>
<option value="">Selecione um local</option>
{% for mesa in mesas %}
<option value="{{mesa.id}}">{{mesa.name}}</option>

View File

@@ -39,10 +39,8 @@ Detalhes {{comanda.name}}
{% else %}
{% endif %}
{% if comanda.status != 'OPEN'%}
<button class="button" id="imprimirFichas"
style="display: none;"
@@ -60,7 +58,6 @@ Detalhes {{comanda.name}}
{% endif %}
</div>
<div>
<input hidden type="text" id="h-mesaId" value="{{comanda.mesa.id}}">
@@ -102,8 +99,6 @@ Detalhes {{comanda.name}}
{% if comanda.status != 'OPEN'%}
{% else %}
<td>
<img
src="{% static 'midia/icons/delete.svg' %}"
style="width: 35px; height: 35px; cursor: pointer;"
@@ -114,9 +109,6 @@ Detalhes {{comanda.name}}
</img>
</td>
{% endif %}
</tr>
{% endfor %}
<tfoot>
@@ -164,15 +156,13 @@ Detalhes {{comanda.name}}
<p>Recebido:</p> <input id="recebido" type="number">
<h4 id="troco">Troco: </h4>
</div>
<footer>
<button class="secondary" hx-get="{% url 'paymentComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="backPage()" style="background-color:green;">
Receber
</button>
<button class="secondary" onclick="backPage()">
<button class="secondary" onclick=" modal_conta_client()">
Conta Cliente
</button>
<button onclick="close_modal_payment_comanda()" style="background-color:red;">Cancelar</button>
</footer>
</article>
@@ -185,10 +175,9 @@ Detalhes {{comanda.name}}
{% 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" required >
<select name="select-mesa" id="select-mesa" >
{% for mesa in mesas %}
<option value="{{mesa.id}}">{{mesa.name}}</option>
@@ -205,20 +194,29 @@ Detalhes {{comanda.name}}
<dialog id="conta-cliente" style="display: none;" >
<article>
<h2>Pagamento</h2>
<form id="form-comanda" method="post" action="{% url 'addContaCliente' %}">
{% csrf_token %}
<h2>Adicionar na Conta</h2>
<h1>R$ {{ total }}</h1>
<div>
<p>Recebido:</p> <input id="recebido" type="number">
<h4 id="troco">Adicionar a conta: </h4>
<input hidden type="text" name="valor-conta" value="{{ total }}">
<input hidden type="text" name="idComanda" value="{{ comanda.id }}">
<p>Selecione o Cliente:</p>
<select name="select-client" id="select-client" required>
<option value="">Selecione um cliente</option>
{% for client in clients %}
<option value="{{client.id}}">{{client.name}}</option>
{% endfor %}
</select>
</div>
<footer>
<button class="secondary" style="background-color:green;">
Receber
<button type="submit" class="secondary" style="background-color:green;" >
Adicionar a conta
</button>
<button onclick="close_modal_payment_comanda()" style="background-color:red;">Cancelar</button>
<button onclick="close_modal_conta_client()" style="background-color:red;">Cancelar</button>
</form>
</footer>
</article>
</dialog>

View File

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

View File

@@ -1,7 +1,9 @@
from decimal import Decimal
from django.shortcuts import render, redirect
from django.db.models import Count, F
from comandas.models import Comanda, ProductComanda
from clients.models import Client
from products.models import Product
from mesas.models import Mesa
from gestaoRaul.decorators import group_required
@@ -21,6 +23,7 @@ def viewComanda(request):
comanda = Comanda.objects.get(id=comanda_id)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
mesas = Mesa.objects.all()
clients = Client.objects.filter(active=True)
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
quantidade=Count('product'),
@@ -36,7 +39,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,'mesas':mesas})
return render(request, 'viewcomanda.html', {'clients':clients,'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados,'mesas':mesas})
@group_required(groupName='Garçom')
@@ -58,3 +61,18 @@ def editComanda(request):
comanda.save()
return redirect('comandas')
@group_required(groupName='Gerente')
def addContaCliente(request):
comandaId = int(request.POST.get('idComanda'))
clientId = int(request.POST.get('select-client'))
valor = float(request.POST.get('valor-conta').replace(',','.'))
comanda = Comanda.objects.get(id=comandaId)
client = Client.objects.get(id=clientId)
client.debt = client.debt + Decimal(valor)
comanda.client = client
comanda.status = 'CLOSED'
client.save()
comanda.save()
return redirect('comandas')

Binary file not shown.

View File

@@ -34,6 +34,18 @@ function modal_payment_comanda() {
recebido.focus()
}
function modal_conta_client() {
document.getElementById('conta-cliente').style.display = 'block';
// recebido = document.getElementById('recebido')
// recebido.focus()
}
function close_modal_conta_client() {
document.getElementById('conta-cliente').style.display = 'none';
}
function close_modal_payment_comanda() {
document.getElementById('payment-comanda').style.display = 'none';
}