mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 05:25:40 +00:00
feat: pagamento parcial comanda part1
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
|
||||
<tr>
|
||||
<td>{{item.product.name}}</td>
|
||||
<td>R$ {{item.product.price}} </td>
|
||||
<td>R$ {{item.product.price}} </td>
|
||||
<td><button class="btn-cancel" onclick="removeProductBalcao({{item.id}})">🗑️ Excluir</button></td>
|
||||
</tr>
|
||||
|
||||
|
||||
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.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')
|
||||
|
||||
@@ -117,14 +117,24 @@ Detalhes {{comanda.name}}
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% 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>
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
||||
|
||||
<button class="btn-secondary" onclick="modal_payment_parcial()">Pagamento Parcial</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -186,6 +196,24 @@ Detalhes {{comanda.name}}
|
||||
</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">
|
||||
<article >
|
||||
<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('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
|
||||
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),
|
||||
path('paymentParcial<int:comanda_id>/', htmx_views.paymentParcial, name='paymentParcial'),
|
||||
]
|
||||
|
||||
urlpatterns += htmx_urlpatterns
|
||||
@@ -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')
|
||||
|
||||
Binary file not shown.
@@ -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() {
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user