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 %} {% csrf_token %}
<h2>Abrir Comanda</h2> <h2>Abrir Comanda</h2>
<input type="text" id="name-comanda" name="name-comanda" required placeholder="Nome"><br> <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 %} {% for mesa in mesas %}
<option value="{{mesa.id}}">{{mesa.name}}</option> <option value="{{mesa.id}}">{{mesa.name}}</option>

View File

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

View File

@@ -9,6 +9,7 @@ urlpatterns = [
path('viewcomanda/', views.viewComanda, name='viewcomanda'), path('viewcomanda/', views.viewComanda, name='viewcomanda'),
path('createComanda/', views.createComanda, name='createComanda'), path('createComanda/', views.createComanda, name='createComanda'),
path('editComanda/', views.editComanda, name='editComanda'), 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.shortcuts import render, redirect
from django.db.models import Count, F from django.db.models import Count, F
from comandas.models import Comanda, ProductComanda from comandas.models import Comanda, ProductComanda
from clients.models import Client
from products.models import Product from products.models import Product
from mesas.models import Mesa from mesas.models import Mesa
from gestaoRaul.decorators import group_required from gestaoRaul.decorators import group_required
@@ -21,6 +23,7 @@ def viewComanda(request):
comanda = Comanda.objects.get(id=comanda_id) comanda = Comanda.objects.get(id=comanda_id)
consumo = ProductComanda.objects.filter(comanda=comanda_id) consumo = ProductComanda.objects.filter(comanda=comanda_id)
mesas = Mesa.objects.all() mesas = Mesa.objects.all()
clients = Client.objects.filter(active=True)
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate( produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
quantidade=Count('product'), quantidade=Count('product'),
@@ -36,7 +39,7 @@ def viewComanda(request):
for produto in consumo: for produto in consumo:
total += produto.product.price 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') @group_required(groupName='Garçom')
@@ -58,3 +61,18 @@ def editComanda(request):
comanda.save() comanda.save()
return redirect('comandas') 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() 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() { function close_modal_payment_comanda() {
document.getElementById('payment-comanda').style.display = 'none'; document.getElementById('payment-comanda').style.display = 'none';
} }