chore: Delete numerous application modules, templates, static assets, documentation, and build files.

This commit is contained in:
2026-02-25 17:09:27 -03:00
parent 7ddaa2d1f9
commit 2fc4fafed7
562 changed files with 17 additions and 6810 deletions

0
clients/__init__.py Normal file
View File

6
clients/admin.py Normal file
View File

@@ -0,0 +1,6 @@
from django.contrib import admin
from clients.models import Client
admin.site.register(Client)

74
clients/api_views.py Normal file
View File

@@ -0,0 +1,74 @@
from rest_framework import viewsets, permissions, status
from rest_framework.decorators import action
from rest_framework.response import Response
from .models import Client
from .serializers import ClientSerializer
from comandas.models import Comanda, ProductComanda
from comandas.serializers import ComandaSerializer
from payments.models import Payments, somar
from typePay.models import TypePay
class ClientViewSet(viewsets.ModelViewSet):
queryset = Client.objects.all()
serializer_class = ClientSerializer
permission_classes = [permissions.IsAuthenticated]
def get_queryset(self):
return Client.objects.all()
@action(detail=True, methods=['get'])
def fiados(self, request, pk=None):
client = self.get_object()
comandas = Comanda.objects.filter(client=client, status='FIADO')
serializer = ComandaSerializer(comandas, many=True)
return Response(serializer.data)
@action(detail=False, methods=['post'])
def pagar_fiados(self, request):
comanda_ids = request.data.get('ids', [])
if not comanda_ids:
return Response({'error': 'Nenhum ID de comanda fornecido.'}, status=status.HTTP_400_BAD_REQUEST)
results = []
for comanda_id in comanda_ids:
try:
comanda = Comanda.objects.get(id=comanda_id)
# Apenas processar se estiver como FIADO
if comanda.status != 'FIADO':
results.append({'id': comanda_id, 'status': 'erro', 'message': 'Status da comanda não é FIADO.'})
continue
# 1. Fechar a comanda
comanda.status = 'CLOSED'
comanda.save()
# 2. Gerar o pagamento (Inspirado no payDebt original)
try:
type_pay = TypePay.objects.get(id=1) # Assume ID 1 como padrão para recebimento de fiado
except TypePay.DoesNotExist:
type_pay, _ = TypePay.objects.get_or_create(id=1, defaults={'name': 'Dinheiro'})
consumo = ProductComanda.objects.filter(comanda=comanda)
valores = somar(consumo, comanda)
payment = Payments.objects.create(
value=valores['totalSemTaxa'], # Valor que falta pagar
type_pay=type_pay,
comanda=comanda,
client=comanda.client,
description='PAGAMENTO DE FIADO (via API)'
)
results.append({'id': comanda_id, 'status': 'sucesso', 'payment_id': payment.id})
except Comanda.DoesNotExist:
results.append({'id': comanda_id, 'status': 'erro', 'message': 'Comanda não encontrada.'})
except Exception as e:
results.append({'id': comanda_id, 'status': 'erro', 'message': str(e)})
return Response({
'success': True,
'message': f'{len(comanda_ids)} comandas processadas',
'results': results
}, status=status.HTTP_200_OK)

6
clients/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ClientsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'clients'

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.1.4 on 2024-12-10 00:52
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Client',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=255)),
('active', models.BooleanField(default=True)),
('contact', models.CharField(blank=True, max_length=255, null=True)),
],
),
]

View File

@@ -0,0 +1,26 @@
# Generated by Django 5.1.4 on 2025-01-15 23:06
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('clients', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='client',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='client',
name='debt',
field=models.DecimalField(decimal_places=2, default=1, max_digits=10),
preserve_default=False,
),
]

View File

13
clients/models.py Normal file
View File

@@ -0,0 +1,13 @@
from django.db import models
# Create your models here.
class Client(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
debt = models.DecimalField(max_digits=10, decimal_places=2)
created_at = models.DateTimeField(auto_now_add=True)
active = models.BooleanField(default=True)
contact = models.CharField(max_length=255, null=True, blank=True)
def __str__(self) -> str:
return self.name

23
clients/serializers.py Normal file
View File

@@ -0,0 +1,23 @@
from rest_framework import serializers
from .models import Client
from comandas.models import Comanda, ProductComanda
from payments.models import Payments, somar
from decimal import Decimal
class ClientSerializer(serializers.ModelSerializer):
debt = serializers.SerializerMethodField()
class Meta:
model = Client
fields = ['id', 'name', 'created_at', 'active', 'contact', 'debt']
def get_debt(self, obj):
comandas = Comanda.objects.filter(client=obj, status='FIADO')
total_debt = Decimal(0)
for comanda in comandas:
consumo = ProductComanda.objects.filter(comanda=comanda)
valores = somar(consumo, comanda)
total_debt += valores['totalSemTaxa']
return total_debt

View File

@@ -0,0 +1,96 @@
{% extends "base.html" %}
{% load static %}
{% load custom_filter_tag %}
{% block 'title' %}
Clientes
{% endblock %}
{% block 'head' %}
<link rel="stylesheet" href="{% static 'clients/css/clients.css' %}">
{% endblock %}
{% block 'body' %}
<div class="grid-container">
<div class="grid-top">
<button class="btn-primary"
onclick="openModal()" id="openModal">Novo Cliente</button>
</div>
<table id="client-list">
<tr>
<th style="text-align: left;">Cliente</th>
<th style="text-align: left;width: 20%;">Débito</th>
<th class="hide-on-mobile" style="text-align: left;">Contato</th>
<th class="hide-on-mobile" style="text-align: left;width: 20%;">Ações</th>
</tr>
{% for client in clients %}
<tr>
<td ><a id="name-{{client.id}}" href="{% url 'viewClient' client.id %}">{{client.name}}</a></td>
<td id="debt-{{client.id}}" >R$ {{client.id | totalFiado}}</td>
<td class="hide-on-mobile" id="contact-{{client.id}}" >{{client.contact}}</td>
<td hidden id="active-{{client.id}}" >{{client.active}}</td>
<td>
<div class="grid-buttons hide-on-mobile">
<img
src="{% static 'midia/icons/edit.svg' %}"
style=" width: 35px; height: 35px; cursor: pointer;"
onclick="editclient({{client.id}})" >
</img>
<input type="hidden" id="name-{{client.id}}" value="{{ client.name }}">
<input type="hidden" id="contact-{{client.id}}" value="{{ client.contact }}">
</div>
</td>
</tr>
{% endfor %}
</table>
</div>
<dialog id='Modal-create-client' >
<article >
<form action="{% url 'createClient' %}" id="clientForm" method="post" >
{% csrf_token %}
<h2 id="title-window">Cadastro Cliente</h2>
<input type="text" id="clientId" name="clientId" hidden >
<input type="text" id="clientName" name="name" required placeholder="Nome">
<input type="checkbox" id="active" name="active" placeholder="Ativo">Ativo
<input type="text" id="clientContact" name="contact" placeholder="Contato"></input>
<footer class="grid-buttons">
<button class="btn-primary" id="save" type="submit">Salvar</button>
<button class="btn-primary" onclick="closeModal()" type="button" id="edit" hx-post="{% url 'editClient' %}" hx-trigger="click" hx-swap="none" style="width: 100%;">Alterar</button>
<button class="btn-cancel" type="button" onclick="closeModal()" style="background-color:red;">Cancelar</button>
</footer>
</form>
</article>
</dialog>
<script src="{% static 'clients/js/clients.js' %}"></script>
{% endblock %}

View File

@@ -0,0 +1,70 @@
{% extends "base.html" %}
{% load static %}
{% load custom_filter_tag %}
{% block 'title' %}
Comandas
{% endblock %}
{% block 'head' %}
<link rel="stylesheet" href="{% static 'comandas/css/comandas.css' %}">
{% endblock %}
{% block 'body' %}
<body>
<div style="justify-self: center;">
<h4>{{client.name}}</h4>
<h4>R$ {{client.id | totalFiado}}</h4><br>
<!-- <h4 id="total-selecionado">R$</h4> -->
<button id="btn-fechar-comandas" class="btn-fechar" onclick="enviarComandasSelecionadas()">
Receber
</button>
</div>
<div class=" ">
<table>
<tr>
<th style="text-align: left;"><b>Nome</b></th>
<th style="text-align: left;"><b>Atendente</b></th>
<th style="text-align: left;"><b>Data abertura</b></th>
<th style="text-align: left;"><b>Data fechamento</b></th>
<th style="text-align: left;"><b><input id="selectAll" name="selectAll" type="checkbox"></b></th>
<th style="text-align: left;"><b>Detalhes</b></th>
<th style="text-align: left;"><b>Valor</b></th>
</tr>
{% for comanda in comandas %}
<tr>
<td>{{comanda.name}}</td>
<td>{{comanda.user.first_name}} {{comanda.user.last_name}}</td>
<td>{{comanda.dt_open}}</td>
<td>{{comanda.dt_close}}</td>
<td><input id="{{comanda.id}}" name="{{comanda.id}}" type="checkbox"></td>
<td>
<span data-tooltip="Visualizar Comanda" data-flow="top">
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">
<img
src="{% static 'midia/icons/view.svg' %}"
style="height: 35px; cursor: pointer;">
</img>
</a>
</span>
</td>
<td>
{{ comanda.id | total }}
</td>
</tr>
{% endfor %}
</table>
</div>
</body>
<script src="{% static 'comandas/js/comandas.js' %}"></script>
<script src="{% static 'clients/js/clients.js' %}"></script>
{% endblock %}

3
clients/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

14
clients/urls.py Normal file
View File

@@ -0,0 +1,14 @@
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.clients, name='clients'),
path('createClient', views.createClient, name='createClient'),
path('editClient', views.editClient, name='editClient'),
path('payDebt', views.payDebt, name='payDebt'),
path('viewClient/<int:clientId>', views.viewClient, name='viewClient'),
]

109
clients/views.py Normal file
View File

@@ -0,0 +1,109 @@
from decimal import Decimal
from django.shortcuts import render, redirect
from django.contrib.auth.models import User
from django.http import JsonResponse
from django.views.decorators.http import require_POST
from django.views.decorators.csrf import csrf_exempt
import json
from comandas.models import Comanda, ProductComanda
from gestaoRaul.decorators import group_required
from clients.models import Client
from payments.models import Payments, somar
from typePay.models import TypePay
# Create your views here.
@group_required(groupName='Gerente')
def clients(request):
clients = Client.objects.all()
return render(request, 'clients.html', {'clients': clients})
def viewClient(request,clientId):
# config = {
# 'taxa': False
# }
client = Client.objects.get(id=int(clientId))
comandas = Comanda.objects.filter(client = client).filter(status = 'FIADO')
total = Decimal(0)
# for comanda in comandas:
# totalConsumo = 0
# totalParcial = 0
# consumo = ProductComanda.objects.filter(comanda=comanda)
# parcial = Payments.objects.filter(comanda=comanda)
# for p in parcial:
# totalParcial += p.value
# for produto in consumo:
# totalConsumo += produto.product.price
# total+= (totalConsumo - totalParcial)
# total = total + round(total * Decimal(0.1), 2) if config['taxa'] else total
return render(request, 'viewclient.html', {'client': client, 'comandas': comandas})
@group_required(groupName='Gerente')
def createClient(request):
name = request.POST.get('name')
contact = request.POST.get('contact')
active = True if request.POST.get('active') else False
# debt = request.POST.get('debt')
client = Client(name=name, contact=contact,debt=0, active=active)
client.save()
return redirect('/clients')
@group_required(groupName='Gerente')
def editClient(request):
client_id = int(request.POST.get('clientId'))
client = Client.objects.get(id=client_id)
client.name = request.POST.get('name')
client.contact = request.POST.get('contact')
client.active = True if request.POST.get('active') else False
# client = Client(name=name, contact=contact,debt=0, active=active)
client.save()
return redirect('/clients')
@csrf_exempt
@require_POST
def payDebt(request):
try:
# Verifica se é uma requisição AJAX
if not request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return JsonResponse({'error': 'Requisição inválida'}, status=400)
# Obter os IDs do corpo da requisição (não mais da URL)
try:
data = json.loads(request.body)
comanda_ids = data.get('ids', [])
except json.JSONDecodeError:
return JsonResponse({'error': 'JSON inválido'}, status=400)
for comanda_id in comanda_ids:
try:
comanda = Comanda.objects.get(id=comanda_id)
comanda.status = 'CLOSED'
comanda.save()
typePayment = TypePay.objects.get(id=1)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
value = somar(consumo,comanda)
description = 'PAGAMENTO DE FIADO'
pagamento = Payments(value=value["totalSemTaxa"], comanda=comanda, type_pay=typePayment,description=description,client=comanda.client)
pagamento.save()
except Comanda.DoesNotExist:
return JsonResponse({'error': f'Comanda com ID {comanda_id} não encontrada'}, status=404)
return JsonResponse({
'success': True,
'message': f'{len(comanda_ids)} comandas processadas',
'ids': comanda_ids
}, status=200)
except Exception as e:
return JsonResponse({
'success': False,
'error': str(e)
}, status=500)