mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
atualizar valor todal modal receber
This commit is contained in:
Binary file not shown.
@@ -1,5 +1,7 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.db.models import Count, F
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from comandas.models import Comanda, ProductComanda
|
from comandas.models import Comanda, ProductComanda
|
||||||
@@ -9,10 +11,24 @@ from typePay.models import TypePay
|
|||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def listProductBalcao(request, comanda_id, search_product):
|
def listProductBalcao(request, comanda_id, search_product):
|
||||||
print('chegouuuuuuuuuuuuuuuuuuuuuuuuuuu')
|
print(search_product)
|
||||||
product = search_product
|
if len(search_product) == 0:
|
||||||
products = Product.objects.filter(name__icontains=product)
|
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
|
||||||
return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products,'comanda_id':comanda_id})
|
quantidade=Count('product'),
|
||||||
|
nome=F('product__name') ).order_by('-quantidade'))
|
||||||
|
products = Product.objects.all()
|
||||||
|
products_ordenados = []
|
||||||
|
|
||||||
|
for produto in produtos_mais_vendidos:
|
||||||
|
for p in products:
|
||||||
|
if p.name == produto['nome']:
|
||||||
|
products_ordenados.append(p)
|
||||||
|
|
||||||
|
return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products,'comanda_id':comanda_id})
|
||||||
|
else:
|
||||||
|
product = 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 listProductBalcao(request, comanda_id):
|
# def listProductBalcao(request, comanda_id):
|
||||||
@@ -32,7 +48,6 @@ def addProductBalcao(request, product_id, comanda_id, qtd):
|
|||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
||||||
qtd = int(request.COOKIES.get('qtd'))
|
|
||||||
for i in range(qtd):
|
for i in range(qtd):
|
||||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||||
product_comanda.save()
|
product_comanda.save()
|
||||||
|
|||||||
@@ -58,6 +58,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr hidden >
|
||||||
|
<td hidden id="total">{{total}}</td>
|
||||||
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -144,7 +147,7 @@
|
|||||||
<dialog id="payment-comanda" style="display: none;" >
|
<dialog id="payment-comanda" style="display: none;" >
|
||||||
<article>
|
<article>
|
||||||
<h2>Receber</h2>
|
<h2>Receber</h2>
|
||||||
<h1>R$ {{ total }}</h1>
|
<h1 id="first-total" >R$ {{ total }}</h1>
|
||||||
<p>
|
<p>
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
Binary file not shown.
@@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
<td value={{total}} colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr >
|
||||||
|
<td hidden id="total">{{total}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
// function openModal() {
|
|
||||||
// document.getElementById('Modal-add-product').style.display = 'block';
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// function open_remove_product_comanda() {
|
|
||||||
// document.getElementById('remove-product-comanda').style.display = 'block';
|
|
||||||
// }
|
|
||||||
|
|
||||||
function modal_payment_comanda() {
|
function modal_payment_comanda() {
|
||||||
document.getElementById('payment-comanda').style.display = 'block';
|
document.getElementById('payment-comanda').style.display = 'block';
|
||||||
}
|
}
|
||||||
@@ -15,14 +8,11 @@ function close_modal_payment_comanda() {
|
|||||||
document.getElementById('payment-comanda').style.display = 'none';
|
document.getElementById('payment-comanda').style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
// function closeModal() {
|
// document.cookie = 'qtd=1';
|
||||||
// document.getElementById('Modal-add-product').style.display = 'none';
|
|
||||||
// }
|
|
||||||
document.cookie = 'qtd=1';
|
|
||||||
|
|
||||||
|
|
||||||
function imprimirFichas() {
|
function imprimirFichas() {
|
||||||
const element = document.getElementById("list-products-comanda");
|
const element = document.getElementById("list-products-balcao");
|
||||||
const style = `<style>
|
const style = `<style>
|
||||||
td, th {
|
td, th {
|
||||||
|
|
||||||
@@ -37,11 +27,9 @@ function imprimirFichas() {
|
|||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
var content = element.innerHTML;
|
var content = element.innerHTML;
|
||||||
// console.log(content);
|
|
||||||
content = content.replace(/<button[^>]*>(?:(?!<\/button>)[\s\S])*<\/button>/gi,'');
|
content = content.replace(/<button[^>]*>(?:(?!<\/button>)[\s\S])*<\/button>/gi,'');
|
||||||
content = content.replace(/<th[^>]*>(?:(?!<\/th>)[\s\S])*<\/th>/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+ '<BR>VÁLIDO SOMENTE POR ESSA NOITE'+'</td></tr>');
|
content = content.replace(/<\/tr>/g,'</tr><tr><td colspan="2" style="font-size: 12px">'+dateString+ '<BR>VÁLIDO SOMENTE POR ESSA NOITE'+'</td></tr>');
|
||||||
console.log(content);
|
|
||||||
|
|
||||||
var printWindow = window.open('', '_blank');
|
var printWindow = window.open('', '_blank');
|
||||||
printWindow.document.write('<table>'+content+'</table>'+style);
|
printWindow.document.write('<table>'+content+'</table>'+style);
|
||||||
@@ -54,39 +42,6 @@ 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(){
|
function reloadPage(){
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
location.reload();}, 10);
|
location.reload();}, 10);
|
||||||
@@ -104,21 +59,22 @@ document.onkeydown = teclado
|
|||||||
function teclado(event){
|
function teclado(event){
|
||||||
if (event.keyCode == 13){
|
if (event.keyCode == 13){
|
||||||
addProductBalcao()
|
addProductBalcao()
|
||||||
// reloadPage()
|
|
||||||
}else{
|
}else{
|
||||||
console.log(event.keyCode)
|
console.log('')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateTotal(){
|
||||||
|
const newTotal = document.getElementById('total').innerText
|
||||||
|
document.getElementById('first-total').innerHTML = 'R$ ' + newTotal
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function addProductBalcao() {
|
function addProductBalcao() {
|
||||||
var productId = document.getElementById('0').innerText;
|
var productId = document.getElementById('0').innerText;
|
||||||
var comandaId = document.getElementById('comanda0').innerText;
|
var comandaId = document.getElementById('comanda0').innerText;
|
||||||
var qtd = document.getElementById('qtd-product').value;
|
var qtd = document.getElementById('qtd-product').value;
|
||||||
console.log(productId, comandaId)
|
|
||||||
const url = `/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}/`;
|
const url = `/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}/`;
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -130,6 +86,12 @@ function addProductBalcao() {
|
|||||||
var listProductsBalcaoElement = document.getElementById("list-products-balcao");
|
var listProductsBalcaoElement = document.getElementById("list-products-balcao");
|
||||||
listProductsBalcaoElement.innerHTML = text;
|
listProductsBalcaoElement.innerHTML = text;
|
||||||
})
|
})
|
||||||
|
const receber = document.getElementById('pagarComanda')
|
||||||
|
const imprimir = document.getElementById('imprimirFichas')
|
||||||
|
receber.removeAttribute('disabled');
|
||||||
|
imprimir.removeAttribute('disabled');
|
||||||
|
setTimeout(function() {
|
||||||
|
updateTotal();}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,6 +108,10 @@ function removeProductBalcao(id) {
|
|||||||
var listProductsBalcaoElement = document.getElementById("list-products-balcao");
|
var listProductsBalcaoElement = document.getElementById("list-products-balcao");
|
||||||
listProductsBalcaoElement.innerHTML = text;
|
listProductsBalcaoElement.innerHTML = text;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
updateTotal();}, 100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -156,41 +122,32 @@ document.getElementById('productForm').addEventListener('submit', function(event
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const qtd = document.getElementById('qtd-product');
|
|
||||||
qtd.addEventListener('input', () => {
|
|
||||||
const chave = 'qtd';
|
|
||||||
const valor = qtd.value;
|
|
||||||
document.cookie = chave + '=' + valor;
|
|
||||||
console.log(chave, valor);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function searchProduct() {
|
function searchProduct() {
|
||||||
var search_product = document.getElementById('search-product').value
|
setTimeout(() => {
|
||||||
|
time();
|
||||||
|
}, 100);
|
||||||
|
function time(){
|
||||||
|
var search_product = document.getElementById('search-product').value.trim()
|
||||||
var productListElement = document.getElementById("product-list");
|
var productListElement = document.getElementById("product-list");
|
||||||
if(search_product.length >= 1){
|
if(search_product.length >= 1 ){
|
||||||
fetch(`/balcao/listProductBalcao/13/${search_product}`, {
|
fetch(`/balcao/listProductBalcao/13/${search_product}`, {
|
||||||
method: 'GET',
|
method: 'GET',}
|
||||||
}
|
|
||||||
).then(function(response) {
|
).then(function(response) {
|
||||||
return response.text();
|
return response.text();
|
||||||
}).then(function(text) {
|
}).then(function(text) {
|
||||||
productListElement.innerHTML = text;
|
productListElement.innerHTML = text;
|
||||||
|
|
||||||
})}
|
})}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addProductClick(productId, comandaId) {
|
function addProductClick(productId, comandaId) {
|
||||||
console.log(productId, comandaId)
|
|
||||||
var qtd = document.getElementById('qtd-product').value
|
var qtd = document.getElementById('qtd-product').value
|
||||||
fetch(`/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}`, {
|
fetch(`/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
})
|
})
|
||||||
|
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
return response.text();
|
return response.text();
|
||||||
@@ -199,12 +156,12 @@ function addProductClick(productId, comandaId) {
|
|||||||
listProductsBalcaoElement.innerHTML = text;
|
listProductsBalcaoElement.innerHTML = text;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const receber = document.getElementById('pagarComanda')
|
||||||
|
const imprimir = document.getElementById('imprimirFichas')
|
||||||
|
receber.removeAttribute('disabled');
|
||||||
|
imprimir.removeAttribute('disabled');
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
updateTotal();}, 100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// hx-get="{% url 'listProductBalcao' comanda.id %}"
|
|
||||||
// hx-trigger="keyup"
|
|
||||||
// hx-target="#product-list"
|
|
||||||
|
|
||||||
// hx-get="{% url 'addProductBalcaoTeclado' product.id comanda.id 1 %}" hx-trigger="click" hx-target="#list-products-balcao"
|
|
||||||
Reference in New Issue
Block a user