From 52f5eece177346b464b6f1e432687fad4a1a5084 Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Fri, 16 Jan 2026 11:43:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(crm/customer):=20Ajoute=20la?= =?UTF-8?q?=20gestion=20des=20clients=20=20(list=20only)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/Version20260116103812.php | 32 ++++ src/Controller/Dashboard/BackupController.php | 1 + .../Dashboard/CustomerController.php | 73 +++++++++ src/Entity/Customer.php | 125 +++++++++++++++ src/Repository/CustomerRepository.php | 43 +++++ templates/dashboard/base.twig | 2 +- templates/dashboard/customer.twig | 150 ++++++++++++++++++ 7 files changed, 425 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20260116103812.php create mode 100644 src/Controller/Dashboard/CustomerController.php create mode 100644 src/Entity/Customer.php create mode 100644 src/Repository/CustomerRepository.php create mode 100644 templates/dashboard/customer.twig diff --git a/migrations/Version20260116103812.php b/migrations/Version20260116103812.php new file mode 100644 index 0000000..b78745f --- /dev/null +++ b/migrations/Version20260116103812.php @@ -0,0 +1,32 @@ +addSql('CREATE TABLE customer (id SERIAL NOT NULL, civ VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, surname VARCHAR(255) NOT NULL, phone VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, siret VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('DROP TABLE customer'); + } +} diff --git a/src/Controller/Dashboard/BackupController.php b/src/Controller/Dashboard/BackupController.php index d8e3e57..64f1b8b 100644 --- a/src/Controller/Dashboard/BackupController.php +++ b/src/Controller/Dashboard/BackupController.php @@ -22,6 +22,7 @@ class BackupController extends AbstractController #[Route(path: '/crm/sauvegarde', name: 'app_crm_backup', methods: ['GET'])] public function crmSauvegarde(BackupRepository $backupRepository): Response { + $this->appLogger->record('VIEW', 'Consultation de la liste des sauvegardes système'); return $this->render('dashboard/backup.twig', [ 'backups' => $backupRepository->findBy([], ['createdAt' => 'DESC']), ]); diff --git a/src/Controller/Dashboard/CustomerController.php b/src/Controller/Dashboard/CustomerController.php new file mode 100644 index 0000000..3728b85 --- /dev/null +++ b/src/Controller/Dashboard/CustomerController.php @@ -0,0 +1,73 @@ +appLogger->record('VIEW', 'Consultation de la liste des clients'); + + // Utilisation d'un QueryBuilder (recommandé pour KNP) ou findAll + $query = $customerRepository->createQueryBuilder('c') + ->orderBy('c.surname', 'ASC') + ->getQuery(); + + $pagination = $paginator->paginate( + $query, + $request->query->getInt('page', 1), + 20 + ); + + return $this->render('dashboard/customer.twig', [ + 'customers' => $pagination, + ]); + } + + #[Route(path: '/crm/customer/add', name: 'app_crm_customer_add', methods: ['GET', 'POST'])] + public function add(Request $request): Response + { + $this->appLogger->record('VIEW', 'Consultation de la page de création client'); + + $c = new Customer(); + //$form = $this->createForm(,$c); + // Ici, tu pourras ajouter ta logique de formulaire (CustomerType) + + return $this->render('dashboard/customer/add.twig'); + } + + #[Route(path: '/crm/customer/show/{id}', name: 'app_crm_customer_show', methods: ['GET'])] + public function show(int $id, CustomerRepository $customerRepository): Response + { + $customer = $customerRepository->find($id); + + if (!$customer) { + throw $this->createNotFoundException('Client introuvable'); + } + + $this->appLogger->record('VIEW', sprintf('Consultation de la fiche client : %s', $customer->getName())); + + return $this->render('dashboard/customer/show.twig', [ + 'customer' => $customer + ]); + } +} diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php new file mode 100644 index 0000000..3e7d02f --- /dev/null +++ b/src/Entity/Customer.php @@ -0,0 +1,125 @@ +id; + } + + public function getCiv(): ?string + { + return $this->civ; + } + + public function setCiv(string $civ): static + { + $this->civ = $civ; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getSurname(): ?string + { + return $this->surname; + } + + public function setSurname(string $surname): static + { + $this->surname = $surname; + + return $this; + } + + public function getPhone(): ?string + { + return $this->phone; + } + + public function setPhone(string $phone): static + { + $this->phone = $phone; + + return $this; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(string $email): static + { + $this->email = $email; + + return $this; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(string $type): static + { + $this->type = $type; + + return $this; + } + + public function getSiret(): ?string + { + return $this->siret; + } + + public function setSiret(?string $siret): static + { + $this->siret = $siret; + + return $this; + } +} diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php new file mode 100644 index 0000000..9e3b066 --- /dev/null +++ b/src/Repository/CustomerRepository.php @@ -0,0 +1,43 @@ + + */ +class CustomerRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Customer::class); + } + + // /** + // * @return Customer[] Returns an array of Customer objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('c.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Customer + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/dashboard/base.twig b/templates/dashboard/base.twig index 5a675f2..b1c3516 100644 --- a/templates/dashboard/base.twig +++ b/templates/dashboard/base.twig @@ -41,7 +41,7 @@ {% import _self as menu %} {{ menu.nav_link(path('app_crm'), 'Dashboard', '', 'app_crm') }} - {{ menu.nav_link('#', 'Clients', '', 'app_clients') }} + {{ menu.nav_link(path('app_crm_customer'), 'Clients', '', 'app_clients') }} diff --git a/templates/dashboard/customer.twig b/templates/dashboard/customer.twig new file mode 100644 index 0000000..a1486aa --- /dev/null +++ b/templates/dashboard/customer.twig @@ -0,0 +1,150 @@ +{% extends 'dashboard/base.twig' %} + +{% block title %}Gestion Clients{% endblock %} +{% block title_header %}Annuaire Clients{% endblock %} + +{% block actions %} +
+ + + + + Nouveau Client + +
+{% endblock %} + +{% block body %} +
+ + {# HEADER TABLEAU #} +
+
+

Liste des clients

+

Base de données centralisée

+
+ + {{ customers|length }} CONTACTS + +
+ +
+ + + + + + + + + + + + {% for customer in customers %} + + + {# 1. IDENTITÉ #} + + + {# 2. TYPE (Badge dynamique) #} + + + {# 3. COORDONNÉES #} + + + {# 4. SIRET #} + + + {# 5. ACTIONS #} + + + + {% else %} + + + + {% endfor %} + +
IdentitéTypeCoordonnéesSIRET / IDActions
+
+
+ {{ customer.surname|first|upper }}{{ customer.name|first|upper }} +
+
+
+ {{ customer.civ }} + {{ customer.surname|upper }} {{ customer.name }} +
+
Client ID: #{{ loop.index + 100 }}
+
+
+
+ {% set typeStyles = { + 'company': 'bg-purple-500/10 text-purple-400 border-purple-500/20', + 'personal': 'bg-sky-500/10 text-sky-400 border-sky-500/20', + 'association': 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20', + 'mairie': 'bg-amber-500/10 text-amber-400 border-amber-500/20' + } %} + + {{ customer.type|default('Indéfini') }} + + +
+
+ + {{ customer.email }} +
+
+ + {{ customer.phone }} +
+
+
+ {% if customer.siret %} +
+ {{ customer.siret }} +
+ {% else %} + N/A + {% endif %} +
+ +
+ Aucun client enregistré dans la base. +
+
+ {# PAGINATION #} +
+
+
+ Affichage de {{ customers.getItemNumberPerPage }} clients par page +
+ +
+
+
{# Fin du conteneur principal #} + + {# CSS pour styliser KnpPagination aux couleurs de ton dashboard #} + +{% endblock %}