mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
pge balcao produtos ordenados por mais vendidos | qtd funcionando
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -24,7 +24,7 @@ def addProductBalcao(request, product_id, comanda_id, qtd):
|
|||||||
|
|
||||||
|
|
||||||
def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
||||||
print('entrouuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu', product_id, comanda_id)
|
qtd = int(request.COOKIES.get('qtd'))
|
||||||
for i in range(qtd):
|
for i in range(qtd):
|
||||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||||
product_comanda.save()
|
product_comanda.save()
|
||||||
@@ -36,7 +36,6 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
|||||||
|
|
||||||
|
|
||||||
def removeProductBalcao(request, productComanda_id):
|
def removeProductBalcao(request, productComanda_id):
|
||||||
print(request.COOKIES['qtd'])
|
|
||||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||||
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
|
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
|
||||||
product_comanda.delete()
|
product_comanda.delete()
|
||||||
@@ -58,6 +57,5 @@ def paymentBalcao(request, comanda_id):
|
|||||||
produto.save()
|
produto.save()
|
||||||
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='VENDA BALCÃO')
|
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='VENDA BALCÃO')
|
||||||
pagamento.save()
|
pagamento.save()
|
||||||
# comanda.save()
|
|
||||||
return redirect('viewBalcao')
|
return redirect('viewBalcao')
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
<h2 style="text-align: center;">Buscar Produto </h2>
|
<h2 style="text-align: center;">Buscar Produto </h2>
|
||||||
<div class="grid-container">
|
<div class="grid-container">
|
||||||
<input
|
<input
|
||||||
onchange="salvarValor()"
|
onwaiting="salvarValor()"
|
||||||
type="text"
|
type="text"
|
||||||
id="search-product"
|
id="search-product"
|
||||||
name="search-product"
|
name="search-product"
|
||||||
|
|||||||
@@ -3,12 +3,7 @@ from django.shortcuts import render, redirect
|
|||||||
from comandas.models import Comanda, ProductComanda
|
from comandas.models import Comanda, ProductComanda
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
from mesas.models import Mesa
|
from mesas.models import Mesa
|
||||||
|
from django.db.models import Count, F
|
||||||
|
|
||||||
# def balcao(request):
|
|
||||||
# comandas = Comanda.objects.filter(status__in=["OPEN", "PAYING"])
|
|
||||||
# mesas = Mesa.objects.all()
|
|
||||||
# return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -16,21 +11,21 @@ def viewBalcao(request):
|
|||||||
|
|
||||||
comanda = Comanda.objects.get(name='VENDA BALCÃO')
|
comanda = Comanda.objects.get(name='VENDA BALCÃO')
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda.id)
|
consumo = ProductComanda.objects.filter(comanda=comanda.id)
|
||||||
|
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
|
||||||
|
quantidade=Count('product'),
|
||||||
|
nome=F('product__name') ).order_by('-quantidade'))
|
||||||
products = Product.objects.all()
|
products = Product.objects.all()
|
||||||
|
products_ordenados = []
|
||||||
|
|
||||||
|
for produto in produtos_mais_vendidos:
|
||||||
|
for p in products:
|
||||||
|
if p.name == produto['nome']:
|
||||||
|
products_ordenados.append(p)
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
for produto in consumo:
|
for produto in consumo:
|
||||||
total += produto.product.price
|
total += produto.product.price
|
||||||
|
|
||||||
return render(request, 'viewBalcao.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products})
|
return render(request, 'viewBalcao.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def createComanda(request):
|
|
||||||
# name = request.POST.get('name-comanda')
|
|
||||||
# mesa_id = int(request.POST.get('select-mesa')[0])
|
|
||||||
# mesa = Mesa.objects.get(id=mesa_id)
|
|
||||||
# comanda = Comanda(name=name, mesa=mesa)
|
|
||||||
# comanda.save()
|
|
||||||
|
|
||||||
# return redirect('comandas')
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -18,7 +18,7 @@ function close_modal_payment_comanda() {
|
|||||||
// function closeModal() {
|
// function closeModal() {
|
||||||
// document.getElementById('Modal-add-product').style.display = 'none';
|
// document.getElementById('Modal-add-product').style.display = 'none';
|
||||||
// }
|
// }
|
||||||
|
document.cookie = 'qtd=1';
|
||||||
|
|
||||||
|
|
||||||
function imprimirFichas() {
|
function imprimirFichas() {
|
||||||
@@ -108,12 +108,6 @@ function teclado(event){
|
|||||||
addProductBalcao()
|
addProductBalcao()
|
||||||
reloadPage()
|
reloadPage()
|
||||||
}
|
}
|
||||||
// else if (event.keyCode == 73){
|
|
||||||
// imprimirFichas()
|
|
||||||
// }
|
|
||||||
// else if (event.keyCode == 51){
|
|
||||||
// document.getElementById('qtd-product').innerHTML = '3'
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,8 +129,7 @@ function addProductBalcao() {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
reloadPage()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// document.getElementById('openModal').addEventListener('click', openModal);
|
// document.getElementById('openModal').addEventListener('click', openModal);
|
||||||
@@ -150,14 +143,12 @@ document.getElementById('productForm').addEventListener('submit', function(event
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const qtd = document.getElementById('qtd-product');
|
||||||
function salvarValor() {
|
qtd.addEventListener('input', () => {
|
||||||
const elemento = document.getElementById('qtd-product');
|
|
||||||
const chave = 'qtd';
|
const chave = 'qtd';
|
||||||
const valor = elemento.value;
|
const valor = qtd.value;
|
||||||
localStorage.setItem(chave, valor);
|
document.cookie = chave + '=' + valor;
|
||||||
setCookie(chave, valor);
|
|
||||||
console.log(chave, valor);
|
console.log(chave, valor);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user