mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: grafico mais vendido dinamico com filtro de periodo
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -29,34 +29,32 @@ RRB&C - DashBoard
|
||||
<body>
|
||||
|
||||
<h1>DashBoard</h1>
|
||||
<!-- <form class="grid-container" > -->
|
||||
<input id="data-start" name="data-start" type="date">
|
||||
<input id="data-end" name="data-end" type="date">
|
||||
<!-- <input type="submit"> -->
|
||||
<button onclick="mediaCuisine()" >Filtrar</button>
|
||||
<!-- </form> -->
|
||||
<div class="grid-container">
|
||||
<input id="data-start" name="data-start" oninput="mediaCuisine()" type="date">
|
||||
<input id="data-end" name="data-end" oninput="mediaCuisine()" type="date">
|
||||
<!-- <button onclick="mediaCuisine()" >Filtrar</button> -->
|
||||
</div>
|
||||
|
||||
<div class="grid-container">
|
||||
|
||||
<div class="card">
|
||||
<h4> Valor de Pagamentos </h4>
|
||||
<h5>R$ {{total_pagamentos |floatformat:2 }} </h5>
|
||||
<h5 id="total-pagamentos">R$ {{total_pagamentos |floatformat:2 }} </h5>
|
||||
<hr>
|
||||
<h4> Quantidade de Pagamentos </h4>
|
||||
<h5> {{ qdt_pagamentos }} </h5>
|
||||
<h5 id="qtd-pagamentos"> {{ qdt_pagamentos }} </h5>
|
||||
<hr>
|
||||
<h4> Ticket médio </h4>
|
||||
<h5>R$ {{ ticekMedio |floatformat:2}} </h5>
|
||||
<h5 id="ticket-medio">R$ {{ ticekMedio |floatformat:2}} </h5>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h4> Gráficos de vendas </h4>
|
||||
<div></div>
|
||||
<canvas id="vendas" style="width:100%;height: 85%;max-width:100%; background-color: rgb(191, 225, 255);border-radius: 5px;">
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<h4> Gráficos cozinha </h4>
|
||||
<div></div>
|
||||
@@ -64,22 +62,7 @@ RRB&C - DashBoard
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h4> Mais Vendidos </h4>
|
||||
<table style="background-color: rgba(0, 255, 255, 0);">
|
||||
<tr style="background-color: rgba(0, 255, 255, 0);">
|
||||
<th style="text-align: left;background-color: rgba(0, 255, 255, 0.089);">Produto</th>
|
||||
<th style="text-align: left;background-color: rgba(0, 255, 255, 0.075);">Quantidade</th>
|
||||
</tr>
|
||||
{% for produto in produtos_mais_vendidos %}
|
||||
<tr>
|
||||
<td id="n-{{forloop.counter0}}" style="background-color: rgba(0, 255, 255, 0);"> {{ produto.nome }} </td>
|
||||
<td id="q-{{forloop.counter0}}" style="background-color: rgba(0, 255, 255, 0);"> {{ produto.quantidade }} </td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.contrib.auth.models import User
|
||||
from django.utils.dateparse import parse_datetime
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
|
||||
|
||||
@@ -17,17 +18,7 @@ from gestaoRaul.decorators import group_required
|
||||
|
||||
@group_required(groupName='Gerente')
|
||||
def home(request):
|
||||
try:
|
||||
total_pagamentos = Payments.objects.aggregate(total=Sum('value'))['total']
|
||||
qdt_pagamentos = Payments.objects.aggregate(total=Count('value'))['total']
|
||||
pagamentos = Payments.objects.all()
|
||||
ticekMedio = total_pagamentos / qdt_pagamentos
|
||||
|
||||
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, })
|
||||
except:
|
||||
return render(request, 'home.html')
|
||||
|
||||
|
||||
@@ -39,13 +30,41 @@ def chartCuisine(request,dateStart,dateEnd):
|
||||
except:
|
||||
dateStart = parse_datetime('2025-01-01 07:00:00')
|
||||
dateEnd = datetime.datetime.now()
|
||||
# print(request.user.groups.all())
|
||||
# print(request.user.is_authenticated)
|
||||
# fulano = User()
|
||||
|
||||
tFila = []
|
||||
tPreparando = []
|
||||
tFinalizado = []
|
||||
|
||||
total_pagamentos = Payments.objects.filter(datetime__range=(dateStart, dateEnd)).aggregate(total=Sum('value'))['total']
|
||||
total_pagamentos = 0 if total_pagamentos is None else total_pagamentos
|
||||
qdt_pagamentos = Payments.objects.filter(datetime__range=(dateStart, dateEnd)).aggregate(total=Count('value'))['total']
|
||||
qdt_pagamentos = 0 if qdt_pagamentos is None else qdt_pagamentos
|
||||
try:
|
||||
ticket_medio = total_pagamentos / qdt_pagamentos
|
||||
except:
|
||||
ticket_medio = 0
|
||||
|
||||
try:
|
||||
produtos_mais_vendidos = ProductComanda.objects.filter(
|
||||
data_time__range=(dateStart, dateEnd)
|
||||
).values('product').annotate(
|
||||
quantidade=Count('product'),
|
||||
nome=F('product__name')
|
||||
).order_by('-quantidade')[:5]
|
||||
maisVendidos = {}
|
||||
for produto in produtos_mais_vendidos:
|
||||
maisVendidos[produto['nome']] = produto['quantidade']
|
||||
produtos_mais_vendidos = maisVendidos
|
||||
|
||||
except:
|
||||
produtos_mais_vendidos = {
|
||||
'petra': 25,
|
||||
'petra2': 26,
|
||||
'petra3': 27,
|
||||
'petra4': 28,
|
||||
'petra5': 29,
|
||||
}
|
||||
|
||||
orders = Order.objects.filter(delivered__isnull=False, queue__gt=dateStart, queue__lt=dateEnd)
|
||||
try:
|
||||
for order in orders:
|
||||
@@ -61,10 +80,18 @@ def chartCuisine(request,dateStart,dateEnd):
|
||||
'mediaFila': mediaFila,
|
||||
'mediaPreparando': mediaPreparando,
|
||||
'mediaFinalizado': mediaFinalizado,
|
||||
'total_pagamentos': round(total_pagamentos, 2),
|
||||
'qtd_pagamentos': qdt_pagamentos,
|
||||
'ticket_medio': round(ticket_medio, 2),
|
||||
'produtos_mais_vendidos': produtos_mais_vendidos,
|
||||
})
|
||||
except:
|
||||
return JsonResponse({
|
||||
'mediaFila': 0,
|
||||
'mediaPreparando': 0,
|
||||
'mediaFinalizado': 0,
|
||||
'total_pagamentos': round(total_pagamentos, 2),
|
||||
'qtd_pagamentos': qdt_pagamentos,
|
||||
'ticket_medio': round(ticket_medio, 2),
|
||||
'produtos_mais_vendidos': produtos_mais_vendidos,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user