mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feedback pagamento de multiplas comandas
This commit is contained in:
Binary file not shown.
@@ -17,10 +17,10 @@ Comandas
|
||||
<div style="justify-self: center;">
|
||||
<h4>{{client.name}}</h4>
|
||||
<h4>R$ {{client.id | totalFiado}}</h4><br>
|
||||
<h4 id="total-selecionado">R$</h4>
|
||||
<!-- <h4 id="total-selecionado">R$</h4> -->
|
||||
<button id="btn-fechar-comandas" class="btn-fechar" onclick="enviarComandasSelecionadas()">
|
||||
<span class="icon">✓</span>
|
||||
Fechar Comandas Selecionadas
|
||||
|
||||
Receber
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -96,13 +96,13 @@ def payDebt(request):
|
||||
except Comanda.DoesNotExist:
|
||||
return JsonResponse({'error': f'Comanda com ID {comanda_id} não encontrada'}, status=404)
|
||||
|
||||
return redirect(f'/clients/viewClient/{comanda.client.id}')
|
||||
# return redirect(f'/clients/viewClient/{comanda.client.id}')
|
||||
|
||||
# return JsonResponse({
|
||||
# 'success': True,
|
||||
# 'message': f'{len(comanda_ids)} comandas processadas',
|
||||
# 'ids': comanda_ids
|
||||
# }, status=200)
|
||||
return JsonResponse({
|
||||
'success': True,
|
||||
'message': f'{len(comanda_ids)} comandas processadas',
|
||||
'ids': comanda_ids
|
||||
}, status=200)
|
||||
|
||||
except Exception as e:
|
||||
return JsonResponse({
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -156,6 +156,8 @@
|
||||
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -174,4 +174,16 @@ function openFullscreen() {
|
||||
setTimeout(() => {
|
||||
toast.classList.remove('show');
|
||||
}, duration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function feedback(message, status, subMessage) {
|
||||
var feedbackMsg = Swal.fire({
|
||||
title: message,
|
||||
text: subMessage || '',
|
||||
icon: status,
|
||||
background: 'rgba(8, 9, 10, 0.75)',
|
||||
confirmButtonColor: 'linear-gradient(145deg, #1E2A3B, #2C3E50)',
|
||||
});
|
||||
return feedbackMsg;
|
||||
}
|
||||
@@ -57,6 +57,8 @@ function editclient(id) {
|
||||
|
||||
|
||||
function calcularTotalSelecionado() {
|
||||
const btn = document.getElementById('btn-fechar-comandas');
|
||||
|
||||
let total = 0;
|
||||
// Seleciona todos os checkboxes marcados (exceto o "selectAll")
|
||||
const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked:not(#selectAll)');
|
||||
@@ -79,12 +81,10 @@ function calcularTotalSelecionado() {
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log(total)
|
||||
|
||||
// Exibe o total na tela (você pode ajustar onde mostrar)
|
||||
const totalElement = document.getElementById('total-selecionado');
|
||||
if (totalElement) {
|
||||
totalElement.textContent = total.toLocaleString('pt-BR', {style: 'currency', currency: 'BRL'});
|
||||
// Exibe o total no botão de receber
|
||||
if (btn) {
|
||||
btn.innerHTML = 'Receber '+total.toLocaleString('pt-BR', {style: 'currency', currency: 'BRL'});
|
||||
} else {
|
||||
// Cria um elemento para mostrar o total se não existir
|
||||
const display = document.createElement('div');
|
||||
@@ -141,9 +141,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
|
||||
|
||||
|
||||
async function enviarComandasSelecionadas() {
|
||||
const btn = document.getElementById('btn-fechar-comandas');
|
||||
const feedback = document.getElementById('api-feedback');
|
||||
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<span class="icon">⏳</span> Processando...';
|
||||
@@ -160,8 +160,8 @@ async function enviarComandasSelecionadas() {
|
||||
});
|
||||
|
||||
if (ids.length === 0) {
|
||||
feedback.textContent = 'Nenhuma comanda válida selecionada.';
|
||||
feedback.className = 'feedback-message error';
|
||||
feedback('Nenhuma comanda selecionada.', 'error', 'Selecione uma comanda e tente novamente.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -188,8 +188,8 @@ async function enviarComandasSelecionadas() {
|
||||
throw new Error(data.error || `Erro HTTP: ${response.status}`);
|
||||
}
|
||||
|
||||
feedback.textContent = data.message || `${ids.length} comandas processadas com sucesso!`;
|
||||
feedback.className = 'feedback-message success';
|
||||
feedback(`${ids.length} comandas pagas com sucesso!`, 'success');
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
@@ -197,15 +197,14 @@ async function enviarComandasSelecionadas() {
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erro:', error);
|
||||
feedback.textContent = error.message || 'Erro ao processar comandas. Verifique o console para mais detalhes.';
|
||||
feedback.className = 'feedback-message error';
|
||||
feedback('Erro', 'error', error);
|
||||
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<span class="icon">✓</span> Fechar Comandas Selecionadas';
|
||||
btn.innerHTML = 'Receber';
|
||||
}
|
||||
}
|
||||
|
||||
// Função auxiliar para pegar o token CSRF
|
||||
function getCookie(name) {
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
@@ -221,5 +220,3 @@ function getCookie(name) {
|
||||
return cookieValue;
|
||||
}
|
||||
|
||||
// Exemplo de como chamar a função (pode ser vinculada a um botão)
|
||||
// document.getElementById('btn-fechar-comandas').addEventListener('click', enviarComandasSelecionadas);
|
||||
Reference in New Issue
Block a user