captura de dados pra dashbooad

This commit is contained in:
2024-12-23 17:00:15 -03:00
parent a21b038868
commit 63c9859557
10 changed files with 104 additions and 35 deletions

View File

@@ -6,12 +6,12 @@ from payments.models import Payments
from typePay.models import TypePay from typePay.models import TypePay
def listProduct(request, comanda_id): def listProductBalcao(request, comanda_id):
product = request.GET.get("search-product") product = request.GET.get("search-product")
products = Product.objects.filter(name__icontains=product) products = Product.objects.filter(name__icontains=product)
return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products,'comanda_id':comanda_id}) return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products,'comanda_id':comanda_id})
def addProduct(request, product_id, comanda_id): def addProductBalcao(request, product_id, comanda_id):
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()
consumo = ProductComanda.objects.filter(comanda=comanda_id) consumo = ProductComanda.objects.filter(comanda=comanda_id)
@@ -21,7 +21,7 @@ def addProduct(request, product_id, comanda_id):
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total}) return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
def removeProductComanda(request, productComanda_id): def removeProductBalcao(request, productComanda_id):
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()
@@ -31,16 +31,26 @@ def removeProductComanda(request, productComanda_id):
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total}) return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
def paymentComanda(request, comanda_id): def paymentBalcao(request, comanda_id):
typePayment = TypePay.objects.get(id=1) typePayment = TypePay.objects.get(id=1)
consumo = ProductComanda.objects.filter(comanda=comanda_id) consumo = ProductComanda.objects.filter(comanda=comanda_id)
vendasBalcao = Comanda.objects.get(name='VENDAS BALCAO')
print('ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg')
print(f'ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg{vendasBalcao.id}')
comanda = Comanda.objects.get(name='VENDA BALCÃO') comanda = Comanda.objects.get(name='VENDA BALCÃO')
total = 0 total = 0
for produto in consumo: for produto in consumo:
total += produto.product.price total += produto.product.price
removeProductComanda(request, produto.id) produto.comanda = 14
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='VENDA BALÃO') produto.save()
# newObject = ProductComanda.objects.get(comanda=produto.id)
# newObject.comanda= 14
# newObject.save()
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='VENDA BALCÃO')
pagamento.save() pagamento.save()
comanda.save() # comanda.save()
return redirect('comandas') return redirect('comandas')

View File

@@ -5,7 +5,7 @@
{% block 'title' %} {% block 'title' %}
Detalhes {{comanda.name}} {{comanda.name}}
{% endblock %} {% endblock %}
@@ -70,7 +70,7 @@ Detalhes {{comanda.name}}
<td>{{item.product.name}}</td> <td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</td> <td>R$ {{item.product.price}}</td>
<td><button <td><button
hx-get="{% url 'removeProductComanda' item.id %} " hx-trigger="click" hx-swap="none" hx-get="{% url 'removeProductBalcao' item.id %} " hx-trigger="click" hx-swap="none"
onclick="reloadPage()">🗑️ Excluir</button></td> onclick="reloadPage()">🗑️ Excluir</button></td>
</tr> </tr>
@@ -96,13 +96,16 @@ Detalhes {{comanda.name}}
<!-- <article> --> <!-- <article> -->
<form id="productForm" > <form id="productForm" >
<h2 style="text-align: center;">Adicionar Produto </h2> <h2 style="text-align: center;">Buscar Produto </h2>
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'listProduct' comanda.id %}" hx-trigger="keyup" hx-target="#product-list"><br> <div class="grid-container">
<input type="text" id="search-product" name="search-product" autofocus placeholder="Buscar Produto" hx-get="{% url 'listProduct' comanda.id %}" hx-trigger="keyup" hx-target="#product-list">
<input type="number" id="qtd-product" name="qtd-product" value="1" required min="1"><br>
</div>
<div id="product-list" class="grid-list-products"> <div id="product-list" class="grid-list-products">
{% for product in products %} {% for product in products %}
<article onclick="reloadPage()" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-swap="none"> <article onclick="reloadPage()" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-swap="none">
{{product.name}} <br> {{ forloop.counter0 }} {{product.name}} <br>
R$ {{product.price}} R$ {{product.price}}
</article > </article >
{% endfor %} {% endfor %}

View File

@@ -14,12 +14,12 @@ urlpatterns = [
htmx_urlpatterns = [ htmx_urlpatterns = [
# path('listProduct/', htmx_views.listProduct, name='listProduct'), # path('listProduct/', htmx_views.listProduct, name='listProduct'),
path('listProduct/<int:comanda_id>/', htmx_views.listProduct, name='listProduct'), path('listProduct/<int:comanda_id>/', htmx_views.listProductBalcao, name='listProductBalcao'),
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'), path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProductBalcao, name='addProductBalcao'),
path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'), path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductBalcao, name='removeProductBalcao'),
# path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'), # path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'),
# path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'), # path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'), path('paymentComanda<int:comanda_id>/', htmx_views.paymentBalcao, name='paymentBalcao'),
] ]
urlpatterns += htmx_urlpatterns urlpatterns += htmx_urlpatterns

View File

@@ -33,11 +33,14 @@ Detalhes {{comanda.name}}
{% endif %} {% endif %}
>Fechar Comanda</button> >Fechar Comanda</button>
<button id="pagarComanda" onclick="modal_payment_comanda()" {% if comanda.status == 'PAYING' %}
{% if comanda.status != 'PAYING' %} <button id="pagarComanda" onclick="modal_payment_comanda()">Receber</button>
style="display: none;" {% else %}
{% endif %} {% endif %}
>Receber</button>
<button class="button" id="imprimirFichas" <button class="button" id="imprimirFichas"
{% if comanda.status != 'OPEN'%} {% if comanda.status != 'OPEN'%}
@@ -74,15 +77,17 @@ Detalhes {{comanda.name}}
<tr> <tr>
<td>{{item.product.name}}</td> <td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</td> <td>R$ {{item.product.price}}</td>
<td><button
{% if comanda.status != 'OPEN'%} {% if comanda.status != 'OPEN'%}
disabled {% else %}
<td>
<button
hx-get="{% url 'removeProductComanda' item.id %} " hx-trigger="click" hx-target="#list-products-comanda" onclick="open_remove_product_comanda()">🗑️ Excluir</button>
</td>
{% endif %} {% endif %}
hx-get="{% url 'removeProductComanda' item.id %} " hx-trigger="click" hx-target="#list-products-comanda" onclick="open_remove_product_comanda()">🗑️ Excluir</button></td>
</tr> </tr>
{% endfor %} {% endfor %}
<tfoot> <tfoot>
<tr> <tr>

Binary file not shown.

View File

@@ -2,8 +2,15 @@
{% for product in products %} {% for product in products %}
<article onclick="reloadPage()" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda_id %} " hx-trigger="click" hx-swap="none"> <article
{{product.name}} <br> id="product-{{ forloop.counter0 }}"
onclick="reloadPage()"
style="background-color: #293552;"
hx-get="{% url 'addProduct' product.id comanda_id %} "
hx-trigger="click"
hx-swap="none">
{{ forloop.counter0 }} {{product.name}} <br>
R$ {{product.price}} R$ {{product.price}}
</article> </article>

View File

@@ -92,17 +92,49 @@ function imprimirConta() {
function reloadPage(){ function reloadPage(){
setTimeout(function() { setTimeout(function() {
location.reload();}, 100); location.reload();}, 10);
} }
function backPage() { function backPage() {
setTimeout(function() { setTimeout(function() {
history.back();}, 100); history.back();}, 100);
setTimeout(function() { setTimeout(function() {
location.reload();}, 100); location.reload();}, 10);
} }
document.onkeydown = teclado
function teclado(event){
if (event.keyCode == 50){
document.getElementById('qtd-product').innerHTML = '2'
}
else if (event.keyCode == 73){
imprimirFichas()
}
else if (event.keyCode == 51){
document.getElementById('qtd-product').innerHTML = '3'
}
else if (event.keyCode == 52){
document.getElementById('qtd-product').innerHTML = '4'
}
else if (event.keyCode == 53){
document.getElementById('qtd-product').innerHTML = '5'
}
else if (event.keyCode == 54){
document.getElementById('qtd-product').innerHTML = '6'
}
else if (event.keyCode == 55){
document.getElementById('qtd-product').innerHTML = '7'
}
else if (event.keyCode == 56){
document.getElementById('qtd-product').innerHTML = '8'
}
else if (event.keyCode == 57){
document.getElementById('qtd-product').innerHTML = '9'
}
}
document.getElementById('openModal').addEventListener('click', openModal); document.getElementById('openModal').addEventListener('click', openModal);

View File

@@ -103,7 +103,19 @@ function backPage() {
} }
document.onkeydown = teclado
function teclado(event){
if (event.keyCode == 65){
openModal()
}
else if (event.keyCode == 73){
imprimirFichas()
}
// else if (event.keyCode == 70){
// imprimirConta()
// }
}
document.getElementById('openModal').addEventListener('click', openModal); document.getElementById('openModal').addEventListener('click', openModal);