diff --git a/gestaoRaul/db.sqlite3 b/gestaoRaul/db.sqlite3 index 84b1bf8..7324541 100644 Binary files a/gestaoRaul/db.sqlite3 and b/gestaoRaul/db.sqlite3 differ diff --git a/gestaoRaul/orders/__pycache__/urls.cpython-313.pyc b/gestaoRaul/orders/__pycache__/urls.cpython-313.pyc index 3b6e4f5..f38ef97 100644 Binary files a/gestaoRaul/orders/__pycache__/urls.cpython-313.pyc and b/gestaoRaul/orders/__pycache__/urls.cpython-313.pyc differ diff --git a/gestaoRaul/orders/__pycache__/views.cpython-313.pyc b/gestaoRaul/orders/__pycache__/views.cpython-313.pyc index 3ea1076..7614150 100644 Binary files a/gestaoRaul/orders/__pycache__/views.cpython-313.pyc and b/gestaoRaul/orders/__pycache__/views.cpython-313.pyc differ diff --git a/gestaoRaul/orders/urls.py b/gestaoRaul/orders/urls.py index 957ecee..ee8d837 100644 --- a/gestaoRaul/orders/urls.py +++ b/gestaoRaul/orders/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path('preparing//', views.preparing, name='preparing'), path('finished//', views.finished, name='finished'), path('delivered//', views.delivered, name='delivered'), + path('notificacao/', views.notificacao, name='notificacao'), ] \ No newline at end of file diff --git a/gestaoRaul/orders/views.py b/gestaoRaul/orders/views.py index 37c9ce1..01a5c9a 100644 --- a/gestaoRaul/orders/views.py +++ b/gestaoRaul/orders/views.py @@ -1,6 +1,8 @@ # from datetime import timezone from django.utils import timezone from django.shortcuts import render +from django.http import JsonResponse, HttpResponse + from orders.models import Order from django.db.models import Q @@ -39,3 +41,79 @@ def delivered(request, order_id): fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15) orders = Order.objects.filter(queue__gte=fifteen_hours_ago ) return render(request, 'htmx_components/orders/htmx_list_orders_fila.html',{'orders': orders}) + + +def notificacao(request): + fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15) + ordersFila = Order.objects.filter(queue__gte=fifteen_hours_ago) + ordersPronto = Order.objects.filter(queue__gte=fifteen_hours_ago, finished__isnull=False) + print(len(ordersFila)) + print(len(ordersPronto)) + + grupoCozinha = request.user.groups.filter(name='Cozinha').exists() + grupoGarcom = request.user.groups.filter(name='Garçom').exists() + grupoGerente = request.user.groups.filter(name='Gerente').exists() + + if grupoCozinha == True: + if 'fila' in request.COOKIES: + cookiesFila = int(request.COOKIES['fila']) + if len(ordersFila) > cookiesFila: + return JsonResponse({ + 'notificacao': 'true', + 'fila': len(ordersFila), + 'pronto':len(ordersPronto), + 'titulo': 'Pedido para: '+ ordersFila[len(ordersFila)-1].id_comanda.name, + 'corpo': ordersFila[len(ordersFila)-1].id_product.name, + }) + else: + return JsonResponse({ + 'notificacao': 'false', + 'fila': len(ordersFila), + 'pronto':len(ordersPronto), + }) + else: + return JsonResponse({ + 'notificacao': 'true', + 'fila': len(ordersFila), + 'pronto':len(ordersPronto), + 'titulo': 'Pedido para: '+ ordersFila[len(ordersFila)-1].id_comanda.name, + 'corpo': ordersFila[len(ordersFila)-1].id_product.name, + }) + + elif grupoGarcom == True and grupoGerente == False: + + if 'pronto' in request.COOKIES: + cookiesPronto = int(request.COOKIES['pronto']) + if len(ordersPronto) > cookiesPronto: + return JsonResponse({ + 'notificacao': 'true', + 'fila': len(ordersPronto), + 'pronto':len(ordersPronto), + 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, + 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, + }) + else: + return JsonResponse({ + 'notificacao': 'false', + 'fila': len(ordersPronto), + }) + else: + return JsonResponse({ + 'notificacao': 'false', + 'fila': len(ordersPronto), + 'pronto':len(ordersPronto), + 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, + 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, + }) + + + else: + return JsonResponse({ + 'notificacao': 'false', + 'fila': len(ordersPronto), + 'pronto':len(ordersPronto), + 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, + 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, + }) + + \ No newline at end of file diff --git a/gestaoRaul/templates/static/comandas/js/comandas.js b/gestaoRaul/templates/static/comandas/js/comandas.js index 7c26dd5..57a19dc 100644 --- a/gestaoRaul/templates/static/comandas/js/comandas.js +++ b/gestaoRaul/templates/static/comandas/js/comandas.js @@ -1,3 +1,8 @@ + +document.cookie = `pronto=0`; + + + function openModal() { document.getElementById('Modal-create-comanda').style.display = 'block'; // HTMLDialogElement.show() @@ -20,4 +25,61 @@ document.getElementById('openModal').addEventListener('click', openModal); // closeModal(); // } // ); - \ No newline at end of file + + + +function mostrarNotificacao(titulo,corpo,grupo) { + if (Notification.permission != 'granted') { + Notification.requestPermission().then(function(permission) { + if (permission == 'granted') { + var notification = new Notification(titulo, { + body: corpo, + icon: 'https://example.com/icon.png' + }); + } + }); + } else { + var notification = new Notification(titulo, { + body: corpo, + icon: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif', + image: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif', + + }); + } +} + +function notificacao(){ + + var resposta = fetch(`/pedidos/notificacao/`, {method: 'GET', + headers: {'Content-Type': 'application/json', + },}) + .then(response => response.json()) + .then(data => { + if (data['notificacao'] == 'true'){ + console.log('verdadeiro') + document.cookie = `pronto=${data['pronto']}`; + // navigator.vibrate(200); + // navigator.vibrate([200, 100, 200]); + mostrarNotificacao(data['titulo'], data['corpo'],'Cozinha') + console.log(data['notificacao']) + + }else{ + document.cookie = `pronto=${data['pronto']}`; + console.log('falso') + console.log(data['notificacao']) + console.log('notificação foi false') + } + // var produtos_mais_vendidos = data.produtos_mais_vendidos + + }) + .catch(error => { + alert('Erro verificar notificação:', error) + console.error('Erro verificar notificação:', error); + }); + + } + + +setInterval(()=> { + notificacao() +}, 10000) diff --git a/gestaoRaul/templates/static/orders/js/orders.js b/gestaoRaul/templates/static/orders/js/orders.js index e7197f9..0d38715 100644 --- a/gestaoRaul/templates/static/orders/js/orders.js +++ b/gestaoRaul/templates/static/orders/js/orders.js @@ -1,4 +1,4 @@ - +document.cookie = `fila=0`; function openTab(evt, etapa) { @@ -48,33 +48,64 @@ function openTab(evt, etapa) { - function mostrarNotificacao() { + function mostrarNotificacao(titulo,corpo,grupo) { if (Notification.permission != 'granted') { Notification.requestPermission().then(function(permission) { if (permission == 'granted') { - var notification = new Notification('Nova Mensagem', { - body: 'Você tem uma nova mensagem!', + var notification = new Notification(titulo, { + body: corpo, icon: 'https://example.com/icon.png' }); } }); } else { - var notification = new Notification('Nova Mensagem', { - body: 'Você tem uma nova mensagem!', - icon: 'https://example.com/icon.png' + var notification = new Notification(titulo, { + body: corpo, + icon: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif', + image: 'https://imagecolorpicker.com/imagecolorpicker-preview_b.avif', + }); } } +function notificacao(){ + + var resposta = fetch(`/pedidos/notificacao/`, {method: 'GET', + headers: {'Content-Type': 'application/json', + },}) + .then(response => response.json()) + .then(data => { + if (data['notificacao'] == 'true'){ + document.cookie = `fila=${data['fila']}`; + // navigator.vibrate(200); + // navigator.vibrate([200, 100, 200]); + mostrarNotificacao(data['titulo'], data['corpo'],'Cozinha') + + }else{ + console.log(data['notificacao']) + console.log('notificação foi false') + } + // var produtos_mais_vendidos = data.produtos_mais_vendidos + + }) + .catch(error => { + alert('Erro verificar notificação:', error) + console.error('Erro verificar notificação:', error); + }); + + } -let i = 0; -while (i < 10) { - setTimeout(function() { - mostrarNotificacao();}, 3000); -} +setInterval(()=> { + notificacao() +}, 10000) -setTimeout(function() { - mostrarNotificacao();}, 3000); + +// setTimeout(function() { +// mostrarNotificacao();}, 2000); + + + // mostrarNotificacao() + // notificacao() \ No newline at end of file