feat: calcular troco com base no valor recebido

This commit is contained in:
2025-01-08 16:50:50 -03:00
parent a41960dcd5
commit 57f6f3a7fa
6 changed files with 110 additions and 122 deletions

View File

@@ -1,13 +1,12 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load static %} {% load static %}
{% block 'title' %} {% block 'title' %}
{{comanda.name}} {{comanda.name}}
{% endblock %} {% endblock %}
{% block 'head' %} {% block 'head' %}
<link rel="stylesheet" href="{% static 'comandas/css/viewbalcao.css' %}"> <link rel="stylesheet" href="{% static 'comandas/css/viewbalcao.css' %}">
{% endblock %} {% endblock %}
@@ -16,117 +15,85 @@
{% block 'body' %} {% block 'body' %}
<body> <body>
<div class="grid-container" > <div class="grid-container">
<div style="text-align: center;"> <div style="text-align: center;">
<h1>Venda Balcão</h1> <h1>Venda Balcão</h1>
<div> <div>
<button id="pagarComanda" onclick="modal_payment_comanda()" <button id="pagarComanda" onclick="modal_payment_comanda()"
{% if total == 0 %} {% if total == 0 %}
disabled disabled
{% endif %} {% endif %}>Receber</button>
>Receber</button>
<button class="button" id="imprimirFichas" onclick="imprimirFichas()" <button class="button" id="imprimirFichas" onclick="imprimirFichas()"
{% if total == 0 %} {% if total == 0 %}
disabled disabled
{% endif %} {% endif %}
>Imprimir Fichas</button> >Imprimir Fichas</button>
</div> </div>
<table id="list-products-balcao"> <table id="list-products-balcao">
<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 onclick="removeProductBalcao({{item.id}})"
>🗑️ Excluir</button></td>
</tr>
{% endfor %}
<tfoot>
<tr> <tr>
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td> <th style="text-align: left;">Produto</th>
<th style="text-align: left;">Preço</th>
</tr> </tr>
<tr hidden > {% for item in consumo%}
<td hidden id="total">{{total}}</td>
<tr>
<td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</td>
<td><button onclick="removeProductBalcao({{item.id}})">🗑️ Excluir</button></td>
</tr> </tr>
</tfoot>
{% endfor %}
<tfoot>
<tr>
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
</tr>
<tr hidden>
<td hidden id="total">{{total}}</td>
</tr>
</tfoot>
</table> </table>
</div> </div>
<div id="add-produto"> <div id="add-produto">
<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"> <input id="search-product" name="search-product" type="text" oninput="searchProduct()" autofocus
<input placeholder="Buscar Produto">
id="search-product" <input type="number" id="qtd-product" name="qtd-product" value="1" required min="1"><br>
name="search-product" </div>
type="text" <div id="product-list" class="grid-list-products">
oninput="searchProduct()" {% for product in products %}
autofocus {% if forloop.counter0 == 0 %}
placeholder="Buscar Produto"
>
<input
type="number"
id="qtd-product"
name="qtd-product"
value="1"
required min="1"
><br>
</div>
<div id="product-list" class="grid-list-products">
{% for product in products %}
{% if forloop.counter0 == 0 %} <article name="productBox" id="productId-{{ product.id }}"
onclick="addProductClick({{product.id}} , {{comanda.id}})" style="background-color: #293552;">
<p hidden id="{{forloop.counter0}}">{{product.id}}</p>
<p hidden id="comanda{{forloop.counter0}}">{{comanda.id}}</p>
{{product.name}} <br>
<p id="{{product.id}}"></p>
R$ {{product.price}}
</article>
<article {% else %}
name="productBox"
id="productId-{{ product.id }}"
onclick="addProductClick({{product.id}} , {{comanda.id}})"
style="background-color: #293552;"
>
<p hidden id="{{forloop.counter0}}" >{{product.id}}</p>
<p hidden id="comanda{{forloop.counter0}}" >{{comanda.id}}</p>
{{product.name}} <br> <p id="{{product.id}}"></p>
R$ {{product.price}}
</article >
{% else %} <article name="productBox" id="productId-{{ product.id }}"
onclick="addProductClick({{product.id}} , {{comanda.id}})" style="background-color: #293552;">
{{product.name}} <br>
R$ {{product.price}}
</article>
<article {% endif %}
name="productBox"
id="productId-{{ product.id }}"
onclick="addProductClick({{product.id}} , {{comanda.id}})"
style="background-color: #293552;"
>
{{product.name}} <br>
R$ {{product.price}}
</article >
{% endif %} {% endfor %}
</div>
{% endfor %} </form>
</div>
</form>
</div> </div>
@@ -134,26 +101,28 @@
</div> </div>
<dialog id="payment-comanda" style="display: none;" > <dialog id="payment-comanda" style="display: none;">
<article> <article>
<h2>Receber</h2> <h2>Pagamento</h2>
<h1 id="first-total" >R$ {{ total }}</h1> <h1 id="first-total">R$ {{ total }}</h1>
<p> <div>
</p> <p>Recebido:</p> <input id="recebido" type="number">
<ul> <h4 id="troco">Troco: </h4>
</ul> </div>
<footer>
<button class="secondary" hx-get="{% url 'paymentBalcao' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="reloadPage()">
Comfimar
</button>
<button onclick="close_modal_payment_comanda()" >Cancelar</button> <footer>
</footer> <button class="secondary" hx-get="{% url 'paymentBalcao' comanda.id %} " hx-trigger="click" hx-swap="none"
</article> onclick="reloadPage()">
</dialog> Receber
</button>
<button onclick="close_modal_payment_comanda()">Cancelar</button>
</footer>
</article>
</dialog>
<script src="{% static 'comandas/js/viewbalcao.js' %}"></script> <script src="{% static 'comandas/js/viewbalcao.js' %}"></script>
</body> </body>

View File

@@ -61,4 +61,4 @@ def paymentComanda(request, comanda_id):
pagamento.save() pagamento.save()
comanda.status = 'CLOSED' comanda.status = 'CLOSED'
comanda.save() comanda.save()
return redirect('comandas') return redirect('/comandas')

Binary file not shown.

View File

@@ -43,13 +43,13 @@
<ul> <ul>
<li class="nav-item"><a href="{% url 'home' %}" class="nav-link">Início</a></li> <li class="nav-item"><a href="{% url 'home' %}" class="nav-link">Início</a></li>
<li class="nav-item"><a href="{% url 'comandas' %}" class="nav-link">Comandas</a></li> <li class="nav-item"><a href="{% url 'comandas' %}" class="nav-link">Comandas</a></li>
<li class="nav-item"><a href="{% url 'viewBalcao' %}" class="nav-link">Balcão</a></li> <!-- <li class="nav-item"><a href="{% url 'viewBalcao' %}" class="nav-link">Balcão</a></li> -->
<li class="nav-item"><a href="{% url 'mapMesas' %}" class="nav-link">Mapa</a></li> <li class="nav-item"><a href="{% url 'mapMesas' %}" class="nav-link">Mapa</a></li>
<li class="nav-item"><a href="{% url 'products' %}" class="nav-link">Produtos</a></li> <li class="nav-item"><a href="{% url 'products' %}" class="nav-link">Produtos</a></li>
</ul> </ul>
<div class="login-button"> <div class="login-button">
<button><a href="#">Entrar</a></button> <button onclick="entrar()"><a href="#">Entrar</a></button>
</div> </div>
</div> </div>
</header> </header>

View File

@@ -2,14 +2,26 @@
function modal_payment_comanda() { function modal_payment_comanda() {
document.getElementById('payment-comanda').style.display = 'block'; document.getElementById('payment-comanda').style.display = 'block';
recebido = document.getElementById('recebido')
recebido.focus()
}
function troco(){
recebido = document.getElementById('recebido').value
total = document.getElementById('first-total').innerHTML
resultado = document.getElementById('troco')
total = total.replace('R$ ','')
total = total.replace(',','.')
result = recebido - total
resultado.innerHTML = 'Troco: R$ '+result
} }
function close_modal_payment_comanda() { function close_modal_payment_comanda() {
document.getElementById('payment-comanda').style.display = 'none'; document.getElementById('payment-comanda').style.display = 'none';
document.getElementById('search-product').focus()
} }
function imprimirFichas() { function imprimirFichas() {
const element = document.getElementById("list-products-balcao"); const element = document.getElementById("list-products-balcao");
const style = `<style> const style = `<style>
@@ -57,11 +69,19 @@ function backPage() {
document.onkeydown = teclado document.onkeydown = teclado
function teclado(event){ function teclado(event){
if (event.keyCode == 13){ if (document.getElementById('payment-comanda').style.display == 'none'){
addProductBalcao() if (event.keyCode == 13){
}else{ addProductBalcao()
console.log('') }else{
} console.log(event.keyCode)
}
}else{
if (event.keyCode == 13){
troco()
}else{
console.log('')
}
}
} }
@@ -123,7 +143,6 @@ document.getElementById('productForm').addEventListener('submit', function(event
function searchProduct() { function searchProduct() {
setTimeout(() => { setTimeout(() => {
time(); time();