feat: taxa de serviço part2

This commit is contained in:
2025-02-18 16:11:27 -03:00
parent aac7f57fbe
commit 44a9c694dc
8 changed files with 105 additions and 55 deletions

View File

@@ -21,7 +21,9 @@ def somar(consumo:ProductComanda, comanda:Comanda):
valores = { valores = {
'total':total, 'total':total,
'parcial':totalParcial, 'parcial':totalParcial,
'taxaTotal': round(total * Decimal(0.1), 2) 'taxa': round(total * Decimal(0.1), 2),
'totalSemTaxa':total - totalParcial,
'totalComTaxa': round((total - totalParcial)+(total * Decimal(0.1)),2)
} }
return valores return valores
@@ -47,8 +49,8 @@ def addProduct(request, product_id, comanda_id):
order.save() order.save()
consumo = ProductComanda.objects.filter(comanda=comanda_id) consumo = ProductComanda.objects.filter(comanda=comanda_id)
valores = somar(consumo,comanda) valores = somar(consumo,comanda)
total = valores['total'] - valores['parcial']
return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'parcials':parcial,'consumo': consumo, 'total': total, 'comanda':comanda}) return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'valores':valores,'parcials':parcial,'consumo': consumo,'comanda':comanda})
@group_required(groupName='Garçom') @group_required(groupName='Garçom')
def editOrders(request, productComanda_id, obs): def editOrders(request, productComanda_id, obs):
@@ -66,8 +68,7 @@ def removeProductComanda(request, productComanda_id):
consumo = ProductComanda.objects.filter(comanda=comanda) consumo = ProductComanda.objects.filter(comanda=comanda)
product_comanda.delete() product_comanda.delete()
valores = somar(consumo,comanda) valores = somar(consumo,comanda)
total = valores['total'] - valores['parcial'] return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'valores': valores,'parcials':parcial,'consumo': consumo, 'comanda':comanda})
return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'parcials':parcial,'consumo': consumo, 'total': total, 'comanda':comanda})
@group_required(groupName='Garçom') @group_required(groupName='Garçom')
def closeComanda(request, comanda_id): def closeComanda(request, comanda_id):
@@ -87,13 +88,18 @@ def reopenComanda(request, comanda_id):
@group_required(groupName='Gerente') @group_required(groupName='Gerente')
def paymentComanda(request, comanda_id): def paymentComanda(request, comanda_id):
taxa = request.POST.get('taxa',False)
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)
comanda = Comanda.objects.get(id=comanda_id) comanda = Comanda.objects.get(id=comanda_id)
valores = somar(consumo,comanda) valores = somar(consumo,comanda)
total = valores['total'] - valores['parcial'] if taxa == 'True':
pagamento = Payments(value=total, comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado') pagamento = Payments(value=valores['totalComTaxa'], comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado')
pagamento.save() pagamento.save()
else:
pagamento = Payments(value=valores['totalSemTaxa'], comanda=comanda, type_pay=typePayment,description='tipo de pagamento mokado')
pagamento.save()
comanda.status = 'CLOSED' comanda.status = 'CLOSED'
comanda.save() comanda.save()
return redirect('/comandas') return redirect('/comandas')
@@ -103,7 +109,6 @@ def paymentParcial(request, comanda_id):
typePayment = TypePay.objects.get(id=1) typePayment = TypePay.objects.get(id=1)
comanda = Comanda.objects.get(id=comanda_id) comanda = Comanda.objects.get(id=comanda_id)
value = Decimal(request.POST.get('value-parcial')) value = Decimal(request.POST.get('value-parcial'))
print(value)
description = request.POST.get('name-parcial') description = request.POST.get('name-parcial')
pagamento = Payments(value=value, comanda=comanda, type_pay=typePayment,description=description) pagamento = Payments(value=value, comanda=comanda, type_pay=typePayment,description=description)
pagamento.save() pagamento.save()

View File

@@ -117,6 +117,14 @@ Detalhes {{comanda.name}}
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
<tr>
<td>
Taxa de serviço 10%
</td>
<td>
R$ {{valores.taxa}}
</td>
</tr>
{% 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 %}
@@ -132,7 +140,7 @@ Detalhes {{comanda.name}}
<tfoot> <tfoot>
<tr> <tr>
<td colspan="2" style="text-align: center;"><b>Total R$ {{total}} - Taxa de serviso {{taxa}}</b></td> <td colspan="2" style="text-align: center;"><b>Total R$ {{valores.totalComTaxa}}</b></td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@@ -178,8 +186,19 @@ Detalhes {{comanda.name}}
<dialog id="payment-comanda" style="display: none;" > <dialog id="payment-comanda" style="display: none;" >
<article> <article>
<form action="{% url 'paymentComanda' comanda.id %}" method="post">
{% csrf_token %}
<h2>Pagamento</h2> <h2>Pagamento</h2>
<h1 id="first-total">R$ {{ total }}</h1> <div style="display: flex; align-content: space-around; align-items: center; justify-self: center;gap: 50px;">
<h1 id="first-total">R$ {{ valores.totalComTaxa }}</h1>
<h1 hidden id="totalComTaxa">R$ {{ valores.totalComTaxa }}</h1>
<h1 hidden id="totalSemTaxa">R$ {{ valores.totalSemTaxa }}</h1>
<div>
<input id="taxa" name="taxa" type="checkbox" value="True" label="Taxa de serviço" checked >Taxa de serviço
</div>
</div>
<div> <div>
<p>Recebido:</p> <input id="recebido" type="number"> <p>Recebido:</p> <input id="recebido" type="number">
<h4 id="troco">Troco: </h4> <h4 id="troco">Troco: </h4>
@@ -187,13 +206,14 @@ Detalhes {{comanda.name}}
<footer> <footer>
<div style="display: flex;gap: 10px;"> <div style="display: flex;gap: 10px;">
<button type="submit" class="btn-secondary" hx-get="{% url 'paymentComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="backPage()">Receber</button> <button type="submit" class="btn-secondary" onclick="backPage()">Receber</button>
<button type="button" class="btn-primary" onclick=" modal_conta_client()"> <button type="button" class="btn-primary" onclick=" modal_conta_client()">
Conta Conta
</button> </button>
<button type="button" class="btn-cancel" onclick="close_modal_payment_comanda()">Cancelar</button> <button type="button" class="btn-cancel" onclick="close_modal_payment_comanda()">Cancelar</button>
</div> </div>
</footer> </footer>
</form>
</article> </article>
</dialog> </dialog>

View File

@@ -32,7 +32,9 @@ def somar(consumo:ProductComanda, comanda:Comanda):
valores = { valores = {
'total':total, 'total':total,
'parcial':totalParcial, 'parcial':totalParcial,
'taxaTotal': round(total * Decimal(0.1), 2) 'taxa': round(total * Decimal(0.1), 2),
'totalSemTaxa':total - totalParcial,
'totalComTaxa': round((total - totalParcial)+(total * Decimal(0.1)),2)
} }
return valores return valores
@@ -57,8 +59,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)
total = valores['total'] - valores['parcial'] 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', {'taxa': valores['taxaTotal'],'parcials':parcial,'clients':clients,'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados,'mesas':mesas})
@group_required(groupName='Garçom') @group_required(groupName='Garçom')
@@ -96,7 +97,7 @@ def addContaCliente(request):
return redirect('comandas') return redirect('comandas')
def notificacao(request): def notificacao(request):
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15) fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=12)
ordersPronto = Order.objects.filter(queue__gte=fifteen_hours_ago, finished__isnull=False) ordersPronto = Order.objects.filter(queue__gte=fifteen_hours_ago, finished__isnull=False)
grupoGarcom = request.user.groups.filter(name='Garçom').exists() grupoGarcom = request.user.groups.filter(name='Garçom').exists()

Binary file not shown.

View File

@@ -1,58 +1,71 @@
{% load static %} {% load static %}
<tr> <tr>
<th style="text-align: left;"><b>Produto</b></th> <th style="text-align: left;"><b>Produto</b></th>
<th style="text-align: left;"><b>Preço</b></th> <th style="text-align: left;"><b>Preço</b></th>
</tr> </tr>
{% for item in consumo%} {% for item in consumo%}
<tr> <tr>
<td> <td >
{{item.product.name}} {{item.product.name}}
{% if item.product.cuisine == True %} {% if item.product.cuisine == True %}
<span data-tooltip="Observações para preparo." data-flow="top"> <span data-tooltip="Observações para preparo." data-flow="top">
<img <img
onclick="openModalObs({{item.id}})" onclick="openModalObs({{item.id}})"
src="{% static 'midia/icons/note.svg' %}" src="{% static 'midia/icons/note.svg' %}"
style="width: 25px; height: 35px; cursor: pointer;"> style="width: 25px; height: 35px; cursor: pointer;">
</img> </img>
<span> </span>
{% endif %} {% endif %}
</td> </td>
<td>R$ {{item.product.price}}</td> <td>R$ {{item.product.price}}</td>
{% if comanda.status != 'OPEN'%}
{% else %} {% if comanda.status != 'OPEN'%}
<td> {% else %}
<img <td>
src="{% static 'midia/icons/delete.svg' %}" <img
style="width: 35px; height: 35px; cursor: pointer;" src="{% static 'midia/icons/delete.svg' %}"
hx-get="{% url 'removeProductComanda' item.id %} " style="width: 35px; height: 35px; cursor: pointer;"
hx-trigger="click" hx-get="{% url 'removeProductComanda' item.id %} "
hx-target="#list-products-comanda" hx-trigger="click"
hx-confirm="Tem certeza que deseja excluir o produto {{item.product.name}}?" > hx-target="#list-products-comanda"
</img> hx-confirm="Tem certeza que deseja excluir o produto {{item.product.name}}?" >
</td> </img>
</td>
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
{% if parcials%} <tr>
<td colspan="2" style="text-align: center;"><b>Pagamentos parciais</b></td> <td>
{% endif %} Taxa de serviço 10%
{% for parcial in parcials %} </td>
<tr> <td>
<td>{{parcial.description}} ás {{parcial.datetime|date:"H:i"}}</td> R$ {{valores.taxa}}
<td>R$ -{{parcial.value}}</td> </td>
</tr> </tr>
{% endfor %} {% if parcials%}
<td colspan="2" style="text-align: center;"><b>Pagamentos parciais</b></td>
{% endif %}
{% for parcial in parcials %}
<tr>
<td>{{parcial.description}} ás {{parcial.datetime|date:"H:i"}}</td>
<td>R$ -{{parcial.value}}</td>
</tr>
{% endfor %}
<tfoot> <tfoot>
<tr> <tr>
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td> <td colspan="2" style="text-align: center;"><b>Total R$ {{valores.totalComTaxa}}</b></td>
</tr> </tr>
</tfoot> </tfoot>
</table>

View File

@@ -247,9 +247,20 @@ function addProductComanda(productId,comandaId, cuisine) {
} }
function taxa(){
var taxa = document.getElementById('taxa')
var total = document.getElementById('first-total')
var totalComTaxa = document.getElementById('totalComTaxa').innerHTML
var totalSemTaxa = document.getElementById('totalSemTaxa').innerHTML
if (taxa.checked){
total.innerHTML = totalComTaxa
}else{
total.innerHTML = totalSemTaxa
}
}
// document.getElementById('openModal').addEventListener('click', openModal); document.getElementById('taxa').addEventListener("change", taxa);
// document.getElementById('productForm').addEventListener('submit', function(event) { // document.getElementById('productForm').addEventListener('submit', function(event) {
// event.preventDefault(); // event.preventDefault();