feat: auto-création contact Directeur à la création client et à l'ouverture fiche
ensureDefaultContact() : - Vérifie si le client a au moins 1 contact dans CustomerContact - Si aucun contact : crée automatiquement un contact avec firstName/lastName du client, email, phone, role='Directeur', isBillingEmail=true - Appelé à la création du client (après flush) - Appelé à l'ouverture de la fiche client (show) pour les clients existants qui n'ont pas encore de contact Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -72,6 +72,7 @@ class ClientsController extends AbstractController
|
||||
$em->flush();
|
||||
|
||||
$this->indexInMeilisearch($meilisearch, $customer, $logger);
|
||||
$this->ensureDefaultContact($customer, $em);
|
||||
|
||||
$this->addFlash('success', 'Client '.$customer->getFullName().' cree.');
|
||||
|
||||
@@ -117,6 +118,32 @@ class ClientsController extends AbstractController
|
||||
return $info;
|
||||
}
|
||||
|
||||
private function ensureDefaultContact(Customer $customer, EntityManagerInterface $em): void
|
||||
{
|
||||
$contactRepo = $em->getRepository(\App\Entity\CustomerContact::class);
|
||||
$existing = $contactRepo->findBy(['customer' => $customer]);
|
||||
|
||||
if ([] !== $existing) {
|
||||
return;
|
||||
}
|
||||
|
||||
$firstName = $customer->getFirstName();
|
||||
$lastName = $customer->getLastName();
|
||||
|
||||
if (null === $firstName || null === $lastName || '' === $firstName || '' === $lastName) {
|
||||
return;
|
||||
}
|
||||
|
||||
$contact = new \App\Entity\CustomerContact($customer, $firstName, $lastName);
|
||||
$contact->setEmail($customer->getEmail());
|
||||
$contact->setPhone($customer->getPhone());
|
||||
$contact->setRole('Directeur');
|
||||
$contact->setIsBillingEmail(true);
|
||||
|
||||
$em->persist($contact);
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
private function populateCustomerData(Request $request, Customer $customer): void
|
||||
{
|
||||
$customer->setFirstName(trim($request->request->getString('firstName')));
|
||||
@@ -279,6 +306,7 @@ class ClientsController extends AbstractController
|
||||
return $this->handleContactForm($request, $customer, $em);
|
||||
}
|
||||
|
||||
$this->ensureDefaultContact($customer, $em);
|
||||
$contacts = $em->getRepository(\App\Entity\CustomerContact::class)->findBy(['customer' => $customer], ['createdAt' => 'DESC']);
|
||||
$domains = $em->getRepository(\App\Entity\Domain::class)->findBy(['customer' => $customer]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user