mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: pagamento parcial comanda part1
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,4 @@
|
|||||||
|
from decimal import Decimal
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
|
||||||
@@ -9,6 +10,16 @@ from typePay.models import TypePay
|
|||||||
from gestaoRaul.decorators import group_required
|
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):
|
def listProduct(request, comanda_id):
|
||||||
product = request.GET.get("search-product")
|
product = request.GET.get("search-product")
|
||||||
allProducts = Product.objects.filter(name__icontains=product)
|
allProducts = Product.objects.filter(name__icontains=product)
|
||||||
@@ -25,21 +36,16 @@ def addProduct(request, product_id, comanda_id):
|
|||||||
product_comanda.save()
|
product_comanda.save()
|
||||||
product = Product.objects.get(id=product_id)
|
product = Product.objects.get(id=product_id)
|
||||||
comanda = Comanda.objects.get(id=comanda_id)
|
comanda = Comanda.objects.get(id=comanda_id)
|
||||||
print(product.cuisine)
|
|
||||||
|
|
||||||
if product.cuisine == True:
|
if product.cuisine == True:
|
||||||
order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='')
|
order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='')
|
||||||
order.save()
|
order.save()
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||||
total = 0
|
total = somar(consumo,comanda)
|
||||||
for produto in consumo:
|
|
||||||
total += produto.product.price
|
|
||||||
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total, 'comanda':comanda})
|
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total, 'comanda':comanda})
|
||||||
|
|
||||||
@group_required(groupName='Garçom')
|
@group_required(groupName='Garçom')
|
||||||
def editOrders(request, productComanda_id, obs):
|
def editOrders(request, productComanda_id, obs):
|
||||||
order = Order.objects.get(productComanda=productComanda_id)
|
order = Order.objects.get(productComanda=productComanda_id)
|
||||||
print(obs)
|
|
||||||
order.obs = obs
|
order.obs = obs
|
||||||
order.save()
|
order.save()
|
||||||
return JsonResponse({'status': 'ok'})
|
return JsonResponse({'status': 'ok'})
|
||||||
@@ -50,11 +56,8 @@ def removeProductComanda(request, productComanda_id):
|
|||||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||||
comanda = Comanda.objects.get(id= product_comanda.comanda.id)
|
comanda = Comanda.objects.get(id= product_comanda.comanda.id)
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda)
|
consumo = ProductComanda.objects.filter(comanda=comanda)
|
||||||
|
|
||||||
product_comanda.delete()
|
product_comanda.delete()
|
||||||
total = 0
|
total = somar(consumo, comanda)
|
||||||
for produto in consumo:
|
|
||||||
total += produto.product.price
|
|
||||||
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total, 'comanda':comanda})
|
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total, 'comanda':comanda})
|
||||||
|
|
||||||
@group_required(groupName='Garçom')
|
@group_required(groupName='Garçom')
|
||||||
@@ -78,11 +81,20 @@ def paymentComanda(request, comanda_id):
|
|||||||
typePayment = TypePay.objects.get(id=1)
|
typePayment = TypePay.objects.get(id=1)
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||||
comanda = Comanda.objects.get(id=comanda_id)
|
comanda = Comanda.objects.get(id=comanda_id)
|
||||||
total = 0
|
total = somar(consumo, comanda)
|
||||||
for produto in consumo:
|
|
||||||
total += produto.product.price
|
|
||||||
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado')
|
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado')
|
||||||
pagamento.save()
|
pagamento.save()
|
||||||
comanda.status = 'CLOSED'
|
comanda.status = 'CLOSED'
|
||||||
comanda.save()
|
comanda.save()
|
||||||
return redirect('/comandas')
|
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')
|
||||||
|
|||||||
@@ -117,14 +117,24 @@ Detalhes {{comanda.name}}
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% for parcial in parcials %}
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: left; color: chartreuse;">{{parcial.datetime}}</td>
|
||||||
|
<td style="text-align: left; color: chartreuse;">R$ -{{parcial.value}}</td>
|
||||||
|
<td style="text-align: left; color: chartreuse;">{{parcial.description}}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
<button class="btn-secondary" onclick="modal_payment_parcial()">Pagamento Parcial</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -186,6 +196,24 @@ Detalhes {{comanda.name}}
|
|||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
|
|
||||||
|
<dialog id="payment-parcial" style="display: none;" >
|
||||||
|
<article>
|
||||||
|
<h2>Pagamento Parcial</h2>
|
||||||
|
<form method="post" action="{% url 'paymentParcial' comanda.id %} ">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input id="value-parcial" name="value-parcial" type="number" step="0.01" placeholder="Valor">
|
||||||
|
<input id="name-parcial" name="name-parcial" type="text" placeholder="Nome" >
|
||||||
|
<footer>
|
||||||
|
<div style="display: flex;gap: 10px;">
|
||||||
|
<button type="submit" class="btn-secondary" onclick="backPage()">Receber</button>
|
||||||
|
<button type="button" class="btn-cancel" onclick="close_modal_payment_parcial()">Cancelar</button>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
</dialog>
|
||||||
|
|
||||||
|
|
||||||
<dialog id="Modal-alter-comanda">
|
<dialog id="Modal-alter-comanda">
|
||||||
<article >
|
<article >
|
||||||
<form id="form-comanda" method="post" action="{% url 'editComanda' %}">
|
<form id="form-comanda" method="post" action="{% url 'editComanda' %}">
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ htmx_urlpatterns = [
|
|||||||
path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'),
|
path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'),
|
||||||
path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
|
path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
|
||||||
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),
|
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),
|
||||||
|
path('paymentParcial<int:comanda_id>/', htmx_views.paymentParcial, name='paymentParcial'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += htmx_urlpatterns
|
urlpatterns += htmx_urlpatterns
|
||||||
@@ -7,6 +7,7 @@ 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 clients.models import Client
|
||||||
|
from payments.models import Payments
|
||||||
from orders.models import Order
|
from orders.models import Order
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
from mesas.models import Mesa
|
from mesas.models import Mesa
|
||||||
@@ -20,12 +21,23 @@ def comandas(request):
|
|||||||
return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
|
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')
|
@group_required(groupName='Garçom')
|
||||||
def viewComanda(request):
|
def viewComanda(request):
|
||||||
id = request.GET.get('parametro')
|
id = request.GET.get('parametro')
|
||||||
comanda_id = int(id)
|
comanda_id = int(id)
|
||||||
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)
|
||||||
|
parcial = Payments.objects.filter(comanda=comanda_id)
|
||||||
mesas = Mesa.objects.all()
|
mesas = Mesa.objects.all()
|
||||||
clients = Client.objects.filter(active=True)
|
clients = Client.objects.filter(active=True)
|
||||||
|
|
||||||
@@ -39,11 +51,8 @@ def viewComanda(request):
|
|||||||
for p in products:
|
for p in products:
|
||||||
if p.name == produto['nome'] and p.active == True:
|
if p.name == produto['nome'] and p.active == True:
|
||||||
products_ordenados.append(p)
|
products_ordenados.append(p)
|
||||||
total = 0
|
total = somar(consumo,comanda)
|
||||||
for produto in consumo:
|
return render(request, 'viewcomanda.html', {'parcials':parcial,'clients':clients,'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados,'mesas':mesas})
|
||||||
total += produto.product.price
|
|
||||||
|
|
||||||
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')
|
||||||
|
|||||||
Binary file not shown.
@@ -33,6 +33,11 @@ function modal_payment_comanda() {
|
|||||||
recebido = document.getElementById('recebido')
|
recebido = document.getElementById('recebido')
|
||||||
recebido.focus()
|
recebido.focus()
|
||||||
}
|
}
|
||||||
|
function modal_payment_parcial() {
|
||||||
|
document.getElementById('payment-parcial').style.display = 'block';
|
||||||
|
// recebido = document.getElementById('recebido')
|
||||||
|
// recebido.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function modal_conta_client() {
|
function modal_conta_client() {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
document.cookie = `fila=0`;
|
// document.cookie = `fila=0`;
|
||||||
|
|
||||||
|
function reloadPage(){
|
||||||
|
setTimeout(function() {
|
||||||
|
location.reload();}, 4000);
|
||||||
|
}
|
||||||
|
|
||||||
function openTab(evt, etapa) {
|
function openTab(evt, etapa) {
|
||||||
var i, tabcontent, tablinks;
|
var i, tabcontent, tablinks;
|
||||||
@@ -80,6 +84,7 @@ function notificacao(){
|
|||||||
mostrarNotificacao(data['titulo'], data['corpo'],'Cozinha')
|
mostrarNotificacao(data['titulo'], data['corpo'],'Cozinha')
|
||||||
texto = new SpeechSynthesisUtterance(data['corpo']+', '+data['titulo']+'.');
|
texto = new SpeechSynthesisUtterance(data['corpo']+', '+data['titulo']+'.');
|
||||||
window.speechSynthesis.speak(texto);
|
window.speechSynthesis.speak(texto);
|
||||||
|
reloadPage();
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
console.log(data['notificacao'])
|
console.log(data['notificacao'])
|
||||||
|
|||||||
Reference in New Issue
Block a user