Skip to content

Commit

Permalink
Modification des contrôleurs liés aux utilisateurs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tendry-Rkt56 committed Jul 22, 2024
1 parent 4c20710 commit 57e2551
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public function admin()
$medicaments = $this->entity->getRepository(Medicament::class)->medicamentNumber();
$categories = $this->entity->getRepository(Category::class)->categoryNumber();
$users = $this->entity->getRepository(User::class)->userNumber();
$total = $this->entity->getRepository(Vente::class)->getSomme();
$lastVentes = $this->entity->getRepository(Vente::class)->getSomme();
$total = 0;
foreach($lastVentes as $vente) {
$total += $vente['total'];
}
$ventes = $this->entity->getRepository(Vente::class)->getLastVente();
return $this->render('admin/home.html.twig', [
'medicaments' => $medicaments,
Expand All @@ -44,7 +48,11 @@ public function user()
$medicaments = $this->entity->getRepository(Medicament::class)->medicamentNumber();
$categories = $this->entity->getRepository(Category::class)->categoryNumber();
$users = $this->entity->getRepository(User::class)->userNumber();
$total = $this->entity->getRepository(Vente::class)->getSomme();
$lastVentes = $this->entity->getRepository(Vente::class)->getSomme();
$total = 0;
foreach($lastVentes as $vente) {
$total += $vente['total'];
}
$ventes = $this->entity->getRepository(Vente::class)->getLastVente();
return $this->render('users/home.html.twig', [
'medicaments' => $medicaments,
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Users/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

#[Route('/users', name: 'users.')]
#[IsGranted('ROLE_USER')]
class UsersController extends AbstractController
{

Expand Down
10 changes: 9 additions & 1 deletion src/Controller/Users/VenteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

#[Route('/users/vente', name: 'users.ventes.')]
#[IsGranted('ROLE_USER')]
class VenteController extends AbstractController
{

Expand All @@ -34,7 +36,12 @@ private function arranegData(array $data = [])
foreach($data as $key => $value) {
if (str_contains($key, 'medicament')) {
(int)$id = substr($key, strlen('medicament-'));
$ids[$id] = (int)$value;
if (isset($ids[$id])) {
$ids[$id] = $ids[$id] + $value;
}
else {
$ids[$id] = (int)$value;
}
}
}
return $ids;
Expand All @@ -56,6 +63,7 @@ private function getTotal(array $data = [])
public function store(Request $request, EventDispatcherInterface $dispatcher): Response
{
$data = $this->arranegData($request->request->all());
dd($data);
$total = $this->getTotal($data);
$vente = new Vente();
$vente->setTotal($total)
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Medicament.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Medicament
private ?string $nom = null;

#[ORM\Column]
#[Groups(['medicament.index'])]
#[Groups(['medicament.index'])]
private ?float $prix = null;

#[ORM\Column]
Expand Down
9 changes: 8 additions & 1 deletion src/EventListener/VenteDeleteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
namespace App\EventListener;

use App\Event\VenteDeleteEvent;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

final class VenteDeleteListener
{

public function __construct(private EntityManagerInterface $entity)
{

}

#[AsEventListener(event: VenteDeleteEvent::class)]
public function onVenteDeleteEvent(VenteDeleteEvent $event): void
{
// ...

}
}
12 changes: 10 additions & 2 deletions src/Repository/VenteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, Vente::class);
}

public function getSommes ()
{
$conn = $this->getEntityManager()->getConnection();
$sql = "SELECT SUM(total) FROM (SELECT total FROM vente ORDER BY id DESC LIMIT 5)";
$result = $conn->prepare($sql);
return $result->executeQuery();
}

public function getSomme()
{
return $this->createQueryBuilder("v")
->select("SUM(v.total)")
->select("v.total")
->orderBy("v.id", "DESC")
->setMaxResults(5)
->getQuery()
->getSingleScalarResult();
->getResult();
}

public function getLastVente()
Expand Down
1 change: 0 additions & 1 deletion templates/users/category/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<div class="container flex-column d-flex align-items-center justify-content-between gap-4 mb-5">
<div class="container d-flex align-items-center justify-content-between flex-row">
<h2 class="align-self-start" style="letter-spacing:2px">Les <span style="border-bottom:2px solid rgb(9,181, 9);">cat</span>égories</h2>
<a href="{{path('admin.category.create')}}" class="btn btn-secondary btn-sm">Nouveau</a>
</div>
<form action="" class="gap-2 align-self-start d-flex align-items-center justify-content-center flex-row">
<input id="limit" type="number" class="form-control" value="{{ limit }}" name="limit">
Expand Down

0 comments on commit 57e2551

Please sign in to comment.