mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 05:25:40 +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):
|
||||
print('entrouuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu', product_id, comanda_id)
|
||||
qtd = int(request.COOKIES.get('qtd'))
|
||||
for i in range(qtd):
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
@@ -36,7 +36,6 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
||||
|
||||
|
||||
def removeProductBalcao(request, productComanda_id):
|
||||
print(request.COOKIES['qtd'])
|
||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
|
||||
product_comanda.delete()
|
||||
@@ -58,6 +57,5 @@ def paymentBalcao(request, comanda_id):
|
||||
produto.save()
|
||||
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='VENDA BALCÃO')
|
||||
pagamento.save()
|
||||
# comanda.save()
|
||||
return redirect('viewBalcao')
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
<h2 style="text-align: center;">Buscar Produto </h2>
|
||||
<div class="grid-container">
|
||||
<input
|
||||
onchange="salvarValor()"
|
||||
onwaiting="salvarValor()"
|
||||
type="text"
|
||||
id="search-product"
|
||||
name="search-product"
|
||||
|
||||
@@ -3,12 +3,7 @@ from django.shortcuts import render, redirect
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
from products.models import Product
|
||||
from mesas.models import Mesa
|
||||
|
||||
|
||||
# def balcao(request):
|
||||
# comandas = Comanda.objects.filter(status__in=["OPEN", "PAYING"])
|
||||
# mesas = Mesa.objects.all()
|
||||
# return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
|
||||
from django.db.models import Count, F
|
||||
|
||||
|
||||
|
||||
@@ -16,21 +11,21 @@ def viewBalcao(request):
|
||||
|
||||
comanda = Comanda.objects.get(name='VENDA BALCÃO')
|
||||
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_ordenados = []
|
||||
|
||||
for produto in produtos_mais_vendidos:
|
||||
for p in products:
|
||||
if p.name == produto['nome']:
|
||||
products_ordenados.append(p)
|
||||
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
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() {
|
||||
// document.getElementById('Modal-add-product').style.display = 'none';
|
||||
// }
|
||||
|
||||
document.cookie = 'qtd=1';
|
||||
|
||||
|
||||
function imprimirFichas() {
|
||||
@@ -108,12 +108,6 @@ function teclado(event){
|
||||
addProductBalcao()
|
||||
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);
|
||||
@@ -150,14 +143,12 @@ document.getElementById('productForm').addEventListener('submit', function(event
|
||||
|
||||
|
||||
|
||||
|
||||
function salvarValor() {
|
||||
const elemento = document.getElementById('qtd-product');
|
||||
const qtd = document.getElementById('qtd-product');
|
||||
qtd.addEventListener('input', () => {
|
||||
const chave = 'qtd';
|
||||
const valor = elemento.value;
|
||||
localStorage.setItem(chave, valor);
|
||||
setCookie(chave, valor);
|
||||
const valor = qtd.value;
|
||||
document.cookie = chave + '=' + valor;
|
||||
console.log(chave, valor);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user