feat: page clients and create client

This commit is contained in:
2025-01-15 20:48:35 -03:00
parent dc21858b9a
commit 15af99f765
22 changed files with 319 additions and 9 deletions

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

@@ -4,5 +4,10 @@ from django.db import models
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)
contact = models.CharField(max_length=255, null=True, blank=True)
def __str__(self) -> str:
return self.name

View File

@@ -1,12 +1,104 @@
{% extends "base.html" %}
{% load static %}
{% block 'title' %}
Type Pay
Clientes
{% endblock %}
{% block 'body' %}
Body Type Pay
<div class="grid-container">
<div class="grid-top">
<button style="
width: 30%;
margin: 5px 10px 20px 10px;"
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 style="text-align: left;width: 20%;">Ações</th>
</tr>
{% for client in clients %}
<tr>
<td id="name-{{client.id}}" >{{client.name}}</td>
<td id="debt-{{client.id}}" >R$ {{client.debt}}</td>
<td class="hide-on-mobile" id="contact-{{client.id}}" >{{client.contact}}</td>
<td>
<div class="grid-buttons">
<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 }}">
<form hx-post="{% url 'payDebt' %}" hx-trigger="click" hx-target="#client-list">
{% csrf_token %}
<input type="hidden" name="id-client" id="id-{{client.id}}" value="{{ client.id }}">
<button style="background-color: rgba(255, 0, 0, 0); padding: 0px;">
<img
src="{% static 'midia/icons/toggle-on.svg' %}"
style=" width: 35px; height: 35px; cursor: pointer;"
>
</img>
</button>
</form>
</div>
</td>
</tr>
{% endfor %}
</table>
</div>
<dialog id='Modal-create-client' >
<article >
<form action="{% url 'createClient' %}" id="clientForm" method="post" >
{% csrf_token %}
<h2>Cadastro Cliente</h2>
<input type="text" id="clientId" name="clientId" hidden >
<input type="text" id="clientName" name="name" required placeholder="Nome">
<input type="number" step="0.01" id="clientDebt" name="debt" required placeholder="Débito">
<input type="checkbox" id="active" name="active" placeholder="Ativo">Ativo
<input type="text" id="clientDescription" name="contact" placeholder="Contato"></input>
<footer class="grid-buttons">
<button id="save" type="submit">Salvar</button>
<button onclick="closeModal()" type="button" id="edit" hx-post="{% url 'createClient' %}" hx-trigger="click" hx-target="#client-list" >Alterar</button>
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
</footer>
</form>
</article>
</dialog>
<script src="{% static 'clients/js/clients.js' %}"></script>
{% endblock %}

View File

@@ -4,6 +4,8 @@ from . import views
urlpatterns = [
path('', views.clients, name='clients'),
path('createClient', views.createClient, name='createClient'),
path('payDebt', views.payDebt, name='payDebt'),

View File

@@ -1,8 +1,31 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.contrib.auth.models import User
from gestaoRaul.decorators import group_required
from clients.models import Client
@group_required(groupName='Gerente')
def clients(request):
return render(request, 'clients.html')
clients = Client.objects.all()
return render(request, 'clients.html', {'clients': clients})
@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')
def payDebt(request):
# id = request.POST.get('id-client')
# client_id = int(id)
# client = Client.objects.get(id=client_id)
# client.debt = client.debt - 1
# client.save()
return redirect('/clients')