diff --git a/gestaoRaul/balcao/templates/viewBalcao.html b/gestaoRaul/balcao/templates/viewBalcao.html index 10afa09..7dd83b1 100644 --- a/gestaoRaul/balcao/templates/viewBalcao.html +++ b/gestaoRaul/balcao/templates/viewBalcao.html @@ -43,7 +43,7 @@ {{item.product.name}} - R$ {{item.product.price}} + R$ {{item.product.price}} diff --git a/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc b/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc index c2cd271..c2f15ee 100644 Binary files a/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc and b/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc differ diff --git a/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc b/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc index 5962582..dd2bf1b 100644 Binary files a/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc and b/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc differ diff --git a/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc b/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc index 2064891..d3dacc0 100644 Binary files a/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc and b/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc differ diff --git a/gestaoRaul/comandas/htmx_views.py b/gestaoRaul/comandas/htmx_views.py index 2204efc..849a4f6 100644 --- a/gestaoRaul/comandas/htmx_views.py +++ b/gestaoRaul/comandas/htmx_views.py @@ -1,3 +1,4 @@ +from decimal import Decimal from django.http import JsonResponse from django.shortcuts import render, redirect @@ -9,6 +10,16 @@ from typePay.models import TypePay from gestaoRaul.decorators import group_required +def somar(consumo:ProductComanda, comanda:Comanda): + parcial = Payments.objects.filter(comanda=comanda) + totalParcial = Decimal(0) + total:Decimal = Decimal(0) + for p in parcial: + totalParcial += p.value + for produto in consumo: + total += Decimal(produto.product.price) + return total - totalParcial + def listProduct(request, comanda_id): product = request.GET.get("search-product") allProducts = Product.objects.filter(name__icontains=product) @@ -25,21 +36,16 @@ def addProduct(request, product_id, comanda_id): product_comanda.save() product = Product.objects.get(id=product_id) comanda = Comanda.objects.get(id=comanda_id) - print(product.cuisine) - if product.cuisine == True: order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='') order.save() consumo = ProductComanda.objects.filter(comanda=comanda_id) - total = 0 - for produto in consumo: - total += produto.product.price + total = somar(consumo,comanda) return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total, 'comanda':comanda}) @group_required(groupName='Garçom') def editOrders(request, productComanda_id, obs): order = Order.objects.get(productComanda=productComanda_id) - print(obs) order.obs = obs order.save() return JsonResponse({'status': 'ok'}) @@ -50,11 +56,8 @@ def removeProductComanda(request, productComanda_id): product_comanda = ProductComanda.objects.get(id=productComanda_id) comanda = Comanda.objects.get(id= product_comanda.comanda.id) consumo = ProductComanda.objects.filter(comanda=comanda) - product_comanda.delete() - total = 0 - for produto in consumo: - total += produto.product.price + total = somar(consumo, comanda) return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total, 'comanda':comanda}) @group_required(groupName='Garçom') @@ -78,11 +81,20 @@ def paymentComanda(request, comanda_id): typePayment = TypePay.objects.get(id=1) consumo = ProductComanda.objects.filter(comanda=comanda_id) comanda = Comanda.objects.get(id=comanda_id) - total = 0 - for produto in consumo: - total += produto.product.price + total = somar(consumo, comanda) pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado') pagamento.save() comanda.status = 'CLOSED' comanda.save() return redirect('/comandas') + +@group_required(groupName='Gerente') +def paymentParcial(request, comanda_id): + typePayment = TypePay.objects.get(id=1) + comanda = Comanda.objects.get(id=comanda_id) + value = Decimal(request.POST.get('value-parcial')) + print(value) + description = request.POST.get('name-parcial') + pagamento = Payments(value=value, comanda=comanda, type_pay=typePayment,description=description) + pagamento.save() + return redirect('/comandas') diff --git a/gestaoRaul/comandas/templates/viewcomanda.html b/gestaoRaul/comandas/templates/viewcomanda.html index cf001d4..0d01c21 100644 --- a/gestaoRaul/comandas/templates/viewcomanda.html +++ b/gestaoRaul/comandas/templates/viewcomanda.html @@ -117,14 +117,24 @@ Detalhes {{comanda.name}} {% endif %} {% endfor %} + {% for parcial in parcials %} + + {{parcial.datetime}} + R$ -{{parcial.value}} + {{parcial.description}} + + {% endfor %} + + + + Total R$ {{total}} - - + @@ -186,6 +196,24 @@ Detalhes {{comanda.name}} + + +
diff --git a/gestaoRaul/comandas/urls.py b/gestaoRaul/comandas/urls.py index 4b947d2..0667507 100644 --- a/gestaoRaul/comandas/urls.py +++ b/gestaoRaul/comandas/urls.py @@ -26,6 +26,7 @@ htmx_urlpatterns = [ path('closeComanda/', htmx_views.closeComanda, name='closeComanda'), path('reopenComanda/', htmx_views.reopenComanda, name='reopenComanda'), path('paymentComanda/', htmx_views.paymentComanda, name='paymentComanda'), + path('paymentParcial/', htmx_views.paymentParcial, name='paymentParcial'), ] urlpatterns += htmx_urlpatterns \ No newline at end of file diff --git a/gestaoRaul/comandas/views.py b/gestaoRaul/comandas/views.py index 7f7ec7b..fc3b87d 100644 --- a/gestaoRaul/comandas/views.py +++ b/gestaoRaul/comandas/views.py @@ -7,6 +7,7 @@ from django.db.models import Count, F from comandas.models import Comanda, ProductComanda from clients.models import Client +from payments.models import Payments from orders.models import Order from products.models import Product from mesas.models import Mesa @@ -20,12 +21,23 @@ def comandas(request): return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas}) +def somar(consumo:ProductComanda, comanda:Comanda): + parcial = Payments.objects.filter(comanda=comanda) + totalParcial = Decimal(0) + total:Decimal = Decimal(0) + for p in parcial: + totalParcial += p.value + for produto in consumo: + total += Decimal(produto.product.price) + return total - totalParcial + @group_required(groupName='Garçom') def viewComanda(request): id = request.GET.get('parametro') comanda_id = int(id) comanda = Comanda.objects.get(id=comanda_id) consumo = ProductComanda.objects.filter(comanda=comanda_id) + parcial = Payments.objects.filter(comanda=comanda_id) mesas = Mesa.objects.all() clients = Client.objects.filter(active=True) @@ -39,11 +51,8 @@ def viewComanda(request): for p in products: if p.name == produto['nome'] and p.active == True: products_ordenados.append(p) - total = 0 - for produto in consumo: - total += produto.product.price - - return render(request, 'viewcomanda.html', {'clients':clients,'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados,'mesas':mesas}) + total = somar(consumo,comanda) + return render(request, 'viewcomanda.html', {'parcials':parcial,'clients':clients,'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados,'mesas':mesas}) @group_required(groupName='Garçom') diff --git a/gestaoRaul/db.sqlite3 b/gestaoRaul/db.sqlite3 index 761ae09..b19affd 100644 Binary files a/gestaoRaul/db.sqlite3 and b/gestaoRaul/db.sqlite3 differ diff --git a/gestaoRaul/templates/static/comandas/js/viewcomanda.js b/gestaoRaul/templates/static/comandas/js/viewcomanda.js index a41347c..cc2cae9 100644 --- a/gestaoRaul/templates/static/comandas/js/viewcomanda.js +++ b/gestaoRaul/templates/static/comandas/js/viewcomanda.js @@ -33,6 +33,11 @@ function modal_payment_comanda() { recebido = document.getElementById('recebido') recebido.focus() } +function modal_payment_parcial() { + document.getElementById('payment-parcial').style.display = 'block'; + // recebido = document.getElementById('recebido') + // recebido.focus() +} function modal_conta_client() { diff --git a/gestaoRaul/templates/static/orders/js/orders.js b/gestaoRaul/templates/static/orders/js/orders.js index 0576813..ad65c7c 100644 --- a/gestaoRaul/templates/static/orders/js/orders.js +++ b/gestaoRaul/templates/static/orders/js/orders.js @@ -1,5 +1,9 @@ -document.cookie = `fila=0`; +// document.cookie = `fila=0`; +function reloadPage(){ + setTimeout(function() { + location.reload();}, 4000); +} function openTab(evt, etapa) { var i, tabcontent, tablinks; @@ -80,6 +84,7 @@ function notificacao(){ mostrarNotificacao(data['titulo'], data['corpo'],'Cozinha') texto = new SpeechSynthesisUtterance(data['corpo']+', '+data['titulo']+'.'); window.speechSynthesis.speak(texto); + reloadPage(); }else{ console.log(data['notificacao'])