Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26b1f2c39b | |||
| 8490de99da | |||
| b3ab23ee8f | |||
| 222338e5a4 | |||
| d4a5df50a7 | |||
| 191fd42406 | |||
| edfb2b1619 | |||
| c5c650c599 | |||
| e598a92f94 | |||
| b8dc3cb696 | |||
| 843e4b0a0c | |||
| a9c14704b7 | |||
| 43b2251ef1 | |||
| 9cda225bdf | |||
| f031c70393 | |||
| e050a7b910 | |||
| b35deed8fe | |||
| 6f9bb68170 | |||
| 97459e798f |
@@ -75,7 +75,7 @@ jobs:
|
|||||||
- name: Bootstrap test database
|
- name: Bootstrap test database
|
||||||
# Aligne sur la cible `test-db-setup` du makefile : apres
|
# Aligne sur la cible `test-db-setup` du makefile : apres
|
||||||
# `schema:update --force`, on RECREE manuellement l'index unique
|
# `schema:update --force`, on RECREE manuellement l'index unique
|
||||||
# partiel `uq_category_name_type_active` car Doctrine ORM ne sait
|
# partiel `uq_category_name_active` car Doctrine ORM ne sait
|
||||||
# pas exprimer les index fonctionnels partiels (LOWER(name) + WHERE
|
# pas exprimer les index fonctionnels partiels (LOWER(name) + WHERE
|
||||||
# deleted_at IS NULL) et `schema:update` les considere comme
|
# deleted_at IS NULL) et `schema:update` les considere comme
|
||||||
# orphelins et les DROP — collisions non detectees, tests d'unicite
|
# orphelins et les DROP — collisions non detectees, tests d'unicite
|
||||||
@@ -89,7 +89,7 @@ jobs:
|
|||||||
php bin/console app:apply-column-comments --env=test --no-interaction
|
php bin/console app:apply-column-comments --env=test --no-interaction
|
||||||
php bin/console doctrine:fixtures:load --env=test --no-interaction
|
php bin/console doctrine:fixtures:load --env=test --no-interaction
|
||||||
php bin/console app:sync-permissions --env=test --no-interaction
|
php bin/console app:sync-permissions --env=test --no-interaction
|
||||||
php bin/console --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_name_type_active ON category (LOWER(name), category_type_id) WHERE deleted_at IS NULL"
|
php bin/console --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_name_active ON category (LOWER(name)) WHERE deleted_at IS NULL"
|
||||||
|
|
||||||
- name: Run PHPUnit
|
- name: Run PHPUnit
|
||||||
run: php -d memory_limit=512M vendor/bin/phpunit
|
run: php -d memory_limit=512M vendor/bin/phpunit
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ Disponibles uniquement après `make db-reset` / `make fixtures` (état « avec s
|
|||||||
| `bob` | `bob` | ROLE_USER | — |
|
| `bob` | `bob` | ROLE_USER | — |
|
||||||
| `bureau` | `demo` | ROLE_USER | clients : view + manage |
|
| `bureau` | `demo` | ROLE_USER | clients : view + manage |
|
||||||
| `compta` | `demo` | ROLE_USER | clients : view + accounting.view / manage |
|
| `compta` | `demo` | ROLE_USER | clients : view + accounting.view / manage |
|
||||||
| `commerciale` | `demo` | ROLE_USER | clients : view + manage (Information obligatoire — RG-1.04) |
|
| `commerciale` | `demo` | ROLE_USER | clients : view + manage |
|
||||||
| `usine` | `demo` | ROLE_USER | aucun accès clients |
|
| `usine` | `demo` | ROLE_USER | aucun accès clients |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
doctrine:
|
||||||
|
dbal:
|
||||||
|
connections:
|
||||||
|
# Force le profiling DBAL en environnement de test independamment de
|
||||||
|
# APP_DEBUG. Sans cela, la CI tourne en APP_DEBUG=0 (prod-like) et le
|
||||||
|
# service `doctrine.debug_data_holder` n'est pas enregistre : le test
|
||||||
|
# anti-N+1 (SupplierListTest::testListQueryCountDoesNotGrowWithRowCount)
|
||||||
|
# qui compte les requetes via ce holder echoue alors en CI alors qu'il
|
||||||
|
# passe en local (APP_DEBUG=1). Activer le profiling ici garde le test
|
||||||
|
# actif precisement la ou il compte (CI), sans impacter la prod.
|
||||||
|
default:
|
||||||
|
profiling: true
|
||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.90'
|
app.version: '0.1.101'
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ trous, zéro duplication »).
|
|||||||
|
|
||||||
ERP-60 n'écrit QUE les tests des RG non déjà couvertes par la stack, et mappe ici
|
ERP-60 n'écrit QUE les tests des RG non déjà couvertes par la stack, et mappe ici
|
||||||
l'intégralité des RG (existantes + nouvelles + déléguées). Les tests dépendants
|
l'intégralité des RG (existantes + nouvelles + déléguées). Les tests dépendants
|
||||||
des **rôles métier** (matrice RBAC bureau/compta/commerciale/usine + RG-1.04
|
des **rôles métier** (matrice RBAC bureau/compta/commerciale/usine) sont
|
||||||
fonctionnel) sont **délégués à ERP-74 (#493)** : ces rôles n'existent qu'après le
|
**délégués à ERP-74 (#493)** : ces rôles n'existent qu'après le
|
||||||
merge de la stack.
|
merge de la stack.
|
||||||
|
|
||||||
## Mapping RG → test
|
## Mapping RG → test
|
||||||
@@ -21,7 +21,7 @@ merge de la stack.
|
|||||||
| ~~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.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~~ | _(supprimée du Client V1)_ téléphones inline retirés du Client (testés sur `ClientContact`) | — | refonte-contact |
|
| ~~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~~ | _(SUPPRIMÉE)_ Onglet Information désormais facultatif pour tous les rôles (validation de complétude retirée) | — | 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 |
|
||||||
| RG-1.06/07/08 | Adresse prospect exclusive de livraison/facturation → 422 (Assert\Callback + CHECK filet) | `ClientAddressTest::testProspectAddressCannotBeDelivery` ; `::testProspectAddressCannotBeBilling` | ERP-60 / **ERP-76** |
|
| RG-1.06/07/08 | Adresse prospect exclusive de livraison/facturation → 422 (Assert\Callback + CHECK filet) | `ClientAddressTest::testProspectAddressCannotBeDelivery` ; `::testProspectAddressCannotBeBilling` | ERP-60 / **ERP-76** |
|
||||||
| RG-1.09 | Code postal `^[0-9]{4,5}$` → 422 | `ClientSubResourceApiTest::testPostAddressWithInvalidPostalCodeReturns422` | ERP-57 |
|
| RG-1.09 | Code postal `^[0-9]{4,5}$` → 422 | `ClientSubResourceApiTest::testPostAddressWithInvalidPostalCodeReturns422` | ERP-57 |
|
||||||
@@ -60,8 +60,7 @@ merge de la stack.
|
|||||||
|
|
||||||
- **Matrice RBAC différenciée** par rôle métier (Bureau / Compta / Commerciale /
|
- **Matrice RBAC différenciée** par rôle métier (Bureau / Compta / Commerciale /
|
||||||
Usine) : 200/403 par verbe et par onglet selon le rôle.
|
Usine) : 200/403 par verbe et par onglet selon le rôle.
|
||||||
- **RG-1.04 fonctionnel** : PATCH onglet Information par une Commerciale avec
|
- ~~**RG-1.04 fonctionnel**~~ : _(SUPPRIMÉE)_ l'onglet Information est désormais facultatif pour tous les rôles.
|
||||||
champs incomplets → 422 ; même PATCH par Admin → 200 (+ durcissement code/spec).
|
|
||||||
- Raison : ces rôles métier ne sont seedés qu'après le merge de la stack M1.
|
- Raison : ces rôles métier ne sont seedés qu'après le merge de la stack M1.
|
||||||
|
|
||||||
## Gaps & suivi
|
## Gaps & suivi
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ CREATE TABLE client (
|
|||||||
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,
|
||||||
-- Onglet Information (Commerciale obligatoire — RG-1.04 — null sinon)
|
-- Onglet Information (facultatif pour tous — RG-1.04 supprimée)
|
||||||
description TEXT,
|
description TEXT,
|
||||||
competitors VARCHAR(255),
|
competitors VARCHAR(255),
|
||||||
founded_at DATE,
|
founded_at DATE,
|
||||||
@@ -864,8 +864,7 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
|
|
||||||
### Onglet Information
|
### Onglet Information
|
||||||
|
|
||||||
- **RG-1.04** _(durcie — ERP-74)_ : Pour un utilisateur portant le rôle métier **Commerciale**, **tous** les champs de l'onglet Information (`description`, `competitors`, `foundedAt`, `employeesCount`, `revenueAmount`, `directorName`, `profitAmount`) sont obligatoires sur **POST et sur tout PATCH**, **indépendamment des champs réellement envoyés** (la condition d'intersection avec `client:write:information` a été retirée). Pour les autres rôles, ces champs restent optionnels. Implémenté via un validator custom `ClientInformationCompletenessValidator` invoqué systématiquement par le `ClientProcessor` quand le user porte le rôle Commerciale.
|
- ~~**RG-1.04**~~ _(SUPPRIMÉE)_ : l'onglet Information est désormais **facultatif pour tous les rôles**, y compris Commerciale. Les champs `description`, `competitors`, `foundedAt`, `employeesCount`, `revenueAmount`, `directorName`, `profitAmount` restent optionnels (colonnes nullable, aucune validation de complétude). Le validator `ClientInformationCompletenessValidator` et le gating par rôle métier dans le `ClientProcessor` ont été retirés.
|
||||||
- **Conséquence** : le POST n'exposant que le groupe `client:write:main`, l'onglet Information n'y est pas renseignable → une Commerciale obtient **422** sur tout POST (cf. § 8.1). La complétude se fait donc via les PATCH `client:write:information` ultérieurs. Un Admin (non gaté) crée normalement (201).
|
|
||||||
|
|
||||||
### Onglet Contact
|
### Onglet Contact
|
||||||
|
|
||||||
@@ -883,7 +882,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.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` (parti pris : nullable + validateur d'onglet plutôt qu'un `Assert\NotBlank` sur l'entité). 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 ».
|
||||||
@@ -938,7 +937,7 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
- [ ] ~~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.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
|
- [x] ~~**RG-1.04**~~ _(SUPPRIMÉE)_ : onglet Information facultatif pour tous les rôles (plus de validation de complétude)
|
||||||
- [ ] **RG-1.05** : POST contact sans firstName ni lastName → 422 (BDD CHECK lève une exception)
|
- [ ] **RG-1.05** : POST contact sans firstName ni lastName → 422 (BDD CHECK lève une exception)
|
||||||
- [ ] **RG-1.06/07/08** : POST adresse avec isProspect=true ET isDelivery=true → 422 / CHECK
|
- [ ] **RG-1.06/07/08** : POST adresse avec isProspect=true ET isDelivery=true → 422 / CHECK
|
||||||
- [ ] **RG-1.09** : POST adresse avec postalCode invalide (3 chiffres) → 422 ; CP/ville incohérents → 200 (pas de validation stricte côté serveur)
|
- [ ] **RG-1.09** : POST adresse avec postalCode invalide (3 chiffres) → 422 ; CP/ville incohérents → 200 (pas de validation stricte côté serveur)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ date_redaction: 2026-05-28
|
|||||||
|
|
||||||
# === LIENS ===
|
# === LIENS ===
|
||||||
maquette_figma: "https://www.figma.com/design/jRYgT0T9c03VsEbjGhCwwS/Composants---Design-System?node-id=1132-31898"
|
maquette_figma: "https://www.figma.com/design/jRYgT0T9c03VsEbjGhCwwS/Composants---Design-System?node-id=1132-31898"
|
||||||
regles_metier: [RG-1.01, RG-1.02, RG-1.03, RG-1.04, RG-1.05, RG-1.06, RG-1.07, RG-1.08, RG-1.09, RG-1.10, RG-1.11, RG-1.12, RG-1.13, RG-1.14, RG-1.15, RG-1.16, RG-1.17, RG-1.18, RG-1.19, RG-1.20, RG-1.21, RG-1.22, RG-1.23, RG-1.24, RG-1.25, RG-1.26, RG-1.27, RG-1.28, RG-1.29]
|
regles_metier: [RG-1.01, RG-1.02, RG-1.03, RG-1.05, RG-1.06, RG-1.07, RG-1.08, RG-1.09, RG-1.10, RG-1.11, RG-1.12, RG-1.13, RG-1.14, RG-1.15, RG-1.16, RG-1.17, RG-1.18, RG-1.19, RG-1.20, RG-1.21, RG-1.22, RG-1.23, RG-1.24, RG-1.25, RG-1.26, RG-1.27, RG-1.28, RG-1.29]
|
||||||
roles: [Admin, Bureau, Compta, Commerciale, Usine]
|
roles: [Admin, Bureau, Compta, Commerciale, Usine]
|
||||||
lien_spec_back: ./spec-back.md
|
lien_spec_back: ./spec-back.md
|
||||||
|
|
||||||
@@ -105,13 +105,13 @@ Saisir les informations de l'entreprise.
|
|||||||
|
|
||||||
| Champ | Type | Obligatoire | Règle |
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| **Description** | `<MalioInputTextArea>` | Conditionnel | RG-1.04 (obligatoire pour rôle Commerciale) |
|
| **Description** | `<MalioInputTextArea>` | Non | — _(onglet facultatif, RG-1.04 supprimée)_ |
|
||||||
| **Concurrents** | `<MalioInputText>` | Conditionnel | RG-1.04 |
|
| **Concurrents** | `<MalioInputText>` | Non | — |
|
||||||
| **Date de création** (de l'entreprise) | `<input type="date">` (exception Malio — pas de composant date couvert) | Conditionnel | RG-1.04 |
|
| **Date de création** (de l'entreprise) | `<input type="date">` (exception Malio — pas de composant date couvert) | Non | — |
|
||||||
| **Nombre de salariés** | `<MalioInputNumber>` | Conditionnel | RG-1.04 |
|
| **Nombre de salariés** | `<MalioInputNumber>` | Non | — |
|
||||||
| **CA €** | `<MalioInputAmount>` | Conditionnel | RG-1.04 |
|
| **CA €** | `<MalioInputAmount>` | Non | — |
|
||||||
| **Dirigeant** | `<MalioInputText>` | Conditionnel | RG-1.04 |
|
| **Dirigeant** | `<MalioInputText>` | Non | — |
|
||||||
| **Résultat €** | `<MalioInputAmount>` | Conditionnel | RG-1.04 |
|
| **Résultat €** | `<MalioInputAmount>` | Non | — |
|
||||||
|
|
||||||
**Action** : « Valider » → PATCH partiel `/api/clients/{id}` (groupe `client:write:information`).
|
**Action** : « Valider » → PATCH partiel `/api/clients/{id}` (groupe `client:write:information`).
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ Toutes les entités métier nouvelles implémentent `TimestampableInterface` + `
|
|||||||
|
|
||||||
Notes (miroir M1) :
|
Notes (miroir M1) :
|
||||||
- **Compta édite uniquement l'onglet Comptabilité** (`accounting.manage`) d'un fournisseur existant. Compta ne peut pas **créer** un fournisseur (pas de `manage` global).
|
- **Compta édite uniquement l'onglet Comptabilité** (`accounting.manage`) d'un fournisseur existant. Compta ne peut pas **créer** un fournisseur (pas de `manage` global).
|
||||||
- **Commerciale** a `view` + `manage` mais **pas** `accounting.view` → l'onglet Comptabilité est masqué (front) et filtré (back, 2 niveaux : `security` API Platform + `SupplierProvider`).
|
- **Commerciale** a `view` + `manage` mais **pas** `accounting.view` → l'onglet Comptabilité est masqué (front) et filtré (back). Mécanisme réel (le code fait foi) : le groupe de lecture `supplier:read:accounting` n'est **pas** dans le contexte de sérialisation par défaut ; le `SupplierReadGroupContextBuilder` ne l'**ajoute** dynamiquement que si l'utilisateur porte `commercial.suppliers.accounting.view` (gating **par ajout** de groupe, jamais par retrait). Sans la permission, les champs comptables (et les RIB) ne sont donc jamais sérialisés. La colonne SIREN de l'export XLSX suit la même règle (`accounting.view`).
|
||||||
- **Bureau** : `view` + `manage` (tout sauf Comptabilité).
|
- **Bureau** : `view` + `manage` (tout sauf Comptabilité).
|
||||||
- **Usine** : aucune permission → item sidebar invisible, accès direct 403.
|
- **Usine** : aucune permission → item sidebar invisible, accès direct 403.
|
||||||
|
|
||||||
@@ -159,9 +159,11 @@ final class SupplierFieldNormalizer
|
|||||||
|
|
||||||
Le formatage `XX XX XX XX XX` est fait à l'affichage côté front. Le back stocke `0612345678` (chiffres seuls).
|
Le formatage `XX XX XX XX XX` est fait à l'affichage côté front. Le back stocke `0612345678` (chiffres seuls).
|
||||||
|
|
||||||
### 2.12 Liste : embed catégories + sites + fetch-joins (cohérence M1/ERP-62)
|
### 2.12 Liste : embed catégories + sites + hydratation anti-N+1 (cohérence M1/ERP-62)
|
||||||
|
|
||||||
Décision d'alignement (02/06/2026) : la **liste** `GET /api/suppliers` **embarque** les `categories[]` (avec `code`/`name`) et les `sites[]` (avec `name`/`postalCode` — pas de `code`), comme la liste Clients après ERP-62 — et **non** des champs dérivés aplatis. Conséquence performance : le `DoctrineSupplierRepository` **DOIT** poser des **fetch-joins** (`leftJoin`+`addSelect`) sur `categories` et `addresses.sites` dans la requête de liste pour éviter le N+1. Les `sites` de la liste sont agrégés/dédoublonnés via `Supplier::getSites()` (cf. § 3.3). Le contrat de sérialisation (groupes `category:read` / `site:read` dans le contexte) est posé **une seule fois** sur l'entité — source de vérité unique, le front ne le redéfinit pas.
|
Décision d'alignement (02/06/2026) : la **liste** `GET /api/suppliers` **embarque** les `categories[]` (avec `code`/`name`) et les `sites[]` (avec `name`/`postalCode` — pas de `code`), comme la liste Clients après ERP-62 — et **non** des champs dérivés aplatis.
|
||||||
|
|
||||||
|
Conséquence performance — **implémentation réelle (le code fait foi)** : le `DoctrineSupplierRepository` **ne fetch-joine PAS** les to-many dans la requête de sélection (`createListQueryBuilder` ne fait que filtres + tri). L'anti-N+1 passe par `hydrateListCollections()` (puis `hydrateContacts()`) : une fois le jeu de fournisseurs borné (page ou export), des requêtes **`IN` bornées séparées** remplissent `categories`, puis `addresses.sites`, puis `contacts` sur les **mêmes** instances `Supplier` (identity map). Ce découpage évite le **produit cartésien** qu'un fetch-join combiné `categories × addresses.sites` imposerait aux chemins non paginés (export, `?pagination=false`). Les `sites` de la liste sont agrégés/dédoublonnés via `Supplier::getSites()` (cf. § 3.3). Le contrat de sérialisation (groupes `category:read` / `site:read` dans le contexte) est posé **une seule fois** sur l'entité — source de vérité unique, le front ne le redéfinit pas.
|
||||||
|
|
||||||
> Dépendance confirmée sur le JSON réel (#82 mergé) : `Category` expose `code`/`name` sous `category:read` ; `Site` expose `name`/`postalCode`/`city`/`color` sous `site:read` (**pas de `code`**). L'embed est pleinement matérialisé.
|
> Dépendance confirmée sur le JSON réel (#82 mergé) : `Category` expose `code`/`name` sous `category:read` ; `Site` expose `name`/`postalCode`/`city`/`color` sous `site:read` (**pas de `code`**). L'embed est pleinement matérialisé.
|
||||||
|
|
||||||
@@ -213,6 +215,8 @@ Namespace : **`DoctrineMigrations` (racine `migrations/`)** — fichier `migrati
|
|||||||
|
|
||||||
> **Rappel règle ABSOLUE n°12** : chaque colonne créée ci-dessous DOIT recevoir son `COMMENT ON COLUMN`. Les 4 colonnes Timestampable/Blamable passent par le helper `addStandardTimestampableBlamableComments($schema, '<table>')`. Le SQL ci-dessous montre la structure ; les `COMMENT ON COLUMN` (un par colonne métier) sont à écrire dans la migration (exemples §3.2.bis).
|
> **Rappel règle ABSOLUE n°12** : chaque colonne créée ci-dessous DOIT recevoir son `COMMENT ON COLUMN`. Les 4 colonnes Timestampable/Blamable passent par le helper `addStandardTimestampableBlamableComments($schema, '<table>')`. Le SQL ci-dessous montre la structure ; les `COMMENT ON COLUMN` (un par colonne métier) sont à écrire dans la migration (exemples §3.2.bis).
|
||||||
|
|
||||||
|
> **Types réels de la migration (le code fait foi)** : le SQL ci-dessous est *illustratif*. La migration mergée (`Version20260605130000`) utilise le **style aligné M1** : clés primaires en `INT GENERATED BY DEFAULT AS IDENTITY` (et **non** `SERIAL`) et horodatages en `TIMESTAMP(0) WITHOUT TIME ZONE` (et **non** `TIMESTAMPTZ`, car le `TimestampableBlamableTrait` mappe `datetime_immutable`). Garantit que `schema:update` reste un no-op une fois les entités mappées.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
-- =====================================================================
|
-- =====================================================================
|
||||||
-- Seed taxonomie : nouveau type FOURNISSEUR (référentiels comptables = M1, non recréés)
|
-- Seed taxonomie : nouveau type FOURNISSEUR (référentiels comptables = M1, non recréés)
|
||||||
@@ -422,8 +426,10 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
// Cohérence M1/ERP-62 : la LISTE embarque catégories + sites (pas de
|
// Cohérence M1/ERP-62 : la LISTE embarque catégories + sites (pas de
|
||||||
// champ dérivé aplati). Maillon (c) : category:read + site:read dans
|
// champ dérivé aplati). Maillon (c) : category:read + site:read dans
|
||||||
// le contexte pour exposer Category(code/name) + Site(name/postalCode).
|
// le contexte pour exposer Category(code/name) + Site(name/postalCode).
|
||||||
// ⚠ Le SupplierRepository DOIT fetch-join categories + addresses.sites
|
// ⚠ Anti-N+1 : pas de fetch-join dans la requête de liste — le
|
||||||
// pour éviter le N+1 sur la liste (cf. § 2.12).
|
// SupplierRepository hydrate categories/sites/contacts via des requêtes
|
||||||
|
// IN bornées séparées (hydrateListCollections), pour éviter le produit
|
||||||
|
// cartésien sur les chemins non paginés (export) — cf. § 2.12.
|
||||||
normalizationContext: ['groups' => [
|
normalizationContext: ['groups' => [
|
||||||
'supplier:read',
|
'supplier:read',
|
||||||
'category:read',
|
'category:read',
|
||||||
@@ -442,13 +448,14 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
normalizationContext: ['groups' => [
|
normalizationContext: ['groups' => [
|
||||||
'supplier:read',
|
'supplier:read',
|
||||||
'supplier:item:read', // embed contacts / addresses
|
'supplier:item:read', // embed contacts / addresses
|
||||||
'supplier:read:accounting', // scalaires compta + embed ribs (filtré par le Provider selon accounting.view)
|
// ⚠ supplier:read:accounting est volontairement ABSENT ici : il est
|
||||||
|
// AJOUTÉ dynamiquement par le SupplierReadGroupContextBuilder quand
|
||||||
|
// l'user porte accounting.view (gating par ajout, pas par retrait —
|
||||||
|
// parade bug #4 M1). Il porte les scalaires compta + l'embed ribs.
|
||||||
'category:read', // embed des Category (id/code/name) — relation imbriquée
|
'category:read', // embed des Category (id/code/name) — relation imbriquée
|
||||||
'site:read', // embed des Site (id/name/postalCode/city/color, pas de code) — relation imbriquée
|
'site:read', // embed des Site (id/name/postalCode/city/color, pas de code) — relation imbriquée
|
||||||
'default:read',
|
'default:read',
|
||||||
]],
|
]],
|
||||||
// Le Provider RETIRE supplier:read:accounting du contexte si l'user
|
|
||||||
// n'a pas is_granted('commercial.suppliers.accounting.view').
|
|
||||||
provider: SupplierProvider::class,
|
provider: SupplierProvider::class,
|
||||||
),
|
),
|
||||||
new Post(
|
new Post(
|
||||||
@@ -458,10 +465,13 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
processor: SupplierProcessor::class,
|
processor: SupplierProcessor::class,
|
||||||
),
|
),
|
||||||
new Patch(
|
new Patch(
|
||||||
security: "is_granted('commercial.suppliers.manage')",
|
// Security élargie : `manage` OU `accounting.manage` — le rôle Compta
|
||||||
// Le SupplierProcessor inspecte les groupes envoyés pour autoriser
|
// n'a pas `manage` mais doit pouvoir éditer l'onglet Comptabilité d'un
|
||||||
// onglet par onglet (cf. § 2.10 + § 5). Patch des champs comptables
|
// fournisseur existant (§ 2.9). Le SupplierProcessor re-gate ensuite
|
||||||
// exige is_granted('commercial.suppliers.accounting.manage') ;
|
// onglet par onglet (mode strict RG-2.16) :
|
||||||
|
security: "is_granted('commercial.suppliers.manage') or is_granted('commercial.suppliers.accounting.manage')",
|
||||||
|
// Patch des champs comptables exige accounting.manage (guardAccounting) ;
|
||||||
|
// champs main/information exigent manage (guardManage) ;
|
||||||
// patch isArchived exige is_granted('commercial.suppliers.archive').
|
// patch isArchived exige is_granted('commercial.suppliers.archive').
|
||||||
normalizationContext: ['groups' => ['supplier:read', 'default:read']],
|
normalizationContext: ['groups' => ['supplier:read', 'default:read']],
|
||||||
denormalizationContext: ['groups' => [
|
denormalizationContext: ['groups' => [
|
||||||
@@ -711,91 +721,108 @@ Même pattern que les jumelles `Client*` (`#[Auditable]`, `TimestampableBlamable
|
|||||||
| Scalaires Comptabilité (siren, refs…) | `supplier:read:accounting` | ✅ (gated) | refs (`tvaMode`…) id+label ∈ `supplier:read:accounting` |
|
| Scalaires Comptabilité (siren, refs…) | `supplier:read:accounting` | ✅ (gated) | refs (`tvaMode`…) id+label ∈ `supplier:read:accounting` |
|
||||||
| `ribs[]` (label/bic/iban) | `ribs` ∈ `supplier:read:accounting` | ✅ (gated) | — |
|
| `ribs[]` (label/bic/iban) | `ribs` ∈ `supplier:read:accounting` | ✅ (gated) | — |
|
||||||
|
|
||||||
### 4.0.bis Réponses JSON de référence (DoD — à confirmer sur l'API réelle)
|
### 4.0.bis Réponses JSON de référence (DoD — RÉELLES, capturées ERP-92)
|
||||||
|
|
||||||
> **Definition of Done de cette spec back (RETEX M1 §3)** : avant d'écrire les tickets front, créer un fournisseur de test et **coller ici les réponses RÉELLES** de `GET /api/suppliers` et `GET /api/suppliers/{id}`. Les containers n'étant pas lancés au moment de la rédaction, le JSON ci-dessous est le **contrat CIBLE** — à valider/remplacer par la réponse réelle (`make start` puis `curl`). Toute donnée affichée par le front DOIT apparaître dans ce JSON.
|
> **Definition of Done CLÔTURÉE (ERP-92, 2026-06-05)** : les réponses ci-dessous sont **réelles**, capturées sur l'API de test via PHPUnit (`SupplierSerializationContractTest`, fournisseur complet seedé). Les `id`/timestamps sont illustratifs (run de test). Toute donnée affichée par le front DOIT apparaître dans ce JSON. Front #93→#96 peuvent démarrer.
|
||||||
|
>
|
||||||
|
> **2 constats validés à la capture** (cf. § 4.0.ter) :
|
||||||
|
> 1. 🔧 **Fix ERP-92** : les réfs comptables (`tvaMode`/`paymentDelay`/`paymentType`/`bank`) sortaient en **IRI nu** (les entités partagées ne portaient que `client:read:accounting`, pas `supplier:read:accounting`). Corrigé → objet `{id, code, label}` embarqué (le front consultation/édition affiche le libellé sans fetch).
|
||||||
|
> 2. ℹ️ **Liste « riche »** : le groupe `supplier:read` étant partagé liste+détail, la **collection embarque tout le bloc Information** (et, pour un user `accounting.view`, les scalaires compta + `ribs[]`). Comportement identique au M1 (groupe `client:read` partagé) — la datatable n'affiche que Nom/Catégories/Site(s)/MAJ, mais le payload est complet. Le gating `accounting` reste effectif (Commerciale ne voit ni compta ni `ribs` en liste comme en détail).
|
||||||
|
|
||||||
> **Forme d'enveloppe confirmée sur le M1 réel** (API Platform 4.2) : JSON-LD **sans préfixe `hydra:`** → clés `member` / `totalItems` / `view`, avec `@type: "Collection"` et `view.@type: "PartialCollectionView"`. `Content-Type: application/ld+json; charset=utf-8`. Pagination défaut 10 confirmée. Login réel = `POST /api/login_check` (nginx réécrit vers `/login_check`), réponse `204` + cookie HttpOnly `BEARER`.
|
> **Forme d'enveloppe confirmée sur le M1 réel** (API Platform 4.2) : JSON-LD **sans préfixe `hydra:`** → clés `member` / `totalItems` / `view`, avec `@type: "Collection"` et `view.@type: "PartialCollectionView"`. `Content-Type: application/ld+json; charset=utf-8`. Pagination défaut 10 confirmée. Login réel = `POST /api/login_check` (nginx réécrit vers `/login_check`), réponse `204` + cookie HttpOnly `BEARER`.
|
||||||
|
|
||||||
`GET /api/suppliers` (liste, ADMIN) :
|
`GET /api/suppliers?search=…` (liste, ADMIN — un membre) :
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"@context": "/api/contexts/Supplier",
|
"@context": "/api/contexts/Supplier",
|
||||||
"@id": "/api/suppliers",
|
"@id": "/api/suppliers",
|
||||||
"@type": "Collection",
|
"@type": "Collection",
|
||||||
"totalItems": 13,
|
"totalItems": 1,
|
||||||
"member": [
|
"member": [
|
||||||
{
|
{
|
||||||
"@id": "/api/suppliers/1",
|
"@id": "/api/suppliers/85",
|
||||||
"@type": "Supplier",
|
"@type": "Supplier",
|
||||||
"id": 1,
|
"id": 85,
|
||||||
"companyName": "RECYCLA SAS",
|
"companyName": "DOD59393F 862875",
|
||||||
"categories": [
|
"categories": [
|
||||||
{"@id": "/api/categories/12", "id": 12, "code": "NEGOCIANT", "name": "Négociant"}
|
{"@type": "Category", "@id": "/api/categories/2279", "id": 2279, "name": "test_cli_cat_fr_negociant", "code": "NEGOCIANT",
|
||||||
|
"categoryType": {"@id": "/api/category_types/602", "@type": "CategoryType", "id": 602, "code": "FOURNISSEUR", "label": "Fournisseur"},
|
||||||
|
"createdAt": "…", "updatedAt": "…"}
|
||||||
],
|
],
|
||||||
|
"description": "Fournisseur de test complet.",
|
||||||
|
"competitors": "Concurrent A, Concurrent B",
|
||||||
|
"foundedAt": "2008-04-01T00:00:00+02:00",
|
||||||
|
"employeesCount": 42,
|
||||||
|
"revenueAmount": "1500000.00",
|
||||||
|
"directorName": "Jean Dupont",
|
||||||
|
"profitAmount": "120000.00",
|
||||||
|
"volumeForecast": 8000,
|
||||||
|
"siren": "123456789",
|
||||||
|
"accountNumber": "F0001",
|
||||||
|
"tvaMode": {"@id": "/api/tva_modes/30", "@type": "TvaMode", "id": 30, "code": "FRANCE_VENTES", "label": "France (ventes)"},
|
||||||
|
"nTva": "FR00123456789",
|
||||||
|
"paymentDelay": {"@id": "/api/payment_delays/11", "@type": "PaymentDelay", "id": 11, "code": "J30", "label": "30 jours"},
|
||||||
|
"paymentType": {"@id": "/api/payment_types/14", "@type": "PaymentType", "id": 14, "code": "LCR", "label": "LCR"},
|
||||||
|
"ribs": [
|
||||||
|
{"@id": "/api/supplier_ribs/27", "@type": "SupplierRib", "id": 27, "label": "Compte principal", "bic": "BNPAFRPPXXX", "iban": "FR1420041010050500013M02606", "createdAt": "…", "updatedAt": "…"}
|
||||||
|
],
|
||||||
|
"createdAt": "…", "updatedAt": "…",
|
||||||
"sites": [
|
"sites": [
|
||||||
{"@id": "/api/sites/1", "id": 1, "name": "Chatellerault", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2"},
|
{"@type": "Site", "@id": "/api/sites/87", "id": 87, "name": "Chatellerault", "street": "14 All. d'Argenson", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2", "fullAddress": "14 All. d'Argenson\n86100 Châtellerault"},
|
||||||
{"@id": "/api/sites/2", "id": 2, "name": "Saint-Jean", "postalCode": "17400", "city": "Fontenet", "color": "#…"}
|
{"@type": "Site", "@id": "/api/sites/88", "id": 88, "name": "Saint-Jean", "street": "Z i", "postalCode": "17400", "city": "Fontenet", "color": "#F3CB00", "fullAddress": "Z i\n17400 Fontenet"}
|
||||||
],
|
],
|
||||||
"updatedAt": "2026-02-17T09:30:00+00:00",
|
|
||||||
"isArchived": false
|
"isArchived": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"view": {
|
"view": {"@id": "/api/suppliers?search=…", "@type": "PartialCollectionView"}
|
||||||
"@id": "/api/suppliers?page=1",
|
|
||||||
"@type": "PartialCollectionView",
|
|
||||||
"first": "/api/suppliers?page=1",
|
|
||||||
"last": "/api/suppliers?page=2",
|
|
||||||
"next": "/api/suppliers?page=2"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> Les fournisseurs archivés sont **exclus** du `totalItems` (sur le M1, 14 clients en base → `totalItems: 13` car 1 archivé filtré par le Provider). `categories[]` (avec `code`/`name`) et `sites[]` (avec `name`/`postalCode` — **pas de `code`**) sont **embarqués** (cohérence M1/ERP-62, § 2.12) ; `sites` est l'agrégat dédoublonné des adresses via `Supplier::getSites()`. Fetch-joins repository obligatoires (anti N+1).
|
> Les fournisseurs archivés sont **exclus** du `totalItems` (RG-2.17 — filtré par le Provider). `categories[]` (avec `code`/`name`) et `sites[]` (avec `name`/`postalCode` — **pas de `code`**) sont **embarqués** (cohérence M1/ERP-62, § 2.12) ; `sites` est l'agrégat dédoublonné des adresses via `Supplier::getSites()`. Fetch-joins repository (anti N+1) **vérifiés par test** (`SupplierListTest::testListQueryCountDoesNotGrowWithRowCount` : nombre de requêtes constant entre 2 et 4 fournisseurs). ⚠️ Le membre embarque aussi l'**Information complète** et — pour un user `accounting.view` (ici admin) — les **scalaires compta + `ribs[]`** (groupe `supplier:read` partagé liste/détail). Pour la **Commerciale** (sans `accounting.view`), `siren`/`tvaMode`/`paymentType`/`ribs`… **disparaissent** de chaque membre.
|
||||||
|
|
||||||
`GET /api/suppliers/1` (détail — user avec `accounting.view`) :
|
`GET /api/suppliers/85` (détail — user avec `accounting.view`) :
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"@id": "/api/suppliers/1",
|
"@context": "/api/contexts/Supplier",
|
||||||
|
"@id": "/api/suppliers/85",
|
||||||
"@type": "Supplier",
|
"@type": "Supplier",
|
||||||
"id": 1,
|
"id": 85,
|
||||||
"companyName": "RECYCLA SAS",
|
"companyName": "DOD59393F 862875",
|
||||||
"categories": [
|
"categories": [
|
||||||
{"@id": "/api/categories/12", "id": 12, "code": "NEGOCIANT", "name": "Négociant"}
|
{"@type": "Category", "@id": "/api/categories/2279", "id": 2279, "name": "test_cli_cat_fr_negociant", "code": "NEGOCIANT",
|
||||||
|
"categoryType": {"@id": "/api/category_types/602", "@type": "CategoryType", "id": 602, "code": "FOURNISSEUR", "label": "Fournisseur"}}
|
||||||
],
|
],
|
||||||
"description": "…", "competitors": "…", "foundedAt": "2008-04-01",
|
"description": "Fournisseur de test complet.", "competitors": "Concurrent A, Concurrent B",
|
||||||
"employeesCount": 42, "revenueAmount": "1500000.00", "directorName": "…",
|
"foundedAt": "2008-04-01T00:00:00+02:00", "employeesCount": 42, "revenueAmount": "1500000.00",
|
||||||
"profitAmount": "120000.00", "volumeForecast": 8000,
|
"directorName": "Jean Dupont", "profitAmount": "120000.00", "volumeForecast": 8000,
|
||||||
|
"siren": "123456789", "accountNumber": "F0001",
|
||||||
|
"tvaMode": {"@id": "/api/tva_modes/30", "@type": "TvaMode", "id": 30, "code": "FRANCE_VENTES", "label": "France (ventes)"},
|
||||||
|
"nTva": "FR00123456789",
|
||||||
|
"paymentDelay": {"@id": "/api/payment_delays/11", "@type": "PaymentDelay", "id": 11, "code": "J30", "label": "30 jours"},
|
||||||
|
"paymentType": {"@id": "/api/payment_types/14", "@type": "PaymentType", "id": 14, "code": "LCR", "label": "LCR"},
|
||||||
"contacts": [
|
"contacts": [
|
||||||
{"@id": "/api/supplier_contacts/1", "id": 1, "firstName": "Marie", "lastName": "Martin",
|
{"@id": "/api/supplier_contacts/39", "@type": "SupplierContact", "id": 39, "firstName": "Marie", "lastName": "Martin",
|
||||||
"jobTitle": "Responsable achats", "phonePrimary": "0612345678", "phoneSecondary": null,
|
"jobTitle": "Responsable achats", "phonePrimary": "0612345678", "email": "marie.martin@seed.test"}
|
||||||
"email": "marie.martin@recycla.fr"}
|
|
||||||
],
|
],
|
||||||
"addresses": [
|
"addresses": [
|
||||||
{"@id": "/api/supplier_addresses/1", "id": 1, "addressType": "DEPART",
|
{"@id": "/api/supplier_addresses/33", "@type": "SupplierAddress", "id": 33, "addressType": "DEPART",
|
||||||
"country": "France", "postalCode": "86000", "city": "Poitiers",
|
"country": "France", "postalCode": "86000", "city": "Poitiers", "street": "12 rue des Acacias",
|
||||||
"street": "12 rue des Acacias", "streetComplement": null,
|
|
||||||
"bennes": 3, "triageProvider": true,
|
"bennes": 3, "triageProvider": true,
|
||||||
"sites": [{"@id": "/api/sites/1", "id": 1, "name": "Chatellerault", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2"}],
|
"sites": [
|
||||||
"categories": [{"@id": "/api/categories/12", "id": 12, "code": "NEGOCIANT", "name": "Négociant"}],
|
{"@type": "Site", "@id": "/api/sites/87", "id": 87, "name": "Chatellerault", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2"},
|
||||||
"contacts": [{"@id": "/api/supplier_contacts/1", "id": 1, "firstName": "Marie", "lastName": "Martin"}]}
|
{"@type": "Site", "@id": "/api/sites/88", "id": 88, "name": "Saint-Jean", "postalCode": "17400", "city": "Fontenet", "color": "#F3CB00"}
|
||||||
|
],
|
||||||
|
"contacts": [{"@id": "/api/supplier_contacts/39", "@type": "SupplierContact", "id": 39, "firstName": "Marie", "lastName": "Martin"}],
|
||||||
|
"categories": [{"@type": "Category", "@id": "/api/categories/2279", "id": 2279, "name": "test_cli_cat_fr_negociant", "code": "NEGOCIANT"}]}
|
||||||
],
|
],
|
||||||
"siren": "123456789", "accountNumber": "F0001",
|
|
||||||
"tvaMode": {"@id": "/api/tva_modes/1", "id": 1, "label": "France (ventes)"},
|
|
||||||
"nTva": "FR00123456789",
|
|
||||||
"paymentDelay": {"@id": "/api/payment_delays/2", "id": 2, "label": "30 jours"},
|
|
||||||
"paymentType": {"@id": "/api/payment_types/2", "id": 2, "code": "LCR", "label": "LCR"},
|
|
||||||
"bank": null,
|
|
||||||
"ribs": [
|
"ribs": [
|
||||||
{"@id": "/api/supplier_ribs/1", "id": 1, "label": "Compte principal",
|
{"@id": "/api/supplier_ribs/27", "@type": "SupplierRib", "id": 27, "label": "Compte principal", "bic": "BNPAFRPPXXX", "iban": "FR1420041010050500013M02606"}
|
||||||
"bic": "SOGEFRPP", "iban": "FR7630003035400005000000123"}
|
|
||||||
],
|
],
|
||||||
"isArchived": false, "archivedAt": null,
|
"isArchived": false
|
||||||
"updatedAt": "2026-02-17T09:30:00+00:00"
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> Pour un user **sans** `accounting.view` (ex. Commerciale) : les clés `siren`, `accountNumber`, `tvaMode`, `nTva`, `paymentDelay`, `paymentType`, `bank`, `ribs` **sont absentes** (pas `null` — réellement non sérialisées car le Provider retire le groupe). Le gating par **omission de clé** est confirmé confortable côté front. Le blame `updatedBy` est sérialisé en **IRI** (`"/api/me"` quand c'est l'user courant) — en tenir compte côté front.
|
> Pour un user **sans** `accounting.view` (ex. Commerciale) : les clés `siren`, `accountNumber`, `tvaMode`, `nTva`, `paymentDelay`, `paymentType`, `bank`, `ribs` **sont absentes** (pas `null` — réellement non sérialisées : le `SupplierReadGroupContextBuilder` n'ajoute pas le groupe). Gating par **omission de clé** confirmé sur le JSON réel (`SupplierSerializationContractTest::testRibsAbsentForCommercialeWithoutAccountingView` + `testAccountingScalarsGatedByOmission`). `bennes`/`triageProvider`/`addressType`/`addresses[].contacts` restent visibles (onglet Adresse non gaté). NB : ici `bank` est absent (paymentType=LCR sans banque) ; avec un VIREMENT, `bank` est embarqué `{id, code, label}` (fix ERP-92).
|
||||||
|
|
||||||
### 4.0.ter Pièges de sérialisation CONSTATÉS sur le M1 réel → parade M2 (OBLIGATOIRE)
|
### 4.0.ter Pièges de sérialisation CONSTATÉS sur le M1 réel → parade M2 (OBLIGATOIRE)
|
||||||
|
|
||||||
@@ -1046,7 +1073,7 @@ Le M1 a subi un aller-retour (ERP-68) faute de fixtures alignées. Pour le M2, p
|
|||||||
|
|
||||||
- [x] 3 maillons de sérialisation documentés pour chaque champ liste + détail (§ 4.0)
|
- [x] 3 maillons de sérialisation documentés pour chaque champ liste + détail (§ 4.0)
|
||||||
- [x] Décision embed vs GetCollection explicite et câblée (embed détail + sous-ressources write — § 3.3 / § 3.4 / § 4.5), **pas de POST-only**
|
- [x] Décision embed vs GetCollection explicite et câblée (embed détail + sous-ressources write — § 3.3 / § 3.4 / § 4.5), **pas de POST-only**
|
||||||
- [ ] **Réponses JSON RÉELLES** collées (§ 4.0.bis) — *en attente de `make start` + curl (DoD avant tickets front)*
|
- [x] **Réponses JSON RÉELLES** collées (§ 4.0.bis) — capturées via PHPUnit (ERP-92, 2026-06-05) ; fix réfs compta IRI→{id,label} inclus
|
||||||
- [x] Matrice RBAC rôle × onglet + mode strict PATCH (§ 2.9 / RG-2.16)
|
- [x] Matrice RBAC rôle × onglet + mode strict PATCH (§ 2.9 / RG-2.16)
|
||||||
- [x] Pagination (n°13), COMMENT ON COLUMN (n°12), Timestampable/Blamable, Audit, routes à plat : rappelés
|
- [x] Pagination (n°13), COMMENT ON COLUMN (n°12), Timestampable/Blamable, Audit, routes à plat : rappelés
|
||||||
- [x] Réutilisations M1 identifiées (référentiels compta partagés, taxonomie code/type, `usePaginatedList`, blocs, archive, normalisation)
|
- [x] Réutilisations M1 identifiées (référentiels compta partagés, taxonomie code/type, `usePaginatedList`, blocs, archive, normalisation)
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
Valeurs en dur issues de la maquette Figma (design Starseed) :
|
Valeurs en dur issues de la maquette Figma (design Starseed) :
|
||||||
- sidebar depliee : 232px (w-[232px], repli laisse par defaut 72px)
|
- sidebar depliee : 232px (w-[232px], repli laisse par defaut 72px)
|
||||||
- marge horizontale du contenu sur desktop : 170px (xl:px-[170px])
|
- marge horizontale du contenu sur desktop : 170px (xl:px-[170px])
|
||||||
- bande blanche sticky sous la navbar : 47px (h-[47px])
|
La marge haute du contenu (44px) vit desormais DANS l'entete (PageHeader,
|
||||||
|
pt-11) et non sur le <main> : sinon, l'entete etant sticky, ce padding
|
||||||
|
laissait un trou blanc entre le SiteSelector et l'entete.
|
||||||
A faire evoluer uniquement avec une mise a jour de maquette.
|
A faire evoluer uniquement avec une mise a jour de maquette.
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
@@ -25,9 +27,6 @@
|
|||||||
<SiteSelector v-if="showSiteSelector"/>
|
<SiteSelector v-if="showSiteSelector"/>
|
||||||
<main
|
<main
|
||||||
class="flex flex-1 flex-col overflow-y-auto overflow-x-hidden bg-white px-4 pb-10 sm:px-6 lg:px-12 xl:px-11">
|
class="flex flex-1 flex-col overflow-y-auto overflow-x-hidden bg-white px-4 pb-10 sm:px-6 lg:px-12 xl:px-11">
|
||||||
<div
|
|
||||||
aria-hidden="true"
|
|
||||||
class="pointer-events-none sticky top-0 z-30 h-11 flex-shrink-0 bg-white"/>
|
|
||||||
<slot/>
|
<slot/>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -88,6 +88,7 @@
|
|||||||
"toast": {
|
"toast": {
|
||||||
"createSuccess": "Client créé avec succès",
|
"createSuccess": "Client créé avec succès",
|
||||||
"updateSuccess": "Client mis à jour avec succès",
|
"updateSuccess": "Client mis à jour avec succès",
|
||||||
|
"addComplete": "Client ajouté",
|
||||||
"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.",
|
||||||
@@ -173,15 +174,20 @@
|
|||||||
"addressTypeDelivery": "Livraison",
|
"addressTypeDelivery": "Livraison",
|
||||||
"addressTypeBilling": "Facturation",
|
"addressTypeBilling": "Facturation",
|
||||||
"addressTypeDeliveryBilling": "Adresse + Facturation",
|
"addressTypeDeliveryBilling": "Adresse + Facturation",
|
||||||
|
"addressTypeBroker": "Adresse Courtier",
|
||||||
|
"addressTypeDistributor": "Adresse Distributeur",
|
||||||
"categories": "Catégorie",
|
"categories": "Catégorie",
|
||||||
"country": "Pays",
|
"country": "Pays",
|
||||||
"postalCode": "Code postal",
|
"postalCode": "Code postal",
|
||||||
"city": "Ville",
|
"city": "Ville",
|
||||||
"street": "Adresse",
|
"street": "Adresse",
|
||||||
|
"streetNotFound": "Adresse introuvable ? Saisissez-la directement.",
|
||||||
"streetComplement": "Adresse complémentaire",
|
"streetComplement": "Adresse complémentaire",
|
||||||
"sites": "Sites",
|
"sites": "Sites",
|
||||||
"contacts": "Contact(s) rattaché(s)",
|
"contacts": "Contact(s) rattaché(s)",
|
||||||
"billingEmail": "Email de facturation",
|
"billingEmail": "Email de facturation",
|
||||||
|
"billingEmailSecondary": "Email de facturation secondaire",
|
||||||
|
"addBillingEmail": "Ajouter un email",
|
||||||
"remove": "Supprimer l'adresse",
|
"remove": "Supprimer l'adresse",
|
||||||
"add": "Nouvelle adresse",
|
"add": "Nouvelle adresse",
|
||||||
"degraded": "Service d'adresse indisponible : saisie de la ville et de l'adresse en mode libre."
|
"degraded": "Service d'adresse indisponible : saisie de la ville et de l'adresse en mode libre."
|
||||||
@@ -416,21 +422,26 @@
|
|||||||
"newCategory": "Ajouter",
|
"newCategory": "Ajouter",
|
||||||
"editCategory": "Modifier la catégorie",
|
"editCategory": "Modifier la catégorie",
|
||||||
"createCategory": "Créer une catégorie",
|
"createCategory": "Créer une catégorie",
|
||||||
"viewCategory": "Détail de la catégorie",
|
|
||||||
"noCategories": "Aucune catégorie pour l'instant.",
|
"noCategories": "Aucune catégorie pour l'instant.",
|
||||||
"table": {
|
"table": {
|
||||||
"name": "Nom",
|
"name": "Nom",
|
||||||
"type": "Type"
|
"types": "Types"
|
||||||
|
},
|
||||||
|
"filters": {
|
||||||
|
"title": "Filtres",
|
||||||
|
"search": "Recherche",
|
||||||
|
"types": "Types de catégorie",
|
||||||
|
"apply": "Voir les résultats",
|
||||||
|
"reset": "Réinitialiser"
|
||||||
},
|
},
|
||||||
"form": {
|
"form": {
|
||||||
"name": "Nom",
|
"name": "Nom",
|
||||||
"type": "Type de catégorie",
|
"types": "Types de catégorie"
|
||||||
"typePlaceholder": "Sélectionner un type"
|
|
||||||
},
|
},
|
||||||
"validation": {
|
"validation": {
|
||||||
"nameRequired": "Le nom est obligatoire.",
|
"nameRequired": "Le nom est obligatoire.",
|
||||||
"nameLength": "Le nom doit faire entre 2 et 120 caractères.",
|
"nameLength": "Le nom doit faire entre 2 et 120 caractères.",
|
||||||
"typeRequired": "Le type de catégorie est obligatoire."
|
"typesRequired": "Sélectionnez au moins un type de catégorie."
|
||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"title": "Supprimer la catégorie",
|
"title": "Supprimer la catégorie",
|
||||||
@@ -440,7 +451,7 @@
|
|||||||
"created": "Catégorie créée avec succès",
|
"created": "Catégorie créée avec succès",
|
||||||
"updated": "Catégorie mise à jour avec succès",
|
"updated": "Catégorie mise à jour avec succès",
|
||||||
"deleted": "Catégorie supprimée avec succès",
|
"deleted": "Catégorie supprimée avec succès",
|
||||||
"duplicate": "Une catégorie nommée « {name} » existe déjà pour ce type.",
|
"duplicate": "Une catégorie nommée « {name} » existe déjà.",
|
||||||
"typesLoadFailed": "Impossible de charger les types de catégorie. Réessayez."
|
"typesLoadFailed": "Impossible de charger les types de catégorie. Réessayez."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,16 +24,17 @@
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Type (RG-1.05 obligatoire). MalioSelect porte la valeur en
|
<!-- Types (RG-1.05 : au moins un obligatoire). MalioSelectCheckbox
|
||||||
number (categoryType id) ; conversion en IRI au moment du save
|
porte un tableau d'ids (categoryType id) ; conversion en tableau
|
||||||
par le composable useCategoryForm. -->
|
d'IRI au moment du save par le composable useCategoryForm. -->
|
||||||
<MalioSelect
|
<MalioSelectCheckbox
|
||||||
v-model="form.categoryTypeId.value"
|
v-model="form.categoryTypeIds.value"
|
||||||
:options="typeOptions"
|
:options="typeOptions"
|
||||||
:label="t('admin.categories.form.type')"
|
:label="t('admin.categories.form.types')"
|
||||||
:empty-option-label="t('admin.categories.form.typePlaceholder')"
|
:error="form.errors.categoryTypes"
|
||||||
:error="form.errors.categoryType"
|
:display-tag="true"
|
||||||
:disabled="loadingTypes"
|
:disabled="loadingTypes"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@@ -89,28 +90,17 @@ const emit = defineEmits<{
|
|||||||
delete: []
|
delete: []
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
/**
|
// Mode du drawer : creation (pas de category prop, POST au save) ou
|
||||||
* Mode du drawer (dérivé du composable `useCategoryForm`) :
|
// modification d'une categorie existante (PATCH au save). Pas de distinction
|
||||||
* - 'create' : pas de category prop, formulaire vide, POST au save.
|
// view/edit : comme les autres drawers, le titre et le bouton Enregistrer sont
|
||||||
* - 'view' : category prop set, formulaire pre-rempli, save MASQUE
|
// stables quel que soit l'etat « dirty » du formulaire.
|
||||||
* jusqu'a ce que l'utilisateur modifie un champ.
|
|
||||||
* - 'edit' : category prop set et formulaire « dirty » (au moins un
|
|
||||||
* champ different de l'original), PATCH au save.
|
|
||||||
*/
|
|
||||||
type DrawerMode = 'create' | 'view' | 'edit'
|
|
||||||
|
|
||||||
const isCreateMode = computed(() => props.category === null)
|
const isCreateMode = computed(() => props.category === null)
|
||||||
|
|
||||||
const mode = computed<DrawerMode>(() => {
|
const headerLabel = computed(() =>
|
||||||
if (isCreateMode.value) return 'create'
|
isCreateMode.value
|
||||||
return form.isDirty.value ? 'edit' : 'view'
|
? t('admin.categories.createCategory')
|
||||||
})
|
: t('admin.categories.editCategory'),
|
||||||
|
)
|
||||||
const headerLabel = computed(() => {
|
|
||||||
if (mode.value === 'create') return t('admin.categories.createCategory')
|
|
||||||
if (mode.value === 'edit') return t('admin.categories.editCategory')
|
|
||||||
return t('admin.categories.viewCategory')
|
|
||||||
})
|
|
||||||
|
|
||||||
// Le bouton Supprimer n'est visible qu'en consultation/edition d'une categorie
|
// Le bouton Supprimer n'est visible qu'en consultation/edition d'une categorie
|
||||||
// existante et seulement pour les users ayant la permission manage. En mode
|
// existante et seulement pour les users ayant la permission manage. En mode
|
||||||
@@ -119,10 +109,12 @@ const canShowDelete = computed(
|
|||||||
() => !isCreateMode.value && can('catalog.categories.manage'),
|
() => !isCreateMode.value && can('catalog.categories.manage'),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Save : visible en creation, ou en edition (apres modification d'un champ).
|
// Save : visible en creation, et en consultation/edition d'une categorie
|
||||||
// Masque en view tant que rien n'a change.
|
// existante (l'utilisateur doit pouvoir enregistrer sans qu'un champ ait
|
||||||
|
// d'abord ete modifie). Le bouton reste neanmoins protege par son `disabled`
|
||||||
|
// pendant la soumission / le chargement des types.
|
||||||
const canShowSave = computed(
|
const canShowSave = computed(
|
||||||
() => mode.value === 'create' || mode.value === 'edit',
|
() => isCreateMode.value || can('catalog.categories.manage'),
|
||||||
)
|
)
|
||||||
|
|
||||||
const typeOptions = computed(() =>
|
const typeOptions = computed(() =>
|
||||||
@@ -152,18 +144,18 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sauvegarde : delegue au composable (POST en mode create, PATCH en mode
|
* Sauvegarde : delegue au composable (POST en creation, PATCH en modification).
|
||||||
* edit). Le toast succes + mapping erreur 409/422 est gere par le composable.
|
* Le toast succes + mapping erreur 409/422 est gere par le composable. Le PATCH
|
||||||
* En cas de succes, on ferme le drawer et on previent le parent pour qu'il
|
* envoie le payload complet, donc le bouton Enregistrer sauvegarde a tout
|
||||||
* refresh la liste.
|
* moment (meme sans modification). En cas de succes, on ferme le drawer et on
|
||||||
|
* previent le parent pour qu'il refresh la liste.
|
||||||
*/
|
*/
|
||||||
async function handleSave(): Promise<void> {
|
async function handleSave(): Promise<void> {
|
||||||
let result: Category | null = null
|
const result = isCreateMode.value
|
||||||
if (mode.value === 'create') {
|
? await form.submitCreate()
|
||||||
result = await form.submitCreate()
|
: props.category
|
||||||
} else if (mode.value === 'edit' && props.category) {
|
? await form.submitUpdate(props.category.id)
|
||||||
result = await form.submitUpdate(props.category.id)
|
: null
|
||||||
}
|
|
||||||
if (result) {
|
if (result) {
|
||||||
emit('saved')
|
emit('saved')
|
||||||
emit('update:modelValue', false)
|
emit('update:modelValue', false)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const TYPE_ACHAT: CategoryType = { id: 2, code: 'ACHAT', label: 'Achat' }
|
|||||||
const CAT: Category = {
|
const CAT: Category = {
|
||||||
id: 42,
|
id: 42,
|
||||||
name: 'Vis',
|
name: 'Vis',
|
||||||
categoryType: TYPE_VENTE,
|
categoryTypes: [TYPE_VENTE],
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
createdAt: '2026-01-01T10:00:00+00:00',
|
createdAt: '2026-01-01T10:00:00+00:00',
|
||||||
updatedAt: '2026-01-01T10:00:00+00:00',
|
updatedAt: '2026-01-01T10:00:00+00:00',
|
||||||
@@ -58,25 +58,25 @@ describe('useCategoryForm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('loadFrom', () => {
|
describe('loadFrom', () => {
|
||||||
it('pre-remplit le formulaire depuis une categorie existante', () => {
|
it('pre-remplit le formulaire depuis une categorie existante (multi-types)', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
|
|
||||||
form.loadFrom(CAT)
|
form.loadFrom({ ...CAT, categoryTypes: [TYPE_VENTE, TYPE_ACHAT] })
|
||||||
|
|
||||||
expect(form.name.value).toBe('Vis')
|
expect(form.name.value).toBe('Vis')
|
||||||
expect(form.categoryTypeId.value).toBe(1)
|
expect(form.categoryTypeIds.value).toEqual([1, 2])
|
||||||
expect(form.errors).toEqual({})
|
expect(form.errors).toEqual({})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('vide le formulaire en mode creation (null)', () => {
|
it('vide le formulaire en mode creation (null)', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'old'
|
form.name.value = 'old'
|
||||||
form.categoryTypeId.value = 99
|
form.categoryTypeIds.value = [99]
|
||||||
|
|
||||||
form.loadFrom(null)
|
form.loadFrom(null)
|
||||||
|
|
||||||
expect(form.name.value).toBe('')
|
expect(form.name.value).toBe('')
|
||||||
expect(form.categoryTypeId.value).toBeNull()
|
expect(form.categoryTypeIds.value).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reinitialise le snapshot initial → isDirty=false juste apres', () => {
|
it('reinitialise le snapshot initial → isDirty=false juste apres', () => {
|
||||||
@@ -98,13 +98,32 @@ describe('useCategoryForm', () => {
|
|||||||
|
|
||||||
expect(form.isDirty.value).toBe(true)
|
expect(form.isDirty.value).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('passe a true quand on ajoute un type (selection multi)', () => {
|
||||||
|
const form = useCategoryForm()
|
||||||
|
form.loadFrom(CAT)
|
||||||
|
expect(form.isDirty.value).toBe(false)
|
||||||
|
|
||||||
|
form.categoryTypeIds.value = [1, 2]
|
||||||
|
|
||||||
|
expect(form.isDirty.value).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('reste false si la selection est identique dans un autre ordre', () => {
|
||||||
|
const form = useCategoryForm()
|
||||||
|
form.loadFrom({ ...CAT, categoryTypes: [TYPE_VENTE, TYPE_ACHAT] })
|
||||||
|
|
||||||
|
form.categoryTypeIds.value = [2, 1]
|
||||||
|
|
||||||
|
expect(form.isDirty.value).toBe(false)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('validate', () => {
|
describe('validate', () => {
|
||||||
it('signale une erreur si name est vide (RG-1.02)', () => {
|
it('signale une erreur si name est vide (RG-1.02)', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = ''
|
form.name.value = ''
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
@@ -115,7 +134,7 @@ describe('useCategoryForm', () => {
|
|||||||
it('signale erreur si name est whitespace-only (trim → vide)', () => {
|
it('signale erreur si name est whitespace-only (trim → vide)', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = ' '
|
form.name.value = ' '
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
@@ -126,7 +145,7 @@ describe('useCategoryForm', () => {
|
|||||||
it('signale erreur si name fait 1 caractere (< 2, RG-1.04)', () => {
|
it('signale erreur si name fait 1 caractere (< 2, RG-1.04)', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'A'
|
form.name.value = 'A'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
@@ -137,7 +156,7 @@ describe('useCategoryForm', () => {
|
|||||||
it('signale erreur si name fait 121 caracteres (> 120, RG-1.04)', () => {
|
it('signale erreur si name fait 121 caracteres (> 120, RG-1.04)', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'A'.repeat(121)
|
form.name.value = 'A'.repeat(121)
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
@@ -145,21 +164,21 @@ describe('useCategoryForm', () => {
|
|||||||
expect(form.errors.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 aucun type selectionne (RG-1.05)', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = null
|
form.categoryTypeIds.value = []
|
||||||
|
|
||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
expect(ok).toBe(false)
|
expect(ok).toBe(false)
|
||||||
expect(form.errors.categoryType).toBe('admin.categories.validation.typeRequired')
|
expect(form.errors.categoryTypes).toBe('admin.categories.validation.typesRequired')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('passe quand name et categoryType sont valides', () => {
|
it('passe quand name et au moins un type sont valides', () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1, 2]
|
||||||
|
|
||||||
const ok = form.validate()
|
const ok = form.validate()
|
||||||
|
|
||||||
@@ -171,7 +190,7 @@ describe('useCategoryForm', () => {
|
|||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
// Erreur prealable : une validation en echec peuple errors.name.
|
// Erreur prealable : une validation en echec peuple errors.name.
|
||||||
form.name.value = ''
|
form.name.value = ''
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
form.validate()
|
form.validate()
|
||||||
expect(form.errors.name).toBeTruthy()
|
expect(form.errors.name).toBeTruthy()
|
||||||
|
|
||||||
@@ -184,17 +203,17 @@ describe('useCategoryForm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('submitCreate', () => {
|
describe('submitCreate', () => {
|
||||||
it('appelle POST /categories avec body { name trimme, categoryType en IRI }', async () => {
|
it('appelle POST /categories avec body { name trimme, categoryTypes en IRI[] }', async () => {
|
||||||
mockPost.mockResolvedValueOnce(CAT)
|
mockPost.mockResolvedValueOnce(CAT)
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = ' Vis '
|
form.name.value = ' Vis '
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1, 2]
|
||||||
|
|
||||||
const result = await form.submitCreate()
|
const result = await form.submitCreate()
|
||||||
|
|
||||||
expect(mockPost).toHaveBeenCalledWith(
|
expect(mockPost).toHaveBeenCalledWith(
|
||||||
'/categories',
|
'/categories',
|
||||||
{ name: 'Vis', categoryType: '/api/category_types/1' },
|
{ name: 'Vis', categoryTypes: ['/api/category_types/1', '/api/category_types/2'] },
|
||||||
{ toast: false },
|
{ toast: false },
|
||||||
)
|
)
|
||||||
expect(result).toEqual(CAT)
|
expect(result).toEqual(CAT)
|
||||||
@@ -203,7 +222,7 @@ describe('useCategoryForm', () => {
|
|||||||
it('ne declenche aucun appel API si la validation client echoue', async () => {
|
it('ne declenche aucun appel API si la validation client echoue', async () => {
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = ''
|
form.name.value = ''
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const result = await form.submitCreate()
|
const result = await form.submitCreate()
|
||||||
|
|
||||||
@@ -215,7 +234,7 @@ describe('useCategoryForm', () => {
|
|||||||
mockPost.mockResolvedValueOnce(CAT)
|
mockPost.mockResolvedValueOnce(CAT)
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
await form.submitCreate()
|
await form.submitCreate()
|
||||||
|
|
||||||
@@ -231,7 +250,7 @@ describe('useCategoryForm', () => {
|
|||||||
})
|
})
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const result = await form.submitCreate()
|
const result = await form.submitCreate()
|
||||||
|
|
||||||
@@ -258,7 +277,7 @@ describe('useCategoryForm', () => {
|
|||||||
})
|
})
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const result = await form.submitCreate()
|
const result = await form.submitCreate()
|
||||||
|
|
||||||
@@ -269,24 +288,24 @@ describe('useCategoryForm', () => {
|
|||||||
expect(mockToastError).not.toHaveBeenCalled()
|
expect(mockToastError).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('mappe aussi hydra:violations (negociation de format alternative)', async () => {
|
it('mappe une violation sur categoryTypes (hydra:violations alternative)', async () => {
|
||||||
mockPost.mockRejectedValueOnce({
|
mockPost.mockRejectedValueOnce({
|
||||||
response: {
|
response: {
|
||||||
status: 422,
|
status: 422,
|
||||||
_data: {
|
_data: {
|
||||||
'hydra:violations': [
|
'hydra:violations': [
|
||||||
{ propertyPath: 'categoryType', message: 'Type invalide.' },
|
{ propertyPath: 'categoryTypes', message: 'Sélectionnez au moins un type de catégorie.' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
await form.submitCreate()
|
await form.submitCreate()
|
||||||
|
|
||||||
expect(form.errors.categoryType).toBe('Type invalide.')
|
expect(form.errors.categoryTypes).toBe('Sélectionnez au moins un type de catégorie.')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fallback en toast generique 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 () => {
|
||||||
@@ -295,7 +314,7 @@ describe('useCategoryForm', () => {
|
|||||||
})
|
})
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
await form.submitCreate()
|
await form.submitCreate()
|
||||||
|
|
||||||
@@ -314,7 +333,7 @@ describe('useCategoryForm', () => {
|
|||||||
)
|
)
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.name.value = 'Vis'
|
form.name.value = 'Vis'
|
||||||
form.categoryTypeId.value = 1
|
form.categoryTypeIds.value = [1]
|
||||||
|
|
||||||
const pending = form.submitCreate()
|
const pending = form.submitCreate()
|
||||||
expect(form.submitting.value).toBe(true)
|
expect(form.submitting.value).toBe(true)
|
||||||
@@ -327,45 +346,52 @@ describe('useCategoryForm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('submitUpdate', () => {
|
describe('submitUpdate', () => {
|
||||||
it('appelle PATCH /categories/{id} uniquement avec les champs modifies', async () => {
|
it('appelle PATCH /categories/{id} avec le payload complet (name + categoryTypes)', async () => {
|
||||||
mockPatch.mockResolvedValueOnce({ ...CAT, name: 'Vis V2' })
|
mockPatch.mockResolvedValueOnce({ ...CAT, name: 'Vis V2' })
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.loadFrom(CAT)
|
form.loadFrom(CAT)
|
||||||
form.name.value = 'Vis V2' // categoryTypeId inchange
|
form.name.value = 'Vis V2' // types inchanges
|
||||||
|
|
||||||
|
await form.submitUpdate(42)
|
||||||
|
|
||||||
|
// Payload complet : meme si seul le name change, on renvoie aussi
|
||||||
|
// les categoryTypes (PATCH full payload, cf. drawers simples).
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
|
'/categories/42',
|
||||||
|
{ name: 'Vis V2', categoryTypes: ['/api/category_types/1'] },
|
||||||
|
{ toast: false },
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('envoie categoryTypes en IRI[] quand on ajoute un type', async () => {
|
||||||
|
mockPatch.mockResolvedValueOnce({ ...CAT, categoryTypes: [TYPE_VENTE, TYPE_ACHAT] })
|
||||||
|
const form = useCategoryForm()
|
||||||
|
form.loadFrom(CAT)
|
||||||
|
form.categoryTypeIds.value = [1, 2]
|
||||||
|
|
||||||
await form.submitUpdate(42)
|
await form.submitUpdate(42)
|
||||||
|
|
||||||
expect(mockPatch).toHaveBeenCalledWith(
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
'/categories/42',
|
'/categories/42',
|
||||||
{ name: 'Vis V2' }, // pas de categoryType car non modifie
|
{ name: CAT.name, categoryTypes: ['/api/category_types/1', '/api/category_types/2'] },
|
||||||
{ toast: false },
|
{ toast: false },
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('envoie categoryType en IRI quand seul le type a change', async () => {
|
it('envoie un PATCH complet meme sans modification (save a tout moment)', async () => {
|
||||||
mockPatch.mockResolvedValueOnce({ ...CAT, categoryType: TYPE_ACHAT })
|
mockPatch.mockResolvedValueOnce(CAT)
|
||||||
const form = useCategoryForm()
|
const form = useCategoryForm()
|
||||||
form.loadFrom(CAT)
|
form.loadFrom(CAT)
|
||||||
form.categoryTypeId.value = 2
|
// Aucune modification : le PATCH part quand meme avec le payload complet.
|
||||||
|
|
||||||
await form.submitUpdate(42)
|
|
||||||
|
|
||||||
expect(mockPatch).toHaveBeenCalledWith(
|
|
||||||
'/categories/42',
|
|
||||||
{ categoryType: '/api/category_types/2' },
|
|
||||||
{ toast: false },
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('court-circuite l appel API si aucun champ n a change', async () => {
|
|
||||||
const form = useCategoryForm()
|
|
||||||
form.loadFrom(CAT)
|
|
||||||
// Aucune modification — isDirty=false, patch payload vide.
|
|
||||||
|
|
||||||
const result = await form.submitUpdate(42)
|
const result = await form.submitUpdate(42)
|
||||||
|
|
||||||
expect(mockPatch).not.toHaveBeenCalled()
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
expect(result).toBeNull()
|
'/categories/42',
|
||||||
|
{ name: CAT.name, categoryTypes: ['/api/category_types/1'] },
|
||||||
|
{ toast: false },
|
||||||
|
)
|
||||||
|
expect(result).toEqual(CAT)
|
||||||
expect(form.submitting.value).toBe(false)
|
expect(form.submitting.value).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -438,7 +464,7 @@ describe('useCategoryForm', () => {
|
|||||||
form.reset()
|
form.reset()
|
||||||
|
|
||||||
expect(form.name.value).toBe('')
|
expect(form.name.value).toBe('')
|
||||||
expect(form.categoryTypeId.value).toBeNull()
|
expect(form.categoryTypeIds.value).toEqual([])
|
||||||
expect(form.errors).toEqual({})
|
expect(form.errors).toEqual({})
|
||||||
expect(form.submitting.value).toBe(false)
|
expect(form.submitting.value).toBe(false)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,9 +13,10 @@
|
|||||||
* revalide toujours (defense en profondeur).
|
* revalide toujours (defense en profondeur).
|
||||||
*
|
*
|
||||||
* Erreurs par champ : delegue a `useFormErrors` (convention ERP-101). Les
|
* Erreurs par champ : delegue a `useFormErrors` (convention ERP-101). Les
|
||||||
* violations 422 sont mappees par `propertyPath` (`name`, `categoryType`) ;
|
* violations 422 sont mappees par `propertyPath` (`name`, `categoryTypes`) ;
|
||||||
* l'erreur globale (status != 422 exploitable) part en toast. Le 409 (doublon
|
* l'erreur globale (status != 422 exploitable) part en toast. Le 409 (doublon
|
||||||
* RG-1.07) reste un cas metier specifique : erreur inline sur `name` + toast.
|
* de nom GLOBAL, 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'
|
||||||
@@ -42,20 +43,29 @@ export function useCategoryForm() {
|
|||||||
// 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('')
|
||||||
const categoryTypeId = ref<number | null>(null)
|
const categoryTypeIds = ref<number[]>([])
|
||||||
|
|
||||||
// Snapshot des valeurs initiales : sert a calculer `isDirty` pour le
|
// Snapshot des valeurs initiales : sert a calculer `isDirty` pour le
|
||||||
// pattern view → edit du drawer (le bouton Enregistrer reste masque tant
|
// pattern view → edit du drawer (le bouton Enregistrer reste masque tant
|
||||||
// que rien n'a change en mode consultation).
|
// que rien n'a change en mode consultation).
|
||||||
const initialName = ref('')
|
const initialName = ref('')
|
||||||
const initialCategoryTypeId = ref<number | null>(null)
|
const initialCategoryTypeIds = ref<number[]>([])
|
||||||
|
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
|
|
||||||
|
// Compare deux listes d'ids sans tenir compte de l'ordre (la selection
|
||||||
|
// multi-types n'est pas ordonnee).
|
||||||
|
function sameIds(a: number[], b: number[]): boolean {
|
||||||
|
if (a.length !== b.length) return false
|
||||||
|
const sortedA = [...a].sort((x, y) => x - y)
|
||||||
|
const sortedB = [...b].sort((x, y) => x - y)
|
||||||
|
return sortedA.every((v, i) => v === sortedB[i])
|
||||||
|
}
|
||||||
|
|
||||||
const isDirty = computed(
|
const isDirty = computed(
|
||||||
() =>
|
() =>
|
||||||
name.value !== initialName.value
|
name.value !== initialName.value
|
||||||
|| categoryTypeId.value !== initialCategoryTypeId.value,
|
|| !sameIds(categoryTypeIds.value, initialCategoryTypeIds.value),
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,15 +76,16 @@ export function useCategoryForm() {
|
|||||||
function loadFrom(category: Category | null): void {
|
function loadFrom(category: Category | null): void {
|
||||||
formErrors.clearErrors()
|
formErrors.clearErrors()
|
||||||
if (category) {
|
if (category) {
|
||||||
|
const ids = category.categoryTypes.map(t => t.id)
|
||||||
name.value = category.name
|
name.value = category.name
|
||||||
categoryTypeId.value = category.categoryType.id
|
categoryTypeIds.value = [...ids]
|
||||||
initialName.value = category.name
|
initialName.value = category.name
|
||||||
initialCategoryTypeId.value = category.categoryType.id
|
initialCategoryTypeIds.value = [...ids]
|
||||||
} else {
|
} else {
|
||||||
name.value = ''
|
name.value = ''
|
||||||
categoryTypeId.value = null
|
categoryTypeIds.value = []
|
||||||
initialName.value = ''
|
initialName.value = ''
|
||||||
initialCategoryTypeId.value = null
|
initialCategoryTypeIds.value = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,23 +106,23 @@ export function useCategoryForm() {
|
|||||||
formErrors.setError('name', t('admin.categories.validation.nameLength'))
|
formErrors.setError('name', t('admin.categories.validation.nameLength'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RG-1.05 — categoryType obligatoire.
|
// RG-1.05 — au moins un type obligatoire.
|
||||||
if (categoryTypeId.value === null) {
|
if (categoryTypeIds.value.length === 0) {
|
||||||
formErrors.setError('categoryType', t('admin.categories.validation.typeRequired'))
|
formErrors.setError('categoryTypes', t('admin.categories.validation.typesRequired'))
|
||||||
}
|
}
|
||||||
|
|
||||||
return !formErrors.errors.name && !formErrors.errors.categoryType
|
return !formErrors.errors.name && !formErrors.errors.categoryTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construit le payload POST a partir du state. Le `categoryType` est
|
* Construit le payload POST a partir du state. Les `categoryTypes` sont
|
||||||
* envoye en IRI Hydra (`/api/category_types/{id}`) — convention API
|
* envoyes en tableau d'IRI Hydra (`/api/category_types/{id}`) — convention
|
||||||
* Platform pour referencer une ressource liee.
|
* API Platform pour referencer une collection de ressources liees.
|
||||||
*/
|
*/
|
||||||
function buildCreatePayload(): Record<string, unknown> {
|
function buildCreatePayload(): Record<string, unknown> {
|
||||||
return {
|
return {
|
||||||
name: name.value.trim(),
|
name: name.value.trim(),
|
||||||
categoryType: `/api/category_types/${categoryTypeId.value}`,
|
categoryTypes: categoryTypeIds.value.map(id => `/api/category_types/${id}`),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,26 +174,18 @@ export function useCategoryForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PATCH /api/categories/{id}. Envoie uniquement les champs modifies pour
|
* PATCH /api/categories/{id}. Envoie le payload complet (name +
|
||||||
* coller a la semantique merge-patch (Content-Type pose par useApi).
|
* categoryTypes), comme les autres drawers du projet : le bouton
|
||||||
* Renvoie la categorie mise a jour, ou `null` en cas d'echec.
|
* Enregistrer sauvegarde a tout moment, meme sans modification, et renvoie
|
||||||
|
* toujours un retour (toast succes + refresh). Renvoie la categorie mise a
|
||||||
|
* jour, ou `null` en cas d'echec.
|
||||||
*/
|
*/
|
||||||
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
|
||||||
const payload: Record<string, unknown> = {}
|
const payload: Record<string, unknown> = {
|
||||||
if (name.value !== initialName.value) {
|
name: name.value.trim(),
|
||||||
payload.name = name.value.trim()
|
categoryTypes: categoryTypeIds.value.map(id => `/api/category_types/${id}`),
|
||||||
}
|
|
||||||
if (categoryTypeId.value !== initialCategoryTypeId.value) {
|
|
||||||
payload.categoryType = `/api/category_types/${categoryTypeId.value}`
|
|
||||||
}
|
|
||||||
// Garde-fou : un PATCH sans changement ne sert a rien. Theoriquement
|
|
||||||
// empeche par le drawer (bouton Enregistrer masque si !isDirty) mais
|
|
||||||
// on protege le composable contre un appel direct mal utilise.
|
|
||||||
if (Object.keys(payload).length === 0) {
|
|
||||||
submitting.value = false
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const updated = await api.patch<Category>(`/categories/${id}`, payload, {
|
const updated = await api.patch<Category>(`/categories/${id}`, payload, {
|
||||||
@@ -233,9 +236,9 @@ export function useCategoryForm() {
|
|||||||
*/
|
*/
|
||||||
function reset(): void {
|
function reset(): void {
|
||||||
name.value = ''
|
name.value = ''
|
||||||
categoryTypeId.value = null
|
categoryTypeIds.value = []
|
||||||
initialName.value = ''
|
initialName.value = ''
|
||||||
initialCategoryTypeId.value = null
|
initialCategoryTypeIds.value = []
|
||||||
formErrors.clearErrors()
|
formErrors.clearErrors()
|
||||||
submitting.value = false
|
submitting.value = false
|
||||||
}
|
}
|
||||||
@@ -243,7 +246,7 @@ export function useCategoryForm() {
|
|||||||
return {
|
return {
|
||||||
// State
|
// State
|
||||||
name,
|
name,
|
||||||
categoryTypeId,
|
categoryTypeIds,
|
||||||
errors: formErrors.errors,
|
errors: formErrors.errors,
|
||||||
submitting,
|
submitting,
|
||||||
isDirty,
|
isDirty,
|
||||||
|
|||||||
@@ -3,13 +3,28 @@
|
|||||||
<PageHeader>
|
<PageHeader>
|
||||||
{{ t('admin.categories.title') }}
|
{{ t('admin.categories.title') }}
|
||||||
<template #actions>
|
<template #actions>
|
||||||
|
<!-- gap-8 = 32px d'espacement entre Filtres et Ajouter (meme
|
||||||
|
design que le Repertoire Clients). -->
|
||||||
|
<div class="flex items-center gap-8">
|
||||||
|
<!-- Bouton Filtres a GAUCHE d'Ajouter. Le compteur reflete
|
||||||
|
les filtres actifs. -->
|
||||||
|
<MalioButton
|
||||||
|
variant="tertiary"
|
||||||
|
:label="filterButtonLabel"
|
||||||
|
icon-name="mdi:tune"
|
||||||
|
icon-position="left"
|
||||||
|
icon-size="24"
|
||||||
|
@click="openFilters"
|
||||||
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-if="canManage"
|
v-if="canManage"
|
||||||
|
variant="secondary"
|
||||||
:label="t('admin.categories.newCategory')"
|
:label="t('admin.categories.newCategory')"
|
||||||
icon-name="mdi:add-bold"
|
icon-name="mdi:add-bold"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
@click="openCreateDrawer"
|
@click="openCreateDrawer"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
|
||||||
@@ -47,6 +62,60 @@
|
|||||||
:loading="deleting"
|
:loading="deleting"
|
||||||
@confirm="handleDelete"
|
@confirm="handleDelete"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- Drawer de filtres : etat BROUILLON, applique uniquement au clic sur
|
||||||
|
« Appliquer ». Meme pattern que le Repertoire Clients. Etat 100 %
|
||||||
|
local, jamais dans l'URL (regle ABSOLUE n°6). -->
|
||||||
|
<MalioDrawer
|
||||||
|
v-model="filterDrawerOpen"
|
||||||
|
drawer-class="max-w-[450px]"
|
||||||
|
body-class="p-0"
|
||||||
|
footer-class="justify-between border-t border-black p-6"
|
||||||
|
>
|
||||||
|
<template #header>
|
||||||
|
<h2 class="text-[24px] font-bold uppercase">{{ t('admin.categories.filters.title') }}</h2>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<MalioAccordion>
|
||||||
|
<!-- Recherche par nom (param `name`, partiel insensible a la casse). -->
|
||||||
|
<MalioAccordionItem :title="t('admin.categories.filters.search')" value="search">
|
||||||
|
<MalioInputText
|
||||||
|
v-model="draftSearch"
|
||||||
|
icon-name="mdi:magnify"
|
||||||
|
/>
|
||||||
|
</MalioAccordionItem>
|
||||||
|
|
||||||
|
<!-- Type(s) : cases a cocher (multi). Une categorie remonte si
|
||||||
|
elle porte AU MOINS UN des types coches (OR cote back). -->
|
||||||
|
<MalioAccordionItem :title="t('admin.categories.filters.types')" value="types">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<MalioCheckbox
|
||||||
|
v-for="opt in typeFilterOptions"
|
||||||
|
:id="`filter-type-${opt.value}`"
|
||||||
|
:key="opt.value"
|
||||||
|
:label="opt.label"
|
||||||
|
:model-value="draftTypeIds.includes(opt.value)"
|
||||||
|
@update:model-value="(val: boolean) => toggleType(opt.value, val)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</MalioAccordionItem>
|
||||||
|
</MalioAccordion>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<MalioButton
|
||||||
|
variant="tertiary"
|
||||||
|
:label="t('admin.categories.filters.reset')"
|
||||||
|
button-class="w-m-btn-action"
|
||||||
|
@click="resetFilters"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('admin.categories.filters.apply')"
|
||||||
|
button-class="w-[170px]"
|
||||||
|
@click="applyFilters"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</MalioDrawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -55,7 +124,7 @@ import type { Category } from '~/modules/catalog/types/category'
|
|||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { can } = usePermissions()
|
const { can } = usePermissions()
|
||||||
const { fetchTypes } = useCategoriesAdmin()
|
const { types, fetchTypes } = useCategoriesAdmin()
|
||||||
const { submitDelete } = useCategoryForm()
|
const { submitDelete } = useCategoryForm()
|
||||||
|
|
||||||
useHead({ title: t('admin.categories.title') })
|
useHead({ title: t('admin.categories.title') })
|
||||||
@@ -74,6 +143,7 @@ const {
|
|||||||
fetch: fetchCategories,
|
fetch: fetchCategories,
|
||||||
goToPage,
|
goToPage,
|
||||||
setItemsPerPage,
|
setItemsPerPage,
|
||||||
|
setFilters,
|
||||||
} = usePaginatedList<Category>({ url: '/categories' })
|
} = usePaginatedList<Category>({ url: '/categories' })
|
||||||
|
|
||||||
const drawerOpen = ref(false)
|
const drawerOpen = ref(false)
|
||||||
@@ -82,21 +152,96 @@ const deleteModalOpen = ref(false)
|
|||||||
const categoryToDelete = ref<Category | null>(null)
|
const categoryToDelete = ref<Category | null>(null)
|
||||||
const deleting = ref(false)
|
const deleting = ref(false)
|
||||||
|
|
||||||
// Colonnes du datatable. Le type est embarque cote API (cf. spec-back § 3.4) —
|
// Colonnes du datatable. Les types sont embarques cote API (ManyToMany) — on
|
||||||
// on aplatit en label lisible pour l'affichage.
|
// aplatit en libelles joints par une virgule pour l'affichage.
|
||||||
const columns = [
|
const columns = [
|
||||||
{ key: 'name', label: t('admin.categories.table.name') },
|
{ key: 'name', label: t('admin.categories.table.name') },
|
||||||
{ key: 'typeLabel', label: t('admin.categories.table.type') },
|
{ key: 'typesLabel', label: t('admin.categories.table.types') },
|
||||||
]
|
]
|
||||||
|
|
||||||
const categoryItems = computed(() =>
|
const categoryItems = computed(() =>
|
||||||
categories.value.map(cat => ({
|
categories.value.map(cat => ({
|
||||||
id: cat.id,
|
id: cat.id,
|
||||||
name: cat.name,
|
name: cat.name,
|
||||||
typeLabel: cat.categoryType?.label ?? '',
|
typesLabel: (cat.categoryTypes ?? []).map(ct => ct.label).join(', '),
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ── Filtres (drawer) ────────────────────────────────────────────────────────
|
||||||
|
// Deux niveaux d'etat (pattern Repertoire Clients) :
|
||||||
|
// - APPLIED : pilote la liste + le compteur du bouton. Modifie uniquement au
|
||||||
|
// clic « Appliquer » / « Réinitialiser ».
|
||||||
|
// - DRAFT : edite librement dans le drawer ; recopie vers applied a la validation.
|
||||||
|
const filterDrawerOpen = ref(false)
|
||||||
|
|
||||||
|
const draftSearch = ref('')
|
||||||
|
const draftTypeIds = ref<number[]>([])
|
||||||
|
|
||||||
|
const appliedSearch = ref('')
|
||||||
|
const appliedTypeIds = ref<number[]>([])
|
||||||
|
|
||||||
|
// Options du filtre Type(s), derivees du referentiel deja charge (fetchTypes).
|
||||||
|
const typeFilterOptions = computed(() =>
|
||||||
|
types.value.map(ct => ({ value: ct.id, label: ct.label })),
|
||||||
|
)
|
||||||
|
|
||||||
|
const activeFilterCount = computed(() => {
|
||||||
|
let count = 0
|
||||||
|
if (appliedSearch.value.trim() !== '') count++
|
||||||
|
if (appliedTypeIds.value.length > 0) count++
|
||||||
|
return count
|
||||||
|
})
|
||||||
|
|
||||||
|
const filterButtonLabel = computed(() => {
|
||||||
|
const base = t('admin.categories.filters.title')
|
||||||
|
return activeFilterCount.value > 0 ? `${base} (${activeFilterCount.value})` : base
|
||||||
|
})
|
||||||
|
|
||||||
|
// Recopie l'etat applique vers le brouillon puis ouvre le drawer.
|
||||||
|
function openFilters(): void {
|
||||||
|
draftSearch.value = appliedSearch.value
|
||||||
|
draftTypeIds.value = [...appliedTypeIds.value]
|
||||||
|
filterDrawerOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleType(id: number, selected: boolean): void {
|
||||||
|
draftTypeIds.value = selected
|
||||||
|
? [...draftTypeIds.value, id]
|
||||||
|
: draftTypeIds.value.filter(t => t !== id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit le payload de filtres serveur a partir de l'etat applique. Cle
|
||||||
|
* `typeId[]` pour que PHP la parse en tableau (OR cote back). Filtres vides omis.
|
||||||
|
*/
|
||||||
|
function buildFilterPayload(): Record<string, string | string[]> {
|
||||||
|
const payload: Record<string, string | string[]> = {}
|
||||||
|
if (appliedSearch.value.trim() !== '') payload.name = appliedSearch.value.trim()
|
||||||
|
if (appliedTypeIds.value.length > 0) payload['typeId[]'] = appliedTypeIds.value.map(String)
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
|
// « Appliquer » : recopie brouillon → applied, pousse les filtres (retombe en
|
||||||
|
// page 1 via usePaginatedList) et ferme le drawer.
|
||||||
|
function applyFilters(): void {
|
||||||
|
appliedSearch.value = draftSearch.value.trim()
|
||||||
|
appliedTypeIds.value = [...draftTypeIds.value]
|
||||||
|
|
||||||
|
setFilters(buildFilterPayload(), { replace: true })
|
||||||
|
filterDrawerOpen.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// « Réinitialiser » : vide brouillon ET applied, recharge la liste complete.
|
||||||
|
// Le drawer reste ouvert pour montrer le formulaire vide.
|
||||||
|
function resetFilters(): void {
|
||||||
|
draftSearch.value = ''
|
||||||
|
draftTypeIds.value = []
|
||||||
|
appliedSearch.value = ''
|
||||||
|
appliedTypeIds.value = []
|
||||||
|
|
||||||
|
setFilters({}, { replace: true })
|
||||||
|
}
|
||||||
|
|
||||||
function getCategoryById(id: number): Category | undefined {
|
function getCategoryById(id: number): Category | undefined {
|
||||||
return categories.value.find(c => c.id === id)
|
return categories.value.find(c => c.id === id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@
|
|||||||
* Contrats API consommes :
|
* Contrats API consommes :
|
||||||
* - GET /api/categories → HydraCollection<Category>
|
* - GET /api/categories → HydraCollection<Category>
|
||||||
* - GET /api/categories/{id} → Category
|
* - GET /api/categories/{id} → Category
|
||||||
* - POST /api/categories → body { name, categoryType: IRI }
|
* - POST /api/categories → body { name, categoryTypes: IRI[] }
|
||||||
* - PATCH /api/categories/{id} → body partiel { name?, categoryType?: IRI }
|
* - PATCH /api/categories/{id} → body partiel { name?, categoryTypes?: IRI[] }
|
||||||
* - DELETE /api/categories/{id} → 204 (soft delete via CategoryProcessor)
|
* - DELETE /api/categories/{id} → 204 (soft delete via CategoryProcessor)
|
||||||
* - GET /api/category_types → HydraCollection<CategoryType>
|
* - GET /api/category_types → HydraCollection<CategoryType>
|
||||||
*
|
*
|
||||||
* Notes :
|
* Notes :
|
||||||
* - Les IRI sont envoyes en POST/PATCH (ex. "/api/category_types/3").
|
* - Les IRI sont envoyes en POST/PATCH (ex. ["/api/category_types/3"]).
|
||||||
* - `categoryType` est embarque (groupe Serializer `category:read` sur les
|
* - `categoryTypes` est embarque (groupe Serializer `category:read` sur les
|
||||||
* proprietes de CategoryType, cf. spec-back § 3.4).
|
* proprietes de CategoryType) : tableau d'objets type en lecture.
|
||||||
* - `createdBy` / `updatedBy` peuvent etre `null` (hors contexte HTTP,
|
* - `createdBy` / `updatedBy` peuvent etre `null` (hors contexte HTTP,
|
||||||
* ON DELETE SET NULL en BDD). Affichage : libelle "Systeme" si null.
|
* ON DELETE SET NULL en BDD). Affichage : libelle "Systeme" si null.
|
||||||
*/
|
*/
|
||||||
@@ -43,7 +43,8 @@ export interface CategoryType {
|
|||||||
export interface Category {
|
export interface Category {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
categoryType: CategoryType
|
/** Types de la categorie (>= 1, ManyToMany embarque en lecture). */
|
||||||
|
categoryTypes: CategoryType[]
|
||||||
/** Soft delete : null = active, valeur = supprimee logiquement le {date}. */
|
/** Soft delete : null = active, valeur = supprimee logiquement le {date}. */
|
||||||
deletedAt: string | null
|
deletedAt: string | null
|
||||||
createdAt: string
|
createdAt: string
|
||||||
@@ -53,12 +54,12 @@ export interface Category {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payload accepte en POST /api/categories. `categoryType` est envoye en
|
* Payload accepte en POST /api/categories. `categoryTypes` est un tableau
|
||||||
* IRI Hydra (ex. `/api/category_types/3`).
|
* d'IRI Hydra (ex. `['/api/category_types/3', '/api/category_types/5']`).
|
||||||
*/
|
*/
|
||||||
export interface CategoryCreateInput {
|
export interface CategoryCreateInput {
|
||||||
name: string
|
name: string
|
||||||
categoryType: string
|
categoryTypes: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,5 +68,5 @@ export interface CategoryCreateInput {
|
|||||||
*/
|
*/
|
||||||
export interface CategoryUpdateInput {
|
export interface CategoryUpdateInput {
|
||||||
name?: string
|
name?: string
|
||||||
categoryType?: string
|
categoryTypes?: string[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,15 @@
|
|||||||
remplacant les 3 cases. Les options encodent les combinaisons valides
|
remplacant les 3 cases. Les options encodent les combinaisons valides
|
||||||
(exclusivite Prospect, RG-1.06/07/08) ; le back recoit toujours les
|
(exclusivite Prospect, RG-1.06/07/08) ; le back recoit toujours les
|
||||||
drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). -->
|
drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). -->
|
||||||
|
<!-- Erreur portee sur `isProspect` cote back (Callback type obligatoire +
|
||||||
|
exclusivite prospect) -> affichee sous le select Type d'adresse. -->
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
:model-value="addressType"
|
:model-value="addressType"
|
||||||
:options="addressTypeOptions"
|
:options="addressTypeOptions"
|
||||||
:label="t('commercial.clients.form.address.addressType')"
|
:label="t('commercial.clients.form.address.addressType')"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:required="true"
|
:required="true"
|
||||||
|
:error="errors?.isProspect"
|
||||||
@update:model-value="onAddressTypeChange"
|
@update:model-value="onAddressTypeChange"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -31,6 +34,7 @@
|
|||||||
:display-tag="true"
|
:display-tag="true"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:required="true"
|
:required="true"
|
||||||
|
:error="errors?.sites"
|
||||||
@update:model-value="(v: (string | number)[]) => update('siteIris', v.map(String))"
|
@update:model-value="(v: (string | number)[]) => update('siteIris', v.map(String))"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -43,9 +47,10 @@
|
|||||||
@update:model-value="(v: (string | number)[]) => update('contactIris', v.map(String))"
|
@update:model-value="(v: (string | number)[]) => update('contactIris', v.map(String))"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Email de facturation : ligne 1 colonne 4, visible/obligatoire
|
<!-- Email(s) de facturation : visible/obligatoire seulement si Facturation
|
||||||
seulement si Facturation (RG-1.11). Sinon un filler comble la
|
(RG-1.11). Le « + » revele un 2e email optionnel (max 2, pendant du
|
||||||
colonne pour que Categorie reparte au debut de la ligne 2. -->
|
telephone secondaire) qui coule dans la grille. Sinon un filler comble
|
||||||
|
la colonne pour que Categorie reparte au debut de la ligne suivante. -->
|
||||||
<MalioInputEmail
|
<MalioInputEmail
|
||||||
v-if="isBillingEmailRequired(model)"
|
v-if="isBillingEmailRequired(model)"
|
||||||
:model-value="model.billingEmail"
|
:model-value="model.billingEmail"
|
||||||
@@ -54,10 +59,23 @@
|
|||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:lowercase="true"
|
:lowercase="true"
|
||||||
:error="errors?.billingEmail"
|
:error="errors?.billingEmail"
|
||||||
|
:addable="!model.hasSecondaryBillingEmail && !readonly"
|
||||||
|
:add-button-label="t('commercial.clients.form.address.addBillingEmail')"
|
||||||
@update:model-value="(v: string) => update('billingEmail', v)"
|
@update:model-value="(v: string) => update('billingEmail', v)"
|
||||||
|
@add="revealSecondaryBillingEmail"
|
||||||
/>
|
/>
|
||||||
<div v-else aria-hidden="true" />
|
<div v-else aria-hidden="true" />
|
||||||
|
|
||||||
|
<MalioInputEmail
|
||||||
|
v-if="isBillingEmailRequired(model) && model.hasSecondaryBillingEmail"
|
||||||
|
:model-value="model.billingEmailSecondary"
|
||||||
|
:label="t('commercial.clients.form.address.billingEmailSecondary')"
|
||||||
|
:readonly="readonly"
|
||||||
|
:lowercase="true"
|
||||||
|
:error="errors?.billingEmailSecondary"
|
||||||
|
@update:model-value="(v: string) => update('billingEmailSecondary', v)"
|
||||||
|
/>
|
||||||
|
|
||||||
<MalioSelectCheckbox
|
<MalioSelectCheckbox
|
||||||
:model-value="model.categoryIris"
|
:model-value="model.categoryIris"
|
||||||
:options="categoryOptions"
|
:options="categoryOptions"
|
||||||
@@ -65,6 +83,7 @@
|
|||||||
:display-tag="true"
|
:display-tag="true"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:required="true"
|
:required="true"
|
||||||
|
:error="errors?.categories"
|
||||||
@update:model-value="(v: (string | number)[]) => update('categoryIris', v.map(String))"
|
@update:model-value="(v: (string | number)[]) => update('categoryIris', v.map(String))"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -87,8 +106,9 @@
|
|||||||
@update:model-value="onPostalCodeChange"
|
@update:model-value="onPostalCodeChange"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Ville : MalioSelect alimente par le code postal (BAN). En mode
|
<!-- Ville : MalioSelect alimente par le code postal (BAN). Si la BAN est
|
||||||
degrade (service indisponible), bascule en saisie libre. -->
|
indisponible, bascule en saisie libre — recuperable : re-saisir le
|
||||||
|
code postal relance la recherche et repasse en select au succes. -->
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
v-if="!degraded"
|
v-if="!degraded"
|
||||||
:model-value="model.city"
|
:model-value="model.city"
|
||||||
@@ -115,11 +135,14 @@
|
|||||||
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) en edition ; champ texte simple en
|
<!-- Adresse : saisie assistee (BAN) en edition ; champ texte simple
|
||||||
mode degrade OU en lecture seule (MalioInputAutocomplete ne reaffiche
|
seulement en lecture seule (MalioInputAutocomplete ne reaffiche pas
|
||||||
pas sa valeur liee, il n'afficherait rien en readonly). -->
|
sa valeur liee, il n'afficherait rien en readonly). allow-create :
|
||||||
|
si la BAN ne propose rien (ou erreur), le texte saisi est CONSERVE au
|
||||||
|
blur/Entree (saisie manuelle) — sinon il serait efface. La ville reste
|
||||||
|
pilotee par le code postal ; choisir une suggestion remplit rue+ville+CP. -->
|
||||||
<MalioInputAutocomplete
|
<MalioInputAutocomplete
|
||||||
v-if="!degraded && !readonly"
|
v-if="!readonly"
|
||||||
:model-value="model.street"
|
:model-value="model.street"
|
||||||
:options="addressOptions"
|
:options="addressOptions"
|
||||||
:loading="addressLoading"
|
:loading="addressLoading"
|
||||||
@@ -128,6 +151,8 @@
|
|||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:required="true"
|
:required="true"
|
||||||
:error="errors?.street"
|
:error="errors?.street"
|
||||||
|
:allow-create="true"
|
||||||
|
:no-results-text="t('commercial.clients.form.address.streetNotFound')"
|
||||||
@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"
|
||||||
@@ -143,7 +168,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-span-2">
|
<div class="col-span-1">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
:model-value="model.streetComplement"
|
:model-value="model.streetComplement"
|
||||||
:label="t('commercial.clients.form.address.streetComplement')"
|
:label="t('commercial.clients.form.address.streetComplement')"
|
||||||
@@ -209,6 +234,8 @@ const addressTypeOptions = computed<RefOption[]>(() => [
|
|||||||
{ value: 'delivery', label: t('commercial.clients.form.address.addressTypeDelivery') },
|
{ value: 'delivery', label: t('commercial.clients.form.address.addressTypeDelivery') },
|
||||||
{ value: 'billing', label: t('commercial.clients.form.address.addressTypeBilling') },
|
{ value: 'billing', label: t('commercial.clients.form.address.addressTypeBilling') },
|
||||||
{ value: 'delivery_billing', label: t('commercial.clients.form.address.addressTypeDeliveryBilling') },
|
{ value: 'delivery_billing', label: t('commercial.clients.form.address.addressTypeDeliveryBilling') },
|
||||||
|
{ value: 'broker', label: t('commercial.clients.form.address.addressTypeBroker') },
|
||||||
|
{ value: 'distributor', label: t('commercial.clients.form.address.addressTypeDistributor') },
|
||||||
])
|
])
|
||||||
|
|
||||||
/** Applique le type choisi en repercutant les 3 drapeaux back (immutabilite). */
|
/** Applique le type choisi en repercutant les 3 drapeaux back (immutabilite). */
|
||||||
@@ -217,8 +244,12 @@ function onAddressTypeChange(value: string | number | null): void {
|
|||||||
emit('update:modelValue', { ...props.modelValue, ...addressFlagsFromType(value as AddressType) })
|
emit('update:modelValue', { ...props.modelValue, ...addressFlagsFromType(value as AddressType) })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mode degrade : service BAN indisponible → Ville/Adresse en saisie libre.
|
// Repli saisie libre de la VILLE quand la BAN est indisponible (recuperable :
|
||||||
|
// remis a false des qu'une recherche de ville aboutit). N'affecte plus le champ
|
||||||
|
// Adresse, qui reste en autocompletion et reessaie a chaque frappe.
|
||||||
const degraded = ref(false)
|
const degraded = ref(false)
|
||||||
|
// Avertissement « service indisponible » envoye au parent une seule fois.
|
||||||
|
let unavailableNotified = false
|
||||||
// Villes proposees par la BAN (alimentees a la saisie du code postal).
|
// Villes proposees par la BAN (alimentees a la saisie du code postal).
|
||||||
const banCityOptions = ref<RefOption[]>([])
|
const banCityOptions = ref<RefOption[]>([])
|
||||||
// Adresses proposees par la BAN (alimentees a la saisie d'adresse).
|
// Adresses proposees par la BAN (alimentees a la saisie d'adresse).
|
||||||
@@ -258,10 +289,15 @@ function update<K extends keyof AddressFormDraft>(field: K, value: AddressFormDr
|
|||||||
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Bascule définitivement en mode degrade et previent le parent (toast unique). */
|
/** Revele le 2e champ email de facturation (clic sur le « + »). */
|
||||||
function enterDegraded(): void {
|
function revealSecondaryBillingEmail(): void {
|
||||||
if (!degraded.value) {
|
emit('update:modelValue', { ...props.modelValue, hasSecondaryBillingEmail: true })
|
||||||
degraded.value = true
|
}
|
||||||
|
|
||||||
|
/** Previent le parent (toast unique) que l'autocompletion est indisponible. */
|
||||||
|
function notifyUnavailable(): void {
|
||||||
|
if (!unavailableNotified) {
|
||||||
|
unavailableNotified = true
|
||||||
emit('degraded')
|
emit('degraded')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,9 +306,6 @@ function enterDegraded(): void {
|
|||||||
async function onPostalCodeChange(value: string): Promise<void> {
|
async function onPostalCodeChange(value: string): Promise<void> {
|
||||||
update('postalCode', value)
|
update('postalCode', value)
|
||||||
|
|
||||||
if (degraded.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const digits = (value ?? '').replace(/\D/g, '')
|
const digits = (value ?? '').replace(/\D/g, '')
|
||||||
if (digits.length < 5) {
|
if (digits.length < 5) {
|
||||||
return
|
return
|
||||||
@@ -280,15 +313,22 @@ async function onPostalCodeChange(value: string): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
const suggestions = await autocomplete.searchCity(digits)
|
const suggestions = await autocomplete.searchCity(digits)
|
||||||
banCityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
|
banCityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
|
||||||
|
// Service repondu : on (re)passe la Ville en select assiste.
|
||||||
|
degraded.value = false
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
enterDegraded()
|
// BAN indispo : Ville en saisie libre (recuperable au prochain essai).
|
||||||
|
degraded.value = true
|
||||||
|
notifyUnavailable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Recherche d'adresse assistee (event de MalioInputAutocomplete). */
|
/** Recherche d'adresse assistee (event de MalioInputAutocomplete). */
|
||||||
async function onAddressSearch(query: string): Promise<void> {
|
async function onAddressSearch(query: string): Promise<void> {
|
||||||
if (degraded.value) {
|
// La BAN exige au moins 3 caracteres : on n'envoie rien en deca (evite un 400)
|
||||||
|
// et on vide les suggestions devenues obsoletes.
|
||||||
|
if (query.trim().length < 3) {
|
||||||
|
banAddressOptions.value = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
addressLoading.value = true
|
addressLoading.value = true
|
||||||
@@ -299,7 +339,10 @@ async function onAddressSearch(query: string): Promise<void> {
|
|||||||
banAddressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
banAddressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
enterDegraded()
|
// Erreur transitoire : on vide les suggestions, la prochaine frappe reessaie
|
||||||
|
// (pas de bascule definitive — c'etait le bug). Avertissement une seule fois.
|
||||||
|
banAddressOptions.value = []
|
||||||
|
notifyUnavailable()
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
addressLoading.value = false
|
addressLoading.value = false
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest'
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
import { mount } from '@vue/test-utils'
|
import { mount, flushPromises } from '@vue/test-utils'
|
||||||
import { defineComponent, h, ref, computed } from 'vue'
|
import { defineComponent, h, ref, computed } from 'vue'
|
||||||
import { emptyAddress } from '~/modules/commercial/types/clientForm'
|
import { emptyAddress } from '~/modules/commercial/types/clientForm'
|
||||||
import ClientAddressBlock from '../ClientAddressBlock.vue'
|
import ClientAddressBlock from '../ClientAddressBlock.vue'
|
||||||
|
|
||||||
// Le composable BAN est mocke : aucun appel reseau, aucune suggestion chargee.
|
// Mocks controlables du composable BAN (hoisted) : chaque test configure le
|
||||||
// On reproduit ainsi l'etat « adresse persistee, mais liste de suggestions
|
// comportement de searchCity / searchAddress (succes, rejet, rejet-puis-succes).
|
||||||
// vide » (remontage apres validation / edition d'une adresse existante).
|
// Par defaut ils renvoient undefined (aucune suggestion) — etat « adresse
|
||||||
|
// persistee mais liste vide » couvert par les tests d'affichage.
|
||||||
|
const { searchCityMock, searchAddressMock } = vi.hoisted(() => ({
|
||||||
|
searchCityMock: vi.fn(),
|
||||||
|
searchAddressMock: vi.fn(),
|
||||||
|
}))
|
||||||
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
||||||
useAddressAutocomplete: () => ({
|
useAddressAutocomplete: () => ({
|
||||||
searchCity: vi.fn(),
|
searchCity: searchCityMock,
|
||||||
searchAddress: vi.fn(),
|
searchAddress: searchAddressMock,
|
||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@@ -31,6 +36,7 @@ const MalioInputAutocompleteStub = defineComponent({
|
|||||||
minSearchLength: { type: Number, default: 0 },
|
minSearchLength: { type: Number, default: 0 },
|
||||||
label: { type: String, default: '' },
|
label: { type: String, default: '' },
|
||||||
readonly: { type: Boolean, default: false },
|
readonly: { type: Boolean, default: false },
|
||||||
|
allowCreate: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
emits: ['update:modelValue', 'search', 'select'],
|
emits: ['update:modelValue', 'search', 'select'],
|
||||||
setup(props) {
|
setup(props) {
|
||||||
@@ -73,6 +79,14 @@ describe('ClientAddressBlock — affichage de l\'adresse persistee', () => {
|
|||||||
|
|
||||||
expect(values).toContain('8 Boulevard du Port')
|
expect(values).toContain('8 Boulevard du Port')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ERP-119 : saisie manuelle possible quand la BAN ne trouve rien -> allow-create
|
||||||
|
// (sans cette prop, MalioInputAutocomplete efface le texte non selectionne au blur).
|
||||||
|
it('active allow-create sur le champ Adresse (saisie manuelle libre)', () => {
|
||||||
|
const wrapper = mountBlock(null)
|
||||||
|
|
||||||
|
expect(wrapper.findComponent(MalioInputAutocompleteStub).props('allowCreate')).toBe(true)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,4 +143,84 @@ describe('ClientAddressBlock — mapping erreur par champ (ERP-101)', () => {
|
|||||||
)
|
)
|
||||||
expect(field?.attributes('data-error')).toBe('Code postal invalide.')
|
expect(field?.attributes('data-error')).toBe('Code postal invalide.')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ERP-119 : type d'adresse (propertyPath back `isProspect`), sites et
|
||||||
|
// categories sont obligatoires ; leurs violations 422 doivent s'afficher sous
|
||||||
|
// le champ correspondant (bindings :error de ClientAddressBlock).
|
||||||
|
it('affiche l\'erreur serveur sur type d\'adresse (propertyPath isProspect)', () => {
|
||||||
|
const wrapper = mountWithErrors({ isProspect: 'Le type d\'adresse est obligatoire.' })
|
||||||
|
|
||||||
|
const field = wrapper.findAll('malio-select-stub').find(
|
||||||
|
el => el.attributes('label') === 'commercial.clients.form.address.addressType',
|
||||||
|
)
|
||||||
|
expect(field?.attributes('error')).toBe('Le type d\'adresse est obligatoire.')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('affiche les erreurs serveur sur sites et categories', () => {
|
||||||
|
const wrapper = mountWithErrors({
|
||||||
|
sites: 'Au moins un site est obligatoire.',
|
||||||
|
categories: 'Au moins une catégorie est obligatoire.',
|
||||||
|
})
|
||||||
|
|
||||||
|
const checkboxes = wrapper.findAll('malio-select-checkbox-stub')
|
||||||
|
const sitesField = checkboxes.find(el => el.attributes('label') === 'commercial.clients.form.address.sites')
|
||||||
|
const categoriesField = checkboxes.find(el => el.attributes('label') === 'commercial.clients.form.address.categories')
|
||||||
|
|
||||||
|
expect(sitesField?.attributes('error')).toBe('Au moins un site est obligatoire.')
|
||||||
|
expect(categoriesField?.attributes('error')).toBe('Au moins une catégorie est obligatoire.')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('ClientAddressBlock — recherche adresse robuste (erreur BAN)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
searchAddressMock.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('n\'appelle pas la BAN en deca de 3 caracteres', async () => {
|
||||||
|
const wrapper = mountBlock(null)
|
||||||
|
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||||
|
|
||||||
|
auto.vm.$emit('search', 'ab')
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
expect(searchAddressMock).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('relance la recherche apres une erreur (pas de bascule definitive)', async () => {
|
||||||
|
searchAddressMock
|
||||||
|
.mockRejectedValueOnce(new Error('BAN indisponible'))
|
||||||
|
.mockResolvedValueOnce([
|
||||||
|
{ label: '8 Boulevard du Port, Paris', street: '8 Boulevard du Port', postalCode: '75001', city: 'Paris' },
|
||||||
|
])
|
||||||
|
|
||||||
|
const wrapper = mountBlock(null)
|
||||||
|
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||||
|
|
||||||
|
// 1er essai -> erreur BAN.
|
||||||
|
auto.vm.$emit('search', 'boulevard du port')
|
||||||
|
await flushPromises()
|
||||||
|
expect(searchAddressMock).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
|
// 2e essai -> DOIT relancer l'appel (c'etait le bug : plus aucune recherche).
|
||||||
|
auto.vm.$emit('search', 'boulevard du porte')
|
||||||
|
await flushPromises()
|
||||||
|
expect(searchAddressMock).toHaveBeenCalledTimes(2)
|
||||||
|
|
||||||
|
// L'autocompletion reste montee (aucune bascule en saisie libre).
|
||||||
|
expect(wrapper.find('[data-testid="addr-autocomplete"]').exists()).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('emet « degraded » une seule fois malgre plusieurs erreurs', async () => {
|
||||||
|
searchAddressMock.mockRejectedValue(new Error('BAN indisponible'))
|
||||||
|
|
||||||
|
const wrapper = mountBlock(null)
|
||||||
|
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||||
|
|
||||||
|
auto.vm.$emit('search', 'rue de la paix')
|
||||||
|
await flushPromises()
|
||||||
|
auto.vm.$emit('search', 'rue de la paixx')
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
expect(wrapper.emitted('degraded')).toHaveLength(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -99,7 +99,9 @@ export function useClientReferentials() {
|
|||||||
*/
|
*/
|
||||||
async function loadCommon(): Promise<void> {
|
async function loadCommon(): Promise<void> {
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
fetchAll<CategoryMember>('/categories')
|
// Taxonomie multi-types (ERP-84) : un client ne porte que des categories
|
||||||
|
// de type CLIENT (pas FOURNISSEUR) -> on filtre la collection cote API.
|
||||||
|
fetchAll<CategoryMember>('/categories', { typeCode: 'CLIENT' })
|
||||||
.then((cats) => { 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')
|
||||||
// Libelle = numero de departement (2 premiers chiffres du code
|
// Libelle = numero de departement (2 premiers chiffres du code
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<!-- En-tete : retour repertoire + nom du client. -->
|
<!-- En-tete : retour repertoire + nom du client. -->
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3 pt-11">
|
||||||
<MalioButtonIcon
|
<MalioButtonIcon
|
||||||
icon="mdi:arrow-left-bold"
|
icon="mdi:arrow-left-bold"
|
||||||
icon-size="24"
|
icon-size="24"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
v-bind="{ ariaLabel: t('commercial.clients.edit.back') }"
|
v-bind="{ ariaLabel: t('commercial.clients.edit.back') }"
|
||||||
@click="goBack"
|
@click="goBack"
|
||||||
/>
|
/>
|
||||||
<h1 class="text-[32px] font-bold text-m-primary">{{ headerTitle }}</h1>
|
<h1 class="text-[30px] font-semibold text-m-primary">{{ headerTitle }}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Etats de chargement / introuvable. -->
|
<!-- Etats de chargement / introuvable. -->
|
||||||
@@ -41,6 +41,7 @@
|
|||||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
|
v-if="showRelationAndTriage"
|
||||||
: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')"
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
@update:model-value="onRelationChange"
|
@update:model-value="onRelationChange"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
v-if="main.relationType === 'courtier'"
|
v-if="showRelationAndTriage && main.relationType === 'courtier'"
|
||||||
:model-value="main.brokerIri"
|
:model-value="main.brokerIri"
|
||||||
:options="brokerOptions"
|
:options="brokerOptions"
|
||||||
:label="t('commercial.clients.form.main.brokerName')"
|
:label="t('commercial.clients.form.main.brokerName')"
|
||||||
@@ -59,7 +60,7 @@
|
|||||||
@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
|
||||||
v-if="main.relationType === 'distributeur'"
|
v-if="showRelationAndTriage && main.relationType === 'distributeur'"
|
||||||
:model-value="main.distributorIri"
|
:model-value="main.distributorIri"
|
||||||
:options="distributorOptions"
|
:options="distributorOptions"
|
||||||
:label="t('commercial.clients.form.main.distributorName')"
|
:label="t('commercial.clients.form.main.distributorName')"
|
||||||
@@ -69,6 +70,7 @@
|
|||||||
@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
|
||||||
|
v-if="showRelationAndTriage"
|
||||||
v-model="main.triageService"
|
v-model="main.triageService"
|
||||||
:label="t('commercial.clients.form.main.triageService')"
|
:label="t('commercial.clients.form.main.triageService')"
|
||||||
group-class="self-center"
|
group-class="self-center"
|
||||||
@@ -80,7 +82,7 @@
|
|||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.edit.save')"
|
:label="t('commercial.clients.edit.save')"
|
||||||
:disabled="!isMainValid || mainSubmitting"
|
:disabled="mainSubmitting"
|
||||||
@click="submitMain"
|
@click="submitMain"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -90,11 +92,14 @@
|
|||||||
<!-- Onglet Information -->
|
<!-- Onglet Information -->
|
||||||
<template #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)]">
|
<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)]">
|
||||||
|
<!-- pt-1/pb-1 alignent le textarea (h-full) en haut ET en bas
|
||||||
|
sur les inputs (champ 40px centre dans un h-12 -> ~4px de
|
||||||
|
coussin de chaque cote). -->
|
||||||
<MalioInputTextArea
|
<MalioInputTextArea
|
||||||
v-model="information.description"
|
v-model="information.description"
|
||||||
:label="t('commercial.clients.form.information.description')"
|
:label="t('commercial.clients.form.information.description')"
|
||||||
resize="none"
|
resize="none"
|
||||||
group-class="row-span-2 pt-1"
|
group-class="row-span-2 pt-1 pb-1"
|
||||||
text-input="h-full text-lg"
|
text-input="h-full text-lg"
|
||||||
:readonly="businessReadonly"
|
:readonly="businessReadonly"
|
||||||
:error="informationErrors.errors.description"
|
:error="informationErrors.errors.description"
|
||||||
@@ -109,6 +114,7 @@
|
|||||||
v-model="information.foundedAt"
|
v-model="information.foundedAt"
|
||||||
:label="t('commercial.clients.form.information.foundedAt')"
|
:label="t('commercial.clients.form.information.foundedAt')"
|
||||||
:readonly="businessReadonly"
|
:readonly="businessReadonly"
|
||||||
|
:editable="true"
|
||||||
:error="informationErrors.errors.foundedAt"
|
:error="informationErrors.errors.foundedAt"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
@@ -173,7 +179,7 @@
|
|||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.edit.save')"
|
:label="t('commercial.clients.edit.save')"
|
||||||
:disabled="!canValidateContacts || tabSubmitting"
|
:disabled="tabSubmitting"
|
||||||
@click="submitContacts"
|
@click="submitContacts"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -205,12 +211,13 @@
|
|||||||
icon-name="mdi:add-bold"
|
icon-name="mdi:add-bold"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
:label="t('commercial.clients.form.address.add')"
|
:label="t('commercial.clients.form.address.add')"
|
||||||
|
:disabled="!canAddAddress"
|
||||||
@click="addAddress"
|
@click="addAddress"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.edit.save')"
|
:label="t('commercial.clients.edit.save')"
|
||||||
:disabled="!canValidateAddresses || tabSubmitting"
|
:disabled="tabSubmitting"
|
||||||
@click="submitAddresses"
|
@click="submitAddresses"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -289,9 +296,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Blocs RIB (0..n) — obligatoires si type de reglement = LCR (RG-1.13). -->
|
<!-- Blocs RIB — affiches uniquement si type de reglement = LCR (RG-1.13). -->
|
||||||
<div
|
<div
|
||||||
v-for="(rib, index) in ribs"
|
v-for="(rib, index) in visibleRibs"
|
||||||
:key="rib.id ?? `new-${index}`"
|
: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)]"
|
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||||
>
|
>
|
||||||
@@ -330,16 +337,18 @@
|
|||||||
|
|
||||||
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
||||||
<MalioButton
|
<MalioButton
|
||||||
|
v-if="isRibRequired"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
icon-name="mdi:add-bold"
|
icon-name="mdi:add-bold"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
:label="t('commercial.clients.form.accounting.addRib')"
|
:label="t('commercial.clients.form.accounting.addRib')"
|
||||||
|
:disabled="!canAddRib"
|
||||||
@click="addRib"
|
@click="addRib"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.edit.save')"
|
:label="t('commercial.clients.edit.save')"
|
||||||
:disabled="!canValidateAccounting || tabSubmitting"
|
:disabled="tabSubmitting"
|
||||||
@click="submitAccounting"
|
@click="submitAccounting"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -379,7 +388,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||||
import { useClient } from '~/modules/commercial/composables/useClient'
|
import { useClient } from '~/modules/commercial/composables/useClient'
|
||||||
import { useClientReferentials, type CategoryOption, type RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
import { useClientReferentials, type CategoryOption, type RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
||||||
import { useClientFormErrors } from '~/modules/commercial/composables/useClientFormErrors'
|
import { useClientFormErrors } from '~/modules/commercial/composables/useClientFormErrors'
|
||||||
@@ -410,16 +419,16 @@ import {
|
|||||||
type MainFormDraft,
|
type MainFormDraft,
|
||||||
} from '~/modules/commercial/utils/clientEdit'
|
} from '~/modules/commercial/utils/clientEdit'
|
||||||
import {
|
import {
|
||||||
addressTypeFromFlags,
|
|
||||||
buildClientFormTabKeys,
|
buildClientFormTabKeys,
|
||||||
hasAllRequiredAccountingFields,
|
isAddressValid,
|
||||||
hasAtLeastOneValidContact,
|
|
||||||
isBankRequiredForPaymentType,
|
isBankRequiredForPaymentType,
|
||||||
isBillingEmailRequired,
|
isBillingEmailRequired,
|
||||||
isContactBlank,
|
isContactBlank,
|
||||||
isContactNamed,
|
isContactNamed,
|
||||||
isRibBlank,
|
isRibBlank,
|
||||||
|
isRibComplete,
|
||||||
isRibRequiredForPaymentType,
|
isRibRequiredForPaymentType,
|
||||||
|
showsRelationAndTriageFields,
|
||||||
} from '~/modules/commercial/utils/clientFormRules'
|
} from '~/modules/commercial/utils/clientFormRules'
|
||||||
import {
|
import {
|
||||||
emptyAddress,
|
emptyAddress,
|
||||||
@@ -430,6 +439,7 @@ import {
|
|||||||
type RibFormDraft,
|
type RibFormDraft,
|
||||||
} from '~/modules/commercial/types/clientForm'
|
} from '~/modules/commercial/types/clientForm'
|
||||||
import { extractApiErrorMessage } from '~/shared/utils/api'
|
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||||
|
import { readHistoryTab } from '~/shared/utils/historyTab'
|
||||||
|
|
||||||
// Masques de saisie (la normalisation finale reste serveur).
|
// Masques de saisie (la normalisation finale reste serveur).
|
||||||
const SIREN_MASK = '#########'
|
const SIREN_MASK = '#########'
|
||||||
@@ -500,7 +510,9 @@ function hydrate(detail: ClientDetail): void {
|
|||||||
// un bloc vierge (non persiste tant qu'incomplet — cf. submit*/canValidate*).
|
// un bloc vierge (non persiste tant qu'incomplet — cf. submit*/canValidate*).
|
||||||
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
||||||
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
||||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
// RIB : amorce un bloc vide seulement si le type de reglement est une LCR
|
||||||
|
// (sinon la section reste masquee — RG-1.13).
|
||||||
|
if (isRibRequired.value && ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||||
// Charge les listes distributeur / courtier si une relation est deja posee.
|
// Charge les listes distributeur / courtier si une relation est deja posee.
|
||||||
if (main.relationType === 'distributeur') referentials.loadDistributors().catch(() => {})
|
if (main.relationType === 'distributeur') referentials.loadDistributors().catch(() => {})
|
||||||
if (main.relationType === 'courtier') referentials.loadBrokers().catch(() => {})
|
if (main.relationType === 'courtier') referentials.loadBrokers().catch(() => {})
|
||||||
@@ -551,6 +563,28 @@ const relationOptions = computed<RefOption[]>(() => [
|
|||||||
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||||
])
|
])
|
||||||
|
|
||||||
|
// Codes des categories selectionnees (resolus depuis l'union referentiel + embed).
|
||||||
|
const selectedCategoryCodes = computed(() =>
|
||||||
|
main.categoryIris
|
||||||
|
.map(iri => mainCategoryOptions.value.find(c => c.value === iri)?.code)
|
||||||
|
.filter((code): code is string => code !== undefined),
|
||||||
|
)
|
||||||
|
|
||||||
|
// « Relation » + « Prestation de triage » masques par defaut, reveles des qu'une
|
||||||
|
// categorie ordinaire (autre que Distributeur/Courtier) est selectionnee.
|
||||||
|
const showRelationAndTriage = computed(() => showsRelationAndTriageFields(selectedCategoryCodes.value))
|
||||||
|
|
||||||
|
// Masquer ces champs reinitialise leurs valeurs : pas de relation/triage fantome
|
||||||
|
// soumis pour un client Distributeur/Courtier.
|
||||||
|
watch(showRelationAndTriage, (visible) => {
|
||||||
|
if (!visible) {
|
||||||
|
main.relationType = null
|
||||||
|
main.distributorIri = null
|
||||||
|
main.brokerIri = null
|
||||||
|
main.triageService = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Distributeur / courtier : referentiel charge a la demande UNION valeur courante.
|
// Distributeur / courtier : referentiel charge a la demande UNION valeur courante.
|
||||||
const currentDistributorOption = computed<RefOption[]>(() => {
|
const currentDistributorOption = computed<RefOption[]>(() => {
|
||||||
const d = client.value?.distributor
|
const d = client.value?.distributor
|
||||||
@@ -592,11 +626,13 @@ const tabs = computed(() => tabKeys.value.map(key => ({
|
|||||||
icon: TAB_ICONS[key],
|
icon: TAB_ICONS[key],
|
||||||
})))
|
})))
|
||||||
|
|
||||||
const activeTab = ref('information')
|
// Onglet initial : repris de la consultation (history.state), sinon Information.
|
||||||
|
const activeTab = ref(readHistoryTab(tabKeys.value) ?? 'information')
|
||||||
|
|
||||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||||
|
/** Retour consultation en conservant l'onglet courant (via history.state). */
|
||||||
function goBack(): void {
|
function goBack(): void {
|
||||||
router.push(`/clients/${clientId}`)
|
router.push({ path: `/clients/${clientId}`, state: { tab: activeTab.value } })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -636,17 +672,6 @@ const {
|
|||||||
} = useClientFormErrors()
|
} = useClientFormErrors()
|
||||||
|
|
||||||
// ── Bloc principal ───────────────────────────────────────────────────────────
|
// ── 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> {
|
async function onRelationChange(value: string | number | null): Promise<void> {
|
||||||
const relation = (value === null || value === '') ? null : (String(value) as 'distributeur' | 'courtier')
|
const relation = (value === null || value === '') ? null : (String(value) as 'distributeur' | 'courtier')
|
||||||
main.relationType = relation
|
main.relationType = relation
|
||||||
@@ -660,7 +685,7 @@ async function onRelationChange(value: string | number | null): Promise<void> {
|
|||||||
|
|
||||||
/** PATCH /clients/{id} — groupe client:write:main UNIQUEMENT (mode strict). */
|
/** PATCH /clients/{id} — groupe client:write:main UNIQUEMENT (mode strict). */
|
||||||
async function submitMain(): Promise<void> {
|
async function submitMain(): Promise<void> {
|
||||||
if (businessReadonly.value || !isMainValid.value || mainSubmitting.value) return
|
if (businessReadonly.value || mainSubmitting.value) return
|
||||||
mainSubmitting.value = true
|
mainSubmitting.value = true
|
||||||
mainErrors.clearErrors()
|
mainErrors.clearErrors()
|
||||||
try {
|
try {
|
||||||
@@ -713,9 +738,6 @@ const canAddContact = computed(() => {
|
|||||||
const last = contacts.value[contacts.value.length - 1]
|
const last = contacts.value[contacts.value.length - 1]
|
||||||
return last === undefined || isContactNamed(last)
|
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 {
|
function addContact(): void {
|
||||||
if (canAddContact.value) contacts.value.push(emptyContact())
|
if (canAddContact.value) contacts.value.push(emptyContact())
|
||||||
}
|
}
|
||||||
@@ -737,7 +759,7 @@ function askRemoveContact(index: number): void {
|
|||||||
* collection contacts (endpoints client_contact dedies).
|
* collection contacts (endpoints client_contact dedies).
|
||||||
*/
|
*/
|
||||||
async function submitContacts(): Promise<void> {
|
async function submitContacts(): Promise<void> {
|
||||||
if (businessReadonly.value || !canValidateContacts.value || tabSubmitting.value) return
|
if (businessReadonly.value || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
contactErrors.value = []
|
contactErrors.value = []
|
||||||
try {
|
try {
|
||||||
@@ -746,6 +768,11 @@ async function submitContacts(): Promise<void> {
|
|||||||
}
|
}
|
||||||
removedContactIds.value = []
|
removedContactIds.value = []
|
||||||
|
|
||||||
|
// RG-1.14 : au moins un contact requis. Si l'onglet ne contient QUE des
|
||||||
|
// amorces neuves vides (ex. tous les contacts existants supprimes), on ne
|
||||||
|
// les skippe pas -> le back renvoie la 422 RG-1.05 « prénom ou nom
|
||||||
|
// obligatoire » inline (la RG-1.14 n'a pas d'equivalent back au POST).
|
||||||
|
const hasSubmittableContact = contacts.value.some(c => c.id !== null || !isContactBlank(c))
|
||||||
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
||||||
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
||||||
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
||||||
@@ -768,10 +795,10 @@ async function submitContacts(): Promise<void> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => showError(error),
|
error => showError(error),
|
||||||
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
// On ne saute une amorce neuve (id null) totalement vide QUE si un autre
|
||||||
// bloc existant vide est soumis -> 422 RG-1.05 inline (sinon la modif
|
// bloc sera soumis : sinon on la soumet pour declencher la 422 RG-1.05
|
||||||
// serait perdue en silence avec un faux toast de succes).
|
// (un onglet Contact vide ne doit pas passer en faux succes).
|
||||||
contact => contact.id === null && isContactBlank(contact),
|
contact => hasSubmittableContact && contact.id === null && isContactBlank(contact),
|
||||||
)
|
)
|
||||||
// Tant qu'un bloc reste en erreur : pas de toast succes.
|
// Tant qu'un bloc reste en erreur : pas de toast succes.
|
||||||
if (hasError) return
|
if (hasError) return
|
||||||
@@ -786,19 +813,14 @@ async function submitContacts(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Onglet Adresse ───────────────────────────────────────────────────────────
|
// ── Onglet Adresse ───────────────────────────────────────────────────────────
|
||||||
const canValidateAddresses = computed(() =>
|
// « + Adresse » desactive tant que la derniere adresse n'est pas valide.
|
||||||
addresses.value.length > 0
|
const canAddAddress = computed(() => {
|
||||||
&& addresses.value.every((a) => {
|
const last = addresses.value[addresses.value.length - 1]
|
||||||
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
return last !== undefined && isAddressValid(last)
|
||||||
return addressTypeFromFlags(a) !== null
|
})
|
||||||
&& a.siteIris.length >= 1
|
|
||||||
&& a.categoryIris.length >= 1
|
|
||||||
&& (!isBillingEmailRequired(a) || filledBillingEmail)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
function addAddress(): void {
|
function addAddress(): void {
|
||||||
addresses.value.push(emptyAddress())
|
if (canAddAddress.value) addresses.value.push(emptyAddress())
|
||||||
}
|
}
|
||||||
|
|
||||||
function askRemoveAddress(index: number): void {
|
function askRemoveAddress(index: number): void {
|
||||||
@@ -823,7 +845,7 @@ function onAddressDegraded(): void {
|
|||||||
|
|
||||||
/** Valide l'onglet Adresse : DELETE des adresses retirees puis POST/PATCH. */
|
/** Valide l'onglet Adresse : DELETE des adresses retirees puis POST/PATCH. */
|
||||||
async function submitAddresses(): Promise<void> {
|
async function submitAddresses(): Promise<void> {
|
||||||
if (businessReadonly.value || !canValidateAddresses.value || tabSubmitting.value) return
|
if (businessReadonly.value || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
addressErrors.value = []
|
addressErrors.value = []
|
||||||
try {
|
try {
|
||||||
@@ -870,25 +892,35 @@ const selectedPaymentTypeCode = computed(() =>
|
|||||||
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||||
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||||
|
|
||||||
|
// Les blocs RIB ne sont affiches que pour une LCR (RG-1.13).
|
||||||
|
const visibleRibs = computed(() => isRibRequired.value ? ribs.value : [])
|
||||||
|
|
||||||
function onPaymentTypeChange(value: string | number | null): void {
|
function onPaymentTypeChange(value: string | number | null): void {
|
||||||
accounting.paymentTypeIri = value === null ? null : String(value)
|
accounting.paymentTypeIri = value === null ? null : String(value)
|
||||||
if (!isBankRequired.value) accounting.bankIri = null
|
if (!isBankRequired.value) accounting.bankIri = null
|
||||||
|
// Les RIB n'ont de sens que pour une LCR (RG-1.13) : on amorce un bloc vide
|
||||||
|
// quand LCR est choisi, sinon on vide la liste — les RIB deja persistes sont
|
||||||
|
// marques pour suppression serveur au prochain enregistrement.
|
||||||
|
if (isRibRequired.value) {
|
||||||
|
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (const rib of ribs.value) {
|
||||||
|
if (rib.id != null) removedRibIds.value.push(rib.id)
|
||||||
|
}
|
||||||
|
ribs.value = []
|
||||||
|
ribErrors.value = []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ribIsComplete(rib: { label: string | null, bic: string | null, iban: string | null }): boolean {
|
// « + RIB » desactive tant que le dernier bloc RIB n'est pas complet.
|
||||||
const filled = (v: string | null) => v !== null && v.trim() !== ''
|
const canAddRib = computed(() => {
|
||||||
return filled(rib.label) && filled(rib.bic) && filled(rib.iban)
|
const last = ribs.value[ribs.value.length - 1]
|
||||||
}
|
return last !== undefined && isRibComplete(last)
|
||||||
|
|
||||||
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 {
|
function addRib(): void {
|
||||||
ribs.value.push(emptyRib())
|
if (canAddRib.value) ribs.value.push(emptyRib())
|
||||||
}
|
}
|
||||||
|
|
||||||
function askRemoveRib(index: number): void {
|
function askRemoveRib(index: number): void {
|
||||||
@@ -903,35 +935,21 @@ function askRemoveRib(index: number): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valide l'onglet Comptabilite : PATCH des scalaires (groupe client:write:accounting,
|
* Valide l'onglet Comptabilite : POST/PATCH des RIB sur la sous-ressource PUIS
|
||||||
* exige accounting.manage cote back) PUIS DELETE/POST/PATCH des RIB sur la
|
* PATCH des scalaires (groupe client:write:accounting, exige accounting.manage cote
|
||||||
* sous-ressource. Aucun champ main/information dans le payload (mode strict
|
* back) PUIS DELETE des RIB retires. Les RIB crees d'abord : le back valide RG-1.13
|
||||||
* RG-1.28 : sinon 403 sur tout le payload).
|
* (LCR => au moins un RIB persiste) sur le PATCH scalaires ; les suppressions en
|
||||||
|
* dernier (le guard back n'autorise la suppression du dernier RIB qu'une fois quitte
|
||||||
|
* LCR). Aucun champ main/information dans le payload (mode strict RG-1.28 : sinon
|
||||||
|
* 403 sur tout le payload).
|
||||||
*/
|
*/
|
||||||
async function submitAccounting(): Promise<void> {
|
async function submitAccounting(): Promise<void> {
|
||||||
if (accountingReadonly.value || !canValidateAccounting.value || tabSubmitting.value) return
|
if (accountingReadonly.value || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
accountingErrors.clearErrors()
|
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 {
|
||||||
// 1) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
// 1) POST/PATCH des RIB d'abord (erreurs inline par ligne, tous les blocs
|
||||||
try {
|
// tentes). Le back exige >=1 RIB persiste pour valider une LCR a l'etape 2.
|
||||||
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.
|
// Seuls les blocs RIB TOTALEMENT vides sont ignores : un RIB partiel (ex.
|
||||||
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
||||||
const ribHasError = await submitRows(
|
const ribHasError = await submitRows(
|
||||||
@@ -958,6 +976,23 @@ async function submitAccounting(): Promise<void> {
|
|||||||
rib => rib.id === null && isRibBlank(rib),
|
rib => rib.id === null && isRibBlank(rib),
|
||||||
)
|
)
|
||||||
if (ribHasError) return
|
if (ribHasError) return
|
||||||
|
|
||||||
|
// 2) 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3) DELETE des RIB retires : APRES le PATCH scalaires (si on quitte LCR, le
|
||||||
|
// guard back n'autorise la suppression du dernier RIB qu'une fois le type change).
|
||||||
|
for (const id of removedRibIds.value) {
|
||||||
|
await api.delete(`/client_ribs/${id}`, {}, { toast: false })
|
||||||
|
}
|
||||||
|
removedRibIds.value = []
|
||||||
|
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<!-- En-tete : retour repertoire + nom du client + actions (Modifier / Archiver|Restaurer). -->
|
<!-- En-tete : retour repertoire + nom du client + actions (Modifier / Archiver|Restaurer). -->
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3 pt-11">
|
||||||
<MalioButtonIcon
|
<MalioButtonIcon
|
||||||
icon="mdi:arrow-left-bold"
|
icon="mdi:arrow-left-bold"
|
||||||
icon-size="24"
|
icon-size="24"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
v-bind="{ ariaLabel: t('commercial.clients.consultation.back') }"
|
v-bind="{ ariaLabel: t('commercial.clients.consultation.back') }"
|
||||||
@click="goBack"
|
@click="goBack"
|
||||||
/>
|
/>
|
||||||
<h1 class="text-[32px] font-bold text-m-primary">{{ headerTitle }}</h1>
|
<h1 class="text-[30px] font-semibold text-m-primary">{{ headerTitle }}</h1>
|
||||||
|
|
||||||
<!-- gap-12 = 48px : meme espacement que Ajouter / Filtres du repertoire. -->
|
<!-- gap-12 = 48px : meme espacement que Ajouter / Filtres du repertoire. -->
|
||||||
<div class="ml-auto flex items-center gap-12">
|
<div class="ml-auto flex items-center gap-12">
|
||||||
@@ -88,11 +88,14 @@
|
|||||||
<!-- Onglet Information -->
|
<!-- Onglet Information -->
|
||||||
<template #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)]">
|
<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)]">
|
||||||
|
<!-- pt-1/pb-1 alignent le textarea (h-full) en haut ET en bas
|
||||||
|
sur les inputs (champ 40px centre dans un h-12 -> ~4px de
|
||||||
|
coussin de chaque cote). -->
|
||||||
<MalioInputTextArea
|
<MalioInputTextArea
|
||||||
:model-value="information.description"
|
:model-value="information.description"
|
||||||
:label="t('commercial.clients.form.information.description')"
|
:label="t('commercial.clients.form.information.description')"
|
||||||
resize="none"
|
resize="none"
|
||||||
group-class="row-span-2 pt-1"
|
group-class="row-span-2 pt-1 pb-1"
|
||||||
text-input="h-full text-lg"
|
text-input="h-full text-lg"
|
||||||
readonly
|
readonly
|
||||||
/>
|
/>
|
||||||
@@ -278,6 +281,7 @@
|
|||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { useClient } from '~/modules/commercial/composables/useClient'
|
import { useClient } from '~/modules/commercial/composables/useClient'
|
||||||
import { buildClientFormTabKeys } from '~/modules/commercial/utils/clientFormRules'
|
import { buildClientFormTabKeys } from '~/modules/commercial/utils/clientFormRules'
|
||||||
|
import { readHistoryTab } from '~/shared/utils/historyTab'
|
||||||
import {
|
import {
|
||||||
canEditClient,
|
canEditClient,
|
||||||
categoryOptionsOf,
|
categoryOptionsOf,
|
||||||
@@ -293,7 +297,7 @@ import {
|
|||||||
type ClientDetail,
|
type ClientDetail,
|
||||||
type SelectOption,
|
type SelectOption,
|
||||||
} from '~/modules/commercial/utils/clientConsultation'
|
} from '~/modules/commercial/utils/clientConsultation'
|
||||||
import { emptyAddress, emptyContact, emptyRib } from '~/modules/commercial/types/clientForm'
|
import { emptyAddress, emptyContact } from '~/modules/commercial/types/clientForm'
|
||||||
|
|
||||||
// Masque d'affichage (purement visuel, la donnee reste celle du serveur).
|
// Masque d'affichage (purement visuel, la donnee reste celle du serveur).
|
||||||
const SIREN_MASK = '#########'
|
const SIREN_MASK = '#########'
|
||||||
@@ -350,10 +354,10 @@ const addressViews = computed(() => {
|
|||||||
const views = (client.value?.addresses ?? []).map(mapAddressView)
|
const views = (client.value?.addresses ?? []).map(mapAddressView)
|
||||||
return views.length ? views : [{ draft: emptyAddress(), siteOptions: [], categoryOptions: [] }]
|
return views.length ? views : [{ draft: emptyAddress(), siteOptions: [], categoryOptions: [] }]
|
||||||
})
|
})
|
||||||
const ribs = computed(() => {
|
// Exception au placeholder ci-dessus : on n'affiche AUCUN bloc RIB quand le
|
||||||
const list = (client.value?.ribs ?? []).map(mapRibToDraft)
|
// client n'en a pas (un RIB n'existe que pour un reglement LCR — RG-1.13). Pas
|
||||||
return list.length ? list : [emptyRib()]
|
// de bloc vierge fantome en consultation.
|
||||||
})
|
const ribs = computed(() => (client.value?.ribs ?? []).map(mapRibToDraft))
|
||||||
// Draft comptable (tout null si l'utilisateur n'a pas accounting.view).
|
// Draft comptable (tout null si l'utilisateur n'a pas accounting.view).
|
||||||
const accounting = computed(() => mapAccountingDraft(client.value ?? ({} as ClientDetail)))
|
const accounting = computed(() => mapAccountingDraft(client.value ?? ({} as ClientDetail)))
|
||||||
|
|
||||||
@@ -413,15 +417,17 @@ const tabs = computed(() => tabKeys.value.map(key => ({
|
|||||||
icon: TAB_ICONS[key],
|
icon: TAB_ICONS[key],
|
||||||
})))
|
})))
|
||||||
|
|
||||||
const activeTab = ref('information')
|
// Onglet initial : repris de l'edition au retour (history.state), sinon Information.
|
||||||
|
const activeTab = ref(readHistoryTab(tabKeys.value) ?? 'information')
|
||||||
|
|
||||||
// ── Navigation ─────────────────────────────────────────────────────────────
|
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||||
function goBack(): void {
|
function goBack(): void {
|
||||||
router.push('/clients')
|
router.push('/clients')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Bascule en edition en conservant l'onglet courant (via history.state). */
|
||||||
function goEdit(): void {
|
function goEdit(): void {
|
||||||
router.push(`/clients/${clientId}/edit`)
|
router.push({ path: `/clients/${clientId}/edit`, state: { tab: activeTab.value } })
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Archivage / Restauration ────────────────────────────────────────────────
|
// ── Archivage / Restauration ────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -3,18 +3,9 @@
|
|||||||
<PageHeader>
|
<PageHeader>
|
||||||
{{ t('commercial.clients.title') }}
|
{{ t('commercial.clients.title') }}
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<!-- gap-12 = 48px d'espacement entre Ajouter et Filtres. -->
|
<!-- gap-8 = 32px d'espacement entre Filtres et Ajouter. -->
|
||||||
<div class="flex items-center gap-12">
|
<div class="flex items-center gap-8">
|
||||||
<MalioButton
|
<!-- Bouton Filtres a GAUCHE d'Ajouter. Le compteur reflete les filtres actifs. -->
|
||||||
v-if="canManage"
|
|
||||||
variant="secondary"
|
|
||||||
:label="t('commercial.clients.add')"
|
|
||||||
icon-name="mdi:add-bold"
|
|
||||||
icon-position="left"
|
|
||||||
@click="goToCreate"
|
|
||||||
/>
|
|
||||||
<!-- Bouton Filtres a DROITE d'Ajouter : meme design que
|
|
||||||
l'audit-log. Le compteur reflete les filtres actifs. -->
|
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-if="canView"
|
v-if="canView"
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
@@ -22,9 +13,16 @@
|
|||||||
icon-name="mdi:tune"
|
icon-name="mdi:tune"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
icon-size="24"
|
icon-size="24"
|
||||||
button-class="w-[184px] justify-start gap-4 text-black"
|
|
||||||
@click="openFilters"
|
@click="openFilters"
|
||||||
/>
|
/>
|
||||||
|
<MalioButton
|
||||||
|
v-if="canManage"
|
||||||
|
variant="secondary"
|
||||||
|
:label="t('commercial.clients.add')"
|
||||||
|
icon-name="mdi:add-bold"
|
||||||
|
icon-position="left"
|
||||||
|
@click="goToCreate"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
@@ -39,7 +37,7 @@
|
|||||||
:per-page="itemsPerPage"
|
:per-page="itemsPerPage"
|
||||||
:per-page-options="itemsPerPageOptions"
|
:per-page-options="itemsPerPageOptions"
|
||||||
row-clickable
|
row-clickable
|
||||||
table-class="table-fixed"
|
table-class="table-fixed clients-table"
|
||||||
:empty-message="t('commercial.clients.empty')"
|
:empty-message="t('commercial.clients.empty')"
|
||||||
@row-click="onRowClick"
|
@row-click="onRowClick"
|
||||||
@update:page="goToPage"
|
@update:page="goToPage"
|
||||||
@@ -56,7 +54,7 @@
|
|||||||
<span
|
<span
|
||||||
v-for="site in (item.sites as ClientSite[])"
|
v-for="site in (item.sites as ClientSite[])"
|
||||||
:key="site.id"
|
:key="site.id"
|
||||||
class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium text-white"
|
class="inline-flex items-center rounded-full px-2 py-0.5 font-medium text-white"
|
||||||
:style="{ backgroundColor: site.color }"
|
:style="{ backgroundColor: site.color }"
|
||||||
>
|
>
|
||||||
{{ site.name }}
|
{{ site.name }}
|
||||||
@@ -70,7 +68,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</MalioDataTable>
|
</MalioDataTable>
|
||||||
|
|
||||||
<div class="flex justify-center mt-6">
|
<div class="flex justify-center mt-4">
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-if="canView"
|
v-if="canView"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
@@ -350,7 +348,9 @@ async function loadFilterOptions(): Promise<void> {
|
|||||||
const [cats, sites] = await Promise.all([
|
const [cats, sites] = await Promise.all([
|
||||||
api.get<{ member?: Array<{ code: string, name: string }> }>(
|
api.get<{ member?: Array<{ code: string, name: string }> }>(
|
||||||
'/categories',
|
'/categories',
|
||||||
{ pagination: 'false' },
|
// Taxonomie multi-types (ERP-84) : le filtre du repertoire client ne
|
||||||
|
// propose que les categories de type CLIENT (pas les FOURNISSEUR).
|
||||||
|
{ pagination: 'false', typeCode: 'CLIENT' },
|
||||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
),
|
),
|
||||||
api.get<{ member?: Array<{ id: number, name: string }> }>(
|
api.get<{ member?: Array<{ id: number, name: string }> }>(
|
||||||
@@ -419,3 +419,16 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
/*
|
||||||
|
* Colonne Sites uniquement (3e colonne : companyName, categories, SITES,
|
||||||
|
* lastActivity) : ses badges rendent la cellule trop haute. On reduit le padding
|
||||||
|
* vertical de SON td (16px Malio -> 8px) sans toucher les autres colonnes ni les
|
||||||
|
* couleurs/tailles (qui restent sur les defauts Malio).
|
||||||
|
*/
|
||||||
|
:deep(.clients-table tbody td:nth-child(3)) {
|
||||||
|
padding-top: 8px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<!-- En-tete : retour vers le repertoire + titre. -->
|
<!-- En-tete : retour vers le repertoire + titre. -->
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3 pt-11">
|
||||||
<MalioButtonIcon
|
<MalioButtonIcon
|
||||||
icon="mdi:arrow-left-bold"
|
icon="mdi:arrow-left-bold"
|
||||||
icon-size="24"
|
icon-size="24"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
v-bind="{ ariaLabel: t('commercial.clients.form.back') }"
|
v-bind="{ ariaLabel: t('commercial.clients.form.back') }"
|
||||||
@click="goBack"
|
@click="goBack"
|
||||||
/>
|
/>
|
||||||
<h1 class="text-[32px] font-bold text-m-primary">{{ t('commercial.clients.form.title') }}</h1>
|
<h1 class="text-[30px] font-semibold text-m-primary">{{ t('commercial.clients.form.title') }}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ── Formulaire principal (pre-onglets) ─────────────────────────────
|
<!-- ── Formulaire principal (pre-onglets) ─────────────────────────────
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
|
v-if="showRelationAndTriage"
|
||||||
: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')"
|
||||||
@@ -43,7 +44,7 @@
|
|||||||
@update:model-value="onRelationChange"
|
@update:model-value="onRelationChange"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
<MalioSelect
|
||||||
v-if="main.relationType === 'courtier'"
|
v-if="showRelationAndTriage && main.relationType === 'courtier'"
|
||||||
: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')"
|
||||||
@@ -53,7 +54,7 @@
|
|||||||
@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
|
||||||
v-if="main.relationType === 'distributeur'"
|
v-if="showRelationAndTriage && main.relationType === 'distributeur'"
|
||||||
: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')"
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
@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
|
||||||
|
v-if="showRelationAndTriage"
|
||||||
v-model="main.triageService"
|
v-model="main.triageService"
|
||||||
:label="t('commercial.clients.form.main.triageService')"
|
:label="t('commercial.clients.form.main.triageService')"
|
||||||
group-class="self-center"
|
group-class="self-center"
|
||||||
@@ -74,7 +76,7 @@
|
|||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.form.submit')"
|
:label="t('commercial.clients.form.submit')"
|
||||||
:disabled="!isMainValid || mainSubmitting"
|
:disabled="mainSubmitting"
|
||||||
@click="submitMain"
|
@click="submitMain"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -84,13 +86,15 @@
|
|||||||
<!-- Onglet Information -->
|
<!-- Onglet Information -->
|
||||||
<template #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)]">
|
<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)]">
|
||||||
<!-- pt-1 : aligne le bord superieur du textarea sur celui des
|
<!-- pt-1/pb-1 alignent le textarea (h-full) sur les inputs, dont
|
||||||
inputs (centres dans un conteneur h-12, soit ~4px de retrait haut). -->
|
le champ de 40px est centre dans un conteneur h-12 (~4px de
|
||||||
|
coussin en HAUT et en BAS). Sans pb-1, le textarea descend ~4px
|
||||||
|
plus bas que les champs voisins. -->
|
||||||
<MalioInputTextArea
|
<MalioInputTextArea
|
||||||
v-model="information.description"
|
v-model="information.description"
|
||||||
:label="t('commercial.clients.form.information.description')"
|
:label="t('commercial.clients.form.information.description')"
|
||||||
resize="none"
|
resize="none"
|
||||||
group-class="row-span-2 pt-1"
|
group-class="row-span-2 pt-1 pb-1"
|
||||||
text-input="h-full text-lg"
|
text-input="h-full text-lg"
|
||||||
:readonly="isValidated('information')"
|
:readonly="isValidated('information')"
|
||||||
:error="informationErrors.errors.description"
|
:error="informationErrors.errors.description"
|
||||||
@@ -105,6 +109,7 @@
|
|||||||
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')"
|
||||||
|
:editable="true"
|
||||||
:error="informationErrors.errors.foundedAt"
|
:error="informationErrors.errors.foundedAt"
|
||||||
/>
|
/>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
@@ -134,9 +139,10 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!isValidated('information')" class="mt-12 flex justify-center">
|
<div v-if="!isValidated('information')" class="mt-12 flex justify-center">
|
||||||
<!-- Desactive tant que le client n'est pas cree : evite un PATCH
|
<!-- Desactive tant que le client n'est pas cree (evite un PATCH
|
||||||
avant le POST si l'utilisateur clique trop tot (le panneau
|
avant le POST si clic trop tot, Information etant l'onglet
|
||||||
Information est l'onglet actif par defaut). -->
|
actif par defaut). Onglet facultatif : un enregistrement a
|
||||||
|
vide reste possible, c'est le back qui valide. -->
|
||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.form.submit')"
|
:label="t('commercial.clients.form.submit')"
|
||||||
@@ -172,7 +178,7 @@
|
|||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.form.submit')"
|
:label="t('commercial.clients.form.submit')"
|
||||||
:disabled="!canValidateContacts || tabSubmitting"
|
:disabled="tabSubmitting"
|
||||||
@click="submitContacts"
|
@click="submitContacts"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -204,12 +210,13 @@
|
|||||||
icon-name="mdi:add-bold"
|
icon-name="mdi:add-bold"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
:label="t('commercial.clients.form.address.add')"
|
:label="t('commercial.clients.form.address.add')"
|
||||||
|
:disabled="!canAddAddress"
|
||||||
@click="addAddress"
|
@click="addAddress"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.form.submit')"
|
:label="t('commercial.clients.form.submit')"
|
||||||
:disabled="!canValidateAddresses || tabSubmitting"
|
:disabled="tabSubmitting"
|
||||||
@click="submitAddresses"
|
@click="submitAddresses"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -287,9 +294,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Blocs RIB (0..n) — obligatoires si type de reglement = LCR. -->
|
<!-- Blocs RIB — affiches uniquement si type de reglement = LCR (RG-1.13). -->
|
||||||
<div
|
<div
|
||||||
v-for="(rib, index) in ribs"
|
v-for="(rib, index) in visibleRibs"
|
||||||
:key="index"
|
:key="index"
|
||||||
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||||
>
|
>
|
||||||
@@ -329,16 +336,18 @@
|
|||||||
|
|
||||||
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
||||||
<MalioButton
|
<MalioButton
|
||||||
|
v-if="isRibRequired"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
icon-name="mdi:add-bold"
|
icon-name="mdi:add-bold"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
:label="t('commercial.clients.form.accounting.addRib')"
|
:label="t('commercial.clients.form.accounting.addRib')"
|
||||||
|
:disabled="!canAddRib"
|
||||||
@click="addRib"
|
@click="addRib"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:label="t('commercial.clients.form.submit')"
|
:label="t('commercial.clients.form.submit')"
|
||||||
:disabled="!canValidateAccounting || tabSubmitting"
|
:disabled="tabSubmitting"
|
||||||
@click="submitAccounting"
|
@click="submitAccounting"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -380,18 +389,24 @@ 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 { useClientFormErrors } from '~/modules/commercial/composables/useClientFormErrors'
|
||||||
import {
|
import {
|
||||||
addressTypeFromFlags,
|
|
||||||
buildClientFormTabKeys,
|
buildClientFormTabKeys,
|
||||||
CLIENT_FORM_PLACEHOLDER_TABS,
|
CLIENT_FORM_PLACEHOLDER_TABS,
|
||||||
hasAllRequiredAccountingFields,
|
isAddressValid,
|
||||||
hasAtLeastOneValidContact,
|
|
||||||
isBankRequiredForPaymentType,
|
isBankRequiredForPaymentType,
|
||||||
isBillingEmailRequired,
|
isBillingEmailRequired,
|
||||||
isContactBlank,
|
isContactBlank,
|
||||||
isContactNamed,
|
isContactNamed,
|
||||||
isRibBlank,
|
isRibBlank,
|
||||||
|
isRibComplete,
|
||||||
isRibRequiredForPaymentType,
|
isRibRequiredForPaymentType,
|
||||||
|
lastFillableTabKey,
|
||||||
|
showsRelationAndTriageFields,
|
||||||
} from '~/modules/commercial/utils/clientFormRules'
|
} from '~/modules/commercial/utils/clientFormRules'
|
||||||
|
import {
|
||||||
|
buildAddressPayload,
|
||||||
|
buildMainPayload,
|
||||||
|
buildRibPayload,
|
||||||
|
} from '~/modules/commercial/utils/clientEdit'
|
||||||
import {
|
import {
|
||||||
emptyAddress,
|
emptyAddress,
|
||||||
emptyContact,
|
emptyContact,
|
||||||
@@ -483,23 +498,26 @@ const relationOptions = computed<RefOption[]>(() => [
|
|||||||
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||||
])
|
])
|
||||||
|
|
||||||
// Validation du formulaire principal (gate le bouton « Valider ») :
|
// Codes des categories selectionnees (resolus depuis les IRI du brouillon).
|
||||||
// - companyName / >= 1 categorie obligatoires ;
|
const selectedCategoryCodes = computed(() =>
|
||||||
// - relation Distributeur/Courtier optionnelle, mais le nom correspondant
|
main.categoryIris
|
||||||
// devient requis si l'un des deux est choisi (spec fonctionnelle).
|
.map(iri => referentials.categories.value.find(c => c.value === iri)?.code)
|
||||||
// Les coordonnees de contact ne sont plus saisies ici : elles vivent dans
|
.filter((code): code is string => code !== undefined),
|
||||||
// l'onglet Contacts (RG-1.05/1.14 garantissent >= 1 contact valide).
|
)
|
||||||
const isMainValid = computed(() => {
|
|
||||||
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
// « Relation » + « Prestation de triage » masques par defaut, reveles des qu'une
|
||||||
// Relation Distributeur/Courtier OPTIONNELLE ; mais si « Depend du
|
// categorie ordinaire (autre que Distributeur/Courtier) est selectionnee.
|
||||||
// distributeur/courtier » est choisi, le nom correspondant devient requis.
|
const showRelationAndTriage = computed(() => showsRelationAndTriageFields(selectedCategoryCodes.value))
|
||||||
const relationValid
|
|
||||||
= main.relationType === null
|
// Masquer ces champs reinitialise leurs valeurs : pas de relation/triage fantome
|
||||||
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
// soumis pour un client Distributeur/Courtier.
|
||||||
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
watch(showRelationAndTriage, (visible) => {
|
||||||
return filled(main.companyName)
|
if (!visible) {
|
||||||
&& main.categoryIris.length >= 1
|
main.relationType = null
|
||||||
&& relationValid
|
main.distributorIri = null
|
||||||
|
main.brokerIri = null
|
||||||
|
main.triageService = false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function onRelationChange(value: string | number | null): Promise<void> {
|
async function onRelationChange(value: string | number | null): Promise<void> {
|
||||||
@@ -517,18 +535,13 @@ async function onRelationChange(value: string | number | null): Promise<void> {
|
|||||||
|
|
||||||
/** POST /clients (groupe client:write:main). Au succes : verrouille + bascule Information. */
|
/** POST /clients (groupe client:write:main). Au succes : verrouille + bascule Information. */
|
||||||
async function submitMain(): Promise<void> {
|
async function submitMain(): Promise<void> {
|
||||||
if (!isMainValid.value || mainSubmitting.value) return
|
if (mainSubmitting.value) return
|
||||||
mainSubmitting.value = true
|
mainSubmitting.value = true
|
||||||
mainErrors.clearErrors()
|
mainErrors.clearErrors()
|
||||||
try {
|
try {
|
||||||
const payload: Record<string, unknown> = {
|
// Payload partage avec l'edition (buildMainPayload) : meme logique
|
||||||
companyName: main.companyName,
|
// d'omission des requis vides et meme envoi de relationType (ERP-119).
|
||||||
categories: main.categoryIris,
|
const created = await api.post<ClientResponse>('/clients', buildMainPayload(main), {
|
||||||
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
|
||||||
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
|
||||||
triageService: main.triageService,
|
|
||||||
}
|
|
||||||
const created = await api.post<ClientResponse>('/clients', payload, {
|
|
||||||
headers: { Accept: 'application/ld+json' },
|
headers: { Accept: 'application/ld+json' },
|
||||||
toast: false,
|
toast: false,
|
||||||
})
|
})
|
||||||
@@ -538,7 +551,9 @@ async function submitMain(): Promise<void> {
|
|||||||
main.companyName = created.companyName ?? main.companyName
|
main.companyName = created.companyName ?? main.companyName
|
||||||
|
|
||||||
mainLocked.value = true
|
mainLocked.value = true
|
||||||
unlockedIndex.value = 0
|
// Information est facultatif : on deverrouille jusqu'a Contact (index 1)
|
||||||
|
// pour que l'utilisateur puisse y aller directement sans valider Information.
|
||||||
|
unlockedIndex.value = tabIndex('contact')
|
||||||
activeTab.value = 'information'
|
activeTab.value = 'information'
|
||||||
toast.success({ title: t('commercial.clients.toast.createSuccess') })
|
toast.success({ title: t('commercial.clients.toast.createSuccess') })
|
||||||
}
|
}
|
||||||
@@ -570,6 +585,12 @@ const validated = reactive<Record<string, boolean>>({})
|
|||||||
|
|
||||||
const tabKeys = computed(() => buildClientFormTabKeys(canAccountingView.value))
|
const tabKeys = computed(() => buildClientFormTabKeys(canAccountingView.value))
|
||||||
|
|
||||||
|
// Dernier onglet REMPLISSABLE par le role (cf. lastFillableTabKey) : deja role-aware
|
||||||
|
// via tabKeys (accounting present ssi accounting.view, et a la creation « present » =
|
||||||
|
// « editable » : aucun role createur n'a la Compta en lecture seule). Sa validation
|
||||||
|
// cloture l'ajout -> redirection vers la liste.
|
||||||
|
const lastFillableTab = computed(() => lastFillableTabKey(tabKeys.value))
|
||||||
|
|
||||||
// Icone (Iconify) affichee dans l'onglet, par cle. A ajuster librement.
|
// Icone (Iconify) affichee dans l'onglet, par cle. A ajuster librement.
|
||||||
const TAB_ICONS: Record<string, string> = {
|
const TAB_ICONS: Record<string, string> = {
|
||||||
information: 'mdi:account-outline',
|
information: 'mdi:account-outline',
|
||||||
@@ -597,12 +618,23 @@ function tabIndex(key: string): number {
|
|||||||
return tabKeys.value.indexOf(key)
|
return tabKeys.value.indexOf(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Marque l'onglet valide, deverrouille et avance automatiquement au suivant. */
|
/**
|
||||||
function completeTab(key: string): void {
|
* Marque l'onglet valide. Si c'est le dernier onglet remplissable, l'ajout est
|
||||||
|
* termine : toast final + redirection vers la liste, et on retourne true pour que
|
||||||
|
* l'appelant n'affiche pas son toast « mis a jour ». Sinon, deverrouille et avance
|
||||||
|
* a l'onglet suivant, et retourne false.
|
||||||
|
*/
|
||||||
|
function completeTab(key: string): boolean {
|
||||||
validated[key] = true
|
validated[key] = true
|
||||||
|
if (key === lastFillableTab.value) {
|
||||||
|
toast.success({ title: t('commercial.clients.toast.addComplete') })
|
||||||
|
router.push('/clients')
|
||||||
|
return true
|
||||||
|
}
|
||||||
const next = tabKeys.value[tabIndex(key) + 1]
|
const next = tabKeys.value[tabIndex(key) + 1]
|
||||||
unlockedIndex.value = Math.max(unlockedIndex.value, tabIndex(key) + 1)
|
unlockedIndex.value = Math.max(unlockedIndex.value, tabIndex(key) + 1)
|
||||||
if (next) activeTab.value = next
|
if (next) activeTab.value = next
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passage automatique sur les onglets coquille (Transport, Stats, Rapports, Echanges).
|
// Passage automatique sur les onglets coquille (Transport, Stats, Rapports, Echanges).
|
||||||
@@ -640,7 +672,7 @@ async function submitInformation(): Promise<void> {
|
|||||||
profitAmount: information.profitAmount || null,
|
profitAmount: information.profitAmount || null,
|
||||||
directorName: information.directorName || null,
|
directorName: information.directorName || null,
|
||||||
}, { toast: false })
|
}, { toast: false })
|
||||||
completeTab('information')
|
if (completeTab('information')) return
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@@ -662,9 +694,6 @@ const canAddContact = computed(() => {
|
|||||||
return last !== undefined && isContactNamed(last)
|
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 {
|
function addContact(): void {
|
||||||
if (canAddContact.value) contacts.value.push(emptyContact())
|
if (canAddContact.value) contacts.value.push(emptyContact())
|
||||||
}
|
}
|
||||||
@@ -678,9 +707,14 @@ function askRemoveContact(index: number): void {
|
|||||||
|
|
||||||
/** POST/PATCH des contacts sur la sous-ressource /clients/{id}/contacts. */
|
/** POST/PATCH des contacts sur la sous-ressource /clients/{id}/contacts. */
|
||||||
async function submitContacts(): Promise<void> {
|
async function submitContacts(): Promise<void> {
|
||||||
if (clientId.value === null || !canValidateContacts.value || tabSubmitting.value) return
|
if (clientId.value === null || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
try {
|
try {
|
||||||
|
// RG-1.14 : au moins un contact requis. Si l'onglet ne contient QUE des
|
||||||
|
// amorces neuves vides, on ne les skippe pas -> le bloc vide est POSTe et
|
||||||
|
// le back renvoie la 422 RG-1.05 « prénom ou nom obligatoire » inline (la
|
||||||
|
// RG-1.14 n'a pas d'equivalent back au POST, on la materialise via RG-1.05).
|
||||||
|
const hasSubmittableContact = contacts.value.some(c => c.id !== null || !isContactBlank(c))
|
||||||
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
||||||
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
||||||
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
||||||
@@ -710,14 +744,14 @@ async function submitContacts(): Promise<void> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
// On ne saute une amorce neuve (id null) totalement vide QUE si un autre
|
||||||
// bloc existant vide est soumis -> 422 RG-1.05 inline (sinon la modif
|
// bloc sera soumis : sinon on la soumet pour declencher la 422 RG-1.05
|
||||||
// serait perdue en silence avec un faux toast de succes).
|
// (un onglet Contact vide ne doit pas passer en faux succes).
|
||||||
contact => contact.id === null && isContactBlank(contact),
|
contact => hasSubmittableContact && contact.id === null && isContactBlank(contact),
|
||||||
)
|
)
|
||||||
// Tant qu'un bloc reste en erreur : pas de validation d'onglet ni de toast succes.
|
// Tant qu'un bloc reste en erreur : pas de validation d'onglet ni de toast succes.
|
||||||
if (hasError) return
|
if (hasError) return
|
||||||
completeTab('contact')
|
if (completeTab('contact')) return
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -750,21 +784,14 @@ const countryOptions: RefOption[] = [
|
|||||||
{ value: 'Espagne', label: 'Espagne' },
|
{ value: 'Espagne', label: 'Espagne' },
|
||||||
]
|
]
|
||||||
|
|
||||||
// Type d'adresse (Select) obligatoire + RG-1.10 (>= 1 site) + RG-1.11 (email
|
// « + Adresse » desactive tant que la derniere adresse n'est pas valide.
|
||||||
// facturation si Facturation) sur chaque adresse.
|
const canAddAddress = computed(() => {
|
||||||
const canValidateAddresses = computed(() =>
|
const last = addresses.value[addresses.value.length - 1]
|
||||||
addresses.value.length > 0
|
return last !== undefined && isAddressValid(last)
|
||||||
&& 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 {
|
function addAddress(): void {
|
||||||
addresses.value.push(emptyAddress())
|
if (canAddAddress.value) addresses.value.push(emptyAddress())
|
||||||
}
|
}
|
||||||
|
|
||||||
function askRemoveAddress(index: number): void {
|
function askRemoveAddress(index: number): void {
|
||||||
@@ -786,7 +813,7 @@ function onAddressDegraded(): void {
|
|||||||
|
|
||||||
/** POST des adresses sur la sous-ressource /clients/{id}/addresses. */
|
/** POST des adresses sur la sous-ressource /clients/{id}/addresses. */
|
||||||
async function submitAddresses(): Promise<void> {
|
async function submitAddresses(): Promise<void> {
|
||||||
if (clientId.value === null || !canValidateAddresses.value || tabSubmitting.value) return
|
if (clientId.value === null || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
try {
|
try {
|
||||||
// On tente TOUS les blocs d'adresse (collecte des erreurs par index, ERP-110).
|
// On tente TOUS les blocs d'adresse (collecte des erreurs par index, ERP-110).
|
||||||
@@ -794,20 +821,8 @@ async function submitAddresses(): Promise<void> {
|
|||||||
addresses.value,
|
addresses.value,
|
||||||
addressErrors,
|
addressErrors,
|
||||||
async (address) => {
|
async (address) => {
|
||||||
const body = {
|
// Payload partage avec l'edition (buildAddressPayload, ERP-119).
|
||||||
isProspect: address.isProspect,
|
const body = buildAddressPayload(address, isBillingEmailRequired(address))
|
||||||
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) {
|
if (address.id === null) {
|
||||||
const created = await api.post<{ id: number }>(
|
const created = await api.post<{ id: number }>(
|
||||||
`/clients/${clientId.value}/addresses`,
|
`/clients/${clientId.value}/addresses`,
|
||||||
@@ -823,7 +838,7 @@ async function submitAddresses(): Promise<void> {
|
|||||||
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||||
)
|
)
|
||||||
if (hasError) return
|
if (hasError) return
|
||||||
completeTab('address')
|
if (completeTab('address')) return
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -853,29 +868,32 @@ const selectedPaymentTypeCode = computed(() =>
|
|||||||
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||||
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||||
|
|
||||||
|
// Les blocs RIB ne sont affiches que pour une LCR (RG-1.13).
|
||||||
|
const visibleRibs = computed(() => isRibRequired.value ? ribs.value : [])
|
||||||
|
|
||||||
function onPaymentTypeChange(value: string | number | null): void {
|
function onPaymentTypeChange(value: string | number | null): void {
|
||||||
accounting.paymentTypeIri = value === null ? null : String(value)
|
accounting.paymentTypeIri = value === null ? null : String(value)
|
||||||
// La banque n'a de sens que pour un virement : on la vide sinon (RG-1.12).
|
// La banque n'a de sens que pour un virement : on la vide sinon (RG-1.12).
|
||||||
if (!isBankRequired.value) accounting.bankIri = null
|
if (!isBankRequired.value) accounting.bankIri = null
|
||||||
|
// Les RIB n'ont de sens que pour une LCR (RG-1.13) : on amorce un bloc vide
|
||||||
|
// quand LCR est choisi, on vide la liste sinon (pas de RIB fantome soumis).
|
||||||
|
if (isRibRequired.value) {
|
||||||
|
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ribs.value = []
|
||||||
|
ribErrors.value = []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ribIsComplete(rib: RibFormDraft): boolean {
|
// « + RIB » desactive tant que le dernier bloc RIB n'est pas complet.
|
||||||
const filled = (v: string | null) => v !== null && v.trim() !== ''
|
const canAddRib = computed(() => {
|
||||||
return filled(rib.label) && filled(rib.bic) && filled(rib.iban)
|
const last = ribs.value[ribs.value.length - 1]
|
||||||
}
|
return last !== undefined && isRibComplete(last)
|
||||||
|
|
||||||
// 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.
|
|
||||||
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 {
|
function addRib(): void {
|
||||||
ribs.value.push(emptyRib())
|
if (canAddRib.value) ribs.value.push(emptyRib())
|
||||||
}
|
}
|
||||||
|
|
||||||
function askRemoveRib(index: number): void {
|
function askRemoveRib(index: number): void {
|
||||||
@@ -888,44 +906,28 @@ function askRemoveRib(index: number): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valide l'onglet Comptabilite : PATCH des scalaires (groupe client:write:accounting)
|
* Valide l'onglet Comptabilite : POST/PATCH des RIB sur /clients/{id}/ribs PUIS
|
||||||
* PUIS POST des RIB sur /clients/{id}/ribs. Deux appels distincts (mode strict
|
* PATCH des scalaires (groupe client:write:accounting). Les RIB d'abord : le back
|
||||||
* RG-1.28 : il n'existe pas d'endpoint /accounting, cf. recon back).
|
* valide RG-1.13 (LCR => au moins un RIB persiste) sur le PATCH scalaires, les RIB
|
||||||
|
* doivent donc exister en base AVANT (sinon 422 « Au moins un RIB est obligatoire
|
||||||
|
* pour le type de reglement LCR »). Deux appels distincts (mode strict RG-1.28 :
|
||||||
|
* il n'existe pas d'endpoint /accounting, cf. recon back).
|
||||||
*/
|
*/
|
||||||
async function submitAccounting(): Promise<void> {
|
async function submitAccounting(): Promise<void> {
|
||||||
if (clientId.value === null || !canValidateAccounting.value || tabSubmitting.value) return
|
if (clientId.value === null || tabSubmitting.value) return
|
||||||
tabSubmitting.value = true
|
tabSubmitting.value = true
|
||||||
accountingErrors.clearErrors()
|
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 {
|
||||||
// 1) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
// 1) POST/PATCH des RIB d'abord (erreurs inline par ligne, tous les blocs
|
||||||
try {
|
// tentes). Le back exige >=1 RIB persiste pour valider une LCR a l'etape 2.
|
||||||
await api.patch(`/clients/${clientId.value}`, {
|
|
||||||
siren: accounting.siren || null,
|
|
||||||
accountNumber: accounting.accountNumber || null,
|
|
||||||
tvaMode: accounting.tvaModeIri,
|
|
||||||
nTva: accounting.nTva || null,
|
|
||||||
paymentDelay: accounting.paymentDelayIri,
|
|
||||||
paymentType: accounting.paymentTypeIri,
|
|
||||||
bank: isBankRequired.value ? accounting.bankIri : null,
|
|
||||||
}, { 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.
|
// Seuls les blocs RIB TOTALEMENT vides sont ignores : un RIB partiel (ex.
|
||||||
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
||||||
const ribHasError = await submitRows(
|
const ribHasError = await submitRows(
|
||||||
ribs.value,
|
ribs.value,
|
||||||
ribErrors,
|
ribErrors,
|
||||||
async (rib) => {
|
async (rib) => {
|
||||||
const body = { label: rib.label, bic: rib.bic, iban: rib.iban }
|
// Payload partage avec l'edition (buildRibPayload, ERP-119).
|
||||||
|
const body = buildRibPayload(rib)
|
||||||
if (rib.id === null) {
|
if (rib.id === null) {
|
||||||
const created = await api.post<{ id: number }>(
|
const created = await api.post<{ id: number }>(
|
||||||
`/clients/${clientId.value}/ribs`,
|
`/clients/${clientId.value}/ribs`,
|
||||||
@@ -946,7 +948,24 @@ async function submitAccounting(): Promise<void> {
|
|||||||
)
|
)
|
||||||
if (ribHasError) return
|
if (ribHasError) return
|
||||||
|
|
||||||
completeTab('accounting')
|
// 2) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||||
|
try {
|
||||||
|
await api.patch(`/clients/${clientId.value}`, {
|
||||||
|
siren: accounting.siren || null,
|
||||||
|
accountNumber: accounting.accountNumber || null,
|
||||||
|
tvaMode: accounting.tvaModeIri,
|
||||||
|
nTva: accounting.nTva || null,
|
||||||
|
paymentDelay: accounting.paymentDelayIri,
|
||||||
|
paymentType: accounting.paymentTypeIri,
|
||||||
|
bank: isBankRequired.value ? accounting.bankIri : null,
|
||||||
|
}, { toast: false })
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
accountingErrors.handleApiError(error, { fallbackMessage: t('commercial.clients.toast.error') })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completeTab('accounting')) return
|
||||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -987,8 +1006,7 @@ 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
|
// Pas d'amorce de RIB ici : un bloc vide n'apparait que si LCR est choisi
|
||||||
// (non persiste tant qu'incomplet — RG-1.13).
|
// (cf. onPaymentTypeChange).
|
||||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ export interface AddressFormDraft {
|
|||||||
isProspect: boolean
|
isProspect: boolean
|
||||||
isDelivery: boolean
|
isDelivery: boolean
|
||||||
isBilling: boolean
|
isBilling: boolean
|
||||||
|
/** Adresse Courtier — type autonome exclusif. */
|
||||||
|
isBroker: boolean
|
||||||
|
/** Adresse Distributeur — type autonome exclusif. */
|
||||||
|
isDistributor: boolean
|
||||||
country: string
|
country: string
|
||||||
postalCode: string | null
|
postalCode: string | null
|
||||||
city: string | null
|
city: string | null
|
||||||
@@ -43,6 +47,10 @@ export interface AddressFormDraft {
|
|||||||
contactIris: string[]
|
contactIris: string[]
|
||||||
/** Email de facturation (obligatoire si isBilling — RG-1.11). */
|
/** Email de facturation (obligatoire si isBilling — RG-1.11). */
|
||||||
billingEmail: string | null
|
billingEmail: string | null
|
||||||
|
/** 2e email de facturation, optionnel (max 2 — pendant du telephone secondaire). */
|
||||||
|
billingEmailSecondary: string | null
|
||||||
|
/** Drapeau UI : 2e champ email revele (comme hasSecondaryPhone). */
|
||||||
|
hasSecondaryBillingEmail: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Un RIB du client (onglet Comptabilite). */
|
/** Un RIB du client (onglet Comptabilite). */
|
||||||
@@ -75,6 +83,8 @@ export function emptyAddress(): AddressFormDraft {
|
|||||||
isProspect: false,
|
isProspect: false,
|
||||||
isDelivery: false,
|
isDelivery: false,
|
||||||
isBilling: false,
|
isBilling: false,
|
||||||
|
isBroker: false,
|
||||||
|
isDistributor: false,
|
||||||
country: 'France',
|
country: 'France',
|
||||||
postalCode: null,
|
postalCode: null,
|
||||||
city: null,
|
city: null,
|
||||||
@@ -84,6 +94,8 @@ export function emptyAddress(): AddressFormDraft {
|
|||||||
siteIris: [],
|
siteIris: [],
|
||||||
contactIris: [],
|
contactIris: [],
|
||||||
billingEmail: null,
|
billingEmail: null,
|
||||||
|
billingEmailSecondary: null,
|
||||||
|
hasSecondaryBillingEmail: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ function accountingDraft(overrides: Partial<AccountingFormDraft> = {}): Accounti
|
|||||||
// Le contact inline (nom/prenom/telephones/email) ne fait plus partie du groupe
|
// Le contact inline (nom/prenom/telephones/email) ne fait plus partie du groupe
|
||||||
// main : les coordonnees vivent desormais sur la sous-ressource ClientContact.
|
// main : les coordonnees vivent desormais sur la sous-ressource ClientContact.
|
||||||
const MAIN_KEYS = [
|
const MAIN_KEYS = [
|
||||||
'companyName', 'categories', 'distributor', 'broker', 'triageService',
|
// relationType : champ transitoire envoye au back pour la validation croisee
|
||||||
|
// « relation choisie => FK obligatoire » (RG-1.03 bis, ERP-119).
|
||||||
|
'companyName', 'categories', 'relationType', 'distributor', 'broker', 'triageService',
|
||||||
]
|
]
|
||||||
const INFORMATION_KEYS = [
|
const INFORMATION_KEYS = [
|
||||||
'description', 'competitors', 'foundedAt', 'employeesCount',
|
'description', 'competitors', 'foundedAt', 'employeesCount',
|
||||||
@@ -99,6 +101,27 @@ describe('buildMainPayload — scoping strict groupe client:write:main', () => {
|
|||||||
expect(payload.distributor).toBeNull()
|
expect(payload.distributor).toBeNull()
|
||||||
expect(payload.broker).toBeNull()
|
expect(payload.broker).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('transmet relationType au back pour la validation croisee (RG-1.03 bis)', () => {
|
||||||
|
expect(buildMainPayload(mainDraft({ relationType: 'distributeur' })).relationType).toBe('distributeur')
|
||||||
|
expect(buildMainPayload(mainDraft({ relationType: 'courtier' })).relationType).toBe('courtier')
|
||||||
|
expect(buildMainPayload(mainDraft({ relationType: null })).relationType).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
// ERP-119 : companyName est requis ET adosse a une colonne NON-nullable. Si le
|
||||||
|
// champ est vide, on OMET la cle (au lieu d'envoyer null) pour que le back
|
||||||
|
// renvoie une 422 NotBlank (propertyPath companyName) et non un 400 de type.
|
||||||
|
it('omet companyName quand il est vide (null) -> 422 NotBlank cote back', () => {
|
||||||
|
expect('companyName' in buildMainPayload(mainDraft({ companyName: null }))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('omet companyName quand il est une chaine vide', () => {
|
||||||
|
expect('companyName' in buildMainPayload(mainDraft({ companyName: '' }))).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('conserve companyName quand il est renseigne', () => {
|
||||||
|
expect(buildMainPayload(mainDraft({ companyName: 'ACME' })).companyName).toBe('ACME')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('buildInformationPayload — scoping strict groupe client:write:information', () => {
|
describe('buildInformationPayload — scoping strict groupe client:write:information', () => {
|
||||||
@@ -142,19 +165,50 @@ describe('buildContactPayload / buildAddressPayload / buildRibPayload', () => {
|
|||||||
|
|
||||||
it('adresse : email facturation conserve uniquement si requis (RG-1.11)', () => {
|
it('adresse : email facturation conserve uniquement si requis (RG-1.11)', () => {
|
||||||
const address: AddressFormDraft = {
|
const address: AddressFormDraft = {
|
||||||
id: 3, isProspect: false, isDelivery: false, isBilling: true, country: 'France',
|
id: 3, isProspect: false, isDelivery: false, isBilling: true, isBroker: false, isDistributor: false, country: 'France',
|
||||||
postalCode: '86100', city: 'Châtellerault', street: '1 rue X', streetComplement: null,
|
postalCode: '86100', city: 'Châtellerault', street: '1 rue X', streetComplement: null,
|
||||||
categoryIris: ['/api/categories/2'], siteIris: ['/api/sites/1'], contactIris: [],
|
categoryIris: ['/api/categories/2'], siteIris: ['/api/sites/1'], contactIris: [],
|
||||||
billingEmail: 'facturation@acme.fr',
|
billingEmail: 'facturation@acme.fr', billingEmailSecondary: 'compta@acme.fr', hasSecondaryBillingEmail: true,
|
||||||
}
|
}
|
||||||
expect(buildAddressPayload(address, true).billingEmail).toBe('facturation@acme.fr')
|
expect(buildAddressPayload(address, true).billingEmail).toBe('facturation@acme.fr')
|
||||||
expect(buildAddressPayload(address, false).billingEmail).toBeNull()
|
expect(buildAddressPayload(address, false).billingEmail).toBeNull()
|
||||||
|
// 2e email : transmis si facturation + revele, sinon null (ERP-119).
|
||||||
|
expect(buildAddressPayload(address, true).billingEmailSecondary).toBe('compta@acme.fr')
|
||||||
|
expect(buildAddressPayload(address, false).billingEmailSecondary).toBeNull()
|
||||||
|
expect(buildAddressPayload({ ...address, hasSecondaryBillingEmail: false }, true).billingEmailSecondary).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('rib : label / bic / iban transmis tels quels', () => {
|
it('rib : label / bic / iban transmis tels quels', () => {
|
||||||
const rib: RibFormDraft = { id: 1, label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' }
|
const rib: RibFormDraft = { id: 1, label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' }
|
||||||
expect(buildRibPayload(rib)).toEqual({ label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' })
|
expect(buildRibPayload(rib)).toEqual({ label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ERP-119 : un RIB partiel (IBAN seul) doit omettre label/bic vides pour
|
||||||
|
// declencher la 422 NotBlank par champ, pas un 400 de type a la deserialisation.
|
||||||
|
it('rib partiel : omet label / bic vides, conserve iban', () => {
|
||||||
|
const rib: RibFormDraft = { id: null, label: null, bic: null, iban: 'FR7612345' }
|
||||||
|
const payload = buildRibPayload(rib)
|
||||||
|
expect('label' in payload).toBe(false)
|
||||||
|
expect('bic' in payload).toBe(false)
|
||||||
|
expect(payload.iban).toBe('FR7612345')
|
||||||
|
})
|
||||||
|
|
||||||
|
// ERP-119 : une adresse partielle omet postalCode/city/street vides (NotBlank).
|
||||||
|
it('adresse partielle : omet postalCode / city / street vides', () => {
|
||||||
|
const address: AddressFormDraft = {
|
||||||
|
id: null, isProspect: false, isDelivery: true, isBilling: false, isBroker: false, isDistributor: false, country: 'France',
|
||||||
|
postalCode: null, city: '', street: null, streetComplement: null,
|
||||||
|
categoryIris: ['/api/categories/2'], siteIris: ['/api/sites/1'], contactIris: [],
|
||||||
|
billingEmail: null, billingEmailSecondary: null, hasSecondaryBillingEmail: false,
|
||||||
|
}
|
||||||
|
const payload = buildAddressPayload(address, false)
|
||||||
|
expect('postalCode' in payload).toBe(false)
|
||||||
|
expect('city' in payload).toBe(false)
|
||||||
|
expect('street' in payload).toBe(false)
|
||||||
|
// Les champs non requis / booleens restent presents.
|
||||||
|
expect(payload.isDelivery).toBe(true)
|
||||||
|
expect(payload.sites).toEqual(['/api/sites/1'])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mapMainDraft — pre-remplissage bloc principal', () => {
|
describe('mapMainDraft — pre-remplissage bloc principal', () => {
|
||||||
|
|||||||
@@ -7,14 +7,22 @@ import {
|
|||||||
canSelectDeliveryOrBilling,
|
canSelectDeliveryOrBilling,
|
||||||
canSelectProspect,
|
canSelectProspect,
|
||||||
hasAllRequiredAccountingFields,
|
hasAllRequiredAccountingFields,
|
||||||
|
hasAtLeastOneInformationField,
|
||||||
hasAtLeastOneValidContact,
|
hasAtLeastOneValidContact,
|
||||||
|
isAddressValid,
|
||||||
isBankRequiredForPaymentType,
|
isBankRequiredForPaymentType,
|
||||||
isBillingEmailRequired,
|
isBillingEmailRequired,
|
||||||
isBlankRow,
|
isBlankRow,
|
||||||
isContactBlank,
|
isContactBlank,
|
||||||
isContactNamed,
|
isContactNamed,
|
||||||
isRibBlank,
|
isRibBlank,
|
||||||
|
isRibComplete,
|
||||||
isRibRequiredForPaymentType,
|
isRibRequiredForPaymentType,
|
||||||
|
lastFillableTabKey,
|
||||||
|
omitEmptyRequired,
|
||||||
|
showsRelationAndTriageFields,
|
||||||
|
type AddressFlagsDraft,
|
||||||
|
type AddressValidityDraft,
|
||||||
type ContactDraft,
|
type ContactDraft,
|
||||||
type ContactFillableDraft,
|
type ContactFillableDraft,
|
||||||
} from '../clientFormRules'
|
} from '../clientFormRules'
|
||||||
@@ -63,6 +71,24 @@ describe('buildClientFormTabKeys (gating onglet Comptabilite + onglets edit-only
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('lastFillableTabKey (redirection fin d\'ajout, role-aware)', () => {
|
||||||
|
it('Adresse pour un role sans Comptabilite (Bureau / Commerciale)', () => {
|
||||||
|
expect(lastFillableTabKey(buildClientFormTabKeys(false))).toBe('address')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Comptabilite pour un role avec accounting.view (Admin)', () => {
|
||||||
|
expect(lastFillableTabKey(buildClientFormTabKeys(true))).toBe('accounting')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ignore les onglets placeholder (Transport en dernier ne compte pas)', () => {
|
||||||
|
expect(lastFillableTabKey(['information', 'contact', 'address', 'transport'])).toBe('address')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('undefined si aucun onglet remplissable (que des placeholders)', () => {
|
||||||
|
expect(lastFillableTabKey(['transport', 'statistics'])).toBeUndefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('isContactNamed (RG-1.05)', () => {
|
describe('isContactNamed (RG-1.05)', () => {
|
||||||
it('vrai si le prenom est renseigne', () => {
|
it('vrai si le prenom est renseigne', () => {
|
||||||
expect(isContactNamed({ firstName: 'Alice', lastName: null })).toBe(true)
|
expect(isContactNamed({ firstName: 'Alice', lastName: null })).toBe(true)
|
||||||
@@ -143,83 +169,79 @@ describe('hasAtLeastOneValidContact (RG-1.14)', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** Drapeaux d'adresse complets (5 types) avec surcharge partielle. */
|
||||||
|
function flags(overrides: Partial<AddressFlagsDraft> = {}): AddressFlagsDraft {
|
||||||
|
return {
|
||||||
|
isProspect: false, isDelivery: false, isBilling: false, isBroker: false, isDistributor: false,
|
||||||
|
...overrides,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe('exclusivite Prospect / Livraison / Facturation (RG-1.06/07/08)', () => {
|
describe('exclusivite Prospect / Livraison / Facturation (RG-1.06/07/08)', () => {
|
||||||
it('Prospect est selectionnable tant que ni Livraison ni Facturation', () => {
|
it('Prospect est selectionnable tant que ni Livraison ni Facturation', () => {
|
||||||
expect(canSelectProspect({ isProspect: false, isDelivery: false, isBilling: false })).toBe(true)
|
expect(canSelectProspect(flags())).toBe(true)
|
||||||
expect(canSelectProspect({ isProspect: false, isDelivery: true, isBilling: false })).toBe(false)
|
expect(canSelectProspect(flags({ isDelivery: true }))).toBe(false)
|
||||||
expect(canSelectProspect({ isProspect: false, isDelivery: false, isBilling: true })).toBe(false)
|
expect(canSelectProspect(flags({ isBilling: true }))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Livraison / Facturation selectionnables tant que pas Prospect', () => {
|
it('Livraison / Facturation selectionnables tant que pas Prospect', () => {
|
||||||
expect(canSelectDeliveryOrBilling({ isProspect: false, isDelivery: false, isBilling: false })).toBe(true)
|
expect(canSelectDeliveryOrBilling(flags())).toBe(true)
|
||||||
expect(canSelectDeliveryOrBilling({ isProspect: true, isDelivery: false, isBilling: false })).toBe(false)
|
expect(canSelectDeliveryOrBilling(flags({ isProspect: true }))).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('cocher Prospect efface Livraison et Facturation', () => {
|
it('cocher Prospect efface Livraison et Facturation', () => {
|
||||||
const next = applyProspectExclusivity(
|
const next = applyProspectExclusivity(flags({ isDelivery: true, isBilling: true }), 'isProspect', true)
|
||||||
{ isProspect: false, isDelivery: true, isBilling: true },
|
expect(next).toEqual(flags({ isProspect: true }))
|
||||||
'isProspect',
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
expect(next).toEqual({ isProspect: true, isDelivery: false, isBilling: false })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('cocher Livraison efface Prospect', () => {
|
it('cocher Livraison efface Prospect', () => {
|
||||||
const next = applyProspectExclusivity(
|
const next = applyProspectExclusivity(flags({ isProspect: true }), 'isDelivery', true)
|
||||||
{ isProspect: true, isDelivery: false, isBilling: false },
|
expect(next).toEqual(flags({ isDelivery: true }))
|
||||||
'isDelivery',
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
expect(next).toEqual({ isProspect: false, isDelivery: true, isBilling: false })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('cocher Facturation efface Prospect mais conserve Livraison', () => {
|
it('cocher Facturation efface Prospect mais conserve Livraison', () => {
|
||||||
const next = applyProspectExclusivity(
|
const next = applyProspectExclusivity(flags({ isProspect: true, isDelivery: true }), 'isBilling', true)
|
||||||
{ isProspect: true, isDelivery: true, isBilling: false },
|
expect(next).toEqual(flags({ isDelivery: true, isBilling: true }))
|
||||||
'isBilling',
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
expect(next).toEqual({ isProspect: false, isDelivery: true, isBilling: true })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('decocher un drapeau ne reactive rien d autre', () => {
|
it('decocher un drapeau ne reactive rien d autre', () => {
|
||||||
const next = applyProspectExclusivity(
|
const next = applyProspectExclusivity(flags({ isDelivery: true, isBilling: true }), 'isBilling', false)
|
||||||
{ isProspect: false, isDelivery: true, isBilling: true },
|
expect(next).toEqual(flags({ isDelivery: true }))
|
||||||
'isBilling',
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
expect(next).toEqual({ isProspect: false, isDelivery: true, isBilling: false })
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('isBillingEmailRequired (RG-1.11)', () => {
|
describe('isBillingEmailRequired (RG-1.11)', () => {
|
||||||
it('obligatoire uniquement si Facturation est coche', () => {
|
it('obligatoire uniquement si Facturation est coche', () => {
|
||||||
expect(isBillingEmailRequired({ isProspect: false, isDelivery: false, isBilling: true })).toBe(true)
|
expect(isBillingEmailRequired(flags({ isBilling: true }))).toBe(true)
|
||||||
expect(isBillingEmailRequired({ isProspect: false, isDelivery: true, isBilling: false })).toBe(false)
|
expect(isBillingEmailRequired(flags({ isDelivery: true }))).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('type d\'adresse (Select front) <-> drapeaux back', () => {
|
describe('type d\'adresse (Select front) <-> drapeaux back', () => {
|
||||||
it('addressFlagsFromType mappe chaque type vers les bons drapeaux', () => {
|
it('addressFlagsFromType mappe chaque type vers les bons drapeaux', () => {
|
||||||
expect(addressFlagsFromType('prospect')).toEqual({ isProspect: true, isDelivery: false, isBilling: false })
|
expect(addressFlagsFromType('prospect')).toEqual(flags({ isProspect: true }))
|
||||||
expect(addressFlagsFromType('delivery')).toEqual({ isProspect: false, isDelivery: true, isBilling: false })
|
expect(addressFlagsFromType('delivery')).toEqual(flags({ isDelivery: true }))
|
||||||
expect(addressFlagsFromType('billing')).toEqual({ isProspect: false, isDelivery: false, isBilling: true })
|
expect(addressFlagsFromType('billing')).toEqual(flags({ isBilling: true }))
|
||||||
expect(addressFlagsFromType('delivery_billing')).toEqual({ isProspect: false, isDelivery: true, isBilling: true })
|
expect(addressFlagsFromType('delivery_billing')).toEqual(flags({ isDelivery: true, isBilling: true }))
|
||||||
|
expect(addressFlagsFromType('broker')).toEqual(flags({ isBroker: true }))
|
||||||
|
expect(addressFlagsFromType('distributor')).toEqual(flags({ isDistributor: true }))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('addressTypeFromFlags reconstruit le type (Prospect prioritaire, livraison+facturation groupes)', () => {
|
it('addressTypeFromFlags reconstruit le type (Prospect/Courtier/Distributeur autonomes, livraison+facturation groupes)', () => {
|
||||||
expect(addressTypeFromFlags({ isProspect: true, isDelivery: false, isBilling: false })).toBe('prospect')
|
expect(addressTypeFromFlags(flags({ isProspect: true }))).toBe('prospect')
|
||||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: true, isBilling: false })).toBe('delivery')
|
expect(addressTypeFromFlags(flags({ isDelivery: true }))).toBe('delivery')
|
||||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: false, isBilling: true })).toBe('billing')
|
expect(addressTypeFromFlags(flags({ isBilling: true }))).toBe('billing')
|
||||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: true, isBilling: true })).toBe('delivery_billing')
|
expect(addressTypeFromFlags(flags({ isDelivery: true, isBilling: true }))).toBe('delivery_billing')
|
||||||
|
expect(addressTypeFromFlags(flags({ isBroker: true }))).toBe('broker')
|
||||||
|
expect(addressTypeFromFlags(flags({ isDistributor: true }))).toBe('distributor')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('addressTypeFromFlags retourne null quand aucun drapeau (amorce vierge -> bouton bloque)', () => {
|
it('addressTypeFromFlags retourne null quand aucun drapeau (amorce vierge -> bouton bloque)', () => {
|
||||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: false, isBilling: false })).toBeNull()
|
expect(addressTypeFromFlags(flags())).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('aller-retour type -> drapeaux -> type stable pour les 4 types', () => {
|
it('aller-retour type -> drapeaux -> type stable pour les 6 types', () => {
|
||||||
for (const type of ['prospect', 'delivery', 'billing', 'delivery_billing'] as const) {
|
for (const type of ['prospect', 'delivery', 'billing', 'delivery_billing', 'broker', 'distributor'] as const) {
|
||||||
expect(addressTypeFromFlags(addressFlagsFromType(type))).toBe(type)
|
expect(addressTypeFromFlags(addressFlagsFromType(type))).toBe(type)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -271,3 +293,128 @@ describe('hasAllRequiredAccountingFields (RG-1.30)', () => {
|
|||||||
})).toBe(false)
|
})).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('showsRelationAndTriageFields (affichage Relation + Triage selon categorie)', () => {
|
||||||
|
it('faux par defaut (aucune categorie selectionnee)', () => {
|
||||||
|
expect(showsRelationAndTriageFields([])).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si seules des categories Distributeur / Courtier sont selectionnees', () => {
|
||||||
|
expect(showsRelationAndTriageFields(['DISTRIBUTEUR'])).toBe(false)
|
||||||
|
expect(showsRelationAndTriageFields(['COURTIER'])).toBe(false)
|
||||||
|
expect(showsRelationAndTriageFields(['DISTRIBUTEUR', 'COURTIER'])).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('vrai des qu\'une categorie ordinaire est selectionnee', () => {
|
||||||
|
expect(showsRelationAndTriageFields(['CLIENT'])).toBe(true)
|
||||||
|
expect(showsRelationAndTriageFields(['DISTRIBUTEUR', 'CLIENT'])).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('hasAtLeastOneInformationField (pas de validation a vide a la creation)', () => {
|
||||||
|
const blank = {
|
||||||
|
description: null,
|
||||||
|
competitors: null,
|
||||||
|
foundedAt: null,
|
||||||
|
employeesCount: null,
|
||||||
|
revenueAmount: null,
|
||||||
|
profitAmount: null,
|
||||||
|
directorName: null,
|
||||||
|
}
|
||||||
|
|
||||||
|
it('faux quand aucun champ n\'est rempli (onglet vierge)', () => {
|
||||||
|
expect(hasAtLeastOneInformationField(blank)).toBe(false)
|
||||||
|
expect(hasAtLeastOneInformationField({ ...blank, description: ' ' })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('vrai des qu\'un champ porte une valeur', () => {
|
||||||
|
expect(hasAtLeastOneInformationField({ ...blank, description: 'Acteur majeur' })).toBe(true)
|
||||||
|
expect(hasAtLeastOneInformationField({ ...blank, employeesCount: '42' })).toBe(true)
|
||||||
|
expect(hasAtLeastOneInformationField({ ...blank, foundedAt: '2020-01-01' })).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('isAddressValid (gating « + Adresse » + validation onglet)', () => {
|
||||||
|
/** Adresse de livraison valide (type + site + categorie ; pas de facturation). */
|
||||||
|
function validDelivery(): AddressValidityDraft {
|
||||||
|
return {
|
||||||
|
isProspect: false,
|
||||||
|
isDelivery: true,
|
||||||
|
isBilling: false,
|
||||||
|
isBroker: false,
|
||||||
|
isDistributor: false,
|
||||||
|
categoryIris: ['/api/client_categories/1'],
|
||||||
|
siteIris: ['/api/sites/1'],
|
||||||
|
billingEmail: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it('vrai quand type + >= 1 site + >= 1 categorie (sans facturation)', () => {
|
||||||
|
expect(isAddressValid(validDelivery())).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si aucun drapeau (type d\'adresse non renseigne, amorce vierge)', () => {
|
||||||
|
expect(isAddressValid({ ...validDelivery(), isDelivery: false })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si aucun site (RG-1.10)', () => {
|
||||||
|
expect(isAddressValid({ ...validDelivery(), siteIris: [] })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si aucune categorie', () => {
|
||||||
|
expect(isAddressValid({ ...validDelivery(), categoryIris: [] })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('RG-1.11 : email de facturation obligatoire quand l\'adresse est de facturation', () => {
|
||||||
|
const billing: AddressValidityDraft = { ...validDelivery(), isBilling: true }
|
||||||
|
expect(isAddressValid({ ...billing, billingEmail: null })).toBe(false)
|
||||||
|
expect(isAddressValid({ ...billing, billingEmail: ' ' })).toBe(false)
|
||||||
|
expect(isAddressValid({ ...billing, billingEmail: 'facture@acme.fr' })).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('isRibComplete (gating « + RIB » + RG-1.13)', () => {
|
||||||
|
it('vrai quand label + BIC + IBAN sont remplis', () => {
|
||||||
|
expect(isRibComplete({ label: 'Compte courant', bic: 'BNPAFRPP', iban: 'FR1420041010050500013M02606' })).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux si un champ manque (null ou vide apres trim)', () => {
|
||||||
|
expect(isRibComplete({ label: null, bic: 'BNPAFRPP', iban: 'FR14...' })).toBe(false)
|
||||||
|
expect(isRibComplete({ label: 'Compte', bic: ' ', iban: 'FR14...' })).toBe(false)
|
||||||
|
expect(isRibComplete({ label: 'Compte', bic: 'BNPAFRPP', iban: null })).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('faux pour un bloc totalement vide (amorce)', () => {
|
||||||
|
expect(isRibComplete({ label: null, bic: null, iban: null })).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('omitEmptyRequired (ERP-119 : 422 NotBlank au lieu de 400 de type)', () => {
|
||||||
|
it('retire les cles requises vides (null / vide / undefined)', () => {
|
||||||
|
const payload = omitEmptyRequired(
|
||||||
|
{ companyName: null, label: '', iban: undefined, categories: ['/api/categories/1'] },
|
||||||
|
['companyName', 'label', 'iban'],
|
||||||
|
)
|
||||||
|
expect('companyName' in payload).toBe(false)
|
||||||
|
expect('label' in payload).toBe(false)
|
||||||
|
expect('iban' in payload).toBe(false)
|
||||||
|
// Les cles hors liste ne sont jamais touchees.
|
||||||
|
expect(payload.categories).toEqual(['/api/categories/1'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('conserve les cles requises renseignees', () => {
|
||||||
|
const payload = omitEmptyRequired({ companyName: 'ACME', bic: 'BNPAFRPP' }, ['companyName', 'bic'])
|
||||||
|
expect(payload).toEqual({ companyName: 'ACME', bic: 'BNPAFRPP' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ne retire jamais une cle hors de la liste requise, meme vide', () => {
|
||||||
|
const payload = omitEmptyRequired({ streetComplement: null }, ['street'])
|
||||||
|
expect('streetComplement' in payload).toBe(true)
|
||||||
|
expect(payload.streetComplement).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('false / 0 ne sont pas consideres vides (booleens / nombres preserves)', () => {
|
||||||
|
const payload = omitEmptyRequired({ isDelivery: false, position: 0 }, ['isDelivery', 'position'])
|
||||||
|
expect(payload).toEqual({ isDelivery: false, position: 0 })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -63,9 +63,12 @@ export interface AddressRead extends HydraRef {
|
|||||||
street?: string | null
|
street?: string | null
|
||||||
streetComplement?: string | null
|
streetComplement?: string | null
|
||||||
billingEmail?: string | null
|
billingEmail?: string | null
|
||||||
|
billingEmailSecondary?: string | null
|
||||||
isProspect?: boolean
|
isProspect?: boolean
|
||||||
isDelivery?: boolean
|
isDelivery?: boolean
|
||||||
isBilling?: boolean
|
isBilling?: boolean
|
||||||
|
isBroker?: boolean
|
||||||
|
isDistributor?: boolean
|
||||||
sites?: SiteRead[]
|
sites?: SiteRead[]
|
||||||
categories?: CategoryRead[]
|
categories?: CategoryRead[]
|
||||||
// L'embed M2M des contacts d'adresse peut etre un objet (partiel) ou un IRI nu.
|
// L'embed M2M des contacts d'adresse peut etre un objet (partiel) ou un IRI nu.
|
||||||
@@ -209,6 +212,8 @@ export function mapAddressToDraft(address: AddressRead): AddressFormDraft {
|
|||||||
isProspect: address.isProspect ?? false,
|
isProspect: address.isProspect ?? false,
|
||||||
isDelivery: address.isDelivery ?? false,
|
isDelivery: address.isDelivery ?? false,
|
||||||
isBilling: address.isBilling ?? false,
|
isBilling: address.isBilling ?? false,
|
||||||
|
isBroker: address.isBroker ?? false,
|
||||||
|
isDistributor: address.isDistributor ?? false,
|
||||||
country: address.country ?? 'France',
|
country: address.country ?? 'France',
|
||||||
postalCode: address.postalCode ?? null,
|
postalCode: address.postalCode ?? null,
|
||||||
city: address.city ?? null,
|
city: address.city ?? null,
|
||||||
@@ -218,6 +223,8 @@ export function mapAddressToDraft(address: AddressRead): AddressFormDraft {
|
|||||||
siteIris: (address.sites ?? []).map(s => s['@id']),
|
siteIris: (address.sites ?? []).map(s => s['@id']),
|
||||||
contactIris: (address.contacts ?? []).map(c => (typeof c === 'string' ? c : c['@id'])),
|
contactIris: (address.contacts ?? []).map(c => (typeof c === 'string' ? c : c['@id'])),
|
||||||
billingEmail: address.billingEmail ?? null,
|
billingEmail: address.billingEmail ?? null,
|
||||||
|
billingEmailSecondary: address.billingEmailSecondary ?? null,
|
||||||
|
hasSecondaryBillingEmail: (address.billingEmailSecondary ?? null) !== null && address.billingEmailSecondary !== '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,8 @@
|
|||||||
*
|
*
|
||||||
* Ces helpers ne touchent ni a l'API ni a l'etat reactif.
|
* Ces helpers ne touchent ni a l'API ni a l'etat reactif.
|
||||||
*
|
*
|
||||||
* NOTE RG-1.04 (Information obligatoire pour la Commerciale) : volontairement NON
|
* NOTE : l'onglet Information est facultatif pour tous les roles (RG-1.04
|
||||||
* miroitee cote front (cf. clientFormRules.ts) — /api/me n'expose pas le code de
|
* « Information obligatoire pour la Commerciale » retiree cote back).
|
||||||
* role et Bureau partage les permissions de Commerciale. Le back l'applique de
|
|
||||||
* maniere fiable (422) ; on laisse remonter ce 422 en toast.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -23,6 +21,12 @@ import {
|
|||||||
relationOf,
|
relationOf,
|
||||||
type ClientDetail,
|
type ClientDetail,
|
||||||
} from '~/modules/commercial/utils/clientConsultation'
|
} from '~/modules/commercial/utils/clientConsultation'
|
||||||
|
import {
|
||||||
|
ADDRESS_REQUIRED_NON_NULLABLE_KEYS,
|
||||||
|
MAIN_REQUIRED_NON_NULLABLE_KEYS,
|
||||||
|
omitEmptyRequired,
|
||||||
|
RIB_REQUIRED_NON_NULLABLE_KEYS,
|
||||||
|
} from '~/modules/commercial/utils/clientFormRules'
|
||||||
import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules/commercial/types/clientForm'
|
import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules/commercial/types/clientForm'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -141,13 +145,21 @@ export function mapAccountingFormDraft(client: ClientDetail): AccountingFormDraf
|
|||||||
* que la FK correspondant au type choisi, l'autre est forcee a null.
|
* que la FK correspondant au type choisi, l'autre est forcee a null.
|
||||||
*/
|
*/
|
||||||
export function buildMainPayload(main: MainFormDraft): Record<string, unknown> {
|
export function buildMainPayload(main: MainFormDraft): Record<string, unknown> {
|
||||||
return {
|
// companyName omis si vide -> 422 NotBlank au lieu d'un 400 de type (ERP-119).
|
||||||
|
// relationType : champ transitoire (non persiste cote back) qui porte
|
||||||
|
// l'intention UI « ce client depend d'un distributeur / courtier ». Il sert
|
||||||
|
// a la validation croisee serveur (RG-1.03 bis) : si une relation est choisie,
|
||||||
|
// la FK correspondante devient obligatoire -> 422 sur distributor / broker.
|
||||||
|
// Sans equivalent derivable cote back (FK nullable), c'est la seule facon de
|
||||||
|
// rester sur « on soumet, le back tranche » plutot qu'une garde front-only.
|
||||||
|
return omitEmptyRequired({
|
||||||
companyName: main.companyName,
|
companyName: main.companyName,
|
||||||
categories: main.categoryIris,
|
categories: main.categoryIris,
|
||||||
|
relationType: main.relationType,
|
||||||
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,
|
||||||
triageService: main.triageService,
|
triageService: main.triageService,
|
||||||
}
|
}, MAIN_REQUIRED_NON_NULLABLE_KEYS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Payload de l'onglet Information — groupe client:write:information UNIQUEMENT. */
|
/** Payload de l'onglet Information — groupe client:write:information UNIQUEMENT. */
|
||||||
@@ -200,10 +212,13 @@ export function buildAddressPayload(
|
|||||||
address: AddressFormDraft,
|
address: AddressFormDraft,
|
||||||
isBillingEmailRequired: boolean,
|
isBillingEmailRequired: boolean,
|
||||||
): Record<string, unknown> {
|
): Record<string, unknown> {
|
||||||
return {
|
// postalCode / city / street omis si vides -> 422 NotBlank (ERP-119).
|
||||||
|
return omitEmptyRequired({
|
||||||
isProspect: address.isProspect,
|
isProspect: address.isProspect,
|
||||||
isDelivery: address.isDelivery,
|
isDelivery: address.isDelivery,
|
||||||
isBilling: address.isBilling,
|
isBilling: address.isBilling,
|
||||||
|
isBroker: address.isBroker,
|
||||||
|
isDistributor: address.isDistributor,
|
||||||
country: address.country,
|
country: address.country,
|
||||||
postalCode: address.postalCode || null,
|
postalCode: address.postalCode || null,
|
||||||
city: address.city || null,
|
city: address.city || null,
|
||||||
@@ -213,16 +228,19 @@ export function buildAddressPayload(
|
|||||||
sites: address.siteIris,
|
sites: address.siteIris,
|
||||||
contacts: address.contactIris,
|
contacts: address.contactIris,
|
||||||
billingEmail: isBillingEmailRequired ? (address.billingEmail || null) : null,
|
billingEmail: isBillingEmailRequired ? (address.billingEmail || null) : null,
|
||||||
}
|
billingEmailSecondary: isBillingEmailRequired && address.hasSecondaryBillingEmail ? (address.billingEmailSecondary || null) : null,
|
||||||
|
}, ADDRESS_REQUIRED_NON_NULLABLE_KEYS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Payload d'un RIB (sous-ressource client_rib). */
|
/** Payload d'un RIB (sous-ressource client_rib). */
|
||||||
export function buildRibPayload(rib: RibFormDraft): Record<string, unknown> {
|
export function buildRibPayload(rib: RibFormDraft): Record<string, unknown> {
|
||||||
return {
|
// label / bic / iban omis si vides -> 422 NotBlank au lieu d'un 400 de type
|
||||||
|
// sur un RIB partiel (ex. IBAN seul). ERP-119.
|
||||||
|
return omitEmptyRequired({
|
||||||
label: rib.label,
|
label: rib.label,
|
||||||
bic: rib.bic,
|
bic: rib.bic,
|
||||||
iban: rib.iban,
|
iban: rib.iban,
|
||||||
}
|
}, RIB_REQUIRED_NON_NULLABLE_KEYS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Gating par permission ────────────────────────────────────────────────────
|
// ── Gating par permission ────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -9,12 +9,9 @@
|
|||||||
* Le back reste la source de verite (les RG sont re-validees serveur) ; ces
|
* Le back reste la source de verite (les RG sont re-validees serveur) ; ces
|
||||||
* regles ne servent qu'au feedback UI immediat (gating de boutons, visibilite).
|
* regles ne servent qu'au feedback UI immediat (gating de boutons, visibilite).
|
||||||
*
|
*
|
||||||
* NOTE RG-1.04 (Information obligatoire pour la Commerciale) : volontairement
|
* NOTE : l'onglet Information est facultatif pour tous les roles. L'ancienne
|
||||||
* NON miroite cote front pour l'instant. Le payload /api/me ne porte pas le code
|
* RG-1.04 (« Information obligatoire pour la Commerciale ») a ete retiree cote
|
||||||
* de role (roles = IRIs opaques) et Bureau partage les memes permissions que
|
* back — rien a miroiter ici.
|
||||||
* Commerciale : aucun signal fiable pour distinguer le role cote front. Le back
|
|
||||||
* (ClientProcessor, via BusinessRoleAware) applique la regle de maniere fiable ;
|
|
||||||
* a rebrancher ici des qu'un code de role sera expose dans /api/me.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +50,38 @@ export function buildClientFormTabKeys(
|
|||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dernier onglet REMPLISSABLE d'un jeu d'onglets : le dernier qui n'est pas un
|
||||||
|
* placeholder (coquille). Role-aware sans regle ad hoc — il suffit de lui passer
|
||||||
|
* les `tabKeys` deja filtres par permission (l'onglet Comptabilite n'y figure que
|
||||||
|
* si accounting.view). Sa validation marque la fin de l'ajout (redirection liste).
|
||||||
|
*/
|
||||||
|
export function lastFillableTabKey(tabKeys: string[]): string | undefined {
|
||||||
|
return [...tabKeys].reverse().find(
|
||||||
|
key => !(CLIENT_FORM_PLACEHOLDER_TABS as readonly string[]).includes(key),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codes de categorie « intermediaire » : un client dont la categorie est
|
||||||
|
* Distributeur ou Courtier n'a ni relation amont (il EST le distributeur /
|
||||||
|
* courtier) ni prestation de triage. Sert a conditionner l'affichage des champs
|
||||||
|
* « Relation » et « Prestation de triage » du formulaire principal.
|
||||||
|
*/
|
||||||
|
export const DISTRIBUTOR_BROKER_CATEGORY_CODES = ['DISTRIBUTEUR', 'COURTIER'] as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrai des qu'au moins une categorie « ordinaire » (autre que Distributeur /
|
||||||
|
* Courtier) est selectionnee. Les champs « Relation » (depend du distributeur /
|
||||||
|
* courtier) et « Prestation de triage » du formulaire principal sont masques par
|
||||||
|
* defaut et reveles uniquement dans ce cas.
|
||||||
|
*/
|
||||||
|
export function showsRelationAndTriageFields(selectedCategoryCodes: string[]): boolean {
|
||||||
|
return selectedCategoryCodes.some(
|
||||||
|
code => !(DISTRIBUTOR_BROKER_CATEGORY_CODES as readonly string[]).includes(code),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/** Sous-ensemble d'un contact necessaire aux regles de nommage (RG-1.05/1.14). */
|
/** Sous-ensemble d'un contact necessaire aux regles de nommage (RG-1.05/1.14). */
|
||||||
export interface ContactDraft {
|
export interface ContactDraft {
|
||||||
firstName: string | null
|
firstName: string | null
|
||||||
@@ -64,6 +93,10 @@ export interface AddressFlagsDraft {
|
|||||||
isProspect: boolean
|
isProspect: boolean
|
||||||
isDelivery: boolean
|
isDelivery: boolean
|
||||||
isBilling: boolean
|
isBilling: boolean
|
||||||
|
/** Adresse Courtier — type autonome exclusif (comme isProspect). */
|
||||||
|
isBroker: boolean
|
||||||
|
/** Adresse Distributeur — type autonome exclusif (comme isProspect). */
|
||||||
|
isDistributor: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Vrai si une chaine porte au moins un caractere non-espace. */
|
/** Vrai si une chaine porte au moins un caractere non-espace. */
|
||||||
@@ -138,6 +171,16 @@ export function isRibBlank(rib: RibFillableDraft): boolean {
|
|||||||
return isBlankRow([rib.label, rib.bic, rib.iban])
|
return isBlankRow([rib.label, rib.bic, rib.iban])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.13 : un RIB est complet quand ses trois champs sont remplis (label, BIC,
|
||||||
|
* IBAN). Predicat par-bloc partage entre le gating du bouton « + RIB » (le
|
||||||
|
* dernier bloc doit etre complet avant d'en ajouter un autre) et la validation
|
||||||
|
* de l'onglet (au moins un RIB complet si reglement LCR).
|
||||||
|
*/
|
||||||
|
export function isRibComplete(rib: RibFillableDraft): boolean {
|
||||||
|
return isFilled(rib.label) && isFilled(rib.bic) && isFilled(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
|
||||||
@@ -193,22 +236,30 @@ export function isBillingEmailRequired(flags: AddressFlagsDraft): boolean {
|
|||||||
* drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). Les seules
|
* drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). Les seules
|
||||||
* combinaisons proposees respectent l'exclusivite Prospect (RG-1.06/07/08).
|
* combinaisons proposees respectent l'exclusivite Prospect (RG-1.06/07/08).
|
||||||
*/
|
*/
|
||||||
export type AddressType = 'prospect' | 'delivery' | 'billing' | 'delivery_billing'
|
export type AddressType = 'prospect' | 'delivery' | 'billing' | 'delivery_billing' | 'broker' | 'distributor'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mappe le type d'adresse choisi vers les trois drapeaux back.
|
* Mappe le type d'adresse choisi vers les cinq drapeaux back.
|
||||||
* « Adresse + Facturation » = livraison ET facturation sur la meme adresse.
|
* « Adresse + Facturation » = livraison ET facturation sur la meme adresse.
|
||||||
|
* Courtier / Distributeur sont autonomes (un seul drapeau, exclusif du reste).
|
||||||
*/
|
*/
|
||||||
export function addressFlagsFromType(type: AddressType): AddressFlagsDraft {
|
export function addressFlagsFromType(type: AddressType): AddressFlagsDraft {
|
||||||
|
const none: AddressFlagsDraft = {
|
||||||
|
isProspect: false, isDelivery: false, isBilling: false, isBroker: false, isDistributor: false,
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'prospect':
|
case 'prospect':
|
||||||
return { isProspect: true, isDelivery: false, isBilling: false }
|
return { ...none, isProspect: true }
|
||||||
case 'delivery':
|
case 'delivery':
|
||||||
return { isProspect: false, isDelivery: true, isBilling: false }
|
return { ...none, isDelivery: true }
|
||||||
case 'billing':
|
case 'billing':
|
||||||
return { isProspect: false, isDelivery: false, isBilling: true }
|
return { ...none, isBilling: true }
|
||||||
case 'delivery_billing':
|
case 'delivery_billing':
|
||||||
return { isProspect: false, isDelivery: true, isBilling: true }
|
return { ...none, isDelivery: true, isBilling: true }
|
||||||
|
case 'broker':
|
||||||
|
return { ...none, isBroker: true }
|
||||||
|
case 'distributor':
|
||||||
|
return { ...none, isDistributor: true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +270,8 @@ export function addressFlagsFromType(type: AddressType): AddressFlagsDraft {
|
|||||||
*/
|
*/
|
||||||
export function addressTypeFromFlags(flags: AddressFlagsDraft): AddressType | null {
|
export function addressTypeFromFlags(flags: AddressFlagsDraft): AddressType | null {
|
||||||
if (flags.isProspect) return 'prospect'
|
if (flags.isProspect) return 'prospect'
|
||||||
|
if (flags.isBroker) return 'broker'
|
||||||
|
if (flags.isDistributor) return 'distributor'
|
||||||
if (flags.isDelivery && flags.isBilling) return 'delivery_billing'
|
if (flags.isDelivery && flags.isBilling) return 'delivery_billing'
|
||||||
if (flags.isDelivery) return 'delivery'
|
if (flags.isDelivery) return 'delivery'
|
||||||
if (flags.isBilling) return 'billing'
|
if (flags.isBilling) return 'billing'
|
||||||
@@ -226,6 +279,31 @@ export function addressTypeFromFlags(flags: AddressFlagsDraft): AddressType | nu
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sous-ensemble d'une adresse necessaire a sa validite par-bloc : drapeaux
|
||||||
|
* d'usage (pour le type + l'email de facturation conditionnel), sites et
|
||||||
|
* categories rattaches, email de facturation.
|
||||||
|
*/
|
||||||
|
export interface AddressValidityDraft extends AddressFlagsDraft {
|
||||||
|
categoryIris: string[]
|
||||||
|
siteIris: string[]
|
||||||
|
billingEmail: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validite par-bloc d'une adresse : type renseigne (RG-1.06/07/08), >= 1 site
|
||||||
|
* (RG-1.10), >= 1 categorie, et email de facturation rempli si l'adresse est de
|
||||||
|
* facturation (RG-1.11). Predicat partage entre le gating du bouton « + Adresse »
|
||||||
|
* (le dernier bloc doit etre valide avant d'en ajouter un autre) et la
|
||||||
|
* validation de l'onglet (toutes les adresses valides).
|
||||||
|
*/
|
||||||
|
export function isAddressValid(address: AddressValidityDraft): boolean {
|
||||||
|
return addressTypeFromFlags(address) !== null
|
||||||
|
&& address.siteIris.length >= 1
|
||||||
|
&& address.categoryIris.length >= 1
|
||||||
|
&& (!isBillingEmailRequired(address) || isFilled(address.billingEmail))
|
||||||
|
}
|
||||||
|
|
||||||
/** 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'
|
||||||
|
|
||||||
@@ -248,6 +326,36 @@ export function isRibRequiredForPaymentType(code: string | null | undefined): bo
|
|||||||
return code === PAYMENT_TYPE_LCR
|
return code === PAYMENT_TYPE_LCR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Champs saisissables de l'onglet Information (tous facultatifs). */
|
||||||
|
export interface InformationFieldsDraft {
|
||||||
|
description: string | null
|
||||||
|
competitors: string | null
|
||||||
|
foundedAt: string | null
|
||||||
|
employeesCount: string | null
|
||||||
|
revenueAmount: string | null
|
||||||
|
profitAmount: string | null
|
||||||
|
directorName: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrai si au moins un champ de l'onglet Information est rempli. L'onglet est
|
||||||
|
* facultatif (aucun champ obligatoire), mais on n'autorise pas une validation
|
||||||
|
* « a vide » a la creation : sans donnee, rien a enregistrer, l'utilisateur
|
||||||
|
* passe directement a l'onglet Contact. (En edition, vider tous les champs reste
|
||||||
|
* une action legitime : ce gate n'y est pas applique.)
|
||||||
|
*/
|
||||||
|
export function hasAtLeastOneInformationField(information: InformationFieldsDraft): boolean {
|
||||||
|
return !isBlankRow([
|
||||||
|
information.description,
|
||||||
|
information.competitors,
|
||||||
|
information.foundedAt,
|
||||||
|
information.employeesCount,
|
||||||
|
information.revenueAmount,
|
||||||
|
information.profitAmount,
|
||||||
|
information.directorName,
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
/** Sous-ensemble du brouillon comptable portant les six champs obligatoires. */
|
/** Sous-ensemble du brouillon comptable portant les six champs obligatoires. */
|
||||||
export interface AccountingRequiredDraft {
|
export interface AccountingRequiredDraft {
|
||||||
siren: string | null
|
siren: string | null
|
||||||
@@ -276,3 +384,38 @@ export function hasAllRequiredAccountingFields(accounting: AccountingRequiredDra
|
|||||||
&& filled(accounting.paymentDelayIri)
|
&& filled(accounting.paymentDelayIri)
|
||||||
&& filled(accounting.paymentTypeIri)
|
&& filled(accounting.paymentTypeIri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Champs requis adosses a une colonne NON-nullable (ERP-119) ───────────────
|
||||||
|
// Ces champs requis (NotBlank back) sont portes par une colonne Doctrine NON
|
||||||
|
// nullable. Si le front envoie `null` (champ vide, desormais possible : le bouton
|
||||||
|
// « Valider » n'est plus desactive), API Platform rejette la valeur en 400 de TYPE
|
||||||
|
// a la deserialisation (« The type of the X attribute must be string, NULL given »)
|
||||||
|
// AVANT le Validator -> pas de violation, donc pas d'erreur rouge cote champ.
|
||||||
|
// La parade : OMETTRE la cle du payload quand elle est vide. Sans la cle, la
|
||||||
|
// propriete garde son defaut null cote entite et #[Assert\NotBlank] se declenche
|
||||||
|
// normalement -> 422 avec propertyPath, mappee en rouge sous le champ.
|
||||||
|
// (Les champs requis a colonne NULLABLE — contacts, scalaires compta — acceptent
|
||||||
|
// deja `null` et renvoient une 422 : inutile de les omettre.)
|
||||||
|
export const MAIN_REQUIRED_NON_NULLABLE_KEYS = ['companyName'] as const
|
||||||
|
export const ADDRESS_REQUIRED_NON_NULLABLE_KEYS = ['postalCode', 'city', 'street'] as const
|
||||||
|
export const RIB_REQUIRED_NON_NULLABLE_KEYS = ['label', 'bic', 'iban'] as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retire d'un payload d'ecriture les cles requises laissees vides (null / ''
|
||||||
|
* / undefined), pour laisser le back produire une 422 NotBlank par champ plutot
|
||||||
|
* qu'un 400 de type sur une colonne non-nullable. Mute et retourne le payload.
|
||||||
|
* A n'appliquer QU'aux cles ci-dessus (champs requis a colonne non-nullable).
|
||||||
|
*/
|
||||||
|
export function omitEmptyRequired<T extends Record<string, unknown>>(
|
||||||
|
payload: T,
|
||||||
|
requiredKeys: readonly string[],
|
||||||
|
): T {
|
||||||
|
for (const key of requiredKeys) {
|
||||||
|
const value = payload[key]
|
||||||
|
if (value === null || value === undefined || value === '') {
|
||||||
|
delete payload[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
icon-name="mdi:tune"
|
icon-name="mdi:tune"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
icon-size="24"
|
icon-size="24"
|
||||||
button-class="w-[184px] justify-start gap-4 text-black"
|
|
||||||
@click="openFilters"
|
@click="openFilters"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
@@ -30,7 +29,7 @@
|
|||||||
>
|
>
|
||||||
<template #cell-action="{ item }">
|
<template #cell-action="{ item }">
|
||||||
<span
|
<span
|
||||||
class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium"
|
class="inline-flex items-center rounded-full px-2 py-0.5 font-medium"
|
||||||
:class="actionBadgeClass(item.action as string)"
|
:class="actionBadgeClass(item.action as string)"
|
||||||
>
|
>
|
||||||
{{ t(`audit.action.${item.action}`) }}
|
{{ t(`audit.action.${item.action}`) }}
|
||||||
@@ -38,15 +37,14 @@
|
|||||||
</template>
|
</template>
|
||||||
<template #cell-entityType="{ item }">
|
<template #cell-entityType="{ item }">
|
||||||
<span
|
<span
|
||||||
class="text-xs"
|
|
||||||
:title="item.entityType as string"
|
:title="item.entityType as string"
|
||||||
>{{ formatEntityType(item.entityType as string) }}</span>
|
>{{ formatEntityType(item.entityType as string) }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #cell-entityId="{ item }">
|
<template #cell-entityId="{ item }">
|
||||||
<span class="font-mono text-xs">{{ item.entityId }}</span>
|
<span>{{ item.entityId }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #cell-summary="{ item }">
|
<template #cell-summary="{ item }">
|
||||||
<span class="text-xs text-gray-600">{{ item.summary }}</span>
|
<span class="text-gray-600">{{ item.summary }}</span>
|
||||||
</template>
|
</template>
|
||||||
</MalioDataTable>
|
</MalioDataTable>
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<template #actions>
|
<template #actions>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-if="can('core.roles.manage')"
|
v-if="can('core.roles.manage')"
|
||||||
|
variant="secondary"
|
||||||
:label="t('admin.roles.newRole')"
|
:label="t('admin.roles.newRole')"
|
||||||
icon-name="mdi:add-bold"
|
icon-name="mdi:add-bold"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
@update:per-page="setItemsPerPage"
|
@update:per-page="setItemsPerPage"
|
||||||
>
|
>
|
||||||
<template #cell-code="{ item }">
|
<template #cell-code="{ item }">
|
||||||
<span class="font-mono text-xs">{{ item.code }}</span>
|
<span>{{ item.code }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #cell-permissions="{ item }">
|
<template #cell-permissions="{ item }">
|
||||||
{{ item.permissions }}
|
{{ item.permissions }}
|
||||||
@@ -36,7 +37,7 @@
|
|||||||
<template #cell-system="{ item }">
|
<template #cell-system="{ item }">
|
||||||
<span
|
<span
|
||||||
v-if="item.isSystem"
|
v-if="item.isSystem"
|
||||||
class="inline-flex items-center rounded-full bg-blue-100 px-2.5 py-0.5 text-xs font-medium text-blue-800"
|
class="inline-flex items-center rounded-full bg-blue-100 px-2.5 py-0.5 font-medium text-blue-800"
|
||||||
>
|
>
|
||||||
{{ t('admin.roles.table.system') }}
|
{{ t('admin.roles.table.system') }}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<template #cell-admin="{ item }">
|
<template #cell-admin="{ item }">
|
||||||
<span
|
<span
|
||||||
v-if="item.admin"
|
v-if="item.admin"
|
||||||
class="inline-flex items-center rounded-full bg-purple-100 px-2.5 py-0.5 text-xs font-medium text-purple-800"
|
class="inline-flex items-center rounded-full bg-purple-100 px-2.5 py-0.5 font-medium text-purple-800"
|
||||||
>
|
>
|
||||||
{{ t('admin.users.table.admin') }}
|
{{ t('admin.users.table.admin') }}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="form.color"
|
v-model="form.color"
|
||||||
placeholder="#RRGGBB"
|
placeholder="#RRGGBB"
|
||||||
input-class="w-full font-mono"
|
input-class="w-full"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<!-- pb-4 sur le wrapper : simule le slot message du
|
<!-- pb-4 sur le wrapper : simule le slot message du
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<template #actions>
|
<template #actions>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-if="can('sites.manage')"
|
v-if="can('sites.manage')"
|
||||||
|
variant="secondary"
|
||||||
:label="t('admin.sites.newSite')"
|
:label="t('admin.sites.newSite')"
|
||||||
icon-name="mdi:add-bold"
|
icon-name="mdi:add-bold"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
@@ -33,11 +34,11 @@
|
|||||||
:style="{ backgroundColor: item.color }"
|
:style="{ backgroundColor: item.color }"
|
||||||
class="inline-block size-5 rounded-full border border-neutral-200"
|
class="inline-block size-5 rounded-full border border-neutral-200"
|
||||||
/>
|
/>
|
||||||
<span class="font-mono text-xs">{{ item.color }}</span>
|
<span>{{ item.color }}</span>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<template #cell-fullAddress="{ item }">
|
<template #cell-fullAddress="{ item }">
|
||||||
<span class="line-clamp-2 text-xs text-neutral-600">
|
<span class="line-clamp-2 text-neutral-600">
|
||||||
{{ item.fullAddress }}
|
{{ item.fullAddress }}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Generated
+14
-14
@@ -7,7 +7,7 @@
|
|||||||
"name": "starseed-frontend",
|
"name": "starseed-frontend",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@malio/layer-ui": "^1.7.4",
|
"@malio/layer-ui": "^1.7.8",
|
||||||
"@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",
|
||||||
@@ -583,20 +583,20 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@emnapi/core": {
|
"node_modules/@emnapi/core": {
|
||||||
"version": "1.10.0",
|
"version": "1.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.0.tgz",
|
||||||
"integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==",
|
"integrity": "sha512-l9Oo58x0HOP5znGzVhYW9U3e5wVuA4LAZU2AGezTmkhO1CgQRFDhDg4nneHsu/t3WniXg9QrG2nIXL/ZS8ln8Q==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emnapi/wasi-threads": "1.2.1",
|
"@emnapi/wasi-threads": "1.2.2",
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@emnapi/runtime": {
|
"node_modules/@emnapi/runtime": {
|
||||||
"version": "1.10.0",
|
"version": "1.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.0.tgz",
|
||||||
"integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==",
|
"integrity": "sha512-55coeOFKHv1ywEcUXJtWU5f+Jr/W5tZDvZig8DLKSwUN1JpROQ4rk/SNOQiFWmaR/VKF4zuFyW1B8JduOSv6Pg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -604,9 +604,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@emnapi/wasi-threads": {
|
"node_modules/@emnapi/wasi-threads": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz",
|
||||||
"integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==",
|
"integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1866,9 +1866,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@malio/layer-ui": {
|
"node_modules/@malio/layer-ui": {
|
||||||
"version": "1.7.4",
|
"version": "1.7.8",
|
||||||
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.4/layer-ui-1.7.4.tgz",
|
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.8/layer-ui-1.7.8.tgz",
|
||||||
"integrity": "sha512-JNXwBelj5UQ35Qv5VmnassXKt8niX9jDXjM1vUSukJQiyeUXRxAiZr16QumVgBN9P9YGDyjXVKrwCHltTXvPtQ==",
|
"integrity": "sha512-gUMAZzBsPCfQUF3OQSjN/OFzjONvQZYfwqH0u5VUbxaqwBdX1hUGtjD4ym6RvZkyNsKulrxkncFZYTWCS+IdGA==",
|
||||||
"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.4",
|
"@malio/layer-ui": "^1.7.8",
|
||||||
"@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",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="(diff, field) in updateDiff" :key="field" class="border-t border-gray-200">
|
<tr v-for="(diff, field) in updateDiff" :key="field" class="border-t border-gray-200">
|
||||||
<td class="px-2 py-1 font-mono">{{ field }}</td>
|
<td class="px-2 py-1">{{ field }}</td>
|
||||||
<td class="px-2 py-1 text-red-700">{{ formatValue(diff.old) }}</td>
|
<td class="px-2 py-1 text-red-700">{{ formatValue(diff.old) }}</td>
|
||||||
<td class="px-2 py-1 text-green-700">{{ formatValue(diff.new) }}</td>
|
<td class="px-2 py-1 text-green-700">{{ formatValue(diff.new) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
{ added: [ids], removed: [ids] } → affiche + et - sur
|
{ added: [ids], removed: [ids] } → affiche + et - sur
|
||||||
la meme ligne pour garder une colonne field unique. -->
|
la meme ligne pour garder une colonne field unique. -->
|
||||||
<tr v-for="(diff, field) in collectionDiff" :key="`col-${field}`" class="border-t border-gray-200">
|
<tr v-for="(diff, field) in collectionDiff" :key="`col-${field}`" class="border-t border-gray-200">
|
||||||
<td class="px-2 py-1 font-mono">{{ field }}</td>
|
<td class="px-2 py-1">{{ field }}</td>
|
||||||
<td class="px-2 py-1 text-red-700">
|
<td class="px-2 py-1 text-red-700">
|
||||||
<span v-if="diff.removed.length">− {{ diff.removed.join(', ') }}</span>
|
<span v-if="diff.removed.length">− {{ diff.removed.join(', ') }}</span>
|
||||||
<span v-else class="text-gray-400">∅</span>
|
<span v-else class="text-gray-400">∅</span>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
<div v-else class="space-y-1">
|
<div v-else class="space-y-1">
|
||||||
<div v-for="(value, key) in entry.changes" :key="key" class="flex gap-2">
|
<div v-for="(value, key) in entry.changes" :key="key" class="flex gap-2">
|
||||||
<span class="font-mono text-xs text-gray-600">{{ key }}:</span>
|
<span class="text-xs text-gray-600">{{ key }}:</span>
|
||||||
<span class="text-xs">{{ formatValue(value) }}</span>
|
<span class="text-xs">{{ formatValue(value) }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<!-- Entete de page standard : source unique du style des titres.
|
<!-- Entete de page standard : source unique du style des titres.
|
||||||
Slot par defaut = texte du titre, slot #actions = boutons a droite. -->
|
Slot par defaut = texte du titre, slot #actions = boutons a droite.
|
||||||
<div class="mb-[44px] flex items-center justify-between gap-4">
|
Sticky en haut du <main> scrollable : reste visible au scroll. Fond blanc
|
||||||
<h1 class="text-[32px] font-semibold text-primary-500">
|
+ pt-[38px]/pb-[30px] (au lieu de marges) pour que le contenu defilant soit
|
||||||
|
masque sous l'entete (espaces haut ET bas compris) et que l'entete soit
|
||||||
|
collee sous le SiteSelector sans trou. pt = marge haute (38px),
|
||||||
|
pb = espace titre -> contenu (30px). z-20 < drawers/modales. -->
|
||||||
|
<div class="sticky top-0 z-20 flex items-center justify-between gap-4 bg-white pt-[38px] pb-[30px]">
|
||||||
|
<h1 class="text-[30px] font-semibold text-primary-500">
|
||||||
<slot/>
|
<slot/>
|
||||||
</h1>
|
</h1>
|
||||||
<div v-if="$slots.actions" class="shrink-0">
|
<div v-if="$slots.actions" class="shrink-0">
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { describe, it, expect, afterEach } from 'vitest'
|
||||||
|
import { readHistoryTab } from '../historyTab'
|
||||||
|
|
||||||
|
const KEYS = ['information', 'contact', 'address', 'accounting']
|
||||||
|
|
||||||
|
describe('readHistoryTab', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
window.history.replaceState(null, '')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne la cle d\'onglet quand elle est presente et valide', () => {
|
||||||
|
window.history.replaceState({ tab: 'address' }, '')
|
||||||
|
expect(readHistoryTab(KEYS)).toBe('address')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne null quand l\'onglet n\'est pas dans les cles valides (ex: role sans Comptabilite)', () => {
|
||||||
|
window.history.replaceState({ tab: 'accounting' }, '')
|
||||||
|
expect(readHistoryTab(['information', 'contact', 'address'])).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne null sans onglet dans l\'etat d\'historique (navigation directe / refresh)', () => {
|
||||||
|
window.history.replaceState(null, '')
|
||||||
|
expect(readHistoryTab(KEYS)).toBeNull()
|
||||||
|
|
||||||
|
window.history.replaceState({ foo: 'bar' }, '')
|
||||||
|
expect(readHistoryTab(KEYS)).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('retourne null quand la valeur n\'est pas une chaine', () => {
|
||||||
|
window.history.replaceState({ tab: 42 }, '')
|
||||||
|
expect(readHistoryTab(KEYS)).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Onglet actif transmis d'une page a l'autre via l'etat d'historique
|
||||||
|
* (`history.state`), SANS le mettre dans l'URL. Sert a preserver l'onglet courant
|
||||||
|
* au passage consultation <-> edition d'un client (dans les deux sens).
|
||||||
|
*
|
||||||
|
* On reste donc fidele a la regle « etat d'UI local, pas dans l'URL » : l'onglet
|
||||||
|
* voyage dans l'entree d'historique de la navigation, l'URL ne change pas.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lit la cle d'onglet posee par la page precedente (`history.state.tab`) si elle
|
||||||
|
* fait partie des onglets valides pour l'utilisateur. Retourne `null` sinon :
|
||||||
|
* navigation directe / deep link, rechargement de page, ou onglet inexistant
|
||||||
|
* pour ce role (ex: Comptabilite sans la permission).
|
||||||
|
*/
|
||||||
|
export function readHistoryTab(validKeys: string[]): string | null {
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const tab = (window.history.state as Record<string, unknown> | null)?.tab
|
||||||
|
return typeof tab === 'string' && validKeys.includes(tab) ? tab : null
|
||||||
|
}
|
||||||
@@ -207,7 +207,8 @@ migration-migrate:
|
|||||||
# orphelins du mapping ORM. Les index partiels (LOWER + WHERE) ne sont pas
|
# orphelins du mapping ORM. Les index partiels (LOWER + WHERE) ne sont pas
|
||||||
# exprimables via les attributs Doctrine ORM (fonctionnel + partiel), donc
|
# exprimables via les attributs Doctrine ORM (fonctionnel + partiel), donc
|
||||||
# ils disparaissent apres schema:update. On les recree par dbal:run-sql :
|
# ils disparaissent apres schema:update. On les recree par dbal:run-sql :
|
||||||
# - `uq_category_name_type_active` (M0 Catalog) : tests RG-1.07.
|
# - `uq_category_name_active` (M0 Catalog) : unicite GLOBALE du nom parmi
|
||||||
|
# les actifs (M:N categorie<->type), tests RG-1.07.
|
||||||
# - `uq_category_code` (Catalog ERP-78) : unicite du code categorie parmi
|
# - `uq_category_code` (Catalog ERP-78) : unicite du code categorie parmi
|
||||||
# les actifs (slug du nom), pilote RG-1.03/1.29.
|
# les actifs (slug du nom), pilote RG-1.03/1.29.
|
||||||
# - `uq_client_company_name_active` (M1 Commercial) : unicite nom societe
|
# - `uq_client_company_name_active` (M1 Commercial) : unicite nom societe
|
||||||
@@ -226,9 +227,10 @@ test-db-setup:
|
|||||||
$(SYMFONY_CONSOLE) --env=test --no-interaction doctrine:fixtures:load
|
$(SYMFONY_CONSOLE) --env=test --no-interaction doctrine:fixtures:load
|
||||||
$(SYMFONY_CONSOLE) --env=test --no-interaction app:sync-permissions
|
$(SYMFONY_CONSOLE) --env=test --no-interaction app:sync-permissions
|
||||||
$(SYMFONY_CONSOLE) --env=test --no-interaction app:seed-rbac
|
$(SYMFONY_CONSOLE) --env=test --no-interaction app:seed-rbac
|
||||||
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_name_type_active ON category (LOWER(name), category_type_id) WHERE deleted_at IS NULL"
|
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_name_active ON category (LOWER(name)) WHERE deleted_at IS NULL"
|
||||||
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_code ON category (code) WHERE deleted_at IS NULL"
|
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_code ON category (code) WHERE deleted_at IS NULL"
|
||||||
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_client_company_name_active ON client (LOWER(company_name)) WHERE is_archived = FALSE AND deleted_at IS NULL"
|
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_client_company_name_active ON client (LOWER(company_name)) WHERE is_archived = FALSE AND deleted_at IS NULL"
|
||||||
|
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_supplier_company_name_active ON supplier (LOWER(company_name)) WHERE is_archived = FALSE AND deleted_at IS NULL"
|
||||||
|
|
||||||
fixtures:
|
fixtures:
|
||||||
$(SYMFONY_CONSOLE) --no-interaction doctrine:fixtures:load
|
$(SYMFONY_CONSOLE) --no-interaction doctrine:fixtures:load
|
||||||
|
|||||||
@@ -256,13 +256,13 @@ final class Version20260601000000 extends AbstractMigration
|
|||||||
$this->comment('client', '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.');
|
$this->comment('client', '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.');
|
||||||
$this->comment('client', '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.');
|
$this->comment('client', '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.');
|
||||||
$this->comment('client', 'triage_service', 'Drapeau service triage active pour le client. Faux par defaut.');
|
$this->comment('client', 'triage_service', 'Drapeau service triage active pour le client. Faux par defaut.');
|
||||||
$this->comment('client', 'description', 'Onglet Information : description libre. Obligatoire pour le role Commerciale (RG-1.04), optionnel sinon.');
|
$this->comment('client', 'description', 'Onglet Information : description libre. Facultatif.');
|
||||||
$this->comment('client', 'competitors', 'Onglet Information : concurrents identifies (texte libre ≤ 255). Obligatoire role Commerciale (RG-1.04).');
|
$this->comment('client', 'competitors', 'Onglet Information : concurrents identifies (texte libre ≤ 255). Facultatif.');
|
||||||
$this->comment('client', 'founded_at', 'Onglet Information : date de creation de l entreprise. Obligatoire role Commerciale (RG-1.04).');
|
$this->comment('client', 'founded_at', 'Onglet Information : date de creation de l entreprise. Facultatif.');
|
||||||
$this->comment('client', 'employees_count', 'Onglet Information : effectif (entier >= 0). Obligatoire role Commerciale (RG-1.04).');
|
$this->comment('client', 'employees_count', 'Onglet Information : effectif (entier >= 0). Facultatif.');
|
||||||
$this->comment('client', 'revenue_amount', 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).');
|
$this->comment('client', 'revenue_amount', 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Facultatif.');
|
||||||
$this->comment('client', 'director_name', 'Onglet Information : nom du dirigeant. Obligatoire role Commerciale (RG-1.04).');
|
$this->comment('client', 'director_name', 'Onglet Information : nom du dirigeant. Facultatif.');
|
||||||
$this->comment('client', 'profit_amount', 'Onglet Information : resultat / benefice (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).');
|
$this->comment('client', 'profit_amount', 'Onglet Information : resultat / benefice (NUMERIC 15,2). Facultatif.');
|
||||||
$this->comment('client', 'siren', 'Onglet Comptabilite : SIREN (9 chiffres attendus). NON unique — peut etre partage entre etablissements (RG-1.15 supprimee, Q4).');
|
$this->comment('client', 'siren', 'Onglet Comptabilite : SIREN (9 chiffres attendus). NON unique — peut etre partage entre etablissements (RG-1.15 supprimee, Q4).');
|
||||||
$this->comment('client', 'account_number', 'Onglet Comptabilite : numero de compte comptable du client.');
|
$this->comment('client', 'account_number', 'Onglet Comptabilite : numero de compte comptable du client.');
|
||||||
$this->comment('client', 'tva_mode_id', 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id, ON DELETE RESTRICT.');
|
$this->comment('client', 'tva_mode_id', 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id, ON DELETE RESTRICT.');
|
||||||
|
|||||||
@@ -82,14 +82,14 @@ final class Version20260605130000 extends AbstractMigration
|
|||||||
// Ordre inverse des dependances FK : jointures et sous-collections
|
// Ordre inverse des dependances FK : jointures et sous-collections
|
||||||
// d'abord, puis supplier. Les referentiels comptables et le
|
// d'abord, puis supplier. Les referentiels comptables et le
|
||||||
// CategoryType FOURNISSEUR ne sont pas touches (crees ailleurs).
|
// CategoryType FOURNISSEUR ne sont pas touches (crees ailleurs).
|
||||||
$this->addSql('DROP TABLE supplier_address_category');
|
$this->addSql('DROP TABLE IF EXISTS supplier_address_category');
|
||||||
$this->addSql('DROP TABLE supplier_address_contact');
|
$this->addSql('DROP TABLE IF EXISTS supplier_address_contact');
|
||||||
$this->addSql('DROP TABLE supplier_address_site');
|
$this->addSql('DROP TABLE IF EXISTS supplier_address_site');
|
||||||
$this->addSql('DROP TABLE supplier_rib');
|
$this->addSql('DROP TABLE IF EXISTS supplier_rib');
|
||||||
$this->addSql('DROP TABLE supplier_address');
|
$this->addSql('DROP TABLE IF EXISTS supplier_address');
|
||||||
$this->addSql('DROP TABLE supplier_contact');
|
$this->addSql('DROP TABLE IF EXISTS supplier_contact');
|
||||||
$this->addSql('DROP TABLE supplier_category');
|
$this->addSql('DROP TABLE IF EXISTS supplier_category');
|
||||||
$this->addSql('DROP TABLE supplier');
|
$this->addSql('DROP TABLE IF EXISTS supplier');
|
||||||
}
|
}
|
||||||
|
|
||||||
// =================================================================
|
// =================================================================
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Catalog — Category multi-types : passage de la relation Category -> CategoryType
|
||||||
|
* de ManyToOne a ManyToMany.
|
||||||
|
*
|
||||||
|
* Ordre critique :
|
||||||
|
* 1. Creation de la table de jonction `category_category_type` (FK category ON
|
||||||
|
* DELETE CASCADE, FK category_type ON DELETE RESTRICT — conserve le garde-fou
|
||||||
|
* « on ne supprime pas un type encore reference »).
|
||||||
|
* 2. Backfill : chaque categorie existante recoit une ligne de jonction vers son
|
||||||
|
* ancien `category_type_id` (avant de dropper la colonne).
|
||||||
|
* 3. Drop de l'index unique (LOWER(name), category_type_id), de l'index FK et de
|
||||||
|
* la colonne `category.category_type_id` (Postgres drope la FK dependante).
|
||||||
|
* 4. Nouvel index unique GLOBAL sur le nom : LOWER(name) WHERE deleted_at IS NULL
|
||||||
|
* (l'unicite n'est plus liee au type — RG-1.07 reformulee).
|
||||||
|
*
|
||||||
|
* Sur base fraiche, les categories seedees CLIENT (Distributeur/Courtier/Secteur/
|
||||||
|
* Autre) et FOURNISSEUR (Negociant/Cooperative/...) n'ont aucun nom en collision
|
||||||
|
* -> l'index unique global passe sans conflit.
|
||||||
|
*
|
||||||
|
* Migration placee au namespace racine `DoctrineMigrations` (regle ABSOLUE n°11) :
|
||||||
|
* Doctrine Migrations 3.x trie par FQCN puis version ; le namespace racine garantit
|
||||||
|
* l'ordre par timestamp apres les migrations d'init des tables.
|
||||||
|
*/
|
||||||
|
final class Version20260608120000 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Catalog : Category <-> CategoryType en ManyToMany (jonction category_category_type), unicite du nom globalisee.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// 1. Table de jonction.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE category_category_type (
|
||||||
|
category_id INT NOT NULL,
|
||||||
|
category_type_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (category_id, category_type_id),
|
||||||
|
CONSTRAINT fk_category_category_type_category
|
||||||
|
FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_category_category_type_type
|
||||||
|
FOREIGN KEY (category_type_id) REFERENCES category_type (id) ON DELETE RESTRICT
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->addSql('CREATE INDEX idx_cat_cat_type_type ON category_category_type (category_type_id)');
|
||||||
|
|
||||||
|
$this->comment('category_category_type', '_table', 'Jointure M2M category <-> category_type (Catalog) — types portes par la categorie, au moins un obligatoire (RG-1.05).');
|
||||||
|
$this->comment('category_category_type', 'category_id', 'FK -> category.id, ON DELETE CASCADE — categorie portant le type.');
|
||||||
|
$this->comment('category_category_type', 'category_type_id', 'FK -> category_type.id, ON DELETE RESTRICT — type rattache (un type ne peut etre supprime tant qu il reste reference).');
|
||||||
|
|
||||||
|
// 2. Backfill depuis l'ancienne colonne ManyToOne (chaque categorie -> 1 type).
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO category_category_type (category_id, category_type_id)
|
||||||
|
SELECT id, category_type_id FROM category
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
// 3. Suppression de l'ancien modele : index unique par type, index FK, colonne.
|
||||||
|
$this->addSql('DROP INDEX uq_category_name_type_active');
|
||||||
|
$this->addSql('DROP INDEX idx_category_type_id');
|
||||||
|
// DROP COLUMN drope automatiquement la FK fk_category_type qui en depend.
|
||||||
|
$this->addSql('ALTER TABLE category DROP COLUMN category_type_id');
|
||||||
|
|
||||||
|
// 4. Unicite du nom desormais GLOBALE parmi les actifs (RG-1.07 reformulee).
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE UNIQUE INDEX uq_category_name_active
|
||||||
|
ON category (LOWER(name))
|
||||||
|
WHERE deleted_at IS NULL
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
// Realignement de la doc SQL de `category` (le type n'est plus une colonne).
|
||||||
|
$this->comment('category', '_table', 'Categories — referentiel multi-types via la jonction category_category_type, soft-delete via deleted_at, unicite LOWER(name) GLOBALE parmi les actifs (uq_category_name_active).');
|
||||||
|
$this->comment('category', 'name', 'Libelle de la categorie (≤ 120 caracteres) — unique GLOBALEMENT parmi les actifs (RG-1.07, uq_category_name_active).');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// Restauration best-effort de l'ancien modele ManyToOne (1 type par categorie).
|
||||||
|
$this->addSql('DROP INDEX IF EXISTS uq_category_name_active');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE category ADD COLUMN category_type_id INT DEFAULT NULL');
|
||||||
|
|
||||||
|
// Reprend le premier type de chaque categorie (l'ordre des types perdus
|
||||||
|
// au-dela du premier est best-effort : le modele cible n'en gardait qu'un).
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
UPDATE category c
|
||||||
|
SET category_type_id = (
|
||||||
|
SELECT cct.category_type_id
|
||||||
|
FROM category_category_type cct
|
||||||
|
WHERE cct.category_id = c.id
|
||||||
|
ORDER BY cct.category_type_id ASC
|
||||||
|
LIMIT 1
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
// Categories sans aucun type (theorique) : on les rattache a defaut au
|
||||||
|
// premier type existant pour pouvoir reposer le NOT NULL.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
UPDATE category
|
||||||
|
SET category_type_id = (SELECT id FROM category_type ORDER BY id ASC LIMIT 1)
|
||||||
|
WHERE category_type_id IS NULL
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE category ALTER COLUMN category_type_id SET NOT NULL');
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE category
|
||||||
|
ADD CONSTRAINT fk_category_type
|
||||||
|
FOREIGN KEY (category_type_id) REFERENCES category_type (id) ON DELETE RESTRICT
|
||||||
|
SQL);
|
||||||
|
$this->addSql('CREATE INDEX idx_category_type_id ON category (category_type_id)');
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE UNIQUE INDEX uq_category_name_type_active
|
||||||
|
ON category (LOWER(name), category_type_id)
|
||||||
|
WHERE deleted_at IS NULL
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql('DROP TABLE category_category_type');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emet un `COMMENT ON TABLE` (colonne speciale `_table`) ou `COMMENT ON COLUMN`
|
||||||
|
* en dollar-quoting Postgres ($_$...$_$) pour eviter tout echappement.
|
||||||
|
*/
|
||||||
|
private function comment(string $table, string $column, string $description): void
|
||||||
|
{
|
||||||
|
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
||||||
|
|
||||||
|
if ('_table' === $column) {
|
||||||
|
$this->addSql(sprintf('COMMENT ON TABLE %s IS $_$%s$_$', $quotedTable, $description));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addSql(sprintf(
|
||||||
|
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||||
|
$quotedTable,
|
||||||
|
'"'.str_replace('"', '""', $column).'"',
|
||||||
|
$description,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commercial — deux nouveaux types d'adresse client : Courtier et Distributeur.
|
||||||
|
*
|
||||||
|
* Ajoute les drapeaux `is_broker` / `is_distributor` sur `client_address`, au
|
||||||
|
* meme titre que `is_prospect` / `is_delivery` / `is_billing`. Ce sont des types
|
||||||
|
* AUTONOMES (comme la Prospection) : exclusifs de tout autre usage. Deux CHECK
|
||||||
|
* Postgres miroitent l'exclusivite applicative (validateExclusiveAddressTypes),
|
||||||
|
* en filet de securite (comme chk_client_address_prospect_exclusive).
|
||||||
|
*
|
||||||
|
* NB Postgres : `ADD COLUMN` ajoute en derniere position physique (pas de clause
|
||||||
|
* AFTER) — l'ordre physique est cosmetique, on adresse par nom. Les colonnes sont
|
||||||
|
* declarees juste apres isBilling dans l'entite (ERP-119).
|
||||||
|
*
|
||||||
|
* Migration au namespace racine `DoctrineMigrations` (regle ABSOLUE n°11) : le
|
||||||
|
* tri par version garantit son passage apres l'init des tables.
|
||||||
|
*/
|
||||||
|
final class Version20260609120000 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Commercial : types d\'adresse Courtier / Distributeur (is_broker / is_distributor) sur client_address, exclusifs (CHECK).';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE client_address ADD COLUMN is_broker BOOLEAN DEFAULT FALSE NOT NULL');
|
||||||
|
$this->addSql('ALTER TABLE client_address ADD COLUMN is_distributor BOOLEAN DEFAULT FALSE NOT NULL');
|
||||||
|
|
||||||
|
// Exclusivite miroir (filet de securite DBAL) : un type autonome interdit
|
||||||
|
// tout autre drapeau. Livraison + Facturation restent cumulables entre eux.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE client_address
|
||||||
|
ADD CONSTRAINT chk_client_address_broker_exclusive
|
||||||
|
CHECK (NOT (is_broker = TRUE AND (is_prospect = TRUE OR is_delivery = TRUE OR is_billing = TRUE OR is_distributor = TRUE)))
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE client_address
|
||||||
|
ADD CONSTRAINT chk_client_address_distributor_exclusive
|
||||||
|
CHECK (NOT (is_distributor = TRUE AND (is_prospect = TRUE OR is_delivery = TRUE OR is_billing = TRUE OR is_broker = TRUE)))
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->comment('client_address', 'is_broker', 'Adresse Courtier — type autonome exclusif de tout autre usage (chk_client_address_broker_exclusive). Faux par defaut.');
|
||||||
|
$this->comment('client_address', 'is_distributor', 'Adresse Distributeur — type autonome exclusif de tout autre usage (chk_client_address_distributor_exclusive). Faux par defaut.');
|
||||||
|
|
||||||
|
// Le commentaire de table mentionnait seulement prospect/livraison/facturation :
|
||||||
|
// on y ajoute les types autonomes Courtier / Distributeur (cf. ColumnCommentsCatalog).
|
||||||
|
$this->addSql('COMMENT ON TABLE client_address IS $_$Adresses d un client (1:n) — types prospect / livraison / facturation (exclusivites RG-1.06/07/08) + Courtier / Distributeur autonomes (exclusifs de tout autre usage), >= 1 site rattache (RG-1.10).$_$');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('COMMENT ON TABLE client_address IS $_$Adresses d un client (1:n) — prospect exclusif de livraison/facturation (RG-1.06/07/08), >= 1 site rattache (RG-1.10).$_$');
|
||||||
|
$this->addSql('ALTER TABLE client_address DROP CONSTRAINT IF EXISTS chk_client_address_broker_exclusive');
|
||||||
|
$this->addSql('ALTER TABLE client_address DROP CONSTRAINT IF EXISTS chk_client_address_distributor_exclusive');
|
||||||
|
$this->addSql('ALTER TABLE client_address DROP COLUMN is_distributor');
|
||||||
|
$this->addSql('ALTER TABLE client_address DROP COLUMN is_broker');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emet un `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour
|
||||||
|
* eviter tout echappement.
|
||||||
|
*/
|
||||||
|
private function comment(string $table, string $column, string $description): void
|
||||||
|
{
|
||||||
|
$this->addSql(sprintf(
|
||||||
|
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||||
|
'"'.str_replace('"', '""', $table).'"',
|
||||||
|
'"'.str_replace('"', '""', $column).'"',
|
||||||
|
$description,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commercial — second email de facturation (optionnel) sur une adresse client.
|
||||||
|
*
|
||||||
|
* Ajoute `billing_email_secondary` sur `client_address`, pendant du telephone
|
||||||
|
* secondaire du contact (max 2 emails). Optionnel ; comme l'email principal, il
|
||||||
|
* n'a de sens que sur une adresse de facturation (validateBillingEmailPresence).
|
||||||
|
*
|
||||||
|
* Migration au namespace racine `DoctrineMigrations` (regle ABSOLUE n°11).
|
||||||
|
*/
|
||||||
|
final class Version20260609140000 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Commercial : 2e email de facturation optionnel (billing_email_secondary) sur client_address.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE client_address ADD COLUMN billing_email_secondary VARCHAR(180) DEFAULT NULL');
|
||||||
|
|
||||||
|
$this->comment('client_address', 'billing_email_secondary', '2e email de facturation, optionnel (max 2). Interdit hors facturation (validateBillingEmailPresence), normalise en minuscules (RG-1.21).');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE client_address DROP COLUMN billing_email_secondary');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emet un `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour
|
||||||
|
* eviter tout echappement.
|
||||||
|
*/
|
||||||
|
private function comment(string $table, string $column, string $description): void
|
||||||
|
{
|
||||||
|
$this->addSql(sprintf(
|
||||||
|
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||||
|
'"'.str_replace('"', '""', $table).'"',
|
||||||
|
'"'.str_replace('"', '""', $column).'"',
|
||||||
|
$description,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,14 +19,18 @@ use App\Shared\Domain\Contract\CategoryInterface;
|
|||||||
use App\Shared\Domain\Contract\TimestampableInterface;
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||||
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Serializer\Attribute\Groups;
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Categorie : referentiel metier classifiant les futurs tiers (clients,
|
* Categorie : referentiel metier classifiant les futurs tiers (clients,
|
||||||
* fournisseurs, prestataires). Porte un `name` libre et un `categoryType`
|
* fournisseurs, prestataires). Porte un `name` libre et un ou plusieurs
|
||||||
* (FK vers le referentiel statique CategoryType).
|
* `categoryTypes` (ManyToMany vers le referentiel statique CategoryType,
|
||||||
|
* table de jonction `category_category_type`). Une categorie peut appartenir
|
||||||
|
* a plusieurs types simultanement (>= 1 obligatoire, RG-1.05).
|
||||||
*
|
*
|
||||||
* - Soft delete via `deletedAt` (pas de hard delete) : la liste exclut par
|
* - Soft delete via `deletedAt` (pas de hard delete) : la liste exclut par
|
||||||
* defaut les categories supprimees (cf. CategoryProvider, ticket 0.3).
|
* defaut les categories supprimees (cf. CategoryProvider, ticket 0.3).
|
||||||
@@ -81,12 +85,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
#[ORM\Entity(repositoryClass: DoctrineCategoryRepository::class)]
|
#[ORM\Entity(repositoryClass: DoctrineCategoryRepository::class)]
|
||||||
#[ORM\Table(name: 'category')]
|
#[ORM\Table(name: 'category')]
|
||||||
// Index nommes pour matcher la migration (cf. Role/Permission/Site). Les index
|
// Index nommes pour matcher la migration (cf. Role/Permission/Site). Les index
|
||||||
// uniques partiels `uq_category_name_type_active` (LOWER(name), category_type_id
|
// uniques partiels `uq_category_name_active` (LOWER(name) WHERE deleted_at IS
|
||||||
// WHERE deleted_at IS NULL) et `uq_category_code` (code WHERE deleted_at IS NULL)
|
// NULL — unicite GLOBALE du nom parmi les actifs) et `uq_category_code` (code
|
||||||
// restent possedes par la seule migration : Doctrine ORM ne sait pas exprimer un
|
// WHERE deleted_at IS NULL) restent possedes par la seule migration : Doctrine
|
||||||
// index partiel via attribut.
|
// ORM ne sait pas exprimer un index partiel via attribut.
|
||||||
#[ORM\Index(name: 'idx_category_deleted_at', columns: ['deleted_at'])]
|
#[ORM\Index(name: 'idx_category_deleted_at', columns: ['deleted_at'])]
|
||||||
#[ORM\Index(name: 'idx_category_type_id', columns: ['category_type_id'])]
|
|
||||||
#[ORM\Index(name: 'idx_category_created_by', columns: ['created_by'])]
|
#[ORM\Index(name: 'idx_category_created_by', columns: ['created_by'])]
|
||||||
#[ORM\Index(name: 'idx_category_updated_by', columns: ['updated_by'])]
|
#[ORM\Index(name: 'idx_category_updated_by', columns: ['updated_by'])]
|
||||||
#[Auditable]
|
#[Auditable]
|
||||||
@@ -126,11 +129,21 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
|||||||
#[Groups(['category:read'])]
|
#[Groups(['category:read'])]
|
||||||
private ?string $code = null;
|
private ?string $code = null;
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: CategoryType::class)]
|
/**
|
||||||
#[ORM\JoinColumn(name: 'category_type_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
|
* Types de la categorie (>= 1 obligatoire, RG-1.05). ManyToMany vers le
|
||||||
#[Assert\NotNull(message: 'Type de catégorie obligatoire.')]
|
* referentiel statique CategoryType via la jonction `category_category_type`.
|
||||||
|
* Cote inverse (category_type) en ON DELETE RESTRICT : un type ne peut etre
|
||||||
|
* supprime tant qu'il reste reference par une categorie.
|
||||||
|
*
|
||||||
|
* @var Collection<int, CategoryType>
|
||||||
|
*/
|
||||||
|
#[ORM\ManyToMany(targetEntity: CategoryType::class)]
|
||||||
|
#[ORM\JoinTable(name: 'category_category_type')]
|
||||||
|
#[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
|
#[ORM\InverseJoinColumn(name: 'category_type_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||||
|
#[Assert\Count(min: 1, minMessage: 'Sélectionnez au moins un type de catégorie.')]
|
||||||
#[Groups(['category:read', 'category:write'])]
|
#[Groups(['category:read', 'category:write'])]
|
||||||
private ?CategoryType $categoryType = null;
|
private Collection $categoryTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Soft delete : null = active, valeur = supprimee logiquement le {date}.
|
* Soft delete : null = active, valeur = supprimee logiquement le {date}.
|
||||||
@@ -141,6 +154,11 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
|||||||
#[Groups(['category:read'])]
|
#[Groups(['category:read'])]
|
||||||
private ?DateTimeImmutable $deletedAt = null;
|
private ?DateTimeImmutable $deletedAt = null;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->categoryTypes = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@@ -173,26 +191,42 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCategoryType(): ?CategoryType
|
/**
|
||||||
|
* @return Collection<int, CategoryType>
|
||||||
|
*/
|
||||||
|
public function getCategoryTypes(): Collection
|
||||||
{
|
{
|
||||||
return $this->categoryType;
|
return $this->categoryTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCategoryType(?CategoryType $categoryType): static
|
public function addCategoryType(CategoryType $categoryType): static
|
||||||
{
|
{
|
||||||
$this->categoryType = $categoryType;
|
if (!$this->categoryTypes->contains($categoryType)) {
|
||||||
|
$this->categoryTypes->add($categoryType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeCategoryType(CategoryType $categoryType): static
|
||||||
|
{
|
||||||
|
$this->categoryTypes->removeElement($categoryType);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implemente CategoryInterface : code du type rattache (ou null). Permet
|
* Implemente CategoryInterface : liste des codes de types rattaches a la
|
||||||
* aux modules tiers de filtrer/valider par type metier sans dependre de
|
* categorie. Permet aux modules tiers de filtrer/valider par type metier
|
||||||
* Catalog.
|
* (ex: RG-2.10 « contient FOURNISSEUR ») sans dependre de Catalog.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
*/
|
*/
|
||||||
public function getCategoryTypeCode(): ?string
|
public function getCategoryTypeCodes(): array
|
||||||
{
|
{
|
||||||
return $this->categoryType?->getCode();
|
return array_values(array_filter(
|
||||||
|
$this->categoryTypes->map(static fn (CategoryType $t): ?string => $t->getCode())->toArray(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDeletedAt(): ?DateTimeImmutable
|
public function getDeletedAt(): ?DateTimeImmutable
|
||||||
|
|||||||
@@ -23,10 +23,26 @@ interface CategoryRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* Construit un QueryBuilder de liste avec filtre soft-delete et tri par defaut.
|
* Construit un QueryBuilder de liste avec filtre soft-delete et tri par defaut.
|
||||||
* - $includeDeleted = false : exclut les categories soft-deleted (RG-1.08)
|
* - $includeDeleted = false : exclut les categories soft-deleted (RG-1.08)
|
||||||
* - $typeCode non null : ne garde que les categories dont le CategoryType
|
* - $typeCode non null : ne garde que les categories PORTANT ce code de type
|
||||||
* porte ce code (filtre `?typeCode=`, ex. FOURNISSEUR / CLIENT). Sert au
|
* (filtre `?typeCode=`, ex. FOURNISSEUR / CLIENT). Sert au multi-select
|
||||||
* multi-select Categorie du fournisseur (M2, RG-2.10).
|
* Categorie du fournisseur (M2, RG-2.10).
|
||||||
|
* - $nameSearch non null : recherche partielle case-insensitive sur le nom
|
||||||
|
* (filtre `?name=` de la liste admin).
|
||||||
|
* - $typeIds non vide : ne garde que les categories portant AU MOINS UN des
|
||||||
|
* types (OR, filtre `?typeId[]=` de la liste admin).
|
||||||
* - Tri : name ASC (RG-1.10).
|
* - Tri : name ASC (RG-1.10).
|
||||||
|
*
|
||||||
|
* Les categories etant en ManyToMany avec leurs types, la collection
|
||||||
|
* `categoryTypes` est eager-loadee (addSelect) pour eviter un N+1 a la
|
||||||
|
* serialisation, et `distinct` est applique des qu'un filtre type joint la
|
||||||
|
* table de jonction (evite les lignes dupliquees).
|
||||||
|
*
|
||||||
|
* @param list<int> $typeIds
|
||||||
*/
|
*/
|
||||||
public function createListQueryBuilder(bool $includeDeleted = false, ?string $typeCode = null): QueryBuilder;
|
public function createListQueryBuilder(
|
||||||
|
bool $includeDeleted = false,
|
||||||
|
?string $typeCode = null,
|
||||||
|
?string $nameSearch = null,
|
||||||
|
array $typeIds = [],
|
||||||
|
): QueryBuilder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
|
|||||||
* via CategoryCodeGenerator ; puis delegation au persist_processor Doctrine
|
* via CategoryCodeGenerator ; puis delegation au persist_processor Doctrine
|
||||||
* ORM. Le code est FIGE a la creation (jamais recalcule sur PATCH). Toute
|
* ORM. Le code est FIGE a la creation (jamais recalcule sur PATCH). Toute
|
||||||
* UniqueConstraintViolationException remontee par Postgres (collision sur
|
* UniqueConstraintViolationException remontee par Postgres (collision sur
|
||||||
* l'index partiel uq_category_name_type_active) est traduite en HTTP 409 avec
|
* l'index partiel uq_category_name_active — unicite GLOBALE du nom parmi les
|
||||||
* le message attendu par la spec (RG-1.07).
|
* actifs) est traduite en HTTP 409 avec le message attendu par la spec (RG-1.07).
|
||||||
* - DELETE : soft delete (RG-1.12). On NE delegue PAS au remove_processor ;
|
* - DELETE : soft delete (RG-1.12). On NE delegue PAS au remove_processor ;
|
||||||
* on pose deletedAt = now() puis on delegue au persist_processor pour que
|
* on pose deletedAt = now() puis on delegue au persist_processor pour que
|
||||||
* le UPDATE Doctrine parte et que le TimestampableBlamableSubscriber mette
|
* le UPDATE Doctrine parte et que le TimestampableBlamableSubscriber mette
|
||||||
@@ -78,10 +78,12 @@ final class CategoryProcessor implements ProcessorInterface
|
|||||||
try {
|
try {
|
||||||
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
} catch (UniqueConstraintViolationException $e) {
|
} catch (UniqueConstraintViolationException $e) {
|
||||||
// RG-1.07 : doublon (LOWER(name), category_type_id) parmi les non-soft-deleted.
|
// RG-1.07 : doublon de nom GLOBAL (LOWER(name)) parmi les non-soft-deleted
|
||||||
|
// (uq_category_name_active). L'unicite n'est plus liee au type depuis le
|
||||||
|
// passage en ManyToMany.
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
409,
|
409,
|
||||||
sprintf('Une catégorie nommée "%s" existe déjà pour ce type.', $data->getName() ?? ''),
|
sprintf('Une catégorie nommée "%s" existe déjà.', $data->getName() ?? ''),
|
||||||
$e,
|
$e,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,12 @@ final class CategoryProvider implements ProviderInterface
|
|||||||
$includeDeleted = $this->readIncludeDeleted($context);
|
$includeDeleted = $this->readIncludeDeleted($context);
|
||||||
|
|
||||||
if ($operation instanceof CollectionOperationInterface) {
|
if ($operation instanceof CollectionOperationInterface) {
|
||||||
$qb = $this->repository->createListQueryBuilder($includeDeleted, $this->readTypeCode($context));
|
$qb = $this->repository->createListQueryBuilder(
|
||||||
|
$includeDeleted,
|
||||||
|
$this->readTypeCode($context),
|
||||||
|
$this->readNameSearch($context),
|
||||||
|
$this->readTypeIds($context),
|
||||||
|
);
|
||||||
|
|
||||||
// Echappatoire ?pagination=false : retourne la collection complete sans Paginator.
|
// Echappatoire ?pagination=false : retourne la collection complete sans Paginator.
|
||||||
// Utile pour les drawers Role/Permission/Site/CategoryType qui alimentent un <select>.
|
// Utile pour les drawers Role/Permission/Site/CategoryType qui alimentent un <select>.
|
||||||
@@ -115,4 +120,48 @@ final class CategoryProvider implements ProviderInterface
|
|||||||
|
|
||||||
return '' === $raw ? null : $raw;
|
return '' === $raw ? null : $raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lit le filtre `?name=` (recherche partielle sur le nom, liste admin).
|
||||||
|
* Renvoie la valeur trimmee ou null si absente / vide.
|
||||||
|
*/
|
||||||
|
private function readNameSearch(array $context): ?string
|
||||||
|
{
|
||||||
|
$raw = $context['filters']['name'] ?? null;
|
||||||
|
|
||||||
|
if (!is_string($raw)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$raw = trim($raw);
|
||||||
|
|
||||||
|
return '' === $raw ? null : $raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lit le filtre `?typeId[]=` (liste admin) : ids des types coches (OR).
|
||||||
|
* Tolere une valeur scalaire unique (`?typeId=3`) ou un tableau. Ignore
|
||||||
|
* les entrees non numeriques.
|
||||||
|
*
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
private function readTypeIds(array $context): array
|
||||||
|
{
|
||||||
|
$raw = $context['filters']['typeId'] ?? null;
|
||||||
|
|
||||||
|
if (null === $raw) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$values = is_array($raw) ? $raw : [$raw];
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (is_int($value) || (is_string($value) && ctype_digit($value))) {
|
||||||
|
$ids[] = (int) $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_unique($ids));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class CategoryFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
$category = new Category();
|
$category = new Category();
|
||||||
$category->setName($name);
|
$category->setName($name);
|
||||||
$category->setCode($code);
|
$category->setCode($code);
|
||||||
$category->setCategoryType($type);
|
$category->addCategoryType($type);
|
||||||
$manager->persist($category);
|
$manager->persist($category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,19 @@ class DoctrineCategoryRepository extends ServiceEntityRepository implements Cate
|
|||||||
return [] !== $qb->getQuery()->getResult();
|
return [] !== $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createListQueryBuilder(bool $includeDeleted = false, ?string $typeCode = null): QueryBuilder
|
public function createListQueryBuilder(
|
||||||
{
|
bool $includeDeleted = false,
|
||||||
|
?string $typeCode = null,
|
||||||
|
?string $nameSearch = null,
|
||||||
|
array $typeIds = [],
|
||||||
|
): QueryBuilder {
|
||||||
|
// Eager-load de la collection categoryTypes (ManyToMany) : embarquee a la
|
||||||
|
// serialisation -> on la fetch-joine pour eviter un N+1 par categorie. Le
|
||||||
|
// provider enveloppe la requete dans un Paginator(fetchJoinCollection: true),
|
||||||
|
// compatible avec ce fetch-join to-many.
|
||||||
$qb = $this->createQueryBuilder('c')
|
$qb = $this->createQueryBuilder('c')
|
||||||
|
->leftJoin('c.categoryTypes', 'cte')
|
||||||
|
->addSelect('cte')
|
||||||
->orderBy('c.name', 'ASC')
|
->orderBy('c.name', 'ASC')
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -58,16 +68,45 @@ class DoctrineCategoryRepository extends ServiceEntityRepository implements Cate
|
|||||||
$qb->andWhere('c.deletedAt IS NULL');
|
$qb->andWhere('c.deletedAt IS NULL');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filtre `?typeCode=` : jointure sur le CategoryType pour ne garder que
|
// Filtre `?typeCode=` : la categorie doit PORTER ce code de type (RG-2.10,
|
||||||
// les categories du type demande (ex. FOURNISSEUR). La jointure reste
|
// multi-select fournisseur). Sous-requete EXISTS correlee pour ne PAS
|
||||||
// compatible avec le Paginator ORM (fetchJoinCollection) du provider.
|
// restreindre la collection eager-loadee `cte` (sinon les autres types de
|
||||||
|
// la categorie disparaitraient du JSON) et eviter les lignes dupliquees.
|
||||||
if (null !== $typeCode) {
|
if (null !== $typeCode) {
|
||||||
$qb->join('c.categoryType', 'ct')
|
$sub = $this->getEntityManager()->createQueryBuilder()
|
||||||
->andWhere('ct.code = :typeCode')
|
->select('1')
|
||||||
|
->from(Category::class, 'c_tc')
|
||||||
|
->join('c_tc.categoryTypes', 'ct_tc')
|
||||||
|
->where('c_tc = c')
|
||||||
|
->andWhere('ct_tc.code = :typeCode')
|
||||||
|
;
|
||||||
|
$qb->andWhere($qb->expr()->exists($sub->getDQL()))
|
||||||
->setParameter('typeCode', $typeCode)
|
->setParameter('typeCode', $typeCode)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filtre `?typeId[]=` (liste admin) : la categorie porte AU MOINS UN des
|
||||||
|
// types coches (OR). Meme strategie EXISTS correlee que `typeCode`.
|
||||||
|
if ([] !== $typeIds) {
|
||||||
|
$sub = $this->getEntityManager()->createQueryBuilder()
|
||||||
|
->select('1')
|
||||||
|
->from(Category::class, 'c_ti')
|
||||||
|
->join('c_ti.categoryTypes', 'ct_ti')
|
||||||
|
->where('c_ti = c')
|
||||||
|
->andWhere('ct_ti.id IN (:typeIds)')
|
||||||
|
;
|
||||||
|
$qb->andWhere($qb->expr()->exists($sub->getDQL()))
|
||||||
|
->setParameter('typeIds', $typeIds)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtre `?name=` (liste admin) : recherche partielle case-insensitive.
|
||||||
|
if (null !== $nameSearch && '' !== $nameSearch) {
|
||||||
|
$qb->andWhere('LOWER(c.name) LIKE :nameSearch')
|
||||||
|
->setParameter('nameSearch', '%'.mb_strtolower($nameSearch).'%')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -16,9 +16,9 @@ use Symfony\Component\Validator\ConstraintViolationList;
|
|||||||
* Type de reglement). La banque reste conditionnelle (RG-1.12) et les RIB aussi
|
* Type de reglement). La banque reste conditionnelle (RG-1.12) et les RIB aussi
|
||||||
* (RG-1.13) : ils ne sont pas couverts ici.
|
* (RG-1.13) : ils ne sont pas couverts ici.
|
||||||
*
|
*
|
||||||
* Calque sur ClientInformationCompletenessValidator (RG-1.04) : colonnes nullable
|
* Parti pris : colonnes nullable en base + validateur contextuel, plutot qu'un
|
||||||
* en base + validateur contextuel, plutot qu'un Assert\NotBlank sur l'entite (qui
|
* Assert\NotBlank sur l'entite (qui casserait le POST de l'onglet principal,
|
||||||
* casserait le POST de l'onglet principal, lequel n'envoie aucun champ comptable).
|
* lequel n'envoie aucun champ comptable).
|
||||||
*
|
*
|
||||||
* Invoque par le ClientProcessor uniquement quand le payload porte les six champs
|
* 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.
|
* (= une validation d'onglet), jamais sur un PATCH ciblant un seul champ comptable.
|
||||||
|
|||||||
-74
@@ -1,74 +0,0 @@
|
|||||||
<?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 RG-1.04 (durcie ERP-74) : pour un utilisateur portant le
|
|
||||||
* role metier Commerciale, TOUS les champs de l'onglet Information sont
|
|
||||||
* obligatoires sur POST comme sur tout PATCH, independamment des champs
|
|
||||||
* reellement envoyes.
|
|
||||||
*
|
|
||||||
* Invoque par le ClientProcessor des que l'utilisateur courant porte le role
|
|
||||||
* Commerciale (plus de condition d'intersection avec l'onglet Information).
|
|
||||||
* Pour les autres roles, ces champs restent optionnels — le validator n'est
|
|
||||||
* pas appele.
|
|
||||||
*
|
|
||||||
* Leve une ValidationException (HTTP 422) listant chaque champ manquant, par
|
|
||||||
* coherence avec les violations Symfony rendues par API Platform.
|
|
||||||
*/
|
|
||||||
final class ClientInformationCompletenessValidator
|
|
||||||
{
|
|
||||||
public function validate(Client $client): void
|
|
||||||
{
|
|
||||||
// Map champ -> valeur courante de l'onglet Information.
|
|
||||||
$fields = [
|
|
||||||
'description' => $client->getDescription(),
|
|
||||||
'competitors' => $client->getCompetitors(),
|
|
||||||
'foundedAt' => $client->getFoundedAt(),
|
|
||||||
'employeesCount' => $client->getEmployeesCount(),
|
|
||||||
'revenueAmount' => $client->getRevenueAmount(),
|
|
||||||
'directorName' => $client->getDirectorName(),
|
|
||||||
'profitAmount' => $client->getProfitAmount(),
|
|
||||||
];
|
|
||||||
|
|
||||||
$violations = new ConstraintViolationList();
|
|
||||||
|
|
||||||
foreach ($fields as $property => $value) {
|
|
||||||
if ($this->isMissing($value)) {
|
|
||||||
$violations->add(new ConstraintViolation(
|
|
||||||
sprintf('Ce champ est obligatoire pour le role Commerciale (champ "%s").', $property),
|
|
||||||
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 zeros numeriques (employeesCount = 0, profitAmount = "0.00") sont des
|
|
||||||
* valeurs valides : on ne les considere pas manquants.
|
|
||||||
*/
|
|
||||||
private function isMissing(mixed $value): bool
|
|
||||||
{
|
|
||||||
if (null === $value) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return is_string($value) && '' === trim($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-2
@@ -10,7 +10,7 @@ use Symfony\Component\Validator\ConstraintViolation;
|
|||||||
use Symfony\Component\Validator\ConstraintViolationList;
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validator metier RG-2.03 (jumeau du ClientInformationCompletenessValidator M1) :
|
* Validator metier RG-2.03 (completude Information cote fournisseur) :
|
||||||
* pour un utilisateur portant le role metier Commerciale, TOUS les champs de
|
* pour un utilisateur portant le role metier Commerciale, TOUS les champs de
|
||||||
* l'onglet Information sont obligatoires sur POST comme sur tout PATCH,
|
* l'onglet Information sont obligatoires sur POST comme sur tout PATCH,
|
||||||
* independamment des champs reellement envoyes.
|
* independamment des champs reellement envoyes.
|
||||||
@@ -47,7 +47,10 @@ final class SupplierInformationCompletenessValidator
|
|||||||
foreach ($fields as $property => $value) {
|
foreach ($fields as $property => $value) {
|
||||||
if ($this->isMissing($value)) {
|
if ($this->isMissing($value)) {
|
||||||
$violations->add(new ConstraintViolation(
|
$violations->add(new ConstraintViolation(
|
||||||
sprintf('Ce champ est obligatoire pour le rôle Commerciale (champ "%s").', $property),
|
// Pas de nom de champ technique dans le message : la violation est
|
||||||
|
// deja rattachee au bon champ via son propertyPath (mappe inline
|
||||||
|
// cote front par useFormErrors).
|
||||||
|
'Ce champ est obligatoire pour le rôle Commerciale.',
|
||||||
null,
|
null,
|
||||||
[],
|
[],
|
||||||
$supplier,
|
$supplier,
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
||||||
* Timestampable/Blamable (referentiel statique whiteliste dans
|
* Timestampable/Blamable (referentiel statique whiteliste dans
|
||||||
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
||||||
* `client:read:accounting` permet l'embarquement dans la reponse Client.
|
* `client:read:accounting` permet l'embarquement dans la reponse Client ;
|
||||||
|
* `supplier:read:accounting` dans la reponse Fournisseur (M2, ERP-92 — § 4.0).
|
||||||
*/
|
*/
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
@@ -47,15 +48,15 @@ class Bank
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['bank:read', 'client:read:accounting'])]
|
#[Groups(['bank:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 30)]
|
#[ORM\Column(length: 30)]
|
||||||
#[Groups(['bank:read', 'client:read:accounting'])]
|
#[Groups(['bank:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $code = null;
|
private ?string $code = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['bank:read', 'client:read:accounting'])]
|
#[Groups(['bank:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $label = null;
|
private ?string $label = null;
|
||||||
|
|
||||||
#[ORM\Column(options: ['default' => 0])]
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
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;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client (M1 Commercial) — entite racine du repertoire clients. Porte le
|
* Client (M1 Commercial) — entite racine du repertoire clients. Porte le
|
||||||
@@ -171,6 +172,17 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
#[Groups(['client:read', 'client:write:main'])]
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
private bool $triageService = false;
|
private bool $triageService = false;
|
||||||
|
|
||||||
|
// Champ transitoire (NON persiste : aucune colonne ORM) portant l'intention UI
|
||||||
|
// « ce client depend d'un distributeur / courtier ». Write-only (groupe
|
||||||
|
// d'ecriture main uniquement, pas de groupe de lecture -> jamais serialise en
|
||||||
|
// sortie). Sert exclusivement a la validation croisee validateRelationName :
|
||||||
|
// si une relation est choisie, la FK correspondante (distributor / broker)
|
||||||
|
// devient obligatoire. Non mappe ORM -> non audite, et toujours null une fois
|
||||||
|
// l'entite rechargee depuis la base (ne sert qu'au cycle d'une ecriture).
|
||||||
|
#[Assert\Choice(choices: ['distributeur', 'courtier'], message: 'Le type de relation est invalide.')]
|
||||||
|
#[Groups(['client:write:main'])]
|
||||||
|
private ?string $relationType = null;
|
||||||
|
|
||||||
// RG : au moins une categorie (Count min 1). M2M vers Category via le contrat
|
// RG : au moins une categorie (Count min 1). M2M vers Category via le contrat
|
||||||
// CategoryInterface (resolve_target_entities -> Category).
|
// CategoryInterface (resolve_target_entities -> Category).
|
||||||
/** @var Collection<int, CategoryInterface> */
|
/** @var Collection<int, CategoryInterface> */
|
||||||
@@ -188,7 +200,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')]
|
#[Assert\Length(max: 255, maxMessage: 'La liste des concurrents 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;
|
||||||
|
|
||||||
@@ -333,6 +345,45 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRelationType(): ?string
|
||||||
|
{
|
||||||
|
return $this->relationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRelationType(?string $relationType): static
|
||||||
|
{
|
||||||
|
$this->relationType = $relationType;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.03 bis : si l'utilisateur declare une relation (« depend d'un
|
||||||
|
* distributeur / courtier » via le champ transitoire relationType), la FK
|
||||||
|
* correspondante est obligatoire. Le back ne peut pas deviner cette intention
|
||||||
|
* a partir des seules FK nullable (distributor=null ne distingue pas « pas de
|
||||||
|
* relation » de « relation choisie sans nom »), d'ou relationType qui la porte.
|
||||||
|
* Violation portee sur distributor / broker (champ fautif cote formulaire), de
|
||||||
|
* sorte que useFormErrors la mappe inline sous le bon select (ERP-101).
|
||||||
|
*/
|
||||||
|
#[Assert\Callback]
|
||||||
|
public function validateRelationName(ExecutionContextInterface $context): void
|
||||||
|
{
|
||||||
|
if ('distributeur' === $this->relationType && null === $this->distributor) {
|
||||||
|
$context->buildViolation('Le nom du distributeur est obligatoire.')
|
||||||
|
->atPath('distributor')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('courtier' === $this->relationType && null === $this->broker) {
|
||||||
|
$context->buildViolation('Le nom du courtier est obligatoire.')
|
||||||
|
->atPath('broker')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function isTriageService(): bool
|
public function isTriageService(): bool
|
||||||
{
|
{
|
||||||
return $this->triageService;
|
return $this->triageService;
|
||||||
|
|||||||
@@ -129,6 +129,18 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
#[Groups(['client_address:write'])]
|
#[Groups(['client_address:write'])]
|
||||||
private bool $isBilling = false;
|
private bool $isBilling = false;
|
||||||
|
|
||||||
|
// Adresse Courtier / Distributeur : types autonomes (comme Prospection),
|
||||||
|
// exclusifs de tout autre usage (validateExclusiveAddressTypes + CHECK BDD
|
||||||
|
// chk_client_address_broker_exclusive / chk_client_address_distributor_exclusive).
|
||||||
|
// Lecture portee par le getter + SerializedName (meme pattern que isProspect).
|
||||||
|
#[ORM\Column(name: 'is_broker', options: ['default' => false])]
|
||||||
|
#[Groups(['client_address:write'])]
|
||||||
|
private bool $isBroker = false;
|
||||||
|
|
||||||
|
#[ORM\Column(name: 'is_distributor', options: ['default' => false])]
|
||||||
|
#[Groups(['client_address:write'])]
|
||||||
|
private bool $isDistributor = 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')]
|
#[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'])]
|
||||||
@@ -166,6 +178,15 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private ?string $billingEmail = null;
|
private ?string $billingEmail = null;
|
||||||
|
|
||||||
|
// 2e email de facturation, optionnel (max 2 — pendant du telephone secondaire).
|
||||||
|
// Comme le principal : interdit hors facturation (validateBillingEmailPresence),
|
||||||
|
// mais jamais obligatoire. Normalise en lowercase par le ClientAddressProcessor.
|
||||||
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
|
#[Assert\Email(message: 'L\'email de facturation secondaire n\'est pas valide.')]
|
||||||
|
#[Assert\Length(max: 180, maxMessage: 'L\'email de facturation secondaire ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private ?string $billingEmailSecondary = null;
|
||||||
|
|
||||||
#[ORM\Column(options: ['default' => 0])]
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
#[Groups(['client_address:read', 'client_address:write'])]
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
private int $position = 0;
|
private int $position = 0;
|
||||||
@@ -223,6 +244,48 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Au moins un type d'adresse est obligatoire (Prospection, Livraison ou
|
||||||
|
* Facturation) : une adresse sans aucun drapeau pose n'a pas de sens metier.
|
||||||
|
* La violation est portee sur `isProspect` (meme champ que l'exclusivite) pour
|
||||||
|
* un mapping inline sous le select « Type d'adresse » cote front (ERP-119).
|
||||||
|
*/
|
||||||
|
#[Assert\Callback]
|
||||||
|
public function validateAddressTypeRequired(ExecutionContextInterface $context): void
|
||||||
|
{
|
||||||
|
if (!$this->isProspect && !$this->isDelivery && !$this->isBilling && !$this->isBroker && !$this->isDistributor) {
|
||||||
|
$context->buildViolation('Le type d\'adresse est obligatoire.')
|
||||||
|
->atPath('isProspect')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Courtier et Distributeur sont des types d'adresse AUTONOMES (comme la
|
||||||
|
* Prospection) : exclusifs de tout autre usage (Livraison / Facturation /
|
||||||
|
* Prospection / l'autre type autonome). Mirror applicatif (422) des CHECK
|
||||||
|
* chk_client_address_broker_exclusive / chk_client_address_distributor_exclusive.
|
||||||
|
* Violation portee sur `isProspect` (mappee sous le select « Type d'adresse »).
|
||||||
|
*/
|
||||||
|
#[Assert\Callback]
|
||||||
|
public function validateExclusiveAddressTypes(ExecutionContextInterface $context): void
|
||||||
|
{
|
||||||
|
if ($this->isBroker && ($this->isProspect || $this->isDelivery || $this->isBilling || $this->isDistributor)) {
|
||||||
|
$context->buildViolation('Une adresse Courtier ne peut pas avoir d\'autre type.')
|
||||||
|
->atPath('isProspect')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isDistributor && ($this->isProspect || $this->isDelivery || $this->isBilling || $this->isBroker)) {
|
||||||
|
$context->buildViolation('Une adresse Distributeur ne peut pas avoir d\'autre type.')
|
||||||
|
->atPath('isProspect')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-1.11 : l'email de facturation est obligatoire si l'adresse est de
|
* RG-1.11 : l'email de facturation est obligatoire si l'adresse est de
|
||||||
* facturation, et interdit sinon. Mirror applicatif (422) du CHECK
|
* facturation, et interdit sinon. Mirror applicatif (422) du CHECK
|
||||||
@@ -254,6 +317,16 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
->addViolation()
|
->addViolation()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Le 2e email est OPTIONNEL (jamais requis), mais comme le principal il
|
||||||
|
// n'a de sens que sur une adresse de facturation.
|
||||||
|
$hasSecondaryEmail = null !== $this->billingEmailSecondary && '' !== trim($this->billingEmailSecondary);
|
||||||
|
if (!$this->isBilling && $hasSecondaryEmail) {
|
||||||
|
$context->buildViolation('L\'email de facturation n\'est autorisé que sur une adresse de facturation.')
|
||||||
|
->atPath('billingEmailSecondary')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -343,6 +416,34 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Groups(['client_address:read'])]
|
||||||
|
#[SerializedName('isBroker')]
|
||||||
|
public function isBroker(): bool
|
||||||
|
{
|
||||||
|
return $this->isBroker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsBroker(bool $isBroker): static
|
||||||
|
{
|
||||||
|
$this->isBroker = $isBroker;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Groups(['client_address:read'])]
|
||||||
|
#[SerializedName('isDistributor')]
|
||||||
|
public function isDistributor(): bool
|
||||||
|
{
|
||||||
|
return $this->isDistributor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsDistributor(bool $isDistributor): static
|
||||||
|
{
|
||||||
|
$this->isDistributor = $isDistributor;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCountry(): string
|
public function getCountry(): string
|
||||||
{
|
{
|
||||||
return $this->country;
|
return $this->country;
|
||||||
@@ -415,6 +516,18 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBillingEmailSecondary(): ?string
|
||||||
|
{
|
||||||
|
return $this->billingEmailSecondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBillingEmailSecondary(?string $billingEmailSecondary): static
|
||||||
|
{
|
||||||
|
$this->billingEmailSecondary = $billingEmailSecondary;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPosition(): int
|
public function getPosition(): int
|
||||||
{
|
{
|
||||||
return $this->position;
|
return $this->position;
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
* comptable et la conformite, cf. spec § 2.5 / § 6.1).
|
* comptable et la conformite, cf. spec § 2.5 / § 6.1).
|
||||||
*
|
*
|
||||||
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony au M1
|
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony au M1
|
||||||
* (HP-M2-14 : pas de controle externe banque reelle). Timestampable/Blamable
|
* (HP-M2-14 : pas de controle externe banque reelle), avec controle croise pays
|
||||||
* standard.
|
* BIC/IBAN (ibanPropertyPath). Timestampable/Blamable standard.
|
||||||
*
|
*
|
||||||
* Sous-ressource API (ERP-57, spec § 4.5) — gating comptable renforce :
|
* Sous-ressource API (ERP-57, spec § 4.5) — gating comptable renforce :
|
||||||
* - POST /api/clients/{clientId}/ribs : creation rattachee au client parent
|
* - POST /api/clients/{clientId}/ribs : creation rattachee au client parent
|
||||||
@@ -109,9 +109,15 @@ class ClientRib implements TimestampableInterface, BlamableInterface
|
|||||||
|
|
||||||
// Bic/Iban bornent deja le format (et donc la longueur) : pas de Length
|
// Bic/Iban bornent deja le format (et donc la longueur) : pas de Length
|
||||||
// redondant calee sur la colonne (whitelist du garde-fou ERP-107).
|
// redondant calee sur la colonne (whitelist du garde-fou ERP-107).
|
||||||
|
// ibanPropertyPath : controle croise — le pays du BIC (positions 5-6) doit
|
||||||
|
// correspondre au pays de l'IBAN (positions 1-2). Violation portee sur `bic`.
|
||||||
#[ORM\Column(length: 20)]
|
#[ORM\Column(length: 20)]
|
||||||
#[Assert\NotBlank(message: 'Le BIC est obligatoire.', normalizer: 'trim')]
|
#[Assert\NotBlank(message: 'Le BIC est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Bic(message: 'Le BIC n\'est pas valide.')]
|
#[Assert\Bic(
|
||||||
|
message: 'Le BIC n\'est pas valide.',
|
||||||
|
ibanPropertyPath: 'iban',
|
||||||
|
ibanMessage: 'Le BIC ne correspond pas au pays de l\'IBAN.',
|
||||||
|
)]
|
||||||
#[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;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
||||||
* Timestampable/Blamable (referentiel statique whiteliste dans
|
* Timestampable/Blamable (referentiel statique whiteliste dans
|
||||||
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
||||||
* `client:read:accounting` permet l'embarquement dans la reponse Client.
|
* `client:read:accounting` permet l'embarquement dans la reponse Client ;
|
||||||
|
* `supplier:read:accounting` dans la reponse Fournisseur (M2, ERP-92 — § 4.0).
|
||||||
*/
|
*/
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
@@ -47,15 +48,15 @@ class PaymentDelay
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['payment_delay:read', 'client:read:accounting'])]
|
#[Groups(['payment_delay:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 30)]
|
#[ORM\Column(length: 30)]
|
||||||
#[Groups(['payment_delay:read', 'client:read:accounting'])]
|
#[Groups(['payment_delay:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $code = null;
|
private ?string $code = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['payment_delay:read', 'client:read:accounting'])]
|
#[Groups(['payment_delay:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $label = null;
|
private ?string $label = null;
|
||||||
|
|
||||||
#[ORM\Column(options: ['default' => 0])]
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
||||||
* Timestampable/Blamable (referentiel statique whiteliste dans
|
* Timestampable/Blamable (referentiel statique whiteliste dans
|
||||||
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
||||||
* `client:read:accounting` permet l'embarquement dans la reponse Client.
|
* `client:read:accounting` permet l'embarquement dans la reponse Client ;
|
||||||
|
* `supplier:read:accounting` dans la reponse Fournisseur (M2, ERP-92 — § 4.0).
|
||||||
*/
|
*/
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
@@ -50,15 +51,15 @@ class PaymentType
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['payment_type:read', 'client:read:accounting'])]
|
#[Groups(['payment_type:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 30)]
|
#[ORM\Column(length: 30)]
|
||||||
#[Groups(['payment_type:read', 'client:read:accounting'])]
|
#[Groups(['payment_type:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $code = null;
|
private ?string $code = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['payment_type:read', 'client:read:accounting'])]
|
#[Groups(['payment_type:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $label = null;
|
private ?string $label = null;
|
||||||
|
|
||||||
#[ORM\Column(options: ['default' => 0])]
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
|||||||
@@ -135,9 +135,9 @@ class Supplier implements TimestampableInterface, BlamableInterface
|
|||||||
use TimestampableBlamableTrait;
|
use TimestampableBlamableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-2.10 : seules les categories de ce type sont autorisees sur le
|
* RG-2.10 : seules les categories PORTANT ce type sont autorisees sur le
|
||||||
* fournisseur (entite principale). Miroir de SupplierAddress (ERP-88).
|
* fournisseur (entite principale). Miroir de SupplierAddress (ERP-88).
|
||||||
* S'appuie sur CategoryInterface::getCategoryTypeCode() (pas d'import du
|
* S'appuie sur CategoryInterface::getCategoryTypeCodes() (pas d'import du
|
||||||
* module Catalog — regle ABSOLUE n°1).
|
* module Catalog — regle ABSOLUE n°1).
|
||||||
*/
|
*/
|
||||||
private const string REQUIRED_CATEGORY_TYPE_CODE = 'FOURNISSEUR';
|
private const string REQUIRED_CATEGORY_TYPE_CODE = 'FOURNISSEUR';
|
||||||
@@ -181,7 +181,7 @@ class Supplier 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')]
|
#[Assert\Length(max: 255, maxMessage: 'La liste des concurrents ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||||
private ?string $competitors = null;
|
private ?string $competitors = null;
|
||||||
|
|
||||||
@@ -300,16 +300,17 @@ class Supplier implements TimestampableInterface, BlamableInterface
|
|||||||
* FOURNISSEUR -> sinon 422 avec violation sur le champ `categories`
|
* FOURNISSEUR -> sinon 422 avec violation sur le champ `categories`
|
||||||
* (propertyPath aligne ERP-101, message FR ERP-107). Miroir de
|
* (propertyPath aligne ERP-101, message FR ERP-107). Miroir de
|
||||||
* SupplierAddress::validateCategoryType (ERP-88). S'appuie sur
|
* SupplierAddress::validateCategoryType (ERP-88). S'appuie sur
|
||||||
* CategoryInterface::getCategoryTypeCode() (pas d'import du module Catalog —
|
* CategoryInterface::getCategoryTypeCodes() (multi-type — la categorie est
|
||||||
* regle ABSOLUE n°1). Joue avant la base via la validation API Platform, sur
|
* acceptee des qu'elle PORTE le type FOURNISSEUR ; pas d'import du module
|
||||||
* POST (categories ∈ supplier:write:main) comme sur PATCH.
|
* Catalog, regle ABSOLUE n°1). Joue avant la base via la validation API
|
||||||
|
* Platform, sur POST (categories ∈ supplier:write:main) comme sur PATCH.
|
||||||
*/
|
*/
|
||||||
#[Assert\Callback]
|
#[Assert\Callback]
|
||||||
public function validateCategoryType(ExecutionContextInterface $context): void
|
public function validateCategoryType(ExecutionContextInterface $context): void
|
||||||
{
|
{
|
||||||
foreach ($this->categories as $category) {
|
foreach ($this->categories as $category) {
|
||||||
if ($category instanceof CategoryInterface
|
if ($category instanceof CategoryInterface
|
||||||
&& self::REQUIRED_CATEGORY_TYPE_CODE !== $category->getCategoryTypeCode()) {
|
&& !in_array(self::REQUIRED_CATEGORY_TYPE_CODE, $category->getCategoryTypeCodes(), true)) {
|
||||||
$context->buildViolation('Type de catégorie non autorisé (FOURNISSEUR attendu).')
|
$context->buildViolation('Type de catégorie non autorisé (FOURNISSEUR attendu).')
|
||||||
->atPath('categories')
|
->atPath('categories')
|
||||||
->addViolation()
|
->addViolation()
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ class SupplierAddress implements TimestampableInterface, BlamableInterface
|
|||||||
public const array ADDRESS_TYPES = ['PROSPECT', 'DEPART', 'RENDU'];
|
public const array ADDRESS_TYPES = ['PROSPECT', 'DEPART', 'RENDU'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-2.10 : seules les categories de ce type sont autorisees sur une adresse
|
* RG-2.10 : seules les categories PORTANT ce type sont autorisees sur une
|
||||||
* fournisseur. S'appuie sur CategoryInterface::getCategoryTypeCode() (pas
|
* adresse fournisseur. S'appuie sur CategoryInterface::getCategoryTypeCodes()
|
||||||
* d'import du module Catalog — regle ABSOLUE n°1).
|
* (pas d'import du module Catalog — regle ABSOLUE n°1).
|
||||||
*/
|
*/
|
||||||
private const string REQUIRED_CATEGORY_TYPE_CODE = 'FOURNISSEUR';
|
private const string REQUIRED_CATEGORY_TYPE_CODE = 'FOURNISSEUR';
|
||||||
|
|
||||||
@@ -219,15 +219,16 @@ class SupplierAddress implements TimestampableInterface, BlamableInterface
|
|||||||
* RG-2.10 : toute categorie posee sur une adresse fournisseur doit etre de
|
* RG-2.10 : toute categorie posee sur une adresse fournisseur doit etre de
|
||||||
* type FOURNISSEUR -> sinon 422 avec violation sur le champ `categories`
|
* type FOURNISSEUR -> sinon 422 avec violation sur le champ `categories`
|
||||||
* (propertyPath aligne ERP-101, message FR ERP-107). S'appuie sur
|
* (propertyPath aligne ERP-101, message FR ERP-107). S'appuie sur
|
||||||
* CategoryInterface::getCategoryTypeCode() (pas d'import du module Catalog —
|
* CategoryInterface::getCategoryTypeCodes() (multi-type — la categorie est
|
||||||
* regle ABSOLUE n°1). Joue avant la base via la validation API Platform.
|
* acceptee des qu'elle PORTE le type FOURNISSEUR ; pas d'import du module
|
||||||
|
* Catalog, regle ABSOLUE n°1). Joue avant la base via la validation API Platform.
|
||||||
*/
|
*/
|
||||||
#[Assert\Callback]
|
#[Assert\Callback]
|
||||||
public function validateCategoryType(ExecutionContextInterface $context): void
|
public function validateCategoryType(ExecutionContextInterface $context): void
|
||||||
{
|
{
|
||||||
foreach ($this->categories as $category) {
|
foreach ($this->categories as $category) {
|
||||||
if ($category instanceof CategoryInterface
|
if ($category instanceof CategoryInterface
|
||||||
&& self::REQUIRED_CATEGORY_TYPE_CODE !== $category->getCategoryTypeCode()) {
|
&& !in_array(self::REQUIRED_CATEGORY_TYPE_CODE, $category->getCategoryTypeCodes(), true)) {
|
||||||
$context->buildViolation('Type de catégorie non autorisé (FOURNISSEUR attendu).')
|
$context->buildViolation('Type de catégorie non autorisé (FOURNISSEUR attendu).')
|
||||||
->atPath('categories')
|
->atPath('categories')
|
||||||
->addViolation()
|
->addViolation()
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
* Tout passe par le SupplierRibProcessor (RG-2.08 sur DELETE).
|
* Tout passe par le SupplierRibProcessor (RG-2.08 sur DELETE).
|
||||||
*
|
*
|
||||||
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony (pas de controle
|
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony (pas de controle
|
||||||
* banque reelle). Audite (#[Auditable]) + Timestampable / Blamable.
|
* banque reelle), avec controle croise pays BIC/IBAN (ibanPropertyPath). Audite
|
||||||
|
* (#[Auditable]) + Timestampable / Blamable.
|
||||||
*/
|
*/
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
@@ -105,9 +106,15 @@ class SupplierRib implements TimestampableInterface, BlamableInterface
|
|||||||
|
|
||||||
// Bic/Iban bornent deja le format (et donc la longueur) : pas de Length
|
// Bic/Iban bornent deja le format (et donc la longueur) : pas de Length
|
||||||
// redondant calee sur la colonne (auto-exempte du miroir ERP-107).
|
// redondant calee sur la colonne (auto-exempte du miroir ERP-107).
|
||||||
|
// ibanPropertyPath : controle croise — le pays du BIC (positions 5-6) doit
|
||||||
|
// correspondre au pays de l'IBAN (positions 1-2). Violation portee sur `bic`.
|
||||||
#[ORM\Column(length: 20)]
|
#[ORM\Column(length: 20)]
|
||||||
#[Assert\NotBlank(message: 'Le BIC est obligatoire.', normalizer: 'trim')]
|
#[Assert\NotBlank(message: 'Le BIC est obligatoire.', normalizer: 'trim')]
|
||||||
#[Assert\Bic(message: 'Le BIC n\'est pas valide.')]
|
#[Assert\Bic(
|
||||||
|
message: 'Le BIC n\'est pas valide.',
|
||||||
|
ibanPropertyPath: 'iban',
|
||||||
|
ibanMessage: 'Le BIC ne correspond pas au pays de l\'IBAN.',
|
||||||
|
)]
|
||||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||||
private ?string $bic = null;
|
private ?string $bic = null;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
* Referentiel statique : pas de Timestampable/Blamable (whiteliste dans
|
* Referentiel statique : pas de Timestampable/Blamable (whiteliste dans
|
||||||
* EntitiesAreTimestampableBlamableTest::EXCLUDED, comme CategoryType). Le
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED, comme CategoryType). Le
|
||||||
* groupe `client:read:accounting` permet d'embarquer le mode dans la reponse
|
* groupe `client:read:accounting` permet d'embarquer le mode dans la reponse
|
||||||
* d'un Client (onglet Comptabilite) au lieu d'un IRI.
|
* d'un Client (onglet Comptabilite) au lieu d'un IRI ; `supplier:read:accounting`
|
||||||
|
* fait de meme dans la reponse Fournisseur (M2, ERP-92 — sinon IRI nu, § 4.0).
|
||||||
*/
|
*/
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
operations: [
|
operations: [
|
||||||
@@ -54,15 +55,15 @@ class TvaMode
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['tva_mode:read', 'client:read:accounting'])]
|
#[Groups(['tva_mode:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 30)]
|
#[ORM\Column(length: 30)]
|
||||||
#[Groups(['tva_mode:read', 'client:read:accounting'])]
|
#[Groups(['tva_mode:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $code = null;
|
private ?string $code = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['tva_mode:read', 'client:read:accounting'])]
|
#[Groups(['tva_mode:read', 'client:read:accounting', 'supplier:read:accounting'])]
|
||||||
private ?string $label = null;
|
private ?string $label = null;
|
||||||
|
|
||||||
#[ORM\Column(options: ['default' => 0])]
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
|||||||
@@ -65,4 +65,16 @@ interface SupplierRepositoryInterface
|
|||||||
* @param list<Supplier> $suppliers
|
* @param list<Supplier> $suppliers
|
||||||
*/
|
*/
|
||||||
public function hydrateListCollections(array $suppliers): void;
|
public function hydrateListCollections(array $suppliers): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hydrate en lot la collection `contacts` sur un jeu de fournisseurs DEJA
|
||||||
|
* charges (memes instances via l'identity map). Reservee a l'export XLSX
|
||||||
|
* (§ 4.6) qui a besoin du contact principal : la LISTE paginee n'embarque
|
||||||
|
* pas les contacts (§ 2.12), d'ou une methode dediee plutot qu'une passe
|
||||||
|
* supplementaire dans {@see self::hydrateListCollections()} — on n'impose pas
|
||||||
|
* le cout du chargement des contacts au chemin liste.
|
||||||
|
*
|
||||||
|
* @param list<Supplier> $suppliers
|
||||||
|
*/
|
||||||
|
public function hydrateContacts(array $suppliers): void;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -94,5 +94,6 @@ final class ClientAddressProcessor implements ProcessorInterface
|
|||||||
private function normalize(ClientAddress $address): void
|
private function normalize(ClientAddress $address): void
|
||||||
{
|
{
|
||||||
$address->setBillingEmail($this->normalizer->normalizeEmail($address->getBillingEmail()));
|
$address->setBillingEmail($this->normalizer->normalizeEmail($address->getBillingEmail()));
|
||||||
|
$address->setBillingEmailSecondary($this->normalizer->normalizeEmail($address->getBillingEmailSecondary()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-37
@@ -9,11 +9,8 @@ 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\ClientAccountingCompletenessValidator;
|
||||||
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\CategoryInterface;
|
use App\Shared\Domain\Contract\CategoryInterface;
|
||||||
use App\Shared\Domain\Security\BusinessRoles;
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
@@ -44,8 +41,8 @@ use Symfony\Component\Validator\ConstraintViolationList;
|
|||||||
* 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.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). L'onglet Information est entierement facultatif
|
||||||
* et tout PATCH pour le role Commerciale).
|
* (RG-1.04 retiree : plus d'obligation, y compris pour le role Commerciale).
|
||||||
* 4. Pose / retrait de archivedAt (RG-1.22 true=now, RG-1.23 false=null).
|
* 4. Pose / retrait de archivedAt (RG-1.22 true=now, RG-1.23 false=null).
|
||||||
* 5. Persistance via le persist_processor Doctrine, avec traduction des
|
* 5. Persistance via le persist_processor Doctrine, avec traduction des
|
||||||
* collisions d'unicite en 409 (RG-1.16 doublon de nom ; RG-1.23 conflit de
|
* collisions d'unicite en 409 (RG-1.16 doublon de nom ; RG-1.23 conflit de
|
||||||
@@ -108,7 +105,6 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
||||||
private readonly ProcessorInterface $persistProcessor,
|
private readonly ProcessorInterface $persistProcessor,
|
||||||
private readonly ClientFieldNormalizer $normalizer,
|
private readonly ClientFieldNormalizer $normalizer,
|
||||||
private readonly ClientInformationCompletenessValidator $informationValidator,
|
|
||||||
private readonly ClientAccountingCompletenessValidator $accountingValidator,
|
private readonly ClientAccountingCompletenessValidator $accountingValidator,
|
||||||
private readonly Security $security,
|
private readonly Security $security,
|
||||||
private readonly RequestStack $requestStack,
|
private readonly RequestStack $requestStack,
|
||||||
@@ -121,6 +117,12 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reinitialisation de la memoisation du payload en debut de traitement :
|
||||||
|
// le service est partage (stateful), on repart du corps de LA requete
|
||||||
|
// courante et on n'herite jamais des cles decodees d'une requete passee.
|
||||||
|
$this->decodedContent = null;
|
||||||
|
$this->decodedPayloadKeys = [];
|
||||||
|
|
||||||
$writableKeys = $this->writablePayloadKeys();
|
$writableKeys = $this->writablePayloadKeys();
|
||||||
|
|
||||||
$isArchiveRequest = $this->guardArchive($data, $writableKeys);
|
$isArchiveRequest = $this->guardArchive($data, $writableKeys);
|
||||||
@@ -136,7 +138,6 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
$this->validateDistributorBroker($data);
|
$this->validateDistributorBroker($data);
|
||||||
$this->validateAccountingConsistency($data);
|
$this->validateAccountingConsistency($data);
|
||||||
$this->validateAccountingCompleteness($data);
|
$this->validateAccountingCompleteness($data);
|
||||||
$this->validateInformationCompleteness($data);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
@@ -505,9 +506,9 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
* ce n'est pas une validation d'onglet (edition ponctuelle preservee). bank /
|
* ce n'est pas une validation d'onglet (edition ponctuelle preservee). bank /
|
||||||
* RIB restent geres par validateAccountingConsistency (RG-1.12 / RG-1.13).
|
* RIB restent geres par validateAccountingConsistency (RG-1.12 / RG-1.13).
|
||||||
*
|
*
|
||||||
* Colonnes nullable en base + validateur contextuel (meme parti que RG-1.04) :
|
* Colonnes nullable en base + validateur contextuel : un Assert\NotBlank sur
|
||||||
* un Assert\NotBlank sur l'entite casserait le POST de l'onglet principal, qui
|
* l'entite casserait le POST de l'onglet principal, qui n'envoie aucun champ
|
||||||
* n'envoie aucun champ comptable.
|
* comptable.
|
||||||
*/
|
*/
|
||||||
private function validateAccountingCompleteness(Client $data): void
|
private function validateAccountingCompleteness(Client $data): void
|
||||||
{
|
{
|
||||||
@@ -520,21 +521,6 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
$this->accountingValidator->validate($data);
|
$this->accountingValidator->validate($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.04 (durcie ERP-74) : si l'utilisateur porte le role metier
|
|
||||||
* Commerciale, TOUS les champs de l'onglet Information sont obligatoires sur
|
|
||||||
* POST comme sur TOUT PATCH — independamment des champs reellement envoyes
|
|
||||||
* (plus de condition d'intersection avec INFORMATION_FIELDS). Garantit qu'un
|
|
||||||
* client cree/edite par une Commerciale ne reste jamais avec un onglet
|
|
||||||
* Information incomplet.
|
|
||||||
*/
|
|
||||||
private function validateInformationCompleteness(Client $data): void
|
|
||||||
{
|
|
||||||
if ($this->currentUserIsCommerciale()) {
|
|
||||||
$this->informationValidator->validate($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vrai si au moins une categorie du client porte le code donne. S'appuie sur
|
* Vrai si au moins une categorie du client porte le code donne. S'appuie sur
|
||||||
* CategoryInterface::getCode() (pas d'import de Category — regle ABSOLUE n°1).
|
* CategoryInterface::getCode() (pas d'import de Category — regle ABSOLUE n°1).
|
||||||
@@ -550,21 +536,12 @@ final class ClientProcessor implements ProcessorInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function currentUserIsCommerciale(): bool
|
|
||||||
{
|
|
||||||
$user = $this->security->getUser();
|
|
||||||
|
|
||||||
return $user instanceof BusinessRoleAwareInterface
|
|
||||||
&& $user->hasBusinessRole(BusinessRoles::COMMERCIALE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cles ecrivables effectivement presentes dans le payload : on retire les
|
* Cles ecrivables effectivement presentes dans le payload : on retire les
|
||||||
* cles JSON-LD (@id, @context, @var...) et tout champ non rattache a un
|
* cles JSON-LD (@id, @context, @var...) et tout champ non rattache a un
|
||||||
* groupe d'ecriture connu. C'est la base du 422 d'archivage (RG-1.22) et du
|
* groupe d'ecriture connu. C'est la base du 422 d'archivage (RG-1.22) —
|
||||||
* declenchement conditionnel de RG-1.04 — sans elles, un PATCH
|
* sans elles, un PATCH « representation complete » porteur de @id ferait
|
||||||
* « representation complete » porteur de @id ferait croire a une
|
* croire a une modification multi-onglets.
|
||||||
* modification multi-onglets.
|
|
||||||
*
|
*
|
||||||
* @return list<string>
|
* @return list<string>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -114,6 +114,12 @@ final class SupplierProcessor implements ProcessorInterface
|
|||||||
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reinitialisation de la memoisation du payload en debut de traitement :
|
||||||
|
// le service est partage (stateful), on repart du corps de LA requete
|
||||||
|
// courante et on n'herite jamais des cles decodees d'une requete passee.
|
||||||
|
$this->decodedContent = null;
|
||||||
|
$this->decodedPayloadKeys = [];
|
||||||
|
|
||||||
$writableKeys = $this->writablePayloadKeys();
|
$writableKeys = $this->writablePayloadKeys();
|
||||||
|
|
||||||
$isArchiveRequest = $this->guardArchive($data, $writableKeys);
|
$isArchiveRequest = $this->guardArchive($data, $writableKeys);
|
||||||
|
|||||||
@@ -0,0 +1,296 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Controller;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierContact;
|
||||||
|
use App\Module\Commercial\Domain\Repository\SupplierRepositoryInterface;
|
||||||
|
use App\Shared\Domain\Contract\CategoryInterface;
|
||||||
|
use App\Shared\Domain\Contract\SiteInterface;
|
||||||
|
use App\Shared\Domain\Contract\SpreadsheetExporterInterface;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export XLSX du repertoire fournisseurs (M2, spec-back § 4.6). Jumeau du
|
||||||
|
* {@see ClientExportController} (M1).
|
||||||
|
*
|
||||||
|
* Controller Symfony custom (et non operation API Platform) car il produit un
|
||||||
|
* binaire de fichier, pas une representation Hydra. `priority: 1` est
|
||||||
|
* OBLIGATOIRE sur la route : sans cela API Platform capterait
|
||||||
|
* `/api/suppliers/export.xlsx` comme l'item `GET /api/suppliers/{id}.{_format}`
|
||||||
|
* (id="export", _format="xlsx") — cf. CLAUDE.md « controller custom sous /api ».
|
||||||
|
*
|
||||||
|
* Separation des responsabilites :
|
||||||
|
* - le COMMENT (generation du fichier) est delegue au service Shared
|
||||||
|
* {@see SpreadsheetExporterInterface} — generique, reutilisable, sans metier ;
|
||||||
|
* - le QUOI vit ICI : selection des fournisseurs (memes filtres que
|
||||||
|
* `GET /api/suppliers`, via {@see SupplierRepositoryInterface::createListQueryBuilder()})
|
||||||
|
* et mapping metier des colonnes.
|
||||||
|
*
|
||||||
|
* Colonnes de contact : depuis la suppression du contact inline (ERP-106), elles
|
||||||
|
* sont alimentees par le CONTACT PRINCIPAL du fournisseur — le SupplierContact de
|
||||||
|
* plus petit `position` (decision D2, spec § 4.6).
|
||||||
|
*
|
||||||
|
* La colonne SIREN n'est ajoutee que si l'utilisateur a la permission
|
||||||
|
* `commercial.suppliers.accounting.view` (gating identique a la lecture).
|
||||||
|
*/
|
||||||
|
#[AsController]
|
||||||
|
final class SupplierExportController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'App\Module\Commercial\Infrastructure\Doctrine\DoctrineSupplierRepository')]
|
||||||
|
private readonly SupplierRepositoryInterface $repository,
|
||||||
|
private readonly SpreadsheetExporterInterface $exporter,
|
||||||
|
private readonly Security $security,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route('/api/suppliers/export.xlsx', name: 'commercial_suppliers_export_xlsx', methods: ['GET'], priority: 1)]
|
||||||
|
#[IsGranted('commercial.suppliers.view')]
|
||||||
|
public function __invoke(Request $request): Response
|
||||||
|
{
|
||||||
|
// Memes filtres d'archivage que la vue liste (SupplierProvider) pour que
|
||||||
|
// l'export reflete exactement ce que l'utilisateur voit a l'ecran :
|
||||||
|
// - includeArchived : inclut les archives en plus des actifs ;
|
||||||
|
// - archivedOnly : restreint aux seules archives (prioritaire, cf.
|
||||||
|
// createListQueryBuilder).
|
||||||
|
$includeArchived = $this->readBool($request->query->get('includeArchived'));
|
||||||
|
$archivedOnly = $this->readBool($request->query->get('archivedOnly'));
|
||||||
|
$search = $request->query->getString('search') ?: null;
|
||||||
|
|
||||||
|
// Memes filtres que la vue liste : categoryCode/siteId tolerent une valeur
|
||||||
|
// unique ou une liste (?categoryCode[]=A&siteId[]=1). On lit via all() pour
|
||||||
|
// ne pas lever d'exception sur une valeur scalaire.
|
||||||
|
$query = $request->query->all();
|
||||||
|
$categoryCodes = $this->readStringList($query['categoryCode'] ?? []);
|
||||||
|
$siteIds = $this->readIntList($query['siteId'] ?? []);
|
||||||
|
|
||||||
|
/** @var list<Supplier> $suppliers */
|
||||||
|
$suppliers = $this->repository
|
||||||
|
->createListQueryBuilder($includeArchived, $search, $categoryCodes, $siteIds, $archivedOnly)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
// Hydratation batchee des collections affichees (§ 2.12) : le QB de
|
||||||
|
// selection ne fetch-join pas les to-many. On remplit categories + sites en
|
||||||
|
// lot (colonnes « Catégories » / « Sites »), puis les contacts (colonnes du
|
||||||
|
// contact principal) — chacune en requetes IN bornees, anti N+1.
|
||||||
|
$this->repository->hydrateListCollections($suppliers);
|
||||||
|
$this->repository->hydrateContacts($suppliers);
|
||||||
|
|
||||||
|
$withSiren = $this->security->isGranted('commercial.suppliers.accounting.view');
|
||||||
|
|
||||||
|
$binary = $this->exporter->export(
|
||||||
|
'Répertoire fournisseurs',
|
||||||
|
$this->buildHeaders($withSiren),
|
||||||
|
$this->buildRows($suppliers, $withSiren),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->buildResponse($binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Colonnes de l'export (spec § 4.6). SIREN inseree avant la date de creation,
|
||||||
|
* uniquement si l'utilisateur a accounting.view.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function buildHeaders(bool $withSiren): array
|
||||||
|
{
|
||||||
|
$headers = [
|
||||||
|
'Nom fournisseur',
|
||||||
|
'Contact principal',
|
||||||
|
'Téléphone principal',
|
||||||
|
'Téléphone secondaire',
|
||||||
|
'Email',
|
||||||
|
'Catégories',
|
||||||
|
'Sites',
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($withSiren) {
|
||||||
|
$headers[] = 'SIREN';
|
||||||
|
}
|
||||||
|
|
||||||
|
$headers[] = 'Date de création';
|
||||||
|
|
||||||
|
return $headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<Supplier> $suppliers
|
||||||
|
*
|
||||||
|
* @return iterable<list<null|scalar>>
|
||||||
|
*/
|
||||||
|
private function buildRows(array $suppliers, bool $withSiren): iterable
|
||||||
|
{
|
||||||
|
foreach ($suppliers as $supplier) {
|
||||||
|
$contact = $this->principalContact($supplier);
|
||||||
|
|
||||||
|
$row = [
|
||||||
|
$supplier->getCompanyName(),
|
||||||
|
null !== $contact ? $this->formatContactName($contact) : '',
|
||||||
|
$contact?->getPhonePrimary() ?? '',
|
||||||
|
$contact?->getPhoneSecondary() ?? '',
|
||||||
|
$contact?->getEmail() ?? '',
|
||||||
|
$this->formatCategories($supplier),
|
||||||
|
$this->formatSites($supplier),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($withSiren) {
|
||||||
|
$row[] = $supplier->getSiren();
|
||||||
|
}
|
||||||
|
|
||||||
|
$row[] = $supplier->getCreatedAt()?->format('d/m/Y');
|
||||||
|
|
||||||
|
yield $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contact principal du fournisseur : le SupplierContact de plus petit
|
||||||
|
* `position` (decision D2, spec § 4.6). Null si le fournisseur n'a aucun
|
||||||
|
* contact (les colonnes contact restent vides).
|
||||||
|
*/
|
||||||
|
private function principalContact(Supplier $supplier): ?SupplierContact
|
||||||
|
{
|
||||||
|
$contacts = $supplier->getContacts()->toArray();
|
||||||
|
if ([] === $contacts) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
usort(
|
||||||
|
$contacts,
|
||||||
|
static fn (SupplierContact $a, SupplierContact $b): int => $a->getPosition() <=> $b->getPosition(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $contacts[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Libelle du contact principal « Nom Prénom » (spec § 4.6). Les deux parties
|
||||||
|
* sont optionnelles (RG-2.04 : au moins l'une des deux), d'ou le trim final.
|
||||||
|
*/
|
||||||
|
private function formatContactName(SupplierContact $contact): string
|
||||||
|
{
|
||||||
|
return trim(sprintf('%s %s', $contact->getLastName() ?? '', $contact->getFirstName() ?? ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Libelles des categories du fournisseur, dedupliques, tries, joints par
|
||||||
|
* virgule.
|
||||||
|
*/
|
||||||
|
private function formatCategories(Supplier $supplier): string
|
||||||
|
{
|
||||||
|
$names = [];
|
||||||
|
foreach ($supplier->getCategories() as $category) {
|
||||||
|
// @var CategoryInterface $category
|
||||||
|
$name = $category->getName();
|
||||||
|
if (null !== $name && '' !== $name) {
|
||||||
|
$names[$name] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->joinSorted($names);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Le fournisseur ne porte pas de sites en propre : ils sont rattaches aux
|
||||||
|
* adresses (RG-2.06). La colonne « Sites » agrege donc l'union distincte des
|
||||||
|
* sites de toutes les adresses du fournisseur.
|
||||||
|
*/
|
||||||
|
private function formatSites(Supplier $supplier): string
|
||||||
|
{
|
||||||
|
$names = [];
|
||||||
|
foreach ($supplier->getAddresses() as $address) {
|
||||||
|
foreach ($address->getSites() as $site) {
|
||||||
|
// @var SiteInterface $site
|
||||||
|
$name = $site->getName();
|
||||||
|
if (null !== $name && '' !== $name) {
|
||||||
|
$names[$name] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->joinSorted($names);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, true> $names ensemble de libelles (cles)
|
||||||
|
*/
|
||||||
|
private function joinSorted(array $names): string
|
||||||
|
{
|
||||||
|
$list = array_keys($names);
|
||||||
|
sort($list);
|
||||||
|
|
||||||
|
return implode(', ', $list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildResponse(string $binary): Response
|
||||||
|
{
|
||||||
|
$filename = sprintf('repertoire-fournisseurs-%s.xlsx', new DateTimeImmutable()->format('Ymd'));
|
||||||
|
|
||||||
|
$response = new Response($binary);
|
||||||
|
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||||
|
$response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $filename));
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lit un flag booleen issu des query params. Accepte true / "true" / "1".
|
||||||
|
* Aligne sur SupplierProvider pour un comportement identique a la liste.
|
||||||
|
*/
|
||||||
|
private function readBool(mixed $raw): bool
|
||||||
|
{
|
||||||
|
return is_string($raw) && in_array(strtolower($raw), ['true', '1'], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalise un filtre en liste de chaines (valeur unique ou liste).
|
||||||
|
* Aligne sur SupplierProvider pour un comportement identique a la liste.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function readStringList(mixed $raw): array
|
||||||
|
{
|
||||||
|
$values = is_array($raw) ? $raw : [$raw];
|
||||||
|
|
||||||
|
$out = [];
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (is_string($value) && '' !== trim($value)) {
|
||||||
|
$out[] = trim($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalise un filtre en liste d'identifiants entiers positifs (valeur unique
|
||||||
|
* ou liste). Aligne sur SupplierProvider.
|
||||||
|
*
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
private function readIntList(mixed $raw): array
|
||||||
|
{
|
||||||
|
$values = is_array($raw) ? $raw : [$raw];
|
||||||
|
|
||||||
|
$out = [];
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if ((is_int($value) || (is_string($value) && ctype_digit($value))) && (int) $value > 0) {
|
||||||
|
$out[] = (int) $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -234,7 +234,7 @@ class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
$this->addAddress($services, ['Chatellerault'], '86100', 'Châtellerault', '15 rue du Conseil', isDelivery: true);
|
$this->addAddress($services, ['Chatellerault'], '86100', 'Châtellerault', '15 rue du Conseil', isDelivery: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Onglet Information complet (RG-1.04) ===
|
// === Onglet Information complet (exemple de fiche renseignee) ===
|
||||||
[$holding, $isNew] = $this->ensureClient(
|
[$holding, $isNew] = $this->ensureClient(
|
||||||
$manager,
|
$manager,
|
||||||
companyName: 'Holding Premium Invest',
|
companyName: 'Holding Premium Invest',
|
||||||
|
|||||||
@@ -0,0 +1,525 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\DataFixtures;
|
||||||
|
|
||||||
|
use App\Module\Catalog\Infrastructure\DataFixtures\CategoryFixtures;
|
||||||
|
use App\Module\Commercial\Application\Service\SupplierFieldNormalizer;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Bank;
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentDelay;
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentType;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierAddress;
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierContact;
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierRib;
|
||||||
|
use App\Module\Commercial\Domain\Entity\TvaMode;
|
||||||
|
use App\Module\Sites\Infrastructure\DataFixtures\SitesFixtures;
|
||||||
|
use App\Shared\Domain\Contract\CategoryInterface;
|
||||||
|
use App\Shared\Domain\Contract\SiteInterface;
|
||||||
|
use App\Shared\Domain\Contract\SiteProviderInterface;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use RuntimeException;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixtures dev/test du module Commercial : ~13 fournisseurs de demonstration
|
||||||
|
* couvrant l'ensemble des cas metier RG-2.xx du repertoire fournisseurs (M2),
|
||||||
|
* jumelles des fixtures Client (ERP-68). Theme metier : negoce / recyclage de
|
||||||
|
* metaux (d'ou les champs `bennes` et `triageProvider` sur les adresses).
|
||||||
|
*
|
||||||
|
* Cas pivots couverts (criteres d'acceptation ERP-112) :
|
||||||
|
* - reglement VIREMENT avec banque renseignee (RG-2.07) ;
|
||||||
|
* - reglement LCR avec 1 puis 2 RIB (RG-2.08) ; CHEQUE et NON_SOUMISE sans RIB ;
|
||||||
|
* - adresses multi-types PROSPECT / DEPART / RENDU (RG-2.09) et multi-sites
|
||||||
|
* (86 / 17 / 82, RG-2.06) ; bennes + prestataire de triage ;
|
||||||
|
* - 1 a 3 contacts dont un avec telephone secondaire et un nomme par le seul
|
||||||
|
* nom (RG-2.04) ;
|
||||||
|
* - 2 fournisseurs archives (isArchived + archivedAt) pour l'exclusion de la
|
||||||
|
* liste (RG-2.17) ;
|
||||||
|
* - mono et multi-categories de type FOURNISSEUR (RG-2.10) ;
|
||||||
|
* - onglet Information complet (dont volumeForecast, specifique fournisseur).
|
||||||
|
*
|
||||||
|
* Resolution inter-modules conforme a la regle n°1 (pas d'import direct) :
|
||||||
|
* - categories resolues via le contrat Shared CategoryInterface
|
||||||
|
* (resolve_target_entities -> Category) ;
|
||||||
|
* - sites resolus via le contrat Shared SiteProviderInterface.
|
||||||
|
*
|
||||||
|
* Normalisation : les valeurs sont fournies BRUTES (casse libre, telephones
|
||||||
|
* formates) et normalisees par SupplierFieldNormalizer avant persist, exactement
|
||||||
|
* comme le ferait le SupplierProcessor via l'API (companyName UPPERCASE,
|
||||||
|
* first/last Capitalize, telephones chiffres seuls, emails lowercase).
|
||||||
|
*
|
||||||
|
* Coherence gating comptable (RG-2.16) : les scalaires comptables (siren,
|
||||||
|
* tvaMode, paymentType, bank...) et les RIB ne sont visibles qu'avec
|
||||||
|
* accounting.view. Les donnees sont posees pour que les roles SANS cette
|
||||||
|
* permission (ex. Commerciale) ne voient pas de compta — support des tests
|
||||||
|
* ERP-92 et du golden path front.
|
||||||
|
*
|
||||||
|
* Idempotence : lookup par companyName normalise (coherent avec l'index unique
|
||||||
|
* partiel uq_supplier_company_name_active). Un fournisseur deja present n'est pas
|
||||||
|
* reconstruit (ses sous-collections ne sont pas redupliquees). Rejouable sans
|
||||||
|
* doublon meme si le purger Doctrine est desactive.
|
||||||
|
*
|
||||||
|
* Audit / Blamable : persist hors contexte HTTP -> created_by / updated_by
|
||||||
|
* restent null (« Systeme » cote front), c'est attendu. Les donnees respectent
|
||||||
|
* les CHECK BDD (chk_supplier_contact_name : firstName OU lastName ;
|
||||||
|
* chk_supplier_address_type : PROSPECT | DEPART | RENDU) ET la coherence des
|
||||||
|
* validators d'entite (RG-2.07/2.08 : VIREMENT => banque, LCR => >= 1 RIB).
|
||||||
|
*
|
||||||
|
* Depend de CategoryFixtures (categories FOURNISSEUR), SitesFixtures (sites) et
|
||||||
|
* CommercialReferentialFixtures (referentiels comptables — REUTILISES de M1,
|
||||||
|
* aucune nouvelle table).
|
||||||
|
*
|
||||||
|
* Portee : DONNEES DE DEMONSTRATION (dev uniquement). En environnement `test`,
|
||||||
|
* la fixture ne charge rien : les tests seedent et nettoient leurs propres
|
||||||
|
* fournisseurs et comptent sur une table `supplier` vierge — y injecter 13
|
||||||
|
* fournisseurs de demo casserait les comptages de liste et les cleanups. Meme
|
||||||
|
* garde-fou que ClientFixtures / CategoryFixtures.
|
||||||
|
*/
|
||||||
|
class SupplierFixtures extends Fixture implements DependentFixtureInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Type de categorie exige pour un fournisseur et ses adresses (RG-2.10).
|
||||||
|
* Miroir de Supplier::REQUIRED_CATEGORY_TYPE_CODE (non importable — regle n°1).
|
||||||
|
*/
|
||||||
|
private const string SUPPLIER_CATEGORY_TYPE_CODE = 'FOURNISSEUR';
|
||||||
|
|
||||||
|
/** Cache des categories resolues par nom (evite des requetes repetees). */
|
||||||
|
private array $categoryCache = [];
|
||||||
|
|
||||||
|
/** Cache des sites resolus par nom. */
|
||||||
|
private array $siteCache = [];
|
||||||
|
|
||||||
|
/** ObjectManager courant, capture en debut de load (resolution categories). */
|
||||||
|
private ObjectManager $manager;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly SupplierFieldNormalizer $normalizer,
|
||||||
|
private readonly SiteProviderInterface $siteProvider,
|
||||||
|
#[Autowire('%kernel.environment%')]
|
||||||
|
private readonly string $environment,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, class-string>
|
||||||
|
*/
|
||||||
|
public function getDependencies(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CategoryFixtures::class,
|
||||||
|
SitesFixtures::class,
|
||||||
|
CommercialReferentialFixtures::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
// Donnees de demo : dev uniquement. En test, on laisse la table vierge.
|
||||||
|
if ('test' === $this->environment) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->manager = $manager;
|
||||||
|
|
||||||
|
// === Fournisseur basique — VIREMENT + banque (RG-2.07), compta complete ===
|
||||||
|
[$negoce, $isNew] = $this->ensureSupplier($manager, 'Négoce Métaux Atlantique', ['Négociant']);
|
||||||
|
if ($isNew) {
|
||||||
|
$negoce->setSiren('841611054');
|
||||||
|
$negoce->setAccountNumber('F0001');
|
||||||
|
$negoce->setTvaMode($this->tvaMode($manager, 'FRANCE_VENTES'));
|
||||||
|
$negoce->setNTva('FR12841611054');
|
||||||
|
$negoce->setPaymentDelay($this->paymentDelay($manager, 'J30'));
|
||||||
|
$negoce->setPaymentType($this->paymentType($manager, 'VIREMENT'));
|
||||||
|
$negoce->setBank($this->bank($manager, 'SG'));
|
||||||
|
$this->addContact($negoce, 'Jean', 'Dubois', 'Responsable achats', '05 49 00 00 01', null, 'jean.dubois@negoce-metaux.fr');
|
||||||
|
$this->addAddress($negoce, 'DEPART', ['Chatellerault'], '86100', 'Châtellerault', '12 rue de la Ferraille', bennes: 4, triageProvider: true, categoryNames: ['Négociant']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === LCR avec 1 RIB (RG-2.08) + 2 contacts ===
|
||||||
|
[$coop, $isNew] = $this->ensureSupplier($manager, 'Coopérative Agricole du Sud-Ouest', ['Coopérative']);
|
||||||
|
if ($isNew) {
|
||||||
|
$coop->setSiren('775680459');
|
||||||
|
$coop->setTvaMode($this->tvaMode($manager, 'FRANCE_VENTES'));
|
||||||
|
$coop->setPaymentDelay($this->paymentDelay($manager, 'J15'));
|
||||||
|
$coop->setPaymentType($this->paymentType($manager, 'LCR'));
|
||||||
|
$this->addContact($coop, 'Sophie', 'Marchand', 'Directrice', '05 56 10 20 30', '06 11 22 33 44', 'sophie.marchand@coop-so.fr', 0);
|
||||||
|
$this->addContact($coop, 'Marc', 'Girard', 'Acheteur', '05 56 10 20 31', null, 'marc.girard@coop-so.fr', 1);
|
||||||
|
$this->addAddress($coop, 'RENDU', ['Pommevic'], '82400', 'Pommevic', '8 route des Cooperateurs', bennes: 2);
|
||||||
|
$this->addRib($coop, 'Compte principal', 'BNPAFRPPXXX', 'FR1420041010050500013M02606', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Prospect seul (adresse PROSPECT), compta minimale ===
|
||||||
|
[$producteur, $isNew] = $this->ensureSupplier($manager, 'Producteur Bio Charente', ['Producteur']);
|
||||||
|
if ($isNew) {
|
||||||
|
$this->addContact($producteur, 'Claire', 'Moreau', 'Gérante', '05 49 21 22 23', null, 'claire.moreau@bio-charente.fr');
|
||||||
|
$this->addAddress($producteur, 'PROSPECT', ['Saint-Jean'], '17400', 'Fontenet', '1 chemin des Producteurs');
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Multi-categories M2M + LCR avec 2 RIB + 3 contacts ===
|
||||||
|
[$grossiste, $isNew] = $this->ensureSupplier($manager, 'Grossiste Multi-Métaux', ['Grossiste', 'Négociant']);
|
||||||
|
if ($isNew) {
|
||||||
|
$grossiste->setSiren('552081317');
|
||||||
|
$grossiste->setAccountNumber('F0004');
|
||||||
|
$grossiste->setTvaMode($this->tvaMode($manager, 'FRANCE_VENTES'));
|
||||||
|
$grossiste->setNTva('FR45552081317');
|
||||||
|
$grossiste->setPaymentDelay($this->paymentDelay($manager, 'J30'));
|
||||||
|
$grossiste->setPaymentType($this->paymentType($manager, 'LCR'));
|
||||||
|
$this->addContact($grossiste, 'Thomas', 'Petit', 'Directeur des achats', '05 56 31 32 33', '06 01 02 03 04', 'thomas.petit@grossiste-mm.fr', 0);
|
||||||
|
$this->addContact($grossiste, 'Julie', 'Roux', 'Assistante commerciale', '05 56 31 32 34', null, 'julie.roux@grossiste-mm.fr', 1);
|
||||||
|
$this->addContact($grossiste, 'Hélène', 'Faure', 'Logistique', '05 56 31 32 35', null, 'helene.faure@grossiste-mm.fr', 2);
|
||||||
|
$this->addAddress($grossiste, 'DEPART', ['Chatellerault'], '86100', 'Châtellerault', '20 zone des Activités', streetComplement: 'Bâtiment C', bennes: 6, triageProvider: true, categoryNames: ['Grossiste', 'Négociant']);
|
||||||
|
$this->addRib($grossiste, 'Compte principal', 'BNPAFRPPXXX', 'FR7630006000011234567890189', 0);
|
||||||
|
$this->addRib($grossiste, 'Compte secondaire', 'SOGEFRPPXXX', 'FR7630001007941234567890185', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === VIREMENT + banque, TVA intracom (importateur), multi-sites sur l'adresse ===
|
||||||
|
[$import, $isNew] = $this->ensureSupplier($manager, 'Import Recyclage International', ['Importateur']);
|
||||||
|
if ($isNew) {
|
||||||
|
$import->setSiren('409512012');
|
||||||
|
$import->setTvaMode($this->tvaMode($manager, 'INTRACOM_VENTES'));
|
||||||
|
$import->setNTva('FR90409512012');
|
||||||
|
$import->setPaymentDelay($this->paymentDelay($manager, 'J30'));
|
||||||
|
$import->setPaymentType($this->paymentType($manager, 'VIREMENT'));
|
||||||
|
$import->setBank($this->bank($manager, 'CIC'));
|
||||||
|
$this->addContact($import, 'Paul', 'Garnier', 'Import manager', '05 56 44 55 66', null, 'paul.garnier@import-recyclage.fr', 0);
|
||||||
|
$this->addContact($import, null, 'Bernard', 'Douanes', '05 56 44 55 67', null, 'douanes@import-recyclage.fr', 1);
|
||||||
|
$this->addAddress($import, 'RENDU', ['Pommevic', 'Saint-Jean'], '82400', 'Pommevic', '3 quai des Importateurs', bennes: 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Multi-adresses PROSPECT / DEPART / RENDU (RG-2.09) + VIREMENT/banque ===
|
||||||
|
[$ferrailleur, $isNew] = $this->ensureSupplier($manager, 'Ferrailleur Grand Ouest', ['Négociant']);
|
||||||
|
if ($isNew) {
|
||||||
|
$ferrailleur->setSiren('732829320');
|
||||||
|
$ferrailleur->setTvaMode($this->tvaMode($manager, 'FRANCE_VENTES'));
|
||||||
|
$ferrailleur->setPaymentDelay($this->paymentDelay($manager, 'A_RECEPTION'));
|
||||||
|
$ferrailleur->setPaymentType($this->paymentType($manager, 'VIREMENT'));
|
||||||
|
$ferrailleur->setBank($this->bank($manager, 'CA'));
|
||||||
|
$this->addContact($ferrailleur, 'Olivier', 'Renard', 'Responsable site', '05 49 61 62 63', null, 'olivier.renard@ferrailleur-go.fr', 0);
|
||||||
|
$this->addContact($ferrailleur, 'Nadia', 'Benali', 'Pesée', '05 49 61 62 64', null, 'nadia.benali@ferrailleur-go.fr', 1);
|
||||||
|
// Prospect (site en cours de demarchage).
|
||||||
|
$this->addAddress($ferrailleur, 'PROSPECT', ['Chatellerault'], '86100', 'Châtellerault', '5 avenue de la Prospection', position: 0);
|
||||||
|
// Depart (collecte) multi-sites avec bennes + triage.
|
||||||
|
$this->addAddress($ferrailleur, 'DEPART', ['Saint-Jean', 'Pommevic'], '17400', 'Fontenet', '4 rue de la Collecte', bennes: 5, triageProvider: true, categoryNames: ['Négociant'], position: 1);
|
||||||
|
// Rendu (livraison).
|
||||||
|
$this->addAddress($ferrailleur, 'RENDU', ['Pommevic'], '82400', 'Pommevic', '7 boulevard du Rendu', bennes: 3, position: 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Onglet Information complet (dont volumeForecast) + VIREMENT/banque ===
|
||||||
|
[$holding, $isNew] = $this->ensureSupplier($manager, 'Holding Recyclage Premium', ['Importateur']);
|
||||||
|
if ($isNew) {
|
||||||
|
$holding->setDescription('Holding de recyclage diversifiée, présente sur le Grand Sud-Ouest.');
|
||||||
|
$holding->setCompetitors('Groupe Atlantique Recyclage, Sud Métaux');
|
||||||
|
$holding->setFoundedAt(new DateTimeImmutable('2008-09-01'));
|
||||||
|
$holding->setEmployeesCount(180);
|
||||||
|
$holding->setRevenueAmount('24500000.00');
|
||||||
|
$holding->setDirectorName('Antoine Lefèvre');
|
||||||
|
$holding->setProfitAmount('1850000.00');
|
||||||
|
$holding->setVolumeForecast(120000);
|
||||||
|
$holding->setSiren('318471925');
|
||||||
|
$holding->setAccountNumber('F0007');
|
||||||
|
$holding->setTvaMode($this->tvaMode($manager, 'FRANCE_VENTES'));
|
||||||
|
$holding->setNTva('FR33318471925');
|
||||||
|
$holding->setPaymentDelay($this->paymentDelay($manager, 'J30'));
|
||||||
|
$holding->setPaymentType($this->paymentType($manager, 'VIREMENT'));
|
||||||
|
$holding->setBank($this->bank($manager, 'SG'));
|
||||||
|
$this->addContact($holding, 'Antoine', 'Lefèvre', 'PDG', '05 56 51 52 53', null, 'antoine.lefevre@holding-recyclage.fr');
|
||||||
|
$this->addAddress($holding, 'DEPART', ['Chatellerault'], '86100', 'Châtellerault', '1 allée des Investisseurs', bennes: 5, triageProvider: true, categoryNames: ['Importateur']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Coop minimale — contact par le seul nom (RG-2.04), sans compta ===
|
||||||
|
[$coopMin, $isNew] = $this->ensureSupplier($manager, 'Coop Métaux Réunis', ['Coopérative']);
|
||||||
|
if ($isNew) {
|
||||||
|
$this->addContact($coopMin, null, 'Caron', 'Président', '05 49 81 82 83', null, 'president@coop-metaux-reunis.fr');
|
||||||
|
$this->addAddress($coopMin, 'DEPART', ['Saint-Jean'], '17400', 'Fontenet', '6 chemin du Village');
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Reglement CHEQUE (sans banque ni RIB requis) ===
|
||||||
|
[$petit, $isNew] = $this->ensureSupplier($manager, 'Petit Négoce Local', ['Négociant']);
|
||||||
|
if ($isNew) {
|
||||||
|
$petit->setTvaMode($this->tvaMode($manager, 'FRANCE_VENTES'));
|
||||||
|
$petit->setPaymentDelay($this->paymentDelay($manager, 'A_RECEPTION'));
|
||||||
|
$petit->setPaymentType($this->paymentType($manager, 'CHEQUE'));
|
||||||
|
$this->addContact($petit, 'Luc', 'Martin', 'Gérant', '05 56 71 72 73', null, 'luc.martin@petit-negoce.fr');
|
||||||
|
$this->addAddress($petit, 'RENDU', ['Chatellerault'], '86100', 'Châtellerault', '15 rue du Commerce');
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Reglement NON_SOUMISE + adresse multi-sites avec triage ===
|
||||||
|
[$recup, $isNew] = $this->ensureSupplier($manager, 'Récupération Métaux Express', ['Grossiste']);
|
||||||
|
if ($isNew) {
|
||||||
|
$recup->setSiren('490212019');
|
||||||
|
$recup->setTvaMode($this->tvaMode($manager, 'FRANCE_VENTES'));
|
||||||
|
$recup->setPaymentDelay($this->paymentDelay($manager, 'J15'));
|
||||||
|
$recup->setPaymentType($this->paymentType($manager, 'NON_SOUMISE'));
|
||||||
|
$this->addContact($recup, 'Marie', 'Lemoine', 'Responsable', '05 49 77 88 99', null, 'marie.lemoine@recup-express.fr', 0);
|
||||||
|
$this->addContact($recup, 'Pierre', 'Durand', 'Chauffeur', '05 49 77 88 98', null, 'pierre.durand@recup-express.fr', 1);
|
||||||
|
$this->addAddress($recup, 'DEPART', ['Saint-Jean', 'Chatellerault'], '17400', 'Fontenet', '10 zone industrielle', bennes: 7, triageProvider: true, categoryNames: ['Grossiste']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Centre de tri — focus bennes/triage + multi-categories ===
|
||||||
|
[$centre, $isNew] = $this->ensureSupplier($manager, 'Centre de Tri Sud', ['Producteur', 'Coopérative']);
|
||||||
|
if ($isNew) {
|
||||||
|
$centre->setPaymentDelay($this->paymentDelay($manager, 'A_RECEPTION'));
|
||||||
|
$this->addContact($centre, 'Camille', 'Faure', 'Chef de centre', '05 56 91 92 93', null, 'camille.faure@centre-tri-sud.fr');
|
||||||
|
$this->addAddress($centre, 'DEPART', ['Pommevic'], '82400', 'Pommevic', '2 route du Tri', bennes: 12, triageProvider: true, categoryNames: ['Producteur']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Fournisseur archive #1 (RG-2.17) ===
|
||||||
|
[$ancien, $isNew] = $this->ensureSupplier($manager, 'Ancien Fournisseur Fermé', ['Producteur'], isArchived: true);
|
||||||
|
if ($isNew) {
|
||||||
|
$this->addContact($ancien, null, 'Lambert', 'Ancien contact', '05 49 99 99 99', null, 'contact@ancien-fournisseur.fr');
|
||||||
|
$this->addAddress($ancien, 'DEPART', ['Chatellerault'], '86100', 'Châtellerault', '99 rue Fermée');
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Fournisseur archive #2 (RG-2.17) ===
|
||||||
|
[$disparu, $isNew] = $this->ensureSupplier($manager, 'Négoce Disparu', ['Grossiste'], isArchived: true);
|
||||||
|
if ($isNew) {
|
||||||
|
$this->addContact($disparu, 'Gérard', 'Blanc', 'Ex-gérant', '05 56 00 00 00', null, 'gerard.blanc@negoce-disparu.fr');
|
||||||
|
$this->addAddress($disparu, 'RENDU', ['Saint-Jean'], '17400', 'Fontenet', '0 impasse Oubliée');
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cree un fournisseur (base normalisee + categories de type FOURNISSEUR)
|
||||||
|
* s'il n'existe pas encore, sinon retourne l'existant. Retourne
|
||||||
|
* [Supplier, isNew] : isNew=false bloque la reconstruction des
|
||||||
|
* sous-collections (idempotence sans doublon).
|
||||||
|
*
|
||||||
|
* @param list<string> $categoryNames categories de type FOURNISSEUR (RG-2.10)
|
||||||
|
*
|
||||||
|
* @return array{0: Supplier, 1: bool}
|
||||||
|
*/
|
||||||
|
private function ensureSupplier(
|
||||||
|
ObjectManager $manager,
|
||||||
|
string $companyName,
|
||||||
|
array $categoryNames,
|
||||||
|
bool $isArchived = false,
|
||||||
|
): array {
|
||||||
|
$normalizedName = (string) $this->normalizer->normalizeCompanyName($companyName);
|
||||||
|
|
||||||
|
$existing = $manager->getRepository(Supplier::class)->findOneBy(['companyName' => $normalizedName]);
|
||||||
|
if ($existing instanceof Supplier) {
|
||||||
|
return [$existing, false];
|
||||||
|
}
|
||||||
|
|
||||||
|
$supplier = new Supplier();
|
||||||
|
$supplier->setCompanyName($normalizedName);
|
||||||
|
|
||||||
|
foreach ($categoryNames as $categoryName) {
|
||||||
|
$supplier->addCategory($this->category($manager, $categoryName));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isArchived) {
|
||||||
|
$supplier->setIsArchived(true);
|
||||||
|
$supplier->setArchivedAt(new DateTimeImmutable());
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->persist($supplier);
|
||||||
|
|
||||||
|
return [$supplier, true];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un contact normalise au fournisseur (cascade persist via
|
||||||
|
* Supplier.contacts). Au moins firstName OU lastName est toujours fourni
|
||||||
|
* (RG-2.04, chk_supplier_contact_name).
|
||||||
|
*/
|
||||||
|
private function addContact(
|
||||||
|
Supplier $supplier,
|
||||||
|
?string $firstName,
|
||||||
|
?string $lastName,
|
||||||
|
?string $jobTitle,
|
||||||
|
?string $phonePrimary,
|
||||||
|
?string $phoneSecondary,
|
||||||
|
?string $email,
|
||||||
|
int $position = 0,
|
||||||
|
): void {
|
||||||
|
$contact = new SupplierContact();
|
||||||
|
$contact->setFirstName($this->normalizer->normalizePersonName($firstName));
|
||||||
|
$contact->setLastName($this->normalizer->normalizePersonName($lastName));
|
||||||
|
$contact->setJobTitle($jobTitle);
|
||||||
|
$contact->setPhonePrimary($this->normalizer->normalizePhone($phonePrimary));
|
||||||
|
$contact->setPhoneSecondary($this->normalizer->normalizePhone($phoneSecondary));
|
||||||
|
$contact->setEmail($this->normalizer->normalizeEmail($email));
|
||||||
|
$contact->setPosition($position);
|
||||||
|
|
||||||
|
$supplier->addContact($contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute une adresse au fournisseur (cascade persist via Supplier.addresses).
|
||||||
|
* Le type d'adresse est exclusif (PROSPECT | DEPART | RENDU — RG-2.09,
|
||||||
|
* chk_supplier_address_type) ; au moins un site est rattache (RG-2.06) ; les
|
||||||
|
* categories d'adresse sont de type FOURNISSEUR (RG-2.10).
|
||||||
|
*
|
||||||
|
* @param list<string> $siteNames au moins un site (RG-2.06)
|
||||||
|
* @param list<string> $categoryNames categories de type FOURNISSEUR (RG-2.10)
|
||||||
|
*/
|
||||||
|
private function addAddress(
|
||||||
|
Supplier $supplier,
|
||||||
|
string $addressType,
|
||||||
|
array $siteNames,
|
||||||
|
string $postalCode,
|
||||||
|
string $city,
|
||||||
|
string $street,
|
||||||
|
?string $streetComplement = null,
|
||||||
|
?int $bennes = null,
|
||||||
|
bool $triageProvider = false,
|
||||||
|
array $categoryNames = [],
|
||||||
|
int $position = 0,
|
||||||
|
): void {
|
||||||
|
$address = new SupplierAddress();
|
||||||
|
$address->setAddressType($addressType);
|
||||||
|
$address->setPostalCode($postalCode);
|
||||||
|
$address->setCity($city);
|
||||||
|
$address->setStreet($street);
|
||||||
|
$address->setStreetComplement($streetComplement);
|
||||||
|
$address->setBennes($bennes);
|
||||||
|
$address->setTriageProvider($triageProvider);
|
||||||
|
$address->setPosition($position);
|
||||||
|
|
||||||
|
foreach ($siteNames as $siteName) {
|
||||||
|
$address->addSite($this->site($siteName));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($categoryNames as $categoryName) {
|
||||||
|
$address->addCategory($this->category($this->manager, $categoryName));
|
||||||
|
}
|
||||||
|
|
||||||
|
$supplier->addAddress($address);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un RIB au fournisseur (cascade persist via Supplier.ribs). IBAN/BIC
|
||||||
|
* valides (Assert\Iban/Bic non rejouee sur persist direct mais donnees
|
||||||
|
* coherentes pour le golden path / les tests).
|
||||||
|
*/
|
||||||
|
private function addRib(Supplier $supplier, string $label, string $bic, string $iban, int $position = 0): void
|
||||||
|
{
|
||||||
|
$rib = new SupplierRib();
|
||||||
|
$rib->setLabel($label);
|
||||||
|
$rib->setBic($bic);
|
||||||
|
$rib->setIban($iban);
|
||||||
|
$rib->setPosition($position);
|
||||||
|
|
||||||
|
$supplier->addRib($rib);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resout une categorie par son nom via le contrat Shared CategoryInterface
|
||||||
|
* (resolve_target_entities -> Category), sans importer le module Catalog
|
||||||
|
* (regle n°1). Mise en cache par nom.
|
||||||
|
*/
|
||||||
|
private function category(ObjectManager $manager, string $name): CategoryInterface
|
||||||
|
{
|
||||||
|
if (isset($this->categoryCache[$name])) {
|
||||||
|
return $this->categoryCache[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-2.10 : on garde la categorie des qu'elle PORTE le type FOURNISSEUR
|
||||||
|
// (multi-type depuis le passage en ManyToMany). Le nom etant desormais
|
||||||
|
// unique GLOBALEMENT parmi les actifs, le lookup par `name` renvoie au
|
||||||
|
// plus une categorie, mais on conserve la verification du type pour
|
||||||
|
// ecarter un homonyme qui ne porterait pas FOURNISSEUR. Le filtre type
|
||||||
|
// est porte cote PHP (findBy ne sait pas filtrer la collection categoryTypes).
|
||||||
|
$candidates = $manager->getRepository(CategoryInterface::class)->findBy([
|
||||||
|
'name' => $name,
|
||||||
|
'deletedAt' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($candidates as $candidate) {
|
||||||
|
if ($candidate instanceof CategoryInterface
|
||||||
|
&& in_array(self::SUPPLIER_CATEGORY_TYPE_CODE, $candidate->getCategoryTypeCodes(), true)) {
|
||||||
|
return $this->categoryCache[$name] = $candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'Categorie FOURNISSEUR "%s" introuvable : CategoryFixtures doit tourner avant SupplierFixtures.',
|
||||||
|
$name,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resout un site par son nom via le contrat Shared SiteProviderInterface,
|
||||||
|
* sans importer le module Sites (regle n°1). Mise en cache par nom.
|
||||||
|
*/
|
||||||
|
private function site(string $name): SiteInterface
|
||||||
|
{
|
||||||
|
if (isset($this->siteCache[$name])) {
|
||||||
|
return $this->siteCache[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
$site = $this->siteProvider->findByName($name);
|
||||||
|
|
||||||
|
if (!$site instanceof SiteInterface) {
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'Site "%s" introuvable : SitesFixtures doit tourner avant SupplierFixtures.',
|
||||||
|
$name,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->siteCache[$name] = $site;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function tvaMode(ObjectManager $manager, string $code): TvaMode
|
||||||
|
{
|
||||||
|
$mode = $manager->getRepository(TvaMode::class)->findOneBy(['code' => $code]);
|
||||||
|
|
||||||
|
if (!$mode instanceof TvaMode) {
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'TvaMode "%s" introuvable : CommercialReferentialFixtures doit tourner avant SupplierFixtures.',
|
||||||
|
$code,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function paymentDelay(ObjectManager $manager, string $code): PaymentDelay
|
||||||
|
{
|
||||||
|
$delay = $manager->getRepository(PaymentDelay::class)->findOneBy(['code' => $code]);
|
||||||
|
|
||||||
|
if (!$delay instanceof PaymentDelay) {
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'PaymentDelay "%s" introuvable : CommercialReferentialFixtures doit tourner avant SupplierFixtures.',
|
||||||
|
$code,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function paymentType(ObjectManager $manager, string $code): PaymentType
|
||||||
|
{
|
||||||
|
$type = $manager->getRepository(PaymentType::class)->findOneBy(['code' => $code]);
|
||||||
|
|
||||||
|
if (!$type instanceof PaymentType) {
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'PaymentType "%s" introuvable : CommercialReferentialFixtures doit tourner avant SupplierFixtures.',
|
||||||
|
$code,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function bank(ObjectManager $manager, string $code): Bank
|
||||||
|
{
|
||||||
|
$bank = $manager->getRepository(Bank::class)->findOneBy(['code' => $code]);
|
||||||
|
|
||||||
|
if (!$bank instanceof Bank) {
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'Bank "%s" introuvable : CommercialReferentialFixtures doit tourner avant SupplierFixtures.',
|
||||||
|
$code,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bank;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,6 +102,31 @@ class DoctrineSupplierRepository extends ServiceEntityRepository implements Supp
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hydrateContacts(array $suppliers): void
|
||||||
|
{
|
||||||
|
$ids = [];
|
||||||
|
foreach ($suppliers as $supplier) {
|
||||||
|
$id = $supplier->getId();
|
||||||
|
if (null !== $id) {
|
||||||
|
$ids[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ([] === $ids) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Une seule requete IN bornee : remplit la collection `contacts` des MEMES
|
||||||
|
// instances Supplier (identity map). Tri par position pour que le « contact
|
||||||
|
// principal » (plus petit position) soit deterministe a l'export (§ 4.6).
|
||||||
|
$this->createQueryBuilder('s')
|
||||||
|
->leftJoin('s.contacts', 'sc')->addSelect('sc')
|
||||||
|
->where('s.id IN (:ids)')->setParameter('ids', $ids)
|
||||||
|
->orderBy('sc.position', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recherche fuzzy insensible a la casse sur companyName ET sur les contacts
|
* Recherche fuzzy insensible a la casse sur companyName ET sur les contacts
|
||||||
* lies (firstName / lastName / email) — decision D1, refonte-contact (§ 4.1).
|
* lies (firstName / lastName / email) — decision D1, refonte-contact (§ 4.1).
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ final class RbacSeeder
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Codes des roles metier (snake_case, regex Role respectee). `commerciale`
|
* Codes des roles metier (snake_case, regex Role respectee). `commerciale`
|
||||||
* reference la constante Shared deja consommee par le ClientProcessor
|
* reference la constante Shared pour eviter tout drift : un seul litteral
|
||||||
* (RG-1.04) pour eviter tout drift : un seul litteral pour ce code.
|
* pour ce code.
|
||||||
*/
|
*/
|
||||||
public const string ROLE_BUREAU = 'bureau';
|
public const string ROLE_BUREAU = 'bureau';
|
||||||
public const string ROLE_COMPTA = 'compta';
|
public const string ROLE_COMPTA = 'compta';
|
||||||
|
|||||||
@@ -344,8 +344,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Busines
|
|||||||
/**
|
/**
|
||||||
* Implemente BusinessRoleAwareInterface : vrai si l'un des roles RBAC
|
* Implemente BusinessRoleAwareInterface : vrai si l'un des roles RBAC
|
||||||
* rattaches porte le code donne. Permet aux modules tiers de detecter un
|
* rattaches porte le code donne. Permet aux modules tiers de detecter un
|
||||||
* role metier (ex: `commerciale` pour RG-1.04 du M1 Clients) sans importer
|
* role metier (ex: `commerciale`) sans importer cette classe. Comparaison
|
||||||
* cette classe. Comparaison stricte sur Role::code.
|
* stricte sur Role::code.
|
||||||
*/
|
*/
|
||||||
public function hasBusinessRole(string $roleCode): bool
|
public function hasBusinessRole(string $roleCode): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ namespace App\Shared\Domain\Contract;
|
|||||||
* App\Shared\Domain\Security\BusinessRoles).
|
* App\Shared\Domain\Security\BusinessRoles).
|
||||||
*
|
*
|
||||||
* Implementee par App\Module\Core\Domain\Entity\User. Permet a un module tiers
|
* Implementee par App\Module\Core\Domain\Entity\User. Permet a un module tiers
|
||||||
* (ex: Commercial — RG-1.04, completude Information pour le role Commerciale)
|
|
||||||
* de raisonner sur les roles metier via Security::getUser() sans importer User
|
* de raisonner sur les roles metier via Security::getUser() sans importer User
|
||||||
* (regle ABSOLUE n°1 : pas d'import inter-modules).
|
* (regle ABSOLUE n°1 : pas d'import inter-modules).
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,10 +35,14 @@ interface CategoryInterface
|
|||||||
public function getCode(): ?string;
|
public function getCode(): ?string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Code du type de categorie rattache (CategoryType::code), ou null si la
|
* Codes des types de categorie rattaches (CategoryType::code), tableau vide
|
||||||
* categorie n'a pas de type. Depuis ERP-78, le modele n'a plus qu'un seul
|
* si aucun. Depuis le passage en ManyToMany, une categorie peut porter
|
||||||
* type (CLIENT) : le filtrage metier passe desormais par getCode() ci-dessus.
|
* plusieurs types : un module tiers teste l'appartenance via
|
||||||
* Conserve pour l'affichage / la retrocompatibilite.
|
* `in_array($code, $category->getCategoryTypeCodes(), true)`. Pilote, cote
|
||||||
|
* M2 Commercial, la RG-2.10 (une categorie de fournisseur doit etre de type
|
||||||
|
* FOURNISSEUR).
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
*/
|
*/
|
||||||
public function getCategoryTypeCode(): ?string;
|
public function getCategoryTypeCodes(): array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ namespace App\Shared\Domain\Security;
|
|||||||
* Distincts des roles SYSTEME (cf. App\Module\Core\Domain\Security\SystemRoles :
|
* Distincts des roles SYSTEME (cf. App\Module\Core\Domain\Security\SystemRoles :
|
||||||
* `admin` / `user`). Un role metier porte une intention fonctionnelle (poste de
|
* `admin` / `user`). Un role metier porte une intention fonctionnelle (poste de
|
||||||
* travail) et conditionne certaines regles de gestion au-dela des permissions
|
* travail) et conditionne certaines regles de gestion au-dela des permissions
|
||||||
* RBAC pures — ex : RG-1.04 du M1 Clients rend l'onglet Information obligatoire
|
* RBAC pures (Commerciale et Bureau partagent par ex. les memes permissions
|
||||||
* pour le seul role Commerciale, alors que Commerciale et Bureau partagent les
|
* commercial.clients.view + manage mais peuvent porter des regles de gestion
|
||||||
* memes permissions (commercial.clients.view + manage, cf. spec-back M1 § 5.2).
|
* propres au poste). NB : l'ancienne RG-1.04 du M1 (« Information obligatoire
|
||||||
|
* pour Commerciale ») a ete retiree — l'onglet Information est facultatif pour
|
||||||
|
* tous ; la machinerie de role metier reste disponible pour de futures regles.
|
||||||
*
|
*
|
||||||
* Ces constantes vivent dans Shared (et non dans un module) pour que :
|
* Ces constantes vivent dans Shared (et non dans un module) pour que :
|
||||||
* - le seed des roles cote Core (ERP-74) reference le meme code sans importer
|
* - le seed des roles cote Core (ERP-74) reference le meme code sans importer
|
||||||
@@ -24,14 +26,14 @@ namespace App\Shared\Domain\Security;
|
|||||||
* Coordination stack M1 :
|
* Coordination stack M1 :
|
||||||
* - ERP-74 seede le role `commerciale` avec ce code exact.
|
* - ERP-74 seede le role `commerciale` avec ce code exact.
|
||||||
* - ERP-59 / ERP-60 (declaration RBAC + tests personas) le reutilisent.
|
* - ERP-59 / ERP-60 (declaration RBAC + tests personas) le reutilisent.
|
||||||
* - ERP-55 (ici) ne fait que le REFERENCER : tant qu'aucun user ne porte le
|
* - ERP-55 le referencait pour la completude Information (M1 RG-1.04), regle
|
||||||
* role `commerciale`, la validation de completude Information reste dormante.
|
* depuis retiree ; le code reste utilise par le seed RBAC et les personas.
|
||||||
*/
|
*/
|
||||||
final class BusinessRoles
|
final class BusinessRoles
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Role metier « Commerciale » — code de Role RBAC (champ Role::code,
|
* Role metier « Commerciale » — code de Role RBAC (champ Role::code,
|
||||||
* snake_case impose par la regex Role). Conditionne RG-1.04.
|
* snake_case impose par la regex Role).
|
||||||
*/
|
*/
|
||||||
public const string COMMERCIALE = 'commerciale';
|
public const string COMMERCIALE = 'commerciale';
|
||||||
|
|
||||||
|
|||||||
@@ -50,11 +50,10 @@ final class ColumnCommentsCatalog
|
|||||||
],
|
],
|
||||||
|
|
||||||
'category' => [
|
'category' => [
|
||||||
'_table' => 'Categories M0 — referentiel type par category_type, soft-delete via deleted_at, unicite (LOWER(name), category_type_id) parmi les actifs.',
|
'_table' => 'Categories — referentiel multi-types via la jonction category_category_type, soft-delete via deleted_at, unicite LOWER(name) GLOBALE parmi les actifs (uq_category_name_active).',
|
||||||
'id' => 'Identifiant interne auto-incremente.',
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
'name' => 'Libelle de la categorie (≤ 120 caracteres) — unique par type parmi les actifs (RG-1.06).',
|
'name' => 'Libelle de la categorie (≤ 120 caracteres) — unique GLOBALEMENT parmi les actifs (RG-1.07, uq_category_name_active).',
|
||||||
'code' => 'Code technique stable (slug MAJUSCULE du nom, ≤ 50) — unique parmi les actifs (uq_category_code). Fige a la creation. DISTRIBUTEUR/COURTIER pilotent RG-1.03/1.29.',
|
'code' => 'Code technique stable (slug MAJUSCULE du nom, ≤ 50) — unique parmi les actifs (uq_category_code). Fige a la creation. DISTRIBUTEUR/COURTIER pilotent RG-1.03/1.29.',
|
||||||
'category_type_id' => 'Reference au type de la categorie — FK -> category_type.id, ON DELETE RESTRICT (un type ne peut etre supprime tant qu il a des categories).',
|
|
||||||
'deleted_at' => 'Horodatage UTC du soft-delete (archivage logique) — null si la categorie est active.',
|
'deleted_at' => 'Horodatage UTC du soft-delete (archivage logique) — null si la categorie est active.',
|
||||||
] + self::timestampableBlamableComments(),
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
@@ -65,6 +64,12 @@ final class ColumnCommentsCatalog
|
|||||||
'label' => 'Libelle affichable du type (FR, ≤ 120 caracteres).',
|
'label' => 'Libelle affichable du type (FR, ≤ 120 caracteres).',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'category_category_type' => [
|
||||||
|
'_table' => 'Jointure M2M category <-> category_type (Catalog) — types portes par la categorie, au moins un obligatoire (RG-1.05).',
|
||||||
|
'category_id' => 'FK -> category.id, ON DELETE CASCADE — categorie portant le type.',
|
||||||
|
'category_type_id' => 'FK -> category_type.id, ON DELETE RESTRICT — type rattache (un type ne peut etre supprime tant qu il reste reference).',
|
||||||
|
],
|
||||||
|
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'_table' => 'Referentiel des permissions RBAC — codes au format module.resource[.subresource].action, synchronise par app:sync-permissions.',
|
'_table' => 'Referentiel des permissions RBAC — codes au format module.resource[.subresource].action, synchronise par app:sync-permissions.',
|
||||||
'id' => 'Identifiant interne auto-incremente.',
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
@@ -175,13 +180,13 @@ final class ColumnCommentsCatalog
|
|||||||
'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.',
|
||||||
'description' => 'Onglet Information : description libre. Obligatoire pour le role Commerciale (RG-1.04), optionnel sinon.',
|
'description' => 'Onglet Information : description libre. Facultatif.',
|
||||||
'competitors' => 'Onglet Information : concurrents identifies (texte libre ≤ 255). Obligatoire role Commerciale (RG-1.04).',
|
'competitors' => 'Onglet Information : concurrents identifies (texte libre ≤ 255). Facultatif.',
|
||||||
'founded_at' => 'Onglet Information : date de creation de l entreprise. Obligatoire role Commerciale (RG-1.04).',
|
'founded_at' => 'Onglet Information : date de creation de l entreprise. Facultatif.',
|
||||||
'employees_count' => 'Onglet Information : effectif (entier >= 0). Obligatoire role Commerciale (RG-1.04).',
|
'employees_count' => 'Onglet Information : effectif (entier >= 0). Facultatif.',
|
||||||
'revenue_amount' => 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).',
|
'revenue_amount' => 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Facultatif.',
|
||||||
'director_name' => 'Onglet Information : nom du dirigeant. Obligatoire role Commerciale (RG-1.04).',
|
'director_name' => 'Onglet Information : nom du dirigeant. Facultatif.',
|
||||||
'profit_amount' => 'Onglet Information : resultat / benefice (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).',
|
'profit_amount' => 'Onglet Information : resultat / benefice (NUMERIC 15,2). Facultatif.',
|
||||||
'siren' => 'Onglet Comptabilite : SIREN (9 chiffres attendus). NON unique — peut etre partage entre etablissements (RG-1.15 supprimee, Q4).',
|
'siren' => 'Onglet Comptabilite : SIREN (9 chiffres attendus). NON unique — peut etre partage entre etablissements (RG-1.15 supprimee, Q4).',
|
||||||
'account_number' => 'Onglet Comptabilite : numero de compte comptable du client.',
|
'account_number' => 'Onglet Comptabilite : numero de compte comptable du client.',
|
||||||
'tva_mode_id' => 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id, ON DELETE RESTRICT.',
|
'tva_mode_id' => 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id, ON DELETE RESTRICT.',
|
||||||
@@ -214,18 +219,21 @@ final class ColumnCommentsCatalog
|
|||||||
] + self::timestampableBlamableComments(),
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
'client_address' => [
|
'client_address' => [
|
||||||
'_table' => 'Adresses d un client (1:n) — prospect exclusif de livraison/facturation (RG-1.06/07/08), >= 1 site rattache (RG-1.10).',
|
'_table' => 'Adresses d un client (1:n) — types prospect / livraison / facturation (exclusivites RG-1.06/07/08) + Courtier / Distributeur autonomes (exclusifs de tout autre usage), >= 1 site rattache (RG-1.10).',
|
||||||
'id' => 'Identifiant interne auto-incremente.',
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
'client_id' => 'FK -> client.id, ON DELETE CASCADE — client proprietaire de l adresse.',
|
'client_id' => 'FK -> client.id, ON DELETE CASCADE — client proprietaire de l adresse.',
|
||||||
'is_prospect' => 'Adresse de prospection — exclusive de is_delivery/is_billing (RG-1.06/07/08, chk_client_address_prospect_exclusive). Faux par defaut.',
|
'is_prospect' => 'Adresse de prospection — exclusive de is_delivery/is_billing (RG-1.06/07/08, chk_client_address_prospect_exclusive). Faux par defaut.',
|
||||||
'is_delivery' => 'Adresse de livraison. Exclusive de is_prospect. Faux par defaut.',
|
'is_delivery' => 'Adresse de livraison. Exclusive de is_prospect. Faux par defaut.',
|
||||||
'is_billing' => 'Adresse de facturation. Exclusive de is_prospect. Impose billing_email (RG-1.11). Faux par defaut.',
|
'is_billing' => 'Adresse de facturation. Exclusive de is_prospect. Impose billing_email (RG-1.11). Faux par defaut.',
|
||||||
|
'is_broker' => 'Adresse Courtier — type autonome exclusif de tout autre usage (chk_client_address_broker_exclusive). Faux par defaut.',
|
||||||
|
'is_distributor' => 'Adresse Distributeur — type autonome exclusif de tout autre usage (chk_client_address_distributor_exclusive). Faux par defaut.',
|
||||||
'country' => 'Pays de l adresse — defaut France.',
|
'country' => 'Pays de l adresse — defaut France.',
|
||||||
'postal_code' => 'Code postal (4-5 chiffres attendus, RG-1.09).',
|
'postal_code' => 'Code postal (4-5 chiffres attendus, RG-1.09).',
|
||||||
'city' => 'Ville — preremplie depuis le code postal via API BAN cote front (RG-1.09).',
|
'city' => 'Ville — preremplie depuis le code postal via API BAN cote front (RG-1.09).',
|
||||||
'street' => 'Numero et voie de l adresse.',
|
'street' => 'Numero et voie de l adresse.',
|
||||||
'street_complement' => 'Complement d adresse (etage, batiment...) — optionnel.',
|
'street_complement' => 'Complement d adresse (etage, batiment...) — optionnel.',
|
||||||
'billing_email' => 'Email de facturation — obligatoire si is_billing, null sinon (RG-1.11, chk_client_address_billing_email).',
|
'billing_email' => 'Email de facturation — obligatoire si is_billing, null sinon (RG-1.11, chk_client_address_billing_email).',
|
||||||
|
'billing_email_secondary' => '2e email de facturation, optionnel (max 2). Interdit hors facturation, normalise en minuscules (RG-1.21).',
|
||||||
'position' => 'Ordre d affichage de l adresse dans la liste du client (croissant).',
|
'position' => 'Ordre d affichage de l adresse dans la liste du client (croissant).',
|
||||||
] + self::timestampableBlamableComments(),
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
@@ -256,6 +264,95 @@ final class ColumnCommentsCatalog
|
|||||||
'iban' => 'IBAN du compte (≤ 34 caracteres).',
|
'iban' => 'IBAN du compte (≤ 34 caracteres).',
|
||||||
'position' => 'Ordre d affichage du RIB dans la liste du client (croissant).',
|
'position' => 'Ordre d affichage du RIB dans la liste du client (croissant).',
|
||||||
] + self::timestampableBlamableComments(),
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
|
// === M2 Commercial (ERP-85) — miroir des COMMENT de la migration
|
||||||
|
// Version20260605130000 pour le chemin schema:update (dev/test). ===
|
||||||
|
|
||||||
|
'supplier' => [
|
||||||
|
'_table' => 'Repertoire fournisseurs (M2 Commercial) — entites archivables (is_archived) et soft-deletables (deleted_at, HP M3).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'company_name' => 'Raison sociale du fournisseur (stockee en MAJUSCULES). Unique case-insensitive parmi les actifs non archives/non supprimes (uq_supplier_company_name_active, § 2.6).',
|
||||||
|
'description' => 'Onglet Information : description libre. Obligatoire pour le role Commerciale (RG-2.03), optionnel sinon.',
|
||||||
|
'competitors' => 'Onglet Information : concurrents identifies (texte libre ≤ 255). Obligatoire role Commerciale (RG-2.03).',
|
||||||
|
'founded_at' => 'Onglet Information : date de creation de l entreprise. Obligatoire role Commerciale (RG-2.03).',
|
||||||
|
'employees_count' => 'Onglet Information : effectif (entier >= 0). Obligatoire role Commerciale (RG-2.03).',
|
||||||
|
'revenue_amount' => 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Obligatoire role Commerciale (RG-2.03).',
|
||||||
|
'director_name' => 'Onglet Information : nom du dirigeant. Obligatoire role Commerciale (RG-2.03).',
|
||||||
|
'profit_amount' => 'Onglet Information : resultat / benefice (NUMERIC 15,2). Obligatoire role Commerciale (RG-2.03).',
|
||||||
|
'volume_forecast' => 'Onglet Information : volume previsionnel (entier >= 0) — specifique fournisseur. Obligatoire role Commerciale (RG-2.03).',
|
||||||
|
'siren' => 'Onglet Comptabilite : SIREN (9 chiffres attendus). NON unique — peut etre partage entre etablissements (§ 2.6).',
|
||||||
|
'account_number' => 'Onglet Comptabilite : numero de compte comptable du fournisseur.',
|
||||||
|
'tva_mode_id' => 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id (referentiel partage M1), ON DELETE RESTRICT.',
|
||||||
|
'n_tva' => 'Onglet Comptabilite : numero de TVA intracommunautaire.',
|
||||||
|
'payment_delay_id' => 'Onglet Comptabilite : delai de reglement — FK -> payment_delay.id (M1), ON DELETE RESTRICT.',
|
||||||
|
'payment_type_id' => 'Onglet Comptabilite : type de reglement — FK -> payment_type.id (M1), ON DELETE RESTRICT. Pilote RG-2.07 (Banque si VIREMENT) et RG-2.08 (RIB).',
|
||||||
|
'bank_id' => 'Onglet Comptabilite : banque — FK -> bank.id (M1), ON DELETE RESTRICT. Obligatoire ssi payment_type = VIREMENT (RG-2.07), null sinon.',
|
||||||
|
'is_archived' => 'Drapeau fonctionnel d archivage — masque par defaut dans la liste. Bascule via permission commercial.suppliers.archive.',
|
||||||
|
'archived_at' => 'Horodatage de l archivage — pose quand is_archived passe a vrai, remis a null a la restauration.',
|
||||||
|
'deleted_at' => 'Horodatage du soft-delete technique (HP M3) — non expose par l API au M2. Null = ligne active.',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
|
'supplier_category' => [
|
||||||
|
'_table' => 'Jointure M2M supplier <-> category (Catalog) — categories de type FOURNISSEUR du fournisseur, au moins une obligatoire (RG-2.10).',
|
||||||
|
'supplier_id' => 'FK -> supplier.id, ON DELETE CASCADE — fournisseur porteur de la categorie.',
|
||||||
|
'category_id' => 'FK -> category.id, ON DELETE RESTRICT — categorie de type FOURNISSEUR rattachee au fournisseur (RG-2.10).',
|
||||||
|
],
|
||||||
|
|
||||||
|
'supplier_contact' => [
|
||||||
|
'_table' => 'Contacts d un fournisseur (1:n) — au moins firstName OU lastName par contact (RG-2.04).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'supplier_id' => 'FK -> supplier.id, ON DELETE CASCADE — fournisseur proprietaire du contact.',
|
||||||
|
'first_name' => 'Prenom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-2.04, chk_supplier_contact_name).',
|
||||||
|
'last_name' => 'Nom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-2.04, chk_supplier_contact_name).',
|
||||||
|
'job_title' => 'Fonction / intitule de poste du contact (≤ 120 caracteres).',
|
||||||
|
'phone_primary' => 'Telephone principal du contact — chiffres uniquement (normalisation serveur).',
|
||||||
|
'phone_secondary' => 'Telephone secondaire du contact — chiffres uniquement (normalisation serveur).',
|
||||||
|
'email' => 'Email du contact (lowercase serveur).',
|
||||||
|
'position' => 'Ordre d affichage du contact dans la liste du fournisseur (croissant).',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
|
'supplier_address' => [
|
||||||
|
'_table' => 'Adresses d un fournisseur (1:n) — type PROSPECT/DEPART/RENDU exclusif (RG-2.09), >= 1 site rattache (RG-2.06).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'supplier_id' => 'FK -> supplier.id, ON DELETE CASCADE — fournisseur proprietaire de l adresse.',
|
||||||
|
'address_type' => 'Type d adresse : PROSPECT | DEPART | RENDU (radio exclusif par construction — RG-2.09, chk_supplier_address_type).',
|
||||||
|
'country' => 'Pays de l adresse — defaut France.',
|
||||||
|
'postal_code' => 'Code postal (4-5 chiffres attendus).',
|
||||||
|
'city' => 'Ville — preremplie depuis le code postal via API BAN cote front.',
|
||||||
|
'street' => 'Numero et voie de l adresse.',
|
||||||
|
'street_complement' => 'Complement d adresse (etage, batiment...) — optionnel.',
|
||||||
|
'bennes' => 'Nombre de bennes sur le site fournisseur (entier nullable) — specifique fournisseur.',
|
||||||
|
'triage_provider' => 'Le fournisseur est prestataire de triage sur cette adresse. Faux par defaut.',
|
||||||
|
'position' => 'Ordre d affichage de l adresse dans la liste du fournisseur (croissant).',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
|
'supplier_address_site' => [
|
||||||
|
'_table' => 'Jointure M2M supplier_address <-> site (Sites) — sites rattaches a l adresse (>= 1 obligatoire, RG-2.06).',
|
||||||
|
'supplier_address_id' => 'FK -> supplier_address.id, ON DELETE CASCADE — adresse concernee.',
|
||||||
|
'site_id' => 'FK -> site.id, ON DELETE RESTRICT — site rattache a l adresse.',
|
||||||
|
],
|
||||||
|
|
||||||
|
'supplier_address_contact' => [
|
||||||
|
'_table' => 'Jointure M2M supplier_address <-> supplier_contact — contacts associes a une adresse.',
|
||||||
|
'supplier_address_id' => 'FK -> supplier_address.id, ON DELETE CASCADE — adresse concernee.',
|
||||||
|
'supplier_contact_id' => 'FK -> supplier_contact.id, ON DELETE CASCADE — contact associe a l adresse.',
|
||||||
|
],
|
||||||
|
|
||||||
|
'supplier_address_category' => [
|
||||||
|
'_table' => 'Jointure M2M supplier_address <-> category — categories d adresse de type FOURNISSEUR (RG-2.10).',
|
||||||
|
'supplier_address_id' => 'FK -> supplier_address.id, ON DELETE CASCADE — adresse concernee.',
|
||||||
|
'category_id' => 'FK -> category.id, ON DELETE RESTRICT — categorie d adresse de type FOURNISSEUR (RG-2.10).',
|
||||||
|
],
|
||||||
|
|
||||||
|
'supplier_rib' => [
|
||||||
|
'_table' => 'Coordonnees bancaires d un fournisseur (1:n) — >= 1 RIB attendu selon le type de reglement (RG-2.08). Tous les champs audites (pas d AuditIgnore).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'supplier_id' => 'FK -> supplier.id, ON DELETE CASCADE — fournisseur proprietaire du RIB.',
|
||||||
|
'label' => 'Libelle du RIB (ex: compte principal).',
|
||||||
|
'bic' => 'Code BIC/SWIFT de la banque (8 ou 11 caracteres).',
|
||||||
|
'iban' => 'IBAN du compte (≤ 34 caracteres).',
|
||||||
|
'position' => 'Ordre d affichage du RIB dans la liste du fournisseur (croissant).',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,11 +70,17 @@ abstract class AbstractCatalogApiTestCase extends AbstractApiTestCase
|
|||||||
* cleanup. Si aucun type n'est fourni, un nouveau CategoryType est cree.
|
* cleanup. Si aucun type n'est fourni, un nouveau CategoryType est cree.
|
||||||
* Le flag $deletedAt permet de seeder directement une categorie
|
* Le flag $deletedAt permet de seeder directement une categorie
|
||||||
* soft-deleted (pour les tests RG-1.08 / RG-1.11).
|
* soft-deleted (pour les tests RG-1.08 / RG-1.11).
|
||||||
|
*
|
||||||
|
* Multi-types (ManyToMany) : `$type` est le type principal (cree si null) ;
|
||||||
|
* `$additionalTypes` permet d'attacher d'autres types pour les cas multi.
|
||||||
|
*
|
||||||
|
* @param list<CategoryType> $additionalTypes
|
||||||
*/
|
*/
|
||||||
protected function createCategory(
|
protected function createCategory(
|
||||||
?string $name = null,
|
?string $name = null,
|
||||||
?CategoryType $type = null,
|
?CategoryType $type = null,
|
||||||
?DateTimeImmutable $deletedAt = null,
|
?DateTimeImmutable $deletedAt = null,
|
||||||
|
array $additionalTypes = [],
|
||||||
): Category {
|
): Category {
|
||||||
$em = $this->getEm();
|
$em = $this->getEm();
|
||||||
|
|
||||||
@@ -86,7 +92,10 @@ abstract class AbstractCatalogApiTestCase extends AbstractApiTestCase
|
|||||||
// ERP-78 : code NOT NULL + unique parmi les actifs (uq_category_code).
|
// ERP-78 : code NOT NULL + unique parmi les actifs (uq_category_code).
|
||||||
// Nonce aleatoire -> unicite garantie entre seeds successifs du test.
|
// Nonce aleatoire -> unicite garantie entre seeds successifs du test.
|
||||||
$category->setCode('TEST_'.strtoupper($suffix));
|
$category->setCode('TEST_'.strtoupper($suffix));
|
||||||
$category->setCategoryType($type);
|
$category->addCategoryType($type);
|
||||||
|
foreach ($additionalTypes as $additionalType) {
|
||||||
|
$category->addCategoryType($additionalType);
|
||||||
|
}
|
||||||
if (null !== $deletedAt) {
|
if (null !== $deletedAt) {
|
||||||
$category->setDeletedAt($deletedAt);
|
$category->setDeletedAt($deletedAt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ final class CategoryAuditTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'audit_create',
|
'name' => self::TEST_CATEGORY_PREFIX.'audit_create',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(201, $response->getStatusCode());
|
self::assertSame(201, $response->getStatusCode());
|
||||||
@@ -139,7 +139,7 @@ final class CategoryAuditTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'audit_manager',
|
'name' => self::TEST_CATEGORY_PREFIX.'audit_manager',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(201, $response->getStatusCode());
|
self::assertSame(201, $response->getStatusCode());
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ final class CategoryCodeTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'Agro-alimentaire',
|
'name' => self::TEST_CATEGORY_PREFIX.'Agro-alimentaire',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
@@ -48,7 +48,7 @@ final class CategoryCodeTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'readonly',
|
'name' => self::TEST_CATEGORY_PREFIX.'readonly',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
// Le client tente d'imposer un code : doit etre ignore.
|
// Le client tente d'imposer un code : doit etre ignore.
|
||||||
'code' => 'CLIENT_FORGED',
|
'code' => 'CLIENT_FORGED',
|
||||||
],
|
],
|
||||||
@@ -65,13 +65,13 @@ final class CategoryCodeTest extends AbstractCatalogApiTestCase
|
|||||||
$type = $this->createCategoryType();
|
$type = $this->createCategoryType();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
|
|
||||||
// Deux noms differents (donc autorises par uq_category_name_type_active)
|
// Deux noms differents (donc autorises par uq_category_name_active)
|
||||||
// mais qui produisent le meme slug -> codes distincts (suffixe `_2`).
|
// mais qui produisent le meme slug -> codes distincts (suffixe `_2`).
|
||||||
$first = $client->request('POST', '/api/categories', [
|
$first = $client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'Agro Plus',
|
'name' => self::TEST_CATEGORY_PREFIX.'Agro Plus',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ final class CategoryCodeTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'Agro-Plus',
|
'name' => self::TEST_CATEGORY_PREFIX.'Agro-Plus',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
])->toArray();
|
])->toArray();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Catalog\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests des filtres de la liste admin sur GET /api/categories :
|
||||||
|
* - `?name=` : recherche partielle case-insensitive sur le nom ;
|
||||||
|
* - `?typeId[]=` : categories portant AU MOINS UN des types coches (OR), sans
|
||||||
|
* doublon meme pour une categorie multi-types ;
|
||||||
|
* - combinaison `?name=` + `?typeId[]=` (ET entre filtres).
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class CategoryFilterTest extends AbstractCatalogApiTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array<int, array<string, mixed>> $members
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function testNames(array $members): array
|
||||||
|
{
|
||||||
|
$names = array_map(static fn (array $m): string => $m['name'], $members);
|
||||||
|
$names = array_values(array_filter(
|
||||||
|
$names,
|
||||||
|
fn (string $n): bool => str_starts_with($n, self::TEST_CATEGORY_PREFIX),
|
||||||
|
));
|
||||||
|
sort($names);
|
||||||
|
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNameFilterIsPartialAndCaseInsensitive(): void
|
||||||
|
{
|
||||||
|
$type = $this->createCategoryType();
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'Acier inox', $type);
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'Aluminium', $type);
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request('GET', '/api/categories?name=ACIER&pagination=false');
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
self::assertSame(
|
||||||
|
[self::TEST_CATEGORY_PREFIX.'Acier inox'],
|
||||||
|
$this->testNames($response->toArray()['member']),
|
||||||
|
'Le filtre ?name= doit etre partiel et insensible a la casse.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTypeIdFilterReturnsCategoriesWithAtLeastOneType(): void
|
||||||
|
{
|
||||||
|
$typeA = $this->createCategoryType();
|
||||||
|
$typeB = $this->createCategoryType();
|
||||||
|
$typeC = $this->createCategoryType();
|
||||||
|
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'only_a', $typeA);
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'only_b', $typeB);
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'only_c', $typeC);
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request(
|
||||||
|
'GET',
|
||||||
|
sprintf('/api/categories?typeId[]=%d&typeId[]=%d&pagination=false', $typeA->getId(), $typeB->getId()),
|
||||||
|
);
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
self::assertSame(
|
||||||
|
[
|
||||||
|
self::TEST_CATEGORY_PREFIX.'only_a',
|
||||||
|
self::TEST_CATEGORY_PREFIX.'only_b',
|
||||||
|
],
|
||||||
|
$this->testNames($response->toArray()['member']),
|
||||||
|
'Le filtre ?typeId[]= doit remonter les categories portant AU MOINS UN des types (OR).',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMultiTypeCategoryAppearsOnceWhenFilteredByOneType(): void
|
||||||
|
{
|
||||||
|
// Une categorie portant deux types ne doit pas etre dupliquee quand on
|
||||||
|
// filtre sur l'un de ses types (la sous-requete EXISTS evite les doublons).
|
||||||
|
$typeA = $this->createCategoryType();
|
||||||
|
$typeB = $this->createCategoryType();
|
||||||
|
|
||||||
|
$this->createCategory(
|
||||||
|
self::TEST_CATEGORY_PREFIX.'multi',
|
||||||
|
$typeA,
|
||||||
|
null,
|
||||||
|
[$typeB],
|
||||||
|
);
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request(
|
||||||
|
'GET',
|
||||||
|
sprintf('/api/categories?typeId[]=%d&pagination=false', $typeA->getId()),
|
||||||
|
);
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
$members = $response->toArray()['member'];
|
||||||
|
self::assertSame(
|
||||||
|
[self::TEST_CATEGORY_PREFIX.'multi'],
|
||||||
|
$this->testNames($members),
|
||||||
|
'La categorie multi-types ne doit apparaitre qu une seule fois.',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Les deux types restent embarques (la collection n'est pas tronquee).
|
||||||
|
$multi = array_values(array_filter(
|
||||||
|
$members,
|
||||||
|
fn (array $m): bool => $m['name'] === self::TEST_CATEGORY_PREFIX.'multi',
|
||||||
|
))[0];
|
||||||
|
self::assertCount(2, $multi['categoryTypes'], 'Les 2 types doivent rester embarques malgre le filtre.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNameAndTypeIdFiltersCombine(): void
|
||||||
|
{
|
||||||
|
$typeA = $this->createCategoryType();
|
||||||
|
$typeB = $this->createCategoryType();
|
||||||
|
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'steel_a', $typeA);
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'steel_b', $typeB);
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'wood_a', $typeA);
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request(
|
||||||
|
'GET',
|
||||||
|
sprintf('/api/categories?name=steel&typeId[]=%d&pagination=false', $typeA->getId()),
|
||||||
|
);
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
self::assertSame(
|
||||||
|
[self::TEST_CATEGORY_PREFIX.'steel_a'],
|
||||||
|
$this->testNames($response->toArray()['member']),
|
||||||
|
'Les filtres ?name= et ?typeId[]= doivent se combiner (ET).',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,7 +66,7 @@ final class CategoryPermissionsTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'forbidden',
|
'name' => self::TEST_CATEGORY_PREFIX.'forbidden',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ final class CategoryPermissionsTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'anon',
|
'name' => self::TEST_CATEGORY_PREFIX.'anon',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ final class CategoryPermissionsTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'admin_create',
|
'name' => self::TEST_CATEGORY_PREFIX.'admin_create',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ final class CategoryPermissionsTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'view_only',
|
'name' => self::TEST_CATEGORY_PREFIX.'view_only',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ final class CategoryTimestampableBlamableTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'tsb_admin',
|
'name' => self::TEST_CATEGORY_PREFIX.'tsb_admin',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(201, $response->getStatusCode());
|
self::assertSame(201, $response->getStatusCode());
|
||||||
@@ -140,7 +140,7 @@ final class CategoryTimestampableBlamableTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'tsb_patch',
|
'name' => self::TEST_CATEGORY_PREFIX.'tsb_patch',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(201, $response->getStatusCode());
|
self::assertSame(201, $response->getStatusCode());
|
||||||
@@ -220,7 +220,7 @@ final class CategoryTimestampableBlamableTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'tsb_delete',
|
'name' => self::TEST_CATEGORY_PREFIX.'tsb_delete',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(201, $response->getStatusCode());
|
self::assertSame(201, $response->getStatusCode());
|
||||||
|
|||||||
@@ -47,9 +47,10 @@ final class CategoryTypeCodeFilterTest extends AbstractCatalogApiTestCase
|
|||||||
'Le filtre ?typeCode= doit ne renvoyer QUE les categories du type demande.',
|
'Le filtre ?typeCode= doit ne renvoyer QUE les categories du type demande.',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Tous les types embarques doivent etre le type filtre.
|
// Chaque categorie remontee doit PORTER le type filtre (multi-types :
|
||||||
|
// la collection categoryTypes embarquee contient le code demande).
|
||||||
foreach ($members as $member) {
|
foreach ($members as $member) {
|
||||||
self::assertSame('TEST_FOURNISSEUR', $member['categoryType']['code']);
|
self::assertContains('TEST_FOURNISSEUR', array_column($member['categoryTypes'], 'code'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ final class CategoryTypeCodeFilterTest extends AbstractCatalogApiTestCase
|
|||||||
self::assertArrayHasKey('member', $data);
|
self::assertArrayHasKey('member', $data);
|
||||||
|
|
||||||
foreach ($data['member'] as $member) {
|
foreach ($data['member'] as $member) {
|
||||||
self::assertSame('TEST_FOURNISSEUR', $member['categoryType']['code']);
|
self::assertContains('TEST_FOURNISSEUR', array_column($member['categoryTypes'], 'code'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,22 +5,22 @@ declare(strict_types=1);
|
|||||||
namespace App\Tests\Module\Catalog\Api;
|
namespace App\Tests\Module\Catalog\Api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests RG-1.07 : unicite case-insensitive de (LOWER(name), category_type_id)
|
* Tests RG-1.07 : unicite case-insensitive du nom GLOBALEMENT (LOWER(name))
|
||||||
* parmi les categories non soft-deleted. L'index Postgres partiel
|
* parmi les categories non soft-deleted. Depuis le passage en ManyToMany,
|
||||||
* `uq_category_name_type_active` est traduit en 409 Conflict par le
|
* l'unicite n'est plus liee au type. L'index Postgres partiel
|
||||||
* CategoryProcessor.
|
* `uq_category_name_active` est traduit en 409 Conflict par le CategoryProcessor.
|
||||||
*
|
*
|
||||||
* Cas couverts :
|
* Cas couverts :
|
||||||
* - doublon strict (meme name + meme type) → 409 ;
|
* - doublon strict (meme name) → 409 ;
|
||||||
* - doublon case-insensitive (Vis / vis sur meme type) → 409 ;
|
* - doublon case-insensitive (Vis / VIS) → 409 ;
|
||||||
* - meme name sur 2 types differents → les deux passent (pas de doublon) ;
|
* - meme name avec des types differents → 409 (unicite GLOBALE) ;
|
||||||
* - recreation apres soft delete → 201 (l'index partiel libere le couple).
|
* - recreation apres soft delete → 201 (l'index partiel libere le nom).
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
||||||
{
|
{
|
||||||
public function testDuplicateNameSameTypeReturns409(): void
|
public function testDuplicateNameReturns409(): void
|
||||||
{
|
{
|
||||||
$type = $this->createCategoryType();
|
$type = $this->createCategoryType();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
@@ -30,28 +30,28 @@ final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'unique',
|
'name' => self::TEST_CATEGORY_PREFIX.'unique',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|
||||||
// 2eme POST : meme name + meme type → doublon strict.
|
// 2eme POST : meme name → doublon (unicite globale).
|
||||||
$response = $client->request('POST', '/api/categories', [
|
$response = $client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'unique',
|
'name' => self::TEST_CATEGORY_PREFIX.'unique',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(409, $response->getStatusCode());
|
self::assertSame(409, $response->getStatusCode());
|
||||||
|
|
||||||
// Message attendu par la spec RG-1.07.
|
// Message attendu par la spec RG-1.07 (reformulee, sans "pour ce type").
|
||||||
$payload = $response->toArray(false);
|
$payload = $response->toArray(false);
|
||||||
$description = $payload['description'] ?? $payload['detail'] ?? $payload['hydra:description'] ?? '';
|
$description = $payload['description'] ?? $payload['detail'] ?? $payload['hydra:description'] ?? '';
|
||||||
self::assertStringContainsString(
|
self::assertStringContainsString(
|
||||||
'existe déjà pour ce type',
|
'existe déjà',
|
||||||
$description,
|
$description,
|
||||||
'Le message d\'erreur 409 doit citer la spec ("existe deja pour ce type").',
|
'Le message d\'erreur 409 doit citer la spec ("existe deja").',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'Vis',
|
'name' => self::TEST_CATEGORY_PREFIX.'Vis',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
@@ -75,16 +75,16 @@ final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
|||||||
'json' => [
|
'json' => [
|
||||||
// Meme prefix mais variation de casse → meme LOWER → collision.
|
// Meme prefix mais variation de casse → meme LOWER → collision.
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'VIS',
|
'name' => self::TEST_CATEGORY_PREFIX.'VIS',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(409, $response->getStatusCode());
|
self::assertSame(409, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSameNameDifferentTypeAllowed(): void
|
public function testSameNameDifferentTypeReturns409(): void
|
||||||
{
|
{
|
||||||
// RG-1.07 : la contrainte est SUR (name, type), pas sur name seul.
|
// RG-1.07 (reformulee) : l'unicite du nom est desormais GLOBALE — le
|
||||||
// Le meme nom doit etre acceptable sur deux types differents.
|
// meme nom sur deux types differents est un doublon.
|
||||||
$type1 = $this->createCategoryType();
|
$type1 = $this->createCategoryType();
|
||||||
$type2 = $this->createCategoryType();
|
$type2 = $this->createCategoryType();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
@@ -93,26 +93,26 @@ final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'shared',
|
'name' => self::TEST_CATEGORY_PREFIX.'shared',
|
||||||
'categoryType' => '/api/category_types/'.$type1->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type1->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|
||||||
$client->request('POST', '/api/categories', [
|
$response = $client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'shared',
|
'name' => self::TEST_CATEGORY_PREFIX.'shared',
|
||||||
'categoryType' => '/api/category_types/'.$type2->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type2->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertSame(409, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRecreateAfterSoftDeleteAllowed(): void
|
public function testRecreateAfterSoftDeleteAllowed(): void
|
||||||
{
|
{
|
||||||
// RG-1.07 : l'index Postgres est partiel (WHERE deleted_at IS NULL).
|
// RG-1.07 : l'index Postgres est partiel (WHERE deleted_at IS NULL).
|
||||||
// Apres un soft delete, le couple (name, type) est libere et un
|
// Apres un soft delete, le nom est libere et un nouveau POST identique
|
||||||
// nouveau POST identique doit reussir.
|
// doit reussir.
|
||||||
$type = $this->createCategoryType();
|
$type = $this->createCategoryType();
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'recreate',
|
'name' => self::TEST_CATEGORY_PREFIX.'recreate',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertSame(201, $response->getStatusCode());
|
self::assertSame(201, $response->getStatusCode());
|
||||||
@@ -131,12 +131,12 @@ final class CategoryUniqueTest extends AbstractCatalogApiTestCase
|
|||||||
$client->request('DELETE', '/api/categories/'.$created['id']);
|
$client->request('DELETE', '/api/categories/'.$created['id']);
|
||||||
self::assertResponseStatusCodeSame(204);
|
self::assertResponseStatusCodeSame(204);
|
||||||
|
|
||||||
// 3) recreation : meme name + meme type → autorise (couple libere).
|
// 3) recreation : meme name → autorise (nom libere par l'archivage).
|
||||||
$client->request('POST', '/api/categories', [
|
$client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'recreate',
|
'name' => self::TEST_CATEGORY_PREFIX.'recreate',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use App\Module\Catalog\Domain\Entity\Category;
|
|||||||
* - RG-1.02 : `name` obligatoire (NotBlank) ;
|
* - RG-1.02 : `name` obligatoire (NotBlank) ;
|
||||||
* - RG-1.03 : `name` trim cote serveur via CategoryProcessor ;
|
* - RG-1.03 : `name` trim cote serveur via CategoryProcessor ;
|
||||||
* - RG-1.04 : `name` longueur 2..120 (Length) ;
|
* - RG-1.04 : `name` longueur 2..120 (Length) ;
|
||||||
* - RG-1.05 : `categoryType` obligatoire ;
|
* - RG-1.05 : `categoryTypes` — au moins un type (Count min 1) ;
|
||||||
* - RG-1.06 : `categoryType` doit pointer un type existant.
|
* - RG-1.06 : chaque IRI de `categoryTypes` doit pointer un type existant.
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@@ -27,7 +27,7 @@ final class CategoryValidationTest extends AbstractCatalogApiTestCase
|
|||||||
$client->request('POST', '/api/categories', [
|
$client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
// name absent
|
// name absent
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
@@ -43,7 +43,7 @@ final class CategoryValidationTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ final class CategoryValidationTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => ' ',
|
'name' => ' ',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ final class CategoryValidationTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => $payloadName,
|
'name' => $payloadName,
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ final class CategoryValidationTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => 'A',
|
'name' => 'A',
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ final class CategoryValidationTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => str_repeat('a', 121),
|
'name' => str_repeat('a', 121),
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -141,70 +141,73 @@ final class CategoryValidationTest extends AbstractCatalogApiTestCase
|
|||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
'categoryTypes' => ['/api/category_types/'.$type->getId()],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ RG-1.05 — categoryType obligatoire ============
|
// ============ RG-1.05 — au moins un type (Count min 1) ============
|
||||||
|
|
||||||
public function testCategoryTypeRequiredReturns422(): void
|
public function testCategoryTypesRequiredReturns422(): void
|
||||||
{
|
{
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$client->request('POST', '/api/categories', [
|
$client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'no_type',
|
'name' => self::TEST_CATEGORY_PREFIX.'no_type',
|
||||||
// categoryType absent
|
// categoryTypes absent -> collection vide -> Count(min:1) viole.
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategoryTypeNullIsRejected(): void
|
public function testCategoryTypesEmptyReturns422(): void
|
||||||
{
|
{
|
||||||
// `categoryType: null` echoue a la deserialization IRI (API Platform
|
// Tableau vide explicite : Assert\Count(min: 1) doit declencher 422 avec
|
||||||
// renvoie 400) bien avant la validation Assert\NotNull. La spec § 4.3
|
// une violation sur le propertyPath `categoryTypes` (consommable inline).
|
||||||
// accepte les deux : on assert le contrat fort "ne passe pas en BDD".
|
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$response = $client->request('POST', '/api/categories', [
|
$response = $client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'null_type',
|
'name' => self::TEST_CATEGORY_PREFIX.'empty_types',
|
||||||
'categoryType' => null,
|
'categoryTypes' => [],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
self::assertSame(422, $response->getStatusCode());
|
||||||
|
$payload = $response->toArray(false);
|
||||||
|
$violations = $payload['violations'] ?? $payload['hydra:violations'] ?? [];
|
||||||
|
$paths = array_column($violations, 'propertyPath');
|
||||||
self::assertContains(
|
self::assertContains(
|
||||||
$response->getStatusCode(),
|
'categoryTypes',
|
||||||
[400, 422],
|
$paths,
|
||||||
'categoryType=null doit etre rejete (400 deserialization ou 422 validation).',
|
'La violation Count doit porter le propertyPath `categoryTypes`.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ RG-1.06 — categoryType doit exister ============
|
// ============ RG-1.06 — chaque type doit exister ============
|
||||||
|
|
||||||
public function testCategoryTypeMustExistReturns4xx(): void
|
public function testCategoryTypeMustExistReturns4xx(): void
|
||||||
{
|
{
|
||||||
// IRI vers un id qui n'existe pas. API Platform peut renvoyer 400
|
// IRI vers un id qui n'existe pas. API Platform peut renvoyer 400
|
||||||
// (resolution IRI echouee) ou 422 (validation NotNull declenchee).
|
// (resolution IRI echouee) ou 422 (validation declenchee). La spec § 4.3
|
||||||
// La spec § 4.3 accepte les deux : on assert le contrat "ne passe pas".
|
// accepte les deux : on assert le contrat "ne passe pas".
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$response = $client->request('POST', '/api/categories', [
|
$response = $client->request('POST', '/api/categories', [
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
'headers' => ['Content-Type' => 'application/ld+json'],
|
||||||
'json' => [
|
'json' => [
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'ghost_type',
|
'name' => self::TEST_CATEGORY_PREFIX.'ghost_type',
|
||||||
'categoryType' => '/api/category_types/9999999',
|
'categoryTypes' => ['/api/category_types/9999999'],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
self::assertContains(
|
self::assertContains(
|
||||||
$response->getStatusCode(),
|
$response->getStatusCode(),
|
||||||
[400, 404, 422],
|
[400, 404, 422],
|
||||||
'IRI categoryType inexistante doit etre rejetee (400/404/422 selon API Platform).',
|
'IRI categoryTypes inexistante doit etre rejetee (400/404/422 selon API Platform).',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ abstract class AbstractCommercialApiTestCase extends AbstractApiTestCase
|
|||||||
$category = new Category();
|
$category = new Category();
|
||||||
$category->setName($name);
|
$category->setName($name);
|
||||||
$category->setCode($effectiveCode);
|
$category->setCode($effectiveCode);
|
||||||
$category->setCategoryType($this->clientCategoryType());
|
$category->addCategoryType($this->clientCategoryType());
|
||||||
$em->persist($category);
|
$em->persist($category);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
@@ -137,6 +137,27 @@ abstract class AbstractCommercialApiTestCase extends AbstractApiTestCase
|
|||||||
return $client;
|
return $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indexe les violations d'un corps de reponse 422 par propertyPath. Permet
|
||||||
|
* d'asserter qu'un 422 porte bien sur le champ attendu (et n'est pas un 422
|
||||||
|
* orthogonal) : un test qui se contente du code 422 passerait meme si la RG
|
||||||
|
* visee etait cassee pour une autre raison. Mutualise ici (et non dans la
|
||||||
|
* sous-classe Supplier) pour etre accessible a tous les tests Commercial.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $body corps decode de la reponse (toArray(false))
|
||||||
|
*
|
||||||
|
* @return array<string, string> propertyPath => message
|
||||||
|
*/
|
||||||
|
protected function violationsByPath(array $body): array
|
||||||
|
{
|
||||||
|
$byPath = [];
|
||||||
|
foreach ($body['violations'] ?? [] as $v) {
|
||||||
|
$byPath[$v['propertyPath']] = $v['message'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $byPath;
|
||||||
|
}
|
||||||
|
|
||||||
private function cleanupCommercialTestData(): void
|
private function cleanupCommercialTestData(): void
|
||||||
{
|
{
|
||||||
$em = $this->getEm();
|
$em = $this->getEm();
|
||||||
|
|||||||
@@ -0,0 +1,322 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
use App\Module\Catalog\Domain\Entity\Category;
|
||||||
|
use App\Module\Catalog\Domain\Entity\CategoryType;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Bank;
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentDelay;
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentType;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierAddress;
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierContact;
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierRib;
|
||||||
|
use App\Module\Commercial\Domain\Entity\TvaMode;
|
||||||
|
use App\Module\Sites\Domain\Entity\Site;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base des tests fonctionnels du repertoire fournisseurs (M2). Jumelle de la base
|
||||||
|
* clients (M1), elle ajoute les factories specifiques fournisseur au-dessus de
|
||||||
|
* {@see AbstractCommercialApiTestCase} (qui apporte deja createCategory sous le
|
||||||
|
* type CLIENT, createUserWithPermission, authenticatedClient...).
|
||||||
|
*
|
||||||
|
* Donnees (RETEX M1 — pas de fixtures globales pour les tests) : chaque test seede
|
||||||
|
* ses fournisseurs en base via les helpers ci-dessous, puis le tearDown les purge.
|
||||||
|
* Les referentiels comptables (tva_mode / payment_delay / payment_type / bank) et
|
||||||
|
* les categories FOURNISSEUR (Negociant, Cooperative...) sont seedes par les
|
||||||
|
* fixtures applicatives (make test-db-setup) ; on les recupere par code.
|
||||||
|
*
|
||||||
|
* Categories : `supplierCategory('NEGOCIANT')` fetch-or-create une categorie de
|
||||||
|
* type FOURNISSEUR (requis par RG-2.10) — fetch-or-create par code pour rester
|
||||||
|
* idempotent et auto-suffisant (ne depend pas du seed, que d'autres tests de la
|
||||||
|
* suite peuvent purger). Pour fabriquer une categorie d'un AUTRE type (test de
|
||||||
|
* rejet RG-2.10), utiliser `createCategory()` du parent, qui cree sous CLIENT.
|
||||||
|
*
|
||||||
|
* Cleanup : le tearDown purge les fournisseurs AVANT le parent (qui supprime les
|
||||||
|
* categories `test_cli_cat_*`) : la jointure supplier_category est ON DELETE
|
||||||
|
* CASCADE cote supplier mais RESTRICT cote category — le DELETE DQL sur Supplier
|
||||||
|
* declenche le cascade BDD sur supplier_category / _contact / _address, liberant
|
||||||
|
* les categories pour la purge du parent.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
abstract class AbstractSupplierApiTestCase extends AbstractCommercialApiTestCase
|
||||||
|
{
|
||||||
|
protected const string LD = 'application/ld+json';
|
||||||
|
protected const string MERGE = 'application/merge-patch+json';
|
||||||
|
|
||||||
|
/** IBAN/BIC valides (Assert\Iban / Assert\Bic) reutilises par les seeds. */
|
||||||
|
protected const string VALID_IBAN = 'FR1420041010050500013M02606';
|
||||||
|
protected const string VALID_BIC = 'BNPAFRPPXXX';
|
||||||
|
// BIC allemand valide isolement (pays DE en positions 5-6) : sert au controle
|
||||||
|
// croise pays BIC/IBAN (DE vs IBAN FR -> mismatch, cf. Assert\Bic ibanPropertyPath).
|
||||||
|
protected const string FOREIGN_BIC = 'DEUTDEFFXXX';
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->getEm()->createQuery('DELETE FROM '.Supplier::class)->execute();
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch-or-create une categorie de type FOURNISSEUR par code (defaut
|
||||||
|
* Negociant). Type FOURNISSEUR exige par RG-2.10 : un POST fournisseur portant
|
||||||
|
* cette categorie passe la validation. Idempotent (lookup par code, aligne sur
|
||||||
|
* l'index unique partiel uq_category_code) et auto-suffisant : ne depend pas du
|
||||||
|
* seed CategoryFixtures (que d'autres tests de la suite peuvent purger). Une
|
||||||
|
* categorie creee ici porte le prefixe de nom de test -> purgee par le parent.
|
||||||
|
*/
|
||||||
|
protected function supplierCategory(string $code = 'NEGOCIANT'): Category
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$existing = $em->getRepository(Category::class)->findOneBy(['code' => $code, 'deletedAt' => null]);
|
||||||
|
if (null !== $existing) {
|
||||||
|
return $existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
$category = new Category();
|
||||||
|
$category->setName(self::TEST_CATEGORY_PREFIX.'fr_'.strtolower($code));
|
||||||
|
$category->setCode($code);
|
||||||
|
$category->addCategoryType($this->supplierCategoryType());
|
||||||
|
$em->persist($category);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recupere (ou cree) le type FOURNISSEUR. Idempotent : la contrainte d'unicite
|
||||||
|
* sur category_type.code interdit les doublons.
|
||||||
|
*/
|
||||||
|
protected function supplierCategoryType(): CategoryType
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$existing = $em->getRepository(CategoryType::class)->findOneBy(['code' => 'FOURNISSEUR']);
|
||||||
|
if (null !== $existing) {
|
||||||
|
return $existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = new CategoryType();
|
||||||
|
$type->setCode('FOURNISSEUR');
|
||||||
|
$type->setLabel('Fournisseur');
|
||||||
|
$em->persist($type);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seede directement un Supplier minimal (sans passer par l'API), pour les
|
||||||
|
* tests de liste / archivage / serialisation. Nom stocke en MAJUSCULES pour
|
||||||
|
* refleter l'etat normalise (RG-2.12) qu'aurait produit le SupplierProcessor.
|
||||||
|
* Porte une categorie FOURNISSEUR (defaut Negociant).
|
||||||
|
*/
|
||||||
|
protected function seedSupplier(string $companyName, bool $isArchived = false, string $categoryCode = 'NEGOCIANT'): Supplier
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$supplier = new Supplier();
|
||||||
|
$supplier->setCompanyName(mb_strtoupper($companyName, 'UTF-8'));
|
||||||
|
$supplier->addCategory($this->supplierCategory($categoryCode));
|
||||||
|
$supplier->setIsArchived($isArchived);
|
||||||
|
if ($isArchived) {
|
||||||
|
$supplier->setArchivedAt(new DateTimeImmutable());
|
||||||
|
}
|
||||||
|
$em->persist($supplier);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $supplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seede un fournisseur COMPLET (sans passer par l'API — validations
|
||||||
|
* applicatives non rejouees mais CHECK BDD respectes) : onglet Information
|
||||||
|
* rempli, bloc comptable non nul (SIREN + refs), >= 1 RIB, >= 1 adresse
|
||||||
|
* multi-sites (>= 2 sites, triageProvider=true) avec >= 1 categorie
|
||||||
|
* FOURNISSEUR, >= 1 contact, >= 1 categorie sur le fournisseur. Sert de socle
|
||||||
|
* au contrat de serialisation et a la DoD (§ 4.0.bis).
|
||||||
|
*
|
||||||
|
* @param string $paymentTypeCode code du type de reglement a poser (defaut LCR,
|
||||||
|
* coherent avec le RIB seede ; RG-2.08)
|
||||||
|
*/
|
||||||
|
protected function seedCompleteSupplier(string $companyName, string $paymentTypeCode = 'LCR'): Supplier
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
|
||||||
|
// Nom unique parmi les actifs (index partiel uq_supplier_company_name_active).
|
||||||
|
$suffix = substr(bin2hex(random_bytes(3)), 0, 6);
|
||||||
|
|
||||||
|
$supplier = new Supplier();
|
||||||
|
$supplier->setCompanyName(mb_strtoupper($companyName.' '.$suffix, 'UTF-8'));
|
||||||
|
$supplier->addCategory($this->supplierCategory('NEGOCIANT'));
|
||||||
|
|
||||||
|
// Onglet Information complet (RG-2.03 : exige pour la Commerciale).
|
||||||
|
$supplier->setDescription('Fournisseur de test complet.');
|
||||||
|
$supplier->setCompetitors('Concurrent A, Concurrent B');
|
||||||
|
$supplier->setFoundedAt(new DateTimeImmutable('2008-04-01'));
|
||||||
|
$supplier->setEmployeesCount(42);
|
||||||
|
$supplier->setRevenueAmount('1500000.00');
|
||||||
|
$supplier->setDirectorName('Jean Dupont');
|
||||||
|
$supplier->setProfitAmount('120000.00');
|
||||||
|
$supplier->setVolumeForecast(8000);
|
||||||
|
|
||||||
|
// Bloc comptable non nul (gating par omission cote Commerciale).
|
||||||
|
$supplier->setSiren('123456789');
|
||||||
|
$supplier->setAccountNumber('F0001');
|
||||||
|
$supplier->setNTva('FR00123456789');
|
||||||
|
$supplier->setTvaMode($this->tvaMode('FRANCE_VENTES'));
|
||||||
|
$supplier->setPaymentDelay($this->paymentDelay('J30'));
|
||||||
|
$supplier->setPaymentType($this->paymentType($paymentTypeCode));
|
||||||
|
if ('VIREMENT' === $paymentTypeCode) {
|
||||||
|
$supplier->setBank($this->bank('SG'));
|
||||||
|
}
|
||||||
|
$em->persist($supplier);
|
||||||
|
|
||||||
|
// >= 2 sites fixtures pour une adresse multi-sites (RG-2.06).
|
||||||
|
$sites = $em->getRepository(Site::class)->findBy([], null, 2);
|
||||||
|
self::assertGreaterThanOrEqual(2, count($sites), 'Au moins 2 sites fixtures requis (SitesFixtures).');
|
||||||
|
|
||||||
|
$contact = new SupplierContact();
|
||||||
|
$contact->setSupplier($supplier);
|
||||||
|
$contact->setFirstName('Marie');
|
||||||
|
$contact->setLastName('Martin');
|
||||||
|
$contact->setJobTitle('Responsable achats');
|
||||||
|
$contact->setPhonePrimary('0612345678');
|
||||||
|
$contact->setEmail('marie.martin@seed.test');
|
||||||
|
$supplier->addContact($contact);
|
||||||
|
$em->persist($contact);
|
||||||
|
|
||||||
|
$address = new SupplierAddress();
|
||||||
|
$address->setSupplier($supplier);
|
||||||
|
$address->setAddressType('DEPART');
|
||||||
|
$address->setPostalCode('86000');
|
||||||
|
$address->setCity('Poitiers');
|
||||||
|
$address->setStreet('12 rue des Acacias');
|
||||||
|
$address->setBennes(3);
|
||||||
|
// triageProvider=true : prouve qu'un booleen `true` est bien serialise
|
||||||
|
// (piege n°3 du M1 — la cle etait droppee).
|
||||||
|
$address->setTriageProvider(true);
|
||||||
|
foreach ($sites as $site) {
|
||||||
|
$address->addSite($site);
|
||||||
|
}
|
||||||
|
$address->addCategory($this->supplierCategory('NEGOCIANT'));
|
||||||
|
$address->addContact($contact);
|
||||||
|
$supplier->addAddress($address);
|
||||||
|
$em->persist($address);
|
||||||
|
|
||||||
|
$rib = new SupplierRib();
|
||||||
|
$rib->setSupplier($supplier);
|
||||||
|
$rib->setLabel('Compte principal');
|
||||||
|
$rib->setBic(self::VALID_BIC);
|
||||||
|
$rib->setIban(self::VALID_IBAN);
|
||||||
|
$supplier->addRib($rib);
|
||||||
|
$em->persist($rib);
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $supplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un contact a un fournisseur deja persiste (seed direct).
|
||||||
|
*/
|
||||||
|
protected function addContact(
|
||||||
|
Supplier $supplier,
|
||||||
|
?string $firstName = 'Marie',
|
||||||
|
?string $lastName = 'Martin',
|
||||||
|
?string $phonePrimary = null,
|
||||||
|
?string $email = null,
|
||||||
|
int $position = 0,
|
||||||
|
): SupplierContact {
|
||||||
|
$contact = new SupplierContact();
|
||||||
|
$contact->setSupplier($supplier);
|
||||||
|
$contact->setFirstName($firstName);
|
||||||
|
$contact->setLastName($lastName);
|
||||||
|
$contact->setPhonePrimary($phonePrimary);
|
||||||
|
$contact->setEmail($email);
|
||||||
|
$contact->setPosition($position);
|
||||||
|
$supplier->addContact($contact);
|
||||||
|
$this->getEm()->persist($contact);
|
||||||
|
$this->getEm()->flush();
|
||||||
|
|
||||||
|
return $contact;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un RIB a un fournisseur deja persiste (seed direct).
|
||||||
|
*/
|
||||||
|
protected function addRib(Supplier $supplier, string $label = 'Compte principal'): SupplierRib
|
||||||
|
{
|
||||||
|
$rib = new SupplierRib();
|
||||||
|
$rib->setSupplier($supplier);
|
||||||
|
$rib->setLabel($label);
|
||||||
|
$rib->setBic(self::VALID_BIC);
|
||||||
|
$rib->setIban(self::VALID_IBAN);
|
||||||
|
$supplier->addRib($rib);
|
||||||
|
$this->getEm()->persist($rib);
|
||||||
|
$this->getEm()->flush();
|
||||||
|
|
||||||
|
return $rib;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payload minimal valide de l'onglet principal (companyName + 1 categorie
|
||||||
|
* FOURNISSEUR). Si $categoryId est null, la categorie Negociant seedee est
|
||||||
|
* utilisee.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
protected function validMainPayload(string $companyName, ?int $categoryId = null): array
|
||||||
|
{
|
||||||
|
$categoryId ??= $this->supplierCategory('NEGOCIANT')->getId();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'companyName' => $companyName,
|
||||||
|
'categories' => ['/api/categories/'.$categoryId],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function paymentType(string $code): PaymentType
|
||||||
|
{
|
||||||
|
return $this->referential(PaymentType::class, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function paymentDelay(string $code): PaymentDelay
|
||||||
|
{
|
||||||
|
return $this->referential(PaymentDelay::class, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tvaMode(string $code): TvaMode
|
||||||
|
{
|
||||||
|
return $this->referential(TvaMode::class, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function bank(string $code): Bank
|
||||||
|
{
|
||||||
|
return $this->referential(Bank::class, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recupere un referentiel comptable seede (CommercialReferentialFixtures) par
|
||||||
|
* code. Echoue explicitement si absent (fixtures non chargees).
|
||||||
|
*
|
||||||
|
* @template T of object
|
||||||
|
*
|
||||||
|
* @param class-string<T> $entityClass
|
||||||
|
*
|
||||||
|
* @return T
|
||||||
|
*/
|
||||||
|
private function referential(string $entityClass, string $code): object
|
||||||
|
{
|
||||||
|
$entity = $this->getEm()->getRepository($entityClass)->findOneBy(['code' => $code]);
|
||||||
|
|
||||||
|
self::assertNotNull(
|
||||||
|
$entity,
|
||||||
|
sprintf('Referentiel %s "%s" introuvable : fixtures comptables chargees (make test-db-setup) ?', $entityClass, $code),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -146,6 +146,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'isBilling' => false,
|
'isBilling' => false,
|
||||||
'billingEmail' => 'parasite@test.fr',
|
'billingEmail' => 'parasite@test.fr',
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
@@ -174,6 +175,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'isBilling' => false,
|
'isBilling' => false,
|
||||||
'billingEmail' => '',
|
'billingEmail' => '',
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
@@ -187,6 +189,62 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(201);
|
self::assertResponseStatusCodeSame(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP-119 : une adresse de facturation accepte un 2e email (optionnel, max 2).
|
||||||
|
*/
|
||||||
|
public function testBillingAddressAcceptsTwoEmails(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Billing Two Emails');
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isBilling' => true,
|
||||||
|
'billingEmail' => 'facturation@test.fr',
|
||||||
|
'billingEmailSecondary' => 'compta@test.fr',
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ERP-119 : le 2e email de facturation, comme le principal, n'est autorise que
|
||||||
|
* sur une adresse de facturation -> 422 avec violation sur billingEmailSecondary.
|
||||||
|
*/
|
||||||
|
public function testSecondaryBillingEmailRejectedOnNonBillingAddress(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Secondary Email Non Billing');
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$body = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
|
'billingEmailSecondary' => 'compta@test.fr',
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
])->toArray(false);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = $this->violationsByPath($body);
|
||||||
|
self::assertArrayHasKey('billingEmailSecondary', $byPath);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RG-1.29 : poster une categorie de type DISTRIBUTEUR sur une adresse -> 422
|
* RG-1.29 : poster une categorie de type DISTRIBUTEUR sur une adresse -> 422
|
||||||
* avec violation sur le champ `categories`.
|
* avec violation sur le champ `categories`.
|
||||||
@@ -201,6 +259,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
@@ -229,6 +288,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
@@ -253,6 +313,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
@@ -277,6 +338,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
@@ -301,6 +363,7 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
@@ -311,6 +374,115 @@ final class ClientAddressTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG (ERP-119) : au moins un type d'adresse (Prospection / Livraison /
|
||||||
|
* Facturation) est obligatoire. POST sans aucun drapeau de type -> 422, avec
|
||||||
|
* une violation portee sur `isProspect` (mappee sous le select « Type
|
||||||
|
* d'adresse » cote front via ClientAddressBlock).
|
||||||
|
*/
|
||||||
|
public function testAddressRequiresAtLeastOneType(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Address No Type');
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$body = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
])->toArray(false);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = $this->violationsByPath($body);
|
||||||
|
self::assertArrayHasKey('isProspect', $byPath);
|
||||||
|
self::assertSame('Le type d\'adresse est obligatoire.', $byPath['isProspect']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nouveaux types d'adresse (ERP-119) : Courtier et Distributeur sont acceptes
|
||||||
|
* comme types autonomes (avec site + categorie). is_broker / is_distributor.
|
||||||
|
*/
|
||||||
|
public function testBrokerAddressAccepted(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Address Broker Type');
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isBroker' => true,
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDistributorAddressAccepted(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Address Distributor Type');
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isDistributor' => true,
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Courtier / Distributeur sont des types AUTONOMES exclusifs : les combiner avec
|
||||||
|
* un autre usage (ici Livraison) -> 422, violation sur isProspect (mappee sous le
|
||||||
|
* select Type d'adresse). Miroir applicatif du CHECK chk_client_address_broker_exclusive.
|
||||||
|
*/
|
||||||
|
public function testExclusiveAddressTypeRejected(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Address Broker Mix');
|
||||||
|
$category = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$body = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isBroker' => true,
|
||||||
|
'isDelivery' => true,
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
'categories' => ['/api/categories/'.$category->getId()],
|
||||||
|
],
|
||||||
|
])->toArray(false);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = $this->violationsByPath($body);
|
||||||
|
self::assertArrayHasKey('isProspect', $byPath);
|
||||||
|
self::assertSame('Une adresse Courtier ne peut pas avoir d\'autre type.', $byPath['isProspect']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne l'IRI du premier site seede (fixtures Sites).
|
* Retourne l'IRI du premier site seede (fixtures Sites).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use App\Module\Sites\Domain\Entity\Site;
|
|||||||
*
|
*
|
||||||
* Authentifies en ADMIN (bypass RBAC via isAdmin) : on valide ici les regles
|
* Authentifies en ADMIN (bypass RBAC via isAdmin) : on valide ici les regles
|
||||||
* METIER (normalisation, unicite, distributor/broker, archivage, liste). Le
|
* METIER (normalisation, unicite, distributor/broker, archivage, liste). Le
|
||||||
* gating par permission (accounting.manage / archive / RG-1.28 strict, RG-1.04
|
* gating par permission (accounting.manage / archive / RG-1.28 strict) est
|
||||||
* Commerciale) est couvert par les tests unitaires du ClientProcessor : il
|
* couvert par les tests unitaires du ClientProcessor : il
|
||||||
* exige des users non-admin portant des permissions `commercial.clients.*` qui
|
* exige des users non-admin portant des permissions `commercial.clients.*` qui
|
||||||
* ne sont declarees qu'en ERP-59 (tests RBAC complets en ERP-60).
|
* ne sont declarees qu'en ERP-59 (tests RBAC complets en ERP-60).
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -85,4 +85,77 @@ final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertNotNull($persisted);
|
self::assertNotNull($persisted);
|
||||||
self::assertSame('LEGACY FIELDS SARL', $persisted->getCompanyName());
|
self::assertSame('LEGACY FIELDS SARL', $persisted->getCompanyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.03 bis : declarer une relation « depend d'un distributeur »
|
||||||
|
* (relationType, champ transitoire) sans renseigner la FK distributor doit
|
||||||
|
* produire une 422 portee sur `distributor`. Le back ne peut pas deviner
|
||||||
|
* l'intention depuis la seule FK nullable (distributor=null = client
|
||||||
|
* independant), d'ou relationType qui la transporte.
|
||||||
|
*/
|
||||||
|
public function testRelationDistributeurSansDistributeurEst422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$body = $client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Relation Sans Distrib SARL',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
'relationType' => 'distributeur',
|
||||||
|
],
|
||||||
|
])->toArray(false);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = $this->violationsByPath($body);
|
||||||
|
self::assertArrayHasKey('distributor', $byPath);
|
||||||
|
self::assertSame('Le nom du distributeur est obligatoire.', $byPath['distributor']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Idem courtier : relationType=courtier sans broker -> 422 portee sur `broker`. */
|
||||||
|
public function testRelationCourtierSansCourtierEst422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$body = $client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Relation Sans Courtier SARL',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
'relationType' => 'courtier',
|
||||||
|
],
|
||||||
|
])->toArray(false);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = $this->violationsByPath($body);
|
||||||
|
self::assertArrayHasKey('broker', $byPath);
|
||||||
|
self::assertSame('Le nom du courtier est obligatoire.', $byPath['broker']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Le champ transitoire relationType ne casse pas la creation nominale : avec
|
||||||
|
* la FK correspondante renseignee, le client se cree (201) et relationType
|
||||||
|
* n'est jamais serialise en sortie (write-only, aucun groupe de lecture).
|
||||||
|
*/
|
||||||
|
public function testRelationDistributeurAvecDistributeurEst201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
$distributor = $this->seedClient('Distrib Cible', false, 'DISTRIBUTEUR');
|
||||||
|
|
||||||
|
$data = $client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Relation Ok SARL',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
'relationType' => 'distributeur',
|
||||||
|
'distributor' => '/api/clients/'.$distributor->getId(),
|
||||||
|
],
|
||||||
|
])->toArray();
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
self::assertArrayNotHasKey('relationType', $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ use Symfony\Component\Console\Output\NullOutput;
|
|||||||
/**
|
/**
|
||||||
* Matrice RBAC complete du repertoire clients par role metier (spec-back M1
|
* Matrice RBAC complete du repertoire clients par role metier (spec-back M1
|
||||||
* § 2.7 + cahier ERP-74). Valide 200/403 par verbe et par onglet pour
|
* § 2.7 + cahier ERP-74). Valide 200/403 par verbe et par onglet pour
|
||||||
* bureau / compta / commerciale / usine, plus le durcissement RG-1.04
|
* bureau / compta / commerciale / usine.
|
||||||
* (Commerciale) au POST.
|
|
||||||
*
|
*
|
||||||
* Les comptes demo et la matrice sont seedes via la commande reelle
|
* Les comptes demo et la matrice sont seedes via la commande reelle
|
||||||
* `app:seed-rbac --with-demo-users` (le MEME chemin qu'en recette), idempotente.
|
* `app:seed-rbac --with-demo-users` (le MEME chemin qu'en recette), idempotente.
|
||||||
@@ -174,14 +173,14 @@ final class ClientRBACMatrixTest extends AbstractCommercialApiTestCase
|
|||||||
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
||||||
self::assertResponseStatusCodeSame(200);
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
// manage : la creation passe la security d'operation (pas un 403 comme
|
// manage : la creation passe la security d'operation et aboutit -> 201
|
||||||
// Compta) mais bute sur RG-1.04 (onglet Information incomplet) -> 422.
|
// (l'onglet Information est facultatif pour tous depuis le retrait de
|
||||||
// C'est la preuve que Commerciale porte `manage` (sinon 403).
|
// RG-1.04). C'est la preuve que Commerciale porte `manage` (sinon 403).
|
||||||
$client->request('POST', '/api/clients', [
|
$client->request('POST', '/api/clients', [
|
||||||
'headers' => ['Content-Type' => self::LD],
|
'headers' => ['Content-Type' => self::LD],
|
||||||
'json' => $this->validMainPayload('Commerciale Post'),
|
'json' => $this->validMainPayload('Commerciale Post'),
|
||||||
]);
|
]);
|
||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|
||||||
// PAS accounting : edition onglet Comptabilite refusee
|
// PAS accounting : edition onglet Comptabilite refusee
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
||||||
@@ -198,27 +197,6 @@ final class ClientRBACMatrixTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(403);
|
self::assertResponseStatusCodeSame(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRG104CommercialePostIncompleteIs422AdminIs201(): void
|
|
||||||
{
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
// RG-1.04 durcie : Commerciale POST sans onglet Information complet -> 422.
|
|
||||||
$commerciale = $this->authAs('commerciale');
|
|
||||||
$commerciale->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('RG104 Commerciale', $cat->getId()),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
|
|
||||||
// Meme payload par un Admin (non gate par RG-1.04) -> 201.
|
|
||||||
$admin = $this->createAdminClient();
|
|
||||||
$admin->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('RG104 Admin', $cat->getId()),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testComptaFullRepresentationPatchWithUnchangedCategoriesIsNotForbidden(): void
|
public function testComptaFullRepresentationPatchWithUnchangedCategoriesIsNotForbidden(): void
|
||||||
{
|
{
|
||||||
// FIX review MR #40 : un Compta (accounting.manage, PAS manage) faisant un
|
// FIX review MR #40 : un Compta (accounting.manage, PAS manage) faisant un
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ namespace App\Tests\Module\Commercial\Api;
|
|||||||
* - 403 si l'utilisateur authentifie ne porte pas `commercial.clients.view`.
|
* - 403 si l'utilisateur authentifie ne porte pas `commercial.clients.view`.
|
||||||
*
|
*
|
||||||
* ⚠ La matrice RBAC differenciee par role metier (bureau / compta / commerciale
|
* ⚠ La matrice RBAC differenciee par role metier (bureau / compta / commerciale
|
||||||
* / usine) et le test fonctionnel RG-1.04 sont DELEGUES a ERP-74 (#493) : ils
|
* / usine) est DELEGUEE a ERP-74 (#493) : elle exige les roles seedes apres le
|
||||||
* exigent les roles seedes apres le merge de la stack. NE PAS les ajouter ici.
|
* merge de la stack. NE PAS l'ajouter ici.
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -59,12 +59,18 @@ final class ClientSerializationContractTest extends AbstractCommercialApiTestCas
|
|||||||
self::assertArrayHasKey('isProspect', $address);
|
self::assertArrayHasKey('isProspect', $address);
|
||||||
self::assertArrayHasKey('isDelivery', $address);
|
self::assertArrayHasKey('isDelivery', $address);
|
||||||
self::assertArrayHasKey('isBilling', $address);
|
self::assertArrayHasKey('isBilling', $address);
|
||||||
|
// Memes garanties pour les types Courtier / Distributeur (ERP-119, meme
|
||||||
|
// pattern getter + SerializedName).
|
||||||
|
self::assertArrayHasKey('isBroker', $address);
|
||||||
|
self::assertArrayHasKey('isDistributor', $address);
|
||||||
|
|
||||||
// L'adresse seedee est livraison + facturation (prospect exclusif, RG-1.06).
|
// L'adresse seedee est livraison + facturation (prospect exclusif, RG-1.06).
|
||||||
// Prouve qu'un booleen `true` est bien serialise (le bug masquait meme les true).
|
// Prouve qu'un booleen `true` est bien serialise (le bug masquait meme les true).
|
||||||
self::assertFalse($address['isProspect']);
|
self::assertFalse($address['isProspect']);
|
||||||
self::assertTrue($address['isDelivery']);
|
self::assertTrue($address['isDelivery']);
|
||||||
self::assertTrue($address['isBilling']);
|
self::assertTrue($address['isBilling']);
|
||||||
|
self::assertFalse($address['isBroker']);
|
||||||
|
self::assertFalse($address['isDistributor']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// === #80 — Gating des RIB par accounting.view ===
|
// === #80 — Gating des RIB par accounting.view ===
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
private const string MERGE = 'application/merge-patch+json';
|
private const string MERGE = 'application/merge-patch+json';
|
||||||
private const string VALID_IBAN = 'FR1420041010050500013M02606';
|
private const string VALID_IBAN = 'FR1420041010050500013M02606';
|
||||||
private const string VALID_BIC = 'BNPAFRPPXXX';
|
private const string VALID_BIC = 'BNPAFRPPXXX';
|
||||||
|
// BIC allemand valide isolement (pays DE en positions 5-6) : sert au controle
|
||||||
|
// croise pays BIC/IBAN (DE vs IBAN FR -> mismatch, cf. Assert\Bic ibanPropertyPath).
|
||||||
|
private const string FOREIGN_BIC = 'DEUTDEFFXXX';
|
||||||
|
|
||||||
// === Contacts ===
|
// === Contacts ===
|
||||||
|
|
||||||
@@ -86,10 +89,7 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
$byPath = [];
|
$byPath = $this->violationsByPath($response->toArray(false));
|
||||||
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::assertArrayHasKey('email', $byPath, 'La violation email doit porter propertyPath=email (mapping front).');
|
||||||
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
||||||
@@ -132,10 +132,7 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
$byPath = [];
|
$byPath = $this->violationsByPath($response->toArray(false));
|
||||||
foreach ($response->toArray(false)['violations'] ?? [] as $v) {
|
|
||||||
$byPath[$v['propertyPath']] = $v['message'];
|
|
||||||
}
|
|
||||||
self::assertArrayHasKey('email', $byPath);
|
self::assertArrayHasKey('email', $byPath);
|
||||||
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
self::assertSame('L\'adresse email n\'est pas valide.', $byPath['email']);
|
||||||
}
|
}
|
||||||
@@ -234,6 +231,7 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '86100',
|
'postalCode' => '86100',
|
||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
@@ -255,6 +253,7 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
$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],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '123',
|
'postalCode' => '123',
|
||||||
'city' => 'Châtellerault',
|
'city' => 'Châtellerault',
|
||||||
'street' => '1 rue du Test',
|
'street' => '1 rue du Test',
|
||||||
@@ -284,6 +283,7 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '75001',
|
'postalCode' => '75001',
|
||||||
'city' => 'Paris',
|
'city' => 'Paris',
|
||||||
'street' => '2 rue Neuve',
|
'street' => '2 rue Neuve',
|
||||||
@@ -310,6 +310,7 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
$client->request('POST', '/api/clients/999999/addresses', [
|
$client->request('POST', '/api/clients/999999/addresses', [
|
||||||
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
'json' => [
|
'json' => [
|
||||||
|
'isDelivery' => true,
|
||||||
'postalCode' => '75001',
|
'postalCode' => '75001',
|
||||||
'city' => 'Paris',
|
'city' => 'Paris',
|
||||||
'street' => '2 rue Neuve',
|
'street' => '2 rue Neuve',
|
||||||
@@ -359,6 +360,32 @@ final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|||||||
self::assertResponseStatusCodeSame(422);
|
self::assertResponseStatusCodeSame(422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controle croise pays BIC/IBAN (Assert\Bic ibanPropertyPath) : un BIC (DE) et
|
||||||
|
* un IBAN (FR) valides isolement mais de pays differents -> 422. La violation
|
||||||
|
* porte propertyPath=bic et le message FR `ibanMessage` (mapping inline front).
|
||||||
|
*/
|
||||||
|
public function testPostRibWithBicIbanCountryMismatchReturns422WithFrenchMessageOnBic(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Rib Pays Mismatch');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/ribs', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'label' => 'Compte incoherent',
|
||||||
|
'bic' => self::FOREIGN_BIC,
|
||||||
|
'iban' => self::VALID_IBAN,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = $this->violationsByPath($response->toArray(false));
|
||||||
|
|
||||||
|
self::assertArrayHasKey('bic', $byPath, 'Le mismatch pays BIC/IBAN doit porter propertyPath=bic (mapping front).');
|
||||||
|
self::assertSame('Le BIC ne correspond pas au pays de l\'IBAN.', $byPath['bic']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regression ERP-110 : POST d'un RIB sur un client qui en a DEJA >= 2 ne doit
|
* 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
|
* pas exploser en 500 (NonUniqueResult sur la resolution du parent). L'admin
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests fonctionnels des RG comptables inter-champs portees par les Assert\Callback
|
||||||
|
* de l'entite Supplier (M2, RG-2.07 / RG-2.08), via le PATCH de l'onglet
|
||||||
|
* Comptabilite (groupe supplier:write:accounting). On asserte le code HTTP et le
|
||||||
|
* propertyPath de la violation (consommable par extractApiViolations cote front,
|
||||||
|
* ERP-101). Complete les tests unitaires SupplierValidationTest par la preuve HTTP.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class SupplierAccountingApiTest extends AbstractSupplierApiTestCase
|
||||||
|
{
|
||||||
|
// === RG-2.07 : Virement impose une banque ===
|
||||||
|
|
||||||
|
public function testVirementWithoutBankReturns422OnBankPath(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Virement No Bank');
|
||||||
|
|
||||||
|
$response = $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE, 'Accept' => self::LD],
|
||||||
|
'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('VIREMENT')->getId()],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
self::assertArrayHasKey('bank', $this->violationsByPath($response->toArray(false)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testVirementWithBankReturns200(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Virement With Bank');
|
||||||
|
|
||||||
|
$client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => [
|
||||||
|
'paymentType' => '/api/payment_types/'.$this->paymentType('VIREMENT')->getId(),
|
||||||
|
'bank' => '/api/banks/'.$this->bank('SG')->getId(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === RG-2.08 : LCR impose au moins un RIB ===
|
||||||
|
|
||||||
|
public function testLcrWithoutRibReturns422OnRibsPath(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Lcr No Rib');
|
||||||
|
|
||||||
|
$response = $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE, 'Accept' => self::LD],
|
||||||
|
'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('LCR')->getId()],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
self::assertArrayHasKey('ribs', $this->violationsByPath($response->toArray(false)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLcrWithRibReturns200(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Lcr With Rib');
|
||||||
|
$this->addRib($seed);
|
||||||
|
|
||||||
|
$client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['paymentType' => '/api/payment_types/'.$this->paymentType('LCR')->getId()],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// violationsByPath() : helper mutualise dans AbstractSupplierApiTestCase.
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests fonctionnels du formulaire principal fournisseur (M2, spec § 4.3 / § 4.4)
|
||||||
|
* sur le CORPS JSON : creation (companyName + categories), normalisation serveur
|
||||||
|
* (RG-2.12 UPPERCASE), categorie de type FOURNISSEUR (RG-2.10), unicite du nom
|
||||||
|
* (RG-2.11) et archivage nominal (RG-2.14). Jumeau de ClientApiTest (M1).
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class SupplierApiTest extends AbstractSupplierApiTestCase
|
||||||
|
{
|
||||||
|
// === POST formulaire principal ===
|
||||||
|
|
||||||
|
public function testPostMainFormUppercasesCompanyName(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->supplierCategory('NEGOCIANT');
|
||||||
|
|
||||||
|
$data = $client->request('POST', '/api/suppliers', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'recycla sas',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
],
|
||||||
|
])->toArray();
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
// RG-2.12 : companyName normalise en MAJUSCULES sur la valeur RENVOYEE.
|
||||||
|
self::assertSame('RECYCLA SAS', $data['companyName']);
|
||||||
|
// Embed categorie : code/name presents (category:read dans le contexte).
|
||||||
|
self::assertSame('NEGOCIANT', $data['categories'][0]['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostMainFormHasNoInlineContactFields(): void
|
||||||
|
{
|
||||||
|
// refonte-contact V0.2 : plus aucun champ de contact inline au POST.
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->supplierCategory('NEGOCIANT');
|
||||||
|
|
||||||
|
$data = $client->request('POST', '/api/suppliers', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'No Inline Co',
|
||||||
|
// Champs historiques : ignores par le denormaliseur.
|
||||||
|
'firstName' => 'Ignored',
|
||||||
|
'lastName' => 'Ignored',
|
||||||
|
'phonePrimary' => '0612345678',
|
||||||
|
'email' => 'ignored@test.fr',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
],
|
||||||
|
])->toArray();
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
foreach (['firstName', 'lastName', 'phonePrimary', 'phoneSecondary', 'email'] as $key) {
|
||||||
|
self::assertArrayNotHasKey($key, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === RG-2.10 : categorie de type FOURNISSEUR ===
|
||||||
|
|
||||||
|
public function testPostWithNonFournisseurCategoryReturns422OnCategoriesPath(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
// createCategory() (parent) cree une categorie de type CLIENT -> interdite.
|
||||||
|
$clientTypedCategory = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/suppliers', [
|
||||||
|
'headers' => ['Content-Type' => self::LD, 'Accept' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Wrong Cat Type',
|
||||||
|
'categories' => ['/api/categories/'.$clientTypedCategory->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
$byPath = [];
|
||||||
|
foreach ($response->toArray(false)['violations'] ?? [] as $v) {
|
||||||
|
$byPath[$v['propertyPath']] = $v['message'];
|
||||||
|
}
|
||||||
|
// ERP-101 : la violation porte propertyPath=categories (mapping inline front).
|
||||||
|
self::assertArrayHasKey('categories', $byPath);
|
||||||
|
self::assertSame('Type de catégorie non autorisé (FOURNISSEUR attendu).', $byPath['categories']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === RG-2.11 : unicite du nom de societe ===
|
||||||
|
|
||||||
|
public function testPostDuplicateCompanyNameReturns409(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$this->seedSupplier('Dup Name Co');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/suppliers', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => $this->validMainPayload('Dup Name Co'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// RG-2.11 : doublon parmi les actifs -> 409 (index uq_supplier_company_name_active).
|
||||||
|
self::assertResponseStatusCodeSame(409);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostSameNameAfterArchivingPreviousReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
// L'homonyme est archive -> hors index partiel : le nom redevient disponible.
|
||||||
|
$this->seedSupplier('Reuse After Archive', true);
|
||||||
|
|
||||||
|
$client->request('POST', '/api/suppliers', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => $this->validMainPayload('Reuse After Archive'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === RG-2.14 : archivage (admin) ===
|
||||||
|
|
||||||
|
public function testAdminArchiveSetsArchivedAt(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Archive Me');
|
||||||
|
|
||||||
|
$client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['isArchived' => true],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
|
$em = $this->getEm();
|
||||||
|
$em->clear();
|
||||||
|
$reloaded = $em->getRepository(Supplier::class)->find($seed->getId());
|
||||||
|
self::assertNotNull($reloaded);
|
||||||
|
self::assertTrue($reloaded->isArchived());
|
||||||
|
self::assertNotNull($reloaded->getArchivedAt(), 'RG-2.14 : archivedAt doit etre rempli a l\'archivage.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArchiveWithOtherFieldReturns422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Archive Plus Field');
|
||||||
|
|
||||||
|
// RG-2.14 : une requete d'archivage ne modifie aucun autre champ.
|
||||||
|
$response = $client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['isArchived' => true, 'companyName' => 'Renamed While Archiving'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
// Le 422 doit etre celui de RG-2.14 (archivage exclusif) et non un 422
|
||||||
|
// orthogonal : on verifie le message porte par l'exception.
|
||||||
|
self::assertStringContainsString('archivage', $response->getContent(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRestoreSetsArchivedAtNull(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Restore Me', true);
|
||||||
|
|
||||||
|
$client->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['isArchived' => false],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
|
$em = $this->getEm();
|
||||||
|
$em->clear();
|
||||||
|
$reloaded = $em->getRepository(Supplier::class)->find($seed->getId());
|
||||||
|
self::assertNotNull($reloaded);
|
||||||
|
self::assertFalse($reloaded->isArchived());
|
||||||
|
self::assertNull($reloaded->getArchivedAt(), 'RG-2.15 : archivedAt repasse a null a la restauration.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests d'archivage / restauration fournisseur — trou 409 de restauration en
|
||||||
|
* conflit d'unicite (M2, RG-2.15). Le nominal RG-2.14 (archive pose archivedAt)
|
||||||
|
* et le 422 « archive + autre champ » sont couverts par SupplierApiTest. Jumeau
|
||||||
|
* de ClientArchiveTest (M1).
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class SupplierArchiveTest extends AbstractSupplierApiTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* RG-2.15 : restaurer un fournisseur archive dont le nom a ete repris par un
|
||||||
|
* fournisseur actif entre-temps doit echouer en 409 (index partiel
|
||||||
|
* uq_supplier_company_name_active : un seul actif portant ce nom).
|
||||||
|
*/
|
||||||
|
public function testRestoreConflictReturns409(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
|
||||||
|
$archived = $this->seedSupplier('Acme Conflict', true);
|
||||||
|
$this->seedSupplier('Acme Conflict', false);
|
||||||
|
|
||||||
|
$client->request('PATCH', '/api/suppliers/'.$archived->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['isArchived' => false],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(409);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests Audit du repertoire fournisseurs (M2, spec § 6). Couvre :
|
||||||
|
* - POST / PATCH / archivage -> ligne audit_log entity_type='commercial.Supplier'
|
||||||
|
* avec l'action et le diff attendus ;
|
||||||
|
* - RIB : `#[Auditable]` SANS `#[AuditIgnore]` sur iban/bic -> ces champs sensibles
|
||||||
|
* DOIVENT apparaitre dans le diff audite (decision § 2.7, miroir M1).
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class SupplierAuditTest extends AbstractSupplierApiTestCase
|
||||||
|
{
|
||||||
|
private const string SUPPLIER_TYPE = 'commercial.Supplier';
|
||||||
|
private const string RIB_TYPE = 'commercial.SupplierRib';
|
||||||
|
|
||||||
|
private ?Connection $auditConnection = null;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
self::bootKernel();
|
||||||
|
|
||||||
|
/** @var Connection $conn */
|
||||||
|
$conn = self::getContainer()->get('doctrine.dbal.audit_connection');
|
||||||
|
$this->auditConnection = $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
if (null !== $this->auditConnection) {
|
||||||
|
$this->auditConnection->close();
|
||||||
|
}
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostSupplierIsAudited(): void
|
||||||
|
{
|
||||||
|
$admin = $this->createAdminClient();
|
||||||
|
$cat = $this->supplierCategory('NEGOCIANT');
|
||||||
|
|
||||||
|
$created = $admin->request('POST', '/api/suppliers', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Audit Created Co',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
],
|
||||||
|
])->toArray();
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|
||||||
|
self::assertGreaterThanOrEqual(
|
||||||
|
1,
|
||||||
|
$this->countAudit(self::SUPPLIER_TYPE, (string) $created['id'], 'create'),
|
||||||
|
'Un audit_log "create" doit etre genere pour le fournisseur.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPatchSupplierIsAudited(): void
|
||||||
|
{
|
||||||
|
$admin = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Audit Patch Co');
|
||||||
|
|
||||||
|
$admin->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['companyName' => 'Audit Patch Renamed'],
|
||||||
|
]);
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
|
self::assertGreaterThanOrEqual(
|
||||||
|
1,
|
||||||
|
$this->countAudit(self::SUPPLIER_TYPE, (string) $seed->getId(), 'update'),
|
||||||
|
'Un audit_log "update" doit etre genere pour le PATCH.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArchiveSupplierIsAudited(): void
|
||||||
|
{
|
||||||
|
$admin = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Audit Archive Co');
|
||||||
|
|
||||||
|
$admin->request('PATCH', '/api/suppliers/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['isArchived' => true],
|
||||||
|
]);
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
|
$rows = $this->auditConnection->fetchAllAssociative(
|
||||||
|
'SELECT changes FROM audit_log WHERE entity_type = :type AND entity_id = :id AND action = :action ORDER BY performed_at DESC',
|
||||||
|
['type' => self::SUPPLIER_TYPE, 'id' => (string) $seed->getId(), 'action' => 'update'],
|
||||||
|
);
|
||||||
|
self::assertGreaterThanOrEqual(1, count($rows));
|
||||||
|
|
||||||
|
/** @var array<string, mixed> $changes */
|
||||||
|
$changes = json_decode((string) $rows[0]['changes'], true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
self::assertArrayHasKey('isArchived', $changes, 'Le diff d\'archivage doit tracer isArchived.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRibCreateAuditIncludesIbanAndBic(): void
|
||||||
|
{
|
||||||
|
$admin = $this->createAdminClient();
|
||||||
|
$seed = $this->seedSupplier('Rib Audit Host');
|
||||||
|
|
||||||
|
$rib = $admin->request('POST', '/api/suppliers/'.$seed->getId().'/ribs', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'label' => 'Compte audite',
|
||||||
|
'bic' => self::VALID_BIC,
|
||||||
|
'iban' => self::VALID_IBAN,
|
||||||
|
],
|
||||||
|
])->toArray();
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|
||||||
|
$rows = $this->auditConnection->fetchAllAssociative(
|
||||||
|
'SELECT changes FROM audit_log WHERE entity_type = :type AND entity_id = :id AND action = :action ORDER BY performed_at DESC',
|
||||||
|
['type' => self::RIB_TYPE, 'id' => (string) $rib['id'], 'action' => 'create'],
|
||||||
|
);
|
||||||
|
self::assertGreaterThanOrEqual(1, count($rows), 'Un audit_log "create" doit etre genere pour le RIB.');
|
||||||
|
|
||||||
|
/** @var array<string, mixed> $changes */
|
||||||
|
$changes = json_decode((string) $rows[0]['changes'], true, flags: JSON_THROW_ON_ERROR);
|
||||||
|
self::assertArrayHasKey('iban', $changes, 'iban doit figurer dans le diff audite (pas d\'AuditIgnore).');
|
||||||
|
self::assertArrayHasKey('bic', $changes, 'bic doit figurer dans le diff audite (pas d\'AuditIgnore).');
|
||||||
|
self::assertSame(self::VALID_IBAN, $changes['iban']);
|
||||||
|
self::assertSame(self::VALID_BIC, $changes['bic']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function countAudit(string $type, string $id, string $action): int
|
||||||
|
{
|
||||||
|
return (int) $this->auditConnection->fetchOne(
|
||||||
|
'SELECT COUNT(*) FROM audit_log WHERE entity_type = :type AND entity_id = :id AND action = :action',
|
||||||
|
['type' => $type, 'id' => $id, 'action' => $action],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user