diff --git a/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc b/gestaoRaul/comandas/__pycache__/htmx_views.cpython-310.pyc index 4eac452..a98cb76 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/home/__pycache__/urls.cpython-310.pyc b/gestaoRaul/home/__pycache__/urls.cpython-310.pyc index c5cb455..198a23b 100644 Binary files a/gestaoRaul/home/__pycache__/urls.cpython-310.pyc and b/gestaoRaul/home/__pycache__/urls.cpython-310.pyc differ diff --git a/gestaoRaul/home/__pycache__/views.cpython-310.pyc b/gestaoRaul/home/__pycache__/views.cpython-310.pyc index 459257b..41433ac 100644 Binary files a/gestaoRaul/home/__pycache__/views.cpython-310.pyc and b/gestaoRaul/home/__pycache__/views.cpython-310.pyc differ diff --git a/gestaoRaul/home/templates/home.html b/gestaoRaul/home/templates/home.html index a9c7719..ac6f9cb 100644 --- a/gestaoRaul/home/templates/home.html +++ b/gestaoRaul/home/templates/home.html @@ -26,6 +26,7 @@ RRB&C - DashBoard {% block 'body' %} +

DashBoard

@@ -45,11 +46,15 @@ RRB&C - DashBoard

Gráficos de vendas

- - +
+
+

Gráficos cozinha

+
+ +
diff --git a/gestaoRaul/home/urls.py b/gestaoRaul/home/urls.py index 3bcaa2f..3351dac 100644 --- a/gestaoRaul/home/urls.py +++ b/gestaoRaul/home/urls.py @@ -3,5 +3,6 @@ from . import views urlpatterns = [ path('', views.home, name='home'), + path('chartCuisine', views.chartCuisine, name='chartCuisine'), ] diff --git a/gestaoRaul/home/views.py b/gestaoRaul/home/views.py index 2c55673..48756a2 100644 --- a/gestaoRaul/home/views.py +++ b/gestaoRaul/home/views.py @@ -1,9 +1,11 @@ from django.shortcuts import render from django.db.models import Sum from django.db.models import Count, F +from django.http import JsonResponse + from comandas.models import ProductComanda -from products.models import Product +from orders.models import Order from payments.models import Payments def home(request): @@ -15,5 +17,34 @@ def home(request): produtos_mais_vendidos = ProductComanda.objects.values('product').annotate( quantidade=Count('product'), nome=F('product__name') ).order_by('-quantidade')[:5] - return render(request, 'home.html', {'total_pagamentos': total_pagamentos, 'pagamentos': pagamentos, 'qdt_pagamentos': qdt_pagamentos, 'produtos_mais_vendidos': produtos_mais_vendidos, 'ticekMedio': ticekMedio}) + + +def chartCuisine(request): + print('entrooooooouuuuu') + tFila = [] + tPreparando = [] + tFinalizado = [] + + orders = Order.objects.filter(delivered__isnull=False) + + for order in orders: + tFila.append((order.preparing - order.queue).total_seconds()) + tPreparando.append((order.finished - order.preparing).total_seconds()) + tFinalizado.append((order.delivered - order.finished).total_seconds()) + + mediaFila = int((sum(tFila) / len(tFila))/60) + mediaPreparando = int((sum(tPreparando) / len(tPreparando))/60) + mediaFinalizado = int((sum(tFinalizado) / len(tFinalizado))/60) + + # orders = Order.objects.filter( + # created_at__gte='a', + # created_at__lte='b', + # delivered__isnull=False + # ) + + return JsonResponse({ + 'mediaFila': mediaFila, + 'mediaPreparando': mediaPreparando, + 'mediaFinalizado': mediaFinalizado, + }) \ No newline at end of file diff --git a/gestaoRaul/templates/static/home/js/home.js b/gestaoRaul/templates/static/home/js/home.js index 24e7080..85c4fdd 100644 --- a/gestaoRaul/templates/static/home/js/home.js +++ b/gestaoRaul/templates/static/home/js/home.js @@ -1,7 +1,6 @@ -console.log(document.getElementById('n-0')) - +function productsPlus(){ var xValues = [document.getElementById('n-0').innerText, document.getElementById('n-1').innerText, @@ -34,4 +33,49 @@ new Chart("vendas", { }, } - }); \ No newline at end of file + }); +} + + +function mediaCuisine(){ + +var yValues = []; +var xValues = ['Fila', 'Preparando', 'Entregar']; +var barColors = ["red", "green","blue","orange","brown"]; + +var resposta = fetch('/chartCuisine', {method: 'GET', + headers: {'Content-Type': 'application/json', + },}) + .then(response => response.json()) + .then(data => { + yValues.push(data['mediaFila']) + yValues.push(data['mediaPreparando']) + yValues.push(data['mediaFinalizado']) + + new Chart("cuisine", { + type: "doughnut", + data: { + labels: xValues, + datasets: [{ + backgroundColor: barColors, + data: yValues + }] + }, + options: { + legend: {display: true}, + title: { + display: true, + text: "Tempo médio (em minutos) do pedido em cada etapa." + }, + } + }); + }) + .catch(error => { + alert('Erro ao trazer dados da cozinha:', error) + console.error('Erro ao trazer dados da cozinha:', error); + }); +} + + +productsPlus() +mediaCuisine() \ No newline at end of file