Modif turbo / requète sql ClientController -> ReductionsType, ajout de CSS

This commit is contained in:
Joshua 2025-04-08 10:47:20 +02:00
parent 01f23682b3
commit 7665fd4817
12 changed files with 659 additions and 557 deletions

View File

@ -40,7 +40,7 @@
"symfony/translation": "7.1.*",
"symfony/twig-bundle": "7.1.*",
"symfony/ux-icons": "^2.24",
"symfony/ux-turbo": "^2.20",
"symfony/ux-turbo": "^2.24",
"symfony/validator": "7.1.*",
"symfony/web-link": "7.1.*",
"symfony/yaml": "7.1.*",

1055
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -79,3 +79,13 @@ table td[colspan="6"] {
font-weight: bold;
margin-top: 25px;
}
.case-verte {
background-color: #d4edda; /* vert clair */
color: #155724; /* texte vert foncé */
}
.case-rouge {
background-color: #f8d7da; /* rouge clair */
color: #721c24; /* texte rouge foncé */
}

View File

@ -8,6 +8,7 @@ use App\Entity\Clients;
use App\Entity\Reductions;
use App\Form\ClientsType;
use App\Repository\ClientsRepository;
use App\Repository\ReductionsRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@ -17,6 +18,11 @@ use Symfony\Component\Routing\Annotation\Route;
#[Route('/clients')]
final class ClientsController extends AbstractController
{
public function __construct(private ReductionsRepository $reductionsRepository,)
{
}
#[Route(name: 'app_clients_index', methods: ['GET'])]
public function index(ClientsRepository $clientsRepository): Response
{
@ -95,17 +101,7 @@ final class ClientsController extends AbstractController
$montantTotal = $client->getTotalDepense();
$entityManager->persist($client);
$reductions = $entityManager->getRepository(Reductions::class)
->createQueryBuilder('r')
->where('r.montant_min <= :montantTotal')
->andWhere('r.actif = :actif')
->andWhere('r.DateDebut <= :currentDate')
->andWhere('r.DateFin >= :currentDate')
->setParameter('montantTotal', $montantTotal)
->setParameter('actif', true)
->setParameter('currentDate', new \DateTime())
->getQuery()
->getResult();
$reductions = $this->reductionsRepository->findApplicableReductions($montantTotal);
$newReduction = new Reductions();

View File

@ -15,8 +15,9 @@ use Symfony\Component\Routing\Attribute\Route;
final class TablesController extends AbstractController
{
#[Route(name: 'app_tables_index', methods: ['GET'])]
public function index(TablesRepository $tablesRepository): Response
public function index(TablesRepository $tablesRepository, Request $request): Response
{
dump($request);
return $this->render('tables/index.html.twig', [
'tables' => $tablesRepository->findAll(),
]);

View File

@ -20,12 +20,6 @@ class ClientsType extends AbstractType
->add('Nom')
->add('Email')
->add('Telephone')
->add('Tables', EntityType::class, [
'class' => Tables::class,
'choice_label' => 'id',
'multiple' => true,
'expanded' => true,
])
->add('totalDepense')
;
}

View File

@ -7,6 +7,7 @@ use App\Entity\Reductions;
use http\Client;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -15,7 +16,8 @@ class ReductionsType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('Taux')
->add('Pourcentage')
->add('MontantMin')
->add('DateDebut', null, [
'widget' => 'single_text',
])
@ -28,6 +30,10 @@ class ReductionsType extends AbstractType
'multiple' => false,
'expanded' => true,
])
->add('actif', HiddenType::class,[
'empty_data' => true,
])
;
}

View File

@ -40,4 +40,20 @@ class ReductionsRepository extends ServiceEntityRepository
// ->getOneOrNullResult()
// ;
// }
public function findApplicableReductions(float $montantTotal): array
{
$qb = $this->createQueryBuilder('r');
return $qb
->where('r.montant_min <= :montantTotal')
->andWhere('r.actif = :actif')
->andWhere('r.DateDebut <= :currentDate')
->andWhere('r.DateFin >= :currentDate')
->setParameter('montantTotal', $montantTotal)
->setParameter('actif', true)
->setParameter('currentDate', new \DateTime())
->getQuery()
->getResult();
}
}

View File

@ -1,4 +1,4 @@
<form method="post" action="{{ path('app_reductions_delete', {'id': reduction.id}) }}" onsubmit="return confirm('Es-tu sur de vouloir le supprimer ?');">
●●●●●●●<form method="post" action="{{ path('app_reductions_delete', {'id': reduction.id}) }}" onsubmit="return confirm('Es-tu sur de vouloir le supprimer ?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ reduction.id) }}">
<button class="btn">Supprimer</button>
</form>

View File

@ -32,6 +32,7 @@
<th>DateDebut</th>
<th>DateFin</th>
<th>Client</th>
<th>Actif</th>
<th>actions</th>
</tr>
</thead>
@ -44,6 +45,9 @@
<td>{{ reduction.DateDebut ? reduction.DateDebut|date('d/m/Y H:i:s') : 'Non spécifié' }}</td>
<td>{{ reduction.DateFin ? reduction.DateFin|date('d/m/Y H:i:s') : 'Non spécifié' }}</td>
<td>{{ reduction.client.nom }}</td>
<td class="{{ reduction.actif ? 'case-verte' : 'case-rouge' }}">
{{ reduction.actif ? 'Oui' : 'Non' }}
</td>
<td>
<form method="post" action="{{ path('app_reductions_delete', {'id': reduction.id}) }}" onsubmit="return confirm('Êtes-vous sûr de vouloir supprimer cette réduction ?'); ">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ reduction.id) }}">
@ -58,6 +62,9 @@
{% endfor %}
</tbody>
</table>
<a href="{{ path('app_reductions_new') }}" class="add-menu">Créer une réduction</a>
</div>
{% endblock %}

View File

@ -33,47 +33,7 @@
</tr>
</thead>
<tbody>
{% for table in tables %}
<tr>
<td>{{ table.id }}</td>
<td>
{% for client in table.Clients %}
{{ client.nom }}{% if not loop.last %}, {% endif %}
{% else %}
Aucun
{% endfor %}
</td>
<td>
{% for utilisateur in table.utilisateurs %}
{{ utilisateur.nom }}{% if not loop.last %}, {% endif %}
{% else %}
Aucun
{% endfor %}
</td>
<td>
<form method="POST" action="{{ path('app_tables_update_statut', {'id': table.id}) }}">
<input type="checkbox" name="libre" value="1" {% if table.libre %}checked{% endif %}>
<button type="submit">Mettre à jour</button>
</form>
</td>
<td>
<a href="{{ path('app_tables_edit', {'id': table.id}) }}">Modifier</a>
<form method="post" action="{{ path('app_tables_delete', {'id': table.id}) }}" onsubmit="return confirm('Es-tu sûr de vouloir le supprimer ?');" style="display:inline;">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ table.id) }}">
<button type="submit">Supprimer</button>
</form>
</td>
</tr>
{% else %}
<tr>
<td colspan="5">Aucun enregistrement trouvé</td>
</tr>
{% endfor %}
{% include 'tables/page_list_tables.html.twig' %}
</tbody>
</table>

View File

@ -0,0 +1,43 @@
<turbo-frame id="tables">
{% for table in tables %}
<tr>
<td>{{ table.id }}</td>
<td>
{% for client in table.Clients %}
{{ client.nom }}{% if not loop.last %}, {% endif %}
{% else %}
Aucun
{% endfor %}
</td>
<td>
{% for utilisateur in table.utilisateurs %}
{{ utilisateur.nom }}{% if not loop.last %}, {% endif %}
{% else %}
Aucun
{% endfor %}
</td>
<td>
<form method="POST" action="{{ path('app_tables_update_statut', {'id': table.id}) }}">
<input type="checkbox" name="libre" value="1" data-turbo-frame="tables" {% if table.libre %}checked{% endif %}>
<button type="submit">Mettre à jour</button>
</form>
</td>
<td>
<a href="{{ path('app_tables_edit', {'id': table.id}) }}">Modifier</a>
<form method="post" action="{{ path('app_tables_delete', {'id': table.id}) }}" onsubmit="return confirm('Es-tu sûr de vouloir le supprimer ?');" style="display:inline;">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ table.id) }}">
<button type="submit">Supprimer</button>
</form>
</td>
</tr>
{% else %}
<tr>
<td colspan="5">Aucun enregistrement trouvé</td>
</tr>
{% endfor %}
</turbo-frame>