Merge pull request #1 from Pindoba/dev_2

Dev 2
This commit is contained in:
Welton Moura
2024-12-21 10:11:37 -03:00
committed by GitHub
77 changed files with 153 additions and 9 deletions

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

@@ -1,7 +1,9 @@
from django.shortcuts import render, redirect from django.shortcuts import render, redirect, HttpResponse
from comandas.models import Comanda, ProductComanda from comandas.models import Comanda, ProductComanda
from products.models import Product from products.models import Product
from payments.models import Payments
from typePay.models import TypePay
def listProduct(request, comanda_id): def listProduct(request, comanda_id):
@@ -29,9 +31,30 @@ 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 closeComanda(request, comanda_id): def closeComanda(request, comanda_id):
# id = request.POST.get('id-comanda')
# comanda_id = int(id)
comanda = Comanda.objects.get(id=comanda_id) comanda = Comanda.objects.get(id=comanda_id)
comanda.status = "PAYING" comanda.status = "PAYING"
comanda.save() comanda.save()
# return redirect('back')
def reopenComanda(request, comanda_id):
comanda = Comanda.objects.get(id=comanda_id)
if comanda.status == 'CLOSED':
pass
else:
comanda.status = "OPEN"
comanda.save()
# return redirect('back')
def paymentComanda(request, comanda_id):
typePayment = TypePay.objects.get(id=1)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
comanda = Comanda.objects.get(id=comanda_id)
total = 0
for produto in consumo:
total += produto.product.price
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado')
pagamento.save()
comanda.status = 'CLOSED'
comanda.save()
return redirect('comandas') return redirect('comandas')

View File

@@ -27,23 +27,34 @@ Detalhes {{comanda.name}}
{% endif %} {% endif %}
>Adicionar Produto</button> >Adicionar Produto</button>
<button id="pagarComanda" hx-get="{% url 'closeComanda' comanda.id %} " hx-trigger="click" <button id="pagarComanda" hx-get="{% url 'closeComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="imprimirConta()"
{% if comanda.status != 'OPEN' %} {% if comanda.status != 'OPEN' %}
style="display: none;" style="display: none;"
{% endif %} {% endif %}
>Fechar Comanda</button> >Fechar Comanda</button>
<button id="pagarComanda" <button id="pagarComanda" onclick="modal_payment_comanda()"
{% if comanda.status != 'PAYING' %} {% if comanda.status != 'PAYING' %}
style="display: none;" style="display: none;"
{% endif %} {% endif %}
>Receber</button> >Receber</button>
<button class="button" id="imprimirFichas" onclick="imprimirFichas()">Imprimir Fichas</button> <button class="button" id="imprimirFichas"
{% if comanda.status != 'OPEN'%}
style="display: none;"
{% endif %}
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> </div>
<!-- <p>{{comanda.id}}</p> -->
<div> <div>
<span>Nome: {{comanda.name}} | </span> <span>Nome: {{comanda.name}} | </span>
<span>Mesa: {{comanda.mesa}}</span> <span>Mesa: {{comanda.mesa}}</span>
@@ -63,7 +74,11 @@ 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 hx-get="{% url 'removeProductComanda' item.id %} " hx-trigger="click" hx-target="#list-products-comanda" onclick="open_remove_product_comanda()">🗑️ Excluir</button></td> <td><button
{% if comanda.status != 'OPEN'%}
disabled
{% 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>
@@ -124,6 +139,24 @@ Detalhes {{comanda.name}}
</article> </article>
</dialog> </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/viewcomanda.js' %}"></script> <script src="{% static 'comandas/js/viewcomanda.js' %}"></script>

View File

@@ -20,6 +20,8 @@ htmx_urlpatterns = [
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'), path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'), path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'),
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('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),
] ]
urlpatterns += htmx_urlpatterns urlpatterns += htmx_urlpatterns

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -52,6 +52,7 @@ INSTALLED_APPS = [
'comandas', 'comandas',
'categories', 'categories',
'home', 'home',
'payments',
] ]
MIDDLEWARE = [ MIDDLEWARE = [

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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,30 @@
# Generated by Django 5.1.4 on 2024-12-20 17:33
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('clients', '0001_initial'),
('comandas', '0003_comanda_status_alter_productcomanda_product'),
('typePay', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Payments',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('value', models.DecimalField(decimal_places=2, max_digits=10)),
('description', models.CharField(max_length=255)),
('datetime', models.DateTimeField(auto_now_add=True)),
('client', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='clients.client')),
('comanda', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='comandas.comanda')),
('type_pay', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='typePay.typepay')),
],
),
]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -7,6 +7,14 @@ function open_remove_product_comanda() {
document.getElementById('remove-product-comanda').style.display = 'block'; document.getElementById('remove-product-comanda').style.display = 'block';
} }
function modal_payment_comanda() {
document.getElementById('payment-comanda').style.display = 'block';
}
function close_modal_payment_comanda() {
document.getElementById('payment-comanda').style.display = 'none';
}
function closeModal() { function closeModal() {
document.getElementById('Modal-add-product').style.display = 'none'; document.getElementById('Modal-add-product').style.display = 'none';
} }
@@ -49,6 +57,53 @@ function imprimirFichas() {
} }
function imprimirConta() {
reloadPage();
const element = document.getElementById("list-products-comanda");
const style = `<style>
td, th {
border-collapse: collapse;
padding-top: 15px;
margin: 15px;
text-align: center;
font-size: 18px;}
</style>`;
const agora = new Date();
var dateString = agora.getDay() + '/' + agora.getMonth() + '/' + agora.getFullYear() + ' - ' + agora.getHours() + ':' + agora.getMinutes()+' - Raul Rock Bar & Café';
if (element) {
var content = element.innerHTML;
// console.log(content);
content = content.replace(/<button[^>]*>(?:(?!<\/button>)[\s\S])*<\/button>/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+'</td></tr>');
console.log(content);
var printWindow = window.open('', '_blank');
printWindow.document.write('<table>'+content+'</table>'+style);
printWindow.document.close();
printWindow.print();
printWindow.close();
} else {
console.error(`Element with ID not found`);
}
}
function reloadPage(){
setTimeout(function() {
location.reload();}, 100);
}
function backPage() {
setTimeout(function() {
history.back();}, 100);
setTimeout(function() {
location.reload();}, 100);
}
document.getElementById('openModal').addEventListener('click', openModal); document.getElementById('openModal').addEventListener('click', openModal);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.