mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: add obs order
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,4 @@
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
@@ -17,11 +18,13 @@ def listProduct(request, comanda_id):
|
||||
return render(request, "htmx_components/htmx_list_products.html", {"products": products,'comanda_id':comanda_id})
|
||||
|
||||
def addProduct(request, product_id, comanda_id):
|
||||
obs = request.GET.get("obs")
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
product = Product.objects.get(id=product_id)
|
||||
comanda = Comanda.objects.get(id=comanda_id)
|
||||
print(product.cuisine)
|
||||
|
||||
if product.cuisine == True:
|
||||
order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='')
|
||||
order.save()
|
||||
@@ -31,6 +34,13 @@ def addProduct(request, product_id, comanda_id):
|
||||
total += produto.product.price
|
||||
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
|
||||
|
||||
def editOrders(request, productComanda_id, obs):
|
||||
order = Order.objects.get(productComanda=productComanda_id)
|
||||
print(obs)
|
||||
order.obs = obs
|
||||
order.save()
|
||||
return JsonResponse({'status': 'ok'})
|
||||
|
||||
|
||||
def removeProductComanda(request, productComanda_id):
|
||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||
|
||||
@@ -17,6 +17,7 @@ Detalhes {{comanda.name}}
|
||||
{% block 'body' %}
|
||||
|
||||
<body>
|
||||
<input hidden id="id-temp" type="number">
|
||||
<div class="grid-container" >
|
||||
<div>
|
||||
<button class="primary" id="openModal" onclick="openModal()"
|
||||
@@ -73,11 +74,24 @@ Detalhes {{comanda.name}}
|
||||
{% for item in consumo%}
|
||||
|
||||
<tr>
|
||||
<td>{{item.product.name}}</td>
|
||||
<td>
|
||||
{{item.product.name}}
|
||||
|
||||
{% if item.product.cuisine == True %}
|
||||
<img
|
||||
onclick="openModalObs({{item.id}})"
|
||||
src="{% static 'midia/icons/edit.svg' %}"
|
||||
style="width: 35px; height: 35px; cursor: pointer;">
|
||||
</img>
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
<td>R$ {{item.product.price}}</td>
|
||||
{% if comanda.status != 'OPEN'%}
|
||||
{% else %}
|
||||
<td>
|
||||
|
||||
|
||||
<img
|
||||
src="{% static 'midia/icons/delete.svg' %}"
|
||||
style="width: 35px; height: 35px; cursor: pointer;"
|
||||
@@ -112,7 +126,7 @@ Detalhes {{comanda.name}}
|
||||
<div id="product-list" class="grid-list-products">
|
||||
{% for product in products %}
|
||||
|
||||
<article onclick="addProductComanda({{product.id}})" style="background-color: #293552;" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda">
|
||||
<article onclick="addProductComanda({{product.id}}, {{comanda.id}}, '{{product.cuisine}}')" style="background-color: #293552;" >
|
||||
{{product.name}} <br>
|
||||
R$ {{product.price}}
|
||||
</article >
|
||||
@@ -122,16 +136,19 @@ Detalhes {{comanda.name}}
|
||||
</article>
|
||||
</dialog>
|
||||
|
||||
<dialog id="modal-obs" style="display: none;">
|
||||
<textarea name="obs" id="obs"></textarea>
|
||||
<button onclick="addOrder()" >OK</button>
|
||||
<button onclick="closeModalObs()" >Cancela</button>
|
||||
</dialog>
|
||||
|
||||
|
||||
|
||||
<dialog id="payment-comanda" style="display: none;" >
|
||||
<article>
|
||||
<h2>Pagamento</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()">
|
||||
Receber
|
||||
|
||||
@@ -19,6 +19,7 @@ htmx_urlpatterns = [
|
||||
path('listProduct/<int:comanda_id>/', htmx_views.listProduct, name='listProduct'),
|
||||
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
|
||||
path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'),
|
||||
path('editOrders/<int:productComanda_id>/<str:obs>', htmx_views.editOrders, name='editOrders'),
|
||||
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'),
|
||||
|
||||
Binary file not shown.
@@ -9,7 +9,18 @@
|
||||
{% for item in consumo%}
|
||||
|
||||
<tr>
|
||||
<td>{{item.product.name}}</td>
|
||||
<td>
|
||||
{{item.product.name}}
|
||||
{% if item.product.cuisine == True %}
|
||||
<img
|
||||
onclick="openModalObs({{item.id}})"
|
||||
src="{% static 'midia/icons/edit.svg' %}"
|
||||
style="width: 35px; height: 35px; cursor: pointer;">
|
||||
</img>
|
||||
{% endif %}
|
||||
|
||||
|
||||
</td>
|
||||
<td>R$ {{item.product.price}}</td>
|
||||
<td>
|
||||
<img
|
||||
|
||||
@@ -2,9 +2,14 @@
|
||||
|
||||
function openModal() {
|
||||
document.getElementById('Modal-add-product').style.display = 'block';
|
||||
// document.getElementById('Modal-add-product').setAttribute();
|
||||
}
|
||||
|
||||
function openModalObs(id) {
|
||||
document.getElementById('modal-obs').style.display = 'block';
|
||||
idd = document.getElementById('id-temp').value = id;
|
||||
obs = document.getElementById('obs').value;
|
||||
console.log(id);
|
||||
console.log(obs);
|
||||
}
|
||||
|
||||
|
||||
function modal_payment_comanda() {
|
||||
@@ -18,6 +23,9 @@ function close_modal_payment_comanda() {
|
||||
function closeModal() {
|
||||
document.getElementById('Modal-add-product').style.display = 'none';
|
||||
}
|
||||
function closeModalObs() {
|
||||
document.getElementById('modal-obs').style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -111,17 +119,61 @@ function backPage() {
|
||||
// }
|
||||
|
||||
// }
|
||||
function addOrder(){
|
||||
obs = document.getElementById('obs').value
|
||||
var id = document.getElementById('id-temp').value
|
||||
fetch(`/comandas/editOrders/${id}/${obs}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'}
|
||||
})
|
||||
|
||||
.then(function(response) {
|
||||
if(response.status == 200){
|
||||
closeModalObs()
|
||||
alert('Pedido atualizado com sucesso!')
|
||||
}else{
|
||||
alert('Erro ao atualizar pedido!')
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
function addProductComanda(productId,comandaId, cuisine) {
|
||||
obs = document.getElementById('obs');
|
||||
console.log(obs.value);
|
||||
console.log(cuisine);
|
||||
if(cuisine == 'ggg'){
|
||||
var obs = openModalObs();
|
||||
|
||||
}else{
|
||||
|
||||
function addProductComanda(productId) {
|
||||
fetch(`/comandas/addProduct${productId}/${comandaId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'}
|
||||
})
|
||||
|
||||
.then(function(response) {
|
||||
return response.text();
|
||||
}).then(function(text) {
|
||||
console.log(text);
|
||||
var listProductsBalcaoElement = document.getElementById("list-products-comanda");
|
||||
listProductsBalcaoElement.innerHTML = text;
|
||||
})
|
||||
|
||||
// const receber = document.getElementById('pagarComanda')
|
||||
// const imprimir = document.getElementById('imprimirFichas')
|
||||
// var search = document.getElementById('search-product')
|
||||
|
||||
// setTimeout(function() {
|
||||
// updateTotal();}, 100);
|
||||
|
||||
alert('Produto adicionado com sucesso!');
|
||||
// const productName = document.getElementById('productName').value;
|
||||
// const productPrice = document.getElementById('productPrice').value;
|
||||
// const productDescription = document.getElementById('productDescription').value;
|
||||
// const productqtd = document.getElementById('productqtd').value;
|
||||
// const categorie = document.getElementById('select-categorie').value;
|
||||
// const url = `/comandas/addProductComanda/${productName}/${productPrice}/${productDescription}/${productqtd}/${categorie}/`;
|
||||
// window.location.href = url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -133,4 +185,4 @@ function addProductComanda(productId) {
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda"
|
||||
Reference in New Issue
Block a user