feat: button on/off products

This commit is contained in:
2024-12-29 20:02:51 -03:00
parent ac87c3a47d
commit 9cc0c72f10
17 changed files with 71 additions and 42 deletions

View File

@@ -31,10 +31,6 @@ def listProductBalcao(request, comanda_id, search_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 listProductBalcao(request, comanda_id):
# product = request.GET.get("search-product")
# products = Product.objects.filter(name__icontains=product)
# return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products,'comanda_id':comanda_id})
def addProductBalcao(request, product_id, comanda_id, qtd): def addProductBalcao(request, product_id, comanda_id, qtd):
for i in range(qtd): for i in range(qtd):

View File

@@ -69,8 +69,6 @@
<div id="add-produto"> <div id="add-produto">
<!-- <article> -->
<form id="productForm" > <form id="productForm" >
<h2 style="text-align: center;">Buscar Produto </h2> <h2 style="text-align: center;">Buscar Produto </h2>
<div class="grid-container"> <div class="grid-container">
@@ -128,22 +126,14 @@
{% endfor %} {% endfor %}
</div> </div>
</form> </form>
<!-- </article> -->
</div> </div>
</div> </div>
<dialog id="payment-comanda" style="display: none;" > <dialog id="payment-comanda" style="display: none;" >
<article> <article>
<h2>Receber</h2> <h2>Receber</h2>

View File

@@ -5,21 +5,16 @@ from balcao import htmx_views
from . import views from . import views
urlpatterns = [ urlpatterns = [
# path('', views.comandas, name='comandas'),
path('', views.viewBalcao, name='viewBalcao'), path('', views.viewBalcao, name='viewBalcao'),
# path('createComanda/', views.createComanda, name='createComanda'),
] ]
htmx_urlpatterns = [ htmx_urlpatterns = [
# path('listProduct/', htmx_views.listProduct, name='listProduct'),
path('listProductBalcao/<int:comanda_id>/<str:search_product>/', htmx_views.listProductBalcao, name='listProductBalcao'), path('listProductBalcao/<int:comanda_id>/<str:search_product>/', htmx_views.listProductBalcao, name='listProductBalcao'),
path('addProductBalcao<int:product_id>/<int:comanda_id>/<int:qtd>/', htmx_views.addProductBalcao, name='addProductBalcao'), path('addProductBalcao<int:product_id>/<int:comanda_id>/<int:qtd>/', htmx_views.addProductBalcao, name='addProductBalcao'),
path('addProductBalcaoTeclado<int:product_id>/<int:comanda_id>/<int:qtd>/', htmx_views.addProductBalcaoTeclado, name='addProductBalcaoTeclado'), path('addProductBalcaoTeclado<int:product_id>/<int:comanda_id>/<int:qtd>/', htmx_views.addProductBalcaoTeclado, name='addProductBalcaoTeclado'),
path('removeProductBalcao<int:productComanda_id>/', htmx_views.removeProductBalcao, name='removeProductBalcao'), path('removeProductBalcao<int:productComanda_id>/', htmx_views.removeProductBalcao, name='removeProductBalcao'),
# path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'),
# path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
path('paymentBalcao<int:comanda_id>/', htmx_views.paymentBalcao, name='paymentBalcao'), path('paymentBalcao<int:comanda_id>/', htmx_views.paymentBalcao, name='paymentBalcao'),
] ]

View File

@@ -2,7 +2,6 @@ from django.shortcuts import render, redirect
from comandas.models import Comanda, ProductComanda from comandas.models import Comanda, ProductComanda
from products.models import Product from products.models import Product
from mesas.models import Mesa
from django.db.models import Count, F from django.db.models import Count, F

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -24,14 +24,6 @@ RRB&C - Mesas
{% endif %} {% endif %}
>{{mesa.name}} >{{mesa.name}}
<form action="{% url 'onOffmesa' %}" method="post">
{% csrf_token %}
<input type="hidden" name="id-mesa" value="{{ mesa.id }}">
<button type="submit">On/Off</button>
</form>
</div> </div>
{% endfor %} {% endfor %}

View File

@@ -19,25 +19,61 @@ Produtos
<body> <body>
<div class="grid-container"> <div class="grid-container">
<div class="pico"><input class="pico" type="text"></div> <div ><input type="text"></div>
<button class="pico" id="openModal">Adicionar Novo Produto</button> <button id="openModal">Adicionar Novo Produto</button>
<table id="list-products">
<tr>
<th style="text-align: left;">Produto</th>
<th style="text-align: left;">Preço</th>
<th style="text-align: left;">Quantidade</th>
<th style="text-align: left;">Categoria</th>
<th style="text-align: left;">Ações</th>
</tr>
{% for product in products %} {% for product in products %}
<div class="card"> <tr>
{{product.name}} <td>{{product.name}}</td>
<td>R$ {{product.price}}</td>
<td>{{product.quantity}}</td>
<td>{{product.category.name}}</td>
<td>
<div class="grid-buttons">
<button>📝 Editar</button>
<form action="{% url 'onOffproduct' %}" method="post">
{% csrf_token %}
<input type="hidden" name="id-product" value="{{ product.id }}">
{% if product.active == True %}
<button style="background-color: red;">🚫 Desativar</button>
{% else %}
<button style="background-color: green;" >✅ Ativar</button>
{% endif %}
</form>
</div> </div>
</td>
</tr>
{% endfor %} {% endfor %}
</table>
</div> </div>
</body> </body>
<div class="modal" id="Modal-create-product">
<div class="modal-content">
<dialog id='Modal-create-product' >
<article>
<form action="{% url 'create_product' %}" id="productForm" method="post" > <form action="{% url 'create_product' %}" id="productForm" method="post" >
{% csrf_token %} {% csrf_token %}
<h2>Cadastro de Produto</h2> <h2>Cadastro de Produto</h2>
@@ -55,8 +91,11 @@ Produtos
<button type="submit">Salvar</button> <button type="submit">Salvar</button>
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button> <button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
</form> </form>
</div>
</div> </article>
</dialog>
<script src="{% static 'products/js/products.js' %}"></script> <script src="{% static 'products/js/products.js' %}"></script>

View File

@@ -5,5 +5,6 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.products, name='products'), path('', views.products, name='products'),
path('create_product', views.createProduct, name='create_product'), path('create_product', views.createProduct, name='create_product'),
path('onOffproduct', views.onOffProduct, name='onOffproduct'),
] ]

View File

@@ -19,3 +19,12 @@ def createProduct(request):
product.save() product.save()
return redirect('/products') return redirect('/products')
# return render(request, 'products.html') # return render(request, 'products.html')
def onOffProduct(request):
id = request.POST.get('id-product')
product_id = int(id)
product = Product.objects.get(id=product_id)
product.active = not product.active
product.save()
return redirect('products')

View File

@@ -8,7 +8,6 @@ function close_modal_payment_comanda() {
document.getElementById('payment-comanda').style.display = 'none'; document.getElementById('payment-comanda').style.display = 'none';
} }
// document.cookie = 'qtd=1';
function imprimirFichas() { function imprimirFichas() {
@@ -28,6 +27,7 @@ function imprimirFichas() {
if (element) { if (element) {
var content = element.innerHTML; var content = element.innerHTML;
content = content.replace(/<button[^>]*>(?:(?!<\/button>)[\s\S])*<\/button>/gi,''); content = content.replace(/<button[^>]*>(?:(?!<\/button>)[\s\S])*<\/button>/gi,'');
content = content.replace(/<tfoot[^>]*>(?:(?!<\/tfoot>)[\s\S])*<\/tfoot>/gi,'');
content = content.replace(/<th[^>]*>(?:(?!<\/th>)[\s\S])*<\/th>/gi,''); content = content.replace(/<th[^>]*>(?:(?!<\/th>)[\s\S])*<\/th>/gi,'');
content = content.replace(/<\/tr>/g,'</tr><tr><td colspan="2" style="font-size: 12px">'+dateString+ '<BR>VÁLIDO SOMENTE POR ESSA NOITE'+'</td></tr>'); content = content.replace(/<\/tr>/g,'</tr><tr><td colspan="2" style="font-size: 12px">'+dateString+ '<BR>VÁLIDO SOMENTE POR ESSA NOITE'+'</td></tr>');

View File

@@ -2,7 +2,7 @@
button { button {
background-color: #007BFF; background-color: #007BFF;
color: white; color: white;
padding: 10px 20px; padding: 10px 10px;
border: none; border: none;
border-radius: 5px; border-radius: 5px;
cursor: pointer; cursor: pointer;
@@ -55,11 +55,19 @@ input, textarea {
.grid-container { .grid-buttons {
display: grid; display: grid;
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);
gap: 10px;
max-width: 500px; /* Define a largura máxima do grid */
/* margin: 0 auto; */
}
.grid-container {
display: grid;
grid-template-columns: repeat(1, 1fr);
gap: 20px; gap: 20px;
max-width: 800px; /* Define a largura máxima do grid */ max-width: 1000px; /* Define a largura máxima do grid */
margin: 0 auto; /* Centraliza o grid na página */ margin: 0 auto; /* Centraliza o grid na página */
} }