feat: create page balcao

This commit is contained in:
2024-12-21 11:43:09 -03:00
parent 59e4eb6039
commit 0ef1c0a61b
44 changed files with 657 additions and 1 deletions

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ComandasConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'balcao'

View File

@@ -0,0 +1,46 @@
from django.shortcuts import render, redirect
from comandas.models import Comanda, ProductComanda
from products.models import Product
from payments.models import Payments
from typePay.models import TypePay
def listProduct(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 addProduct(request, product_id, comanda_id):
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
product_comanda.save()
consumo = ProductComanda.objects.filter(comanda=comanda_id)
total = 0
for produto in consumo:
total += produto.product.price
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
def removeProductComanda(request, productComanda_id):
product_comanda = ProductComanda.objects.get(id=productComanda_id)
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
product_comanda.delete()
total = 0
for produto in consumo:
total += produto.product.price
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
def paymentComanda(request, comanda_id):
typePayment = TypePay.objects.get(id=1)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
comanda = Comanda.objects.get(name='VENDA BALCÃO')
total = 0
for produto in consumo:
total += produto.product.price
removeProductComanda(request, produto.id)
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='VENDA BALÃO')
pagamento.save()
comanda.save()
return redirect('comandas')

View File

@@ -0,0 +1,30 @@
# Generated by Django 5.1.4 on 2024-12-10 01:19
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('clients', '0001_initial'),
('mesas', '0001_initial'),
('typePay', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Comanda',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('dt_open', models.DateTimeField(auto_now_add=True)),
('dt_close', models.DateTimeField(blank=True, null=True)),
('name', models.CharField(max_length=255)),
('client', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='clients.client')),
('mesa', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mesas.mesa')),
('type_pay', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='typePay.typepay')),
],
),
]

View File

@@ -0,0 +1,25 @@
# Generated by Django 5.1.4 on 2024-12-10 01:20
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('comandas', '0001_initial'),
('products', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ProductComanda',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('data_time', models.DateTimeField(auto_now_add=True)),
('applicant', models.CharField(blank=True, max_length=255, null=True)),
('comanda', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='comandas.comanda')),
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='products.product')),
],
),
]

View File

@@ -0,0 +1,25 @@
# Generated by Django 5.1.4 on 2024-12-20 12:36
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('comandas', '0002_productcomanda'),
('products', '0002_product_image_product_quantity'),
]
operations = [
migrations.AddField(
model_name='comanda',
name='status',
field=models.CharField(default='OPEN', max_length=255),
),
migrations.AlterField(
model_name='productcomanda',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='products.product'),
),
]

View File

View File

@@ -0,0 +1,27 @@
# from django.db import models
# from clients.models import Client
# from products.models import Product
# from mesas.models import Mesa
# from typePay.models import TypePay
# class Comanda(models.Model):
# id = models.AutoField(primary_key=True)
# mesa = models.ForeignKey(Mesa, on_delete=models.CASCADE)
# type_pay = models.ForeignKey(TypePay, on_delete=models.SET_NULL, null=True)
# dt_open = models.DateTimeField(auto_now_add=True)
# dt_close = models.DateTimeField(null=True, blank=True)
# client = models.ForeignKey(Client, on_delete=models.SET_NULL, null=True, blank=True)
# name = models.CharField(max_length=255)
# status = models.CharField(max_length=255, default="OPEN")
# def __str__(self) -> str:
# return self.name
# class ProductComanda(models.Model):
# id = models.AutoField(primary_key=True)
# comanda = models.ForeignKey(Comanda, on_delete=models.CASCADE)
# data_time = models.DateTimeField(auto_now_add=True)
# product = models.ForeignKey(Product, on_delete=models.PROTECT)
# applicant = models.CharField(max_length=255, null=True, blank=True)
# def __str__(self) -> str:
# return self.comanda.name + " - " + self.product.name

View File

@@ -0,0 +1,201 @@
{% extends "base.html" %}
{% load static %}
{% block 'title' %}
Detalhes {{comanda.name}}
{% endblock %}
{% block 'head' %}
<link rel="stylesheet" href="{% static 'comandas/css/viewbalcao.css' %}">
{% endblock %}
{% block 'body' %}
<body>
<div class="grid-container" >
<div>
<h1>Venda Balcão</h1>
<div>
<button class="primary" id="openModal" >Adicionar Produto</button>
<button id="pagarComanda" hx-get="{% url 'closeComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="imprimirConta()"
{% if comanda.status != 'OPEN' %}
style="display: none;"
{% endif %}
>Fechar Comanda</button>
<button id="pagarComanda" onclick="modal_payment_comanda()"
>Receber</button>
<button class="button" id="imprimirFichas" onclick="imprimirFichas()"
>Imprimir Fichas</button>
<!-- <button class="button" id="imprimirFichas" hx-get="{% url 'reopenComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="reloadPage()"
{% if comanda.status == 'OPEN'%}
style="display: none;"
{% elif comanda.status == 'CLOSED' %}
style="display: none;"
{% endif %}
>Reabrir</button> -->
</div>
<!-- <p>Aberta em: {{comanda.dt_open|date:"D"}} {{comanda.dt_open|date:"d/m/Y - H:i"}}</p> -->
<table id="list-products-comanda">
<tr>
<th style="text-align: left;">Produto</th>
<th style="text-align: left;">Preço</th>
</tr>
{% for item in consumo%}
<tr>
<td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</td>
<td><button
hx-get="{% url 'removeProductComanda' item.id %} " hx-trigger="click" hx-target="#list-products-comanda"
onclick="reloadPage()">🗑️ Excluir</button></td>
</tr>
{% endfor %}
<tfoot>
<tr>
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
</tr>
</tfoot>
</table>
</div>
<div id="add-produto">
<article>
<form id="productForm" >
<h2>Adicionar 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 id="product-list" class="grid-list-products">
{% for product in products %}
<article onclick="reloadPage()" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda">
{{product.name}} <br>
R$ {{product.price}}
</article >
{% endfor %}
</div>
</form>
</article>
</div>
</div>
<!-- <dialog id="Modal-add-product" style="display: none;" >
<article>
<form id="productForm" >
<h2>Adicionar Produto <button type="button" onclick="closeModal()" style="background-color:red;" >Fechar</button></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 id="product-list" class="grid-list-products">
{% for product in products %}
<article onclick="reloadPage()" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda">
{{product.name}} <br>
R$ {{product.price}}
</article >
{% endfor %}
</div>
</form>
</article>
</dialog> -->
<dialog id="remove-product-comanda" style="display: none;" >
<article>
<h2>Produto Excluido!</h2>
<h1></h1>
<p>
</p>
<ul>
</ul>
<footer>
<button class="secondary" onclick="removeCloseModal()">
OK
</button>
<!-- <button >Excluir</button> -->
</footer>
</article>
</dialog>
<dialog id="payment-comanda" style="display: none;" >
<article>
<h2>Receber</h2>
<h1>R$ {{ total }}</h1>
<p>
</p>
<ul>
</ul>
<footer>
<button class="secondary" hx-get="{% url 'paymentComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="backPage()">
Comfimar
</button>
<button onclick="close_modal_payment_comanda()" >Cancelar</button>
</footer>
</article>
</dialog>
<script src="{% static 'comandas/js/viewbalcao.js' %}"></script>
</body>
{% endblock %}

View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

25
gestaoRaul/balcao/urls.py Normal file
View File

@@ -0,0 +1,25 @@
from django.urls import path
from balcao import htmx_views
from . import views
urlpatterns = [
# path('', views.comandas, name='comandas'),
path('', views.viewBalcao, name='viewBalcao'),
# path('createComanda/', views.createComanda, name='createComanda'),
]
htmx_urlpatterns = [
# path('listProduct/', htmx_views.listProduct, name='listProduct'),
path('listProduct/<int:comanda_id>/', htmx_views.listProduct, name='listProduct'),
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'),
# path('closeComanda<int:comanda_id>/', htmx_views.closeComanda, name='closeComanda'),
# path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),
]
urlpatterns += htmx_urlpatterns

View File

@@ -0,0 +1,36 @@
from django.shortcuts import render, redirect
from comandas.models import Comanda, ProductComanda
from products.models import Product
from mesas.models import Mesa
# def balcao(request):
# comandas = Comanda.objects.filter(status__in=["OPEN", "PAYING"])
# mesas = Mesa.objects.all()
# return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
def viewBalcao(request):
comanda = Comanda.objects.get(name='VENDA BALCÃO')
consumo = ProductComanda.objects.filter(comanda=comanda.id)
products = Product.objects.all()
total = 0
for produto in consumo:
total += produto.product.price
return render(request, 'viewBalcao.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products})
# def createComanda(request):
# name = request.POST.get('name-comanda')
# mesa_id = int(request.POST.get('select-mesa')[0])
# mesa = Mesa.objects.get(id=mesa_id)
# comanda = Comanda(name=name, mesa=mesa)
# comanda.save()
# return redirect('comandas')