Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 786638a02f | |||
| fcacde2a34 | |||
| fea325e10f | |||
| e139d234a9 | |||
| c437bc52a2 | |||
| 597101262d | |||
| 90dfc17fcb | |||
| ce89c5e46a | |||
| 546ba462b9 | |||
| ee3bbea649 | |||
| e85d46a17b | |||
| ec952896ba | |||
| 468894cfad | |||
| 912280d24e | |||
| f406a598eb | |||
| a72a5dd812 | |||
| 3dc98994f5 | |||
| 96ddd15c86 | |||
| 1b924ba0fd | |||
| 8fae987e15 | |||
| 6f977d387d | |||
| 1888b70623 | |||
| 1961bc62c8 | |||
| bc7c8f6f83 | |||
| 7833ff32e6 | |||
| 6fee9f6bd6 | |||
| 276f242b10 |
+19
-131
@@ -6,6 +6,13 @@
|
|||||||
- PHP CS Fixer : regles Symfony + PSR-12 + strict types (commande : `make php-cs-fixer-allow-risky`)
|
- PHP CS Fixer : regles Symfony + PSR-12 + strict types (commande : `make php-cs-fixer-allow-risky`)
|
||||||
- Commentaires (docblock, inline, bloc) **en francais** ; code (classes, methodes, variables) en anglais
|
- Commentaires (docblock, inline, bloc) **en francais** ; code (classes, methodes, variables) en anglais
|
||||||
|
|
||||||
|
## Messages de validation (obligatoire)
|
||||||
|
|
||||||
|
Toute contrainte `#[Assert\*]` d'une entite metier : **message FR explicite**, et `Assert\Length.max` = `length` de la colonne ORM (coherence 3 niveaux nullable DB <-> NotBlank back <-> required front, ERP-101). RG inter-champs via `#[Assert\Callback]->atPath('<champ>')` (mapping inline front, pas toast). Exceptions miroir Length (Bic/Iban/Regex borne) : whitelist `EntityConstraintsHaveFrenchMessageTest::EXCLUDED_LENGTH_MIRROR`.
|
||||||
|
|
||||||
|
Garde-fou : `tests/Architecture/EntityConstraintsHaveFrenchMessageTest` (casse `make test`).
|
||||||
|
→ patterns code + exemples + justification complete : skill `backend-entity-conventions`.
|
||||||
|
|
||||||
## API Platform (pas de controllers)
|
## API Platform (pas de controllers)
|
||||||
|
|
||||||
- Toujours utiliser `#[ApiResource]` + Providers + Processors — pas de controllers Symfony classiques
|
- Toujours utiliser `#[ApiResource]` + Providers + Processors — pas de controllers Symfony classiques
|
||||||
@@ -15,61 +22,10 @@
|
|||||||
|
|
||||||
## Pagination (obligatoire)
|
## Pagination (obligatoire)
|
||||||
|
|
||||||
**Regle** : toute collection API DOIT etre paginee. Aucun retour de collection complete cote serveur.
|
Toute collection API est paginee (defaut 10, max 50 ; `?pagination=false` = echappatoire selects, `?itemsPerPage=25` borne par le max). Standard global dans `config/packages/api_platform.yaml`. Jamais `paginationEnabled: false` hors whitelist `CollectionsArePaginatedTest::EXCLUDED`. Provider custom : ne jamais retourner un `array` brut sur une `CollectionOperationInterface` (court-circuite Hydra) — wrapper un Paginator (ORM : `ApiPlatform\Doctrine\Orm\Paginator` ; DBAL : `DbalPaginator`) et gerer `?pagination=false` via `$this->pagination->isEnabled(...)`.
|
||||||
|
|
||||||
### Standard global
|
Garde-fou : `tests/Architecture/CollectionsArePaginatedTest` (casse `make test`).
|
||||||
|
→ tableau des cles `pagination_*` + selects + providers ORM/DBAL detailles : skill `backend-entity-conventions`.
|
||||||
Pose dans `config/packages/api_platform.yaml` (section `defaults:`) et heritee par toutes les ressources :
|
|
||||||
|
|
||||||
| Cle | Valeur | Effet |
|
|
||||||
|---|---|---|
|
|
||||||
| `pagination_enabled` | `true` | Pagination Hydra active par defaut. |
|
|
||||||
| `pagination_items_per_page` | `10` | Taille de page par defaut, aligne sur l'UI `MalioDataTable`. |
|
|
||||||
| `pagination_maximum_items_per_page` | `50` | Borne dure : `?itemsPerPage=999` → ramene a 50. Anti deep-fetch. |
|
|
||||||
| `pagination_client_items_per_page` | `true` | Le client peut envoyer `?itemsPerPage=25` (bornee par le max). |
|
|
||||||
| `pagination_client_enabled` | `true` | Le client peut envoyer `?pagination=false` pour TOUT recuperer (echappatoire selects). |
|
|
||||||
|
|
||||||
### Override par ressource (rare)
|
|
||||||
|
|
||||||
Si une ressource a besoin d'un autre defaut (ex: payload lourd), utiliser les attributs sur l'operation. **JAMAIS `paginationEnabled: false`** sans whitelist explicite dans `tests/Architecture/CollectionsArePaginatedTest::EXCLUDED`.
|
|
||||||
|
|
||||||
```php
|
|
||||||
new GetCollection(
|
|
||||||
paginationItemsPerPage: 5, // override taille par defaut
|
|
||||||
paginationMaximumItemsPerPage: 20, // override borne max
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Selects et autocompletions
|
|
||||||
|
|
||||||
Pour alimenter un `<select>` ou un drawer RBAC (Role, Permission, Site, CategoryType), le front passe :
|
|
||||||
|
|
||||||
```ts
|
|
||||||
useApi().get('/api/roles?pagination=false')
|
|
||||||
```
|
|
||||||
|
|
||||||
Le serveur retourne toute la collection, sans `view`. C'est l'echappatoire prevue par `pagination_client_enabled: true`. Sur les ressources a forte volumetrie, preferer une saisie assistee (recherche serveur via `?q=`) — a planifier dans un ticket dedie.
|
|
||||||
|
|
||||||
Les tests fonctionnels qui exercent ce comportement doivent egalement passer `?pagination=false` (cf. `CategoryListTest`, `PermissionApiTest`).
|
|
||||||
|
|
||||||
### Providers customs et pagination
|
|
||||||
|
|
||||||
Un provider custom qui retourne un `array` brut sur une `CollectionOperationInterface` **court-circuite la pagination Hydra** (pas de `totalItems`, pas de `view`). Patterns supportes :
|
|
||||||
|
|
||||||
- **ORM** : injecter `ApiPlatform\State\Pagination\Pagination`, wrap un `Doctrine\ORM\Tools\Pagination\Paginator` dans `ApiPlatform\Doctrine\Orm\Paginator`. Exemple : `CategoryProvider`.
|
|
||||||
- **DBAL** : implementer un paginator local conforme a `PaginatorInterface`. Exemple : `DbalPaginator` (Core) + `AuditLogProvider`.
|
|
||||||
|
|
||||||
Gerer l'echappatoire `?pagination=false` :
|
|
||||||
|
|
||||||
```php
|
|
||||||
if (!$this->pagination->isEnabled($operation, $context)) {
|
|
||||||
return $qb->getQuery()->getResult(); // tout retourner
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Garde-fou architecture
|
|
||||||
|
|
||||||
`tests/Architecture/CollectionsArePaginatedTest` scanne reflexivement toutes les classes `#[ApiResource]` sous `src/` et echoue si une `GetCollection` pose `paginationEnabled: false` hors whitelist `EXCLUDED`. Ajouter une entree a la whitelist requiert une justification courte + un ticket Lesstime ouvert.
|
|
||||||
|
|
||||||
## Repositories
|
## Repositories
|
||||||
|
|
||||||
@@ -100,42 +56,17 @@ Format obligatoire : `module.resource[.subresource].action` en snake_case.
|
|||||||
|
|
||||||
### Libelle i18n du type d'entite (obligatoire avec `#[Auditable]`)
|
### Libelle i18n du type d'entite (obligatoire avec `#[Auditable]`)
|
||||||
|
|
||||||
**Toute entite `#[Auditable]` doit avoir son libelle FR dans le bloc `audit.entity` de `frontend/i18n/locales/fr.json`.** C'est la contrepartie i18n de l'attribut : sans elle, le filtre « Type d'entite » de l'audit-log affiche le type technique brut (ex: `commercial.Client`) au lieu d'un libelle lisible.
|
Toute entite `#[Auditable]` doit avoir sa cle `audit.entity.<module>_<entity>` dans `frontend/i18n/locales/fr.json` (cle = `strtolower(module)` + `_` + `strtolower(Entity)`, decision ERP-99). Sans elle, le filtre « Type d'entite » de l'audit-log retombe silencieusement sur le type technique brut (ex: `commercial.Client`). Fait partie de la definition de fini d'une entite auditee.
|
||||||
|
|
||||||
Pourquoi : le filtre est dynamique (`GET /audit-log-entity-types` renvoie les `entity_type` distincts presents en base) ; des qu'un module audite une entite, son type y apparait. Le front (`formatEntityType`, `audit-log.vue`) construit la cle `audit.entity.<module>_<entity>` et, faute de traduction, **retombe silencieusement** sur le type brut.
|
Garde-fou : `tests/Architecture/AuditableEntitiesHaveI18nLabelTest` (casse `make test`).
|
||||||
|
→ derivation detaillee + exemples : skill `backend-entity-conventions`.
|
||||||
Derivation de la cle (emplacement centralise + schema flat — decision ERP-99) :
|
|
||||||
|
|
||||||
| FQCN entite | `entity_type` (back) | Cle i18n (flat) |
|
|
||||||
|---|---|---|
|
|
||||||
| `App\Module\Commercial\Domain\Entity\Client` | `commercial.Client` | `commercial_client` |
|
|
||||||
| `App\Module\Commercial\Domain\Entity\ClientAddress` | `commercial.ClientAddress` | `commercial_clientaddress` |
|
|
||||||
| `App\Module\Catalog\Domain\Entity\Category` | `catalog.Category` | `catalog_category` |
|
|
||||||
|
|
||||||
Regle : `strtolower(module)` + `_` + `strtolower(Entity)`. Ajouter sa cle de libelle audit fait partie de la **definition de fini** d'une entite metier auditee.
|
|
||||||
|
|
||||||
**Garde-fou** : `tests/Architecture/AuditableEntitiesHaveI18nLabelTest` scanne les entites `#[Auditable]` et echoue si une seule n'a pas sa cle `audit.entity.*`. Conclusion : creer une entite `#[Auditable]` sans son libelle i18n casse `make test`.
|
|
||||||
|
|
||||||
## Timestampable + Blamable (obligatoire pour entites metier)
|
## Timestampable + Blamable (obligatoire pour entites metier)
|
||||||
|
|
||||||
Toute **nouvelle** entite metier sous `src/Module/*/Domain/Entity/` doit porter les 4 colonnes `created_at` / `updated_at` / `created_by` / `updated_by`, remplies automatiquement. Trois lignes a ajouter a l'entite :
|
Toute **nouvelle** entite metier sous `src/Module/*/Domain/Entity/` : `implements TimestampableInterface, BlamableInterface` + `use TimestampableBlamableTrait` (porte les 4 colonnes `created_at` / `updated_at` / `created_by` / `updated_by`, remplies par `TimestampableBlamableSubscriber` au prePersist/preUpdate). La migration cree les 4 colonnes (`created_at`/`updated_at` NOT NULL, `created_by`/`updated_by` nullable `ON DELETE SET NULL`). Referentiel statique justifie : whitelist `EntitiesAreTimestampableBlamableTest::EXCLUDED`.
|
||||||
|
|
||||||
```php
|
Garde-fou : `tests/Architecture/EntitiesAreTimestampableBlamableTest` (casse `make test`).
|
||||||
use App\Shared\Domain\Contract\BlamableInterface;
|
→ snippet complet : skill `backend-entity-conventions` ; spec : @docs/specs/M0-categories/spec-back.md § 2.8 + § 2.8.bis.
|
||||||
use App\Shared\Domain\Contract\TimestampableInterface;
|
|
||||||
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
|
||||||
|
|
||||||
class MyEntity implements TimestampableInterface, BlamableInterface
|
|
||||||
{
|
|
||||||
use TimestampableBlamableTrait; // porte les 4 props + getters/setters
|
|
||||||
// ... reste metier
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- Le `TimestampableBlamableSubscriber` (`Shared/Infrastructure/Doctrine/`) remplit les colonnes au `prePersist` / `preUpdate`. Hors contexte HTTP (CLI, cron, migration), le blame reste `null` (libelle « Systeme » cote front).
|
|
||||||
- La migration de l'entite doit creer les 4 colonnes (`created_at` / `updated_at` NOT NULL, `created_by` / `updated_by` nullable `ON DELETE SET NULL`).
|
|
||||||
- **Garde-fou CI** : `tests/Architecture/EntitiesAreTimestampableBlamableTest` echoue si une entite oublie le pattern. Un referentiel statique justifie (ex: `CategoryType`) doit etre explicitement whiteliste dans la constante `EXCLUDED` avec un commentaire.
|
|
||||||
- Spec complete : @docs/specs/M0-categories/spec-back.md § 2.8 + § 2.8.bis
|
|
||||||
|
|
||||||
## Serialization
|
## Serialization
|
||||||
|
|
||||||
@@ -153,50 +84,7 @@ Exemple : pour qu'`User.profile` soit embarque au lieu d'un lien IRI sous le gro
|
|||||||
|
|
||||||
## Migrations Doctrine
|
## Migrations Doctrine
|
||||||
|
|
||||||
### Documentation SQL obligatoire (`COMMENT ON COLUMN`)
|
Toute migration creant/modifiant une colonne d'une table metier pose un `COMMENT ON COLUMN` (FR, ≤ 200 caracteres, semantique + contrainte/RG, cible pour les FK). Les 4 colonnes Timestampable/Blamable recoivent leur description via le helper centralise `addStandardTimestampableBlamableComments($schema, 'table')`. Bonus : `COMMENT ON TABLE` pour decrire la table.
|
||||||
|
|
||||||
**Toute migration qui cree ou modifie une colonne d'une table metier doit poser un `COMMENT ON COLUMN` decrivant le champ.** La description est stockee dans `pg_description` et visible dans tous les outils d'admin BDD (DBeaver, DataGrip, pgAdmin), sans avoir a lire les annotations PHP.
|
Garde-fou : `tests/Architecture/ColumnsHaveSqlCommentTest` parcourt `information_schema.columns` (schema `public`) ; une seule colonne sans `col_description` casse `make test` (hors `EXCLUDED_TABLES`).
|
||||||
|
→ exemples SQL + textes du helper : skill `backend-entity-conventions`.
|
||||||
**Format de la description** :
|
|
||||||
- En francais
|
|
||||||
- ≤ 200 caracteres
|
|
||||||
- Semantique du champ — contraintes / lien RG si pertinent
|
|
||||||
- Pour les colonnes d'identifiant ou FK, mentionner la cible
|
|
||||||
|
|
||||||
Exemples :
|
|
||||||
|
|
||||||
```php
|
|
||||||
// Migration : creation d'une colonne avec son commentaire dans la meme migration
|
|
||||||
$this->addSql("ALTER TABLE client ADD COLUMN siren VARCHAR(9) DEFAULT NULL");
|
|
||||||
$this->addSql("COMMENT ON COLUMN client.siren IS 'SIREN (9 chiffres) — identifiant legal entreprise. Unique parmi non-archives (RG-1.15).'");
|
|
||||||
|
|
||||||
// Cas FK : preciser la cible
|
|
||||||
$this->addSql("COMMENT ON COLUMN client.legal_form_id IS 'Reference forme juridique (SARL, SAS, SA...) — FK -> legal_form.id, ON DELETE RESTRICT.'");
|
|
||||||
|
|
||||||
// Cas booleen : preciser le sens et la valeur par defaut
|
|
||||||
$this->addSql("COMMENT ON COLUMN user.is_admin IS 'Drapeau super-administrateur — bypass complet RBAC. Faux par defaut.'");
|
|
||||||
|
|
||||||
// Bonus : decrire la table elle-meme
|
|
||||||
$this->addSql("COMMENT ON TABLE client IS 'Repertoire clients (M1 Commercial) — entites archivables.'");
|
|
||||||
```
|
|
||||||
|
|
||||||
### Helper Timestampable/Blamable
|
|
||||||
|
|
||||||
Les 4 colonnes `created_at`, `updated_at`, `created_by`, `updated_by` ajoutees par `TimestampableBlamableTrait` recoivent une description **standardisee** via le helper centralise pour eviter la duplication. Helper a creer ou appeler :
|
|
||||||
|
|
||||||
```php
|
|
||||||
// Dans la migration, apres avoir ajoute les 4 colonnes :
|
|
||||||
$this->addStandardTimestampableBlamableComments($schema, 'client');
|
|
||||||
```
|
|
||||||
|
|
||||||
L'implementation du helper applique :
|
|
||||||
- `created_at` : « Horodatage de creation de la ligne (UTC, rempli automatiquement par TimestampableBlamableSubscriber). »
|
|
||||||
- `updated_at` : « Horodatage de derniere modification de la ligne (UTC, rempli automatiquement par TimestampableBlamableSubscriber). »
|
|
||||||
- `created_by` : « ID de l'utilisateur ayant cree la ligne — null pour les creations hors HTTP (CLI, migration, fixture). FK -> user.id, ON DELETE SET NULL. »
|
|
||||||
- `updated_by` : « ID de l'utilisateur ayant modifie la ligne en dernier — null pour les modifications hors HTTP. FK -> user.id, ON DELETE SET NULL. »
|
|
||||||
|
|
||||||
### Garde-fou architecture
|
|
||||||
|
|
||||||
`tests/Architecture/ColumnsHaveSqlCommentTest` parcourt `information_schema.columns` filtre sur le schema `public` et echoue si **une seule colonne** n'a pas de `col_description`. Seules les tables system (`doctrine_migration_versions`) et la whitelist `EXCLUDED_TABLES` explicite (commentaire de justification + ticket Lesstime ouvert pour le retrofit) sont tolerees.
|
|
||||||
|
|
||||||
Conclusion : si tu crees une colonne sans poser son `COMMENT ON COLUMN`, `make test` casse en CI.
|
|
||||||
|
|||||||
@@ -44,6 +44,44 @@ Tout champ de formulaire / filtre doit utiliser les composants `Malio*` plutot q
|
|||||||
|
|
||||||
Toute autre exception requiert validation avant merge.
|
Toute autre exception requiert validation avant merge.
|
||||||
|
|
||||||
|
## Standard ecran formulaire — reference : ecran Client
|
||||||
|
|
||||||
|
**Tout nouvel ecran de formulaire doit ressembler au premier ecran Client** (`frontend/modules/commercial/pages/clients/new.vue` + `[id]/edit.vue`) : meme structure (bloc principal puis onglets), memes marges/espacements, memes blocs de collection (ajout/suppression inline), meme validation inline 422 par champ. C'est la reference visuelle et fonctionnelle des formulaires du projet — s'en inspirer avant d'en creer un nouveau.
|
||||||
|
|
||||||
|
## Validation des formulaires — useFormErrors obligatoire (erreur par champ)
|
||||||
|
|
||||||
|
**Tout formulaire qui soumet a une API DOIT afficher les erreurs de validation 422 sous le champ concerne, via `useFormErrors`** (`frontend/shared/composables/useFormErrors.ts`). C'est le pendant front de « le back renvoie TOUTES les violations d'une 422 d'un coup » : un seul aller-retour, chaque erreur affichee inline sous son champ (prop `:error` des `Malio*`), pas un toast fourre-tout.
|
||||||
|
|
||||||
|
Principe cle : **le nom du champ cote front = le `propertyPath` renvoye par le back**. Aucun mapping manuel champ par champ.
|
||||||
|
|
||||||
|
Pattern de reference (champs scalaires) :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const { errors, setError, clearErrors, handleApiError } = useFormErrors()
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
clearErrors()
|
||||||
|
try {
|
||||||
|
await useApi().post('/clients', payload, { toast: false }) // toast: false obligatoire
|
||||||
|
} catch (e) {
|
||||||
|
// 422 → mapping inline par champ (pas de toast) ; autre → toast de fallback.
|
||||||
|
handleApiError(e, { fallbackMessage: t('foo.error') })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<MalioInputText v-model="form.companyName" :error="errors.companyName" />
|
||||||
|
<MalioSelect v-model="form.siren" :error="errors.siren" />
|
||||||
|
```
|
||||||
|
|
||||||
|
Regles :
|
||||||
|
- **Toujours `{ toast: false }`** sur l'appel API qui veut un mapping inline (sinon le toast natif d'`useApi` masque le fin).
|
||||||
|
- **Cas metier specifique** (ex: 409 doublon) : `setError('champ', message)` + toast explicite **avant** de deleguer le reste a `handleApiError`. Cf. `useCategoryForm` (doublon RG-1.07).
|
||||||
|
- **Collections** (listes de sous-entites sauvees par un appel par ligne) : une erreur PAR LIGNE via un tableau `ref<Record<string, string>[]>` aligne sur l'index, peuple par `mapViolationsToRecord(error.response._data)` (util pur de `shared/utils/api.ts`). Le composant de ligne expose une prop `:errors` (`Record<string, string>`) bindee sur le `:error` de chaque champ. Cf. `ClientContactBlock` / `ClientAddressBlock` et les submits de `clients/new.vue` / `clients/[id]/edit.vue`.
|
||||||
|
|
||||||
|
**Interdit** : se contenter d'un toast global sur une 422 quand le back identifie les champs fautifs (`propertyPath`). Reimplementer un mapping `if/else` par champ a la main au lieu d'`useFormErrors` / `mapViolationsToRecord`.
|
||||||
|
|
||||||
## Tableaux de donnees — MalioDataTable obligatoire
|
## Tableaux de donnees — MalioDataTable obligatoire
|
||||||
|
|
||||||
Tout affichage LISTE tabulaire (donnees metier paginees, CRUD admin) doit passer par `MalioDataTable` :
|
Tout affichage LISTE tabulaire (donnees metier paginees, CRUD admin) doit passer par `MalioDataTable` :
|
||||||
@@ -108,6 +146,18 @@ A NE PAS faire :
|
|||||||
- Seuls les deep links "de navigation metier" (ex: ouvrir un detail precis `/users/42`) sont dans l'URL
|
- Seuls les deep links "de navigation metier" (ex: ouvrir un detail precis `/users/42`) sont dans l'URL
|
||||||
- Exceptions autorisees **sur demande explicite** de l'utilisateur
|
- Exceptions autorisees **sur demande explicite** de l'utilisateur
|
||||||
|
|
||||||
|
## Validation des formulaires (standard ERP-101)
|
||||||
|
|
||||||
|
Regle transverse a TOUS les formulaires front (et a rappeler a l'ecriture de chaque ticket back/front portant un formulaire). Decidee en ERP-101 (declencheur : ecran « Ajouter un client » ERP-63).
|
||||||
|
|
||||||
|
- **Champs obligatoires** : prop `required` du composant `Malio*` + etoile (asterisque) rouge dans le label. Ne JAMAIS griser le bouton « Valider » sans feedback : bouton toujours actif + erreurs affichees sous les champs.
|
||||||
|
- **Couche de validation autoritaire = le back** : les RG sont re-validees serveur (mode strict). Au `422`, mapper `violations[].propertyPath` vers la prop `error` du champ via `extractApiViolations` (deja utilise par `useCategoryForm`). Zero duplication de RG, zero drift.
|
||||||
|
- **Feedback instantane au blur** : uniquement requis / min / max / format (pas de re-implementation des RG metier cote front).
|
||||||
|
- **Regles front-only** : celles sans equivalent back (ex. FK nullable cote back mais obligatoire selon un choix UI) sont validees et affichees cote front.
|
||||||
|
- **Email — PAS de masque** : un email n'a pas de structure fixe. Normalisation via la prop `lowercase` de `MalioInputEmail` (trim + suppression des espaces + lowercase, coherent avec la normalisation serveur RG-1.21). Le format est valide par la prop `error` (violations serveur ou check au blur), jamais par un masque. Retirer tout shaping email ad hoc des ecrans.
|
||||||
|
- **Contrat back attendu** : tout `422` issu d'un Processor/Validator doit porter `violations[].propertyPath` aligne sur les noms de champs du formulaire, pour etre consommable par `extractApiViolations`.
|
||||||
|
- **Dependance** : le branchement des props `required` suppose `@malio/layer-ui` a jour (props `required` + etoile — MUI-41 / ERP-101).
|
||||||
|
|
||||||
## Interdits
|
## Interdits
|
||||||
|
|
||||||
- `modules-loader.ts`, `.module.ts` — le scan des layers est automatique
|
- `modules-loader.ts`, `.module.ts` — le scan des layers est automatique
|
||||||
|
|||||||
@@ -0,0 +1,251 @@
|
|||||||
|
---
|
||||||
|
name: backend-entity-conventions
|
||||||
|
description: Conventions détaillées des entités métier Starseed (back PHP/Symfony/API Platform) — messages de validation FR sur les contraintes, pagination API Platform et providers ORM/DBAL, libellé i18n du type d'entité auditée, Timestampable/Blamable, COMMENT ON COLUMN des migrations. Charger dès qu'on crée ou modifie une entité Domain, un ApiResource, un Provider/Processor, une contrainte de validation, ou une migration Doctrine. Le résumé court de chaque règle (+ nom du test garde-fou) reste dans .claude/rules/backend.md ; ce skill porte les patterns, tableaux et exemples complets.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Conventions entités métier — détail
|
||||||
|
|
||||||
|
Ce skill contient le détail (patterns code, tableaux, dérivations) des 5 règles back qui ont chacune
|
||||||
|
un test Architecture déterministe. L'énoncé court de chaque règle vit dans `.claude/rules/backend.md`
|
||||||
|
(chargé à chaque session) ; ici on trouve le « comment » complet.
|
||||||
|
|
||||||
|
> Règle d'or : le **test Architecture reste le juge** (il casse `make test`). Ce skill aide à écrire
|
||||||
|
> le code juste du premier coup, il ne remplace pas le garde-fou.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Messages de validation (Garde-fou : `EntityConstraintsHaveFrenchMessageTest`)
|
||||||
|
|
||||||
|
**Toute contrainte `#[Assert\*]` portée par une entité métier doit avoir un message FR explicite**, et
|
||||||
|
**`Assert\Length.max` doit refléter le `length` de la colonne ORM**. C'est le pendant back du mapping
|
||||||
|
d'erreur par champ côté front (ERP-101 : `useFormErrors` / `mapViolationsToRecord` affiche sous chaque
|
||||||
|
champ le `message` renvoyé par le back).
|
||||||
|
|
||||||
|
Pourquoi :
|
||||||
|
- Sans `message:` explicite, Symfony renvoie le défaut **anglais** (« This value is not a valid email
|
||||||
|
address. »). La locale FR globale (`default_locale: fr` dans `framework.yaml`) sert de FILET via
|
||||||
|
`validators.fr.xlf`, mais les contraintes métier portent en plus leur message FR pour un contrôle total.
|
||||||
|
- Une colonne string bornée **sans `Assert\Length`** échoue au niveau Postgres (500 générique, non
|
||||||
|
rattachée au champ) au lieu d'une 422 propre. Le `max` doit égaler le `length` ORM (anti-dérive).
|
||||||
|
|
||||||
|
Pattern par champ scalaire :
|
||||||
|
|
||||||
|
```php
|
||||||
|
// Email métier
|
||||||
|
#[Assert\Email(message: 'L\'adresse email n\'est pas valide.')]
|
||||||
|
|
||||||
|
// Longueur calée sur la colonne (VARCHAR(120))
|
||||||
|
#[ORM\Column(length: 120)]
|
||||||
|
#[Assert\Length(max: 120, maxMessage: 'Le nom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
|
|
||||||
|
// Obligatoire (aligner nullable DB / NotBlank back / required front)
|
||||||
|
#[Assert\NotBlank(message: 'Le téléphone est obligatoire.', normalizer: 'trim')]
|
||||||
|
```
|
||||||
|
|
||||||
|
Cohérence à 3 niveaux pour un champ obligatoire : colonne `nullable` (DB) <-> `Assert\NotBlank` (back)
|
||||||
|
<-> `:required` + astérisque (front ERP-101). Les trois doivent s'accorder.
|
||||||
|
|
||||||
|
Exceptions au miroir `Length` : un format déjà borné par `Assert\Bic` / `Assert\Iban` (longueur
|
||||||
|
garantie) ou par un `Assert\Regex` borné (ex. code postal `{4,5}`, couleur hex `#RRGGBB`) — whitelister
|
||||||
|
alors la propriété dans `EntityConstraintsHaveFrenchMessageTest::EXCLUDED_LENGTH_MIRROR` avec justification.
|
||||||
|
|
||||||
|
Les règles inter-champs (RG métier : exclusivité distributor/broker RG-1.03, billingEmail RG-1.11, etc.)
|
||||||
|
passent par un `#[Assert\Callback]` qui construit la violation avec `->atPath('<champ>')` — indispensable
|
||||||
|
pour que le front la mappe en inline plutôt qu'en toast.
|
||||||
|
|
||||||
|
### Garde-fou architecture
|
||||||
|
|
||||||
|
`tests/Architecture/EntityConstraintsHaveFrenchMessageTest` scanne réflexivement les entités sous
|
||||||
|
`src/Module/*/Domain/Entity/` et échoue si :
|
||||||
|
1. une contrainte connue n'a pas de message FR explicite (comparé au défaut Symfony) ;
|
||||||
|
2. une colonne string bornée writable n'a pas de `Assert\Length(max == ORM length)` (hors whitelist).
|
||||||
|
|
||||||
|
Une contrainte non gérée par le mapping du test le fait échouer : il faut l'ajouter explicitement
|
||||||
|
(anti faux positif vert).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Pagination (Garde-fou : `CollectionsArePaginatedTest`)
|
||||||
|
|
||||||
|
**Règle** : toute collection API DOIT être paginée. Aucun retour de collection complète côté serveur.
|
||||||
|
|
||||||
|
### Standard global
|
||||||
|
|
||||||
|
Posé dans `config/packages/api_platform.yaml` (section `defaults:`) et hérité par toutes les ressources :
|
||||||
|
|
||||||
|
| Clé | Valeur | Effet |
|
||||||
|
|---|---|---|
|
||||||
|
| `pagination_enabled` | `true` | Pagination Hydra active par défaut. |
|
||||||
|
| `pagination_items_per_page` | `10` | Taille de page par défaut, alignée sur l'UI `MalioDataTable`. |
|
||||||
|
| `pagination_maximum_items_per_page` | `50` | Borne dure : `?itemsPerPage=999` → ramené à 50. Anti deep-fetch. |
|
||||||
|
| `pagination_client_items_per_page` | `true` | Le client peut envoyer `?itemsPerPage=25` (bornée par le max). |
|
||||||
|
| `pagination_client_enabled` | `true` | Le client peut envoyer `?pagination=false` pour TOUT récupérer (échappatoire selects). |
|
||||||
|
|
||||||
|
### Override par ressource (rare)
|
||||||
|
|
||||||
|
Si une ressource a besoin d'un autre défaut (ex: payload lourd), utiliser les attributs sur l'opération.
|
||||||
|
**JAMAIS `paginationEnabled: false`** sans whitelist explicite dans
|
||||||
|
`tests/Architecture/CollectionsArePaginatedTest::EXCLUDED`.
|
||||||
|
|
||||||
|
```php
|
||||||
|
new GetCollection(
|
||||||
|
paginationItemsPerPage: 5, // override taille par défaut
|
||||||
|
paginationMaximumItemsPerPage: 20, // override borne max
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Selects et autocomplétions
|
||||||
|
|
||||||
|
Pour alimenter un `<select>` ou un drawer RBAC (Role, Permission, Site, CategoryType), le front passe :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
useApi().get('/api/roles?pagination=false')
|
||||||
|
```
|
||||||
|
|
||||||
|
Le serveur retourne toute la collection, sans `view`. C'est l'échappatoire prévue par
|
||||||
|
`pagination_client_enabled: true`. Sur les ressources à forte volumétrie, préférer une saisie assistée
|
||||||
|
(recherche serveur via `?q=`) — à planifier dans un ticket dédié.
|
||||||
|
|
||||||
|
Les tests fonctionnels qui exercent ce comportement doivent également passer `?pagination=false`
|
||||||
|
(cf. `CategoryListTest`, `PermissionApiTest`).
|
||||||
|
|
||||||
|
### Providers customs et pagination
|
||||||
|
|
||||||
|
Un provider custom qui retourne un `array` brut sur une `CollectionOperationInterface`
|
||||||
|
**court-circuite la pagination Hydra** (pas de `totalItems`, pas de `view`). Patterns supportés :
|
||||||
|
|
||||||
|
- **ORM** : injecter `ApiPlatform\State\Pagination\Pagination`, wrap un
|
||||||
|
`Doctrine\ORM\Tools\Pagination\Paginator` dans `ApiPlatform\Doctrine\Orm\Paginator`. Exemple : `CategoryProvider`.
|
||||||
|
- **DBAL** : implémenter un paginator local conforme à `PaginatorInterface`. Exemple : `DbalPaginator`
|
||||||
|
(Core) + `AuditLogProvider`.
|
||||||
|
|
||||||
|
Gérer l'échappatoire `?pagination=false` :
|
||||||
|
|
||||||
|
```php
|
||||||
|
if (!$this->pagination->isEnabled($operation, $context)) {
|
||||||
|
return $qb->getQuery()->getResult(); // tout retourner
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Garde-fou architecture
|
||||||
|
|
||||||
|
`tests/Architecture/CollectionsArePaginatedTest` scanne réflexivement toutes les classes
|
||||||
|
`#[ApiResource]` sous `src/` et échoue si une `GetCollection` pose `paginationEnabled: false` hors
|
||||||
|
whitelist `EXCLUDED`. Ajouter une entrée à la whitelist requiert une justification courte + un ticket
|
||||||
|
Lesstime ouvert.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Libellé i18n du type d'entité auditée (Garde-fou : `AuditableEntitiesHaveI18nLabelTest`)
|
||||||
|
|
||||||
|
**Toute entité `#[Auditable]` doit avoir son libellé FR dans le bloc `audit.entity` de
|
||||||
|
`frontend/i18n/locales/fr.json`.** C'est la contrepartie i18n de l'attribut : sans elle, le filtre
|
||||||
|
« Type d'entité » de l'audit-log affiche le type technique brut (ex: `commercial.Client`) au lieu d'un
|
||||||
|
libellé lisible.
|
||||||
|
|
||||||
|
Pourquoi : le filtre est dynamique (`GET /audit-log-entity-types` renvoie les `entity_type` distincts
|
||||||
|
présents en base) ; dès qu'un module audite une entité, son type y apparaît. Le front
|
||||||
|
(`formatEntityType`, `audit-log.vue`) construit la clé `audit.entity.<module>_<entity>` et, faute de
|
||||||
|
traduction, **retombe silencieusement** sur le type brut.
|
||||||
|
|
||||||
|
Dérivation de la clé (emplacement centralisé + schéma flat — décision ERP-99) :
|
||||||
|
|
||||||
|
| FQCN entité | `entity_type` (back) | Clé i18n (flat) |
|
||||||
|
|---|---|---|
|
||||||
|
| `App\Module\Commercial\Domain\Entity\Client` | `commercial.Client` | `commercial_client` |
|
||||||
|
| `App\Module\Commercial\Domain\Entity\ClientAddress` | `commercial.ClientAddress` | `commercial_clientaddress` |
|
||||||
|
| `App\Module\Catalog\Domain\Entity\Category` | `catalog.Category` | `catalog_category` |
|
||||||
|
|
||||||
|
Règle : `strtolower(module)` + `_` + `strtolower(Entity)`. Ajouter sa clé de libellé audit fait partie
|
||||||
|
de la **définition de fini** d'une entité métier auditée.
|
||||||
|
|
||||||
|
**Garde-fou** : `tests/Architecture/AuditableEntitiesHaveI18nLabelTest` scanne les entités `#[Auditable]`
|
||||||
|
et échoue si une seule n'a pas sa clé `audit.entity.*`. Conclusion : créer une entité `#[Auditable]`
|
||||||
|
sans son libellé i18n casse `make test`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Timestampable + Blamable (Garde-fou : `EntitiesAreTimestampableBlamableTest`)
|
||||||
|
|
||||||
|
Toute **nouvelle** entité métier sous `src/Module/*/Domain/Entity/` doit porter les 4 colonnes
|
||||||
|
`created_at` / `updated_at` / `created_by` / `updated_by`, remplies automatiquement. Trois lignes à
|
||||||
|
ajouter à l'entité :
|
||||||
|
|
||||||
|
```php
|
||||||
|
use App\Shared\Domain\Contract\BlamableInterface;
|
||||||
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||||
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||||
|
|
||||||
|
class MyEntity implements TimestampableInterface, BlamableInterface
|
||||||
|
{
|
||||||
|
use TimestampableBlamableTrait; // porte les 4 props + getters/setters
|
||||||
|
// ... reste métier
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Le `TimestampableBlamableSubscriber` (`Shared/Infrastructure/Doctrine/`) remplit les colonnes au
|
||||||
|
`prePersist` / `preUpdate`. Hors contexte HTTP (CLI, cron, migration), le blame reste `null`
|
||||||
|
(libellé « Système » côté front).
|
||||||
|
- La migration de l'entité doit créer les 4 colonnes (`created_at` / `updated_at` NOT NULL,
|
||||||
|
`created_by` / `updated_by` nullable `ON DELETE SET NULL`).
|
||||||
|
- **Garde-fou CI** : `tests/Architecture/EntitiesAreTimestampableBlamableTest` échoue si une entité
|
||||||
|
oublie le pattern. Un référentiel statique justifié (ex: `CategoryType`) doit être explicitement
|
||||||
|
whitelisté dans la constante `EXCLUDED` avec un commentaire.
|
||||||
|
- Spec complète : @docs/specs/M0-categories/spec-back.md § 2.8 + § 2.8.bis
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Migrations Doctrine — COMMENT ON COLUMN (Garde-fou : `ColumnsHaveSqlCommentTest`)
|
||||||
|
|
||||||
|
**Toute migration qui crée ou modifie une colonne d'une table métier doit poser un `COMMENT ON COLUMN`
|
||||||
|
décrivant le champ.** La description est stockée dans `pg_description` et visible dans tous les outils
|
||||||
|
d'admin BDD (DBeaver, DataGrip, pgAdmin), sans avoir à lire les annotations PHP.
|
||||||
|
|
||||||
|
**Format de la description** :
|
||||||
|
- En français
|
||||||
|
- ≤ 200 caractères
|
||||||
|
- Sémantique du champ — contraintes / lien RG si pertinent
|
||||||
|
- Pour les colonnes d'identifiant ou FK, mentionner la cible
|
||||||
|
|
||||||
|
Exemples :
|
||||||
|
|
||||||
|
```php
|
||||||
|
// Migration : création d'une colonne avec son commentaire dans la même migration
|
||||||
|
$this->addSql("ALTER TABLE client ADD COLUMN siren VARCHAR(9) DEFAULT NULL");
|
||||||
|
$this->addSql("COMMENT ON COLUMN client.siren IS 'SIREN (9 chiffres) — identifiant legal entreprise. Unique parmi non-archives (RG-1.15).'");
|
||||||
|
|
||||||
|
// Cas FK : préciser la cible
|
||||||
|
$this->addSql("COMMENT ON COLUMN client.legal_form_id IS 'Reference forme juridique (SARL, SAS, SA...) — FK -> legal_form.id, ON DELETE RESTRICT.'");
|
||||||
|
|
||||||
|
// Cas booléen : préciser le sens et la valeur par défaut
|
||||||
|
$this->addSql("COMMENT ON COLUMN user.is_admin IS 'Drapeau super-administrateur — bypass complet RBAC. Faux par defaut.'");
|
||||||
|
|
||||||
|
// Bonus : décrire la table elle-même
|
||||||
|
$this->addSql("COMMENT ON TABLE client IS 'Repertoire clients (M1 Commercial) — entites archivables.'");
|
||||||
|
```
|
||||||
|
|
||||||
|
### Helper Timestampable/Blamable
|
||||||
|
|
||||||
|
Les 4 colonnes `created_at`, `updated_at`, `created_by`, `updated_by` ajoutées par
|
||||||
|
`TimestampableBlamableTrait` reçoivent une description **standardisée** via le helper centralisé pour
|
||||||
|
éviter la duplication. Helper à créer ou appeler :
|
||||||
|
|
||||||
|
```php
|
||||||
|
// Dans la migration, après avoir ajouté les 4 colonnes :
|
||||||
|
$this->addStandardTimestampableBlamableComments($schema, 'client');
|
||||||
|
```
|
||||||
|
|
||||||
|
L'implémentation du helper applique :
|
||||||
|
- `created_at` : « Horodatage de creation de la ligne (UTC, rempli automatiquement par TimestampableBlamableSubscriber). »
|
||||||
|
- `updated_at` : « Horodatage de derniere modification de la ligne (UTC, rempli automatiquement par TimestampableBlamableSubscriber). »
|
||||||
|
- `created_by` : « ID de l'utilisateur ayant cree la ligne — null pour les creations hors HTTP (CLI, migration, fixture). FK -> user.id, ON DELETE SET NULL. »
|
||||||
|
- `updated_by` : « ID de l'utilisateur ayant modifie la ligne en dernier — null pour les modifications hors HTTP. FK -> user.id, ON DELETE SET NULL. »
|
||||||
|
|
||||||
|
### Garde-fou architecture
|
||||||
|
|
||||||
|
`tests/Architecture/ColumnsHaveSqlCommentTest` parcourt `information_schema.columns` filtré sur le
|
||||||
|
schéma `public` et échoue si **une seule colonne** n'a pas de `col_description`. Seules les tables
|
||||||
|
système (`doctrine_migration_versions`) et la whitelist `EXCLUDED_TABLES` explicite (commentaire de
|
||||||
|
justification + ticket Lesstime ouvert pour le retrofit) sont tolérées.
|
||||||
|
|
||||||
|
Conclusion : si tu crées une colonne sans poser son `COMMENT ON COLUMN`, `make test` casse en CI.
|
||||||
@@ -1,209 +1,362 @@
|
|||||||
# Starseed
|
# Starseed
|
||||||
|
|
||||||
CRM/ERP — Symfony 8 (API Platform 4) + Nuxt 4
|
CRM/ERP en architecture **modular monolith DDD** — Symfony 8 (API Platform 4) + Nuxt 4.
|
||||||
|
|
||||||
|
Le backend est la **source de vérité unique** : il décide des modules actifs et de
|
||||||
|
l'organisation de la sidebar. Le frontend scanne `frontend/modules/*/` comme layers
|
||||||
|
Nuxt et consomme l'API pour la navigation.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Sommaire
|
||||||
|
|
||||||
|
- [Stack](#stack)
|
||||||
|
- [Prérequis](#prérequis)
|
||||||
|
- [Démarrage rapide](#démarrage-rapide)
|
||||||
|
- [Dev local : avec ou sans données de seed](#dev-local--avec-ou-sans-données-de-seed)
|
||||||
|
- [Comptes (dev)](#comptes-dev)
|
||||||
|
- [Bases de données : dev et test](#bases-de-données--dev-et-test)
|
||||||
|
- [Tests](#tests)
|
||||||
|
- [Déploiement : seed RBAC en recette / prod](#déploiement--seed-rbac-en-recette--prod)
|
||||||
|
- [Commandes make](#commandes-make)
|
||||||
|
- [Architecture](#architecture)
|
||||||
|
- [Structure du dépôt](#structure-du-dépôt)
|
||||||
|
- [CI/CD](#cicd)
|
||||||
|
- [Conventions](#conventions)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
- **Backend** : PHP 8.4, Symfony 8, API Platform 4, Doctrine ORM, PostgreSQL 16
|
- **Backend** : PHP 8.4, Symfony 8, API Platform 4, Doctrine ORM, PostgreSQL 16
|
||||||
- **Frontend** : Nuxt 4 (SPA), Vue 3, Pinia, Tailwind CSS, @malio/layer-ui
|
- **Frontend** : Nuxt 4 (SPA, SSR off), Vue 3, Pinia, Tailwind CSS, @malio/layer-ui, @nuxtjs/i18n
|
||||||
- **Auth** : JWT HTTP-only cookie (Lexik)
|
- **Auth** : JWT HTTP-only cookie (Lexik), login sur `/login_check`
|
||||||
- **Infra** : Docker Compose (dev + prod multi-stage)
|
- **Infra** : Docker Compose (dev + prod multi-stage)
|
||||||
- **CI/CD** : Gitea Actions (auto-tag + build Docker)
|
- **CI/CD** : Gitea Actions (auto-tag + build Docker)
|
||||||
|
|
||||||
## Quick Start
|
| Service | Port |
|
||||||
|
|---------------|------|
|
||||||
|
| API (Nginx) | 8083 |
|
||||||
|
| Frontend dev | 3004 |
|
||||||
|
| PostgreSQL | 5437 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Prérequis
|
||||||
|
|
||||||
|
- Docker + Docker Compose
|
||||||
|
- `make`
|
||||||
|
- `nvm` (la version de Node est fixée par `.nvmrc`, voir `make node-use`)
|
||||||
|
|
||||||
|
Toutes les commandes `make` s'exécutent dans le container PHP (`php-starseed-fpm`) ;
|
||||||
|
rien n'est requis sur l'hôte hormis Docker — **sauf les tests E2E**, qui tournent sur
|
||||||
|
l'hôte (navigateur réel, voir [Tests](#tests)).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Démarrage rapide
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make start # Demarrer les containers Docker
|
make start # Démarre les containers Docker
|
||||||
make install # Composer, migrations, fixtures, build Nuxt
|
make install # Composer + clés JWT + migrations + permissions + BDD de test
|
||||||
|
make dev-nuxt # Serveur Nuxt avec hot reload (http://localhost:3004)
|
||||||
```
|
```
|
||||||
|
|
||||||
Dev frontend (hot reload) :
|
`make install` prépare une base de dev **vierge** (schéma + RBAC structurel, sans
|
||||||
|
données de démo) et la base de **test**. Pour obtenir des comptes et des données de
|
||||||
|
démo prêtes à l'emploi, lis la section suivante.
|
||||||
|
|
||||||
|
> Override local possible : `make` lit `infra/dev/.env.docker`, surchargé par
|
||||||
|
> `infra/dev/.env.docker.local` s'il existe (créé automatiquement par `make env-init`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Dev local : avec ou sans données de seed
|
||||||
|
|
||||||
|
Le projet distingue deux états de base de données de dev. Les **fixtures Doctrine sont
|
||||||
|
en `require-dev`** : elles n'existent qu'en dev, jamais dans le build de prod.
|
||||||
|
|
||||||
|
### Sans données de seed (base vierge)
|
||||||
|
|
||||||
|
C'est ce que produit `make install`. La base contient :
|
||||||
|
|
||||||
|
- le **schéma** complet (toutes les migrations jouées) ;
|
||||||
|
- les **rôles système** `admin` / `user` (seedés en SQL par la migration RBAC) ;
|
||||||
|
- le **catalogue de permissions** synchronisé (`app:sync-permissions`).
|
||||||
|
|
||||||
|
Mais **aucun compte utilisateur ni donnée métier**. Pour pouvoir te connecter,
|
||||||
|
crée toi-même un compte :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make dev-nuxt # Port 3003
|
make shell
|
||||||
|
php bin/console app:create-user admin monMotDePasse --admin # compte ROLE_ADMIN
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ports
|
Optionnel — provisionner les **rôles métier** (bureau / compta / commerciale / usine
|
||||||
|
+ matrice RBAC § 2.7) sans comptes de démo :
|
||||||
|
|
||||||
| Service | Port |
|
```bash
|
||||||
|------------|------|
|
php bin/console app:seed-rbac
|
||||||
| API (Nginx)| 8083 |
|
```
|
||||||
| Frontend | 3004 |
|
|
||||||
| PostgreSQL | 5437 |
|
|
||||||
|
|
||||||
## Commandes
|
Cet état est utile pour repartir d'une base propre, reproduire un bug sur données
|
||||||
|
minimales, ou tester un parcours d'onboarding réel.
|
||||||
|
|
||||||
| Commande | Description |
|
### Avec données de seed (base de démo)
|
||||||
|----------|-------------|
|
|
||||||
| `make start` | Demarrer les containers |
|
`make db-reset` (ou `make fixtures` après un `make install`) recharge la base de dev
|
||||||
| `make stop` | Arreter les containers |
|
avec un jeu complet de données de démonstration, **idempotent** :
|
||||||
| `make restart` | Redemarrer les containers |
|
|
||||||
| `make install` | Install complet |
|
```bash
|
||||||
| `make reset` | Tout supprimer et reinstaller |
|
make db-reset # ATTENTION : drop + recrée la base de dev, puis charge tout le seed
|
||||||
| `make dev-nuxt` | Serveur dev Nuxt (hot reload) |
|
```
|
||||||
| `make shell` | Shell dans le container PHP |
|
|
||||||
| `make cache-clear` | Vider le cache Symfony |
|
Ce que les fixtures posent :
|
||||||
| `make migration-migrate` | Lancer les migrations |
|
|
||||||
| `make fixtures` | Charger les fixtures |
|
- **3 utilisateurs système** : `admin` (ROLE_ADMIN), `alice`, `bob` (ROLE_USER),
|
||||||
| `make db-reset` | Reset BDD + migrations + fixtures |
|
rattachés à des sites distincts ;
|
||||||
| `make test` | PHPUnit (tests back) |
|
- **3 sites** : Chatellerault, Saint-Jean, Pommevic ;
|
||||||
| `make nuxt-test` | Vitest (tests unitaires front) |
|
- **les comptes de démo RBAC métier** (`bureau`, `compta`, `commerciale`, `usine`,
|
||||||
| `make test-e2e` | Playwright (tests E2E front) |
|
mot de passe `demo`) avec la matrice § 2.7 attachée ;
|
||||||
| `make test-e2e-ui` | Playwright UI interactive (debug) |
|
- les **référentiels et données métier** des modules (catégories, clients de démo,
|
||||||
| `make seed-e2e` | Seed les 6 personas E2E |
|
référentiels comptables…).
|
||||||
| `make install-e2e-deps` | One-time : Chromium + libs systeme (sudo) |
|
|
||||||
| `make php-cs-fixer-allow-risky` | Fix code style PHP |
|
Toutes les fixtures sont rejouables sans effet de bord (lookup par clé naturelle,
|
||||||
| `make logs-dev` | Tail logs Symfony |
|
aucun doublon).
|
||||||
|
|
||||||
|
> Différence avec `make install` : `install` ne charge **pas** les fixtures sur la base
|
||||||
|
> de dev (il alimente uniquement la base de test). Utilise `make db-reset` ou
|
||||||
|
> `make fixtures` quand tu veux des données de démo en dev.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Comptes (dev)
|
||||||
|
|
||||||
|
Disponibles uniquement après `make db-reset` / `make fixtures` (état « avec seed ») :
|
||||||
|
|
||||||
|
| Username | Password | Rôle | RBAC métier |
|
||||||
|
|---------------|----------|------------|---------------------------------------------------------------|
|
||||||
|
| `admin` | `admin` | ROLE_ADMIN | bypass complet (`is_admin`) |
|
||||||
|
| `alice` | `alice` | ROLE_USER | — |
|
||||||
|
| `bob` | `bob` | ROLE_USER | — |
|
||||||
|
| `bureau` | `demo` | ROLE_USER | clients : view + manage |
|
||||||
|
| `compta` | `demo` | ROLE_USER | clients : view + accounting.view / manage |
|
||||||
|
| `commerciale` | `demo` | ROLE_USER | clients : view + manage (Information obligatoire — RG-1.04) |
|
||||||
|
| `usine` | `demo` | ROLE_USER | aucun accès clients |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Bases de données : dev et test
|
||||||
|
|
||||||
|
Deux bases distinctes vivent dans le **même container PostgreSQL** (port 5437) :
|
||||||
|
|
||||||
|
| Base | Environnement | Construite par | Usage |
|
||||||
|
|------------|---------------|--------------------------------------|--------------------------------|
|
||||||
|
| `<db>` | `dev` | `make install` / `make db-reset` | développement manuel, dev-nuxt |
|
||||||
|
| `<db>_test` | `test` | `make test-db-setup` | PHPUnit (jamais touchée à la main) |
|
||||||
|
|
||||||
|
Le suffixe `_test` est appliqué **automatiquement** par Doctrine quand `APP_ENV=test`
|
||||||
|
(config `when@test` dans `config/packages/doctrine.yaml`). La base de test est donc
|
||||||
|
totalement **isolée** de la base de dev : lancer `make test` ne touche jamais tes
|
||||||
|
données de dev.
|
||||||
|
|
||||||
|
`make test-db-setup` fait davantage que jouer les migrations, car certaines structures
|
||||||
|
ne sont pas portées par des migrations « métier » :
|
||||||
|
|
||||||
|
1. `doctrine:migrations:migrate` — schéma métier réel ;
|
||||||
|
2. `doctrine:schema:update --force` — crée les tables mappées en `when@test`
|
||||||
|
uniquement (entités de test) ;
|
||||||
|
3. `app:apply-column-comments` — réapplique les `COMMENT ON COLUMN` que
|
||||||
|
`schema:update` efface sur les tables managées par l'ORM (garde-fou
|
||||||
|
`ColumnsHaveSqlCommentTest`) ;
|
||||||
|
4. `fixtures:load` → `sync-permissions` → `seed-rbac` — dans cet ordre précis
|
||||||
|
(le purger des fixtures vide la table `permission`, donc la sync passe après) ;
|
||||||
|
5. recréation des **index partiels uniques** (`LOWER(...) WHERE ...`) non exprimables
|
||||||
|
en attributs ORM, indispensables aux tests d'unicité (RG-1.07, RG-1.16, RG-1.03/1.29).
|
||||||
|
|
||||||
|
`make install` et `make db-reset` appellent déjà `test-db-setup` : tu n'as à le
|
||||||
|
relancer à la main que si la base de test diverge (nouvelle migration, nouvelle
|
||||||
|
permission) sans vouloir reseed la base de dev.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
- **Back** : `make test` (PHPUnit). Fixtures dediees sous `tests/Fixtures/`.
|
| Suite | Commande | Outil | Où |
|
||||||
- **Front unitaire** : `make nuxt-test` (Vitest, happy-dom). Composables, utils, stores — rapide, <30s.
|
|-------------------|------------------|----------------------|-----------------------------------|
|
||||||
- **Front E2E** : `make test-e2e` (Playwright). Couvre login + matrice RBAC sidebar. Suite volontairement minimaliste (11 tests) — voir la regle d'or dans `CLAUDE.md`.
|
| Back | `make test` | PHPUnit | container PHP, base `<db>_test` |
|
||||||
|
| Front unitaire | `make nuxt-test` | Vitest (happy-dom) | container Node, < 30 s |
|
||||||
|
| Front E2E | `make test-e2e` | Playwright | **hôte** (navigateur réel requis) |
|
||||||
|
| Tout (back+front) | `make test-all` | PHPUnit + Vitest | — |
|
||||||
|
|
||||||
|
### Tests back (PHPUnit)
|
||||||
|
|
||||||
**Bootstrap E2E (une fois par poste)** :
|
|
||||||
```bash
|
```bash
|
||||||
make install-e2e-deps # Telecharge Chromium + libs systeme via apt (sudo)
|
make test # toute la suite
|
||||||
|
make test FILES=tests/Module/Commercial # un dossier / fichier ciblé
|
||||||
```
|
```
|
||||||
|
|
||||||
**Workflow E2E** :
|
PHPUnit force `APP_ENV=test` (`phpunit.dist.xml`) : les tests tournent **toujours**
|
||||||
|
sur la base `<db>_test`, jamais sur la base de dev. Prérequis : que la base de test
|
||||||
|
existe — c'est le cas après `make install`. Si elle a divergé, rejoue
|
||||||
|
`make test-db-setup` (cf. [Bases de données](#bases-de-données--dev-et-test)).
|
||||||
|
|
||||||
|
### Tests front unitaires (Vitest)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Terminal 1 : containers + dev server
|
make nuxt-test # composables, utils, stores — rapide et stable
|
||||||
|
```
|
||||||
|
|
||||||
|
C'est la **place par défaut** pour étendre la couverture (cf. règle d'or ci-dessous).
|
||||||
|
|
||||||
|
### Tests E2E (Playwright)
|
||||||
|
|
||||||
|
Suite volontairement minimaliste (login + matrice RBAC sidebar). **Règle d'or : un
|
||||||
|
nouveau test E2E ne s'ajoute que si un bug critique est passé en prod** — sinon,
|
||||||
|
préférer un test Vitest ou étendre un persona existant.
|
||||||
|
|
||||||
|
Bootstrap (une fois par poste) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make install-e2e-deps # télécharge Chromium + libs système (apt/dnf, sudo)
|
||||||
|
```
|
||||||
|
|
||||||
|
Workflow :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Terminal 1 — containers, seed des personas, serveur dev
|
||||||
make start && make seed-e2e && make dev-nuxt
|
make start && make seed-e2e && make dev-nuxt
|
||||||
|
|
||||||
# Terminal 2 : tests
|
# Terminal 2 — tests
|
||||||
make test-e2e
|
make test-e2e # headless
|
||||||
|
make test-e2e-ui # UI interactive (debug)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> Toute permission testable touche **3 miroirs** à garder alignés : `config/sidebar.php`,
|
||||||
|
> `frontend/tests/e2e/_fixtures/personas.ts`, `SeedE2ECommand.php`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Déploiement : seed RBAC en recette / prod
|
||||||
|
|
||||||
|
Les fixtures Doctrine étant en `require-dev`, elles sont **absentes du build de prod**.
|
||||||
|
Le RBAC métier (rôles `bureau` / `compta` / `commerciale` / `usine` + matrice § 2.7)
|
||||||
|
est seedé par une **commande applicative idempotente**, jouée dans l'étape de release,
|
||||||
|
**après** les migrations et la synchronisation des permissions :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php bin/console doctrine:migrations:migrate --no-interaction
|
||||||
|
php bin/console app:sync-permissions # pose les permissions (commercial.clients.*, …)
|
||||||
|
php bin/console app:seed-rbac # PROD : rôles + matrice § 2.7 (sans comptes démo)
|
||||||
|
```
|
||||||
|
|
||||||
|
En **recette / staging**, ajouter le flag pour disposer de logins de test. Le mot de
|
||||||
|
passe est fourni **explicitement** (jamais en dur, jamais committé) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php bin/console app:seed-rbac --with-demo-users --password='<mot-de-passe>'
|
||||||
|
# ou via la variable d'environnement RBAC_DEMO_PASSWORD
|
||||||
|
```
|
||||||
|
|
||||||
|
La commande est rejouable sans effet de bord (aucun doublon de rôle, de lien ou de
|
||||||
|
compte). Pour créer un premier administrateur en prod :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php bin/console app:create-user <username> <password> --admin
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Commandes make
|
||||||
|
|
||||||
|
`make` (sans argument) ou `make help` affiche l'aide colorée. Les principales :
|
||||||
|
|
||||||
|
| Commande | Description |
|
||||||
|
|--------------------------------|----------------------------------------------------------|
|
||||||
|
| `make start` / `stop` / `restart` | Cycle de vie des containers |
|
||||||
|
| `make install` | Install complet (base dev vierge + base de test) |
|
||||||
|
| `make reset` | Tout supprimer et réinstaller (**drop la BDD**) |
|
||||||
|
| `make dev-nuxt` | Serveur Nuxt hot reload (port 3004) |
|
||||||
|
| `make shell` / `shell-root` | Shell bash dans le container PHP |
|
||||||
|
| `make migration-migrate` | Jouer les migrations Doctrine |
|
||||||
|
| `make fixtures` | Charger les fixtures (données de démo dev) |
|
||||||
|
| `make sync-permissions` | Synchroniser le catalogue RBAC |
|
||||||
|
| `make seed-rbac` | Seed RBAC métier (rôles + matrice § 2.7) |
|
||||||
|
| `make db-reset` | Reset base dev : drop + migrate + fixtures + RBAC |
|
||||||
|
| `make test-db-setup` | (Re)construire la base de test |
|
||||||
|
| `make test` | PHPUnit (back) |
|
||||||
|
| `make nuxt-test` | Vitest (front unitaire) |
|
||||||
|
| `make test-all` | PHPUnit + Vitest |
|
||||||
|
| `make test-e2e` / `test-e2e-ui`| Playwright (E2E, sur l'hôte) |
|
||||||
|
| `make seed-e2e` | Seed des 6 personas E2E |
|
||||||
|
| `make php-cs-fixer-allow-risky`| Fix du code style PHP |
|
||||||
|
| `make php-cs-fixer-check` | Dry-run du fixer (CI / avant push) |
|
||||||
|
| `make logs-dev` | Tail des logs Symfony |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
**Modular Monolith DDD** : chaque module est un bounded context autonome, activable/desactivable par tenant. Le backend est la seule source de verite pour l'activation et l'organisation de la sidebar.
|
**Modular Monolith DDD** : chaque module est un bounded context autonome,
|
||||||
|
activable / désactivable par tenant. Le backend est la seule source de vérité pour
|
||||||
|
l'activation des modules et l'organisation de la sidebar.
|
||||||
|
|
||||||
- `config/modules.php` — liste des modules actifs
|
- `config/modules.php` — liste des modules actifs
|
||||||
- `config/sidebar.php` — structure de la sidebar (sections + items avec module owner)
|
- `config/sidebar.php` — structure de la sidebar (sections + items avec module owner)
|
||||||
- `GET /api/sidebar` — retourne les sections filtrees par les modules actifs + les routes desactivees
|
- `GET /api/modules` — IDs des modules actifs (public)
|
||||||
- Frontend : chaque `frontend/modules/*/` est auto-detecte comme layer Nuxt, la sidebar est fetchee de l'API
|
- `GET /api/sidebar` — sections filtrées par modules actifs + routes désactivées (public)
|
||||||
|
|
||||||
Pour desactiver un module : commenter sa ligne dans `config/modules.php`, clear cache. Ses items de sidebar disparaissent et ses routes sont bloquees par le middleware front.
|
**Désactiver un module** : commenter sa ligne dans `config/modules.php`, vider le cache.
|
||||||
|
Ses items de sidebar disparaissent et ses routes sont bloquées par le middleware front.
|
||||||
|
Le code reste dans le bundle (layer auto-détecté) → réactivation instantanée.
|
||||||
|
|
||||||
Pour reorganiser la sidebar (ex: deplacer un item d'une section a l'autre) : editer `config/sidebar.php` uniquement, le code des modules n'est pas touche.
|
**Réorganiser la sidebar** : éditer `config/sidebar.php` uniquement — le code des
|
||||||
|
modules n'est pas touché.
|
||||||
|
|
||||||
## Structure
|
**Communication inter-modules** : jamais d'import direct d'un module à l'autre. Passer
|
||||||
|
par `Shared/Domain/Contract/` (interfaces) ou des domain events.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Structure du dépôt
|
||||||
|
|
||||||
```
|
```
|
||||||
src/ # Backend Symfony
|
src/ # Backend Symfony
|
||||||
Kernel.php
|
Shared/ # Noyau technique partagé (Domain/, Application/Bus/, Infrastructure/ApiPlatform/)
|
||||||
Shared/ # Noyau technique partage
|
|
||||||
Domain/
|
|
||||||
ValueObject/ # Email, ...
|
|
||||||
Event/ # DomainEventInterface
|
|
||||||
Contract/ # Interfaces inter-modules
|
|
||||||
Application/
|
|
||||||
Bus/ # CommandBusInterface, QueryBusInterface
|
|
||||||
Infrastructure/
|
|
||||||
ApiPlatform/
|
|
||||||
Resource/ # AppVersion, ModulesResource, SidebarResource
|
|
||||||
State/ # AppVersionProvider, ModulesProvider, SidebarProvider
|
|
||||||
Module/
|
Module/
|
||||||
Core/ # Module obligatoire (auth, users)
|
Core/ # Module obligatoire (auth, users, RBAC)
|
||||||
CoreModule.php # Declaration (ID, LABEL, REQUIRED)
|
CoreModule.php # Déclaration (ID, LABEL, REQUIRED, permissions())
|
||||||
Domain/
|
Domain/ Application/ Infrastructure/
|
||||||
Entity/ # User
|
Commercial/ Catalog/ Sites/ # Modules métier
|
||||||
Repository/ # UserRepositoryInterface
|
|
||||||
Event/ # UserCreated
|
|
||||||
Application/
|
|
||||||
DTO/ # UserOutput
|
|
||||||
Infrastructure/
|
|
||||||
Doctrine/ # DoctrineUserRepository, Migrations/
|
|
||||||
ApiPlatform/State/
|
|
||||||
Provider/ # MeProvider
|
|
||||||
Processor/ # UserPasswordHasherProcessor
|
|
||||||
Console/ # CreateUserCommand
|
|
||||||
DataFixtures/ # AppFixtures
|
|
||||||
Commercial/ # Autre module (exemple)
|
|
||||||
CommercialModule.php
|
|
||||||
config/
|
config/
|
||||||
modules.php # Source de verite activation
|
modules.php # Source de vérité : activation
|
||||||
sidebar.php # Source de verite navigation
|
sidebar.php # Source de vérité : navigation
|
||||||
version.yaml
|
packages/ # Config Symfony (doctrine, api_platform, security…)
|
||||||
packages/ # Config Symfony
|
migrations/ # Migrations d'initialisation (namespace racine : setup, RBAC, seed de base)
|
||||||
jwt/ # Cles JWT
|
|
||||||
migrations/ # Anciennes migrations
|
|
||||||
frontend/ # App Nuxt 4 (SPA)
|
frontend/ # App Nuxt 4 (SPA)
|
||||||
app/
|
app/ # Shell : layouts, middlewares (auth.global, modules.global)
|
||||||
layouts/ # default.vue, auth.vue
|
shared/ # Code inter-modules (composables, stores, utils, types)
|
||||||
middleware/ # auth.global.ts, modules.global.ts
|
modules/ # Layers Nuxt auto-détectés (core/, commercial/…)
|
||||||
shared/ # Code partage (hors modules)
|
i18n/locales/ # Traductions (sidebar.*, audit.entity.*, …)
|
||||||
composables/ # useApi, useAppVersion, useSidebar
|
|
||||||
components/ui/ # AppTopNav, ...
|
|
||||||
stores/ # auth, ui
|
|
||||||
services/ # auth
|
|
||||||
types/ # SidebarSection, UserData
|
|
||||||
utils/ # api (Hydra)
|
|
||||||
modules/ # Modules auto-detectes comme layers Nuxt
|
|
||||||
core/
|
|
||||||
nuxt.config.ts # Marqueur layer
|
|
||||||
pages/ # index, login, logout
|
|
||||||
commercial/
|
|
||||||
nuxt.config.ts
|
|
||||||
pages/ # commercial.vue
|
|
||||||
app.vue
|
|
||||||
nuxt.config.ts # Scanne modules/*/ automatiquement
|
|
||||||
i18n/locales/ # Traductions (sidebar.*, etc.)
|
|
||||||
assets/ # CSS, images
|
|
||||||
public/ # Fichiers statiques
|
|
||||||
infra/
|
infra/
|
||||||
dev/ # Docker dev (Dockerfile, nginx, php.ini, xdebug)
|
dev/ # Docker dev (Dockerfile, nginx, php.ini, xdebug, .env.docker)
|
||||||
prod/ # Docker prod (multi-stage, nginx, php-prod.ini)
|
prod/ # Docker prod (multi-stage, nginx, php-prod.ini)
|
||||||
.gitea/workflows/ # CI Gitea (auto-tag, build Docker)
|
.gitea/workflows/ # CI Gitea (auto-tag, build Docker)
|
||||||
.claude/
|
|
||||||
skills/create-module/ # Skill Claude Code pour scaffolder un module
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## CI/CD
|
## CI/CD
|
||||||
|
|
||||||
- **Auto Tag** : push sur `develop` → bump `config/version.yaml` → tag `vX.Y.Z`
|
- **Auto Tag** : push sur `develop` → bump `config/version.yaml` → tag `vX.Y.Z`
|
||||||
- **Build Docker** : push tag `v*` → build image multi-stage → push Gitea Registry
|
- **Build Docker** : push tag `v*` → build image multi-stage → push Gitea Registry
|
||||||
|
|
||||||
Secrets requis dans Gitea :
|
Secrets requis dans Gitea :
|
||||||
|
|
||||||
- `RELEASE_TOKEN` — PAT avec droits `write:repository`
|
- `RELEASE_TOKEN` — PAT avec droits `write:repository`
|
||||||
- `REGISTRY_TOKEN` — token pour le registry Docker
|
- `REGISTRY_TOKEN` — token pour le registry Docker
|
||||||
|
|
||||||
## Déploiement — seed RBAC (recette / prod)
|
---
|
||||||
|
|
||||||
Le RBAC métier (rôles `bureau` / `compta` / `commerciale` / `usine` + matrice § 2.7)
|
|
||||||
est seedé par une **commande applicative idempotente** (présente dans le build prod,
|
|
||||||
contrairement aux fixtures Doctrine en `require-dev`). À jouer dans l'étape de release,
|
|
||||||
**après** les migrations et la synchronisation des permissions :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
php bin/console doctrine:migrations:migrate --no-interaction
|
|
||||||
php bin/console app:sync-permissions # pose les permissions commercial.clients.*
|
|
||||||
php bin/console app:seed-rbac # PROD : rôles + matrice § 2.7 (sans comptes démo)
|
|
||||||
```
|
|
||||||
|
|
||||||
En **recette / staging**, ajouter le flag pour disposer de logins de test (mot de passe
|
|
||||||
fourni explicitement, jamais en dur) :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
php bin/console app:seed-rbac --with-demo-users --password='<mot-de-passe>'
|
|
||||||
# ou via la variable d'env RBAC_DEMO_PASSWORD
|
|
||||||
```
|
|
||||||
|
|
||||||
La commande est rejouable sans effet de bord (aucun doublon de rôle, de lien ou de compte).
|
|
||||||
En dev, `make db-reset` produit le même résultat (rôles + matrice + comptes démo).
|
|
||||||
|
|
||||||
## Credentials (dev)
|
|
||||||
|
|
||||||
| Username | Password | Role | RBAC métier |
|
|
||||||
|----------|----------|------|-------------|
|
|
||||||
| admin | admin | ROLE_ADMIN | bypass (is_admin) |
|
|
||||||
| alice | alice | ROLE_USER | — |
|
|
||||||
| bob | bob | ROLE_USER | — |
|
|
||||||
| bureau | demo | ROLE_USER | clients : view + manage |
|
|
||||||
| compta | demo | ROLE_USER | clients : view + accounting.view/manage |
|
|
||||||
| commerciale | demo | ROLE_USER | clients : view + manage (Information obligatoire — RG-1.04) |
|
|
||||||
| usine | demo | ROLE_USER | aucun accès clients |
|
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
@@ -213,4 +366,13 @@ En dev, `make db-reset` produit le même résultat (rôles + matrice + comptes d
|
|||||||
<type>(<scope optionnel>) : <message>
|
<type>(<scope optionnel>) : <message>
|
||||||
```
|
```
|
||||||
|
|
||||||
Types : `build`, `chore`, `ci`, `docs`, `feat`, `fix`, `perf`, `refactor`, `revert`, `style`, `test`
|
Espaces obligatoires autour du `:`. Types : `build`, `chore`, `ci`, `docs`, `feat`,
|
||||||
|
`fix`, `perf`, `refactor`, `revert`, `style`, `test`.
|
||||||
|
|
||||||
|
### Langue
|
||||||
|
|
||||||
|
- UI et communication : **français**
|
||||||
|
- Code (classes, méthodes, variables) : **anglais**
|
||||||
|
- Commentaires (PHP, TS, Vue) : **français**
|
||||||
|
|
||||||
|
> Règles détaillées : `CLAUDE.md` et `.claude/rules/`.
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
"symfony/runtime": "8.0.*",
|
"symfony/runtime": "8.0.*",
|
||||||
"symfony/security-bundle": "8.0.*",
|
"symfony/security-bundle": "8.0.*",
|
||||||
"symfony/serializer": "8.0.*",
|
"symfony/serializer": "8.0.*",
|
||||||
|
"symfony/translation": "8.0.*",
|
||||||
"symfony/twig-bundle": "8.0.*",
|
"symfony/twig-bundle": "8.0.*",
|
||||||
"symfony/uid": "8.0.*",
|
"symfony/uid": "8.0.*",
|
||||||
"symfony/validator": "8.0.*",
|
"symfony/validator": "8.0.*",
|
||||||
|
|||||||
Generated
+94
-1
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "aada2e60fd7563f1498b5505b37e3f4b",
|
"content-hash": "2dc5db01e7f5d6aecd5956749b21a092",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "api-platform/doctrine-common",
|
"name": "api-platform/doctrine-common",
|
||||||
@@ -7657,6 +7657,99 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-03-30T15:14:47+00:00"
|
"time": "2026-03-30T15:14:47+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/translation",
|
||||||
|
"version": "v8.0.10",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/translation.git",
|
||||||
|
"reference": "f63e9342e12646a57c91ef8a366a4f9d8e557b67"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/translation/zipball/f63e9342e12646a57c91ef8a366a4f9d8e557b67",
|
||||||
|
"reference": "f63e9342e12646a57c91ef8a366a4f9d8e557b67",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.4",
|
||||||
|
"symfony/polyfill-mbstring": "^1.0",
|
||||||
|
"symfony/translation-contracts": "^3.6.1"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"nikic/php-parser": "<5.0",
|
||||||
|
"symfony/http-client-contracts": "<2.5",
|
||||||
|
"symfony/service-contracts": "<2.5"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"symfony/translation-implementation": "2.3|3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"nikic/php-parser": "^5.0",
|
||||||
|
"psr/log": "^1|^2|^3",
|
||||||
|
"symfony/config": "^7.4|^8.0",
|
||||||
|
"symfony/console": "^7.4|^8.0",
|
||||||
|
"symfony/dependency-injection": "^7.4|^8.0",
|
||||||
|
"symfony/finder": "^7.4|^8.0",
|
||||||
|
"symfony/http-client-contracts": "^2.5|^3.0",
|
||||||
|
"symfony/http-kernel": "^7.4|^8.0",
|
||||||
|
"symfony/intl": "^7.4|^8.0",
|
||||||
|
"symfony/polyfill-intl-icu": "^1.21",
|
||||||
|
"symfony/routing": "^7.4|^8.0",
|
||||||
|
"symfony/service-contracts": "^2.5|^3",
|
||||||
|
"symfony/yaml": "^7.4|^8.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"Resources/functions.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Component\\Translation\\": ""
|
||||||
|
},
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"/Tests/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Provides tools to internationalize your application",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/translation/tree/v8.0.10"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nicolas-grekas",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-05-06T11:30:54+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/translation-contracts",
|
"name": "symfony/translation-contracts",
|
||||||
"version": "v3.6.1",
|
"version": "v3.6.1",
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
framework:
|
||||||
|
# Locale par defaut FR (ERP-107) : les messages natifs des contraintes
|
||||||
|
# Symfony (Email, NotBlank, Length, Iban, Bic...) sont alors servis en
|
||||||
|
# francais via validators.fr.xlf. C'est le FILET ; les contraintes metier
|
||||||
|
# portent en plus un `message:` FR explicite, teste par
|
||||||
|
# tests/Architecture/EntityConstraintsHaveFrenchMessageTest.
|
||||||
|
default_locale: fr
|
||||||
|
translator:
|
||||||
|
default_path: '%kernel.project_dir%/translations'
|
||||||
|
fallbacks:
|
||||||
|
- fr
|
||||||
|
providers:
|
||||||
+22
-19
@@ -38,6 +38,28 @@ declare(strict_types=1);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
// Section "Commerciale" : pole metier principal, remontee en tete de sidebar (ERP-71).
|
||||||
|
// L'ordre interne des onglets et les permissions restent inchanges (simple deplacement
|
||||||
|
// du bloc, aucun gate touche).
|
||||||
|
[
|
||||||
|
'label' => 'sidebar.commercial.section',
|
||||||
|
'icon' => 'mdi:account-arrow-left-outline',
|
||||||
|
'items' => [
|
||||||
|
[
|
||||||
|
'label' => 'sidebar.commercial.clients',
|
||||||
|
'to' => '/clients',
|
||||||
|
'icon' => 'mdi:account-group-outline',
|
||||||
|
'module' => 'commercial',
|
||||||
|
'permission' => 'commercial.clients.view',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'label' => 'sidebar.commercial.suppliers',
|
||||||
|
'to' => '/suppliers',
|
||||||
|
'icon' => 'mdi:account-arrow-left-outline',
|
||||||
|
'module' => 'commercial',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
// Section "Administration" : regroupe toutes les pages de configuration
|
// Section "Administration" : regroupe toutes les pages de configuration
|
||||||
// applicative (RBAC, users, sites, audit log).
|
// applicative (RBAC, users, sites, audit log).
|
||||||
//
|
//
|
||||||
@@ -99,25 +121,6 @@ return [
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'label' => 'sidebar.commercial.section',
|
|
||||||
'icon' => 'mdi:account-arrow-left-outline',
|
|
||||||
'items' => [
|
|
||||||
[
|
|
||||||
'label' => 'sidebar.commercial.clients',
|
|
||||||
'to' => '/clients',
|
|
||||||
'icon' => 'mdi:account-group-outline',
|
|
||||||
'module' => 'commercial',
|
|
||||||
'permission' => 'commercial.clients.view',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'label' => 'sidebar.commercial.suppliers',
|
|
||||||
'to' => '/suppliers',
|
|
||||||
'icon' => 'mdi:account-arrow-left-outline',
|
|
||||||
'module' => 'commercial',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// Section "Mon compte" : espace personnel. Accessible a tout user authentifie
|
// Section "Mon compte" : espace personnel. Accessible a tout user authentifie
|
||||||
// (aucune permission RBAC requise, tous les items restent dans `core` pour
|
// (aucune permission RBAC requise, tous les items restent dans `core` pour
|
||||||
// rester toujours presents meme quand les modules metier sont desactives).
|
// rester toujours presents meme quand les modules metier sont desactives).
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.69'
|
app.version: '0.1.83'
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
# Validation « tous les blocs » sur les onglets à blocs dynamiques (Client M1)
|
||||||
|
|
||||||
|
> Date : 2026-06-04 · Module : Commercial (M1 Clients) · Tickets liés : ERP-101 / ERP-107
|
||||||
|
> Écrans : `clients/new.vue`, `clients/[id]/edit.vue` · Onglets concernés : Contacts, Adresses, RIB
|
||||||
|
|
||||||
|
## 1. Problème
|
||||||
|
|
||||||
|
À la soumission des onglets à **blocs d'ajout dynamiques** (Contacts / Adresses / RIB), la validation
|
||||||
|
par champ ne s'affiche pas correctement. Deux causes **distinctes et cumulées** :
|
||||||
|
|
||||||
|
### Cause A — 500 back qui court-circuite la validation (cause racine)
|
||||||
|
|
||||||
|
Les opérations `Post` des sous-ressources sont déclarées ainsi :
|
||||||
|
|
||||||
|
```php
|
||||||
|
new Post(
|
||||||
|
uriTemplate: '/clients/{clientId}/contacts',
|
||||||
|
uriVariables: ['clientId' => new Link(fromClass: Client::class, toProperty: 'client')],
|
||||||
|
processor: ClientContactProcessor::class,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Au stade « read » du POST, API Platform résout `clientId` via `LinksHandlerTrait` (branche `toProperty`,
|
||||||
|
`vendor/api-platform/doctrine-orm/State/LinksHandlerTrait.php:134-141`). La requête générée porte sur
|
||||||
|
l'entité **enfant** :
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT o FROM ClientContact o INNER JOIN o.client c WHERE c.id = :clientId
|
||||||
|
```
|
||||||
|
|
||||||
|
exécutée via `ItemProvider::provide` → `getOneOrNullResult()`
|
||||||
|
(`vendor/api-platform/doctrine-orm/State/ItemProvider.php:89`). Donc :
|
||||||
|
|
||||||
|
| Nb d'enfants du client | Lignes retournées | Résultat |
|
||||||
|
|---|---|---|
|
||||||
|
| 0 | 0 | `null` → OK (cas du test CI actuel) |
|
||||||
|
| 1 | 1 | OK |
|
||||||
|
| **≥ 2** | **≥ 2** | **`NonUniqueResultException` → HTTP 500** |
|
||||||
|
|
||||||
|
Conséquence : un client à ≥2 contacts (resp. adresses, RIB) ne peut plus en recevoir un nouveau.
|
||||||
|
La 500 survient **avant** la déserialisation/validation → aucune 422 n'est produite → `mapRowError`
|
||||||
|
(qui ne mappe que les 422) retombe sur un toast générique.
|
||||||
|
|
||||||
|
Les **3** sous-ressources ont strictement la même config → même bug latent (contacts est juste le
|
||||||
|
premier à sauter car les clients de démo ont 3 contacts).
|
||||||
|
|
||||||
|
### Cause B — la boucle front s'arrête au premier bloc en erreur
|
||||||
|
|
||||||
|
`submitContacts` / `submitAddresses` / boucle RIB de `submitAccounting` (dans `new.vue` ET `edit.vue`)
|
||||||
|
font `return` dans le `catch` du premier bloc en échec :
|
||||||
|
|
||||||
|
```js
|
||||||
|
catch (error) {
|
||||||
|
if (!mapRowError(error, contactErrors, index)) { toast(...) }
|
||||||
|
return // ← stoppe : les blocs suivants ne sont jamais validés ni affichés
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
→ même une fois le 500 corrigé, seules les erreurs du **premier** bloc fautif s'afficheraient.
|
||||||
|
|
||||||
|
## 2. Objectif
|
||||||
|
|
||||||
|
À la validation d'un onglet collection, **tenter tous les blocs** et **afficher l'erreur inline sous
|
||||||
|
chaque champ fautif, pour chaque bloc**, en un seul aller-retour de soumission. Pas de toast récapitulatif
|
||||||
|
(décision : inline seul, cohérent ERP-101). Pas de toast succès tant qu'au moins un bloc reste en erreur.
|
||||||
|
|
||||||
|
Hors périmètre : le workflow incrémental (créer le client, puis débloquer les onglets) reste inchangé ;
|
||||||
|
les onglets scalaires (Principal / Information / Comptabilité-scalaires) fonctionnent déjà et ne sont pas
|
||||||
|
touchés.
|
||||||
|
|
||||||
|
## 3. Conception
|
||||||
|
|
||||||
|
### 3.1 Back — supprimer le read cassé du POST (cause racine)
|
||||||
|
|
||||||
|
Sur les opérations `Post` de `ClientContact`, `ClientAddress`, `ClientRib` :
|
||||||
|
|
||||||
|
- Ajouter **`read: false`**. Le stade « read » est inutile : le `*Processor::linkParent` rattache déjà le
|
||||||
|
parent manuellement via `$em->getRepository(Client::class)->find($clientId)`. Pattern déjà employé dans
|
||||||
|
le projet (`Sites/.../CurrentSiteResource.php`).
|
||||||
|
- Durcir les 3 `linkParent` : si `find($clientId)` renvoie `null`, lever
|
||||||
|
`Symfony\Component\HttpKernel\Exception\NotFoundHttpException` (préserve le **404** sur parent
|
||||||
|
inexistant — sans le read, on régresserait sinon en 500 au persist sur `client_id NOT NULL`).
|
||||||
|
|
||||||
|
Effet : plus de `getOneOrNullResult` foireux → déserialisation + validation Symfony s'exécutent → **422
|
||||||
|
propre par champ** avec `violations[].propertyPath` (déjà garanti par ERP-107 : messages FR explicites).
|
||||||
|
|
||||||
|
Aucune autre modification (security, normalizationContext, processor restant) n'est nécessaire.
|
||||||
|
|
||||||
|
### 3.2 Front — collecter les erreurs de tous les blocs
|
||||||
|
|
||||||
|
Dans `submitContacts`, `submitAddresses`, et la boucle RIB de `submitAccounting`, **dans `new.vue` ET
|
||||||
|
`edit.vue`** :
|
||||||
|
|
||||||
|
- Conserver la réinitialisation du tableau d'erreurs en début de submit (`xxxErrors.value = []`).
|
||||||
|
- Introduire un drapeau local `hasError`. Dans le `catch`, remplacer `return` par
|
||||||
|
`hasError = true; continue` → la boucle tente/valide **tous** les blocs ; chaque 422 se mappe sur
|
||||||
|
`xxxErrors[index]` via `mapRowError` (mécanique existante, inchangée).
|
||||||
|
- Après la boucle : si `hasError` → **ne pas** appeler `completeTab(...)`, **pas** de toast succès. Sinon
|
||||||
|
→ comportement actuel (`completeTab` + toast succès).
|
||||||
|
- Les blocs déjà créés (id non-null) repassent en `PATCH` au resubmit → idempotent, pas de doublon.
|
||||||
|
- Awaits **séquentiels** conservés (volume faible, ordre des blocs préservé, pas de course).
|
||||||
|
|
||||||
|
Le binding inline est déjà en place côté template (`:errors="contactErrors[index]"` /
|
||||||
|
`:error="ribErrors[index]?.iban"` …). Aucun changement de composant `Malio*` requis.
|
||||||
|
|
||||||
|
### 3.3 Réutilisation / isolation
|
||||||
|
|
||||||
|
Le bloc « boucle de soumission d'une collection avec collecte d'erreurs par index » est dupliqué 3× × 2
|
||||||
|
pages. Pour rester testable et DRY, extraire un helper de soumission de collection (ex.
|
||||||
|
`submitCollection(rows, { buildBody, post, patch, errors })` retournant `{ hasError }`) consommé par les
|
||||||
|
6 sites d'appel. À acter dans le plan d'implémentation (option : garder inline si l'extraction dégrade la
|
||||||
|
lisibilité — décision lors du plan).
|
||||||
|
|
||||||
|
## 4. Tests
|
||||||
|
|
||||||
|
### Back (TDD — échouent d'abord)
|
||||||
|
|
||||||
|
Dans `tests/Module/Commercial/Api/ClientSubResourceApiTest` :
|
||||||
|
|
||||||
|
- `testPostContactToClientWithTwoExistingContactsReturns201` : seed un client + 2 contacts, POST un 3ᵉ →
|
||||||
|
attendu **201** (rouge aujourd'hui : 500).
|
||||||
|
- `testPostContactInvalidEmailOnClientWithExistingContactsReturns422` : même seed, POST email invalide →
|
||||||
|
**422** avec `propertyPath=email` et message FR (vérifie que la validation est bien atteinte).
|
||||||
|
- Variantes germes pour adresses et RIB (au moins une chacune) pour verrouiller les 3 sous-ressources.
|
||||||
|
|
||||||
|
Pré-requis : helper de seed de contacts/adresses/RIB dans `AbstractCommercialApiTestCase` (ajouter si
|
||||||
|
absent).
|
||||||
|
|
||||||
|
### Front (Vitest)
|
||||||
|
|
||||||
|
- Si helper `submitCollection` extrait : test unitaire « 3 blocs, le 2ᵉ renvoie 422 → les erreurs du 2ᵉ
|
||||||
|
sont mappées, les blocs 1 et 3 sont tentés, `hasError = true`, tab non complété ».
|
||||||
|
- Sinon : test de composant sur `ClientContactBlock` + page, vérifiant l'affichage inline multi-blocs.
|
||||||
|
|
||||||
|
### Vérifications finales
|
||||||
|
|
||||||
|
`make test` + `make php-cs-fixer-allow-risky` (back), `make nuxt-test` (front). Golden path manuel :
|
||||||
|
client à 3 contacts, ajouter un 4ᵉ avec email invalide → 422 inline sous l'email du bon bloc, pas de 500.
|
||||||
|
|
||||||
|
## 5. Impact / risques
|
||||||
|
|
||||||
|
- API contract : POST sous-ressource passe de 500→201/422 (correction) ; 404 préservé sur parent
|
||||||
|
inexistant. Pas de changement de payload ni de réponse de succès.
|
||||||
|
- Le test fonctionnel CI actuel (POST sur client à 0 contact) reste vert.
|
||||||
|
- Régression possible si un consommateur dépendait du read implicite du parent au POST : aucun identifié
|
||||||
|
(les 3 processors gèrent déjà le rattachement manuellement).
|
||||||
@@ -0,0 +1,633 @@
|
|||||||
|
# Validation « tous les blocs » — onglets à blocs dynamiques (Client M1) — Plan d'implémentation
|
||||||
|
|
||||||
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||||
|
|
||||||
|
**Goal:** Permettre la validation 422 par champ sur TOUS les blocs des onglets Contacts / Adresses / RIB d'un client (création + édition), en supprimant la 500 `NonUniqueResultException` qui les bloque dès ≥2 enfants et en ne stoppant plus la boucle front au premier bloc en erreur.
|
||||||
|
|
||||||
|
**Architecture:** Côté back, on retire le stade « read » inutile du POST des 3 sous-ressources (`read: false`) — le parent est déjà rattaché manuellement par le processor — et on durcit ce rattachement (404 si parent absent). Côté front, on factorise la boucle de soumission de collection dans `useClientFormErrors().submitRows(...)` qui tente tous les blocs et collecte les erreurs par index, puis on branche les 6 sites d'appel (`new.vue` + `edit.vue` × contacts/adresses/RIB).
|
||||||
|
|
||||||
|
**Tech Stack:** Symfony 8 / API Platform 4 (PHP 8.4, PHPUnit) ; Nuxt 4 / Vue 3 / TypeScript / Vitest.
|
||||||
|
|
||||||
|
**Spec de référence :** `docs/superpowers/specs/2026-06-04-client-collection-blocks-validation-design.md`
|
||||||
|
|
||||||
|
**Pré-vol :** `make start` (containers up), branche de travail = celle de la MR (`feat/erp-107-validation-messages-fr`) ou une branche dédiée selon décision utilisateur.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Structure des fichiers
|
||||||
|
|
||||||
|
**Back — modifiés :**
|
||||||
|
- `src/Module/Commercial/Domain/Entity/ClientContact.php` — `read: false` sur `Post`
|
||||||
|
- `src/Module/Commercial/Domain/Entity/ClientAddress.php` — `read: false` sur `Post`
|
||||||
|
- `src/Module/Commercial/Domain/Entity/ClientRib.php` — `read: false` sur `Post`
|
||||||
|
- `src/Module/Commercial/Infrastructure/ApiPlatform/State/Processor/ClientContactProcessor.php` — `linkParent` → 404
|
||||||
|
- `.../Processor/ClientAddressProcessor.php` — idem
|
||||||
|
- `.../Processor/ClientRibProcessor.php` — idem
|
||||||
|
- `tests/Module/Commercial/Api/AbstractCommercialApiTestCase.php` — helper `seedContact()`
|
||||||
|
- `tests/Module/Commercial/Api/ClientSubResourceApiTest.php` — tests de non-régression
|
||||||
|
|
||||||
|
**Front — modifiés :**
|
||||||
|
- `frontend/modules/commercial/composables/useClientFormErrors.ts` — méthode `submitRows()`
|
||||||
|
- `frontend/modules/commercial/composables/__tests__/useClientFormErrors.spec.ts` — créé (test unitaire)
|
||||||
|
- `frontend/modules/commercial/pages/clients/new.vue` — branchements (3 submits)
|
||||||
|
- `frontend/modules/commercial/pages/clients/[id]/edit.vue` — branchements (3 submits)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Task 1 : Back — test rouge (POST sur client à ≥2 enfants)
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `tests/Module/Commercial/Api/AbstractCommercialApiTestCase.php`
|
||||||
|
- Test: `tests/Module/Commercial/Api/ClientSubResourceApiTest.php`
|
||||||
|
|
||||||
|
- [ ] **Step 1 : Ajouter un helper de seed de contact à la base de test**
|
||||||
|
|
||||||
|
Dans `AbstractCommercialApiTestCase.php`, ajouter (sous `seedClient`, avant `cleanupCommercialTestData`) :
|
||||||
|
|
||||||
|
```php
|
||||||
|
/**
|
||||||
|
* Seede directement un ClientContact en base (sans passer par l'API), pour
|
||||||
|
* preparer un client deja dote de N contacts. Au moins le prenom est pose
|
||||||
|
* (RG-1.05 / CHECK chk_client_contact_name).
|
||||||
|
*/
|
||||||
|
protected function seedContact(ClientEntity $client, string $firstName): \App\Module\Commercial\Domain\Entity\ClientContact
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$contact = new \App\Module\Commercial\Domain\Entity\ClientContact();
|
||||||
|
$contact->setClient($client);
|
||||||
|
$contact->setFirstName($firstName);
|
||||||
|
$em->persist($contact);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $contact;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2 : Écrire les tests rouges**
|
||||||
|
|
||||||
|
Dans `ClientSubResourceApiTest.php`, ajouter dans la section `// === Contacts ===` :
|
||||||
|
|
||||||
|
```php
|
||||||
|
/**
|
||||||
|
* Regression ERP (bug subresource Link toProperty) : POST d'un contact sur un
|
||||||
|
* client qui en a DEJA >= 2 ne doit pas exploser en 500
|
||||||
|
* (NonUniqueResultException sur la resolution du parent), mais creer (201).
|
||||||
|
*/
|
||||||
|
public function testPostContactOnClientWithTwoExistingContactsReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Contact Multi');
|
||||||
|
$this->seedContact($seed, 'Alpha');
|
||||||
|
$this->seedContact($seed, 'Beta');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['firstName' => 'Gamma'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meme contexte (>= 2 contacts existants) : un email invalide doit produire
|
||||||
|
* une 422 par champ (la validation est bien atteinte), pas une 500.
|
||||||
|
*/
|
||||||
|
public function testPostInvalidContactOnPopulatedClientReturns422OnField(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Contact Multi Bad');
|
||||||
|
$this->seedContact($seed, 'Alpha');
|
||||||
|
$this->seedContact($seed, 'Beta');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['firstName' => 'Gamma', 'email' => 'pas-un-email'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = [];
|
||||||
|
foreach ($response->toArray(false)['violations'] ?? [] as $v) {
|
||||||
|
$byPath[$v['propertyPath']] = $v['message'];
|
||||||
|
}
|
||||||
|
self::assertArrayHasKey('email', $byPath);
|
||||||
|
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3 : Lancer les tests, vérifier qu'ils échouent (500 au lieu de 201/422)**
|
||||||
|
|
||||||
|
Run : `make test` (ou ciblé dans le container : `docker exec php-starseed-fpm php bin/phpunit --filter ClientSubResourceApiTest`)
|
||||||
|
Expected : les 2 nouveaux tests ÉCHOUENT (HTTP 500 `NonUniqueResultException`). `testPostContactOnClient...` reçoit 500, pas 201.
|
||||||
|
|
||||||
|
- [ ] **Step 4 : Commit (test rouge)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add tests/Module/Commercial/Api/AbstractCommercialApiTestCase.php tests/Module/Commercial/Api/ClientSubResourceApiTest.php
|
||||||
|
git commit -m "test(commercial) : reproduit la 500 NonUniqueResult au POST contact sur client peuple (ERP-107)"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Task 2 : Back — fix (read:false + linkParent durci) → tests verts
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/Module/Commercial/Domain/Entity/ClientContact.php:48-57`
|
||||||
|
- Modify: `src/Module/Commercial/Domain/Entity/ClientAddress.php:61-70`
|
||||||
|
- Modify: `src/Module/Commercial/Domain/Entity/ClientRib.php:52-61`
|
||||||
|
- Modify: `.../State/Processor/ClientContactProcessor.php:76-94`
|
||||||
|
- Modify: `.../State/Processor/ClientAddressProcessor.php:63-81`
|
||||||
|
- Modify: `.../State/Processor/ClientRibProcessor.php:65-83`
|
||||||
|
|
||||||
|
- [ ] **Step 1 : `read: false` sur les 3 opérations `Post`**
|
||||||
|
|
||||||
|
`ClientContact.php`, opération `Post` — ajouter la ligne `read: false,` :
|
||||||
|
|
||||||
|
```php
|
||||||
|
new Post(
|
||||||
|
uriTemplate: '/clients/{clientId}/contacts',
|
||||||
|
uriVariables: [
|
||||||
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
||||||
|
],
|
||||||
|
// read:false : pas de stade lecture du parent (le Link toProperty
|
||||||
|
// resoudrait l'enfant et casse en NonUniqueResult des >= 2 enfants).
|
||||||
|
// Le parent est rattache par ClientContactProcessor::linkParent.
|
||||||
|
read: false,
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client_contact:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client_contact:write']],
|
||||||
|
processor: ClientContactProcessor::class,
|
||||||
|
),
|
||||||
|
```
|
||||||
|
|
||||||
|
`ClientAddress.php` — idem dans son `Post` (`security: commercial.clients.manage`, processor `ClientAddressProcessor`), commentaire pointant `ClientAddressProcessor::linkParent`.
|
||||||
|
|
||||||
|
`ClientRib.php` — idem dans son `Post` (`security: commercial.clients.accounting.manage`, processor `ClientRibProcessor`), commentaire pointant `ClientRibProcessor::linkParent`.
|
||||||
|
|
||||||
|
- [ ] **Step 2 : Durcir les 3 `linkParent` (404 si parent absent)**
|
||||||
|
|
||||||
|
Dans chaque processor, ajouter l'import en tête de fichier :
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
```
|
||||||
|
|
||||||
|
`ClientContactProcessor::linkParent` — remplacer le bloc final par :
|
||||||
|
|
||||||
|
```php
|
||||||
|
if (null === $clientId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $clientId instanceof Client
|
||||||
|
? $clientId
|
||||||
|
: $this->em->getRepository(Client::class)->find($clientId);
|
||||||
|
|
||||||
|
// read:false sur le POST : sans stade lecture, un parent introuvable
|
||||||
|
// n'est plus intercepte en amont -> 404 explicite (sinon 500 au persist
|
||||||
|
// sur client_id NOT NULL).
|
||||||
|
if (!$client instanceof Client) {
|
||||||
|
throw new NotFoundHttpException('Client introuvable.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact->setClient($client);
|
||||||
|
```
|
||||||
|
|
||||||
|
`ClientAddressProcessor::linkParent` — idem avec `$address->setClient($client);`.
|
||||||
|
`ClientRibProcessor::linkParent` — idem avec `$rib->setClient($client);`.
|
||||||
|
|
||||||
|
- [ ] **Step 3 : Lancer les tests, vérifier qu'ils passent**
|
||||||
|
|
||||||
|
Run : `make test`
|
||||||
|
Expected : les 2 tests de Task 1 PASSENT (201 + 422 `propertyPath=email`). Aucun test existant cassé (notamment `testPostContactInvalidEmailReturns422WithFrenchMessageOnField` et les tests d'archi ERP-107 restent verts).
|
||||||
|
|
||||||
|
- [ ] **Step 4 : Lint PHP**
|
||||||
|
|
||||||
|
Run : `make php-cs-fixer-allow-risky`
|
||||||
|
Expected : 0 fichier à corriger (ou corrections appliquées et re-vérifiées).
|
||||||
|
|
||||||
|
- [ ] **Step 5 : Commit (fix back)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/Module/Commercial/Domain/Entity/ClientContact.php src/Module/Commercial/Domain/Entity/ClientAddress.php src/Module/Commercial/Domain/Entity/ClientRib.php src/Module/Commercial/Infrastructure/ApiPlatform/State/Processor/ClientContactProcessor.php src/Module/Commercial/Infrastructure/ApiPlatform/State/Processor/ClientAddressProcessor.php src/Module/Commercial/Infrastructure/ApiPlatform/State/Processor/ClientRibProcessor.php
|
||||||
|
git commit -m "fix(commercial) : POST sous-ressource client en read:false + parent 404 (corrige 500 NonUniqueResult, ERP-107)"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Task 3 : Back — germes adresses + RIB (verrouille les 3 sous-ressources)
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `tests/Module/Commercial/Api/AbstractCommercialApiTestCase.php` (helpers `seedAddress`, `seedRib`)
|
||||||
|
- Test: `tests/Module/Commercial/Api/ClientSubResourceApiTest.php`
|
||||||
|
|
||||||
|
- [ ] **Step 1 : Helpers de seed adresse + RIB**
|
||||||
|
|
||||||
|
Dans `AbstractCommercialApiTestCase.php`, ajouter :
|
||||||
|
|
||||||
|
```php
|
||||||
|
/** Seede une adresse minimale valide (RG : CP/ville/rue requis). */
|
||||||
|
protected function seedAddress(ClientEntity $client, string $city): \App\Module\Commercial\Domain\Entity\ClientAddress
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$address = new \App\Module\Commercial\Domain\Entity\ClientAddress();
|
||||||
|
$address->setClient($client);
|
||||||
|
$address->setPostalCode('33000');
|
||||||
|
$address->setCity($city);
|
||||||
|
$address->setStreet('1 rue du Test');
|
||||||
|
$em->persist($address);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Seede un RIB valide (BIC/IBAN conformes). */
|
||||||
|
protected function seedRib(ClientEntity $client, string $label): \App\Module\Commercial\Domain\Entity\ClientRib
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$rib = new \App\Module\Commercial\Domain\Entity\ClientRib();
|
||||||
|
$rib->setClient($client);
|
||||||
|
$rib->setLabel($label);
|
||||||
|
$rib->setBic('BNPAFRPPXXX');
|
||||||
|
$rib->setIban('FR1420041010050500013M02606');
|
||||||
|
$em->persist($rib);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $rib;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> Note : si une propriété est non-nullable et absente ci-dessus (ex. `position`, flags d'adresse), poser les setters correspondants avec une valeur par défaut neutre — vérifier les entités `ClientAddress` / `ClientRib` au moment de l'écriture.
|
||||||
|
|
||||||
|
- [ ] **Step 2 : Tests de non-régression adresses + RIB**
|
||||||
|
|
||||||
|
Dans `ClientSubResourceApiTest.php`, section adresses puis RIB :
|
||||||
|
|
||||||
|
```php
|
||||||
|
public function testPostAddressOnClientWithTwoExistingAddressesReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Addr Multi');
|
||||||
|
$this->seedAddress($seed, 'Bordeaux');
|
||||||
|
$this->seedAddress($seed, 'Lyon');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['postalCode' => '75001', 'city' => 'Paris', 'street' => '2 rue Neuve'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostRibOnClientWithTwoExistingRibsReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Rib Multi');
|
||||||
|
$this->seedRib($seed, 'Compte 1');
|
||||||
|
$this->seedRib($seed, 'Compte 2');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/ribs', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['label' => 'Compte 3', 'bic' => self::VALID_BIC, 'iban' => self::VALID_IBAN],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> Le POST RIB exige `commercial.clients.accounting.manage` — `admin` (ROLE_ADMIN) l'a. Si une 403 apparaît, vérifier le compte de test.
|
||||||
|
|
||||||
|
- [ ] **Step 3 : Lancer, vérifier vert**
|
||||||
|
|
||||||
|
Run : `make test`
|
||||||
|
Expected : PASS (les 2 nouveaux tests verts grâce au fix de Task 2).
|
||||||
|
|
||||||
|
- [ ] **Step 4 : Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add tests/Module/Commercial/Api/AbstractCommercialApiTestCase.php tests/Module/Commercial/Api/ClientSubResourceApiTest.php
|
||||||
|
git commit -m "test(commercial) : verrouille POST adresses/RIB sur client peuple (ERP-107)"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Task 4 : Front — helper `submitRows` + test unitaire
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `frontend/modules/commercial/composables/useClientFormErrors.ts`
|
||||||
|
- Create: `frontend/modules/commercial/composables/__tests__/useClientFormErrors.spec.ts`
|
||||||
|
|
||||||
|
- [ ] **Step 1 : Écrire le test rouge**
|
||||||
|
|
||||||
|
Créer `useClientFormErrors.spec.ts` :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { describe, it, expect, vi } from 'vitest'
|
||||||
|
import { useClientFormErrors } from '../useClientFormErrors'
|
||||||
|
|
||||||
|
// Construit une erreur facon useApi : 422 avec violations Hydra.
|
||||||
|
function http422(path: string, message: string) {
|
||||||
|
return { response: { status: 422, _data: { violations: [{ propertyPath: path, message }] } } }
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('useClientFormErrors.submitRows', () => {
|
||||||
|
it('tente TOUS les blocs et mappe les erreurs par index, sans stopper au premier echec', async () => {
|
||||||
|
const { contactErrors, submitRows } = useClientFormErrors()
|
||||||
|
const seen: number[] = []
|
||||||
|
const onUnmapped = vi.fn()
|
||||||
|
|
||||||
|
const saveRow = async (_row: unknown, index: number) => {
|
||||||
|
seen.push(index)
|
||||||
|
if (index === 1) throw http422('email', 'Email invalide')
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasError = await submitRows(
|
||||||
|
[{ a: 0 }, { a: 1 }, { a: 2 }],
|
||||||
|
contactErrors,
|
||||||
|
saveRow,
|
||||||
|
onUnmapped,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(seen).toEqual([0, 1, 2]) // tous les blocs tentes
|
||||||
|
expect(hasError).toBe(true)
|
||||||
|
expect(contactErrors.value[1]).toEqual({ email: 'Email invalide' })
|
||||||
|
expect(contactErrors.value[0]).toBeUndefined()
|
||||||
|
expect(onUnmapped).not.toHaveBeenCalled() // 422 mappee, pas de fallback
|
||||||
|
})
|
||||||
|
|
||||||
|
it('saute les lignes filtrees par shouldSkip et renvoie false si tout passe', async () => {
|
||||||
|
const { contactErrors, submitRows } = useClientFormErrors()
|
||||||
|
const saved: number[] = []
|
||||||
|
|
||||||
|
const hasError = await submitRows(
|
||||||
|
[{ skip: true }, { skip: false }],
|
||||||
|
contactErrors,
|
||||||
|
async (_row, index) => { saved.push(index) },
|
||||||
|
vi.fn(),
|
||||||
|
(row: { skip: boolean }) => row.skip,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(saved).toEqual([1])
|
||||||
|
expect(hasError).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2 : Lancer, vérifier l'échec**
|
||||||
|
|
||||||
|
Run : `make nuxt-test` (ou ciblé : `docker exec <node> npx vitest run useClientFormErrors`)
|
||||||
|
Expected : FAIL — `submitRows` n'existe pas encore.
|
||||||
|
|
||||||
|
- [ ] **Step 3 : Implémenter `submitRows`**
|
||||||
|
|
||||||
|
Dans `useClientFormErrors.ts`, ajouter la méthode (dans la fonction, après `mapRowError`) et l'exposer dans le `return` :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
/**
|
||||||
|
* Soumet TOUS les blocs d'une collection (contacts/adresses/RIB) en collectant
|
||||||
|
* les erreurs par index : on n'arrete PAS au premier bloc en echec (ERP-101).
|
||||||
|
* Reinitialise le tableau d'erreurs cible, tente chaque ligne via `saveRow`,
|
||||||
|
* mappe les 422 inline (mapRowError) ou delegue le fallback a `onUnmappedError`.
|
||||||
|
* Retourne true si au moins un bloc a echoue (le caller ne valide alors pas l'onglet).
|
||||||
|
*/
|
||||||
|
async function submitRows<T>(
|
||||||
|
rows: T[],
|
||||||
|
target: Ref<Record<string, string>[]>,
|
||||||
|
saveRow: (row: T, index: number) => Promise<void>,
|
||||||
|
onUnmappedError: (error: unknown, index: number) => void,
|
||||||
|
shouldSkip?: (row: T, index: number) => boolean,
|
||||||
|
): Promise<boolean> {
|
||||||
|
target.value = []
|
||||||
|
let hasError = false
|
||||||
|
for (let index = 0; index < rows.length; index++) {
|
||||||
|
if (shouldSkip?.(rows[index], index)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await saveRow(rows[index], index)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (!mapRowError(error, target, index)) {
|
||||||
|
onUnmappedError(error, index)
|
||||||
|
}
|
||||||
|
hasError = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasError
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Ajouter `submitRows` à l'objet retourné par `useClientFormErrors`.
|
||||||
|
|
||||||
|
- [ ] **Step 4 : Lancer, vérifier vert**
|
||||||
|
|
||||||
|
Run : `make nuxt-test`
|
||||||
|
Expected : PASS (les 2 cas verts).
|
||||||
|
|
||||||
|
- [ ] **Step 5 : Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add frontend/modules/commercial/composables/useClientFormErrors.ts frontend/modules/commercial/composables/__tests__/useClientFormErrors.spec.ts
|
||||||
|
git commit -m "feat(commercial) : submitRows collecte les erreurs de tous les blocs de collection (ERP-101)"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Task 5 : Front — brancher `submitRows` dans new.vue + edit.vue
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `frontend/modules/commercial/pages/clients/new.vue` (`submitContacts`, `submitAddresses`, boucle RIB de `submitAccounting`)
|
||||||
|
- Modify: `frontend/modules/commercial/pages/clients/[id]/edit.vue` (les 3 équivalents)
|
||||||
|
|
||||||
|
- [ ] **Step 1 : Récupérer `submitRows` du composable**
|
||||||
|
|
||||||
|
Dans `new.vue` ET `edit.vue`, ajouter `submitRows` à la déstructuration de `useClientFormErrors()` :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const {
|
||||||
|
mainErrors,
|
||||||
|
informationErrors,
|
||||||
|
accountingErrors,
|
||||||
|
contactErrors,
|
||||||
|
addressErrors,
|
||||||
|
ribErrors,
|
||||||
|
mapRowError,
|
||||||
|
submitRows,
|
||||||
|
} = useClientFormErrors()
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2 : Réécrire `submitContacts` (new.vue)**
|
||||||
|
|
||||||
|
Remplacer le corps de la boucle par un appel à `submitRows` :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
async function submitContacts(): Promise<void> {
|
||||||
|
if (clientId.value === null || !canValidateContacts.value || tabSubmitting.value) return
|
||||||
|
tabSubmitting.value = true
|
||||||
|
try {
|
||||||
|
const hasError = await submitRows(
|
||||||
|
contacts.value,
|
||||||
|
contactErrors,
|
||||||
|
async (contact) => {
|
||||||
|
const body = {
|
||||||
|
firstName: contact.firstName || null,
|
||||||
|
lastName: contact.lastName || null,
|
||||||
|
jobTitle: contact.jobTitle || null,
|
||||||
|
phonePrimary: contact.phonePrimary || null,
|
||||||
|
phoneSecondary: contact.hasSecondaryPhone ? (contact.phoneSecondary || null) : null,
|
||||||
|
email: contact.email || null,
|
||||||
|
}
|
||||||
|
if (contact.id === null) {
|
||||||
|
const created = await api.post<ContactResponse>(
|
||||||
|
`/clients/${clientId.value}/contacts`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
contact.id = created.id
|
||||||
|
contact.iri = created['@id'] ?? null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/client_contacts/${contact.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
|
(contact) => !isContactNamed(contact),
|
||||||
|
)
|
||||||
|
if (hasError) return
|
||||||
|
completeTab('contact')
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tabSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3 : Réécrire `submitAddresses` (new.vue)**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
async function submitAddresses(): Promise<void> {
|
||||||
|
if (clientId.value === null || !canValidateAddresses.value || tabSubmitting.value) return
|
||||||
|
tabSubmitting.value = true
|
||||||
|
try {
|
||||||
|
const hasError = await submitRows(
|
||||||
|
addresses.value,
|
||||||
|
addressErrors,
|
||||||
|
async (address) => {
|
||||||
|
const body = {
|
||||||
|
isProspect: address.isProspect,
|
||||||
|
isDelivery: address.isDelivery,
|
||||||
|
isBilling: address.isBilling,
|
||||||
|
country: address.country,
|
||||||
|
postalCode: address.postalCode || null,
|
||||||
|
city: address.city || null,
|
||||||
|
street: address.street || null,
|
||||||
|
streetComplement: address.streetComplement || null,
|
||||||
|
categories: address.categoryIris,
|
||||||
|
sites: address.siteIris,
|
||||||
|
contacts: address.contactIris,
|
||||||
|
billingEmail: isBillingEmailRequired(address) ? (address.billingEmail || null) : null,
|
||||||
|
}
|
||||||
|
if (address.id === null) {
|
||||||
|
const created = await api.post<{ id: number }>(
|
||||||
|
`/clients/${clientId.value}/addresses`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
address.id = created.id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/client_addresses/${address.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
|
)
|
||||||
|
if (hasError) return
|
||||||
|
completeTab('address')
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tabSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4 : Réécrire la boucle RIB de `submitAccounting` (new.vue)**
|
||||||
|
|
||||||
|
Garder le PATCH scalaire inchangé (1) ; remplacer la boucle (2) :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// 2) POST/PATCH des RIB (erreurs inline par ligne, tous les blocs).
|
||||||
|
const ribHasError = await submitRows(
|
||||||
|
ribs.value,
|
||||||
|
ribErrors,
|
||||||
|
async (rib) => {
|
||||||
|
const body = { label: rib.label, bic: rib.bic, iban: rib.iban }
|
||||||
|
if (rib.id === null) {
|
||||||
|
const created = await api.post<{ id: number }>(
|
||||||
|
`/clients/${clientId.value}/ribs`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
rib.id = created.id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/client_ribs/${rib.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
|
(rib) => !ribIsComplete(rib),
|
||||||
|
)
|
||||||
|
if (ribHasError) return
|
||||||
|
|
||||||
|
completeTab('accounting')
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
```
|
||||||
|
|
||||||
|
> Retirer le `ribErrors.value = []` désormais fait par `submitRows`. Le `accountingErrors.clearErrors()` du PATCH scalaire reste.
|
||||||
|
|
||||||
|
- [ ] **Step 5 : Mirror dans edit.vue**
|
||||||
|
|
||||||
|
Appliquer les mêmes réécritures aux `submitContacts` / `submitAddresses` / boucle RIB de `submitAccounting` d'`edit.vue`. Conserver le **fallback d'erreur propre à edit.vue** (si edit.vue utilise `showError(...)` au lieu de `toast.error(...)`, passer ce fallback comme `onUnmappedError`). Vérifier les noms des refs (`clientId` peut y être l'id de route).
|
||||||
|
|
||||||
|
- [ ] **Step 6 : Vérifier le typecheck + tests front**
|
||||||
|
|
||||||
|
Run : `make nuxt-test`
|
||||||
|
Expected : PASS. Aucune régression des specs existantes (`ClientContactBlock.spec.ts`, etc.).
|
||||||
|
|
||||||
|
- [ ] **Step 7 : Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add frontend/modules/commercial/pages/clients/new.vue "frontend/modules/commercial/pages/clients/[id]/edit.vue"
|
||||||
|
git commit -m "feat(commercial) : valide tous les blocs contacts/adresses/RIB et affiche les erreurs par bloc (ERP-101)"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Task 6 : Vérification finale + golden path manuel
|
||||||
|
|
||||||
|
- [ ] **Step 1 : Suite complète back**
|
||||||
|
|
||||||
|
Run : `make test` puis `make php-cs-fixer-allow-risky`
|
||||||
|
Expected : tout vert, 0 fichier à corriger.
|
||||||
|
|
||||||
|
- [ ] **Step 2 : Suite complète front**
|
||||||
|
|
||||||
|
Run : `make nuxt-test`
|
||||||
|
Expected : tout vert.
|
||||||
|
|
||||||
|
- [ ] **Step 3 : Golden path manuel (`make dev-nuxt`, port 3004)**
|
||||||
|
|
||||||
|
Scénario : ouvrir un client à 3 contacts (compte `admin`), onglet Contacts, ajouter un bloc avec email invalide + un autre bloc avec prénom/nom vides → Valider.
|
||||||
|
Attendu : **pas de 500** ; « L'adresse email n'est pas valide. » sous l'email du bon bloc ET « Le prénom ou le nom du contact est obligatoire. » sous le prénom de l'autre bloc, **affichés simultanément**. L'onglet ne se valide pas tant qu'une erreur subsiste. Idem à vérifier rapidement sur Adresses et RIB.
|
||||||
|
|
||||||
|
- [ ] **Step 4 : Si une vérif échoue ou ne peut être lancée, le dire explicitement** (ne pas annoncer « fini »).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Self-review (auteur du plan)
|
||||||
|
|
||||||
|
- **Couverture spec §3.1 (back)** : Task 2 (read:false + linkParent 404) ✓ ; §3.2 (front collect-all) : Tasks 4-5 ✓ ; §3.3 (helper réutilisable) : Task 4 `submitRows` ✓ ; §4 tests : Tasks 1, 3 (back), 4 (front) + Task 6 golden path ✓.
|
||||||
|
- **Périmètre 3 sous-ressources** : contacts (Task 1-2), adresses + RIB (Task 3 + branchements Task 5) ✓.
|
||||||
|
- **Décision « inline seul »** : aucun toast succès si `hasError` ; pas de toast récap ✓.
|
||||||
|
- **Pas de placeholder** : le seul point ouvert est la note Task 3 Step 1 (setters non-nullables éventuels d'adresse/RIB à compléter en lisant les entités) — à lever à l'écriture. Cohérence des noms : `submitRows` utilisé identiquement en Task 4 et Task 5.
|
||||||
@@ -18,8 +18,8 @@ merge de la stack.
|
|||||||
|
|
||||||
| RG | Intitulé | Test(s) | Source |
|
| RG | Intitulé | Test(s) | Source |
|
||||||
|----|----------|---------|--------|
|
|----|----------|---------|--------|
|
||||||
| RG-1.01 | Prénom OU nom obligatoire → 422 | `ClientApiTest::testPostWithoutFirstOrLastNameReturns422` ; `ClientProcessorTest` (unit) | ERP-55 |
|
| ~~RG-1.01~~ | _(supprimée V1 — refonte-contact)_ contact inline retiré du Client ; complétude couverte par RG-1.05 / RG-1.14 (`ClientContact`) | — | refonte-contact |
|
||||||
| RG-1.02 | phoneSecondary persisté ; max 2 téléphones | `ClientFormulaireMainTest::testPostPersistsSecondaryPhoneNormalized` ; `::testThirdPhoneFieldIsIgnored` | **ERP-60** |
|
| ~~RG-1.02~~ | _(supprimée du Client V1)_ téléphones inline retirés du Client (testés sur `ClientContact`) | — | refonte-contact |
|
||||||
| RG-1.03 | distributor/broker exclusifs + type catégorie | `ClientApiTest::testPostWithDistributorAndBrokerReturns422` ; `::testPostDistributorReferencingNonDistributorReturns422` ; `::testPostValidDistributorReturns201` ; `ClientProcessorTest` (unit) | ERP-55 |
|
| RG-1.03 | distributor/broker exclusifs + type catégorie | `ClientApiTest::testPostWithDistributorAndBrokerReturns422` ; `::testPostDistributorReferencingNonDistributorReturns422` ; `::testPostValidDistributorReturns201` ; `ClientProcessorTest` (unit) | ERP-55 |
|
||||||
| RG-1.04 | Onglet Information obligatoire pour rôle Commerciale | `ClientProcessorTest::testCommercialeIncompleteInformationIsUnprocessable` ; `::testNonCommercialeSkipsInformationCompleteness` (unit, dormant). **Test fonctionnel + durcissement → ERP-74** | ERP-55 / **ERP-74** |
|
| RG-1.04 | Onglet Information obligatoire pour rôle Commerciale | `ClientProcessorTest::testCommercialeIncompleteInformationIsUnprocessable` ; `::testNonCommercialeSkipsInformationCompleteness` (unit, dormant). **Test fonctionnel + durcissement → ERP-74** | ERP-55 / **ERP-74** |
|
||||||
| RG-1.05 | Contact : prénom OU nom → 422 (CHECK) | `ClientSubResourceApiTest::testPostContactWithoutNameReturns422` | ERP-57 |
|
| RG-1.05 | Contact : prénom OU nom → 422 (CHECK) | `ClientSubResourceApiTest::testPostContactWithoutNameReturns422` | ERP-57 |
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
# M1 · Ticket 1/3 (Backend) — Supprimer le contact inline du `Client`
|
||||||
|
|
||||||
|
## 1. Objectif
|
||||||
|
|
||||||
|
Retirer de l'entité `Client` (et de la table `client`) les **5 champs du contact
|
||||||
|
principal inline** : `firstName`, `lastName`, `phonePrimary`, `phoneSecondary`, `email`.
|
||||||
|
La gestion des contacts passe désormais **exclusivement** par la sous-entité
|
||||||
|
`ClientContact` (onglet « Contacts »), déjà en place et déjà porteuse des mêmes champs.
|
||||||
|
|
||||||
|
Le code M1 est **déjà livré en prod** : ce ticket inclut donc une **migration de données**
|
||||||
|
(backfill) pour ne perdre aucune information de contact existante avant de supprimer les
|
||||||
|
colonnes.
|
||||||
|
|
||||||
|
Contexte et justification : voir `README.md` du dossier `refonte-contact`.
|
||||||
|
|
||||||
|
## 2. Périmètre
|
||||||
|
|
||||||
|
### IN
|
||||||
|
|
||||||
|
- Migration Doctrine : **backfill puis suppression** des 5 colonnes de `client`.
|
||||||
|
- `Client` (entité) : supprimer les 5 propriétés, getters/setters, annotations ORM /
|
||||||
|
`Assert` / `Groups`.
|
||||||
|
- `ClientProcessor` : retirer les 5 champs de `MAIN_FIELDS`, `changedBusinessFields()`,
|
||||||
|
`normalize()` ; supprimer `validateMainContact()` (RG-1.01 — n'a plus d'objet).
|
||||||
|
- `DoctrineClientRepository::applySearch()` : trancher D1 (recherche) et l'appliquer.
|
||||||
|
- `ClientExportController` : trancher D2 (colonnes export) et l'appliquer.
|
||||||
|
- `ClientFixtures` : retirer les 5 paramètres inline de `ensureClient()` ; garantir que
|
||||||
|
chaque client seedé possède au moins 1 `ClientContact` (déjà géré par `addContact()`).
|
||||||
|
- Tests PHPUnit : mettre à jour / retirer les cas qui exercent ces 5 champs sur `Client`.
|
||||||
|
|
||||||
|
### OUT
|
||||||
|
|
||||||
|
- Toute modification de `ClientContact` / `ClientContactProcessor` : **inchangés** (c'est la
|
||||||
|
cible, les champs y restent). `ClientFieldNormalizer` reste tel quel (toujours appelé par
|
||||||
|
`ClientContactProcessor`).
|
||||||
|
- Le front (formulaires, vues, types, i18n) → **ticket 2/3**.
|
||||||
|
- Les specs (`spec-back.md`, `spec-front.md`, cahier de test) → **ticket 3/3**.
|
||||||
|
|
||||||
|
## 3. Fichiers à modifier
|
||||||
|
|
||||||
|
| Fichier | Action |
|
||||||
|
|---|---|
|
||||||
|
| `src/Module/Commercial/Domain/Entity/Client.php` | Supprimer props `firstName` (~l.158), `lastName` (~l.163), `phonePrimary` (~l.168), `phoneSecondary` (~l.172), `email` (~l.178) + leurs getters/setters (~l.329-382) + groupes `client:read`/`client:write:main` + `Assert\*`. |
|
||||||
|
| `src/Module/Commercial/Infrastructure/ApiPlatform/State/Processor/ClientProcessor.php` | Retirer les 5 clés de `MAIN_FIELDS` (~l.63) ; de `changedBusinessFields()` (~l.277-281) ; les 6 lignes de `normalize()` qui touchent email/phone/first/last/secondary (~l.433-441) ; supprimer `validateMainContact()` (~l.447-456) et son appel. |
|
||||||
|
| `src/Module/Commercial/Infrastructure/Doctrine/DoctrineClientRepository.php` | `applySearch()` (~l.110-124) : appliquer **D1**. |
|
||||||
|
| `src/Module/Commercial/Infrastructure/Controller/ClientExportController.php` | `buildHeaders()` (~l.94-114) + `buildRows()` (~l.121-143) : appliquer **D2**. |
|
||||||
|
| `src/Module/Commercial/Infrastructure/DataFixtures/ClientFixtures.php` | `ensureClient()` (~l.357-395) : retirer firstName/lastName/phonePrimary/phoneSecondary/email ; conserver `addContact()`. |
|
||||||
|
| `migrations/Version<timestamp>.php` (NOUVELLE) | Backfill + `DROP COLUMN` (cf. § 4). |
|
||||||
|
| `tests/Module/Commercial/**` | Voir § 5. |
|
||||||
|
|
||||||
|
## 4. Migration Doctrine — backfill puis suppression
|
||||||
|
|
||||||
|
> Migration **modulaire** (`src/Module/Commercial/Infrastructure/Doctrine/Migrations/`) : ce
|
||||||
|
> n'est PAS une migration d'initialisation, le schéma `client` / `client_contact` existe
|
||||||
|
> déjà (règle ABSOLUE n°11).
|
||||||
|
|
||||||
|
### `up()`
|
||||||
|
|
||||||
|
1. **Backfill — ne créer un contact que pour les clients qui n'en ont aucun**, afin de ne
|
||||||
|
pas dupliquer le contact déjà recopié à la création (`prefillFirstContact`) :
|
||||||
|
|
||||||
|
```sql
|
||||||
|
INSERT INTO client_contact
|
||||||
|
(client_id, first_name, last_name, phone_primary, phone_secondary, email, position, created_at, updated_at)
|
||||||
|
SELECT c.id, c.first_name, c.last_name, c.phone_primary, c.phone_secondary, c.email, 0, NOW(), NOW()
|
||||||
|
FROM client c
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM client_contact cc WHERE cc.client_id = c.id)
|
||||||
|
AND (c.first_name IS NOT NULL OR c.last_name IS NOT NULL);
|
||||||
|
```
|
||||||
|
|
||||||
|
> Le `WHERE ... first_name OU last_name IS NOT NULL` respecte le CHECK
|
||||||
|
> `chk_client_contact_name`. Les rares clients sans nom de contact ET sans contact
|
||||||
|
> existant ne reçoivent pas de ligne (cas théorique : `phone_primary`/`email` étaient
|
||||||
|
> `NOT NULL` mais les noms nullables).
|
||||||
|
|
||||||
|
2. **Supprimer les 5 colonnes** :
|
||||||
|
|
||||||
|
```sql
|
||||||
|
ALTER TABLE client
|
||||||
|
DROP COLUMN first_name,
|
||||||
|
DROP COLUMN last_name,
|
||||||
|
DROP COLUMN phone_primary,
|
||||||
|
DROP COLUMN phone_secondary,
|
||||||
|
DROP COLUMN email;
|
||||||
|
```
|
||||||
|
|
||||||
|
> Pas de `COMMENT ON COLUMN` à poser (on supprime). Vérifier qu'aucun index ne portait
|
||||||
|
> sur `email` (l'index unique `uq_client_email_active` a déjà été supprimé — décision Q4 /
|
||||||
|
> RG-1.17, cf. `ClientMigrationTest`).
|
||||||
|
|
||||||
|
### `down()` (best-effort)
|
||||||
|
|
||||||
|
1. Recréer les 5 colonnes (`phone_primary`/`email` en `NOT NULL` impose un défaut transitoire
|
||||||
|
ou un re-remplissage depuis le contact `position = 0`).
|
||||||
|
2. Re-remplir depuis `client_contact` (`position = 0`) si possible.
|
||||||
|
3. Reposer les `COMMENT ON COLUMN` d'origine (textes RG-1.19/1.20/1.21/1.01/1.17 — cf.
|
||||||
|
`migrations/Version20260601000000.php` l.251-255).
|
||||||
|
|
||||||
|
> `down()` ne peut pas restaurer parfaitement les données (ambiguïté si plusieurs contacts).
|
||||||
|
> Documenter cette limite dans le docblock de la migration.
|
||||||
|
|
||||||
|
## 5. Tests à mettre à jour
|
||||||
|
|
||||||
|
| Fichier | Action |
|
||||||
|
|---|---|
|
||||||
|
| `tests/Module/Commercial/Api/ClientApiTest.php` | Retirer firstName/lastName/phone/email des payloads POST/PATCH `client` et des assertions JSON. |
|
||||||
|
| `tests/.../ClientFormulaireMainTest.php` | Supprimer les tests RG-1.01 (firstName/lastName) et RG-1.02 (téléphones) **côté Client** — ils basculent côté `ClientContact` (couverts ailleurs). |
|
||||||
|
| `tests/.../ClientExportControllerTest.php` | Aligner les en-têtes/lignes attendus sur **D2**. |
|
||||||
|
| `tests/.../ClientMigrationTest.php` | Asserter que les 5 colonnes **n'existent plus** sur `client` ; vérifier le backfill (un client sans contact obtient bien 1 `client_contact`). |
|
||||||
|
| `tests/.../ClientFieldNormalizerTest.php` | Conserver les tests du normalizer (toujours utilisé par `ClientContact`) ; retirer les cas spécifiques aux champs `Client` s'il y en a. |
|
||||||
|
| RG-1.01/1.02 (matrice) | Ne plus tester sur `Client` ; vérifier qu'ils restent couverts sur `ClientContact` (RG-1.05). |
|
||||||
|
|
||||||
|
## 6. Décisions à trancher (cf. README § 3)
|
||||||
|
|
||||||
|
- **D1 — recherche** : recommandé = `LEFT JOIN client_contact` (fuzzy sur
|
||||||
|
`companyName` + contact `first_name`/`last_name`/`email`). Attention au `DISTINCT` /
|
||||||
|
risque de doublons de lignes si plusieurs contacts matchent (grouper par `client.id`).
|
||||||
|
- **D2 — export** : recommandé = alimenter les colonnes contact depuis le contact de plus
|
||||||
|
petit `position` (fetch-join `contacts` pour éviter le N+1).
|
||||||
|
|
||||||
|
## 7. Critères d'acceptation (DoD)
|
||||||
|
|
||||||
|
- [ ] Les colonnes `first_name`, `last_name`, `phone_primary`, `phone_secondary`, `email`
|
||||||
|
n'existent plus sur la table `client`.
|
||||||
|
- [ ] La migration est jouable sur une base seedée sans perte de contact (backfill vérifié)
|
||||||
|
et `down()` documenté comme best-effort.
|
||||||
|
- [ ] `Client`, `ClientProcessor`, `DoctrineClientRepository`, `ClientExportController`,
|
||||||
|
`ClientFixtures` ne référencent plus les 5 champs.
|
||||||
|
- [ ] D1 et D2 implémentées conformément à la décision validée.
|
||||||
|
- [ ] `ClientContact` / `ClientContactProcessor` / `ClientFieldNormalizer` inchangés.
|
||||||
|
- [ ] `make test` vert (notamment `tests/Architecture/ColumnsHaveSqlCommentTest` et
|
||||||
|
`EntitiesAreTimestampableBlamableTest`).
|
||||||
|
- [ ] `make php-cs-fixer-allow-risky` ne signale rien sur les fichiers touchés.
|
||||||
|
- [ ] Aucune régression du contrat de sérialisation : capturer le JSON réel de
|
||||||
|
`GET /api/clients/{id}` et vérifier l'absence des 5 champs (réflexe RETEX M1).
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# Prompt d'implémentation — M1 · Ticket 1/3 (Backend)
|
||||||
|
|
||||||
|
Tu travailles sur le projet **Starseed** (Symfony 8 / API Platform 4 / Doctrine / PostgreSQL).
|
||||||
|
Lis `CLAUDE.md` et `.claude/rules/backend.md` avant de coder. Commentaires en français,
|
||||||
|
code en anglais, `declare(strict_types=1);` partout.
|
||||||
|
|
||||||
|
## Mission
|
||||||
|
|
||||||
|
Supprimer le **contact principal inline** de l'entité `Client` : les 5 champs
|
||||||
|
`firstName`, `lastName`, `phonePrimary`, `phoneSecondary`, `email`. Les contacts sont gérés
|
||||||
|
uniquement via la sous-entité `ClientContact` (onglet Contacts), déjà en place. Le code est
|
||||||
|
déjà en prod → migration avec **backfill** avant `DROP`.
|
||||||
|
|
||||||
|
La spec détaillée du ticket est dans `docs/specs/M1-clients/refonte-contact/M1-ticket-01-back.md`.
|
||||||
|
Lis-la en entier, ainsi que le `README.md` du même dossier (décision + RG impactées + D1/D2).
|
||||||
|
|
||||||
|
## Étapes
|
||||||
|
|
||||||
|
1. **Explorer** : `Client.php`, `ClientProcessor.php`, `DoctrineClientRepository.php`,
|
||||||
|
`ClientExportController.php`, `ClientFixtures.php`, et `ClientContact.php` (pour confirmer
|
||||||
|
que la cible porte bien les mêmes champs).
|
||||||
|
2. **Demander la validation des décisions D1 (recherche) et D2 (export)** avant de coder —
|
||||||
|
défauts recommandés : D1 = LEFT JOIN sur `client_contact`, D2 = colonnes export depuis le
|
||||||
|
contact `position` minimal. Ne pas inventer un autre comportement.
|
||||||
|
3. **Migration** (`src/Module/Commercial/Infrastructure/Doctrine/Migrations/`) : backfill
|
||||||
|
`INSERT INTO client_contact ... WHERE NOT EXISTS(...)` puis `ALTER TABLE client DROP COLUMN ...`
|
||||||
|
(les 5). `down()` best-effort documenté. Voir le SQL exact dans la spec § 4.
|
||||||
|
4. **Entité** : retirer les 5 props + getters/setters + `#[ORM\Column]` + `#[Assert\*]` +
|
||||||
|
`#[Groups(['client:read','client:write:main'])]`.
|
||||||
|
5. **Processor** : retirer de `MAIN_FIELDS`, `changedBusinessFields()`, `normalize()` ;
|
||||||
|
supprimer `validateMainContact()` et son appel.
|
||||||
|
6. **Repository** : `applySearch()` selon D1.
|
||||||
|
7. **Export** : `buildHeaders()` / `buildRows()` selon D2.
|
||||||
|
8. **Fixtures** : alléger `ensureClient()` ; garder `addContact()`.
|
||||||
|
9. **Tests** : mettre à jour `ClientApiTest`, `ClientFormulaireMainTest`,
|
||||||
|
`ClientExportControllerTest`, `ClientMigrationTest`, `ClientFieldNormalizerTest`
|
||||||
|
(cf. spec § 5). Ajouter une assertion que le backfill crée bien un contact pour un client
|
||||||
|
qui n'en avait pas.
|
||||||
|
|
||||||
|
## Garde-fous
|
||||||
|
|
||||||
|
- Ne touche **pas** `ClientContact`, `ClientContactProcessor`, `ClientFieldNormalizer`.
|
||||||
|
- Respecte les règles ABSOLUES : pagination, `#[Auditable]`, COMMENT ON COLUMN (ici on
|
||||||
|
supprime → pas de commentaire à poser, mais ne pas casser le garde-fou).
|
||||||
|
- Les RG-1.01 et RG-1.02 disparaissent **du Client** : leur équivalent (RG-1.05 / RG-1.14)
|
||||||
|
vit déjà sur `ClientContact`, ne le duplique pas.
|
||||||
|
|
||||||
|
## Vérification finale (obligatoire avant de dire « fini »)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make db-reset && make migration-migrate # migration rejouable sur base fraîche
|
||||||
|
make test # PHPUnit vert
|
||||||
|
make php-cs-fixer-allow-risky # lint
|
||||||
|
```
|
||||||
|
|
||||||
|
Puis capture le JSON réel de `GET /api/clients/{id}` (avec un JWT) et confirme que les 5
|
||||||
|
champs ont disparu de la réponse et que `contacts[]` porte bien l'info (réflexe RETEX M1 :
|
||||||
|
on valide sur le contrat réel, pas sur les annotations).
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
# M1 · Ticket 2/3 (Frontend) — Retirer le bloc contact principal des écrans Client
|
||||||
|
|
||||||
|
## 1. Objectif
|
||||||
|
|
||||||
|
Retirer le **bloc « contact principal »** (Nom, Prénom, Téléphone, Téléphone 2, Email) des
|
||||||
|
trois écrans Client — **création**, **consultation**, **modification** — ainsi que des
|
||||||
|
types, mappeurs, validations et clés i18n associés. La saisie des contacts se fait
|
||||||
|
désormais uniquement dans l'**onglet « Contacts »** (composant `ClientContactBlock`, déjà
|
||||||
|
en place et inchangé).
|
||||||
|
|
||||||
|
Dépend du **ticket 1/3 (back)** : l'API ne renvoie/n'accepte plus ces 5 champs sur `client`.
|
||||||
|
Contexte : voir `README.md` du dossier `refonte-contact`.
|
||||||
|
|
||||||
|
## 2. Périmètre
|
||||||
|
|
||||||
|
### IN — fichiers `frontend/modules/commercial/`
|
||||||
|
|
||||||
|
| Fichier | Action |
|
||||||
|
|---|---|
|
||||||
|
| `pages/clients/new.vue` | Supprimer le bloc principal Nom/Prénom/Téléphones/Email (~l.27-63), l'état `main.firstName/lastName/email`, `mainPhones` (~l.445-459), la fonction `prefillFirstContact()` (~l.658-665) et son appel, le mapping payload POST `phonePrimary/phoneSecondary` (~l.513-524). Adapter `isMainValid` (~l.479-493) : la validation principale ne porte plus que sur `companyName` (+ relation/catégories selon RG existantes). L'onglet **Contacts** devient le point de saisie des coordonnées ; garantir au moins un `ClientContactBlock` vide au départ. |
|
||||||
|
| `pages/clients/[id]/edit.vue` | Supprimer les 5 champs du bloc principal (~l.32-73). `mapMainDraft()` et `buildMainPayload()` ne portent plus ces champs. L'onglet Contacts reste éditable. |
|
||||||
|
| `pages/clients/[id]/index.vue` | Supprimer l'affichage lecture seule des 5 champs du bloc principal (~l.49-104, partie contact). Conserver l'onglet Contacts (lecture seule). |
|
||||||
|
| `types/clientForm.ts` | `MainFormDraft` : retirer `firstName`, `lastName`, `email`, `phonePrimary`, `phoneSecondary`, `hasSecondaryPhone`. Garder `ContactFormDraft` (inchangé). |
|
||||||
|
| `types/clientConsultation.ts` | `ClientDetail` : retirer `firstName/lastName/phonePrimary/phoneSecondary/email` (les commentaires « Contact principal »). Garder `ContactRead`. |
|
||||||
|
| `utils/clientEdit.ts` | `mapMainDraft()` et `buildMainPayload()` : retirer les 5 champs. Garder `buildContactPayload()`. |
|
||||||
|
| `utils/clientConsultation.ts` | Retirer toute lecture des 5 champs inline du client (garder `mapContactToDraft`, `contactOptionsOf`). |
|
||||||
|
| `i18n/locales/fr.json` | Retirer `commercial.clients.form.main.firstName/lastName/email/phonePrimary/phoneSecondary/addPhone`. **Conserver** tout le bloc `commercial.clients.form.contact.*`. Vérifier qu'aucune autre vue ne référence les clés retirées. |
|
||||||
|
| `**/__tests__/*.spec.ts` | Mettre à jour `clientFormRules.spec.ts`, `clientEdit.spec.ts`, `clientConsultation.spec.ts` (cf. § 4). |
|
||||||
|
|
||||||
|
### OUT
|
||||||
|
|
||||||
|
- `ClientContactBlock.vue`, l'onglet Contacts, `useClient`, la liste/répertoire
|
||||||
|
(`pages/clients/index.vue` — ses colonnes n'affichent déjà pas le contact inline) :
|
||||||
|
**inchangés**.
|
||||||
|
- Le back → ticket 1/3. Les specs → ticket 3/3.
|
||||||
|
|
||||||
|
## 3. Comportement attendu après modification
|
||||||
|
|
||||||
|
- **Création** : le formulaire principal demande l'entreprise (et relation/catégories selon
|
||||||
|
l'existant), plus de Nom/Prénom/Téléphone/Email inline. L'utilisateur renseigne les
|
||||||
|
coordonnées dans l'onglet **Contacts**. La création reste valide tant qu'il y a
|
||||||
|
`companyName` **et** ≥ 1 bloc Contact valide (Nom OU Prénom) — RG-1.05/RG-1.14 inchangées.
|
||||||
|
- **Consultation** : plus de bloc contact principal ; l'onglet Contacts affiche les
|
||||||
|
contacts.
|
||||||
|
- **Modification** : idem ; le PATCH du groupe `client:write:main` n'envoie plus les 5
|
||||||
|
champs.
|
||||||
|
|
||||||
|
## 4. Tests Vitest à mettre à jour
|
||||||
|
|
||||||
|
- `clientFormRules.spec.ts` : la validité du « principal » ne dépend plus de
|
||||||
|
firstName/email/phone ; conserver `isContactNamed()` (RG-1.05) sur les blocs Contacts.
|
||||||
|
- `clientEdit.spec.ts` : `buildMainPayload()` ne contient plus les 5 champs ; `mapMainDraft()`
|
||||||
|
non plus.
|
||||||
|
- `clientConsultation.spec.ts` : retirer les assertions sur les 5 champs inline.
|
||||||
|
|
||||||
|
## 5. Tips & rappels projet
|
||||||
|
|
||||||
|
- `useApi()` obligatoire (jamais `$fetch`/`ofetch`). Composants `Malio*` obligatoires.
|
||||||
|
- État de tableau jamais dans l'URL (règle inchangée).
|
||||||
|
- Les valeurs sont **normalisées côté serveur** (Capitalize / chiffres / lowercase) : le
|
||||||
|
front envoie la saisie et réaffiche la valeur renvoyée — ne pas réintroduire de
|
||||||
|
normalisation front.
|
||||||
|
- Ne pas créer de clé i18n orpheline ni laisser de clé `form.main.*` morte.
|
||||||
|
|
||||||
|
## 6. Critères d'acceptation (DoD)
|
||||||
|
|
||||||
|
- [ ] Les 3 écrans n'affichent plus Nom/Prénom/Téléphone/Téléphone 2/Email en bloc principal.
|
||||||
|
- [ ] Le parcours de création fonctionne avec `companyName` + onglet Contacts (≥ 1 contact).
|
||||||
|
- [ ] `MainFormDraft` / `ClientDetail` ne déclarent plus les 5 champs ; `mapMainDraft` /
|
||||||
|
`buildMainPayload` non plus.
|
||||||
|
- [ ] Aucune clé i18n `form.main.firstName/lastName/email/phone*` restante ni référencée.
|
||||||
|
- [ ] `make nuxt-test` vert.
|
||||||
|
- [ ] Vérification visuelle du golden path (`make dev-nuxt`, port 3004) : création →
|
||||||
|
consultation → modification d'un client sans bloc contact inline.
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# Prompt d'implémentation — M1 · Ticket 2/3 (Frontend)
|
||||||
|
|
||||||
|
Projet **Starseed** (Nuxt 4 / Vue 3 Composition API / TypeScript / @malio/layer-ui).
|
||||||
|
Lis `CLAUDE.md` et `.claude/rules/frontend.md` avant de coder. Commentaires en français,
|
||||||
|
code en anglais, 4 espaces d'indentation.
|
||||||
|
|
||||||
|
## Mission
|
||||||
|
|
||||||
|
Retirer le **bloc « contact principal »** (Nom, Prénom, Téléphone, Téléphone 2, Email) des
|
||||||
|
écrans Client (création / consultation / modification) et de tout le code associé (types,
|
||||||
|
mappeurs, validations, i18n). Les contacts restent gérés par l'onglet **Contacts**
|
||||||
|
(`ClientContactBlock`, inchangé).
|
||||||
|
|
||||||
|
Spec détaillée : `docs/specs/M1-clients/refonte-contact/M1-ticket-02-front.md` (lis-la en
|
||||||
|
entier + le `README.md` du dossier). Ce ticket dépend du ticket back (l'API ne porte plus
|
||||||
|
les 5 champs sur `client`).
|
||||||
|
|
||||||
|
## Étapes
|
||||||
|
|
||||||
|
1. Explorer `frontend/modules/commercial/` : `pages/clients/new.vue`, `[id]/edit.vue`,
|
||||||
|
`[id]/index.vue`, `types/clientForm.ts`, `types/clientConsultation.ts`,
|
||||||
|
`utils/clientEdit.ts`, `utils/clientConsultation.ts`, `i18n/locales/fr.json`.
|
||||||
|
2. Supprimer le bloc principal des 3 écrans + l'état réactif `main.firstName/lastName/email`,
|
||||||
|
`mainPhones`, `prefillFirstContact()`.
|
||||||
|
3. Adapter `isMainValid` : ne dépend plus que de `companyName` (+ relation/catégories selon
|
||||||
|
l'existant). La garantie « ≥ 1 contact valide » reste portée par l'onglet Contacts.
|
||||||
|
4. Nettoyer les types (`MainFormDraft`, `ClientDetail`) et les mappeurs (`mapMainDraft`,
|
||||||
|
`buildMainPayload`, `clientConsultation`).
|
||||||
|
5. Retirer les clés i18n `form.main.firstName/lastName/email/phonePrimary/phoneSecondary/addPhone` ;
|
||||||
|
vérifier par recherche qu'aucune vue ne les utilise plus. **Garder** `form.contact.*`.
|
||||||
|
6. Mettre à jour les specs Vitest (`clientFormRules`, `clientEdit`, `clientConsultation`).
|
||||||
|
|
||||||
|
## Garde-fous
|
||||||
|
|
||||||
|
- `useApi()` uniquement ; composants `Malio*` uniquement ; pas d'état tableau dans l'URL.
|
||||||
|
- Ne touche pas `ClientContactBlock.vue`, l'onglet Contacts, ni la liste/répertoire.
|
||||||
|
- Pas de normalisation front (le serveur normalise).
|
||||||
|
|
||||||
|
## Vérification finale
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make nuxt-test # Vitest vert
|
||||||
|
make dev-nuxt # port 3004 — golden path manuel
|
||||||
|
```
|
||||||
|
|
||||||
|
Golden path à vérifier dans le navigateur : créer un client (entreprise + 1 contact dans
|
||||||
|
l'onglet Contacts), le consulter, le modifier — sans aucun bloc contact inline.
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
# M1 · Ticket 3/3 (Specs) — Acter la suppression du contact inline dans les specs M1
|
||||||
|
|
||||||
|
## 1. Objectif
|
||||||
|
|
||||||
|
Mettre à jour la **documentation fonctionnelle/technique M1** pour refléter la décision :
|
||||||
|
le contact principal inline est supprimé du `Client`, les contacts vivent uniquement dans
|
||||||
|
`ClientContact`. Les specs sont la **source de vérité** du projet (cf. `workflow.md`) : elles
|
||||||
|
doivent décrire le modèle cible, pas l'ancien.
|
||||||
|
|
||||||
|
> Idéalement réalisé **avant** les tickets 1 et 2 (la spec guide le code), mais peut être
|
||||||
|
> fait en parallèle. À minima, ne pas merger le code sans aligner la spec.
|
||||||
|
|
||||||
|
## 2. Fichiers à modifier
|
||||||
|
|
||||||
|
| Fichier | Sections concernées |
|
||||||
|
|---|---|
|
||||||
|
| `docs/specs/M1-clients/spec-back.md` | § 3.1 diagramme E-R (retirer les 5 colonnes du bloc `client`) ; § 3.2 migration SQL `CREATE TABLE client` (retirer `first_name`/`last_name`/`phone_primary`/`phone_secondary`/`email` + leurs COMMENT) ; § 3.4 squelette entité `Client` (retirer les 5 props) ; § 4.3 exemple payload `POST /api/clients` (retirer les 5 champs) ; § 4.1 filtre `?search=` (refléter D1) ; § 4.6 export (refléter D2) ; § 7 RG (voir § 3 ci-dessous) ; § 8 cahier de tests (déplacer RG-1.01/1.02 vers ClientContact). |
|
||||||
|
| `docs/specs/M1-clients/spec-front.md` | « Formulaire principal » (l.85-103) : retirer les lignes Nom/Prénom/Téléphone/Téléphone 2/Email ; écrans Consultation / Modification ; règles de formatage. Préciser que les coordonnées se saisissent dans l'onglet Contact. |
|
||||||
|
| `docs/specs/M1-clients/cahier-test-back-M1.md` | Retirer / requalifier les lignes RG-1.01 et RG-1.02 (désormais couvertes par RG-1.05 sur `ClientContact`). |
|
||||||
|
|
||||||
|
## 3. Traitement des règles de gestion
|
||||||
|
|
||||||
|
- **RG-1.01** (firstName OU lastName obligatoire sur Client) → marquer **supprimée** :
|
||||||
|
« Remplacée par RG-1.05 (≥ 1 contact valide) + RG-1.14 (≥ 1 bloc Contact). Le contact
|
||||||
|
principal inline n'existe plus. »
|
||||||
|
- **RG-1.02** (max 2 téléphones sur Client) → marquer **supprimée du Client** (reste
|
||||||
|
applicable aux blocs `ClientContact`).
|
||||||
|
- **RG-1.19 / RG-1.20 / RG-1.21** (normalisation) → préciser que le **scope `Client`
|
||||||
|
disparaît** ; la normalisation reste sur `ClientContact` (et `ClientAddress.billingEmail`
|
||||||
|
pour RG-1.21).
|
||||||
|
- Ne **pas renuméroter** les RG existantes (éviter le drift avec le code/tests) : marquer
|
||||||
|
« supprimée / requalifiée » en place, avec date et renvoi à la décision.
|
||||||
|
|
||||||
|
## 4. Forme
|
||||||
|
|
||||||
|
- Bumper la version des deux specs (`version: V0` → `V1`) dans le frontmatter, avec une
|
||||||
|
entrée d'historique : date `2026-06-03`, motif « Suppression du contact inline du Client
|
||||||
|
(refonte-contact) », auteur.
|
||||||
|
- Ajouter un encadré « Décision » en tête de la section modèle de données, renvoyant au
|
||||||
|
`README.md` du dossier `refonte-contact`.
|
||||||
|
- Conserver le style des specs (sections numérotées, tableaux RG, exemples JSON).
|
||||||
|
|
||||||
|
## 5. Critères d'acceptation (DoD)
|
||||||
|
|
||||||
|
- [ ] `spec-back.md` : aucune mention des 5 colonnes inline dans le modèle `client`
|
||||||
|
(E-R + SQL + entité + payload) ; RG-1.01/1.02 marquées supprimées ; D1/D2 décrites.
|
||||||
|
- [ ] `spec-front.md` : le formulaire principal ne liste plus les champs de contact ;
|
||||||
|
l'onglet Contact est présenté comme seul lieu de saisie des coordonnées.
|
||||||
|
- [ ] `cahier-test-back-M1.md` : RG-1.01/1.02 retirées/requalifiées.
|
||||||
|
- [ ] Versions bumpées (V1) + historique daté dans les deux specs.
|
||||||
|
- [ ] Cohérence vérifiée avec les tickets 1 et 2 (mêmes décisions D1/D2).
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Prompt d'implémentation — M1 · Ticket 3/3 (Specs)
|
||||||
|
|
||||||
|
Projet **Starseed**. Tâche **documentaire** : mettre à jour les specs M1 Clients pour acter
|
||||||
|
la suppression du contact principal inline du `Client`. Les specs sont la source de vérité ;
|
||||||
|
elles doivent décrire le modèle cible.
|
||||||
|
|
||||||
|
## Mission
|
||||||
|
|
||||||
|
Modifier `docs/specs/M1-clients/spec-back.md`, `spec-front.md` et `cahier-test-back-M1.md`
|
||||||
|
pour retirer le contact inline du `Client` (5 champs `firstName/lastName/phonePrimary/
|
||||||
|
phoneSecondary/email`) — les contacts vivent uniquement dans `ClientContact`.
|
||||||
|
|
||||||
|
Spec du ticket : `docs/specs/M1-clients/refonte-contact/M1-ticket-03-specs.md` (lis-la + le
|
||||||
|
`README.md` du dossier, qui contient la décision, les RG impactées et les décisions D1/D2).
|
||||||
|
|
||||||
|
## Étapes
|
||||||
|
|
||||||
|
1. Lire les 3 fichiers de specs M1 visés, repérer toutes les occurrences des 5 champs
|
||||||
|
(diagramme E-R, CREATE TABLE client, squelette entité, payload POST, filtre search,
|
||||||
|
export, RG, cahier de test).
|
||||||
|
2. Retirer les 5 colonnes du modèle `client` (E-R + SQL + entité + exemple JSON).
|
||||||
|
3. Marquer **supprimées** RG-1.01 et RG-1.02 (renvoi à RG-1.05/RG-1.14 sur `ClientContact`),
|
||||||
|
restreindre le scope de RG-1.19/1.20/1.21 à `ClientContact`. **Ne pas renuméroter** les RG.
|
||||||
|
4. Refléter les décisions D1 (recherche) et D2 (export) une fois tranchées.
|
||||||
|
5. Côté `spec-front.md` : retirer les champs de contact du formulaire principal ; présenter
|
||||||
|
l'onglet Contact comme seul lieu de saisie.
|
||||||
|
6. Bumper `version: V0 → V1` + ajouter une entrée d'historique datée (2026-06-03).
|
||||||
|
|
||||||
|
## Garde-fous
|
||||||
|
|
||||||
|
- Ne touche pas au code, uniquement aux `.md` de specs.
|
||||||
|
- Garde le style existant (sections numérotées, tableaux RG, exemples JSON).
|
||||||
|
- Cohérence stricte avec les tickets 1 (back) et 2 (front) : mêmes décisions D1/D2.
|
||||||
|
|
||||||
|
## Vérification
|
||||||
|
|
||||||
|
Relire les 3 fichiers : plus aucune mention des 5 champs inline dans le modèle `client` ;
|
||||||
|
RG-1.01/1.02 marquées supprimées ; versions à V1 avec historique.
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# Amendement des tickets M2 existants — suppression du contact inline du `Supplier`
|
||||||
|
|
||||||
|
Les 14 tickets M2 (n° 84–97, groupe Lesstime « M2 — Répertoire fournisseurs ») ont été
|
||||||
|
rédigés sur le modèle initial **avec** contact inline. La décision `refonte-contact` les
|
||||||
|
amende : `Supplier` ne porte **plus** les 5 champs `firstName/lastName/phonePrimary/
|
||||||
|
phoneSecondary/email` ; les contacts vivent uniquement dans `SupplierContact` (onglet
|
||||||
|
Contacts). Comme M2 n'est pas codé, il suffit de **ne jamais créer** ces colonnes/champs.
|
||||||
|
|
||||||
|
## Bandeau injecté en tête des tickets impactés
|
||||||
|
|
||||||
|
> ⚠️ **AMENDEMENT 2026-06-03 — refonte-contact.** Le contact principal inline est
|
||||||
|
> **supprimé** du `Supplier` : ne pas créer/saisir les colonnes ni les champs `firstName`,
|
||||||
|
> `lastName`, `phonePrimary`, `phoneSecondary`, `email` sur l'entité/le formulaire
|
||||||
|
> `Supplier`. Les contacts sont gérés **uniquement** via `SupplierContact` (onglet
|
||||||
|
> Contacts). RG-2.01 et RG-2.02 sont supprimées (équivalent assuré par RG-2.04 / RG-2.13).
|
||||||
|
> RG-2.12 ne s'applique qu'à `companyName` + `SupplierContact`. Décisions transverses
|
||||||
|
> recherche (D1) et export (D2) : cf. `docs/specs/M1-clients/refonte-contact/README.md`.
|
||||||
|
|
||||||
|
## Tickets à amender
|
||||||
|
|
||||||
|
### Back
|
||||||
|
|
||||||
|
| Ticket | n° | Impact |
|
||||||
|
|---|---|---|
|
||||||
|
| migration BDD M2 (supplier + sous-collections) | #85 | Retirer `first_name/last_name/phone_primary/phone_secondary/email` du `CREATE TABLE supplier` et leurs `COMMENT ON COLUMN`. `supplier_contact` inchangé. |
|
||||||
|
| entités + repositories M2 | #86 | `Supplier` : retirer les 5 props + `Assert\Callback` RG-2.01. `SupplierContact` inchangé. |
|
||||||
|
| SupplierProvider + SupplierProcessor | #87 | Retirer la validation RG-2.01, la normalisation des champs inline, leur présence dans `MAIN_FIELDS` / changedFields. Recherche selon D1. |
|
||||||
|
| export XLSX fournisseurs | #91 | Colonnes contact selon D2 (depuis le contact principal, ou supprimées). |
|
||||||
|
| tests PHPUnit M2 | #92 | RG-2.01/2.02 testées sur `SupplierContact` (pas `Supplier`) ; contrat de sérialisation sans les 5 champs inline sur le supplier. |
|
||||||
|
|
||||||
|
### Front
|
||||||
|
|
||||||
|
| Ticket | n° | Impact |
|
||||||
|
|---|---|---|
|
||||||
|
| page Ajouter un fournisseur (`/suppliers/new`) + `useSupplierForm` | #94 | Retirer le bloc contact principal du formulaire + le pré-remplissage du 1er contact. Saisie des coordonnées dans l'onglet Contacts. |
|
||||||
|
| page Consultation fournisseur (`/suppliers/{id}`) | #95 | Retirer l'affichage du bloc contact principal. |
|
||||||
|
| page Modification fournisseur (`/suppliers/{id}/edit`) | #96 | Retirer les 5 champs du bloc principal ; payload `supplier:write:main` sans ces champs. |
|
||||||
|
|
||||||
|
### Léger
|
||||||
|
|
||||||
|
| Ticket | n° | Impact |
|
||||||
|
|---|---|---|
|
||||||
|
| page Répertoire fournisseurs + datatable | #93 | Recherche « nom / contact / email » selon D1. Datatable : colonnes inchangées (pas de contact inline en colonne). |
|
||||||
|
| i18n + sidebar fournisseurs | #97 | Ne pas créer les clés i18n `form.main.firstName/lastName/email/phone*` (garder `form.contact.*`). |
|
||||||
|
|
||||||
|
## Tickets NON impactés
|
||||||
|
|
||||||
|
- #84 (taxonomie FOURNISSEUR), #88 (sous-ressources contacts/adresses/ribs —
|
||||||
|
`SupplierContact` est la cible, inchangé), #89 (validators Information Commerciale /
|
||||||
|
catégorie / RG-2.07-2.08), #90 (RBAC fournisseurs).
|
||||||
|
|
||||||
|
## Méthode d'amendement
|
||||||
|
|
||||||
|
Pour chaque ticket impacté : **préfixer** la description existante du bandeau ci-dessus
|
||||||
|
(sans rien supprimer du contenu d'origine), via `mcp__lesstime__update-task`
|
||||||
|
(`description` = bandeau + description actuelle). La méthode préserve l'historique et reste
|
||||||
|
réversible (retirer le bandeau).
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# M2 · Ticket Specs — Retirer le contact inline du `Supplier` dans les specs M2
|
||||||
|
|
||||||
|
## 1. Objectif
|
||||||
|
|
||||||
|
Mettre à jour les specs **M2 Fournisseurs** déjà rédigées pour **ne plus inclure** le contact
|
||||||
|
principal inline sur le `Supplier`. M2 est le jumeau strict de M1 (`Supplier` /
|
||||||
|
`SupplierContact` / `SupplierAddress` / `SupplierRib`) et n'est **pas encore codé** : il faut
|
||||||
|
donc corriger la conception **en amont**, pour que les 14 tickets M2 « prêts à dev » soient
|
||||||
|
implémentés directement sans les 5 colonnes inline.
|
||||||
|
|
||||||
|
> Pendant de M1 ticket 3/3, mais côté M2 : **aucune migration de suppression ni backfill** —
|
||||||
|
> on retire simplement le contact inline du modèle cible. Contexte : `README.md` du dossier
|
||||||
|
> `refonte-contact`.
|
||||||
|
|
||||||
|
## 2. Fichiers à modifier
|
||||||
|
|
||||||
|
| Fichier | Sections concernées |
|
||||||
|
|---|---|
|
||||||
|
| `docs/specs/M2-suppliers/spec-back.md` | § 3.1 diagramme E-R (l.175-179 : retirer les 5 colonnes du bloc `supplier`) ; § 3.2 `CREATE TABLE supplier` (l.227-231) ; § 3.4 squelette entité `Supplier` (l.496-517 : props + `Assert\Callback` RG-2.01) ; § 4 exemples payload POST/GET (l.782-805, 867-871) ; recherche `?search=` (l.847 : refléter D1) ; export (refléter D2) ; § contrat de sérialisation (l.725, 729) ; § 7 RG (voir § 3). |
|
||||||
|
| `docs/specs/M2-suppliers/spec-front.md` | « Formulaire principal » (l.105-117 : retirer Nom/Prénom/Téléphone/Téléphone 2/Email) ; onglet « Contact » (l.140-157 : retirer la phrase de pré-remplissage depuis le formulaire principal, l.142) ; écrans Consultation/Modification ; règles de formatage (l.283-285) ; recherche (l.76 : refléter D1). |
|
||||||
|
|
||||||
|
## 3. Traitement des règles de gestion M2
|
||||||
|
|
||||||
|
- **RG-2.01** (firstName OU lastName obligatoire sur Supplier) → **supprimée** : remplacée
|
||||||
|
par RG-2.04 (≥ 1 contact valide) + RG-2.13 (≥ 1 bloc Contact). Le contact inline n'existe
|
||||||
|
plus sur `Supplier`.
|
||||||
|
- **RG-2.02** (max 2 téléphones sur Supplier) → **supprimée du Supplier** (reste sur
|
||||||
|
`SupplierContact`).
|
||||||
|
- **RG-2.12** (normalisation Capitalize / chiffres / lowercase) → restreindre le scope :
|
||||||
|
s'applique à `companyName` (UPPERCASE) et aux champs de `SupplierContact` ; **plus** aux
|
||||||
|
champs inline du `Supplier` (qui disparaissent).
|
||||||
|
- Ne pas renuméroter les RG : marquer « supprimée / requalifiée » en place, avec date.
|
||||||
|
|
||||||
|
## 4. Forme
|
||||||
|
|
||||||
|
- Bumper la version des deux specs M2 + entrée d'historique datée (2026-06-03, motif
|
||||||
|
« Suppression du contact inline du Supplier — alignement refonte-contact M1 »).
|
||||||
|
- Encadré « Décision » renvoyant au `README.md` du dossier `refonte-contact`.
|
||||||
|
- Garder le style des specs M2.
|
||||||
|
|
||||||
|
## 5. Lien avec les tickets M2 existants
|
||||||
|
|
||||||
|
La mise à jour des specs doit être cohérente avec l'**amendement des tickets M2** (voir
|
||||||
|
`M2-amendement-tickets.md`) : tickets back #85/#86/#87/#91/#92 et front #94/#95/#96 (+ #93/#97
|
||||||
|
légers). Specs et tickets décrivent le **même** modèle cible (sans contact inline).
|
||||||
|
|
||||||
|
## 6. Critères d'acceptation (DoD)
|
||||||
|
|
||||||
|
- [ ] `spec-back.md` M2 : aucune mention des 5 colonnes inline dans le modèle `supplier`
|
||||||
|
(E-R + SQL + entité + payloads + sérialisation) ; RG-2.01/2.02 marquées supprimées ;
|
||||||
|
D1/D2 décrites.
|
||||||
|
- [ ] `spec-front.md` M2 : formulaire principal sans champs de contact ; onglet Contact
|
||||||
|
présenté comme seul lieu de saisie (sans pré-remplissage depuis le principal).
|
||||||
|
- [ ] Versions bumpées + historique daté.
|
||||||
|
- [ ] Cohérence avec l'amendement des tickets M2.
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Prompt d'implémentation — M2 · Ticket Specs
|
||||||
|
|
||||||
|
Projet **Starseed**. Tâche **documentaire**. Mettre à jour les specs M2 Fournisseurs
|
||||||
|
(`docs/specs/M2-suppliers/spec-back.md` + `spec-front.md`) pour retirer le contact principal
|
||||||
|
inline du `Supplier` (5 champs `firstName/lastName/phonePrimary/phoneSecondary/email`).
|
||||||
|
|
||||||
|
M2 n'est **pas encore codé** : on corrige la conception en amont, **sans** migration ni
|
||||||
|
backfill (contrairement à M1). Les contacts vivent uniquement dans `SupplierContact`.
|
||||||
|
|
||||||
|
Spec du ticket : `docs/specs/M1-clients/refonte-contact/M2-ticket-specs.md` (lis-la + le
|
||||||
|
`README.md` du dossier).
|
||||||
|
|
||||||
|
## Étapes
|
||||||
|
|
||||||
|
1. Lire `spec-back.md` et `spec-front.md` M2 ; repérer toutes les occurrences des 5 champs
|
||||||
|
(E-R l.175-179, CREATE TABLE supplier l.227-231, entité l.496-517, payloads l.782-805 /
|
||||||
|
867-871, sérialisation l.725-729, RG-2.01/2.02/2.12, recherche, export, formulaire
|
||||||
|
principal front l.105-117, pré-remplissage onglet Contact l.142).
|
||||||
|
2. Retirer les 5 colonnes du modèle `supplier`.
|
||||||
|
3. Marquer **supprimées** RG-2.01 et RG-2.02 (renvoi RG-2.04/RG-2.13) ; restreindre RG-2.12
|
||||||
|
à `companyName` + `SupplierContact`. Ne pas renuméroter.
|
||||||
|
4. Refléter D1 (recherche : LEFT JOIN supplier_contact recommandé) et D2 (export depuis le
|
||||||
|
contact principal recommandé).
|
||||||
|
5. Front : retirer les champs de contact du formulaire principal ; retirer la phrase de
|
||||||
|
pré-remplissage du 1er bloc Contact ; présenter l'onglet Contact comme seul lieu de saisie.
|
||||||
|
6. Bumper la version + historique daté (2026-06-03).
|
||||||
|
|
||||||
|
## Garde-fous
|
||||||
|
|
||||||
|
- Uniquement les `.md` de specs M2. Style existant conservé.
|
||||||
|
- Cohérence stricte avec l'amendement des tickets M2 et avec la décision M1 (jumeau).
|
||||||
|
|
||||||
|
## Vérification
|
||||||
|
|
||||||
|
Relire les 2 specs : plus aucune mention des 5 champs inline dans le modèle `supplier` ;
|
||||||
|
RG-2.01/2.02 supprimées ; versions bumpées.
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
# Refonte « contact » — suppression du contact inline des tiers (Client M1 + Supplier M2)
|
||||||
|
|
||||||
|
> Dossier de tickets transverse. Source de vérité de la décision et de son découpage.
|
||||||
|
> Rédigé le 2026-06-03. Owner : Matthieu.
|
||||||
|
|
||||||
|
## 1. Décision
|
||||||
|
|
||||||
|
Le **contact « principal » inline** (les 5 colonnes plates `first_name`, `last_name`,
|
||||||
|
`phone_primary`, `phone_secondary`, `email`) est **supprimé de l'entité tier** (`Client`,
|
||||||
|
puis `Supplier`). La gestion des contacts passe **exclusivement** par la sous-entité
|
||||||
|
dédiée (`ClientContact` / `SupplierContact`), c.-à-d. l'**onglet « Contacts »**.
|
||||||
|
|
||||||
|
### Pourquoi
|
||||||
|
|
||||||
|
- **Modèle unique, zéro duplication.** Aujourd'hui le contact est saisi deux fois : une
|
||||||
|
fois dans le bloc principal (inline sur le tier) et une fois dans l'onglet Contacts
|
||||||
|
(sous-entité). À la création, le front recopie même l'un dans l'autre
|
||||||
|
(`prefillFirstContact`). Deux sources pour la même information = risque de divergence.
|
||||||
|
- **Cohérence métier.** Un tier peut avoir plusieurs contacts ; il n'y a pas de raison
|
||||||
|
qu'un seul soit « privilégié » au niveau de la table tier. La notion de contact
|
||||||
|
appartient à la collection de contacts.
|
||||||
|
- **Garantie préservée.** L'invariant « il y a toujours au moins un contact » est déjà
|
||||||
|
assuré par la sous-entité : RG-1.05/RG-1.14 (M1) et RG-2.04/RG-2.13 (M2) imposent
|
||||||
|
**≥ 1 bloc Contact valide** (Nom OU Prénom). Supprimer le contact inline ne crée donc
|
||||||
|
aucun trou : le contact reste obligatoire, mais au bon endroit.
|
||||||
|
|
||||||
|
### Règles de gestion impactées
|
||||||
|
|
||||||
|
| RG | Avant | Après |
|
||||||
|
|---|---|---|
|
||||||
|
| RG-1.01 / RG-2.01 (firstName OU lastName obligatoire **sur le tier**) | sur `Client` / `Supplier` | **supprimée** du tier — équivalent assuré par RG-1.05 / RG-2.04 sur la sous-entité |
|
||||||
|
| RG-1.02 / RG-2.02 (max 2 téléphones **sur le tier**) | sur le tier | **supprimée** du tier — reste sur la sous-entité |
|
||||||
|
| RG-1.19/1.20/1.21 — RG-2.12 (normalisation Capitalize / chiffres / lowercase) | appliquée aux champs **du tier ET** de la sous-entité | ne s'applique plus aux champs du tier (qui n'existent plus) — **inchangée** sur la sous-entité |
|
||||||
|
|
||||||
|
## 2. Périmètre & découpage
|
||||||
|
|
||||||
|
### M1 — Clients (code DÉJÀ livré → suppression + migration de données)
|
||||||
|
|
||||||
|
| # | Ticket | Tag | Effort |
|
||||||
|
|---|--------|-----|--------|
|
||||||
|
| 1 | `M1-ticket-01-back` — supprimer le contact inline du `Client` (migration + backfill + entité + processor + provider + export + fixtures + tests) | Backend | M |
|
||||||
|
| 2 | `M1-ticket-02-front` — retirer le bloc contact principal des écrans création / consultation / modification | Frontend | M |
|
||||||
|
| 3 | `M1-ticket-03-specs` — acter la décision dans les specs M1 (back + front + cahier de test) | Maintenance | S |
|
||||||
|
|
||||||
|
### M2 — Fournisseurs (NON codé → on retire le contact inline dès la conception)
|
||||||
|
|
||||||
|
| # | Action | Tag | Effort |
|
||||||
|
|---|--------|-----|--------|
|
||||||
|
| 4 | `M2-ticket-specs` — mettre à jour les specs M2 déjà écrites (back + front) pour retirer le contact inline du `Supplier` | Maintenance | S |
|
||||||
|
| — | `M2-amendement-tickets` — amender les tickets M2 existants (n° 84–97) impactés (migration, entités, processor, export, front, tests, i18n) | — | — |
|
||||||
|
|
||||||
|
> M2 ne nécessite **pas** de migration de suppression ni de backfill : il suffit de **ne
|
||||||
|
> jamais créer** les 5 colonnes inline sur `supplier`. Le travail M2 est donc un
|
||||||
|
> ajustement de specs + un amendement des tickets « prêts à dev ».
|
||||||
|
|
||||||
|
## 3. Décisions transverses à trancher (mêmes pour M1 et M2)
|
||||||
|
|
||||||
|
Deux comportements s'appuyaient sur les colonnes inline du tier. À la suppression, il faut
|
||||||
|
choisir leur nouvelle source. Recommandation par défaut entre parenthèses.
|
||||||
|
|
||||||
|
- **D1 — Recherche serveur** (`?search=`). Aujourd'hui : fuzzy sur `companyName` +
|
||||||
|
`lastName` + `email` **du tier**. Après suppression, deux options :
|
||||||
|
- (a) restreindre la recherche à `companyName` seul (simple, mais perte de la recherche
|
||||||
|
par contact) ;
|
||||||
|
- (b) **[recommandé]** étendre la recherche en `LEFT JOIN` sur la sous-entité contact
|
||||||
|
(`first_name` / `last_name` / `email` du contact), pour préserver l'UX « recherche par
|
||||||
|
nom / contact / email » annoncée dans la barre de recherche.
|
||||||
|
- **D2 — Colonnes de l'export XLSX** (Nom contact / Prénom / Téléphone / Téléphone 2 /
|
||||||
|
Email). Après suppression :
|
||||||
|
- (a) supprimer ces colonnes ;
|
||||||
|
- (b) **[recommandé]** les alimenter depuis le **contact principal** (le contact de plus
|
||||||
|
petit `position`), pour garder un export utile.
|
||||||
|
|
||||||
|
Ces deux décisions sont à valider par le métier (Matthieu) avant implémentation et sont
|
||||||
|
rappelées dans chaque ticket concerné.
|
||||||
|
|
||||||
|
## 4. Fichiers de ce dossier
|
||||||
|
|
||||||
|
- `README.md` (ce fichier) — décision + découpage.
|
||||||
|
- `M1-ticket-01-back.md` / `.prompt.md` — description + prompt d'implémentation.
|
||||||
|
- `M1-ticket-02-front.md` / `.prompt.md`.
|
||||||
|
- `M1-ticket-03-specs.md` / `.prompt.md`.
|
||||||
|
- `M2-ticket-specs.md` / `.prompt.md`.
|
||||||
|
- `M2-amendement-tickets.md` — bandeau d'amendement + liste des tickets M2 à mettre à jour.
|
||||||
@@ -5,8 +5,11 @@ nom: "Répertoire clients"
|
|||||||
ecran: repertoire-clients
|
ecran: repertoire-clients
|
||||||
owner_spec: Matthieu
|
owner_spec: Matthieu
|
||||||
backup_spec: Tristan
|
backup_spec: Tristan
|
||||||
version: V0
|
version: V1
|
||||||
date_redaction: 2026-05-28
|
date_redaction: 2026-05-28
|
||||||
|
# Historique : V1 (2026-06-03) — Refonte contact : suppression du contact principal inline
|
||||||
|
# du Client (firstName/lastName/phonePrimary/phoneSecondary/email retirés de la table client).
|
||||||
|
# Les contacts vivent uniquement dans ClientContact. Cf. docs/specs/M1-clients/refonte-contact/README.md
|
||||||
|
|
||||||
# === LIENS ===
|
# === LIENS ===
|
||||||
spec_front: ./spec-front.md
|
spec_front: ./spec-front.md
|
||||||
@@ -203,11 +206,11 @@ Le **formatage `XX XX XX XX XX`** est fait à l'affichage côté front (filter V
|
|||||||
| | +-----------------------+ | (Catalog) |
|
| | +-----------------------+ | (Catalog) |
|
||||||
| id (PK) | +--------------+
|
| id (PK) | +--------------+
|
||||||
| company_name |
|
| company_name |
|
||||||
| first_name | +-----------------------+ +--------------+
|
| (contact inline | +-----------------------+ +--------------+
|
||||||
| last_name |--1:n-->| client_contact | | site |
|
| retiré V1 — |--1:n-->| client_contact | | site |
|
||||||
| phone_primary | +-----------------------+ | (Sites) |
|
| firstName, | +-----------------------+ | (Sites) |
|
||||||
| phone_secondary | +--------------+
|
| lastName, phones,| +--------------+
|
||||||
| email | +-----------------------+ ^
|
| email) | +-----------------------+ ^
|
||||||
| distributor_id |--1:n-->| client_address |--n:m---------+
|
| distributor_id |--1:n-->| client_address |--n:m---------+
|
||||||
| broker_id | +-----------------------+
|
| broker_id | +-----------------------+
|
||||||
| triage_service | |
|
| triage_service | |
|
||||||
@@ -302,11 +305,8 @@ CREATE TABLE client (
|
|||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
-- Formulaire principal
|
-- Formulaire principal
|
||||||
company_name VARCHAR(180) NOT NULL,
|
company_name VARCHAR(180) NOT NULL,
|
||||||
first_name VARCHAR(120),
|
-- Contact inline retiré (V1, refonte-contact) : first_name / last_name / phone_primary /
|
||||||
last_name VARCHAR(120),
|
-- phone_secondary / email vivent désormais uniquement dans client_contact (onglet Contacts).
|
||||||
phone_primary VARCHAR(20) NOT NULL,
|
|
||||||
phone_secondary VARCHAR(20),
|
|
||||||
email VARCHAR(180) NOT NULL,
|
|
||||||
distributor_id INT REFERENCES client(id) ON DELETE SET NULL,
|
distributor_id INT REFERENCES client(id) ON DELETE SET NULL,
|
||||||
broker_id INT REFERENCES client(id) ON DELETE SET NULL,
|
broker_id INT REFERENCES client(id) ON DELETE SET NULL,
|
||||||
triage_service BOOLEAN NOT NULL DEFAULT FALSE,
|
triage_service BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
@@ -580,32 +580,9 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
#[Groups(['client:read', 'client:write:main'])]
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
private ?string $companyName = null;
|
private ?string $companyName = null;
|
||||||
|
|
||||||
// RG-1.01 — first_name OU last_name obligatoire (validation Assert\Callback
|
// Contact inline retiré (V1, refonte-contact) : firstName / lastName / phonePrimary /
|
||||||
// au niveau de l'entite, levee dans le Processor).
|
// phoneSecondary / email ne sont plus portés par Client — ils vivent dans ClientContact
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
// (onglet Contacts). La garantie « ≥ 1 contact nommé » est portée par RG-1.05 + RG-1.14.
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $firstName = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $lastName = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 20)]
|
|
||||||
#[Assert\NotBlank]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $phonePrimary = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 20, nullable: true)]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $phoneSecondary = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
|
||||||
#[Assert\NotBlank]
|
|
||||||
#[Assert\Email]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $email = null;
|
|
||||||
|
|
||||||
// RG-1.03 — distributor / broker auto-references (mutuellement exclusives,
|
// RG-1.03 — distributor / broker auto-references (mutuellement exclusives,
|
||||||
// contrainte CHECK en base).
|
// contrainte CHECK en base).
|
||||||
@@ -749,7 +726,7 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
- **Query params** :
|
- **Query params** :
|
||||||
- `includeArchived=true|false` (default `false`)
|
- `includeArchived=true|false` (default `false`)
|
||||||
- `categoryCode=<code>` (filtre les clients ayant ≥ 1 `Category` de ce code stable — ERP-78 ; ex. `DISTRIBUTEUR`, `COURTIER`)
|
- `categoryCode=<code>` (filtre les clients ayant ≥ 1 `Category` de ce code stable — ERP-78 ; ex. `DISTRIBUTEUR`, `COURTIER`)
|
||||||
- `search=<text>` (recherche fuzzy sur companyName + lastName + email)
|
- `search=<text>` (recherche fuzzy sur companyName + contacts liés `client_contact` (firstName / lastName / email) via LEFT JOIN groupé par `client.id` — décision D1, refonte-contact)
|
||||||
- **Tri par défaut** : `companyName ASC`
|
- **Tri par défaut** : `companyName ASC`
|
||||||
- **Pagination** : front via `<MalioDataTable>` (volumétrie cible faible). Pas de pagination serveur au M1.
|
- **Pagination** : front via `<MalioDataTable>` (volumétrie cible faible). Pas de pagination serveur au M1.
|
||||||
- **Réponse 200** (JSON-LD Hydra) : items avec champs `client:read` UNIQUEMENT (pas les champs `client:read:accounting` sauf si l'user a la permission `accounting.view`).
|
- **Réponse 200** (JSON-LD Hydra) : items avec champs `client:read` UNIQUEMENT (pas les champs `client:read:accounting` sauf si l'user a la permission `accounting.view`).
|
||||||
@@ -768,10 +745,6 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"companyName": "ACME SAS",
|
"companyName": "ACME SAS",
|
||||||
"firstName": "Jean",
|
|
||||||
"lastName": "Dupont",
|
|
||||||
"phonePrimary": "0612345678",
|
|
||||||
"email": "jean.dupont@acme.fr",
|
|
||||||
"categories": ["/api/categories/3", "/api/categories/7"],
|
"categories": ["/api/categories/3", "/api/categories/7"],
|
||||||
"distributor": null,
|
"distributor": null,
|
||||||
"broker": null,
|
"broker": null,
|
||||||
@@ -783,7 +756,7 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
- `201` / `400` / `401` / `403`
|
- `201` / `400` / `401` / `403`
|
||||||
- `409 Conflict` si doublon de nom de société (`companyName` — RG-1.16). SIREN et email ne sont pas uniques (cf. Q4, § 2.4).
|
- `409 Conflict` si doublon de nom de société (`companyName` — RG-1.16). SIREN et email ne sont pas uniques (cf. Q4, § 2.4).
|
||||||
- `422 Unprocessable Entity` :
|
- `422 Unprocessable Entity` :
|
||||||
- RG-1.01 : ni firstName ni lastName
|
- (RG-1.01 supprimée V1 — la complétude du contact est portée par l'onglet Contacts : RG-1.05 / RG-1.14)
|
||||||
- RG-1.03 : distributor + broker remplis simultanément
|
- RG-1.03 : distributor + broker remplis simultanément
|
||||||
- Catégories vides (Assert\Count min=1)
|
- Catégories vides (Assert\Count min=1)
|
||||||
|
|
||||||
@@ -885,8 +858,8 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
|
|
||||||
### Formulaire principal
|
### Formulaire principal
|
||||||
|
|
||||||
- **RG-1.01** : Au moins l'un des champs `firstName` (Prénom du contact principal) ou `lastName` (Nom du contact principal) doit être renseigné. Sinon → 422.
|
- ~~**RG-1.01**~~ _(SUPPRIMÉE — V1, 2026-06-03, refonte-contact)_ : le contact principal inline est retiré du `Client`. La garantie « au moins un contact nommé » est désormais portée par **RG-1.05** (bloc Contact valide) + **RG-1.14** (≥ 1 bloc Contact) sur `ClientContact`.
|
||||||
- **RG-1.02** : Le champ `phoneSecondary` est optionnel et apparaît au clic sur un bouton `+` côté front. Maximum 2 téléphones (primary + secondary). Comportement purement front au niveau UI ; côté serveur, les 2 colonnes existent et sont distinctes.
|
- ~~**RG-1.02**~~ _(SUPPRIMÉE du Client — V1, refonte-contact)_ : plus de téléphones inline sur le `Client`. Le « maximum 2 téléphones » reste applicable aux blocs `ClientContact` (normalisation RG-1.20).
|
||||||
- **RG-1.03** : Les champs `distributor` et `broker` sont **mutuellement exclusifs** (au plus une seule des deux est renseignée). Tentative d'envoyer les deux → 422. Contrainte CHECK en base également : `NOT (distributor_id IS NOT NULL AND broker_id IS NOT NULL)`. Un `distributor` référencé doit porter une **`Category` de code `DISTRIBUTEUR`** ; un `broker` une **`Category` de code `COURTIER`** — sinon 422. _(Refonte ERP-78 : le filtrage se fait sur le `code` de la `Category`, plus sur le type — `ClientProcessor::hasCategoryCode`.)_ La liste front de `distributor` = clients ayant une catégorie de code `DISTRIBUTEUR`, via `GET /api/clients?categoryCode=DISTRIBUTEUR` ; idem `broker` avec `COURTIER`.
|
- **RG-1.03** : Les champs `distributor` et `broker` sont **mutuellement exclusifs** (au plus une seule des deux est renseignée). Tentative d'envoyer les deux → 422. Contrainte CHECK en base également : `NOT (distributor_id IS NOT NULL AND broker_id IS NOT NULL)`. Un `distributor` référencé doit porter une **`Category` de code `DISTRIBUTEUR`** ; un `broker` une **`Category` de code `COURTIER`** — sinon 422. _(Refonte ERP-78 : le filtrage se fait sur le `code` de la `Category`, plus sur le type — `ClientProcessor::hasCategoryCode`.)_ La liste front de `distributor` = clients ayant une catégorie de code `DISTRIBUTEUR`, via `GET /api/clients?categoryCode=DISTRIBUTEUR` ; idem `broker` avec `COURTIER`.
|
||||||
|
|
||||||
### Onglet Information
|
### Onglet Information
|
||||||
@@ -910,6 +883,7 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
|
|
||||||
### Onglet Comptabilité
|
### Onglet Comptabilité
|
||||||
|
|
||||||
|
- **RG-1.30** _(ajoutée — correctif incohérence spec-front/spec-back)_ : à la **validation complète de l'onglet Comptabilité**, les six champs scalaires `siren`, `accountNumber`, `tvaMode`, `nTva`, `paymentDelay`, `paymentType` sont **obligatoires** (alignement sur spec-front § Onglet Comptabilité). Colonnes `nullable` en base (l'onglet est rempli dans un second temps, et l'onglet principal ne les envoie pas) + validateur contextuel `ClientAccountingCompletenessValidator` invoqué par le `ClientProcessor` — même parti que RG-1.04 (Information). Déclenchement : uniquement quand **les six champs sont présents dans le payload** (le front les envoie toujours ensemble via « Valider ») ; un PATCH ciblant un sous-ensemble de champs comptables (édition ponctuelle) n'est pas soumis à la complétude. Chaque champ manquant → 422 sur son `propertyPath` (mapping inline front, ERP-101). `bank` reste hors complétude (conditionnel RG-1.12).
|
||||||
- **RG-1.12** : Le champ `bank` est visible et obligatoire **uniquement** si `paymentType.code = 'VIREMENT'`. Validation server-side dans le `ClientProcessor` : si `payment_type.code = VIREMENT` et `bank IS NULL` → 422.
|
- **RG-1.12** : Le champ `bank` est visible et obligatoire **uniquement** si `paymentType.code = 'VIREMENT'`. Validation server-side dans le `ClientProcessor` : si `payment_type.code = VIREMENT` et `bank IS NULL` → 422.
|
||||||
- **RG-1.13** : Les champs RIB (`label`, `bic`, `iban`) sont obligatoires si **au moins un bloc RIB est présent ET** `paymentType.code = 'LCR'`. C'est-à-dire :
|
- **RG-1.13** : Les champs RIB (`label`, `bic`, `iban`) sont obligatoires si **au moins un bloc RIB est présent ET** `paymentType.code = 'LCR'`. C'est-à-dire :
|
||||||
- Si `paymentType.code = LCR` ET `client.ribs.count() = 0` → 422 « Au moins un RIB est obligatoire pour le type LCR ».
|
- Si `paymentType.code = LCR` ET `client.ribs.count() = 0` → 422 « Au moins un RIB est obligatoire pour le type LCR ».
|
||||||
@@ -929,9 +903,9 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
### Normalisation serveur (formatage)
|
### Normalisation serveur (formatage)
|
||||||
|
|
||||||
- **RG-1.18** : `companyName` est **upper-cased** intégralement côté serveur avant validation et persistance (`mb_strtoupper(trim($v), 'UTF-8')`). Le client n'a pas besoin de saisir en majuscules ; la BDD stocke en majuscules.
|
- **RG-1.18** : `companyName` est **upper-cased** intégralement côté serveur avant validation et persistance (`mb_strtoupper(trim($v), 'UTF-8')`). Le client n'a pas besoin de saisir en majuscules ; la BDD stocke en majuscules.
|
||||||
- **RG-1.19** : `firstName`, `lastName` (sur `Client` et `ClientContact`) sont **capitalize**-és serveur (`mb_convert_case(trim($v), MB_CASE_TITLE, 'UTF-8')`). Exemple : `JEAN dupont` → `Jean Dupont`.
|
- **RG-1.19** : `firstName`, `lastName` (sur `ClientContact` ; scope `Client` retiré en V1) sont **capitalize**-és serveur (`mb_convert_case(trim($v), MB_CASE_TITLE, 'UTF-8')`). Exemple : `JEAN dupont` → `Jean Dupont`.
|
||||||
- **RG-1.20** : Les champs téléphone (`phonePrimary`, `phoneSecondary` sur `Client`, et idem sur `ClientContact`) sont **normalisés à chiffres uniquement** côté serveur (`preg_replace('/\D+/', '', $v)`). Stockage : `0612345678`. Le **format affichage `XX XX XX XX XX`** est de la responsabilité du front via un filter Vue dédié (cf. spec-front).
|
- **RG-1.20** : Les champs téléphone (`phonePrimary`, `phoneSecondary` sur `ClientContact` ; scope `Client` retiré en V1) sont **normalisés à chiffres uniquement** côté serveur (`preg_replace('/\D+/', '', $v)`). Stockage : `0612345678`. Le **format affichage `XX XX XX XX XX`** est de la responsabilité du front via un filter Vue dédié (cf. spec-front).
|
||||||
- **RG-1.21** : `email` (`Client.email`, `ClientAddress.billingEmail`, `ClientContact.email`) est **lowercase** intégralement côté serveur (`mb_strtolower(trim($v), 'UTF-8')`).
|
- **RG-1.21** : `email` (`ClientAddress.billingEmail`, `ClientContact.email` ; `Client.email` retiré en V1) est **lowercase** intégralement côté serveur (`mb_strtolower(trim($v), 'UTF-8')`).
|
||||||
|
|
||||||
### Archivage
|
### Archivage
|
||||||
|
|
||||||
@@ -960,8 +934,8 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
|
|
||||||
### 8.1 Cas à couvrir (back — PHPUnit)
|
### 8.1 Cas à couvrir (back — PHPUnit)
|
||||||
|
|
||||||
- [ ] **RG-1.01** : POST sans firstName ni lastName → 422
|
- [ ] ~~RG-1.01~~ _(supprimée V1)_ : la complétude du contact est couverte par RG-1.05 / RG-1.14 sur `ClientContact`
|
||||||
- [ ] **RG-1.02** : POST avec phoneSecondary rempli → persistance OK ; PATCH ajoutant un 3e téléphone → côté API, 2 colonnes uniquement (test que le payload ne peut pas créer un 3e)
|
- [ ] ~~RG-1.02~~ _(supprimée du Client V1)_ : plus de téléphones inline sur le Client (téléphones testés sur `ClientContact`)
|
||||||
- [ ] **RG-1.03** : POST avec distributor ET broker → 422 ; POST distributor seul → 201
|
- [ ] **RG-1.03** : POST avec distributor ET broker → 422 ; POST distributor seul → 201
|
||||||
- [ ] **RG-1.03** : POST distributor référençant un client SANS catégorie de code DISTRIBUTEUR → 422 (validation custom `ClientProcessor::hasCategoryCode`)
|
- [ ] **RG-1.03** : POST distributor référençant un client SANS catégorie de code DISTRIBUTEUR → 422 (validation custom `ClientProcessor::hasCategoryCode`)
|
||||||
- [ ] **RG-1.04** : PATCH onglet Information par un user Commerciale avec champs incomplets → 422 ; même PATCH par Admin → 200
|
- [ ] **RG-1.04** : PATCH onglet Information par un user Commerciale avec champs incomplets → 422 ; même PATCH par Admin → 200
|
||||||
@@ -975,9 +949,9 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
- [ ] **RG-1.14** : front-driven uniquement, pas de test back
|
- [ ] **RG-1.14** : front-driven uniquement, pas de test back
|
||||||
- [ ] **RG-1.16** : POST avec `companyName` déjà pris → 409 ; POST avec même `companyName` après archivage de l'ancien → 201. SIREN et email dupliqués → 201 (plus d'unicité — RG-1.15/1.17 supprimées, Q4).
|
- [ ] **RG-1.16** : POST avec `companyName` déjà pris → 409 ; POST avec même `companyName` après archivage de l'ancien → 201. SIREN et email dupliqués → 201 (plus d'unicité — RG-1.15/1.17 supprimées, Q4).
|
||||||
- [ ] **RG-1.18** : POST `companyName="acme sas"` → BDD persiste `"ACME SAS"`
|
- [ ] **RG-1.18** : POST `companyName="acme sas"` → BDD persiste `"ACME SAS"`
|
||||||
- [ ] **RG-1.19** : POST `firstName="JEAN"`, `lastName="dupont"` → persiste `"Jean"`, `"Dupont"`
|
- [ ] **RG-1.19** : POST `firstName="JEAN"`, `lastName="dupont"` (via un bloc `ClientContact`) → persiste `"Jean"`, `"Dupont"`
|
||||||
- [ ] **RG-1.20** : POST `phonePrimary="06.12.34.56.78"` → persiste `"0612345678"`
|
- [ ] **RG-1.20** : POST `phonePrimary="06.12.34.56.78"` (via un bloc `ClientContact`) → persiste `"0612345678"`
|
||||||
- [ ] **RG-1.21** : POST `email="Jean.DUPONT@ACME.FR"` → persiste `"jean.dupont@acme.fr"`
|
- [ ] **RG-1.21** : POST `email="Jean.DUPONT@ACME.FR"` (via `ClientContact` ou `ClientAddress.billingEmail`) → persiste `"jean.dupont@acme.fr"`
|
||||||
- [ ] **RG-1.22/23** : PATCH isArchived=true par Bureau (sans `archive`) → 403 ; par Admin → 200 + archivedAt rempli ; PATCH isArchived=false sur un client archivé dont le SIREN a été repris → 409
|
- [ ] **RG-1.22/23** : PATCH isArchived=true par Bureau (sans `archive`) → 403 ; par Admin → 200 + archivedAt rempli ; PATCH isArchived=false sur un client archivé dont le SIREN a été repris → 409
|
||||||
- [ ] **RG-1.24/25** : GET liste sans flag → exclut archivés ; avec `?includeArchived=true` → inclut
|
- [ ] **RG-1.24/25** : GET liste sans flag → exclut archivés ; avec `?includeArchived=true` → inclut
|
||||||
- [ ] **RG-1.26** : GET liste → tri companyName ASC
|
- [ ] **RG-1.26** : GET liste → tri companyName ASC
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ nom: "Répertoire clients"
|
|||||||
ecran: repertoire-clients
|
ecran: repertoire-clients
|
||||||
owner_spec: Matthieu
|
owner_spec: Matthieu
|
||||||
backup_spec: Tristan
|
backup_spec: Tristan
|
||||||
version: V0
|
version: V1
|
||||||
|
# Historique : V1 (2026-06-03) — Refonte contact : suppression du bloc contact principal inline
|
||||||
|
# (Nom/Prénom/Téléphone/Téléphone 2/Email retirés du formulaire principal et des écrans).
|
||||||
|
# Saisie via l'onglet Contacts uniquement. Cf. docs/specs/M1-clients/refonte-contact/README.md
|
||||||
date_redaction: 2026-05-28
|
date_redaction: 2026-05-28
|
||||||
|
|
||||||
# === LIENS ===
|
# === LIENS ===
|
||||||
@@ -68,9 +71,6 @@ Composant : `<MalioDataTable>`. Colonnes (à raffiner avec Tristan en revue maqu
|
|||||||
| Colonne | Source | Tri |
|
| Colonne | Source | Tri |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| **Nom entreprise** | `client.companyName` | ASC par défaut |
|
| **Nom entreprise** | `client.companyName` | ASC par défaut |
|
||||||
| **Contact principal** | `firstName + lastName` | Oui |
|
|
||||||
| **Téléphone principal** | `phonePrimary` (formaté `XX XX XX XX XX`) | Non |
|
|
||||||
| **Email principal** | `email` | Oui |
|
|
||||||
| **Catégories** | liste des codes catégories séparés par `,` | Non |
|
| **Catégories** | liste des codes catégories séparés par `,` | Non |
|
||||||
| **Site(s)** | sites rattachés à au moins une adresse (badges colorés) | Non |
|
| **Site(s)** | sites rattachés à au moins une adresse (badges colorés) | Non |
|
||||||
|
|
||||||
@@ -86,15 +86,12 @@ Création par **onglets successifs avec validation incrémentale** : pour pouvoi
|
|||||||
|
|
||||||
C'est le 1er bloc à remplir. Sans validation de ce formulaire, les onglets ne sont pas accessibles.
|
C'est le 1er bloc à remplir. Sans validation de ce formulaire, les onglets ne sont pas accessibles.
|
||||||
|
|
||||||
|
> **V1 — refonte-contact** : le contact principal (Nom / Prénom / Téléphone / Téléphone 2 / Email) a été **retiré** du formulaire principal. Les coordonnées se saisissent désormais dans l'onglet **Contacts** (RG-1.05 / RG-1.14). Le formulaire principal ne contient plus que Entreprise + Catégorie + relation Distributeur/Courtier.
|
||||||
|
|
||||||
| Champ | Type composant | Obligatoire | Règle |
|
| Champ | Type composant | Obligatoire | Règle |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| **Nom du client (Entreprise)** | `<MalioInputText>` | Oui | RG-1.18 (normalisation UPPERCASE serveur) |
|
| **Nom du client (Entreprise)** | `<MalioInputText>` | Oui | RG-1.18 (normalisation UPPERCASE serveur) |
|
||||||
| **Nom du contact principal** | `<MalioInputText>` | Conditionnel | RG-1.01 + RG-1.19 (Capitalize) |
|
|
||||||
| **Prénom du contact principal** | `<MalioInputText>` | Conditionnel | RG-1.01 + RG-1.19 (Capitalize) |
|
|
||||||
| **Catégorie** | `<MalioSelectCheckbox>` (multi) | Oui | Liste des `Category` de l'API ; M2M Client ↔ Category |
|
| **Catégorie** | `<MalioSelectCheckbox>` (multi) | Oui | Liste des `Category` de l'API ; M2M Client ↔ Category |
|
||||||
| **Téléphone principal** | `<MalioInputText>` (masque tel) | Oui | RG-1.02 + RG-1.20 (format `XX XX XX XX XX`) |
|
|
||||||
| **Téléphone secondaire** | `<MalioInputText>` (masque tel) | Non | Apparaît au clic sur le bouton `+` (RG-1.02). Max 2 — bouton `+` disparaît une fois rempli. |
|
|
||||||
| **Email** | `<MalioInputText>` type email | Oui | RG-1.21 (lowercase) |
|
|
||||||
| **Distributeur / Courtier** | `<MalioSelect>` | Non | Valeurs : `Dépend du distributeur` / `Dépend du courtier` / `Aucun`. RG-1.03 conditionne les 2 champs suivants. |
|
| **Distributeur / Courtier** | `<MalioSelect>` | Non | Valeurs : `Dépend du distributeur` / `Dépend du courtier` / `Aucun`. RG-1.03 conditionne les 2 champs suivants. |
|
||||||
| **Nom du distributeur** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du distributeur ». Liste = clients ayant ≥ 1 catégorie de **code** `DISTRIBUTEUR` (ERP-78), via `GET /api/clients?categoryCode=DISTRIBUTEUR`. RG-1.03. |
|
| **Nom du distributeur** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du distributeur ». Liste = clients ayant ≥ 1 catégorie de **code** `DISTRIBUTEUR` (ERP-78), via `GET /api/clients?categoryCode=DISTRIBUTEUR`. RG-1.03. |
|
||||||
| **Nom du courtier** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du courtier ». Liste = clients ayant ≥ 1 catégorie de **code** `COURTIER` (ERP-78), via `GET /api/clients?categoryCode=COURTIER`. RG-1.03. |
|
| **Nom du courtier** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du courtier ». Liste = clients ayant ≥ 1 catégorie de **code** `COURTIER` (ERP-78), via `GET /api/clients?categoryCode=COURTIER`. RG-1.03. |
|
||||||
@@ -120,7 +117,7 @@ Saisir les informations de l'entreprise.
|
|||||||
|
|
||||||
### Onglet « Contact »
|
### Onglet « Contact »
|
||||||
|
|
||||||
Saisir un ou plusieurs contacts associés au client. Le 1er bloc est **pré-rempli** depuis les champs du formulaire principal (Nom, Prénom, Téléphone, Email — édition autorisée).
|
Saisir un ou plusieurs contacts associés au client. **(V1 — refonte-contact : plus de pré-remplissage depuis le formulaire principal ; les coordonnées du contact se saisissent directement ici.)** Au moins un bloc Contact valide est requis (RG-1.14).
|
||||||
|
|
||||||
**Bloc Contact** :
|
**Bloc Contact** :
|
||||||
|
|
||||||
@@ -250,7 +247,7 @@ Le serveur normalise systématiquement (cf. RG-1.18 à RG-1.21 dans [`spec-back.
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Nom entreprise (`companyName`) | UPPERCASE intégral | UPPERCASE |
|
| Nom entreprise (`companyName`) | UPPERCASE intégral | UPPERCASE |
|
||||||
| Nom + Prénom contact | Capitalize (1ère lettre majuscule + reste minuscule) | identique |
|
| Nom + Prénom contact | Capitalize (1ère lettre majuscule + reste minuscule) | identique |
|
||||||
| Téléphone (`phonePrimary`, `phoneSecondary`, contact phones) | Chiffres uniquement en BDD | Formaté `XX XX XX XX XX` à l'affichage (filter Vue) |
|
| Téléphone (téléphones des blocs `ClientContact`) | Chiffres uniquement en BDD | Formaté `XX XX XX XX XX` à l'affichage (filter Vue) |
|
||||||
| Email | lowercase intégral | identique |
|
| Email | lowercase intégral | identique |
|
||||||
|
|
||||||
> **Le front ne fait pas la normalisation** — il envoie la valeur saisie, le serveur normalise puis renvoie la valeur normalisée. L'UI affiche immédiatement la valeur normalisée renvoyée par l'API. Cohérent avec le pattern `useApi()`.
|
> **Le front ne fait pas la normalisation** — il envoie la valeur saisie, le serveur normalise puis renvoie la valeur normalisée. L'UI affiche immédiatement la valeur normalisée renvoyée par l'API. Cohérent avec le pattern `useApi()`.
|
||||||
@@ -261,7 +258,8 @@ Le composant `Code postal` + `Ville` + `Adresse` est branché sur **api-adresse.
|
|||||||
|
|
||||||
- Composable dédié `useAddressAutocomplete()` (à créer en M1).
|
- Composable dédié `useAddressAutocomplete()` (à créer en M1).
|
||||||
- Appel HTTP **direct depuis le front** (CORS OK), pas de proxy back.
|
- Appel HTTP **direct depuis le front** (CORS OK), pas de proxy back.
|
||||||
- Pattern : à la saisie du code postal (5 chiffres), GET `https://api-adresse.data.gouv.fr/search/?q={cp}&type=municipality` → alimente le select Ville. Sur saisie d'adresse : `?q={addr}&postcode={cp}&type=housenumber` → suggestions adresse.
|
- Pattern : à la saisie du code postal (5 chiffres), GET `https://api-adresse.data.gouv.fr/search/?q={cp}&type=municipality` → alimente le select Ville. Sur saisie d'adresse : `?q={addr}&postcode={cp}` (sans filtre `type`) → suggestions adresse.
|
||||||
|
- ⚠ **Ne pas forcer `type=housenumber`** sur la recherche d'adresse (corrigé en ERP-66) : la BAN ne renvoie un résultat de ce type qu'une fois un numéro saisi, donc une recherche par nom de rue (« boulevard du port ») renverrait **0 résultat** pendant toute la frappe. Sans filtre `type`, la BAN classe rues + numéros par pertinence — comportement d'autocomplétion attendu.
|
||||||
- Cas dégradé : si l'API ne répond pas (offline, timeout), le champ Ville devient un `<MalioInputText>` libre éditable + toast d'avertissement. Validation serveur acceptera la saisie libre.
|
- Cas dégradé : si l'API ne répond pas (offline, timeout), le champ Ville devient un `<MalioInputText>` libre éditable + toast d'avertissement. Validation serveur acceptera la saisie libre.
|
||||||
|
|
||||||
## Points laissés ouverts par la V0 (résolus côté back)
|
## Points laissés ouverts par la V0 (résolus côté back)
|
||||||
@@ -275,7 +273,7 @@ Le composant `Code postal` + `Ville` + `Adresse` est branché sur **api-adresse.
|
|||||||
| 5 | Onglets « À venir » | **Placeholders blancs** (frames vides, pas de message). Ré-activables sans rebuild quand les modules associés arriveront. |
|
| 5 | Onglets « À venir » | **Placeholders blancs** (frames vides, pas de message). Ré-activables sans rebuild quand les modules associés arriveront. |
|
||||||
| 6 | Archive vs soft delete | **Flag `is_archived` séparé de `deleted_at`**. Archive ≠ delete : un client archivé est masqué par défaut mais reste en BDD éditable (Admin seul). Filtres UI distincts. Soft delete = HP M2. |
|
| 6 | Archive vs soft delete | **Flag `is_archived` séparé de `deleted_at`**. Archive ≠ delete : un client archivé est masqué par défaut mais reste en BDD éditable (Admin seul). Filtres UI distincts. Soft delete = HP M2. |
|
||||||
| 7 | Unicité métier | **Nom d'entreprise uniquement** (case-insensitive, parmi non-archivés) — décision Q4. SIREN et email NON uniques. Index partiel Postgres `uq_client_company_name_active`. Doublon de nom → 409 Conflict. |
|
| 7 | Unicité métier | **Nom d'entreprise uniquement** (case-insensitive, parmi non-archivés) — décision Q4. SIREN et email NON uniques. Index partiel Postgres `uq_client_company_name_active`. Doublon de nom → 409 Conflict. |
|
||||||
| 8 | Téléphones (max 2) | **2 colonnes plates** `phone_primary` + `phone_secondary`. Pas de table séparée. |
|
| 8 | Téléphones (max 2) | Sur les blocs `ClientContact` (`phone_primary` + `phone_secondary`). _(V1 : retirés du Client — refonte-contact.)_ |
|
||||||
| 9 | API code postal | **api-adresse.data.gouv.fr** (BAN). Appel direct front via composable dédié. Cas dégradé : saisie libre + toast. |
|
| 9 | API code postal | **api-adresse.data.gouv.fr** (BAN). Appel direct front via composable dédié. Cas dégradé : saisie libre + toast. |
|
||||||
| 10 | Référentiels comptables | **4 entités CRUD-ables** (`TvaMode`, `PaymentDelay`, `PaymentType`, `Bank`) seedées au M1, CRUD admin futur (HP-M2). |
|
| 10 | Référentiels comptables | **4 entités CRUD-ables** (`TvaMode`, `PaymentDelay`, `PaymentType`, `Bank`) seedées au M1, CRUD admin futur (HP-M2). |
|
||||||
| 11 | Format de l'export | **XLSX uniquement** au M1. CSV à étudier en HP. |
|
| 11 | Format de l'export | **XLSX uniquement** au M1. CSV à étudier en HP. |
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,331 @@
|
|||||||
|
---
|
||||||
|
# === IDENTITÉ ===
|
||||||
|
module: M2
|
||||||
|
nom: "Répertoire fournisseurs"
|
||||||
|
ecran: repertoire-fournisseurs
|
||||||
|
owner_spec: Matthieu
|
||||||
|
backup_spec: Tristan
|
||||||
|
version: V0.2
|
||||||
|
date_redaction: 2026-06-02
|
||||||
|
# Historique : V0.2 (2026-06-03) — Refonte contact : suppression du bloc contact principal inline
|
||||||
|
# du formulaire Supplier (Nom/Prénom/Téléphone/Téléphone 2/Email). Saisie via l'onglet Contacts.
|
||||||
|
# Aligné sur M1. Cf. docs/specs/M1-clients/refonte-contact/README.md
|
||||||
|
|
||||||
|
# === LIENS ===
|
||||||
|
maquette_figma: "https://www.figma.com/design/jRYgT0T9c03VsEbjGhCwwS/Composants---Design-System?node-id=1132-36987&p=f&m=dev"
|
||||||
|
regles_metier: [RG-2.01, RG-2.02, RG-2.03, RG-2.04, RG-2.05, RG-2.06, RG-2.07, RG-2.08, RG-2.09, RG-2.10, RG-2.11, RG-2.12, RG-2.13, RG-2.14, RG-2.15, RG-2.16, RG-2.17]
|
||||||
|
roles: [Admin, Bureau, Compta, Commerciale, Usine]
|
||||||
|
lien_spec_back: ./spec-back.md
|
||||||
|
|
||||||
|
# === VALIDATION CLIENT ===
|
||||||
|
client_validation_1:
|
||||||
|
statut: validee
|
||||||
|
date: 2026-05-22
|
||||||
|
version: V0
|
||||||
|
valide_par: "Matthieu (CP MALIO)"
|
||||||
|
client_validation_2:
|
||||||
|
statut: validee
|
||||||
|
date: 2026-06-01
|
||||||
|
version: V0.1
|
||||||
|
valide_par: "Matthieu (CP MALIO)"
|
||||||
|
resume: "Module 2 — Répertoire fournisseurs. Page d'entrée Commercial. Datatable + 3 écrans (Ajouter / Consulter / Modifier). Création par onglets : Information / Contact / Adresse / Comptabilité (Transport, Statistiques, Rapports, Échanges = placeholders 'À venir')."
|
||||||
|
trace_archivee: "uploads/M2-reportoire-fournisseurs.docx (V0.1) + M2-reportoire-fournisseurs-V01.pdf"
|
||||||
|
|
||||||
|
# === LIEN LESSTIME ===
|
||||||
|
lesstime_taskgroup_id: 26
|
||||||
|
lesstime_project_id: 6
|
||||||
|
statut_global: a_dev
|
||||||
|
---
|
||||||
|
|
||||||
|
# Module 2 — Répertoire fournisseurs (V0.1 front)
|
||||||
|
|
||||||
|
> **Origine** : spec front livrée le 22/05/2026 (V0), amendée le 01/06/2026 (V0.1) — `M2-reportoire-fournisseurs.docx`. Restitution Markdown pour intégration au workflow MALIO. Le contenu fonctionnel original n'est pas modifié ; toute décision technique (back) vit dans [`spec-back.md`](./spec-back.md). Le M2 réutilise massivement le pattern et les composants posés au [M1 clients](../M1-clients/spec-front.md).
|
||||||
|
|
||||||
|
## But
|
||||||
|
|
||||||
|
Permettre aux utilisateurs Starseed (selon rôle) de gérer le **répertoire des fournisseurs** de l'organisation : consultation, création, modification, archivage. C'est la **deuxième porte d'entrée du module Commercial** (aux côtés des Clients).
|
||||||
|
|
||||||
|
## Accès
|
||||||
|
|
||||||
|
- **Depuis** : menu principal → section **Commercial** → entrée « Répertoire fournisseurs » (route `/suppliers`).
|
||||||
|
- **Rôles autorisés** :
|
||||||
|
|
||||||
|
| Rôle | Consultation | Création / Modification | Archivage |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Admin** | ✅ Tout | ✅ Tout | ✅ |
|
||||||
|
| **Bureau** | ✅ Tout | ✅ Tout sauf onglet Comptabilité | ❌ |
|
||||||
|
| **Compta** | ✅ Tout | ✅ Onglet Comptabilité uniquement | ❌ |
|
||||||
|
| **Commerciale** | ✅ Tout sauf Comptabilité | ✅ Tout sauf Comptabilité | ❌ |
|
||||||
|
| **Usine** | ❌ (pas d'accès) | ❌ | ❌ |
|
||||||
|
|
||||||
|
> **Note** : RBAC identique au M1, transposée sur `commercial.suppliers.*`. Compta édite uniquement l'onglet Comptabilité (SIREN / N° compte / TVA / Délai / Type de règlement / Banque / RIBs) d'un fournisseur existant ; Compta ne peut pas **créer** un fournisseur. **L'archivage est réservé à Admin** (cf. tableau du docx).
|
||||||
|
|
||||||
|
## Navigation
|
||||||
|
|
||||||
|
Page d'entrée du module **Commercial** (route `/suppliers`). Titre : « **Répertoire fournisseurs** ».
|
||||||
|
|
||||||
|
- Affichage principal : un **datatable** listant tous les fournisseurs **actifs** (les archivés sont masqués par défaut — toggle UI dédié).
|
||||||
|
- **Clic sur une ligne** → écran **Consultation fournisseur** (page dédiée).
|
||||||
|
- **Bouton « + Ajouter »** (haut droite) → écran **Ajouter un fournisseur**.
|
||||||
|
- **Bouton « Filtrer »** (haut droite, **à côté de « + Ajouter »**) → ouvre le **panneau de filtres** (cf. ci-dessous). Un badge/compteur indique le nombre de filtres actifs ; un bouton « Réinitialiser » les vide.
|
||||||
|
- **Bouton « Exporter »** (haut droite) → télécharge un **XLSX** des fournisseurs **affichés** (cf. filtres actifs). Format dans [`spec-back.md § 4.6`](./spec-back.md).
|
||||||
|
|
||||||
|
### Panneau de filtres (bouton « Filtrer »)
|
||||||
|
|
||||||
|
Ouvre un drawer/popover (composant à confirmer côté équipe front — réutiliser le pattern M1 s'il existe). Filtres proposés, branchés sur les query params de `GET /api/suppliers` (cf. [`spec-back.md § 4.1`](./spec-back.md)) :
|
||||||
|
|
||||||
|
| Filtre | Composant | Query param back |
|
||||||
|
|---|---|---|
|
||||||
|
| **Recherche** (nom entreprise / contact / email — recherche contact via `supplier_contact`, décision D1) | `<MalioInputText>` | `?search=` |
|
||||||
|
| **Catégorie** | `<MalioSelectCheckbox>` (multi, type FOURNISSEUR) | `?categoryCode=` |
|
||||||
|
| **Site** | `<MalioSelectCheckbox>` (86 / 17 / 82) | `?siteId=` |
|
||||||
|
| **Inclure les archivés** | `<MalioCheckbox>` | `?includeArchived=true` |
|
||||||
|
|
||||||
|
- À l'application des filtres → `setFilters(...)` de `usePaginatedList` (retombe en **page 1**), qui relance `GET /api/suppliers` avec les params.
|
||||||
|
- **État 100 % local** (jamais dans l'URL — règle ABSOLUE n°6). Le bouton « Filtrer » + son panneau remplacent/regroupent l'ancien toggle « archivés » isolé.
|
||||||
|
|
||||||
|
## Datatable du Répertoire
|
||||||
|
|
||||||
|
Composant : `<MalioDataTable>` branché sur `usePaginatedList<Supplier>({ url: '/suppliers' })` (règle frontend obligatoire — pagination Hydra, état 100 % local). Colonnes **conformes à la maquette Figma** (4 colonnes) :
|
||||||
|
|
||||||
|
| Colonne | Source | Tri |
|
||||||
|
|---|---|---|
|
||||||
|
| **Nom** | `supplier.companyName` | ASC par défaut |
|
||||||
|
| **Catégories** | `supplier.categories[].name` (embarquées en liste — cohérence M1/ERP-62 ; libellé = `name`, pas `label`) | Non |
|
||||||
|
| **Site** | `supplier.sites[].name` (agrégat des adresses via `getSites()` ; `Site` n'a pas de `code`) | Non |
|
||||||
|
| **Dernière activité** | `supplier.updatedAt` (format `JJ-MM-AAAA`) — exposé dans `supplier:read` | Oui |
|
||||||
|
|
||||||
|
> **Clic sur une ligne** (texte en bleu lien) → écran Consultation.
|
||||||
|
> **Filtres** : regroupés dans le panneau du bouton « Filtrer » (cf. section précédente), dont l'inclusion des archivés (désactivée par défaut). **État local** (jamais dans l'URL — règle ABSOLUE n°6).
|
||||||
|
> **Pagination** : `<MalioDataTable>` + `usePaginatedList`, options **standard Starseed 10 / 25 / 50 (défaut 10)** — on **n'applique pas** le « Ligne : 20 » de la maquette (décision Matthieu : on reste sur le standard). Tri serveur `companyName ASC` par défaut.
|
||||||
|
|
||||||
|
## Écran « Ajouter un fournisseur »
|
||||||
|
|
||||||
|
Création par **onglets successifs avec validation incrémentale** : pour passer à l'onglet suivant, il faut avoir validé l'onglet en cours. **Une fois un onglet validé, on passe automatiquement au suivant** ; les champs validés passent en lecture seule + bouton « Valider » désactivé (disabled). Cf. [`spec-back.md § 2.10`](./spec-back.md) (PATCH partiels par groupe de sérialisation).
|
||||||
|
|
||||||
|
**Barre d'onglets en création (5 onglets, conforme maquette)** : `Information` · `Contacts` · `Adresses` · `Transport` · `Comptabilité`. L'onglet `Information` est actif par défaut juste après validation du formulaire principal. Les onglets `Statistiques`, `Rapports` et `Échanges` **n'apparaissent PAS dans le flux de création** — ils ne sont présents qu'en Consultation / Modification.
|
||||||
|
|
||||||
|
### Formulaire principal (pré-onglets)
|
||||||
|
|
||||||
|
1er bloc à remplir. Sans validation, les onglets ne sont pas accessibles. Une fois validé → POST `/api/suppliers`, puis bascule sur l'onglet Information ; les champs passent en readonly.
|
||||||
|
|
||||||
|
> **V0.2 — refonte-contact** : le contact principal (Nom / Prénom / Téléphone / Téléphone 2 / Email) a été **retiré** du formulaire principal. Les coordonnées se saisissent dans l'onglet **Contacts** (RG-2.04 / RG-2.13). Le formulaire principal ne contient plus que Entreprise + Catégorie.
|
||||||
|
|
||||||
|
| Champ | Type composant | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Nom du fournisseur (Entreprise)** | `<MalioInputText>` | Oui | RG-2.12 (UPPERCASE serveur) |
|
||||||
|
| **Catégorie** | `<MalioSelectCheckbox>` (multi) | Oui | `Category` de **type FOURNISSEUR** via `GET /api/categories?typeCode=FOURNISSEUR` (RG-2.10). Libellé affiché = `category.name`. ⚠️ Le type + le filtre `?typeCode=` sont **à créer** côté back (n'existent pas en prod — cf. spec-back § 2.4). |
|
||||||
|
|
||||||
|
**Action** : « Valider » (`<MalioButton>`) → POST `/api/suppliers` ([`spec-back.md § 4.3`](./spec-back.md)). Succès → onglet « Information ».
|
||||||
|
|
||||||
|
### Onglet « Information »
|
||||||
|
|
||||||
|
Saisir les informations du fournisseur.
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Description** | `<MalioInputTextArea>` | Conditionnel | RG-2.03 (obligatoire rôle Commerciale) |
|
||||||
|
| **Concurrent** | `<MalioInputText>` | Conditionnel | RG-2.03 |
|
||||||
|
| **Date création** (entreprise) | `<input type="date">` (exception Malio — `// TODO migrer`) | Conditionnel | RG-2.03 |
|
||||||
|
| **Nombre de salariés** | `<MalioInputNumber>` | Conditionnel | RG-2.03 |
|
||||||
|
| **CA €** | `<MalioInputAmount>` | Conditionnel | RG-2.03 |
|
||||||
|
| **Dirigeant** | `<MalioInputText>` | Conditionnel | RG-2.03 |
|
||||||
|
| **Résultat €** | `<MalioInputAmount>` | Conditionnel | RG-2.03 |
|
||||||
|
| **Volume Prévisionnel** | `<MalioInputNumber>` | Conditionnel | RG-2.03 (champ spécifique fournisseur) |
|
||||||
|
|
||||||
|
> **Disposition maquette** : 3 colonnes — ligne 1 (Description / Concurrent / Date création), ligne 2 (Nombre de salariés / CA / Dirigeant), ligne 3 (Résultat / Volume Prévisionnel).
|
||||||
|
|
||||||
|
**Action** : « Valider » → PATCH `/api/suppliers/{id}` (groupe `supplier:write:information`).
|
||||||
|
|
||||||
|
### Onglet « Contact »
|
||||||
|
|
||||||
|
Saisir un ou plusieurs contacts. **(V0.2 — refonte-contact : plus de pré-remplissage depuis le formulaire principal ; les coordonnées du contact se saisissent directement ici.)** Au moins un bloc Contact valide est requis (RG-2.13).
|
||||||
|
|
||||||
|
**Bloc Contact** :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Nom** | `<MalioInputText>` | Conditionnel | RG-2.04 + RG-2.12 (Capitalize) |
|
||||||
|
| **Prénom** | `<MalioInputText>` | Conditionnel | RG-2.04 + RG-2.12 (Capitalize) |
|
||||||
|
| **Fonction** | `<MalioInputText>` | Non | — |
|
||||||
|
| **Téléphone** (x1, +1 possible) | `<MalioInputText>` | Non | RG-2.12 (format) |
|
||||||
|
| **Email** | `<MalioInputText>` type email | Non | RG-2.12 (lowercase) |
|
||||||
|
|
||||||
|
**RG-2.04 / RG-2.13** : au moins 1 bloc Contact valide (Nom OU Prénom rempli) pour valider l'onglet — l'onglet Contact ne peut pas être finalisé vide.
|
||||||
|
|
||||||
|
**Actions** :
|
||||||
|
- « + Nouveau contact » : ajoute un bloc. **Désactivé tant que le bloc précédent n'a pas Prénom OU Nom** (RG-2.04).
|
||||||
|
- « Supprimer » (icône) : modal de confirmation, puis suppression du bloc.
|
||||||
|
- « Valider » → PATCH `/api/suppliers/{id}/contacts`.
|
||||||
|
|
||||||
|
### Onglet « Adresse »
|
||||||
|
|
||||||
|
Saisir une ou plusieurs adresses, rattachées à un ou plusieurs sites (86 / 17 / 82) et à des contacts.
|
||||||
|
|
||||||
|
**Bloc Adresse** :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Type d'adresse** | `<MalioRadioButton>` — `Prospect` / `Départ` / `Rendu` | Oui | RG-2.09 (exclusif, enum `PROSPECT`/`DEPART`/`RENDU`) |
|
||||||
|
| **Pays** | `<MalioSelect>` (saisie assistée — préremplie « France ») | Oui | — |
|
||||||
|
| **Code postal** | `<MalioInputText>` (saisie assistée) | Oui | RG-2.05 — déclenche autocomplete ville (BAN) |
|
||||||
|
| **Ville** | `<MalioSelect>` (saisie assistée) | Oui | RG-2.05 — alimentée par api-adresse.data.gouv.fr suivant le CP |
|
||||||
|
| **Adresse** | `<MalioInputText>` (saisie assistée) | Oui | RG-2.05 — autocomplete BAN |
|
||||||
|
| **Adresse complémentaire** | `<MalioInputText>` | Non | — |
|
||||||
|
| **Sélecteur de site** | `<MalioSelectCheckbox>` (86 / 17 / 82) | Oui | RG-2.06 — ≥ 1 site. Les 3 cases = les 3 `Site` fixes ; libellés « 86/17/82 » = **préfixe du `postalCode`** (86100/17400/82400), pas un `Site.code` (qui n'existe pas). La sélection stocke des **IDs de Site** (M2M). |
|
||||||
|
| **Catégories** | `<MalioSelectCheckbox>` (multi) | Oui | Catégories de type FOURNISSEUR (RG-2.10), liées aux catégories du fournisseur |
|
||||||
|
| **Contact** | `<MalioSelectCheckbox>` (multi) | Non | Liste = blocs Contact saisis dans l'onglet Contact |
|
||||||
|
| **Benne(s)** | `<MalioInputNumber>` (stepper −/+ , défaut 0) | Non | Champ spécifique fournisseur |
|
||||||
|
| **Prestation de triage** | `<MalioCheckbox>` | Non | Champ spécifique fournisseur (porté par l'adresse — colonne back `triage_provider`) |
|
||||||
|
|
||||||
|
> **Disposition maquette par bloc** : ligne 1 = radio (Prospect / Départ / Rendu) + Pays + Code postal ; ligne 2 = Ville + Adresse + Adresse complémentaire ; ligne 3 = sites (86 / 17 / 82) + Catégories + Contact ; ligne 4 = Benne(s) + Prestation de triage. Icône corbeille en haut à droite de chaque bloc pour le supprimer.
|
||||||
|
|
||||||
|
**Actions** :
|
||||||
|
- « + Nouvelle Adresse » : ajoute un bloc identique au premier.
|
||||||
|
- « Supprimer » : modal de confirmation puis suppression.
|
||||||
|
- « Valider » → PATCH `/api/suppliers/{id}/addresses`.
|
||||||
|
|
||||||
|
### Onglet « Transport »
|
||||||
|
|
||||||
|
🚧 **Onglet placeholder minimal au M2.** Conforme à la maquette : la frame est **vide** (aucun champ, aucun bouton de validation, aucune API back). L'onglet reste navigable. Un libellé discret « À venir » est toléré mais non requis (la maquette ne l'affiche pas). Cet onglet **fait partie de la barre de création** (entre Adresses et Comptabilité).
|
||||||
|
|
||||||
|
### Onglet « Comptabilité »
|
||||||
|
|
||||||
|
⚠ **Accessible aux rôles avec `commercial.suppliers.accounting.view`** (Admin + Compta au M2). Bureau et Commerciale ne voient pas l'onglet. **Compta peut éditer** cet onglet (`accounting.manage`). Compta ne peut pas créer un fournisseur (pas de `manage` global).
|
||||||
|
|
||||||
|
**Champs comptables** :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **SIREN** | `<MalioInputText>` (masque 9 chiffres) | Oui | 9 chiffres. **Pas d'unicité** (cf. § 2.6) |
|
||||||
|
| **Numéro de compte** | `<MalioInputText>` | Oui | — |
|
||||||
|
| **Mode de TVA** | `<MalioSelect>` | Oui | Liste depuis `/api/tva_modes` (référentiel M1) |
|
||||||
|
| **N° de TVA** | `<MalioInputText>` | Oui | — |
|
||||||
|
| **Délai de règlement** | `<MalioSelect>` | Oui | Liste depuis `/api/payment_delays` |
|
||||||
|
| **Type de règlement** | `<MalioSelect>` | Oui | Liste depuis `/api/payment_types` |
|
||||||
|
| **Banque** | `<MalioSelect>` | Conditionnel | RG-2.07 — visible et obligatoire **si** Type de règlement = `VIREMENT`. Liste depuis `/api/banks` (SG / CIC / CA). |
|
||||||
|
|
||||||
|
**Bloc RIB** (0..n, présence obligatoire conditionnée par RG-2.08) :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Libellé** | `<MalioInputText>` | Oui (si LCR) | RG-2.08 |
|
||||||
|
| **BIC** | `<MalioInputText>` | Oui (si LCR) | RG-2.08 |
|
||||||
|
| **IBAN** | `<MalioInputText>` | Oui (si LCR) | RG-2.08 |
|
||||||
|
|
||||||
|
**Actions** :
|
||||||
|
- « + RIB » : ajoute un bloc.
|
||||||
|
- « Supprimer » (icône) : modal de confirmation.
|
||||||
|
- « Valider » → PATCH `/api/suppliers/{id}` (groupe `supplier:write:accounting`) + sous-ressource RIBs.
|
||||||
|
|
||||||
|
### Onglets « Statistiques » / « Rapports » / « Échanges »
|
||||||
|
|
||||||
|
🚧 **Placeholders minimaux au M2 — uniquement en Consultation / Modification** (ils n'apparaissent **pas** dans le flux de création, cf. maquette). Frames vides, pas de validation, pas d'API.
|
||||||
|
|
||||||
|
## Écran « Consultation fournisseur »
|
||||||
|
|
||||||
|
Tous les champs en **lecture seule**. Layout identique à l'écran Ajouter mais sans bouton « Valider », sans `+` pour ajouter des blocs.
|
||||||
|
|
||||||
|
- **Flèche retour** (gauche) → revient au Répertoire.
|
||||||
|
- **Bouton « Modifier »** (droite, visible si `commercial.suppliers.manage`) → écran Modification.
|
||||||
|
- **Bouton « Archiver »** (droite, visible **uniquement Admin** via `commercial.suppliers.archive`) → modal de confirmation, puis PATCH `/api/suppliers/{id}` `{ "isArchived": true }`.
|
||||||
|
|
||||||
|
> Un fournisseur archivé peut être restauré (`isArchived: false`) — bouton « Restaurer » remplace « Archiver » dans la consultation d'un archivé.
|
||||||
|
|
||||||
|
### Onglets affichés en consultation
|
||||||
|
|
||||||
|
Information / Contacts / Adresses / Transport / Statistiques / Rapports / Échanges / Comptabilité (les 4 derniers métiers en placeholder « À venir », Comptabilité selon permission). L'utilisateur navigue **librement** entre les onglets (pas de séquence forcée en consultation).
|
||||||
|
|
||||||
|
## Écran « Modification fournisseur »
|
||||||
|
|
||||||
|
Comportement identique à l'écran Ajouter sauf :
|
||||||
|
- **Pas de formulaire principal** réaffiché (champs principaux édités via les onglets correspondants).
|
||||||
|
- Les champs sont **pré-remplis** avec les valeurs actuelles.
|
||||||
|
- **Validation par onglet** : on peut modifier UN onglet sans toucher aux autres (PATCH partiel).
|
||||||
|
- Les onglets pour lesquels l'utilisateur n'a **pas** la permission `manage` (ou `accounting.manage`) restent en **lecture seule** (pas de bouton Valider, pas d'icône suppression).
|
||||||
|
- Les onglets placeholders « À venir » restent non éditables.
|
||||||
|
|
||||||
|
## Composants UI à utiliser (`@malio/layer-ui`)
|
||||||
|
|
||||||
|
- **Datatable** : `<MalioDataTable>` (+ `usePaginatedList`)
|
||||||
|
- **Input texte** : `<MalioInputText>`
|
||||||
|
- **Input numérique** : `<MalioInputNumber>` (Nombre de salariés, Volume prévisionnel, Bennes)
|
||||||
|
- **Input montant** : `<MalioInputAmount>` (CA, Résultat)
|
||||||
|
- **TextArea** : `<MalioInputTextArea>` (Description)
|
||||||
|
- **Select simple** : `<MalioSelect>` (Pays, Ville, référentiels comptables)
|
||||||
|
- **Select multi (cases à cocher)** : `<MalioSelectCheckbox>` (Catégorie, Sites, Contacts rattachés)
|
||||||
|
- **Radio** : `<MalioRadioButton>` (Type d'adresse Prospect / Départ / Rendu — RG-2.09)
|
||||||
|
- **Checkbox** : `<MalioCheckbox>` (Prestataire de triage)
|
||||||
|
- **Bouton** : `<MalioButton>`, `<MalioButtonIcon>`
|
||||||
|
- **Toasts** : standards via `useApi()`
|
||||||
|
|
||||||
|
**Exceptions autorisées** (commenter `// TODO migrer quand Malio couvre`) :
|
||||||
|
- `<input type="date">` pour « Date Création » (`MalioDate` non couvert).
|
||||||
|
- Modal de confirmation : `<MalioModal>` ou wrapper partagé dans `frontend/shared/` (réutiliser celui du M1 si présent).
|
||||||
|
|
||||||
|
## Composables & appels API
|
||||||
|
|
||||||
|
- `usePaginatedList<Supplier>({ url: '/suppliers' })` — liste paginée (obligatoire, règle frontend). La liste consomme `categories[]` (libellé = `name`) et `sites[]` (libellé = `name`, pas de `code`) **embarqués** + `updatedAt` (cohérence M1/ERP-62, cf. [`spec-back.md § 2.12 / § 4.0`](./spec-back.md)). Côté back, fetch-joins anti-N+1.
|
||||||
|
- `useSupplier(id)` — charge le détail via `GET /api/suppliers/{id}`, qui **embarque** `contacts`, `addresses` (avec `sites` / `categories` / `contacts` imbriqués) et, si permission, `ribs` + scalaires compta. Les écrans Consultation et Modification se peuplent depuis cette seule réponse (RETEX M1 §2 : embed borné, pas de N+1 d'appels). **DoD avant intégration** : vérifier que le JSON réel contient bien ces blocs (cf. [`spec-back.md § 4.0.bis`](./spec-back.md)).
|
||||||
|
- `useSupplierForm()` — workflow par onglet (POST principal + PATCH partiels par groupe), miroir de `useClientForm()`.
|
||||||
|
- `useAddressAutocomplete()` — **réutilisé du M1** (BAN), pas de réécriture.
|
||||||
|
- `usePermissions()` — masque l'onglet Comptabilité et le bouton Archiver.
|
||||||
|
- Tous les appels passent par `useApi()` (jamais `$fetch` direct — règle ABSOLUE n°4).
|
||||||
|
- Filter `formatPhoneFR()` — **réutilisé du M1** pour l'affichage `XX XX XX XX XX`.
|
||||||
|
|
||||||
|
## Règles de formatage et normalisation
|
||||||
|
|
||||||
|
Le serveur normalise systématiquement (RG-2.12 — cf. [`spec-back.md`](./spec-back.md)) :
|
||||||
|
|
||||||
|
| Champ | Normalisation serveur | Affichage front |
|
||||||
|
|---|---|---|
|
||||||
|
| Nom fournisseur (`companyName`) | UPPERCASE intégral | UPPERCASE |
|
||||||
|
| Nom + Prénom contact | Capitalize | identique |
|
||||||
|
| Téléphones (blocs `SupplierContact`) | Chiffres uniquement en BDD | Formaté `XX XX XX XX XX` (filter Vue) |
|
||||||
|
| Email | lowercase intégral | identique |
|
||||||
|
|
||||||
|
> Le front **ne normalise pas** : il envoie la valeur saisie, le serveur normalise et renvoie la valeur normalisée que l'UI affiche. Cohérent avec `useApi()`.
|
||||||
|
|
||||||
|
## API adresse postale
|
||||||
|
|
||||||
|
Code postal + Ville + Adresse branchés sur **api-adresse.data.gouv.fr** (BAN) via le composable `useAddressAutocomplete()` **déjà créé au M1** (réutilisé tel quel) :
|
||||||
|
- À la saisie du CP (5 chiffres) : `GET https://api-adresse.data.gouv.fr/search/?q={cp}&type=municipality` → alimente le select Ville.
|
||||||
|
- À la saisie d'adresse : `?q={addr}&postcode={cp}&type=housenumber` → suggestions.
|
||||||
|
- Cas dégradé (timeout / offline) : Ville en `<MalioInputText>` libre + toast d'avertissement.
|
||||||
|
|
||||||
|
## Différences notables avec le M1 (clients)
|
||||||
|
|
||||||
|
| Zone | M1 clients | M2 fournisseurs |
|
||||||
|
|---|---|---|
|
||||||
|
| Distributeur / Courtier | Auto-référence Client (RG-1.03) | **Absent** |
|
||||||
|
| Prestation de triage | Booléen sur le client (formulaire principal) | **Booléen sur l'adresse** (`triage_provider`) |
|
||||||
|
| Type d'adresse | 3 checkboxes Prospect / Livraison / Facturation | **Radio exclusif** Prospect / Départ / Rendu (RG-2.09) |
|
||||||
|
| Email facturation sur adresse | Oui (conditionnel) | **Absent** |
|
||||||
|
| Champ adresse « Bennes » | — | **Présent** (nombre) |
|
||||||
|
| Onglet Information | 7 champs | **8 champs** (ajout « Volume prévisionnel ») |
|
||||||
|
| Catégories | type unique `CLIENT` (codes ERP-78) | **nouveau type `FOURNISSEUR`** |
|
||||||
|
| Archivage | Admin | **Admin uniquement** (idem) |
|
||||||
|
| Onglets « À venir » | frames blanches | **placeholder « À venir »** (minimal) |
|
||||||
|
|
||||||
|
## Points résolus côté back
|
||||||
|
|
||||||
|
| # | Zone d'ombre | Résolution (cf. `spec-back.md`) |
|
||||||
|
|---|---|---|
|
||||||
|
| 1 | Catégorie multi-select | M2M `supplier_category`, `Category` de type **FOURNISSEUR** (RG-2.10) |
|
||||||
|
| 2 | Type d'adresse Prospect/Départ/Rendu | Enum exclusif `address_type` (RG-2.09) |
|
||||||
|
| 3 | Onglet Comptabilité : qui édite ? | Admin + Compta (`accounting.manage`) ; Bureau/Commerciale ne le voient pas |
|
||||||
|
| 4 | Workflow par onglet | Sauvegarde incrémentale (POST principal + PATCH partiels) — pas d'état « draft » |
|
||||||
|
| 5 | Onglets « À venir » | Placeholder minimal « À venir » (Transport / Stats / Rapports / Échanges) |
|
||||||
|
| 6 | Archive vs delete | Flag `is_archived` séparé de `deleted_at` ; archivage Admin seul ; soft delete = HP |
|
||||||
|
| 7 | Unicité métier | Nom de fournisseur uniquement (à valider — § 2.6). SIREN/email non uniques |
|
||||||
|
| 8 | Référentiels comptables | Réutilisés du M1 (zéro duplication) |
|
||||||
|
| 9 | API code postal | BAN via `useAddressAutocomplete()` du M1 |
|
||||||
|
| 10 | Format export | XLSX uniquement (CSV = HP) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Tickets Lesstime
|
||||||
|
|
||||||
|
**TaskGroup Lesstime** : à créer — `M2 — Répertoire fournisseurs` (projet `ERP / Starseed`, projectId=6).
|
||||||
|
|
||||||
|
> Détail complet et action manuelle → voir [`spec-back.md § Tickets Lesstime`](./spec-back.md#-tickets-lesstime-à-découper).
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
# ERP-101 — Mapping des erreurs de validation par champ (convention forms)
|
||||||
|
|
||||||
|
> Statut : design validé — implémentation TDD en cours
|
||||||
|
> Branche : `feat/ERP-101-form-field-validation-mapping`
|
||||||
|
> Date : 2026-06-03
|
||||||
|
|
||||||
|
## Problème
|
||||||
|
|
||||||
|
Quand le back renvoie une **422** (violations API Platform), il renvoie **toutes** les
|
||||||
|
violations d'un coup (un `propertyPath` + `message` par champ fautif). Aujourd'hui, seul
|
||||||
|
le drawer Catégorie (`useCategoryForm`) exploite ce détail pour afficher l'erreur **sous
|
||||||
|
le champ concerné** ; il le fait via un `if/else` manuel par champ, non réutilisable.
|
||||||
|
|
||||||
|
Le formulaire Client (≈ 20 champs sur 5 submits, dont 3 collections) ne mappe rien : une
|
||||||
|
422 multi-champs ⇒ un seul **toast global**. On veut un retour par champ, et surtout
|
||||||
|
**une convention unique réutilisée par tous les modules**.
|
||||||
|
|
||||||
|
## Décisions
|
||||||
|
|
||||||
|
1. **Primitif générique** plutôt que composable par form : `useFormErrors()` partagé.
|
||||||
|
2. **Périmètre complet** sur Client : champs scalaires **et** collections (erreur par ligne).
|
||||||
|
|
||||||
|
## Architecture — 3 briques
|
||||||
|
|
||||||
|
### 1. `mapViolationsToRecord(data)` — `frontend/shared/utils/api.ts`
|
||||||
|
|
||||||
|
Util pur, fondation réutilisée partout. Transforme un payload 422 en
|
||||||
|
`Record<propertyPath, message>`. S'appuie sur `extractApiViolations` (déjà existant,
|
||||||
|
gère les formats `violations` et `hydra:violations`).
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export function mapViolationsToRecord(data: unknown): Record<string, string> {
|
||||||
|
const out: Record<string, string> = {}
|
||||||
|
for (const v of extractApiViolations(data)) {
|
||||||
|
if (v.propertyPath) out[v.propertyPath] = v.message
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. `useFormErrors()` — `frontend/shared/composables/useFormErrors.ts`
|
||||||
|
|
||||||
|
API que tous les forms **scalaires** consomment.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const { errors, hasErrors, setServerErrors, setError, clearError, clearErrors, handleApiError } = useFormErrors()
|
||||||
|
```
|
||||||
|
|
||||||
|
- `errors` : `reactive<Record<string, string>>` indexé par `propertyPath`.
|
||||||
|
- `setServerErrors(data)` : `mapViolationsToRecord` → remplit `errors`. Retourne `true`
|
||||||
|
si au moins une violation a été mappée.
|
||||||
|
- `setError(field, msg)` / `clearError(field)` / `clearErrors()` : manipulation fine.
|
||||||
|
- `hasErrors` : `computed` booléen.
|
||||||
|
- `handleApiError(e, opts?)` : dispatch standard depuis une erreur ofetch —
|
||||||
|
**422** → `setServerErrors` (mapping inline, pas de toast) ; **autre** → toast
|
||||||
|
générique de fallback (message extrait via `extractApiErrorMessage`).
|
||||||
|
|
||||||
|
Côté template, le nom du champ **est** le `propertyPath` :
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<MalioInputText v-model="main.companyName" :error="errors.companyName" />
|
||||||
|
<MalioInputText v-model="accounting.siren" :error="errors.siren" />
|
||||||
|
```
|
||||||
|
|
||||||
|
> L'unicité SIREN (RG-1.15) remonte en **422 `UniqueEntity` avec `propertyPath: "siren"`**
|
||||||
|
> → mappée automatiquement. Pas de cas 409 spécial (contrairement à Catégorie).
|
||||||
|
|
||||||
|
### 3. Collections — erreurs par ligne
|
||||||
|
|
||||||
|
Chaque ligne (contact / adresse / RIB) est persistée par **son propre appel API**, donc
|
||||||
|
le back renvoie un 422 **relatif à la sous-entité** (`propertyPath: "email"`, `"iban"`…).
|
||||||
|
|
||||||
|
- Le parent tient, par collection, un tableau d'erreurs **aligné sur l'index de ligne** :
|
||||||
|
`const contactErrors = ref<Record<string, string>[]>([])`.
|
||||||
|
- Au submit de la ligne `i` : `catch` → `contactErrors.value[i] = mapViolationsToRecord(data)`.
|
||||||
|
- On `clearErrors` la collection au début de chaque passe de submit.
|
||||||
|
- Les blocs reçoivent une prop `:errors` (`Record<string, string>`) et bindent
|
||||||
|
`:error="errors?.email"` sur chaque champ Malio.
|
||||||
|
|
||||||
|
## Fichiers touchés
|
||||||
|
|
||||||
|
| Fichier | Action |
|
||||||
|
|---|---|
|
||||||
|
| `shared/utils/api.ts` | + `mapViolationsToRecord` |
|
||||||
|
| `shared/composables/useFormErrors.ts` | **nouveau** composable |
|
||||||
|
| `modules/commercial/pages/clients/new.vue` | scalaires (Main/Info/Compta) + erreurs par ligne |
|
||||||
|
| `modules/commercial/pages/clients/[id]/edit.vue` | idem |
|
||||||
|
| `modules/commercial/components/ClientContactBlock.vue` | + prop `:errors`, bind `:error` |
|
||||||
|
| `modules/commercial/components/ClientAddressBlock.vue` | + prop `:errors`, bind `:error` |
|
||||||
|
| RIB (inline dans new/edit) | bind `:error` par ligne |
|
||||||
|
|
||||||
|
## Tests (Vitest — règle « pas d'E2E »)
|
||||||
|
|
||||||
|
- `mapViolationsToRecord` : formats `violations` / `hydra:violations`, payload vide,
|
||||||
|
`propertyPath` manquant.
|
||||||
|
- `useFormErrors` : `setServerErrors` mappe et retourne `true` / `false` sans violation,
|
||||||
|
`clearErrors`, fallback toast sur non-422.
|
||||||
|
|
||||||
|
## Convention posée pour tous les forms
|
||||||
|
|
||||||
|
À reporter dans `.claude/rules/frontend.md` une fois le pattern stabilisé :
|
||||||
|
|
||||||
|
> Tout form qui veut un retour d'erreur par champ : appels API en `{ toast: false }` +
|
||||||
|
> `useFormErrors` pour les champs scalaires (422 inline), `mapViolationsToRecord` par
|
||||||
|
> ligne pour les collections. `useCategoryForm` migrera sur `useFormErrors`.
|
||||||
|
|
||||||
|
## Fait dans la foulée (post-ERP-101 initial)
|
||||||
|
|
||||||
|
- **`useCategoryForm` migré sur `useFormErrors`** : `errors` devient le `reactive` du
|
||||||
|
composable (drawer adapté : `form.errors.name` au lieu de `form.errors.value.name`,
|
||||||
|
bloc `_global` retiré → erreur transverse en toast). 28 tests verts.
|
||||||
|
- **Convention reportée dans `.claude/rules/frontend.md`** (section « Validation des
|
||||||
|
formulaires — useFormErrors obligatoire »).
|
||||||
|
|
||||||
|
## Hors scope ERP-101 (suivi : ticket ERP-107)
|
||||||
|
|
||||||
|
- Langue / présence des messages de validation côté back : le `message` affiché est celui
|
||||||
|
renvoyé par le serveur. Audit des contraintes Symfony (présence d'un `message` FR,
|
||||||
|
contraintes manquantes, violations sans `propertyPath`) tracké dans **ERP-107**.
|
||||||
@@ -10,7 +10,11 @@
|
|||||||
"confirm": "Confirmer",
|
"confirm": "Confirmer",
|
||||||
"yes": "Oui",
|
"yes": "Oui",
|
||||||
"no": "Non",
|
"no": "Non",
|
||||||
"actions": "Actions"
|
"actions": "Actions",
|
||||||
|
"comingSoon": {
|
||||||
|
"title": "En cours de dev",
|
||||||
|
"subtitle": "Cette fonctionnalité arrive bientôt."
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"administration": {
|
"administration": {
|
||||||
@@ -87,7 +91,29 @@
|
|||||||
"archiveSuccess": "Client archivé avec succès",
|
"archiveSuccess": "Client archivé avec succès",
|
||||||
"restoreSuccess": "Client restauré avec succès",
|
"restoreSuccess": "Client restauré avec succès",
|
||||||
"error": "Une erreur est survenue. Réessayez.",
|
"error": "Une erreur est survenue. Réessayez.",
|
||||||
"exportError": "L'export du répertoire clients a échoué. Réessayez."
|
"exportError": "L'export du répertoire clients a échoué. Réessayez.",
|
||||||
|
"restoreConflict": "Impossible de restaurer : un client actif portant ce nom existe déjà."
|
||||||
|
},
|
||||||
|
"consultation": {
|
||||||
|
"title": "Consultation client",
|
||||||
|
"back": "Retour au répertoire",
|
||||||
|
"loading": "Chargement du client…",
|
||||||
|
"notFound": "Client introuvable.",
|
||||||
|
"confirmArchive": {
|
||||||
|
"title": "Archiver le client",
|
||||||
|
"message": "Ce client n'apparaîtra plus dans le répertoire actif. Confirmer l'archivage ?"
|
||||||
|
},
|
||||||
|
"confirmRestore": {
|
||||||
|
"title": "Restaurer le client",
|
||||||
|
"message": "Ce client réapparaîtra dans le répertoire actif. Confirmer la restauration ?"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"edit": {
|
||||||
|
"title": "Modifier le client",
|
||||||
|
"back": "Retour au répertoire",
|
||||||
|
"loading": "Chargement du client…",
|
||||||
|
"notFound": "Client introuvable.",
|
||||||
|
"save": "Valider"
|
||||||
},
|
},
|
||||||
"validation": {
|
"validation": {
|
||||||
"informationRequiredForCommercial": "Les informations de l'entreprise sont obligatoires pour le rôle Commerciale.",
|
"informationRequiredForCommercial": "Les informations de l'entreprise sont obligatoires pour le rôle Commerciale.",
|
||||||
@@ -107,14 +133,9 @@
|
|||||||
"duplicateCompany": "Un client portant ce nom de société existe déjà.",
|
"duplicateCompany": "Un client portant ce nom de société existe déjà.",
|
||||||
"main": {
|
"main": {
|
||||||
"companyName": "Nom du client (Entreprise)",
|
"companyName": "Nom du client (Entreprise)",
|
||||||
"firstName": "Prénom du contact principal",
|
|
||||||
"lastName": "Nom du contact principal",
|
|
||||||
"email": "Email",
|
|
||||||
"phonePrimary": "Téléphone",
|
|
||||||
"phoneSecondary": "Téléphone (2)",
|
|
||||||
"addPhone": "Ajouter un numéro",
|
|
||||||
"categories": "Catégorie",
|
"categories": "Catégorie",
|
||||||
"relation": "Distributeur / Courtier",
|
"relation": "Distributeur / Courtier",
|
||||||
|
"relationNone": "Aucun",
|
||||||
"relationDistributor": "Dépend du distributeur",
|
"relationDistributor": "Dépend du distributeur",
|
||||||
"relationBroker": "Dépend du courtier",
|
"relationBroker": "Dépend du courtier",
|
||||||
"distributorName": "Nom du distributeur",
|
"distributorName": "Nom du distributeur",
|
||||||
@@ -147,13 +168,18 @@
|
|||||||
"prospect": "Prospect",
|
"prospect": "Prospect",
|
||||||
"delivery": "Adresse de livraison",
|
"delivery": "Adresse de livraison",
|
||||||
"billing": "Facturation",
|
"billing": "Facturation",
|
||||||
|
"addressType": "Type d'adresse",
|
||||||
|
"addressTypeProspect": "Prospect",
|
||||||
|
"addressTypeDelivery": "Livraison",
|
||||||
|
"addressTypeBilling": "Facturation",
|
||||||
|
"addressTypeDeliveryBilling": "Adresse + Facturation",
|
||||||
"categories": "Catégorie",
|
"categories": "Catégorie",
|
||||||
"country": "Pays",
|
"country": "Pays",
|
||||||
"postalCode": "Code postal",
|
"postalCode": "Code postal",
|
||||||
"city": "Ville",
|
"city": "Ville",
|
||||||
"street": "Adresse",
|
"street": "Adresse",
|
||||||
"streetComplement": "Adresse complémentaire",
|
"streetComplement": "Adresse complémentaire",
|
||||||
"sites": "Sites Starseed",
|
"sites": "Sites",
|
||||||
"contacts": "Contact(s) rattaché(s)",
|
"contacts": "Contact(s) rattaché(s)",
|
||||||
"billingEmail": "Email de facturation",
|
"billingEmail": "Email de facturation",
|
||||||
"remove": "Supprimer l'adresse",
|
"remove": "Supprimer l'adresse",
|
||||||
@@ -207,7 +233,10 @@
|
|||||||
},
|
},
|
||||||
"sites": {
|
"sites": {
|
||||||
"notAuthorized": "Vous n'êtes pas autorisé à sélectionner ce site."
|
"notAuthorized": "Vous n'êtes pas autorisé à sélectionner ce site."
|
||||||
}
|
},
|
||||||
|
"title": "Erreur",
|
||||||
|
"generic": "Une erreur est survenue.",
|
||||||
|
"unknown": "Erreur inconnue."
|
||||||
},
|
},
|
||||||
"sites": {
|
"sites": {
|
||||||
"selector": {
|
"selector": {
|
||||||
@@ -264,7 +293,8 @@
|
|||||||
"success": {
|
"success": {
|
||||||
"auth": {
|
"auth": {
|
||||||
"logout": "Deconnexion reussie"
|
"logout": "Deconnexion reussie"
|
||||||
}
|
},
|
||||||
|
"title": "Succès"
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
"roles": {
|
"roles": {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
:label="t('admin.categories.form.name')"
|
:label="t('admin.categories.form.name')"
|
||||||
input-class="w-full"
|
input-class="w-full"
|
||||||
:max-length="120"
|
:max-length="120"
|
||||||
:error="form.errors.value.name"
|
:error="form.errors.name"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -32,15 +32,9 @@
|
|||||||
:options="typeOptions"
|
:options="typeOptions"
|
||||||
:label="t('admin.categories.form.type')"
|
:label="t('admin.categories.form.type')"
|
||||||
:empty-option-label="t('admin.categories.form.typePlaceholder')"
|
:empty-option-label="t('admin.categories.form.typePlaceholder')"
|
||||||
:error="form.errors.value.categoryType"
|
:error="form.errors.categoryType"
|
||||||
:disabled="loadingTypes"
|
:disabled="loadingTypes"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Erreur transverse (typiquement reseau / 5xx) — separe des
|
|
||||||
erreurs de validation par champ. -->
|
|
||||||
<p v-if="form.errors.value._global" class="text-sm text-red-600">
|
|
||||||
{{ form.errors.value._global }}
|
|
||||||
</p>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- Footer fixe : depuis 1.7.1 le slot #footer est un frere du body
|
<!-- Footer fixe : depuis 1.7.1 le slot #footer est un frere du body
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
import type { Category, CategoryType } from '~/modules/catalog/types/category'
|
import type { Category, CategoryType } from '~/modules/catalog/types/category'
|
||||||
|
import { useFormErrors } from '~/shared/composables/useFormErrors'
|
||||||
import { useCategoryForm } from '../useCategoryForm'
|
import { useCategoryForm } from '../useCategoryForm'
|
||||||
|
|
||||||
// Stubs des auto-imports Nuxt consommes par le composable.
|
// Stubs des auto-imports Nuxt consommes par le composable.
|
||||||
@@ -21,6 +22,9 @@ vi.stubGlobal('useToast', () => ({
|
|||||||
success: mockToastSuccess,
|
success: mockToastSuccess,
|
||||||
error: mockToastError,
|
error: mockToastError,
|
||||||
}))
|
}))
|
||||||
|
// useFormErrors est un auto-import Nuxt : on expose l'implementation reelle
|
||||||
|
// (elle consomme useToast, deja stubbe ci-dessus) pour tester l'integration.
|
||||||
|
vi.stubGlobal('useFormErrors', useFormErrors)
|
||||||
// useI18n.t : on renvoie la cle telle quelle (pratique pour asserter dessus).
|
// useI18n.t : on renvoie la cle telle quelle (pratique pour asserter dessus).
|
||||||
// Quand le composable passe des params (ex: doublon), on les serialise pour
|
// Quand le composable passe des params (ex: doublon), on les serialise pour
|
||||||
// pouvoir verifier que l'interpolation a bien recu le bon nom.
|
// pouvoir verifier que l'interpolation a bien recu le bon nom.
|
||||||
@@ -61,7 +65,7 @@ describe('useCategoryForm', () => {
|
|||||||
|
|
||||||
expect(form.name.value).toBe('Vis')
|
expect(form.name.value).toBe('Vis')
|
||||||
expect(form.categoryTypeId.value).toBe(1)
|
expect(form.categoryTypeId.value).toBe(1)
|
||||||
expect(form.errors.value).toEqual({ name: '', categoryType: '', _global: '' })
|
expect(form.errors).toEqual({})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('vide le formulaire en mode creation (null)', () => {
|
it('vide le formulaire en mode creation (null)', () => {
|
||||||
@@ -105,7 +109,7 @@ describe('useCategoryForm', () => {
|
|||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
expect(ok).toBe(false)
|
expect(ok).toBe(false)
|
||||||
expect(form.errors.value.name).toBe('admin.categories.validation.nameRequired')
|
expect(form.errors.name).toBe('admin.categories.validation.nameRequired')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('signale erreur si name est whitespace-only (trim → vide)', () => {
|
it('signale erreur si name est whitespace-only (trim → vide)', () => {
|
||||||
@@ -116,7 +120,7 @@ describe('useCategoryForm', () => {
|
|||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
expect(ok).toBe(false)
|
expect(ok).toBe(false)
|
||||||
expect(form.errors.value.name).toBe('admin.categories.validation.nameRequired')
|
expect(form.errors.name).toBe('admin.categories.validation.nameRequired')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('signale erreur si name fait 1 caractere (< 2, RG-1.04)', () => {
|
it('signale erreur si name fait 1 caractere (< 2, RG-1.04)', () => {
|
||||||
@@ -127,7 +131,7 @@ describe('useCategoryForm', () => {
|
|||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
expect(ok).toBe(false)
|
expect(ok).toBe(false)
|
||||||
expect(form.errors.value.name).toBe('admin.categories.validation.nameLength')
|
expect(form.errors.name).toBe('admin.categories.validation.nameLength')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('signale erreur si name fait 121 caracteres (> 120, RG-1.04)', () => {
|
it('signale erreur si name fait 121 caracteres (> 120, RG-1.04)', () => {
|
||||||
@@ -138,7 +142,7 @@ describe('useCategoryForm', () => {
|
|||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
expect(ok).toBe(false)
|
expect(ok).toBe(false)
|
||||||
expect(form.errors.value.name).toBe('admin.categories.validation.nameLength')
|
expect(form.errors.name).toBe('admin.categories.validation.nameLength')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('signale erreur si categoryTypeId est null (RG-1.05)', () => {
|
it('signale erreur si categoryTypeId est null (RG-1.05)', () => {
|
||||||
@@ -149,7 +153,7 @@ describe('useCategoryForm', () => {
|
|||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
expect(ok).toBe(false)
|
expect(ok).toBe(false)
|
||||||
expect(form.errors.value.categoryType).toBe('admin.categories.validation.typeRequired')
|
expect(form.errors.categoryType).toBe('admin.categories.validation.typeRequired')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('passe quand name et categoryType sont valides', () => {
|
it('passe quand name et categoryType sont valides', () => {
|
||||||
@@ -160,19 +164,22 @@ describe('useCategoryForm', () => {
|
|||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
expect(ok).toBe(true)
|
expect(ok).toBe(true)
|
||||||
expect(form.errors.value).toEqual({ name: '', categoryType: '', _global: '' })
|
expect(form.errors).toEqual({})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reinitialise les erreurs avant chaque validation', () => {
|
it('reinitialise les erreurs avant chaque validation', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
// Erreur prealable.
|
// Erreur prealable : une validation en echec peuple errors.name.
|
||||||
form.errors.value._global = 'erreur ancienne'
|
form.name.value = ''
|
||||||
form.name.value = 'Vis'
|
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeId.value = 1
|
||||||
|
form.validate()
|
||||||
|
expect(form.errors.name).toBeTruthy()
|
||||||
|
|
||||||
|
// Seconde validation avec des valeurs valides : errors repart vide.
|
||||||
|
form.name.value = 'Vis'
|
||||||
form.validate()
|
form.validate()
|
||||||
|
|
||||||
expect(form.errors.value._global).toBe('')
|
expect(form.errors).toEqual({})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -213,7 +220,7 @@ describe('useCategoryForm', () => {
|
|||||||
await form.submitCreate()
|
await form.submitCreate()
|
||||||
|
|
||||||
expect(mockToastSuccess).toHaveBeenCalledWith({
|
expect(mockToastSuccess).toHaveBeenCalledWith({
|
||||||
title: 'Succès',
|
title: 'success.title',
|
||||||
message: 'admin.categories.toast.created',
|
message: 'admin.categories.toast.created',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -231,8 +238,8 @@ describe('useCategoryForm', () => {
|
|||||||
expect(result).toBeNull()
|
expect(result).toBeNull()
|
||||||
// La cle est interpolee avec le nom soumis : on retrouve "Vis" dans
|
// La cle est interpolee avec le nom soumis : on retrouve "Vis" dans
|
||||||
// les params i18n (stub serialise les params).
|
// les params i18n (stub serialise les params).
|
||||||
expect(form.errors.value.name).toContain('admin.categories.toast.duplicate')
|
expect(form.errors.name).toContain('admin.categories.toast.duplicate')
|
||||||
expect(form.errors.value.name).toContain('"name":"Vis"')
|
expect(form.errors.name).toContain('"name":"Vis"')
|
||||||
expect(mockToastError).toHaveBeenCalledTimes(1)
|
expect(mockToastError).toHaveBeenCalledTimes(1)
|
||||||
const toastArg = mockToastError.mock.calls[0]?.[0] as { message: string }
|
const toastArg = mockToastError.mock.calls[0]?.[0] as { message: string }
|
||||||
expect(toastArg.message).toContain('Vis')
|
expect(toastArg.message).toContain('Vis')
|
||||||
@@ -256,7 +263,7 @@ describe('useCategoryForm', () => {
|
|||||||
const result = await form.submitCreate()
|
const result = await form.submitCreate()
|
||||||
|
|
||||||
expect(result).toBeNull()
|
expect(result).toBeNull()
|
||||||
expect(form.errors.value.name).toBe('name should not be blank.')
|
expect(form.errors.name).toBe('name should not be blank.')
|
||||||
// Pas de toast quand on a mappe les violations : l erreur est
|
// Pas de toast quand on a mappe les violations : l erreur est
|
||||||
// affichee inline sous le champ concerne.
|
// affichee inline sous le champ concerne.
|
||||||
expect(mockToastError).not.toHaveBeenCalled()
|
expect(mockToastError).not.toHaveBeenCalled()
|
||||||
@@ -279,10 +286,10 @@ describe('useCategoryForm', () => {
|
|||||||
|
|
||||||
await form.submitCreate()
|
await form.submitCreate()
|
||||||
|
|
||||||
expect(form.errors.value.categoryType).toBe('Type invalide.')
|
expect(form.errors.categoryType).toBe('Type invalide.')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fallback en erreur globale + toast si le status n est ni 409 ni 422', async () => {
|
it('fallback en toast generique si le status n est ni 409 ni 422', async () => {
|
||||||
mockPost.mockRejectedValueOnce({
|
mockPost.mockRejectedValueOnce({
|
||||||
response: { status: 500, _data: { 'hydra:description': 'Boom server' } },
|
response: { status: 500, _data: { 'hydra:description': 'Boom server' } },
|
||||||
})
|
})
|
||||||
@@ -292,9 +299,10 @@ describe('useCategoryForm', () => {
|
|||||||
|
|
||||||
await form.submitCreate()
|
await form.submitCreate()
|
||||||
|
|
||||||
expect(form.errors.value._global).toBe('Boom server')
|
// Pas d'erreur inline par champ : l'erreur transverse part en toast.
|
||||||
|
expect(form.errors).toEqual({})
|
||||||
expect(mockToastError).toHaveBeenCalledWith({
|
expect(mockToastError).toHaveBeenCalledWith({
|
||||||
title: 'Erreur',
|
title: 'errors.title',
|
||||||
message: 'Boom server',
|
message: 'Boom server',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -370,7 +378,7 @@ describe('useCategoryForm', () => {
|
|||||||
await form.submitUpdate(42)
|
await form.submitUpdate(42)
|
||||||
|
|
||||||
expect(mockToastSuccess).toHaveBeenCalledWith({
|
expect(mockToastSuccess).toHaveBeenCalledWith({
|
||||||
title: 'Succès',
|
title: 'success.title',
|
||||||
message: 'admin.categories.toast.updated',
|
message: 'admin.categories.toast.updated',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -386,8 +394,8 @@ describe('useCategoryForm', () => {
|
|||||||
const result = await form.submitUpdate(42)
|
const result = await form.submitUpdate(42)
|
||||||
|
|
||||||
expect(result).toBeNull()
|
expect(result).toBeNull()
|
||||||
expect(form.errors.value.name).toContain('admin.categories.toast.duplicate')
|
expect(form.errors.name).toContain('admin.categories.toast.duplicate')
|
||||||
expect(form.errors.value.name).toContain('"name":"Doublon"')
|
expect(form.errors.name).toContain('"name":"Doublon"')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -401,7 +409,7 @@ describe('useCategoryForm', () => {
|
|||||||
expect(mockDelete).toHaveBeenCalledWith('/categories/42', {}, { toast: false })
|
expect(mockDelete).toHaveBeenCalledWith('/categories/42', {}, { toast: false })
|
||||||
expect(ok).toBe(true)
|
expect(ok).toBe(true)
|
||||||
expect(mockToastSuccess).toHaveBeenCalledWith({
|
expect(mockToastSuccess).toHaveBeenCalledWith({
|
||||||
title: 'Succès',
|
title: 'success.title',
|
||||||
message: 'admin.categories.toast.deleted',
|
message: 'admin.categories.toast.deleted',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -415,7 +423,6 @@ describe('useCategoryForm', () => {
|
|||||||
const ok = await form.submitDelete(42)
|
const ok = await form.submitDelete(42)
|
||||||
|
|
||||||
expect(ok).toBe(false)
|
expect(ok).toBe(false)
|
||||||
expect(form.errors.value._global).toBe('down')
|
|
||||||
expect(mockToastError).toHaveBeenCalled()
|
expect(mockToastError).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -424,15 +431,15 @@ describe('useCategoryForm', () => {
|
|||||||
it('vide le formulaire et les erreurs', () => {
|
it('vide le formulaire et les erreurs', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.loadFrom(CAT)
|
form.loadFrom(CAT)
|
||||||
form.name.value = 'edit'
|
form.name.value = ''
|
||||||
form.errors.value._global = 'erreur'
|
form.validate() // peuple errors.name
|
||||||
form.submitting.value = true
|
form.submitting.value = true
|
||||||
|
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|
||||||
expect(form.name.value).toBe('')
|
expect(form.name.value).toBe('')
|
||||||
expect(form.categoryTypeId.value).toBeNull()
|
expect(form.categoryTypeId.value).toBeNull()
|
||||||
expect(form.errors.value).toEqual({ name: '', categoryType: '', _global: '' })
|
expect(form.errors).toEqual({})
|
||||||
expect(form.submitting.value).toBe(false)
|
expect(form.submitting.value).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,14 +12,13 @@
|
|||||||
* elles servent juste a eviter l'aller-retour reseau evitable. Le serveur
|
* elles servent juste a eviter l'aller-retour reseau evitable. Le serveur
|
||||||
* revalide toujours (defense en profondeur).
|
* revalide toujours (defense en profondeur).
|
||||||
*
|
*
|
||||||
* Mapping erreurs API :
|
* Erreurs par champ : delegue a `useFormErrors` (convention ERP-101). Les
|
||||||
* - 409 (RG-1.07 doublon) → toast + erreur sur le champ `name`
|
* violations 422 sont mappees par `propertyPath` (`name`, `categoryType`) ;
|
||||||
* - 422 (violations API Platform) → mapping sur les champs concernes
|
* l'erreur globale (status != 422 exploitable) part en toast. Le 409 (doublon
|
||||||
* - autre → erreur globale `_global` + toast generique
|
* RG-1.07) reste un cas metier specifique : erreur inline sur `name` + toast.
|
||||||
*/
|
*/
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import type { Category } from '~/modules/catalog/types/category'
|
import type { Category } from '~/modules/catalog/types/category'
|
||||||
import { extractApiErrorMessage, extractApiViolations } from '~/shared/utils/api'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erreur HTTP capturee par ofetch. On expose juste les champs utilises ici
|
* Erreur HTTP capturee par ofetch. On expose juste les champs utilises ici
|
||||||
@@ -37,6 +36,9 @@ export function useCategoryForm() {
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
|
||||||
|
// Etat d'erreurs par champ (indexe par propertyPath) + dispatch API 422.
|
||||||
|
const formErrors = useFormErrors()
|
||||||
|
|
||||||
// State local du formulaire — pas singleton, chaque appel a useCategoryForm
|
// State local du formulaire — pas singleton, chaque appel a useCategoryForm
|
||||||
// cree son propre state (cohérent avec le pattern « un drawer = un form »).
|
// cree son propre state (cohérent avec le pattern « un drawer = un form »).
|
||||||
const name = ref('')
|
const name = ref('')
|
||||||
@@ -48,16 +50,6 @@ export function useCategoryForm() {
|
|||||||
const initialName = ref('')
|
const initialName = ref('')
|
||||||
const initialCategoryTypeId = ref<number | null>(null)
|
const initialCategoryTypeId = ref<number | null>(null)
|
||||||
|
|
||||||
const errors = ref<{
|
|
||||||
name: string
|
|
||||||
categoryType: string
|
|
||||||
_global: string
|
|
||||||
}>({
|
|
||||||
name: '',
|
|
||||||
categoryType: '',
|
|
||||||
_global: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
|
|
||||||
const isDirty = computed(
|
const isDirty = computed(
|
||||||
@@ -72,7 +64,7 @@ export function useCategoryForm() {
|
|||||||
* erreurs et le snapshot initial pour repartir d'un etat propre.
|
* erreurs et le snapshot initial pour repartir d'un etat propre.
|
||||||
*/
|
*/
|
||||||
function loadFrom(category: Category | null): void {
|
function loadFrom(category: Category | null): void {
|
||||||
errors.value = { name: '', categoryType: '', _global: '' }
|
formErrors.clearErrors()
|
||||||
if (category) {
|
if (category) {
|
||||||
name.value = category.name
|
name.value = category.name
|
||||||
categoryTypeId.value = category.categoryType.id
|
categoryTypeId.value = category.categoryType.id
|
||||||
@@ -92,32 +84,29 @@ export function useCategoryForm() {
|
|||||||
* mais le serveur retrim de toute facon — pas de risque de divergence.
|
* mais le serveur retrim de toute facon — pas de risque de divergence.
|
||||||
*/
|
*/
|
||||||
function validate(): boolean {
|
function validate(): boolean {
|
||||||
errors.value = { name: '', categoryType: '', _global: '' }
|
formErrors.clearErrors()
|
||||||
const trimmedName = name.value.trim()
|
const trimmedName = name.value.trim()
|
||||||
|
|
||||||
// RG-1.02 — name obligatoire (vide / whitespace-only).
|
// RG-1.02 — name obligatoire (vide / whitespace-only).
|
||||||
if (trimmedName === '') {
|
if (trimmedName === '') {
|
||||||
errors.value.name = t('admin.categories.validation.nameRequired')
|
formErrors.setError('name', t('admin.categories.validation.nameRequired'))
|
||||||
} else if (trimmedName.length < 2 || trimmedName.length > 120) {
|
} else if (trimmedName.length < 2 || trimmedName.length > 120) {
|
||||||
// RG-1.04 — longueur 2-120 apres trim.
|
// RG-1.04 — longueur 2-120 apres trim.
|
||||||
errors.value.name = t('admin.categories.validation.nameLength')
|
formErrors.setError('name', t('admin.categories.validation.nameLength'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RG-1.05 — categoryType obligatoire.
|
// RG-1.05 — categoryType obligatoire.
|
||||||
if (categoryTypeId.value === null) {
|
if (categoryTypeId.value === null) {
|
||||||
errors.value.categoryType = t('admin.categories.validation.typeRequired')
|
formErrors.setError('categoryType', t('admin.categories.validation.typeRequired'))
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.value.name === '' && errors.value.categoryType === ''
|
return !formErrors.errors.name && !formErrors.errors.categoryType
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construit le payload POST a partir du state. Le `categoryType` est
|
* Construit le payload POST a partir du state. Le `categoryType` est
|
||||||
* envoye en IRI Hydra (`/api/category_types/{id}`) — convention API
|
* envoye en IRI Hydra (`/api/category_types/{id}`) — convention API
|
||||||
* Platform pour referencer une ressource liee. Retourne un object literal
|
* Platform pour referencer une ressource liee.
|
||||||
* compatible avec `AnyObject` de `useApi()` (un type nomme strict comme
|
|
||||||
* `CategoryCreateInput` ne serait pas assignable a `Record<string, unknown>`
|
|
||||||
* en TS strict).
|
|
||||||
*/
|
*/
|
||||||
function buildCreatePayload(): Record<string, unknown> {
|
function buildCreatePayload(): Record<string, unknown> {
|
||||||
return {
|
return {
|
||||||
@@ -127,72 +116,24 @@ export function useCategoryForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mappe les violations 422 d'API Platform sur les champs du formulaire.
|
* Traite une erreur API : 409 (doublon RG-1.07) → erreur inline sur `name`
|
||||||
* Renvoie true des qu'au moins une violation a ete posee — false sinon
|
* + toast ; sinon delegue a `useFormErrors.handleApiError` (422 mappe inline
|
||||||
* (payload sans violations exploitables, ou tous les `propertyPath` hors
|
* par champ sans toast, autre → toast de fallback). Retourne true si traitee
|
||||||
* du mapping connu). L'extraction Hydra (`violations` / `hydra:violations`)
|
* inline (409/422 mappe), false si fallback toast.
|
||||||
* est centralisee dans `shared/utils/api.ts` pour rester reutilisable
|
|
||||||
* sur les futurs drawers de formulaire.
|
|
||||||
*/
|
|
||||||
function mapServerViolations(data: unknown): boolean {
|
|
||||||
const violations = extractApiViolations(data)
|
|
||||||
if (violations.length === 0) return false
|
|
||||||
let mapped = false
|
|
||||||
for (const v of violations) {
|
|
||||||
if (v.propertyPath === 'name') {
|
|
||||||
errors.value.name = v.message
|
|
||||||
mapped = true
|
|
||||||
} else if (v.propertyPath === 'categoryType') {
|
|
||||||
errors.value.categoryType = v.message
|
|
||||||
mapped = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mapped
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Traite une erreur API : mappe selon le status, declenche les toasts
|
|
||||||
* appropries. Centralise la logique entre create/update.
|
|
||||||
*
|
|
||||||
* - 409 (RG-1.07) : doublon — toast + errors.name avec libelle qui inclut
|
|
||||||
* le nom soumis.
|
|
||||||
* - 422 : tentative de mapping fin via les violations API Platform — si au
|
|
||||||
* moins une violation est mappee, pas de toast (erreur affichee inline
|
|
||||||
* sous le champ concerne).
|
|
||||||
* - autre : message global + toast generique. Le toast natif d'useApi
|
|
||||||
* est desactive (`toast: false`) pour permettre ce mapping fin ; il faut
|
|
||||||
* donc en re-emettre un manuellement ici, sinon une 500 reste silencieuse.
|
|
||||||
*
|
|
||||||
* Retourne true si l'erreur a ete reconnue et traitee (409/422 mappes),
|
|
||||||
* false sinon (fallback generique).
|
|
||||||
*/
|
*/
|
||||||
function handleApiError(e: unknown, attemptedName: string): boolean {
|
function handleApiError(e: unknown, attemptedName: string): boolean {
|
||||||
const status = (e as ApiFetchError)?.response?.status
|
const status = (e as ApiFetchError)?.response?.status
|
||||||
const data = (e as ApiFetchError)?.response?._data
|
|
||||||
|
|
||||||
if (status === 409) {
|
if (status === 409) {
|
||||||
const duplicateMessage = t('admin.categories.toast.duplicate', {
|
const duplicateMessage = t('admin.categories.toast.duplicate', {
|
||||||
name: attemptedName,
|
name: attemptedName,
|
||||||
})
|
})
|
||||||
errors.value.name = duplicateMessage
|
formErrors.setError('name', duplicateMessage)
|
||||||
toast.error({
|
toast.error({ title: t('errors.title'), message: duplicateMessage })
|
||||||
title: 'Erreur',
|
|
||||||
message: duplicateMessage,
|
|
||||||
})
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status === 422 && mapServerViolations(data)) {
|
return formErrors.handleApiError(e, { fallbackMessage: t('errors.generic') })
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
const extracted = extractApiErrorMessage(data)
|
|
||||||
errors.value._global = extracted || 'Une erreur est survenue.'
|
|
||||||
toast.error({
|
|
||||||
title: 'Erreur',
|
|
||||||
message: errors.value._global,
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,14 +144,13 @@ export function useCategoryForm() {
|
|||||||
async function submitCreate(): Promise<Category | null> {
|
async function submitCreate(): Promise<Category | null> {
|
||||||
if (!validate()) return null
|
if (!validate()) return null
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
errors.value._global = ''
|
|
||||||
const payload = buildCreatePayload()
|
const payload = buildCreatePayload()
|
||||||
try {
|
try {
|
||||||
const created = await api.post<Category>('/categories', payload, {
|
const created = await api.post<Category>('/categories', payload, {
|
||||||
toast: false,
|
toast: false,
|
||||||
})
|
})
|
||||||
toast.success({
|
toast.success({
|
||||||
title: 'Succès',
|
title: t('success.title'),
|
||||||
message: t('admin.categories.toast.created'),
|
message: t('admin.categories.toast.created'),
|
||||||
})
|
})
|
||||||
return created
|
return created
|
||||||
@@ -230,7 +170,6 @@ export function useCategoryForm() {
|
|||||||
async function submitUpdate(id: number): Promise<Category | null> {
|
async function submitUpdate(id: number): Promise<Category | null> {
|
||||||
if (!validate()) return null
|
if (!validate()) return null
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
errors.value._global = ''
|
|
||||||
const payload: Record<string, unknown> = {}
|
const payload: Record<string, unknown> = {}
|
||||||
if (name.value !== initialName.value) {
|
if (name.value !== initialName.value) {
|
||||||
payload.name = name.value.trim()
|
payload.name = name.value.trim()
|
||||||
@@ -250,7 +189,7 @@ export function useCategoryForm() {
|
|||||||
toast: false,
|
toast: false,
|
||||||
})
|
})
|
||||||
toast.success({
|
toast.success({
|
||||||
title: 'Succès',
|
title: t('success.title'),
|
||||||
message: t('admin.categories.toast.updated'),
|
message: t('admin.categories.toast.updated'),
|
||||||
})
|
})
|
||||||
return updated
|
return updated
|
||||||
@@ -272,11 +211,11 @@ export function useCategoryForm() {
|
|||||||
*/
|
*/
|
||||||
async function submitDelete(id: number): Promise<boolean> {
|
async function submitDelete(id: number): Promise<boolean> {
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
errors.value._global = ''
|
formErrors.clearErrors()
|
||||||
try {
|
try {
|
||||||
await api.delete(`/categories/${id}`, {}, { toast: false })
|
await api.delete(`/categories/${id}`, {}, { toast: false })
|
||||||
toast.success({
|
toast.success({
|
||||||
title: 'Succès',
|
title: t('success.title'),
|
||||||
message: t('admin.categories.toast.deleted'),
|
message: t('admin.categories.toast.deleted'),
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
@@ -297,7 +236,7 @@ export function useCategoryForm() {
|
|||||||
categoryTypeId.value = null
|
categoryTypeId.value = null
|
||||||
initialName.value = ''
|
initialName.value = ''
|
||||||
initialCategoryTypeId.value = null
|
initialCategoryTypeId.value = null
|
||||||
errors.value = { name: '', categoryType: '', _global: '' }
|
formErrors.clearErrors()
|
||||||
submitting.value = false
|
submitting.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +244,7 @@ export function useCategoryForm() {
|
|||||||
// State
|
// State
|
||||||
name,
|
name,
|
||||||
categoryTypeId,
|
categoryTypeId,
|
||||||
errors,
|
errors: formErrors.errors,
|
||||||
submitting,
|
submitting,
|
||||||
isDirty,
|
isDirty,
|
||||||
// Methods
|
// Methods
|
||||||
|
|||||||
@@ -10,41 +10,61 @@
|
|||||||
@click="$emit('remove')"
|
@click="$emit('remove')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Usage de l'adresse : Prospect exclusif de Livraison/Facturation
|
<!-- Usage de l'adresse : Select unique (plus simple pour l'utilisateur)
|
||||||
(RG-1.06/07/08). L'exclusivite est appliquee au toggle (cocher l'un
|
remplacant les 3 cases. Les options encodent les combinaisons valides
|
||||||
decoche l'autre) plutot qu'en masquant les options. -->
|
(exclusivite Prospect, RG-1.06/07/08) ; le back recoit toujours les
|
||||||
<MalioCheckbox
|
drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). -->
|
||||||
:model-value="model.isProspect"
|
<MalioSelect
|
||||||
:label="t('commercial.clients.form.address.prospect')"
|
:model-value="addressType"
|
||||||
group-class="self-center"
|
:options="addressTypeOptions"
|
||||||
|
:label="t('commercial.clients.form.address.addressType')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
@update:model-value="(v: boolean) => toggleFlag('isProspect', v)"
|
:required="true"
|
||||||
/>
|
@update:model-value="onAddressTypeChange"
|
||||||
<MalioCheckbox
|
|
||||||
:model-value="model.isDelivery"
|
|
||||||
:label="t('commercial.clients.form.address.delivery')"
|
|
||||||
group-class="self-center"
|
|
||||||
:readonly="readonly"
|
|
||||||
@update:model-value="(v: boolean) => toggleFlag('isDelivery', v)"
|
|
||||||
/>
|
|
||||||
<MalioCheckbox
|
|
||||||
:model-value="model.isBilling"
|
|
||||||
:label="t('commercial.clients.form.address.billing')"
|
|
||||||
group-class="self-center"
|
|
||||||
:readonly="readonly"
|
|
||||||
@update:model-value="(v: boolean) => toggleFlag('isBilling', v)"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Cellule vide : laisse un trou en position 4 (ligne 1) pour que
|
<!-- Sites Starseed : multiselect a tags (>= 1 obligatoire, RG-1.10). -->
|
||||||
Categorie reparte au debut de la ligne suivante. -->
|
<MalioSelectCheckbox
|
||||||
<div aria-hidden="true" />
|
:model-value="model.siteIris"
|
||||||
|
:options="siteOptions"
|
||||||
|
:label="t('commercial.clients.form.address.sites')"
|
||||||
|
:display-tag="true"
|
||||||
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
@update:model-value="(v: (string | number)[]) => update('siteIris', v.map(String))"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<MalioSelectCheckbox
|
||||||
|
:model-value="model.contactIris"
|
||||||
|
:options="contactOptions"
|
||||||
|
:label="t('commercial.clients.form.address.contacts')"
|
||||||
|
:display-tag="true"
|
||||||
|
:readonly="readonly"
|
||||||
|
@update:model-value="(v: (string | number)[]) => update('contactIris', v.map(String))"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Email de facturation : ligne 1 colonne 4, visible/obligatoire
|
||||||
|
seulement si Facturation (RG-1.11). Sinon un filler comble la
|
||||||
|
colonne pour que Categorie reparte au debut de la ligne 2. -->
|
||||||
|
<MalioInputEmail
|
||||||
|
v-if="isBillingEmailRequired(model)"
|
||||||
|
:model-value="model.billingEmail"
|
||||||
|
:label="t('commercial.clients.form.address.billingEmail')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="readonly"
|
||||||
|
:lowercase="true"
|
||||||
|
:error="errors?.billingEmail"
|
||||||
|
@update:model-value="(v: string) => update('billingEmail', v)"
|
||||||
|
/>
|
||||||
|
<div v-else aria-hidden="true" />
|
||||||
|
|
||||||
<MalioSelectCheckbox
|
<MalioSelectCheckbox
|
||||||
:model-value="model.categoryIris"
|
:model-value="model.categoryIris"
|
||||||
:options="categoryOptions"
|
:options="categoryOptions"
|
||||||
:label="t('commercial.clients.form.address.categories')"
|
:label="t('commercial.clients.form.address.categories')"
|
||||||
:display-tag="true"
|
:display-tag="true"
|
||||||
:disabled="readonly"
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
@update:model-value="(v: (string | number)[]) => update('categoryIris', v.map(String))"
|
@update:model-value="(v: (string | number)[]) => update('categoryIris', v.map(String))"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -52,7 +72,8 @@
|
|||||||
:model-value="model.country"
|
:model-value="model.country"
|
||||||
:options="countryOptions"
|
:options="countryOptions"
|
||||||
:label="t('commercial.clients.form.address.country')"
|
:label="t('commercial.clients.form.address.country')"
|
||||||
:disabled="readonly"
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
@update:model-value="(v: string | number | null) => update('country', String(v ?? 'France'))"
|
@update:model-value="(v: string | number | null) => update('country', String(v ?? 'France'))"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -61,6 +82,8 @@
|
|||||||
:label="t('commercial.clients.form.address.postalCode')"
|
:label="t('commercial.clients.form.address.postalCode')"
|
||||||
:mask="POSTAL_CODE_MASK"
|
:mask="POSTAL_CODE_MASK"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.postalCode"
|
||||||
@update:model-value="onPostalCodeChange"
|
@update:model-value="onPostalCodeChange"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -71,8 +94,10 @@
|
|||||||
:model-value="model.city"
|
:model-value="model.city"
|
||||||
:options="cityOptions"
|
:options="cityOptions"
|
||||||
:label="t('commercial.clients.form.address.city')"
|
:label="t('commercial.clients.form.address.city')"
|
||||||
:disabled="readonly"
|
:readonly="readonly"
|
||||||
empty-option-label=""
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.city"
|
||||||
@update:model-value="(v: string | number | null) => update('city', v === null ? null : String(v))"
|
@update:model-value="(v: string | number | null) => update('city', v === null ? null : String(v))"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
@@ -80,6 +105,8 @@
|
|||||||
:model-value="model.city"
|
:model-value="model.city"
|
||||||
:label="t('commercial.clients.form.address.city')"
|
:label="t('commercial.clients.form.address.city')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.city"
|
||||||
@update:model-value="(v: string) => update('city', v)"
|
@update:model-value="(v: string) => update('city', v)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -88,15 +115,19 @@
|
|||||||
sur l'input interne, pas sur la cellule de grille. Le wrapper porte
|
sur l'input interne, pas sur la cellule de grille. Le wrapper porte
|
||||||
le col-span-2, le champ le remplit (w-full). -->
|
le col-span-2, le champ le remplit (w-full). -->
|
||||||
<div class="col-span-2">
|
<div class="col-span-2">
|
||||||
<!-- Adresse : saisie assistee (BAN) ou libre en mode degrade. -->
|
<!-- Adresse : saisie assistee (BAN) en edition ; champ texte simple en
|
||||||
|
mode degrade OU en lecture seule (MalioInputAutocomplete ne reaffiche
|
||||||
|
pas sa valeur liee, il n'afficherait rien en readonly). -->
|
||||||
<MalioInputAutocomplete
|
<MalioInputAutocomplete
|
||||||
v-if="!degraded"
|
v-if="!degraded && !readonly"
|
||||||
:model-value="model.street"
|
:model-value="model.street"
|
||||||
:options="addressOptions"
|
:options="addressOptions"
|
||||||
:loading="addressLoading"
|
:loading="addressLoading"
|
||||||
:min-search-length="3"
|
:min-search-length="3"
|
||||||
:label="t('commercial.clients.form.address.street')"
|
:label="t('commercial.clients.form.address.street')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.street"
|
||||||
@update:model-value="(v: string | number | null) => update('street', v === null ? null : String(v))"
|
@update:model-value="(v: string | number | null) => update('street', v === null ? null : String(v))"
|
||||||
@search="onAddressSearch"
|
@search="onAddressSearch"
|
||||||
@select="onAddressSelect"
|
@select="onAddressSelect"
|
||||||
@@ -106,6 +137,8 @@
|
|||||||
:model-value="model.street"
|
:model-value="model.street"
|
||||||
:label="t('commercial.clients.form.address.street')"
|
:label="t('commercial.clients.form.address.street')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.street"
|
||||||
@update:model-value="(v: string) => update('street', v)"
|
@update:model-value="(v: string) => update('street', v)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -115,50 +148,20 @@
|
|||||||
:model-value="model.streetComplement"
|
:model-value="model.streetComplement"
|
||||||
:label="t('commercial.clients.form.address.streetComplement')"
|
:label="t('commercial.clients.form.address.streetComplement')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:error="errors?.streetComplement"
|
||||||
@update:model-value="(v: string) => update('streetComplement', v)"
|
@update:model-value="(v: string) => update('streetComplement', v)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Sites Starseed : cases a cocher inline (>= 1 obligatoire, RG-1.10). -->
|
|
||||||
<div class="flex justify-between">
|
|
||||||
<MalioCheckbox
|
|
||||||
v-for="site in siteOptions"
|
|
||||||
:key="site.value"
|
|
||||||
:model-value="model.siteIris.includes(site.value)"
|
|
||||||
:label="site.label"
|
|
||||||
group-class="w-auto self-center"
|
|
||||||
:readonly="readonly"
|
|
||||||
@update:model-value="(v: boolean) => toggleSite(site.value, v)"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<MalioSelectCheckbox
|
|
||||||
:model-value="model.contactIris"
|
|
||||||
:options="contactOptions"
|
|
||||||
:label="t('commercial.clients.form.address.contacts')"
|
|
||||||
:display-tag="true"
|
|
||||||
:disabled="readonly"
|
|
||||||
@update:model-value="(v: (string | number)[]) => update('contactIris', v.map(String))"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- Email de facturation : visible/obligatoire seulement si Facturation
|
|
||||||
est coche (RG-1.11). -->
|
|
||||||
<MalioInputText
|
|
||||||
v-if="isBillingEmailRequired(model)"
|
|
||||||
:model-value="model.billingEmail"
|
|
||||||
:label="t('commercial.clients.form.address.billingEmail')"
|
|
||||||
:required="true"
|
|
||||||
:readonly="readonly"
|
|
||||||
@update:model-value="(v: string) => update('billingEmail', v)"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import {
|
||||||
applyProspectExclusivity,
|
addressFlagsFromType,
|
||||||
|
addressTypeFromFlags,
|
||||||
isBillingEmailRequired,
|
isBillingEmailRequired,
|
||||||
type AddressFlagsDraft,
|
type AddressType,
|
||||||
} from '~/modules/commercial/utils/clientFormRules'
|
} from '~/modules/commercial/utils/clientFormRules'
|
||||||
import { useAddressAutocomplete, type AddressSuggestion } from '~/shared/composables/useAddressAutocomplete'
|
import { useAddressAutocomplete, type AddressSuggestion } from '~/shared/composables/useAddressAutocomplete'
|
||||||
import type { CategoryOption, RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
import type { CategoryOption, RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
||||||
@@ -181,6 +184,8 @@ const props = defineProps<{
|
|||||||
countryOptions: RefOption[]
|
countryOptions: RefOption[]
|
||||||
removable?: boolean
|
removable?: boolean
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
|
/** Erreurs serveur 422 de cette ligne, indexees par champ (ERP-101). */
|
||||||
|
errors?: Record<string, string>
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -195,10 +200,55 @@ const autocomplete = useAddressAutocomplete()
|
|||||||
|
|
||||||
const model = computed(() => props.modelValue)
|
const model = computed(() => props.modelValue)
|
||||||
|
|
||||||
|
// Type d'adresse (Select unique) derive des drapeaux back. null tant qu'aucun
|
||||||
|
// drapeau n'est pose -> champ vide + bouton « Valider » bloque (cf. parent).
|
||||||
|
const addressType = computed<AddressType | null>(() => addressTypeFromFlags(model.value))
|
||||||
|
|
||||||
|
const addressTypeOptions = computed<RefOption[]>(() => [
|
||||||
|
{ value: 'prospect', label: t('commercial.clients.form.address.addressTypeProspect') },
|
||||||
|
{ value: 'delivery', label: t('commercial.clients.form.address.addressTypeDelivery') },
|
||||||
|
{ value: 'billing', label: t('commercial.clients.form.address.addressTypeBilling') },
|
||||||
|
{ value: 'delivery_billing', label: t('commercial.clients.form.address.addressTypeDeliveryBilling') },
|
||||||
|
])
|
||||||
|
|
||||||
|
/** Applique le type choisi en repercutant les 3 drapeaux back (immutabilite). */
|
||||||
|
function onAddressTypeChange(value: string | number | null): void {
|
||||||
|
if (value === null) return
|
||||||
|
emit('update:modelValue', { ...props.modelValue, ...addressFlagsFromType(value as AddressType) })
|
||||||
|
}
|
||||||
|
|
||||||
// Mode degrade : service BAN indisponible → Ville/Adresse en saisie libre.
|
// Mode degrade : service BAN indisponible → Ville/Adresse en saisie libre.
|
||||||
const degraded = ref(false)
|
const degraded = ref(false)
|
||||||
const cityOptions = ref<RefOption[]>([])
|
// Villes proposees par la BAN (alimentees a la saisie du code postal).
|
||||||
const addressOptions = ref<RefOption[]>([])
|
const banCityOptions = ref<RefOption[]>([])
|
||||||
|
// Adresses proposees par la BAN (alimentees a la saisie d'adresse).
|
||||||
|
const banAddressOptions = ref<RefOption[]>([])
|
||||||
|
|
||||||
|
// Options ville effectives : on garantit que la ville courante figure toujours
|
||||||
|
// dans la liste, sinon MalioSelect (qui resout le libelle depuis ses options)
|
||||||
|
// afficherait un champ vide en lecture seule (consultation 1.11) ou en edition
|
||||||
|
// d'une adresse existante (1.12), ou la BAN n'a pas (re)peuple les suggestions.
|
||||||
|
const cityOptions = computed<RefOption[]>(() => {
|
||||||
|
const current = props.modelValue.city
|
||||||
|
if (current && !banCityOptions.value.some(o => o.value === current)) {
|
||||||
|
return [{ value: current, label: current }, ...banCityOptions.value]
|
||||||
|
}
|
||||||
|
return banCityOptions.value
|
||||||
|
})
|
||||||
|
|
||||||
|
// Meme garantie que cityOptions pour le champ Adresse : la rue courante doit
|
||||||
|
// toujours figurer dans les options, sinon MalioInputAutocomplete (qui resout
|
||||||
|
// l'affichage depuis ses options) laisse le champ VIDE des que la liste de
|
||||||
|
// suggestions BAN est vide — typiquement juste apres validation (remontage) ou
|
||||||
|
// a l'edition d'une adresse existante (1.12), alors que la valeur est bien
|
||||||
|
// persistee. On reinjecte donc la rue liee si la BAN ne l'a pas (re)proposee.
|
||||||
|
const addressOptions = computed<RefOption[]>(() => {
|
||||||
|
const current = props.modelValue.street
|
||||||
|
if (current && !banAddressOptions.value.some(o => o.value === current)) {
|
||||||
|
return [{ value: current, label: current }, ...banAddressOptions.value]
|
||||||
|
}
|
||||||
|
return banAddressOptions.value
|
||||||
|
})
|
||||||
const addressLoading = ref(false)
|
const addressLoading = ref(false)
|
||||||
// Conserve les suggestions d'adresse pour retrouver ville/CP au moment du select.
|
// Conserve les suggestions d'adresse pour retrouver ville/CP au moment du select.
|
||||||
let lastAddressSuggestions: AddressSuggestion[] = []
|
let lastAddressSuggestions: AddressSuggestion[] = []
|
||||||
@@ -208,25 +258,6 @@ function update<K extends keyof AddressFormDraft>(field: K, value: AddressFormDr
|
|||||||
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Coche/decoche un site Starseed rattache a l'adresse (M2M par IRI, RG-1.10). */
|
|
||||||
function toggleSite(siteIri: string, selected: boolean): void {
|
|
||||||
const current = props.modelValue.siteIris
|
|
||||||
const next = selected
|
|
||||||
? [...current, siteIri]
|
|
||||||
: current.filter(iri => iri !== siteIri)
|
|
||||||
update('siteIris', next)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Applique l'exclusivite Prospect / (Livraison|Facturation) au changement. */
|
|
||||||
function toggleFlag(field: keyof AddressFlagsDraft, value: boolean): void {
|
|
||||||
const flags = applyProspectExclusivity(
|
|
||||||
{ isProspect: model.value.isProspect, isDelivery: model.value.isDelivery, isBilling: model.value.isBilling },
|
|
||||||
field,
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
emit('update:modelValue', { ...props.modelValue, ...flags })
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Bascule définitivement en mode degrade et previent le parent (toast unique). */
|
/** Bascule définitivement en mode degrade et previent le parent (toast unique). */
|
||||||
function enterDegraded(): void {
|
function enterDegraded(): void {
|
||||||
if (!degraded.value) {
|
if (!degraded.value) {
|
||||||
@@ -248,7 +279,7 @@ async function onPostalCodeChange(value: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const suggestions = await autocomplete.searchCity(digits)
|
const suggestions = await autocomplete.searchCity(digits)
|
||||||
cityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
|
banCityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
enterDegraded()
|
enterDegraded()
|
||||||
@@ -265,7 +296,7 @@ async function onAddressSearch(query: string): Promise<void> {
|
|||||||
const postalCode = (model.value.postalCode ?? '').replace(/\D/g, '') || undefined
|
const postalCode = (model.value.postalCode ?? '').replace(/\D/g, '') || undefined
|
||||||
const suggestions = await autocomplete.searchAddress(query, postalCode)
|
const suggestions = await autocomplete.searchAddress(query, postalCode)
|
||||||
lastAddressSuggestions = suggestions
|
lastAddressSuggestions = suggestions
|
||||||
addressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
banAddressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
enterDegraded()
|
enterDegraded()
|
||||||
|
|||||||
@@ -16,24 +16,29 @@
|
|||||||
:model-value="model.lastName"
|
:model-value="model.lastName"
|
||||||
:label="t('commercial.clients.form.contact.lastName')"
|
:label="t('commercial.clients.form.contact.lastName')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:error="errors?.lastName"
|
||||||
@update:model-value="(v: string) => update('lastName', v)"
|
@update:model-value="(v: string) => update('lastName', v)"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
:model-value="model.firstName"
|
:model-value="model.firstName"
|
||||||
:label="t('commercial.clients.form.contact.firstName')"
|
:label="t('commercial.clients.form.contact.firstName')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:error="errors?.firstName"
|
||||||
@update:model-value="(v: string) => update('firstName', v)"
|
@update:model-value="(v: string) => update('firstName', v)"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
:model-value="model.jobTitle"
|
:model-value="model.jobTitle"
|
||||||
:label="t('commercial.clients.form.contact.jobTitle')"
|
:label="t('commercial.clients.form.contact.jobTitle')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:error="errors?.jobTitle"
|
||||||
@update:model-value="(v: string) => update('jobTitle', v)"
|
@update:model-value="(v: string) => update('jobTitle', v)"
|
||||||
/>
|
/>
|
||||||
<MalioInputEmail
|
<MalioInputEmail
|
||||||
:model-value="model.email"
|
:model-value="model.email"
|
||||||
:label="t('commercial.clients.form.contact.email')"
|
:label="t('commercial.clients.form.contact.email')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:lowercase="true"
|
||||||
|
:error="errors?.email"
|
||||||
@update:model-value="(v: string) => update('email', v)"
|
@update:model-value="(v: string) => update('email', v)"
|
||||||
/>
|
/>
|
||||||
<MalioInputPhone
|
<MalioInputPhone
|
||||||
@@ -41,6 +46,7 @@
|
|||||||
:label="t('commercial.clients.form.contact.phonePrimary')"
|
:label="t('commercial.clients.form.contact.phonePrimary')"
|
||||||
:mask="PHONE_MASK"
|
:mask="PHONE_MASK"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:error="errors?.phonePrimary"
|
||||||
:addable="!model.hasSecondaryPhone && !readonly"
|
:addable="!model.hasSecondaryPhone && !readonly"
|
||||||
:add-button-label="t('commercial.clients.form.contact.addPhone')"
|
:add-button-label="t('commercial.clients.form.contact.addPhone')"
|
||||||
@update:model-value="(v: string) => update('phonePrimary', v)"
|
@update:model-value="(v: string) => update('phonePrimary', v)"
|
||||||
@@ -52,6 +58,7 @@
|
|||||||
:label="t('commercial.clients.form.contact.phoneSecondary')"
|
:label="t('commercial.clients.form.contact.phoneSecondary')"
|
||||||
:mask="PHONE_MASK"
|
:mask="PHONE_MASK"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
|
:error="errors?.phoneSecondary"
|
||||||
@update:model-value="(v: string) => update('phoneSecondary', v)"
|
@update:model-value="(v: string) => update('phoneSecondary', v)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -73,6 +80,8 @@ const props = defineProps<{
|
|||||||
removable?: boolean
|
removable?: boolean
|
||||||
/** Bloc en lecture seule (onglet valide). */
|
/** Bloc en lecture seule (onglet valide). */
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
|
/** Erreurs serveur 422 de cette ligne, indexees par champ (ERP-101). */
|
||||||
|
errors?: Record<string, string>
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
<template>
|
|
||||||
<!--
|
|
||||||
Placeholder des onglets non encore implementes (Transport, Statistiques,
|
|
||||||
Rapports, Echanges). Frame vide blanche : aucun champ, aucun bouton,
|
|
||||||
aucun message « En cours » (decision Tristan 28/05). L'orchestrateur passe
|
|
||||||
automatiquement a l'onglet suivant — ce composant n'est qu'une coquille
|
|
||||||
visuelle reutilisee par 1.11/1.12.
|
|
||||||
-->
|
|
||||||
<div class="min-h-[240px] rounded-md bg-white" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
// Composant purement presentationnel : aucune prop, aucun event.
|
|
||||||
</script>
|
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
import { describe, it, expect, vi } from 'vitest'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import { defineComponent, h, ref, computed } from 'vue'
|
||||||
|
import { emptyAddress } from '~/modules/commercial/types/clientForm'
|
||||||
|
import ClientAddressBlock from '../ClientAddressBlock.vue'
|
||||||
|
|
||||||
|
// Le composable BAN est mocke : aucun appel reseau, aucune suggestion chargee.
|
||||||
|
// On reproduit ainsi l'etat « adresse persistee, mais liste de suggestions
|
||||||
|
// vide » (remontage apres validation / edition d'une adresse existante).
|
||||||
|
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
||||||
|
useAddressAutocomplete: () => ({
|
||||||
|
searchCity: vi.fn(),
|
||||||
|
searchAddress: vi.fn(),
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
// Auto-imports Nuxt/Vue utilises sans import explicite par le composant.
|
||||||
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||||
|
vi.stubGlobal('ref', ref)
|
||||||
|
vi.stubGlobal('computed', computed)
|
||||||
|
|
||||||
|
// Stub de MalioInputAutocomplete : expose les `value` des options recues, pour
|
||||||
|
// verifier que la rue courante figure bien dans la liste (sinon le composant
|
||||||
|
// Malio ne peut pas resoudre/afficher la valeur liee -> champ vide).
|
||||||
|
const MalioInputAutocompleteStub = defineComponent({
|
||||||
|
name: 'MalioInputAutocomplete',
|
||||||
|
props: {
|
||||||
|
modelValue: { type: [String, Number, null], default: undefined },
|
||||||
|
options: { type: Array as () => { value: string | number, label: string }[], default: () => [] },
|
||||||
|
loading: { type: Boolean, default: false },
|
||||||
|
minSearchLength: { type: Number, default: 0 },
|
||||||
|
label: { type: String, default: '' },
|
||||||
|
readonly: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
emits: ['update:modelValue', 'search', 'select'],
|
||||||
|
setup(props) {
|
||||||
|
return () => h('div', {
|
||||||
|
'data-testid': 'addr-autocomplete',
|
||||||
|
'data-options': JSON.stringify(props.options.map(o => o.value)),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function mountBlock(street: string | null) {
|
||||||
|
return mount(ClientAddressBlock, {
|
||||||
|
props: {
|
||||||
|
modelValue: { ...emptyAddress(), street },
|
||||||
|
title: 'Adresse',
|
||||||
|
categoryOptions: [],
|
||||||
|
siteOptions: [],
|
||||||
|
contactOptions: [],
|
||||||
|
countryOptions: [],
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
MalioButtonIcon: true,
|
||||||
|
MalioCheckbox: true,
|
||||||
|
MalioSelect: true,
|
||||||
|
MalioSelectCheckbox: true,
|
||||||
|
MalioInputText: true,
|
||||||
|
MalioInputAutocomplete: MalioInputAutocompleteStub,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('ClientAddressBlock — affichage de l\'adresse persistee', () => {
|
||||||
|
it('inclut la rue courante dans les options de l\'autocomplete meme sans recherche BAN', () => {
|
||||||
|
const wrapper = mountBlock('8 Boulevard du Port')
|
||||||
|
|
||||||
|
const el = wrapper.find('[data-testid="addr-autocomplete"]')
|
||||||
|
const values = JSON.parse(el.attributes('data-options') ?? '[]')
|
||||||
|
|
||||||
|
expect(values).toContain('8 Boulevard du Port')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stub MalioInputText qui re-expose `label` + `error` recus : permet de cibler
|
||||||
|
* un champ par son libelle et de verifier l'erreur 422 propagee (ERP-101).
|
||||||
|
*/
|
||||||
|
const MalioInputTextProbe = defineComponent({
|
||||||
|
name: 'MalioInputTextProbe',
|
||||||
|
props: {
|
||||||
|
modelValue: { type: [String, Number, null], default: undefined },
|
||||||
|
error: { type: String, default: '' },
|
||||||
|
label: { type: String, default: '' },
|
||||||
|
readonly: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
return () => h('div', {
|
||||||
|
'data-testid': 'addr-text',
|
||||||
|
'data-label': props.label,
|
||||||
|
'data-error': props.error,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('ClientAddressBlock — mapping erreur par champ (ERP-101)', () => {
|
||||||
|
function mountWithErrors(errors: Record<string, string>) {
|
||||||
|
return mount(ClientAddressBlock, {
|
||||||
|
props: {
|
||||||
|
modelValue: emptyAddress(),
|
||||||
|
title: 'Adresse',
|
||||||
|
categoryOptions: [],
|
||||||
|
siteOptions: [],
|
||||||
|
contactOptions: [],
|
||||||
|
countryOptions: [],
|
||||||
|
errors,
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
MalioButtonIcon: true,
|
||||||
|
MalioCheckbox: true,
|
||||||
|
MalioSelect: true,
|
||||||
|
MalioSelectCheckbox: true,
|
||||||
|
MalioInputAutocomplete: MalioInputAutocompleteStub,
|
||||||
|
MalioInputText: MalioInputTextProbe,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
it('affiche l\'erreur serveur sur le champ code postal via la prop errors', () => {
|
||||||
|
const wrapper = mountWithErrors({ postalCode: 'Code postal invalide.' })
|
||||||
|
|
||||||
|
const field = wrapper.findAll('[data-testid="addr-text"]').find(
|
||||||
|
el => el.attributes('data-label') === 'commercial.clients.form.address.postalCode',
|
||||||
|
)
|
||||||
|
expect(field?.attributes('data-error')).toBe('Code postal invalide.')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import { defineComponent, h, ref, computed } from 'vue'
|
||||||
|
import { emptyContact } from '~/modules/commercial/types/clientForm'
|
||||||
|
import ClientContactBlock from '../ClientContactBlock.vue'
|
||||||
|
|
||||||
|
// Auto-imports Nuxt/Vue utilises sans import explicite par le composant.
|
||||||
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||||
|
vi.stubGlobal('ref', ref)
|
||||||
|
vi.stubGlobal('computed', computed)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stub d'un champ Malio qui re-expose la prop `error` recue dans un attribut
|
||||||
|
* data-* : permet de verifier que le bloc propage bien `:errors[champ]` sur le
|
||||||
|
* bon champ (ERP-101 — mapping erreur 422 par champ, par ligne de collection).
|
||||||
|
*/
|
||||||
|
function errorProbe(testid: string) {
|
||||||
|
return defineComponent({
|
||||||
|
name: `Probe-${testid}`,
|
||||||
|
props: {
|
||||||
|
modelValue: { type: [String, Number, null], default: undefined },
|
||||||
|
error: { type: String, default: '' },
|
||||||
|
label: { type: String, default: '' },
|
||||||
|
readonly: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
return () => h('div', { 'data-testid': testid, 'data-error': props.error })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function mountBlock(errors?: Record<string, string>) {
|
||||||
|
return mount(ClientContactBlock, {
|
||||||
|
props: {
|
||||||
|
modelValue: emptyContact(),
|
||||||
|
title: 'Contact 1',
|
||||||
|
...(errors ? { errors } : {}),
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
MalioButtonIcon: true,
|
||||||
|
MalioInputPhone: true,
|
||||||
|
MalioInputText: errorProbe('contact-text'),
|
||||||
|
MalioInputEmail: errorProbe('contact-email'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('ClientContactBlock — mapping erreur par champ (ERP-101)', () => {
|
||||||
|
it('affiche l\'erreur serveur sur le champ email via la prop errors', () => {
|
||||||
|
const wrapper = mountBlock({ email: 'Adresse e-mail invalide.' })
|
||||||
|
|
||||||
|
const email = wrapper.find('[data-testid="contact-email"]')
|
||||||
|
expect(email.attributes('data-error')).toBe('Adresse e-mail invalide.')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('laisse les champs sans erreur quand errors est absent', () => {
|
||||||
|
const wrapper = mountBlock()
|
||||||
|
|
||||||
|
const email = wrapper.find('[data-testid="contact-email"]')
|
||||||
|
expect(email.attributes('data-error')).toBe('')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
|
// Mocks des composables auto-importes par Nuxt (indisponibles sous happy-dom).
|
||||||
|
const mockGet = vi.hoisted(() => vi.fn())
|
||||||
|
const mockPatch = vi.hoisted(() => vi.fn())
|
||||||
|
|
||||||
|
vi.stubGlobal('useApi', () => ({
|
||||||
|
get: mockGet,
|
||||||
|
post: vi.fn(),
|
||||||
|
put: vi.fn(),
|
||||||
|
patch: mockPatch,
|
||||||
|
delete: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
const { useClient } = await import('../useClient')
|
||||||
|
|
||||||
|
const SAMPLE = { '@id': '/api/clients/42', id: 42, companyName: 'ACME', isArchived: false }
|
||||||
|
|
||||||
|
describe('useClient', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockGet.mockReset()
|
||||||
|
mockPatch.mockReset()
|
||||||
|
mockGet.mockResolvedValue(SAMPLE)
|
||||||
|
mockPatch.mockResolvedValue({ ...SAMPLE, isArchived: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('charge le detail via GET /clients/{id} en Hydra, sans toast', async () => {
|
||||||
|
const { client, load } = useClient(42)
|
||||||
|
await load()
|
||||||
|
|
||||||
|
expect(mockGet).toHaveBeenCalledWith(
|
||||||
|
'/clients/42',
|
||||||
|
{},
|
||||||
|
expect.objectContaining({
|
||||||
|
headers: { Accept: 'application/ld+json' },
|
||||||
|
toast: false,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
expect(client.value).toEqual(SAMPLE)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('bascule loading pendant le chargement et le retombe a false', async () => {
|
||||||
|
const { loading, load } = useClient(42)
|
||||||
|
const promise = load()
|
||||||
|
expect(loading.value).toBe(true)
|
||||||
|
await promise
|
||||||
|
expect(loading.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('marque error et laisse client null si le GET echoue (404...)', async () => {
|
||||||
|
mockGet.mockRejectedValueOnce(new Error('not found'))
|
||||||
|
const { client, error, load } = useClient(99)
|
||||||
|
await load()
|
||||||
|
expect(error.value).toBe(true)
|
||||||
|
expect(client.value).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('archive() PATCHe { isArchived: true } sans toast puis RECHARGE le detail complet', async () => {
|
||||||
|
// 1er GET = chargement initial, 2e GET = rechargement post-archivage.
|
||||||
|
mockGet.mockResolvedValueOnce(SAMPLE)
|
||||||
|
mockGet.mockResolvedValueOnce({ ...SAMPLE, isArchived: true })
|
||||||
|
const { client, load, archive } = useClient(42)
|
||||||
|
await load()
|
||||||
|
await archive()
|
||||||
|
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
|
'/clients/42',
|
||||||
|
{ isArchived: true },
|
||||||
|
expect.objectContaining({ toast: false }),
|
||||||
|
)
|
||||||
|
// Le detail est re-fetch (le PATCH ne renvoie pas l'embed complet).
|
||||||
|
expect(mockGet).toHaveBeenCalledTimes(2)
|
||||||
|
expect(client.value?.isArchived).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('restore() PATCHe { isArchived: false } (payload isArchived SEUL)', async () => {
|
||||||
|
const { load, restore } = useClient(42)
|
||||||
|
await load()
|
||||||
|
await restore()
|
||||||
|
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
|
'/clients/42',
|
||||||
|
{ isArchived: false },
|
||||||
|
expect.objectContaining({ toast: false }),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('propage l\'erreur (ex: 409 conflit homonyme RG-1.23) au lieu de l\'avaler', async () => {
|
||||||
|
const conflict = { response: { status: 409 } }
|
||||||
|
mockPatch.mockRejectedValueOnce(conflict)
|
||||||
|
const { load, restore } = useClient(42)
|
||||||
|
await load()
|
||||||
|
await expect(restore()).rejects.toBe(conflict)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import { describe, it, expect, vi } from 'vitest'
|
||||||
|
import { useFormErrors } from '~/shared/composables/useFormErrors'
|
||||||
|
import { useClientFormErrors } from '../useClientFormErrors'
|
||||||
|
|
||||||
|
// useFormErrors (auto-import) expose l'implementation reelle ; elle consomme
|
||||||
|
// useToast + useI18n, stubbes ici.
|
||||||
|
vi.stubGlobal('useToast', () => ({ error: vi.fn(), success: vi.fn() }))
|
||||||
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||||
|
vi.stubGlobal('useFormErrors', useFormErrors)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests du composable partage `useClientFormErrors` — factorisation du cablage
|
||||||
|
* d'erreurs des ecrans client (creation/edition), suggestion de revue ERP-101.
|
||||||
|
* `mapRowError` ne toaste plus : il retourne un booleen et chaque page garde son
|
||||||
|
* propre fallback (toast.error en creation, showError en edition).
|
||||||
|
*/
|
||||||
|
describe('useClientFormErrors', () => {
|
||||||
|
it('expose les 3 etats scalaires (vides) et les 3 tableaux d\'erreurs par ligne', () => {
|
||||||
|
const f = useClientFormErrors()
|
||||||
|
expect(f.mainErrors.errors).toEqual({})
|
||||||
|
expect(f.informationErrors.errors).toEqual({})
|
||||||
|
expect(f.accountingErrors.errors).toEqual({})
|
||||||
|
expect(f.contactErrors.value).toEqual([])
|
||||||
|
expect(f.addressErrors.value).toEqual([])
|
||||||
|
expect(f.ribErrors.value).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('mapRowError mappe une 422 sur target[index] et retourne true', () => {
|
||||||
|
const f = useClientFormErrors()
|
||||||
|
const error = {
|
||||||
|
response: {
|
||||||
|
status: 422,
|
||||||
|
_data: { violations: [{ propertyPath: 'email', message: 'Adresse invalide.' }] },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const mapped = f.mapRowError(error, f.contactErrors, 0)
|
||||||
|
expect(mapped).toBe(true)
|
||||||
|
expect(f.contactErrors.value[0]).toEqual({ email: 'Adresse invalide.' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('mapRowError retourne false et ne touche pas la cible pour une erreur non-422', () => {
|
||||||
|
const f = useClientFormErrors()
|
||||||
|
const error = { response: { status: 500, _data: {} } }
|
||||||
|
expect(f.mapRowError(error, f.ribErrors, 0)).toBe(false)
|
||||||
|
expect(f.ribErrors.value[0]).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('mapRowError retourne false pour une 422 sans violation exploitable', () => {
|
||||||
|
const f = useClientFormErrors()
|
||||||
|
const error = { response: { status: 422, _data: { 'hydra:description': 'Donnees invalides.' } } }
|
||||||
|
expect(f.mapRowError(error, f.addressErrors, 0)).toBe(false)
|
||||||
|
expect(f.addressErrors.value[0]).toBeUndefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Construit une erreur facon useApi : 422 avec violations Hydra.
|
||||||
|
function http422(path: string, message: string) {
|
||||||
|
return { response: { status: 422, _data: { violations: [{ propertyPath: path, message }] } } }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `submitRows` factorise la soumission d'une collection de blocs (contacts /
|
||||||
|
* adresses / RIB) : on tente TOUS les blocs et on collecte les erreurs par index
|
||||||
|
* sans stopper au premier echec (ERP-110 / ERP-101).
|
||||||
|
*/
|
||||||
|
describe('useClientFormErrors.submitRows', () => {
|
||||||
|
it('tente TOUS les blocs et mappe les erreurs par index, sans stopper au premier echec', async () => {
|
||||||
|
const { contactErrors, submitRows } = useClientFormErrors()
|
||||||
|
const seen: number[] = []
|
||||||
|
const onUnmapped = vi.fn()
|
||||||
|
|
||||||
|
const saveRow = async (_row: unknown, index: number) => {
|
||||||
|
seen.push(index)
|
||||||
|
if (index === 1) throw http422('email', 'Email invalide')
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasError = await submitRows(
|
||||||
|
[{ a: 0 }, { a: 1 }, { a: 2 }],
|
||||||
|
contactErrors,
|
||||||
|
saveRow,
|
||||||
|
onUnmapped,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(seen).toEqual([0, 1, 2]) // tous les blocs tentes
|
||||||
|
expect(hasError).toBe(true)
|
||||||
|
expect(contactErrors.value[1]).toEqual({ email: 'Email invalide' })
|
||||||
|
expect(contactErrors.value[0]).toBeUndefined()
|
||||||
|
expect(onUnmapped).not.toHaveBeenCalled() // 422 mappee, pas de fallback
|
||||||
|
})
|
||||||
|
|
||||||
|
it('delegue le fallback onUnmappedError pour une erreur non mappable et marque hasError', async () => {
|
||||||
|
const { ribErrors, submitRows } = useClientFormErrors()
|
||||||
|
const onUnmapped = vi.fn()
|
||||||
|
|
||||||
|
const hasError = await submitRows(
|
||||||
|
[{ a: 0 }],
|
||||||
|
ribErrors,
|
||||||
|
async () => { throw { response: { status: 500, _data: {} } } },
|
||||||
|
onUnmapped,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(hasError).toBe(true)
|
||||||
|
expect(onUnmapped).toHaveBeenCalledTimes(1)
|
||||||
|
expect(ribErrors.value[0]).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('saute les lignes filtrees par shouldSkip et renvoie false si tout passe', async () => {
|
||||||
|
const { contactErrors, submitRows } = useClientFormErrors()
|
||||||
|
const saved: number[] = []
|
||||||
|
|
||||||
|
const hasError = await submitRows(
|
||||||
|
[{ skip: true }, { skip: false }],
|
||||||
|
contactErrors,
|
||||||
|
async (_row, index) => { saved.push(index) },
|
||||||
|
vi.fn(),
|
||||||
|
(row: { skip: boolean }) => row.skip,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(saved).toEqual([1])
|
||||||
|
expect(hasError).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -28,7 +28,7 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
return Promise.reject(new Error('403 Forbidden'))
|
return Promise.reject(new Error('403 Forbidden'))
|
||||||
}
|
}
|
||||||
if (url === '/sites') {
|
if (url === '/sites') {
|
||||||
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault' }] })
|
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault', postalCode: '86100' }] })
|
||||||
}
|
}
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
member: [{ '@id': '/api/x/1', code: 'X', label: 'Libelle X' }],
|
member: [{ '@id': '/api/x/1', code: 'X', label: 'Libelle X' }],
|
||||||
@@ -40,7 +40,8 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
await refs.loadCommon()
|
await refs.loadCommon()
|
||||||
|
|
||||||
// Resilience : les referentiels OK sont peuples malgre l'echec de /categories.
|
// Resilience : les referentiels OK sont peuples malgre l'echec de /categories.
|
||||||
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: 'Chatellerault' }])
|
// Le libelle d'un site est son numero de departement (2 premiers chiffres du code postal).
|
||||||
|
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: '86' }])
|
||||||
expect(refs.tvaModes.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
expect(refs.tvaModes.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
||||||
expect(refs.banks.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
expect(refs.banks.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (url === '/sites') {
|
if (url === '/sites') {
|
||||||
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault' }] })
|
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault', postalCode: '86100' }] })
|
||||||
}
|
}
|
||||||
return Promise.resolve({ member: [] })
|
return Promise.resolve({ member: [] })
|
||||||
})
|
})
|
||||||
@@ -67,6 +68,7 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
|||||||
expect(refs.categories.value).toEqual([
|
expect(refs.categories.value).toEqual([
|
||||||
{ value: '/api/categories/1', label: 'Secteur', code: 'SECTEUR' },
|
{ value: '/api/categories/1', label: 'Secteur', code: 'SECTEUR' },
|
||||||
])
|
])
|
||||||
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: 'Chatellerault' }])
|
// Le libelle d'un site est son numero de departement (2 premiers chiffres du code postal).
|
||||||
|
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: '86' }])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import { ref } from 'vue'
|
||||||
|
import type { ClientDetail } from '~/modules/commercial/utils/clientConsultation'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chargement et actions d'archivage d'un client unique (ecran « Consultation
|
||||||
|
* client », 1.11). Lit le detail embarque via `GET /api/clients/{id}` (contacts /
|
||||||
|
* adresses / ribs sous `client:item:read` / `client:read:accounting`) et expose
|
||||||
|
* les bascules d'archivage (PATCH `isArchived` SEUL — tout autre champ => 422).
|
||||||
|
*
|
||||||
|
* L'en-tete `Accept: application/ld+json` est impose pour obtenir le payload
|
||||||
|
* Hydra complet (sans lui, API Platform 4 renvoie une representation reduite).
|
||||||
|
*
|
||||||
|
* Etat 100 % local a l'instance (refs) — aucune persistance URL. Les erreurs
|
||||||
|
* d'archivage/restauration (notamment le 409 RG-1.23 : homonyme actif a la
|
||||||
|
* restauration) sont PROPAGEES a l'appelant, qui decide du toast a afficher.
|
||||||
|
*/
|
||||||
|
export function useClient(id: number | string) {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const client = ref<ClientDetail | null>(null)
|
||||||
|
const loading = ref(false)
|
||||||
|
const error = ref(false)
|
||||||
|
|
||||||
|
/** Recupere le detail complet (embed contacts/adresses/ribs + comptabilite). */
|
||||||
|
function fetchDetail(): Promise<ClientDetail> {
|
||||||
|
return api.get<ClientDetail>(
|
||||||
|
`/clients/${id}`,
|
||||||
|
{},
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Charge le detail du client. En cas d'echec : `error = true`, `client = null`. */
|
||||||
|
async function load(): Promise<void> {
|
||||||
|
loading.value = true
|
||||||
|
error.value = false
|
||||||
|
try {
|
||||||
|
client.value = await fetchDetail()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
error.value = true
|
||||||
|
client.value = null
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bascule l'archivage (PATCH `isArchived` SEUL — tout autre champ => 422),
|
||||||
|
* puis RECHARGE le detail complet : la reponse du PATCH ne porte que le groupe
|
||||||
|
* `client:read` (ni l'embed contacts/adresses/ribs ni les libelles des
|
||||||
|
* referentiels comptables), un simple merge laisserait l'affichage incoherent.
|
||||||
|
* Toute erreur (notamment le 409 d'homonyme actif a la restauration, RG-1.23)
|
||||||
|
* est propagee a l'appelant AVANT le rechargement.
|
||||||
|
*/
|
||||||
|
async function setArchived(isArchived: boolean): Promise<void> {
|
||||||
|
await api.patch(`/clients/${id}`, { isArchived }, { toast: false })
|
||||||
|
client.value = await fetchDetail()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
client,
|
||||||
|
loading,
|
||||||
|
error,
|
||||||
|
load,
|
||||||
|
archive: () => setArchived(true),
|
||||||
|
restore: () => setArchived(false),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* Composable d'erreurs partage des ecrans client (creation + edition, M1
|
||||||
|
* Commercial). Factorise le cablage identique entre `clients/new.vue` et
|
||||||
|
* `clients/[id]/edit.vue` (suggestion de revue ERP-101) :
|
||||||
|
* - un `useFormErrors` par groupe scalaire (Principal / Information /
|
||||||
|
* Comptabilite) : violations 422 affichees inline sous chaque champ ;
|
||||||
|
* - un tableau d'erreurs PAR LIGNE pour chaque collection (contacts /
|
||||||
|
* adresses / RIB), aligne sur l'index du `v-for`.
|
||||||
|
*
|
||||||
|
* `mapRowError` ne toaste PAS lui-meme : il retourne un booleen (true = mappe
|
||||||
|
* inline). Chaque page conserve ainsi son propre fallback dans le `catch`
|
||||||
|
* (toast generique en creation, `showError` en edition) sans imposer un
|
||||||
|
* comportement commun.
|
||||||
|
*/
|
||||||
|
import { ref, type Ref } from 'vue'
|
||||||
|
import { mapViolationsToRecord } from '~/shared/utils/api'
|
||||||
|
|
||||||
|
export function useClientFormErrors() {
|
||||||
|
const mainErrors = useFormErrors()
|
||||||
|
const informationErrors = useFormErrors()
|
||||||
|
const accountingErrors = useFormErrors()
|
||||||
|
const contactErrors = ref<Record<string, string>[]>([])
|
||||||
|
const addressErrors = ref<Record<string, string>[]>([])
|
||||||
|
const ribErrors = ref<Record<string, string>[]>([])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mappe l'erreur d'une ligne de collection sur le tableau cible (par index).
|
||||||
|
* 422 avec violations exploitables → erreurs inline sous les champs de la
|
||||||
|
* ligne + retourne true. Sinon → ne touche pas la cible et retourne false
|
||||||
|
* (le caller decide du fallback toast).
|
||||||
|
*/
|
||||||
|
function mapRowError(
|
||||||
|
error: unknown,
|
||||||
|
target: Ref<Record<string, string>[]>,
|
||||||
|
index: number,
|
||||||
|
): boolean {
|
||||||
|
const response = (error as { response?: { status?: number, _data?: unknown } })?.response
|
||||||
|
const mapped = response?.status === 422 ? mapViolationsToRecord(response._data) : {}
|
||||||
|
if (Object.keys(mapped).length > 0) {
|
||||||
|
target.value[index] = mapped
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Soumet TOUS les blocs d'une collection (contacts / adresses / RIB) en
|
||||||
|
* collectant les erreurs par index : on n'arrete PAS au premier bloc en echec
|
||||||
|
* (decision ERP-110 / ERP-101). Reinitialise le tableau d'erreurs cible, tente
|
||||||
|
* chaque ligne via `saveRow`, mappe les 422 inline (mapRowError) ou delegue le
|
||||||
|
* fallback a `onUnmappedError`. `shouldSkip` permet d'ignorer les blocs vides
|
||||||
|
* (non remplis). Retourne true si au moins un bloc a echoue (le caller ne valide
|
||||||
|
* alors pas l'onglet et n'affiche pas de toast succes).
|
||||||
|
*/
|
||||||
|
async function submitRows<T>(
|
||||||
|
rows: T[],
|
||||||
|
target: Ref<Record<string, string>[]>,
|
||||||
|
saveRow: (row: T, index: number) => Promise<void>,
|
||||||
|
onUnmappedError: (error: unknown, index: number) => void,
|
||||||
|
shouldSkip?: (row: T, index: number) => boolean,
|
||||||
|
): Promise<boolean> {
|
||||||
|
target.value = []
|
||||||
|
let hasError = false
|
||||||
|
for (let index = 0; index < rows.length; index++) {
|
||||||
|
// L'index reste borne par rows.length : la ligne existe forcement.
|
||||||
|
const row = rows[index] as T
|
||||||
|
if (shouldSkip?.(row, index)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await saveRow(row, index)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (!mapRowError(error, target, index)) {
|
||||||
|
onUnmappedError(error, index)
|
||||||
|
}
|
||||||
|
hasError = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasError
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
mainErrors,
|
||||||
|
informationErrors,
|
||||||
|
accountingErrors,
|
||||||
|
contactErrors,
|
||||||
|
addressErrors,
|
||||||
|
ribErrors,
|
||||||
|
mapRowError,
|
||||||
|
submitRows,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,6 +45,7 @@ interface CategoryMember extends HydraMember {
|
|||||||
|
|
||||||
interface SiteMember extends HydraMember {
|
interface SiteMember extends HydraMember {
|
||||||
name: string
|
name: string
|
||||||
|
postalCode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ReferentialMember extends HydraMember {
|
interface ReferentialMember extends HydraMember {
|
||||||
@@ -85,37 +86,34 @@ export function useClientReferentials() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Charge en parallele les referentiels communs (hors distributeurs/courtiers,
|
* Charge en parallele les referentiels communs (hors distributeurs/courtiers,
|
||||||
* charges a la demande selon la relation choisie). Les selects compta ne sont
|
* charges a la demande selon la relation choisie).
|
||||||
* pertinents que si l'utilisateur a acces a l'onglet, mais le cout est
|
|
||||||
* negligeable et simplifie l'orchestration.
|
|
||||||
*
|
*
|
||||||
* Resilience (ERP-102) : chaque referentiel est charge et affecte
|
* Chargement RESILIENT (Promise.allSettled) : chaque referentiel est isole.
|
||||||
* independamment via `Promise.allSettled`. Si UN endpoint echoue (ex: 403,
|
* Necessaire pour les roles metier qui n'ont pas toutes les permissions de
|
||||||
* coupure reseau), seul SON select reste vide — les autres sont peuples
|
* lecture — ex. Compta a `commercial.clients.view` (donc /tva_modes, /banks...
|
||||||
* normalement. Un `Promise.all` rejetterait au premier echec et viderait la
|
* accessibles) mais PAS `catalog.categories.view` ni `sites.view` : sans
|
||||||
* TOTALITE des selects, rendant le formulaire de creation client inutilisable.
|
* isolation, le 403 sur /categories ferait echouer tout le bloc et viderait
|
||||||
* `loadCommon` ne rejette donc jamais.
|
* les selects comptables dont Compta a besoin sur l'ecran de modification.
|
||||||
|
* Un referentiel en echec reste simplement vide (l'ecran d'edition complete
|
||||||
|
* l'affichage des valeurs courantes depuis l'embed du detail client).
|
||||||
*/
|
*/
|
||||||
async function loadCommon(): Promise<void> {
|
async function loadCommon(): Promise<void> {
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
fetchAll<CategoryMember>('/categories').then(cats => {
|
fetchAll<CategoryMember>('/categories')
|
||||||
categories.value = cats.map(c => ({ value: c['@id'], label: c.name, code: c.code }))
|
.then((cats) => { categories.value = cats.map(c => ({ value: c['@id'], label: c.name, code: c.code })) }),
|
||||||
}),
|
fetchAll<SiteMember>('/sites')
|
||||||
fetchAll<SiteMember>('/sites').then(sitesList => {
|
// Libelle = numero de departement (2 premiers chiffres du code
|
||||||
sites.value = sitesList.map(s => ({ value: s['@id'], label: s.name }))
|
// postal du site), ex: 86100 -> « 86 ». Le code postal est deja
|
||||||
}),
|
// expose par /sites (groupe site:read) — aucune colonne a ajouter.
|
||||||
fetchAll<ReferentialMember>('/tva_modes').then(tva => {
|
.then((sitesList) => { sites.value = sitesList.map(s => ({ value: s['@id'], label: (s.postalCode ?? '').slice(0, 2) })) }),
|
||||||
tvaModes.value = tva.map(t => ({ value: t['@id'], label: t.label }))
|
fetchAll<ReferentialMember>('/tva_modes')
|
||||||
}),
|
.then((tva) => { tvaModes.value = tva.map(t => ({ value: t['@id'], label: t.label })) }),
|
||||||
fetchAll<ReferentialMember>('/payment_delays').then(delays => {
|
fetchAll<ReferentialMember>('/payment_delays')
|
||||||
paymentDelays.value = delays.map(d => ({ value: d['@id'], label: d.label }))
|
.then((delays) => { paymentDelays.value = delays.map(d => ({ value: d['@id'], label: d.label })) }),
|
||||||
}),
|
fetchAll<ReferentialMember>('/payment_types')
|
||||||
fetchAll<ReferentialMember>('/payment_types').then(types => {
|
.then((types) => { paymentTypes.value = types.map(t => ({ value: t['@id'], label: t.label, code: t.code })) }),
|
||||||
paymentTypes.value = types.map(t => ({ value: t['@id'], label: t.label, code: t.code }))
|
fetchAll<ReferentialMember>('/banks')
|
||||||
}),
|
.then((banksList) => { banks.value = banksList.map(b => ({ value: b['@id'], label: b.label })) }),
|
||||||
fetchAll<ReferentialMember>('/banks').then(banksList => {
|
|
||||||
banks.value = banksList.map(b => ({ value: b['@id'], label: b.label }))
|
|
||||||
}),
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,999 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<!-- En-tete : retour repertoire + nom du client. -->
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<MalioButtonIcon
|
||||||
|
icon="mdi:arrow-left-bold"
|
||||||
|
icon-size="24"
|
||||||
|
variant="ghost"
|
||||||
|
v-bind="{ ariaLabel: t('commercial.clients.edit.back') }"
|
||||||
|
@click="goBack"
|
||||||
|
/>
|
||||||
|
<h1 class="text-[32px] font-bold text-m-primary">{{ headerTitle }}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Etats de chargement / introuvable. -->
|
||||||
|
<p v-if="loading" class="mt-12 text-center text-black/60">{{ t('commercial.clients.edit.loading') }}</p>
|
||||||
|
<p v-else-if="error" class="mt-12 text-center text-m-danger">{{ t('commercial.clients.edit.notFound') }}</p>
|
||||||
|
|
||||||
|
<template v-else-if="client">
|
||||||
|
<!-- ── Bloc principal (pre-rempli, editable si `manage`) ──────────────
|
||||||
|
Decision Tristan : on conserve le bloc principal en modification
|
||||||
|
(« pour ne pas tout casser »), edite via son propre PATCH scope
|
||||||
|
sur le groupe client:write:main. Readonly pour les roles sans
|
||||||
|
`manage` (ex. Compta). -->
|
||||||
|
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
|
<MalioInputText
|
||||||
|
v-model="main.companyName"
|
||||||
|
:label="t('commercial.clients.form.main.companyName')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="mainErrors.errors.companyName"
|
||||||
|
/>
|
||||||
|
<MalioSelectCheckbox
|
||||||
|
:model-value="main.categoryIris"
|
||||||
|
:options="mainCategoryOptions"
|
||||||
|
:label="t('commercial.clients.form.main.categories')"
|
||||||
|
:display-tag="true"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="mainErrors.errors.categories"
|
||||||
|
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="main.relationType"
|
||||||
|
:options="relationOptions"
|
||||||
|
:label="t('commercial.clients.form.main.relation')"
|
||||||
|
:empty-option-label="t('commercial.clients.form.main.relationNone')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
@update:model-value="onRelationChange"
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
v-if="main.relationType === 'courtier'"
|
||||||
|
:model-value="main.brokerIri"
|
||||||
|
:options="brokerOptions"
|
||||||
|
:label="t('commercial.clients.form.main.brokerName')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="mainErrors.errors.broker"
|
||||||
|
@update:model-value="(v: string | number | null) => main.brokerIri = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
v-if="main.relationType === 'distributeur'"
|
||||||
|
:model-value="main.distributorIri"
|
||||||
|
:options="distributorOptions"
|
||||||
|
:label="t('commercial.clients.form.main.distributorName')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="mainErrors.errors.distributor"
|
||||||
|
@update:model-value="(v: string | number | null) => main.distributorIri = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
<MalioCheckbox
|
||||||
|
v-model="main.triageService"
|
||||||
|
:label="t('commercial.clients.form.main.triageService')"
|
||||||
|
group-class="self-center"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!businessReadonly" class="mt-12 flex justify-center">
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('commercial.clients.edit.save')"
|
||||||
|
:disabled="!isMainValid || mainSubmitting"
|
||||||
|
@click="submitMain"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Onglets : navigation LIBRE, edition independante par onglet ──── -->
|
||||||
|
<MalioTabList v-model="activeTab" :tabs="tabs" :max-visible-tabs="5" :max-width="1100" class="mt-[60px]">
|
||||||
|
<!-- Onglet Information -->
|
||||||
|
<template #information>
|
||||||
|
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
|
<MalioInputTextArea
|
||||||
|
v-model="information.description"
|
||||||
|
:label="t('commercial.clients.form.information.description')"
|
||||||
|
resize="none"
|
||||||
|
group-class="row-span-2 pt-1"
|
||||||
|
text-input="h-full text-lg"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="informationErrors.errors.description"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="information.competitors"
|
||||||
|
:label="t('commercial.clients.form.information.competitors')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="informationErrors.errors.competitors"
|
||||||
|
/>
|
||||||
|
<MalioDate
|
||||||
|
v-model="information.foundedAt"
|
||||||
|
:label="t('commercial.clients.form.information.foundedAt')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="informationErrors.errors.foundedAt"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="information.employeesCount"
|
||||||
|
:label="t('commercial.clients.form.information.employeesCount')"
|
||||||
|
:mask="EMPLOYEES_MASK"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="informationErrors.errors.employeesCount"
|
||||||
|
/>
|
||||||
|
<MalioInputAmount
|
||||||
|
v-model="information.revenueAmount"
|
||||||
|
:label="t('commercial.clients.form.information.revenueAmount')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="informationErrors.errors.revenueAmount"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="information.directorName"
|
||||||
|
:label="t('commercial.clients.form.information.directorName')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="informationErrors.errors.directorName"
|
||||||
|
/>
|
||||||
|
<MalioInputAmount
|
||||||
|
v-model="information.profitAmount"
|
||||||
|
:label="t('commercial.clients.form.information.profitAmount')"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:error="informationErrors.errors.profitAmount"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div v-if="!businessReadonly" class="mt-12 flex justify-center">
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('commercial.clients.edit.save')"
|
||||||
|
:disabled="tabSubmitting"
|
||||||
|
@click="submitInformation"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglet Contact -->
|
||||||
|
<template #contact>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<ClientContactBlock
|
||||||
|
v-for="(contact, index) in contacts"
|
||||||
|
:key="contact.id ?? `new-${index}`"
|
||||||
|
:model-value="contact"
|
||||||
|
:title="t('commercial.clients.form.contact.title', { n: index + 1 })"
|
||||||
|
:removable="contacts.length > 1"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:errors="contactErrors[index]"
|
||||||
|
@update:model-value="(v) => contacts[index] = v"
|
||||||
|
@remove="askRemoveContact(index)"
|
||||||
|
/>
|
||||||
|
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
icon-name="mdi:add-bold"
|
||||||
|
icon-position="left"
|
||||||
|
:label="t('commercial.clients.form.contact.add')"
|
||||||
|
:disabled="!canAddContact"
|
||||||
|
@click="addContact"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('commercial.clients.edit.save')"
|
||||||
|
:disabled="!canValidateContacts || tabSubmitting"
|
||||||
|
@click="submitContacts"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglet Adresse -->
|
||||||
|
<template #address>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<ClientAddressBlock
|
||||||
|
v-for="(address, index) in addresses"
|
||||||
|
:key="address.id ?? `new-${index}`"
|
||||||
|
:model-value="address"
|
||||||
|
:title="t('commercial.clients.form.address.title', { n: index + 1 })"
|
||||||
|
:category-options="addressCategoryOptions"
|
||||||
|
:site-options="siteOptions"
|
||||||
|
:contact-options="contactOptions"
|
||||||
|
:country-options="countryOptions"
|
||||||
|
:removable="addresses.length > 1"
|
||||||
|
:readonly="businessReadonly"
|
||||||
|
:errors="addressErrors[index]"
|
||||||
|
@update:model-value="(v) => addresses[index] = v"
|
||||||
|
@remove="askRemoveAddress(index)"
|
||||||
|
@degraded="onAddressDegraded"
|
||||||
|
/>
|
||||||
|
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
icon-name="mdi:add-bold"
|
||||||
|
icon-position="left"
|
||||||
|
:label="t('commercial.clients.form.address.add')"
|
||||||
|
@click="addAddress"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('commercial.clients.edit.save')"
|
||||||
|
:disabled="!canValidateAddresses || tabSubmitting"
|
||||||
|
@click="submitAddresses"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglet Comptabilite (present uniquement si accounting.view ;
|
||||||
|
editable uniquement si accounting.manage). -->
|
||||||
|
<template v-if="canAccountingView" #accounting>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
|
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
|
<MalioInputText
|
||||||
|
v-model="accounting.siren"
|
||||||
|
:label="t('commercial.clients.form.accounting.siren')"
|
||||||
|
:mask="SIREN_MASK"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.siren"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="accounting.accountNumber"
|
||||||
|
:label="t('commercial.clients.form.accounting.accountNumber')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.accountNumber"
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="accounting.tvaModeIri"
|
||||||
|
:options="tvaModeOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.tvaMode')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.tvaMode"
|
||||||
|
@update:model-value="(v: string | number | null) => accounting.tvaModeIri = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="accounting.nTva"
|
||||||
|
:label="t('commercial.clients.form.accounting.nTva')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.nTva"
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="accounting.paymentDelayIri"
|
||||||
|
:options="paymentDelayOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.paymentDelay')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.paymentDelay"
|
||||||
|
@update:model-value="(v: string | number | null) => accounting.paymentDelayIri = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="accounting.paymentTypeIri"
|
||||||
|
:options="paymentTypeOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.paymentType')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.paymentType"
|
||||||
|
@update:model-value="onPaymentTypeChange"
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
v-if="isBankRequired"
|
||||||
|
:model-value="accounting.bankIri"
|
||||||
|
:options="bankOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.bank')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.bank"
|
||||||
|
@update:model-value="(v: string | number | null) => accounting.bankIri = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Blocs RIB (0..n) — obligatoires si type de reglement = LCR (RG-1.13). -->
|
||||||
|
<div
|
||||||
|
v-for="(rib, index) in ribs"
|
||||||
|
:key="rib.id ?? `new-${index}`"
|
||||||
|
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||||
|
>
|
||||||
|
<MalioButtonIcon
|
||||||
|
v-if="!accountingReadonly"
|
||||||
|
icon="mdi:delete-outline"
|
||||||
|
variant="ghost"
|
||||||
|
button-class="absolute top-3 right-3"
|
||||||
|
v-bind="{ ariaLabel: t('commercial.clients.form.accounting.removeRib') }"
|
||||||
|
@click="askRemoveRib(index)"
|
||||||
|
/>
|
||||||
|
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
|
<MalioInputText
|
||||||
|
v-model="rib.label"
|
||||||
|
:label="t('commercial.clients.form.accounting.ribLabel')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
:required="isRibRequired"
|
||||||
|
:error="ribErrors[index]?.label"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="rib.bic"
|
||||||
|
:label="t('commercial.clients.form.accounting.ribBic')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
:required="isRibRequired"
|
||||||
|
:error="ribErrors[index]?.bic"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-model="rib.iban"
|
||||||
|
:label="t('commercial.clients.form.accounting.ribIban')"
|
||||||
|
:readonly="accountingReadonly"
|
||||||
|
:required="isRibRequired"
|
||||||
|
:error="ribErrors[index]?.iban"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
icon-name="mdi:add-bold"
|
||||||
|
icon-position="left"
|
||||||
|
:label="t('commercial.clients.form.accounting.addRib')"
|
||||||
|
@click="addRib"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('commercial.clients.edit.save')"
|
||||||
|
:disabled="!canValidateAccounting || tabSubmitting"
|
||||||
|
@click="submitAccounting"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
||||||
|
<template #transport><ComingSoonPlaceholder /></template>
|
||||||
|
<template #statistics><ComingSoonPlaceholder /></template>
|
||||||
|
<template #reports><ComingSoonPlaceholder /></template>
|
||||||
|
<template #exchanges><ComingSoonPlaceholder /></template>
|
||||||
|
</MalioTabList>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation generique (suppression contact / adresse / RIB). -->
|
||||||
|
<MalioModal v-model="confirmModal.open" modal-class="max-w-md">
|
||||||
|
<template #header>
|
||||||
|
<h2 class="text-[24px] font-bold">{{ t('commercial.clients.form.confirmDelete.title') }}</h2>
|
||||||
|
</template>
|
||||||
|
<p>{{ confirmModal.message }}</p>
|
||||||
|
<template #footer>
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('commercial.clients.form.confirmDelete.cancel')"
|
||||||
|
@click="confirmModal.open = false"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="danger"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('commercial.clients.form.confirmDelete.confirm')"
|
||||||
|
@click="runConfirm"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</MalioModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
|
import { useClient } from '~/modules/commercial/composables/useClient'
|
||||||
|
import { useClientReferentials, type CategoryOption, type RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
||||||
|
import { useClientFormErrors } from '~/modules/commercial/composables/useClientFormErrors'
|
||||||
|
import {
|
||||||
|
canEditClient,
|
||||||
|
categoryOptionsOf,
|
||||||
|
referentialOptionOf,
|
||||||
|
siteOptionsOf,
|
||||||
|
mapContactToDraft,
|
||||||
|
mapAddressToDraft,
|
||||||
|
mapRibToDraft,
|
||||||
|
type ClientDetail,
|
||||||
|
} from '~/modules/commercial/utils/clientConsultation'
|
||||||
|
import {
|
||||||
|
buildAccountingPayload,
|
||||||
|
buildAddressPayload,
|
||||||
|
buildContactPayload,
|
||||||
|
buildInformationPayload,
|
||||||
|
buildMainPayload,
|
||||||
|
buildRibPayload,
|
||||||
|
mapAccountingFormDraft,
|
||||||
|
mapInformationDraft,
|
||||||
|
mapMainDraft,
|
||||||
|
resolveTabEditability,
|
||||||
|
type AccountingFormDraft,
|
||||||
|
type ClientEditAbilities,
|
||||||
|
type InformationFormDraft,
|
||||||
|
type MainFormDraft,
|
||||||
|
} from '~/modules/commercial/utils/clientEdit'
|
||||||
|
import {
|
||||||
|
addressTypeFromFlags,
|
||||||
|
buildClientFormTabKeys,
|
||||||
|
hasAllRequiredAccountingFields,
|
||||||
|
hasAtLeastOneValidContact,
|
||||||
|
isBankRequiredForPaymentType,
|
||||||
|
isBillingEmailRequired,
|
||||||
|
isContactBlank,
|
||||||
|
isContactNamed,
|
||||||
|
isRibBlank,
|
||||||
|
isRibRequiredForPaymentType,
|
||||||
|
} from '~/modules/commercial/utils/clientFormRules'
|
||||||
|
import {
|
||||||
|
emptyAddress,
|
||||||
|
emptyContact,
|
||||||
|
emptyRib,
|
||||||
|
type AddressFormDraft,
|
||||||
|
type ContactFormDraft,
|
||||||
|
type RibFormDraft,
|
||||||
|
} from '~/modules/commercial/types/clientForm'
|
||||||
|
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||||
|
|
||||||
|
// Masques de saisie (la normalisation finale reste serveur).
|
||||||
|
const SIREN_MASK = '#########'
|
||||||
|
const EMPLOYEES_MASK = '#######'
|
||||||
|
|
||||||
|
// Codes de categorie interdits sur une adresse (RG-1.29, ERP-78).
|
||||||
|
const FORBIDDEN_ADDRESS_CATEGORY_CODES = ['DISTRIBUTEUR', 'COURTIER']
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const api = useApi()
|
||||||
|
const toast = useToast()
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
const { can, canAny } = usePermissions()
|
||||||
|
|
||||||
|
// Gating de la route : l'edition exige de pouvoir editer au moins un onglet
|
||||||
|
// (`manage` OU `accounting.manage`). Usine et roles en lecture seule sont
|
||||||
|
// rediriges vers le repertoire (lui-meme protege).
|
||||||
|
if (!canEditClient(canAny)) {
|
||||||
|
await navigateTo('/clients')
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientId = route.params.id as string
|
||||||
|
|
||||||
|
const { client, loading, error, load } = useClient(clientId)
|
||||||
|
const referentials = useClientReferentials()
|
||||||
|
|
||||||
|
// ── Permissions / editabilite par zone (option 1 ERP-74) ────────────────────
|
||||||
|
const abilities = computed<ClientEditAbilities>(() => ({
|
||||||
|
canManage: can('commercial.clients.manage'),
|
||||||
|
canAccountingView: can('commercial.clients.accounting.view'),
|
||||||
|
canAccountingManage: can('commercial.clients.accounting.manage'),
|
||||||
|
}))
|
||||||
|
const editability = computed(() => resolveTabEditability(abilities.value))
|
||||||
|
// Bloc principal + onglets Information / Contact / Adresse.
|
||||||
|
const businessReadonly = computed(() => !editability.value.businessEditable)
|
||||||
|
const canAccountingView = computed(() => editability.value.accountingVisible)
|
||||||
|
const accountingReadonly = computed(() => !editability.value.accountingEditable)
|
||||||
|
|
||||||
|
const headerTitle = computed(() => client.value?.companyName ?? t('commercial.clients.edit.title'))
|
||||||
|
|
||||||
|
// ── Brouillons editables (pre-remplis depuis le detail) ─────────────────────
|
||||||
|
const main = reactive<MainFormDraft>(mapMainDraft({} as ClientDetail))
|
||||||
|
const information = reactive<InformationFormDraft>(mapInformationDraft({} as ClientDetail))
|
||||||
|
const accounting = reactive<AccountingFormDraft>(mapAccountingFormDraft({} as ClientDetail))
|
||||||
|
const contacts = ref<ContactFormDraft[]>([])
|
||||||
|
const addresses = ref<AddressFormDraft[]>([])
|
||||||
|
const ribs = ref<RibFormDraft[]>([])
|
||||||
|
|
||||||
|
// Ids des sous-ressources existantes supprimees (DELETE differe au « Valider »).
|
||||||
|
const removedContactIds = ref<number[]>([])
|
||||||
|
const removedAddressIds = ref<number[]>([])
|
||||||
|
const removedRibIds = ref<number[]>([])
|
||||||
|
|
||||||
|
const mainSubmitting = ref(false)
|
||||||
|
const tabSubmitting = ref(false)
|
||||||
|
const addressDegradedNotified = ref(false)
|
||||||
|
|
||||||
|
/** Recopie le detail charge dans les brouillons editables. */
|
||||||
|
function hydrate(detail: ClientDetail): void {
|
||||||
|
Object.assign(main, mapMainDraft(detail))
|
||||||
|
Object.assign(information, mapInformationDraft(detail))
|
||||||
|
Object.assign(accounting, mapAccountingFormDraft(detail))
|
||||||
|
contacts.value = (detail.contacts ?? []).map(mapContactToDraft)
|
||||||
|
addresses.value = (detail.addresses ?? []).map(mapAddressToDraft)
|
||||||
|
ribs.value = (detail.ribs ?? []).map(mapRibToDraft)
|
||||||
|
// Chaque bloc reste visible meme vide : si une collection est vide, on amorce
|
||||||
|
// un bloc vierge (non persiste tant qu'incomplet — cf. submit*/canValidate*).
|
||||||
|
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
||||||
|
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
||||||
|
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||||
|
// Charge les listes distributeur / courtier si une relation est deja posee.
|
||||||
|
if (main.relationType === 'distributeur') referentials.loadDistributors().catch(() => {})
|
||||||
|
if (main.relationType === 'courtier') referentials.loadBrokers().catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Options de selects (referentiels UNION valeurs courantes de l'embed) ─────
|
||||||
|
// L'union garantit que les valeurs deja posees s'affichent meme quand le
|
||||||
|
// referentiel complet n'est pas chargeable (roles metier sans
|
||||||
|
// catalog.categories.view / sites.view → 403, cf. matrice § 2.7).
|
||||||
|
function mergeOptions<T extends { value: string }>(primary: T[], extra: T[]): T[] {
|
||||||
|
const seen = new Set(primary.map(o => o.value))
|
||||||
|
return [...primary, ...extra.filter(o => !seen.has(o.value))]
|
||||||
|
}
|
||||||
|
|
||||||
|
const embedCategoryOptions = computed<CategoryOption[]>(() => {
|
||||||
|
const fromClient = categoryOptionsOf(client.value?.categories)
|
||||||
|
const fromAddresses = (client.value?.addresses ?? []).flatMap(a => categoryOptionsOf(a.categories))
|
||||||
|
return mergeOptions(fromClient, fromAddresses)
|
||||||
|
})
|
||||||
|
const mainCategoryOptions = computed(() => mergeOptions(referentials.categories.value, embedCategoryOptions.value))
|
||||||
|
// Categories autorisees sur une adresse : toutes SAUF DISTRIBUTEUR/COURTIER (RG-1.29).
|
||||||
|
const addressCategoryOptions = computed(() =>
|
||||||
|
mainCategoryOptions.value.filter(c => !FORBIDDEN_ADDRESS_CATEGORY_CODES.includes(c.code)),
|
||||||
|
)
|
||||||
|
|
||||||
|
const embedSiteOptions = computed<RefOption[]>(() =>
|
||||||
|
mergeOptions([], (client.value?.addresses ?? []).flatMap(a => siteOptionsOf(a.sites))),
|
||||||
|
)
|
||||||
|
const siteOptions = computed(() => mergeOptions(referentials.sites.value, embedSiteOptions.value))
|
||||||
|
|
||||||
|
// Contacts deja persistes (iri non null), rattachables a une adresse (M2M).
|
||||||
|
const contactOptions = computed<RefOption[]>(() =>
|
||||||
|
contacts.value
|
||||||
|
.filter(c => c.iri !== null)
|
||||||
|
.map(c => ({
|
||||||
|
value: c.iri as string,
|
||||||
|
label: [c.firstName, c.lastName].filter(Boolean).join(' ') || (c.email ?? ''),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
const countryOptions: RefOption[] = [
|
||||||
|
{ value: 'France', label: 'France' },
|
||||||
|
{ value: 'Espagne', label: 'Espagne' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const relationOptions = computed<RefOption[]>(() => [
|
||||||
|
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
||||||
|
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||||
|
])
|
||||||
|
|
||||||
|
// Distributeur / courtier : referentiel charge a la demande UNION valeur courante.
|
||||||
|
const currentDistributorOption = computed<RefOption[]>(() => {
|
||||||
|
const d = client.value?.distributor
|
||||||
|
return d && typeof d === 'object' ? [{ value: d['@id'], label: d.companyName ?? d['@id'] }] : []
|
||||||
|
})
|
||||||
|
const currentBrokerOption = computed<RefOption[]>(() => {
|
||||||
|
const b = client.value?.broker
|
||||||
|
return b && typeof b === 'object' ? [{ value: b['@id'], label: b.companyName ?? b['@id'] }] : []
|
||||||
|
})
|
||||||
|
const distributorOptions = computed(() => mergeOptions(referentials.distributors.value, currentDistributorOption.value))
|
||||||
|
const brokerOptions = computed(() => mergeOptions(referentials.brokers.value, currentBrokerOption.value))
|
||||||
|
|
||||||
|
// Selects comptables : referentiel UNION valeur courante de l'embed (libelle).
|
||||||
|
const tvaModeOptions = computed(() => mergeOptions(referentials.tvaModes.value, referentialOptionOf(client.value?.tvaMode)))
|
||||||
|
const paymentDelayOptions = computed(() => mergeOptions(referentials.paymentDelays.value, referentialOptionOf(client.value?.paymentDelay)))
|
||||||
|
const paymentTypeOptions = computed(() => mergeOptions(
|
||||||
|
referentials.paymentTypes.value.map(p => ({ value: p.value, label: p.label })),
|
||||||
|
referentialOptionOf(client.value?.paymentType),
|
||||||
|
))
|
||||||
|
const bankOptions = computed(() => mergeOptions(referentials.banks.value, referentialOptionOf(client.value?.bank)))
|
||||||
|
|
||||||
|
// ── Onglets : navigation libre (4 actifs + 4 coquilles, comme la consultation) ─
|
||||||
|
const tabKeys = computed(() => buildClientFormTabKeys(canAccountingView.value, { includeEditOnlyTabs: true }))
|
||||||
|
|
||||||
|
const TAB_ICONS: Record<string, string> = {
|
||||||
|
information: 'mdi:account-outline',
|
||||||
|
contact: 'mdi:account-box-plus-outline',
|
||||||
|
address: 'mdi:map-marker-outline',
|
||||||
|
transport: 'mdi:truck-delivery-outline',
|
||||||
|
accounting: 'mdi:bank-circle-outline',
|
||||||
|
statistics: 'mdi:finance',
|
||||||
|
reports: 'mdi:file-document-edit-outline',
|
||||||
|
exchanges: 'mdi:account-group-outline',
|
||||||
|
}
|
||||||
|
|
||||||
|
const tabs = computed(() => tabKeys.value.map(key => ({
|
||||||
|
key,
|
||||||
|
label: t(`commercial.clients.tab.${key}`),
|
||||||
|
icon: TAB_ICONS[key],
|
||||||
|
})))
|
||||||
|
|
||||||
|
const activeTab = ref('information')
|
||||||
|
|
||||||
|
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||||
|
function goBack(): void {
|
||||||
|
router.push(`/clients/${clientId}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message d'erreur a afficher : violation 422 / detail renvoye par le serveur,
|
||||||
|
* sinon un libelle generique. Le 409 d'unicite de nom (bloc principal) est
|
||||||
|
* traduit explicitement par l'appelant.
|
||||||
|
*/
|
||||||
|
function apiErrorMessage(e: unknown): string {
|
||||||
|
const data = (e as { data?: unknown })?.data
|
||||||
|
return extractApiErrorMessage(data) || t('commercial.clients.toast.error')
|
||||||
|
}
|
||||||
|
|
||||||
|
function showError(e: unknown, opts: { duplicateCompany?: boolean } = {}): void {
|
||||||
|
const status = (e as { response?: { status?: number } })?.response?.status
|
||||||
|
toast.error({
|
||||||
|
title: t('commercial.clients.toast.error'),
|
||||||
|
message: opts.duplicateCompany && status === 409
|
||||||
|
? t('commercial.clients.form.duplicateCompany')
|
||||||
|
: apiErrorMessage(e),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Erreurs de validation par champ (ERP-101) ───────────────────────────────
|
||||||
|
// Etat d'erreurs factorise avec l'ecran de creation (cf. useClientFormErrors) :
|
||||||
|
// un `useFormErrors` par groupe scalaire + un tableau d'erreurs par ligne pour
|
||||||
|
// chaque collection (aligne sur l'index visible). `mapRowError` mappe une 422
|
||||||
|
// inline et retourne true ; il ne toaste pas, le fallback `showError` reste
|
||||||
|
// local a l'edition (cf. catch des submits de collection).
|
||||||
|
const {
|
||||||
|
mainErrors,
|
||||||
|
informationErrors,
|
||||||
|
accountingErrors,
|
||||||
|
contactErrors,
|
||||||
|
addressErrors,
|
||||||
|
ribErrors,
|
||||||
|
submitRows,
|
||||||
|
} = useClientFormErrors()
|
||||||
|
|
||||||
|
// ── Bloc principal ───────────────────────────────────────────────────────────
|
||||||
|
const isMainValid = computed(() => {
|
||||||
|
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
||||||
|
const relationValid
|
||||||
|
= main.relationType === null
|
||||||
|
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
||||||
|
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
||||||
|
return filled(main.companyName)
|
||||||
|
&& main.categoryIris.length >= 1
|
||||||
|
&& relationValid
|
||||||
|
})
|
||||||
|
|
||||||
|
async function onRelationChange(value: string | number | null): Promise<void> {
|
||||||
|
const relation = (value === null || value === '') ? null : (String(value) as 'distributeur' | 'courtier')
|
||||||
|
main.relationType = relation
|
||||||
|
// Une seule FK remplie a la fois (RG-1.03).
|
||||||
|
if (relation !== 'distributeur') main.distributorIri = null
|
||||||
|
if (relation !== 'courtier') main.brokerIri = null
|
||||||
|
|
||||||
|
if (relation === 'distributeur') await referentials.loadDistributors().catch(() => {})
|
||||||
|
if (relation === 'courtier') await referentials.loadBrokers().catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PATCH /clients/{id} — groupe client:write:main UNIQUEMENT (mode strict). */
|
||||||
|
async function submitMain(): Promise<void> {
|
||||||
|
if (businessReadonly.value || !isMainValid.value || mainSubmitting.value) return
|
||||||
|
mainSubmitting.value = true
|
||||||
|
mainErrors.clearErrors()
|
||||||
|
try {
|
||||||
|
const updated = await api.patch<ClientDetail>(`/clients/${clientId}`, buildMainPayload(main), {
|
||||||
|
headers: { Accept: 'application/ld+json' },
|
||||||
|
toast: false,
|
||||||
|
})
|
||||||
|
// Reaffiche les valeurs normalisees renvoyees par le serveur.
|
||||||
|
Object.assign(main, mapMainDraft(updated))
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// 409 = doublon nom de societe → erreur inline + toast ; 422 → mapping
|
||||||
|
// inline par champ ; autre → toast de fallback. Cf. ERP-101.
|
||||||
|
const status = (e as { response?: { status?: number } })?.response?.status
|
||||||
|
if (status === 409) {
|
||||||
|
const message = t('commercial.clients.form.duplicateCompany')
|
||||||
|
mainErrors.setError('companyName', message)
|
||||||
|
toast.error({ title: t('commercial.clients.toast.error'), message })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mainErrors.handleApiError(e, { fallbackMessage: t('commercial.clients.toast.error') })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
mainSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Onglet Information ───────────────────────────────────────────────────────
|
||||||
|
/** PATCH /clients/{id} — groupe client:write:information UNIQUEMENT. */
|
||||||
|
async function submitInformation(): Promise<void> {
|
||||||
|
if (businessReadonly.value || tabSubmitting.value) return
|
||||||
|
tabSubmitting.value = true
|
||||||
|
informationErrors.clearErrors()
|
||||||
|
try {
|
||||||
|
await api.patch(`/clients/${clientId}`, buildInformationPayload(information), { toast: false })
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
informationErrors.handleApiError(e, { fallbackMessage: t('commercial.clients.toast.error') })
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tabSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Onglet Contact ───────────────────────────────────────────────────────────
|
||||||
|
const canAddContact = computed(() => {
|
||||||
|
const last = contacts.value[contacts.value.length - 1]
|
||||||
|
return last === undefined || isContactNamed(last)
|
||||||
|
})
|
||||||
|
// RG-1.14 : au moins un contact nomme pour finaliser l'onglet.
|
||||||
|
const canValidateContacts = computed(() => hasAtLeastOneValidContact(contacts.value))
|
||||||
|
|
||||||
|
function addContact(): void {
|
||||||
|
if (canAddContact.value) contacts.value.push(emptyContact())
|
||||||
|
}
|
||||||
|
|
||||||
|
function askRemoveContact(index: number): void {
|
||||||
|
askConfirm(t('commercial.clients.form.confirmDelete.contact'), () => {
|
||||||
|
const removed = contacts.value[index]
|
||||||
|
if (removed?.id != null) removedContactIds.value.push(removed.id)
|
||||||
|
contacts.value.splice(index, 1)
|
||||||
|
contactErrors.value.splice(index, 1)
|
||||||
|
// Garde au moins un bloc visible (cf. amorce a l'hydratation).
|
||||||
|
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valide l'onglet Contact : DELETE des contacts retires (existants), puis
|
||||||
|
* POST/PATCH des blocs restants sur la sous-ressource. Strictement scope a la
|
||||||
|
* collection contacts (endpoints client_contact dedies).
|
||||||
|
*/
|
||||||
|
async function submitContacts(): Promise<void> {
|
||||||
|
if (businessReadonly.value || !canValidateContacts.value || tabSubmitting.value) return
|
||||||
|
tabSubmitting.value = true
|
||||||
|
contactErrors.value = []
|
||||||
|
try {
|
||||||
|
for (const id of removedContactIds.value) {
|
||||||
|
await api.delete(`/client_contacts/${id}`, {}, { toast: false })
|
||||||
|
}
|
||||||
|
removedContactIds.value = []
|
||||||
|
|
||||||
|
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
||||||
|
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
||||||
|
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
||||||
|
const hasError = await submitRows(
|
||||||
|
contacts.value,
|
||||||
|
contactErrors,
|
||||||
|
async (contact) => {
|
||||||
|
const body = buildContactPayload(contact)
|
||||||
|
if (contact.id === null) {
|
||||||
|
const created = await api.post<{ '@id'?: string, id: number }>(
|
||||||
|
`/clients/${clientId}/contacts`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
contact.id = created.id
|
||||||
|
contact.iri = created['@id'] ?? null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/client_contacts/${contact.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => showError(error),
|
||||||
|
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||||
|
// bloc existant vide est soumis -> 422 RG-1.05 inline (sinon la modif
|
||||||
|
// serait perdue en silence avec un faux toast de succes).
|
||||||
|
contact => contact.id === null && isContactBlank(contact),
|
||||||
|
)
|
||||||
|
// Tant qu'un bloc reste en erreur : pas de toast succes.
|
||||||
|
if (hasError) return
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
showError(e)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tabSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Onglet Adresse ───────────────────────────────────────────────────────────
|
||||||
|
const canValidateAddresses = computed(() =>
|
||||||
|
addresses.value.length > 0
|
||||||
|
&& addresses.value.every((a) => {
|
||||||
|
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
||||||
|
return addressTypeFromFlags(a) !== null
|
||||||
|
&& a.siteIris.length >= 1
|
||||||
|
&& a.categoryIris.length >= 1
|
||||||
|
&& (!isBillingEmailRequired(a) || filledBillingEmail)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
function addAddress(): void {
|
||||||
|
addresses.value.push(emptyAddress())
|
||||||
|
}
|
||||||
|
|
||||||
|
function askRemoveAddress(index: number): void {
|
||||||
|
askConfirm(t('commercial.clients.form.confirmDelete.address'), () => {
|
||||||
|
const removed = addresses.value[index]
|
||||||
|
if (removed?.id != null) removedAddressIds.value.push(removed.id)
|
||||||
|
addresses.value.splice(index, 1)
|
||||||
|
addressErrors.value.splice(index, 1)
|
||||||
|
// Garde au moins un bloc visible (cf. amorce a l'hydratation).
|
||||||
|
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAddressDegraded(): void {
|
||||||
|
if (addressDegradedNotified.value) return
|
||||||
|
addressDegradedNotified.value = true
|
||||||
|
toast.warning({
|
||||||
|
title: t('commercial.clients.toast.error'),
|
||||||
|
message: t('commercial.clients.form.address.degraded'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Valide l'onglet Adresse : DELETE des adresses retirees puis POST/PATCH. */
|
||||||
|
async function submitAddresses(): Promise<void> {
|
||||||
|
if (businessReadonly.value || !canValidateAddresses.value || tabSubmitting.value) return
|
||||||
|
tabSubmitting.value = true
|
||||||
|
addressErrors.value = []
|
||||||
|
try {
|
||||||
|
for (const id of removedAddressIds.value) {
|
||||||
|
await api.delete(`/client_addresses/${id}`, {}, { toast: false })
|
||||||
|
}
|
||||||
|
removedAddressIds.value = []
|
||||||
|
|
||||||
|
// On tente TOUS les blocs d'adresse (collecte des erreurs par index, ERP-110).
|
||||||
|
const hasError = await submitRows(
|
||||||
|
addresses.value,
|
||||||
|
addressErrors,
|
||||||
|
async (address) => {
|
||||||
|
const body = buildAddressPayload(address, isBillingEmailRequired(address))
|
||||||
|
if (address.id === null) {
|
||||||
|
const created = await api.post<{ id: number }>(
|
||||||
|
`/clients/${clientId}/addresses`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
address.id = created.id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/client_addresses/${address.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => showError(error),
|
||||||
|
)
|
||||||
|
if (hasError) return
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
showError(e)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tabSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Onglet Comptabilite ──────────────────────────────────────────────────────
|
||||||
|
const selectedPaymentTypeCode = computed(() =>
|
||||||
|
referentials.paymentTypes.value.find(p => p.value === accounting.paymentTypeIri)?.code ?? null,
|
||||||
|
)
|
||||||
|
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||||
|
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||||
|
|
||||||
|
function onPaymentTypeChange(value: string | number | null): void {
|
||||||
|
accounting.paymentTypeIri = value === null ? null : String(value)
|
||||||
|
if (!isBankRequired.value) accounting.bankIri = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function ribIsComplete(rib: { label: string | null, bic: string | null, iban: string | null }): boolean {
|
||||||
|
const filled = (v: string | null) => v !== null && v.trim() !== ''
|
||||||
|
return filled(rib.label) && filled(rib.bic) && filled(rib.iban)
|
||||||
|
}
|
||||||
|
|
||||||
|
const canValidateAccounting = computed(() => {
|
||||||
|
if (!hasAllRequiredAccountingFields(accounting)) return false
|
||||||
|
if (isBankRequired.value && accounting.bankIri === null) return false
|
||||||
|
if (isRibRequired.value && !ribs.value.some(ribIsComplete)) return false
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
function addRib(): void {
|
||||||
|
ribs.value.push(emptyRib())
|
||||||
|
}
|
||||||
|
|
||||||
|
function askRemoveRib(index: number): void {
|
||||||
|
askConfirm(t('commercial.clients.form.confirmDelete.rib'), () => {
|
||||||
|
const removed = ribs.value[index]
|
||||||
|
if (removed?.id != null) removedRibIds.value.push(removed.id)
|
||||||
|
ribs.value.splice(index, 1)
|
||||||
|
ribErrors.value.splice(index, 1)
|
||||||
|
// Garde au moins un bloc RIB visible (cf. amorce a l'hydratation).
|
||||||
|
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valide l'onglet Comptabilite : PATCH des scalaires (groupe client:write:accounting,
|
||||||
|
* exige accounting.manage cote back) PUIS DELETE/POST/PATCH des RIB sur la
|
||||||
|
* sous-ressource. Aucun champ main/information dans le payload (mode strict
|
||||||
|
* RG-1.28 : sinon 403 sur tout le payload).
|
||||||
|
*/
|
||||||
|
async function submitAccounting(): Promise<void> {
|
||||||
|
if (accountingReadonly.value || !canValidateAccounting.value || tabSubmitting.value) return
|
||||||
|
tabSubmitting.value = true
|
||||||
|
accountingErrors.clearErrors()
|
||||||
|
// Reset des erreurs RIB des le debut : l'etape 1 (PATCH scalaires) peut
|
||||||
|
// echouer et `return` avant submitRows (qui porte sinon le reset), laissant
|
||||||
|
// des erreurs de RIB obsoletes affichees sous les blocs.
|
||||||
|
ribErrors.value = []
|
||||||
|
try {
|
||||||
|
// 1) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||||
|
try {
|
||||||
|
await api.patch(`/clients/${clientId}`, buildAccountingPayload(accounting, isBankRequired.value), { toast: false })
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
accountingErrors.handleApiError(error, { fallbackMessage: t('commercial.clients.toast.error') })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const id of removedRibIds.value) {
|
||||||
|
await api.delete(`/client_ribs/${id}`, {}, { toast: false })
|
||||||
|
}
|
||||||
|
removedRibIds.value = []
|
||||||
|
|
||||||
|
// 2) POST/PATCH des RIB (erreurs inline par ligne, tous les blocs tentes).
|
||||||
|
// Seuls les blocs RIB TOTALEMENT vides sont ignores : un RIB partiel (ex.
|
||||||
|
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
||||||
|
const ribHasError = await submitRows(
|
||||||
|
ribs.value,
|
||||||
|
ribErrors,
|
||||||
|
async (rib) => {
|
||||||
|
const body = buildRibPayload(rib)
|
||||||
|
if (rib.id === null) {
|
||||||
|
const created = await api.post<{ id: number }>(
|
||||||
|
`/clients/${clientId}/ribs`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
rib.id = created.id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/client_ribs/${rib.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => showError(error),
|
||||||
|
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||||
|
// RIB existant vide est soumis -> 422 NotBlank inline (sinon la modif
|
||||||
|
// serait perdue en silence avec un faux toast de succes).
|
||||||
|
rib => rib.id === null && isRibBlank(rib),
|
||||||
|
)
|
||||||
|
if (ribHasError) return
|
||||||
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
showError(e)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tabSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Modal de confirmation generique ──────────────────────────────────────────
|
||||||
|
const confirmModal = reactive({
|
||||||
|
open: false,
|
||||||
|
message: '',
|
||||||
|
action: null as null | (() => void),
|
||||||
|
})
|
||||||
|
|
||||||
|
function askConfirm(message: string, action: () => void): void {
|
||||||
|
confirmModal.message = message
|
||||||
|
confirmModal.action = action
|
||||||
|
confirmModal.open = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function runConfirm(): void {
|
||||||
|
confirmModal.action?.()
|
||||||
|
confirmModal.action = null
|
||||||
|
confirmModal.open = false
|
||||||
|
}
|
||||||
|
|
||||||
|
useHead({ title: headerTitle })
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// Referentiels en best-effort (echec non bloquant : l'embed alimente les
|
||||||
|
// libelles des valeurs courantes).
|
||||||
|
referentials.loadCommon().catch(() => {})
|
||||||
|
await load()
|
||||||
|
if (client.value) hydrate(client.value)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,471 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<!-- En-tete : retour repertoire + nom du client + actions (Modifier / Archiver|Restaurer). -->
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<MalioButtonIcon
|
||||||
|
icon="mdi:arrow-left-bold"
|
||||||
|
icon-size="24"
|
||||||
|
variant="ghost"
|
||||||
|
v-bind="{ ariaLabel: t('commercial.clients.consultation.back') }"
|
||||||
|
@click="goBack"
|
||||||
|
/>
|
||||||
|
<h1 class="text-[32px] font-bold text-m-primary">{{ headerTitle }}</h1>
|
||||||
|
|
||||||
|
<!-- gap-12 = 48px : meme espacement que Ajouter / Filtres du repertoire. -->
|
||||||
|
<div class="ml-auto flex items-center gap-12">
|
||||||
|
<MalioButton
|
||||||
|
v-if="canEdit"
|
||||||
|
variant="secondary"
|
||||||
|
icon-name="mdi:pencil-outline"
|
||||||
|
icon-position="left"
|
||||||
|
:label="t('commercial.clients.action.edit')"
|
||||||
|
@click="goEdit"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
v-if="showArchive"
|
||||||
|
variant="secondary"
|
||||||
|
icon-name="mdi:archive-arrow-down-outline"
|
||||||
|
icon-position="left"
|
||||||
|
:label="t('commercial.clients.action.archive')"
|
||||||
|
@click="askToggleArchive"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
v-if="showRestore"
|
||||||
|
variant="secondary"
|
||||||
|
icon-name="mdi:archive-arrow-up-outline"
|
||||||
|
icon-position="left"
|
||||||
|
:label="t('commercial.clients.action.restore')"
|
||||||
|
@click="askToggleArchive"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Etats de chargement / introuvable. -->
|
||||||
|
<p v-if="loading" class="mt-12 text-center text-black/60">{{ t('commercial.clients.consultation.loading') }}</p>
|
||||||
|
<p v-else-if="error" class="mt-12 text-center text-m-danger">{{ t('commercial.clients.consultation.notFound') }}</p>
|
||||||
|
|
||||||
|
<template v-else-if="client">
|
||||||
|
<!-- ── Formulaire principal (lecture seule) ──────────────────────── -->
|
||||||
|
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="client.companyName"
|
||||||
|
:label="t('commercial.clients.form.main.companyName')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioSelectCheckbox
|
||||||
|
:model-value="categoryIris"
|
||||||
|
:options="mainCategoryOptions"
|
||||||
|
:label="t('commercial.clients.form.main.categories')"
|
||||||
|
:display-tag="true"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<!-- Relation toujours affichee (vide = « Aucun »), comme en edition. -->
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="relation.type"
|
||||||
|
:options="relationOptions"
|
||||||
|
:label="t('commercial.clients.form.main.relation')"
|
||||||
|
:empty-option-label="t('commercial.clients.form.main.relationNone')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<!-- Nom du distributeur/courtier : conditionnel (libelle type-dependant,
|
||||||
|
aucune valeur sans relation — meme comportement qu'en edition). -->
|
||||||
|
<MalioInputText
|
||||||
|
v-if="relation.type"
|
||||||
|
:model-value="relation.name"
|
||||||
|
:label="relation.type === 'distributeur' ? t('commercial.clients.form.main.distributorName') : t('commercial.clients.form.main.brokerName')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioCheckbox
|
||||||
|
:model-value="client.triageService === true"
|
||||||
|
:label="t('commercial.clients.form.main.triageService')"
|
||||||
|
group-class="self-center"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Onglets (navigation libre, tout en lecture seule) ─────────── -->
|
||||||
|
<MalioTabList v-model="activeTab" :tabs="tabs" :max-visible-tabs="5" :max-width="1100" class="mt-[60px]">
|
||||||
|
<!-- Onglet Information -->
|
||||||
|
<template #information>
|
||||||
|
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
|
<MalioInputTextArea
|
||||||
|
:model-value="information.description"
|
||||||
|
:label="t('commercial.clients.form.information.description')"
|
||||||
|
resize="none"
|
||||||
|
group-class="row-span-2 pt-1"
|
||||||
|
text-input="h-full text-lg"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="information.competitors"
|
||||||
|
:label="t('commercial.clients.form.information.competitors')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioDate
|
||||||
|
:model-value="information.foundedAt"
|
||||||
|
:label="t('commercial.clients.form.information.foundedAt')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="information.employeesCount"
|
||||||
|
:label="t('commercial.clients.form.information.employeesCount')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputAmount
|
||||||
|
:model-value="information.revenueAmount"
|
||||||
|
:label="t('commercial.clients.form.information.revenueAmount')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="information.directorName"
|
||||||
|
:label="t('commercial.clients.form.information.directorName')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputAmount
|
||||||
|
:model-value="information.profitAmount"
|
||||||
|
:label="t('commercial.clients.form.information.profitAmount')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglet Contact -->
|
||||||
|
<template #contact>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<ClientContactBlock
|
||||||
|
v-for="(contact, index) in contacts"
|
||||||
|
:key="contact.id ?? index"
|
||||||
|
:model-value="contact"
|
||||||
|
:title="t('commercial.clients.form.contact.title', { n: index + 1 })"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglet Adresse -->
|
||||||
|
<template #address>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<ClientAddressBlock
|
||||||
|
v-for="(view, index) in addressViews"
|
||||||
|
:key="view.draft.id ?? index"
|
||||||
|
:model-value="view.draft"
|
||||||
|
:title="t('commercial.clients.form.address.title', { n: index + 1 })"
|
||||||
|
:category-options="view.categoryOptions"
|
||||||
|
:site-options="allSiteOptions"
|
||||||
|
:contact-options="contactOptions"
|
||||||
|
:country-options="countryOptions"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglet Comptabilite (present uniquement si accounting.view). -->
|
||||||
|
<template v-if="canAccountingView" #accounting>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
|
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="accounting.siren"
|
||||||
|
:label="t('commercial.clients.form.accounting.siren')"
|
||||||
|
:mask="SIREN_MASK"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="accounting.accountNumber"
|
||||||
|
:label="t('commercial.clients.form.accounting.accountNumber')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="accounting.tvaModeIri"
|
||||||
|
:options="tvaModeOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.tvaMode')"
|
||||||
|
empty-option-label=""
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="accounting.nTva"
|
||||||
|
:label="t('commercial.clients.form.accounting.nTva')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="accounting.paymentDelayIri"
|
||||||
|
:options="paymentDelayOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.paymentDelay')"
|
||||||
|
empty-option-label=""
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="accounting.paymentTypeIri"
|
||||||
|
:options="paymentTypeOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.paymentType')"
|
||||||
|
empty-option-label=""
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioSelect
|
||||||
|
v-if="accounting.bankIri"
|
||||||
|
:model-value="accounting.bankIri"
|
||||||
|
:options="bankOptions"
|
||||||
|
:label="t('commercial.clients.form.accounting.bank')"
|
||||||
|
empty-option-label=""
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Blocs RIB (0..n), lecture seule. -->
|
||||||
|
<div
|
||||||
|
v-for="(rib, index) in ribs"
|
||||||
|
:key="rib.id ?? index"
|
||||||
|
class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||||
|
>
|
||||||
|
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="rib.label"
|
||||||
|
:label="t('commercial.clients.form.accounting.ribLabel')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="rib.bic"
|
||||||
|
:label="t('commercial.clients.form.accounting.ribBic')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="rib.iban"
|
||||||
|
:label="t('commercial.clients.form.accounting.ribIban')"
|
||||||
|
readonly
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
||||||
|
<template #transport><ComingSoonPlaceholder /></template>
|
||||||
|
<template #statistics><ComingSoonPlaceholder /></template>
|
||||||
|
<template #reports><ComingSoonPlaceholder /></template>
|
||||||
|
<template #exchanges><ComingSoonPlaceholder /></template>
|
||||||
|
</MalioTabList>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation Archiver / Restaurer. -->
|
||||||
|
<MalioModal v-model="confirmOpen" modal-class="max-w-md">
|
||||||
|
<template #header>
|
||||||
|
<h2 class="text-[24px] font-bold">
|
||||||
|
{{ isArchived ? t('commercial.clients.consultation.confirmRestore.title') : t('commercial.clients.consultation.confirmArchive.title') }}
|
||||||
|
</h2>
|
||||||
|
</template>
|
||||||
|
<p>{{ isArchived ? t('commercial.clients.consultation.confirmRestore.message') : t('commercial.clients.consultation.confirmArchive.message') }}</p>
|
||||||
|
<template #footer>
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('commercial.clients.form.confirmDelete.cancel')"
|
||||||
|
@click="confirmOpen = false"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
:variant="isArchived ? 'primary' : 'danger'"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('commercial.clients.form.confirmDelete.confirm')"
|
||||||
|
:disabled="toggling"
|
||||||
|
@click="confirmToggleArchive"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</MalioModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
import { useClient } from '~/modules/commercial/composables/useClient'
|
||||||
|
import { buildClientFormTabKeys } from '~/modules/commercial/utils/clientFormRules'
|
||||||
|
import {
|
||||||
|
canEditClient,
|
||||||
|
categoryOptionsOf,
|
||||||
|
contactOptionsOf,
|
||||||
|
mapAccountingDraft,
|
||||||
|
mapAddressView,
|
||||||
|
mapContactToDraft,
|
||||||
|
mapRibToDraft,
|
||||||
|
referentialOptionOf,
|
||||||
|
relationOf,
|
||||||
|
showArchiveAction,
|
||||||
|
showRestoreAction,
|
||||||
|
type ClientDetail,
|
||||||
|
type SelectOption,
|
||||||
|
} from '~/modules/commercial/utils/clientConsultation'
|
||||||
|
import { emptyAddress, emptyContact, emptyRib } from '~/modules/commercial/types/clientForm'
|
||||||
|
|
||||||
|
// Masque d'affichage (purement visuel, la donnee reste celle du serveur).
|
||||||
|
const SIREN_MASK = '#########'
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
const toast = useToast()
|
||||||
|
const { can, canAny } = usePermissions()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
|
// Gating de la route : la consultation exige `view`. Usine (sans view) est
|
||||||
|
// redirige vers le repertoire (lui-meme protege). Cf. matrice § 2.7.
|
||||||
|
if (!can('commercial.clients.view')) {
|
||||||
|
await navigateTo('/clients')
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientId = route.params.id as string
|
||||||
|
|
||||||
|
const { client, loading, error, load, archive, restore } = useClient(clientId)
|
||||||
|
|
||||||
|
// ── Permissions / visibilite des actions ───────────────────────────────────
|
||||||
|
const canAccountingView = computed(() => can('commercial.clients.accounting.view'))
|
||||||
|
const canEdit = computed(() => canEditClient(canAny))
|
||||||
|
const isArchived = computed(() => client.value?.isArchived === true)
|
||||||
|
const showArchive = computed(() => showArchiveAction(can, isArchived.value))
|
||||||
|
const showRestore = computed(() => showRestoreAction(can, isArchived.value))
|
||||||
|
|
||||||
|
const headerTitle = computed(() => client.value?.companyName ?? t('commercial.clients.consultation.title'))
|
||||||
|
|
||||||
|
// ── Donnees derivees du payload (lecture seule) ────────────────────────────
|
||||||
|
const relation = computed(() => (client.value ? relationOf(client.value) : { type: null, name: null }))
|
||||||
|
const categoryIris = computed(() => (client.value?.categories ?? []).map(c => c['@id']))
|
||||||
|
|
||||||
|
const information = computed(() => ({
|
||||||
|
description: client.value?.description ?? null,
|
||||||
|
competitors: client.value?.competitors ?? null,
|
||||||
|
// MalioDate attend strictement YYYY-MM-DD : on tronque l'ISO datetime renvoye.
|
||||||
|
foundedAt: client.value?.foundedAt ? client.value.foundedAt.slice(0, 10) : null,
|
||||||
|
employeesCount: client.value?.employeesCount != null ? String(client.value.employeesCount) : null,
|
||||||
|
revenueAmount: client.value?.revenueAmount ?? null,
|
||||||
|
profitAmount: client.value?.profitAmount ?? null,
|
||||||
|
directorName: client.value?.directorName ?? null,
|
||||||
|
}))
|
||||||
|
|
||||||
|
// Chaque bloc reste visible meme vide en consultation : si la collection est
|
||||||
|
// vide, on affiche un bloc vierge en lecture seule (pas de message « Aucun … »).
|
||||||
|
const contacts = computed(() => {
|
||||||
|
const list = (client.value?.contacts ?? []).map(mapContactToDraft)
|
||||||
|
return list.length ? list : [emptyContact()]
|
||||||
|
})
|
||||||
|
// Vue par adresse : brouillon + options (sites/categories) propres a l'adresse.
|
||||||
|
const addressViews = computed(() => {
|
||||||
|
const views = (client.value?.addresses ?? []).map(mapAddressView)
|
||||||
|
return views.length ? views : [{ draft: emptyAddress(), siteOptions: [], categoryOptions: [] }]
|
||||||
|
})
|
||||||
|
const ribs = computed(() => {
|
||||||
|
const list = (client.value?.ribs ?? []).map(mapRibToDraft)
|
||||||
|
return list.length ? list : [emptyRib()]
|
||||||
|
})
|
||||||
|
// Draft comptable (tout null si l'utilisateur n'a pas accounting.view).
|
||||||
|
const accounting = computed(() => mapAccountingDraft(client.value ?? ({} as ClientDetail)))
|
||||||
|
|
||||||
|
// ── Options des selects (construites depuis l'EMBED, jamais via un GET de
|
||||||
|
// referentiel : /categories et /sites sont en 403 pour les roles metier
|
||||||
|
// non-admin, ce qui laisserait les libelles vides). ───────────────────────
|
||||||
|
const mainCategoryOptions = computed(() => categoryOptionsOf(client.value?.categories))
|
||||||
|
const contactOptions = computed(() => contactOptionsOf(client.value?.contacts))
|
||||||
|
|
||||||
|
// Liste COMPLETE des sites disponibles, issue de /api/me (groupe me:read — donc
|
||||||
|
// pas de 403 pour les roles metier, contrairement a GET /sites). Libelle = numero
|
||||||
|
// de departement (2 premiers chiffres du code postal). Permet d'afficher TOUJOURS
|
||||||
|
// toutes les cases « Sites » (86 / 17 / 82) dans le bloc adresse, meme celles non
|
||||||
|
// rattachees a l'adresse consultee (les rattachees restent cochees via siteIris).
|
||||||
|
const allSiteOptions = computed<SelectOption[]>(() =>
|
||||||
|
(authStore.user?.sites ?? []).map(s => ({
|
||||||
|
value: `/api/sites/${s.id}`,
|
||||||
|
label: (s.postalCode ?? '').slice(0, 2),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
const relationOptions = computed<SelectOption[]>(() => [
|
||||||
|
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
||||||
|
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||||
|
])
|
||||||
|
|
||||||
|
const countryOptions: SelectOption[] = [
|
||||||
|
{ value: 'France', label: 'France' },
|
||||||
|
{ value: 'Espagne', label: 'Espagne' },
|
||||||
|
]
|
||||||
|
|
||||||
|
// Selects comptables : libelle issu de l'embed (option unique ou vide).
|
||||||
|
const tvaModeOptions = computed(() => referentialOptionOf(client.value?.tvaMode))
|
||||||
|
const paymentDelayOptions = computed(() => referentialOptionOf(client.value?.paymentDelay))
|
||||||
|
const paymentTypeOptions = computed(() => referentialOptionOf(client.value?.paymentType))
|
||||||
|
const bankOptions = computed(() => referentialOptionOf(client.value?.bank))
|
||||||
|
|
||||||
|
// ── Onglets : navigation LIBRE (pas de sequence forcee en consultation) ────
|
||||||
|
// 4 onglets actifs (Information, Contact, Adresse, + Comptabilite si droit) et
|
||||||
|
// 4 coquilles (Transport, Statistiques, Rapports, Echanges).
|
||||||
|
const tabKeys = computed(() => buildClientFormTabKeys(canAccountingView.value, { includeEditOnlyTabs: true }))
|
||||||
|
|
||||||
|
const TAB_ICONS: Record<string, string> = {
|
||||||
|
information: 'mdi:account-outline',
|
||||||
|
contact: 'mdi:account-box-plus-outline',
|
||||||
|
address: 'mdi:map-marker-outline',
|
||||||
|
transport: 'mdi:truck-delivery-outline',
|
||||||
|
accounting: 'mdi:bank-circle-outline',
|
||||||
|
statistics: 'mdi:finance',
|
||||||
|
reports: 'mdi:file-document-edit-outline',
|
||||||
|
exchanges: 'mdi:account-group-outline',
|
||||||
|
}
|
||||||
|
|
||||||
|
const tabs = computed(() => tabKeys.value.map(key => ({
|
||||||
|
key,
|
||||||
|
label: t(`commercial.clients.tab.${key}`),
|
||||||
|
icon: TAB_ICONS[key],
|
||||||
|
})))
|
||||||
|
|
||||||
|
const activeTab = ref('information')
|
||||||
|
|
||||||
|
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||||
|
function goBack(): void {
|
||||||
|
router.push('/clients')
|
||||||
|
}
|
||||||
|
|
||||||
|
function goEdit(): void {
|
||||||
|
router.push(`/clients/${clientId}/edit`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Archivage / Restauration ────────────────────────────────────────────────
|
||||||
|
const confirmOpen = ref(false)
|
||||||
|
const toggling = ref(false)
|
||||||
|
|
||||||
|
function askToggleArchive(): void {
|
||||||
|
confirmOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirme l'archivage ou la restauration (PATCH isArchived seul). Gere le 409
|
||||||
|
* de conflit d'homonyme actif a la restauration (RG-1.23) avec un message dedie.
|
||||||
|
*/
|
||||||
|
async function confirmToggleArchive(): Promise<void> {
|
||||||
|
if (toggling.value) return
|
||||||
|
toggling.value = true
|
||||||
|
const restoring = isArchived.value
|
||||||
|
try {
|
||||||
|
if (restoring) {
|
||||||
|
await restore()
|
||||||
|
toast.success({ title: t('commercial.clients.toast.restoreSuccess') })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await archive()
|
||||||
|
toast.success({ title: t('commercial.clients.toast.archiveSuccess') })
|
||||||
|
}
|
||||||
|
confirmOpen.value = false
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const status = (e as { response?: { status?: number } })?.response?.status
|
||||||
|
toast.error({
|
||||||
|
title: t('commercial.clients.toast.error'),
|
||||||
|
message: restoring && status === 409
|
||||||
|
? t('commercial.clients.toast.restoreConflict')
|
||||||
|
: t('commercial.clients.toast.error'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
toggling.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useHead({ title: headerTitle })
|
||||||
|
|
||||||
|
onMounted(load)
|
||||||
|
</script>
|
||||||
@@ -22,50 +22,24 @@
|
|||||||
:label="t('commercial.clients.form.main.companyName')"
|
:label="t('commercial.clients.form.main.companyName')"
|
||||||
:required="true"
|
:required="true"
|
||||||
:readonly="mainLocked"
|
:readonly="mainLocked"
|
||||||
/>
|
:error="mainErrors.errors.companyName"
|
||||||
<MalioInputText
|
|
||||||
v-model="main.lastName"
|
|
||||||
:label="t('commercial.clients.form.main.lastName')"
|
|
||||||
:readonly="mainLocked"
|
|
||||||
/>
|
|
||||||
<MalioInputText
|
|
||||||
v-model="main.firstName"
|
|
||||||
:label="t('commercial.clients.form.main.firstName')"
|
|
||||||
:readonly="mainLocked"
|
|
||||||
/>
|
/>
|
||||||
<MalioSelectCheckbox
|
<MalioSelectCheckbox
|
||||||
:model-value="main.categoryIris"
|
:model-value="main.categoryIris"
|
||||||
:options="referentials.categories.value"
|
:options="referentials.categories.value"
|
||||||
:label="t('commercial.clients.form.main.categories')"
|
:label="t('commercial.clients.form.main.categories')"
|
||||||
:display-tag="true"
|
:display-tag="true"
|
||||||
:disabled="mainLocked"
|
|
||||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
|
||||||
/>
|
|
||||||
<!-- Telephones : 1 par defaut, le bouton « + » revele le 2e (max 2, RG-1.02). -->
|
|
||||||
<MalioInputPhone
|
|
||||||
v-for="(_, index) in mainPhones"
|
|
||||||
:key="index"
|
|
||||||
v-model="mainPhones[index]"
|
|
||||||
:label="t('commercial.clients.form.main.phonePrimary')"
|
|
||||||
:mask="PHONE_MASK"
|
|
||||||
:required="index === 0"
|
|
||||||
:readonly="mainLocked"
|
:readonly="mainLocked"
|
||||||
add-icon-name="mdi:plus"
|
|
||||||
:addable="mainPhones.length === 1 && !mainLocked"
|
|
||||||
:add-button-label="t('commercial.clients.form.main.addPhone')"
|
|
||||||
@add="addMainPhone"
|
|
||||||
/>
|
|
||||||
<MalioInputEmail
|
|
||||||
v-model="main.email"
|
|
||||||
:label="t('commercial.clients.form.main.email')"
|
|
||||||
:required="true"
|
:required="true"
|
||||||
:readonly="mainLocked"
|
:error="mainErrors.errors.categories"
|
||||||
|
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
:model-value="main.relationType"
|
:model-value="main.relationType"
|
||||||
:options="relationOptions"
|
:options="relationOptions"
|
||||||
:label="t('commercial.clients.form.main.relation')"
|
:label="t('commercial.clients.form.main.relation')"
|
||||||
:disabled="mainLocked"
|
:empty-option-label="t('commercial.clients.form.main.relationNone')"
|
||||||
|
:readonly="mainLocked"
|
||||||
@update:model-value="onRelationChange"
|
@update:model-value="onRelationChange"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
@@ -73,7 +47,9 @@
|
|||||||
:model-value="main.brokerIri"
|
:model-value="main.brokerIri"
|
||||||
:options="referentials.brokers.value"
|
:options="referentials.brokers.value"
|
||||||
:label="t('commercial.clients.form.main.brokerName')"
|
:label="t('commercial.clients.form.main.brokerName')"
|
||||||
:disabled="mainLocked"
|
:readonly="mainLocked"
|
||||||
|
:required="true"
|
||||||
|
:error="mainErrors.errors.broker"
|
||||||
@update:model-value="(v: string | number | null) => main.brokerIri = v === null ? null : String(v)"
|
@update:model-value="(v: string | number | null) => main.brokerIri = v === null ? null : String(v)"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
@@ -81,7 +57,9 @@
|
|||||||
:model-value="main.distributorIri"
|
:model-value="main.distributorIri"
|
||||||
:options="referentials.distributors.value"
|
:options="referentials.distributors.value"
|
||||||
:label="t('commercial.clients.form.main.distributorName')"
|
:label="t('commercial.clients.form.main.distributorName')"
|
||||||
:disabled="mainLocked"
|
:readonly="mainLocked"
|
||||||
|
:required="true"
|
||||||
|
:error="mainErrors.errors.distributor"
|
||||||
@update:model-value="(v: string | number | null) => main.distributorIri = v === null ? null : String(v)"
|
@update:model-value="(v: string | number | null) => main.distributorIri = v === null ? null : String(v)"
|
||||||
/>
|
/>
|
||||||
<MalioCheckbox
|
<MalioCheckbox
|
||||||
@@ -114,38 +92,45 @@
|
|||||||
resize="none"
|
resize="none"
|
||||||
group-class="row-span-2 pt-1"
|
group-class="row-span-2 pt-1"
|
||||||
text-input="h-full text-lg"
|
text-input="h-full text-lg"
|
||||||
:disabled="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
|
:error="informationErrors.errors.description"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="information.competitors"
|
v-model="information.competitors"
|
||||||
:label="t('commercial.clients.form.information.competitors')"
|
:label="t('commercial.clients.form.information.competitors')"
|
||||||
:readonly="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
|
:error="informationErrors.errors.competitors"
|
||||||
/>
|
/>
|
||||||
<MalioDate
|
<MalioDate
|
||||||
v-model="information.foundedAt"
|
v-model="information.foundedAt"
|
||||||
:label="t('commercial.clients.form.information.foundedAt')"
|
:label="t('commercial.clients.form.information.foundedAt')"
|
||||||
:readonly="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
|
:error="informationErrors.errors.foundedAt"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="information.employeesCount"
|
v-model="information.employeesCount"
|
||||||
:label="t('commercial.clients.form.information.employeesCount')"
|
:label="t('commercial.clients.form.information.employeesCount')"
|
||||||
:mask="EMPLOYEES_MASK"
|
:mask="EMPLOYEES_MASK"
|
||||||
:readonly="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
|
:error="informationErrors.errors.employeesCount"
|
||||||
/>
|
/>
|
||||||
<MalioInputAmount
|
<MalioInputAmount
|
||||||
v-model="information.revenueAmount"
|
v-model="information.revenueAmount"
|
||||||
:label="t('commercial.clients.form.information.revenueAmount')"
|
:label="t('commercial.clients.form.information.revenueAmount')"
|
||||||
:disabled="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
|
:error="informationErrors.errors.revenueAmount"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="information.directorName"
|
v-model="information.directorName"
|
||||||
:label="t('commercial.clients.form.information.directorName')"
|
:label="t('commercial.clients.form.information.directorName')"
|
||||||
:readonly="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
|
:error="informationErrors.errors.directorName"
|
||||||
/>
|
/>
|
||||||
<MalioInputAmount
|
<MalioInputAmount
|
||||||
v-model="information.profitAmount"
|
v-model="information.profitAmount"
|
||||||
:label="t('commercial.clients.form.information.profitAmount')"
|
:label="t('commercial.clients.form.information.profitAmount')"
|
||||||
:disabled="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
|
:error="informationErrors.errors.profitAmount"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!isValidated('information')" class="mt-12 flex justify-center">
|
<div v-if="!isValidated('information')" class="mt-12 flex justify-center">
|
||||||
@@ -171,6 +156,7 @@
|
|||||||
:title="t('commercial.clients.form.contact.title', { n: index + 1 })"
|
:title="t('commercial.clients.form.contact.title', { n: index + 1 })"
|
||||||
:removable="index > 0"
|
:removable="index > 0"
|
||||||
:readonly="isValidated('contact')"
|
:readonly="isValidated('contact')"
|
||||||
|
:errors="contactErrors[index]"
|
||||||
@update:model-value="(v) => contacts[index] = v"
|
@update:model-value="(v) => contacts[index] = v"
|
||||||
@remove="askRemoveContact(index)"
|
@remove="askRemoveContact(index)"
|
||||||
/>
|
/>
|
||||||
@@ -207,6 +193,7 @@
|
|||||||
:country-options="countryOptions"
|
:country-options="countryOptions"
|
||||||
:removable="index > 0"
|
:removable="index > 0"
|
||||||
:readonly="isValidated('address')"
|
:readonly="isValidated('address')"
|
||||||
|
:errors="addressErrors[index]"
|
||||||
@update:model-value="(v) => addresses[index] = v"
|
@update:model-value="(v) => addresses[index] = v"
|
||||||
@remove="askRemoveAddress(index)"
|
@remove="askRemoveAddress(index)"
|
||||||
@degraded="onAddressDegraded"
|
@degraded="onAddressDegraded"
|
||||||
@@ -233,45 +220,57 @@
|
|||||||
<template v-if="canAccountingView" #accounting>
|
<template v-if="canAccountingView" #accounting>
|
||||||
<div class="mt-12 flex flex-col gap-6">
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="accounting.siren"
|
v-model="accounting.siren"
|
||||||
:label="t('commercial.clients.form.accounting.siren')"
|
:label="t('commercial.clients.form.accounting.siren')"
|
||||||
:mask="SIREN_MASK"
|
:mask="SIREN_MASK"
|
||||||
:readonly="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.siren"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="accounting.accountNumber"
|
v-model="accounting.accountNumber"
|
||||||
:label="t('commercial.clients.form.accounting.accountNumber')"
|
:label="t('commercial.clients.form.accounting.accountNumber')"
|
||||||
:readonly="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.accountNumber"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
:model-value="accounting.tvaModeIri"
|
:model-value="accounting.tvaModeIri"
|
||||||
:options="referentials.tvaModes.value"
|
:options="referentials.tvaModes.value"
|
||||||
:label="t('commercial.clients.form.accounting.tvaMode')"
|
:label="t('commercial.clients.form.accounting.tvaMode')"
|
||||||
:disabled="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
empty-option-label=""
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.tvaMode"
|
||||||
@update:model-value="(v: string | number | null) => accounting.tvaModeIri = v === null ? null : String(v)"
|
@update:model-value="(v: string | number | null) => accounting.tvaModeIri = v === null ? null : String(v)"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="accounting.nTva"
|
v-model="accounting.nTva"
|
||||||
:label="t('commercial.clients.form.accounting.nTva')"
|
:label="t('commercial.clients.form.accounting.nTva')"
|
||||||
:readonly="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.nTva"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
:model-value="accounting.paymentDelayIri"
|
:model-value="accounting.paymentDelayIri"
|
||||||
:options="referentials.paymentDelays.value"
|
:options="referentials.paymentDelays.value"
|
||||||
:label="t('commercial.clients.form.accounting.paymentDelay')"
|
:label="t('commercial.clients.form.accounting.paymentDelay')"
|
||||||
:disabled="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
empty-option-label=""
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.paymentDelay"
|
||||||
@update:model-value="(v: string | number | null) => accounting.paymentDelayIri = v === null ? null : String(v)"
|
@update:model-value="(v: string | number | null) => accounting.paymentDelayIri = v === null ? null : String(v)"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
:model-value="accounting.paymentTypeIri"
|
:model-value="accounting.paymentTypeIri"
|
||||||
:options="referentials.paymentTypes.value"
|
:options="referentials.paymentTypes.value"
|
||||||
:label="t('commercial.clients.form.accounting.paymentType')"
|
:label="t('commercial.clients.form.accounting.paymentType')"
|
||||||
:disabled="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
empty-option-label=""
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.paymentType"
|
||||||
@update:model-value="onPaymentTypeChange"
|
@update:model-value="onPaymentTypeChange"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
@@ -279,8 +278,10 @@
|
|||||||
:model-value="accounting.bankIri"
|
:model-value="accounting.bankIri"
|
||||||
:options="referentials.banks.value"
|
:options="referentials.banks.value"
|
||||||
:label="t('commercial.clients.form.accounting.bank')"
|
:label="t('commercial.clients.form.accounting.bank')"
|
||||||
:disabled="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
empty-option-label=""
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="accountingErrors.errors.bank"
|
||||||
@update:model-value="(v: string | number | null) => accounting.bankIri = v === null ? null : String(v)"
|
@update:model-value="(v: string | number | null) => accounting.bankIri = v === null ? null : String(v)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -301,21 +302,27 @@
|
|||||||
v-bind="{ ariaLabel: t('commercial.clients.form.accounting.removeRib') }"
|
v-bind="{ ariaLabel: t('commercial.clients.form.accounting.removeRib') }"
|
||||||
@click="askRemoveRib(index)"
|
@click="askRemoveRib(index)"
|
||||||
/>
|
/>
|
||||||
<div class="grid grid-cols-3 gap-x-[80px] gap-y-5">
|
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="rib.label"
|
v-model="rib.label"
|
||||||
:label="t('commercial.clients.form.accounting.ribLabel')"
|
:label="t('commercial.clients.form.accounting.ribLabel')"
|
||||||
:readonly="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
|
:required="isRibRequired"
|
||||||
|
:error="ribErrors[index]?.label"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="rib.bic"
|
v-model="rib.bic"
|
||||||
:label="t('commercial.clients.form.accounting.ribBic')"
|
:label="t('commercial.clients.form.accounting.ribBic')"
|
||||||
:readonly="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
|
:required="isRibRequired"
|
||||||
|
:error="ribErrors[index]?.bic"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="rib.iban"
|
v-model="rib.iban"
|
||||||
:label="t('commercial.clients.form.accounting.ribIban')"
|
:label="t('commercial.clients.form.accounting.ribIban')"
|
||||||
:readonly="accountingReadonly"
|
:readonly="accountingReadonly"
|
||||||
|
:required="isRibRequired"
|
||||||
|
:error="ribErrors[index]?.iban"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -341,7 +348,7 @@
|
|||||||
<!-- Onglet non encore implemente : frame vide, passage automatique.
|
<!-- Onglet non encore implemente : frame vide, passage automatique.
|
||||||
Statistiques / Rapports / Echanges sont edit-only (absents a la
|
Statistiques / Rapports / Echanges sont edit-only (absents a la
|
||||||
creation) — cf. buildClientFormTabKeys. -->
|
creation) — cf. buildClientFormTabKeys. -->
|
||||||
<template #transport><TabPlaceholderBlank /></template>
|
<template #transport><ComingSoonPlaceholder /></template>
|
||||||
</MalioTabList>
|
</MalioTabList>
|
||||||
|
|
||||||
<!-- Modal de confirmation generique (suppression contact/adresse/RIB). -->
|
<!-- Modal de confirmation generique (suppression contact/adresse/RIB). -->
|
||||||
@@ -371,13 +378,18 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||||
import { useClientReferentials, type RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
import { useClientReferentials, type RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
||||||
|
import { useClientFormErrors } from '~/modules/commercial/composables/useClientFormErrors'
|
||||||
import {
|
import {
|
||||||
|
addressTypeFromFlags,
|
||||||
buildClientFormTabKeys,
|
buildClientFormTabKeys,
|
||||||
CLIENT_FORM_PLACEHOLDER_TABS,
|
CLIENT_FORM_PLACEHOLDER_TABS,
|
||||||
|
hasAllRequiredAccountingFields,
|
||||||
hasAtLeastOneValidContact,
|
hasAtLeastOneValidContact,
|
||||||
isBankRequiredForPaymentType,
|
isBankRequiredForPaymentType,
|
||||||
isBillingEmailRequired,
|
isBillingEmailRequired,
|
||||||
|
isContactBlank,
|
||||||
isContactNamed,
|
isContactNamed,
|
||||||
|
isRibBlank,
|
||||||
isRibRequiredForPaymentType,
|
isRibRequiredForPaymentType,
|
||||||
} from '~/modules/commercial/utils/clientFormRules'
|
} from '~/modules/commercial/utils/clientFormRules'
|
||||||
import {
|
import {
|
||||||
@@ -388,11 +400,9 @@ import {
|
|||||||
type ContactFormDraft,
|
type ContactFormDraft,
|
||||||
type RibFormDraft,
|
type RibFormDraft,
|
||||||
} from '~/modules/commercial/types/clientForm'
|
} from '~/modules/commercial/types/clientForm'
|
||||||
import { formatPhoneFR } from '~/shared/utils/phone'
|
|
||||||
import { extractApiErrorMessage } from '~/shared/utils/api'
|
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||||
|
|
||||||
// Masques de saisie (la normalisation finale reste serveur).
|
// Masques de saisie (la normalisation finale reste serveur).
|
||||||
const PHONE_MASK = '## ## ## ## ##'
|
|
||||||
const SIREN_MASK = '#########'
|
const SIREN_MASK = '#########'
|
||||||
// Masque « nombre » du champ Nombre de salaries : chiffres uniquement (max 7).
|
// Masque « nombre » du champ Nombre de salaries : chiffres uniquement (max 7).
|
||||||
const EMPLOYEES_MASK = '#######'
|
const EMPLOYEES_MASK = '#######'
|
||||||
@@ -422,6 +432,22 @@ function apiErrorMessage(error: unknown): string {
|
|||||||
return extractApiErrorMessage(data) || t('commercial.clients.toast.error')
|
return extractApiErrorMessage(data) || t('commercial.clients.toast.error')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Erreurs de validation par champ (ERP-101) ───────────────────────────────
|
||||||
|
// Etat d'erreurs factorise entre creation et edition (cf. useClientFormErrors) :
|
||||||
|
// un `useFormErrors` par groupe scalaire (Principal / Information / Comptabilite)
|
||||||
|
// + un tableau d'erreurs par ligne pour chaque collection (contacts/adresses/RIB).
|
||||||
|
// `mapRowError` mappe une 422 inline et retourne true ; il ne toaste pas, le
|
||||||
|
// fallback reste local a la creation (cf. catch des submits de collection).
|
||||||
|
const {
|
||||||
|
mainErrors,
|
||||||
|
informationErrors,
|
||||||
|
accountingErrors,
|
||||||
|
contactErrors,
|
||||||
|
addressErrors,
|
||||||
|
ribErrors,
|
||||||
|
submitRows,
|
||||||
|
} = useClientFormErrors()
|
||||||
|
|
||||||
useHead({ title: t('commercial.clients.form.title') })
|
useHead({ title: t('commercial.clients.form.title') })
|
||||||
|
|
||||||
// Gating de la route : la creation est reservee a `manage`. Compta (accounting
|
// Gating de la route : la creation est reservee a `manage`. Compta (accounting
|
||||||
@@ -444,9 +470,6 @@ const tabSubmitting = ref(false)
|
|||||||
// ── Formulaire principal ────────────────────────────────────────────────────
|
// ── Formulaire principal ────────────────────────────────────────────────────
|
||||||
const main = reactive({
|
const main = reactive({
|
||||||
companyName: null as string | null,
|
companyName: null as string | null,
|
||||||
firstName: null as string | null,
|
|
||||||
lastName: null as string | null,
|
|
||||||
email: null as string | null,
|
|
||||||
categoryIris: [] as string[],
|
categoryIris: [] as string[],
|
||||||
relationType: null as 'distributeur' | 'courtier' | null,
|
relationType: null as 'distributeur' | 'courtier' | null,
|
||||||
distributorIri: null as string | null,
|
distributorIri: null as string | null,
|
||||||
@@ -454,17 +477,6 @@ const main = reactive({
|
|||||||
triageService: false,
|
triageService: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Telephones du formulaire principal : 1 par defaut, 2 au maximum (RG-1.02).
|
|
||||||
// L'index 0 alimente phonePrimary, l'index 1 phoneSecondary au POST.
|
|
||||||
const mainPhones = ref<string[]>([''])
|
|
||||||
|
|
||||||
/** Revele le 2e numero (le bouton « + » disparait une fois a 2, RG-1.02). */
|
|
||||||
function addMainPhone(): void {
|
|
||||||
if (mainPhones.value.length === 1) {
|
|
||||||
mainPhones.value.push('')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pas d'option « Aucun » : le select est vide par defaut (relationType = null).
|
// Pas d'option « Aucun » : le select est vide par defaut (relationType = null).
|
||||||
const relationOptions = computed<RefOption[]>(() => [
|
const relationOptions = computed<RefOption[]>(() => [
|
||||||
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
||||||
@@ -472,10 +484,11 @@ const relationOptions = computed<RefOption[]>(() => [
|
|||||||
])
|
])
|
||||||
|
|
||||||
// Validation du formulaire principal (gate le bouton « Valider ») :
|
// Validation du formulaire principal (gate le bouton « Valider ») :
|
||||||
// - companyName / email / telephone principal / >= 1 categorie obligatoires ;
|
// - companyName / >= 1 categorie obligatoires ;
|
||||||
// - RG-1.01 : nom OU prenom du contact principal ;
|
// - relation Distributeur/Courtier optionnelle, mais le nom correspondant
|
||||||
// - relation Distributeur/Courtier obligatoire (un des deux), ET le nom
|
// devient requis si l'un des deux est choisi (spec fonctionnelle).
|
||||||
// correspondant obligatoire selon le choix (spec fonctionnelle).
|
// Les coordonnees de contact ne sont plus saisies ici : elles vivent dans
|
||||||
|
// l'onglet Contacts (RG-1.05/1.14 garantissent >= 1 contact valide).
|
||||||
const isMainValid = computed(() => {
|
const isMainValid = computed(() => {
|
||||||
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
||||||
// Relation Distributeur/Courtier OPTIONNELLE ; mais si « Depend du
|
// Relation Distributeur/Courtier OPTIONNELLE ; mais si « Depend du
|
||||||
@@ -485,9 +498,6 @@ const isMainValid = computed(() => {
|
|||||||
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
||||||
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
||||||
return filled(main.companyName)
|
return filled(main.companyName)
|
||||||
&& filled(main.email)
|
|
||||||
&& filled(mainPhones.value[0])
|
|
||||||
&& (filled(main.firstName) || filled(main.lastName))
|
|
||||||
&& main.categoryIris.length >= 1
|
&& main.categoryIris.length >= 1
|
||||||
&& relationValid
|
&& relationValid
|
||||||
})
|
})
|
||||||
@@ -509,14 +519,10 @@ async function onRelationChange(value: string | number | null): Promise<void> {
|
|||||||
async function submitMain(): Promise<void> {
|
async function submitMain(): Promise<void> {
|
||||||
if (!isMainValid.value || mainSubmitting.value) return
|
if (!isMainValid.value || mainSubmitting.value) return
|
||||||
mainSubmitting.value = true
|
mainSubmitting.value = true
|
||||||
|
mainErrors.clearErrors()
|
||||||
try {
|
try {
|
||||||
const payload: Record<string, unknown> = {
|
const payload: Record<string, unknown> = {
|
||||||
companyName: main.companyName,
|
companyName: main.companyName,
|
||||||
firstName: main.firstName || null,
|
|
||||||
lastName: main.lastName || null,
|
|
||||||
email: main.email,
|
|
||||||
phonePrimary: mainPhones.value[0] || null,
|
|
||||||
phoneSecondary: mainPhones.value[1] || null,
|
|
||||||
categories: main.categoryIris,
|
categories: main.categoryIris,
|
||||||
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
||||||
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
||||||
@@ -528,18 +534,8 @@ async function submitMain(): Promise<void> {
|
|||||||
})
|
})
|
||||||
|
|
||||||
clientId.value = created.id
|
clientId.value = created.id
|
||||||
// Reaffiche les valeurs normalisees renvoyees par le serveur.
|
// Reaffiche la valeur normalisee renvoyee par le serveur.
|
||||||
main.companyName = created.companyName ?? main.companyName
|
main.companyName = created.companyName ?? main.companyName
|
||||||
main.firstName = created.firstName ?? null
|
|
||||||
main.lastName = created.lastName ?? null
|
|
||||||
main.email = created.email ?? main.email
|
|
||||||
// Reaffiche les telephones normalises (reformates via formatPhoneFR).
|
|
||||||
const normalizedPhones = [formatPhoneFR(created.phonePrimary), formatPhoneFR(created.phoneSecondary)]
|
|
||||||
.filter(p => p !== '')
|
|
||||||
mainPhones.value = normalizedPhones.length > 0 ? normalizedPhones : ['']
|
|
||||||
|
|
||||||
// Pre-remplit le 1er contact a partir du formulaire principal (editable).
|
|
||||||
prefillFirstContact()
|
|
||||||
|
|
||||||
mainLocked.value = true
|
mainLocked.value = true
|
||||||
unlockedIndex.value = 0
|
unlockedIndex.value = 0
|
||||||
@@ -547,15 +543,18 @@ async function submitMain(): Promise<void> {
|
|||||||
toast.success({ title: t('commercial.clients.toast.createSuccess') })
|
toast.success({ title: t('commercial.clients.toast.createSuccess') })
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
// 409 = doublon nom de societe (RG d'unicite) → message explicite ;
|
// 409 = doublon nom de societe (RG d'unicite) → erreur inline sur le
|
||||||
// sinon on remonte le message de validation du serveur (ex: 422).
|
// champ + toast explicite ; 422 → mapping inline par champ (pas de
|
||||||
|
// toast) ; autre → toast de fallback. Cf. ERP-101.
|
||||||
const status = (error as { response?: { status?: number } })?.response?.status
|
const status = (error as { response?: { status?: number } })?.response?.status
|
||||||
toast.error({
|
if (status === 409) {
|
||||||
title: t('commercial.clients.toast.error'),
|
const message = t('commercial.clients.form.duplicateCompany')
|
||||||
message: status === 409
|
mainErrors.setError('companyName', message)
|
||||||
? t('commercial.clients.form.duplicateCompany')
|
toast.error({ title: t('commercial.clients.toast.error'), message })
|
||||||
: apiErrorMessage(error),
|
}
|
||||||
})
|
else {
|
||||||
|
mainErrors.handleApiError(error, { fallbackMessage: t('commercial.clients.toast.error') })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
mainSubmitting.value = false
|
mainSubmitting.value = false
|
||||||
@@ -630,6 +629,7 @@ const information = reactive({
|
|||||||
async function submitInformation(): Promise<void> {
|
async function submitInformation(): Promise<void> {
|
||||||
if (clientId.value === null || tabSubmitting.value) return
|
if (clientId.value === null || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
|
informationErrors.clearErrors()
|
||||||
try {
|
try {
|
||||||
await api.patch(`/clients/${clientId.value}`, {
|
await api.patch(`/clients/${clientId.value}`, {
|
||||||
description: information.description || null,
|
description: information.description || null,
|
||||||
@@ -644,7 +644,7 @@ async function submitInformation(): Promise<void> {
|
|||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) })
|
informationErrors.handleApiError(error, { fallbackMessage: t('commercial.clients.toast.error') })
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
tabSubmitting.value = false
|
tabSubmitting.value = false
|
||||||
@@ -652,18 +652,10 @@ async function submitInformation(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Onglet Contact ──────────────────────────────────────────────────────────
|
// ── Onglet Contact ──────────────────────────────────────────────────────────
|
||||||
|
// Au moins un bloc Contact vide au depart : c'est desormais le seul point de
|
||||||
|
// saisie des coordonnees (le bloc principal ne porte plus de contact inline).
|
||||||
const contacts = ref<ContactFormDraft[]>([emptyContact()])
|
const contacts = ref<ContactFormDraft[]>([emptyContact()])
|
||||||
|
|
||||||
/** Pre-remplit le 1er contact depuis le formulaire principal (apres creation). */
|
|
||||||
function prefillFirstContact(): void {
|
|
||||||
const first = contacts.value[0]
|
|
||||||
if (!first) return
|
|
||||||
first.lastName = main.lastName
|
|
||||||
first.firstName = main.firstName
|
|
||||||
first.email = main.email
|
|
||||||
first.phonePrimary = mainPhones.value[0] ?? null
|
|
||||||
}
|
|
||||||
|
|
||||||
// « + Nouveau contact » desactive tant que le dernier bloc n'a ni nom ni prenom.
|
// « + Nouveau contact » desactive tant que le dernier bloc n'a ni nom ni prenom.
|
||||||
const canAddContact = computed(() => {
|
const canAddContact = computed(() => {
|
||||||
const last = contacts.value[contacts.value.length - 1]
|
const last = contacts.value[contacts.value.length - 1]
|
||||||
@@ -680,6 +672,7 @@ function addContact(): void {
|
|||||||
function askRemoveContact(index: number): void {
|
function askRemoveContact(index: number): void {
|
||||||
askConfirm(t('commercial.clients.form.confirmDelete.contact'), () => {
|
askConfirm(t('commercial.clients.form.confirmDelete.contact'), () => {
|
||||||
contacts.value.splice(index, 1)
|
contacts.value.splice(index, 1)
|
||||||
|
contactErrors.value.splice(index, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -688,38 +681,45 @@ async function submitContacts(): Promise<void> {
|
|||||||
if (clientId.value === null || !canValidateContacts.value || tabSubmitting.value) return
|
if (clientId.value === null || !canValidateContacts.value || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
try {
|
try {
|
||||||
for (const contact of contacts.value) {
|
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
||||||
// On ignore les blocs totalement vides (ni nom ni prenom).
|
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
||||||
if (!isContactNamed(contact)) continue
|
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
||||||
|
const hasError = await submitRows(
|
||||||
const body = {
|
contacts.value,
|
||||||
firstName: contact.firstName || null,
|
contactErrors,
|
||||||
lastName: contact.lastName || null,
|
async (contact) => {
|
||||||
jobTitle: contact.jobTitle || null,
|
const body = {
|
||||||
phonePrimary: contact.phonePrimary || null,
|
firstName: contact.firstName || null,
|
||||||
phoneSecondary: contact.hasSecondaryPhone ? (contact.phoneSecondary || null) : null,
|
lastName: contact.lastName || null,
|
||||||
email: contact.email || null,
|
jobTitle: contact.jobTitle || null,
|
||||||
}
|
phonePrimary: contact.phonePrimary || null,
|
||||||
|
phoneSecondary: contact.hasSecondaryPhone ? (contact.phoneSecondary || null) : null,
|
||||||
if (contact.id === null) {
|
email: contact.email || null,
|
||||||
const created = await api.post<ContactResponse>(
|
}
|
||||||
`/clients/${clientId.value}/contacts`,
|
if (contact.id === null) {
|
||||||
body,
|
const created = await api.post<ContactResponse>(
|
||||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
`/clients/${clientId.value}/contacts`,
|
||||||
)
|
body,
|
||||||
contact.id = created.id
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
contact.iri = created['@id'] ?? null
|
)
|
||||||
}
|
contact.id = created.id
|
||||||
else {
|
contact.iri = created['@id'] ?? null
|
||||||
await api.patch(`/client_contacts/${contact.id}`, body, { toast: false })
|
}
|
||||||
}
|
else {
|
||||||
}
|
await api.patch(`/client_contacts/${contact.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
|
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||||
|
// bloc existant vide est soumis -> 422 RG-1.05 inline (sinon la modif
|
||||||
|
// serait perdue en silence avec un faux toast de succes).
|
||||||
|
contact => contact.id === null && isContactBlank(contact),
|
||||||
|
)
|
||||||
|
// Tant qu'un bloc reste en erreur : pas de validation d'onglet ni de toast succes.
|
||||||
|
if (hasError) return
|
||||||
completeTab('contact')
|
completeTab('contact')
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
catch (error) {
|
|
||||||
toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) })
|
|
||||||
}
|
|
||||||
finally {
|
finally {
|
||||||
tabSubmitting.value = false
|
tabSubmitting.value = false
|
||||||
}
|
}
|
||||||
@@ -750,12 +750,16 @@ const countryOptions: RefOption[] = [
|
|||||||
{ value: 'Espagne', label: 'Espagne' },
|
{ value: 'Espagne', label: 'Espagne' },
|
||||||
]
|
]
|
||||||
|
|
||||||
// RG-1.10 (>= 1 site) + RG-1.11 (email facturation si Facturation) sur chaque adresse.
|
// Type d'adresse (Select) obligatoire + RG-1.10 (>= 1 site) + RG-1.11 (email
|
||||||
|
// facturation si Facturation) sur chaque adresse.
|
||||||
const canValidateAddresses = computed(() =>
|
const canValidateAddresses = computed(() =>
|
||||||
addresses.value.length > 0
|
addresses.value.length > 0
|
||||||
&& addresses.value.every((a) => {
|
&& addresses.value.every((a) => {
|
||||||
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
||||||
return a.siteIris.length >= 1 && (!isBillingEmailRequired(a) || filledBillingEmail)
|
return addressTypeFromFlags(a) !== null
|
||||||
|
&& a.siteIris.length >= 1
|
||||||
|
&& a.categoryIris.length >= 1
|
||||||
|
&& (!isBillingEmailRequired(a) || filledBillingEmail)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -766,6 +770,7 @@ function addAddress(): void {
|
|||||||
function askRemoveAddress(index: number): void {
|
function askRemoveAddress(index: number): void {
|
||||||
askConfirm(t('commercial.clients.form.confirmDelete.address'), () => {
|
askConfirm(t('commercial.clients.form.confirmDelete.address'), () => {
|
||||||
addresses.value.splice(index, 1)
|
addresses.value.splice(index, 1)
|
||||||
|
addressErrors.value.splice(index, 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -784,40 +789,43 @@ async function submitAddresses(): Promise<void> {
|
|||||||
if (clientId.value === null || !canValidateAddresses.value || tabSubmitting.value) return
|
if (clientId.value === null || !canValidateAddresses.value || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
try {
|
try {
|
||||||
for (const address of addresses.value) {
|
// On tente TOUS les blocs d'adresse (collecte des erreurs par index, ERP-110).
|
||||||
const body = {
|
const hasError = await submitRows(
|
||||||
isProspect: address.isProspect,
|
addresses.value,
|
||||||
isDelivery: address.isDelivery,
|
addressErrors,
|
||||||
isBilling: address.isBilling,
|
async (address) => {
|
||||||
country: address.country,
|
const body = {
|
||||||
postalCode: address.postalCode || null,
|
isProspect: address.isProspect,
|
||||||
city: address.city || null,
|
isDelivery: address.isDelivery,
|
||||||
street: address.street || null,
|
isBilling: address.isBilling,
|
||||||
streetComplement: address.streetComplement || null,
|
country: address.country,
|
||||||
categories: address.categoryIris,
|
postalCode: address.postalCode || null,
|
||||||
sites: address.siteIris,
|
city: address.city || null,
|
||||||
contacts: address.contactIris,
|
street: address.street || null,
|
||||||
billingEmail: isBillingEmailRequired(address) ? (address.billingEmail || null) : null,
|
streetComplement: address.streetComplement || null,
|
||||||
}
|
categories: address.categoryIris,
|
||||||
|
sites: address.siteIris,
|
||||||
if (address.id === null) {
|
contacts: address.contactIris,
|
||||||
const created = await api.post<{ id: number }>(
|
billingEmail: isBillingEmailRequired(address) ? (address.billingEmail || null) : null,
|
||||||
`/clients/${clientId.value}/addresses`,
|
}
|
||||||
body,
|
if (address.id === null) {
|
||||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
const created = await api.post<{ id: number }>(
|
||||||
)
|
`/clients/${clientId.value}/addresses`,
|
||||||
address.id = created.id
|
body,
|
||||||
}
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
else {
|
)
|
||||||
await api.patch(`/client_addresses/${address.id}`, body, { toast: false })
|
address.id = created.id
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
await api.patch(`/client_addresses/${address.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
|
)
|
||||||
|
if (hasError) return
|
||||||
completeTab('address')
|
completeTab('address')
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
catch (error) {
|
|
||||||
toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) })
|
|
||||||
}
|
|
||||||
finally {
|
finally {
|
||||||
tabSubmitting.value = false
|
tabSubmitting.value = false
|
||||||
}
|
}
|
||||||
@@ -856,8 +864,11 @@ function ribIsComplete(rib: RibFormDraft): boolean {
|
|||||||
return filled(rib.label) && filled(rib.bic) && filled(rib.iban)
|
return filled(rib.label) && filled(rib.bic) && filled(rib.iban)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RG-1.30 : les 6 champs scalaires obligatoires (comme les onglets Contact /
|
||||||
|
// Adresse, le bouton reste desactive tant que l'onglet n'est pas complet).
|
||||||
// RG-1.12 : banque requise si VIREMENT. RG-1.13 : >= 1 RIB complet si LCR.
|
// RG-1.12 : banque requise si VIREMENT. RG-1.13 : >= 1 RIB complet si LCR.
|
||||||
const canValidateAccounting = computed(() => {
|
const canValidateAccounting = computed(() => {
|
||||||
|
if (!hasAllRequiredAccountingFields(accounting)) return false
|
||||||
if (isBankRequired.value && (accounting.bankIri === null)) return false
|
if (isBankRequired.value && (accounting.bankIri === null)) return false
|
||||||
if (isRibRequired.value && !ribs.value.some(ribIsComplete)) return false
|
if (isRibRequired.value && !ribs.value.some(ribIsComplete)) return false
|
||||||
return true
|
return true
|
||||||
@@ -870,6 +881,9 @@ function addRib(): void {
|
|||||||
function askRemoveRib(index: number): void {
|
function askRemoveRib(index: number): void {
|
||||||
askConfirm(t('commercial.clients.form.confirmDelete.rib'), () => {
|
askConfirm(t('commercial.clients.form.confirmDelete.rib'), () => {
|
||||||
ribs.value.splice(index, 1)
|
ribs.value.splice(index, 1)
|
||||||
|
ribErrors.value.splice(index, 1)
|
||||||
|
// Garde au moins un bloc RIB visible (cf. amorce au montage).
|
||||||
|
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,38 +895,60 @@ function askRemoveRib(index: number): void {
|
|||||||
async function submitAccounting(): Promise<void> {
|
async function submitAccounting(): Promise<void> {
|
||||||
if (clientId.value === null || !canValidateAccounting.value || tabSubmitting.value) return
|
if (clientId.value === null || !canValidateAccounting.value || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
|
accountingErrors.clearErrors()
|
||||||
|
// Reset des erreurs RIB des le debut : l'etape 1 (PATCH scalaires) peut
|
||||||
|
// echouer et `return` avant submitRows (qui porte sinon le reset), laissant
|
||||||
|
// des erreurs de RIB obsoletes affichees sous les blocs.
|
||||||
|
ribErrors.value = []
|
||||||
try {
|
try {
|
||||||
await api.patch(`/clients/${clientId.value}`, {
|
// 1) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||||
siren: accounting.siren || null,
|
try {
|
||||||
accountNumber: accounting.accountNumber || null,
|
await api.patch(`/clients/${clientId.value}`, {
|
||||||
tvaMode: accounting.tvaModeIri,
|
siren: accounting.siren || null,
|
||||||
nTva: accounting.nTva || null,
|
accountNumber: accounting.accountNumber || null,
|
||||||
paymentDelay: accounting.paymentDelayIri,
|
tvaMode: accounting.tvaModeIri,
|
||||||
paymentType: accounting.paymentTypeIri,
|
nTva: accounting.nTva || null,
|
||||||
bank: isBankRequired.value ? accounting.bankIri : null,
|
paymentDelay: accounting.paymentDelayIri,
|
||||||
}, { toast: false })
|
paymentType: accounting.paymentTypeIri,
|
||||||
|
bank: isBankRequired.value ? accounting.bankIri : null,
|
||||||
for (const rib of ribs.value) {
|
}, { toast: false })
|
||||||
if (!ribIsComplete(rib)) continue
|
|
||||||
if (rib.id === null) {
|
|
||||||
const created = await api.post<{ id: number }>(
|
|
||||||
`/clients/${clientId.value}/ribs`,
|
|
||||||
{ label: rib.label, bic: rib.bic, iban: rib.iban },
|
|
||||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
|
||||||
)
|
|
||||||
rib.id = created.id
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
await api.patch(`/client_ribs/${rib.id}`, { label: rib.label, bic: rib.bic, iban: rib.iban }, { toast: false })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (error) {
|
||||||
|
accountingErrors.handleApiError(error, { fallbackMessage: t('commercial.clients.toast.error') })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) POST/PATCH des RIB (erreurs inline par ligne, tous les blocs tentes).
|
||||||
|
// Seuls les blocs RIB TOTALEMENT vides sont ignores : un RIB partiel (ex.
|
||||||
|
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
||||||
|
const ribHasError = await submitRows(
|
||||||
|
ribs.value,
|
||||||
|
ribErrors,
|
||||||
|
async (rib) => {
|
||||||
|
const body = { label: rib.label, bic: rib.bic, iban: rib.iban }
|
||||||
|
if (rib.id === null) {
|
||||||
|
const created = await api.post<{ id: number }>(
|
||||||
|
`/clients/${clientId.value}/ribs`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
rib.id = created.id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/client_ribs/${rib.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
|
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||||
|
// RIB existant vide est soumis -> 422 NotBlank inline (sinon la modif
|
||||||
|
// serait perdue en silence avec un faux toast de succes).
|
||||||
|
rib => rib.id === null && isRibBlank(rib),
|
||||||
|
)
|
||||||
|
if (ribHasError) return
|
||||||
|
|
||||||
completeTab('accounting')
|
completeTab('accounting')
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
catch (error) {
|
|
||||||
toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) })
|
|
||||||
}
|
|
||||||
finally {
|
finally {
|
||||||
tabSubmitting.value = false
|
tabSubmitting.value = false
|
||||||
}
|
}
|
||||||
@@ -941,11 +977,6 @@ function runConfirm(): void {
|
|||||||
interface ClientResponse {
|
interface ClientResponse {
|
||||||
id: number
|
id: number
|
||||||
companyName: string | null
|
companyName: string | null
|
||||||
firstName: string | null
|
|
||||||
lastName: string | null
|
|
||||||
email: string | null
|
|
||||||
phonePrimary: string | null
|
|
||||||
phoneSecondary: string | null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContactResponse {
|
interface ContactResponse {
|
||||||
@@ -956,5 +987,8 @@ interface ContactResponse {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// Echec du chargement des referentiels non bloquant : les selects restent vides.
|
// Echec du chargement des referentiels non bloquant : les selects restent vides.
|
||||||
referentials.loadCommon().catch(() => {})
|
referentials.loadCommon().catch(() => {})
|
||||||
|
// Au moins un bloc RIB toujours visible en creation : on amorce un bloc vide
|
||||||
|
// (non persiste tant qu'incomplet — RG-1.13).
|
||||||
|
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,235 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import {
|
||||||
|
canEditClient,
|
||||||
|
categoryOptionsOf,
|
||||||
|
contactOptionsOf,
|
||||||
|
iriOf,
|
||||||
|
mapAccountingDraft,
|
||||||
|
mapAddressToDraft,
|
||||||
|
mapAddressView,
|
||||||
|
mapContactToDraft,
|
||||||
|
mapRibToDraft,
|
||||||
|
referentialOptionOf,
|
||||||
|
relationOf,
|
||||||
|
showArchiveAction,
|
||||||
|
showRestoreAction,
|
||||||
|
siteOptionsOf,
|
||||||
|
type ClientDetail,
|
||||||
|
} from '../clientConsultation'
|
||||||
|
|
||||||
|
describe('iriOf', () => {
|
||||||
|
it('retourne l\'@id d\'une relation embarquee (objet)', () => {
|
||||||
|
expect(iriOf({ '@id': '/api/payment_types/10', code: 'LCR' })).toBe('/api/payment_types/10')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne la chaine telle quelle si la relation est deja un IRI', () => {
|
||||||
|
expect(iriOf('/api/banks/3')).toBe('/api/banks/3')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne null pour une relation absente (null / undefined / skip_null_values)', () => {
|
||||||
|
expect(iriOf(null)).toBeNull()
|
||||||
|
expect(iriOf(undefined)).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('relationOf', () => {
|
||||||
|
it('detecte une relation distributeur et expose son nom', () => {
|
||||||
|
const client = { distributor: { '@id': '/api/clients/15', companyName: 'DISTRIB GRAND SUD-OUEST' } } as ClientDetail
|
||||||
|
expect(relationOf(client)).toEqual({ type: 'distributeur', name: 'DISTRIB GRAND SUD-OUEST' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('detecte une relation courtier et expose son nom', () => {
|
||||||
|
const client = { broker: { '@id': '/api/clients/16', companyName: 'CABINET LEONARD' } } as ClientDetail
|
||||||
|
expect(relationOf(client)).toEqual({ type: 'courtier', name: 'CABINET LEONARD' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne type null quand aucune relation n\'est posee (cles omises)', () => {
|
||||||
|
expect(relationOf({} as ClientDetail)).toEqual({ type: null, name: null })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mapContactToDraft', () => {
|
||||||
|
it('formate les telephones en XX XX XX XX XX et conserve l\'iri', () => {
|
||||||
|
const draft = mapContactToDraft({
|
||||||
|
'@id': '/api/client_contacts/18',
|
||||||
|
id: 18,
|
||||||
|
firstName: 'Sophie',
|
||||||
|
lastName: 'Léonard',
|
||||||
|
jobTitle: 'Gérante',
|
||||||
|
phonePrimary: '0549112233',
|
||||||
|
email: 'sophie@x.fr',
|
||||||
|
})
|
||||||
|
expect(draft.id).toBe(18)
|
||||||
|
expect(draft.iri).toBe('/api/client_contacts/18')
|
||||||
|
expect(draft.phonePrimary).toBe('05 49 11 22 33')
|
||||||
|
expect(draft.hasSecondaryPhone).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('revele le 2e telephone quand phoneSecondary est present', () => {
|
||||||
|
const draft = mapContactToDraft({
|
||||||
|
'@id': '/api/client_contacts/19',
|
||||||
|
id: 19,
|
||||||
|
phonePrimary: '0600000000',
|
||||||
|
phoneSecondary: '0611111111',
|
||||||
|
})
|
||||||
|
expect(draft.hasSecondaryPhone).toBe(true)
|
||||||
|
expect(draft.phoneSecondary).toBe('06 11 11 11 11')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mapAddressToDraft', () => {
|
||||||
|
it('extrait les iris de sites / categories / contacts (objets ou chaines)', () => {
|
||||||
|
const draft = mapAddressToDraft({
|
||||||
|
'@id': '/api/client_addresses/18',
|
||||||
|
id: 18,
|
||||||
|
country: 'France',
|
||||||
|
postalCode: '86100',
|
||||||
|
city: 'Châtellerault',
|
||||||
|
street: '5 rue des Courtiers',
|
||||||
|
billingEmail: 'factures@x.fr',
|
||||||
|
isProspect: false,
|
||||||
|
isDelivery: false,
|
||||||
|
isBilling: true,
|
||||||
|
sites: [{ '@id': '/api/sites/4', name: 'Chatellerault', color: '#056CF2' }],
|
||||||
|
categories: [{ '@id': '/api/categories/3', code: 'SECTEUR' }],
|
||||||
|
contacts: [{ '@id': '/api/client_contacts/18' }, '/api/client_contacts/20'],
|
||||||
|
})
|
||||||
|
expect(draft.siteIris).toEqual(['/api/sites/4'])
|
||||||
|
expect(draft.categoryIris).toEqual(['/api/categories/3'])
|
||||||
|
expect(draft.contactIris).toEqual(['/api/client_contacts/18', '/api/client_contacts/20'])
|
||||||
|
expect(draft.isBilling).toBe(true)
|
||||||
|
expect(draft.city).toBe('Châtellerault')
|
||||||
|
expect(draft.country).toBe('France')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('tolere les sous-collections absentes (defaut tableau vide, pays France)', () => {
|
||||||
|
const draft = mapAddressToDraft({ '@id': '/api/client_addresses/9', id: 9 })
|
||||||
|
expect(draft.siteIris).toEqual([])
|
||||||
|
expect(draft.categoryIris).toEqual([])
|
||||||
|
expect(draft.contactIris).toEqual([])
|
||||||
|
expect(draft.country).toBe('France')
|
||||||
|
expect(draft.isBilling).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mapRibToDraft', () => {
|
||||||
|
it('mappe label / bic / iban et l\'id serveur', () => {
|
||||||
|
const draft = mapRibToDraft({ '@id': '/api/client_ribs/3', id: 3, label: 'Compte', bic: 'BNPAFRPPXXX', iban: 'FR14...' })
|
||||||
|
expect(draft).toEqual({ id: 3, label: 'Compte', bic: 'BNPAFRPPXXX', iban: 'FR14...' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mapAccountingDraft', () => {
|
||||||
|
it('mappe les scalaires et resout les iris des referentiels embarques', () => {
|
||||||
|
const acc = mapAccountingDraft({
|
||||||
|
'@id': '/api/clients/1',
|
||||||
|
id: 1,
|
||||||
|
siren: '123456789',
|
||||||
|
accountNumber: '411000',
|
||||||
|
nTva: 'FR123',
|
||||||
|
tvaMode: { '@id': '/api/tva_modes/1' },
|
||||||
|
paymentDelay: { '@id': '/api/payment_delays/2' },
|
||||||
|
paymentType: { '@id': '/api/payment_types/10', code: 'LCR' },
|
||||||
|
bank: { '@id': '/api/banks/3' },
|
||||||
|
} as ClientDetail)
|
||||||
|
expect(acc).toEqual({
|
||||||
|
siren: '123456789',
|
||||||
|
accountNumber: '411000',
|
||||||
|
nTva: 'FR123',
|
||||||
|
tvaModeIri: '/api/tva_modes/1',
|
||||||
|
paymentDelayIri: '/api/payment_delays/2',
|
||||||
|
paymentTypeIri: '/api/payment_types/10',
|
||||||
|
bankIri: '/api/banks/3',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renvoie des null quand les champs comptables sont absents (sans accounting.view)', () => {
|
||||||
|
const acc = mapAccountingDraft({} as ClientDetail)
|
||||||
|
expect(acc).toEqual({
|
||||||
|
siren: null,
|
||||||
|
accountNumber: null,
|
||||||
|
nTva: null,
|
||||||
|
tvaModeIri: null,
|
||||||
|
paymentDelayIri: null,
|
||||||
|
paymentTypeIri: null,
|
||||||
|
bankIri: null,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('options construites depuis l\'embed (role-independantes)', () => {
|
||||||
|
it('categoryOptionsOf expose value=IRI, label=nom, code', () => {
|
||||||
|
expect(categoryOptionsOf([{ '@id': '/api/categories/3', name: 'Secteur', code: 'SECTEUR' }])).toEqual([
|
||||||
|
{ value: '/api/categories/3', label: 'Secteur', code: 'SECTEUR' },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('siteOptionsOf expose value=IRI, label=nom', () => {
|
||||||
|
expect(siteOptionsOf([{ '@id': '/api/sites/4', name: 'Chatellerault', color: '#000' }])).toEqual([
|
||||||
|
{ value: '/api/sites/4', label: 'Chatellerault' },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('contactOptionsOf compose le libelle (nom complet, sinon email)', () => {
|
||||||
|
expect(contactOptionsOf([
|
||||||
|
{ '@id': '/api/client_contacts/1', id: 1, firstName: 'Jean', lastName: 'Dupont' },
|
||||||
|
{ '@id': '/api/client_contacts/2', id: 2, email: 'a@b.fr' },
|
||||||
|
])).toEqual([
|
||||||
|
{ value: '/api/client_contacts/1', label: 'Jean Dupont' },
|
||||||
|
{ value: '/api/client_contacts/2', label: 'a@b.fr' },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('referentialOptionOf : option unique depuis l\'embed, vide pour IRI nu / absent', () => {
|
||||||
|
expect(referentialOptionOf({ '@id': '/api/payment_types/10', label: 'LCR' })).toEqual([
|
||||||
|
{ value: '/api/payment_types/10', label: 'LCR' },
|
||||||
|
])
|
||||||
|
expect(referentialOptionOf('/api/banks/3')).toEqual([])
|
||||||
|
expect(referentialOptionOf(null)).toEqual([])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('mapAddressView assemble brouillon + options propres a l\'adresse', () => {
|
||||||
|
const view = mapAddressView({
|
||||||
|
'@id': '/api/client_addresses/18',
|
||||||
|
id: 18,
|
||||||
|
city: 'Châtellerault',
|
||||||
|
sites: [{ '@id': '/api/sites/4', name: 'Chatellerault' }],
|
||||||
|
categories: [{ '@id': '/api/categories/3', name: 'Secteur', code: 'SECTEUR' }],
|
||||||
|
})
|
||||||
|
expect(view.draft.id).toBe(18)
|
||||||
|
expect(view.siteOptions).toEqual([{ value: '/api/sites/4', label: 'Chatellerault' }])
|
||||||
|
expect(view.categoryOptions).toEqual([{ value: '/api/categories/3', label: 'Secteur', code: 'SECTEUR' }])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('canEditClient', () => {
|
||||||
|
const can = (granted: string[]) => (codes: string[]) => codes.some(c => granted.includes(c))
|
||||||
|
|
||||||
|
it('visible pour manage', () => {
|
||||||
|
expect(canEditClient(can(['commercial.clients.manage']))).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('visible pour accounting.manage (role Compta)', () => {
|
||||||
|
expect(canEditClient(can(['commercial.clients.accounting.manage']))).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('masque sans aucune des deux permissions (role Usine)', () => {
|
||||||
|
expect(canEditClient(can(['commercial.clients.view']))).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('showArchiveAction / showRestoreAction', () => {
|
||||||
|
const can = (granted: string[]) => (code: string) => granted.includes(code)
|
||||||
|
|
||||||
|
it('Archiver : visible avec la permission archive ET client non archive', () => {
|
||||||
|
expect(showArchiveAction(can(['commercial.clients.archive']), false)).toBe(true)
|
||||||
|
expect(showArchiveAction(can(['commercial.clients.archive']), true)).toBe(false)
|
||||||
|
expect(showArchiveAction(can([]), false)).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Restaurer : visible avec la permission archive ET client archive', () => {
|
||||||
|
expect(showRestoreAction(can(['commercial.clients.archive']), true)).toBe(true)
|
||||||
|
expect(showRestoreAction(can(['commercial.clients.archive']), false)).toBe(false)
|
||||||
|
expect(showRestoreAction(can([]), true)).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,241 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import {
|
||||||
|
buildAccountingPayload,
|
||||||
|
buildAddressPayload,
|
||||||
|
buildContactPayload,
|
||||||
|
buildInformationPayload,
|
||||||
|
buildMainPayload,
|
||||||
|
buildRibPayload,
|
||||||
|
mapAccountingFormDraft,
|
||||||
|
mapInformationDraft,
|
||||||
|
mapMainDraft,
|
||||||
|
resolveTabEditability,
|
||||||
|
type AccountingFormDraft,
|
||||||
|
type InformationFormDraft,
|
||||||
|
type MainFormDraft,
|
||||||
|
} from '../clientEdit'
|
||||||
|
import type { ClientDetail } from '../clientConsultation'
|
||||||
|
import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules/commercial/types/clientForm'
|
||||||
|
|
||||||
|
// ── Fabriques de brouillons (valeurs distinctes pour reperer les fuites) ─────
|
||||||
|
|
||||||
|
function mainDraft(overrides: Partial<MainFormDraft> = {}): MainFormDraft {
|
||||||
|
return {
|
||||||
|
companyName: 'ACME',
|
||||||
|
categoryIris: ['/api/categories/1'],
|
||||||
|
relationType: null,
|
||||||
|
distributorIri: null,
|
||||||
|
brokerIri: null,
|
||||||
|
triageService: false,
|
||||||
|
...overrides,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function informationDraft(overrides: Partial<InformationFormDraft> = {}): InformationFormDraft {
|
||||||
|
return {
|
||||||
|
description: 'desc',
|
||||||
|
competitors: 'concurrents',
|
||||||
|
foundedAt: '2010-05-01',
|
||||||
|
employeesCount: '42',
|
||||||
|
revenueAmount: '1000000',
|
||||||
|
profitAmount: '50000',
|
||||||
|
directorName: 'PDG',
|
||||||
|
...overrides,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function accountingDraft(overrides: Partial<AccountingFormDraft> = {}): AccountingFormDraft {
|
||||||
|
return {
|
||||||
|
siren: '123456789',
|
||||||
|
accountNumber: 'C-001',
|
||||||
|
nTva: 'FR123',
|
||||||
|
tvaModeIri: '/api/tva_modes/1',
|
||||||
|
paymentDelayIri: '/api/payment_delays/1',
|
||||||
|
paymentTypeIri: '/api/payment_types/1',
|
||||||
|
bankIri: '/api/banks/1',
|
||||||
|
...overrides,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Champs de chaque groupe de serialisation (miroir back ClientProcessor).
|
||||||
|
// Le contact inline (nom/prenom/telephones/email) ne fait plus partie du groupe
|
||||||
|
// main : les coordonnees vivent desormais sur la sous-ressource ClientContact.
|
||||||
|
const MAIN_KEYS = [
|
||||||
|
'companyName', 'categories', 'distributor', 'broker', 'triageService',
|
||||||
|
]
|
||||||
|
const INFORMATION_KEYS = [
|
||||||
|
'description', 'competitors', 'foundedAt', 'employeesCount',
|
||||||
|
'revenueAmount', 'profitAmount', 'directorName',
|
||||||
|
]
|
||||||
|
const ACCOUNTING_KEYS = ['siren', 'accountNumber', 'tvaMode', 'nTva', 'paymentDelay', 'paymentType', 'bank']
|
||||||
|
|
||||||
|
describe('buildMainPayload — scoping strict groupe client:write:main', () => {
|
||||||
|
it('n\'expose QUE les champs du groupe main (aucune fuite information/accounting)', () => {
|
||||||
|
expect(Object.keys(buildMainPayload(mainDraft())).sort()).toEqual([...MAIN_KEYS].sort())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('relation distributeur : renseigne distributor, force broker a null (RG-1.03)', () => {
|
||||||
|
const payload = buildMainPayload(mainDraft({
|
||||||
|
relationType: 'distributeur',
|
||||||
|
distributorIri: '/api/clients/9',
|
||||||
|
brokerIri: '/api/clients/7',
|
||||||
|
}))
|
||||||
|
expect(payload.distributor).toBe('/api/clients/9')
|
||||||
|
expect(payload.broker).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('relation courtier : renseigne broker, force distributor a null (RG-1.03)', () => {
|
||||||
|
const payload = buildMainPayload(mainDraft({
|
||||||
|
relationType: 'courtier',
|
||||||
|
distributorIri: '/api/clients/9',
|
||||||
|
brokerIri: '/api/clients/7',
|
||||||
|
}))
|
||||||
|
expect(payload.broker).toBe('/api/clients/7')
|
||||||
|
expect(payload.distributor).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sans relation : distributor et broker a null', () => {
|
||||||
|
const payload = buildMainPayload(mainDraft({ relationType: null }))
|
||||||
|
expect(payload.distributor).toBeNull()
|
||||||
|
expect(payload.broker).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('buildInformationPayload — scoping strict groupe client:write:information', () => {
|
||||||
|
it('n\'expose QUE les champs du groupe information (aucune fuite main/accounting)', () => {
|
||||||
|
expect(Object.keys(buildInformationPayload(informationDraft())).sort()).toEqual([...INFORMATION_KEYS].sort())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('convertit employeesCount en nombre et vide -> null', () => {
|
||||||
|
expect(buildInformationPayload(informationDraft({ employeesCount: '42' })).employeesCount).toBe(42)
|
||||||
|
expect(buildInformationPayload(informationDraft({ employeesCount: null })).employeesCount).toBeNull()
|
||||||
|
expect(buildInformationPayload(informationDraft({ employeesCount: '' })).employeesCount).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('chaines vides normalisees en null', () => {
|
||||||
|
const payload = buildInformationPayload(informationDraft({ description: '', directorName: '' }))
|
||||||
|
expect(payload.description).toBeNull()
|
||||||
|
expect(payload.directorName).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('buildAccountingPayload — scoping strict groupe client:write:accounting', () => {
|
||||||
|
it('n\'expose QUE les champs du groupe accounting (aucune fuite main/information)', () => {
|
||||||
|
expect(Object.keys(buildAccountingPayload(accountingDraft(), true)).sort()).toEqual([...ACCOUNTING_KEYS].sort())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('banque conservee si requise (Virement), forcee a null sinon (RG-1.12)', () => {
|
||||||
|
expect(buildAccountingPayload(accountingDraft(), true).bank).toBe('/api/banks/1')
|
||||||
|
expect(buildAccountingPayload(accountingDraft(), false).bank).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('buildContactPayload / buildAddressPayload / buildRibPayload', () => {
|
||||||
|
it('contact : telephone secondaire ignore si non revele', () => {
|
||||||
|
const contact: ContactFormDraft = {
|
||||||
|
id: 5, iri: '/api/client_contacts/5', firstName: 'A', lastName: 'B',
|
||||||
|
jobTitle: null, phonePrimary: '0549112233', phoneSecondary: '0600000000',
|
||||||
|
email: null, hasSecondaryPhone: false,
|
||||||
|
}
|
||||||
|
expect(buildContactPayload(contact).phoneSecondary).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('adresse : email facturation conserve uniquement si requis (RG-1.11)', () => {
|
||||||
|
const address: AddressFormDraft = {
|
||||||
|
id: 3, isProspect: false, isDelivery: false, isBilling: true, country: 'France',
|
||||||
|
postalCode: '86100', city: 'Châtellerault', street: '1 rue X', streetComplement: null,
|
||||||
|
categoryIris: ['/api/categories/2'], siteIris: ['/api/sites/1'], contactIris: [],
|
||||||
|
billingEmail: 'facturation@acme.fr',
|
||||||
|
}
|
||||||
|
expect(buildAddressPayload(address, true).billingEmail).toBe('facturation@acme.fr')
|
||||||
|
expect(buildAddressPayload(address, false).billingEmail).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('rib : label / bic / iban transmis tels quels', () => {
|
||||||
|
const rib: RibFormDraft = { id: 1, label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' }
|
||||||
|
expect(buildRibPayload(rib)).toEqual({ label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mapMainDraft — pre-remplissage bloc principal', () => {
|
||||||
|
it('resout la relation et extrait les IRI (sans contact inline)', () => {
|
||||||
|
const client = {
|
||||||
|
'@id': '/api/clients/1', id: 1,
|
||||||
|
companyName: 'ACME', triageService: true,
|
||||||
|
categories: [{ '@id': '/api/categories/1', code: 'SECTEUR' }],
|
||||||
|
distributor: { '@id': '/api/clients/9', companyName: 'DISTRIB' },
|
||||||
|
} as ClientDetail
|
||||||
|
|
||||||
|
const draft = mapMainDraft(client)
|
||||||
|
expect(draft.companyName).toBe('ACME')
|
||||||
|
expect(draft.categoryIris).toEqual(['/api/categories/1'])
|
||||||
|
expect(draft.relationType).toBe('distributeur')
|
||||||
|
expect(draft.distributorIri).toBe('/api/clients/9')
|
||||||
|
expect(draft.brokerIri).toBeNull()
|
||||||
|
expect(draft.triageService).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('gere les cles omises (skip_null_values) sans planter', () => {
|
||||||
|
const draft = mapMainDraft({ '@id': '/api/clients/2', id: 2 } as ClientDetail)
|
||||||
|
expect(draft.companyName).toBeNull()
|
||||||
|
expect(draft.categoryIris).toEqual([])
|
||||||
|
expect(draft.relationType).toBeNull()
|
||||||
|
expect(draft.triageService).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mapInformationDraft — pre-remplissage onglet Information', () => {
|
||||||
|
it('tronque foundedAt en YYYY-MM-DD et stringifie employeesCount', () => {
|
||||||
|
const draft = mapInformationDraft({
|
||||||
|
'@id': '/api/clients/1', id: 1,
|
||||||
|
foundedAt: '2010-05-01T00:00:00+00:00', employeesCount: 42, revenueAmount: '1000000',
|
||||||
|
} as ClientDetail)
|
||||||
|
expect(draft.foundedAt).toBe('2010-05-01')
|
||||||
|
expect(draft.employeesCount).toBe('42')
|
||||||
|
expect(draft.revenueAmount).toBe('1000000')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('cles omises -> null', () => {
|
||||||
|
const draft = mapInformationDraft({ '@id': '/api/clients/1', id: 1 } as ClientDetail)
|
||||||
|
expect(draft.foundedAt).toBeNull()
|
||||||
|
expect(draft.employeesCount).toBeNull()
|
||||||
|
expect(draft.description).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mapAccountingFormDraft — pre-remplissage onglet Comptabilite', () => {
|
||||||
|
it('extrait les scalaires et les IRI des referentiels embarques', () => {
|
||||||
|
const draft = mapAccountingFormDraft({
|
||||||
|
'@id': '/api/clients/1', id: 1,
|
||||||
|
siren: '123456789', accountNumber: 'C-001', nTva: 'FR123',
|
||||||
|
tvaMode: { '@id': '/api/tva_modes/2', label: 'Normal' },
|
||||||
|
paymentType: '/api/payment_types/3',
|
||||||
|
} as ClientDetail)
|
||||||
|
expect(draft.siren).toBe('123456789')
|
||||||
|
expect(draft.tvaModeIri).toBe('/api/tva_modes/2')
|
||||||
|
expect(draft.paymentTypeIri).toBe('/api/payment_types/3')
|
||||||
|
expect(draft.bankIri).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('resolveTabEditability — gating par role (matrice § 2.7)', () => {
|
||||||
|
it('Admin : tout editable', () => {
|
||||||
|
expect(resolveTabEditability({ canManage: true, canAccountingView: true, canAccountingManage: true }))
|
||||||
|
.toEqual({ businessEditable: true, accountingVisible: true, accountingEditable: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Bureau / Commerciale (manage seul) : metier editable, Comptabilite masquee', () => {
|
||||||
|
expect(resolveTabEditability({ canManage: true, canAccountingView: false, canAccountingManage: false }))
|
||||||
|
.toEqual({ businessEditable: true, accountingVisible: false, accountingEditable: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Compta (accounting seul) : metier readonly, Comptabilite editable', () => {
|
||||||
|
expect(resolveTabEditability({ canManage: false, canAccountingView: true, canAccountingManage: true }))
|
||||||
|
.toEqual({ businessEditable: false, accountingVisible: true, accountingEditable: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Sans permission d\'edition : rien d\'editable', () => {
|
||||||
|
expect(resolveTabEditability({ canManage: false, canAccountingView: false, canAccountingManage: false }))
|
||||||
|
.toEqual({ businessEditable: false, accountingVisible: false, accountingEditable: false })
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,17 +1,36 @@
|
|||||||
import { describe, it, expect } from 'vitest'
|
import { describe, it, expect } from 'vitest'
|
||||||
import {
|
import {
|
||||||
|
addressFlagsFromType,
|
||||||
|
addressTypeFromFlags,
|
||||||
applyProspectExclusivity,
|
applyProspectExclusivity,
|
||||||
buildClientFormTabKeys,
|
buildClientFormTabKeys,
|
||||||
canSelectDeliveryOrBilling,
|
canSelectDeliveryOrBilling,
|
||||||
canSelectProspect,
|
canSelectProspect,
|
||||||
|
hasAllRequiredAccountingFields,
|
||||||
hasAtLeastOneValidContact,
|
hasAtLeastOneValidContact,
|
||||||
isBankRequiredForPaymentType,
|
isBankRequiredForPaymentType,
|
||||||
isBillingEmailRequired,
|
isBillingEmailRequired,
|
||||||
|
isBlankRow,
|
||||||
|
isContactBlank,
|
||||||
isContactNamed,
|
isContactNamed,
|
||||||
|
isRibBlank,
|
||||||
isRibRequiredForPaymentType,
|
isRibRequiredForPaymentType,
|
||||||
type ContactDraft,
|
type ContactDraft,
|
||||||
|
type ContactFillableDraft,
|
||||||
} from '../clientFormRules'
|
} from '../clientFormRules'
|
||||||
|
|
||||||
|
/** Bloc contact totalement vide (amorce par defaut). */
|
||||||
|
function blankContact(): ContactFillableDraft {
|
||||||
|
return {
|
||||||
|
firstName: null,
|
||||||
|
lastName: null,
|
||||||
|
jobTitle: null,
|
||||||
|
phonePrimary: null,
|
||||||
|
phoneSecondary: null,
|
||||||
|
email: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe('buildClientFormTabKeys (gating onglet Comptabilite + onglets edit-only)', () => {
|
describe('buildClientFormTabKeys (gating onglet Comptabilite + onglets edit-only)', () => {
|
||||||
it('inclut l onglet accounting si l utilisateur a accounting.view', () => {
|
it('inclut l onglet accounting si l utilisateur a accounting.view', () => {
|
||||||
expect(buildClientFormTabKeys(true)).toContain('accounting')
|
expect(buildClientFormTabKeys(true)).toContain('accounting')
|
||||||
@@ -59,6 +78,49 @@ describe('isContactNamed (RG-1.05)', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('isBlankRow (primitive : toutes les valeurs vides)', () => {
|
||||||
|
it('vrai si toutes les valeurs sont nulles / vides / espaces', () => {
|
||||||
|
expect(isBlankRow([null, undefined, '', ' '])).toBe(true)
|
||||||
|
expect(isBlankRow([])).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux des qu une valeur porte un caractere non-espace', () => {
|
||||||
|
expect(isBlankRow([null, 'x', ''])).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('isRibBlank (bloc RIB totalement vide vs partiellement rempli)', () => {
|
||||||
|
it('vrai si label / bic / iban sont tous vides', () => {
|
||||||
|
expect(isRibBlank({ label: null, bic: null, iban: null })).toBe(true)
|
||||||
|
expect(isRibBlank({ label: ' ', bic: '', iban: null })).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si un IBAN seul est saisi (bloc a soumettre -> 422 NotBlank inline)', () => {
|
||||||
|
expect(isRibBlank({ label: null, bic: null, iban: 'FR1420041010050500013M02606' })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si seul le libelle est saisi', () => {
|
||||||
|
expect(isRibBlank({ label: 'Compte courant', bic: null, iban: null })).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('isContactBlank (bloc totalement vide vs partiellement rempli)', () => {
|
||||||
|
it('vrai si aucun champ saisissable n est rempli', () => {
|
||||||
|
expect(isContactBlank(blankContact())).toBe(true)
|
||||||
|
expect(isContactBlank({ ...blankContact(), firstName: ' ', email: '' })).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si un email seul est saisi (bloc a soumettre -> 422 RG-1.05 inline)', () => {
|
||||||
|
expect(isContactBlank({ ...blankContact(), email: 'jean@acme.fr' })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si seul un telephone, une fonction ou un nom est saisi', () => {
|
||||||
|
expect(isContactBlank({ ...blankContact(), phonePrimary: '0612345678' })).toBe(false)
|
||||||
|
expect(isContactBlank({ ...blankContact(), jobTitle: 'Directeur' })).toBe(false)
|
||||||
|
expect(isContactBlank({ ...blankContact(), firstName: 'Alice' })).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('hasAtLeastOneValidContact (RG-1.14)', () => {
|
describe('hasAtLeastOneValidContact (RG-1.14)', () => {
|
||||||
it('faux sur une liste vide', () => {
|
it('faux sur une liste vide', () => {
|
||||||
expect(hasAtLeastOneValidContact([])).toBe(false)
|
expect(hasAtLeastOneValidContact([])).toBe(false)
|
||||||
@@ -137,6 +199,32 @@ describe('isBillingEmailRequired (RG-1.11)', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('type d\'adresse (Select front) <-> drapeaux back', () => {
|
||||||
|
it('addressFlagsFromType mappe chaque type vers les bons drapeaux', () => {
|
||||||
|
expect(addressFlagsFromType('prospect')).toEqual({ isProspect: true, isDelivery: false, isBilling: false })
|
||||||
|
expect(addressFlagsFromType('delivery')).toEqual({ isProspect: false, isDelivery: true, isBilling: false })
|
||||||
|
expect(addressFlagsFromType('billing')).toEqual({ isProspect: false, isDelivery: false, isBilling: true })
|
||||||
|
expect(addressFlagsFromType('delivery_billing')).toEqual({ isProspect: false, isDelivery: true, isBilling: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('addressTypeFromFlags reconstruit le type (Prospect prioritaire, livraison+facturation groupes)', () => {
|
||||||
|
expect(addressTypeFromFlags({ isProspect: true, isDelivery: false, isBilling: false })).toBe('prospect')
|
||||||
|
expect(addressTypeFromFlags({ isProspect: false, isDelivery: true, isBilling: false })).toBe('delivery')
|
||||||
|
expect(addressTypeFromFlags({ isProspect: false, isDelivery: false, isBilling: true })).toBe('billing')
|
||||||
|
expect(addressTypeFromFlags({ isProspect: false, isDelivery: true, isBilling: true })).toBe('delivery_billing')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('addressTypeFromFlags retourne null quand aucun drapeau (amorce vierge -> bouton bloque)', () => {
|
||||||
|
expect(addressTypeFromFlags({ isProspect: false, isDelivery: false, isBilling: false })).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('aller-retour type -> drapeaux -> type stable pour les 4 types', () => {
|
||||||
|
for (const type of ['prospect', 'delivery', 'billing', 'delivery_billing'] as const) {
|
||||||
|
expect(addressTypeFromFlags(addressFlagsFromType(type))).toBe(type)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('regles type de reglement (RG-1.12 / RG-1.13)', () => {
|
describe('regles type de reglement (RG-1.12 / RG-1.13)', () => {
|
||||||
it('banque obligatoire si VIREMENT', () => {
|
it('banque obligatoire si VIREMENT', () => {
|
||||||
expect(isBankRequiredForPaymentType('VIREMENT')).toBe(true)
|
expect(isBankRequiredForPaymentType('VIREMENT')).toBe(true)
|
||||||
@@ -150,3 +238,36 @@ describe('regles type de reglement (RG-1.12 / RG-1.13)', () => {
|
|||||||
expect(isRibRequiredForPaymentType(null)).toBe(false)
|
expect(isRibRequiredForPaymentType(null)).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('hasAllRequiredAccountingFields (RG-1.30)', () => {
|
||||||
|
const complete = {
|
||||||
|
siren: '123456789',
|
||||||
|
accountNumber: '00012345678',
|
||||||
|
nTva: 'FR12345678901',
|
||||||
|
tvaModeIri: '/api/tva_modes/1',
|
||||||
|
paymentDelayIri: '/api/payment_delays/1',
|
||||||
|
paymentTypeIri: '/api/payment_types/1',
|
||||||
|
}
|
||||||
|
|
||||||
|
it('vrai quand les six champs obligatoires sont remplis', () => {
|
||||||
|
expect(hasAllRequiredAccountingFields(complete)).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si un champ est manquant (null ou vide apres trim)', () => {
|
||||||
|
expect(hasAllRequiredAccountingFields({ ...complete, siren: null })).toBe(false)
|
||||||
|
expect(hasAllRequiredAccountingFields({ ...complete, accountNumber: ' ' })).toBe(false)
|
||||||
|
expect(hasAllRequiredAccountingFields({ ...complete, tvaModeIri: null })).toBe(false)
|
||||||
|
expect(hasAllRequiredAccountingFields({ ...complete, paymentTypeIri: null })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux quand tout est vide (onglet non rempli)', () => {
|
||||||
|
expect(hasAllRequiredAccountingFields({
|
||||||
|
siren: null,
|
||||||
|
accountNumber: null,
|
||||||
|
nTva: null,
|
||||||
|
tvaModeIri: null,
|
||||||
|
paymentDelayIri: null,
|
||||||
|
paymentTypeIri: null,
|
||||||
|
})).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -0,0 +1,316 @@
|
|||||||
|
/**
|
||||||
|
* Helpers purs de l'ecran « Consultation client » (M1 Commercial, lecture seule).
|
||||||
|
*
|
||||||
|
* Mappent le payload `GET /api/clients/{id}` (relations embarquees, cf. groupe
|
||||||
|
* `client:item:read` + `client:read:accounting`) vers les brouillons « plats »
|
||||||
|
* partages avec les blocs reutilisables `ClientContactBlock` / `ClientAddressBlock`
|
||||||
|
* et l'onglet Comptabilite. Ne touchent ni a l'API ni a l'etat reactif : testables
|
||||||
|
* unitairement (cf. clientConsultation.spec.ts).
|
||||||
|
*
|
||||||
|
* Rappels de contrat back (verifies sur l'API reelle) :
|
||||||
|
* - les relations ManyToOne (distributor/broker/tvaMode/paymentType/...) sont
|
||||||
|
* serialisees en OBJETS embarques (avec @id + companyName/code/label), pas en IRI nu ;
|
||||||
|
* - les champs nuls sont OMIS du JSON (skip_null_values) → toujours lire avec `?? null` ;
|
||||||
|
* - les champs comptables et `ribs` sont TOTALEMENT ABSENTS sans permission
|
||||||
|
* accounting.view (gate serveur via ClientReadGroupContextBuilder).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { formatPhoneFR } from '~/shared/utils/phone'
|
||||||
|
import type {
|
||||||
|
AddressFormDraft,
|
||||||
|
ContactFormDraft,
|
||||||
|
RibFormDraft,
|
||||||
|
} from '~/modules/commercial/types/clientForm'
|
||||||
|
|
||||||
|
/** Reference Hydra embarquee minimale (@id toujours present). */
|
||||||
|
export interface HydraRef {
|
||||||
|
'@id': string
|
||||||
|
[key: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Une relation peut etre embarquee (objet), un IRI nu (chaine) ou absente. */
|
||||||
|
export type Relation = HydraRef | string | null | undefined
|
||||||
|
|
||||||
|
/** Site embarque dans une adresse (groupe site:read). */
|
||||||
|
export interface SiteRead extends HydraRef {
|
||||||
|
name?: string
|
||||||
|
color?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Categorie embarquee (groupe category:read). */
|
||||||
|
export interface CategoryRead extends HydraRef {
|
||||||
|
code?: string
|
||||||
|
name?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Contact embarque (groupe client_contact:read). */
|
||||||
|
export interface ContactRead extends HydraRef {
|
||||||
|
id: number
|
||||||
|
firstName?: string | null
|
||||||
|
lastName?: string | null
|
||||||
|
jobTitle?: string | null
|
||||||
|
phonePrimary?: string | null
|
||||||
|
phoneSecondary?: string | null
|
||||||
|
email?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adresse embarquee (groupe client_address:read). */
|
||||||
|
export interface AddressRead extends HydraRef {
|
||||||
|
id: number
|
||||||
|
country?: string | null
|
||||||
|
postalCode?: string | null
|
||||||
|
city?: string | null
|
||||||
|
street?: string | null
|
||||||
|
streetComplement?: string | null
|
||||||
|
billingEmail?: string | null
|
||||||
|
isProspect?: boolean
|
||||||
|
isDelivery?: boolean
|
||||||
|
isBilling?: boolean
|
||||||
|
sites?: SiteRead[]
|
||||||
|
categories?: CategoryRead[]
|
||||||
|
// L'embed M2M des contacts d'adresse peut etre un objet (partiel) ou un IRI nu.
|
||||||
|
contacts?: Array<HydraRef | string>
|
||||||
|
}
|
||||||
|
|
||||||
|
/** RIB embarque (groupe client:read:accounting, present ssi accounting.view). */
|
||||||
|
export interface RibRead extends HydraRef {
|
||||||
|
id: number
|
||||||
|
label?: string | null
|
||||||
|
bic?: string | null
|
||||||
|
iban?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Client relie (distributeur / courtier) embarque (groupe client:read). */
|
||||||
|
export interface RelatedClientRead extends HydraRef {
|
||||||
|
companyName?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detail d'un client tel que renvoye par `GET /api/clients/{id}`. Tous les
|
||||||
|
* champs sont optionnels : skip_null_values cote serveur et gating accounting
|
||||||
|
* peuvent omettre n'importe quelle cle.
|
||||||
|
*/
|
||||||
|
export interface ClientDetail extends HydraRef {
|
||||||
|
id: number
|
||||||
|
companyName?: string | null
|
||||||
|
triageService?: boolean
|
||||||
|
isArchived?: boolean
|
||||||
|
categories?: CategoryRead[]
|
||||||
|
distributor?: RelatedClientRead | string | null
|
||||||
|
broker?: RelatedClientRead | string | null
|
||||||
|
contacts?: ContactRead[]
|
||||||
|
addresses?: AddressRead[]
|
||||||
|
ribs?: RibRead[]
|
||||||
|
// Onglet Information
|
||||||
|
description?: string | null
|
||||||
|
competitors?: string | null
|
||||||
|
foundedAt?: string | null
|
||||||
|
employeesCount?: number | null
|
||||||
|
revenueAmount?: string | null
|
||||||
|
profitAmount?: string | null
|
||||||
|
directorName?: string | null
|
||||||
|
// Onglet Comptabilite (present ssi accounting.view)
|
||||||
|
siren?: string | null
|
||||||
|
accountNumber?: string | null
|
||||||
|
nTva?: string | null
|
||||||
|
tvaMode?: Relation
|
||||||
|
paymentDelay?: Relation
|
||||||
|
paymentType?: Relation
|
||||||
|
bank?: Relation
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Etat « plat » de l'onglet Comptabilite (miroir lecture du formulaire 1.10). */
|
||||||
|
export interface AccountingDraft {
|
||||||
|
siren: string | null
|
||||||
|
accountNumber: string | null
|
||||||
|
nTva: string | null
|
||||||
|
tvaModeIri: string | null
|
||||||
|
paymentDelayIri: string | null
|
||||||
|
paymentTypeIri: string | null
|
||||||
|
bankIri: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Relation Distributeur/Courtier resolue pour l'affichage en lecture seule. */
|
||||||
|
export interface ClientRelation {
|
||||||
|
type: 'distributeur' | 'courtier' | null
|
||||||
|
name: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Option de select ({ value, label }) construite a partir de l'embed. */
|
||||||
|
export interface SelectOption {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Option de categorie enrichie de son code (compatible CategoryOption des blocs). */
|
||||||
|
export interface CategorySelectOption extends SelectOption {
|
||||||
|
code: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vue d'une adresse pour la consultation : le brouillon + ses options de select
|
||||||
|
* construites a partir de l'embed (sites/categories propres a CETTE adresse).
|
||||||
|
*/
|
||||||
|
export interface AddressView {
|
||||||
|
draft: AddressFormDraft
|
||||||
|
siteOptions: SelectOption[]
|
||||||
|
categoryOptions: CategorySelectOption[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extrait l'IRI d'une relation (objet embarque, IRI nu, ou null si absente). */
|
||||||
|
export function iriOf(relation: Relation): string | null {
|
||||||
|
if (relation === null || relation === undefined) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (typeof relation === 'string') {
|
||||||
|
return relation
|
||||||
|
}
|
||||||
|
return relation['@id'] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resout la relation Distributeur/Courtier (RG-1.03 : mutuellement exclusives).
|
||||||
|
* Le nom est lu sur l'objet embarque (`companyName`) ; null si la relation est
|
||||||
|
* un IRI nu ou absente.
|
||||||
|
*/
|
||||||
|
export function relationOf(client: ClientDetail): ClientRelation {
|
||||||
|
const nameOf = (rel: RelatedClientRead | string | null | undefined): string | null =>
|
||||||
|
rel && typeof rel === 'object' ? (rel.companyName ?? null) : null
|
||||||
|
|
||||||
|
if (client.distributor) {
|
||||||
|
return { type: 'distributeur', name: nameOf(client.distributor) }
|
||||||
|
}
|
||||||
|
if (client.broker) {
|
||||||
|
return { type: 'courtier', name: nameOf(client.broker) }
|
||||||
|
}
|
||||||
|
return { type: null, name: null }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mappe un contact embarque vers un brouillon (telephones formates XX XX XX XX XX). */
|
||||||
|
export function mapContactToDraft(contact: ContactRead): ContactFormDraft {
|
||||||
|
const phoneSecondary = contact.phoneSecondary ?? null
|
||||||
|
return {
|
||||||
|
id: contact.id,
|
||||||
|
iri: contact['@id'] ?? null,
|
||||||
|
firstName: contact.firstName ?? null,
|
||||||
|
lastName: contact.lastName ?? null,
|
||||||
|
jobTitle: contact.jobTitle ?? null,
|
||||||
|
phonePrimary: contact.phonePrimary ? formatPhoneFR(contact.phonePrimary) : null,
|
||||||
|
phoneSecondary: phoneSecondary ? formatPhoneFR(phoneSecondary) : null,
|
||||||
|
email: contact.email ?? null,
|
||||||
|
hasSecondaryPhone: phoneSecondary !== null && phoneSecondary !== '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mappe une adresse embarquee vers un brouillon (IRI extraits des sous-collections). */
|
||||||
|
export function mapAddressToDraft(address: AddressRead): AddressFormDraft {
|
||||||
|
return {
|
||||||
|
id: address.id,
|
||||||
|
isProspect: address.isProspect ?? false,
|
||||||
|
isDelivery: address.isDelivery ?? false,
|
||||||
|
isBilling: address.isBilling ?? false,
|
||||||
|
country: address.country ?? 'France',
|
||||||
|
postalCode: address.postalCode ?? null,
|
||||||
|
city: address.city ?? null,
|
||||||
|
street: address.street ?? null,
|
||||||
|
streetComplement: address.streetComplement ?? null,
|
||||||
|
categoryIris: (address.categories ?? []).map(c => c['@id']),
|
||||||
|
siteIris: (address.sites ?? []).map(s => s['@id']),
|
||||||
|
contactIris: (address.contacts ?? []).map(c => (typeof c === 'string' ? c : c['@id'])),
|
||||||
|
billingEmail: address.billingEmail ?? null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mappe un RIB embarque vers un brouillon. */
|
||||||
|
export function mapRibToDraft(rib: RibRead): RibFormDraft {
|
||||||
|
return {
|
||||||
|
id: rib.id,
|
||||||
|
label: rib.label ?? null,
|
||||||
|
bic: rib.bic ?? null,
|
||||||
|
iban: rib.iban ?? null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mappe les champs comptables du client (scalaires + IRI des referentiels). */
|
||||||
|
export function mapAccountingDraft(client: ClientDetail): AccountingDraft {
|
||||||
|
return {
|
||||||
|
siren: client.siren ?? null,
|
||||||
|
accountNumber: client.accountNumber ?? null,
|
||||||
|
nTva: client.nTva ?? null,
|
||||||
|
tvaModeIri: iriOf(client.tvaMode),
|
||||||
|
paymentDelayIri: iriOf(client.paymentDelay),
|
||||||
|
paymentTypeIri: iriOf(client.paymentType),
|
||||||
|
bankIri: iriOf(client.bank),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options de categories (value=IRI, label=nom, code) construites depuis l'embed.
|
||||||
|
* Source role-independante : evite de dependre de `GET /categories` (403 pour les
|
||||||
|
* roles metier non-admin), qui laisserait les libelles vides.
|
||||||
|
*/
|
||||||
|
export function categoryOptionsOf(categories: CategoryRead[] | undefined): CategorySelectOption[] {
|
||||||
|
return (categories ?? []).map(c => ({
|
||||||
|
value: c['@id'],
|
||||||
|
label: c.name ?? c.code ?? c['@id'],
|
||||||
|
code: c.code ?? '',
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Options de sites (value=IRI, label=nom) construites depuis l'embed d'une adresse. */
|
||||||
|
export function siteOptionsOf(sites: SiteRead[] | undefined): SelectOption[] {
|
||||||
|
return (sites ?? []).map(s => ({ value: s['@id'], label: s.name ?? s['@id'] }))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Options de contacts (value=IRI, label=nom complet ou email) depuis l'embed client. */
|
||||||
|
export function contactOptionsOf(contacts: ContactRead[] | undefined): SelectOption[] {
|
||||||
|
return (contacts ?? []).map(c => ({
|
||||||
|
value: c['@id'],
|
||||||
|
label: [c.firstName, c.lastName].filter(Boolean).join(' ') || (c.email ?? c['@id']),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste a une seule option (ou vide) construite depuis un referentiel embarque
|
||||||
|
* (TvaMode / PaymentDelay / PaymentType / Bank) pour alimenter un MalioSelect en
|
||||||
|
* lecture seule. Le libelle vient de l'embed (`label` ou `name`), jamais d'un
|
||||||
|
* `GET` de referentiel — l'affichage reste correct quel que soit le role.
|
||||||
|
*/
|
||||||
|
export function referentialOptionOf(relation: Relation): SelectOption[] {
|
||||||
|
if (!relation || typeof relation === 'string') {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const label = (relation.label as string | undefined)
|
||||||
|
?? (relation.name as string | undefined)
|
||||||
|
?? relation['@id']
|
||||||
|
return [{ value: relation['@id'], label }]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Vue d'une adresse (brouillon + options de select propres a l'adresse). */
|
||||||
|
export function mapAddressView(address: AddressRead): AddressView {
|
||||||
|
return {
|
||||||
|
draft: mapAddressToDraft(address),
|
||||||
|
siteOptions: siteOptionsOf(address.sites),
|
||||||
|
categoryOptions: categoryOptionsOf(address.categories),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bouton « Modifier » : visible si l'utilisateur peut editer au moins un onglet
|
||||||
|
* — `manage` (formulaire/onglets metier) OU `accounting.manage` (le role Compta
|
||||||
|
* doit pouvoir ouvrir l'edition pour son onglet Comptabilite). Le readonly fin
|
||||||
|
* par onglet est gere sur l'ecran d'edition (1.12).
|
||||||
|
*/
|
||||||
|
export function canEditClient(canAny: (codes: string[]) => boolean): boolean {
|
||||||
|
return canAny(['commercial.clients.manage', 'commercial.clients.accounting.manage'])
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bouton « Archiver » : permission archive ET client encore actif. */
|
||||||
|
export function showArchiveAction(can: (code: string) => boolean, isArchived: boolean): boolean {
|
||||||
|
return can('commercial.clients.archive') && !isArchived
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bouton « Restaurer » : permission archive ET client deja archive. */
|
||||||
|
export function showRestoreAction(can: (code: string) => boolean, isArchived: boolean): boolean {
|
||||||
|
return can('commercial.clients.archive') && isArchived
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
/**
|
||||||
|
* Helpers purs de l'ecran « Modification client » (M1 Commercial, 1.12).
|
||||||
|
*
|
||||||
|
* Deux responsabilites, toutes deux testables unitairement (cf. clientEdit.spec.ts) :
|
||||||
|
* 1. Pre-remplissage : mapper le payload `GET /api/clients/{id}` (embed
|
||||||
|
* contacts/adresses/ribs + scalaires) vers les brouillons « plats » edites
|
||||||
|
* par la page et les blocs reutilisables (mappers contacts/adresses/ribs/
|
||||||
|
* comptabilite reutilises depuis clientConsultation).
|
||||||
|
* 2. Scoping STRICT des payloads PATCH (mode strict RG-1.28 / ERP-74) : chaque
|
||||||
|
* onglet n'envoie QUE les champs de SON groupe de serialisation, jamais un
|
||||||
|
* payload mixte — un champ hors-permission = 403 sur l'integralite cote back.
|
||||||
|
*
|
||||||
|
* Ces helpers ne touchent ni a l'API ni a l'etat reactif.
|
||||||
|
*
|
||||||
|
* NOTE RG-1.04 (Information obligatoire pour la Commerciale) : volontairement NON
|
||||||
|
* miroitee cote front (cf. clientFormRules.ts) — /api/me n'expose pas le code de
|
||||||
|
* role et Bureau partage les permissions de Commerciale. Le back l'applique de
|
||||||
|
* maniere fiable (422) ; on laisse remonter ce 422 en toast.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
iriOf,
|
||||||
|
relationOf,
|
||||||
|
type ClientDetail,
|
||||||
|
} from '~/modules/commercial/utils/clientConsultation'
|
||||||
|
import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules/commercial/types/clientForm'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Etat « plat » du bloc principal (groupe client:write:main). Distinct des
|
||||||
|
* brouillons Contact : ces champs vivent sur le Client lui-meme (companyName,
|
||||||
|
* categories, relation, triage), pas sur une sous-ressource ClientContact. Les
|
||||||
|
* coordonnees de contact (nom, prenom, telephones, email) ne sont plus portees
|
||||||
|
* par le Client : elles vivent exclusivement dans l'onglet Contacts.
|
||||||
|
*/
|
||||||
|
export interface MainFormDraft {
|
||||||
|
companyName: string | null
|
||||||
|
/** IRI des categories rattachees (M2M). */
|
||||||
|
categoryIris: string[]
|
||||||
|
relationType: 'distributeur' | 'courtier' | null
|
||||||
|
distributorIri: string | null
|
||||||
|
brokerIri: string | null
|
||||||
|
triageService: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Etat « plat » de l'onglet Information (groupe client:write:information). */
|
||||||
|
export interface InformationFormDraft {
|
||||||
|
description: string | null
|
||||||
|
competitors: string | null
|
||||||
|
/** Date de creation de l'entreprise au format YYYY-MM-DD (MalioDate). */
|
||||||
|
foundedAt: string | null
|
||||||
|
/** Nombre de salaries en chaine (saisie masquee), converti en number au PATCH. */
|
||||||
|
employeesCount: string | null
|
||||||
|
revenueAmount: string | null
|
||||||
|
profitAmount: string | null
|
||||||
|
directorName: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Etat « plat » de l'onglet Comptabilite (groupe client:write:accounting). */
|
||||||
|
export interface AccountingFormDraft {
|
||||||
|
siren: string | null
|
||||||
|
accountNumber: string | null
|
||||||
|
nTva: string | null
|
||||||
|
tvaModeIri: string | null
|
||||||
|
paymentDelayIri: string | null
|
||||||
|
paymentTypeIri: string | null
|
||||||
|
bankIri: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Permissions de l'utilisateur courant pertinentes pour l'edition d'un client. */
|
||||||
|
export interface ClientEditAbilities {
|
||||||
|
/** `commercial.clients.manage` : bloc principal + onglets metier. */
|
||||||
|
canManage: boolean
|
||||||
|
/** `commercial.clients.accounting.view` : visibilite de l'onglet Comptabilite. */
|
||||||
|
canAccountingView: boolean
|
||||||
|
/** `commercial.clients.accounting.manage` : edition de l'onglet Comptabilite. */
|
||||||
|
canAccountingManage: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Editabilite resolue par zone d'onglet (deduite des permissions). */
|
||||||
|
export interface TabEditability {
|
||||||
|
/** Bloc principal + onglets Information / Contact / Adresse editables. */
|
||||||
|
businessEditable: boolean
|
||||||
|
/** Onglet Comptabilite present (affiche). */
|
||||||
|
accountingVisible: boolean
|
||||||
|
/** Onglet Comptabilite editable. */
|
||||||
|
accountingEditable: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Pre-remplissage (GET detail -> brouillons) ──────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mappe le detail client vers le brouillon du bloc principal. La relation
|
||||||
|
* Distributeur/Courtier est resolue par exclusivite (RG-1.03) et son IRI extrait
|
||||||
|
* de l'embed.
|
||||||
|
*/
|
||||||
|
export function mapMainDraft(client: ClientDetail): MainFormDraft {
|
||||||
|
const relation = relationOf(client)
|
||||||
|
|
||||||
|
return {
|
||||||
|
companyName: client.companyName ?? null,
|
||||||
|
categoryIris: (client.categories ?? []).map(c => c['@id']),
|
||||||
|
relationType: relation.type,
|
||||||
|
distributorIri: iriOf(client.distributor),
|
||||||
|
brokerIri: iriOf(client.broker),
|
||||||
|
triageService: client.triageService === true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mappe le detail client vers le brouillon de l'onglet Information. */
|
||||||
|
export function mapInformationDraft(client: ClientDetail): InformationFormDraft {
|
||||||
|
return {
|
||||||
|
description: client.description ?? null,
|
||||||
|
competitors: client.competitors ?? null,
|
||||||
|
// MalioDate attend strictement YYYY-MM-DD : on tronque l'ISO datetime.
|
||||||
|
foundedAt: client.foundedAt ? client.foundedAt.slice(0, 10) : null,
|
||||||
|
employeesCount: client.employeesCount != null ? String(client.employeesCount) : null,
|
||||||
|
revenueAmount: client.revenueAmount ?? null,
|
||||||
|
profitAmount: client.profitAmount ?? null,
|
||||||
|
directorName: client.directorName ?? null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mappe les champs comptables du detail vers le brouillon de l'onglet (scalaires + IRI). */
|
||||||
|
export function mapAccountingFormDraft(client: ClientDetail): AccountingFormDraft {
|
||||||
|
return {
|
||||||
|
siren: client.siren ?? null,
|
||||||
|
accountNumber: client.accountNumber ?? null,
|
||||||
|
nTva: client.nTva ?? null,
|
||||||
|
tvaModeIri: iriOf(client.tvaMode),
|
||||||
|
paymentDelayIri: iriOf(client.paymentDelay),
|
||||||
|
paymentTypeIri: iriOf(client.paymentType),
|
||||||
|
bankIri: iriOf(client.bank),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Scoping strict des payloads PATCH ────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payload du bloc principal — groupe client:write:main UNIQUEMENT. La relation
|
||||||
|
* Distributeur/Courtier est mutuellement exclusive (RG-1.03) : on ne renseigne
|
||||||
|
* que la FK correspondant au type choisi, l'autre est forcee a null.
|
||||||
|
*/
|
||||||
|
export function buildMainPayload(main: MainFormDraft): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
companyName: main.companyName,
|
||||||
|
categories: main.categoryIris,
|
||||||
|
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
||||||
|
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
||||||
|
triageService: main.triageService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Payload de l'onglet Information — groupe client:write:information UNIQUEMENT. */
|
||||||
|
export function buildInformationPayload(information: InformationFormDraft): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
description: information.description || null,
|
||||||
|
competitors: information.competitors || null,
|
||||||
|
foundedAt: information.foundedAt || null,
|
||||||
|
employeesCount: information.employeesCount ? Number(information.employeesCount) : null,
|
||||||
|
revenueAmount: information.revenueAmount || null,
|
||||||
|
profitAmount: information.profitAmount || null,
|
||||||
|
directorName: information.directorName || null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payload des scalaires de l'onglet Comptabilite — groupe client:write:accounting
|
||||||
|
* UNIQUEMENT (les RIB passent par la sous-ressource /clients/{id}/ribs). La banque
|
||||||
|
* n'a de sens que pour un Virement (RG-1.12) : forcee a null sinon.
|
||||||
|
*/
|
||||||
|
export function buildAccountingPayload(
|
||||||
|
accounting: AccountingFormDraft,
|
||||||
|
isBankRequired: boolean,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
siren: accounting.siren || null,
|
||||||
|
accountNumber: accounting.accountNumber || null,
|
||||||
|
tvaMode: accounting.tvaModeIri,
|
||||||
|
nTva: accounting.nTva || null,
|
||||||
|
paymentDelay: accounting.paymentDelayIri,
|
||||||
|
paymentType: accounting.paymentTypeIri,
|
||||||
|
bank: isBankRequired ? accounting.bankIri : null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Payload d'un contact (sous-ressource client_contact). */
|
||||||
|
export function buildContactPayload(contact: ContactFormDraft): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
firstName: contact.firstName || null,
|
||||||
|
lastName: contact.lastName || null,
|
||||||
|
jobTitle: contact.jobTitle || null,
|
||||||
|
phonePrimary: contact.phonePrimary || null,
|
||||||
|
phoneSecondary: contact.hasSecondaryPhone ? (contact.phoneSecondary || null) : null,
|
||||||
|
email: contact.email || null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Payload d'une adresse (sous-ressource client_address). */
|
||||||
|
export function buildAddressPayload(
|
||||||
|
address: AddressFormDraft,
|
||||||
|
isBillingEmailRequired: boolean,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
isProspect: address.isProspect,
|
||||||
|
isDelivery: address.isDelivery,
|
||||||
|
isBilling: address.isBilling,
|
||||||
|
country: address.country,
|
||||||
|
postalCode: address.postalCode || null,
|
||||||
|
city: address.city || null,
|
||||||
|
street: address.street || null,
|
||||||
|
streetComplement: address.streetComplement || null,
|
||||||
|
categories: address.categoryIris,
|
||||||
|
sites: address.siteIris,
|
||||||
|
contacts: address.contactIris,
|
||||||
|
billingEmail: isBillingEmailRequired ? (address.billingEmail || null) : null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Payload d'un RIB (sous-ressource client_rib). */
|
||||||
|
export function buildRibPayload(rib: RibFormDraft): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
label: rib.label,
|
||||||
|
bic: rib.bic,
|
||||||
|
iban: rib.iban,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Gating par permission ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resout l'editabilite par zone a partir des permissions (option 1 ERP-74,
|
||||||
|
* miroir UI du re-gating champ-par-champ du ClientProcessor) :
|
||||||
|
* - bloc principal + Information/Contact/Adresse : editables ssi `manage` ;
|
||||||
|
* - Comptabilite : visible ssi `accounting.view`, editable ssi `accounting.manage`.
|
||||||
|
*
|
||||||
|
* Produit le comportement attendu :
|
||||||
|
* - Admin : tout editable.
|
||||||
|
* - Bureau / Commerciale (manage, sans accounting) : metier editable, Compta masquee.
|
||||||
|
* - Compta (accounting seul, sans manage) : metier readonly, Compta editable.
|
||||||
|
*/
|
||||||
|
export function resolveTabEditability(abilities: ClientEditAbilities): TabEditability {
|
||||||
|
return {
|
||||||
|
businessEditable: abilities.canManage,
|
||||||
|
accountingVisible: abilities.canAccountingView,
|
||||||
|
accountingEditable: abilities.canAccountingManage,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,58 @@ export function hasAtLeastOneValidContact(contacts: ContactDraft[]): boolean {
|
|||||||
return contacts.some(isContactNamed)
|
return contacts.some(isContactNamed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primitive reutilisable : vrai si TOUTES les valeurs fournies sont vides (null /
|
||||||
|
* undefined / espaces uniquement). Sert a detecter un bloc de collection
|
||||||
|
* totalement vide (amorce non remplie). Un bloc qui porte la moindre donnee
|
||||||
|
* n'est PAS « blank » : il doit etre soumis pour declencher sa 422 inline plutot
|
||||||
|
* que d'etre saute silencieusement.
|
||||||
|
*/
|
||||||
|
export function isBlankRow(values: (string | null | undefined)[]): boolean {
|
||||||
|
return values.every(value => !isFilled(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Champs saisissables d'un bloc contact (pour detecter un bloc totalement vide). */
|
||||||
|
export interface ContactFillableDraft extends ContactDraft {
|
||||||
|
jobTitle: string | null
|
||||||
|
phonePrimary: string | null
|
||||||
|
phoneSecondary: string | null
|
||||||
|
email: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrai si AUCUN champ saisissable du bloc contact n'est rempli. Distingue un bloc
|
||||||
|
* d'amorce vide (a ignorer au submit) d'un bloc partiellement rempli sans nom
|
||||||
|
* (email / telephone / fonction seul) : ce dernier doit etre soumis pour
|
||||||
|
* declencher la 422 RG-1.05 (« prenom ou nom obligatoire ») affichee inline.
|
||||||
|
*/
|
||||||
|
export function isContactBlank(contact: ContactFillableDraft): boolean {
|
||||||
|
return isBlankRow([
|
||||||
|
contact.firstName,
|
||||||
|
contact.lastName,
|
||||||
|
contact.jobTitle,
|
||||||
|
contact.phonePrimary,
|
||||||
|
contact.phoneSecondary,
|
||||||
|
contact.email,
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Champs saisissables d'un bloc RIB (pour detecter un bloc totalement vide). */
|
||||||
|
export interface RibFillableDraft {
|
||||||
|
label: string | null
|
||||||
|
bic: string | null
|
||||||
|
iban: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrai si AUCUN champ du bloc RIB n'est rempli. Un RIB partiellement rempli (ex.
|
||||||
|
* IBAN seul) n'est PAS « blank » : il doit etre soumis pour declencher les 422
|
||||||
|
* NotBlank (label / bic / iban) inline plutot que d'etre saute silencieusement.
|
||||||
|
*/
|
||||||
|
export function isRibBlank(rib: RibFillableDraft): boolean {
|
||||||
|
return isBlankRow([rib.label, rib.bic, rib.iban])
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-1.06/07/08 : une adresse de prospection est exclusive d'une adresse de
|
* RG-1.06/07/08 : une adresse de prospection est exclusive d'une adresse de
|
||||||
* livraison/facturation. Prospect n'est selectionnable que si ni Livraison ni
|
* livraison/facturation. Prospect n'est selectionnable que si ni Livraison ni
|
||||||
@@ -135,6 +187,45 @@ export function isBillingEmailRequired(flags: AddressFlagsDraft): boolean {
|
|||||||
return flags.isBilling
|
return flags.isBilling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type d'adresse expose a l'utilisateur (Select unique remplacant les trois
|
||||||
|
* cases a cocher). Sucre purement front : le back continue de recevoir les
|
||||||
|
* drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). Les seules
|
||||||
|
* combinaisons proposees respectent l'exclusivite Prospect (RG-1.06/07/08).
|
||||||
|
*/
|
||||||
|
export type AddressType = 'prospect' | 'delivery' | 'billing' | 'delivery_billing'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mappe le type d'adresse choisi vers les trois drapeaux back.
|
||||||
|
* « Adresse + Facturation » = livraison ET facturation sur la meme adresse.
|
||||||
|
*/
|
||||||
|
export function addressFlagsFromType(type: AddressType): AddressFlagsDraft {
|
||||||
|
switch (type) {
|
||||||
|
case 'prospect':
|
||||||
|
return { isProspect: true, isDelivery: false, isBilling: false }
|
||||||
|
case 'delivery':
|
||||||
|
return { isProspect: false, isDelivery: true, isBilling: false }
|
||||||
|
case 'billing':
|
||||||
|
return { isProspect: false, isDelivery: false, isBilling: true }
|
||||||
|
case 'delivery_billing':
|
||||||
|
return { isProspect: false, isDelivery: true, isBilling: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reconstruit le type d'adresse a partir des drapeaux (consultation / edition
|
||||||
|
* d'une adresse persistee, ou amorce vierge). Retourne null si aucun drapeau
|
||||||
|
* n'est positionne — le Select reste alors a saisir (et bloque la validation).
|
||||||
|
*/
|
||||||
|
export function addressTypeFromFlags(flags: AddressFlagsDraft): AddressType | null {
|
||||||
|
if (flags.isProspect) return 'prospect'
|
||||||
|
if (flags.isDelivery && flags.isBilling) return 'delivery_billing'
|
||||||
|
if (flags.isDelivery) return 'delivery'
|
||||||
|
if (flags.isBilling) return 'billing'
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
/** Code stable du type de reglement « virement » (cf. PaymentType.code, RG-1.12). */
|
/** Code stable du type de reglement « virement » (cf. PaymentType.code, RG-1.12). */
|
||||||
const PAYMENT_TYPE_TRANSFER = 'VIREMENT'
|
const PAYMENT_TYPE_TRANSFER = 'VIREMENT'
|
||||||
|
|
||||||
@@ -156,3 +247,32 @@ export function isBankRequiredForPaymentType(code: string | null | undefined): b
|
|||||||
export function isRibRequiredForPaymentType(code: string | null | undefined): boolean {
|
export function isRibRequiredForPaymentType(code: string | null | undefined): boolean {
|
||||||
return code === PAYMENT_TYPE_LCR
|
return code === PAYMENT_TYPE_LCR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sous-ensemble du brouillon comptable portant les six champs obligatoires. */
|
||||||
|
export interface AccountingRequiredDraft {
|
||||||
|
siren: string | null
|
||||||
|
accountNumber: string | null
|
||||||
|
nTva: string | null
|
||||||
|
tvaModeIri: string | null
|
||||||
|
paymentDelayIri: string | null
|
||||||
|
paymentTypeIri: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.30 : les six champs scalaires de l'onglet Comptabilite sont obligatoires
|
||||||
|
* pour valider l'onglet (SIREN, N de compte, Mode de TVA, N de TVA, Delai de
|
||||||
|
* reglement, Type de reglement). bank / RIB restent conditionnels (RG-1.12 /
|
||||||
|
* RG-1.13) et sont evalues a part. Miroir front du
|
||||||
|
* ClientAccountingCompletenessValidator : meme gate que les onglets Contact /
|
||||||
|
* Adresse (bouton « Valider » desactive tant que l'onglet n'est pas complet).
|
||||||
|
*/
|
||||||
|
export function hasAllRequiredAccountingFields(accounting: AccountingRequiredDraft): boolean {
|
||||||
|
const filled = (v: string | null): boolean => v !== null && v.trim() !== ''
|
||||||
|
|
||||||
|
return filled(accounting.siren)
|
||||||
|
&& filled(accounting.accountNumber)
|
||||||
|
&& filled(accounting.nTva)
|
||||||
|
&& filled(accounting.tvaModeIri)
|
||||||
|
&& filled(accounting.paymentDelayIri)
|
||||||
|
&& filled(accounting.paymentTypeIri)
|
||||||
|
}
|
||||||
|
|||||||
Generated
+4
-4
@@ -7,7 +7,7 @@
|
|||||||
"name": "starseed-frontend",
|
"name": "starseed-frontend",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@malio/layer-ui": "^1.7.3",
|
"@malio/layer-ui": "^1.7.4",
|
||||||
"@nuxt/icon": "^2.2.1",
|
"@nuxt/icon": "^2.2.1",
|
||||||
"@nuxtjs/i18n": "^10.2.3",
|
"@nuxtjs/i18n": "^10.2.3",
|
||||||
"@nuxtjs/tailwindcss": "^6.14.0",
|
"@nuxtjs/tailwindcss": "^6.14.0",
|
||||||
@@ -1866,9 +1866,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@malio/layer-ui": {
|
"node_modules/@malio/layer-ui": {
|
||||||
"version": "1.7.3",
|
"version": "1.7.4",
|
||||||
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.3/layer-ui-1.7.3.tgz",
|
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.4/layer-ui-1.7.4.tgz",
|
||||||
"integrity": "sha512-jw3ka0Az6Jf0F9ifsooknkwXph8TNgoe6H3CjF8tbBxl8oND8HLHjlZ04ooUCoOUEIlsQ1Mm2hFFlQRCB04qdA==",
|
"integrity": "sha512-JNXwBelj5UQ35Qv5VmnassXKt8niX9jDXjM1vUSukJQiyeUXRxAiZr16QumVgBN9P9YGDyjXVKrwCHltTXvPtQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/icon": "^2.2.1",
|
"@nuxt/icon": "^2.2.1",
|
||||||
"@nuxtjs/tailwindcss": "^6.14.0",
|
"@nuxtjs/tailwindcss": "^6.14.0",
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
"test:e2e:ui": "playwright test --ui"
|
"test:e2e:ui": "playwright test --ui"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@malio/layer-ui": "^1.7.3",
|
"@malio/layer-ui": "^1.7.4",
|
||||||
"@nuxt/icon": "^2.2.1",
|
"@nuxt/icon": "^2.2.1",
|
||||||
"@nuxtjs/i18n": "^10.2.3",
|
"@nuxtjs/i18n": "^10.2.3",
|
||||||
"@nuxtjs/tailwindcss": "^6.14.0",
|
"@nuxtjs/tailwindcss": "^6.14.0",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
@@ -0,0 +1,51 @@
|
|||||||
|
<template>
|
||||||
|
<!--
|
||||||
|
Placeholder generique « En cours de dev » pour les ecrans / onglets non
|
||||||
|
encore implementes. Composant PARTAGE (shared/components) : auto-importe
|
||||||
|
sans prefixe (`<ComingSoonPlaceholder>`) et reutilisable depuis n'importe
|
||||||
|
quel module. Affiche un gif (asset local par defaut) + un message i18n.
|
||||||
|
-->
|
||||||
|
<div class="flex min-h-[240px] flex-col items-center justify-center gap-4 rounded-md bg-white py-10">
|
||||||
|
<img
|
||||||
|
v-if="!imageFailed"
|
||||||
|
:src="src"
|
||||||
|
:alt="resolvedTitle"
|
||||||
|
class="max-h-[220px] w-auto rounded-md"
|
||||||
|
@error="imageFailed = true"
|
||||||
|
>
|
||||||
|
<!-- Repli si le gif ne charge pas (offline, CSP, asset absent) :
|
||||||
|
illustration emoji, le message reste affiche. -->
|
||||||
|
<div v-else class="text-5xl" aria-hidden="true">🚧 👨💻 🚧</div>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<p class="text-xl font-bold text-black">{{ resolvedTitle }}</p>
|
||||||
|
<p class="mt-1 text-black/60">{{ resolvedSubtitle }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
/** Source de l'image/gif affichee. Defaut : asset local `/coming-soon.gif`. */
|
||||||
|
src?: string
|
||||||
|
/** Titre. Defaut : i18n `common.comingSoon.title`. */
|
||||||
|
title?: string
|
||||||
|
/** Sous-titre. Defaut : i18n `common.comingSoon.subtitle`. */
|
||||||
|
subtitle?: string
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
src: '/coming-soon.gif',
|
||||||
|
title: '',
|
||||||
|
subtitle: '',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const imageFailed = ref(false)
|
||||||
|
|
||||||
|
// Les props priment sur les libelles i18n par defaut (permet a un module
|
||||||
|
// d'override le texte sans toucher au composant).
|
||||||
|
const resolvedTitle = computed(() => props.title || t('common.comingSoon.title'))
|
||||||
|
const resolvedSubtitle = computed(() => props.subtitle || t('common.comingSoon.subtitle'))
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
import {
|
||||||
|
useAddressAutocomplete,
|
||||||
|
AddressAutocompleteUnavailableError,
|
||||||
|
} from '../useAddressAutocomplete'
|
||||||
|
|
||||||
|
// On mocke le helper d'appel externe : aucun vrai appel reseau a la BAN.
|
||||||
|
// vi.mock est hoiste par Vitest au-dessus des imports.
|
||||||
|
const mockHttp = vi.hoisted(() => vi.fn())
|
||||||
|
vi.mock('~/shared/utils/httpExternal', () => ({ httpExternal: mockHttp }))
|
||||||
|
|
||||||
|
const BAN_URL = 'https://api-adresse.data.gouv.fr/search/'
|
||||||
|
|
||||||
|
describe('useAddressAutocomplete', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockHttp.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('searchCity', () => {
|
||||||
|
it('interroge la BAN en type=municipality et mappe { city, postalCode }', async () => {
|
||||||
|
mockHttp.mockResolvedValueOnce({
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [
|
||||||
|
{ properties: { city: 'Amiens', postcode: '80000', name: 'Amiens', type: 'municipality' } },
|
||||||
|
{ properties: { city: 'Amiens', postcode: '80080', name: 'Amiens', type: 'municipality' } },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const { searchCity } = useAddressAutocomplete()
|
||||||
|
const res = await searchCity('80000')
|
||||||
|
|
||||||
|
expect(mockHttp).toHaveBeenCalledWith(
|
||||||
|
BAN_URL,
|
||||||
|
expect.objectContaining({ query: { q: '80000', type: 'municipality' } }),
|
||||||
|
)
|
||||||
|
expect(res).toEqual([
|
||||||
|
{ city: 'Amiens', postalCode: '80000' },
|
||||||
|
{ city: 'Amiens', postalCode: '80080' },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throw une AddressAutocompleteUnavailableError sur erreur reseau / 5xx', async () => {
|
||||||
|
mockHttp.mockRejectedValueOnce(new Error('500 Server Error'))
|
||||||
|
|
||||||
|
const { searchCity } = useAddressAutocomplete()
|
||||||
|
|
||||||
|
await expect(searchCity('80000')).rejects.toBeInstanceOf(AddressAutocompleteUnavailableError)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throw une AddressAutocompleteUnavailableError sur timeout', async () => {
|
||||||
|
mockHttp.mockRejectedValueOnce(new Error('The operation was aborted due to timeout'))
|
||||||
|
|
||||||
|
const { searchCity } = useAddressAutocomplete()
|
||||||
|
|
||||||
|
await expect(searchCity('80000')).rejects.toBeInstanceOf(AddressAutocompleteUnavailableError)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('searchAddress', () => {
|
||||||
|
it('interroge la BAN avec postcode et mappe la suggestion', async () => {
|
||||||
|
mockHttp.mockResolvedValueOnce({
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
label: '8 Boulevard du Port 80000 Amiens',
|
||||||
|
name: '8 Boulevard du Port',
|
||||||
|
street: 'Boulevard du Port',
|
||||||
|
postcode: '80000',
|
||||||
|
city: 'Amiens',
|
||||||
|
type: 'housenumber',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
const { searchAddress } = useAddressAutocomplete()
|
||||||
|
const res = await searchAddress('8 boulevard du port', '80000')
|
||||||
|
|
||||||
|
expect(mockHttp).toHaveBeenCalledWith(
|
||||||
|
BAN_URL,
|
||||||
|
expect.objectContaining({
|
||||||
|
query: { q: '8 boulevard du port', postcode: '80000' },
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
expect(res).toEqual([
|
||||||
|
{
|
||||||
|
label: '8 Boulevard du Port 80000 Amiens',
|
||||||
|
street: '8 Boulevard du Port',
|
||||||
|
postalCode: '80000',
|
||||||
|
city: 'Amiens',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('omet le parametre postcode quand aucun code postal n\'est fourni', async () => {
|
||||||
|
mockHttp.mockResolvedValueOnce({ type: 'FeatureCollection', features: [] })
|
||||||
|
|
||||||
|
const { searchAddress } = useAddressAutocomplete()
|
||||||
|
await searchAddress('8 boulevard du port')
|
||||||
|
|
||||||
|
expect(mockHttp).toHaveBeenCalledWith(
|
||||||
|
BAN_URL,
|
||||||
|
expect.objectContaining({
|
||||||
|
query: { q: '8 boulevard du port' },
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ne restreint PAS la recherche a type=housenumber (sinon la BAN ne renvoie rien tant qu\'aucun numero n\'est saisi)', async () => {
|
||||||
|
// Regression : avec `type=housenumber`, une saisie de nom de rue sans
|
||||||
|
// numero (ex: « boulevard du port ») renvoie 0 resultat cote BAN.
|
||||||
|
mockHttp.mockResolvedValueOnce({ type: 'FeatureCollection', features: [] })
|
||||||
|
|
||||||
|
const { searchAddress } = useAddressAutocomplete()
|
||||||
|
await searchAddress('boulevard du port', '80000')
|
||||||
|
|
||||||
|
const sentQuery = mockHttp.mock.calls[0]?.[1]?.query as Record<string, string>
|
||||||
|
expect(sentQuery.type).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throw une AddressAutocompleteUnavailableError sur erreur reseau', async () => {
|
||||||
|
mockHttp.mockRejectedValueOnce(new Error('network down'))
|
||||||
|
|
||||||
|
const { searchAddress } = useAddressAutocomplete()
|
||||||
|
|
||||||
|
await expect(searchAddress('8 boulevard du port', '80000')).rejects.toBeInstanceOf(
|
||||||
|
AddressAutocompleteUnavailableError,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
import { useFormErrors } from '../useFormErrors'
|
||||||
|
|
||||||
|
const mockToastError = vi.hoisted(() => vi.fn())
|
||||||
|
vi.stubGlobal('useToast', () => ({ error: mockToastError, success: vi.fn() }))
|
||||||
|
// useI18n stub : renvoie la cle telle quelle (pour asserter dessus).
|
||||||
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests du composable `useFormErrors` — pendant front de la regle « le back
|
||||||
|
* renvoie toutes les violations 422 d'un coup » (ERP-101). Centralise l'etat
|
||||||
|
* d'erreurs par champ (`Record<propertyPath, message>`) et la dispatch d'une
|
||||||
|
* erreur API : 422 mappee inline, sinon toast de fallback.
|
||||||
|
*/
|
||||||
|
describe('useFormErrors', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockToastError.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Fabrique une erreur ofetch avec status + payload. */
|
||||||
|
function fetchError(status: number, data: unknown) {
|
||||||
|
return { response: { status, _data: data } }
|
||||||
|
}
|
||||||
|
|
||||||
|
it('demarre sans erreur', () => {
|
||||||
|
const { errors, hasErrors } = useFormErrors()
|
||||||
|
expect(errors).toEqual({})
|
||||||
|
expect(hasErrors.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setServerErrors mappe les violations par champ et retourne true', () => {
|
||||||
|
const { errors, hasErrors, setServerErrors } = useFormErrors()
|
||||||
|
const mapped = setServerErrors({
|
||||||
|
violations: [
|
||||||
|
{ propertyPath: 'companyName', message: 'Obligatoire.' },
|
||||||
|
{ propertyPath: 'siren', message: 'Deja utilise.' },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
expect(mapped).toBe(true)
|
||||||
|
expect(errors).toEqual({ companyName: 'Obligatoire.', siren: 'Deja utilise.' })
|
||||||
|
expect(hasErrors.value).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setServerErrors retourne false et ne touche rien sans violation', () => {
|
||||||
|
const { errors, setServerErrors } = useFormErrors()
|
||||||
|
expect(setServerErrors({})).toBe(false)
|
||||||
|
expect(errors).toEqual({})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setError / clearError / clearErrors manipulent l\'etat finement', () => {
|
||||||
|
const { errors, setError, clearError, clearErrors } = useFormErrors()
|
||||||
|
setError('iban', 'IBAN invalide.')
|
||||||
|
expect(errors.iban).toBe('IBAN invalide.')
|
||||||
|
clearError('iban')
|
||||||
|
expect(errors.iban).toBeUndefined()
|
||||||
|
setError('a', 'x')
|
||||||
|
setError('b', 'y')
|
||||||
|
clearErrors()
|
||||||
|
expect(errors).toEqual({})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handleApiError : 422 avec violations → mappe inline, pas de toast, retourne true', () => {
|
||||||
|
const { errors, handleApiError } = useFormErrors()
|
||||||
|
const handled = handleApiError(
|
||||||
|
fetchError(422, { violations: [{ propertyPath: 'email', message: 'Invalide.' }] }),
|
||||||
|
)
|
||||||
|
expect(handled).toBe(true)
|
||||||
|
expect(errors.email).toBe('Invalide.')
|
||||||
|
expect(mockToastError).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handleApiError : erreur non-422 → toast de fallback, retourne false', () => {
|
||||||
|
const { errors, handleApiError } = useFormErrors()
|
||||||
|
const handled = handleApiError(
|
||||||
|
fetchError(500, { 'hydra:description': 'Erreur serveur.' }),
|
||||||
|
{ fallbackMessage: 'Oups.' },
|
||||||
|
)
|
||||||
|
expect(handled).toBe(false)
|
||||||
|
expect(errors).toEqual({})
|
||||||
|
expect(mockToastError).toHaveBeenCalledTimes(1)
|
||||||
|
// Titre via i18n (cle renvoyee telle quelle par le stub).
|
||||||
|
expect(mockToastError.mock.calls[0][0]).toMatchObject({ title: 'errors.title', message: 'Erreur serveur.' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handleApiError : 422 sans violation mappable → toast de fallback, retourne false', () => {
|
||||||
|
const { handleApiError } = useFormErrors()
|
||||||
|
const handled = handleApiError(fetchError(422, { 'hydra:description': 'Donnees invalides.' }))
|
||||||
|
expect(handled).toBe(false)
|
||||||
|
expect(mockToastError).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,27 +1,29 @@
|
|||||||
// STUB ERP-63 — remplacé par l'implémentation BAN d'ERP-66.
|
import { httpExternal } from '~/shared/utils/httpExternal'
|
||||||
|
|
||||||
|
// Autocompletion d'adresse branchee sur la Base Adresse Nationale (BAN),
|
||||||
|
// `api-adresse.data.gouv.fr` — service public francais, gratuit, CORS ouvert.
|
||||||
//
|
//
|
||||||
// Ce fichier appartient fonctionnellement à ERP-66 (#66). ERP-63 n'en livre
|
// Appel HTTP DIRECT depuis le front (pas de proxy back), conformement a la spec
|
||||||
// qu'un STUB pour ne pas se bloquer : la vraie implémentation (appels
|
// M1 (§ API adresse postale). On passe par `httpExternal` et NON `useApi()` :
|
||||||
// api-adresse.data.gouv.fr) viendra remplacer le CORPS des deux méthodes SANS
|
// la BAN est un domaine externe, sans cookie de session ni enveloppe Hydra.
|
||||||
// changer leur signature ni l'usage côté composant.
|
|
||||||
//
|
//
|
||||||
// Contrat figé par ERP-66 (c'est lui qui fait foi) :
|
// Contrat (fige) :
|
||||||
// searchCity(postalCode) -> liste { city, postalCode }
|
// searchCity(postalCode) -> liste { city, postalCode }
|
||||||
// searchAddress(query, cp?) -> liste { label, street, postalCode, city }
|
// searchAddress(query, cp?) -> liste { label, street, postalCode, city }
|
||||||
// En cas d'erreur/timeout, la méthode THROW. Le composant catch l'erreur,
|
// En cas d'erreur/timeout, la methode THROW une AddressAutocompleteUnavailableError.
|
||||||
// affiche un toast d'avertissement et bascule en saisie libre (MalioInputText).
|
// Le composant consommateur catch, affiche un toast d'avertissement et bascule
|
||||||
//
|
// en saisie libre (MalioInputText).
|
||||||
// Comportement du stub : les deux méthodes throw systématiquement → l'onglet
|
|
||||||
// Adresse part directement en mode dégradé (Ville + Adresse en saisie libre,
|
|
||||||
// Code postal saisi manuellement). Aucun appel réseau n'est émis ici.
|
|
||||||
|
|
||||||
/** Une suggestion de ville renvoyée à partir d'un code postal. */
|
/** URL de l'endpoint de recherche BAN. */
|
||||||
|
const BAN_SEARCH_URL = 'https://api-adresse.data.gouv.fr/search/'
|
||||||
|
|
||||||
|
/** Une suggestion de ville renvoyee a partir d'un code postal. */
|
||||||
export interface CitySuggestion {
|
export interface CitySuggestion {
|
||||||
city: string
|
city: string
|
||||||
postalCode: string
|
postalCode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Une suggestion d'adresse complète (saisie assistée du champ « Adresse »). */
|
/** Une suggestion d'adresse complete (saisie assistee du champ « Adresse »). */
|
||||||
export interface AddressSuggestion {
|
export interface AddressSuggestion {
|
||||||
label: string
|
label: string
|
||||||
street: string
|
street: string
|
||||||
@@ -34,27 +36,82 @@ export interface AddressAutocomplete {
|
|||||||
searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]>
|
searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Erreur signalant que le service d'autocomplétion BAN n'est pas disponible. */
|
/** Erreur signalant que le service d'autocompletion BAN n'est pas disponible. */
|
||||||
export class AddressAutocompleteUnavailableError extends Error {
|
export class AddressAutocompleteUnavailableError extends Error {
|
||||||
constructor() {
|
constructor() {
|
||||||
// Message technique (non affiché tel quel) : le composant remonte son
|
// Message technique (non affiche tel quel) : le composant remonte son
|
||||||
// propre libellé i18n. Sert au debug / aux logs uniquement.
|
// propre libelle i18n. Sert au debug / aux logs uniquement.
|
||||||
super('Address autocomplete (BAN) is not available yet — ERP-66 stub.')
|
super('Address autocomplete (BAN) is not available.')
|
||||||
this.name = 'AddressAutocompleteUnavailableError'
|
this.name = 'AddressAutocompleteUnavailableError'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Proprietes d'une « feature » GeoJSON renvoyee par la BAN (champs utilises). */
|
||||||
* STUB : renvoie un composable conforme au contrat ERP-66 dont les méthodes
|
interface BanFeatureProperties {
|
||||||
* échouent toujours, forçant le mode dégradé côté onglet Adresse.
|
label?: string
|
||||||
*/
|
name?: string
|
||||||
|
street?: string
|
||||||
|
postcode?: string
|
||||||
|
city?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reponse GeoJSON FeatureCollection de la BAN. */
|
||||||
|
interface BanResponse {
|
||||||
|
features?: { properties?: BanFeatureProperties }[]
|
||||||
|
}
|
||||||
|
|
||||||
export function useAddressAutocomplete(): AddressAutocomplete {
|
export function useAddressAutocomplete(): AddressAutocomplete {
|
||||||
return {
|
return {
|
||||||
async searchCity(_postalCode: string): Promise<CitySuggestion[]> {
|
async searchCity(postalCode: string): Promise<CitySuggestion[]> {
|
||||||
throw new AddressAutocompleteUnavailableError()
|
let res: BanResponse
|
||||||
|
try {
|
||||||
|
res = await httpExternal<BanResponse>(BAN_SEARCH_URL, {
|
||||||
|
query: { q: postalCode, type: 'municipality' },
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
// Reseau coupe, 5xx, timeout... -> mode degrade cote composant.
|
||||||
|
throw new AddressAutocompleteUnavailableError()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (res.features ?? []).map((feature) => {
|
||||||
|
const props = feature.properties ?? {}
|
||||||
|
return {
|
||||||
|
city: props.city ?? props.name ?? '',
|
||||||
|
postalCode: props.postcode ?? '',
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
async searchAddress(_query: string, _postalCode?: string): Promise<AddressSuggestion[]> {
|
|
||||||
throw new AddressAutocompleteUnavailableError()
|
async searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]> {
|
||||||
|
// IMPORTANT : pas de `type=housenumber` ici. La BAN ne renvoie un
|
||||||
|
// resultat de ce type qu'une fois un numero saisi → une recherche par
|
||||||
|
// nom de rue (« boulevard du port ») renverrait 0 resultat pendant
|
||||||
|
// toute la frappe. Sans filtre `type`, la BAN classe rues + numeros
|
||||||
|
// par pertinence (comportement d'autocompletion attendu).
|
||||||
|
// On n'ajoute `postcode` que s'il est fourni (sinon recherche large).
|
||||||
|
const banQuery: Record<string, string> = { q: query }
|
||||||
|
if (postalCode) {
|
||||||
|
banQuery.postcode = postalCode
|
||||||
|
}
|
||||||
|
|
||||||
|
let res: BanResponse
|
||||||
|
try {
|
||||||
|
res = await httpExternal<BanResponse>(BAN_SEARCH_URL, { query: banQuery })
|
||||||
|
} catch {
|
||||||
|
throw new AddressAutocompleteUnavailableError()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (res.features ?? []).map((feature) => {
|
||||||
|
const props = feature.properties ?? {}
|
||||||
|
return {
|
||||||
|
label: props.label ?? '',
|
||||||
|
// `name` porte la ligne d'adresse complete (numero + voie) ;
|
||||||
|
// `street` ne contient que la voie. On privilegie `name`.
|
||||||
|
street: props.name ?? props.street ?? '',
|
||||||
|
postalCode: props.postcode ?? '',
|
||||||
|
city: props.city ?? '',
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export function useApi(): ApiClient {
|
|||||||
const data = responseData ?? (error as FetchError)?.data
|
const data = responseData ?? (error as FetchError)?.data
|
||||||
const msg = extractApiErrorMessage(data)
|
const msg = extractApiErrorMessage(data)
|
||||||
if (msg) return msg
|
if (msg) return msg
|
||||||
return (error as FetchError)?.message ?? 'Erreur inconnue.'
|
return (error as FetchError)?.message ?? t('errors.unknown')
|
||||||
}
|
}
|
||||||
|
|
||||||
const methodErrorKeys: Record<string, string> = {
|
const methodErrorKeys: Record<string, string> = {
|
||||||
@@ -76,7 +76,7 @@ export function useApi(): ApiClient {
|
|||||||
|
|
||||||
if (successMessage) {
|
if (successMessage) {
|
||||||
toast.success({
|
toast.success({
|
||||||
title: 'Succes',
|
title: t('success.title'),
|
||||||
message: successMessage
|
message: successMessage
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -98,10 +98,10 @@ export function useApi(): ApiClient {
|
|||||||
apiOptions?.toastErrorMessage ||
|
apiOptions?.toastErrorMessage ||
|
||||||
errorMessage ||
|
errorMessage ||
|
||||||
extractedMessage ||
|
extractedMessage ||
|
||||||
'Une erreur est survenue.'
|
t('errors.generic')
|
||||||
|
|
||||||
toast.error({
|
toast.error({
|
||||||
title: apiOptions?.toastTitle ?? 'Erreur',
|
title: apiOptions?.toastTitle ?? t('errors.title'),
|
||||||
message
|
message
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ export function useApi(): ApiClient {
|
|||||||
'Une erreur est survenue.'
|
'Une erreur est survenue.'
|
||||||
|
|
||||||
toast.error({
|
toast.error({
|
||||||
title: apiOptions?.toastTitle ?? 'Erreur',
|
title: apiOptions?.toastTitle ?? t('errors.title'),
|
||||||
message
|
message
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
* Composable d'erreurs de formulaire — convention de mapping erreur→champ pour
|
||||||
|
* tous les forms du projet (ERP-101).
|
||||||
|
*
|
||||||
|
* Le back renvoie TOUTES les violations d'une 422 d'un coup (un `propertyPath`
|
||||||
|
* + `message` par champ fautif). Ce composable centralise leur affichage
|
||||||
|
* inline : il tient un `Record<propertyPath, message>` reactif que le template
|
||||||
|
* branche directement sur la prop `:error` des composants `Malio*` (le nom du
|
||||||
|
* champ cote front = le `propertyPath` cote back, donc aucun mapping manuel).
|
||||||
|
*
|
||||||
|
* Chaque appel cree son propre etat (refs internes a la fonction) — un form =
|
||||||
|
* une instance, pas de singleton partage.
|
||||||
|
*
|
||||||
|
* Convention d'usage : les appels API qui veulent un retour inline doivent
|
||||||
|
* passer `{ toast: false }` a `useApi` (sinon le toast natif masque le mapping
|
||||||
|
* fin), puis router l'erreur via `handleApiError`. Pour les collections (1
|
||||||
|
* appel par ligne), utiliser directement `mapViolationsToRecord` par ligne.
|
||||||
|
*/
|
||||||
|
import { computed, reactive } from 'vue'
|
||||||
|
import { extractApiErrorMessage, mapViolationsToRecord } from '~/shared/utils/api'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erreur HTTP capturee par ofetch. On n'expose que les champs lus ici (status
|
||||||
|
* + payload) pour eviter de typer toute la lib.
|
||||||
|
*/
|
||||||
|
interface ApiFetchError {
|
||||||
|
response?: {
|
||||||
|
status?: number
|
||||||
|
_data?: unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Options de `handleApiError`. */
|
||||||
|
interface HandleApiErrorOptions {
|
||||||
|
/** Message de toast si l'erreur n'est pas une 422 exploitable. */
|
||||||
|
fallbackMessage?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useFormErrors() {
|
||||||
|
const toast = useToast()
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
// Etat d'erreurs indexe par propertyPath. Reactif : muter une cle suffit a
|
||||||
|
// rafraichir la prop `:error` du champ correspondant.
|
||||||
|
const errors = reactive<Record<string, string>>({})
|
||||||
|
|
||||||
|
const hasErrors = computed(() => Object.keys(errors).length > 0)
|
||||||
|
|
||||||
|
/** Pose une erreur sur un champ. */
|
||||||
|
function setError(field: string, message: string): void {
|
||||||
|
errors[field] = message
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Retire l'erreur d'un champ (no-op si absente). */
|
||||||
|
function clearError(field: string): void {
|
||||||
|
delete errors[field]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Vide toutes les erreurs (a appeler en debut de submit). */
|
||||||
|
function clearErrors(): void {
|
||||||
|
for (const key of Object.keys(errors)) {
|
||||||
|
delete errors[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mappe les violations 422 d'un payload sur les champs. Retourne true des
|
||||||
|
* qu'au moins une violation a ete posee, false sinon (payload sans
|
||||||
|
* violation exploitable).
|
||||||
|
*/
|
||||||
|
function setServerErrors(data: unknown): boolean {
|
||||||
|
const mapped = mapViolationsToRecord(data)
|
||||||
|
const keys = Object.keys(mapped)
|
||||||
|
if (keys.length === 0) return false
|
||||||
|
for (const key of keys) {
|
||||||
|
errors[key] = mapped[key]
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route une erreur API : 422 avec violations exploitables → mapping inline
|
||||||
|
* (pas de toast, l'erreur s'affiche sous le champ) ; sinon → toast de
|
||||||
|
* fallback (message serveur extrait, ou `fallbackMessage`).
|
||||||
|
*
|
||||||
|
* Retourne true si l'erreur a ete mappee inline, false si fallback toast.
|
||||||
|
*/
|
||||||
|
function handleApiError(e: unknown, opts: HandleApiErrorOptions = {}): boolean {
|
||||||
|
const status = (e as ApiFetchError)?.response?.status
|
||||||
|
const data = (e as ApiFetchError)?.response?._data
|
||||||
|
|
||||||
|
if (status === 422 && setServerErrors(data)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const message
|
||||||
|
= extractApiErrorMessage(data)
|
||||||
|
|| opts.fallbackMessage
|
||||||
|
|| t('errors.generic')
|
||||||
|
toast.error({ title: t('errors.title'), message })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
errors,
|
||||||
|
hasErrors,
|
||||||
|
setError,
|
||||||
|
clearError,
|
||||||
|
clearErrors,
|
||||||
|
setServerErrors,
|
||||||
|
handleApiError,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { mapViolationsToRecord } from '../api'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests de `mapViolationsToRecord` — fondation du mapping erreur→champ des
|
||||||
|
* formulaires (ERP-101). Transforme un payload 422 API Platform en
|
||||||
|
* `Record<propertyPath, message>` directement consommable par la prop `:error`
|
||||||
|
* des composants `Malio*`.
|
||||||
|
*/
|
||||||
|
describe('mapViolationsToRecord', () => {
|
||||||
|
it('mappe chaque violation par son propertyPath (format `violations`)', () => {
|
||||||
|
const data = {
|
||||||
|
violations: [
|
||||||
|
{ propertyPath: 'companyName', message: 'Obligatoire.' },
|
||||||
|
{ propertyPath: 'siren', message: 'SIREN deja utilise.' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
expect(mapViolationsToRecord(data)).toEqual({
|
||||||
|
companyName: 'Obligatoire.',
|
||||||
|
siren: 'SIREN deja utilise.',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('supporte le format negocie `hydra:violations`', () => {
|
||||||
|
const data = {
|
||||||
|
'hydra:violations': [
|
||||||
|
{ propertyPath: 'email', message: 'Adresse invalide.' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
expect(mapViolationsToRecord(data)).toEqual({ email: 'Adresse invalide.' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renvoie un objet vide quand il n\'y a pas de violation exploitable', () => {
|
||||||
|
expect(mapViolationsToRecord({})).toEqual({})
|
||||||
|
expect(mapViolationsToRecord(null)).toEqual({})
|
||||||
|
expect(mapViolationsToRecord({ violations: [] })).toEqual({})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ignore les violations sans propertyPath', () => {
|
||||||
|
const data = {
|
||||||
|
violations: [
|
||||||
|
{ propertyPath: '', message: 'Erreur globale.' },
|
||||||
|
{ propertyPath: 'iban', message: 'IBAN invalide.' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
expect(mapViolationsToRecord(data)).toEqual({ iban: 'IBAN invalide.' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('en cas de doublon de propertyPath, la derniere violation gagne', () => {
|
||||||
|
const data = {
|
||||||
|
violations: [
|
||||||
|
{ propertyPath: 'name', message: 'Premier message.' },
|
||||||
|
{ propertyPath: 'name', message: 'Second message.' },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
expect(mapViolationsToRecord(data)).toEqual({ name: 'Second message.' })
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
import { httpExternal } from '../httpExternal'
|
||||||
|
|
||||||
|
// On mocke ofetch : httpExternal s'appuie sur $fetch sans jamais toucher le
|
||||||
|
// reseau pendant les tests. vi.mock est hoiste par Vitest au-dessus des imports.
|
||||||
|
const mockFetch = vi.hoisted(() => vi.fn())
|
||||||
|
vi.mock('ofetch', () => ({ $fetch: mockFetch }))
|
||||||
|
|
||||||
|
describe('httpExternal', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockFetch.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne le JSON parse renvoye par $fetch', async () => {
|
||||||
|
mockFetch.mockResolvedValueOnce({ ok: true })
|
||||||
|
|
||||||
|
const res = await httpExternal<{ ok: boolean }>('https://example.test/api')
|
||||||
|
|
||||||
|
expect(res).toEqual({ ok: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('transmet la query, coupe le cookie (credentials omit) et pose un timeout par defaut', async () => {
|
||||||
|
mockFetch.mockResolvedValueOnce([])
|
||||||
|
|
||||||
|
await httpExternal('https://example.test/search', {
|
||||||
|
query: { q: '80000', type: 'municipality' },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockFetch).toHaveBeenCalledWith(
|
||||||
|
'https://example.test/search',
|
||||||
|
expect.objectContaining({
|
||||||
|
query: { q: '80000', type: 'municipality' },
|
||||||
|
credentials: 'omit',
|
||||||
|
retry: 0,
|
||||||
|
timeout: 5000,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('permet de surcharger le timeout', async () => {
|
||||||
|
mockFetch.mockResolvedValueOnce(null)
|
||||||
|
|
||||||
|
await httpExternal('https://example.test', { timeoutMs: 1000 })
|
||||||
|
|
||||||
|
expect(mockFetch).toHaveBeenCalledWith(
|
||||||
|
'https://example.test',
|
||||||
|
expect.objectContaining({ timeout: 1000 }),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('propage l\'erreur reseau / timeout (throw)', async () => {
|
||||||
|
mockFetch.mockRejectedValueOnce(new Error('network down'))
|
||||||
|
|
||||||
|
await expect(httpExternal('https://example.test')).rejects.toThrow('network down')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -20,4 +20,27 @@ describe('formatPhoneFR', () => {
|
|||||||
it('groupe par 2 meme un nombre impair de chiffres (dernier groupe seul)', () => {
|
it('groupe par 2 meme un nombre impair de chiffres (dernier groupe seul)', () => {
|
||||||
expect(formatPhoneFR('123')).toBe('12 3')
|
expect(formatPhoneFR('123')).toBe('12 3')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('formate une saisie courte (<= 4 chiffres) sans planter', () => {
|
||||||
|
expect(formatPhoneFR('1')).toBe('1')
|
||||||
|
expect(formatPhoneFR('12')).toBe('12')
|
||||||
|
expect(formatPhoneFR('1234')).toBe('12 34')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('strip les caracteres non numeriques (lettres, espaces, ponctuation)', () => {
|
||||||
|
expect(formatPhoneFR('abc')).toBe('')
|
||||||
|
expect(formatPhoneFR('Tel : 06.12')).toBe('06 12')
|
||||||
|
expect(formatPhoneFR(' 06 12 ')).toBe('06 12')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('conserve l\'indicatif international (+33) sans le transformer', () => {
|
||||||
|
// Comportement fige : on retire seulement le `+`, on ne deduit pas le
|
||||||
|
// prefixe pays. Le `+33...` est donc groupe brut par paquets de 2.
|
||||||
|
expect(formatPhoneFR('+33612345678')).toBe('33 61 23 45 67 8')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('groupe sans tronquer une saisie plus longue que 10 chiffres', () => {
|
||||||
|
// Aucune troncature silencieuse : on figure tous les chiffres groupes par 2.
|
||||||
|
expect(formatPhoneFR('061234567899')).toBe('06 12 34 56 78 99')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -66,6 +66,25 @@ export function extractApiViolations(data: unknown): ApiViolation[] {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforme un payload d'erreur 422 d'API Platform en dictionnaire
|
||||||
|
* `{ propertyPath: message }`, directement consommable par la prop `:error`
|
||||||
|
* des composants `Malio*` (le nom du champ cote front = le `propertyPath`
|
||||||
|
* renvoye par le back). Fondation du mapping erreur→champ des formulaires :
|
||||||
|
* utilise par `useFormErrors` (champs scalaires) et par les boucles de submit
|
||||||
|
* de collections (erreur par ligne).
|
||||||
|
*
|
||||||
|
* Les violations sans `propertyPath` (erreur globale) sont ignorees ; en cas
|
||||||
|
* de doublon de `propertyPath`, la derniere violation l'emporte.
|
||||||
|
*/
|
||||||
|
export function mapViolationsToRecord(data: unknown): Record<string, string> {
|
||||||
|
const out: Record<string, string> = {}
|
||||||
|
for (const v of extractApiViolations(data)) {
|
||||||
|
if (v.propertyPath) out[v.propertyPath] = v.message
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extrait un message d'erreur lisible depuis un payload Hydra / JSON
|
* Extrait un message d'erreur lisible depuis un payload Hydra / JSON
|
||||||
* d'erreur API Platform. Essaie les champs courants dans l'ordre :
|
* d'erreur API Platform. Essaie les champs courants dans l'ordre :
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { $fetch } from 'ofetch'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options d'un appel HTTP externe.
|
||||||
|
*/
|
||||||
|
export interface HttpExternalOptions {
|
||||||
|
/** Parametres de query string (encodes par ofetch). */
|
||||||
|
query?: Record<string, string | number | undefined>
|
||||||
|
/** Timeout en millisecondes avant abandon (defaut 5000). */
|
||||||
|
timeoutMs?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Petit client HTTP pour les APIs PUBLIQUES EXTERNES (domaine tiers, hors `/api`).
|
||||||
|
*
|
||||||
|
* Pourquoi un helper dedie plutot que `useApi()` : `useApi()` est le client de
|
||||||
|
* l'API interne Starseed (baseURL `/api`, cookie JWT `credentials: 'include'`,
|
||||||
|
* parsing/erreurs Hydra, redirection `/login` sur 401, toasts i18n). Tout cela
|
||||||
|
* est inadapte — voire indesirable — pour un endpoint public externe comme la
|
||||||
|
* Base Adresse Nationale (`api-adresse.data.gouv.fr`).
|
||||||
|
*
|
||||||
|
* Ce helper est donc le SEUL point d'entree autorise pour un `$fetch` brut vers
|
||||||
|
* l'externe (cf. regle frontend n°4 : pas de `$fetch` eparpille dans les
|
||||||
|
* composants). Il :
|
||||||
|
* - cible une URL absolue (pas de baseURL `/api`) ;
|
||||||
|
* - n'envoie PAS le cookie de session (`credentials: 'omit'`) ;
|
||||||
|
* - ne retente pas (`retry: 0`) et applique un timeout ;
|
||||||
|
* - laisse remonter l'erreur (throw) — au consommateur de gerer le mode degrade.
|
||||||
|
*/
|
||||||
|
export async function httpExternal<T>(
|
||||||
|
url: string,
|
||||||
|
opts: HttpExternalOptions = {},
|
||||||
|
): Promise<T> {
|
||||||
|
return $fetch<T>(url, {
|
||||||
|
query: opts.query,
|
||||||
|
credentials: 'omit',
|
||||||
|
retry: 0,
|
||||||
|
timeout: opts.timeoutMs ?? 5000,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* M1 — Suppression du contact principal inline du `Client` (refonte contact).
|
||||||
|
*
|
||||||
|
* Modele AVANT : le `Client` portait 5 colonnes de contact principal
|
||||||
|
* (first_name, last_name, phone_primary, phone_secondary, email) en doublon
|
||||||
|
* conceptuel de la sous-entite `ClientContact` (onglet Contact).
|
||||||
|
*
|
||||||
|
* Modele APRES (decision produit, README refonte-contact) : les contacts vivent
|
||||||
|
* UNIQUEMENT dans `client_contact`. Les 5 colonnes inline disparaissent du
|
||||||
|
* `client`. RG-1.01 (firstName OU lastName sur Client) et RG-1.02 (max 2
|
||||||
|
* telephones sur Client) sont supprimees : leur equivalent vit deja sur
|
||||||
|
* `client_contact` (RG-1.05 / RG-1.14).
|
||||||
|
*
|
||||||
|
* Le code etant deja en prod, la suppression est precedee d'un BACKFILL : pour
|
||||||
|
* tout client n'ayant encore AUCUN contact, on materialise son contact principal
|
||||||
|
* inline en une ligne `client_contact` (position 0) avant le DROP, afin de ne
|
||||||
|
* perdre aucune donnee.
|
||||||
|
*
|
||||||
|
* Namespace racine `DoctrineMigrations` (regle ABSOLUE n°11) et NON modulaire
|
||||||
|
* Commercial : avec plusieurs migrations_paths, Doctrine Migrations 3.x trie par
|
||||||
|
* FQCN alphabetique (AlphabeticalComparator). Une migration
|
||||||
|
* `App\Module\Commercial\...` trierait AVANT toutes les `DoctrineMigrations\...`
|
||||||
|
* sur base vide -> ce DROP s'executerait avant le CREATE TABLE client
|
||||||
|
* (Version20260601000000). Le namespace racine garantit l'ordre par timestamp.
|
||||||
|
*/
|
||||||
|
final class Version20260603120000 extends AbstractMigration
|
||||||
|
{
|
||||||
|
/** Colonnes de contact inline supprimees du `client`. */
|
||||||
|
private const array INLINE_CONTACT_COLUMNS = [
|
||||||
|
'first_name', 'last_name', 'phone_primary', 'phone_secondary', 'email',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'M1 : suppression du contact inline du Client (backfill vers client_contact puis DROP des 5 colonnes).';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// 1. Backfill : tout client SANS contact recoit une ligne client_contact
|
||||||
|
// (position 0) reprenant ses champs inline. phone_primary / email du
|
||||||
|
// client sont NOT NULL -> toujours une donnee a reporter. Le CHECK
|
||||||
|
// chk_client_contact_name (first_name OU last_name) est garanti par le
|
||||||
|
// fallback company_name si jamais les deux noms etaient null (cas qui ne
|
||||||
|
// devrait pas exister, RG-1.01 ayant ete appliquee a l'ecriture).
|
||||||
|
// created_at/updated_at NOT NULL -> NOW() ; created_by/updated_by null
|
||||||
|
// (backfill hors contexte HTTP, libelle « Systeme » cote front).
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO client_contact (
|
||||||
|
client_id, first_name, last_name, phone_primary, phone_secondary,
|
||||||
|
email, position, created_at, updated_at
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
c.id,
|
||||||
|
c.first_name,
|
||||||
|
CASE
|
||||||
|
WHEN c.first_name IS NULL AND c.last_name IS NULL THEN c.company_name
|
||||||
|
ELSE c.last_name
|
||||||
|
END,
|
||||||
|
c.phone_primary,
|
||||||
|
c.phone_secondary,
|
||||||
|
c.email,
|
||||||
|
0,
|
||||||
|
NOW(),
|
||||||
|
NOW()
|
||||||
|
FROM client c
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM client_contact cc WHERE cc.client_id = c.id
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
// 2. DROP des 5 colonnes inline (rien a documenter : suppression).
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE client
|
||||||
|
DROP COLUMN first_name,
|
||||||
|
DROP COLUMN last_name,
|
||||||
|
DROP COLUMN phone_primary,
|
||||||
|
DROP COLUMN phone_secondary,
|
||||||
|
DROP COLUMN email
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// Best-effort : on RECREE les 5 colonnes (en NULLABLE — l'etat NOT NULL
|
||||||
|
// d'origine de phone_primary/email ne peut etre restaure sur une table
|
||||||
|
// peuplee sans risque) et on retro-alimente depuis le contact principal
|
||||||
|
// (position minimale) de chaque client. La donnee n'est pas garantie
|
||||||
|
// identique a l'origine : ce down() sert au rollback technique, pas a une
|
||||||
|
// restauration fidele.
|
||||||
|
$this->addSql('ALTER TABLE client ADD COLUMN first_name VARCHAR(120) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE client ADD COLUMN last_name VARCHAR(120) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE client ADD COLUMN phone_primary VARCHAR(20) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE client ADD COLUMN phone_secondary VARCHAR(20) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE client ADD COLUMN email VARCHAR(180) DEFAULT NULL');
|
||||||
|
|
||||||
|
// Retro-alimentation depuis le contact de position la plus basse.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
UPDATE client c SET
|
||||||
|
first_name = cc.first_name,
|
||||||
|
last_name = cc.last_name,
|
||||||
|
phone_primary = cc.phone_primary,
|
||||||
|
phone_secondary = cc.phone_secondary,
|
||||||
|
email = cc.email
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (client_id)
|
||||||
|
client_id, first_name, last_name, phone_primary, phone_secondary, email
|
||||||
|
FROM client_contact
|
||||||
|
ORDER BY client_id, position ASC, id ASC
|
||||||
|
) cc
|
||||||
|
WHERE cc.client_id = c.id
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
// Re-pose des commentaires d'origine (regle ABSOLUE n°12) — dollar-quoting
|
||||||
|
// Postgres pour eviter tout echappement d apostrophe.
|
||||||
|
$this->addSql('COMMENT ON COLUMN client.first_name IS $_$Prenom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).$_$');
|
||||||
|
$this->addSql('COMMENT ON COLUMN client.last_name IS $_$Nom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).$_$');
|
||||||
|
$this->addSql('COMMENT ON COLUMN client.phone_primary IS $_$Telephone principal — stocke en chiffres uniquement (RG-1.20). Obligatoire.$_$');
|
||||||
|
$this->addSql('COMMENT ON COLUMN client.phone_secondary IS $_$Telephone secondaire optionnel — chiffres uniquement (RG-1.20).$_$');
|
||||||
|
$this->addSql('COMMENT ON COLUMN client.email IS $_$Email principal (lowercase serveur, RG-1.21). NON unique (RG-1.17 supprimee, Q4).$_$');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,7 +112,7 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
|||||||
// persiste, sans contradiction entre l'ordre Validate / Process.
|
// persiste, sans contradiction entre l'ordre Validate / Process.
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Assert\NotBlank(message: 'Le nom est obligatoire.', normalizer: 'trim')]
|
#[Assert\NotBlank(message: 'Le nom est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Length(min: 2, max: 120, normalizer: 'trim')]
|
#[Assert\Length(min: 2, max: 120, minMessage: 'Le nom doit comporter au moins {{ limit }} caractères.', maxMessage: 'Le nom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['category:read', 'category:write'])]
|
#[Groups(['category:read', 'category:write'])]
|
||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Application\Validator;
|
||||||
|
|
||||||
|
use ApiPlatform\Validator\Exception\ValidationException;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator metier (spec-front § Onglet Comptabilite) : a la soumission complete
|
||||||
|
* de l'onglet Comptabilite, les six champs scalaires obligatoires doivent etre
|
||||||
|
* renseignes (SIREN, Numero de compte, Mode de TVA, N de TVA, Delai de reglement,
|
||||||
|
* Type de reglement). La banque reste conditionnelle (RG-1.12) et les RIB aussi
|
||||||
|
* (RG-1.13) : ils ne sont pas couverts ici.
|
||||||
|
*
|
||||||
|
* Calque sur ClientInformationCompletenessValidator (RG-1.04) : colonnes nullable
|
||||||
|
* en base + validateur contextuel, plutot qu'un Assert\NotBlank sur l'entite (qui
|
||||||
|
* casserait le POST de l'onglet principal, lequel n'envoie aucun champ comptable).
|
||||||
|
*
|
||||||
|
* Invoque par le ClientProcessor uniquement quand le payload porte les six champs
|
||||||
|
* (= une validation d'onglet), jamais sur un PATCH ciblant un seul champ comptable.
|
||||||
|
*
|
||||||
|
* Leve une ValidationException (HTTP 422) listant chaque champ manquant, par
|
||||||
|
* coherence avec les violations Symfony rendues par API Platform (mapping inline
|
||||||
|
* front via useFormErrors, ERP-101).
|
||||||
|
*/
|
||||||
|
final class ClientAccountingCompletenessValidator
|
||||||
|
{
|
||||||
|
public function validate(Client $client): void
|
||||||
|
{
|
||||||
|
// Map champ -> valeur courante des champs obligatoires de l'onglet.
|
||||||
|
$fields = [
|
||||||
|
'siren' => $client->getSiren(),
|
||||||
|
'accountNumber' => $client->getAccountNumber(),
|
||||||
|
'tvaMode' => $client->getTvaMode(),
|
||||||
|
'nTva' => $client->getNTva(),
|
||||||
|
'paymentDelay' => $client->getPaymentDelay(),
|
||||||
|
'paymentType' => $client->getPaymentType(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$violations = new ConstraintViolationList();
|
||||||
|
|
||||||
|
foreach ($fields as $property => $value) {
|
||||||
|
if ($this->isMissing($value)) {
|
||||||
|
$violations->add(new ConstraintViolation(
|
||||||
|
'Ce champ est obligatoire.',
|
||||||
|
null,
|
||||||
|
[],
|
||||||
|
$client,
|
||||||
|
$property,
|
||||||
|
$value,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($violations) > 0) {
|
||||||
|
throw new ValidationException($violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Une valeur est manquante si null ou, pour une chaine, vide apres trim. Les
|
||||||
|
* references (TvaMode / PaymentDelay / PaymentType) ne sont manquantes que
|
||||||
|
* lorsqu'elles valent null.
|
||||||
|
*/
|
||||||
|
private function isMissing(mixed $value): bool
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_string($value) && '' === trim($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -147,35 +147,13 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
// === Formulaire principal ===
|
// === Formulaire principal ===
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Assert\NotBlank(message: 'Le nom de l\'entreprise est obligatoire.', normalizer: 'trim')]
|
#[Assert\NotBlank(message: 'Le nom de l\'entreprise est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Length(min: 2, max: 180, normalizer: 'trim')]
|
#[Assert\Length(min: 2, max: 180, minMessage: 'Le nom de l\'entreprise doit comporter au moins {{ limit }} caractères.', maxMessage: 'Le nom de l\'entreprise ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
private ?string $companyName = null;
|
private ?string $companyName = null;
|
||||||
|
|
||||||
// RG-1.01 : firstName OU lastName obligatoire (validation au futur Processor).
|
// Le contact principal n'est plus porte inline par le Client : les contacts
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
// vivent uniquement dans ClientContact (onglet Contact). RG-1.01 / RG-1.02
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
// supprimees du Client (equivalent RG-1.05 / RG-1.14 sur ClientContact).
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $firstName = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $lastName = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 20)]
|
|
||||||
#[Assert\NotBlank]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $phonePrimary = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 20, nullable: true)]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $phoneSecondary = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
|
||||||
#[Assert\NotBlank]
|
|
||||||
#[Assert\Email]
|
|
||||||
#[Groups(['client:read', 'client:write:main'])]
|
|
||||||
private ?string $email = null;
|
|
||||||
|
|
||||||
// RG-1.03 : distributor / broker auto-references mutuellement exclusives
|
// RG-1.03 : distributor / broker auto-references mutuellement exclusives
|
||||||
// (CHECK chk_client_distrib_or_broker en base).
|
// (CHECK chk_client_distrib_or_broker en base).
|
||||||
@@ -210,6 +188,7 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
private ?string $description = null;
|
private ?string $description = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
#[Assert\Length(max: 255, maxMessage: 'Ce champ ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client:read', 'client:write:information'])]
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
private ?string $competitors = null;
|
private ?string $competitors = null;
|
||||||
|
|
||||||
@@ -218,7 +197,7 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
private ?DateTimeImmutable $foundedAt = null;
|
private ?DateTimeImmutable $foundedAt = null;
|
||||||
|
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
#[Assert\PositiveOrZero]
|
#[Assert\PositiveOrZero(message: 'L\'effectif doit être un nombre positif ou nul.')]
|
||||||
#[Groups(['client:read', 'client:write:information'])]
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
private ?int $employeesCount = null;
|
private ?int $employeesCount = null;
|
||||||
|
|
||||||
@@ -227,6 +206,7 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
private ?string $revenueAmount = null;
|
private ?string $revenueAmount = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
|
#[Assert\Length(max: 120, maxMessage: 'Le nom du dirigeant ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client:read', 'client:write:information'])]
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
private ?string $directorName = null;
|
private ?string $directorName = null;
|
||||||
|
|
||||||
@@ -239,10 +219,12 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
// futur Provider si l'user a la permission accounting.view). Ecriture via
|
// futur Provider si l'user a la permission accounting.view). Ecriture via
|
||||||
// `client:write:accounting` (le futur Processor exige accounting.manage).
|
// `client:write:accounting` (le futur Processor exige accounting.manage).
|
||||||
#[ORM\Column(length: 20, nullable: true)]
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
#[Assert\Length(max: 20, maxMessage: 'Le SIREN ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
private ?string $siren = null;
|
private ?string $siren = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 40, nullable: true)]
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
|
#[Assert\Length(max: 40, maxMessage: 'Le numéro de compte ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
private ?string $accountNumber = null;
|
private ?string $accountNumber = null;
|
||||||
|
|
||||||
@@ -252,6 +234,7 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
private ?TvaMode $tvaMode = null;
|
private ?TvaMode $tvaMode = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 40, nullable: true)]
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
|
#[Assert\Length(max: 40, maxMessage: 'Le numéro de TVA ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
private ?string $nTva = null;
|
private ?string $nTva = null;
|
||||||
|
|
||||||
@@ -326,66 +309,6 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFirstName(): ?string
|
|
||||||
{
|
|
||||||
return $this->firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setFirstName(?string $firstName): static
|
|
||||||
{
|
|
||||||
$this->firstName = $firstName;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLastName(): ?string
|
|
||||||
{
|
|
||||||
return $this->lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setLastName(?string $lastName): static
|
|
||||||
{
|
|
||||||
$this->lastName = $lastName;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPhonePrimary(): ?string
|
|
||||||
{
|
|
||||||
return $this->phonePrimary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setPhonePrimary(string $phonePrimary): static
|
|
||||||
{
|
|
||||||
$this->phonePrimary = $phonePrimary;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPhoneSecondary(): ?string
|
|
||||||
{
|
|
||||||
return $this->phoneSecondary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setPhoneSecondary(?string $phoneSecondary): static
|
|
||||||
{
|
|
||||||
$this->phoneSecondary = $phoneSecondary;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEmail(): ?string
|
|
||||||
{
|
|
||||||
return $this->email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setEmail(string $email): static
|
|
||||||
{
|
|
||||||
$this->email = $email;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDistributor(): ?Client
|
public function getDistributor(): ?Client
|
||||||
{
|
{
|
||||||
return $this->distributor;
|
return $this->distributor;
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||||||
uriVariables: [
|
uriVariables: [
|
||||||
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
||||||
],
|
],
|
||||||
|
// read:false : pas de stade lecture du parent. Le Link toProperty
|
||||||
|
// resoudrait l'enfant (SELECT ClientAddress ... WHERE client = :id) et
|
||||||
|
// casse en NonUniqueResult des >= 2 enfants. Le parent est rattache
|
||||||
|
// manuellement par ClientAddressProcessor::linkParent (404 si absent).
|
||||||
|
read: false,
|
||||||
security: "is_granted('commercial.clients.manage')",
|
security: "is_granted('commercial.clients.manage')",
|
||||||
normalizationContext: ['groups' => ['client_address:read']],
|
normalizationContext: ['groups' => ['client_address:read']],
|
||||||
denormalizationContext: ['groups' => ['client_address:write']],
|
denormalizationContext: ['groups' => ['client_address:write']],
|
||||||
@@ -125,33 +130,39 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
private bool $isBilling = false;
|
private bool $isBilling = false;
|
||||||
|
|
||||||
#[ORM\Column(length: 80, options: ['default' => 'France'])]
|
#[ORM\Column(length: 80, options: ['default' => 'France'])]
|
||||||
|
#[Assert\Length(max: 80, maxMessage: 'Le pays ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private string $country = 'France';
|
private string $country = 'France';
|
||||||
|
|
||||||
// RG-1.09 : code postal a 4 ou 5 chiffres (pas de controle CP/ville serveur).
|
// RG-1.09 : code postal a 4 ou 5 chiffres (pas de controle CP/ville serveur).
|
||||||
|
// Le Regex borne deja la longueur (≤ 5) : pas de Length redondant.
|
||||||
#[ORM\Column(length: 20)]
|
#[ORM\Column(length: 20)]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'Le code postal est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Regex(pattern: '/^[0-9]{4,5}$/', message: 'Le code postal doit comporter 4 ou 5 chiffres.')]
|
#[Assert\Regex(pattern: '/^[0-9]{4,5}$/', message: 'Le code postal doit comporter 4 ou 5 chiffres.')]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private ?string $postalCode = null;
|
private ?string $postalCode = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'La ville est obligatoire.', normalizer: 'trim')]
|
||||||
|
#[Assert\Length(max: 120, maxMessage: 'La ville ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private ?string $city = null;
|
private ?string $city = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'La rue est obligatoire.', normalizer: 'trim')]
|
||||||
|
#[Assert\Length(max: 255, maxMessage: 'La rue ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private ?string $street = null;
|
private ?string $street = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
#[Assert\Length(max: 255, maxMessage: 'Le complément d\'adresse ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private ?string $streetComplement = null;
|
private ?string $streetComplement = null;
|
||||||
|
|
||||||
// RG-1.11 : obligatoire ssi isBilling (validateBillingEmailPresence + CHECK BDD).
|
// RG-1.11 : obligatoire ssi isBilling (validateBillingEmailPresence + CHECK BDD).
|
||||||
#[ORM\Column(length: 180, nullable: true)]
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
#[Assert\Email]
|
#[Assert\Email(message: 'L\'email de facturation n\'est pas valide.')]
|
||||||
|
#[Assert\Length(max: 180, maxMessage: 'L\'email de facturation ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private ?string $billingEmail = null;
|
private ?string $billingEmail = null;
|
||||||
|
|
||||||
@@ -177,12 +188,14 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private Collection $contacts;
|
private Collection $contacts;
|
||||||
|
|
||||||
|
// Au moins une categorie est obligatoire sur une adresse (spec-front § Adresse).
|
||||||
// RG-1.29 : categories de code DISTRIBUTEUR/COURTIER interdites (validateCategoryCodes).
|
// RG-1.29 : categories de code DISTRIBUTEUR/COURTIER interdites (validateCategoryCodes).
|
||||||
/** @var Collection<int, CategoryInterface> */
|
/** @var Collection<int, CategoryInterface> */
|
||||||
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
||||||
#[ORM\JoinTable(name: 'client_address_category')]
|
#[ORM\JoinTable(name: 'client_address_category')]
|
||||||
#[ORM\JoinColumn(name: 'client_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
#[ORM\JoinColumn(name: 'client_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||||
|
#[Assert\Count(min: 1, minMessage: 'Au moins une catégorie est obligatoire.')]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private Collection $categories;
|
private Collection $categories;
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
uriVariables: [
|
uriVariables: [
|
||||||
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
||||||
],
|
],
|
||||||
|
// read:false : pas de stade lecture du parent. Le Link toProperty
|
||||||
|
// resoudrait l'enfant (SELECT ClientContact ... WHERE client = :id) et
|
||||||
|
// casse en NonUniqueResult des >= 2 enfants. Le parent est rattache
|
||||||
|
// manuellement par ClientContactProcessor::linkParent (404 si absent).
|
||||||
|
read: false,
|
||||||
security: "is_granted('commercial.clients.manage')",
|
security: "is_granted('commercial.clients.manage')",
|
||||||
normalizationContext: ['groups' => ['client_contact:read']],
|
normalizationContext: ['groups' => ['client_contact:read']],
|
||||||
denormalizationContext: ['groups' => ['client_contact:write']],
|
denormalizationContext: ['groups' => ['client_contact:write']],
|
||||||
@@ -88,30 +93,36 @@ class ClientContact implements TimestampableInterface, BlamableInterface
|
|||||||
// RG-1.05 : firstName OU lastName obligatoire (CHECK BDD + Processor). Les
|
// RG-1.05 : firstName OU lastName obligatoire (CHECK BDD + Processor). Les
|
||||||
// deux restent nullable au niveau ORM.
|
// deux restent nullable au niveau ORM.
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
#[Assert\Length(max: 120, maxMessage: 'Le prénom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_contact:read', 'client_contact:write'])]
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
private ?string $firstName = null;
|
private ?string $firstName = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
#[Assert\Length(max: 120, maxMessage: 'Le nom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_contact:read', 'client_contact:write'])]
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
private ?string $lastName = null;
|
private ?string $lastName = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120, nullable: true)]
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
#[Assert\Length(max: 120, maxMessage: 'La fonction ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_contact:read', 'client_contact:write'])]
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
private ?string $jobTitle = null;
|
private ?string $jobTitle = null;
|
||||||
|
|
||||||
|
// RG : pas de validation de format telephone (saisie libre), mais une
|
||||||
|
// Assert\Length calee sur la colonne VARCHAR(20) evite l'erreur Postgres
|
||||||
|
// (500 non rattachee au champ) au profit d'une 422 propre (ERP-107).
|
||||||
#[ORM\Column(length: 20, nullable: true)]
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
#[Assert\Length(max: 20, maxMessage: 'Le téléphone ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_contact:read', 'client_contact:write'])]
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
private ?string $phonePrimary = null;
|
private ?string $phonePrimary = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 20, nullable: true)]
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
#[Assert\Length(max: 20, maxMessage: 'Le téléphone secondaire ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_contact:read', 'client_contact:write'])]
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
private ?string $phoneSecondary = null;
|
private ?string $phoneSecondary = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180, nullable: true)]
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
#[Assert\Email]
|
#[Assert\Email(message: 'L\'adresse email n\'est pas valide.')]
|
||||||
|
#[Assert\Length(max: 180, maxMessage: 'L\'email ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_contact:read', 'client_contact:write'])]
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
uriVariables: [
|
uriVariables: [
|
||||||
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
||||||
],
|
],
|
||||||
|
// read:false : pas de stade lecture du parent. Le Link toProperty
|
||||||
|
// resoudrait l'enfant (SELECT ClientRib ... WHERE client = :id) et
|
||||||
|
// casse en NonUniqueResult des >= 2 enfants. Le parent est rattache
|
||||||
|
// manuellement par ClientRibProcessor::linkParent (404 si absent).
|
||||||
|
read: false,
|
||||||
security: "is_granted('commercial.clients.accounting.manage')",
|
security: "is_granted('commercial.clients.accounting.manage')",
|
||||||
normalizationContext: ['groups' => ['client_rib:read']],
|
normalizationContext: ['groups' => ['client_rib:read']],
|
||||||
denormalizationContext: ['groups' => ['client_rib:write']],
|
denormalizationContext: ['groups' => ['client_rib:write']],
|
||||||
@@ -97,20 +102,22 @@ class ClientRib implements TimestampableInterface, BlamableInterface
|
|||||||
private ?Client $client = null;
|
private ?Client $client = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'Le libellé du RIB est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Length(max: 120, normalizer: 'trim')]
|
#[Assert\Length(max: 120, maxMessage: 'Le libellé ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
||||||
private ?string $label = null;
|
private ?string $label = null;
|
||||||
|
|
||||||
|
// Bic/Iban bornent deja le format (et donc la longueur) : pas de Length
|
||||||
|
// redondant calee sur la colonne (whitelist du garde-fou ERP-107).
|
||||||
#[ORM\Column(length: 20)]
|
#[ORM\Column(length: 20)]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'Le BIC est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Bic]
|
#[Assert\Bic(message: 'Le BIC n\'est pas valide.')]
|
||||||
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
||||||
private ?string $bic = null;
|
private ?string $bic = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 34)]
|
#[ORM\Column(length: 34)]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'L\'IBAN est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Iban]
|
#[Assert\Iban(message: 'L\'IBAN n\'est pas valide.')]
|
||||||
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
||||||
private ?string $iban = null;
|
private ?string $iban = null;
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -12,6 +12,7 @@ use App\Module\Commercial\Domain\Entity\Client;
|
|||||||
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processor d'ecriture de la sous-ressource Adresse d'un client (M1, § 4.5).
|
* Processor d'ecriture de la sous-ressource Adresse d'un client (M1, § 4.5).
|
||||||
@@ -75,9 +76,14 @@ final class ClientAddressProcessor implements ProcessorInterface
|
|||||||
? $clientId
|
? $clientId
|
||||||
: $this->em->getRepository(Client::class)->find($clientId);
|
: $this->em->getRepository(Client::class)->find($clientId);
|
||||||
|
|
||||||
if ($client instanceof Client) {
|
// read:false sur le POST : sans stade lecture, un parent introuvable n'est
|
||||||
$address->setClient($client);
|
// plus intercepte en amont -> 404 explicite (sinon 500 au persist sur la
|
||||||
|
// contrainte client_id NOT NULL).
|
||||||
|
if (!$client instanceof Client) {
|
||||||
|
throw new NotFoundHttpException('Client introuvable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$address->setClient($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+8
-2
@@ -14,6 +14,7 @@ use App\Module\Commercial\Domain\Entity\ClientContact;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\Validator\ConstraintViolation;
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
use Symfony\Component\Validator\ConstraintViolationList;
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
|
||||||
@@ -88,9 +89,14 @@ final class ClientContactProcessor implements ProcessorInterface
|
|||||||
? $clientId
|
? $clientId
|
||||||
: $this->em->getRepository(Client::class)->find($clientId);
|
: $this->em->getRepository(Client::class)->find($clientId);
|
||||||
|
|
||||||
if ($client instanceof Client) {
|
// read:false sur le POST : sans stade lecture, un parent introuvable n'est
|
||||||
$contact->setClient($client);
|
// plus intercepte en amont -> 404 explicite (sinon 500 au persist sur la
|
||||||
|
// contrainte client_id NOT NULL).
|
||||||
|
if (!$client instanceof Client) {
|
||||||
|
throw new NotFoundHttpException('Client introuvable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$contact->setClient($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+42
-37
@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\Operation;
|
|||||||
use ApiPlatform\State\ProcessorInterface;
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
use ApiPlatform\Validator\Exception\ValidationException;
|
use ApiPlatform\Validator\Exception\ValidationException;
|
||||||
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
||||||
|
use App\Module\Commercial\Application\Validator\ClientAccountingCompletenessValidator;
|
||||||
use App\Module\Commercial\Application\Validator\ClientInformationCompletenessValidator;
|
use App\Module\Commercial\Application\Validator\ClientInformationCompletenessValidator;
|
||||||
use App\Module\Commercial\Domain\Entity\Client;
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
use App\Shared\Domain\Contract\BusinessRoleAwareInterface;
|
use App\Shared\Domain\Contract\BusinessRoleAwareInterface;
|
||||||
@@ -29,7 +30,7 @@ use Symfony\Component\Validator\ConstraintViolationList;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Processor d'ecriture du repertoire clients (M1). Cf. spec-back M1 § 2.8 /
|
* Processor d'ecriture du repertoire clients (M1). Cf. spec-back M1 § 2.8 /
|
||||||
* § 2.9 / § 4.3 / § 4.4 + RG-1.01 a RG-1.28.
|
* § 2.9 / § 4.3 / § 4.4 + RG-1.03 a RG-1.28 (RG-1.01/1.02 supprimees : contact inline retire).
|
||||||
*
|
*
|
||||||
* Sequence (POST / PATCH) :
|
* Sequence (POST / PATCH) :
|
||||||
* 1. Autorisation additionnelle par groupe d'onglet. La security d'operation
|
* 1. Autorisation additionnelle par groupe d'onglet. La security d'operation
|
||||||
@@ -41,7 +42,7 @@ use Symfony\Component\Validator\ConstraintViolationList;
|
|||||||
* - champ isArchived dans le payload -> exige archive (RG-1.22, 403) et
|
* - champ isArchived dans le payload -> exige archive (RG-1.22, 403) et
|
||||||
* interdit toute autre modification dans la meme requete (RG-1.22, 422).
|
* interdit toute autre modification dans la meme requete (RG-1.22, 422).
|
||||||
* 2. Normalisation serveur (RG-1.18 a 1.21) via ClientFieldNormalizer.
|
* 2. Normalisation serveur (RG-1.18 a 1.21) via ClientFieldNormalizer.
|
||||||
* 3. Regles metier : RG-1.01 (prenom/nom), RG-1.03 (distributor/broker
|
* 3. Regles metier : RG-1.03 (distributor/broker
|
||||||
* exclusifs + type de categorie), RG-1.12 (Virement -> banque),
|
* exclusifs + type de categorie), RG-1.12 (Virement -> banque),
|
||||||
* RG-1.13 (LCR -> >= 1 RIB), RG-1.04 (completude Information exigee sur POST
|
* RG-1.13 (LCR -> >= 1 RIB), RG-1.04 (completude Information exigee sur POST
|
||||||
* et tout PATCH pour le role Commerciale).
|
* et tout PATCH pour le role Commerciale).
|
||||||
@@ -60,8 +61,7 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
{
|
{
|
||||||
/** Champs de l'onglet principal (groupe client:write:main). */
|
/** Champs de l'onglet principal (groupe client:write:main). */
|
||||||
private const array MAIN_FIELDS = [
|
private const array MAIN_FIELDS = [
|
||||||
'companyName', 'firstName', 'lastName', 'phonePrimary', 'phoneSecondary',
|
'companyName', 'distributor', 'broker', 'triageService', 'categories',
|
||||||
'email', 'distributor', 'broker', 'triageService', 'categories',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/** Champs de l'onglet Information (groupe client:write:information). */
|
/** Champs de l'onglet Information (groupe client:write:information). */
|
||||||
@@ -76,6 +76,14 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
'paymentType', 'bank',
|
'paymentType', 'bank',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Champs comptables obligatoires a la validation complete de l'onglet
|
||||||
|
* (spec-front § Onglet Comptabilite). bank est exclu : conditionnel (RG-1.12).
|
||||||
|
*/
|
||||||
|
private const array ACCOUNTING_REQUIRED_FIELDS = [
|
||||||
|
'siren', 'accountNumber', 'tvaMode', 'nTva', 'paymentDelay', 'paymentType',
|
||||||
|
];
|
||||||
|
|
||||||
/** Champ d'archivage (groupe client:write:archive). */
|
/** Champ d'archivage (groupe client:write:archive). */
|
||||||
private const string ARCHIVE_FIELD = 'isArchived';
|
private const string ARCHIVE_FIELD = 'isArchived';
|
||||||
|
|
||||||
@@ -101,6 +109,7 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
private readonly ProcessorInterface $persistProcessor,
|
private readonly ProcessorInterface $persistProcessor,
|
||||||
private readonly ClientFieldNormalizer $normalizer,
|
private readonly ClientFieldNormalizer $normalizer,
|
||||||
private readonly ClientInformationCompletenessValidator $informationValidator,
|
private readonly ClientInformationCompletenessValidator $informationValidator,
|
||||||
|
private readonly ClientAccountingCompletenessValidator $accountingValidator,
|
||||||
private readonly Security $security,
|
private readonly Security $security,
|
||||||
private readonly RequestStack $requestStack,
|
private readonly RequestStack $requestStack,
|
||||||
private readonly EntityManagerInterface $em,
|
private readonly EntityManagerInterface $em,
|
||||||
@@ -124,9 +133,9 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
// valeurs normalisees des deux cotes (l'etat persiste l'a deja ete).
|
// valeurs normalisees des deux cotes (l'etat persiste l'a deja ete).
|
||||||
$this->guardManage($data);
|
$this->guardManage($data);
|
||||||
|
|
||||||
$this->validateMainContact($data);
|
|
||||||
$this->validateDistributorBroker($data);
|
$this->validateDistributorBroker($data);
|
||||||
$this->validateAccountingConsistency($data);
|
$this->validateAccountingConsistency($data);
|
||||||
|
$this->validateAccountingCompleteness($data);
|
||||||
$this->validateInformationCompleteness($data);
|
$this->validateInformationCompleteness($data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -274,11 +283,6 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
{
|
{
|
||||||
$newValues = [
|
$newValues = [
|
||||||
'companyName' => $data->getCompanyName(),
|
'companyName' => $data->getCompanyName(),
|
||||||
'firstName' => $data->getFirstName(),
|
|
||||||
'lastName' => $data->getLastName(),
|
|
||||||
'phonePrimary' => $data->getPhonePrimary(),
|
|
||||||
'phoneSecondary' => $data->getPhoneSecondary(),
|
|
||||||
'email' => $data->getEmail(),
|
|
||||||
'distributor' => $data->getDistributor(),
|
'distributor' => $data->getDistributor(),
|
||||||
'broker' => $data->getBroker(),
|
'broker' => $data->getBroker(),
|
||||||
'triageService' => $data->isTriageService(),
|
'triageService' => $data->isTriageService(),
|
||||||
@@ -420,39 +424,17 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalisation serveur (RG-1.18 a 1.21). Les setters non-nullables
|
* Normalisation serveur du formulaire principal (RG-1.18). Seul companyName
|
||||||
* (companyName, email, phonePrimary) ne sont touches que si une valeur est
|
* subsiste cote Client depuis la suppression du contact inline (les champs de
|
||||||
* presente, pour ne jamais ecraser l'existant lors d'un PATCH partiel.
|
* contact — noms, telephones, email — sont normalises par ClientContactProcessor).
|
||||||
|
* Le setter non-nullable n'est touche que si une valeur est presente, pour ne
|
||||||
|
* jamais ecraser l'existant lors d'un PATCH partiel.
|
||||||
*/
|
*/
|
||||||
private function normalize(Client $data): void
|
private function normalize(Client $data): void
|
||||||
{
|
{
|
||||||
if (null !== $data->getCompanyName()) {
|
if (null !== $data->getCompanyName()) {
|
||||||
$data->setCompanyName((string) $this->normalizer->normalizeCompanyName($data->getCompanyName()));
|
$data->setCompanyName((string) $this->normalizer->normalizeCompanyName($data->getCompanyName()));
|
||||||
}
|
}
|
||||||
if (null !== $data->getEmail()) {
|
|
||||||
$data->setEmail((string) $this->normalizer->normalizeEmail($data->getEmail()));
|
|
||||||
}
|
|
||||||
if (null !== $data->getPhonePrimary()) {
|
|
||||||
$data->setPhonePrimary((string) $this->normalizer->normalizePhone($data->getPhonePrimary()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$data->setFirstName($this->normalizer->normalizePersonName($data->getFirstName()));
|
|
||||||
$data->setLastName($this->normalizer->normalizePersonName($data->getLastName()));
|
|
||||||
$data->setPhoneSecondary($this->normalizer->normalizePhone($data->getPhoneSecondary()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.01 : au moins le prenom OU le nom du contact principal.
|
|
||||||
*/
|
|
||||||
private function validateMainContact(Client $data): void
|
|
||||||
{
|
|
||||||
if (null === $data->getFirstName() && null === $data->getLastName()) {
|
|
||||||
$this->throwViolation(
|
|
||||||
'firstName',
|
|
||||||
'Le prénom ou le nom du contact principal est obligatoire.',
|
|
||||||
$data,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -515,6 +497,29 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* spec-front § Onglet Comptabilite : a la validation COMPLETE de l'onglet
|
||||||
|
* (les six champs obligatoires presents dans le payload — le front les envoie
|
||||||
|
* toujours ensemble), chacun doit etre renseigne, sinon 422 par champ. On ne
|
||||||
|
* declenche pas sur un PATCH ciblant un sous-ensemble de champs comptables :
|
||||||
|
* ce n'est pas une validation d'onglet (edition ponctuelle preservee). bank /
|
||||||
|
* RIB restent geres par validateAccountingConsistency (RG-1.12 / RG-1.13).
|
||||||
|
*
|
||||||
|
* Colonnes nullable en base + validateur contextuel (meme parti que RG-1.04) :
|
||||||
|
* un Assert\NotBlank sur l'entite casserait le POST de l'onglet principal, qui
|
||||||
|
* n'envoie aucun champ comptable.
|
||||||
|
*/
|
||||||
|
private function validateAccountingCompleteness(Client $data): void
|
||||||
|
{
|
||||||
|
// Declenche uniquement si TOUS les champs requis sont presents dans le
|
||||||
|
// payload (= soumission d'onglet, pas un PATCH partiel cible).
|
||||||
|
if ([] !== array_diff(self::ACCOUNTING_REQUIRED_FIELDS, $this->payloadKeys())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->accountingValidator->validate($data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-1.04 (durcie ERP-74) : si l'utilisateur porte le role metier
|
* RG-1.04 (durcie ERP-74) : si l'utilisateur porte le role metier
|
||||||
* Commerciale, TOUS les champs de l'onglet Information sont obligatoires sur
|
* Commerciale, TOUS les champs de l'onglet Information sont obligatoires sur
|
||||||
|
|||||||
+8
-2
@@ -12,6 +12,7 @@ use App\Module\Commercial\Domain\Entity\ClientRib;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processor d'ecriture de la sous-ressource RIB d'un client (M1, § 4.5).
|
* Processor d'ecriture de la sous-ressource RIB d'un client (M1, § 4.5).
|
||||||
@@ -77,9 +78,14 @@ final class ClientRibProcessor implements ProcessorInterface
|
|||||||
? $clientId
|
? $clientId
|
||||||
: $this->em->getRepository(Client::class)->find($clientId);
|
: $this->em->getRepository(Client::class)->find($clientId);
|
||||||
|
|
||||||
if ($client instanceof Client) {
|
// read:false sur le POST : sans stade lecture, un parent introuvable n'est
|
||||||
$rib->setClient($client);
|
// plus intercepte en amont -> 404 explicite (sinon 500 au persist sur la
|
||||||
|
// contrainte client_id NOT NULL).
|
||||||
|
if (!$client instanceof Client) {
|
||||||
|
throw new NotFoundHttpException('Client introuvable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rib->setClient($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ final class ClientExportController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Colonnes dans l'ordre impose par la spec § 4.6. SIREN inseree avant la
|
* Colonnes de l'export. Depuis la suppression du contact inline (refonte
|
||||||
|
* contact, D2), les colonnes de contact principal sont retirees : l'export
|
||||||
|
* ne porte plus que les donnees propres au Client. SIREN inseree avant la
|
||||||
* date de creation, uniquement si l'utilisateur a accounting.view.
|
* date de creation, uniquement si l'utilisateur a accounting.view.
|
||||||
*
|
*
|
||||||
* @return list<string>
|
* @return list<string>
|
||||||
@@ -95,11 +97,6 @@ final class ClientExportController
|
|||||||
{
|
{
|
||||||
$headers = [
|
$headers = [
|
||||||
'Nom entreprise',
|
'Nom entreprise',
|
||||||
'Nom contact principal',
|
|
||||||
'Prénom',
|
|
||||||
'Téléphone principal',
|
|
||||||
'Téléphone secondaire',
|
|
||||||
'Email',
|
|
||||||
'Catégories',
|
'Catégories',
|
||||||
'Sites',
|
'Sites',
|
||||||
];
|
];
|
||||||
@@ -123,11 +120,6 @@ final class ClientExportController
|
|||||||
foreach ($clients as $client) {
|
foreach ($clients as $client) {
|
||||||
$row = [
|
$row = [
|
||||||
$client->getCompanyName(),
|
$client->getCompanyName(),
|
||||||
$client->getLastName(),
|
|
||||||
$client->getFirstName(),
|
|
||||||
$client->getPhonePrimary(),
|
|
||||||
$client->getPhoneSecondary(),
|
|
||||||
$client->getEmail(),
|
|
||||||
$this->formatCategories($client),
|
$this->formatCategories($client),
|
||||||
$this->formatSites($client),
|
$this->formatSites($client),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -112,10 +112,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$gso, $gsoIsNew] = $this->ensureClient(
|
[$gso, $gsoIsNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Distrib Grand Sud-Ouest',
|
companyName: 'Distrib Grand Sud-Ouest',
|
||||||
firstName: 'Paul',
|
|
||||||
lastName: 'Garnier',
|
|
||||||
phonePrimary: '05 56 10 20 30',
|
|
||||||
email: 'contact@distrib-gso.fr',
|
|
||||||
categoryNames: ['Distributeur'],
|
categoryNames: ['Distributeur'],
|
||||||
);
|
);
|
||||||
if ($gsoIsNew) {
|
if ($gsoIsNew) {
|
||||||
@@ -127,10 +123,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$leonard, $leonardIsNew] = $this->ensureClient(
|
[$leonard, $leonardIsNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Cabinet Léonard Assurances',
|
companyName: 'Cabinet Léonard Assurances',
|
||||||
firstName: 'Sophie',
|
|
||||||
lastName: 'Léonard',
|
|
||||||
phonePrimary: '05 49 11 22 33',
|
|
||||||
email: 'contact@cabinet-leonard.fr',
|
|
||||||
categoryNames: ['Courtier'],
|
categoryNames: ['Courtier'],
|
||||||
);
|
);
|
||||||
if ($leonardIsNew) {
|
if ($leonardIsNew) {
|
||||||
@@ -142,10 +134,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$dubois, $isNew] = $this->ensureClient(
|
[$dubois, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Menuiserie Dubois',
|
companyName: 'Menuiserie Dubois',
|
||||||
firstName: 'Jean',
|
|
||||||
lastName: 'Dubois',
|
|
||||||
phonePrimary: '05 49 00 00 01',
|
|
||||||
email: 'contact@menuiserie-dubois.fr',
|
|
||||||
categoryNames: ['BTP'],
|
categoryNames: ['BTP'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -159,10 +147,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$garage, $isNew] = $this->ensureClient(
|
[$garage, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Garage Martin',
|
companyName: 'Garage Martin',
|
||||||
firstName: 'Luc',
|
|
||||||
lastName: 'Martin',
|
|
||||||
phonePrimary: '05 56 44 55 66',
|
|
||||||
email: 'accueil@garage-martin.fr',
|
|
||||||
categoryNames: ['Services'],
|
categoryNames: ['Services'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -175,10 +159,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$boulangerie, $isNew] = $this->ensureClient(
|
[$boulangerie, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Boulangerie Lemoine',
|
companyName: 'Boulangerie Lemoine',
|
||||||
firstName: 'Marie',
|
|
||||||
lastName: 'Lemoine',
|
|
||||||
phonePrimary: '05 49 77 88 99',
|
|
||||||
email: 'bonjour@boulangerie-lemoine.fr',
|
|
||||||
categoryNames: ['Agro-alimentaire'],
|
categoryNames: ['Agro-alimentaire'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -191,10 +171,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$transports, $isNew] = $this->ensureClient(
|
[$transports, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Transports Rapides',
|
companyName: 'Transports Rapides',
|
||||||
firstName: null,
|
|
||||||
lastName: 'Bernard',
|
|
||||||
phonePrimary: '05 56 12 13 14',
|
|
||||||
email: 'exploitation@transports-rapides.fr',
|
|
||||||
categoryNames: ['Transport/Logistique'],
|
categoryNames: ['Transport/Logistique'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -209,10 +185,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$industries, $isNew] = $this->ensureClient(
|
[$industries, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Industries Vertes',
|
companyName: 'Industries Vertes',
|
||||||
firstName: 'Claire',
|
|
||||||
lastName: 'Moreau',
|
|
||||||
phonePrimary: '05 49 21 22 23',
|
|
||||||
email: 'contact@industries-vertes.fr',
|
|
||||||
categoryNames: ['Industrie'],
|
categoryNames: ['Industrie'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -229,12 +201,7 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$agro, $isNew] = $this->ensureClient(
|
[$agro, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Agro Distribution Sud',
|
companyName: 'Agro Distribution Sud',
|
||||||
firstName: 'Thomas',
|
|
||||||
lastName: 'Petit',
|
|
||||||
phonePrimary: '05 56 31 32 33',
|
|
||||||
email: 'contact@agro-sud.fr',
|
|
||||||
categoryNames: ['Agro-alimentaire'],
|
categoryNames: ['Agro-alimentaire'],
|
||||||
phoneSecondary: '06 01 02 03 04',
|
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
$this->addContact($agro, 'Thomas', 'Petit', 'Directeur des achats', '05 56 31 32 33', '06 01 02 03 04', 'thomas.petit@agro-sud.fr', 0);
|
$this->addContact($agro, 'Thomas', 'Petit', 'Directeur des achats', '05 56 31 32 33', '06 01 02 03 04', 'thomas.petit@agro-sud.fr', 0);
|
||||||
@@ -247,10 +214,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$ancienne, $isNew] = $this->ensureClient(
|
[$ancienne, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Ancienne Société Oubliée',
|
companyName: 'Ancienne Société Oubliée',
|
||||||
firstName: null,
|
|
||||||
lastName: 'Durand',
|
|
||||||
phonePrimary: '05 49 99 99 99',
|
|
||||||
email: 'contact@ancienne-societe.fr',
|
|
||||||
categoryNames: ['Association'],
|
categoryNames: ['Association'],
|
||||||
isArchived: true,
|
isArchived: true,
|
||||||
);
|
);
|
||||||
@@ -263,10 +226,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$services, $isNew] = $this->ensureClient(
|
[$services, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Services Pro Conseil',
|
companyName: 'Services Pro Conseil',
|
||||||
firstName: 'Nadia',
|
|
||||||
lastName: 'Benali',
|
|
||||||
phonePrimary: '05 49 41 42 43',
|
|
||||||
email: 'contact@services-pro.fr',
|
|
||||||
categoryNames: ['Services'],
|
categoryNames: ['Services'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -279,10 +238,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$holding, $isNew] = $this->ensureClient(
|
[$holding, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Holding Premium Invest',
|
companyName: 'Holding Premium Invest',
|
||||||
firstName: 'Antoine',
|
|
||||||
lastName: 'Lefèvre',
|
|
||||||
phonePrimary: '05 56 51 52 53',
|
|
||||||
email: 'direction@holding-premium.fr',
|
|
||||||
categoryNames: ['Industrie'],
|
categoryNames: ['Industrie'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -301,10 +256,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$conglo, $isNew] = $this->ensureClient(
|
[$conglo, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Conglomérat Multi Activités',
|
companyName: 'Conglomérat Multi Activités',
|
||||||
firstName: 'Hélène',
|
|
||||||
lastName: 'Faure',
|
|
||||||
phonePrimary: '05 49 61 62 63',
|
|
||||||
email: 'contact@conglomerat-multi.fr',
|
|
||||||
categoryNames: ['BTP', 'Industrie', 'Services'],
|
categoryNames: ['BTP', 'Industrie', 'Services'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -316,10 +267,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$prospect, $isNew] = $this->ensureClient(
|
[$prospect, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Prospect Futur Client',
|
companyName: 'Prospect Futur Client',
|
||||||
firstName: 'Olivier',
|
|
||||||
lastName: 'Renard',
|
|
||||||
phonePrimary: '05 56 71 72 73',
|
|
||||||
email: 'olivier.renard@prospect-futur.fr',
|
|
||||||
categoryNames: ['BTP'],
|
categoryNames: ['BTP'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -331,10 +278,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
[$association, $isNew] = $this->ensureClient(
|
[$association, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Association des Riverains',
|
companyName: 'Association des Riverains',
|
||||||
firstName: null,
|
|
||||||
lastName: 'Caron',
|
|
||||||
phonePrimary: '05 49 81 82 83',
|
|
||||||
email: 'contact@asso-riverains.fr',
|
|
||||||
categoryNames: ['Association'],
|
categoryNames: ['Association'],
|
||||||
);
|
);
|
||||||
if ($isNew) {
|
if ($isNew) {
|
||||||
@@ -350,6 +293,9 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
* sinon retourne l'existant. Retourne [Client, isNew] : isNew=false bloque la
|
* sinon retourne l'existant. Retourne [Client, isNew] : isNew=false bloque la
|
||||||
* reconstruction des sous-collections (idempotence sans doublon).
|
* reconstruction des sous-collections (idempotence sans doublon).
|
||||||
*
|
*
|
||||||
|
* Le contact principal n'est plus porte par le Client (refonte contact) : les
|
||||||
|
* coordonnees de contact sont fournies via addContact() dans le bloc isNew.
|
||||||
|
*
|
||||||
* @param list<string> $categoryNames
|
* @param list<string> $categoryNames
|
||||||
*
|
*
|
||||||
* @return array{0: Client, 1: bool}
|
* @return array{0: Client, 1: bool}
|
||||||
@@ -357,12 +303,7 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
private function ensureClient(
|
private function ensureClient(
|
||||||
ObjectManager $manager,
|
ObjectManager $manager,
|
||||||
string $companyName,
|
string $companyName,
|
||||||
?string $firstName,
|
|
||||||
?string $lastName,
|
|
||||||
string $phonePrimary,
|
|
||||||
string $email,
|
|
||||||
array $categoryNames,
|
array $categoryNames,
|
||||||
?string $phoneSecondary = null,
|
|
||||||
bool $isArchived = false,
|
bool $isArchived = false,
|
||||||
): array {
|
): array {
|
||||||
$normalizedName = (string) $this->normalizer->normalizeCompanyName($companyName);
|
$normalizedName = (string) $this->normalizer->normalizeCompanyName($companyName);
|
||||||
@@ -374,11 +315,6 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$client->setCompanyName($normalizedName);
|
$client->setCompanyName($normalizedName);
|
||||||
$client->setFirstName($this->normalizer->normalizePersonName($firstName));
|
|
||||||
$client->setLastName($this->normalizer->normalizePersonName($lastName));
|
|
||||||
$client->setPhonePrimary((string) $this->normalizer->normalizePhone($phonePrimary));
|
|
||||||
$client->setPhoneSecondary($this->normalizer->normalizePhone($phoneSecondary));
|
|
||||||
$client->setEmail((string) $this->normalizer->normalizeEmail($email));
|
|
||||||
|
|
||||||
foreach ($categoryNames as $categoryName) {
|
foreach ($categoryNames as $categoryName) {
|
||||||
$client->addCategory($this->category($manager, $categoryName));
|
$client->addCategory($this->category($manager, $categoryName));
|
||||||
|
|||||||
@@ -103,9 +103,11 @@ class DoctrineClientRepository extends ServiceEntityRepository implements Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recherche fuzzy insensible a la casse sur companyName + lastName + email.
|
* Recherche fuzzy insensible a la casse sur companyName (D1, refonte contact).
|
||||||
* Les metacaracteres LIKE (%, _, \) saisis sont echappes pour rester
|
* Depuis la suppression du contact inline du Client, la recherche ne porte
|
||||||
* litteraux.
|
* plus que sur le nom d'entreprise (les anciens criteres lastName / email
|
||||||
|
* vivaient sur les colonnes inline disparues). Les metacaracteres LIKE
|
||||||
|
* (%, _, \) saisis sont echappes pour rester litteraux.
|
||||||
*/
|
*/
|
||||||
private function applySearch(QueryBuilder $qb, ?string $search): void
|
private function applySearch(QueryBuilder $qb, ?string $search): void
|
||||||
{
|
{
|
||||||
@@ -116,11 +118,9 @@ class DoctrineClientRepository extends ServiceEntityRepository implements Client
|
|||||||
$escaped = str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], trim($search));
|
$escaped = str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], trim($search));
|
||||||
$pattern = '%'.mb_strtolower($escaped, 'UTF-8').'%';
|
$pattern = '%'.mb_strtolower($escaped, 'UTF-8').'%';
|
||||||
|
|
||||||
$qb->andWhere(
|
$qb->andWhere('LOWER(c.companyName) LIKE :search')
|
||||||
'LOWER(c.companyName) LIKE :search '
|
->setParameter('search', $pattern)
|
||||||
.'OR LOWER(c.lastName) LIKE :search '
|
;
|
||||||
.'OR LOWER(c.email) LIKE :search',
|
|
||||||
)->setParameter('search', $pattern);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -79,13 +79,15 @@ class Role
|
|||||||
|
|
||||||
#[ORM\Column(length: 100)]
|
#[ORM\Column(length: 100)]
|
||||||
#[Groups(['role:read', 'role:write'])]
|
#[Groups(['role:read', 'role:write'])]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'Le code du rôle est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Regex(pattern: '/^[a-z][a-z0-9_]*$/', message: 'Le code doit etre en snake_case et commencer par une lettre minuscule.')]
|
#[Assert\Regex(pattern: '/^[a-z][a-z0-9_]*$/', message: 'Le code doit être en snake_case et commencer par une lettre minuscule.')]
|
||||||
|
#[Assert\Length(max: 100, maxMessage: 'Le code ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
private string $code;
|
private string $code;
|
||||||
|
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
#[Groups(['role:read', 'role:write'])]
|
#[Groups(['role:read', 'role:write'])]
|
||||||
#[Assert\NotBlank]
|
#[Assert\NotBlank(message: 'Le libellé du rôle est obligatoire.', normalizer: 'trim')]
|
||||||
|
#[Assert\Length(max: 255, maxMessage: 'Le libellé ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
private string $label;
|
private string $label;
|
||||||
|
|
||||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
use Symfony\Component\Serializer\Attribute\Groups;
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
@@ -85,6 +86,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Busines
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180, unique: true)]
|
#[ORM\Column(length: 180, unique: true)]
|
||||||
|
#[Assert\NotBlank(message: 'Le nom d\'utilisateur est obligatoire.', normalizer: 'trim')]
|
||||||
|
#[Assert\Length(max: 180, maxMessage: 'Le nom d\'utilisateur ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['me:read', 'user:list', 'user:write'])]
|
#[Groups(['me:read', 'user:list', 'user:write'])]
|
||||||
private ?string $username = null;
|
private ?string $username = null;
|
||||||
|
|
||||||
|
|||||||
+12
@@ -30,6 +30,8 @@ use function sprintf;
|
|||||||
* - resource != Site::class → no-op (les autres resources sont
|
* - resource != Site::class → no-op (les autres resources sont
|
||||||
* gerees par SiteScopedQueryExtension) ;
|
* gerees par SiteScopedQueryExtension) ;
|
||||||
* - is_granted('sites.bypass_scope') → pas de filtre (admin / bypass) ;
|
* - is_granted('sites.bypass_scope') → pas de filtre (admin / bypass) ;
|
||||||
|
* - is_granted('sites.read_ref') → pas de filtre (lecture-referentiel
|
||||||
|
* transverse complet, ERP-102) ;
|
||||||
* - user non authentifie → no-op (API Platform renvoie 401 avant) ;
|
* - user non authentifie → no-op (API Platform renvoie 401 avant) ;
|
||||||
* - user sans aucun site → WHERE 1 = 0 (aucun acces) ;
|
* - user sans aucun site → WHERE 1 = 0 (aucun acces) ;
|
||||||
* - cas normal → WHERE site.id IN (:allowedSites).
|
* - cas normal → WHERE site.id IN (:allowedSites).
|
||||||
@@ -84,6 +86,16 @@ final class SiteCollectionScopedExtension implements QueryCollectionExtensionInt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2bis) Lecture-referentiel transverse (ERP-102) : `sites.read_ref` donne
|
||||||
|
// acces a la LISTE COMPLETE des sites (selects d'adresse des modules Tiers).
|
||||||
|
// Sans ce bypass, le cloisonnement par site rattache reduirait le select
|
||||||
|
// aux seuls sites de l'utilisateur (voire a rien s'il n'en a aucun) et le
|
||||||
|
// referentiel ne serait plus "transverse". `read_ref` est une lecture seule :
|
||||||
|
// il ouvre la visibilite sans permettre la moindre ecriture.
|
||||||
|
if ($this->security->isGranted('sites.read_ref')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 3) Pas d'user authentifie -> no-op (API Platform gere le 401 en amont).
|
// 3) Pas d'user authentifie -> no-op (API Platform gere le 401 en amont).
|
||||||
$user = $this->security->getUser();
|
$user = $this->security->getUser();
|
||||||
if (!$user instanceof User) {
|
if (!$user instanceof User) {
|
||||||
|
|||||||
@@ -166,14 +166,12 @@ final class ColumnCommentsCatalog
|
|||||||
],
|
],
|
||||||
|
|
||||||
'client' => [
|
'client' => [
|
||||||
'_table' => 'Repertoire clients (M1 Commercial) — entites archivables (is_archived) et soft-deletables (deleted_at, HP M2).',
|
'_table' => 'Repertoire clients (M1 Commercial) — entites archivables (is_archived) et soft-deletables (deleted_at, HP M2).',
|
||||||
'id' => 'Identifiant interne auto-incremente.',
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
'company_name' => 'Raison sociale (stockee en MAJUSCULES, RG-1.18). Unique case-insensitive parmi les actifs non archives/non supprimes (RG-1.16, uq_client_company_name_active).',
|
'company_name' => 'Raison sociale (stockee en MAJUSCULES, RG-1.18). Unique case-insensitive parmi les actifs non archives/non supprimes (RG-1.16, uq_client_company_name_active).',
|
||||||
'first_name' => 'Prenom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).',
|
// Contact principal inline supprime (refonte contact) : first_name,
|
||||||
'last_name' => 'Nom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).',
|
// last_name, phone_primary, phone_secondary, email vivent desormais
|
||||||
'phone_primary' => 'Telephone principal — stocke en chiffres uniquement (RG-1.20). Obligatoire.',
|
// uniquement sur client_contact.
|
||||||
'phone_secondary' => 'Telephone secondaire optionnel — chiffres uniquement (RG-1.20).',
|
|
||||||
'email' => 'Email principal (lowercase serveur, RG-1.21). NON unique (RG-1.17 supprimee, Q4).',
|
|
||||||
'distributor_id' => 'FK auto-referente vers un client porteur de la categorie DISTRIBUTEUR — exclusive avec broker_id (RG-1.03, chk_client_distrib_or_broker). FK -> client.id, ON DELETE SET NULL.',
|
'distributor_id' => 'FK auto-referente vers un client porteur de la categorie DISTRIBUTEUR — exclusive avec broker_id (RG-1.03, chk_client_distrib_or_broker). FK -> client.id, ON DELETE SET NULL.',
|
||||||
'broker_id' => 'FK auto-referente vers un client porteur de la categorie COURTIER — exclusive avec distributor_id (RG-1.03). FK -> client.id, ON DELETE SET NULL.',
|
'broker_id' => 'FK auto-referente vers un client porteur de la categorie COURTIER — exclusive avec distributor_id (RG-1.03). FK -> client.id, ON DELETE SET NULL.',
|
||||||
'triage_service' => 'Drapeau service triage active pour le client. Faux par defaut.',
|
'triage_service' => 'Drapeau service triage active pour le client. Faux par defaut.',
|
||||||
|
|||||||
@@ -219,6 +219,19 @@
|
|||||||
"config/routes/security.yaml"
|
"config/routes/security.yaml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"symfony/translation": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "6.3",
|
||||||
|
"ref": "620a1b84865ceb2ba304c8f8bf2a185fbf32a843"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/translation.yaml",
|
||||||
|
"translations/.gitignore"
|
||||||
|
]
|
||||||
|
},
|
||||||
"symfony/twig-bundle": {
|
"symfony/twig-bundle": {
|
||||||
"version": "8.0",
|
"version": "8.0",
|
||||||
"recipe": {
|
"recipe": {
|
||||||
|
|||||||
@@ -0,0 +1,363 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Architecture;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping\Column;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ReflectionClass;
|
||||||
|
use ReflectionProperty;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
use function in_array;
|
||||||
|
use function is_string;
|
||||||
|
use function sprintf;
|
||||||
|
use function str_contains;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Garde-fou architecture ERP-107 : toute contrainte `#[Assert\*]` portee par une
|
||||||
|
* entite metier doit avoir un message FR EXPLICITE (et non le defaut anglais de
|
||||||
|
* Symfony), et toute colonne string bornee writable doit avoir une `Assert\Length`
|
||||||
|
* calee sur le `length` de la colonne ORM.
|
||||||
|
*
|
||||||
|
* Pourquoi (lien ERP-101) : le front (useFormErrors / mapViolationsToRecord)
|
||||||
|
* affiche sous chaque champ le `message` renvoye par le back. Un message absent
|
||||||
|
* = defaut anglais ; une colonne bornee sans Assert\Length = erreur Postgres
|
||||||
|
* (500) au lieu d'une 422 propre rattachee au champ.
|
||||||
|
*
|
||||||
|
* Deux verifications, sur le modele de AuditableEntitiesHaveI18nLabelTest :
|
||||||
|
* 1. MESSAGE EXPLICITE : pour chaque contrainte connue, la (ou les) propriete(s)
|
||||||
|
* de message pertinente(s) doivent differer du defaut Symfony. La comparaison
|
||||||
|
* au defaut (instance « nue » de la meme contrainte) evite de valider un
|
||||||
|
* message anglais natif laisse tel quel.
|
||||||
|
* 2. LENGTH == ORM length : toute propriete string writable avec `ORM\Column(length:)`
|
||||||
|
* doit porter `Assert\Length(max:)` egal a ce length — sauf si le format est
|
||||||
|
* deja borne par Bic/Iban, ou whitelistee dans EXCLUDED_LENGTH_MIRROR.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class EntityConstraintsHaveFrenchMessageTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Proprietes writable exemptees du miroir Assert\Length == ORM length, avec
|
||||||
|
* justification. Toute entree doit citer la raison (format deja borne par une
|
||||||
|
* autre contrainte). Cle : "<ClasseCourte>::<propriete>".
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
private const array EXCLUDED_LENGTH_MIRROR = [
|
||||||
|
// Le Regex /^[0-9]{4,5}$/ borne deja la longueur a 5 caracteres (< 20).
|
||||||
|
'ClientAddress::postalCode' => 'Regex {4,5} borne deja la longueur.',
|
||||||
|
// Le Regex /^#[0-9A-Fa-f]{6}$/ borne la longueur a exactement 7 caracteres.
|
||||||
|
'Site::color' => 'Regex code hex #RRGGBB borne deja la longueur.',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapping contrainte -> proprietes de message a verifier. Une contrainte
|
||||||
|
* absente de ce mapping (hors Callback) fait ECHOUER le test : il faut
|
||||||
|
* l'ajouter explicitement (anti faux positif vert sur une contrainte inconnue).
|
||||||
|
*
|
||||||
|
* Pour Length / Count, la liste est calculee dynamiquement (minMessage si
|
||||||
|
* `min` est pose, maxMessage si `max` est pose).
|
||||||
|
*
|
||||||
|
* @var list<class-string<Constraint>>
|
||||||
|
*/
|
||||||
|
private const array SIMPLE_MESSAGE_CONSTRAINTS = [
|
||||||
|
Assert\NotBlank::class,
|
||||||
|
Assert\NotNull::class,
|
||||||
|
Assert\Email::class,
|
||||||
|
Assert\Regex::class,
|
||||||
|
Assert\Bic::class,
|
||||||
|
Assert\Iban::class,
|
||||||
|
Assert\PositiveOrZero::class,
|
||||||
|
Assert\Positive::class,
|
||||||
|
Assert\NegativeOrZero::class,
|
||||||
|
Assert\Negative::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
public function testEveryConstraintHasAnExplicitFrenchMessage(): void
|
||||||
|
{
|
||||||
|
$checked = 0;
|
||||||
|
|
||||||
|
foreach ($this->entityProperties() as [$shortClass, $property]) {
|
||||||
|
foreach ($property->getAttributes() as $attribute) {
|
||||||
|
$name = $attribute->getName();
|
||||||
|
if (!is_subclass_of($name, Constraint::class)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Les Callback portent leur message dans la closure : hors scope.
|
||||||
|
if (Assert\Callback::class === $name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Constraint $constraint */
|
||||||
|
$constraint = $attribute->newInstance();
|
||||||
|
$messageProps = $this->messagePropertiesFor($constraint);
|
||||||
|
|
||||||
|
self::assertNotNull(
|
||||||
|
$messageProps,
|
||||||
|
sprintf(
|
||||||
|
'Contrainte non geree par le garde-fou : %s sur %s::$%s. '
|
||||||
|
.'Ajouter sa classe au mapping de EntityConstraintsHaveFrenchMessageTest.',
|
||||||
|
$name,
|
||||||
|
$shortClass,
|
||||||
|
$property->getName(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($messageProps as $prop) {
|
||||||
|
$actual = $constraint->{$prop} ?? null;
|
||||||
|
$default = $this->defaultMessageFor($name, $prop);
|
||||||
|
|
||||||
|
self::assertTrue(
|
||||||
|
is_string($actual) && '' !== $actual && $actual !== $default,
|
||||||
|
sprintf(
|
||||||
|
'La contrainte %s sur %s::$%s n\'a pas de %s FR explicite '
|
||||||
|
.'(message absent ou laisse au defaut anglais). Cf. ERP-107.',
|
||||||
|
$name,
|
||||||
|
$shortClass,
|
||||||
|
$property->getName(),
|
||||||
|
$prop,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
++$checked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self::assertGreaterThan(0, $checked, 'Aucune contrainte verifiee : detection d\'attributs cassee ?');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBoundedStringColumnsHaveMatchingLength(): void
|
||||||
|
{
|
||||||
|
$checked = 0;
|
||||||
|
|
||||||
|
foreach ($this->entityProperties() as [$shortClass, $property]) {
|
||||||
|
$column = $this->ormColumn($property);
|
||||||
|
if (null === $column || null === $column->length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Colonnes non-string (text, decimal, date...) : pas de length scalaire a calquer.
|
||||||
|
if (null !== $column->type && 'string' !== $column->type) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Le miroir ne protege que la saisie utilisateur (champs writable).
|
||||||
|
if (!$this->isPropertyWritable($property)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$constraints = $this->constraintsOf($property);
|
||||||
|
|
||||||
|
// Format deja borne par Bic/Iban : longueur garantie cote contrainte.
|
||||||
|
if ($this->hasAnyConstraint($constraints, [Assert\Bic::class, Assert\Iban::class])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$excludeKey = $shortClass.'::'.$property->getName();
|
||||||
|
if (isset(self::EXCLUDED_LENGTH_MIRROR[$excludeKey])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$length = null;
|
||||||
|
foreach ($constraints as $c) {
|
||||||
|
if ($c instanceof Assert\Length) {
|
||||||
|
$length = $c->max;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self::assertNotNull(
|
||||||
|
$length,
|
||||||
|
sprintf(
|
||||||
|
'%s::$%s est une colonne string bornee (length=%d) writable sans Assert\Length : '
|
||||||
|
.'risque d\'erreur Postgres 500. Ajouter Assert\Length(max: %d) ou whitelister. Cf. ERP-107.',
|
||||||
|
$shortClass,
|
||||||
|
$property->getName(),
|
||||||
|
$column->length,
|
||||||
|
$column->length,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
self::assertSame(
|
||||||
|
$column->length,
|
||||||
|
$length,
|
||||||
|
sprintf(
|
||||||
|
'Derive Assert\Length.max (%s) != ORM length (%d) sur %s::$%s. '
|
||||||
|
.'Le max doit refleter le length de la colonne (anti-derive ERP-107).',
|
||||||
|
(string) $length,
|
||||||
|
$column->length,
|
||||||
|
$shortClass,
|
||||||
|
$property->getName(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
++$checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::assertGreaterThan(0, $checked, 'Aucune colonne string bornee verifiee : scan casse ?');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Itere (classe courte, ReflectionProperty) sur toutes les entites metier
|
||||||
|
* sous src/Module/<m>/Domain/Entity/.
|
||||||
|
*
|
||||||
|
* @return iterable<array{0: string, 1: ReflectionProperty}>
|
||||||
|
*/
|
||||||
|
private function entityProperties(): iterable
|
||||||
|
{
|
||||||
|
$finder = new Finder()
|
||||||
|
->files()
|
||||||
|
->in(__DIR__.'/../../src/Module')
|
||||||
|
->path('Domain/Entity')
|
||||||
|
->name('*.php')
|
||||||
|
;
|
||||||
|
|
||||||
|
self::assertNotEmpty(iterator_to_array($finder), 'Aucune entite scannee : chemin src/Module invalide ?');
|
||||||
|
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
$fqcn = $this->extractFqcn($file->getRealPath());
|
||||||
|
if (null === $fqcn) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflection = new ReflectionClass($fqcn);
|
||||||
|
if ($reflection->isAbstract()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($reflection->getProperties() as $property) {
|
||||||
|
yield [$reflection->getShortName(), $property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste des proprietes de message a verifier pour une contrainte donnee, ou
|
||||||
|
* null si la contrainte n'est pas geree (le test echoue alors explicitement).
|
||||||
|
*
|
||||||
|
* @return list<string>|null
|
||||||
|
*/
|
||||||
|
private function messagePropertiesFor(Constraint $constraint): ?array
|
||||||
|
{
|
||||||
|
if ($constraint instanceof Assert\Length) {
|
||||||
|
$props = [];
|
||||||
|
if (null !== $constraint->min) {
|
||||||
|
$props[] = 'minMessage';
|
||||||
|
}
|
||||||
|
if (null !== $constraint->max) {
|
||||||
|
$props[] = 'maxMessage';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $props;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($constraint instanceof Assert\Count) {
|
||||||
|
$props = [];
|
||||||
|
if (null !== $constraint->min) {
|
||||||
|
$props[] = 'minMessage';
|
||||||
|
}
|
||||||
|
if (null !== $constraint->max) {
|
||||||
|
$props[] = 'maxMessage';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $props;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($constraint::class, self::SIMPLE_MESSAGE_CONSTRAINTS, true)) {
|
||||||
|
return ['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message par defaut d'une contrainte (instance « nue ») pour la propriete
|
||||||
|
* demandee. Sert de reference pour detecter un message laisse au defaut.
|
||||||
|
*/
|
||||||
|
private function defaultMessageFor(string $class, string $prop): ?string
|
||||||
|
{
|
||||||
|
$bare = match ($class) {
|
||||||
|
Assert\Length::class => new Assert\Length(max: 1),
|
||||||
|
Assert\Count::class => new Assert\Count(min: 1),
|
||||||
|
Assert\Regex::class => new Assert\Regex(pattern: '/^x$/'),
|
||||||
|
default => new $class(),
|
||||||
|
};
|
||||||
|
|
||||||
|
$value = $bare->{$prop} ?? null;
|
||||||
|
|
||||||
|
return is_string($value) ? $value : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ormColumn(ReflectionProperty $property): ?Column
|
||||||
|
{
|
||||||
|
$attrs = $property->getAttributes(Column::class);
|
||||||
|
|
||||||
|
return [] === $attrs ? null : $attrs[0]->newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<Constraint> */
|
||||||
|
private function constraintsOf(ReflectionProperty $property): array
|
||||||
|
{
|
||||||
|
$out = [];
|
||||||
|
foreach ($property->getAttributes() as $attribute) {
|
||||||
|
if (is_subclass_of($attribute->getName(), Constraint::class)) {
|
||||||
|
$out[] = $attribute->newInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<Constraint> $constraints
|
||||||
|
* @param list<class-string<Constraint>> $classes
|
||||||
|
*/
|
||||||
|
private function hasAnyConstraint(array $constraints, array $classes): bool
|
||||||
|
{
|
||||||
|
foreach ($constraints as $c) {
|
||||||
|
if (in_array($c::class, $classes, true)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isPropertyWritable(ReflectionProperty $property): bool
|
||||||
|
{
|
||||||
|
$attrs = $property->getAttributes(Groups::class);
|
||||||
|
if ([] === $attrs) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Groups $groups */
|
||||||
|
$groups = $attrs[0]->newInstance();
|
||||||
|
foreach ($groups->groups as $group) {
|
||||||
|
if (is_string($group) && str_contains($group, 'write')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function extractFqcn(string $path): ?string
|
||||||
|
{
|
||||||
|
$source = file_get_contents($path);
|
||||||
|
if (false === $source) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
1 !== preg_match('/^namespace\s+([^;]+);/m', $source, $nsMatch)
|
||||||
|
|| 1 !== preg_match('/^(?:final\s+|abstract\s+|readonly\s+)*class\s+(\w+)/m', $source, $classMatch)
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim($nsMatch[1]).'\\'.$classMatch[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -126,9 +126,6 @@ abstract class AbstractCommercialApiTestCase extends AbstractApiTestCase
|
|||||||
// Stocke en MAJUSCULES pour refleter l'etat normalise (RG-1.18) qu'aurait
|
// Stocke en MAJUSCULES pour refleter l'etat normalise (RG-1.18) qu'aurait
|
||||||
// produit le ClientProcessor via l'API.
|
// produit le ClientProcessor via l'API.
|
||||||
$client->setCompanyName(mb_strtoupper($companyName, 'UTF-8'));
|
$client->setCompanyName(mb_strtoupper($companyName, 'UTF-8'));
|
||||||
$client->setLastName('Seed');
|
|
||||||
$client->setPhonePrimary('0102030405');
|
|
||||||
$client->setEmail(strtolower(str_replace(' ', '', $companyName)).'@seed.test');
|
|
||||||
$client->addCategory($this->createCategory($categoryCode));
|
$client->addCategory($this->createCategory($categoryCode));
|
||||||
$client->setIsArchived($isArchived);
|
$client->setIsArchived($isArchived);
|
||||||
if ($isArchived) {
|
if ($isArchived) {
|
||||||
|
|||||||
@@ -167,8 +167,9 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
public function testNonBillingAddressAcceptsEmptyBillingEmail(): void
|
public function testNonBillingAddressAcceptsEmptyBillingEmail(): void
|
||||||
{
|
{
|
||||||
$this->skipIfSitesModuleDisabled();
|
$this->skipIfSitesModuleDisabled();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$seed = $this->seedClient('Non Billing Empty Email');
|
$seed = $this->seedClient('Non Billing Empty Email');
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
@@ -179,6 +180,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
'sites' => [$this->firstSiteIri()],
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -286,6 +288,29 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spec-front § Adresse : au moins une categorie est obligatoire sur une
|
||||||
|
* adresse. POST sans categorie (mais avec site) -> 422.
|
||||||
|
*/
|
||||||
|
public function testAddressRequiresAtLeastOneCategory(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Address No Cat');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne l'IRI du premier site seede (fixtures Sites).
|
* Retourne l'IRI du premier site seede (fixtures Sites).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
{
|
{
|
||||||
private const string LD = 'application/ld+json';
|
private const string LD = 'application/ld+json';
|
||||||
|
|
||||||
public function testPostNormalizesTextFields(): void
|
public function testPostNormalizesCompanyName(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$cat = $this->createCategory('SECTEUR');
|
$cat = $this->createCategory('SECTEUR');
|
||||||
@@ -33,23 +33,18 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
$response = $client->request('POST', '/api/clients', [
|
$response = $client->request('POST', '/api/clients', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'acme sas',
|
'companyName' => 'acme sas',
|
||||||
'firstName' => 'JEAN',
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
'lastName' => 'dupont',
|
|
||||||
'phonePrimary' => '06.12.34.56.78',
|
|
||||||
'email' => 'Jean.DUPONT@ACME.FR',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
$data = $response->toArray();
|
$data = $response->toArray();
|
||||||
// RG-1.18 / 1.19 / 1.20 / 1.21
|
// RG-1.18 : companyName normalise en MAJUSCULES. Les champs de contact
|
||||||
|
// inline ont disparu (refonte contact) -> plus de normalisation ici.
|
||||||
self::assertSame('ACME SAS', $data['companyName']);
|
self::assertSame('ACME SAS', $data['companyName']);
|
||||||
self::assertSame('Jean', $data['firstName']);
|
self::assertArrayNotHasKey('firstName', $data);
|
||||||
self::assertSame('Dupont', $data['lastName']);
|
self::assertArrayNotHasKey('email', $data);
|
||||||
self::assertSame('0612345678', $data['phonePrimary']);
|
|
||||||
self::assertSame('jean.dupont@acme.fr', $data['email']);
|
|
||||||
self::assertFalse($data['isArchived']);
|
self::assertFalse($data['isArchived']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,41 +55,18 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
$iri = '/api/categories/'.$cat->getId();
|
$iri = '/api/categories/'.$cat->getId();
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'companyName' => 'Doublon SARL',
|
'companyName' => 'Doublon SARL',
|
||||||
'firstName' => 'A',
|
'categories' => [$iri],
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'dup@test.fr',
|
|
||||||
'categories' => [$iri],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload]);
|
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload]);
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|
||||||
// Meme nom (insensible a la casse via l'index LOWER) -> 409 (RG-1.16).
|
// Meme nom (insensible a la casse via l'index LOWER) -> 409 (RG-1.16).
|
||||||
$payload['email'] = 'dup2@test.fr';
|
|
||||||
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload]);
|
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload]);
|
||||||
self::assertResponseStatusCodeSame(409);
|
self::assertResponseStatusCodeSame(409);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPostWithoutFirstOrLastNameReturns422(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'companyName' => 'No Contact Name',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'nc@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// RG-1.01
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPostWithoutCategoryReturns422(): void
|
public function testPostWithoutCategoryReturns422(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
@@ -102,11 +74,8 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
$client->request('POST', '/api/clients', [
|
$client->request('POST', '/api/clients', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'No Category',
|
'companyName' => 'No Category',
|
||||||
'firstName' => 'A',
|
'categories' => [],
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'nocat@test.fr',
|
|
||||||
'categories' => [],
|
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -124,9 +93,6 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Mutex Client',
|
'companyName' => 'Mutex Client',
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'mutex@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
'distributor' => '/api/clients/'.$distributor->getId(),
|
'distributor' => '/api/clients/'.$distributor->getId(),
|
||||||
'broker' => '/api/clients/'.$distributor->getId(),
|
'broker' => '/api/clients/'.$distributor->getId(),
|
||||||
@@ -147,9 +113,6 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Bad Distrib Ref',
|
'companyName' => 'Bad Distrib Ref',
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'baddistrib@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
'distributor' => '/api/clients/'.$notDistro->getId(),
|
'distributor' => '/api/clients/'.$notDistro->getId(),
|
||||||
],
|
],
|
||||||
@@ -169,9 +132,6 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Client Avec Distrib',
|
'companyName' => 'Client Avec Distrib',
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'okdistrib@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
'distributor' => '/api/clients/'.$distributor->getId(),
|
'distributor' => '/api/clients/'.$distributor->getId(),
|
||||||
],
|
],
|
||||||
@@ -190,9 +150,6 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Bad Broker Ref',
|
'companyName' => 'Bad Broker Ref',
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'badbroker@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
'broker' => '/api/clients/'.$notBroker->getId(),
|
'broker' => '/api/clients/'.$notBroker->getId(),
|
||||||
],
|
],
|
||||||
@@ -212,9 +169,6 @@ final class ClientApiTest extends AbstractCommercialApiTestCase
|
|||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Client Avec Courtier',
|
'companyName' => 'Client Avec Courtier',
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'okbroker@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
'broker' => '/api/clients/'.$broker->getId(),
|
'broker' => '/api/clients/'.$broker->getId(),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -68,9 +68,6 @@ final class ClientAuditTest extends AbstractCommercialApiTestCase
|
|||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Blamable Co',
|
'companyName' => 'Blamable Co',
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'blamable@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
],
|
],
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ namespace App\Tests\Module\Commercial\Api;
|
|||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests fonctionnels du formulaire principal — combler les trous (ERP-60).
|
* Tests fonctionnels du formulaire principal apres la refonte contact.
|
||||||
*
|
*
|
||||||
* RG-1.01 (prenom OU nom obligatoire) et RG-1.03 (distributor/broker exclusifs
|
* RG-1.01 (prenom OU nom) et RG-1.02 (telephone secondaire) ont ete SUPPRIMEES
|
||||||
* + type de categorie) sont DEJA couverts par ClientApiTest (ERP-55) : on ne les
|
* du Client : le contact principal n'est plus porte inline, il vit uniquement
|
||||||
* reduplique pas ici. Ce fichier ne couvre que RG-1.02 (telephone secondaire),
|
* dans ClientContact (onglet Contact). Ce fichier verifie que :
|
||||||
* non encore testee.
|
* - le formulaire principal se cree avec les seuls champs subsistants
|
||||||
|
* (companyName + categories), sans aucun champ de contact ;
|
||||||
|
* - les anciens champs de contact (firstName, lastName, phonePrimary,
|
||||||
|
* phoneSecondary, email) ne sont plus exposes ni persistes.
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@@ -21,11 +24,10 @@ final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
|
|||||||
private const string LD = 'application/ld+json';
|
private const string LD = 'application/ld+json';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-1.02 : le telephone secondaire est optionnel mais persiste (2 colonnes
|
* Le formulaire principal n'exige plus que companyName + au moins une
|
||||||
* distinctes). Verifie aussi la normalisation chiffres-seuls (RG-1.20) sur
|
* categorie (RG-1.16 / RG sur categories). Aucun champ de contact requis.
|
||||||
* la colonne secondaire.
|
|
||||||
*/
|
*/
|
||||||
public function testPostPersistsSecondaryPhoneNormalized(): void
|
public function testPostMainFormWithoutContactFields(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$cat = $this->createCategory('SECTEUR');
|
$cat = $this->createCategory('SECTEUR');
|
||||||
@@ -33,26 +35,28 @@ final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
|
|||||||
$data = $client->request('POST', '/api/clients', [
|
$data = $client->request('POST', '/api/clients', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Two Phones SARL',
|
'companyName' => 'Main Form SARL',
|
||||||
'firstName' => 'A',
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
'phonePrimary' => '06.12.34.56.78',
|
|
||||||
'phoneSecondary' => '05 49 00 11 22',
|
|
||||||
'email' => 'twophones@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
|
||||||
],
|
],
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
self::assertSame('0612345678', $data['phonePrimary']);
|
self::assertSame('MAIN FORM SARL', $data['companyName']);
|
||||||
self::assertSame('0549001122', $data['phoneSecondary']);
|
|
||||||
|
// Les champs de contact inline ont disparu de la representation.
|
||||||
|
self::assertArrayNotHasKey('firstName', $data);
|
||||||
|
self::assertArrayNotHasKey('lastName', $data);
|
||||||
|
self::assertArrayNotHasKey('phonePrimary', $data);
|
||||||
|
self::assertArrayNotHasKey('phoneSecondary', $data);
|
||||||
|
self::assertArrayNotHasKey('email', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-1.02 : maximum 2 telephones — le modele n'expose que phonePrimary et
|
* Les anciens champs de contact envoyes par un appel API direct (payload
|
||||||
* phoneSecondary. Un eventuel 3e champ envoye par un appel API direct est
|
* historique) sont ignores par le denormaliseur : ils n'apparaissent pas
|
||||||
* ignore (aucune 3e colonne), il ne peut donc pas creer un troisieme numero.
|
* dans la representation et ne creent aucune colonne sur le client.
|
||||||
*/
|
*/
|
||||||
public function testThirdPhoneFieldIsIgnored(): void
|
public function testLegacyContactFieldsAreIgnored(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$cat = $this->createCategory('SECTEUR');
|
$cat = $this->createCategory('SECTEUR');
|
||||||
@@ -60,25 +64,25 @@ final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
|
|||||||
$data = $client->request('POST', '/api/clients', [
|
$data = $client->request('POST', '/api/clients', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
'companyName' => 'Third Phone SARL',
|
'companyName' => 'Legacy Fields SARL',
|
||||||
'firstName' => 'A',
|
'firstName' => 'Ignored',
|
||||||
|
'lastName' => 'Ignored',
|
||||||
'phonePrimary' => '0612345678',
|
'phonePrimary' => '0612345678',
|
||||||
'phoneSecondary' => '0549001122',
|
'phoneSecondary' => '0549001122',
|
||||||
'phoneTertiary' => '0700000000',
|
'email' => 'ignored@test.fr',
|
||||||
'email' => 'thirdphone@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
],
|
],
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
// Le champ inconnu est ignore par le denormaliseur : il n'apparait pas
|
self::assertArrayNotHasKey('firstName', $data);
|
||||||
// dans la representation et n'a pas ete persiste.
|
self::assertArrayNotHasKey('phonePrimary', $data);
|
||||||
self::assertArrayNotHasKey('phoneTertiary', $data);
|
self::assertArrayNotHasKey('email', $data);
|
||||||
|
|
||||||
// Confirmation cote base : seules les 2 colonnes telephone existent.
|
// Confirmation cote base : le client cree ne porte aucun contact inline
|
||||||
|
// (les colonnes n'existent plus, l'entite n'a plus les proprietes).
|
||||||
$persisted = $this->getEm()->getRepository(ClientEntity::class)->find($data['id']);
|
$persisted = $this->getEm()->getRepository(ClientEntity::class)->find($data['id']);
|
||||||
self::assertNotNull($persisted);
|
self::assertNotNull($persisted);
|
||||||
self::assertSame('0612345678', $persisted->getPhonePrimary());
|
self::assertSame('LEGACY FIELDS SARL', $persisted->getCompanyName());
|
||||||
self::assertSame('0549001122', $persisted->getPhoneSecondary());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,41 @@ namespace App\Tests\Module\Commercial\Api;
|
|||||||
* - les anciens index uq_client_siren_active (RG-1.15) et uq_client_email_active
|
* - les anciens index uq_client_siren_active (RG-1.15) et uq_client_email_active
|
||||||
* (RG-1.17) ont ete supprimes / ne sont jamais crees.
|
* (RG-1.17) ont ete supprimes / ne sont jamais crees.
|
||||||
*
|
*
|
||||||
|
* Verifie aussi la refonte contact (Version20260603120000) : les 5 colonnes de
|
||||||
|
* contact principal inline ont ete supprimees de la table `client`.
|
||||||
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class ClientMigrationTest extends AbstractCommercialApiTestCase
|
final class ClientMigrationTest extends AbstractCommercialApiTestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Refonte contact : first_name / last_name / phone_primary / phone_secondary
|
||||||
|
* / email ne doivent plus exister sur la table `client` (deplaces vers
|
||||||
|
* client_contact). NB : le backfill de la migration ne s'exerce que sur une
|
||||||
|
* base portant des donnees pre-refonte ; sur le schema de test (table client
|
||||||
|
* vierge au moment de la migration) il est un no-op, donc non assertable ici
|
||||||
|
* au runtime — seul l'etat de schema final est verifie.
|
||||||
|
*/
|
||||||
|
public function testInlineContactColumnsAreDropped(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
|
||||||
|
/** @var list<array{column_name: string}> $columns */
|
||||||
|
$columns = $this->getEm()->getConnection()->fetchAllAssociative(
|
||||||
|
"SELECT column_name FROM information_schema.columns "
|
||||||
|
."WHERE table_schema = 'public' AND table_name = 'client'",
|
||||||
|
);
|
||||||
|
$names = array_map(static fn (array $r): string => $r['column_name'], $columns);
|
||||||
|
|
||||||
|
foreach (['first_name', 'last_name', 'phone_primary', 'phone_secondary', 'email'] as $dropped) {
|
||||||
|
self::assertNotContains(
|
||||||
|
$dropped,
|
||||||
|
$names,
|
||||||
|
sprintf('La colonne client.%s aurait du etre supprimee (refonte contact).', $dropped),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testCompanyNameActivePartialIndexExistsExactlyOnce(): void
|
public function testCompanyNameActivePartialIndexExistsExactlyOnce(): void
|
||||||
{
|
{
|
||||||
$rows = $this->clientIndexes();
|
$rows = $this->clientIndexes();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace App\Tests\Module\Commercial\Api;
|
|||||||
|
|
||||||
use ApiPlatform\Symfony\Bundle\Test\Client;
|
use ApiPlatform\Symfony\Bundle\Test\Client;
|
||||||
use App\Module\Core\Infrastructure\DataFixtures\RbacDemoFixtures;
|
use App\Module\Core\Infrastructure\DataFixtures\RbacDemoFixtures;
|
||||||
|
use App\Module\Sites\Domain\Entity\Site;
|
||||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
@@ -281,14 +282,32 @@ final class ClientRBACMatrixTest extends AbstractCommercialApiTestCase
|
|||||||
// / sites.read_ref) attachee par la matrice § 2.7 — sans pour autant porter
|
// / sites.read_ref) attachee par la matrice § 2.7 — sans pour autant porter
|
||||||
// la permission d'administration `.view`. Usine, sans aucune permission,
|
// la permission d'administration `.view`. Usine, sans aucune permission,
|
||||||
// reste interdit.
|
// reste interdit.
|
||||||
|
// Le referentiel /sites est TRANSVERSE et COMPLET : le cloisonnement par
|
||||||
|
// site rattache (SiteCollectionScopedExtension) est neutralise par
|
||||||
|
// `sites.read_ref` (ERP-102). Les comptes demo ne sont rattaches qu'a un
|
||||||
|
// seul site (Chatellerault) alors que la base en compte plusieurs : on
|
||||||
|
// verifie donc que le role voit la TOTALITE du referentiel, pas son seul
|
||||||
|
// site rattache. Sans le bypass de scope, totalItems vaudrait 1.
|
||||||
|
$totalSites = $this->getEm()->getRepository(Site::class)->count([]);
|
||||||
|
self::assertGreaterThan(
|
||||||
|
1,
|
||||||
|
$totalSites,
|
||||||
|
'Pre-requis du test : la base doit contenir plusieurs sites pour distinguer scope et bypass.',
|
||||||
|
);
|
||||||
|
|
||||||
foreach (['bureau', 'compta', 'commerciale'] as $role) {
|
foreach (['bureau', 'compta', 'commerciale'] as $role) {
|
||||||
$client = $this->authAs($role);
|
$client = $this->authAs($role);
|
||||||
|
|
||||||
$client->request('GET', '/api/categories', ['headers' => ['Accept' => self::LD]]);
|
$client->request('GET', '/api/categories', ['headers' => ['Accept' => self::LD]]);
|
||||||
self::assertResponseStatusCodeSame(200, sprintf('Le role %s doit pouvoir lister /categories', $role));
|
self::assertResponseStatusCodeSame(200, sprintf('Le role %s doit pouvoir lister /categories', $role));
|
||||||
|
|
||||||
$client->request('GET', '/api/sites', ['headers' => ['Accept' => self::LD]]);
|
$response = $client->request('GET', '/api/sites', ['headers' => ['Accept' => self::LD]]);
|
||||||
self::assertResponseStatusCodeSame(200, sprintf('Le role %s doit pouvoir lister /sites', $role));
|
self::assertResponseStatusCodeSame(200, sprintf('Le role %s doit pouvoir lister /sites', $role));
|
||||||
|
self::assertSame(
|
||||||
|
$totalSites,
|
||||||
|
$response->toArray()['totalItems'] ?? null,
|
||||||
|
sprintf('Le role %s doit voir tout le referentiel sites (%d), pas seulement son site rattache', $role, $totalSites),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usine : aucune permission -> reste a 403 sur les referentiels.
|
// Usine : aucune permission -> reste a 403 sur les referentiels.
|
||||||
@@ -305,9 +324,9 @@ final class ClientRBACMatrixTest extends AbstractCommercialApiTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payload minimal valide de l'onglet principal (RG-1.01 : un nom de contact ;
|
* Payload minimal valide de l'onglet principal (companyName + une categorie
|
||||||
* une categorie SECTEUR). Si $categoryId est null, une categorie est creee a
|
* SECTEUR ; le contact inline a ete supprime). Si $categoryId est null, une
|
||||||
* la volee.
|
* categorie est creee a la volee.
|
||||||
*
|
*
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
@@ -316,11 +335,8 @@ final class ClientRBACMatrixTest extends AbstractCommercialApiTestCase
|
|||||||
$categoryId ??= $this->createCategory('SECTEUR')->getId();
|
$categoryId ??= $this->createCategory('SECTEUR')->getId();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'companyName' => $companyName,
|
'companyName' => $companyName,
|
||||||
'firstName' => 'Jean',
|
'categories' => ['/api/categories/'.$categoryId],
|
||||||
'phonePrimary' => '0612345678',
|
|
||||||
'email' => strtolower(str_replace(' ', '', $companyName)).'@matrix.test',
|
|
||||||
'categories' => ['/api/categories/'.$categoryId],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,9 +232,6 @@ final class ClientSerializationContractTest extends AbstractCommercialApiTestCas
|
|||||||
|
|
||||||
$client = new ClientEntity();
|
$client = new ClientEntity();
|
||||||
$client->setCompanyName(mb_strtoupper($companyName.' '.$suffix, 'UTF-8'));
|
$client->setCompanyName(mb_strtoupper($companyName.' '.$suffix, 'UTF-8'));
|
||||||
$client->setLastName('Complet');
|
|
||||||
$client->setPhonePrimary('0102030405');
|
|
||||||
$client->setEmail('complet'.$suffix.'@seed.test');
|
|
||||||
$client->addCategory($this->createCategory('SECTEUR'));
|
$client->addCategory($this->createCategory('SECTEUR'));
|
||||||
// Bloc comptable non nul (gating par omission cote Commerciale).
|
// Bloc comptable non nul (gating par omission cote Commerciale).
|
||||||
$client->setSiren('123456789');
|
$client->setSiren('123456789');
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Tests\Module\Commercial\Api;
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
||||||
use App\Module\Commercial\Domain\Entity\ClientContact;
|
use App\Module\Commercial\Domain\Entity\ClientContact;
|
||||||
use App\Module\Commercial\Domain\Entity\ClientRib;
|
use App\Module\Commercial\Domain\Entity\ClientRib;
|
||||||
use App\Module\Commercial\Domain\Entity\PaymentType;
|
use App\Module\Commercial\Domain\Entity\PaymentType;
|
||||||
@@ -66,6 +67,98 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP-107 : une violation de contrainte sort avec un message FR explicite ET
|
||||||
|
* un `propertyPath` rattache au champ (consommable par useFormErrors /
|
||||||
|
* mapViolationsToRecord cote front, ERP-101). On verifie le JSON 422 reel.
|
||||||
|
*/
|
||||||
|
public function testPostContactInvalidEmailReturns422WithFrenchMessageOnField(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Contact Bad Email');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'firstName' => 'Jean',
|
||||||
|
'email' => 'pas-un-email',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = [];
|
||||||
|
foreach ($response->toArray(false)['violations'] ?? [] as $v) {
|
||||||
|
$byPath[$v['propertyPath']] = $v['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
self::assertArrayHasKey('email', $byPath, 'La violation email doit porter propertyPath=email (mapping front).');
|
||||||
|
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression ERP-110 (bug subresource Link toProperty) : POST d'un contact sur
|
||||||
|
* un client qui en a DEJA >= 2 ne doit pas exploser en 500
|
||||||
|
* (NonUniqueResultException sur la resolution du parent), mais creer (201).
|
||||||
|
*/
|
||||||
|
public function testPostContactOnClientWithTwoExistingContactsReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Contact Multi');
|
||||||
|
$this->seedContact($seed, 'Alpha');
|
||||||
|
$this->seedContact($seed, 'Beta');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['firstName' => 'Gamma'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meme contexte (>= 2 contacts existants) : un email invalide doit produire
|
||||||
|
* une 422 par champ (la validation est bien atteinte), pas une 500.
|
||||||
|
*/
|
||||||
|
public function testPostInvalidContactOnPopulatedClientReturns422OnField(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Contact Multi Bad');
|
||||||
|
$this->seedContact($seed, 'Alpha');
|
||||||
|
$this->seedContact($seed, 'Beta');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['firstName' => 'Gamma', 'email' => 'pas-un-email'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = [];
|
||||||
|
foreach ($response->toArray(false)['violations'] ?? [] as $v) {
|
||||||
|
$byPath[$v['propertyPath']] = $v['message'];
|
||||||
|
}
|
||||||
|
self::assertArrayHasKey('email', $byPath);
|
||||||
|
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP-110 : avec read:false sur le POST, un parent introuvable n'est plus
|
||||||
|
* intercepte au stade lecture. Le 404 est desormais porte par
|
||||||
|
* ClientContactProcessor::linkParent (sinon 500 au persist sur client_id
|
||||||
|
* NOT NULL). Le payload est valide pour atteindre le processor (apres la
|
||||||
|
* validation).
|
||||||
|
*/
|
||||||
|
public function testPostContactOnMissingClientReturns404(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/999999/contacts', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['firstName' => 'Orphan'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(404);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPatchContactNormalizes(): void
|
public function testPatchContactNormalizes(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
@@ -110,9 +203,10 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
public function testPostAddressNormalizesBillingEmail(): void
|
public function testPostAddressNormalizesBillingEmail(): void
|
||||||
{
|
{
|
||||||
$this->skipIfSitesModuleDisabled();
|
$this->skipIfSitesModuleDisabled();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$seed = $this->seedClient('Address Host');
|
$seed = $this->seedClient('Address Host');
|
||||||
$siteIri = $this->firstSiteIri();
|
$siteIri = $this->firstSiteIri();
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
$data = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
$data = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
@@ -123,6 +217,7 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
'sites' => [$siteIri],
|
'sites' => [$siteIri],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
],
|
],
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
@@ -171,6 +266,61 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression ERP-110 : POST d'une adresse sur un client qui en a DEJA >= 2 ne
|
||||||
|
* doit pas exploser en 500 (NonUniqueResult sur la resolution du parent). Le
|
||||||
|
* POST porte un site + une categorie (RG-1.10 / RG-1.29) pour etre valide.
|
||||||
|
*/
|
||||||
|
public function testPostAddressOnClientWithTwoExistingAddressesReturns201(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Addr Multi');
|
||||||
|
$siteIri = $this->firstSiteIri();
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
$this->seedAddress($seed, 'Bordeaux');
|
||||||
|
$this->seedAddress($seed, 'Lyon');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'postalCode' => '75001',
|
||||||
|
'city' => 'Paris',
|
||||||
|
'street' => '2 rue Neuve',
|
||||||
|
'sites' => [$siteIri],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP-110 : POST adresse sur un client inexistant -> 404 porte par
|
||||||
|
* ClientAddressProcessor::linkParent (read:false). Payload valide (site +
|
||||||
|
* categorie, RG-1.10 / RG-1.29) pour atteindre le processor.
|
||||||
|
*/
|
||||||
|
public function testPostAddressOnMissingClientReturns404(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$siteIri = $this->firstSiteIri();
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/999999/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'postalCode' => '75001',
|
||||||
|
'city' => 'Paris',
|
||||||
|
'street' => '2 rue Neuve',
|
||||||
|
'sites' => [$siteIri],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(404);
|
||||||
|
}
|
||||||
|
|
||||||
// === RIBs ===
|
// === RIBs ===
|
||||||
|
|
||||||
public function testPostRibByAdminReturns201(): void
|
public function testPostRibByAdminReturns201(): void
|
||||||
@@ -209,6 +359,43 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression ERP-110 : POST d'un RIB sur un client qui en a DEJA >= 2 ne doit
|
||||||
|
* pas exploser en 500 (NonUniqueResult sur la resolution du parent). L'admin
|
||||||
|
* porte commercial.clients.accounting.manage requis par le POST.
|
||||||
|
*/
|
||||||
|
public function testPostRibOnClientWithTwoExistingRibsReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Rib Multi');
|
||||||
|
$this->seedRib($seed, 'Compte 1');
|
||||||
|
$this->seedRib($seed, 'Compte 2');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/ribs', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['label' => 'Compte 3', 'bic' => self::VALID_BIC, 'iban' => self::VALID_IBAN],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP-110 : POST RIB sur un client inexistant -> 404 porte par
|
||||||
|
* ClientRibProcessor::linkParent (read:false). L'admin porte
|
||||||
|
* commercial.clients.accounting.manage ; payload valide (BIC / IBAN).
|
||||||
|
*/
|
||||||
|
public function testPostRibOnMissingClientReturns404(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/999999/ribs', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => ['label' => 'Orphan', 'bic' => self::VALID_BIC, 'iban' => self::VALID_IBAN],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(404);
|
||||||
|
}
|
||||||
|
|
||||||
public function testDeleteRibNonLcrReturns204(): void
|
public function testDeleteRibNonLcrReturns204(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
@@ -276,13 +463,34 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seede un ClientRib valide rattache a un client (sans passer par l'API).
|
* Seede une adresse minimale valide en base (sans passer par l'API) : seules
|
||||||
|
* les colonnes NOT NULL sont posees (CP / ville / rue). Les M2M sites /
|
||||||
|
* categories restent vides — non contraints en base, suffisant pour peupler
|
||||||
|
* un client de plusieurs adresses.
|
||||||
*/
|
*/
|
||||||
private function seedRib(ClientEntity $client): ClientRib
|
private function seedAddress(ClientEntity $client, string $city): ClientAddress
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$address = new ClientAddress();
|
||||||
|
$address->setClient($client);
|
||||||
|
$address->setPostalCode('33000');
|
||||||
|
$address->setCity($city);
|
||||||
|
$address->setStreet('1 rue du Test');
|
||||||
|
$em->persist($address);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seede un ClientRib valide rattache a un client (sans passer par l'API). Le
|
||||||
|
* libelle est parametrable pour seeder plusieurs RIB distincts.
|
||||||
|
*/
|
||||||
|
private function seedRib(ClientEntity $client, string $label = 'Seed RIB'): ClientRib
|
||||||
{
|
{
|
||||||
$em = $this->getEm();
|
$em = $this->getEm();
|
||||||
$rib = new ClientRib();
|
$rib = new ClientRib();
|
||||||
$rib->setLabel('Seed RIB');
|
$rib->setLabel($label);
|
||||||
$rib->setBic(self::VALID_BIC);
|
$rib->setBic(self::VALID_BIC);
|
||||||
$rib->setIban(self::VALID_IBAN);
|
$rib->setIban(self::VALID_IBAN);
|
||||||
$rib->setClient($client);
|
$rib->setClient($client);
|
||||||
|
|||||||
@@ -12,41 +12,13 @@ use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|||||||
* RG-1.16 (doublon de companyName parmi les actifs -> 409) est DEJA couvert par
|
* RG-1.16 (doublon de companyName parmi les actifs -> 409) est DEJA couvert par
|
||||||
* ClientApiTest::testPostDuplicateCompanyNameReturns409 (ERP-55). Ce fichier
|
* ClientApiTest::testPostDuplicateCompanyNameReturns409 (ERP-55). Ce fichier
|
||||||
* verifie l'envers de la decision Q4 (29/05/2026) : le SIREN (RG-1.15 supprimee)
|
* verifie l'envers de la decision Q4 (29/05/2026) : le SIREN (RG-1.15 supprimee)
|
||||||
* et l'email (RG-1.17 supprimee) NE SONT PLUS contraints uniques.
|
* n'est PLUS contraint unique. (L'email — RG-1.17 — a disparu du Client avec la
|
||||||
|
* refonte contact, il vit desormais sur ClientContact.)
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class ClientUniquenessTest extends AbstractCommercialApiTestCase
|
final class ClientUniquenessTest extends AbstractCommercialApiTestCase
|
||||||
{
|
{
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.16 / RG-1.17 (Q4) : deux clients actifs peuvent partager le meme
|
|
||||||
* email principal — aucune contrainte d'unicite (un email peut servir
|
|
||||||
* plusieurs clients).
|
|
||||||
*/
|
|
||||||
public function testDuplicateEmailIsAllowed(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
$iri = '/api/categories/'.$cat->getId();
|
|
||||||
|
|
||||||
$payload = static fn (string $name): array => [
|
|
||||||
'companyName' => $name,
|
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'partage@test.fr',
|
|
||||||
'categories' => [$iri],
|
|
||||||
];
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload('Email Share One')]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
|
|
||||||
// Meme email, nom different -> doit passer (pas d'index unique email).
|
|
||||||
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload('Email Share Two')]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-1.15 (Q4) : deux clients peuvent partager le meme SIREN (etablissements
|
* RG-1.15 (Q4) : deux clients peuvent partager le meme SIREN (etablissements
|
||||||
* multiples). Le SIREN n'est pas ecrivable au POST (groupe accounting), on
|
* multiples). Le SIREN n'est pas ecrivable au POST (groupe accounting), on
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ use ApiPlatform\Metadata\Operation;
|
|||||||
use ApiPlatform\State\ProcessorInterface;
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
use ApiPlatform\Validator\Exception\ValidationException;
|
use ApiPlatform\Validator\Exception\ValidationException;
|
||||||
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
||||||
|
use App\Module\Commercial\Application\Validator\ClientAccountingCompletenessValidator;
|
||||||
use App\Module\Commercial\Application\Validator\ClientInformationCompletenessValidator;
|
use App\Module\Commercial\Application\Validator\ClientInformationCompletenessValidator;
|
||||||
use App\Module\Commercial\Domain\Entity\Bank;
|
use App\Module\Commercial\Domain\Entity\Bank;
|
||||||
use App\Module\Commercial\Domain\Entity\Client;
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
use App\Module\Commercial\Domain\Entity\ClientRib;
|
use App\Module\Commercial\Domain\Entity\ClientRib;
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentDelay;
|
||||||
use App\Module\Commercial\Domain\Entity\PaymentType;
|
use App\Module\Commercial\Domain\Entity\PaymentType;
|
||||||
|
use App\Module\Commercial\Domain\Entity\TvaMode;
|
||||||
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientProcessor;
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientProcessor;
|
||||||
use App\Shared\Domain\Contract\BusinessRoleAwareInterface;
|
use App\Shared\Domain\Contract\BusinessRoleAwareInterface;
|
||||||
use App\Shared\Domain\Security\BusinessRoles;
|
use App\Shared\Domain\Security\BusinessRoles;
|
||||||
@@ -134,14 +137,11 @@ final class ClientProcessorTest extends TestCase
|
|||||||
'isArchived' => false,
|
'isArchived' => false,
|
||||||
],
|
],
|
||||||
managed: true,
|
managed: true,
|
||||||
// Etat persiste complet (valeurs normalisees) : sans les champs
|
// Etat persiste (valeurs normalisees) : sans companyName, guardManage
|
||||||
// metier, guardManage (ERP-74) les croirait modifies (companyName,
|
// (ERP-74) le croirait modifie (compare a null) et leverait un 403
|
||||||
// lastName... compares a null) et leverait un 403 parasite.
|
// parasite.
|
||||||
originalData: [
|
originalData: [
|
||||||
'companyName' => 'TEST CO',
|
'companyName' => 'TEST CO',
|
||||||
'lastName' => 'Dupont',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 't@test.fr',
|
|
||||||
'triageService' => false,
|
'triageService' => false,
|
||||||
'isArchived' => false,
|
'isArchived' => false,
|
||||||
],
|
],
|
||||||
@@ -164,13 +164,10 @@ final class ClientProcessorTest extends TestCase
|
|||||||
managed: true,
|
managed: true,
|
||||||
// getOriginalEntityData renvoie tous les champs mappes d'une entite
|
// getOriginalEntityData renvoie tous les champs mappes d'une entite
|
||||||
// geree : isArchived (non-null) y figure toujours, ainsi que les
|
// geree : isArchived (non-null) y figure toujours, ainsi que les
|
||||||
// champs metier (sinon guardManage les croirait modifies).
|
// champs metier (companyName) sinon guardManage les croirait modifies.
|
||||||
originalData: [
|
originalData: [
|
||||||
'siren' => '123456789',
|
'siren' => '123456789',
|
||||||
'companyName' => 'TEST CO',
|
'companyName' => 'TEST CO',
|
||||||
'lastName' => 'Dupont',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 't@test.fr',
|
|
||||||
'triageService' => false,
|
'triageService' => false,
|
||||||
'isArchived' => false,
|
'isArchived' => false,
|
||||||
],
|
],
|
||||||
@@ -193,9 +190,6 @@ final class ClientProcessorTest extends TestCase
|
|||||||
managed: true,
|
managed: true,
|
||||||
originalData: [
|
originalData: [
|
||||||
'companyName' => 'TEST CO',
|
'companyName' => 'TEST CO',
|
||||||
'lastName' => 'Dupont',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 't@test.fr',
|
|
||||||
'triageService' => false,
|
'triageService' => false,
|
||||||
'isArchived' => false,
|
'isArchived' => false,
|
||||||
],
|
],
|
||||||
@@ -220,9 +214,6 @@ final class ClientProcessorTest extends TestCase
|
|||||||
originalData: [
|
originalData: [
|
||||||
'siren' => '111111111',
|
'siren' => '111111111',
|
||||||
'companyName' => 'TEST CO',
|
'companyName' => 'TEST CO',
|
||||||
'lastName' => 'Dupont',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 't@test.fr',
|
|
||||||
'triageService' => false,
|
'triageService' => false,
|
||||||
'isArchived' => false,
|
'isArchived' => false,
|
||||||
],
|
],
|
||||||
@@ -292,6 +283,65 @@ final class ClientProcessorTest extends TestCase
|
|||||||
self::assertInstanceOf(Client::class, $processor->process($client, $this->operation()));
|
self::assertInstanceOf(Client::class, $processor->process($client, $this->operation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFullAccountingSubmitWithEmptyFieldsIsUnprocessable(): void
|
||||||
|
{
|
||||||
|
// spec-front § Onglet Comptabilite : une validation complete de l'onglet
|
||||||
|
// (les 6 champs presents dans le payload) avec des valeurs vides -> 422.
|
||||||
|
// C'est le bug corrige : avant, le back acceptait un onglet tout vide.
|
||||||
|
$client = $this->minimalClient(); // aucun champ comptable renseigne
|
||||||
|
|
||||||
|
$processor = $this->makeProcessor(
|
||||||
|
granted: ['commercial.clients.accounting.manage'],
|
||||||
|
payload: $this->emptyAccountingPayload(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->expectException(ValidationException::class);
|
||||||
|
$processor->process($client, $this->operation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFullAccountingSubmitWithAllFieldsPasses(): void
|
||||||
|
{
|
||||||
|
// Les 6 champs obligatoires renseignes + type de reglement neutre
|
||||||
|
// (ni VIREMENT ni LCR -> ni banque ni RIB requis) -> 200.
|
||||||
|
$client = $this->minimalClient();
|
||||||
|
$client->setSiren('123456789');
|
||||||
|
$client->setAccountNumber('00012345678');
|
||||||
|
$client->setTvaMode(new TvaMode());
|
||||||
|
$client->setNTva('FR12345678901');
|
||||||
|
$client->setPaymentDelay(new PaymentDelay());
|
||||||
|
$client->setPaymentType($this->paymentType('CHEQUE'));
|
||||||
|
|
||||||
|
$processor = $this->makeProcessor(
|
||||||
|
granted: ['commercial.clients.accounting.manage'],
|
||||||
|
payload: $this->emptyAccountingPayload(),
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertInstanceOf(Client::class, $processor->process($client, $this->operation()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPartialAccountingPatchSkipsCompleteness(): void
|
||||||
|
{
|
||||||
|
// Un PATCH ciblant un seul champ comptable n'est pas une validation
|
||||||
|
// d'onglet : la completude n'est pas exigee (les autres champs restent
|
||||||
|
// vides) -> 200. Preserve l'edition ponctuelle (ex. Compta corrige le SIREN).
|
||||||
|
$client = $this->minimalClient();
|
||||||
|
$client->setSiren('999999999');
|
||||||
|
|
||||||
|
$processor = $this->makeProcessor(
|
||||||
|
granted: ['commercial.clients.accounting.manage'],
|
||||||
|
payload: ['siren' => '999999999'],
|
||||||
|
managed: true,
|
||||||
|
originalData: [
|
||||||
|
'siren' => '111111111',
|
||||||
|
'companyName' => 'TEST CO',
|
||||||
|
'triageService' => false,
|
||||||
|
'isArchived' => false,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertInstanceOf(Client::class, $processor->process($client, $this->operation()));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCommercialeIncompleteInformationIsUnprocessable(): void
|
public function testCommercialeIncompleteInformationIsUnprocessable(): void
|
||||||
{
|
{
|
||||||
// RG-1.04 : role Commerciale + onglet Information incomplet -> 422.
|
// RG-1.04 : role Commerciale + onglet Information incomplet -> 422.
|
||||||
@@ -324,9 +374,6 @@ final class ClientProcessorTest extends TestCase
|
|||||||
managed: true,
|
managed: true,
|
||||||
originalData: [
|
originalData: [
|
||||||
'companyName' => 'TEST CO',
|
'companyName' => 'TEST CO',
|
||||||
'lastName' => 'Dupont',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 't@test.fr',
|
|
||||||
'triageService' => false,
|
'triageService' => false,
|
||||||
'isArchived' => false,
|
'isArchived' => false,
|
||||||
],
|
],
|
||||||
@@ -394,6 +441,7 @@ final class ClientProcessorTest extends TestCase
|
|||||||
$persist,
|
$persist,
|
||||||
new ClientFieldNormalizer(),
|
new ClientFieldNormalizer(),
|
||||||
new ClientInformationCompletenessValidator(),
|
new ClientInformationCompletenessValidator(),
|
||||||
|
new ClientAccountingCompletenessValidator(),
|
||||||
$security,
|
$security,
|
||||||
$requestStack,
|
$requestStack,
|
||||||
$em,
|
$em,
|
||||||
@@ -401,20 +449,37 @@ final class ClientProcessorTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client minimal valide vis-a-vis de RG-1.01 (un nom de contact) — suffisant
|
* Client minimal — companyName seul depuis la suppression du contact inline.
|
||||||
* pour atteindre les validations testees.
|
* Suffisant pour atteindre les validations testees (le contact vit desormais
|
||||||
|
* dans ClientContact, hors scope du ClientProcessor).
|
||||||
*/
|
*/
|
||||||
private function minimalClient(): Client
|
private function minimalClient(): Client
|
||||||
{
|
{
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$client->setCompanyName('Test Co');
|
$client->setCompanyName('Test Co');
|
||||||
$client->setLastName('Dupont');
|
|
||||||
$client->setPhonePrimary('0102030405');
|
|
||||||
$client->setEmail('t@test.fr');
|
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payload simulant une validation complete de l'onglet Comptabilite : les 6
|
||||||
|
* champs obligatoires presents (le front les envoie toujours ensemble). Les
|
||||||
|
* valeurs importent peu — la completude est evaluee sur l'etat de l'entite.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function emptyAccountingPayload(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'siren' => null,
|
||||||
|
'accountNumber' => null,
|
||||||
|
'tvaMode' => null,
|
||||||
|
'nTva' => null,
|
||||||
|
'paymentDelay' => null,
|
||||||
|
'paymentType' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
private function paymentType(string $code): PaymentType
|
private function paymentType(string $code): PaymentType
|
||||||
{
|
{
|
||||||
$type = new PaymentType();
|
$type = new PaymentType();
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Les traductions natives FR viennent du vendor (validators.fr.xlf).
|
||||||
|
# Ce dossier accueille les overrides applicatifs eventuels.
|
||||||
Reference in New Issue
Block a user