From ec0c0366c4a75ecd40768c4d476aed318bb8ce17 Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Sat, 4 Apr 2026 11:04:43 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20auto-d=C3=A9tection=20type=20entreprise?= =?UTF-8?q?=20+=20RNA=20pour=20associations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Customer entity : - Ajout champ rna (VARCHAR 20, nullable) pour identifiant RNA associations - Migration : ALTER TABLE customer ADD rna Recherche entreprise (entreprise-search.js) : - resolveTypeCompany() : mapping nature_juridique vers type formulaire 92xx/91xx/93xx → association, 10xx → auto-entrepreneur, 54xx/55xx → sarl, 57xx → sas, 52xx → eurl, 65xx → sci - Auto-remplissage typeCompany depuis nature_juridique - Récupération RNA depuis complements.identifiant_association - Badge "Association" affiché dans les résultats si nature_juridique 92xx - RNA affiché dans les résultats (ex: RNA W502004724) Template create.html.twig : - Ajout champ "RNA (associations)" dans la section Entreprise ClientsController : - populateCustomerData : ajout setRna depuis le formulaire Co-Authored-By: Claude Opus 4.6 (1M context) --- assets/modules/entreprise-search.js | 23 ++++++++++++++++ migrations/Version20260404090416.php | 31 ++++++++++++++++++++++ src/Controller/Admin/ClientsController.php | 1 + src/Entity/Customer.php | 15 +++++++++++ templates/admin/clients/create.html.twig | 5 ++++ 5 files changed, 75 insertions(+) create mode 100644 migrations/Version20260404090416.php diff --git a/assets/modules/entreprise-search.js b/assets/modules/entreprise-search.js index d5bb4a0..0fe1360 100644 --- a/assets/modules/entreprise-search.js +++ b/assets/modules/entreprise-search.js @@ -27,12 +27,27 @@ const buildRcs = (siren, city) => { return 'RCS ' + capitalize(city) + ' ' + siren } +const resolveTypeCompany = (natureJuridique) => { + if (!natureJuridique) return '' + const code = String(natureJuridique) + if (code.startsWith('92') || code.startsWith('91') || code.startsWith('93')) return 'association' + if (code.startsWith('10')) return 'auto-entrepreneur' + if (code.startsWith('54') || code.startsWith('55')) return 'sarl' + if (code.startsWith('57')) return 'sas' + if (code.startsWith('52')) return 'eurl' + if (code.startsWith('55') && code === '5599') return 'sa' + if (code.startsWith('65')) return 'sci' + return '' +} + const renderResult = (e, onSelect) => { const s = e.siege || {} const d = (e.dirigeants && e.dirigeants[0]) || {} const actif = e.etat_administratif === 'A' const addr = [s.numero_voie, s.type_voie, s.libelle_voie].filter(Boolean).join(' ') const ape = e.activite_principale || '' + const rna = (e.complements && e.complements.identifiant_association) || '' + const isAsso = resolveTypeCompany(e.nature_juridique) === 'association' const div = document.createElement('div') div.className = 'glass p-4 cursor-pointer hover:bg-white/80 transition-all' @@ -44,9 +59,11 @@ const renderResult = (e, onSelect) => { SIREN ${e.siren || '?'} ${s.siret ? ' — SIRET ' + s.siret + '' : ''} ${ape ? ' — APE ' + ape + '' : ''} + ${rna ? ' — RNA ' + rna + '' : ''}
${s.geo_adresse || s.adresse || ''}
${d.nom ? '
Dirigeant : ' + (d.prenoms || '') + ' ' + d.nom + '
' : ''} + ${isAsso ? '
Association
' : ''} ${actif ? 'Actif' : 'Ferme'} @@ -63,6 +80,12 @@ const renderResult = (e, onSelect) => { fillField('zipCode', s.code_postal || '') fillField('city', s.libelle_commune || '') + const typeCompany = resolveTypeCompany(e.nature_juridique) + if (typeCompany) fillField('typeCompany', typeCompany) + + const rna = (e.complements && e.complements.identifiant_association) || '' + if (rna) fillField('rna', rna) + const prenom = (d.prenoms || '').split(' ')[0] fillFieldIfEmpty('firstName', capitalize(prenom)) fillFieldIfEmpty('lastName', capitalize(d.nom)) diff --git a/migrations/Version20260404090416.php b/migrations/Version20260404090416.php new file mode 100644 index 0000000..dacda3a --- /dev/null +++ b/migrations/Version20260404090416.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE customer ADD rna VARCHAR(20) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE customer DROP rna'); + } +} diff --git a/src/Controller/Admin/ClientsController.php b/src/Controller/Admin/ClientsController.php index 499d21e..cd5817e 100644 --- a/src/Controller/Admin/ClientsController.php +++ b/src/Controller/Admin/ClientsController.php @@ -92,6 +92,7 @@ class ClientsController extends AbstractController $customer->setRcs(trim($request->request->getString('rcs')) ?: null); $customer->setNumTva(trim($request->request->getString('numTva')) ?: null); $customer->setApe(trim($request->request->getString('ape')) ?: null); + $customer->setRna(trim($request->request->getString('rna')) ?: null); $customer->setAddress(trim($request->request->getString('address')) ?: null); $customer->setAddress2(trim($request->request->getString('address2')) ?: null); $customer->setZipCode(trim($request->request->getString('zipCode')) ?: null); diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index dfb90cb..1336da1 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -86,6 +86,9 @@ class Customer #[ORM\Column(length: 10, nullable: true)] private ?string $ape = null; + #[ORM\Column(length: 20, nullable: true)] + private ?string $rna = null; + #[ORM\Column(length: 255, nullable: true)] private ?string $stripeCustomerId = null; @@ -316,6 +319,18 @@ class Customer return $this; } + public function getRna(): ?string + { + return $this->rna; + } + + public function setRna(?string $rna): static + { + $this->rna = $rna; + + return $this; + } + public function getStripeCustomerId(): ?string { return $this->stripeCustomerId; diff --git a/templates/admin/clients/create.html.twig b/templates/admin/clients/create.html.twig index 7e028ca..7bed114 100644 --- a/templates/admin/clients/create.html.twig +++ b/templates/admin/clients/create.html.twig @@ -103,6 +103,11 @@ +
+ + +