feat: taxa de serviço conticionado a configuração (que ainda não existe rs)

This commit is contained in:
2025-02-21 10:33:03 -03:00
parent 46f0900763
commit fdb9d9e453
11 changed files with 63 additions and 18 deletions

View File

@@ -1,5 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load static %} {% load static %}
{% load custom_filter_tag %}
@@ -34,7 +36,7 @@ Clientes
<tr> <tr>
<td ><a id="name-{{client.id}}" href="{% url 'viewClient' client.id %}">{{client.name}}</a></td> <td ><a id="name-{{client.id}}" href="{% url 'viewClient' client.id %}">{{client.name}}</a></td>
<td id="debt-{{client.id}}" >R$ {{client.debt}}</td> <td id="debt-{{client.id}}" >R$ {{client.id | totalFiado}}</td>
<td class="hide-on-mobile" id="contact-{{client.id}}" >{{client.contact}}</td> <td class="hide-on-mobile" id="contact-{{client.id}}" >{{client.contact}}</td>
<td hidden id="active-{{client.id}}" >{{client.active}}</td> <td hidden id="active-{{client.id}}" >{{client.active}}</td>
<td> <td>

View File

@@ -16,7 +16,7 @@ Comandas
<body> <body>
<div style="justify-self: center;"> <div style="justify-self: center;">
<h4>{{client.name}}</h4> <h4>{{client.name}}</h4>
<h4>R$ {{total}}</h4> <h4>R$ {{client.id | totalFiado}}</h4>
</div> </div>
<div class=" "> <div class=" ">

View File

@@ -15,21 +15,24 @@ def clients(request):
return render(request, 'clients.html', {'clients': clients}) return render(request, 'clients.html', {'clients': clients})
def viewClient(request,clientId): def viewClient(request,clientId):
# config = {
# 'taxa': False
# }
client = Client.objects.get(id=int(clientId)) client = Client.objects.get(id=int(clientId))
comandas = Comanda.objects.filter(client = client).filter(status = 'FIADO') comandas = Comanda.objects.filter(client = client).filter(status = 'FIADO')
total = Decimal(0) total = Decimal(0)
for comanda in comandas: # for comanda in comandas:
totalConsumo = 0 # totalConsumo = 0
totalParcial = 0 # totalParcial = 0
consumo = ProductComanda.objects.filter(comanda=comanda) # consumo = ProductComanda.objects.filter(comanda=comanda)
parcial = Payments.objects.filter(comanda=comanda) # parcial = Payments.objects.filter(comanda=comanda)
for p in parcial: # for p in parcial:
totalParcial += p.value # totalParcial += p.value
for produto in consumo: # for produto in consumo:
totalConsumo += produto.product.price # totalConsumo += produto.product.price
total+= (totalConsumo - totalParcial) # total+= (totalConsumo - totalParcial)
total+= round(total * Decimal(0.1), 2) # total = total + round(total * Decimal(0.1), 2) if config['taxa'] else total
return render(request, 'viewclient.html', {'total': total, 'client': client, 'comandas': comandas}) return render(request, 'viewclient.html', {'client': client, 'comandas': comandas})
@group_required(groupName='Gerente') @group_required(groupName='Gerente')

View File

@@ -117,6 +117,7 @@ Detalhes {{comanda.name}}
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
{% if config.taxa %}
<tr> <tr>
<td> <td>
Taxa de serviço 10% Taxa de serviço 10%
@@ -125,6 +126,8 @@ Detalhes {{comanda.name}}
R$ {{valores.taxa}} R$ {{valores.taxa}}
</td> </td>
</tr> </tr>
{% endif %}
{% if parcials%} {% if parcials%}
<td colspan="2" style="text-align: center;"><b>Pagamentos parciais</b></td> <td colspan="2" style="text-align: center;"><b>Pagamentos parciais</b></td>
{% endif %} {% endif %}
@@ -140,7 +143,11 @@ Detalhes {{comanda.name}}
<tfoot> <tfoot>
<tr> <tr>
{% if config.taxa %}
<td colspan="2" style="text-align: center;"><b>Total R$ {{valores.totalComTaxa}}</b></td> <td colspan="2" style="text-align: center;"><b>Total R$ {{valores.totalComTaxa}}</b></td>
{% else %}
<td colspan="2" style="text-align: center;"><b>Total R$ {{valores.totalSemTaxa}}</b></td>
{% endif %}
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@@ -191,12 +198,16 @@ Detalhes {{comanda.name}}
<h2>Pagamento</h2> <h2>Pagamento</h2>
<div style="display: flex; align-content: space-around; align-items: center; justify-self: center;gap: 50px;"> <div style="display: flex; align-content: space-around; align-items: center; justify-self: center;gap: 50px;">
{% if config.taxa %}
<h1 id="first-total">R$ {{ valores.totalComTaxa }}</h1> <h1 id="first-total">R$ {{ valores.totalComTaxa }}</h1>
<h1 hidden id="totalComTaxa">R$ {{ valores.totalComTaxa }}</h1> <h1 hidden id="totalComTaxa">R$ {{ valores.totalComTaxa }}</h1>
<h1 hidden id="totalSemTaxa">R$ {{ valores.totalSemTaxa }}</h1> <h1 hidden id="totalSemTaxa">R$ {{ valores.totalSemTaxa }}</h1>
<div> <div>
<input id="taxa" name="taxa" type="checkbox" value="True" label="Taxa de serviço" checked >Taxa de serviço <input id="taxa" name="taxa" type="checkbox" value="True" label="Taxa de serviço" checked >Taxa de serviço
{% else %}
<h1 id="first-total">R$ {{ valores.totalSemTaxa }}</h1>
{% endif %}
</div> </div>
</div> </div>
<div> <div>
@@ -268,7 +279,7 @@ Detalhes {{comanda.name}}
<form id="form-comanda" method="post" action="{% url 'addContaCliente' %}"> <form id="form-comanda" method="post" action="{% url 'addContaCliente' %}">
{% csrf_token %} {% csrf_token %}
<h2>Adicionar na Conta</h2> <h2>Adicionar na Conta</h2>
<h1>R$ {{ total }}</h1> <h1>R$ {{ valores.totalSemTaxa }}</h1>
<div> <div>
<input hidden type="text" name="valor-conta" value="{{ total }}"> <input hidden type="text" name="valor-conta" value="{{ total }}">
<input hidden type="text" name="idComanda" value="{{ comanda.id }}"> <input hidden type="text" name="idComanda" value="{{ comanda.id }}">

View File

@@ -2,12 +2,16 @@ from decimal import Decimal
from django import template from django import template
from comandas.models import Comanda, ProductComanda from comandas.models import Comanda, ProductComanda
from clients.models import Client
from payments.models import Payments from payments.models import Payments
register = template.Library() register = template.Library()
@register.filter(name='total') @register.filter(name='total')
def filter_total(value): def filter_total(value):
config = {
'taxa': False
}
id = value id = value
comanda_id = int(id) comanda_id = int(id)
totalParcial = Decimal(0) totalParcial = Decimal(0)
@@ -21,9 +25,31 @@ def filter_total(value):
for produto in consumo: for produto in consumo:
total += produto.product.price total += produto.product.price
taxa = round(total * Decimal(0.1), 2) taxa = round(total * Decimal(0.1), 2)
total = (total + taxa) - totalParcial total = (total + taxa) - totalParcial if config['taxa'] else total - totalParcial
return f'R$ {total}' return f'R$ {total}'
@register.filter(name='totalFiado')
def viewClient(clientId):
config = {
'taxa': False
}
client = Client.objects.get(id=int(clientId))
comandas = Comanda.objects.filter(client = client).filter(status = 'FIADO')
total = Decimal(0)
for comanda in comandas:
totalConsumo = 0
totalParcial = 0
consumo = ProductComanda.objects.filter(comanda=comanda)
parcial = Payments.objects.filter(comanda=comanda)
for p in parcial:
totalParcial += p.value
for produto in consumo:
totalConsumo += produto.product.price
total+= (totalConsumo - totalParcial)
total = total + round(total * Decimal(0.1), 2) if config['taxa'] else total
return total
@register.filter(name='groupUser') @register.filter(name='groupUser')
def has_group(user, group_name): def has_group(user, group_name):

View File

@@ -41,6 +41,9 @@ def somar(consumo:ProductComanda, comanda:Comanda):
@group_required(groupName='Garçom') @group_required(groupName='Garçom')
def viewComanda(request): def viewComanda(request):
config = {
'taxa': False
}
id = request.GET.get('parametro') id = request.GET.get('parametro')
comanda_id = int(id) comanda_id = int(id)
comanda = Comanda.objects.get(id=comanda_id) comanda = Comanda.objects.get(id=comanda_id)
@@ -60,7 +63,7 @@ def viewComanda(request):
if p.name == produto['nome'] and p.active == True: if p.name == produto['nome'] and p.active == True:
products_ordenados.append(p) products_ordenados.append(p)
valores = somar(consumo,comanda) valores = somar(consumo,comanda)
return render(request, 'viewcomanda.html', {'valores':valores,'parcials':parcial,'clients':clients,'comanda': comanda, 'consumo': consumo, 'products': products_ordenados,'mesas':mesas}) return render(request, 'viewcomanda.html', {'config':config, 'valores':valores,'parcials':parcial,'clients':clients,'comanda': comanda, 'consumo': consumo, 'products': products_ordenados,'mesas':mesas})
@group_required(groupName='Garçom') @group_required(groupName='Garçom')

Binary file not shown.