Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 865180e648 | |||
| 0e3299300f | |||
| 8d50f1fbe7 | |||
| 120058049c | |||
| 9507664bd0 | |||
| 0c9b563cae | |||
| b495e4030a | |||
| 56cf492dcc | |||
| d9023ec9b9 | |||
| ddf874a4e1 | |||
| a25ddac466 | |||
| df8e44fcfa | |||
| 5bdd63cc6c | |||
| ad20d1f4c9 | |||
| 0c6919201e | |||
| 3e46394be1 | |||
| 1d91b4dea9 | |||
| c402418937 | |||
| 2866fb8865 |
@@ -13,6 +13,64 @@
|
|||||||
- Le login `/login_check` est **hors** prefix `/api` (nginx reecrit `REQUEST_URI` vers `/login_check`)
|
- Le login `/login_check` est **hors** prefix `/api` (nginx reecrit `REQUEST_URI` vers `/login_check`)
|
||||||
- **Exception** : si tu dois creer un controller custom sous `/api/`, mettre `priority: 1` sur `#[Route]` pour eviter le conflit avec API Platform `{id}`
|
- **Exception** : si tu dois creer un controller custom sous `/api/`, mettre `priority: 1` sur `#[Route]` pour eviter le conflit avec API Platform `{id}`
|
||||||
|
|
||||||
|
## Pagination (obligatoire)
|
||||||
|
|
||||||
|
**Regle** : toute collection API DOIT etre paginee. Aucun retour de collection complete cote serveur.
|
||||||
|
|
||||||
|
### Standard global
|
||||||
|
|
||||||
|
Pose dans `config/packages/api_platform.yaml` (section `defaults:`) et heritee par toutes les ressources :
|
||||||
|
|
||||||
|
| Cle | Valeur | Effet |
|
||||||
|
|---|---|---|
|
||||||
|
| `pagination_enabled` | `true` | Pagination Hydra active par defaut. |
|
||||||
|
| `pagination_items_per_page` | `10` | Taille de page par defaut, aligne sur l'UI `MalioDataTable`. |
|
||||||
|
| `pagination_maximum_items_per_page` | `50` | Borne dure : `?itemsPerPage=999` → ramene a 50. Anti deep-fetch. |
|
||||||
|
| `pagination_client_items_per_page` | `true` | Le client peut envoyer `?itemsPerPage=25` (bornee par le max). |
|
||||||
|
| `pagination_client_enabled` | `true` | Le client peut envoyer `?pagination=false` pour TOUT recuperer (echappatoire selects). |
|
||||||
|
|
||||||
|
### Override par ressource (rare)
|
||||||
|
|
||||||
|
Si une ressource a besoin d'un autre defaut (ex: payload lourd), utiliser les attributs sur l'operation. **JAMAIS `paginationEnabled: false`** sans whitelist explicite dans `tests/Architecture/CollectionsArePaginatedTest::EXCLUDED`.
|
||||||
|
|
||||||
|
```php
|
||||||
|
new GetCollection(
|
||||||
|
paginationItemsPerPage: 5, // override taille par defaut
|
||||||
|
paginationMaximumItemsPerPage: 20, // override borne max
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Selects et autocompletions
|
||||||
|
|
||||||
|
Pour alimenter un `<select>` ou un drawer RBAC (Role, Permission, Site, CategoryType), le front passe :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
useApi().get('/api/roles?pagination=false')
|
||||||
|
```
|
||||||
|
|
||||||
|
Le serveur retourne toute la collection, sans `view`. C'est l'echappatoire prevue par `pagination_client_enabled: true`. Sur les ressources a forte volumetrie, preferer une saisie assistee (recherche serveur via `?q=`) — a planifier dans un ticket dedie.
|
||||||
|
|
||||||
|
Les tests fonctionnels qui exercent ce comportement doivent egalement passer `?pagination=false` (cf. `CategoryListTest`, `PermissionApiTest`).
|
||||||
|
|
||||||
|
### Providers customs et pagination
|
||||||
|
|
||||||
|
Un provider custom qui retourne un `array` brut sur une `CollectionOperationInterface` **court-circuite la pagination Hydra** (pas de `totalItems`, pas de `view`). Patterns supportes :
|
||||||
|
|
||||||
|
- **ORM** : injecter `ApiPlatform\State\Pagination\Pagination`, wrap un `Doctrine\ORM\Tools\Pagination\Paginator` dans `ApiPlatform\Doctrine\Orm\Paginator`. Exemple : `CategoryProvider`.
|
||||||
|
- **DBAL** : implementer un paginator local conforme a `PaginatorInterface`. Exemple : `DbalPaginator` (Core) + `AuditLogProvider`.
|
||||||
|
|
||||||
|
Gerer l'echappatoire `?pagination=false` :
|
||||||
|
|
||||||
|
```php
|
||||||
|
if (!$this->pagination->isEnabled($operation, $context)) {
|
||||||
|
return $qb->getQuery()->getResult(); // tout retourner
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Garde-fou architecture
|
||||||
|
|
||||||
|
`tests/Architecture/CollectionsArePaginatedTest` scanne reflexivement toutes les classes `#[ApiResource]` sous `src/` et echoue si une `GetCollection` pose `paginationEnabled: false` hors whitelist `EXCLUDED`. Ajouter une entree a la whitelist requiert une justification courte + un ticket Lesstime ouvert.
|
||||||
|
|
||||||
## Repositories
|
## Repositories
|
||||||
|
|
||||||
- Interface : `*RepositoryInterface` dans `Domain/Repository/`
|
- Interface : `*RepositoryInterface` dans `Domain/Repository/`
|
||||||
|
|||||||
@@ -53,6 +53,53 @@ Tout affichage LISTE tabulaire (donnees metier paginees, CRUD admin) doit passer
|
|||||||
|
|
||||||
**Exception** : tableaux purement presentationnels non paginables (diff field/old/new, grille de comparaison, matrice RBAC d'admin, etc.) peuvent rester en `<table>` HTML brut.
|
**Exception** : tableaux purement presentationnels non paginables (diff field/old/new, grille de comparaison, matrice RBAC d'admin, etc.) peuvent rester en `<table>` HTML brut.
|
||||||
|
|
||||||
|
## Listes paginees (standard) — usePaginatedList obligatoire
|
||||||
|
|
||||||
|
**Toute liste qui consomme une `GetCollection` API doit passer par `usePaginatedList`** (`frontend/shared/composables/usePaginatedList.ts`). Le composable est le pendant front de la regle ABSOLUE n°13 (« toute collection est paginee cote back ») : il consomme l'envelope Hydra (`member` / `totalItems` / `view`) et expose un etat reactif a brancher directement sur `MalioDataTable`.
|
||||||
|
|
||||||
|
Pattern de reference :
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const {
|
||||||
|
items,
|
||||||
|
totalItems,
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
itemsPerPageOptions,
|
||||||
|
fetch: loadList,
|
||||||
|
goToPage,
|
||||||
|
setItemsPerPage,
|
||||||
|
} = usePaginatedList<MyEntity>({ url: '/my-resources' })
|
||||||
|
|
||||||
|
onMounted(loadList)
|
||||||
|
```
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<MalioDataTable
|
||||||
|
:columns="columns"
|
||||||
|
:items="rows"
|
||||||
|
:total-items="totalItems"
|
||||||
|
:page="currentPage"
|
||||||
|
:per-page="itemsPerPage"
|
||||||
|
:per-page-options="itemsPerPageOptions"
|
||||||
|
:empty-message="t('foo.empty')"
|
||||||
|
@update:page="goToPage"
|
||||||
|
@update:per-page="setItemsPerPage"
|
||||||
|
/>
|
||||||
|
```
|
||||||
|
|
||||||
|
Garanties offertes par le composable :
|
||||||
|
- Force `Accept: application/ld+json` → API Platform 4 renvoie bien `member` / `totalItems` (sans Accept, retour tableau plat sans pagination).
|
||||||
|
- Defaut 10 items/page, choix client 10 / 25 / 50, aligne sur le defaut serveur.
|
||||||
|
- Mutation `setFilters` / `setSort` / `setItemsPerPage` → retombe systematiquement en page 1.
|
||||||
|
- Cas limite « page hors borne apres filtre » : retombe automatiquement sur la derniere page valide (`tests/usePaginatedList.test.ts`).
|
||||||
|
- Etat 100 % local (refs internes a l'instance) — **jamais reflete dans l'URL**, conformement a la regle « Etat des tableaux — pas de persistance URL » ci-dessous.
|
||||||
|
|
||||||
|
A NE PAS faire :
|
||||||
|
- Charger une collection complete via `?itemsPerPage=999` pour bypasser la pagination. Le seul cas legitime de retour complet est l'alimentation d'un `<select>` sur un referentiel ≤ quelques dizaines d'entrees, et il passe par `?pagination=false` (echappatoire prevue par `pagination_client_enabled: true`).
|
||||||
|
- Reimplementer la pagination prev/next a la main au-dessus de `MalioDataTable` — le composant porte deja le selecteur items/page et les boutons Prev/Next.
|
||||||
|
- Persister `page`/`tri`/`filtre` dans la query string — meme regle que pour `<MalioDataTable>` brut (cf. section suivante).
|
||||||
|
|
||||||
## Etat des tableaux — pas de persistance URL
|
## Etat des tableaux — pas de persistance URL
|
||||||
|
|
||||||
**Interdit** de persister l'etat d'un tableau (filtres, pagination, tri par colonne, selection, ligne active, scroll) dans la query string ou de le reinjecter depuis `route.query` au montage.
|
**Interdit** de persister l'etat d'un tableau (filtres, pagination, tri par colonne, selection, ligne active, scroll) dans la query string ou de le reinjecter depuis `route.query` au montage.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
## Contexte
|
## Contexte
|
||||||
CRM/ERP en architecture **modular monolith DDD**. Le backend est la source de verite unique (modules actifs, sidebar). Le frontend scanne `frontend/modules/*/` comme layers Nuxt et consomme l'API pour la navigation. Multi-tenant : chaque module est activable/desactivable.
|
CRM/ERP en architecture **modular monolith DDD**. Le backend est la source de verite unique (modules actifs, sidebar). Le frontend scanne `frontend/modules/*/` comme layers Nuxt et consomme l'API pour la navigation. Multi-tenant : chaque module est activable/desactivable.
|
||||||
|
|
||||||
Doc humaine : @README.md — Spec audit : @doc/audit-log.md
|
Doc humaine : `README.md` — Spec audit : `doc/audit-log.md` (à lire à la demande, non chargés en permanence).
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
- Backend : PHP 8.4, Symfony 8, API Platform 4, Doctrine ORM, PostgreSQL 16 (port 5437)
|
- Backend : PHP 8.4, Symfony 8, API Platform 4, Doctrine ORM, PostgreSQL 16 (port 5437)
|
||||||
@@ -25,6 +25,8 @@ Doc humaine : @README.md — Spec audit : @doc/audit-log.md
|
|||||||
10. **Jamais mentionner Claude, Anthropic ou une IA** dans un commit (message, titre, body, footer, trailer) ou une PR (titre, description). Pas de `Co-Authored-By: Claude`, pas de `Generated with Claude Code`, pas de `🤖`, pas d'emoji robot, rien. Les commits sont signes par l'utilisateur uniquement.
|
10. **Jamais mentionner Claude, Anthropic ou une IA** dans un commit (message, titre, body, footer, trailer) ou une PR (titre, description). Pas de `Co-Authored-By: Claude`, pas de `Generated with Claude Code`, pas de `🤖`, pas d'emoji robot, rien. Les commits sont signes par l'utilisateur uniquement.
|
||||||
11. **Migrations d'initialisation au namespace racine** `DoctrineMigrations` dans `migrations/` (setup user, RBAC, seed de base). Les migrations modulaires (`src/Module/*/Infrastructure/Doctrine/Migrations/`) sont reservees aux evolutions post-schema (ajout de colonnes, index) — cf. @.claude/rules/architecture.md pour la raison.
|
11. **Migrations d'initialisation au namespace racine** `DoctrineMigrations` dans `migrations/` (setup user, RBAC, seed de base). Les migrations modulaires (`src/Module/*/Infrastructure/Doctrine/Migrations/`) sont reservees aux evolutions post-schema (ajout de colonnes, index) — cf. @.claude/rules/architecture.md pour la raison.
|
||||||
12. **Toujours documenter chaque colonne BDD via `COMMENT ON COLUMN`** dans la migration qui la cree ou la modifie. Description en francais, courte (≤ 200 caracteres), explique la semantique metier + contraintes implicites (unicite partielle, FK importante, lien RG). Garde-fou : `tests/Architecture/ColumnsHaveSqlCommentTest` echoue si une colonne `public` n'a pas de description (`col_description IS NULL`). Details et exemples : @.claude/rules/backend.md § Migrations Doctrine.
|
12. **Toujours documenter chaque colonne BDD via `COMMENT ON COLUMN`** dans la migration qui la cree ou la modifie. Description en francais, courte (≤ 200 caracteres), explique la semantique metier + contraintes implicites (unicite partielle, FK importante, lien RG). Garde-fou : `tests/Architecture/ColumnsHaveSqlCommentTest` echoue si une colonne `public` n'a pas de description (`col_description IS NULL`). Details et exemples : @.claude/rules/backend.md § Migrations Doctrine.
|
||||||
|
13. **Toujours paginer toute collection exposee par l'API.** Aucun retour de collection complete (pas de provider qui retourne un array brut). Standard pose dans `config/packages/api_platform.yaml` : 10 items par defaut, max 50, le client peut basculer entre 10/25/50 et peut envoyer `?pagination=false` pour alimenter un select. Garde-fou : `tests/Architecture/CollectionsArePaginatedTest` echoue si une `GetCollection` desactive la pagination sans whitelist. Details et exemples : @.claude/rules/backend.md § Pagination.
|
||||||
|
14. **`symfony.lock` est versionne** (au meme titre que `composer.lock`) — ne JAMAIS le `.gitignore`. C'est le registre des recipes Flex appliquees : sans lui, chaque `composer require` rejoue toutes les recipes et repollue `.env`, `config/bundles.php`, `docker-compose.yml` et recree du scaffolding parasite (`src/Entity/`, `src/Controller/`...). Le regenerer si besoin via `composer recipes:install --force`.
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
@.claude/rules/architecture.md
|
@.claude/rules/architecture.md
|
||||||
@@ -35,7 +37,7 @@ Doc humaine : @README.md — Spec audit : @doc/audit-log.md
|
|||||||
@.claude/rules/git.md
|
@.claude/rules/git.md
|
||||||
@.claude/rules/workflow.md
|
@.claude/rules/workflow.md
|
||||||
|
|
||||||
## Commandes (liste complete dans @README.md)
|
## Commandes (liste complete dans `README.md`)
|
||||||
|
|
||||||
- Demarrer : `make start`
|
- Demarrer : `make start`
|
||||||
- Dev front (hot reload) : `make dev-nuxt` (port 3004)
|
- Dev front (hot reload) : `make dev-nuxt` (port 3004)
|
||||||
@@ -53,6 +55,7 @@ Editer uniquement `config/modules.php` (commenter la ligne). Cascade automatique
|
|||||||
## A NE PAS faire
|
## A NE PAS faire
|
||||||
|
|
||||||
- Pas de controller Symfony custom sous `/api/` sans `priority: 1` sur `#[Route]` (conflit API Platform `{id}`).
|
- Pas de controller Symfony custom sous `/api/` sans `priority: 1` sur `#[Route]` (conflit API Platform `{id}`).
|
||||||
|
- Pas de provider API Platform qui retourne un array brut sur une `GetCollection` — court-circuite la pagination Hydra (`totalItems` / `view` absents). Utiliser `ApiPlatform\Doctrine\Orm\Paginator` (ORM) ou un paginator implementant `PaginatorInterface` (DBAL — cf. `DbalPaginator`).
|
||||||
- Pas de `getClientMimeType()` pour valider un upload — utiliser `$file->getMimeType()` (serveur).
|
- Pas de `getClientMimeType()` pour valider un upload — utiliser `$file->getMimeType()` (serveur).
|
||||||
- Pas de hardcode de la sidebar cote front, pas de `modules-loader.ts` ni `.module.ts`.
|
- Pas de hardcode de la sidebar cote front, pas de `modules-loader.ts` ni `.module.ts`.
|
||||||
- Pas d'edition manuelle de `extends` dans `frontend/nuxt.config.ts` — les layers sont scannes automatiquement.
|
- Pas d'edition manuelle de `extends` dans `frontend/nuxt.config.ts` — les layers sont scannes automatiquement.
|
||||||
@@ -67,3 +70,5 @@ Editer uniquement `config/modules.php` (commenter la ligne). Cascade automatique
|
|||||||
## Credentials (dev)
|
## Credentials (dev)
|
||||||
|
|
||||||
`admin` / `admin` (ROLE_ADMIN) ; `alice` / `alice`, `bob` / `bob` (ROLE_USER).
|
`admin` / `admin` (ROLE_ADMIN) ; `alice` / `alice`, `bob` / `bob` (ROLE_USER).
|
||||||
|
|
||||||
|
Comptes demo des roles metier (seedes par `RbacDemoFixtures` / `app:seed-rbac --with-demo-users`, mot de passe `demo`) : `bureau` / `demo`, `compta` / `demo`, `commerciale` / `demo`, `usine` / `demo`. Matrice RBAC § 2.7 (M1 Clients) attachee aux roles correspondants.
|
||||||
|
|||||||
@@ -169,13 +169,41 @@ Secrets requis dans Gitea :
|
|||||||
- `RELEASE_TOKEN` — PAT avec droits `write:repository`
|
- `RELEASE_TOKEN` — PAT avec droits `write:repository`
|
||||||
- `REGISTRY_TOKEN` — token pour le registry Docker
|
- `REGISTRY_TOKEN` — token pour le registry Docker
|
||||||
|
|
||||||
|
## Déploiement — seed RBAC (recette / prod)
|
||||||
|
|
||||||
|
Le RBAC métier (rôles `bureau` / `compta` / `commerciale` / `usine` + matrice § 2.7)
|
||||||
|
est seedé par une **commande applicative idempotente** (présente dans le build prod,
|
||||||
|
contrairement aux fixtures Doctrine en `require-dev`). À jouer dans l'étape de release,
|
||||||
|
**après** les migrations et la synchronisation des permissions :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php bin/console doctrine:migrations:migrate --no-interaction
|
||||||
|
php bin/console app:sync-permissions # pose les permissions commercial.clients.*
|
||||||
|
php bin/console app:seed-rbac # PROD : rôles + matrice § 2.7 (sans comptes démo)
|
||||||
|
```
|
||||||
|
|
||||||
|
En **recette / staging**, ajouter le flag pour disposer de logins de test (mot de passe
|
||||||
|
fourni explicitement, jamais en dur) :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php bin/console app:seed-rbac --with-demo-users --password='<mot-de-passe>'
|
||||||
|
# ou via la variable d'env RBAC_DEMO_PASSWORD
|
||||||
|
```
|
||||||
|
|
||||||
|
La commande est rejouable sans effet de bord (aucun doublon de rôle, de lien ou de compte).
|
||||||
|
En dev, `make db-reset` produit le même résultat (rôles + matrice + comptes démo).
|
||||||
|
|
||||||
## Credentials (dev)
|
## Credentials (dev)
|
||||||
|
|
||||||
| Username | Password | Role |
|
| Username | Password | Role | RBAC métier |
|
||||||
|----------|----------|------|
|
|----------|----------|------|-------------|
|
||||||
| admin | admin | ROLE_ADMIN |
|
| admin | admin | ROLE_ADMIN | bypass (is_admin) |
|
||||||
| alice | alice | ROLE_USER |
|
| alice | alice | ROLE_USER | — |
|
||||||
| bob | bob | ROLE_USER |
|
| bob | bob | ROLE_USER | — |
|
||||||
|
| bureau | demo | ROLE_USER | clients : view + manage |
|
||||||
|
| compta | demo | ROLE_USER | clients : view + accounting.view/manage |
|
||||||
|
| commerciale | demo | ROLE_USER | clients : view + manage (Information obligatoire — RG-1.04) |
|
||||||
|
| usine | demo | ROLE_USER | aucun accès clients |
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"nelmio/cors-bundle": "^2.6",
|
"nelmio/cors-bundle": "^2.6",
|
||||||
"nyholm/psr7": "^1.8",
|
"nyholm/psr7": "^1.8",
|
||||||
"phpdocumentor/reflection-docblock": "^5.6|^6.0",
|
"phpdocumentor/reflection-docblock": "^5.6|^6.0",
|
||||||
|
"phpoffice/phpspreadsheet": "^5.7",
|
||||||
"phpstan/phpdoc-parser": "^2.3",
|
"phpstan/phpdoc-parser": "^2.3",
|
||||||
"symfony/asset": "8.0.*",
|
"symfony/asset": "8.0.*",
|
||||||
"symfony/console": "8.0.*",
|
"symfony/console": "8.0.*",
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
"symfony/expression-language": "8.0.*",
|
"symfony/expression-language": "8.0.*",
|
||||||
"symfony/flex": "^2",
|
"symfony/flex": "^2",
|
||||||
"symfony/framework-bundle": "8.0.*",
|
"symfony/framework-bundle": "8.0.*",
|
||||||
|
"symfony/intl": "8.0.*",
|
||||||
"symfony/mime": "8.0.*",
|
"symfony/mime": "8.0.*",
|
||||||
"symfony/monolog-bundle": "^4.0",
|
"symfony/monolog-bundle": "^4.0",
|
||||||
"symfony/property-access": "8.0.*",
|
"symfony/property-access": "8.0.*",
|
||||||
|
|||||||
Generated
+514
-80
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "d65a546151abb6b977fbf7f1c86d14fe",
|
"content-hash": "aada2e60fd7563f1498b5505b37e3f4b",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "api-platform/doctrine-common",
|
"name": "api-platform/doctrine-common",
|
||||||
@@ -1160,6 +1160,85 @@
|
|||||||
},
|
},
|
||||||
"time": "2026-03-17T15:23:21+00:00"
|
"time": "2026-03-17T15:23:21+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "composer/pcre",
|
||||||
|
"version": "3.3.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/composer/pcre.git",
|
||||||
|
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
||||||
|
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.4 || ^8.0"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"phpstan/phpstan": "<1.11.10"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpstan/phpstan": "^1.12 || ^2",
|
||||||
|
"phpstan/phpstan-strict-rules": "^1 || ^2",
|
||||||
|
"phpunit/phpunit": "^8 || ^9"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"phpstan": {
|
||||||
|
"includes": [
|
||||||
|
"extension.neon"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "3.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Composer\\Pcre\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jordi Boggiano",
|
||||||
|
"email": "j.boggiano@seld.be",
|
||||||
|
"homepage": "http://seld.be"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
|
||||||
|
"keywords": [
|
||||||
|
"PCRE",
|
||||||
|
"preg",
|
||||||
|
"regex",
|
||||||
|
"regular expression"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/composer/pcre/issues",
|
||||||
|
"source": "https://github.com/composer/pcre/tree/3.3.2"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://packagist.com",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/composer",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-11-12T16:29:46+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "composer/semver",
|
"name": "composer/semver",
|
||||||
"version": "3.4.4",
|
"version": "3.4.4",
|
||||||
@@ -2630,6 +2709,191 @@
|
|||||||
],
|
],
|
||||||
"time": "2025-12-20T17:47:00+00:00"
|
"time": "2025-12-20T17:47:00+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "maennchen/zipstream-php",
|
||||||
|
"version": "3.2.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/maennchen/ZipStream-PHP.git",
|
||||||
|
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
||||||
|
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-mbstring": "*",
|
||||||
|
"ext-zlib": "*",
|
||||||
|
"php-64bit": "^8.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"brianium/paratest": "^7.7",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.86",
|
||||||
|
"guzzlehttp/guzzle": "^7.5",
|
||||||
|
"mikey179/vfsstream": "^1.6",
|
||||||
|
"php-coveralls/php-coveralls": "^2.5",
|
||||||
|
"phpunit/phpunit": "^12.0",
|
||||||
|
"vimeo/psalm": "^6.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"guzzlehttp/psr7": "^2.4",
|
||||||
|
"psr/http-message": "^2.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"ZipStream\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Paul Duncan",
|
||||||
|
"email": "pabs@pablotron.org"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jonatan Männchen",
|
||||||
|
"email": "jonatan@maennchen.ch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jesse Donat",
|
||||||
|
"email": "donatj@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "András Kolesár",
|
||||||
|
"email": "kolesar@kolesar.hu"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
|
||||||
|
"keywords": [
|
||||||
|
"stream",
|
||||||
|
"zip"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/maennchen/ZipStream-PHP/issues",
|
||||||
|
"source": "https://github.com/maennchen/ZipStream-PHP/tree/3.2.2"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/maennchen",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-04-11T18:38:28+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "markbaker/complex",
|
||||||
|
"version": "3.0.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/MarkBaker/PHPComplex.git",
|
||||||
|
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
|
||||||
|
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.2 || ^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.3",
|
||||||
|
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Complex\\": "classes/src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Mark Baker",
|
||||||
|
"email": "mark@lange.demon.co.uk"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP Class for working with complex numbers",
|
||||||
|
"homepage": "https://github.com/MarkBaker/PHPComplex",
|
||||||
|
"keywords": [
|
||||||
|
"complex",
|
||||||
|
"mathematics"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/MarkBaker/PHPComplex/issues",
|
||||||
|
"source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.2"
|
||||||
|
},
|
||||||
|
"time": "2022-12-06T16:21:08+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "markbaker/matrix",
|
||||||
|
"version": "3.0.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/MarkBaker/PHPMatrix.git",
|
||||||
|
"reference": "728434227fe21be27ff6d86621a1b13107a2562c"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/728434227fe21be27ff6d86621a1b13107a2562c",
|
||||||
|
"reference": "728434227fe21be27ff6d86621a1b13107a2562c",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.1 || ^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.3",
|
||||||
|
"phpdocumentor/phpdocumentor": "2.*",
|
||||||
|
"phploc/phploc": "^4.0",
|
||||||
|
"phpmd/phpmd": "2.*",
|
||||||
|
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
||||||
|
"sebastian/phpcpd": "^4.0",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Matrix\\": "classes/src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Mark Baker",
|
||||||
|
"email": "mark@demon-angel.eu"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP Class for working with matrices",
|
||||||
|
"homepage": "https://github.com/MarkBaker/PHPMatrix",
|
||||||
|
"keywords": [
|
||||||
|
"mathematics",
|
||||||
|
"matrix",
|
||||||
|
"vector"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/MarkBaker/PHPMatrix/issues",
|
||||||
|
"source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.1"
|
||||||
|
},
|
||||||
|
"time": "2022-12-02T22:17:43+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "monolog/monolog",
|
"name": "monolog/monolog",
|
||||||
"version": "3.10.0",
|
"version": "3.10.0",
|
||||||
@@ -3052,6 +3316,115 @@
|
|||||||
},
|
},
|
||||||
"time": "2026-01-06T21:53:42+00:00"
|
"time": "2026-01-06T21:53:42+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "phpoffice/phpspreadsheet",
|
||||||
|
"version": "5.7.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
|
||||||
|
"reference": "9f55d3b9b7bcb1084fda8340e4b7ce4ed10cd0c8"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/9f55d3b9b7bcb1084fda8340e4b7ce4ed10cd0c8",
|
||||||
|
"reference": "9f55d3b9b7bcb1084fda8340e4b7ce4ed10cd0c8",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"composer/pcre": "^1||^2||^3",
|
||||||
|
"ext-ctype": "*",
|
||||||
|
"ext-dom": "*",
|
||||||
|
"ext-fileinfo": "*",
|
||||||
|
"ext-filter": "*",
|
||||||
|
"ext-gd": "*",
|
||||||
|
"ext-iconv": "*",
|
||||||
|
"ext-libxml": "*",
|
||||||
|
"ext-mbstring": "*",
|
||||||
|
"ext-simplexml": "*",
|
||||||
|
"ext-xml": "*",
|
||||||
|
"ext-xmlreader": "*",
|
||||||
|
"ext-xmlwriter": "*",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"ext-zlib": "*",
|
||||||
|
"maennchen/zipstream-php": "^2.1 || ^3.0",
|
||||||
|
"markbaker/complex": "^3.0",
|
||||||
|
"markbaker/matrix": "^3.0",
|
||||||
|
"php": "^8.1",
|
||||||
|
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "dev-main",
|
||||||
|
"dompdf/dompdf": "^2.0 || ^3.0",
|
||||||
|
"ext-intl": "*",
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.2",
|
||||||
|
"mitoteam/jpgraph": "^10.5",
|
||||||
|
"mpdf/mpdf": "^8.1.1",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.3",
|
||||||
|
"phpstan/phpstan": "^1.1 || ^2.0",
|
||||||
|
"phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0",
|
||||||
|
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
|
||||||
|
"phpunit/phpunit": "^10.5",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7",
|
||||||
|
"tecnickcom/tcpdf": "^6.5"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"dompdf/dompdf": "Option for rendering PDF with PDF Writer",
|
||||||
|
"ext-intl": "PHP Internationalization Functions, required for NumberFormat Wizard and StringHelper::setLocale()",
|
||||||
|
"mitoteam/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers",
|
||||||
|
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
|
||||||
|
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Maarten Balliauw",
|
||||||
|
"homepage": "https://blog.maartenballiauw.be"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mark Baker",
|
||||||
|
"homepage": "https://markbakeruk.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Franck Lefevre",
|
||||||
|
"homepage": "https://rootslabs.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Erik Tilt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Adrien Crivelli"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Owen Leibman"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
|
||||||
|
"homepage": "https://github.com/PHPOffice/PhpSpreadsheet",
|
||||||
|
"keywords": [
|
||||||
|
"OpenXML",
|
||||||
|
"excel",
|
||||||
|
"gnumeric",
|
||||||
|
"ods",
|
||||||
|
"php",
|
||||||
|
"spreadsheet",
|
||||||
|
"xls",
|
||||||
|
"xlsx"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
|
||||||
|
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/5.7.0"
|
||||||
|
},
|
||||||
|
"time": "2026-04-20T02:42:17+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpdoc-parser",
|
"name": "phpstan/phpdoc-parser",
|
||||||
"version": "2.3.2",
|
"version": "2.3.2",
|
||||||
@@ -3513,6 +3886,57 @@
|
|||||||
},
|
},
|
||||||
"time": "2024-09-11T13:17:53+00:00"
|
"time": "2024-09-11T13:17:53+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "psr/simple-cache",
|
||||||
|
"version": "3.0.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-fig/simple-cache.git",
|
||||||
|
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865",
|
||||||
|
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.0.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.0.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Psr\\SimpleCache\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "PHP-FIG",
|
||||||
|
"homepage": "https://www.php-fig.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Common interfaces for simple caching",
|
||||||
|
"keywords": [
|
||||||
|
"cache",
|
||||||
|
"caching",
|
||||||
|
"psr",
|
||||||
|
"psr-16",
|
||||||
|
"simple-cache"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/php-fig/simple-cache/tree/3.0.0"
|
||||||
|
},
|
||||||
|
"time": "2021-10-29T13:26:27+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/asset",
|
"name": "symfony/asset",
|
||||||
"version": "v8.0.8",
|
"version": "v8.0.8",
|
||||||
@@ -5172,6 +5596,95 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-03-31T21:14:05+00:00"
|
"time": "2026-03-31T21:14:05+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/intl",
|
||||||
|
"version": "v8.0.8",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/intl.git",
|
||||||
|
"reference": "604a1dbbd67471e885e93274379cadd80dc33535"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/intl/zipball/604a1dbbd67471e885e93274379cadd80dc33535",
|
||||||
|
"reference": "604a1dbbd67471e885e93274379cadd80dc33535",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.4"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"symfony/string": "<7.4"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"symfony/filesystem": "^7.4|^8.0",
|
||||||
|
"symfony/var-exporter": "^7.4|^8.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Symfony\\Component\\Intl\\": ""
|
||||||
|
},
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"/Tests/",
|
||||||
|
"/Resources/data/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Bernhard Schussek",
|
||||||
|
"email": "bschussek@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Eriksen Costa",
|
||||||
|
"email": "eriksen.costa@infranology.com.br"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Igor Wiedler",
|
||||||
|
"email": "igor@wiedler.ch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "https://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Provides access to the localization data of the ICU library",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"keywords": [
|
||||||
|
"i18n",
|
||||||
|
"icu",
|
||||||
|
"internationalization",
|
||||||
|
"intl",
|
||||||
|
"l10n",
|
||||||
|
"localization"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/intl/tree/v8.0.8"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/nicolas-grekas",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-03-30T15:14:47+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/mime",
|
"name": "symfony/mime",
|
||||||
"version": "v8.0.8",
|
"version": "v8.0.8",
|
||||||
@@ -8263,85 +8776,6 @@
|
|||||||
],
|
],
|
||||||
"time": "2022-12-23T10:58:28+00:00"
|
"time": "2022-12-23T10:58:28+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "composer/pcre",
|
|
||||||
"version": "3.3.2",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/composer/pcre.git",
|
|
||||||
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
|
||||||
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": "^7.4 || ^8.0"
|
|
||||||
},
|
|
||||||
"conflict": {
|
|
||||||
"phpstan/phpstan": "<1.11.10"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpstan/phpstan": "^1.12 || ^2",
|
|
||||||
"phpstan/phpstan-strict-rules": "^1 || ^2",
|
|
||||||
"phpunit/phpunit": "^8 || ^9"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"phpstan": {
|
|
||||||
"includes": [
|
|
||||||
"extension.neon"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-main": "3.x-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Composer\\Pcre\\": "src"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Jordi Boggiano",
|
|
||||||
"email": "j.boggiano@seld.be",
|
|
||||||
"homepage": "http://seld.be"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
|
|
||||||
"keywords": [
|
|
||||||
"PCRE",
|
|
||||||
"preg",
|
|
||||||
"regex",
|
|
||||||
"regular expression"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/composer/pcre/issues",
|
|
||||||
"source": "https://github.com/composer/pcre/tree/3.3.2"
|
|
||||||
},
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"url": "https://packagist.com",
|
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://github.com/composer",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
|
||||||
"type": "tidelift"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"time": "2024-11-12T16:29:46+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "composer/xdebug-handler",
|
"name": "composer/xdebug-handler",
|
||||||
"version": "3.0.5",
|
"version": "3.0.5",
|
||||||
|
|||||||
@@ -21,3 +21,18 @@ api_platform:
|
|||||||
stateless: true
|
stateless: true
|
||||||
cache_headers:
|
cache_headers:
|
||||||
vary: ['Content-Type', 'Authorization', 'Origin']
|
vary: ['Content-Type', 'Authorization', 'Origin']
|
||||||
|
# === Pagination Hydra (regle projet : toute collection DOIT etre paginee) ===
|
||||||
|
# Standard datatable : 10 items par defaut, choix client 10 / 25 / 50.
|
||||||
|
# Borne dure cote serveur a 50 pour prevenir tout `?itemsPerPage=999999`
|
||||||
|
# (attaque memoire / deep-fetch). Le client peut neanmoins desactiver la
|
||||||
|
# pagination via `?pagination=false` pour alimenter un <select> ou autre
|
||||||
|
# vue "tout-en-un" — c'est l'echappatoire prevue pour les ressources
|
||||||
|
# servant a la fois de datatable et de source de select (Role,
|
||||||
|
# Permission, Site, CategoryType). Override par ressource possible via
|
||||||
|
# `paginationItemsPerPage` / `paginationMaximumItemsPerPage` /
|
||||||
|
# `paginationEnabled` sur l'attribut #[ApiResource] ou sur une operation.
|
||||||
|
pagination_enabled: true
|
||||||
|
pagination_items_per_page: 10
|
||||||
|
pagination_maximum_items_per_page: 50
|
||||||
|
pagination_client_items_per_page: true
|
||||||
|
pagination_client_enabled: true
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ doctrine:
|
|||||||
# Permet a Shared de referencer UserInterface dans ses ORM mappings sans
|
# Permet a Shared de referencer UserInterface dans ses ORM mappings sans
|
||||||
# importer la classe concrete du module Core (cf. spec-back M0 § 2.8).
|
# importer la classe concrete du module Core (cf. spec-back M0 § 2.8).
|
||||||
Symfony\Component\Security\Core\User\UserInterface: App\Module\Core\Domain\Entity\User
|
Symfony\Component\Security\Core\User\UserInterface: App\Module\Core\Domain\Entity\User
|
||||||
|
# Cible des ManyToMany Client.categories / ClientAddress.categories (M1).
|
||||||
|
# Permet au module Commercial de referencer une Category via le contrat
|
||||||
|
# Shared sans importer la classe concrete du module Catalog (regle n°1).
|
||||||
|
App\Shared\Domain\Contract\CategoryInterface: App\Module\Catalog\Domain\Entity\Category
|
||||||
mappings:
|
mappings:
|
||||||
Core:
|
Core:
|
||||||
type: attribute
|
type: attribute
|
||||||
@@ -66,6 +70,16 @@ doctrine:
|
|||||||
dir: '%kernel.project_dir%/src/Module/Catalog/Domain/Entity'
|
dir: '%kernel.project_dir%/src/Module/Catalog/Domain/Entity'
|
||||||
prefix: 'App\Module\Catalog\Domain\Entity'
|
prefix: 'App\Module\Catalog\Domain\Entity'
|
||||||
alias: Catalog
|
alias: Catalog
|
||||||
|
# Mapping inconditionnel du module Commercial (meme logique que Catalog) :
|
||||||
|
# les tables (client, sous-collections, referentiels comptables) creees
|
||||||
|
# par la migration M1 (Version20260601000000) doivent etre connues de
|
||||||
|
# l'ORM. L'activation fonctionnelle passe par config/modules.php.
|
||||||
|
Commercial:
|
||||||
|
type: attribute
|
||||||
|
is_bundle: false
|
||||||
|
dir: '%kernel.project_dir%/src/Module/Commercial/Domain/Entity'
|
||||||
|
prefix: 'App\Module\Commercial\Domain\Entity'
|
||||||
|
alias: Commercial
|
||||||
controller_resolver:
|
controller_resolver:
|
||||||
auto_mapping: false
|
auto_mapping: false
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,13 @@ return [
|
|||||||
'label' => 'sidebar.commercial.section',
|
'label' => 'sidebar.commercial.section',
|
||||||
'icon' => 'mdi:account-arrow-left-outline',
|
'icon' => 'mdi:account-arrow-left-outline',
|
||||||
'items' => [
|
'items' => [
|
||||||
|
[
|
||||||
|
'label' => 'sidebar.commercial.clients',
|
||||||
|
'to' => '/clients',
|
||||||
|
'icon' => 'mdi:account-group-outline',
|
||||||
|
'module' => 'commercial',
|
||||||
|
'permission' => 'commercial.clients.view',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'label' => 'sidebar.commercial.suppliers',
|
'label' => 'sidebar.commercial.suppliers',
|
||||||
'to' => '/suppliers',
|
'to' => '/suppliers',
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.53'
|
app.version: '0.1.61'
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
# Cahier de test back — M1 Répertoire clients (ticket ERP-60 / #478)
|
||||||
|
|
||||||
|
Mapping **toutes les RG (§ 7) → test(s) PHPUnit**, à jour après ERP-60.
|
||||||
|
|
||||||
|
Légende source : `ERP-55` `ERP-56` `ERP-57` `ERP-58` = tests écrits par les wagons
|
||||||
|
précédents ; **`ERP-60`** = tests ajoutés par ce ticket (stratégie « combler les
|
||||||
|
trous, zéro duplication »).
|
||||||
|
|
||||||
|
## Stratégie
|
||||||
|
|
||||||
|
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
|
||||||
|
des **rôles métier** (matrice RBAC bureau/compta/commerciale/usine + RG-1.04
|
||||||
|
fonctionnel) sont **délégués à ERP-74 (#493)** : ces rôles n'existent qu'après le
|
||||||
|
merge de la stack.
|
||||||
|
|
||||||
|
## Mapping RG → test
|
||||||
|
|
||||||
|
| RG | Intitulé | Test(s) | Source |
|
||||||
|
|----|----------|---------|--------|
|
||||||
|
| RG-1.01 | Prénom OU nom obligatoire → 422 | `ClientApiTest::testPostWithoutFirstOrLastNameReturns422` ; `ClientProcessorTest` (unit) | ERP-55 |
|
||||||
|
| RG-1.02 | phoneSecondary persisté ; max 2 téléphones | `ClientFormulaireMainTest::testPostPersistsSecondaryPhoneNormalized` ; `::testThirdPhoneFieldIsIgnored` | **ERP-60** |
|
||||||
|
| 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.05 | Contact : prénom OU nom → 422 (CHECK) | `ClientSubResourceApiTest::testPostContactWithoutNameReturns422` | ERP-57 |
|
||||||
|
| RG-1.06/07/08 | Adresse prospect exclusive de livraison/facturation (CHECK) | `ClientAddressTest::testProspectAddressCannotBeDelivery` ; `::testProspectAddressCannotBeBilling` | **ERP-60** |
|
||||||
|
| RG-1.09 | Code postal `^[0-9]{4,5}$` → 422 | `ClientSubResourceApiTest::testPostAddressWithInvalidPostalCodeReturns422` | ERP-57 |
|
||||||
|
| RG-1.10 | ≥ 1 site sur adresse → 422 | `ClientSubResourceApiTest::testPostAddressWithoutSiteReturns422` | ERP-57 |
|
||||||
|
| RG-1.11 | billingEmail obligatoire ssi isBilling (CHECK) | `ClientAddressTest::testBillingAddressRequiresBillingEmail` ; `::testNonBillingAddressRejectsBillingEmail` | **ERP-60** |
|
||||||
|
| RG-1.12 | Virement → banque obligatoire → 422 | `ClientProcessorTest::testVirementWithoutBankIsUnprocessable` ; `::testVirementWithBankPasses` (unit) | ERP-55 |
|
||||||
|
| RG-1.13 | LCR → ≥ 1 RIB ; DELETE dernier RIB en LCR → 409 | `ClientProcessorTest::testLcrWithoutRibIsUnprocessable` / `::testLcrWithRibPasses` (unit) ; `ClientSubResourceApiTest::testDeleteLastRibUnderLcrReturns409` / `::testDeleteRibNonLcrReturns204` | ERP-55 / ERP-57 |
|
||||||
|
| RG-1.14 | ≥ 1 bloc Contact pour finaliser l'onglet | **Front-driven (pas de state machine back).** Back voisin : `ClientSubResourceApiTest::testDeleteLastContactReturns409` | ERP-57 |
|
||||||
|
| RG-1.15 | ~~Unicité SIREN~~ supprimée (Q4) — SIREN partageable | `ClientUniquenessTest::testDuplicateSirenIsAllowed` ; `ClientMigrationTest::testNoSirenOrEmailUniqueIndex` | **ERP-60** |
|
||||||
|
| RG-1.16 | companyName unique (case-insensitive) parmi actifs → 409 | `ClientApiTest::testPostDuplicateCompanyNameReturns409` ; `ClientMigrationTest::testCompanyNameActivePartialIndexExistsExactlyOnce` | ERP-55 / **ERP-60** |
|
||||||
|
| RG-1.17 | ~~Unicité email~~ supprimée (Q4) — email partageable | `ClientUniquenessTest::testDuplicateEmailIsAllowed` ; `ClientMigrationTest::testNoSirenOrEmailUniqueIndex` | **ERP-60** |
|
||||||
|
| RG-1.18 | companyName upper-cased serveur | `ClientApiTest::testPostNormalizesTextFields` ; `ClientFieldNormalizerTest::testCompanyNameIsUppercased` (unit) | ERP-55 |
|
||||||
|
| RG-1.19 | firstName/lastName capitalize serveur | `ClientApiTest::testPostNormalizesTextFields` ; `ClientFieldNormalizerTest::testPersonNameIsTitleCased` (unit) ; `ClientSubResourceApiTest::testPostContactNormalizesFields` | ERP-55 / ERP-57 |
|
||||||
|
| RG-1.20 | Téléphones chiffres-seuls serveur | `ClientApiTest::testPostNormalizesTextFields` ; `ClientFieldNormalizerTest::testPhoneKeepsOnlyDigits` (unit) ; `ClientFormulaireMainTest::testPostPersistsSecondaryPhoneNormalized` (secondary) | ERP-55 / **ERP-60** |
|
||||||
|
| RG-1.21 | email lowercase serveur | `ClientApiTest::testPostNormalizesTextFields` ; `ClientFieldNormalizerTest::testEmailIsLowercased` (unit) ; `ClientSubResourceApiTest::testPostContactNormalizesFields` / `::testPostAddressNormalizesBillingEmail` | ERP-55 / ERP-57 |
|
||||||
|
| RG-1.22 | Archive : permission `archive` + archivedAt + aucun autre champ | `ClientApiTest::testPatchArchiveSetsArchivedAtThenRestore` ; `::testPatchArchiveWithOtherFieldReturns422` ; `ClientProcessorTest` (unit, gating archive) | ERP-55 |
|
||||||
|
| RG-1.23 | Restauration : archivedAt=null ; **409 si conflit d'unicité** | `ClientApiTest::testPatchArchiveSetsArchivedAtThenRestore` (cas nominal) ; **`ClientArchiveTest::testRestoreConflictReturns409`** (409 restauration, gap P1) | ERP-55 / **ERP-60** |
|
||||||
|
| RG-1.24 | Liste exclut les archivés par défaut | `ClientApiTest::testListSortedByCompanyNameAscAndExcludesArchived` | ERP-55 |
|
||||||
|
| RG-1.25 | `?includeArchived=true` inclut les archivés | `ClientApiTest::testListIncludeArchivedReturnsArchived` | ERP-55 |
|
||||||
|
| RG-1.26 | Tri par défaut companyName ASC | `ClientApiTest::testListSortedByCompanyNameAscAndExcludesArchived` | ERP-55 |
|
||||||
|
| RG-1.27 | Timestampable/Blamable : created* figés, updated* mis à jour | `ClientAuditTest::testCreatedFrozenAndUpdatedByReflectsModifier` | **ERP-60** |
|
||||||
|
| RG-1.28 | PATCH multi-groupes sans permission → 403 strict (tout le payload) | `ClientProcessorTest::testStrictMixWithAccountingFieldIsForbidden` / `::testAccountingFieldWithoutPermissionIsForbidden` (unit) ; **`ClientPatchStrictTest::testMixedGroupsPatchWithoutAccountingPermissionIsForbidden`** (fonctionnel) | ERP-55 / **ERP-60** |
|
||||||
|
| RG-1.29 | Catégorie d'adresse limitée aux types SECTEUR/AUTRE | **Filtrage LECTURE = front-driven** (SearchFilter `GET /api/categories?categoryType.code[]=…`). **Validation ÉCRITURE (POST/PATPH catégorie DISTRIBUTEUR/COURTIER → 422) NON IMPLÉMENTÉE côté back au M1** (absente du `ClientAddressProcessor` et de la liste § 8.1). → voir « Gaps & suivi » | — (gap) |
|
||||||
|
|
||||||
|
## Couvertures transverses
|
||||||
|
|
||||||
|
| Sujet | Test(s) | Source |
|
||||||
|
|-------|---------|--------|
|
||||||
|
| Audit iban/bic présents dans le diff (pas d'`#[AuditIgnore]`) | `ClientAuditTest::testRibCreateAuditIncludesIbanAndBic` | **ERP-60** |
|
||||||
|
| Sécurité générique : 401 anonyme + 403 sans `commercial.clients.view` | `ClientSecurityTest` (collection + détail) ; `ClientExportControllerTest::testForbiddenWithoutClientsViewPermission` / `::testUnauthorizedWhenAnonymous` | **ERP-60** / ERP-58 |
|
||||||
|
| Migration : index partiel unique présent (1 seul), pas de siren/email unique | `ClientMigrationTest` | **ERP-60** |
|
||||||
|
| Référentiels comptables read-only (405 écriture, 401/403) | `ReferentialApiTest` | ERP-56 |
|
||||||
|
| Export XLSX (colonnes accounting selon permission, 401/403) | `ClientExportControllerTest` | ERP-58 |
|
||||||
|
|
||||||
|
## Délégué à ERP-74 (#493) — NE PAS faire dans ERP-60
|
||||||
|
|
||||||
|
- **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.
|
||||||
|
- **RG-1.04 fonctionnel** : PATCH onglet Information par une Commerciale avec
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Gaps & suivi
|
||||||
|
|
||||||
|
- **RG-1.29 (validation écriture)** : refuser une catégorie de type
|
||||||
|
`DISTRIBUTEUR`/`COURTIER` sur une `ClientAddress` (→ 422, violation
|
||||||
|
`categories`) n'est pas implémenté au M1. La spec § 8.1 ne le liste pas comme
|
||||||
|
cas de test back ; le filtrage de lecture est front-driven. **Suggestion** :
|
||||||
|
ouvrir un follow-up (durcissement `ClientAddressProcessor`) ou l'intégrer à
|
||||||
|
ERP-74. Aucune invention de feature dans ERP-60 (ticket test-only).
|
||||||
|
- **Violations CHECK → statut HTTP** : les CHECK d'adresse (RG-1.06/07/08/11)
|
||||||
|
sont aujourd'hui rejetées par la base (statut ≥ 400) mais sans mapping fin
|
||||||
|
vers 422 (pas d'`exception_to_status` ni de listener DBAL→HTTP). Les tests
|
||||||
|
ERP-60 assertent donc le **rejet** (≥ 400). Un mapping explicite vers 422
|
||||||
|
serait une amélioration UX d'API (follow-up possible).
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,289 @@
|
|||||||
|
---
|
||||||
|
# === IDENTITÉ ===
|
||||||
|
module: M1
|
||||||
|
nom: "Répertoire clients"
|
||||||
|
ecran: repertoire-clients
|
||||||
|
owner_spec: Matthieu
|
||||||
|
backup_spec: Tristan
|
||||||
|
version: V0
|
||||||
|
date_redaction: 2026-05-28
|
||||||
|
|
||||||
|
# === LIENS ===
|
||||||
|
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]
|
||||||
|
roles: [Admin, Bureau, Compta, Commerciale, Usine]
|
||||||
|
lien_spec_back: ./spec-back.md
|
||||||
|
|
||||||
|
# === VALIDATION CLIENT #1 ===
|
||||||
|
client_validation_1:
|
||||||
|
statut: validee
|
||||||
|
date: 2026-05-22
|
||||||
|
canal: ecrit
|
||||||
|
valide_par: "Matthieu (CP MALIO) — validation implicite, périmètre projet"
|
||||||
|
resume: "Module 1 — Répertoire clients. Page d'entrée Commercial. Datatable + 3 écrans (Ajouter / Consulter / Modifier). Création par onglets : Information / Contact / Adresse / Comptabilité (Transport, Statistiques, Rapports, Échanges = placeholders blancs)."
|
||||||
|
trace_archivee: "uploads/4a1b026f-M1-reportoire-clients.docx (V0 d'origine .docx)"
|
||||||
|
|
||||||
|
# === LIEN LESSTIME ===
|
||||||
|
lesstime_taskgroup_id: 23
|
||||||
|
lesstime_project_id: 6
|
||||||
|
statut_global: en_dev
|
||||||
|
---
|
||||||
|
|
||||||
|
# Module 1 — Répertoire clients (V0 front)
|
||||||
|
|
||||||
|
> **Origine** : spec front V0 livrée le 22/05/2026 (`M1-reportoire-clients.docx`). Restitution Markdown pour intégration au workflow MALIO. Le contenu original n'est pas modifié — toute précision et toute décision (en particulier côté back) vit dans [`spec-back.md`](./spec-back.md).
|
||||||
|
|
||||||
|
## But
|
||||||
|
|
||||||
|
Permettre aux utilisateurs Starseed (selon rôle) de gérer le **répertoire des clients** de l'organisation : consultation, création, modification, archivage. Cette page est la **porte d'entrée du module Commercial**.
|
||||||
|
|
||||||
|
## Accès
|
||||||
|
|
||||||
|
- **Depuis** : menu principal → section **Commercial** → entrée « Répertoire clients »
|
||||||
|
- **Rôles autorisés** :
|
||||||
|
|
||||||
|
| Rôle | Consultation | Création / Modification | Archivage |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Admin** | ✅ Tout | ✅ Tout | ✅ |
|
||||||
|
| **Bureau** | ✅ Tout | ✅ Tout sauf onglet Comptabilité | ❌ |
|
||||||
|
| **Compta** | ✅ Tout | ✅ Onglet Comptabilité uniquement | ❌ |
|
||||||
|
| **Commerciale** | ✅ Tout sauf Comptabilité | ✅ Tout sauf Comptabilité | ❌ |
|
||||||
|
| **Usine** | ❌ | ❌ | ❌ |
|
||||||
|
|
||||||
|
> **Note** : aligné sur le docx d'origine — Compta édite uniquement l'onglet Comptabilité (champs SIREN / TVA / Délai de règlement / Type de règlement / Banque / RIBs). Compta ne peut pas **créer** un client (pas de droit `manage` général), mais peut éditer la partie comptable d'un client existant créé par Admin ou Bureau.
|
||||||
|
|
||||||
|
## Navigation
|
||||||
|
|
||||||
|
L'écran est la page d'entrée du module **Commercial**. Titre : « **Répertoire clients** ».
|
||||||
|
|
||||||
|
- Affichage principal : un **datatable** listant tous les clients **actifs** de l'organisation (les clients archivés sont masqués par défaut — filtre UI dédié pour les voir).
|
||||||
|
- **Clic sur une ligne** → bascule sur l'écran **Consultation client** (page dédiée, pas un drawer — cf. maquette Figma).
|
||||||
|
- **Bouton « + Ajouter »** (en haut à droite) → bascule sur l'écran **Ajouter un client**.
|
||||||
|
- **Bouton « Exporter »** (en haut à droite) → télécharge un **fichier XLSX** des clients **affichés** (cf. filtre actif). Format détaillé dans [`spec-back.md` § Export](./spec-back.md).
|
||||||
|
|
||||||
|
## Datatable du Répertoire
|
||||||
|
|
||||||
|
Composant : `<MalioDataTable>`. Colonnes (à raffiner avec Tristan en revue maquette) :
|
||||||
|
|
||||||
|
| Colonne | Source | Tri |
|
||||||
|
|---|---|---|
|
||||||
|
| **Nom entreprise** | `client.companyName` | ASC par défaut |
|
||||||
|
| **Contact principal** | `firstName + lastName` | Oui |
|
||||||
|
| **Téléphone principal** | `phonePrimary` (formaté `XX XX XX XX XX`) | Non |
|
||||||
|
| **Email principal** | `email` | Oui |
|
||||||
|
| **Catégories** | liste des codes catégories séparés par `,` | Non |
|
||||||
|
| **Site(s)** | sites rattachés à au moins une adresse (badges colorés) | Non |
|
||||||
|
|
||||||
|
> **Filtre archivés** : toggle UI en haut du datatable. Désactivé par défaut. État local (pas dans l'URL — cf. règle ABSOLUE Starseed n°6).
|
||||||
|
|
||||||
|
> **Pagination** : front via `<MalioDataTable>` (volumétrie cible faible — quelques centaines). Tri serveur `companyName ASC` par défaut.
|
||||||
|
|
||||||
|
## Écran « Ajouter un client »
|
||||||
|
|
||||||
|
Création par **onglets successifs avec validation incrémentale** : pour pouvoir passer à l'onglet suivant, il faut avoir validé l'onglet en cours. **Une fois un onglet validé, on passe automatiquement au suivant**, et les champs de l'onglet validé passent en lecture seule + bouton « Valider » désactivé (disabled).
|
||||||
|
|
||||||
|
### Formulaire principal (pré-onglets)
|
||||||
|
|
||||||
|
C'est le 1er bloc à remplir. Sans validation de ce formulaire, les onglets ne sont pas accessibles.
|
||||||
|
|
||||||
|
| Champ | Type composant | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Nom du client (Entreprise)** | `<MalioInputText>` | Oui | RG-1.18 (normalisation UPPERCASE serveur) |
|
||||||
|
| **Nom du contact principal** | `<MalioInputText>` | Conditionnel | RG-1.01 + RG-1.19 (Capitalize) |
|
||||||
|
| **Prénom du contact principal** | `<MalioInputText>` | Conditionnel | RG-1.01 + RG-1.19 (Capitalize) |
|
||||||
|
| **Catégorie** | `<MalioSelectCheckbox>` (multi) | Oui | Liste des `Category` de l'API ; M2M Client ↔ Category |
|
||||||
|
| **Téléphone principal** | `<MalioInputText>` (masque tel) | Oui | RG-1.02 + RG-1.20 (format `XX XX XX XX XX`) |
|
||||||
|
| **Téléphone secondaire** | `<MalioInputText>` (masque tel) | Non | Apparaît au clic sur le bouton `+` (RG-1.02). Max 2 — bouton `+` disparaît une fois rempli. |
|
||||||
|
| **Email** | `<MalioInputText>` type email | Oui | RG-1.21 (lowercase) |
|
||||||
|
| **Distributeur / Courtier** | `<MalioSelect>` | Non | Valeurs : `Dépend du distributeur` / `Dépend du courtier` / `Aucun`. RG-1.03 conditionne les 2 champs suivants. |
|
||||||
|
| **Nom du distributeur** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du distributeur ». Liste = clients ayant ≥ 1 catégorie de type `DISTRIBUTEUR`. RG-1.03. |
|
||||||
|
| **Nom du courtier** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du courtier ». Liste = clients ayant ≥ 1 catégorie de type `COURTIER`. RG-1.03. |
|
||||||
|
| **Prestation de triage** | `<MalioCheckbox>` | Non | — |
|
||||||
|
|
||||||
|
**Action** : « Valider » (`<MalioButton>`) → POST `/api/clients` ([`spec-back.md` § 4.3](./spec-back.md)). Si succès, on passe automatiquement à l'onglet « Information ».
|
||||||
|
|
||||||
|
### Onglet « Information »
|
||||||
|
|
||||||
|
Saisir les informations de l'entreprise.
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Description** | `<MalioInputTextArea>` | Conditionnel | RG-1.04 (obligatoire pour rôle Commerciale) |
|
||||||
|
| **Concurrents** | `<MalioInputText>` | Conditionnel | RG-1.04 |
|
||||||
|
| **Date de création** (de l'entreprise) | `<input type="date">` (exception Malio — pas de composant date couvert) | Conditionnel | RG-1.04 |
|
||||||
|
| **Nombre de salariés** | `<MalioInputNumber>` | Conditionnel | RG-1.04 |
|
||||||
|
| **CA €** | `<MalioInputAmount>` | Conditionnel | RG-1.04 |
|
||||||
|
| **Dirigeant** | `<MalioInputText>` | Conditionnel | RG-1.04 |
|
||||||
|
| **Résultat €** | `<MalioInputAmount>` | Conditionnel | RG-1.04 |
|
||||||
|
|
||||||
|
**Action** : « Valider » → PATCH partiel `/api/clients/{id}` (groupe `client:write:information`).
|
||||||
|
|
||||||
|
### Onglet « Contact »
|
||||||
|
|
||||||
|
Saisir un ou plusieurs contacts associés au client. Le 1er bloc est **pré-rempli** depuis les champs du formulaire principal (Nom, Prénom, Téléphone, Email — édition autorisée).
|
||||||
|
|
||||||
|
**Bloc Contact** :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Nom** | `<MalioInputText>` | Conditionnel | RG-1.05 + RG-1.19 (Capitalize) |
|
||||||
|
| **Prénom** | `<MalioInputText>` | Conditionnel | RG-1.05 + RG-1.19 (Capitalize) |
|
||||||
|
| **Fonction** | `<MalioInputText>` | Non | — |
|
||||||
|
| **Téléphone** (x1, +1 possible) | `<MalioInputText>` | Non | RG-1.20 (format) |
|
||||||
|
| **Email** | `<MalioInputText>` type email | Non | RG-1.21 (lowercase) |
|
||||||
|
|
||||||
|
**RG-1.14 (renforcement validée par Tristan le 28/05)** : **au moins 1 bloc Contact valide** (au moins Nom OU Prénom rempli) est obligatoire pour valider l'onglet. Donc l'onglet Contact ne peut pas être finalisé vide.
|
||||||
|
|
||||||
|
**Actions** :
|
||||||
|
- « + Nouveau contact » : ajoute un bloc. Bouton **désactivé tant que le bloc précédent n'a pas Prénom OU Nom rempli** (RG-1.05).
|
||||||
|
- « Supprimer » (icône) sur un bloc : modal de confirmation (`<MalioButton>` Annuler / Confirmer). Si Oui → suppression du bloc.
|
||||||
|
- « Valider » → PATCH `/api/clients/{id}/contacts` (création/mise à jour de la collection).
|
||||||
|
|
||||||
|
### Onglet « Adresse »
|
||||||
|
|
||||||
|
Saisir une ou plusieurs adresses du client, rattachées à un ou plusieurs sites Starseed (Châtellerault 86 / Saint-Jean 17 / Pommevic 82) et à des contacts.
|
||||||
|
|
||||||
|
**Bloc Adresse** :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Prospect** | `<MalioCheckbox>` | Non | RG-1.06 — masque Adresse de livraison + Facturation si coché |
|
||||||
|
| **Adresse de livraison** | `<MalioCheckbox>` | Non | RG-1.07 — masque Prospect si coché |
|
||||||
|
| **Facturation** | `<MalioCheckbox>` | Non | RG-1.08 — masque Prospect si coché ; affiche le champ Email (RG-1.11) |
|
||||||
|
| **Catégorie** | `<MalioSelectCheckbox>` (multi) | Oui | Liste des `Category` de **type SECTEUR + AUTRE** uniquement (cf. décision Q5 — DISTRIBUTEUR et COURTIER qualifient une relation entre clients, pas un lieu) |
|
||||||
|
| **Pays** | `<MalioSelect>` | Oui | Préremplie « France » |
|
||||||
|
| **Code postal** | `<MalioInputText>` (masque numérique) | Oui | RG-1.09 — déclenche autocomplete ville via BAN |
|
||||||
|
| **Ville** | `<MalioSelect>` | Oui | RG-1.09 — alimentée par api-adresse.data.gouv.fr suivant le CP |
|
||||||
|
| **Adresse** | `<MalioInputText>` (saisie assistée) | Oui | RG-1.09 — autocomplete BAN |
|
||||||
|
| **Adresse complémentaire** | `<MalioInputText>` | Non | — |
|
||||||
|
| **Sites Starseed** | `<MalioSelectCheckbox>` (multi-checkbox 86 / 17 / 82) | Oui | RG-1.10 — ≥ 1 site obligatoire |
|
||||||
|
| **Contact(s) rattaché(s)** | `<MalioSelectCheckbox>` (multi) | Non | Liste = blocs Contact saisis dans l'onglet Contact |
|
||||||
|
| **Email (facturation)** | `<MalioInputText>` type email | Conditionnel | RG-1.11 — visible/obligatoire uniquement si « Facturation » coché |
|
||||||
|
|
||||||
|
**Actions** :
|
||||||
|
- « + Nouvelle Adresse » : ajoute un bloc identique.
|
||||||
|
- « Supprimer » : modal de confirmation puis suppression.
|
||||||
|
- « Valider » → PATCH `/api/clients/{id}/addresses`.
|
||||||
|
|
||||||
|
### Onglet « Transport »
|
||||||
|
|
||||||
|
🚧 **Placeholder blanc au M1.** Frame vide. Aucun champ. Aucun bouton de validation. L'utilisateur passe automatiquement à l'onglet suivant. **Pas de mention « En cours »** — c'est juste blanc (décision Tristan 28/05).
|
||||||
|
|
||||||
|
### Onglet « Comptabilité »
|
||||||
|
|
||||||
|
⚠ **Accessible aux rôles avec `commercial.clients.accounting.manage`** (Admin + Compta au M1). Bureau et Commerciale ne voient pas l'onglet. **Compta peut éditer cet onglet** (champs SIREN / N° compte / TVA / Délai / Type de règlement / Banque / RIBs) — cf. décision Q1, aligné docx. Compta ne peut pas créer un client (pas de `manage` général).
|
||||||
|
|
||||||
|
**Champs comptables** :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **SIREN** | `<MalioInputText>` (masque 9 chiffres) | Oui | Format 9 chiffres. **Pas d'unicité** (décision Q4) |
|
||||||
|
| **Numéro de compte** | `<MalioInputText>` | Oui | — |
|
||||||
|
| **Mode de TVA** | `<MalioSelect>` | Oui | Liste depuis `/api/tva_modes` |
|
||||||
|
| **N° de TVA** | `<MalioInputText>` | Oui | — |
|
||||||
|
| **Délai de règlement** | `<MalioSelect>` | Oui | Liste depuis `/api/payment_delays` |
|
||||||
|
| **Type de règlement** | `<MalioSelect>` | Oui | Liste depuis `/api/payment_types` |
|
||||||
|
| **Banque** | `<MalioSelect>` | Conditionnel | RG-1.12 — visible et obligatoire **si** Type de règlement = `VIREMENT`. Liste depuis `/api/banks`. |
|
||||||
|
|
||||||
|
**Bloc RIB** (0..n blocs, présence obligatoire conditionnée par RG-1.13) :
|
||||||
|
|
||||||
|
| Champ | Type | Obligatoire | Règle |
|
||||||
|
|---|---|---|---|
|
||||||
|
| **Libellé** | `<MalioInputText>` | Oui (si LCR) | RG-1.13 |
|
||||||
|
| **BIC** | `<MalioInputText>` | Oui (si LCR) | RG-1.13 — `#[AuditIgnore]` (champ sensible) |
|
||||||
|
| **IBAN** | `<MalioInputText>` | Oui (si LCR) | RG-1.13 — `#[AuditIgnore]` (champ sensible) |
|
||||||
|
|
||||||
|
**Actions** :
|
||||||
|
- « + RIB » : ajoute un bloc.
|
||||||
|
- « Supprimer » (icône) : modal de confirmation.
|
||||||
|
- « Valider » → PATCH `/api/clients/{id}/accounting`.
|
||||||
|
|
||||||
|
### Onglets « Statistiques » / « Rapports » / « Échanges »
|
||||||
|
|
||||||
|
🚧 **Placeholders blancs au M1.** Mêmes règles que Transport (frames vides, pas de validation).
|
||||||
|
|
||||||
|
## Écran « Consultation client »
|
||||||
|
|
||||||
|
Tous les champs en **lecture seule**. Layout identique à l'écran Ajouter mais sans bouton « Valider », sans bouton `+` pour ajouter des blocs Contact / Adresse / RIB.
|
||||||
|
|
||||||
|
- **Flèche retour** (à gauche) → revient au Répertoire.
|
||||||
|
- **Bouton « Modifier »** (à droite, visible si l'utilisateur a la permission `commercial.clients.manage`) → bascule sur l'écran Modification.
|
||||||
|
- **Bouton « Archiver »** (à droite, visible **uniquement pour Admin** via permission `commercial.clients.archive`) → ouvre une modal de confirmation, puis PATCH `/api/clients/{id}` `{ "isArchived": true }`. Le client passe en archivé (cf. flag `is_archived`).
|
||||||
|
|
||||||
|
> Le client archivé peut être restauré (`isArchived: false`) — bouton « Restaurer » remplace « Archiver » dans la consultation d'un archivé. Décision validée Tristan 28/05.
|
||||||
|
|
||||||
|
### Onglets affichés en consultation
|
||||||
|
|
||||||
|
Mêmes onglets qu'en création, **plus** les 4 placeholders blancs. L'utilisateur navigue librement entre les onglets (pas de séquence forcée en consultation).
|
||||||
|
|
||||||
|
## Écran « Modification client »
|
||||||
|
|
||||||
|
Comportement identique à l'écran Ajouter sauf :
|
||||||
|
- **Pas de formulaire principal** (les champs principaux sont édités via les onglets correspondants).
|
||||||
|
- Les champs sont **pré-remplis** avec les valeurs actuelles.
|
||||||
|
- **Validation par onglet** : on peut modifier UN onglet sans toucher aux autres (PATCH partiel).
|
||||||
|
- Les onglets pour lesquels l'utilisateur n'a **pas** la permission `manage` restent en lecture seule (pas de bouton Valider, pas d'icône suppression de bloc).
|
||||||
|
- Les onglets placeholders restent inaccessibles à l'édition (blancs).
|
||||||
|
|
||||||
|
## Composants UI à utiliser (`@malio/layer-ui`)
|
||||||
|
|
||||||
|
- **Datatable** : `<MalioDataTable>` (Répertoire)
|
||||||
|
- **Input texte** : `<MalioInputText>`
|
||||||
|
- **Input numérique** : `<MalioInputNumber>`
|
||||||
|
- **Input montant** : `<MalioInputAmount>` (CA, Résultat)
|
||||||
|
- **TextArea** : `<MalioInputTextArea>` (Description)
|
||||||
|
- **Select simple** : `<MalioSelect>` (Pays, Ville, distributeur/courtier, refs comptables)
|
||||||
|
- **Select multi (cases à cocher)** : `<MalioSelectCheckbox>` (Catégorie, Sites, Contacts rattachés)
|
||||||
|
- **Checkbox** : `<MalioCheckbox>` (Prospect, Adresse livraison, Facturation, Prestation de triage)
|
||||||
|
- **Bouton** : `<MalioButton>`, `<MalioButtonIcon>`
|
||||||
|
- **Toasts** : standards via `useApi()`
|
||||||
|
|
||||||
|
**Exceptions autorisées** (à commenter `// TODO migrer quand Malio couvre`) :
|
||||||
|
- `<input type="date">` pour « Date de création » (composant `MalioDate` non couvert)
|
||||||
|
- Modal de confirmation : composant à confirmer côté équipe front (probablement `<MalioModal>` ou un wrapper à créer dans `frontend/shared/`)
|
||||||
|
|
||||||
|
## Règles de formatage et normalisation
|
||||||
|
|
||||||
|
Le serveur normalise systématiquement (cf. RG-1.18 à RG-1.21 dans [`spec-back.md`](./spec-back.md)) :
|
||||||
|
|
||||||
|
| Champ | Normalisation serveur | Affichage front |
|
||||||
|
|---|---|---|
|
||||||
|
| Nom entreprise (`companyName`) | UPPERCASE intégral | UPPERCASE |
|
||||||
|
| Nom + Prénom contact | Capitalize (1ère lettre majuscule + reste minuscule) | identique |
|
||||||
|
| Téléphone (`phonePrimary`, `phoneSecondary`, contact phones) | Chiffres uniquement en BDD | Formaté `XX XX XX XX XX` à l'affichage (filter Vue) |
|
||||||
|
| Email | lowercase intégral | identique |
|
||||||
|
|
||||||
|
> **Le front ne fait pas la normalisation** — il envoie la valeur saisie, le serveur normalise puis renvoie la valeur normalisée. L'UI affiche immédiatement la valeur normalisée renvoyée par l'API. Cohérent avec le pattern `useApi()`.
|
||||||
|
|
||||||
|
## API adresse postale
|
||||||
|
|
||||||
|
Le composant `Code postal` + `Ville` + `Adresse` est branché sur **api-adresse.data.gouv.fr** (Base Adresse Nationale, gratuite, française).
|
||||||
|
|
||||||
|
- Composable dédié `useAddressAutocomplete()` (à créer en M1).
|
||||||
|
- Appel HTTP **direct depuis le front** (CORS OK), pas de proxy back.
|
||||||
|
- Pattern : à la saisie du code postal (5 chiffres), GET `https://api-adresse.data.gouv.fr/search/?q={cp}&type=municipality` → alimente le select Ville. Sur saisie d'adresse : `?q={addr}&postcode={cp}&type=housenumber` → suggestions adresse.
|
||||||
|
- Cas dégradé : si l'API ne répond pas (offline, timeout), le champ Ville devient un `<MalioInputText>` libre éditable + toast d'avertissement. Validation serveur acceptera la saisie libre.
|
||||||
|
|
||||||
|
## Points laissés ouverts par la V0 (résolus côté back)
|
||||||
|
|
||||||
|
| # | Zone d'ombre V0 | Résolution (cf. `spec-back.md`) |
|
||||||
|
|---|---|---|
|
||||||
|
| 1 | Catégorie en multi-select non clarifiée (1 ou n par client) | **M2M `client_category`** validée. CategoryType seedé avec `DISTRIBUTEUR`, `COURTIER`, `SECTEUR`, `AUTRE` (HP-3 du M0 levé). |
|
||||||
|
| 2 | Distributeur / Courtier : liste de quoi ? | **Auto-référence Client** via 2 FK nullables `distributor_id` et `broker_id` (cf. RG-1.03). Une seule des deux est remplie à la fois. |
|
||||||
|
| 3 | Onglet « Comptabilité » : qui édite ? | **Admin et Compta** peuvent éditer l'onglet Comptabilité (`commercial.clients.accounting.manage`). Bureau / Commerciale ne voient pas l'onglet. Compta ne peut pas créer un client (pas de `manage` global), mais peut éditer la partie comptable d'un client existant. |
|
||||||
|
| 4 | Workflow par onglet | **Sauvegarde incrémentale**. POST formulaire principal crée le `Client` (status implicite « actif »). Chaque onglet validé = PATCH partiel par groupe de sérialisation dédié. Pas d'état « draft ». |
|
||||||
|
| 5 | Onglets « À venir » | **Placeholders blancs** (frames vides, pas de message). Ré-activables sans rebuild quand les modules associés arriveront. |
|
||||||
|
| 6 | Archive vs soft delete | **Flag `is_archived` séparé de `deleted_at`**. Archive ≠ delete : un client archivé est masqué par défaut mais reste en BDD éditable (Admin seul). Filtres UI distincts. Soft delete = HP M2. |
|
||||||
|
| 7 | Unicité métier | **Nom d'entreprise uniquement** (case-insensitive, parmi non-archivés) — décision Q4. SIREN et email NON uniques. Index partiel Postgres `uq_client_company_name_active`. Doublon de nom → 409 Conflict. |
|
||||||
|
| 8 | Téléphones (max 2) | **2 colonnes plates** `phone_primary` + `phone_secondary`. Pas de table séparée. |
|
||||||
|
| 9 | API code postal | **api-adresse.data.gouv.fr** (BAN). Appel direct front via composable dédié. Cas dégradé : saisie libre + toast. |
|
||||||
|
| 10 | Référentiels comptables | **4 entités CRUD-ables** (`TvaMode`, `PaymentDelay`, `PaymentType`, `Bank`) seedées au M1, CRUD admin futur (HP-M2). |
|
||||||
|
| 11 | Format de l'export | **XLSX uniquement** au M1. CSV à étudier en HP. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Tickets Lesstime générés
|
||||||
|
|
||||||
|
**TaskGroup Lesstime** : à créer — `M1 — Répertoire clients` (projet `ERP / Starseed`, projectId=6).
|
||||||
|
|
||||||
|
> Détail complet, table des tickets et action manuelle dans Lesstime → voir [`spec-back.md § Tickets Lesstime générés`](./spec-back.md#-tickets-lesstime-générés).
|
||||||
@@ -24,10 +24,10 @@
|
|||||||
<div class="h-full flex-1 flex flex-col min-h-0 min-w-0">
|
<div class="h-full flex-1 flex flex-col min-h-0 min-w-0">
|
||||||
<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-[170px]">
|
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
|
<div
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
class="pointer-events-none sticky top-0 z-30 h-[47px] flex-shrink-0 bg-white"/>
|
class="pointer-events-none sticky top-0 z-30 h-11 flex-shrink-0 bg-white"/>
|
||||||
<slot/>
|
<slot/>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"commercial": {
|
"commercial": {
|
||||||
"section": "Commercial",
|
"section": "Commercial",
|
||||||
|
"clients": "Répertoire clients",
|
||||||
"suppliers": "Répertoire fournisseurs"
|
"suppliers": "Répertoire fournisseurs"
|
||||||
},
|
},
|
||||||
"core": {
|
"core": {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</h2>
|
</h2>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<form class="flex flex-col gap-4 py-4" @submit.prevent="handleSave">
|
<form class="flex flex-col py-4 gap-2" @submit.prevent="handleSave">
|
||||||
<!-- Nom (RG-1.02 obligatoire / RG-1.04 longueur 2-120 apres trim).
|
<!-- Nom (RG-1.02 obligatoire / RG-1.04 longueur 2-120 apres trim).
|
||||||
Erreur miroir client + erreurs server-side (422) mappees sur ce champ. -->
|
Erreur miroir client + erreurs server-side (422) mappees sur ce champ. -->
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
@@ -52,21 +52,21 @@
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
icon-name="mdi:delete-outline"
|
icon-name="mdi:delete-outline"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
@click="emit('delete')"
|
@click="emit('delete')"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-else
|
v-else
|
||||||
:label="t('common.cancel')"
|
:label="t('common.cancel')"
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
@click="emit('update:modelValue', false)"
|
@click="emit('update:modelValue', false)"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-if="canShowSave"
|
v-if="canShowSave"
|
||||||
:label="t('common.save')"
|
:label="t('common.save')"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
:disabled="form.submitting.value || loadingTypes"
|
:disabled="form.submitting.value || loadingTypes"
|
||||||
@click="handleSave"
|
@click="handleSave"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
import type { Category, CategoryType } from '~/modules/catalog/types/category'
|
import type { CategoryType } from '~/modules/catalog/types/category'
|
||||||
import type { HydraCollection } from '~/shared/utils/api'
|
import type { HydraCollection } from '~/shared/utils/api'
|
||||||
|
|
||||||
// Mock du store auth : useCategoriesAdmin s'auto-enregistre via
|
// Mock du store auth : useCategoriesAdmin s'auto-enregistre via
|
||||||
@@ -28,27 +28,6 @@ const { useCategoriesAdmin } = await import('../useCategoriesAdmin')
|
|||||||
const TYPE_VENTE: CategoryType = { id: 1, code: 'VENTE', label: 'Vente' }
|
const TYPE_VENTE: CategoryType = { id: 1, code: 'VENTE', label: 'Vente' }
|
||||||
const TYPE_ACHAT: CategoryType = { id: 2, code: 'ACHAT', label: 'Achat' }
|
const TYPE_ACHAT: CategoryType = { id: 2, code: 'ACHAT', label: 'Achat' }
|
||||||
|
|
||||||
const CAT_A: Category = {
|
|
||||||
id: 10,
|
|
||||||
name: 'Vis',
|
|
||||||
categoryType: TYPE_VENTE,
|
|
||||||
deletedAt: null,
|
|
||||||
createdAt: '2026-01-01T10:00:00+00:00',
|
|
||||||
updatedAt: '2026-01-01T10:00:00+00:00',
|
|
||||||
createdBy: null,
|
|
||||||
updatedBy: null,
|
|
||||||
}
|
|
||||||
const CAT_B: Category = {
|
|
||||||
id: 11,
|
|
||||||
name: 'Boulons',
|
|
||||||
categoryType: TYPE_VENTE,
|
|
||||||
deletedAt: null,
|
|
||||||
createdAt: '2026-01-02T10:00:00+00:00',
|
|
||||||
updatedAt: '2026-01-02T10:00:00+00:00',
|
|
||||||
createdBy: null,
|
|
||||||
updatedBy: null,
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeHydra<T>(items: T[]): HydraCollection<T> {
|
function makeHydra<T>(items: T[]): HydraCollection<T> {
|
||||||
return {
|
return {
|
||||||
totalItems: items.length,
|
totalItems: items.length,
|
||||||
@@ -56,113 +35,32 @@ function makeHydra<T>(items: T[]): HydraCollection<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apres ERP-73, `useCategoriesAdmin` ne porte plus la liste paginee des
|
||||||
|
* categories (elle est geree par `usePaginatedList<Category>` cote page).
|
||||||
|
* Le composable se concentre sur le referentiel CategoryType (lecture
|
||||||
|
* seule, ≤ 5 entrees connues) charge en une fois via `?pagination=false`.
|
||||||
|
*/
|
||||||
describe('useCategoriesAdmin', () => {
|
describe('useCategoriesAdmin', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockGet.mockReset()
|
mockGet.mockReset()
|
||||||
// Reset systematique du state singleton entre tests : sans ca,
|
// Reset systematique du state singleton entre tests : sans ca,
|
||||||
// les categories chargees dans un test fuiteraient dans le suivant.
|
// les types charges dans un test fuiteraient dans le suivant.
|
||||||
const { resetCategoriesAdmin } = useCategoriesAdmin()
|
const { resetCategoriesAdmin } = useCategoriesAdmin()
|
||||||
resetCategoriesAdmin()
|
resetCategoriesAdmin()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('fetchAll', () => {
|
|
||||||
it('appelle GET /categories avec itemsPerPage=999 par defaut', async () => {
|
|
||||||
mockGet.mockResolvedValueOnce(makeHydra<Category>([]))
|
|
||||||
const { fetchAll } = useCategoriesAdmin()
|
|
||||||
|
|
||||||
await fetchAll()
|
|
||||||
|
|
||||||
expect(mockGet).toHaveBeenCalledTimes(1)
|
|
||||||
expect(mockGet).toHaveBeenCalledWith(
|
|
||||||
'/categories',
|
|
||||||
{ itemsPerPage: 999 },
|
|
||||||
{ toast: false },
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('peuple categories.value depuis le champ Hydra member', async () => {
|
|
||||||
mockGet.mockResolvedValueOnce(makeHydra([CAT_A, CAT_B]))
|
|
||||||
const { fetchAll, categories } = useCategoriesAdmin()
|
|
||||||
|
|
||||||
await fetchAll()
|
|
||||||
|
|
||||||
expect(categories.value).toEqual([CAT_A, CAT_B])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('exclut les soft-deleted par defaut (pas de query includeDeleted)', async () => {
|
|
||||||
mockGet.mockResolvedValueOnce(makeHydra<Category>([]))
|
|
||||||
const { fetchAll } = useCategoriesAdmin()
|
|
||||||
|
|
||||||
await fetchAll()
|
|
||||||
|
|
||||||
const queryArg = mockGet.mock.calls[0]?.[1] as Record<string, unknown>
|
|
||||||
expect(queryArg).not.toHaveProperty('includeDeleted')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('ajoute includeDeleted=true quand demande explicitement', async () => {
|
|
||||||
mockGet.mockResolvedValueOnce(makeHydra<Category>([]))
|
|
||||||
const { fetchAll } = useCategoriesAdmin()
|
|
||||||
|
|
||||||
await fetchAll(true)
|
|
||||||
|
|
||||||
expect(mockGet).toHaveBeenCalledWith(
|
|
||||||
'/categories',
|
|
||||||
{ itemsPerPage: 999, includeDeleted: 'true' },
|
|
||||||
{ toast: false },
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('passe loading a true pendant la requete et false apres', async () => {
|
|
||||||
let resolveRequest: (v: HydraCollection<Category>) => void = () => {}
|
|
||||||
mockGet.mockImplementationOnce(
|
|
||||||
() => new Promise((resolve) => { resolveRequest = resolve }),
|
|
||||||
)
|
|
||||||
const { fetchAll, loading } = useCategoriesAdmin()
|
|
||||||
|
|
||||||
const pending = fetchAll()
|
|
||||||
expect(loading.value).toBe(true)
|
|
||||||
|
|
||||||
resolveRequest(makeHydra<Category>([]))
|
|
||||||
await pending
|
|
||||||
|
|
||||||
expect(loading.value).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('peuple error.value et vide categories en cas d echec', async () => {
|
|
||||||
mockGet.mockRejectedValueOnce(new Error('Network down'))
|
|
||||||
const { fetchAll, categories, error, loading } = useCategoriesAdmin()
|
|
||||||
// Pre-charge volontairement quelque chose pour verifier la purge.
|
|
||||||
categories.value = [CAT_A]
|
|
||||||
|
|
||||||
await fetchAll()
|
|
||||||
|
|
||||||
expect(categories.value).toEqual([])
|
|
||||||
expect(error.value).toBe('Network down')
|
|
||||||
expect(loading.value).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('gere une reponse sans champ member (fallback tableau vide)', async () => {
|
|
||||||
mockGet.mockResolvedValueOnce({
|
|
||||||
totalItems: 0,
|
|
||||||
} as unknown as HydraCollection<Category>)
|
|
||||||
const { fetchAll, categories } = useCategoriesAdmin()
|
|
||||||
|
|
||||||
await fetchAll()
|
|
||||||
|
|
||||||
expect(categories.value).toEqual([])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('fetchTypes', () => {
|
describe('fetchTypes', () => {
|
||||||
it('appelle GET /category_types avec itemsPerPage=999', async () => {
|
it('appelle GET /category_types avec ?pagination=false (echappatoire selects)', async () => {
|
||||||
mockGet.mockResolvedValueOnce(makeHydra<CategoryType>([]))
|
mockGet.mockResolvedValueOnce(makeHydra<CategoryType>([]))
|
||||||
const { fetchTypes } = useCategoriesAdmin()
|
const { fetchTypes } = useCategoriesAdmin()
|
||||||
|
|
||||||
await fetchTypes()
|
await fetchTypes()
|
||||||
|
|
||||||
|
expect(mockGet).toHaveBeenCalledTimes(1)
|
||||||
expect(mockGet).toHaveBeenCalledWith(
|
expect(mockGet).toHaveBeenCalledWith(
|
||||||
'/category_types',
|
'/category_types',
|
||||||
{ itemsPerPage: 999 },
|
{ pagination: 'false' },
|
||||||
{ toast: false },
|
{ toast: false },
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -203,48 +101,55 @@ describe('useCategoriesAdmin', () => {
|
|||||||
|
|
||||||
expect(loadingTypes.value).toBe(false)
|
expect(loadingTypes.value).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('gere une reponse sans champ member (fallback tableau vide)', async () => {
|
||||||
|
mockGet.mockResolvedValueOnce({
|
||||||
|
totalItems: 0,
|
||||||
|
} as unknown as HydraCollection<CategoryType>)
|
||||||
|
const { fetchTypes, types } = useCategoriesAdmin()
|
||||||
|
|
||||||
|
await fetchTypes()
|
||||||
|
|
||||||
|
expect(types.value).toEqual([])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('resetCategoriesAdmin', () => {
|
describe('resetCategoriesAdmin', () => {
|
||||||
it('vide categories, types, loading, loadingTypes et error', () => {
|
it('vide types, loadingTypes et error', () => {
|
||||||
const { resetCategoriesAdmin, categories, types, loading, loadingTypes, error }
|
const { resetCategoriesAdmin, types, loadingTypes, error }
|
||||||
= useCategoriesAdmin()
|
= useCategoriesAdmin()
|
||||||
// Pre-peuple le state pour verifier la purge effective.
|
// Pre-peuple le state pour verifier la purge effective.
|
||||||
categories.value = [CAT_A]
|
|
||||||
types.value = [TYPE_VENTE]
|
types.value = [TYPE_VENTE]
|
||||||
loading.value = true
|
|
||||||
loadingTypes.value = true
|
loadingTypes.value = true
|
||||||
error.value = 'oops'
|
error.value = 'oops'
|
||||||
|
|
||||||
resetCategoriesAdmin()
|
resetCategoriesAdmin()
|
||||||
|
|
||||||
expect(categories.value).toEqual([])
|
|
||||||
expect(types.value).toEqual([])
|
expect(types.value).toEqual([])
|
||||||
expect(loading.value).toBe(false)
|
|
||||||
expect(loadingTypes.value).toBe(false)
|
expect(loadingTypes.value).toBe(false)
|
||||||
expect(error.value).toBeNull()
|
expect(error.value).toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('singleton', () => {
|
describe('singleton', () => {
|
||||||
it('deux appels a useCategoriesAdmin() partagent la meme ref categories', () => {
|
it('deux appels a useCategoriesAdmin() partagent la meme ref types', () => {
|
||||||
const a = useCategoriesAdmin()
|
const a = useCategoriesAdmin()
|
||||||
const b = useCategoriesAdmin()
|
const b = useCategoriesAdmin()
|
||||||
|
|
||||||
// Les fonctions sont reinstanciees a chaque appel mais les refs
|
// Les fonctions sont reinstanciees a chaque appel mais les refs
|
||||||
// doivent etre rigoureusement les memes (state au niveau module).
|
// doivent etre rigoureusement les memes (state au niveau module).
|
||||||
expect(a.categories).toBe(b.categories)
|
|
||||||
expect(a.types).toBe(b.types)
|
expect(a.types).toBe(b.types)
|
||||||
expect(a.loading).toBe(b.loading)
|
expect(a.loadingTypes).toBe(b.loadingTypes)
|
||||||
|
expect(a.error).toBe(b.error)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('une mutation via une instance est visible depuis une autre instance', () => {
|
it('une mutation via une instance est visible depuis une autre instance', () => {
|
||||||
const a = useCategoriesAdmin()
|
const a = useCategoriesAdmin()
|
||||||
const b = useCategoriesAdmin()
|
const b = useCategoriesAdmin()
|
||||||
|
|
||||||
a.categories.value = [CAT_A]
|
a.types.value = [TYPE_VENTE]
|
||||||
|
|
||||||
expect(b.categories.value).toEqual([CAT_A])
|
expect(b.types.value).toEqual([TYPE_VENTE])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,96 +1,56 @@
|
|||||||
/**
|
/**
|
||||||
* Composable d'administration des categories (M0 — Gestion des categories).
|
* Composable de chargement du referentiel CategoryType (M0 — Gestion des
|
||||||
|
* categories).
|
||||||
*
|
*
|
||||||
* Centralise le chargement et le state des deux ressources lues par la page
|
* Apres ERP-73 (composable de liste paginee), la liste des categories
|
||||||
* `/admin/categories` : la liste des categories et le referentiel
|
* elle-meme passe par `usePaginatedList<Category>` directement dans
|
||||||
* CategoryType (utilise dans le select du drawer).
|
* `admin/categories.vue` — c'est un etat propre a la page (pagination,
|
||||||
|
* filtres, tri locaux). Ce composable se concentre donc sur le
|
||||||
|
* referentiel CategoryType : petite collection lue une fois et reutilisee
|
||||||
|
* dans le drawer (select de type) → singleton volontaire pour eviter de
|
||||||
|
* la recharger a chaque ouverture du drawer.
|
||||||
*
|
*
|
||||||
* State singleton au niveau module (meme convention que `useSidebar` /
|
* State singleton au niveau module : reset automatique au logout via
|
||||||
* `useModules` / `useAuditLog`) : reset automatique au logout via
|
* `onAuthSessionCleared` (cf. CLAUDE.md regle frontend.md), et reset
|
||||||
* `onAuthSessionCleared` (cf. CLAUDE.md regle frontend.md : « composables
|
* explicite via `resetCategoriesAdmin()` appele depuis logout.vue.
|
||||||
* avec state singleton doivent etre reinitialises au logout »), et reset
|
|
||||||
* explicite expose via `resetCategoriesAdmin()` appele depuis
|
|
||||||
* `modules/core/pages/logout.vue`.
|
|
||||||
*/
|
*/
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import type { Category, CategoryType } from '~/modules/catalog/types/category'
|
import type { CategoryType } from '~/modules/catalog/types/category'
|
||||||
import type { HydraCollection } from '~/shared/utils/api'
|
import type { HydraCollection } from '~/shared/utils/api'
|
||||||
import { onAuthSessionCleared } from '~/shared/stores/auth'
|
import { onAuthSessionCleared } from '~/shared/stores/auth'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dette M0 : pas de pagination serveur sur les ressources Catalog (volumetrie
|
* CategoryType est un referentiel lecture-seule (RG-1.06) avec une
|
||||||
* cible ≤ 300). On force une page geante via `itemsPerPage` pour recuperer
|
* cardinalite minuscule (≤ 5 entrees connues). On force `pagination=false`
|
||||||
* toute la liste en un coup. A basculer en pagination serveur quand la
|
* pour recuperer toutes les entrees en un appel et alimenter le select du
|
||||||
* volumetrie reelle depassera ce plafond — meme pattern que sites.vue.
|
* drawer sans pagination — echappatoire prevue par
|
||||||
|
* `pagination_client_enabled: true` cote API Platform.
|
||||||
*/
|
*/
|
||||||
const HYDRA_NO_PAGINATION = 999
|
const NO_PAGINATION_QUERY = { pagination: 'false' } as const
|
||||||
|
|
||||||
// State singleton — partage entre tous les composants qui appellent le
|
|
||||||
// composable dans la meme session. Les refs sont declarees au niveau module
|
|
||||||
// (pas dans la fonction `useCategoriesAdmin()`) pour eviter qu'une nouvelle
|
|
||||||
// instance soit creee a chaque appel.
|
|
||||||
const categories = ref<Category[]>([])
|
|
||||||
const types = ref<CategoryType[]>([])
|
const types = ref<CategoryType[]>([])
|
||||||
const loading = ref(false)
|
|
||||||
const loadingTypes = ref(false)
|
const loadingTypes = ref(false)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
function resetCategoriesAdminState(): void {
|
function resetCategoriesAdminState(): void {
|
||||||
categories.value = []
|
|
||||||
types.value = []
|
types.value = []
|
||||||
loading.value = false
|
|
||||||
loadingTypes.value = false
|
loadingTypes.value = false
|
||||||
error.value = null
|
error.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-enregistrement singleton : purge le state sur 401/clearSession pour
|
// Auto-enregistrement singleton : purge le state sur 401/clearSession
|
||||||
// eviter qu'un user suivant (connecte sur le meme onglet) voie l'etat de
|
// pour eviter qu'un user suivant (connecte sur le meme onglet) voie le
|
||||||
// l'ancien. Le logout volontaire (page logout.vue) appelle directement
|
// referentiel de l'ancien tenant. Le logout volontaire (page logout.vue)
|
||||||
// `resetCategoriesAdmin()` ci-dessous.
|
// appelle directement `resetCategoriesAdmin()` ci-dessous.
|
||||||
onAuthSessionCleared(resetCategoriesAdminState)
|
onAuthSessionCleared(resetCategoriesAdminState)
|
||||||
|
|
||||||
export function useCategoriesAdmin() {
|
export function useCategoriesAdmin() {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Charge la liste des categories. Le serveur exclut les soft-deleted par
|
* Charge le referentiel CategoryType. Appele a l'ouverture de la page
|
||||||
* defaut (RG-1.08) et trie par name ASC (RG-1.10). Pas de pagination
|
* admin pour que le select du drawer ait deja les options pretes au
|
||||||
* serveur (volumetrie ≤ 300, pagination front via MalioDataTable).
|
* moment de la creation/edition.
|
||||||
*
|
|
||||||
* `includeDeleted=true` permet a un user avec `catalog.categories.manage`
|
|
||||||
* de voir les soft-deleted (RG-1.09) — au M0 la page n'utilise pas cette
|
|
||||||
* option mais on l'expose pour la suite (corbeille future).
|
|
||||||
*
|
|
||||||
* Swallow volontaire : un 403 (user sans permission view) ne doit pas
|
|
||||||
* toaster — la sidebar masque deja l'entree pour ces users, on tombe sur
|
|
||||||
* la page seulement par URL directe et on affiche un tableau vide propre.
|
|
||||||
*/
|
|
||||||
async function fetchAll(includeDeleted = false): Promise<void> {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const query: Record<string, unknown> = { itemsPerPage: HYDRA_NO_PAGINATION }
|
|
||||||
if (includeDeleted) {
|
|
||||||
query.includeDeleted = 'true'
|
|
||||||
}
|
|
||||||
const data = await api.get<HydraCollection<Category>>(
|
|
||||||
'/categories',
|
|
||||||
query,
|
|
||||||
{ toast: false },
|
|
||||||
)
|
|
||||||
categories.value = data.member ?? []
|
|
||||||
} catch (e) {
|
|
||||||
categories.value = []
|
|
||||||
error.value = (e as Error)?.message ?? 'Erreur de chargement'
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Charge le referentiel CategoryType (lecture seule, RG-1.06). Appele a
|
|
||||||
* l'ouverture de la page admin pour que le select du drawer ait deja les
|
|
||||||
* options pretes au moment de la creation/edition.
|
|
||||||
*
|
*
|
||||||
* Toast desactive : on stocke l'erreur dans `error` plutot que de
|
* Toast desactive : on stocke l'erreur dans `error` plutot que de
|
||||||
* spammer un toast — le drawer affichera l'erreur inline s'il y a lieu.
|
* spammer un toast — le drawer affichera l'erreur inline s'il y a lieu.
|
||||||
@@ -100,7 +60,7 @@ export function useCategoriesAdmin() {
|
|||||||
try {
|
try {
|
||||||
const data = await api.get<HydraCollection<CategoryType>>(
|
const data = await api.get<HydraCollection<CategoryType>>(
|
||||||
'/category_types',
|
'/category_types',
|
||||||
{ itemsPerPage: HYDRA_NO_PAGINATION },
|
NO_PAGINATION_QUERY,
|
||||||
{ toast: false },
|
{ toast: false },
|
||||||
)
|
)
|
||||||
types.value = data.member ?? []
|
types.value = data.member ?? []
|
||||||
@@ -113,21 +73,18 @@ export function useCategoriesAdmin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset explicite — appele depuis `logout.vue` apres `auth.logout()` pour
|
* Reset explicite — appele depuis `logout.vue` apres `auth.logout()`
|
||||||
* garantir que la prochaine session reparte sur un state propre meme si
|
* pour garantir que la prochaine session reparte sur un state propre
|
||||||
* `clearSession()` n'a pas ete declenche (cas logout volontaire).
|
* meme si `clearSession()` n'a pas ete declenche (cas logout volontaire).
|
||||||
*/
|
*/
|
||||||
function resetCategoriesAdmin(): void {
|
function resetCategoriesAdmin(): void {
|
||||||
resetCategoriesAdminState()
|
resetCategoriesAdminState()
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
categories,
|
|
||||||
types,
|
types,
|
||||||
loading,
|
|
||||||
loadingTypes,
|
loadingTypes,
|
||||||
error,
|
error,
|
||||||
fetchAll,
|
|
||||||
fetchTypes,
|
fetchTypes,
|
||||||
resetCategoriesAdmin,
|
resetCategoriesAdmin,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,18 +13,23 @@
|
|||||||
</template>
|
</template>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
|
||||||
<!-- Table des categories. Affichage exhaustif (volumetrie cible
|
<!-- Table des categories. Tri serveur (name ASC, RG-1.10) +
|
||||||
<= 300, cf. spec § 4.1) — tri 100% serveur via CategoryProvider
|
pagination serveur via usePaginatedList (#73). Le composable
|
||||||
(name ASC, RG-1.10). La barre de pagination du MalioDataTable
|
remplace l'ancien chargement « tout en un coup » a volumetrie
|
||||||
reste cosmetique tant qu'aucun slice client n'est cable : a
|
cible ≤ 300 — la pagination est desormais alignee sur la regle
|
||||||
traiter cote @malio/layer-ui le jour ou la volumetrie monte. -->
|
projet (toute collection paginee, regle ABSOLUE n°13). -->
|
||||||
<MalioDataTable
|
<MalioDataTable
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:items="categoryItems"
|
:items="categoryItems"
|
||||||
:total-items="categories.length"
|
:total-items="totalItems"
|
||||||
|
:page="currentPage"
|
||||||
|
:per-page="itemsPerPage"
|
||||||
|
:per-page-options="itemsPerPageOptions"
|
||||||
:row-clickable="true"
|
:row-clickable="true"
|
||||||
:empty-message="t('admin.categories.noCategories')"
|
:empty-message="t('admin.categories.noCategories')"
|
||||||
@row-click="onRowClick"
|
@row-click="onRowClick"
|
||||||
|
@update:page="goToPage"
|
||||||
|
@update:per-page="setItemsPerPage"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Drawer creation / consultation / edition. -->
|
<!-- Drawer creation / consultation / edition. -->
|
||||||
@@ -50,13 +55,27 @@ import type { Category } from '~/modules/catalog/types/category'
|
|||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { can } = usePermissions()
|
const { can } = usePermissions()
|
||||||
const { categories, fetchAll, fetchTypes } = useCategoriesAdmin()
|
const { fetchTypes } = useCategoriesAdmin()
|
||||||
const { submitDelete } = useCategoryForm()
|
const { submitDelete } = useCategoryForm()
|
||||||
|
|
||||||
useHead({ title: t('admin.categories.title') })
|
useHead({ title: t('admin.categories.title') })
|
||||||
|
|
||||||
const canManage = computed(() => can('catalog.categories.manage'))
|
const canManage = computed(() => can('catalog.categories.manage'))
|
||||||
|
|
||||||
|
// Pagination serveur via le composable partage (#73). Le CategoryProvider
|
||||||
|
// applique deja name ASC (RG-1.10) — pas besoin de defaultSort cote front
|
||||||
|
// tant qu'aucun OrderFilter n'est expose.
|
||||||
|
const {
|
||||||
|
items: categories,
|
||||||
|
totalItems,
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
itemsPerPageOptions,
|
||||||
|
fetch: fetchCategories,
|
||||||
|
goToPage,
|
||||||
|
setItemsPerPage,
|
||||||
|
} = usePaginatedList<Category>({ url: '/categories' })
|
||||||
|
|
||||||
const drawerOpen = ref(false)
|
const drawerOpen = ref(false)
|
||||||
const selectedCategory = ref<Category | null>(null)
|
const selectedCategory = ref<Category | null>(null)
|
||||||
const deleteModalOpen = ref(false)
|
const deleteModalOpen = ref(false)
|
||||||
@@ -118,7 +137,7 @@ async function handleDelete(): Promise<void> {
|
|||||||
deleteModalOpen.value = false
|
deleteModalOpen.value = false
|
||||||
categoryToDelete.value = null
|
categoryToDelete.value = null
|
||||||
drawerOpen.value = false
|
drawerOpen.value = false
|
||||||
await fetchAll()
|
await fetchCategories()
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
deleting.value = false
|
deleting.value = false
|
||||||
@@ -126,14 +145,14 @@ async function handleDelete(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onCategorySaved() {
|
function onCategorySaved() {
|
||||||
fetchAll()
|
fetchCategories()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chargement initial des deux ressources (liste + referentiel des types).
|
// Chargement initial des deux ressources (liste + referentiel des types).
|
||||||
// Le referentiel est pre-charge ici (et pas dans le drawer) pour que le
|
// Le referentiel est pre-charge ici (et pas dans le drawer) pour que le
|
||||||
// select soit pret au moment ou l'utilisateur clique sur « + Ajouter ».
|
// select soit pret au moment ou l'utilisateur clique sur « + Ajouter ».
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchAll()
|
fetchCategories()
|
||||||
fetchTypes()
|
fetchTypes()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
:title="`${group.module} (${selectedCountFor(group)}/${group.permissions.length})`"
|
:title="`${group.module} (${selectedCountFor(group)}/${group.permissions.length})`"
|
||||||
header-class="capitalize"
|
header-class="capitalize"
|
||||||
>
|
>
|
||||||
<div class="flex flex-col gap-3">
|
<div class="flex flex-col">
|
||||||
<!-- Tout selectionner pour ce module -->
|
<!-- Tout selectionner pour ce module -->
|
||||||
<MalioCheckbox
|
<MalioCheckbox
|
||||||
:id="`${idPrefix}-group-${group.module}`"
|
:id="`${idPrefix}-group-${group.module}`"
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
label-class="font-semibold text-sm text-neutral-700"
|
label-class="font-semibold text-sm text-neutral-700"
|
||||||
@update:model-value="(val: boolean) => emit('toggle-all', group.module, val)"
|
@update:model-value="(val: boolean) => emit('toggle-all', group.module, val)"
|
||||||
/>
|
/>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col">
|
||||||
<MalioCheckbox
|
<MalioCheckbox
|
||||||
v-for="perm in group.permissions"
|
v-for="perm in group.permissions"
|
||||||
:id="`${idPrefix}-perm-${perm.id}`"
|
:id="`${idPrefix}-perm-${perm.id}`"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
{{ isEditMode ? t('admin.roles.editRole') : t('admin.roles.createRole') }}
|
{{ isEditMode ? t('admin.roles.editRole') : t('admin.roles.createRole') }}
|
||||||
</h2>
|
</h2>
|
||||||
</template>
|
</template>
|
||||||
<form class="flex flex-col gap-4 py-4" @submit.prevent="handleSave">
|
<form class="flex flex-col py-4 gap-2" @submit.prevent="handleSave">
|
||||||
<!-- Champs du role -->
|
<!-- Champs du role -->
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="form.label"
|
v-model="form.label"
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
icon-name="mdi:delete-outline"
|
icon-name="mdi:delete-outline"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
:disabled="role?.isSystem"
|
:disabled="role?.isSystem"
|
||||||
@click="emit('delete')"
|
@click="emit('delete')"
|
||||||
/>
|
/>
|
||||||
@@ -79,13 +79,13 @@
|
|||||||
v-else
|
v-else
|
||||||
:label="t('common.cancel')"
|
:label="t('common.cancel')"
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
@click="emit('update:modelValue', false)"
|
@click="emit('update:modelValue', false)"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
:label="t('common.save')"
|
:label="t('common.save')"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
:disabled="saving || permissionsLoadFailed"
|
:disabled="saving || permissionsLoadFailed"
|
||||||
@click="handleSave"
|
@click="handleSave"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
{{ t('admin.users.drawer.title', { username: user?.username ?? '' }) }}
|
{{ t('admin.users.drawer.title', { username: user?.username ?? '' }) }}
|
||||||
</h2>
|
</h2>
|
||||||
</template>
|
</template>
|
||||||
<div class="flex flex-col gap-4 py-4">
|
<div class="flex flex-col space-y-4 py-4">
|
||||||
<!-- Etat d'erreur de chargement des referentiels : bloque la
|
<!-- Etat d'erreur de chargement des referentiels : bloque la
|
||||||
sauvegarde pour empecher un ecrasement silencieux des droits. -->
|
sauvegarde pour empecher un ecrasement silencieux des droits. -->
|
||||||
<div
|
<div
|
||||||
@@ -41,11 +41,13 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Section Roles -->
|
<!-- Section Roles -->
|
||||||
<div>
|
<!-- !mt-0 : la MalioCheckbox au-dessus expose son slot message (16px),
|
||||||
|
qui couvre deja l'ecart attendu — pas besoin du space-y-4 ici. -->
|
||||||
|
<div class="!mt-0">
|
||||||
<h4 class="mb-3 text-sm font-semibold text-neutral-700">
|
<h4 class="mb-3 text-sm font-semibold text-neutral-700">
|
||||||
{{ t('admin.users.drawer.rolesSection') }}
|
{{ t('admin.users.drawer.rolesSection') }}
|
||||||
</h4>
|
</h4>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col">
|
||||||
<MalioCheckbox
|
<MalioCheckbox
|
||||||
v-for="role in allRoles"
|
v-for="role in allRoles"
|
||||||
:key="role.id"
|
:key="role.id"
|
||||||
@@ -84,7 +86,7 @@
|
|||||||
<div v-if="allSites.length === 0" class="text-sm text-neutral-400">
|
<div v-if="allSites.length === 0" class="text-sm text-neutral-400">
|
||||||
{{ t('admin.sites.noSites') }}
|
{{ t('admin.sites.noSites') }}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col">
|
||||||
<MalioCheckbox
|
<MalioCheckbox
|
||||||
v-for="site in allSites"
|
v-for="site in allSites"
|
||||||
:id="`site-${site.id}`"
|
:id="`site-${site.id}`"
|
||||||
@@ -113,13 +115,13 @@
|
|||||||
<MalioButton
|
<MalioButton
|
||||||
:label="t('common.cancel')"
|
:label="t('common.cancel')"
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
@click="emit('update:modelValue', false)"
|
@click="emit('update:modelValue', false)"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
:label="t('common.save')"
|
:label="t('common.save')"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
:disabled="saving || loadFailed"
|
:disabled="saving || loadFailed"
|
||||||
@click="handleSave"
|
@click="handleSave"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -66,15 +66,18 @@
|
|||||||
<MalioAccordion>
|
<MalioAccordion>
|
||||||
<!-- Dates : deux champs date+heure Du / Au (champs datetime a l'origine) -->
|
<!-- Dates : deux champs date+heure Du / Au (champs datetime a l'origine) -->
|
||||||
<MalioAccordionItem :title="t('audit.filters.date_range')" value="dates">
|
<MalioAccordionItem :title="t('audit.filters.date_range')" value="dates">
|
||||||
<div class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-4">
|
<!-- pb-4 sur les labels Du/Au : simule le slot message
|
||||||
<span>{{ t('audit.filters.date_from') }}</span>
|
du MalioDateTime voisin pour qu'items-center recentre
|
||||||
|
le label sur le centre visible du champ. -->
|
||||||
|
<div class="grid grid-cols-[auto_1fr] items-center gap-x-3">
|
||||||
|
<span class="pb-4">{{ t('audit.filters.date_from') }}</span>
|
||||||
<!-- Borne le picker "Du" par la valeur "Au" pour interdire une plage
|
<!-- Borne le picker "Du" par la valeur "Au" pour interdire une plage
|
||||||
inversee a la saisie (le backend renverrait silencieusement 0 ligne). -->
|
inversee a la saisie (le backend renverrait silencieusement 0 ligne). -->
|
||||||
<MalioDateTime
|
<MalioDateTime
|
||||||
v-model="draftDateFrom"
|
v-model="draftDateFrom"
|
||||||
:max="draftDateTo ?? undefined"
|
:max="draftDateTo ?? undefined"
|
||||||
/>
|
/>
|
||||||
<span>{{ t('audit.filters.date_to') }}</span>
|
<span class="pb-4">{{ t('audit.filters.date_to') }}</span>
|
||||||
<MalioDateTime
|
<MalioDateTime
|
||||||
v-model="draftDateTo"
|
v-model="draftDateTo"
|
||||||
:min="draftDateFrom ?? undefined"
|
:min="draftDateFrom ?? undefined"
|
||||||
@@ -84,7 +87,7 @@
|
|||||||
|
|
||||||
<!-- Type d'entite : cases a cocher (multi-selection) -->
|
<!-- Type d'entite : cases a cocher (multi-selection) -->
|
||||||
<MalioAccordionItem :title="t('audit.filters.entity_type')" value="entity">
|
<MalioAccordionItem :title="t('audit.filters.entity_type')" value="entity">
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col">
|
||||||
<MalioCheckbox
|
<MalioCheckbox
|
||||||
v-for="opt in entityTypeOptions"
|
v-for="opt in entityTypeOptions"
|
||||||
:id="`filter-entity-${opt.value}`"
|
:id="`filter-entity-${opt.value}`"
|
||||||
@@ -105,6 +108,7 @@
|
|||||||
name="audit-action"
|
name="audit-action"
|
||||||
:value="opt.value"
|
:value="opt.value"
|
||||||
:label="opt.label"
|
:label="opt.label"
|
||||||
|
group-class="mt-0"
|
||||||
/>
|
/>
|
||||||
</MalioAccordionItem>
|
</MalioAccordionItem>
|
||||||
|
|
||||||
@@ -121,7 +125,7 @@
|
|||||||
<MalioButton
|
<MalioButton
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
:label="t('audit.filters.reset')"
|
:label="t('audit.filters.reset')"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
@click="resetFilters"
|
@click="resetFilters"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
|
|||||||
@@ -13,14 +13,19 @@
|
|||||||
</template>
|
</template>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
|
||||||
<!-- Table des roles -->
|
<!-- Table des roles — pagination serveur via usePaginatedList (#73). -->
|
||||||
<MalioDataTable
|
<MalioDataTable
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:items="roleItems"
|
:items="roleItems"
|
||||||
:total-items="roles.length"
|
:total-items="totalItems"
|
||||||
|
:page="currentPage"
|
||||||
|
:per-page="itemsPerPage"
|
||||||
|
:per-page-options="itemsPerPageOptions"
|
||||||
:row-clickable="canManage"
|
:row-clickable="canManage"
|
||||||
:empty-message="t('admin.roles.noRoles')"
|
:empty-message="t('admin.roles.noRoles')"
|
||||||
@row-click="onRowClick"
|
@row-click="onRowClick"
|
||||||
|
@update:page="goToPage"
|
||||||
|
@update:per-page="setItemsPerPage"
|
||||||
>
|
>
|
||||||
<template #cell-code="{ item }">
|
<template #cell-code="{ item }">
|
||||||
<span class="font-mono text-xs">{{ item.code }}</span>
|
<span class="font-mono text-xs">{{ item.code }}</span>
|
||||||
@@ -66,8 +71,17 @@ const canManage = computed(() => can('core.roles.manage'))
|
|||||||
|
|
||||||
useHead({ title: t('admin.roles.title') })
|
useHead({ title: t('admin.roles.title') })
|
||||||
|
|
||||||
const roles = ref<Role[]>([])
|
// Pagination serveur via le composable partage (#73).
|
||||||
const loading = ref(false)
|
const {
|
||||||
|
items: roles,
|
||||||
|
totalItems,
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
itemsPerPageOptions,
|
||||||
|
fetch: loadRoles,
|
||||||
|
goToPage,
|
||||||
|
setItemsPerPage,
|
||||||
|
} = usePaginatedList<Role>({ url: '/roles' })
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ key: 'label', label: t('admin.roles.table.label') },
|
{ key: 'label', label: t('admin.roles.table.label') },
|
||||||
@@ -102,25 +116,6 @@ const deleteModalOpen = ref(false)
|
|||||||
const roleToDelete = ref<Role | null>(null)
|
const roleToDelete = ref<Role | null>(null)
|
||||||
const deleting = ref(false)
|
const deleting = ref(false)
|
||||||
|
|
||||||
// Charger la liste des roles
|
|
||||||
async function loadRoles() {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
const data = await api.get<{ member: Role[] }>(
|
|
||||||
'/roles',
|
|
||||||
{},
|
|
||||||
{ toast: false },
|
|
||||||
)
|
|
||||||
roles.value = data.member
|
|
||||||
} catch {
|
|
||||||
// Reset sur echec pour ne pas afficher de donnees stale (ancienne
|
|
||||||
// requete reussie avant une perte reseau ou 403).
|
|
||||||
roles.value = []
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function openCreateDrawer() {
|
function openCreateDrawer() {
|
||||||
selectedRole.value = null
|
selectedRole.value = null
|
||||||
drawerOpen.value = true
|
drawerOpen.value = true
|
||||||
|
|||||||
@@ -2,14 +2,19 @@
|
|||||||
<div>
|
<div>
|
||||||
<PageHeader>{{ t('admin.users.title') }}</PageHeader>
|
<PageHeader>{{ t('admin.users.title') }}</PageHeader>
|
||||||
|
|
||||||
<!-- Table des utilisateurs -->
|
<!-- Table des utilisateurs — pagination serveur via usePaginatedList (#73). -->
|
||||||
<MalioDataTable
|
<MalioDataTable
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:items="userItems"
|
:items="userItems"
|
||||||
:total-items="users.length"
|
:total-items="totalItems"
|
||||||
|
:page="currentPage"
|
||||||
|
:per-page="itemsPerPage"
|
||||||
|
:per-page-options="itemsPerPageOptions"
|
||||||
:row-clickable="canManage"
|
:row-clickable="canManage"
|
||||||
:empty-message="t('admin.users.noUsers')"
|
:empty-message="t('admin.users.noUsers')"
|
||||||
@row-click="onRowClick"
|
@row-click="onRowClick"
|
||||||
|
@update:page="goToPage"
|
||||||
|
@update:per-page="setItemsPerPage"
|
||||||
>
|
>
|
||||||
<template #cell-admin="{ item }">
|
<template #cell-admin="{ item }">
|
||||||
<span
|
<span
|
||||||
@@ -34,15 +39,26 @@
|
|||||||
import type { UserListItem } from '~/shared/types/rbac'
|
import type { UserListItem } from '~/shared/types/rbac'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const api = useApi()
|
|
||||||
const { can } = usePermissions()
|
const { can } = usePermissions()
|
||||||
|
|
||||||
useHead({ title: t('admin.users.title') })
|
useHead({ title: t('admin.users.title') })
|
||||||
|
|
||||||
const canManage = computed(() => can('core.users.manage'))
|
const canManage = computed(() => can('core.users.manage'))
|
||||||
|
|
||||||
const users = ref<UserListItem[]>([])
|
// Pagination serveur via le composable partage (#73). Le payload `users`
|
||||||
const loading = ref(false)
|
// reste leger (pas de detail RBAC dans la liste — cf. commentaire colonne
|
||||||
|
// "Sites" plus bas) ce qui rend la pagination 10/25/50 par page confortable.
|
||||||
|
const {
|
||||||
|
items: users,
|
||||||
|
totalItems,
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
itemsPerPageOptions,
|
||||||
|
fetch: loadUsers,
|
||||||
|
goToPage,
|
||||||
|
setItemsPerPage,
|
||||||
|
} = usePaginatedList<UserListItem>({ url: '/users' })
|
||||||
|
|
||||||
const drawerOpen = ref(false)
|
const drawerOpen = ref(false)
|
||||||
const selectedUser = ref<UserListItem | null>(null)
|
const selectedUser = ref<UserListItem | null>(null)
|
||||||
|
|
||||||
@@ -67,21 +83,6 @@ const userItems = computed(() =>
|
|||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
async function loadUsers() {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
const usersData = await api.get<{ member: UserListItem[] }>('/users', {}, { toast: false })
|
|
||||||
users.value = usersData.member
|
|
||||||
} catch {
|
|
||||||
// Reset sur echec pour ne pas afficher de donnees stale (ancienne
|
|
||||||
// requete reussie avant une perte reseau ou 403). Pas de toast par
|
|
||||||
// design ici : on laisse la liste vide parler d'elle-meme.
|
|
||||||
users.value = []
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getUserById(id: number): UserListItem | undefined {
|
function getUserById(id: number): UserListItem | undefined {
|
||||||
return users.value.find(u => u.id === id)
|
return users.value.find(u => u.id === id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<img src="/LOGO_MALIO.png" alt="Logo" class="w-[150px]"/>
|
<img src="/LOGO_MALIO.png" alt="Logo" class="w-[150px]"/>
|
||||||
</span>
|
</span>
|
||||||
<form
|
<form
|
||||||
class="mt-8 space-y-6 rounded-lg border border-neutral-200 bg-white p-6 shadow-sm"
|
class="mt-8 rounded-lg border border-neutral-200 bg-white p-6 shadow-sm"
|
||||||
@submit.prevent="handleSubmit"
|
@submit.prevent="handleSubmit"
|
||||||
>
|
>
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
type="submit"
|
type="submit"
|
||||||
:disabled="isSubmitting"
|
:disabled="isSubmitting"
|
||||||
/>
|
/>
|
||||||
<p class="font-bold">v{{ version }}</p>
|
<p class="mt-6 font-bold">v{{ version }}</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
{{ isEditMode ? t('admin.sites.editSite') : t('admin.sites.createSite') }}
|
{{ isEditMode ? t('admin.sites.editSite') : t('admin.sites.createSite') }}
|
||||||
</h2>
|
</h2>
|
||||||
</template>
|
</template>
|
||||||
<form class="flex flex-col gap-4 py-4" @submit.prevent="handleSave">
|
<form class="flex flex-col py-4 gap-2" @submit.prevent="handleSave">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="form.name"
|
v-model="form.name"
|
||||||
:label="t('admin.sites.form.name')"
|
:label="t('admin.sites.form.name')"
|
||||||
@@ -65,11 +65,16 @@
|
|||||||
input-class="w-full font-mono"
|
input-class="w-full font-mono"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<span
|
<!-- pb-4 sur le wrapper : simule le slot message du
|
||||||
:style="{ backgroundColor: isValidHex ? form.color : 'transparent' }"
|
MalioInputText voisin pour qu'items-center recentre
|
||||||
class="inline-block size-10 shrink-0 rounded-lg border border-neutral-200"
|
la puce sur le centre visible de l'input. -->
|
||||||
:class="{ 'border-dashed': !isValidHex }"
|
<div class="shrink-0 pb-4">
|
||||||
/>
|
<span
|
||||||
|
:style="{ backgroundColor: isValidHex ? form.color : 'transparent' }"
|
||||||
|
class="inline-block size-10 rounded-lg border border-neutral-200"
|
||||||
|
:class="{ 'border-dashed': !isValidHex }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="form.color && !isValidHex" class="mt-1 text-xs text-red-600">
|
<p v-if="form.color && !isValidHex" class="mt-1 text-xs text-red-600">
|
||||||
{{ t('admin.sites.form.colorInvalid') }}
|
{{ t('admin.sites.form.colorInvalid') }}
|
||||||
@@ -87,20 +92,20 @@
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
icon-name="mdi:delete-outline"
|
icon-name="mdi:delete-outline"
|
||||||
icon-position="left"
|
icon-position="left"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
@click="emit('delete')"
|
@click="emit('delete')"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
v-else
|
v-else
|
||||||
:label="t('common.cancel')"
|
:label="t('common.cancel')"
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
@click="emit('update:modelValue', false)"
|
@click="emit('update:modelValue', false)"
|
||||||
/>
|
/>
|
||||||
<MalioButton
|
<MalioButton
|
||||||
:label="t('common.save')"
|
:label="t('common.save')"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
button-class="w-[150px]"
|
button-class="w-m-btn-action"
|
||||||
:disabled="saving || !isValidHex"
|
:disabled="saving || !isValidHex"
|
||||||
@click="handleSave"
|
@click="handleSave"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -13,14 +13,19 @@
|
|||||||
</template>
|
</template>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
|
|
||||||
<!-- Table des sites -->
|
<!-- Table des sites — pagination serveur via usePaginatedList (#73). -->
|
||||||
<MalioDataTable
|
<MalioDataTable
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:items="siteItems"
|
:items="siteItems"
|
||||||
:total-items="sites.length"
|
:total-items="totalItems"
|
||||||
|
:page="currentPage"
|
||||||
|
:per-page="itemsPerPage"
|
||||||
|
:per-page-options="itemsPerPageOptions"
|
||||||
:row-clickable="canManage"
|
:row-clickable="canManage"
|
||||||
:empty-message="t('admin.sites.noSites')"
|
:empty-message="t('admin.sites.noSites')"
|
||||||
@row-click="onRowClick"
|
@row-click="onRowClick"
|
||||||
|
@update:page="goToPage"
|
||||||
|
@update:per-page="setItemsPerPage"
|
||||||
>
|
>
|
||||||
<template #cell-color="{ item }">
|
<template #cell-color="{ item }">
|
||||||
<span class="inline-flex items-center gap-2">
|
<span class="inline-flex items-center gap-2">
|
||||||
@@ -67,8 +72,20 @@ const canManage = computed(() => can('sites.manage'))
|
|||||||
|
|
||||||
useHead({ title: t('admin.sites.title') })
|
useHead({ title: t('admin.sites.title') })
|
||||||
|
|
||||||
const sites = ref<Site[]>([])
|
// Pagination serveur via le composable partage (#73). Aucun OrderFilter
|
||||||
const loading = ref(false)
|
// declare cote API Platform sur Site, donc on s'appuie sur le tri par
|
||||||
|
// defaut du repository (id ASC). Le composable est neanmoins pret a
|
||||||
|
// recevoir un `defaultSort` ou des filtres le jour ou l'API les expose.
|
||||||
|
const {
|
||||||
|
items: sites,
|
||||||
|
totalItems,
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
itemsPerPageOptions,
|
||||||
|
fetch: loadSites,
|
||||||
|
goToPage,
|
||||||
|
setItemsPerPage,
|
||||||
|
} = usePaginatedList<Site>({ url: '/sites' })
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ key: 'name', label: t('admin.sites.table.name') },
|
{ key: 'name', label: t('admin.sites.table.name') },
|
||||||
@@ -107,24 +124,6 @@ const deleteModalOpen = ref(false)
|
|||||||
const siteToDelete = ref<Site | null>(null)
|
const siteToDelete = ref<Site | null>(null)
|
||||||
const deleting = ref(false)
|
const deleting = ref(false)
|
||||||
|
|
||||||
async function loadSites() {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
const data = await api.get<{ member: Site[] }>(
|
|
||||||
'/sites',
|
|
||||||
{ itemsPerPage: 999 },
|
|
||||||
{ toast: false },
|
|
||||||
)
|
|
||||||
sites.value = data.member
|
|
||||||
} catch {
|
|
||||||
// Reset sur echec pour ne pas afficher de donnees stale (ancienne
|
|
||||||
// requete reussie avant une perte reseau ou 403).
|
|
||||||
sites.value = []
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function openCreateDrawer() {
|
function openCreateDrawer() {
|
||||||
selectedSite.value = null
|
selectedSite.value = null
|
||||||
drawerOpen.value = true
|
drawerOpen.value = true
|
||||||
|
|||||||
Generated
+4
-4
@@ -7,7 +7,7 @@
|
|||||||
"name": "starseed-frontend",
|
"name": "starseed-frontend",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@malio/layer-ui": "^1.7.1",
|
"@malio/layer-ui": "^1.7.3",
|
||||||
"@nuxt/icon": "^2.2.1",
|
"@nuxt/icon": "^2.2.1",
|
||||||
"@nuxtjs/i18n": "^10.2.3",
|
"@nuxtjs/i18n": "^10.2.3",
|
||||||
"@nuxtjs/tailwindcss": "^6.14.0",
|
"@nuxtjs/tailwindcss": "^6.14.0",
|
||||||
@@ -1866,9 +1866,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@malio/layer-ui": {
|
"node_modules/@malio/layer-ui": {
|
||||||
"version": "1.7.1",
|
"version": "1.7.3",
|
||||||
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.1/layer-ui-1.7.1.tgz",
|
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.3/layer-ui-1.7.3.tgz",
|
||||||
"integrity": "sha512-RYMMappWt/fgjD+BM7//h2O6kxD6WH9Fui8hoC29xtKySRQsqD61XKTdR7BRRkpktbxKmV39q/hblyAFBqV5yw==",
|
"integrity": "sha512-jw3ka0Az6Jf0F9ifsooknkwXph8TNgoe6H3CjF8tbBxl8oND8HLHjlZ04ooUCoOUEIlsQ1Mm2hFFlQRCB04qdA==",
|
||||||
"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.1",
|
"@malio/layer-ui": "^1.7.3",
|
||||||
"@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",
|
||||||
|
|||||||
@@ -0,0 +1,412 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
import { usePaginatedList } from '../usePaginatedList'
|
||||||
|
|
||||||
|
const mockApiGet = vi.hoisted(() => vi.fn())
|
||||||
|
vi.stubGlobal('useApi', () => ({ get: mockApiGet }))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests du composable `usePaginatedList`.
|
||||||
|
*
|
||||||
|
* Couvre les invariants critiques :
|
||||||
|
* - parse Hydra (member / totalItems)
|
||||||
|
* - navigation page (goToPage / next / prev / bornes)
|
||||||
|
* - changement items/page → retour page 1
|
||||||
|
* - mutation filtres / tri → retour page 1
|
||||||
|
* - cas limite : page courante hors borne apres filtre → derniere page valide
|
||||||
|
* - liste vide / page unique
|
||||||
|
* - reset → defaults
|
||||||
|
* - swallow d'erreur reseau (la promesse `fetch` ne reject jamais)
|
||||||
|
* - header `Accept: application/ld+json` toujours envoye (besoin du
|
||||||
|
* paginator Hydra cote API Platform 4).
|
||||||
|
*/
|
||||||
|
describe('usePaginatedList', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockApiGet.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
function mockResponse(member: unknown[], totalItems: number): void {
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member, totalItems })
|
||||||
|
}
|
||||||
|
|
||||||
|
it('fetch initial : page=1, itemsPerPage par defaut, parse Hydra', async () => {
|
||||||
|
mockResponse([{ id: 1 }, { id: 2 }], 42)
|
||||||
|
const list = usePaginatedList<{ id: number }>({ url: '/sites' })
|
||||||
|
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
expect(mockApiGet).toHaveBeenCalledTimes(1)
|
||||||
|
const [url, query, opts] = mockApiGet.mock.calls[0]
|
||||||
|
expect(url).toBe('/sites')
|
||||||
|
expect(query).toMatchObject({ page: 1, itemsPerPage: 10 })
|
||||||
|
expect(opts).toMatchObject({
|
||||||
|
toast: false,
|
||||||
|
headers: { Accept: 'application/ld+json' },
|
||||||
|
})
|
||||||
|
expect(list.items.value).toEqual([{ id: 1 }, { id: 2 }])
|
||||||
|
expect(list.totalItems.value).toBe(42)
|
||||||
|
expect(list.totalPages.value).toBe(5)
|
||||||
|
expect(list.isEmpty.value).toBe(false)
|
||||||
|
expect(list.isSinglePage.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('itemsPerPage personnalise est respecte au premier fetch', async () => {
|
||||||
|
mockResponse([], 0)
|
||||||
|
const list = usePaginatedList({ url: '/users', defaultItemsPerPage: 25 })
|
||||||
|
await list.fetch()
|
||||||
|
expect(mockApiGet.mock.calls[0][1]).toMatchObject({ itemsPerPage: 25 })
|
||||||
|
expect(list.itemsPerPage.value).toBe(25)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('goToPage(N) declenche un nouvel appel avec page=N', async () => {
|
||||||
|
mockResponse([{ id: 1 }], 30) // page 1
|
||||||
|
const list = usePaginatedList<{ id: number }>({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockResponse([{ id: 2 }], 30) // page 2
|
||||||
|
await list.goToPage(2)
|
||||||
|
|
||||||
|
expect(mockApiGet).toHaveBeenCalledTimes(2)
|
||||||
|
expect(mockApiGet.mock.calls[1][1]).toMatchObject({ page: 2, itemsPerPage: 10 })
|
||||||
|
expect(list.currentPage.value).toBe(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('goToPage hors borne sup. est clampe a totalPages', async () => {
|
||||||
|
mockResponse([], 30) // totalPages = 3
|
||||||
|
const list = usePaginatedList({ url: '/roles' })
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockResponse([], 30)
|
||||||
|
await list.goToPage(999)
|
||||||
|
|
||||||
|
expect(list.currentPage.value).toBe(3)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('goToPage hors borne inf. est clampe a 1 (no-op si deja en 1)', async () => {
|
||||||
|
mockResponse([], 30)
|
||||||
|
const list = usePaginatedList({ url: '/roles' })
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockApiGet.mockClear()
|
||||||
|
await list.goToPage(-5)
|
||||||
|
|
||||||
|
// Deja en page 1 -> aucun nouvel appel.
|
||||||
|
expect(mockApiGet).toHaveBeenCalledTimes(0)
|
||||||
|
expect(list.currentPage.value).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('nextPage / prevPage avancent et reculent dans les bornes', async () => {
|
||||||
|
mockResponse([], 30) // page 1, totalPages 3
|
||||||
|
const list = usePaginatedList({ url: '/roles' })
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockResponse([], 30)
|
||||||
|
await list.nextPage()
|
||||||
|
expect(list.currentPage.value).toBe(2)
|
||||||
|
|
||||||
|
mockResponse([], 30)
|
||||||
|
await list.nextPage()
|
||||||
|
expect(list.currentPage.value).toBe(3)
|
||||||
|
|
||||||
|
// En derniere page -> no-op
|
||||||
|
mockApiGet.mockClear()
|
||||||
|
await list.nextPage()
|
||||||
|
expect(mockApiGet).toHaveBeenCalledTimes(0)
|
||||||
|
expect(list.currentPage.value).toBe(3)
|
||||||
|
|
||||||
|
mockResponse([], 30)
|
||||||
|
await list.prevPage()
|
||||||
|
expect(list.currentPage.value).toBe(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setItemsPerPage revient en page 1 et refetch', async () => {
|
||||||
|
mockResponse([], 100)
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
// place-toi page 3
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.goToPage(3)
|
||||||
|
expect(list.currentPage.value).toBe(3)
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setItemsPerPage(25)
|
||||||
|
|
||||||
|
expect(list.currentPage.value).toBe(1)
|
||||||
|
expect(list.itemsPerPage.value).toBe(25)
|
||||||
|
expect(mockApiGet.mock.calls.at(-1)?.[1]).toMatchObject({ page: 1, itemsPerPage: 25 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setItemsPerPage no-op si meme valeur', async () => {
|
||||||
|
mockResponse([], 10)
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockApiGet.mockClear()
|
||||||
|
await list.setItemsPerPage(10)
|
||||||
|
expect(mockApiGet).toHaveBeenCalledTimes(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setFilters fusionne et retombe en page 1', async () => {
|
||||||
|
mockResponse([], 100)
|
||||||
|
const list = usePaginatedList<unknown, { name?: string; active?: boolean }>({
|
||||||
|
url: '/users',
|
||||||
|
defaultFilters: { active: true },
|
||||||
|
})
|
||||||
|
await list.fetch()
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.goToPage(2)
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setFilters({ name: 'alice' })
|
||||||
|
|
||||||
|
expect(list.currentPage.value).toBe(1)
|
||||||
|
expect(list.filters.value).toEqual({ active: true, name: 'alice' })
|
||||||
|
expect(mockApiGet.mock.calls.at(-1)?.[1]).toMatchObject({
|
||||||
|
page: 1,
|
||||||
|
active: true,
|
||||||
|
name: 'alice',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setFilters({ key: undefined }) supprime la cle', async () => {
|
||||||
|
mockResponse([], 100)
|
||||||
|
const list = usePaginatedList<unknown, { name?: string }>({
|
||||||
|
url: '/users',
|
||||||
|
defaultFilters: { name: 'alice' },
|
||||||
|
})
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setFilters({ name: undefined })
|
||||||
|
|
||||||
|
expect(list.filters.value).toEqual({})
|
||||||
|
// Le query envoye ne contient plus `name` (compactQuery elimine
|
||||||
|
// aussi les valeurs vides).
|
||||||
|
const q = mockApiGet.mock.calls.at(-1)?.[1] as Record<string, unknown>
|
||||||
|
expect(q.name).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setFilters({ replace: true }) remplace integralement', async () => {
|
||||||
|
mockResponse([], 100)
|
||||||
|
const list = usePaginatedList<unknown, { a?: string; b?: string }>({
|
||||||
|
url: '/users',
|
||||||
|
defaultFilters: { a: 'x' },
|
||||||
|
})
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setFilters({ b: 'y' }, { replace: true })
|
||||||
|
|
||||||
|
expect(list.filters.value).toEqual({ b: 'y' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setSort envoie order[field]=direction et reset page', async () => {
|
||||||
|
mockResponse([], 100)
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.goToPage(2)
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setSort({ field: 'username', direction: 'desc' })
|
||||||
|
|
||||||
|
expect(list.currentPage.value).toBe(1)
|
||||||
|
const q = mockApiGet.mock.calls.at(-1)?.[1] as Record<string, unknown>
|
||||||
|
expect(q['order[username]']).toBe('desc')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setSort(null) retire le tri', async () => {
|
||||||
|
mockResponse([], 100)
|
||||||
|
const list = usePaginatedList({
|
||||||
|
url: '/users',
|
||||||
|
defaultSort: { field: 'name', direction: 'asc' },
|
||||||
|
})
|
||||||
|
await list.fetch()
|
||||||
|
// Le tri initial est applique
|
||||||
|
let q = mockApiGet.mock.calls[0][1] as Record<string, unknown>
|
||||||
|
expect(q['order[name]']).toBe('asc')
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setSort(null)
|
||||||
|
q = mockApiGet.mock.calls.at(-1)?.[1] as Record<string, unknown>
|
||||||
|
expect(q['order[name]']).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('setFilters retombe en page 1 (cas standard, pas le hors-borne)', async () => {
|
||||||
|
// setFilters remet toujours page=1 avant de refetcher : ce n'est
|
||||||
|
// donc PAS le chemin de retry hors-borne (couvert par le test
|
||||||
|
// suivant via un refetch a page constante). On verifie juste le
|
||||||
|
// reset de page ici.
|
||||||
|
mockResponse([], 50) // 5 pages
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
mockResponse([], 50)
|
||||||
|
await list.goToPage(5)
|
||||||
|
expect(list.currentPage.value).toBe(5)
|
||||||
|
|
||||||
|
mockResponse([{ id: 1 }, { id: 2 }], 12)
|
||||||
|
await list.setFilters({ active: true } as never)
|
||||||
|
|
||||||
|
expect(list.currentPage.value).toBe(1)
|
||||||
|
expect(mockApiGet.mock.calls.at(-1)?.[1]).toMatchObject({ page: 1 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('declenche le retry sur derniere page si currentPage > totalPages apres fetch', async () => {
|
||||||
|
// Scenario : on a fait un fetch (5 pages, page=1). Sans toucher aux
|
||||||
|
// filtres mais entre deux fetchs la donnee a change cote serveur,
|
||||||
|
// la page courante peut devenir hors borne. On force le scenario
|
||||||
|
// en montant manuellement currentPage via goToPage borne, puis en
|
||||||
|
// simulant une reponse plus petite.
|
||||||
|
mockResponse([], 50) // 5 pages
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockResponse([], 50)
|
||||||
|
await list.goToPage(5)
|
||||||
|
expect(list.currentPage.value).toBe(5)
|
||||||
|
|
||||||
|
// Maintenant simule : refetch -> totalItems chute a 12 (2 pages),
|
||||||
|
// le composable doit refetcher sur page=2.
|
||||||
|
mockApiGet.mockReset()
|
||||||
|
mockApiGet
|
||||||
|
.mockResolvedValueOnce({ member: [], totalItems: 12 }) // page=5 vide
|
||||||
|
.mockResolvedValueOnce({ member: [{ id: 11 }, { id: 12 }], totalItems: 12 }) // page=2
|
||||||
|
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
expect(mockApiGet).toHaveBeenCalledTimes(2)
|
||||||
|
expect(mockApiGet.mock.calls[1][1]).toMatchObject({ page: 2 })
|
||||||
|
expect(list.currentPage.value).toBe(2)
|
||||||
|
expect(list.items.value).toEqual([{ id: 11 }, { id: 12 }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('liste vide : isEmpty true, isSinglePage true', async () => {
|
||||||
|
mockResponse([], 0)
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
expect(list.totalItems.value).toBe(0)
|
||||||
|
expect(list.isEmpty.value).toBe(true)
|
||||||
|
expect(list.isSinglePage.value).toBe(true)
|
||||||
|
expect(list.totalPages.value).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('isEmpty est faux avant le premier fetch (etat indetermine)', () => {
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
expect(list.isEmpty.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('reset revient aux defaults', async () => {
|
||||||
|
mockResponse([], 100)
|
||||||
|
const list = usePaginatedList<unknown, { a?: string }>({
|
||||||
|
url: '/users',
|
||||||
|
defaultItemsPerPage: 10,
|
||||||
|
defaultFilters: { a: 'x' },
|
||||||
|
defaultSort: { field: 'name', direction: 'asc' },
|
||||||
|
})
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setItemsPerPage(50)
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setFilters({ a: 'y' })
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.setSort({ field: 'id', direction: 'desc' })
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.goToPage(2)
|
||||||
|
expect(list.currentPage.value).toBe(2)
|
||||||
|
|
||||||
|
mockResponse([], 100)
|
||||||
|
await list.reset()
|
||||||
|
|
||||||
|
expect(list.itemsPerPage.value).toBe(10)
|
||||||
|
expect(list.filters.value).toEqual({ a: 'x' })
|
||||||
|
expect(list.sort.value).toEqual({ field: 'name', direction: 'asc' })
|
||||||
|
expect(list.currentPage.value).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('swallow l\'erreur reseau : items vides, loading false, fetch ne reject pas', async () => {
|
||||||
|
const boom = new Error('boom')
|
||||||
|
mockApiGet.mockRejectedValueOnce(boom)
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
|
||||||
|
await expect(list.fetch()).resolves.toBeUndefined()
|
||||||
|
expect(list.items.value).toEqual([])
|
||||||
|
expect(list.totalItems.value).toBe(0)
|
||||||
|
expect(list.loading.value).toBe(false)
|
||||||
|
// L'erreur est consideree comme un fetch consume -> isEmpty=true.
|
||||||
|
expect(list.isEmpty.value).toBe(true)
|
||||||
|
// ... mais `error` est expose pour distinguer « vide » d'« echec ».
|
||||||
|
expect(list.error.value).toBe(boom)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('error est remis a null des qu\'un fetch ulterieur reussit', async () => {
|
||||||
|
mockApiGet.mockRejectedValueOnce(new Error('boom'))
|
||||||
|
const list = usePaginatedList({ url: '/users' })
|
||||||
|
await list.fetch()
|
||||||
|
expect(list.error.value).toBeInstanceOf(Error)
|
||||||
|
|
||||||
|
mockResponse([{ id: 1 }], 1)
|
||||||
|
await list.fetch()
|
||||||
|
expect(list.error.value).toBeNull()
|
||||||
|
expect(list.items.value).toEqual([{ id: 1 }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ignore une reponse periemee : la derniere requete *demandee* gagne', async () => {
|
||||||
|
// Deux fetch concurrents : le 1er resout APRES le 2eme. Sans garde
|
||||||
|
// de sequence, la reponse arrivee en dernier (token 1) ecraserait
|
||||||
|
// les donnees plus fraiches du token 2. Avec la garde, token 2 fait
|
||||||
|
// foi quel que soit l'ordre d'arrivee reseau.
|
||||||
|
const list = usePaginatedList<{ id: number }>({ url: '/users' })
|
||||||
|
|
||||||
|
let resolveSlow!: (v: unknown) => void
|
||||||
|
const slow = new Promise((r) => { resolveSlow = r })
|
||||||
|
// 1er appel : reponse lente (en vol).
|
||||||
|
mockApiGet.mockReturnValueOnce(slow)
|
||||||
|
// 2eme appel : reponse immediate avec des donnees plus fraiches.
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member: [{ id: 2 }], totalItems: 30 })
|
||||||
|
|
||||||
|
const p1 = list.fetch() // token 1, en vol
|
||||||
|
const p2 = list.fetch() // token 2, resout tout de suite
|
||||||
|
await p2
|
||||||
|
expect(list.items.value).toEqual([{ id: 2 }])
|
||||||
|
|
||||||
|
// La reponse lente du token 1 arrive enfin : elle doit etre ignoree.
|
||||||
|
resolveSlow({ member: [{ id: 1 }], totalItems: 30 })
|
||||||
|
await p1
|
||||||
|
expect(list.items.value).toEqual([{ id: 2 }])
|
||||||
|
// Le spinner reste eteint (la requete recente l'avait deja coupe).
|
||||||
|
expect(list.loading.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('extraQuery est injecte a chaque fetch (ex : includeDeleted)', async () => {
|
||||||
|
mockResponse([], 0)
|
||||||
|
const list = usePaginatedList({
|
||||||
|
url: '/categories',
|
||||||
|
extraQuery: { includeDeleted: 'true' },
|
||||||
|
})
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
expect(mockApiGet.mock.calls[0][1]).toMatchObject({ includeDeleted: 'true' })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('valeurs nulles/vides des filtres ne sont pas envoyees', async () => {
|
||||||
|
mockResponse([], 0)
|
||||||
|
const list = usePaginatedList<unknown, { name?: string; q?: string }>({
|
||||||
|
url: '/users',
|
||||||
|
defaultFilters: { name: '', q: undefined } as never,
|
||||||
|
})
|
||||||
|
await list.fetch()
|
||||||
|
|
||||||
|
const q = mockApiGet.mock.calls[0][1] as Record<string, unknown>
|
||||||
|
expect(q.name).toBeUndefined()
|
||||||
|
expect(q.q).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('refresh() est un alias de fetch()', async () => {
|
||||||
|
mockResponse([{ id: 1 }], 1)
|
||||||
|
const list = usePaginatedList<{ id: number }>({ url: '/users' })
|
||||||
|
|
||||||
|
await list.refresh()
|
||||||
|
expect(list.items.value).toEqual([{ id: 1 }])
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,364 @@
|
|||||||
|
import { computed, ref, type Ref } from 'vue'
|
||||||
|
import type { HydraCollection } from '~/shared/utils/api'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composable generique de liste paginee serveur.
|
||||||
|
*
|
||||||
|
* Responsabilites :
|
||||||
|
* - centraliser l'etat tableau (page courante, items/page, tri, filtres,
|
||||||
|
* totalItems, items, loading, error) cote local — JAMAIS dans l'URL,
|
||||||
|
* conformement a la regle ABSOLUE n°6 du CLAUDE.md (« Jamais persister
|
||||||
|
* l'etat de tableau dans l'URL »).
|
||||||
|
* - dialoguer avec une ressource API Platform 4 (Hydra) en passant
|
||||||
|
* `page`, `itemsPerPage` et le tri/filtres en query params.
|
||||||
|
* - exposer une API simple a brancher sur `MalioDataTable`
|
||||||
|
* (props page/perPage/totalItems + events update:page / update:per-page).
|
||||||
|
*
|
||||||
|
* Volontairement **par-instance** (state local a chaque appel) : a la
|
||||||
|
* difference de `useAuditLog` / `useCategoriesAdmin` qui sont des
|
||||||
|
* singletons module-level partages, une liste paginee est propre a son
|
||||||
|
* ecran et ne doit pas etre partagee entre pages (sinon un retour
|
||||||
|
* arriere reprendrait la pagination d'une autre liste).
|
||||||
|
*
|
||||||
|
* Pas de gestion URL : si une page veut un deep link (ex : ouvrir un
|
||||||
|
* detail), elle le fait via sa propre route, pas via la query string
|
||||||
|
* de pagination. Derogation possible uniquement si l'utilisateur le
|
||||||
|
* demande explicitement, cf. CLAUDE.md.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Direction de tri serveur. API Platform 4 attend `asc` ou `desc` via la
|
||||||
|
* syntaxe `?order[field]=asc`.
|
||||||
|
*/
|
||||||
|
export type SortDirection = 'asc' | 'desc'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specification de tri : un seul champ trie a la fois cote front (la
|
||||||
|
* majorite des tableaux Malio n'expose pas le multi-tri). Si null, aucun
|
||||||
|
* `order[...]` n'est envoye et l'API applique son tri par defaut.
|
||||||
|
*/
|
||||||
|
export interface SortSpec {
|
||||||
|
field: string
|
||||||
|
direction: SortDirection
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type des filtres : un dictionnaire de valeurs serialisables en query
|
||||||
|
* params. Le caller decide du mapping (ex : `{ active: true }`,
|
||||||
|
* `{ 'name[ilike]': 'a' }`). Valeurs `null` / `undefined` / chaines vides
|
||||||
|
* sont automatiquement omises au moment de la requete.
|
||||||
|
*/
|
||||||
|
export type PaginatedListFilters = Record<string, string | number | boolean | string[] | null | undefined>
|
||||||
|
|
||||||
|
export interface UsePaginatedListOptions<F extends PaginatedListFilters = PaginatedListFilters> {
|
||||||
|
/** URL relative au prefix `/api` (ex : `/sites`, `/categories`). */
|
||||||
|
url: string
|
||||||
|
/** Items par page initial. Defaut 10 (aligne avec le defaut serveur). */
|
||||||
|
defaultItemsPerPage?: number
|
||||||
|
/** Options proposees dans le selecteur items/page. Defaut [10, 25, 50]. */
|
||||||
|
itemsPerPageOptions?: number[]
|
||||||
|
/** Filtres initiaux. */
|
||||||
|
defaultFilters?: F
|
||||||
|
/** Tri initial. */
|
||||||
|
defaultSort?: SortSpec | null
|
||||||
|
/**
|
||||||
|
* Query params additionnels propres a la ressource (ex : `includeDeleted=true`,
|
||||||
|
* `groups[]=foo`) injectes a chaque requete. **Snapshot statique** : l'objet
|
||||||
|
* est lu tel quel a chaque `fetch()`, ses valeurs ne sont pas deballees. Ne
|
||||||
|
* pas y passer de `ref` / `computed` (elles seraient serialisees comme objet,
|
||||||
|
* pas comme valeur) — pour un extra reactif, muter les filtres via
|
||||||
|
* `setFilters` ou ouvrir un ticket pour un support `MaybeRefOrGetter`.
|
||||||
|
*/
|
||||||
|
extraQuery?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UsePaginatedListReturn<T, F extends PaginatedListFilters = PaginatedListFilters> {
|
||||||
|
/** Items de la page courante. */
|
||||||
|
items: Ref<T[]>
|
||||||
|
/** Total d'items (toutes pages) renvoye par Hydra. */
|
||||||
|
totalItems: Ref<number>
|
||||||
|
/** Page courante (1-based). */
|
||||||
|
currentPage: Ref<number>
|
||||||
|
/** Taille de page courante. */
|
||||||
|
itemsPerPage: Ref<number>
|
||||||
|
/** Options exposees au selecteur items/page. */
|
||||||
|
itemsPerPageOptions: Ref<number[]>
|
||||||
|
/** Nombre total de pages (≥ 1). */
|
||||||
|
totalPages: Ref<number>
|
||||||
|
/** Indicateur de chargement (vrai pendant `fetch()`). */
|
||||||
|
loading: Ref<boolean>
|
||||||
|
/**
|
||||||
|
* Derniere erreur de `fetch()` (null si le dernier appel a abouti).
|
||||||
|
* Permet a la page de distinguer « liste reellement vide » d'un echec
|
||||||
|
* reseau / 403 : sans ca, `isEmpty` confond les deux cas (la liste
|
||||||
|
* tombe a 0 item dans les deux situations). La page decide de l'UX
|
||||||
|
* (bandeau, bouton reessayer) — le composable ne toaste pas.
|
||||||
|
*/
|
||||||
|
error: Ref<unknown | null>
|
||||||
|
/** Vrai apres au moins un fetch reussi avec 0 item. */
|
||||||
|
isEmpty: Ref<boolean>
|
||||||
|
/** Vrai si la collection tient en une seule page (totalPages <= 1). */
|
||||||
|
isSinglePage: Ref<boolean>
|
||||||
|
/** Filtres courants (mutation via `setFilters`). */
|
||||||
|
filters: Ref<F>
|
||||||
|
/** Tri courant (mutation via `setSort`). */
|
||||||
|
sort: Ref<SortSpec | null>
|
||||||
|
/** Lance un fetch contre l'API et met a jour items/totalItems. */
|
||||||
|
fetch: () => Promise<void>
|
||||||
|
/** Va a la page demandee (bornes appliquees : 1 ≤ p ≤ totalPages). */
|
||||||
|
goToPage: (page: number) => Promise<void>
|
||||||
|
/** Page suivante (no-op si deja en derniere page). */
|
||||||
|
nextPage: () => Promise<void>
|
||||||
|
/** Page precedente (no-op si deja en premiere page). */
|
||||||
|
prevPage: () => Promise<void>
|
||||||
|
/** Change la taille de page et revient en page 1. */
|
||||||
|
setItemsPerPage: (value: number) => Promise<void>
|
||||||
|
/** Applique de nouveaux filtres et revient en page 1. */
|
||||||
|
setFilters: (next: Partial<F>, options?: { replace?: boolean }) => Promise<void>
|
||||||
|
/** Change le tri et revient en page 1. */
|
||||||
|
setSort: (next: SortSpec | null) => Promise<void>
|
||||||
|
/** Reinitialise filtres + tri + page sur les valeurs par defaut. */
|
||||||
|
reset: () => Promise<void>
|
||||||
|
/** Alias de `fetch()` (intention plus claire dans certains contextes). */
|
||||||
|
refresh: () => Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force `application/ld+json` : sous `application/json`, API Platform 4
|
||||||
|
* renvoie un tableau plat sans envelope de pagination — on ne pourrait pas
|
||||||
|
* lire `totalItems` ni `view`. Voir aussi `useAuditLog.ts`.
|
||||||
|
*/
|
||||||
|
const JSONLD_HEADERS = { Accept: 'application/ld+json' } as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filtre les entrees nulles/undefined/vides d'un objet de query : evite
|
||||||
|
* d'envoyer `?foo=&bar=null` a l'API qui declencherait parfois des erreurs
|
||||||
|
* de filtre cote Symfony (`FilterInterface::apply` strict).
|
||||||
|
*/
|
||||||
|
function compactQuery(raw: Record<string, unknown>): Record<string, unknown> {
|
||||||
|
const out: Record<string, unknown> = {}
|
||||||
|
for (const [key, value] of Object.entries(raw)) {
|
||||||
|
if (value === null || value === undefined) continue
|
||||||
|
if (typeof value === 'string' && value === '') continue
|
||||||
|
if (Array.isArray(value) && value.length === 0) continue
|
||||||
|
out[key] = value
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePaginatedList<T, F extends PaginatedListFilters = PaginatedListFilters>(
|
||||||
|
options: UsePaginatedListOptions<F>,
|
||||||
|
): UsePaginatedListReturn<T, F> {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const defaultItemsPerPage = options.defaultItemsPerPage ?? 10
|
||||||
|
const initialFilters = { ...(options.defaultFilters ?? ({} as F)) } as F
|
||||||
|
const initialSort = options.defaultSort ?? null
|
||||||
|
|
||||||
|
const items = ref<T[]>([]) as Ref<T[]>
|
||||||
|
const totalItems = ref(0)
|
||||||
|
const currentPage = ref(1)
|
||||||
|
const itemsPerPage = ref(defaultItemsPerPage)
|
||||||
|
const itemsPerPageOptions = ref(options.itemsPerPageOptions ?? [10, 25, 50])
|
||||||
|
const loading = ref(false)
|
||||||
|
const error = ref<unknown | null>(null)
|
||||||
|
// Jeton de sequence : incremente a chaque `fetch()`. Une reponse dont
|
||||||
|
// le jeton n'est plus le dernier est ignoree (protection contre les
|
||||||
|
// reponses periemes quand l'utilisateur enchaine page / tri / filtres
|
||||||
|
// plus vite que le reseau ne repond — sinon la derniere reponse
|
||||||
|
// *arrivee* gagnerait au lieu de la derniere *demandee*).
|
||||||
|
let fetchToken = 0
|
||||||
|
// `hasFetched` evite que `isEmpty` retourne `true` avant le premier
|
||||||
|
// chargement (etat initial = 0 items mais on ne sait pas encore si la
|
||||||
|
// ressource est vide ou en cours de chargement). Un appel reseau au
|
||||||
|
// moins doit avoir abouti pour qu'on annonce une liste « vide ».
|
||||||
|
const hasFetched = ref(false)
|
||||||
|
const filters = ref({ ...initialFilters }) as Ref<F>
|
||||||
|
const sort = ref<SortSpec | null>(initialSort ? { ...initialSort } : null)
|
||||||
|
|
||||||
|
const totalPages = computed(() => {
|
||||||
|
if (totalItems.value <= 0 || itemsPerPage.value <= 0) return 1
|
||||||
|
return Math.max(1, Math.ceil(totalItems.value / itemsPerPage.value))
|
||||||
|
})
|
||||||
|
const isEmpty = computed(() => hasFetched.value && totalItems.value === 0)
|
||||||
|
const isSinglePage = computed(() => totalPages.value <= 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit l'objet query envoye a l'API : extras + filtres, puis
|
||||||
|
* pagination + tri. Les cles reservees (`page`, `itemsPerPage`,
|
||||||
|
* `order[...]`) sont assignees **en dernier** pour qu'un filtre ou un
|
||||||
|
* extra portant le meme nom ne puisse pas ecraser silencieusement la
|
||||||
|
* pagination. Les filtres `null`/`undefined`/'' sont elimines pour ne
|
||||||
|
* pas polluer l'URL.
|
||||||
|
*/
|
||||||
|
function buildQuery(): Record<string, unknown> {
|
||||||
|
const query: Record<string, unknown> = {}
|
||||||
|
if (options.extraQuery) {
|
||||||
|
Object.assign(query, options.extraQuery)
|
||||||
|
}
|
||||||
|
Object.assign(query, filters.value)
|
||||||
|
// Cles reservees en dernier : priorite a la pagination/au tri.
|
||||||
|
query.page = currentPage.value
|
||||||
|
query.itemsPerPage = itemsPerPage.value
|
||||||
|
if (sort.value) {
|
||||||
|
// Format API Platform : ?order[field]=asc
|
||||||
|
query[`order[${sort.value.field}]`] = sort.value.direction
|
||||||
|
}
|
||||||
|
return compactQuery(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lance un fetch et applique la borne haute si necessaire. Si la page
|
||||||
|
* courante depasse `totalPages` apres l'application des filtres (cas
|
||||||
|
* « j'etais en page 5, je filtre, il ne reste qu'une page »), on
|
||||||
|
* rappelle l'API sur la derniere page valide. Un seul niveau de retry
|
||||||
|
* pour eviter une boucle si l'API renvoie des resultats incoherents.
|
||||||
|
*/
|
||||||
|
async function fetch(): Promise<void> {
|
||||||
|
const token = ++fetchToken
|
||||||
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
|
try {
|
||||||
|
const data = await api.get<HydraCollection<T>>(
|
||||||
|
options.url,
|
||||||
|
buildQuery(),
|
||||||
|
{ toast: false, headers: JSONLD_HEADERS },
|
||||||
|
)
|
||||||
|
// Une requete plus recente a ete lancee entre-temps : on jette
|
||||||
|
// cette reponse pour ne pas ecraser des donnees plus fraiches.
|
||||||
|
if (token !== fetchToken) return
|
||||||
|
items.value = data.member ?? []
|
||||||
|
totalItems.value = data.totalItems ?? 0
|
||||||
|
|
||||||
|
const tp = totalItems.value > 0
|
||||||
|
? Math.max(1, Math.ceil(totalItems.value / itemsPerPage.value))
|
||||||
|
: 1
|
||||||
|
|
||||||
|
// Si on est hors borne ET qu'il y a au moins une page valide
|
||||||
|
// a viser, on retombe sur la derniere page (cf. cas limite
|
||||||
|
// « page hors borne apres filtre » de la spec #73). On ne
|
||||||
|
// refetch que si la nouvelle page est differente, sinon
|
||||||
|
// boucle infinie potentielle.
|
||||||
|
if (currentPage.value > tp && tp >= 1 && totalItems.value > 0) {
|
||||||
|
currentPage.value = tp
|
||||||
|
const data2 = await api.get<HydraCollection<T>>(
|
||||||
|
options.url,
|
||||||
|
buildQuery(),
|
||||||
|
{ toast: false, headers: JSONLD_HEADERS },
|
||||||
|
)
|
||||||
|
// Meme garde apres le refetch hors-borne.
|
||||||
|
if (token !== fetchToken) return
|
||||||
|
items.value = data2.member ?? []
|
||||||
|
totalItems.value = data2.totalItems ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
hasFetched.value = true
|
||||||
|
} catch (e) {
|
||||||
|
// Reponse periemee : ne pas toucher au state, une requete plus
|
||||||
|
// recente est en cours et fera foi.
|
||||||
|
if (token !== fetchToken) return
|
||||||
|
// Swallow volontaire : on remet la liste a vide pour ne pas
|
||||||
|
// afficher de donnees stale, et on expose l'erreur pour que la
|
||||||
|
// page distingue « vide » d'« echec ». Le composant parent
|
||||||
|
// decide de l'UX (toast / message d'erreur) — pas d'a-priori ici.
|
||||||
|
error.value = e
|
||||||
|
items.value = []
|
||||||
|
totalItems.value = 0
|
||||||
|
hasFetched.value = true
|
||||||
|
} finally {
|
||||||
|
// Seule la requete la plus recente eteint le spinner : une
|
||||||
|
// reponse periemee ne doit pas le couper alors qu'un fetch plus
|
||||||
|
// recent est encore en vol.
|
||||||
|
if (token === fetchToken) loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function goToPage(page: number): Promise<void> {
|
||||||
|
const tp = totalPages.value
|
||||||
|
const next = Math.max(1, Math.min(page, tp))
|
||||||
|
if (next === currentPage.value) return
|
||||||
|
currentPage.value = next
|
||||||
|
await fetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function nextPage(): Promise<void> {
|
||||||
|
if (currentPage.value >= totalPages.value) return
|
||||||
|
await goToPage(currentPage.value + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prevPage(): Promise<void> {
|
||||||
|
if (currentPage.value <= 1) return
|
||||||
|
await goToPage(currentPage.value - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setItemsPerPage(value: number): Promise<void> {
|
||||||
|
if (!Number.isFinite(value) || value <= 0) return
|
||||||
|
const rounded = Math.floor(value)
|
||||||
|
if (rounded === itemsPerPage.value) return
|
||||||
|
itemsPerPage.value = rounded
|
||||||
|
currentPage.value = 1
|
||||||
|
await fetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `replace: false` (defaut) fusionne avec les filtres courants. Une
|
||||||
|
* valeur explicitement `undefined` retire la cle (utile pour effacer
|
||||||
|
* un filtre depuis un champ controle). `replace: true` remplace
|
||||||
|
* integralement l'objet par `next`.
|
||||||
|
*/
|
||||||
|
async function setFilters(next: Partial<F>, opts?: { replace?: boolean }): Promise<void> {
|
||||||
|
if (opts?.replace) {
|
||||||
|
filters.value = { ...(next as F) }
|
||||||
|
} else {
|
||||||
|
const merged = { ...filters.value, ...next } as F
|
||||||
|
// Supprime les cles explicitement passees a undefined : sans ce
|
||||||
|
// nettoyage, l'objet `filters` accumulerait des cles fantomes.
|
||||||
|
for (const key of Object.keys(next)) {
|
||||||
|
if (next[key as keyof F] === undefined) {
|
||||||
|
delete (merged as Record<string, unknown>)[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filters.value = merged
|
||||||
|
}
|
||||||
|
currentPage.value = 1
|
||||||
|
await fetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setSort(next: SortSpec | null): Promise<void> {
|
||||||
|
sort.value = next ? { ...next } : null
|
||||||
|
currentPage.value = 1
|
||||||
|
await fetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reset(): Promise<void> {
|
||||||
|
filters.value = { ...initialFilters }
|
||||||
|
sort.value = initialSort ? { ...initialSort } : null
|
||||||
|
itemsPerPage.value = defaultItemsPerPage
|
||||||
|
currentPage.value = 1
|
||||||
|
await fetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
items,
|
||||||
|
totalItems,
|
||||||
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
itemsPerPageOptions,
|
||||||
|
totalPages,
|
||||||
|
loading,
|
||||||
|
error,
|
||||||
|
isEmpty,
|
||||||
|
isSinglePage,
|
||||||
|
filters,
|
||||||
|
sort,
|
||||||
|
fetch,
|
||||||
|
goToPage,
|
||||||
|
nextPage,
|
||||||
|
prevPage,
|
||||||
|
setItemsPerPage,
|
||||||
|
setFilters,
|
||||||
|
setSort,
|
||||||
|
reset,
|
||||||
|
refresh: fetch,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,6 +65,16 @@ export const personas: Record<PersonaKey, Persona> = {
|
|||||||
'sites.bypass_scope',
|
'sites.bypass_scope',
|
||||||
'catalog.categories.view',
|
'catalog.categories.view',
|
||||||
'catalog.categories.manage',
|
'catalog.categories.manage',
|
||||||
|
// Commercial — Repertoire clients (M1). Mappe ici sur le persona
|
||||||
|
// "tout" en attendant les vrais roles metier (bureau/compta/
|
||||||
|
// commerciale/usine) seedes par ERP-74. Pas de nouveau persona
|
||||||
|
// (regle ABSOLUE n°7). commercial.clients.view n'ajoute pas de lien
|
||||||
|
// dans la section Administration, donc expectedAdminLinks reste inchange.
|
||||||
|
'commercial.clients.view',
|
||||||
|
'commercial.clients.manage',
|
||||||
|
'commercial.clients.accounting.view',
|
||||||
|
'commercial.clients.accounting.manage',
|
||||||
|
'commercial.clients.archive',
|
||||||
],
|
],
|
||||||
expectedAdminLinks: ['users', 'roles', 'sites', 'categories', 'audit-log'],
|
expectedAdminLinks: ['users', 'roles', 'sites', 'categories', 'audit-log'],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -198,15 +198,19 @@ migration-migrate:
|
|||||||
# doctrine:fixtures:load essaie de DELETE toutes les tables connues
|
# doctrine:fixtures:load essaie de DELETE toutes les tables connues
|
||||||
# via les mappings — si fake_site_aware_entity est mappe mais absent
|
# via les mappings — si fake_site_aware_entity est mappe mais absent
|
||||||
# en DB, le purger crash.
|
# en DB, le purger crash.
|
||||||
# 3. fixtures -> sync-permissions : fixtures:load purge la table permission,
|
# 3. fixtures -> sync-permissions -> seed-rbac : fixtures:load purge la table
|
||||||
# donc sync doit passer apres.
|
# permission, donc sync doit passer apres. seed-rbac (matrice RBAC § 2.7)
|
||||||
# 4. recreation index `uq_category_name_type_active` : schema:update drop
|
# passe ensuite, car attachMatrix() exige les permissions en base. Les
|
||||||
# les index orphelins du mapping ORM. L'index partiel (LOWER + WHERE) du
|
# comptes demo sont crees par RbacDemoFixtures au load (sans la matrice,
|
||||||
# M0 Catalog n'est pas exprimable via les attributs Doctrine ORM 3
|
# attachee ici). Cf. ERP-74.
|
||||||
# (fonctionnel + partiel), donc il disparait apres schema:update. On le
|
# 4. recreation des index partiels uniques : schema:update drop les index
|
||||||
# recree par dbal:run-sql pour que les tests RG-1.07 (unicite
|
# orphelins du mapping ORM. Les index partiels (LOWER + WHERE) ne sont pas
|
||||||
# case-insensitive) voient bien la contrainte SQL. Sans ce restore, les
|
# exprimables via les attributs Doctrine ORM (fonctionnel + partiel), donc
|
||||||
# POST doublons remontent 201 au lieu de 409.
|
# ils disparaissent apres schema:update. On les recree par dbal:run-sql :
|
||||||
|
# - `uq_category_name_type_active` (M0 Catalog) : tests RG-1.07.
|
||||||
|
# - `uq_client_company_name_active` (M1 Commercial) : unicite nom societe
|
||||||
|
# parmi actifs non archives/non supprimes (RG-1.16), tests ERP-55.
|
||||||
|
# Sans ces restores, les POST doublons remontent 201 au lieu de 409.
|
||||||
# 5. app:apply-column-comments : meme cause, schema:update drop les COMMENT
|
# 5. app:apply-column-comments : meme cause, schema:update drop les COMMENT
|
||||||
# ON COLUMN/TABLE des tables managees par l'ORM (le mapping PHP ne porte
|
# ON COLUMN/TABLE des tables managees par l'ORM (le mapping PHP ne porte
|
||||||
# pas d'attribut options['comment']). On rejoue le catalogue partage
|
# pas d'attribut options['comment']). On rejoue le catalogue partage
|
||||||
@@ -219,7 +223,9 @@ test-db-setup:
|
|||||||
$(SYMFONY_CONSOLE) --env=test --no-interaction app:apply-column-comments
|
$(SYMFONY_CONSOLE) --env=test --no-interaction app:apply-column-comments
|
||||||
$(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 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_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_client_company_name_active ON client (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
|
||||||
@@ -229,6 +235,15 @@ fixtures:
|
|||||||
sync-permissions:
|
sync-permissions:
|
||||||
$(SYMFONY_CONSOLE) --no-interaction app:sync-permissions
|
$(SYMFONY_CONSOLE) --no-interaction app:sync-permissions
|
||||||
|
|
||||||
|
# Seed RBAC metier : roles (bureau/compta/commerciale/usine) + matrice § 2.7
|
||||||
|
# (+ comptes demo en dev). Idempotent et NON destructif. A lancer APRES
|
||||||
|
# sync-permissions (attachMatrix exige les permissions en base). Les comptes
|
||||||
|
# demo dev sont deja crees par RbacDemoFixtures (make fixtures) ; ici on attache
|
||||||
|
# la matrice (les permissions etaient purgees au moment du load fixtures).
|
||||||
|
# En recette/prod, c'est cette commande (avec/sans --with-demo-users) qui seede.
|
||||||
|
seed-rbac:
|
||||||
|
$(SYMFONY_CONSOLE) --no-interaction app:seed-rbac
|
||||||
|
|
||||||
# Attention, supprime votre bdd local
|
# Attention, supprime votre bdd local
|
||||||
db-reset:
|
db-reset:
|
||||||
$(DOCKER_COMPOSE) down -v
|
$(DOCKER_COMPOSE) down -v
|
||||||
@@ -238,6 +253,7 @@ db-reset:
|
|||||||
$(MAKE) migration-migrate
|
$(MAKE) migration-migrate
|
||||||
$(MAKE) fixtures
|
$(MAKE) fixtures
|
||||||
$(MAKE) sync-permissions
|
$(MAKE) sync-permissions
|
||||||
|
$(MAKE) seed-rbac
|
||||||
$(MAKE) test-db-setup
|
$(MAKE) test-db-setup
|
||||||
|
|
||||||
# Restart la bdd
|
# Restart la bdd
|
||||||
|
|||||||
@@ -39,7 +39,19 @@ final class Version20260528120000 extends AbstractMigration
|
|||||||
|
|
||||||
public function up(Schema $schema): void
|
public function up(Schema $schema): void
|
||||||
{
|
{
|
||||||
foreach (ColumnCommentsCatalog::toSqlStatements() as $sql) {
|
// Ne commente que les tables deja presentes a ce stade de la chaine de
|
||||||
|
// migrations. Les modules crees plus tard (ex: M1 Commercial, 06-01)
|
||||||
|
// figurent desormais dans le catalogue partage mais leurs tables
|
||||||
|
// n'existent pas encore ici : elles posent leurs propres COMMENT dans
|
||||||
|
// leur migration dediee (regle ABSOLUE n°12). Garde-fou indispensable,
|
||||||
|
// sinon l'ajout d'un module au catalogue casse ce retrofit avec un
|
||||||
|
// "relation X does not exist".
|
||||||
|
$existingTables = array_values(array_filter(
|
||||||
|
array_keys(ColumnCommentsCatalog::comments()),
|
||||||
|
static fn (string $table): bool => $schema->hasTable($table),
|
||||||
|
));
|
||||||
|
|
||||||
|
foreach (ColumnCommentsCatalog::toSqlStatements($existingTables) as $sql) {
|
||||||
$this->addSql($sql);
|
$this->addSql($sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +59,13 @@ final class Version20260528120000 extends AbstractMigration
|
|||||||
public function down(Schema $schema): void
|
public function down(Schema $schema): void
|
||||||
{
|
{
|
||||||
foreach (ColumnCommentsCatalog::comments() as $table => $entries) {
|
foreach (ColumnCommentsCatalog::comments() as $table => $entries) {
|
||||||
|
// Symetrie avec up() : on n'efface que les commentaires des tables
|
||||||
|
// presentes (les tables des modules ulterieurs sont gerees par leur
|
||||||
|
// propre migration).
|
||||||
|
if (!$schema->hasTable($table)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
||||||
foreach ($entries as $column => $_) {
|
foreach ($entries as $column => $_) {
|
||||||
if ('_table' === $column) {
|
if ('_table' === $column) {
|
||||||
|
|||||||
@@ -0,0 +1,554 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use App\Shared\Infrastructure\Database\ColumnCommentsCatalog;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* M1 — Repertoire clients (ERP-53) : creation de toute la structure BDD du
|
||||||
|
* module Commercial (clients + sous-collections + referentiels comptables).
|
||||||
|
*
|
||||||
|
* Tables creees :
|
||||||
|
* - Referentiels comptables (statiques, seedes ici) : tva_mode, payment_delay,
|
||||||
|
* payment_type, bank.
|
||||||
|
* - Table principale : client (formulaire + Information + Comptabilite +
|
||||||
|
* archive + soft-delete + Timestampable/Blamable).
|
||||||
|
* - Sous-collections : client_category (M2M), client_contact (1:n),
|
||||||
|
* client_address (1:n), client_rib (1:n).
|
||||||
|
* - Jointures de client_address : client_address_site, client_address_contact,
|
||||||
|
* client_address_category.
|
||||||
|
*
|
||||||
|
* Seed `category_type` (extension M0) : DISTRIBUTEUR / COURTIER / SECTEUR /
|
||||||
|
* AUTRE, en `ON CONFLICT (code) DO NOTHING` (idempotent — la table peut deja
|
||||||
|
* porter des donnees en prod). En dev/test, les fixtures purgent et re-seedent
|
||||||
|
* ces 4 types (cf. CategoryTypeFixtures) ; ce seed migration couvre la prod ou
|
||||||
|
* les fixtures ne tournent pas.
|
||||||
|
*
|
||||||
|
* Namespace racine `DoctrineMigrations` (regle ABSOLUE Starseed n°11) et NON
|
||||||
|
* `App\Module\Commercial\...` : avec plusieurs migrations_paths, Doctrine
|
||||||
|
* Migrations 3.x trie par FQCN alphabetique (AlphabeticalComparator → strcmp).
|
||||||
|
* Un namespace `App\Module\Commercial\...` trierait AVANT `DoctrineMigrations\...`
|
||||||
|
* et la migration s'executerait avant la creation de user/category/site sur
|
||||||
|
* base vide → echec des FK. Le namespace racine garantit l'ordre par timestamp.
|
||||||
|
*
|
||||||
|
* Style DDL aligne sur la migration M0 (Version20260527164000) plutot que sur
|
||||||
|
* le pseudo-SQL de la spec § 3.2 : `INT GENERATED BY DEFAULT AS IDENTITY` (et
|
||||||
|
* non SERIAL), `TIMESTAMP(0) WITHOUT TIME ZONE` (et non TIMESTAMPTZ, car le
|
||||||
|
* `TimestampableBlamableTrait` mappe `datetime_immutable`). Garantit que
|
||||||
|
* `schema:update` restera un no-op quand les entites arriveront (ticket ERP-54).
|
||||||
|
*
|
||||||
|
* Decision Q4 (29/05/2026) : unicite metier sur le NOM DE SOCIETE uniquement.
|
||||||
|
* Pas d'index unique sur siren ni email (RG-1.15 / RG-1.17 supprimees).
|
||||||
|
*
|
||||||
|
* Chaque colonne porte un `COMMENT ON COLUMN` (regle ABSOLUE n°12, garde-fou
|
||||||
|
* ColumnsHaveSqlCommentTest). Les tables n'etant pas encore mappees par l'ORM,
|
||||||
|
* ces commentaires survivent au `schema:update --force` du setup de test.
|
||||||
|
*/
|
||||||
|
final class Version20260601000000 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'ERP-53 (M1) : tables client + sous-collections + referentiels comptables + seed category_type.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->createAccountingReferentials();
|
||||||
|
$this->createClientTable();
|
||||||
|
$this->createClientCategory();
|
||||||
|
$this->createClientContact();
|
||||||
|
$this->createClientAddress();
|
||||||
|
$this->createClientAddressJoinTables();
|
||||||
|
$this->createClientRib();
|
||||||
|
$this->seedCategoryTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// Ordre inverse des dependances FK : on supprime d'abord les jointures
|
||||||
|
// et sous-collections, puis client, puis les referentiels.
|
||||||
|
$this->addSql('DROP TABLE client_address_category');
|
||||||
|
$this->addSql('DROP TABLE client_address_contact');
|
||||||
|
$this->addSql('DROP TABLE client_address_site');
|
||||||
|
$this->addSql('DROP TABLE client_rib');
|
||||||
|
$this->addSql('DROP TABLE client_address');
|
||||||
|
$this->addSql('DROP TABLE client_contact');
|
||||||
|
$this->addSql('DROP TABLE client_category');
|
||||||
|
$this->addSql('DROP TABLE client');
|
||||||
|
$this->addSql('DROP TABLE bank');
|
||||||
|
$this->addSql('DROP TABLE payment_type');
|
||||||
|
$this->addSql('DROP TABLE payment_delay');
|
||||||
|
$this->addSql('DROP TABLE tva_mode');
|
||||||
|
|
||||||
|
// Retire uniquement les 4 types seedes par cette migration ET restes
|
||||||
|
// orphelins (aucune `category` ne les reference). Sans la clause
|
||||||
|
// NOT EXISTS, le DELETE casse sur la FK RESTRICT category.category_type_id
|
||||||
|
// des qu'une categorie pointe sur l'un d'eux. Symetrique du
|
||||||
|
// `ON CONFLICT (code) DO NOTHING` du up() : on ne defait que ce qu'on a
|
||||||
|
// reellement cree et qui n'est pas reutilise.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DELETE FROM category_type
|
||||||
|
WHERE code IN ('DISTRIBUTEUR', 'COURTIER', 'SECTEUR', 'AUTRE')
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM category c WHERE c.category_type_id = category_type.id
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Referentiels comptables (4 tables statiques, memes colonnes)
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function createAccountingReferentials(): void
|
||||||
|
{
|
||||||
|
$referentials = [
|
||||||
|
'tva_mode' => 'Referentiel des modes de TVA appliques a un client (France, Export, Intracom).',
|
||||||
|
'payment_delay' => 'Referentiel des delais de reglement (15 jours, 30 jours, a reception).',
|
||||||
|
'payment_type' => 'Referentiel des types de reglement (virement, LCR, cheque, non soumise).',
|
||||||
|
'bank' => 'Referentiel des banques selectionnables pour le reglement par virement.',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($referentials as $table => $tableComment) {
|
||||||
|
$this->addSql(sprintf(<<<'SQL'
|
||||||
|
CREATE TABLE %s (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
code VARCHAR(30) NOT NULL,
|
||||||
|
label VARCHAR(120) NOT NULL,
|
||||||
|
position INT DEFAULT 0 NOT NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
)
|
||||||
|
SQL, $table));
|
||||||
|
$this->addSql(sprintf('CREATE UNIQUE INDEX uq_%s_code ON %s (code)', $table, $table));
|
||||||
|
|
||||||
|
$this->comment($table, '_table', $tableComment);
|
||||||
|
$this->comment($table, 'id', 'Identifiant interne auto-incremente.');
|
||||||
|
$this->comment($table, 'code', 'Code technique stable (UPPER_SNAKE, ≤ 30 caracteres) — unique, utilise par le code metier.');
|
||||||
|
$this->comment($table, 'label', 'Libelle affichable (FR, ≤ 120 caracteres).');
|
||||||
|
$this->comment($table, 'position', 'Ordre d affichage croissant dans les selecteurs (tri position ASC puis label ASC).');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seed initial (cf. spec § 3.2). Tables fraichement creees donc vides :
|
||||||
|
// INSERT direct sans ON CONFLICT.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO tva_mode (code, label, position) VALUES
|
||||||
|
('FRANCE_VENTES', 'France (ventes)', 10),
|
||||||
|
('EXPORT_VENTES', 'Export (ventes)', 20),
|
||||||
|
('INTRACOM_VENTES', 'Intracom (ventes)', 30)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO payment_delay (code, label, position) VALUES
|
||||||
|
('J15', '15 jours', 10),
|
||||||
|
('J30', '30 jours', 20),
|
||||||
|
('A_RECEPTION', 'À réception', 30)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO payment_type (code, label, position) VALUES
|
||||||
|
('VIREMENT', 'Virement', 10),
|
||||||
|
('LCR', 'LCR', 20),
|
||||||
|
('NON_SOUMISE', 'Non soumise', 30),
|
||||||
|
('CHEQUE', 'Chèque', 40)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO bank (code, label, position) VALUES
|
||||||
|
('SG', 'Société Générale', 10),
|
||||||
|
('CIC', 'CIC', 20),
|
||||||
|
('CA', 'Crédit Agricole', 30)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Table principale `client`
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function createClientTable(): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
company_name VARCHAR(180) NOT NULL,
|
||||||
|
first_name VARCHAR(120) DEFAULT NULL,
|
||||||
|
last_name VARCHAR(120) DEFAULT NULL,
|
||||||
|
phone_primary VARCHAR(20) NOT NULL,
|
||||||
|
phone_secondary VARCHAR(20) DEFAULT NULL,
|
||||||
|
email VARCHAR(180) NOT NULL,
|
||||||
|
distributor_id INT DEFAULT NULL,
|
||||||
|
broker_id INT DEFAULT NULL,
|
||||||
|
triage_service BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
|
description TEXT DEFAULT NULL,
|
||||||
|
competitors VARCHAR(255) DEFAULT NULL,
|
||||||
|
founded_at DATE DEFAULT NULL,
|
||||||
|
employees_count INT DEFAULT NULL,
|
||||||
|
revenue_amount NUMERIC(15, 2) DEFAULT NULL,
|
||||||
|
director_name VARCHAR(120) DEFAULT NULL,
|
||||||
|
profit_amount NUMERIC(15, 2) DEFAULT NULL,
|
||||||
|
siren VARCHAR(20) DEFAULT NULL,
|
||||||
|
account_number VARCHAR(40) DEFAULT NULL,
|
||||||
|
tva_mode_id INT DEFAULT NULL,
|
||||||
|
n_tva VARCHAR(40) DEFAULT NULL,
|
||||||
|
payment_delay_id INT DEFAULT NULL,
|
||||||
|
payment_type_id INT DEFAULT NULL,
|
||||||
|
bank_id INT DEFAULT NULL,
|
||||||
|
is_archived BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
|
archived_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
|
||||||
|
deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
|
||||||
|
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
created_by INT DEFAULT NULL,
|
||||||
|
updated_by INT DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
CONSTRAINT chk_client_distrib_or_broker
|
||||||
|
CHECK (NOT (distributor_id IS NOT NULL AND broker_id IS NOT NULL)),
|
||||||
|
CONSTRAINT fk_client_distributor
|
||||||
|
FOREIGN KEY (distributor_id) REFERENCES client (id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_client_broker
|
||||||
|
FOREIGN KEY (broker_id) REFERENCES client (id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_client_tva_mode
|
||||||
|
FOREIGN KEY (tva_mode_id) REFERENCES tva_mode (id) ON DELETE RESTRICT,
|
||||||
|
CONSTRAINT fk_client_payment_delay
|
||||||
|
FOREIGN KEY (payment_delay_id) REFERENCES payment_delay (id) ON DELETE RESTRICT,
|
||||||
|
CONSTRAINT fk_client_payment_type
|
||||||
|
FOREIGN KEY (payment_type_id) REFERENCES payment_type (id) ON DELETE RESTRICT,
|
||||||
|
CONSTRAINT fk_client_bank
|
||||||
|
FOREIGN KEY (bank_id) REFERENCES bank (id) ON DELETE RESTRICT,
|
||||||
|
CONSTRAINT fk_client_created_by
|
||||||
|
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_client_updated_by
|
||||||
|
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->addSql('CREATE INDEX idx_client_is_archived ON client (is_archived)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_deleted_at ON client (deleted_at)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_distributor_id ON client (distributor_id)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_broker_id ON client (broker_id)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_created_by ON client (created_by)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_updated_by ON client (updated_by)');
|
||||||
|
|
||||||
|
// Index sur les FK des referentiels comptables — coherence avec les autres
|
||||||
|
// FK deja indexees ci-dessus (Postgres n'indexe pas automatiquement les
|
||||||
|
// colonnes portant une FOREIGN KEY).
|
||||||
|
$this->addSql('CREATE INDEX idx_client_tva_mode_id ON client (tva_mode_id)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_payment_delay_id ON client (payment_delay_id)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_payment_type_id ON client (payment_type_id)');
|
||||||
|
$this->addSql('CREATE INDEX idx_client_bank_id ON client (bank_id)');
|
||||||
|
|
||||||
|
// Unicite metier partielle (Q4) : nom de societe insensible a la casse,
|
||||||
|
// parmi les non-archives ET non soft-deletes uniquement. Pas d'index
|
||||||
|
// unique sur siren ni email.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE UNIQUE INDEX uq_client_company_name_active
|
||||||
|
ON client (LOWER(company_name))
|
||||||
|
WHERE is_archived = FALSE AND deleted_at IS NULL
|
||||||
|
SQL);
|
||||||
|
|
||||||
|
$this->comment('client', '_table', 'Repertoire clients (M1 Commercial) — entites archivables (is_archived) et soft-deletables (deleted_at, HP M2).');
|
||||||
|
$this->comment('client', 'id', 'Identifiant interne auto-incremente.');
|
||||||
|
$this->comment('client', 'company_name', 'Raison sociale (stockee en MAJUSCULES, RG-1.18). Unique case-insensitive parmi les actifs non archives/non supprimes (RG-1.16, uq_client_company_name_active).');
|
||||||
|
$this->comment('client', 'first_name', 'Prenom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).');
|
||||||
|
$this->comment('client', 'last_name', 'Nom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).');
|
||||||
|
$this->comment('client', 'phone_primary', 'Telephone principal — stocke en chiffres uniquement (RG-1.20). Obligatoire.');
|
||||||
|
$this->comment('client', 'phone_secondary', 'Telephone secondaire optionnel — chiffres uniquement (RG-1.20).');
|
||||||
|
$this->comment('client', 'email', 'Email principal (lowercase serveur, RG-1.21). NON unique (RG-1.17 supprimee, Q4).');
|
||||||
|
$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', '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', 'competitors', 'Onglet Information : concurrents identifies (texte libre ≤ 255). Obligatoire role Commerciale (RG-1.04).');
|
||||||
|
$this->comment('client', 'founded_at', 'Onglet Information : date de creation de l entreprise. Obligatoire role Commerciale (RG-1.04).');
|
||||||
|
$this->comment('client', 'employees_count', 'Onglet Information : effectif (entier >= 0). Obligatoire role Commerciale (RG-1.04).');
|
||||||
|
$this->comment('client', 'revenue_amount', 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).');
|
||||||
|
$this->comment('client', 'director_name', 'Onglet Information : nom du dirigeant. Obligatoire role Commerciale (RG-1.04).');
|
||||||
|
$this->comment('client', 'profit_amount', 'Onglet Information : resultat / benefice (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).');
|
||||||
|
$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', 'tva_mode_id', 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id, ON DELETE RESTRICT.');
|
||||||
|
$this->comment('client', 'n_tva', 'Onglet Comptabilite : numero de TVA intracommunautaire.');
|
||||||
|
$this->comment('client', 'payment_delay_id', 'Onglet Comptabilite : delai de reglement — FK -> payment_delay.id, ON DELETE RESTRICT.');
|
||||||
|
$this->comment('client', 'payment_type_id', 'Onglet Comptabilite : type de reglement — FK -> payment_type.id, ON DELETE RESTRICT. Code LCR impose >= 1 RIB (RG-1.13), VIREMENT impose une banque (RG-1.12).');
|
||||||
|
$this->comment('client', 'bank_id', 'Onglet Comptabilite : banque — FK -> bank.id, ON DELETE RESTRICT. Obligatoire si payment_type = VIREMENT (RG-1.12).');
|
||||||
|
$this->comment('client', 'is_archived', 'Drapeau fonctionnel d archivage — masque par defaut dans la liste. Bascule via permission commercial.clients.archive (RG-1.22/23).');
|
||||||
|
$this->comment('client', 'archived_at', 'Horodatage de l archivage — pose quand is_archived passe a vrai, remis a null a la restauration (RG-1.22/23).');
|
||||||
|
$this->comment('client', 'deleted_at', 'Horodatage du soft-delete technique (HP M2) — non expose par l API au M1. Null = ligne active.');
|
||||||
|
$this->addTimestampableBlamableComments('client');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// M2M client <-> category
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function createClientCategory(): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client_category (
|
||||||
|
client_id INT NOT NULL,
|
||||||
|
category_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (client_id, category_id),
|
||||||
|
CONSTRAINT fk_client_category_client
|
||||||
|
FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_client_category_category
|
||||||
|
FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE RESTRICT
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->addSql('CREATE INDEX idx_client_category_category ON client_category (category_id)');
|
||||||
|
|
||||||
|
$this->comment('client_category', '_table', 'Jointure M2M client <-> category (Catalog) — categories metier du client (au moins une obligatoire).');
|
||||||
|
$this->comment('client_category', 'client_id', 'FK -> client.id, ON DELETE CASCADE — client porteur de la categorie.');
|
||||||
|
$this->comment('client_category', 'category_id', 'FK -> category.id, ON DELETE RESTRICT — categorie rattachee au client.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Sous-collection : contacts (1:n)
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function createClientContact(): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client_contact (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
client_id INT NOT NULL,
|
||||||
|
first_name VARCHAR(120) DEFAULT NULL,
|
||||||
|
last_name VARCHAR(120) DEFAULT NULL,
|
||||||
|
job_title VARCHAR(120) DEFAULT NULL,
|
||||||
|
phone_primary VARCHAR(20) DEFAULT NULL,
|
||||||
|
phone_secondary VARCHAR(20) DEFAULT NULL,
|
||||||
|
email VARCHAR(180) DEFAULT NULL,
|
||||||
|
position INT DEFAULT 0 NOT NULL,
|
||||||
|
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
created_by INT DEFAULT NULL,
|
||||||
|
updated_by INT DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
CONSTRAINT chk_client_contact_name
|
||||||
|
CHECK (first_name IS NOT NULL OR last_name IS NOT NULL),
|
||||||
|
CONSTRAINT fk_client_contact_client
|
||||||
|
FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_client_contact_created_by
|
||||||
|
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_client_contact_updated_by
|
||||||
|
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->addSql('CREATE INDEX idx_client_contact_client ON client_contact (client_id)');
|
||||||
|
|
||||||
|
$this->comment('client_contact', '_table', 'Contacts d un client (1:n) — au moins firstName OU lastName par contact (RG-1.05).');
|
||||||
|
$this->comment('client_contact', 'id', 'Identifiant interne auto-incremente.');
|
||||||
|
$this->comment('client_contact', 'client_id', 'FK -> client.id, ON DELETE CASCADE — client proprietaire du contact.');
|
||||||
|
$this->comment('client_contact', 'first_name', 'Prenom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-1.05, chk_client_contact_name).');
|
||||||
|
$this->comment('client_contact', 'last_name', 'Nom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-1.05, chk_client_contact_name).');
|
||||||
|
$this->comment('client_contact', 'job_title', 'Fonction / intitule de poste du contact (≤ 120 caracteres).');
|
||||||
|
$this->comment('client_contact', 'phone_primary', 'Telephone principal du contact — chiffres uniquement (RG-1.20).');
|
||||||
|
$this->comment('client_contact', 'phone_secondary', 'Telephone secondaire du contact — chiffres uniquement (RG-1.20).');
|
||||||
|
$this->comment('client_contact', 'email', 'Email du contact (lowercase serveur, RG-1.21).');
|
||||||
|
$this->comment('client_contact', 'position', 'Ordre d affichage du contact dans la liste du client (croissant).');
|
||||||
|
$this->addTimestampableBlamableComments('client_contact');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Sous-collection : adresses (1:n)
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function createClientAddress(): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client_address (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
client_id INT NOT NULL,
|
||||||
|
is_prospect BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
|
is_delivery BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
|
is_billing BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
|
country VARCHAR(80) DEFAULT 'France' NOT NULL,
|
||||||
|
postal_code VARCHAR(20) NOT NULL,
|
||||||
|
city VARCHAR(120) NOT NULL,
|
||||||
|
street VARCHAR(255) NOT NULL,
|
||||||
|
street_complement VARCHAR(255) DEFAULT NULL,
|
||||||
|
billing_email VARCHAR(180) DEFAULT NULL,
|
||||||
|
position INT DEFAULT 0 NOT NULL,
|
||||||
|
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
created_by INT DEFAULT NULL,
|
||||||
|
updated_by INT DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
CONSTRAINT chk_client_address_prospect_exclusive
|
||||||
|
CHECK (NOT (is_prospect = TRUE AND (is_delivery = TRUE OR is_billing = TRUE))),
|
||||||
|
CONSTRAINT chk_client_address_billing_email
|
||||||
|
CHECK ((is_billing = FALSE AND billing_email IS NULL)
|
||||||
|
OR (is_billing = TRUE AND billing_email IS NOT NULL)),
|
||||||
|
CONSTRAINT fk_client_address_client
|
||||||
|
FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_client_address_created_by
|
||||||
|
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_client_address_updated_by
|
||||||
|
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->addSql('CREATE INDEX idx_client_address_client ON client_address (client_id)');
|
||||||
|
|
||||||
|
$this->comment('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).');
|
||||||
|
$this->comment('client_address', 'id', 'Identifiant interne auto-incremente.');
|
||||||
|
$this->comment('client_address', 'client_id', 'FK -> client.id, ON DELETE CASCADE — client proprietaire de l adresse.');
|
||||||
|
$this->comment('client_address', 'is_prospect', 'Adresse de prospection — exclusive de is_delivery/is_billing (RG-1.06/07/08, chk_client_address_prospect_exclusive). Faux par defaut.');
|
||||||
|
$this->comment('client_address', 'is_delivery', 'Adresse de livraison. Exclusive de is_prospect. Faux par defaut.');
|
||||||
|
$this->comment('client_address', 'is_billing', 'Adresse de facturation. Exclusive de is_prospect. Impose billing_email (RG-1.11). Faux par defaut.');
|
||||||
|
$this->comment('client_address', 'country', 'Pays de l adresse — defaut France.');
|
||||||
|
$this->comment('client_address', 'postal_code', 'Code postal (4-5 chiffres attendus, RG-1.09).');
|
||||||
|
$this->comment('client_address', 'city', 'Ville — preremplie depuis le code postal via API BAN cote front (RG-1.09).');
|
||||||
|
$this->comment('client_address', 'street', 'Numero et voie de l adresse.');
|
||||||
|
$this->comment('client_address', 'street_complement', 'Complement d adresse (etage, batiment...) — optionnel.');
|
||||||
|
$this->comment('client_address', 'billing_email', 'Email de facturation — obligatoire si is_billing, null sinon (RG-1.11, chk_client_address_billing_email).');
|
||||||
|
$this->comment('client_address', 'position', 'Ordre d affichage de l adresse dans la liste du client (croissant).');
|
||||||
|
$this->addTimestampableBlamableComments('client_address');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Jointures de client_address (M2M)
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function createClientAddressJoinTables(): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client_address_site (
|
||||||
|
client_address_id INT NOT NULL,
|
||||||
|
site_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (client_address_id, site_id),
|
||||||
|
CONSTRAINT fk_client_address_site_address
|
||||||
|
FOREIGN KEY (client_address_id) REFERENCES client_address (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_client_address_site_site
|
||||||
|
FOREIGN KEY (site_id) REFERENCES site (id) ON DELETE RESTRICT
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->comment('client_address_site', '_table', 'Jointure M2M client_address <-> site (Sites) — sites desservis par l adresse (>= 1 obligatoire, RG-1.10).');
|
||||||
|
$this->comment('client_address_site', 'client_address_id', 'FK -> client_address.id, ON DELETE CASCADE — adresse concernee.');
|
||||||
|
$this->comment('client_address_site', 'site_id', 'FK -> site.id, ON DELETE RESTRICT — site rattache a l adresse.');
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client_address_contact (
|
||||||
|
client_address_id INT NOT NULL,
|
||||||
|
client_contact_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (client_address_id, client_contact_id),
|
||||||
|
CONSTRAINT fk_client_address_contact_address
|
||||||
|
FOREIGN KEY (client_address_id) REFERENCES client_address (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_client_address_contact_contact
|
||||||
|
FOREIGN KEY (client_contact_id) REFERENCES client_contact (id) ON DELETE CASCADE
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->comment('client_address_contact', '_table', 'Jointure M2M client_address <-> client_contact — contacts associes a une adresse.');
|
||||||
|
$this->comment('client_address_contact', 'client_address_id', 'FK -> client_address.id, ON DELETE CASCADE — adresse concernee.');
|
||||||
|
$this->comment('client_address_contact', 'client_contact_id', 'FK -> client_contact.id, ON DELETE CASCADE — contact associe a l adresse.');
|
||||||
|
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client_address_category (
|
||||||
|
client_address_id INT NOT NULL,
|
||||||
|
category_id INT NOT NULL,
|
||||||
|
PRIMARY KEY (client_address_id, category_id),
|
||||||
|
CONSTRAINT fk_client_address_category_address
|
||||||
|
FOREIGN KEY (client_address_id) REFERENCES client_address (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_client_address_category_category
|
||||||
|
FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE RESTRICT
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->comment('client_address_category', '_table', 'Jointure M2M client_address <-> category — categories d adresse (types SECTEUR/AUTRE uniquement, RG-1.29).');
|
||||||
|
$this->comment('client_address_category', 'client_address_id', 'FK -> client_address.id, ON DELETE CASCADE — adresse concernee.');
|
||||||
|
$this->comment('client_address_category', 'category_id', 'FK -> category.id, ON DELETE RESTRICT — categorie d adresse (type SECTEUR ou AUTRE, RG-1.29).');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Sous-collection : RIB (1:n)
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function createClientRib(): void
|
||||||
|
{
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE client_rib (
|
||||||
|
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||||
|
client_id INT NOT NULL,
|
||||||
|
label VARCHAR(120) NOT NULL,
|
||||||
|
bic VARCHAR(20) NOT NULL,
|
||||||
|
iban VARCHAR(34) NOT NULL,
|
||||||
|
position INT DEFAULT 0 NOT NULL,
|
||||||
|
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||||
|
created_by INT DEFAULT NULL,
|
||||||
|
updated_by INT DEFAULT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
CONSTRAINT fk_client_rib_client
|
||||||
|
FOREIGN KEY (client_id) REFERENCES client (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_client_rib_created_by
|
||||||
|
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_client_rib_updated_by
|
||||||
|
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||||
|
)
|
||||||
|
SQL);
|
||||||
|
$this->addSql('CREATE INDEX idx_client_rib_client ON client_rib (client_id)');
|
||||||
|
|
||||||
|
$this->comment('client_rib', '_table', 'Coordonnees bancaires d un client (1:n) — >= 1 RIB obligatoire si payment_type = LCR (RG-1.13). Tous les champs audites (pas d AuditIgnore).');
|
||||||
|
$this->comment('client_rib', 'id', 'Identifiant interne auto-incremente.');
|
||||||
|
$this->comment('client_rib', 'client_id', 'FK -> client.id, ON DELETE CASCADE — client proprietaire du RIB.');
|
||||||
|
$this->comment('client_rib', 'label', 'Libelle du RIB (ex: compte principal).');
|
||||||
|
$this->comment('client_rib', 'bic', 'Code BIC/SWIFT de la banque (8 ou 11 caracteres).');
|
||||||
|
$this->comment('client_rib', 'iban', 'IBAN du compte (≤ 34 caracteres).');
|
||||||
|
$this->comment('client_rib', 'position', 'Ordre d affichage du RIB dans la liste du client (croissant).');
|
||||||
|
$this->addTimestampableBlamableComments('client_rib');
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Seed extension category_type (M0)
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
private function seedCategoryTypes(): void
|
||||||
|
{
|
||||||
|
// Idempotent : la table category_type peut deja porter des donnees en
|
||||||
|
// prod. ON CONFLICT (code) s appuie sur l index unique uq_category_type_code.
|
||||||
|
// NB : la table M0 n a pas de colonne `position` (id/code/label seulement),
|
||||||
|
// contrairement au pseudo-SQL de la spec § 3.3.
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO category_type (code, label) VALUES
|
||||||
|
('DISTRIBUTEUR', 'Distributeur'),
|
||||||
|
('COURTIER', 'Courtier'),
|
||||||
|
('SECTEUR', 'Secteur'),
|
||||||
|
('AUTRE', 'Autre')
|
||||||
|
ON CONFLICT (code) DO NOTHING
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================================================================
|
||||||
|
// Helpers
|
||||||
|
// =================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pose les 4 commentaires standardises Timestampable/Blamable sur une table,
|
||||||
|
* en reutilisant le catalogue partage (source unique, cf. ERP-67).
|
||||||
|
*/
|
||||||
|
private function addTimestampableBlamableComments(string $table): void
|
||||||
|
{
|
||||||
|
foreach (ColumnCommentsCatalog::timestampableBlamableComments() as $column => $description) {
|
||||||
|
$this->comment($table, $column, $description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emet un `COMMENT ON TABLE` (colonne speciale `_table`) ou
|
||||||
|
* `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour eviter
|
||||||
|
* tout echappement d apostrophe.
|
||||||
|
*/
|
||||||
|
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,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ use App\Module\Catalog\Infrastructure\ApiPlatform\State\Provider\CategoryProvide
|
|||||||
use App\Module\Catalog\Infrastructure\Doctrine\DoctrineCategoryRepository;
|
use App\Module\Catalog\Infrastructure\Doctrine\DoctrineCategoryRepository;
|
||||||
use App\Shared\Domain\Attribute\Auditable;
|
use App\Shared\Domain\Attribute\Auditable;
|
||||||
use App\Shared\Domain\Contract\BlamableInterface;
|
use App\Shared\Domain\Contract\BlamableInterface;
|
||||||
|
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;
|
||||||
@@ -82,7 +83,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
#[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]
|
||||||
class Category implements TimestampableInterface, BlamableInterface
|
class Category implements TimestampableInterface, BlamableInterface, CategoryInterface
|
||||||
{
|
{
|
||||||
// === Timestampable + Blamable ===
|
// === Timestampable + Blamable ===
|
||||||
// Les 4 colonnes (created_at, updated_at, created_by, updated_by) + leurs
|
// Les 4 colonnes (created_at, updated_at, created_by, updated_by) + leurs
|
||||||
@@ -152,6 +153,16 @@ class Category implements TimestampableInterface, BlamableInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implemente CategoryInterface : code du type rattache (ou null). Permet
|
||||||
|
* aux modules tiers de filtrer/valider par type metier sans dependre de
|
||||||
|
* Catalog.
|
||||||
|
*/
|
||||||
|
public function getCategoryTypeCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->categoryType?->getCode();
|
||||||
|
}
|
||||||
|
|
||||||
public function getDeletedAt(): ?DateTimeImmutable
|
public function getDeletedAt(): ?DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->deletedAt;
|
return $this->deletedAt;
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Module\Catalog\Infrastructure\ApiPlatform\State\Provider;
|
namespace App\Module\Catalog\Infrastructure\ApiPlatform\State\Provider;
|
||||||
|
|
||||||
|
use ApiPlatform\Doctrine\Orm\Paginator;
|
||||||
use ApiPlatform\Metadata\CollectionOperationInterface;
|
use ApiPlatform\Metadata\CollectionOperationInterface;
|
||||||
use ApiPlatform\Metadata\Operation;
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\Pagination\Pagination;
|
||||||
use ApiPlatform\State\ProviderInterface;
|
use ApiPlatform\State\ProviderInterface;
|
||||||
use App\Module\Catalog\Domain\Entity\Category;
|
use App\Module\Catalog\Domain\Entity\Category;
|
||||||
use App\Module\Catalog\Domain\Repository\CategoryRepositoryInterface;
|
use App\Module\Catalog\Domain\Repository\CategoryRepositoryInterface;
|
||||||
|
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,18 +32,32 @@ final class CategoryProvider implements ProviderInterface
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(service: 'App\Module\Catalog\Infrastructure\Doctrine\DoctrineCategoryRepository')]
|
#[Autowire(service: 'App\Module\Catalog\Infrastructure\Doctrine\DoctrineCategoryRepository')]
|
||||||
private readonly CategoryRepositoryInterface $repository,
|
private readonly CategoryRepositoryInterface $repository,
|
||||||
|
private readonly Pagination $pagination,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Category|iterable|null
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Category|iterable|Paginator|null
|
||||||
{
|
{
|
||||||
$includeDeleted = $this->readIncludeDeleted($context);
|
$includeDeleted = $this->readIncludeDeleted($context);
|
||||||
|
|
||||||
if ($operation instanceof CollectionOperationInterface) {
|
if ($operation instanceof CollectionOperationInterface) {
|
||||||
return $this->repository
|
$qb = $this->repository->createListQueryBuilder($includeDeleted);
|
||||||
->createListQueryBuilder($includeDeleted)
|
|
||||||
->getQuery()
|
// Echappatoire ?pagination=false : retourne la collection complete sans Paginator.
|
||||||
->getResult()
|
// Utile pour les drawers Role/Permission/Site/CategoryType qui alimentent un <select>.
|
||||||
;
|
if (!$this->pagination->isEnabled($operation, $context)) {
|
||||||
|
return $qb->getQuery()->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Branche paginee standard : on applique offset/limit via Pagination,
|
||||||
|
// puis on enveloppe dans le Paginator ORM (fetchJoinCollection: true
|
||||||
|
// pour que Doctrine compte correctement avec les JOINs futurs).
|
||||||
|
$limit = $this->pagination->getLimit($operation, $context);
|
||||||
|
$page = max(1, $this->pagination->getPage($context));
|
||||||
|
$offset = ($page - 1) * $limit;
|
||||||
|
|
||||||
|
$qb->setFirstResult($offset)->setMaxResults($limit);
|
||||||
|
|
||||||
|
return new Paginator(new DoctrinePaginator($qb->getQuery(), fetchJoinCollection: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get unitaire : recharger l'entite, puis appliquer le filtre soft-delete.
|
// Get unitaire : recharger l'entite, puis appliquer le filtre soft-delete.
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Catalog\Infrastructure\DataFixtures;
|
||||||
|
|
||||||
|
use App\Module\Catalog\Domain\Entity\CategoryType;
|
||||||
|
use App\Module\Catalog\Domain\Repository\CategoryTypeRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixtures du module Catalog : seed des types de categorie metier (M1).
|
||||||
|
*
|
||||||
|
* La table `category_type` est creee vide au M0 ; le M1 la peuple avec les 4
|
||||||
|
* types DISTRIBUTEUR / COURTIER / SECTEUR / AUTRE (cf. spec M1 § 3.3).
|
||||||
|
*
|
||||||
|
* Pourquoi une fixture EN PLUS du seed de la migration (Version20260601000000) :
|
||||||
|
* `category_type` est une entite managee par l ORM, donc le purger Doctrine la
|
||||||
|
* vide avant chaque `doctrine:fixtures:load`. Sans cette fixture, les 4 types
|
||||||
|
* seedes par la migration disparaitraient apres `make db-reset` / setup de test.
|
||||||
|
* Le seed migration couvre la prod (ou les fixtures ne tournent pas) ; cette
|
||||||
|
* fixture re-aligne dev et test. Les deux chemins produisent un etat identique.
|
||||||
|
*
|
||||||
|
* Idempotence : lookup par `code` parmi les types existants avant insertion,
|
||||||
|
* sur le modele d AppFixtures::ensureSystemRole. Rejouable sans doublon meme
|
||||||
|
* si le purger est desactive.
|
||||||
|
*/
|
||||||
|
class CategoryTypeFixtures extends Fixture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Source unique des 4 types metier : code technique => libelle FR.
|
||||||
|
* Doit rester aligne sur le seed de la migration Version20260601000000.
|
||||||
|
*/
|
||||||
|
private const TYPES = [
|
||||||
|
'DISTRIBUTEUR' => 'Distributeur',
|
||||||
|
'COURTIER' => 'Courtier',
|
||||||
|
'SECTEUR' => 'Secteur',
|
||||||
|
'AUTRE' => 'Autre',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly CategoryTypeRepositoryInterface $categoryTypeRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
// Index des types deja presents par code, pour ne pas creer de doublon.
|
||||||
|
$existingByCode = [];
|
||||||
|
foreach ($this->categoryTypeRepository->findAllOrderedByLabel() as $type) {
|
||||||
|
$existingByCode[$type->getCode()] = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (self::TYPES as $code => $label) {
|
||||||
|
$type = $existingByCode[$code] ?? new CategoryType();
|
||||||
|
$type->setCode($code);
|
||||||
|
$type->setLabel($label);
|
||||||
|
$manager->persist($type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Application\Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalisation serveur des champs texte d'un Client / ClientContact, appliquee
|
||||||
|
* par le ClientProcessor (et plus tard le ClientContactProcessor) AVANT
|
||||||
|
* persistance. Cf. spec-back M1 § 2.9 + RG-1.18 a RG-1.21.
|
||||||
|
*
|
||||||
|
* - companyName : UPPERCASE integral (RG-1.18)
|
||||||
|
* - firstName / lastName (personnes) : Title Case (RG-1.19)
|
||||||
|
* - phone* : chiffres uniquement, ex "06.12.34.56.78" -> "0612345678" (RG-1.20).
|
||||||
|
* Le formatage d'affichage "XX XX XX XX XX" est de la responsabilite du front.
|
||||||
|
* - email : lowercase integral (RG-1.21)
|
||||||
|
*
|
||||||
|
* Toutes les methodes sont null-safe et trim-ent l'entree ; une chaine vide
|
||||||
|
* apres trim devient null (evite de persister "" dans des colonnes nullable).
|
||||||
|
*/
|
||||||
|
final class ClientFieldNormalizer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Nom de societe en majuscules (RG-1.18). Conserve null tel quel ; une
|
||||||
|
* chaine non vide est trim + upper. Une chaine vide reste "" (champ
|
||||||
|
* obligatoire : c'est l'Assert\NotBlank qui rejette, pas le normalizer).
|
||||||
|
*/
|
||||||
|
public function normalizeCompanyName(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mb_strtoupper(trim($value), 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nom/prenom de personne en Title Case (RG-1.19) : "JEAN dupont" ->
|
||||||
|
* "Jean Dupont". Une chaine vide apres trim devient null.
|
||||||
|
*/
|
||||||
|
public function normalizePersonName(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
|
return '' === $value ? null : mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email en minuscules (RG-1.21). Une chaine vide apres trim devient null.
|
||||||
|
*/
|
||||||
|
public function normalizeEmail(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
|
return '' === $value ? null : mb_strtolower($value, 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telephone reduit aux chiffres (RG-1.20) : "06.12.34.56.78" ->
|
||||||
|
* "0612345678". Une valeur sans aucun chiffre devient null.
|
||||||
|
*/
|
||||||
|
public function normalizePhone(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$digits = preg_replace('/\D+/', '', $value) ?? '';
|
||||||
|
|
||||||
|
return '' === $digits ? null : $digits;
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,4 +9,36 @@ final class CommercialModule
|
|||||||
public const string ID = 'commercial';
|
public const string ID = 'commercial';
|
||||||
public const string LABEL = 'Commercial';
|
public const string LABEL = 'Commercial';
|
||||||
public const bool REQUIRED = false;
|
public const bool REQUIRED = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste declarative des permissions RBAC exposees par le module Commercial.
|
||||||
|
*
|
||||||
|
* Consommee par la commande `app:sync-permissions` (SyncPermissionsCommand)
|
||||||
|
* qui se charge d'upserter ces entrees dans la table `permission`, de
|
||||||
|
* reactiver les codes precedemment marques orphelins et de marquer comme
|
||||||
|
* orphelins ceux qui ont disparu du code source.
|
||||||
|
*
|
||||||
|
* La cle `module` est auto-injectee par le sync command a partir de
|
||||||
|
* `self::ID`, il est donc inutile de la repeter dans chaque entree.
|
||||||
|
*
|
||||||
|
* Convention de nommage des codes : `module.resource[.sub].action` en
|
||||||
|
* snake_case, le prefixe module devant correspondre exactement a
|
||||||
|
* `self::ID` (verifie par la commande de synchronisation).
|
||||||
|
*
|
||||||
|
* Granularite alignee sur Core/Catalog (view + manage), plus deux
|
||||||
|
* permissions dediees a l'onglet Comptabilite et a l'archivage
|
||||||
|
* (cf. spec-back M1 § 2.7).
|
||||||
|
*
|
||||||
|
* @return array<int, array{code: string, label: string}>
|
||||||
|
*/
|
||||||
|
public static function permissions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['code' => 'commercial.clients.view', 'label' => 'Voir les clients'],
|
||||||
|
['code' => 'commercial.clients.manage', 'label' => 'Créer / modifier les clients (hors onglet Comptabilité)'],
|
||||||
|
['code' => 'commercial.clients.accounting.view', 'label' => 'Voir l\'onglet Comptabilité d\'un client'],
|
||||||
|
['code' => 'commercial.clients.accounting.manage', 'label' => 'Modifier l\'onglet Comptabilité d\'un client'],
|
||||||
|
['code' => 'commercial.clients.archive', 'label' => 'Archiver / restaurer un client'],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineBankRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Banque selectionnable pour le reglement par virement (Societe Generale,
|
||||||
|
* CIC, Credit Agricole) : referentiel statique seede par la migration M1 et
|
||||||
|
* re-seede en dev/test par CommercialReferentialFixtures.
|
||||||
|
*
|
||||||
|
* Lecture seule au M1 (HP-M2-2) : GetCollection + Get uniquement (ERP-56),
|
||||||
|
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
||||||
|
* Timestampable/Blamable (referentiel statique whiteliste dans
|
||||||
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
||||||
|
* `client:read:accounting` permet l'embarquement dans la reponse Client.
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new GetCollection(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['bank:read']],
|
||||||
|
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC.
|
||||||
|
order: ['position' => 'ASC', 'label' => 'ASC'],
|
||||||
|
// ERP-72 : pagination serveur + toggle ?pagination=false (cf. TvaMode).
|
||||||
|
paginationClientEnabled: true,
|
||||||
|
),
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['bank:read']],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrineBankRepository::class)]
|
||||||
|
#[ORM\Table(name: 'bank')]
|
||||||
|
#[ORM\UniqueConstraint(name: 'uq_bank_code', columns: ['code'])]
|
||||||
|
class Bank
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['bank:read', 'client:read:accounting'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 30)]
|
||||||
|
#[Groups(['bank:read', 'client:read:accounting'])]
|
||||||
|
private ?string $code = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120)]
|
||||||
|
#[Groups(['bank:read', 'client:read:accounting'])]
|
||||||
|
private ?string $label = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
#[Groups(['bank:read'])]
|
||||||
|
private int $position = 0;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCode(string $code): static
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel(): ?string
|
||||||
|
{
|
||||||
|
return $this->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLabel(string $label): static
|
||||||
|
{
|
||||||
|
$this->label = $label;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(int $position): static
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,719 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use ApiPlatform\Metadata\Patch;
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientProcessor;
|
||||||
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Provider\ClientProvider;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientRepository;
|
||||||
|
use App\Shared\Domain\Attribute\Auditable;
|
||||||
|
use App\Shared\Domain\Contract\BlamableInterface;
|
||||||
|
use App\Shared\Domain\Contract\CategoryInterface;
|
||||||
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||||
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client (M1 Commercial) — entite racine du repertoire clients. Porte le
|
||||||
|
* formulaire principal, l'onglet Information, l'onglet Comptabilite, le
|
||||||
|
* mecanisme d'archivage (is_archived / archived_at) et le soft-delete technique
|
||||||
|
* prepare mais non expose au M1 (deleted_at, HP-M2-1).
|
||||||
|
*
|
||||||
|
* Decisions structurantes :
|
||||||
|
* - Audit complet (#[Auditable]) sur tous les champs (M2M categories audite
|
||||||
|
* automatiquement). Timestampable/Blamable via le trait Shared.
|
||||||
|
* - PAS de #[ORM\UniqueConstraint] : l'unicite du nom de societe (RG-1.16) est
|
||||||
|
* portee par l'index partiel fonctionnel uq_client_company_name_active
|
||||||
|
* (LOWER(company_name) WHERE is_archived = FALSE AND deleted_at IS NULL),
|
||||||
|
* inexprimable en attribut ORM, donc possede par la seule migration. Le SIREN
|
||||||
|
* et l'email NE SONT PAS uniques (RG-1.15/1.17 supprimees, decision Q4).
|
||||||
|
* - distributor / broker : 2 FK auto-referentes mutuellement exclusives
|
||||||
|
* (RG-1.03, CHECK chk_client_distrib_or_broker en base).
|
||||||
|
* - categories : M2M vers Category (module Catalog) via le contrat
|
||||||
|
* CategoryInterface + resolve_target_entities (regle n°1, pas d'import direct).
|
||||||
|
*
|
||||||
|
* Operations API (Provider + Processor) branchees en ERP-55 :
|
||||||
|
* - GetCollection / Get : security commercial.clients.view. La liste expose le
|
||||||
|
* groupe client:read ; le detail embarque en plus contacts/adresses/ribs
|
||||||
|
* (groupe client:item:read). Les champs comptables (client:read:accounting)
|
||||||
|
* sont ajoutes DYNAMIQUEMENT par ClientReadGroupContextBuilder si l'user a
|
||||||
|
* la permission accounting.view (§ 2.7 / § 4.1 / § 4.2).
|
||||||
|
* - Post / Patch : security commercial.clients.manage ; le ClientProcessor
|
||||||
|
* applique normalisation, gating accounting/archive et regles metier.
|
||||||
|
* - Pas de Delete au M1 (HP-M2-1) : l'archivage passe par PATCH isArchived.
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new GetCollection(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['client:read', 'default:read']],
|
||||||
|
provider: ClientProvider::class,
|
||||||
|
),
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
// Detail : client + sous-collections embarquees. Le groupe
|
||||||
|
// client:read:accounting est ajoute par le context builder selon la
|
||||||
|
// permission, donc absent ici volontairement.
|
||||||
|
normalizationContext: ['groups' => [
|
||||||
|
'client:read',
|
||||||
|
'client:item:read',
|
||||||
|
'client_contact:read',
|
||||||
|
'client_address:read',
|
||||||
|
'client_rib:read',
|
||||||
|
'default:read',
|
||||||
|
]],
|
||||||
|
provider: ClientProvider::class,
|
||||||
|
),
|
||||||
|
new Post(
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client:read', 'default:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client:write:main']],
|
||||||
|
processor: ClientProcessor::class,
|
||||||
|
),
|
||||||
|
new Patch(
|
||||||
|
// Security elargie (ERP-74) : `manage` OU `accounting.manage`. Le
|
||||||
|
// role Compta n'a pas `manage` mais doit pouvoir editer l'onglet
|
||||||
|
// Comptabilite d'un client existant (§ 2.7). Le ClientProcessor
|
||||||
|
// re-gate ensuite onglet par onglet :
|
||||||
|
// - champs accounting -> accounting.manage (guardAccounting, RG-1.28) ;
|
||||||
|
// - champs main/information -> manage (guardManage : empeche Compta
|
||||||
|
// d'editer les autres onglets) ;
|
||||||
|
// - isArchived -> archive (guardArchive, RG-1.22).
|
||||||
|
security: "is_granted('commercial.clients.manage') or is_granted('commercial.clients.accounting.manage')",
|
||||||
|
// Le ClientProcessor inspecte les champs reellement envoyes pour
|
||||||
|
// autoriser/refuser onglet par onglet (RG-1.22 / RG-1.28) : les
|
||||||
|
// champs accounting exigent accounting.manage, isArchived exige
|
||||||
|
// archive, le reste (main/information) exige manage.
|
||||||
|
normalizationContext: ['groups' => ['client:read', 'default:read']],
|
||||||
|
denormalizationContext: ['groups' => [
|
||||||
|
'client:write:main',
|
||||||
|
'client:write:information',
|
||||||
|
'client:write:accounting',
|
||||||
|
'client:write:archive',
|
||||||
|
]],
|
||||||
|
provider: ClientProvider::class,
|
||||||
|
processor: ClientProcessor::class,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrineClientRepository::class)]
|
||||||
|
#[ORM\Table(name: 'client')]
|
||||||
|
// Index nommes pour matcher la migration (Version20260601000000). L'index
|
||||||
|
// unique partiel uq_client_company_name_active reste possede par la migration :
|
||||||
|
// Doctrine ORM ne sait pas exprimer un index fonctionnel (LOWER) + partiel
|
||||||
|
// (WHERE) via attribut. Pas de #[ORM\UniqueConstraint] (decision Q4).
|
||||||
|
#[ORM\Index(name: 'idx_client_is_archived', columns: ['is_archived'])]
|
||||||
|
#[ORM\Index(name: 'idx_client_deleted_at', columns: ['deleted_at'])]
|
||||||
|
#[ORM\Index(name: 'idx_client_distributor_id', columns: ['distributor_id'])]
|
||||||
|
#[ORM\Index(name: 'idx_client_broker_id', columns: ['broker_id'])]
|
||||||
|
#[ORM\Index(name: 'idx_client_created_by', columns: ['created_by'])]
|
||||||
|
#[ORM\Index(name: 'idx_client_updated_by', columns: ['updated_by'])]
|
||||||
|
#[Auditable]
|
||||||
|
class Client implements TimestampableInterface, BlamableInterface
|
||||||
|
{
|
||||||
|
use TimestampableBlamableTrait;
|
||||||
|
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['client:read'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
// === Formulaire principal ===
|
||||||
|
#[ORM\Column(length: 180)]
|
||||||
|
#[Assert\NotBlank(message: 'Le nom de l\'entreprise est obligatoire.', normalizer: 'trim')]
|
||||||
|
#[Assert\Length(min: 2, max: 180, normalizer: 'trim')]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?string $companyName = null;
|
||||||
|
|
||||||
|
// RG-1.01 : firstName OU lastName obligatoire (validation au futur Processor).
|
||||||
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
|
#[Assert\Length(max: 120, normalizer: 'trim')]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?string $firstName = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
|
#[Assert\Length(max: 120, normalizer: 'trim')]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?string $lastName = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 20)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?string $phonePrimary = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?string $phoneSecondary = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 180)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Assert\Email]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?string $email = null;
|
||||||
|
|
||||||
|
// RG-1.03 : distributor / broker auto-references mutuellement exclusives
|
||||||
|
// (CHECK chk_client_distrib_or_broker en base).
|
||||||
|
#[ORM\ManyToOne(targetEntity: self::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'distributor_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?Client $distributor = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: self::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'broker_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private ?Client $broker = null;
|
||||||
|
|
||||||
|
#[ORM\Column(name: 'triage_service', options: ['default' => false])]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private bool $triageService = false;
|
||||||
|
|
||||||
|
// RG : au moins une categorie (Count min 1). M2M vers Category via le contrat
|
||||||
|
// CategoryInterface (resolve_target_entities -> Category).
|
||||||
|
/** @var Collection<int, CategoryInterface> */
|
||||||
|
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
||||||
|
#[ORM\JoinTable(name: 'client_category')]
|
||||||
|
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
|
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||||
|
#[Assert\Count(min: 1, minMessage: 'Au moins une catégorie est obligatoire.')]
|
||||||
|
#[Groups(['client:read', 'client:write:main'])]
|
||||||
|
private Collection $categories;
|
||||||
|
|
||||||
|
// === Onglet Information ===
|
||||||
|
#[ORM\Column(type: 'text', nullable: true)]
|
||||||
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
|
private ?string $description = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
|
private ?string $competitors = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'date_immutable', nullable: true)]
|
||||||
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
|
private ?DateTimeImmutable $foundedAt = null;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
#[Assert\PositiveOrZero]
|
||||||
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
|
private ?int $employeesCount = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'decimal', precision: 15, scale: 2, nullable: true)]
|
||||||
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
|
private ?string $revenueAmount = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
|
private ?string $directorName = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'decimal', precision: 15, scale: 2, nullable: true)]
|
||||||
|
#[Groups(['client:read', 'client:write:information'])]
|
||||||
|
private ?string $profitAmount = null;
|
||||||
|
|
||||||
|
// === Onglet Comptabilite ===
|
||||||
|
// Lecture conditionnee via le groupe `client:read:accounting` (ajoute par le
|
||||||
|
// futur Provider si l'user a la permission accounting.view). Ecriture via
|
||||||
|
// `client:write:accounting` (le futur Processor exige accounting.manage).
|
||||||
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
|
private ?string $siren = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
|
private ?string $accountNumber = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: TvaMode::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'tva_mode_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||||
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
|
private ?TvaMode $tvaMode = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
|
private ?string $nTva = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: PaymentDelay::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'payment_delay_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||||
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
|
private ?PaymentDelay $paymentDelay = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: PaymentType::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'payment_type_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||||
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
|
private ?PaymentType $paymentType = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Bank::class)]
|
||||||
|
#[ORM\JoinColumn(name: 'bank_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||||
|
#[Groups(['client:read:accounting', 'client:write:accounting'])]
|
||||||
|
private ?Bank $bank = null;
|
||||||
|
|
||||||
|
// === Sous-collections (exposees via sous-ressources API dediees, ulterieur) ===
|
||||||
|
/** @var Collection<int, ClientContact> */
|
||||||
|
#[ORM\OneToMany(mappedBy: 'client', targetEntity: ClientContact::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
|
private Collection $contacts;
|
||||||
|
|
||||||
|
/** @var Collection<int, ClientAddress> */
|
||||||
|
#[ORM\OneToMany(mappedBy: 'client', targetEntity: ClientAddress::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
|
private Collection $addresses;
|
||||||
|
|
||||||
|
/** @var Collection<int, ClientRib> */
|
||||||
|
#[ORM\OneToMany(mappedBy: 'client', targetEntity: ClientRib::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||||
|
private Collection $ribs;
|
||||||
|
|
||||||
|
// === Archive / Soft delete ===
|
||||||
|
// Groupe d'ECRITURE uniquement sur la propriete (denormalisation PATCH
|
||||||
|
// archive). Le groupe de LECTURE est declare sur le getter isArchived()
|
||||||
|
// avec SerializedName('isArchived') : sans cela, Symfony strip le prefixe
|
||||||
|
// "is" et exposerait la cle JSON "archived" (meme pattern que User::isAdmin
|
||||||
|
// et Role::isSystem).
|
||||||
|
#[ORM\Column(name: 'is_archived', options: ['default' => false])]
|
||||||
|
#[Groups(['client:write:archive'])]
|
||||||
|
private bool $isArchived = false;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
||||||
|
#[Groups(['client:read'])]
|
||||||
|
private ?DateTimeImmutable $archivedAt = null;
|
||||||
|
|
||||||
|
// Soft delete technique (HP-M2-1) : non expose en lecture/ecriture au M1.
|
||||||
|
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
||||||
|
private ?DateTimeImmutable $deletedAt = null;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->categories = new ArrayCollection();
|
||||||
|
$this->contacts = new ArrayCollection();
|
||||||
|
$this->addresses = new ArrayCollection();
|
||||||
|
$this->ribs = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCompanyName(): ?string
|
||||||
|
{
|
||||||
|
return $this->companyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCompanyName(string $companyName): static
|
||||||
|
{
|
||||||
|
$this->companyName = $companyName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFirstName(): ?string
|
||||||
|
{
|
||||||
|
return $this->firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFirstName(?string $firstName): static
|
||||||
|
{
|
||||||
|
$this->firstName = $firstName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastName(): ?string
|
||||||
|
{
|
||||||
|
return $this->lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLastName(?string $lastName): static
|
||||||
|
{
|
||||||
|
$this->lastName = $lastName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhonePrimary(): ?string
|
||||||
|
{
|
||||||
|
return $this->phonePrimary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPhonePrimary(string $phonePrimary): static
|
||||||
|
{
|
||||||
|
$this->phonePrimary = $phonePrimary;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhoneSecondary(): ?string
|
||||||
|
{
|
||||||
|
return $this->phoneSecondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPhoneSecondary(?string $phoneSecondary): static
|
||||||
|
{
|
||||||
|
$this->phoneSecondary = $phoneSecondary;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmail(): ?string
|
||||||
|
{
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEmail(string $email): static
|
||||||
|
{
|
||||||
|
$this->email = $email;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDistributor(): ?Client
|
||||||
|
{
|
||||||
|
return $this->distributor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDistributor(?Client $distributor): static
|
||||||
|
{
|
||||||
|
$this->distributor = $distributor;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBroker(): ?Client
|
||||||
|
{
|
||||||
|
return $this->broker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBroker(?Client $broker): static
|
||||||
|
{
|
||||||
|
$this->broker = $broker;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isTriageService(): bool
|
||||||
|
{
|
||||||
|
return $this->triageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTriageService(bool $triageService): static
|
||||||
|
{
|
||||||
|
$this->triageService = $triageService;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, CategoryInterface> */
|
||||||
|
public function getCategories(): Collection
|
||||||
|
{
|
||||||
|
return $this->categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCategory(CategoryInterface $category): static
|
||||||
|
{
|
||||||
|
if (!$this->categories->contains($category)) {
|
||||||
|
$this->categories->add($category);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeCategory(CategoryInterface $category): static
|
||||||
|
{
|
||||||
|
$this->categories->removeElement($category);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): ?string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(?string $description): static
|
||||||
|
{
|
||||||
|
$this->description = $description;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCompetitors(): ?string
|
||||||
|
{
|
||||||
|
return $this->competitors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCompetitors(?string $competitors): static
|
||||||
|
{
|
||||||
|
$this->competitors = $competitors;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFoundedAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->foundedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFoundedAt(?DateTimeImmutable $foundedAt): static
|
||||||
|
{
|
||||||
|
$this->foundedAt = $foundedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmployeesCount(): ?int
|
||||||
|
{
|
||||||
|
return $this->employeesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEmployeesCount(?int $employeesCount): static
|
||||||
|
{
|
||||||
|
$this->employeesCount = $employeesCount;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRevenueAmount(): ?string
|
||||||
|
{
|
||||||
|
return $this->revenueAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRevenueAmount(?string $revenueAmount): static
|
||||||
|
{
|
||||||
|
$this->revenueAmount = $revenueAmount;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDirectorName(): ?string
|
||||||
|
{
|
||||||
|
return $this->directorName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDirectorName(?string $directorName): static
|
||||||
|
{
|
||||||
|
$this->directorName = $directorName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProfitAmount(): ?string
|
||||||
|
{
|
||||||
|
return $this->profitAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setProfitAmount(?string $profitAmount): static
|
||||||
|
{
|
||||||
|
$this->profitAmount = $profitAmount;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSiren(): ?string
|
||||||
|
{
|
||||||
|
return $this->siren;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSiren(?string $siren): static
|
||||||
|
{
|
||||||
|
$this->siren = $siren;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAccountNumber(): ?string
|
||||||
|
{
|
||||||
|
return $this->accountNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAccountNumber(?string $accountNumber): static
|
||||||
|
{
|
||||||
|
$this->accountNumber = $accountNumber;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTvaMode(): ?TvaMode
|
||||||
|
{
|
||||||
|
return $this->tvaMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTvaMode(?TvaMode $tvaMode): static
|
||||||
|
{
|
||||||
|
$this->tvaMode = $tvaMode;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNTva(): ?string
|
||||||
|
{
|
||||||
|
return $this->nTva;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNTva(?string $nTva): static
|
||||||
|
{
|
||||||
|
$this->nTva = $nTva;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaymentDelay(): ?PaymentDelay
|
||||||
|
{
|
||||||
|
return $this->paymentDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPaymentDelay(?PaymentDelay $paymentDelay): static
|
||||||
|
{
|
||||||
|
$this->paymentDelay = $paymentDelay;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaymentType(): ?PaymentType
|
||||||
|
{
|
||||||
|
return $this->paymentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPaymentType(?PaymentType $paymentType): static
|
||||||
|
{
|
||||||
|
$this->paymentType = $paymentType;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBank(): ?Bank
|
||||||
|
{
|
||||||
|
return $this->bank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBank(?Bank $bank): static
|
||||||
|
{
|
||||||
|
$this->bank = $bank;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, ClientContact> */
|
||||||
|
#[Groups(['client:item:read'])]
|
||||||
|
public function getContacts(): Collection
|
||||||
|
{
|
||||||
|
return $this->contacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addContact(ClientContact $contact): static
|
||||||
|
{
|
||||||
|
if (!$this->contacts->contains($contact)) {
|
||||||
|
$this->contacts->add($contact);
|
||||||
|
$contact->setClient($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeContact(ClientContact $contact): static
|
||||||
|
{
|
||||||
|
if ($this->contacts->removeElement($contact) && $contact->getClient() === $this) {
|
||||||
|
$contact->setClient(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, ClientAddress> */
|
||||||
|
#[Groups(['client:item:read'])]
|
||||||
|
public function getAddresses(): Collection
|
||||||
|
{
|
||||||
|
return $this->addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAddress(ClientAddress $address): static
|
||||||
|
{
|
||||||
|
if (!$this->addresses->contains($address)) {
|
||||||
|
$this->addresses->add($address);
|
||||||
|
$address->setClient($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeAddress(ClientAddress $address): static
|
||||||
|
{
|
||||||
|
if ($this->addresses->removeElement($address) && $address->getClient() === $this) {
|
||||||
|
$address->setClient(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, ClientRib> */
|
||||||
|
#[Groups(['client:item:read'])]
|
||||||
|
public function getRibs(): Collection
|
||||||
|
{
|
||||||
|
return $this->ribs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRib(ClientRib $rib): static
|
||||||
|
{
|
||||||
|
if (!$this->ribs->contains($rib)) {
|
||||||
|
$this->ribs->add($rib);
|
||||||
|
$rib->setClient($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeRib(ClientRib $rib): static
|
||||||
|
{
|
||||||
|
if ($this->ribs->removeElement($rib) && $rib->getClient() === $this) {
|
||||||
|
$rib->setClient(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Groupe de lecture + nom serialise explicite : sans SerializedName, Symfony
|
||||||
|
// exposerait la cle "archived" (strip du prefixe "is" sur les getters).
|
||||||
|
#[Groups(['client:read'])]
|
||||||
|
#[SerializedName('isArchived')]
|
||||||
|
public function isArchived(): bool
|
||||||
|
{
|
||||||
|
return $this->isArchived;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsArchived(bool $isArchived): static
|
||||||
|
{
|
||||||
|
$this->isArchived = $isArchived;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArchivedAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->archivedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setArchivedAt(?DateTimeImmutable $archivedAt): static
|
||||||
|
{
|
||||||
|
$this->archivedAt = $archivedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDeletedAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->deletedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDeletedAt(?DateTimeImmutable $deletedAt): static
|
||||||
|
{
|
||||||
|
$this->deletedAt = $deletedAt;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,379 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Delete;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\Link;
|
||||||
|
use ApiPlatform\Metadata\Patch;
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientAddressProcessor;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientAddressRepository;
|
||||||
|
use App\Shared\Domain\Attribute\Auditable;
|
||||||
|
use App\Shared\Domain\Contract\BlamableInterface;
|
||||||
|
use App\Shared\Domain\Contract\CategoryInterface;
|
||||||
|
use App\Shared\Domain\Contract\SiteInterface;
|
||||||
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||||
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adresse d'un client (1:n) — onglet Adresse. Une adresse de prospection
|
||||||
|
* (isProspect) est exclusive d'une adresse de livraison/facturation
|
||||||
|
* (RG-1.06/07/08, CHECK BDD). Un email de facturation est obligatoire ssi
|
||||||
|
* isBilling (RG-1.11, CHECK BDD). Au moins un site doit etre rattache
|
||||||
|
* (RG-1.10, Assert\Count).
|
||||||
|
*
|
||||||
|
* Relations M2M :
|
||||||
|
* - sites : SiteInterface (module Sites) via resolve_target_entities
|
||||||
|
* - contacts : ClientContact (meme module)
|
||||||
|
* - categories : CategoryInterface (module Catalog) via resolve_target_entities
|
||||||
|
* — limitees aux types SECTEUR/AUTRE cote validation (RG-1.29, hors ERP-57)
|
||||||
|
*
|
||||||
|
* Audite (#[Auditable]) + Timestampable/Blamable.
|
||||||
|
*
|
||||||
|
* Sous-ressource API (ERP-57, spec § 4.5) :
|
||||||
|
* - POST /api/clients/{clientId}/addresses : creation rattachee au client parent
|
||||||
|
* (Link toProperty 'client'), security commercial.clients.manage.
|
||||||
|
* - PATCH / DELETE /api/client_addresses/{id} : security commercial.clients.manage.
|
||||||
|
* - GET /api/client_addresses/{id} : lecture unitaire (security view) — la
|
||||||
|
* lecture courante reste via le parent. Pas de GET collection autonome.
|
||||||
|
* Tout passe par le ClientAddressProcessor (normalisation RG-1.21 billingEmail).
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['client_address:read']],
|
||||||
|
),
|
||||||
|
new Post(
|
||||||
|
uriTemplate: '/clients/{clientId}/addresses',
|
||||||
|
uriVariables: [
|
||||||
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
||||||
|
],
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client_address:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client_address:write']],
|
||||||
|
processor: ClientAddressProcessor::class,
|
||||||
|
),
|
||||||
|
new Patch(
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client_address:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client_address:write']],
|
||||||
|
processor: ClientAddressProcessor::class,
|
||||||
|
),
|
||||||
|
new Delete(
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
processor: ClientAddressProcessor::class,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrineClientAddressRepository::class)]
|
||||||
|
#[ORM\Table(name: 'client_address')]
|
||||||
|
#[ORM\Index(name: 'idx_client_address_client', columns: ['client_id'])]
|
||||||
|
#[Auditable]
|
||||||
|
class ClientAddress implements TimestampableInterface, BlamableInterface
|
||||||
|
{
|
||||||
|
use TimestampableBlamableTrait;
|
||||||
|
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['client_address:read'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Client::class, inversedBy: 'addresses')]
|
||||||
|
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||||
|
private ?Client $client = null;
|
||||||
|
|
||||||
|
#[ORM\Column(name: 'is_prospect', options: ['default' => false])]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private bool $isProspect = false;
|
||||||
|
|
||||||
|
#[ORM\Column(name: 'is_delivery', options: ['default' => false])]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private bool $isDelivery = false;
|
||||||
|
|
||||||
|
#[ORM\Column(name: 'is_billing', options: ['default' => false])]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private bool $isBilling = false;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 80, options: ['default' => 'France'])]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private string $country = 'France';
|
||||||
|
|
||||||
|
// RG-1.09 : code postal a 4 ou 5 chiffres (pas de controle CP/ville serveur).
|
||||||
|
#[ORM\Column(length: 20)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Assert\Regex(pattern: '/^[0-9]{4,5}$/', message: 'Le code postal doit comporter 4 ou 5 chiffres.')]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private ?string $postalCode = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private ?string $city = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private ?string $street = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private ?string $streetComplement = null;
|
||||||
|
|
||||||
|
// RG-1.11 : obligatoire ssi isBilling (CHECK BDD + futur Processor).
|
||||||
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
|
#[Assert\Email]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private ?string $billingEmail = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private int $position = 0;
|
||||||
|
|
||||||
|
// RG-1.10 : au moins un site rattache a chaque adresse.
|
||||||
|
/** @var Collection<int, SiteInterface> */
|
||||||
|
#[ORM\ManyToMany(targetEntity: SiteInterface::class)]
|
||||||
|
#[ORM\JoinTable(name: 'client_address_site')]
|
||||||
|
#[ORM\JoinColumn(name: 'client_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
|
#[ORM\InverseJoinColumn(name: 'site_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||||
|
#[Assert\Count(min: 1, minMessage: 'Au moins un site est obligatoire.')]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private Collection $sites;
|
||||||
|
|
||||||
|
/** @var Collection<int, ClientContact> */
|
||||||
|
#[ORM\ManyToMany(targetEntity: ClientContact::class)]
|
||||||
|
#[ORM\JoinTable(name: 'client_address_contact')]
|
||||||
|
#[ORM\JoinColumn(name: 'client_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
|
#[ORM\InverseJoinColumn(name: 'client_contact_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private Collection $contacts;
|
||||||
|
|
||||||
|
// RG-1.29 : categories de type SECTEUR/AUTRE uniquement (filtre au Processor).
|
||||||
|
/** @var Collection<int, CategoryInterface> */
|
||||||
|
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
||||||
|
#[ORM\JoinTable(name: 'client_address_category')]
|
||||||
|
#[ORM\JoinColumn(name: 'client_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||||
|
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||||
|
#[Groups(['client_address:read', 'client_address:write'])]
|
||||||
|
private Collection $categories;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->sites = new ArrayCollection();
|
||||||
|
$this->contacts = new ArrayCollection();
|
||||||
|
$this->categories = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClient(): ?Client
|
||||||
|
{
|
||||||
|
return $this->client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClient(?Client $client): static
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isProspect(): bool
|
||||||
|
{
|
||||||
|
return $this->isProspect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsProspect(bool $isProspect): static
|
||||||
|
{
|
||||||
|
$this->isProspect = $isProspect;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDelivery(): bool
|
||||||
|
{
|
||||||
|
return $this->isDelivery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsDelivery(bool $isDelivery): static
|
||||||
|
{
|
||||||
|
$this->isDelivery = $isDelivery;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isBilling(): bool
|
||||||
|
{
|
||||||
|
return $this->isBilling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsBilling(bool $isBilling): static
|
||||||
|
{
|
||||||
|
$this->isBilling = $isBilling;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCountry(): string
|
||||||
|
{
|
||||||
|
return $this->country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCountry(string $country): static
|
||||||
|
{
|
||||||
|
$this->country = $country;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPostalCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->postalCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPostalCode(?string $postalCode): static
|
||||||
|
{
|
||||||
|
$this->postalCode = $postalCode;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCity(): ?string
|
||||||
|
{
|
||||||
|
return $this->city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCity(?string $city): static
|
||||||
|
{
|
||||||
|
$this->city = $city;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStreet(): ?string
|
||||||
|
{
|
||||||
|
return $this->street;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStreet(?string $street): static
|
||||||
|
{
|
||||||
|
$this->street = $street;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStreetComplement(): ?string
|
||||||
|
{
|
||||||
|
return $this->streetComplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStreetComplement(?string $streetComplement): static
|
||||||
|
{
|
||||||
|
$this->streetComplement = $streetComplement;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBillingEmail(): ?string
|
||||||
|
{
|
||||||
|
return $this->billingEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBillingEmail(?string $billingEmail): static
|
||||||
|
{
|
||||||
|
$this->billingEmail = $billingEmail;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(int $position): static
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, SiteInterface> */
|
||||||
|
public function getSites(): Collection
|
||||||
|
{
|
||||||
|
return $this->sites;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSite(SiteInterface $site): static
|
||||||
|
{
|
||||||
|
if (!$this->sites->contains($site)) {
|
||||||
|
$this->sites->add($site);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeSite(SiteInterface $site): static
|
||||||
|
{
|
||||||
|
$this->sites->removeElement($site);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, ClientContact> */
|
||||||
|
public function getContacts(): Collection
|
||||||
|
{
|
||||||
|
return $this->contacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addContact(ClientContact $contact): static
|
||||||
|
{
|
||||||
|
if (!$this->contacts->contains($contact)) {
|
||||||
|
$this->contacts->add($contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeContact(ClientContact $contact): static
|
||||||
|
{
|
||||||
|
$this->contacts->removeElement($contact);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, CategoryInterface> */
|
||||||
|
public function getCategories(): Collection
|
||||||
|
{
|
||||||
|
return $this->categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCategory(CategoryInterface $category): static
|
||||||
|
{
|
||||||
|
if (!$this->categories->contains($category)) {
|
||||||
|
$this->categories->add($category);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeCategory(CategoryInterface $category): static
|
||||||
|
{
|
||||||
|
$this->categories->removeElement($category);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,222 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Delete;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\Link;
|
||||||
|
use ApiPlatform\Metadata\Patch;
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientContactProcessor;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientContactRepository;
|
||||||
|
use App\Shared\Domain\Attribute\Auditable;
|
||||||
|
use App\Shared\Domain\Contract\BlamableInterface;
|
||||||
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||||
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contact d'un client (1:n) — onglet Contact. Au moins firstName OU lastName
|
||||||
|
* doit etre renseigne (RG-1.05) : la contrainte est portee par un CHECK BDD
|
||||||
|
* (chk_client_contact_name) et validee dans le ClientContactProcessor ;
|
||||||
|
* l'entite reste permissive (les deux champs sont nullable).
|
||||||
|
*
|
||||||
|
* Audite (#[Auditable]) + Timestampable/Blamable (pattern Shared standard).
|
||||||
|
*
|
||||||
|
* Sous-ressource API (ERP-57, spec § 4.5) :
|
||||||
|
* - POST /api/clients/{clientId}/contacts : creation rattachee au client parent
|
||||||
|
* (Link toProperty 'client'), security commercial.clients.manage.
|
||||||
|
* - PATCH / DELETE /api/client_contacts/{id} : security commercial.clients.manage.
|
||||||
|
* Le DELETE est physique (sous-collection, pas le client) ; le processor
|
||||||
|
* refuse la suppression du dernier contact (RG-1.14, 409).
|
||||||
|
* - GET /api/client_contacts/{id} : lecture unitaire (security view) — la
|
||||||
|
* lecture courante reste via le parent (client embarque ses contacts). Pas de
|
||||||
|
* GET collection autonome : non concernee par la pagination ERP-72.
|
||||||
|
* Tout passe par le ClientContactProcessor (normalisation RG-1.19/1.20/1.21).
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['client_contact:read']],
|
||||||
|
),
|
||||||
|
new Post(
|
||||||
|
uriTemplate: '/clients/{clientId}/contacts',
|
||||||
|
uriVariables: [
|
||||||
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
||||||
|
],
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client_contact:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client_contact:write']],
|
||||||
|
processor: ClientContactProcessor::class,
|
||||||
|
),
|
||||||
|
new Patch(
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client_contact:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client_contact:write']],
|
||||||
|
processor: ClientContactProcessor::class,
|
||||||
|
),
|
||||||
|
new Delete(
|
||||||
|
security: "is_granted('commercial.clients.manage')",
|
||||||
|
processor: ClientContactProcessor::class,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrineClientContactRepository::class)]
|
||||||
|
#[ORM\Table(name: 'client_contact')]
|
||||||
|
#[ORM\Index(name: 'idx_client_contact_client', columns: ['client_id'])]
|
||||||
|
#[Auditable]
|
||||||
|
class ClientContact implements TimestampableInterface, BlamableInterface
|
||||||
|
{
|
||||||
|
use TimestampableBlamableTrait;
|
||||||
|
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['client_contact:read'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Client::class, inversedBy: 'contacts')]
|
||||||
|
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||||
|
private ?Client $client = null;
|
||||||
|
|
||||||
|
// RG-1.05 : firstName OU lastName obligatoire (CHECK BDD + Processor). Les
|
||||||
|
// deux restent nullable au niveau ORM.
|
||||||
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
|
#[Assert\Length(max: 120, normalizer: 'trim')]
|
||||||
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
|
private ?string $firstName = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
|
#[Assert\Length(max: 120, normalizer: 'trim')]
|
||||||
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
|
private ?string $lastName = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120, nullable: true)]
|
||||||
|
#[Assert\Length(max: 120, normalizer: 'trim')]
|
||||||
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
|
private ?string $jobTitle = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
|
private ?string $phonePrimary = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 20, nullable: true)]
|
||||||
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
|
private ?string $phoneSecondary = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
|
#[Assert\Email]
|
||||||
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
|
private ?string $email = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
#[Groups(['client_contact:read', 'client_contact:write'])]
|
||||||
|
private int $position = 0;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClient(): ?Client
|
||||||
|
{
|
||||||
|
return $this->client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClient(?Client $client): static
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFirstName(): ?string
|
||||||
|
{
|
||||||
|
return $this->firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFirstName(?string $firstName): static
|
||||||
|
{
|
||||||
|
$this->firstName = $firstName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastName(): ?string
|
||||||
|
{
|
||||||
|
return $this->lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLastName(?string $lastName): static
|
||||||
|
{
|
||||||
|
$this->lastName = $lastName;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getJobTitle(): ?string
|
||||||
|
{
|
||||||
|
return $this->jobTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJobTitle(?string $jobTitle): static
|
||||||
|
{
|
||||||
|
$this->jobTitle = $jobTitle;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhonePrimary(): ?string
|
||||||
|
{
|
||||||
|
return $this->phonePrimary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPhonePrimary(?string $phonePrimary): static
|
||||||
|
{
|
||||||
|
$this->phonePrimary = $phonePrimary;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhoneSecondary(): ?string
|
||||||
|
{
|
||||||
|
return $this->phoneSecondary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPhoneSecondary(?string $phoneSecondary): static
|
||||||
|
{
|
||||||
|
$this->phoneSecondary = $phoneSecondary;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmail(): ?string
|
||||||
|
{
|
||||||
|
return $this->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEmail(?string $email): static
|
||||||
|
{
|
||||||
|
$this->email = $email;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(int $position): static
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Delete;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\Link;
|
||||||
|
use ApiPlatform\Metadata\Patch;
|
||||||
|
use ApiPlatform\Metadata\Post;
|
||||||
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientRibProcessor;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientRibRepository;
|
||||||
|
use App\Shared\Domain\Attribute\Auditable;
|
||||||
|
use App\Shared\Domain\Contract\BlamableInterface;
|
||||||
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||||
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coordonnees bancaires d'un client (1:n) — onglet Comptabilite. Au moins un
|
||||||
|
* RIB est obligatoire si le type de reglement du client est LCR (RG-1.13,
|
||||||
|
* verifie au ClientRibProcessor : refus du DELETE du dernier RIB sous LCR).
|
||||||
|
*
|
||||||
|
* Audit (#[Auditable]) : TOUS les champs sont audites, y compris `iban` et
|
||||||
|
* `bic` — AUCUN #[AuditIgnore] (decision Matthieu en revue MR 29/05/2026 :
|
||||||
|
* l'audit etant admin-only, la tracabilite RIB est necessaire pour le suivi
|
||||||
|
* comptable et la conformite, cf. spec § 2.5 / § 6.1).
|
||||||
|
*
|
||||||
|
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony au M1
|
||||||
|
* (HP-M2-14 : pas de controle externe banque reelle). Timestampable/Blamable
|
||||||
|
* standard.
|
||||||
|
*
|
||||||
|
* Sous-ressource API (ERP-57, spec § 4.5) — gating comptable renforce :
|
||||||
|
* - POST /api/clients/{clientId}/ribs : creation rattachee au client parent
|
||||||
|
* (Link toProperty 'client'), security commercial.clients.accounting.manage.
|
||||||
|
* - PATCH / DELETE /api/client_ribs/{id} : security commercial.clients.accounting.manage.
|
||||||
|
* - GET /api/client_ribs/{id} : lecture unitaire, security
|
||||||
|
* commercial.clients.accounting.view (donnees bancaires sensibles). Pas de
|
||||||
|
* GET collection autonome.
|
||||||
|
* Tout passe par le ClientRibProcessor (RG-1.13 sur DELETE).
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.accounting.view')",
|
||||||
|
normalizationContext: ['groups' => ['client_rib:read']],
|
||||||
|
),
|
||||||
|
new Post(
|
||||||
|
uriTemplate: '/clients/{clientId}/ribs',
|
||||||
|
uriVariables: [
|
||||||
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
||||||
|
],
|
||||||
|
security: "is_granted('commercial.clients.accounting.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client_rib:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client_rib:write']],
|
||||||
|
processor: ClientRibProcessor::class,
|
||||||
|
),
|
||||||
|
new Patch(
|
||||||
|
security: "is_granted('commercial.clients.accounting.manage')",
|
||||||
|
normalizationContext: ['groups' => ['client_rib:read']],
|
||||||
|
denormalizationContext: ['groups' => ['client_rib:write']],
|
||||||
|
processor: ClientRibProcessor::class,
|
||||||
|
),
|
||||||
|
new Delete(
|
||||||
|
security: "is_granted('commercial.clients.accounting.manage')",
|
||||||
|
processor: ClientRibProcessor::class,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrineClientRibRepository::class)]
|
||||||
|
#[ORM\Table(name: 'client_rib')]
|
||||||
|
#[ORM\Index(name: 'idx_client_rib_client', columns: ['client_id'])]
|
||||||
|
#[Auditable]
|
||||||
|
class ClientRib implements TimestampableInterface, BlamableInterface
|
||||||
|
{
|
||||||
|
use TimestampableBlamableTrait;
|
||||||
|
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['client_rib:read'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Client::class, inversedBy: 'ribs')]
|
||||||
|
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||||
|
private ?Client $client = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Assert\Length(max: 120, normalizer: 'trim')]
|
||||||
|
#[Groups(['client_rib:read', 'client_rib:write'])]
|
||||||
|
private ?string $label = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 20)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Assert\Bic]
|
||||||
|
#[Groups(['client_rib:read', 'client_rib:write'])]
|
||||||
|
private ?string $bic = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 34)]
|
||||||
|
#[Assert\NotBlank]
|
||||||
|
#[Assert\Iban]
|
||||||
|
#[Groups(['client_rib:read', 'client_rib:write'])]
|
||||||
|
private ?string $iban = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
#[Groups(['client_rib:read', 'client_rib:write'])]
|
||||||
|
private int $position = 0;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClient(): ?Client
|
||||||
|
{
|
||||||
|
return $this->client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClient(?Client $client): static
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel(): ?string
|
||||||
|
{
|
||||||
|
return $this->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLabel(string $label): static
|
||||||
|
{
|
||||||
|
$this->label = $label;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBic(): ?string
|
||||||
|
{
|
||||||
|
return $this->bic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBic(string $bic): static
|
||||||
|
{
|
||||||
|
$this->bic = $bic;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIban(): ?string
|
||||||
|
{
|
||||||
|
return $this->iban;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIban(string $iban): static
|
||||||
|
{
|
||||||
|
$this->iban = $iban;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(int $position): static
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrinePaymentDelayRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delai de reglement applique a un client (15 jours, 30 jours, a reception) :
|
||||||
|
* referentiel statique seede par la migration M1 et re-seede en dev/test par
|
||||||
|
* CommercialReferentialFixtures.
|
||||||
|
*
|
||||||
|
* Lecture seule au M1 (HP-M2-2) : GetCollection + Get uniquement (ERP-56),
|
||||||
|
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
||||||
|
* Timestampable/Blamable (referentiel statique whiteliste dans
|
||||||
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
||||||
|
* `client:read:accounting` permet l'embarquement dans la reponse Client.
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new GetCollection(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['payment_delay:read']],
|
||||||
|
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC.
|
||||||
|
order: ['position' => 'ASC', 'label' => 'ASC'],
|
||||||
|
// ERP-72 : pagination serveur + toggle ?pagination=false (cf. TvaMode).
|
||||||
|
paginationClientEnabled: true,
|
||||||
|
),
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['payment_delay:read']],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrinePaymentDelayRepository::class)]
|
||||||
|
#[ORM\Table(name: 'payment_delay')]
|
||||||
|
#[ORM\UniqueConstraint(name: 'uq_payment_delay_code', columns: ['code'])]
|
||||||
|
class PaymentDelay
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['payment_delay:read', 'client:read:accounting'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 30)]
|
||||||
|
#[Groups(['payment_delay:read', 'client:read:accounting'])]
|
||||||
|
private ?string $code = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120)]
|
||||||
|
#[Groups(['payment_delay:read', 'client:read:accounting'])]
|
||||||
|
private ?string $label = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
#[Groups(['payment_delay:read'])]
|
||||||
|
private int $position = 0;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCode(string $code): static
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel(): ?string
|
||||||
|
{
|
||||||
|
return $this->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLabel(string $label): static
|
||||||
|
{
|
||||||
|
$this->label = $label;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(int $position): static
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrinePaymentTypeRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type de reglement applique a un client (virement, LCR, cheque, non soumise) :
|
||||||
|
* referentiel statique seede par la migration M1 et re-seede en dev/test par
|
||||||
|
* CommercialReferentialFixtures.
|
||||||
|
*
|
||||||
|
* Le `code` porte une semantique metier : VIREMENT impose une banque (RG-1.12),
|
||||||
|
* LCR impose au moins un RIB (RG-1.13).
|
||||||
|
*
|
||||||
|
* Lecture seule au M1 (HP-M2-2) : GetCollection + Get uniquement (ERP-56),
|
||||||
|
* permission commercial.clients.view ; POST/PATCH/DELETE -> 405. Pas de
|
||||||
|
* Timestampable/Blamable (referentiel statique whiteliste dans
|
||||||
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED). Le groupe
|
||||||
|
* `client:read:accounting` permet l'embarquement dans la reponse Client.
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new GetCollection(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['payment_type:read']],
|
||||||
|
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC.
|
||||||
|
order: ['position' => 'ASC', 'label' => 'ASC'],
|
||||||
|
// ERP-72 : pagination serveur + toggle ?pagination=false (cf. TvaMode).
|
||||||
|
paginationClientEnabled: true,
|
||||||
|
),
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['payment_type:read']],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrinePaymentTypeRepository::class)]
|
||||||
|
#[ORM\Table(name: 'payment_type')]
|
||||||
|
#[ORM\UniqueConstraint(name: 'uq_payment_type_code', columns: ['code'])]
|
||||||
|
class PaymentType
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['payment_type:read', 'client:read:accounting'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 30)]
|
||||||
|
#[Groups(['payment_type:read', 'client:read:accounting'])]
|
||||||
|
private ?string $code = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120)]
|
||||||
|
#[Groups(['payment_type:read', 'client:read:accounting'])]
|
||||||
|
private ?string $label = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
#[Groups(['payment_type:read'])]
|
||||||
|
private int $position = 0;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCode(string $code): static
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel(): ?string
|
||||||
|
{
|
||||||
|
return $this->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLabel(string $label): static
|
||||||
|
{
|
||||||
|
$this->label = $label;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(int $position): static
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineTvaModeRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mode de TVA applique a un client (France ventes, Export, Intracom) :
|
||||||
|
* referentiel statique seede par la migration M1 (Version20260601000000) et
|
||||||
|
* re-seede en dev/test par CommercialReferentialFixtures.
|
||||||
|
*
|
||||||
|
* Lecture seule au M1 (HP-M2-2) : seules GetCollection et Get sont exposees
|
||||||
|
* (ERP-56), sous la permission commercial.clients.view ; aucune ecriture
|
||||||
|
* declaree -> POST/PATCH/DELETE renvoient 405.
|
||||||
|
*
|
||||||
|
* Referentiel statique : pas de Timestampable/Blamable (whiteliste dans
|
||||||
|
* EntitiesAreTimestampableBlamableTest::EXCLUDED, comme CategoryType). Le
|
||||||
|
* groupe `client:read:accounting` permet d'embarquer le mode dans la reponse
|
||||||
|
* d'un Client (onglet Comptabilite) au lieu d'un IRI.
|
||||||
|
*/
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new GetCollection(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['tva_mode:read']],
|
||||||
|
// Tri par defaut spec M1 § 4.7 : position ASC puis label ASC
|
||||||
|
// (ordre des selecteurs comptables) — provider Doctrine par defaut.
|
||||||
|
order: ['position' => 'ASC', 'label' => 'ASC'],
|
||||||
|
// ERP-72 : pagination serveur sur toute collection autonome. Le
|
||||||
|
// toggle client est desactive globalement, on l'active ici pour
|
||||||
|
// permettre ?pagination=false (alimenter un <MalioSelect> entier).
|
||||||
|
paginationClientEnabled: true,
|
||||||
|
),
|
||||||
|
new Get(
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
normalizationContext: ['groups' => ['tva_mode:read']],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
security: "is_granted('commercial.clients.view')",
|
||||||
|
)]
|
||||||
|
#[ORM\Entity(repositoryClass: DoctrineTvaModeRepository::class)]
|
||||||
|
#[ORM\Table(name: 'tva_mode')]
|
||||||
|
#[ORM\UniqueConstraint(name: 'uq_tva_mode_code', columns: ['code'])]
|
||||||
|
class TvaMode
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
#[Groups(['tva_mode:read', 'client:read:accounting'])]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 30)]
|
||||||
|
#[Groups(['tva_mode:read', 'client:read:accounting'])]
|
||||||
|
private ?string $code = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 120)]
|
||||||
|
#[Groups(['tva_mode:read', 'client:read:accounting'])]
|
||||||
|
private ?string $label = null;
|
||||||
|
|
||||||
|
#[ORM\Column(options: ['default' => 0])]
|
||||||
|
#[Groups(['tva_mode:read'])]
|
||||||
|
private int $position = 0;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCode(string $code): static
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel(): ?string
|
||||||
|
{
|
||||||
|
return $this->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLabel(string $label): static
|
||||||
|
{
|
||||||
|
$this->label = $label;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): int
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(int $position): static
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Bank;
|
||||||
|
|
||||||
|
interface BankRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?Bank;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne toutes les banques triees position ASC puis label ASC.
|
||||||
|
*
|
||||||
|
* @return list<Bank>
|
||||||
|
*/
|
||||||
|
public function findAllOrdered(): array;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
||||||
|
|
||||||
|
interface ClientAddressRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?ClientAddress;
|
||||||
|
|
||||||
|
public function save(ClientAddress $address): void;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientContact;
|
||||||
|
|
||||||
|
interface ClientContactRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?ClientContact;
|
||||||
|
|
||||||
|
public function save(ClientContact $contact): void;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
||||||
|
interface ClientRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?Client;
|
||||||
|
|
||||||
|
public function save(Client $client): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construit un QueryBuilder de liste pour le repertoire clients.
|
||||||
|
* - Exclut toujours les clients soft-deletes (deleted_at IS NOT NULL, RG-1.24).
|
||||||
|
* - Exclut les archives sauf si $includeArchived = true (RG-1.25).
|
||||||
|
* - Tri par defaut : companyName ASC (RG-1.26).
|
||||||
|
* - $search : recherche fuzzy insensible a la casse sur companyName +
|
||||||
|
* lastName + email (metacaracteres LIKE echappes). Ignore si null/vide.
|
||||||
|
* - $categoryType : restreint aux clients possedant au moins une categorie
|
||||||
|
* du type donne (code). Ignore si null/vide.
|
||||||
|
*
|
||||||
|
* Filtrage centralise ICI (et non dans les providers/controllers) pour que
|
||||||
|
* la liste paginee (ClientProvider) et l'export (ClientExportController)
|
||||||
|
* partagent strictement la meme logique de selection.
|
||||||
|
*/
|
||||||
|
public function createListQueryBuilder(
|
||||||
|
bool $includeArchived = false,
|
||||||
|
?string $search = null,
|
||||||
|
?string $categoryType = null,
|
||||||
|
): QueryBuilder;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientRib;
|
||||||
|
|
||||||
|
interface ClientRibRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?ClientRib;
|
||||||
|
|
||||||
|
public function save(ClientRib $rib): void;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentDelay;
|
||||||
|
|
||||||
|
interface PaymentDelayRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?PaymentDelay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne tous les delais de reglement tries position ASC puis label ASC.
|
||||||
|
*
|
||||||
|
* @return list<PaymentDelay>
|
||||||
|
*/
|
||||||
|
public function findAllOrdered(): array;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentType;
|
||||||
|
|
||||||
|
interface PaymentTypeRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?PaymentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne tous les types de reglement tries position ASC puis label ASC.
|
||||||
|
*
|
||||||
|
* @return list<PaymentType>
|
||||||
|
*/
|
||||||
|
public function findAllOrdered(): array;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\TvaMode;
|
||||||
|
|
||||||
|
interface TvaModeRepositoryInterface
|
||||||
|
{
|
||||||
|
public function findById(int $id): ?TvaMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne tous les modes de TVA tries position ASC puis label ASC
|
||||||
|
* (ordre des selecteurs, reutilise par la fixture de re-seed).
|
||||||
|
*
|
||||||
|
* @return list<TvaMode>
|
||||||
|
*/
|
||||||
|
public function findAllOrdered(): array;
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\Serializer;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\IriConverterInterface;
|
||||||
|
use App\Shared\Domain\Contract\CategoryInterface;
|
||||||
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Denormalise un IRI (`/api/categories/{id}`) vers la Category concrete quand la
|
||||||
|
* propriete cible est type-hintee par le contrat CategoryInterface (ex:
|
||||||
|
* Client::$categories, ClientAddress::$categories).
|
||||||
|
*
|
||||||
|
* Pourquoi ce denormalizer : API Platform deduit le type de l'element de
|
||||||
|
* collection depuis le phpdoc `@var Collection<int, CategoryInterface>`, donc
|
||||||
|
* l'INTERFACE. Or le serializer ne sait pas denormaliser un IRI vers une
|
||||||
|
* interface (« Could not denormalize object of type CategoryInterface[] ») : il
|
||||||
|
* lui faut une classe-ressource concrete. On resout donc l'IRI via l'IriConverter
|
||||||
|
* (qui retourne la Category mappee a la route) sans importer Category — la regle
|
||||||
|
* ABSOLUE n°1 reste respectee (dependance au seul contrat Shared + API Platform).
|
||||||
|
*
|
||||||
|
* En lecture (normalisation), aucun probleme : l'objet reel EST une Category,
|
||||||
|
* resource a part entiere, serialisee en IRI par le normalizer standard.
|
||||||
|
*/
|
||||||
|
final class CategoryReferenceDenormalizer implements DenormalizerInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly IriConverterInterface $iriConverter,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): ?CategoryInterface
|
||||||
|
{
|
||||||
|
if (!is_string($data) || '' === $data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getResourceFromIri leve une exception sur IRI invalide -> 400, ce qui
|
||||||
|
// est le comportement attendu pour une reference cassee.
|
||||||
|
$resource = $this->iriConverter->getResourceFromIri($data);
|
||||||
|
|
||||||
|
// IRI syntaxiquement valide mais pointant sur une autre ressource (ex:
|
||||||
|
// '/api/clients/5' la ou une categorie est attendue) : on refuse
|
||||||
|
// explicitement plutot que de retourner null silencieusement, ce qui
|
||||||
|
// perdrait la reference sans erreur. UnexpectedValueException -> 400.
|
||||||
|
if (!$resource instanceof CategoryInterface) {
|
||||||
|
throw new UnexpectedValueException(sprintf(
|
||||||
|
'L\'IRI "%s" ne référence pas une catégorie.',
|
||||||
|
$data,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
|
||||||
|
{
|
||||||
|
// Support base sur le seul type cible : l'ArrayDenormalizer (collection
|
||||||
|
// `CategoryInterface[]`) interroge le support en passant le TABLEAU
|
||||||
|
// complet comme $data avant de deleguer element par element. Tester
|
||||||
|
// is_string($data) ici casserait donc la chaine pour les collections.
|
||||||
|
return CategoryInterface::class === $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<class-string|string, bool>
|
||||||
|
*/
|
||||||
|
public function getSupportedTypes(?string $format): array
|
||||||
|
{
|
||||||
|
return [CategoryInterface::class => true];
|
||||||
|
}
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\Serializer;
|
||||||
|
|
||||||
|
use ApiPlatform\State\SerializerContextBuilderInterface;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decore le context builder de serialisation d'API Platform pour ajouter
|
||||||
|
* DYNAMIQUEMENT le groupe de lecture `client:read:accounting` sur les ressources
|
||||||
|
* Client, uniquement si l'utilisateur courant a la permission
|
||||||
|
* `commercial.clients.accounting.view` (cf. spec-back M1 § 2.7 / § 4.1 / § 4.2).
|
||||||
|
*
|
||||||
|
* Pourquoi un context builder et pas le Provider : un Provider retourne des
|
||||||
|
* donnees mais ne peut pas influencer les groupes de serialisation. Le contexte
|
||||||
|
* de normalisation est construit ici, en amont du serializer — c'est le point
|
||||||
|
* d'extension idiomatique d'API Platform pour conditionner un groupe selon
|
||||||
|
* l'utilisateur. Realise l'intention « ajout conditionnel du groupe accounting »
|
||||||
|
* de la spec.
|
||||||
|
*
|
||||||
|
* S'applique aux operations de LECTURE (normalization) sur Client : liste ET
|
||||||
|
* detail. Sans la permission, les champs comptables (siren, accountNumber,
|
||||||
|
* tvaMode, nTva, paymentDelay, paymentType, bank) ne sont jamais serialises.
|
||||||
|
*/
|
||||||
|
#[AsDecorator('api_platform.serializer.context_builder')]
|
||||||
|
final readonly class ClientReadGroupContextBuilder implements SerializerContextBuilderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[AutowireDecorated]
|
||||||
|
private SerializerContextBuilderInterface $decorated,
|
||||||
|
private Security $security,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function createFromRequest(Request $request, bool $normalization, ?array $extractedAttributes = null): array
|
||||||
|
{
|
||||||
|
$context = $this->decorated->createFromRequest($request, $normalization, $extractedAttributes);
|
||||||
|
|
||||||
|
// Uniquement en lecture, sur la ressource Client, avec la permission.
|
||||||
|
if (!$normalization) {
|
||||||
|
return $context;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Client::class !== ($context['resource_class'] ?? null)) {
|
||||||
|
return $context;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->security->isGranted('commercial.clients.accounting.view')) {
|
||||||
|
return $context;
|
||||||
|
}
|
||||||
|
|
||||||
|
$groups = $context['groups'] ?? [];
|
||||||
|
if (!in_array('client:read:accounting', $groups, true)) {
|
||||||
|
$groups[] = 'client:read:accounting';
|
||||||
|
}
|
||||||
|
$context['groups'] = $groups;
|
||||||
|
|
||||||
|
return $context;
|
||||||
|
}
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\Serializer;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\IriConverterInterface;
|
||||||
|
use App\Shared\Domain\Contract\SiteInterface;
|
||||||
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Denormalise un IRI (`/api/sites/{id}`) vers le Site concret quand la propriete
|
||||||
|
* cible est type-hintee par le contrat SiteInterface (ClientAddress::$sites).
|
||||||
|
*
|
||||||
|
* Meme mecanisme que CategoryReferenceDenormalizer : API Platform deduit le type
|
||||||
|
* d'element de collection depuis le phpdoc `@var Collection<int, SiteInterface>`,
|
||||||
|
* donc l'INTERFACE. Le serializer ne sait pas denormaliser un IRI vers une
|
||||||
|
* interface (« Could not denormalize object of type SiteInterface[] ») ; on
|
||||||
|
* resout l'IRI via l'IriConverter (qui retourne le Site mappe a la route) sans
|
||||||
|
* importer la classe Site du module Sites — la regle ABSOLUE n°1 (pas d'import
|
||||||
|
* cross-module) reste respectee : dependance au seul contrat Shared + API Platform.
|
||||||
|
*
|
||||||
|
* En lecture (normalisation), aucun probleme : l'objet reel EST un Site,
|
||||||
|
* ressource a part entiere, serialise en IRI par le normalizer standard.
|
||||||
|
*/
|
||||||
|
final class SiteReferenceDenormalizer implements DenormalizerInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly IriConverterInterface $iriConverter,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): ?SiteInterface
|
||||||
|
{
|
||||||
|
if (!is_string($data) || '' === $data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getResourceFromIri leve une exception sur IRI invalide -> 400, ce qui
|
||||||
|
// est le comportement attendu pour une reference cassee.
|
||||||
|
$resource = $this->iriConverter->getResourceFromIri($data);
|
||||||
|
|
||||||
|
// IRI syntaxiquement valide mais pointant sur une autre ressource : on
|
||||||
|
// refuse explicitement plutot que de retourner null silencieusement.
|
||||||
|
if (!$resource instanceof SiteInterface) {
|
||||||
|
throw new UnexpectedValueException(sprintf(
|
||||||
|
'L\'IRI "%s" ne référence pas un site.',
|
||||||
|
$data,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
|
||||||
|
{
|
||||||
|
// Support base sur le seul type cible : l'ArrayDenormalizer (collection
|
||||||
|
// `SiteInterface[]`) interroge le support en passant le TABLEAU complet
|
||||||
|
// comme $data avant de deleguer element par element. Tester
|
||||||
|
// is_string($data) ici casserait la chaine pour les collections.
|
||||||
|
return SiteInterface::class === $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<class-string|string, bool>
|
||||||
|
*/
|
||||||
|
public function getSupportedTypes(?string $format): array
|
||||||
|
{
|
||||||
|
return [SiteInterface::class => true];
|
||||||
|
}
|
||||||
|
}
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\DeleteOperationInterface;
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
|
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processor d'ecriture de la sous-ressource Adresse d'un client (M1, § 4.5).
|
||||||
|
*
|
||||||
|
* Sequence :
|
||||||
|
* - POST / PATCH : normalisation serveur du billingEmail en lowercase (RG-1.21)
|
||||||
|
* via le ClientFieldNormalizer partage. Les autres regles de l'onglet Adresse
|
||||||
|
* sont deja garanties en amont : RG-1.09 (code postal) et RG-1.10 (>= 1 site)
|
||||||
|
* par des contraintes Assert sur l'entite, RG-1.06/07/08/11 par des CHECK BDD.
|
||||||
|
* - DELETE : aucune regle metier specifique (suppression physique directe).
|
||||||
|
*
|
||||||
|
* La security de l'operation (commercial.clients.manage) est deja appliquee par
|
||||||
|
* API Platform, de meme que la validation Symfony des contraintes d'attribut.
|
||||||
|
*
|
||||||
|
* @implements ProcessorInterface<ClientAddress, null|ClientAddress>
|
||||||
|
*/
|
||||||
|
final class ClientAddressProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
||||||
|
private readonly ProcessorInterface $persistProcessor,
|
||||||
|
#[Autowire(service: 'api_platform.doctrine.orm.state.remove_processor')]
|
||||||
|
private readonly ProcessorInterface $removeProcessor,
|
||||||
|
private readonly ClientFieldNormalizer $normalizer,
|
||||||
|
private readonly EntityManagerInterface $em,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
||||||
|
{
|
||||||
|
if (!$data instanceof ClientAddress) {
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($operation instanceof DeleteOperationInterface) {
|
||||||
|
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->linkParent($data, $uriVariables);
|
||||||
|
$this->normalize($data);
|
||||||
|
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rattache l'adresse au client parent de la sous-ressource POST
|
||||||
|
* (/clients/{clientId}/addresses) : la relation n'est pas peuplee
|
||||||
|
* automatiquement par le Link sur une ecriture. Sur PATCH, no-op.
|
||||||
|
*/
|
||||||
|
private function linkParent(ClientAddress $address, array $uriVariables): void
|
||||||
|
{
|
||||||
|
if (null !== $address->getClient()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientId = $uriVariables['clientId'] ?? null;
|
||||||
|
if (null === $clientId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $clientId instanceof Client
|
||||||
|
? $clientId
|
||||||
|
: $this->em->getRepository(Client::class)->find($clientId);
|
||||||
|
|
||||||
|
if ($client instanceof Client) {
|
||||||
|
$address->setClient($client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalisation serveur (RG-1.21) : email de facturation en minuscules. La
|
||||||
|
* methode est null-safe — une adresse non facturable (billingEmail null)
|
||||||
|
* reste null.
|
||||||
|
*/
|
||||||
|
private function normalize(ClientAddress $address): void
|
||||||
|
{
|
||||||
|
$address->setBillingEmail($this->normalizer->normalizeEmail($address->getBillingEmail()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+151
@@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\DeleteOperationInterface;
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
|
use ApiPlatform\Validator\Exception\ValidationException;
|
||||||
|
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientContact;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processor d'ecriture de la sous-ressource Contact d'un client (M1, § 4.5).
|
||||||
|
*
|
||||||
|
* Sequence :
|
||||||
|
* - POST / PATCH : normalisation serveur (RG-1.19 prenom/nom capitalize,
|
||||||
|
* RG-1.20 telephones reduits aux chiffres, RG-1.21 email lowercase) via le
|
||||||
|
* ClientFieldNormalizer partage (reutilise d'ERP-55), puis validation RG-1.05
|
||||||
|
* (au moins prenom OU nom) avant persistance.
|
||||||
|
* - DELETE : RG-1.14 — la suppression du DERNIER contact d'un client est
|
||||||
|
* refusee (409). Au M1, la completude de l'onglet Contact est purement front
|
||||||
|
* (pas de state machine back) : on garantit seulement qu'un client deja dote
|
||||||
|
* d'un contact n'en soit jamais vide via l'API.
|
||||||
|
*
|
||||||
|
* La security de l'operation (commercial.clients.manage) est deja appliquee par
|
||||||
|
* API Platform en amont. La validation Symfony des contraintes d'attribut
|
||||||
|
* (Assert\Email, Assert\Length...) est jouee avant ce processor.
|
||||||
|
*
|
||||||
|
* @implements ProcessorInterface<ClientContact, null|ClientContact>
|
||||||
|
*/
|
||||||
|
final class ClientContactProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
||||||
|
private readonly ProcessorInterface $persistProcessor,
|
||||||
|
#[Autowire(service: 'api_platform.doctrine.orm.state.remove_processor')]
|
||||||
|
private readonly ProcessorInterface $removeProcessor,
|
||||||
|
private readonly ClientFieldNormalizer $normalizer,
|
||||||
|
private readonly EntityManagerInterface $em,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
||||||
|
{
|
||||||
|
if (!$data instanceof ClientContact) {
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($operation instanceof DeleteOperationInterface) {
|
||||||
|
$this->guardLastContactDeletion($data);
|
||||||
|
|
||||||
|
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->linkParent($data, $uriVariables);
|
||||||
|
$this->normalize($data);
|
||||||
|
$this->validateName($data);
|
||||||
|
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rattache le contact au client parent de la sous-ressource POST
|
||||||
|
* (/clients/{clientId}/contacts). La relation n'est pas peuplee
|
||||||
|
* automatiquement par le Link sur une operation d'ecriture : on resout donc
|
||||||
|
* le parent depuis l'uri variable. Sur PATCH (entite existante), le client
|
||||||
|
* est deja present -> no-op.
|
||||||
|
*/
|
||||||
|
private function linkParent(ClientContact $contact, array $uriVariables): void
|
||||||
|
{
|
||||||
|
if (null !== $contact->getClient()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientId = $uriVariables['clientId'] ?? null;
|
||||||
|
if (null === $clientId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $clientId instanceof Client
|
||||||
|
? $clientId
|
||||||
|
: $this->em->getRepository(Client::class)->find($clientId);
|
||||||
|
|
||||||
|
if ($client instanceof Client) {
|
||||||
|
$contact->setClient($client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalisation serveur (RG-1.19 / 1.20 / 1.21). Toutes les methodes du
|
||||||
|
* normalizer sont null-safe : une chaine vide apres trim devient null.
|
||||||
|
*/
|
||||||
|
private function normalize(ClientContact $contact): void
|
||||||
|
{
|
||||||
|
$contact->setFirstName($this->normalizer->normalizePersonName($contact->getFirstName()));
|
||||||
|
$contact->setLastName($this->normalizer->normalizePersonName($contact->getLastName()));
|
||||||
|
$contact->setPhonePrimary($this->normalizer->normalizePhone($contact->getPhonePrimary()));
|
||||||
|
$contact->setPhoneSecondary($this->normalizer->normalizePhone($contact->getPhoneSecondary()));
|
||||||
|
$contact->setEmail($this->normalizer->normalizeEmail($contact->getEmail()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.05 : au moins le prenom OU le nom est obligatoire (double garde avec
|
||||||
|
* le CHECK BDD chk_client_contact_name — leve un 422 propre plutot qu'une
|
||||||
|
* erreur SQL). Joue apres normalisation, donc les chaines vides sont deja
|
||||||
|
* ramenees a null.
|
||||||
|
*/
|
||||||
|
private function validateName(ClientContact $contact): void
|
||||||
|
{
|
||||||
|
if (null === $contact->getFirstName() && null === $contact->getLastName()) {
|
||||||
|
$violations = new ConstraintViolationList();
|
||||||
|
$violations->add(new ConstraintViolation(
|
||||||
|
'Le prénom ou le nom du contact est obligatoire.',
|
||||||
|
null,
|
||||||
|
[],
|
||||||
|
$contact,
|
||||||
|
'firstName',
|
||||||
|
null,
|
||||||
|
));
|
||||||
|
|
||||||
|
throw new ValidationException($violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.14 : refuse la suppression du dernier contact d'un client (409). La
|
||||||
|
* collection inclut le contact en cours de suppression : un effectif <= 1
|
||||||
|
* signifie qu'il ne resterait aucun contact. Sans client rattache (cas
|
||||||
|
* theorique), on laisse passer.
|
||||||
|
*/
|
||||||
|
private function guardLastContactDeletion(ClientContact $contact): void
|
||||||
|
{
|
||||||
|
$client = $contact->getClient();
|
||||||
|
if (null === $client) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($client->getContacts()->count() <= 1) {
|
||||||
|
throw new ConflictHttpException(
|
||||||
|
'Impossible de supprimer le dernier contact du client : au moins un contact est requis.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,638 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
|
use ApiPlatform\Validator\Exception\ValidationException;
|
||||||
|
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
||||||
|
use App\Module\Commercial\Application\Validator\ClientInformationCompletenessValidator;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use App\Shared\Domain\Contract\BusinessRoleAwareInterface;
|
||||||
|
use App\Shared\Domain\Contract\CategoryInterface;
|
||||||
|
use App\Shared\Domain\Security\BusinessRoles;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\PersistentCollection;
|
||||||
|
use JsonException;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processor d'ecriture du repertoire clients (M1). Cf. spec-back M1 § 2.8 /
|
||||||
|
* § 2.9 / § 4.3 / § 4.4 + RG-1.01 a RG-1.28.
|
||||||
|
*
|
||||||
|
* Sequence (POST / PATCH) :
|
||||||
|
* 1. Autorisation additionnelle par groupe d'onglet. La security d'operation
|
||||||
|
* du PATCH a ete elargie (ERP-74) a `manage` OU `accounting.manage` pour
|
||||||
|
* laisser entrer le role Compta ; ce processor re-gate alors finement :
|
||||||
|
* - champ comptable modifie dans le payload -> exige accounting.manage (RG-1.28, 403) ;
|
||||||
|
* - champ main/information modifie -> exige manage (guardManage, 403) : empeche
|
||||||
|
* Compta d'editer un autre onglet que la Comptabilite (§ 2.7) ;
|
||||||
|
* - champ isArchived dans le payload -> exige archive (RG-1.22, 403) et
|
||||||
|
* interdit toute autre modification dans la meme requete (RG-1.22, 422).
|
||||||
|
* 2. Normalisation serveur (RG-1.18 a 1.21) via ClientFieldNormalizer.
|
||||||
|
* 3. Regles metier : RG-1.01 (prenom/nom), RG-1.03 (distributor/broker
|
||||||
|
* exclusifs + type de categorie), RG-1.12 (Virement -> banque),
|
||||||
|
* RG-1.13 (LCR -> >= 1 RIB), RG-1.04 (completude Information exigee sur POST
|
||||||
|
* et tout PATCH pour le role Commerciale).
|
||||||
|
* 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
|
||||||
|
* collisions d'unicite en 409 (RG-1.16 doublon de nom ; RG-1.23 conflit de
|
||||||
|
* restauration).
|
||||||
|
*
|
||||||
|
* Note : la validation Symfony (Assert\NotBlank, Assert\Email, Assert\Count sur
|
||||||
|
* categories...) est jouee par API Platform AVANT ce processor ; on n'y traite
|
||||||
|
* donc que les regles non exprimables en simples contraintes d'attribut.
|
||||||
|
*
|
||||||
|
* @implements ProcessorInterface<Client, Client>
|
||||||
|
*/
|
||||||
|
final class ClientProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
/** Champs de l'onglet principal (groupe client:write:main). */
|
||||||
|
private const array MAIN_FIELDS = [
|
||||||
|
'companyName', 'firstName', 'lastName', 'phonePrimary', 'phoneSecondary',
|
||||||
|
'email', 'distributor', 'broker', 'triageService', 'categories',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** Champs de l'onglet Information (groupe client:write:information). */
|
||||||
|
private const array INFORMATION_FIELDS = [
|
||||||
|
'description', 'competitors', 'foundedAt', 'employeesCount',
|
||||||
|
'revenueAmount', 'directorName', 'profitAmount',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** Champs de l'onglet Comptabilite (groupe client:write:accounting). */
|
||||||
|
private const array ACCOUNTING_FIELDS = [
|
||||||
|
'siren', 'accountNumber', 'tvaMode', 'nTva', 'paymentDelay',
|
||||||
|
'paymentType', 'bank',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** Champ d'archivage (groupe client:write:archive). */
|
||||||
|
private const string ARCHIVE_FIELD = 'isArchived';
|
||||||
|
|
||||||
|
private const string PERM_MANAGE = 'commercial.clients.manage';
|
||||||
|
private const string PERM_ACCOUNTING_MANAGE = 'commercial.clients.accounting.manage';
|
||||||
|
private const string PERM_ARCHIVE = 'commercial.clients.archive';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memoisation du dernier corps de requete decode, clos par le contenu brut.
|
||||||
|
* payloadKeys() est appele plusieurs fois par requete (writablePayloadKeys,
|
||||||
|
* categoriesChanged...) : on evite de rejouer json_decode a chaque appel. La
|
||||||
|
* cle etant le contenu lui-meme et le calcul une fonction pure de ce contenu,
|
||||||
|
* aucune fuite n'est possible entre requetes sur ce service partage (un meme
|
||||||
|
* corps redonne les memes cles).
|
||||||
|
*/
|
||||||
|
private ?string $decodedContent = null;
|
||||||
|
|
||||||
|
/** @var list<string> Cles de premier niveau correspondant au corps memoise. */
|
||||||
|
private array $decodedPayloadKeys = [];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
||||||
|
private readonly ProcessorInterface $persistProcessor,
|
||||||
|
private readonly ClientFieldNormalizer $normalizer,
|
||||||
|
private readonly ClientInformationCompletenessValidator $informationValidator,
|
||||||
|
private readonly Security $security,
|
||||||
|
private readonly RequestStack $requestStack,
|
||||||
|
private readonly EntityManagerInterface $em,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
||||||
|
{
|
||||||
|
if (!$data instanceof Client) {
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
$writableKeys = $this->writablePayloadKeys();
|
||||||
|
|
||||||
|
$isArchiveRequest = $this->guardArchive($data, $writableKeys);
|
||||||
|
$this->guardAccounting($data);
|
||||||
|
|
||||||
|
$this->normalize($data);
|
||||||
|
|
||||||
|
// guardManage apres normalize : la comparaison « change vs etat
|
||||||
|
// persiste » des champs texte (companyName, email...) se fait sur des
|
||||||
|
// valeurs normalisees des deux cotes (l'etat persiste l'a deja ete).
|
||||||
|
$this->guardManage($data);
|
||||||
|
|
||||||
|
$this->validateMainContact($data);
|
||||||
|
$this->validateDistributorBroker($data);
|
||||||
|
$this->validateAccountingConsistency($data);
|
||||||
|
$this->validateInformationCompleteness($data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
} catch (UniqueConstraintViolationException $e) {
|
||||||
|
// Le seul index unique partiel est uq_client_company_name_active
|
||||||
|
// (LOWER(company_name) parmi non-archives/non-deletes — decision Q4).
|
||||||
|
if ($isArchiveRequest && false === $data->isArchived()) {
|
||||||
|
// RG-1.23 : restauration en conflit avec un homonyme actif.
|
||||||
|
throw new ConflictHttpException(
|
||||||
|
'Restauration impossible : un autre client a pris le nom entre-temps.',
|
||||||
|
$e,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-1.16 : doublon de nom de societe.
|
||||||
|
throw new ConflictHttpException(
|
||||||
|
sprintf('Un client nommé "%s" existe déjà.', (string) $data->getCompanyName()),
|
||||||
|
$e,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.22 / RG-1.23 : si le payload bascule reellement isArchived, exige la
|
||||||
|
* permission archive (403), interdit toute autre modification (422) et
|
||||||
|
* pose/retire archivedAt. Retourne true si la requete est une requete
|
||||||
|
* d'archivage.
|
||||||
|
*
|
||||||
|
* Le gating est restreint a la mise a jour d'un client existant ET au seul
|
||||||
|
* cas ou isArchived change vraiment : un POST (entite non encore geree par
|
||||||
|
* l'ORM) ou un PATCH « representation complete » renvoyant isArchived
|
||||||
|
* inchange ne doit declencher ni 403 ni 422 parasite.
|
||||||
|
*
|
||||||
|
* @param list<string> $writableKeys cles ecrivables du payload (hors @* et champs inconnus)
|
||||||
|
*/
|
||||||
|
private function guardArchive(Client $data, array $writableKeys): bool
|
||||||
|
{
|
||||||
|
// POST / entite non geree : l'archivage est une action de mise a jour.
|
||||||
|
if (!$this->em->contains($data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// isArchived inchange par rapport a l'etat persiste : pas une requete
|
||||||
|
// d'archivage (cas du PATCH representation complete).
|
||||||
|
if (!$this->fieldChanged($data, 'isArchived', $data->isArchived())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->security->isGranted(self::PERM_ARCHIVE)) {
|
||||||
|
throw new AccessDeniedHttpException(sprintf(
|
||||||
|
'Le champ "%s" requiert la permission "%s".',
|
||||||
|
self::ARCHIVE_FIELD,
|
||||||
|
self::PERM_ARCHIVE,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-1.22 : une requete d'archivage ne modifie aucun autre champ ecrivable.
|
||||||
|
if ([] !== array_diff($writableKeys, [self::ARCHIVE_FIELD])) {
|
||||||
|
throw new UnprocessableEntityHttpException(
|
||||||
|
'Une requête d\'archivage ne peut modifier aucun autre champ que "isArchived".',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-1.22 (true -> now) / RG-1.23 (false -> null).
|
||||||
|
$data->setArchivedAt($data->isArchived() ? new DateTimeImmutable() : null);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.28 : la modification effective d'un champ comptable exige
|
||||||
|
* accounting.manage, sinon 403 sur l'ensemble du payload (mode strict, pas
|
||||||
|
* de filtrage silencieux). On ne gate que si un champ change reellement par
|
||||||
|
* rapport a l'etat persiste : un POST/PATCH renvoyant des champs comptables
|
||||||
|
* inchanges (ou null en creation) ne declenche pas de 403 parasite. Le
|
||||||
|
* message precise le premier champ fautif.
|
||||||
|
*/
|
||||||
|
private function guardAccounting(Client $data): void
|
||||||
|
{
|
||||||
|
$changed = $this->changedAccountingFields($data);
|
||||||
|
|
||||||
|
if ([] === $changed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->security->isGranted(self::PERM_ACCOUNTING_MANAGE)) {
|
||||||
|
throw new AccessDeniedHttpException(sprintf(
|
||||||
|
'Le champ "%s" requiert la permission "%s".',
|
||||||
|
$changed[0],
|
||||||
|
self::PERM_ACCOUNTING_MANAGE,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* § 2.7 / RG-1.28 (ERP-74) : la modification effective d'un champ « metier »
|
||||||
|
* (onglets principal ou Information) exige `commercial.clients.manage`. Sans
|
||||||
|
* cette permission -> 403 sur l'ensemble du payload (mode strict, miroir de
|
||||||
|
* guardAccounting). C'est ce qui empeche le role Compta — qui entre dans le
|
||||||
|
* PATCH via `accounting.manage` (security d'operation elargie) — d'editer
|
||||||
|
* autre chose que l'onglet Comptabilite.
|
||||||
|
*
|
||||||
|
* Ne s'applique qu'aux mises a jour (entite geree) : la creation (POST) est
|
||||||
|
* deja gardee par la security d'operation `manage`, donc inutile de la
|
||||||
|
* re-gater ici (et un POST par un porteur de `manage` passerait de toute
|
||||||
|
* facon).
|
||||||
|
*/
|
||||||
|
private function guardManage(Client $data): void
|
||||||
|
{
|
||||||
|
if (!$this->em->contains($data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$changed = $this->changedBusinessFields($data);
|
||||||
|
|
||||||
|
if ([] === $changed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->security->isGranted(self::PERM_MANAGE)) {
|
||||||
|
throw new AccessDeniedHttpException(sprintf(
|
||||||
|
'Le champ "%s" requiert la permission "%s".',
|
||||||
|
$changed[0],
|
||||||
|
self::PERM_MANAGE,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Champs « metier » (onglets principal + Information, hors comptabilite et
|
||||||
|
* archivage) dont la valeur courante differe de l'etat persiste. Memes
|
||||||
|
* regles de comparaison que changedAccountingFields (scalaires par valeur,
|
||||||
|
* relations ManyToOne distributor/broker par identite via l'identity map).
|
||||||
|
*
|
||||||
|
* Cas particulier `categories` (M2M) : non trace par getOriginalEntityData,
|
||||||
|
* compare par valeur via le snapshot de la PersistentCollection (cf.
|
||||||
|
* categoriesChanged) — la simple presence dans le payload ne suffit pas, sous
|
||||||
|
* peine de 403 parasite sur un PATCH representation complete reincluant des
|
||||||
|
* categories inchangees.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function changedBusinessFields(Client $data): array
|
||||||
|
{
|
||||||
|
$newValues = [
|
||||||
|
'companyName' => $data->getCompanyName(),
|
||||||
|
'firstName' => $data->getFirstName(),
|
||||||
|
'lastName' => $data->getLastName(),
|
||||||
|
'phonePrimary' => $data->getPhonePrimary(),
|
||||||
|
'phoneSecondary' => $data->getPhoneSecondary(),
|
||||||
|
'email' => $data->getEmail(),
|
||||||
|
'distributor' => $data->getDistributor(),
|
||||||
|
'broker' => $data->getBroker(),
|
||||||
|
'triageService' => $data->isTriageService(),
|
||||||
|
'description' => $data->getDescription(),
|
||||||
|
'competitors' => $data->getCompetitors(),
|
||||||
|
'foundedAt' => $data->getFoundedAt(),
|
||||||
|
'employeesCount' => $data->getEmployeesCount(),
|
||||||
|
'revenueAmount' => $data->getRevenueAmount(),
|
||||||
|
'directorName' => $data->getDirectorName(),
|
||||||
|
'profitAmount' => $data->getProfitAmount(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$changed = [];
|
||||||
|
foreach ($newValues as $field => $newValue) {
|
||||||
|
if ($this->fieldChanged($data, $field, $newValue)) {
|
||||||
|
$changed[] = $field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->categoriesChanged($data)) {
|
||||||
|
$changed[] = 'categories';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrai si l'ensemble des categories (M2M) differe reellement de l'etat
|
||||||
|
* persiste. La collection n'etant pas tracee par getOriginalEntityData, on
|
||||||
|
* compare par identifiants (independamment de l'ordre) le snapshot de la
|
||||||
|
* PersistentCollection (etat charge depuis la base) a l'etat courant (apres
|
||||||
|
* application du payload). Symetrique de changedAccountingFields : seul un
|
||||||
|
* changement effectif compte, pas la simple presence dans le payload.
|
||||||
|
*
|
||||||
|
* - POST / entite non geree : fournir des categories est un acte metier
|
||||||
|
* (comportement historique conserve) — branche defensive, guardManage ne
|
||||||
|
* s'execute de toute facon que sur entite geree.
|
||||||
|
* - categories absent du payload (PATCH partiel) : aucun changement.
|
||||||
|
*/
|
||||||
|
private function categoriesChanged(Client $data): bool
|
||||||
|
{
|
||||||
|
if (!$this->em->contains($data)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array('categories', $this->payloadKeys(), true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$collection = $data->getCategories();
|
||||||
|
|
||||||
|
// Hors PersistentCollection (cas limite hors flux PATCH reel) : faute
|
||||||
|
// d'etat persiste comparable, on se rabat sur la presence payload.
|
||||||
|
if (!$collection instanceof PersistentCollection) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->categoryIdSet($collection->toArray())
|
||||||
|
!== $this->categoryIdSet($collection->getSnapshot());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensemble trie des identifiants d'une liste de categories — pour une
|
||||||
|
* comparaison par valeur independante de l'ordre.
|
||||||
|
*
|
||||||
|
* @param array<int, object> $categories
|
||||||
|
*
|
||||||
|
* @return list<mixed>
|
||||||
|
*/
|
||||||
|
private function categoryIdSet(array $categories): array
|
||||||
|
{
|
||||||
|
$ids = array_map(
|
||||||
|
static fn (object $category): mixed => method_exists($category, 'getId')
|
||||||
|
? $category->getId()
|
||||||
|
: spl_object_id($category),
|
||||||
|
array_values($categories),
|
||||||
|
);
|
||||||
|
sort($ids);
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Champs comptables dont la valeur courante differe de l'etat persiste. Les
|
||||||
|
* relations (tvaMode, paymentDelay, paymentType, bank) sont comparees par
|
||||||
|
* identite d'objet : l'identity map Doctrine renvoie la meme instance tant
|
||||||
|
* que la reference est inchangee.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function changedAccountingFields(Client $data): array
|
||||||
|
{
|
||||||
|
$changed = [];
|
||||||
|
|
||||||
|
foreach (self::ACCOUNTING_FIELDS as $field) {
|
||||||
|
$newValue = match ($field) {
|
||||||
|
'siren' => $data->getSiren(),
|
||||||
|
'accountNumber' => $data->getAccountNumber(),
|
||||||
|
'tvaMode' => $data->getTvaMode(),
|
||||||
|
'nTva' => $data->getNTva(),
|
||||||
|
'paymentDelay' => $data->getPaymentDelay(),
|
||||||
|
'paymentType' => $data->getPaymentType(),
|
||||||
|
'bank' => $data->getBank(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($this->fieldChanged($data, $field, $newValue)) {
|
||||||
|
$changed[] = $field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrai si la valeur courante d'un champ differe de l'etat persiste. Pour une
|
||||||
|
* entite non geree (creation/POST), l'etat persiste est vide : toute valeur
|
||||||
|
* non-null est alors un changement.
|
||||||
|
*/
|
||||||
|
private function fieldChanged(Client $data, string $field, mixed $newValue): bool
|
||||||
|
{
|
||||||
|
$original = $this->originalData($data);
|
||||||
|
|
||||||
|
return $newValue !== ($original[$field] ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Snapshot des valeurs persistees de l'entite (telles que chargees, avant
|
||||||
|
* application du payload). Vide pour une entite non geree (POST).
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function originalData(Client $data): array
|
||||||
|
{
|
||||||
|
if (!$this->em->contains($data)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->em->getUnitOfWork()->getOriginalEntityData($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalisation serveur (RG-1.18 a 1.21). Les setters non-nullables
|
||||||
|
* (companyName, email, phonePrimary) ne sont touches que si une valeur est
|
||||||
|
* presente, pour ne jamais ecraser l'existant lors d'un PATCH partiel.
|
||||||
|
*/
|
||||||
|
private function normalize(Client $data): void
|
||||||
|
{
|
||||||
|
if (null !== $data->getCompanyName()) {
|
||||||
|
$data->setCompanyName((string) $this->normalizer->normalizeCompanyName($data->getCompanyName()));
|
||||||
|
}
|
||||||
|
if (null !== $data->getEmail()) {
|
||||||
|
$data->setEmail((string) $this->normalizer->normalizeEmail($data->getEmail()));
|
||||||
|
}
|
||||||
|
if (null !== $data->getPhonePrimary()) {
|
||||||
|
$data->setPhonePrimary((string) $this->normalizer->normalizePhone($data->getPhonePrimary()));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data->setFirstName($this->normalizer->normalizePersonName($data->getFirstName()));
|
||||||
|
$data->setLastName($this->normalizer->normalizePersonName($data->getLastName()));
|
||||||
|
$data->setPhoneSecondary($this->normalizer->normalizePhone($data->getPhoneSecondary()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.01 : au moins le prenom OU le nom du contact principal.
|
||||||
|
*/
|
||||||
|
private function validateMainContact(Client $data): void
|
||||||
|
{
|
||||||
|
if (null === $data->getFirstName() && null === $data->getLastName()) {
|
||||||
|
$this->throwViolation(
|
||||||
|
'firstName',
|
||||||
|
'Le prénom ou le nom du contact principal est obligatoire.',
|
||||||
|
$data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.03 : distributor et broker mutuellement exclusifs ; un distributor
|
||||||
|
* doit referencer un client de categorie DISTRIBUTEUR (idem broker ->
|
||||||
|
* COURTIER).
|
||||||
|
*/
|
||||||
|
private function validateDistributorBroker(Client $data): void
|
||||||
|
{
|
||||||
|
$distributor = $data->getDistributor();
|
||||||
|
$broker = $data->getBroker();
|
||||||
|
|
||||||
|
if (null !== $distributor && null !== $broker) {
|
||||||
|
$this->throwViolation(
|
||||||
|
'distributor',
|
||||||
|
'Un client ne peut pas être rattaché à la fois à un distributeur et à un courtier.',
|
||||||
|
$data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $distributor && !$this->hasCategoryType($distributor, 'DISTRIBUTEUR')) {
|
||||||
|
$this->throwViolation(
|
||||||
|
'distributor',
|
||||||
|
'Le distributeur référencé doit être un client de catégorie DISTRIBUTEUR.',
|
||||||
|
$data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $broker && !$this->hasCategoryType($broker, 'COURTIER')) {
|
||||||
|
$this->throwViolation(
|
||||||
|
'broker',
|
||||||
|
'Le courtier référencé doit être un client de catégorie COURTIER.',
|
||||||
|
$data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.12 : Virement -> banque obligatoire. RG-1.13 : LCR -> au moins un RIB.
|
||||||
|
*/
|
||||||
|
private function validateAccountingConsistency(Client $data): void
|
||||||
|
{
|
||||||
|
$paymentCode = $data->getPaymentType()?->getCode();
|
||||||
|
|
||||||
|
if ('VIREMENT' === $paymentCode && null === $data->getBank()) {
|
||||||
|
$this->throwViolation(
|
||||||
|
'bank',
|
||||||
|
'La banque est obligatoire pour le type de règlement Virement.',
|
||||||
|
$data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('LCR' === $paymentCode && $data->getRibs()->isEmpty()) {
|
||||||
|
$this->throwViolation(
|
||||||
|
'paymentType',
|
||||||
|
'Au moins un RIB est obligatoire pour le type de règlement LCR.',
|
||||||
|
$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 type donne. S'appuie
|
||||||
|
* sur CategoryInterface::getCategoryTypeCode() (pas d'import de Category).
|
||||||
|
*/
|
||||||
|
private function hasCategoryType(Client $client, string $typeCode): bool
|
||||||
|
{
|
||||||
|
foreach ($client->getCategories() as $category) {
|
||||||
|
if ($category instanceof CategoryInterface && $category->getCategoryTypeCode() === $typeCode) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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
|
||||||
|
* declenchement conditionnel de RG-1.04 — sans elles, un PATCH
|
||||||
|
* « representation complete » porteur de @id ferait croire a une
|
||||||
|
* modification multi-onglets.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function writablePayloadKeys(): array
|
||||||
|
{
|
||||||
|
$writable = array_merge(
|
||||||
|
self::MAIN_FIELDS,
|
||||||
|
self::INFORMATION_FIELDS,
|
||||||
|
self::ACCOUNTING_FIELDS,
|
||||||
|
[self::ARCHIVE_FIELD],
|
||||||
|
);
|
||||||
|
|
||||||
|
return array_values(array_intersect($this->payloadKeys(), $writable));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cles de premier niveau effectivement envoyees par le client (payload JSON
|
||||||
|
* brut), filtrage compris. Pour un PATCH merge-patch+json, ce sont les seuls
|
||||||
|
* champs modifies.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function payloadKeys(): array
|
||||||
|
{
|
||||||
|
$request = $this->requestStack->getCurrentRequest();
|
||||||
|
if (null === $request) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = $request->getContent();
|
||||||
|
|
||||||
|
// Cache hit : meme corps brut que le dernier decodage -> memes cles.
|
||||||
|
if ($content === $this->decodedContent) {
|
||||||
|
return $this->decodedPayloadKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->decodedContent = $content;
|
||||||
|
$this->decodedPayloadKeys = $this->extractPayloadKeys($content);
|
||||||
|
|
||||||
|
return $this->decodedPayloadKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode le corps brut et en extrait les cles de premier niveau (chaines).
|
||||||
|
* Corps vide ou JSON invalide -> aucune cle.
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function extractPayloadKeys(string $content): array
|
||||||
|
{
|
||||||
|
if ('' === $content) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$decoded = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
|
||||||
|
} catch (JsonException) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_array($decoded) ? array_values(array_filter(array_keys($decoded), 'is_string')) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Leve une ValidationException (HTTP 422) portant une violation unique sur
|
||||||
|
* la propriete visee — meme rendu Hydra que les contraintes Symfony.
|
||||||
|
*
|
||||||
|
* @return never
|
||||||
|
*/
|
||||||
|
private function throwViolation(string $property, string $message, Client $root): void
|
||||||
|
{
|
||||||
|
$violations = new ConstraintViolationList();
|
||||||
|
$violations->add(new ConstraintViolation($message, null, [], $root, $property, null));
|
||||||
|
|
||||||
|
throw new ValidationException($violations);
|
||||||
|
}
|
||||||
|
}
|
||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\DeleteOperationInterface;
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientRib;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processor d'ecriture de la sous-ressource RIB d'un client (M1, § 4.5).
|
||||||
|
*
|
||||||
|
* Sequence :
|
||||||
|
* - POST / PATCH : aucune normalisation specifique. La validite de l'IBAN et du
|
||||||
|
* BIC est garantie par Assert\Iban / Assert\Bic sur l'entite (jouees en amont
|
||||||
|
* par API Platform). Aucun #[AuditIgnore] sur iban/bic : la tracabilite
|
||||||
|
* comptable est volontaire (decision Matthieu 29/05, spec § 6.1).
|
||||||
|
* - DELETE : RG-1.13 — si le client est en reglement LCR, la suppression de son
|
||||||
|
* DERNIER RIB est refusee (409), car LCR exige au moins un RIB.
|
||||||
|
*
|
||||||
|
* La security de l'operation (commercial.clients.accounting.manage) est deja
|
||||||
|
* appliquee par API Platform en amont : un utilisateur sans cette permission
|
||||||
|
* recoit 403 sur POST/PATCH/DELETE avant d'atteindre ce processor.
|
||||||
|
*
|
||||||
|
* @implements ProcessorInterface<ClientRib, null|ClientRib>
|
||||||
|
*/
|
||||||
|
final class ClientRibProcessor implements ProcessorInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
||||||
|
private readonly ProcessorInterface $persistProcessor,
|
||||||
|
#[Autowire(service: 'api_platform.doctrine.orm.state.remove_processor')]
|
||||||
|
private readonly ProcessorInterface $removeProcessor,
|
||||||
|
private readonly EntityManagerInterface $em,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
||||||
|
{
|
||||||
|
if (!$data instanceof ClientRib) {
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($operation instanceof DeleteOperationInterface) {
|
||||||
|
$this->guardLastRibDeletionUnderLcr($data);
|
||||||
|
|
||||||
|
return $this->removeProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->linkParent($data, $uriVariables);
|
||||||
|
|
||||||
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rattache le RIB au client parent de la sous-ressource POST
|
||||||
|
* (/clients/{clientId}/ribs) : la relation n'est pas peuplee automatiquement
|
||||||
|
* par le Link sur une ecriture. Sur PATCH, no-op.
|
||||||
|
*/
|
||||||
|
private function linkParent(ClientRib $rib, array $uriVariables): void
|
||||||
|
{
|
||||||
|
if (null !== $rib->getClient()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clientId = $uriVariables['clientId'] ?? null;
|
||||||
|
if (null === $clientId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $clientId instanceof Client
|
||||||
|
? $clientId
|
||||||
|
: $this->em->getRepository(Client::class)->find($clientId);
|
||||||
|
|
||||||
|
if ($client instanceof Client) {
|
||||||
|
$rib->setClient($client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.13 : un client dont le type de reglement est LCR doit conserver au
|
||||||
|
* moins un RIB. La collection inclut le RIB en cours de suppression : un
|
||||||
|
* effectif <= 1 signifie qu'il ne resterait aucun RIB -> 409. Pour tout autre
|
||||||
|
* type de reglement, les RIBs sont optionnels (suppression libre).
|
||||||
|
*/
|
||||||
|
private function guardLastRibDeletionUnderLcr(ClientRib $rib): void
|
||||||
|
{
|
||||||
|
$client = $rib->getClient();
|
||||||
|
if (null === $client) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('LCR' === $client->getPaymentType()?->getCode() && $client->getRibs()->count() <= 1) {
|
||||||
|
throw new ConflictHttpException(
|
||||||
|
'Impossible de supprimer le dernier RIB : le type de règlement LCR exige au moins un RIB.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\ApiPlatform\State\Provider;
|
||||||
|
|
||||||
|
use ApiPlatform\Doctrine\Orm\Paginator;
|
||||||
|
use ApiPlatform\Metadata\CollectionOperationInterface;
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use ApiPlatform\State\Pagination\Pagination;
|
||||||
|
use ApiPlatform\State\ProviderInterface;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use App\Module\Commercial\Domain\Repository\ClientRepositoryInterface;
|
||||||
|
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
|
||||||
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider du repertoire clients (M1). Cf. spec-back M1 § 4.1 / § 4.2.
|
||||||
|
*
|
||||||
|
* Collection (GET /api/clients) :
|
||||||
|
* - exclut par defaut les archives (is_archived = true) ET les soft-deletes
|
||||||
|
* (deleted_at IS NOT NULL) — RG-1.24 ;
|
||||||
|
* - ?includeArchived=true reintegre les archives (les soft-deletes restent
|
||||||
|
* exclus au M1) — RG-1.25 ;
|
||||||
|
* - tri par defaut companyName ASC — RG-1.26 ;
|
||||||
|
* - filtres ?search=... (fuzzy companyName + lastName + email) et
|
||||||
|
* ?categoryType=<code> (clients ayant >= 1 categorie de ce type) ;
|
||||||
|
* - pagination obligatoire (convention Starseed ERP-72) : Paginator ORM ;
|
||||||
|
* echappatoire ?pagination=false pour alimenter un <select> sans pagination.
|
||||||
|
*
|
||||||
|
* Item (GET /api/clients/{id} + provider de PATCH) :
|
||||||
|
* - 404 si introuvable OU soft-delete (deleted_at non null, jamais expose au
|
||||||
|
* M1) ; les archives restent consultables/restaurables en detail.
|
||||||
|
*
|
||||||
|
* Le filtrage des champs comptables en lecture (groupe client:read:accounting)
|
||||||
|
* n'est PAS fait ici mais dans ClientReadGroupContextBuilder (le provider ne
|
||||||
|
* peut pas influencer les groupes de serialisation).
|
||||||
|
*
|
||||||
|
* @implements ProviderInterface<Client>
|
||||||
|
*/
|
||||||
|
final class ClientProvider implements ProviderInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientRepository')]
|
||||||
|
private readonly ClientRepositoryInterface $repository,
|
||||||
|
private readonly Pagination $pagination,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Client|iterable|Paginator|null
|
||||||
|
{
|
||||||
|
if ($operation instanceof CollectionOperationInterface) {
|
||||||
|
return $this->provideCollection($operation, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->provideItem($uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $context
|
||||||
|
*
|
||||||
|
* @return list<Client>|Paginator<Client>
|
||||||
|
*/
|
||||||
|
private function provideCollection(Operation $operation, array $context): array|Paginator
|
||||||
|
{
|
||||||
|
$filters = $context['filters'] ?? [];
|
||||||
|
$includeArchived = $this->readBool($filters['includeArchived'] ?? false);
|
||||||
|
$search = $filters['search'] ?? null;
|
||||||
|
$categoryType = $filters['categoryType'] ?? null;
|
||||||
|
|
||||||
|
// Filtrage delegue au repository (logique partagee avec l'export XLSX).
|
||||||
|
$qb = $this->repository->createListQueryBuilder(
|
||||||
|
$includeArchived,
|
||||||
|
is_string($search) ? $search : null,
|
||||||
|
is_string($categoryType) ? $categoryType : null,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Echappatoire ?pagination=false : collection complete sans Paginator
|
||||||
|
// (cf. convention ERP-72 — utile pour un <select> cote front).
|
||||||
|
if (!$this->pagination->isEnabled($operation, $context)) {
|
||||||
|
// @var list<Client> $result
|
||||||
|
return $qb->getQuery()->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit = $this->pagination->getLimit($operation, $context);
|
||||||
|
$page = max(1, $this->pagination->getPage($context));
|
||||||
|
$offset = ($page - 1) * $limit;
|
||||||
|
|
||||||
|
$qb->setFirstResult($offset)->setMaxResults($limit);
|
||||||
|
|
||||||
|
// fetchJoinCollection: true pour un COUNT correct des que des JOINs
|
||||||
|
// to-many seront ajoutes (sous-collections embarquees en detail).
|
||||||
|
return new Paginator(new DoctrinePaginator($qb->getQuery(), fetchJoinCollection: true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $uriVariables
|
||||||
|
*/
|
||||||
|
private function provideItem(array $uriVariables): ?Client
|
||||||
|
{
|
||||||
|
$id = $uriVariables['id'] ?? null;
|
||||||
|
if (!is_int($id) && !(is_string($id) && ctype_digit($id))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $this->repository->findById((int) $id);
|
||||||
|
if (null === $client) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Soft-delete : jamais expose au M1 (HP-M2-1) — 404 via retour null.
|
||||||
|
// Les archives restent visibles en detail (consultation + restauration).
|
||||||
|
if (null !== $client->getDeletedAt()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lit un flag booleen issu des query params. Accepte true / "true" / "1".
|
||||||
|
*/
|
||||||
|
private function readBool(mixed $raw): bool
|
||||||
|
{
|
||||||
|
if (is_bool($raw)) {
|
||||||
|
return $raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_string($raw) && in_array(strtolower($raw), ['true', '1'], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Controller;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use App\Module\Commercial\Domain\Repository\ClientRepositoryInterface;
|
||||||
|
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 clients (M1, spec-back § 4.6).
|
||||||
|
*
|
||||||
|
* 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/clients/export.xlsx` comme l'item `GET /api/clients/{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 clients (memes filtres que
|
||||||
|
* `GET /api/clients`, via {@see ClientRepositoryInterface::createListQueryBuilder()})
|
||||||
|
* et mapping metier des colonnes.
|
||||||
|
*
|
||||||
|
* La colonne SIREN n'est ajoutee que si l'utilisateur a la permission
|
||||||
|
* `commercial.clients.accounting.view` (gating identique a la lecture).
|
||||||
|
*/
|
||||||
|
#[AsController]
|
||||||
|
final class ClientExportController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Autowire(service: 'App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientRepository')]
|
||||||
|
private readonly ClientRepositoryInterface $repository,
|
||||||
|
private readonly SpreadsheetExporterInterface $exporter,
|
||||||
|
private readonly Security $security,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route('/api/clients/export.xlsx', name: 'commercial_clients_export_xlsx', methods: ['GET'], priority: 1)]
|
||||||
|
#[IsGranted('commercial.clients.view')]
|
||||||
|
public function __invoke(Request $request): Response
|
||||||
|
{
|
||||||
|
$includeArchived = $this->readBool($request->query->get('includeArchived'));
|
||||||
|
$search = $request->query->getString('search') ?: null;
|
||||||
|
$categoryType = $request->query->getString('categoryType') ?: null;
|
||||||
|
|
||||||
|
/** @var list<Client> $clients */
|
||||||
|
$clients = $this->repository
|
||||||
|
->createListQueryBuilder($includeArchived, $search, $categoryType)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
$withSiren = $this->security->isGranted('commercial.clients.accounting.view');
|
||||||
|
|
||||||
|
$binary = $this->exporter->export(
|
||||||
|
'Répertoire clients',
|
||||||
|
$this->buildHeaders($withSiren),
|
||||||
|
$this->buildRows($clients, $withSiren),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->buildResponse($binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Colonnes dans l'ordre impose par la 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 entreprise',
|
||||||
|
'Nom contact principal',
|
||||||
|
'Prénom',
|
||||||
|
'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<Client> $clients
|
||||||
|
*
|
||||||
|
* @return iterable<list<null|scalar>>
|
||||||
|
*/
|
||||||
|
private function buildRows(array $clients, bool $withSiren): iterable
|
||||||
|
{
|
||||||
|
foreach ($clients as $client) {
|
||||||
|
$row = [
|
||||||
|
$client->getCompanyName(),
|
||||||
|
$client->getLastName(),
|
||||||
|
$client->getFirstName(),
|
||||||
|
$client->getPhonePrimary(),
|
||||||
|
$client->getPhoneSecondary(),
|
||||||
|
$client->getEmail(),
|
||||||
|
$this->formatCategories($client),
|
||||||
|
$this->formatSites($client),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($withSiren) {
|
||||||
|
$row[] = $client->getSiren();
|
||||||
|
}
|
||||||
|
|
||||||
|
$row[] = $client->getCreatedAt()?->format('d/m/Y');
|
||||||
|
|
||||||
|
yield $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Libelles des categories du client, dedupliques, tries, joints par virgule.
|
||||||
|
*/
|
||||||
|
private function formatCategories(Client $client): string
|
||||||
|
{
|
||||||
|
$names = [];
|
||||||
|
foreach ($client->getCategories() as $category) {
|
||||||
|
// @var CategoryInterface $category
|
||||||
|
$name = $category->getName();
|
||||||
|
if (null !== $name && '' !== $name) {
|
||||||
|
$names[$name] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->joinSorted($names);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Le Client ne porte pas de sites en propre : ils sont rattaches aux
|
||||||
|
* adresses (RG-1.10). La colonne « Sites » agrege donc l'union distincte des
|
||||||
|
* sites de toutes les adresses du client (decision validee 01/06).
|
||||||
|
*/
|
||||||
|
private function formatSites(Client $client): string
|
||||||
|
{
|
||||||
|
$names = [];
|
||||||
|
foreach ($client->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-clients-%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 ClientProvider pour un comportement identique a la liste.
|
||||||
|
*/
|
||||||
|
private function readBool(mixed $raw): bool
|
||||||
|
{
|
||||||
|
return is_string($raw) && in_array(strtolower($raw), ['true', '1'], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\DataFixtures;
|
||||||
|
|
||||||
|
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\TvaMode;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixtures du module Commercial : re-seed des 4 referentiels comptables
|
||||||
|
* (tva_mode, payment_delay, payment_type, bank) seedes par la migration M1
|
||||||
|
* (Version20260601000000).
|
||||||
|
*
|
||||||
|
* Pourquoi cette fixture EN PLUS du seed de la migration : depuis ERP-54 ces
|
||||||
|
* 4 tables sont des entites managees par l'ORM, donc le purger Doctrine les
|
||||||
|
* vide avant chaque `doctrine:fixtures:load`. Sans cette fixture, les
|
||||||
|
* referentiels seedes par la migration disparaitraient apres `make db-reset`
|
||||||
|
* (0 ligne en dev/test) — cassant les FK Client -> referentiels et les tests
|
||||||
|
* RG-1.12/1.13. Le seed migration couvre la prod (ou les fixtures ne tournent
|
||||||
|
* pas) ; cette fixture re-aligne dev et test. Memes valeurs des deux cotes.
|
||||||
|
*
|
||||||
|
* Idempotence : lookup par `code` avant insertion (sur le modele de
|
||||||
|
* CategoryTypeFixtures). Rejouable sans doublon meme si le purger est desactive.
|
||||||
|
*/
|
||||||
|
class CommercialReferentialFixtures extends Fixture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Source unique des referentiels : classe d'entite => [code => [label, position]].
|
||||||
|
* Doit rester aligne sur le seed de la migration Version20260601000000.
|
||||||
|
*
|
||||||
|
* @var array<class-string, array<string, array{string, int}>>
|
||||||
|
*/
|
||||||
|
private const REFERENTIALS = [
|
||||||
|
TvaMode::class => [
|
||||||
|
'FRANCE_VENTES' => ['France (ventes)', 10],
|
||||||
|
'EXPORT_VENTES' => ['Export (ventes)', 20],
|
||||||
|
'INTRACOM_VENTES' => ['Intracom (ventes)', 30],
|
||||||
|
],
|
||||||
|
PaymentDelay::class => [
|
||||||
|
'J15' => ['15 jours', 10],
|
||||||
|
'J30' => ['30 jours', 20],
|
||||||
|
'A_RECEPTION' => ['À réception', 30],
|
||||||
|
],
|
||||||
|
PaymentType::class => [
|
||||||
|
'VIREMENT' => ['Virement', 10],
|
||||||
|
'LCR' => ['LCR', 20],
|
||||||
|
'NON_SOUMISE' => ['Non soumise', 30],
|
||||||
|
'CHEQUE' => ['Chèque', 40],
|
||||||
|
],
|
||||||
|
Bank::class => [
|
||||||
|
'SG' => ['Société Générale', 10],
|
||||||
|
'CIC' => ['CIC', 20],
|
||||||
|
'CA' => ['Crédit Agricole', 30],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
foreach (self::REFERENTIALS as $entityClass => $rows) {
|
||||||
|
$this->seedReferential($manager, $entityClass, $rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upsert idempotent d'un referentiel : indexe l'existant par code puis
|
||||||
|
* cree/met a jour chaque entree. Les 4 entites partagent le meme contrat
|
||||||
|
* setCode/setLabel/setPosition.
|
||||||
|
*
|
||||||
|
* @param class-string $entityClass
|
||||||
|
* @param array<string, array{string, int}> $rows
|
||||||
|
*/
|
||||||
|
private function seedReferential(ObjectManager $manager, string $entityClass, array $rows): void
|
||||||
|
{
|
||||||
|
$existingByCode = [];
|
||||||
|
foreach ($manager->getRepository($entityClass)->findAll() as $entity) {
|
||||||
|
$existingByCode[$entity->getCode()] = $entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($rows as $code => [$label, $position]) {
|
||||||
|
$entity = $existingByCode[$code] ?? new $entityClass();
|
||||||
|
$entity->setCode($code);
|
||||||
|
$entity->setLabel($label);
|
||||||
|
$entity->setPosition($position);
|
||||||
|
$manager->persist($entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Bank;
|
||||||
|
use App\Module\Commercial\Domain\Repository\BankRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Bank>
|
||||||
|
*/
|
||||||
|
class DoctrineBankRepository extends ServiceEntityRepository implements BankRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Bank::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?Bank
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findAllOrdered(): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('b')
|
||||||
|
->orderBy('b.position', 'ASC')
|
||||||
|
->addOrderBy('b.label', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
||||||
|
use App\Module\Commercial\Domain\Repository\ClientAddressRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<ClientAddress>
|
||||||
|
*/
|
||||||
|
class DoctrineClientAddressRepository extends ServiceEntityRepository implements ClientAddressRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, ClientAddress::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?ClientAddress
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(ClientAddress $address): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($address);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientContact;
|
||||||
|
use App\Module\Commercial\Domain\Repository\ClientContactRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<ClientContact>
|
||||||
|
*/
|
||||||
|
class DoctrineClientContactRepository extends ServiceEntityRepository implements ClientContactRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, ClientContact::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?ClientContact
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(ClientContact $contact): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($contact);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client;
|
||||||
|
use App\Module\Commercial\Domain\Repository\ClientRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Client>
|
||||||
|
*/
|
||||||
|
class DoctrineClientRepository extends ServiceEntityRepository implements ClientRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Client::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?Client
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(Client $client): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($client);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createListQueryBuilder(
|
||||||
|
bool $includeArchived = false,
|
||||||
|
?string $search = null,
|
||||||
|
?string $categoryType = null,
|
||||||
|
): QueryBuilder {
|
||||||
|
$qb = $this->createQueryBuilder('c')
|
||||||
|
->andWhere('c.deletedAt IS NULL')
|
||||||
|
->orderBy('c.companyName', 'ASC')
|
||||||
|
;
|
||||||
|
|
||||||
|
if (!$includeArchived) {
|
||||||
|
$qb->andWhere('c.isArchived = false');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->applySearch($qb, $search);
|
||||||
|
$this->applyCategoryType($qb, $categoryType);
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recherche fuzzy insensible a la casse sur companyName + lastName + email.
|
||||||
|
* Les metacaracteres LIKE (%, _, \) saisis sont echappes pour rester
|
||||||
|
* litteraux.
|
||||||
|
*/
|
||||||
|
private function applySearch(QueryBuilder $qb, ?string $search): void
|
||||||
|
{
|
||||||
|
if (null === $search || '' === trim($search)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$escaped = str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], trim($search));
|
||||||
|
$pattern = '%'.mb_strtolower($escaped, 'UTF-8').'%';
|
||||||
|
|
||||||
|
$qb->andWhere(
|
||||||
|
'LOWER(c.companyName) LIKE :search '
|
||||||
|
.'OR LOWER(c.lastName) LIKE :search '
|
||||||
|
.'OR LOWER(c.email) LIKE :search',
|
||||||
|
)->setParameter('search', $pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restreint aux clients possedant au moins une categorie du type donne.
|
||||||
|
* Sous-requete IN (plutot qu'un JOIN sur la collection M2M) pour ne pas
|
||||||
|
* perturber le DISTINCT / ORDER BY de la requete principale.
|
||||||
|
*/
|
||||||
|
private function applyCategoryType(QueryBuilder $qb, ?string $categoryType): void
|
||||||
|
{
|
||||||
|
if (null === $categoryType || '' === trim($categoryType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sub = $this->getEntityManager()->createQueryBuilder()
|
||||||
|
->select('c2.id')
|
||||||
|
->from(Client::class, 'c2')
|
||||||
|
->join('c2.categories', 'cat2')
|
||||||
|
->join('cat2.categoryType', 'ct2')
|
||||||
|
->where('ct2.code = :categoryType')
|
||||||
|
;
|
||||||
|
|
||||||
|
$qb->andWhere($qb->expr()->in('c.id', $sub->getDQL()))
|
||||||
|
->setParameter('categoryType', trim($categoryType))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\ClientRib;
|
||||||
|
use App\Module\Commercial\Domain\Repository\ClientRibRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<ClientRib>
|
||||||
|
*/
|
||||||
|
class DoctrineClientRibRepository extends ServiceEntityRepository implements ClientRibRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, ClientRib::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?ClientRib
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(ClientRib $rib): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($rib);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentDelay;
|
||||||
|
use App\Module\Commercial\Domain\Repository\PaymentDelayRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<PaymentDelay>
|
||||||
|
*/
|
||||||
|
class DoctrinePaymentDelayRepository extends ServiceEntityRepository implements PaymentDelayRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, PaymentDelay::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?PaymentDelay
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findAllOrdered(): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('p')
|
||||||
|
->orderBy('p.position', 'ASC')
|
||||||
|
->addOrderBy('p.label', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\PaymentType;
|
||||||
|
use App\Module\Commercial\Domain\Repository\PaymentTypeRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<PaymentType>
|
||||||
|
*/
|
||||||
|
class DoctrinePaymentTypeRepository extends ServiceEntityRepository implements PaymentTypeRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, PaymentType::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?PaymentType
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findAllOrdered(): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('p')
|
||||||
|
->orderBy('p.position', 'ASC')
|
||||||
|
->addOrderBy('p.label', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\TvaMode;
|
||||||
|
use App\Module\Commercial\Domain\Repository\TvaModeRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<TvaMode>
|
||||||
|
*/
|
||||||
|
class DoctrineTvaModeRepository extends ServiceEntityRepository implements TvaModeRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, TvaMode::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?TvaMode
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findAllOrdered(): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('t')
|
||||||
|
->orderBy('t.position', 'ASC')
|
||||||
|
->addOrderBy('t.label', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Core\Application\Rbac;
|
||||||
|
|
||||||
|
use App\Module\Core\Domain\Entity\Role;
|
||||||
|
use App\Module\Core\Domain\Entity\User;
|
||||||
|
use App\Module\Core\Domain\Exception\RbacSeedException;
|
||||||
|
use App\Module\Core\Domain\Repository\PermissionRepositoryInterface;
|
||||||
|
use App\Module\Core\Domain\Repository\RoleRepositoryInterface;
|
||||||
|
use App\Module\Core\Domain\Repository\UserRepositoryInterface;
|
||||||
|
use App\Shared\Domain\Contract\SiteProviderInterface;
|
||||||
|
use App\Shared\Domain\Security\BusinessRoles;
|
||||||
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source UNIQUE (anti-drift) du RBAC metier MALIO : les 4 roles
|
||||||
|
* (bureau / compta / commerciale / usine), la matrice § 2.7 (role -> permissions)
|
||||||
|
* et les comptes demo par role. Aucun de ces litteraux ne doit etre duplique
|
||||||
|
* ailleurs (ni SQL en dur, ni autre fixture).
|
||||||
|
*
|
||||||
|
* Consomme par :
|
||||||
|
* - la commande applicative `app:seed-rbac` (presente dans le build prod, donc
|
||||||
|
* rejouable en recette/prod, contrairement aux fixtures `require-dev`) ;
|
||||||
|
* - la fixture Core dev/test (DRY : meme seeder).
|
||||||
|
*
|
||||||
|
* Toutes les operations sont idempotentes et non destructives :
|
||||||
|
* - ensureRoles() : cree un role par lookup de code (skip si present) ;
|
||||||
|
* - attachMatrix() : attache les permissions § 2.7 via la M2M role_permission,
|
||||||
|
* sans re-attacher un lien existant ; STOP explicite si un code manque ;
|
||||||
|
* - ensureDemoUsers() : cree un user par role (lookup par username, skip si
|
||||||
|
* present), rattache au role + a >= 1 site.
|
||||||
|
*/
|
||||||
|
final class RbacSeeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Codes des roles metier (snake_case, regex Role respectee). `commerciale`
|
||||||
|
* reference la constante Shared deja consommee par le ClientProcessor
|
||||||
|
* (RG-1.04) pour eviter tout drift : un seul litteral pour ce code.
|
||||||
|
*/
|
||||||
|
public const string ROLE_BUREAU = 'bureau';
|
||||||
|
public const string ROLE_COMPTA = 'compta';
|
||||||
|
public const string ROLE_COMMERCIALE = BusinessRoles::COMMERCIALE;
|
||||||
|
public const string ROLE_USINE = 'usine';
|
||||||
|
|
||||||
|
/** Site de rattachement par defaut des comptes demo (cf. SitesFixtures). */
|
||||||
|
private const string DEFAULT_SITE_NAME = 'Chatellerault';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Definition unique des 4 roles + matrice § 2.7. La cle est le code du role,
|
||||||
|
* `label` le libelle FR affichable, `permissions` la liste des codes RBAC a
|
||||||
|
* attacher (vide pour usine : aucun acces ; admin n'apparait pas car il
|
||||||
|
* bypass tout via isAdmin ; `commercial.clients.archive` n'est attache a
|
||||||
|
* aucun role metier — admin seul).
|
||||||
|
*
|
||||||
|
* @var array<string, array{label: string, permissions: list<string>}>
|
||||||
|
*/
|
||||||
|
private const array MATRIX = [
|
||||||
|
self::ROLE_BUREAU => [
|
||||||
|
'label' => 'Bureau',
|
||||||
|
'permissions' => [
|
||||||
|
'commercial.clients.view',
|
||||||
|
'commercial.clients.manage',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
self::ROLE_COMPTA => [
|
||||||
|
'label' => 'Comptabilité',
|
||||||
|
'permissions' => [
|
||||||
|
'commercial.clients.view',
|
||||||
|
'commercial.clients.accounting.view',
|
||||||
|
'commercial.clients.accounting.manage',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
self::ROLE_COMMERCIALE => [
|
||||||
|
'label' => 'Commerciale',
|
||||||
|
'permissions' => [
|
||||||
|
'commercial.clients.view',
|
||||||
|
'commercial.clients.manage',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
self::ROLE_USINE => [
|
||||||
|
'label' => 'Usine',
|
||||||
|
'permissions' => [],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoleRepositoryInterface $roleRepository,
|
||||||
|
private readonly PermissionRepositoryInterface $permissionRepository,
|
||||||
|
private readonly UserRepositoryInterface $userRepository,
|
||||||
|
private readonly SiteProviderInterface $siteProvider,
|
||||||
|
private readonly UserPasswordHasherInterface $passwordHasher,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cree chaque role metier absent (lookup par code). Idempotent.
|
||||||
|
*
|
||||||
|
* @return list<string> codes des roles effectivement crees (vide au rejeu)
|
||||||
|
*/
|
||||||
|
public function ensureRoles(): array
|
||||||
|
{
|
||||||
|
$created = [];
|
||||||
|
|
||||||
|
foreach (self::MATRIX as $code => $definition) {
|
||||||
|
if (null !== $this->roleRepository->findByCode($code)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// isSystem=false : ce sont des roles metier, supprimables par un
|
||||||
|
// admin (contrairement aux roles systeme admin/user).
|
||||||
|
$this->roleRepository->save(new Role($code, $definition['label'], isSystem: false));
|
||||||
|
$created[] = $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $created;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attache la matrice § 2.7 a chaque role via la M2M role_permission. Lookup
|
||||||
|
* de la permission par code ; un code absent leve une RbacSeedException
|
||||||
|
* (garde-fou : `app:sync-permissions` doit avoir tourne). Idempotent : un
|
||||||
|
* lien deja present n'est pas recree.
|
||||||
|
*
|
||||||
|
* @return int nombre de liens role->permission effectivement ajoutes (0 au rejeu)
|
||||||
|
*
|
||||||
|
* @throws RbacSeedException si un role ou une permission de la matrice manque
|
||||||
|
*/
|
||||||
|
public function attachMatrix(): int
|
||||||
|
{
|
||||||
|
$added = 0;
|
||||||
|
|
||||||
|
foreach (self::MATRIX as $code => $definition) {
|
||||||
|
$role = $this->roleRepository->findByCode($code);
|
||||||
|
if (null === $role) {
|
||||||
|
throw RbacSeedException::missingRole($code);
|
||||||
|
}
|
||||||
|
|
||||||
|
$touched = false;
|
||||||
|
foreach ($definition['permissions'] as $permissionCode) {
|
||||||
|
$permission = $this->permissionRepository->findByCode($permissionCode);
|
||||||
|
if (null === $permission) {
|
||||||
|
throw RbacSeedException::missingPermission($permissionCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$role->getPermissions()->contains($permission)) {
|
||||||
|
$role->addPermission($permission);
|
||||||
|
$touched = true;
|
||||||
|
++$added;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un seul flush par role, et seulement si un lien a change.
|
||||||
|
if ($touched) {
|
||||||
|
$this->roleRepository->save($role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $added;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cree un compte demo par role metier (username = code du role), non-admin,
|
||||||
|
* mot de passe hashe, rattache a son role et a >= 1 site. Lookup par
|
||||||
|
* username : idempotent (un compte existant est laisse intact, mot de passe
|
||||||
|
* inchange).
|
||||||
|
*
|
||||||
|
* @return list<string> usernames effectivement crees (vide au rejeu)
|
||||||
|
*
|
||||||
|
* @throws RbacSeedException si un role metier attendu est absent (ensureRoles non joue)
|
||||||
|
*/
|
||||||
|
public function ensureDemoUsers(string $password): array
|
||||||
|
{
|
||||||
|
// Rattachement a un site par defaut s'il existe (les flux login / me en
|
||||||
|
// ont besoin ; le repertoire clients n'est pas site-scope mais on reste
|
||||||
|
// coherent avec les fixtures admin/alice/bob).
|
||||||
|
$defaultSite = $this->siteProvider->findByName(self::DEFAULT_SITE_NAME);
|
||||||
|
$created = [];
|
||||||
|
|
||||||
|
foreach (array_keys(self::MATRIX) as $code) {
|
||||||
|
$username = $code;
|
||||||
|
if (null !== $this->userRepository->findByUsername($username)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$role = $this->roleRepository->findByCode($code);
|
||||||
|
if (null === $role) {
|
||||||
|
throw RbacSeedException::missingRole($code);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
$user->setUsername($username);
|
||||||
|
$user->setIsAdmin(false);
|
||||||
|
$user->setPassword($this->passwordHasher->hashPassword($user, $password));
|
||||||
|
$user->addRbacRole($role);
|
||||||
|
|
||||||
|
if (null !== $defaultSite) {
|
||||||
|
$user->addSite($defaultSite);
|
||||||
|
$user->setCurrentSite($defaultSite);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->userRepository->save($user);
|
||||||
|
$created[] = $username;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $created;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liste des codes des roles metier definis (pour reporting / tests).
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
public static function roleCodes(): array
|
||||||
|
{
|
||||||
|
return array_keys(self::MATRIX);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ use App\Module\Core\Infrastructure\Doctrine\DoctrineUserRepository;
|
|||||||
// C'est le pattern officiel Doctrine pour les bounded contexts DDD.
|
// C'est le pattern officiel Doctrine pour les bounded contexts DDD.
|
||||||
use App\Shared\Domain\Attribute\Auditable;
|
use App\Shared\Domain\Attribute\Auditable;
|
||||||
use App\Shared\Domain\Attribute\AuditIgnore;
|
use App\Shared\Domain\Attribute\AuditIgnore;
|
||||||
|
use App\Shared\Domain\Contract\BusinessRoleAwareInterface;
|
||||||
use App\Shared\Domain\Contract\SiteInterface;
|
use App\Shared\Domain\Contract\SiteInterface;
|
||||||
use App\Shared\Domain\Exception\SiteNotAuthorizedException;
|
use App\Shared\Domain\Exception\SiteNotAuthorizedException;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
@@ -75,7 +76,7 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
|||||||
#[ORM\Entity(repositoryClass: DoctrineUserRepository::class)]
|
#[ORM\Entity(repositoryClass: DoctrineUserRepository::class)]
|
||||||
#[ORM\Table(name: '`user`')]
|
#[ORM\Table(name: '`user`')]
|
||||||
#[Auditable]
|
#[Auditable]
|
||||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
class User implements UserInterface, PasswordAuthenticatedUserInterface, BusinessRoleAwareInterface
|
||||||
{
|
{
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
@@ -337,6 +338,23 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||||||
return $keys;
|
return $keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implemente BusinessRoleAwareInterface : vrai si l'un des roles RBAC
|
||||||
|
* 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
|
||||||
|
* cette classe. Comparaison stricte sur Role::code.
|
||||||
|
*/
|
||||||
|
public function hasBusinessRole(string $roleCode): bool
|
||||||
|
{
|
||||||
|
foreach ($this->rbacRoles as $role) {
|
||||||
|
if ($role->getCode() === $roleCode) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPassword(): ?string
|
public function getPassword(): ?string
|
||||||
{
|
{
|
||||||
return $this->password;
|
return $this->password;
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Core\Domain\Exception;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erreur de seed RBAC (service RbacSeeder / commande app:seed-rbac).
|
||||||
|
*
|
||||||
|
* Deux causes possibles, toutes deux fatales et explicites :
|
||||||
|
* - role metier attendu introuvable (ensureRoles() n'a pas tourne avant
|
||||||
|
* attachMatrix() ou ensureDemoUsers()) ;
|
||||||
|
* - code de permission de la matrice § 2.7 absent du catalogue : signe que
|
||||||
|
* `app:sync-permissions` n'a pas ete joue. Le message embarque alors
|
||||||
|
* l'invite a lancer la synchronisation, exploitee telle quelle par la
|
||||||
|
* commande.
|
||||||
|
*/
|
||||||
|
final class RbacSeedException extends RuntimeException
|
||||||
|
{
|
||||||
|
public static function missingRole(string $roleCode): self
|
||||||
|
{
|
||||||
|
return new self(sprintf(
|
||||||
|
'Role metier "%s" introuvable. Appelle RbacSeeder::ensureRoles() avant attachMatrix()/ensureDemoUsers().',
|
||||||
|
$roleCode,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function missingPermission(string $permissionCode): self
|
||||||
|
{
|
||||||
|
return new self(sprintf(
|
||||||
|
'Permission "%s" (matrice § 2.7) absente du catalogue. '
|
||||||
|
.'Lance d\'abord `bin/console app:sync-permissions` pour la poser en base, puis relance le seed RBAC.',
|
||||||
|
$permissionCode,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,18 +29,16 @@ use App\Module\Core\Infrastructure\ApiPlatform\State\Provider\AuditLogProvider;
|
|||||||
* ?performed_at[after]=2026-04-01T00:00:00Z
|
* ?performed_at[after]=2026-04-01T00:00:00Z
|
||||||
* ?performed_at[before]=2026-04-30T23:59:59Z
|
* ?performed_at[before]=2026-04-30T23:59:59Z
|
||||||
*
|
*
|
||||||
* La pagination est assuree par le provider via DbalPaginator (implementant
|
* La pagination herite du standard global (10 items / page, max 50, cf.
|
||||||
* ApiPlatform\State\Pagination\PaginatorInterface), ce qui genere
|
* `config/packages/api_platform.yaml`). Elle est materialisee par le
|
||||||
* automatiquement hydra:view — aucune construction manuelle.
|
* DbalPaginator du provider qui implemente PaginatorInterface — API Platform
|
||||||
|
* genere automatiquement hydra:view sans construction manuelle.
|
||||||
*/
|
*/
|
||||||
#[ApiResource(
|
#[ApiResource(
|
||||||
shortName: 'AuditLog',
|
shortName: 'AuditLog',
|
||||||
operations: [
|
operations: [
|
||||||
new GetCollection(
|
new GetCollection(
|
||||||
uriTemplate: '/audit-logs',
|
uriTemplate: '/audit-logs',
|
||||||
paginationItemsPerPage: 30,
|
|
||||||
paginationClientItemsPerPage: true,
|
|
||||||
paginationMaximumItemsPerPage: 50,
|
|
||||||
security: "is_granted('core.audit_log.view')",
|
security: "is_granted('core.audit_log.view')",
|
||||||
provider: AuditLogProvider::class,
|
provider: AuditLogProvider::class,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -68,6 +68,13 @@ final readonly class AuditLogProvider implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
private function provideCollection(Operation $operation, array $context): DbalPaginator
|
private function provideCollection(Operation $operation, array $context): DbalPaginator
|
||||||
{
|
{
|
||||||
|
// Contrairement aux ressources ORM (cf. CategoryProvider), ce provider
|
||||||
|
// ne gere PAS l'echappatoire `?pagination=false` : la pagination y est
|
||||||
|
// toujours forcee. `audit_log` est une table append-only a croissance
|
||||||
|
// infinie — la dumper entierement saturerait memoire/reseau et n'a aucun
|
||||||
|
// usage front (pas de <select> alimente par l'audit). Le flag global
|
||||||
|
// `pagination_client_enabled: true` reste donc volontairement inerte ici.
|
||||||
|
//
|
||||||
// `page` brut peut etre <= 0 (parametre client) → OFFSET negatif → 500 PG
|
// `page` brut peut etre <= 0 (parametre client) → OFFSET negatif → 500 PG
|
||||||
// (`SQLSTATE[22023] OFFSET must not be negative`). API Platform clampe
|
// (`SQLSTATE[22023] OFFSET must not be negative`). API Platform clampe
|
||||||
// `itemsPerPage` au max de la resource mais pas `page` ; on impose un
|
// `itemsPerPage` au max de la resource mais pas `page` ; on impose un
|
||||||
|
|||||||
@@ -186,6 +186,15 @@ final class SeedE2ECommand extends Command
|
|||||||
'sites.bypass_scope',
|
'sites.bypass_scope',
|
||||||
'catalog.categories.view',
|
'catalog.categories.view',
|
||||||
'catalog.categories.manage',
|
'catalog.categories.manage',
|
||||||
|
// Commercial — Repertoire clients (M1). Mappe ici sur le
|
||||||
|
// persona "tout" en attendant les vrais roles metier
|
||||||
|
// (bureau/compta/commerciale/usine) seedes par ERP-74.
|
||||||
|
// Miroir de frontend/tests/e2e/_fixtures/personas.ts.
|
||||||
|
'commercial.clients.view',
|
||||||
|
'commercial.clients.manage',
|
||||||
|
'commercial.clients.accounting.view',
|
||||||
|
'commercial.clients.accounting.manage',
|
||||||
|
'commercial.clients.archive',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Core\Infrastructure\Console;
|
||||||
|
|
||||||
|
use App\Module\Core\Application\Rbac\RbacSeeder;
|
||||||
|
use App\Module\Core\Domain\Exception\RbacSeedException;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed RBAC metier idempotent et NON destructif (cf. ERP-74 / spec-back M1
|
||||||
|
* § 2.7). Contrairement aux fixtures Doctrine (`require-dev`, absentes du build
|
||||||
|
* prod `--no-dev`), cette commande applicative est presente dans l'image prod :
|
||||||
|
* elle est donc rejouable en recette/staging/prod.
|
||||||
|
*
|
||||||
|
* Etape de release : a lancer APRES `doctrine:migrations:migrate` et
|
||||||
|
* `app:sync-permissions`.
|
||||||
|
* - En prod : `app:seed-rbac` (roles + matrice § 2.7, sans comptes demo).
|
||||||
|
* - En recette : `app:seed-rbac --with-demo-users --password=<...>` pour
|
||||||
|
* disposer de logins de test.
|
||||||
|
*
|
||||||
|
* Toute la logique (litteraux des roles, matrice, comptes demo) vit dans
|
||||||
|
* RbacSeeder — cette commande n'en est que l'enveloppe CLI.
|
||||||
|
*/
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'app:seed-rbac',
|
||||||
|
description: 'Seede les roles metier RBAC + la matrice § 2.7 (idempotent, non destructif).',
|
||||||
|
)]
|
||||||
|
final class SeedRbacCommand extends Command
|
||||||
|
{
|
||||||
|
/** Variable d'environnement de repli pour le mot de passe des comptes demo. */
|
||||||
|
private const string PASSWORD_ENV = 'RBAC_DEMO_PASSWORD';
|
||||||
|
|
||||||
|
public function __construct(private readonly RbacSeeder $seeder)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->addOption(
|
||||||
|
'with-demo-users',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'Cree aussi un compte demo par role metier (recette/dev — JAMAIS en prod).',
|
||||||
|
)
|
||||||
|
->addOption(
|
||||||
|
'password',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_REQUIRED,
|
||||||
|
'Mot de passe des comptes demo (defaut : variable d\'env '.self::PASSWORD_ENV.'). Requis avec --with-demo-users.',
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
// 1. Roles metier + matrice § 2.7. attachMatrix() exige que les
|
||||||
|
// permissions soient en base : sinon RbacSeedException porteuse de
|
||||||
|
// l'invite a lancer `app:sync-permissions`.
|
||||||
|
try {
|
||||||
|
$createdRoles = $this->seeder->ensureRoles();
|
||||||
|
$addedLinks = $this->seeder->attachMatrix();
|
||||||
|
} catch (RbacSeedException $e) {
|
||||||
|
$io->error($e->getMessage());
|
||||||
|
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$io->text(sprintf(
|
||||||
|
'Roles metier : %d cree(s), matrice § 2.7 : %d lien(s) ajoute(s).',
|
||||||
|
count($createdRoles),
|
||||||
|
$addedLinks,
|
||||||
|
));
|
||||||
|
|
||||||
|
// 2. Comptes demo (optionnel, jamais en prod).
|
||||||
|
if ((bool) $input->getOption('with-demo-users')) {
|
||||||
|
$password = $this->resolveDemoPassword($input);
|
||||||
|
if (null === $password) {
|
||||||
|
$io->error(sprintf(
|
||||||
|
'--with-demo-users exige un mot de passe : passe --password=<...> ou definis la variable d\'env %s. '
|
||||||
|
.'(Aucun mot de passe en dur cote serveur.)',
|
||||||
|
self::PASSWORD_ENV,
|
||||||
|
));
|
||||||
|
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$createdUsers = $this->seeder->ensureDemoUsers($password);
|
||||||
|
} catch (RbacSeedException $e) {
|
||||||
|
$io->error($e->getMessage());
|
||||||
|
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$io->text(sprintf(
|
||||||
|
'Comptes demo : %d cree(s)%s.',
|
||||||
|
count($createdUsers),
|
||||||
|
[] === $createdUsers ? '' : ' ['.implode(', ', $createdUsers).']',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$io->success('Seed RBAC metier termine (idempotent).');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resout le mot de passe demo : option `--password` prioritaire, sinon
|
||||||
|
* variable d'environnement. Renvoie null si aucun n'est fourni (la commande
|
||||||
|
* refuse alors --with-demo-users plutot que d'inventer un mot de passe).
|
||||||
|
*/
|
||||||
|
private function resolveDemoPassword(InputInterface $input): ?string
|
||||||
|
{
|
||||||
|
/** @var null|string $option */
|
||||||
|
$option = $input->getOption('password');
|
||||||
|
if (null !== $option && '' !== $option) {
|
||||||
|
return $option;
|
||||||
|
}
|
||||||
|
|
||||||
|
$env = $_SERVER[self::PASSWORD_ENV] ?? $_ENV[self::PASSWORD_ENV] ?? getenv(self::PASSWORD_ENV);
|
||||||
|
if (is_string($env) && '' !== $env) {
|
||||||
|
return $env;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Core\Infrastructure\DataFixtures;
|
||||||
|
|
||||||
|
use App\Module\Core\Application\Rbac\RbacSeeder;
|
||||||
|
use App\Module\Sites\Infrastructure\DataFixtures\SitesFixtures;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixture dev/test des roles metier MALIO (bureau / compta / commerciale /
|
||||||
|
* usine) + comptes demo associes. DRY : delegue au MEME service RbacSeeder que
|
||||||
|
* la commande `app:seed-rbac`, de sorte que `make db-reset` reproduise l'etat
|
||||||
|
* de recette.
|
||||||
|
*
|
||||||
|
* Depend de SitesFixtures : les comptes demo sont rattaches au site par defaut
|
||||||
|
* (cf. RbacSeeder::DEFAULT_SITE_NAME).
|
||||||
|
*
|
||||||
|
* ⚠ N'attache PAS la matrice § 2.7 ici : `doctrine:fixtures:load` PURGE la table
|
||||||
|
* `permission` avant de charger, donc les codes `commercial.clients.*` ne sont
|
||||||
|
* pas encore en base au moment du load (cf. ordre du makefile : fixtures PUIS
|
||||||
|
* `app:sync-permissions`). La matrice est attachee juste apres, par l'etape
|
||||||
|
* `app:seed-rbac` du makefile (db-reset / test-db-setup), via le meme seeder.
|
||||||
|
* Resultat final identique a la recette : roles + matrice + comptes demo.
|
||||||
|
*/
|
||||||
|
final class RbacDemoFixtures extends Fixture implements DependentFixtureInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Mot de passe DEV/TEST connu des comptes demo (bureau / compta /
|
||||||
|
* commerciale / usine). Reference par les tests fonctionnels de matrice
|
||||||
|
* RBAC. Sans rapport avec la prod : en recette/prod le mot de passe est
|
||||||
|
* fourni explicitement a `app:seed-rbac --with-demo-users --password=...`.
|
||||||
|
*/
|
||||||
|
public const string DEMO_PASSWORD = 'demo';
|
||||||
|
|
||||||
|
public function __construct(private readonly RbacSeeder $seeder) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, class-string>
|
||||||
|
*/
|
||||||
|
public function getDependencies(): array
|
||||||
|
{
|
||||||
|
return [SitesFixtures::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(ObjectManager $manager): void
|
||||||
|
{
|
||||||
|
// Idempotent : ensureRoles puis ensureDemoUsers (lookup par code /
|
||||||
|
// username). La matrice est volontairement deferree (cf. docblock).
|
||||||
|
$this->seeder->ensureRoles();
|
||||||
|
$this->seeder->ensureDemoUsers(self::DEMO_PASSWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Shared\Domain\Contract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose, sans coupler a la classe concrete User (module Core), le moyen de
|
||||||
|
* savoir si un utilisateur porte un role METIER donne (par son code, cf.
|
||||||
|
* App\Shared\Domain\Security\BusinessRoles).
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* (regle ABSOLUE n°1 : pas d'import inter-modules).
|
||||||
|
*
|
||||||
|
* Distinct de UserInterface::getRoles() (roles SYSTEME Symfony ROLE_*, derives
|
||||||
|
* de is_admin) : ici on parle des roles RBAC metier rattaches a l'utilisateur.
|
||||||
|
*/
|
||||||
|
interface BusinessRoleAwareInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Vrai si l'utilisateur porte le role RBAC metier identifie par $roleCode
|
||||||
|
* (compare au champ Role::code).
|
||||||
|
*/
|
||||||
|
public function hasBusinessRole(string $roleCode): bool;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Shared\Domain\Contract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface minimale exposant ce qu'un module tiers (Commercial...) doit
|
||||||
|
* connaitre d'une Category, sans creer de couplage direct vers le module
|
||||||
|
* Catalog (regle ABSOLUE n°1 : pas d'import inter-modules).
|
||||||
|
*
|
||||||
|
* Implementee par App\Module\Catalog\Domain\Entity\Category.
|
||||||
|
* Utilisee comme cible des ManyToMany Client.categories et
|
||||||
|
* ClientAddress.categories via resolve_target_entities (cf. doctrine.yaml),
|
||||||
|
* sur le meme modele que SiteInterface / UserInterface.
|
||||||
|
*/
|
||||||
|
interface CategoryInterface
|
||||||
|
{
|
||||||
|
public function getId(): ?int;
|
||||||
|
|
||||||
|
public function getName(): ?string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Code du type de categorie rattache (CategoryType::code), ou null si la
|
||||||
|
* categorie n'a pas de type. Expose pour permettre a un module tiers de
|
||||||
|
* raisonner sur le type metier (ex: M1 Commercial — RG-1.03 : un distributor
|
||||||
|
* doit referencer un client categorise DISTRIBUTEUR ; RG-1.29 : categorie
|
||||||
|
* d'adresse limitee a SECTEUR/AUTRE) sans importer la classe concrete
|
||||||
|
* Category (regle ABSOLUE n°1).
|
||||||
|
*/
|
||||||
|
public function getCategoryTypeCode(): ?string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Shared\Domain\Contract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrat d'export d'une feuille de calcul tabulaire vers un binaire XLSX.
|
||||||
|
*
|
||||||
|
* Service GENERIQUE et reutilisable : il ne connait aucune entite metier. Le
|
||||||
|
* module appelant decide QUOI exporter (en-tetes + lignes deja mappees) ; cette
|
||||||
|
* interface decrit seulement COMMENT produire le fichier. Aucun module n'est
|
||||||
|
* couple a une implementation concrete : on depend de ce contrat (dans Shared),
|
||||||
|
* jamais l'inverse (regle ABSOLUE n°1).
|
||||||
|
*
|
||||||
|
* Implementee par App\Shared\Infrastructure\Export\PhpSpreadsheetExporter (on
|
||||||
|
* ne la reference pas via @see pour ne pas creer un import Domain -> Infra).
|
||||||
|
*/
|
||||||
|
interface SpreadsheetExporterInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Genere un classeur XLSX a une feuille et retourne son contenu binaire.
|
||||||
|
*
|
||||||
|
* @param string $sheetTitle titre de l'onglet (assaini / tronque par l'implementation si besoin)
|
||||||
|
* @param list<string> $headers libelles de la ligne d'en-tete (ligne 1)
|
||||||
|
* @param iterable<list<null|scalar>> $rows lignes de donnees ; chaque ligne est une liste de cellules alignee sur $headers
|
||||||
|
*
|
||||||
|
* @return string contenu binaire du fichier XLSX
|
||||||
|
*/
|
||||||
|
public function export(string $sheetTitle, array $headers, iterable $rows): string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Shared\Domain\Security;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codes des roles METIER MALIO partages entre modules.
|
||||||
|
*
|
||||||
|
* Distincts des roles SYSTEME (cf. App\Module\Core\Domain\Security\SystemRoles :
|
||||||
|
* `admin` / `user`). Un role metier porte une intention fonctionnelle (poste de
|
||||||
|
* 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
|
||||||
|
* pour le seul role Commerciale, alors que Commerciale et Bureau partagent les
|
||||||
|
* memes permissions (commercial.clients.view + manage, cf. spec-back M1 § 5.2).
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* une constante du module Commercial (regle ABSOLUE n°1 : pas d'import
|
||||||
|
* inter-modules) ;
|
||||||
|
* - le ClientProcessor (module Commercial) detecte le role Commerciale via ce
|
||||||
|
* meme code, sans dependre de Core.
|
||||||
|
*
|
||||||
|
* Coordination stack M1 :
|
||||||
|
* - ERP-74 seede le role `commerciale` avec ce code exact.
|
||||||
|
* - 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
|
||||||
|
* role `commerciale`, la validation de completude Information reste dormante.
|
||||||
|
*/
|
||||||
|
final class BusinessRoles
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Role metier « Commerciale » — code de Role RBAC (champ Role::code,
|
||||||
|
* snake_case impose par la regex Role). Conditionne RG-1.04.
|
||||||
|
*/
|
||||||
|
public const string COMMERCIALE = 'commerciale';
|
||||||
|
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
// Classe de constantes : non instanciable.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -128,6 +128,135 @@ final class ColumnCommentsCatalog
|
|||||||
'user_id' => 'FK -> user.id, ON DELETE CASCADE — utilisateur ayant acces au site.',
|
'user_id' => 'FK -> user.id, ON DELETE CASCADE — utilisateur ayant acces au site.',
|
||||||
'site_id' => 'FK -> site.id, ON DELETE CASCADE — site accessible par l utilisateur.',
|
'site_id' => 'FK -> site.id, ON DELETE CASCADE — site accessible par l utilisateur.',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// === M1 Commercial (ERP-53/54) — miroir des COMMENT de la migration
|
||||||
|
// Version20260601000000 pour le chemin schema:update (dev/test). ===
|
||||||
|
|
||||||
|
'tva_mode' => [
|
||||||
|
'_table' => 'Referentiel des modes de TVA appliques a un client (France, Export, Intracom).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'code' => 'Code technique stable (UPPER_SNAKE, ≤ 30 caracteres) — unique, utilise par le code metier.',
|
||||||
|
'label' => 'Libelle affichable (FR, ≤ 120 caracteres).',
|
||||||
|
'position' => 'Ordre d affichage croissant dans les selecteurs (tri position ASC puis label ASC).',
|
||||||
|
],
|
||||||
|
|
||||||
|
'payment_delay' => [
|
||||||
|
'_table' => 'Referentiel des delais de reglement (15 jours, 30 jours, a reception).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'code' => 'Code technique stable (UPPER_SNAKE, ≤ 30 caracteres) — unique, utilise par le code metier.',
|
||||||
|
'label' => 'Libelle affichable (FR, ≤ 120 caracteres).',
|
||||||
|
'position' => 'Ordre d affichage croissant dans les selecteurs (tri position ASC puis label ASC).',
|
||||||
|
],
|
||||||
|
|
||||||
|
'payment_type' => [
|
||||||
|
'_table' => 'Referentiel des types de reglement (virement, LCR, cheque, non soumise).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'code' => 'Code technique stable (UPPER_SNAKE, ≤ 30 caracteres) — unique, utilise par le code metier.',
|
||||||
|
'label' => 'Libelle affichable (FR, ≤ 120 caracteres).',
|
||||||
|
'position' => 'Ordre d affichage croissant dans les selecteurs (tri position ASC puis label ASC).',
|
||||||
|
],
|
||||||
|
|
||||||
|
'bank' => [
|
||||||
|
'_table' => 'Referentiel des banques selectionnables pour le reglement par virement.',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'code' => 'Code technique stable (UPPER_SNAKE, ≤ 30 caracteres) — unique, utilise par le code metier.',
|
||||||
|
'label' => 'Libelle affichable (FR, ≤ 120 caracteres).',
|
||||||
|
'position' => 'Ordre d affichage croissant dans les selecteurs (tri position ASC puis label ASC).',
|
||||||
|
],
|
||||||
|
|
||||||
|
'client' => [
|
||||||
|
'_table' => 'Repertoire clients (M1 Commercial) — entites archivables (is_archived) et soft-deletables (deleted_at, HP M2).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'company_name' => 'Raison sociale (stockee en MAJUSCULES, RG-1.18). Unique case-insensitive parmi les actifs non archives/non supprimes (RG-1.16, uq_client_company_name_active).',
|
||||||
|
'first_name' => 'Prenom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).',
|
||||||
|
'last_name' => 'Nom du contact principal (capitalise serveur, RG-1.19). first_name OU last_name obligatoire (RG-1.01).',
|
||||||
|
'phone_primary' => 'Telephone principal — stocke en chiffres uniquement (RG-1.20). Obligatoire.',
|
||||||
|
'phone_secondary' => 'Telephone secondaire optionnel — chiffres uniquement (RG-1.20).',
|
||||||
|
'email' => 'Email principal (lowercase serveur, RG-1.21). NON unique (RG-1.17 supprimee, Q4).',
|
||||||
|
'distributor_id' => 'FK auto-referente vers un client porteur de la categorie DISTRIBUTEUR — exclusive avec broker_id (RG-1.03, chk_client_distrib_or_broker). FK -> client.id, ON DELETE SET NULL.',
|
||||||
|
'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.',
|
||||||
|
'description' => 'Onglet Information : description libre. Obligatoire pour le role Commerciale (RG-1.04), optionnel sinon.',
|
||||||
|
'competitors' => 'Onglet Information : concurrents identifies (texte libre ≤ 255). Obligatoire role Commerciale (RG-1.04).',
|
||||||
|
'founded_at' => 'Onglet Information : date de creation de l entreprise. Obligatoire role Commerciale (RG-1.04).',
|
||||||
|
'employees_count' => 'Onglet Information : effectif (entier >= 0). Obligatoire role Commerciale (RG-1.04).',
|
||||||
|
'revenue_amount' => 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).',
|
||||||
|
'director_name' => 'Onglet Information : nom du dirigeant. Obligatoire role Commerciale (RG-1.04).',
|
||||||
|
'profit_amount' => 'Onglet Information : resultat / benefice (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).',
|
||||||
|
'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.',
|
||||||
|
'tva_mode_id' => 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id, ON DELETE RESTRICT.',
|
||||||
|
'n_tva' => 'Onglet Comptabilite : numero de TVA intracommunautaire.',
|
||||||
|
'payment_delay_id' => 'Onglet Comptabilite : delai de reglement — FK -> payment_delay.id, ON DELETE RESTRICT.',
|
||||||
|
'payment_type_id' => 'Onglet Comptabilite : type de reglement — FK -> payment_type.id, ON DELETE RESTRICT. Code LCR impose >= 1 RIB (RG-1.13), VIREMENT impose une banque (RG-1.12).',
|
||||||
|
'bank_id' => 'Onglet Comptabilite : banque — FK -> bank.id, ON DELETE RESTRICT. Obligatoire si payment_type = VIREMENT (RG-1.12).',
|
||||||
|
'is_archived' => 'Drapeau fonctionnel d archivage — masque par defaut dans la liste. Bascule via permission commercial.clients.archive (RG-1.22/23).',
|
||||||
|
'archived_at' => 'Horodatage de l archivage — pose quand is_archived passe a vrai, remis a null a la restauration (RG-1.22/23).',
|
||||||
|
'deleted_at' => 'Horodatage du soft-delete technique (HP M2) — non expose par l API au M1. Null = ligne active.',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
|
'client_category' => [
|
||||||
|
'_table' => 'Jointure M2M client <-> category (Catalog) — categories metier du client (au moins une obligatoire).',
|
||||||
|
'client_id' => 'FK -> client.id, ON DELETE CASCADE — client porteur de la categorie.',
|
||||||
|
'category_id' => 'FK -> category.id, ON DELETE RESTRICT — categorie rattachee au client.',
|
||||||
|
],
|
||||||
|
|
||||||
|
'client_contact' => [
|
||||||
|
'_table' => 'Contacts d un client (1:n) — au moins firstName OU lastName par contact (RG-1.05).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'client_id' => 'FK -> client.id, ON DELETE CASCADE — client proprietaire du contact.',
|
||||||
|
'first_name' => 'Prenom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-1.05, chk_client_contact_name).',
|
||||||
|
'last_name' => 'Nom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-1.05, chk_client_contact_name).',
|
||||||
|
'job_title' => 'Fonction / intitule de poste du contact (≤ 120 caracteres).',
|
||||||
|
'phone_primary' => 'Telephone principal du contact — chiffres uniquement (RG-1.20).',
|
||||||
|
'phone_secondary' => 'Telephone secondaire du contact — chiffres uniquement (RG-1.20).',
|
||||||
|
'email' => 'Email du contact (lowercase serveur, RG-1.21).',
|
||||||
|
'position' => 'Ordre d affichage du contact dans la liste du client (croissant).',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
|
'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).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'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_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.',
|
||||||
|
'country' => 'Pays de l adresse — defaut France.',
|
||||||
|
'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).',
|
||||||
|
'street' => 'Numero et voie de l adresse.',
|
||||||
|
'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).',
|
||||||
|
'position' => 'Ordre d affichage de l adresse dans la liste du client (croissant).',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
|
|
||||||
|
'client_address_site' => [
|
||||||
|
'_table' => 'Jointure M2M client_address <-> site (Sites) — sites desservis par l adresse (>= 1 obligatoire, RG-1.10).',
|
||||||
|
'client_address_id' => 'FK -> client_address.id, ON DELETE CASCADE — adresse concernee.',
|
||||||
|
'site_id' => 'FK -> site.id, ON DELETE RESTRICT — site rattache a l adresse.',
|
||||||
|
],
|
||||||
|
|
||||||
|
'client_address_contact' => [
|
||||||
|
'_table' => 'Jointure M2M client_address <-> client_contact — contacts associes a une adresse.',
|
||||||
|
'client_address_id' => 'FK -> client_address.id, ON DELETE CASCADE — adresse concernee.',
|
||||||
|
'client_contact_id' => 'FK -> client_contact.id, ON DELETE CASCADE — contact associe a l adresse.',
|
||||||
|
],
|
||||||
|
|
||||||
|
'client_address_category' => [
|
||||||
|
'_table' => 'Jointure M2M client_address <-> category — categories d adresse (types SECTEUR/AUTRE uniquement, RG-1.29).',
|
||||||
|
'client_address_id' => 'FK -> client_address.id, ON DELETE CASCADE — adresse concernee.',
|
||||||
|
'category_id' => 'FK -> category.id, ON DELETE RESTRICT — categorie d adresse (type SECTEUR ou AUTRE, RG-1.29).',
|
||||||
|
],
|
||||||
|
|
||||||
|
'client_rib' => [
|
||||||
|
'_table' => 'Coordonnees bancaires d un client (1:n) — >= 1 RIB obligatoire si payment_type = LCR (RG-1.13). Tous les champs audites (pas d AuditIgnore).',
|
||||||
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
|
'client_id' => 'FK -> client.id, ON DELETE CASCADE — client 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 client (croissant).',
|
||||||
|
] + self::timestampableBlamableComments(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,12 +280,25 @@ final class ColumnCommentsCatalog
|
|||||||
* Construit la liste des requetes SQL `COMMENT ON TABLE/COLUMN` (en
|
* Construit la liste des requetes SQL `COMMENT ON TABLE/COLUMN` (en
|
||||||
* dollar-quoting Postgres `$_$`) a partir du catalogue.
|
* dollar-quoting Postgres `$_$`) a partir du catalogue.
|
||||||
*
|
*
|
||||||
|
* @param null|list<string> $onlyTables Restreint la generation a ces tables
|
||||||
|
* (utile pour la migration retrofit qui
|
||||||
|
* ne doit commenter que les tables deja
|
||||||
|
* presentes a son instant T — les tables
|
||||||
|
* des modules crees plus tard posent
|
||||||
|
* leurs propres COMMENT). null = tout.
|
||||||
|
*
|
||||||
* @return list<string>
|
* @return list<string>
|
||||||
*/
|
*/
|
||||||
public static function toSqlStatements(): array
|
public static function toSqlStatements(?array $onlyTables = null): array
|
||||||
{
|
{
|
||||||
|
$allowed = null === $onlyTables ? null : array_fill_keys($onlyTables, true);
|
||||||
|
|
||||||
$statements = [];
|
$statements = [];
|
||||||
foreach (self::comments() as $table => $entries) {
|
foreach (self::comments() as $table => $entries) {
|
||||||
|
if (null !== $allowed && !isset($allowed[$table])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$quotedTable = self::quoteIdent($table);
|
$quotedTable = self::quoteIdent($table);
|
||||||
foreach ($entries as $column => $description) {
|
foreach ($entries as $column => $description) {
|
||||||
if ('_table' === $column) {
|
if ('_table' === $column) {
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Shared\Infrastructure\Export;
|
||||||
|
|
||||||
|
use App\Shared\Domain\Contract\SpreadsheetExporterInterface;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation XLSX du contrat d'export via la librairie PhpSpreadsheet.
|
||||||
|
*
|
||||||
|
* Strictement technique : ecrit la ligne d'en-tete puis les lignes de donnees
|
||||||
|
* dans l'unique feuille du classeur, et retourne le binaire. Aucune logique
|
||||||
|
* metier, aucune reference a une entite d'un module — le mapping des colonnes
|
||||||
|
* est de la responsabilite de l'appelant.
|
||||||
|
*/
|
||||||
|
final class PhpSpreadsheetExporter implements SpreadsheetExporterInterface
|
||||||
|
{
|
||||||
|
// Excel limite le titre d'un onglet a 31 caracteres et interdit certains
|
||||||
|
// caracteres ; on assainit pour ne jamais faire echouer setTitle().
|
||||||
|
private const int MAX_SHEET_TITLE_LENGTH = 31;
|
||||||
|
private const string INVALID_TITLE_CHARS = '*:/\?[]';
|
||||||
|
|
||||||
|
public function export(string $sheetTitle, array $headers, iterable $rows): string
|
||||||
|
{
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
$sheet->setTitle($this->sanitizeSheetTitle($sheetTitle));
|
||||||
|
|
||||||
|
// Ligne 1 : en-tete.
|
||||||
|
$sheet->fromArray($headers, null, 'A1');
|
||||||
|
|
||||||
|
// Lignes 2..n : donnees. Iteration manuelle pour supporter un iterable
|
||||||
|
// paresseux (generator) sans tout materialiser en memoire.
|
||||||
|
$rowNumber = 2;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$sheet->fromArray($row, null, 'A'.$rowNumber);
|
||||||
|
++$rowNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->toBinary($spreadsheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function toBinary(Spreadsheet $spreadsheet): string
|
||||||
|
{
|
||||||
|
$writer = new Xlsx($spreadsheet);
|
||||||
|
|
||||||
|
// Le writer ecrit vers un chemin de fichier : on passe par un fichier
|
||||||
|
// temporaire puis on lit son contenu binaire.
|
||||||
|
$tmpFile = tempnam(sys_get_temp_dir(), 'xlsx_export_');
|
||||||
|
if (false === $tmpFile) {
|
||||||
|
throw new RuntimeException('Impossible de creer un fichier temporaire pour l\'export XLSX.');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$writer->save($tmpFile);
|
||||||
|
$binary = file_get_contents($tmpFile);
|
||||||
|
if (false === $binary) {
|
||||||
|
throw new RuntimeException('Lecture du fichier XLSX temporaire impossible.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $binary;
|
||||||
|
} finally {
|
||||||
|
// Libere les references internes de PhpSpreadsheet puis supprime le
|
||||||
|
// fichier temporaire, meme en cas d'exception.
|
||||||
|
$spreadsheet->disconnectWorksheets();
|
||||||
|
@unlink($tmpFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retire les caracteres interdits et tronque a 31 caracteres ; renvoie un
|
||||||
|
* titre par defaut si la chaine resultante est vide.
|
||||||
|
*/
|
||||||
|
private function sanitizeSheetTitle(string $title): string
|
||||||
|
{
|
||||||
|
$clean = str_replace(str_split(self::INVALID_TITLE_CHARS), '', $title);
|
||||||
|
$clean = mb_substr($clean, 0, self::MAX_SHEET_TITLE_LENGTH);
|
||||||
|
|
||||||
|
return '' === $clean ? 'Export' : $clean;
|
||||||
|
}
|
||||||
|
}
|
||||||
+256
@@ -0,0 +1,256 @@
|
|||||||
|
{
|
||||||
|
"api-platform/symfony": {
|
||||||
|
"version": "4.3",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "4.0",
|
||||||
|
"ref": "e9952e9f393c2d048f10a78f272cd35e807d972b"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/api_platform.yaml",
|
||||||
|
"config/routes/api_platform.yaml",
|
||||||
|
"src/ApiResource/.gitignore"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"doctrine/deprecations": {
|
||||||
|
"version": "1.1",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "1.0",
|
||||||
|
"ref": "fdd756167454623e21f1d769c5b814b243782a67"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"doctrine/doctrine-bundle": {
|
||||||
|
"version": "3.2",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "3.0",
|
||||||
|
"ref": "d39a3bd844edfe90c20ae520b804a3bf4f82b4ad"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/doctrine.yaml",
|
||||||
|
"src/Entity/.gitignore",
|
||||||
|
"src/Repository/.gitignore"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"doctrine/doctrine-fixtures-bundle": {
|
||||||
|
"version": "4.3",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "3.0",
|
||||||
|
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/DataFixtures/AppFixtures.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"doctrine/doctrine-migrations-bundle": {
|
||||||
|
"version": "4.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "3.1",
|
||||||
|
"ref": "1d01ec03c6ecbd67c3375c5478c9a423ae5d6a33"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/doctrine_migrations.yaml",
|
||||||
|
"migrations/.gitignore"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"friendsofphp/php-cs-fixer": {
|
||||||
|
"version": "3.94",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "3.39",
|
||||||
|
"ref": "97aaf9026490db73b86c23d49e5774bc89d2b232"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
".php-cs-fixer.dist.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"lexik/jwt-authentication-bundle": {
|
||||||
|
"version": "3.2",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "2.5",
|
||||||
|
"ref": "e9481b233a11ef7e15fe055a2b21fd3ac1aa2bb7"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/lexik_jwt_authentication.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nelmio/cors-bundle": {
|
||||||
|
"version": "2.6",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "1.5",
|
||||||
|
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/nelmio_cors.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nyholm/psr7": {
|
||||||
|
"version": "1.8",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "1.0",
|
||||||
|
"ref": "4a8c0345442dcca1d8a2c65633dcf0285dd5a5a2"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/nyholm_psr7.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"phpunit/phpunit": {
|
||||||
|
"version": "13.1",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "11.1",
|
||||||
|
"ref": "ca0bc067abfb40a8de1b2561b96cbfc2b833c314"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
".env.test",
|
||||||
|
"phpunit.dist.xml",
|
||||||
|
"tests/bootstrap.php",
|
||||||
|
"bin/phpunit"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/console": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "5.3",
|
||||||
|
"ref": "1781ff40d8a17d87cf53f8d4cf0c8346ed2bb461"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"bin/console"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/flex": {
|
||||||
|
"version": "2.10",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "2.4",
|
||||||
|
"ref": "52e9754527a15e2b79d9a610f98185a1fe46622a"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
".env",
|
||||||
|
".env.dev"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/framework-bundle": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "7.4",
|
||||||
|
"ref": "d5dcd308c8becd725c9d8b91e31aab1ff0bbc30b"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/cache.yaml",
|
||||||
|
"config/packages/framework.yaml",
|
||||||
|
"config/preload.php",
|
||||||
|
"config/routes/framework.yaml",
|
||||||
|
"config/services.yaml",
|
||||||
|
"public/index.php",
|
||||||
|
"src/Controller/.gitignore",
|
||||||
|
"src/Kernel.php",
|
||||||
|
".editorconfig"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/monolog-bundle": {
|
||||||
|
"version": "4.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "3.7",
|
||||||
|
"ref": "1b9efb10c54cb51c713a9391c9300ff8bceda459"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/monolog.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/property-info": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "7.3",
|
||||||
|
"ref": "dae70df71978ae9226ae915ffd5fad817f5ca1f7"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/property_info.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/routing": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "7.4",
|
||||||
|
"ref": "bc94c4fd86f393f3ab3947c18b830ea343e51ded"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/routing.yaml",
|
||||||
|
"config/routes.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/security-bundle": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "7.4",
|
||||||
|
"ref": "c42fee7802181cdd50f61b8622715829f5d2335c"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/security.yaml",
|
||||||
|
"config/routes/security.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/twig-bundle": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "6.4",
|
||||||
|
"ref": "f250159ebe99153d0c640a3e7742876fc7453f2c"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/twig.yaml",
|
||||||
|
"templates/base.html.twig"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"symfony/uid": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "7.0",
|
||||||
|
"ref": "0df5844274d871b37fc3816c57a768ffc60a43a5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"symfony/validator": {
|
||||||
|
"version": "8.0",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "main",
|
||||||
|
"version": "7.0",
|
||||||
|
"ref": "8c1c4e28d26a124b0bb273f537ca8ce443472bfd"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/validator.yaml"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Architecture;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ReflectionClass;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Garde-fou architecture : toute operation `GetCollection` exposee via API Platform
|
||||||
|
* doit avoir la pagination activee (ou laisser la valeur par defaut, qui est
|
||||||
|
* activee globalement dans `config/packages/api_platform.yaml`).
|
||||||
|
*
|
||||||
|
* Interdit : `new GetCollection(paginationEnabled: false)` sans exception documentee.
|
||||||
|
*
|
||||||
|
* Raison : une collection non paginee peut retourner des milliers de lignes et
|
||||||
|
* saturer la memoire du serveur, le reseau et le navigateur. La pagination est la
|
||||||
|
* seule protection fiable contre ce risque sur un CRM a donnees croissantes.
|
||||||
|
*
|
||||||
|
* Quand ajouter une entree dans `EXCLUDED` :
|
||||||
|
* - La collection est structurellement bornee (referentiel statique, < 100 items,
|
||||||
|
* jamais alimente par des utilisateurs) ET la suppression de la pagination est
|
||||||
|
* documentee avec une justification metier explicite.
|
||||||
|
* - Format obligatoire : `FQCN => 'justification + reference ticket/spec'`
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class CollectionsArePaginatedTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Resources API Platform dont un `GetCollection` peut desactiver la pagination.
|
||||||
|
*
|
||||||
|
* Laisser vide au demarrage. Pour ajouter une exception :
|
||||||
|
* 'App\Module\Foo\Infrastructure\ApiPlatform\Resource\BarResource'
|
||||||
|
* => 'Referentiel statique < 50 items (types de contrat). Cf. ERP-XX.',
|
||||||
|
*
|
||||||
|
* @var array<class-string, string>
|
||||||
|
*/
|
||||||
|
private const EXCLUDED = [];
|
||||||
|
|
||||||
|
public function testAllGetCollectionOperationsHavePaginationEnabled(): void
|
||||||
|
{
|
||||||
|
$finder = new Finder()
|
||||||
|
->files()
|
||||||
|
->in(__DIR__.'/../../src')
|
||||||
|
->name('*.php')
|
||||||
|
->contains('#[ApiResource')
|
||||||
|
;
|
||||||
|
|
||||||
|
// Garde : si le scan ne trouve rien, le chemin est casse — le test
|
||||||
|
// deviendrait un faux positif vert. On verifie qu'il a du grain a moudre.
|
||||||
|
self::assertNotEmpty(
|
||||||
|
iterator_to_array($finder),
|
||||||
|
'Aucun fichier #[ApiResource] trouve sous src/ : chemin invalide ou codebase vide.',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
$fqcn = $this->extractFqcn($file->getRealPath());
|
||||||
|
if (null === $fqcn || !class_exists($fqcn)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflection = new ReflectionClass($fqcn);
|
||||||
|
$apiResourceAttributes = $reflection->getAttributes(ApiResource::class);
|
||||||
|
|
||||||
|
if ([] === $apiResourceAttributes) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($apiResourceAttributes as $attribute) {
|
||||||
|
/** @var ApiResource $apiResource */
|
||||||
|
$apiResource = $attribute->newInstance();
|
||||||
|
$operations = $apiResource->getOperations()?->getIterator() ?? [];
|
||||||
|
|
||||||
|
foreach ($operations as $operation) {
|
||||||
|
if (!$operation instanceof GetCollection) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false !== $operation->getPaginationEnabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// La pagination est explicitement desactivee : verifier
|
||||||
|
// que la resource est dans la whitelist EXCLUDED.
|
||||||
|
self::assertArrayHasKey(
|
||||||
|
$fqcn,
|
||||||
|
self::EXCLUDED,
|
||||||
|
sprintf(
|
||||||
|
"La resource %s desactive la pagination sur une operation GetCollection.\n"
|
||||||
|
."Regle : toute collection API Platform doit etre paginee (cf. .claude/rules/backend.md).\n"
|
||||||
|
."Si cette collection est structurellement bornee et que la desactivation est justifiee,\n"
|
||||||
|
.'ajouter une entree dans CollectionsArePaginatedTest::EXCLUDED avec une justification.',
|
||||||
|
$fqcn,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extrait le FQCN (namespace + classe) d'un fichier PHP par lecture du
|
||||||
|
* source, sans charger le fichier.
|
||||||
|
*/
|
||||||
|
private function extractFqcn(string $path): ?string
|
||||||
|
{
|
||||||
|
$source = file_get_contents($path);
|
||||||
|
if (false === $source) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
1 !== preg_match('/^namespace\s+([^;]+);/m', $source, $nsMatch)
|
||||||
|
|| 1 !== preg_match('/^(?:final\s+|abstract\s+|readonly\s+)*class\s+(\w+)/m', $source, $classMatch)
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim($nsMatch[1]).'\\'.$classMatch[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,10 @@ declare(strict_types=1);
|
|||||||
namespace App\Tests\Architecture;
|
namespace App\Tests\Architecture;
|
||||||
|
|
||||||
use App\Module\Catalog\Domain\Entity\CategoryType;
|
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\TvaMode;
|
||||||
use App\Module\Core\Domain\Entity\Permission;
|
use App\Module\Core\Domain\Entity\Permission;
|
||||||
use App\Module\Core\Domain\Entity\Role;
|
use App\Module\Core\Domain\Entity\Role;
|
||||||
use App\Module\Core\Domain\Entity\User;
|
use App\Module\Core\Domain\Entity\User;
|
||||||
@@ -49,6 +53,11 @@ final class EntitiesAreTimestampableBlamableTest extends TestCase
|
|||||||
* - CategoryType : referentiel statique (codes de typage des categories),
|
* - CategoryType : referentiel statique (codes de typage des categories),
|
||||||
* pas de besoin de tracabilite user-driven (cree par migration/seed,
|
* pas de besoin de tracabilite user-driven (cree par migration/seed,
|
||||||
* pas pilote utilisateur au M0). Cf. spec-back § 2.8.bis + RG-1.17.
|
* pas pilote utilisateur au M0). Cf. spec-back § 2.8.bis + RG-1.17.
|
||||||
|
* - TvaMode / PaymentDelay / PaymentType / Bank (M1 Commercial) : referentiels
|
||||||
|
* comptables statiques (id/code/label/position), seedes par migration +
|
||||||
|
* CommercialReferentialFixtures, lecture seule au M1 (HP-M2-2). Pas de
|
||||||
|
* tracabilite user-driven, meme justification que CategoryType. Cf.
|
||||||
|
* spec-back M1 § 2.6 + § 3.5.
|
||||||
*
|
*
|
||||||
* Les futurs referentiels statiques s'ajoutent ici avec une justification.
|
* Les futurs referentiels statiques s'ajoutent ici avec une justification.
|
||||||
*/
|
*/
|
||||||
@@ -58,6 +67,10 @@ final class EntitiesAreTimestampableBlamableTest extends TestCase
|
|||||||
Permission::class,
|
Permission::class,
|
||||||
Site::class,
|
Site::class,
|
||||||
CategoryType::class,
|
CategoryType::class,
|
||||||
|
TvaMode::class,
|
||||||
|
PaymentDelay::class,
|
||||||
|
PaymentType::class,
|
||||||
|
Bank::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testAllBusinessEntitiesImplementBothInterfaces(): void
|
public function testAllBusinessEntitiesImplementBothInterfaces(): void
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ final class CategoryListTest extends AbstractCatalogApiTestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$response = $client->request('GET', '/api/categories');
|
$response = $client->request('GET', '/api/categories?pagination=false');
|
||||||
self::assertSame(200, $response->getStatusCode());
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
$data = $response->toArray();
|
$data = $response->toArray();
|
||||||
@@ -62,7 +62,7 @@ final class CategoryListTest extends AbstractCatalogApiTestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$response = $client->request('GET', '/api/categories?includeDeleted=true');
|
$response = $client->request('GET', '/api/categories?includeDeleted=true&pagination=false');
|
||||||
self::assertSame(200, $response->getStatusCode());
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
$names = array_values(array_filter(
|
$names = array_values(array_filter(
|
||||||
@@ -87,7 +87,7 @@ final class CategoryListTest extends AbstractCatalogApiTestCase
|
|||||||
$this->createCategory(self::TEST_CATEGORY_PREFIX.'mid', $type);
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'mid', $type);
|
||||||
|
|
||||||
$client = $this->createAdminClient();
|
$client = $this->createAdminClient();
|
||||||
$response = $client->request('GET', '/api/categories');
|
$response = $client->request('GET', '/api/categories?pagination=false');
|
||||||
self::assertSame(200, $response->getStatusCode());
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
$names = array_values(array_filter(
|
$names = array_values(array_filter(
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Catalog\Api;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests du contrat de pagination sur GET /api/categories (ERP-72).
|
||||||
|
*
|
||||||
|
* Invariants testes :
|
||||||
|
* - la collection expose les metadonnees Hydra (totalItems, view, member) ;
|
||||||
|
* - itemsPerPage est plafonne au maximum global (50) ;
|
||||||
|
* - une page hors limites retourne une collection vide, pas une 500 ;
|
||||||
|
* - ?pagination=false retourne tous les items sans troncature (select-box) ;
|
||||||
|
* - la pagination est compatible avec le flag ?includeDeleted=true.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class CategoryPaginationTest extends AbstractCatalogApiTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* La collection expose les metadonnees de pagination JSON-LD sans prefixe :
|
||||||
|
* `totalItems`, `view`, `member` (convention API Platform 4, pas hydra:*).
|
||||||
|
*
|
||||||
|
* On cree 12 categories pour depasser la limite par page (10) : la cle
|
||||||
|
* `view` n'est presente que lorsqu'il y a plus d'items que la taille de page.
|
||||||
|
*/
|
||||||
|
public function testCollectionExposesHydraPaginationMetadata(): void
|
||||||
|
{
|
||||||
|
$type = $this->createCategoryType();
|
||||||
|
for ($i = 1; $i <= 12; ++$i) {
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'meta_'.$i, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request('GET', '/api/categories');
|
||||||
|
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
$data = $response->toArray();
|
||||||
|
self::assertArrayHasKey('totalItems', $data, 'La collection doit exposer totalItems.');
|
||||||
|
self::assertArrayHasKey('view', $data, 'La collection doit exposer view (pagination) quand totalItems > itemsPerPage.');
|
||||||
|
self::assertIsArray($data['member'], 'member doit etre un tableau.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Un itemsPerPage arbitrairement grand (99999) doit etre plafonne au
|
||||||
|
* maximum global configure (50). On cree 12 categories pour etre certain
|
||||||
|
* de disposer de donnees ; le cap doit s'appliquer quelle que soit la taille
|
||||||
|
* reelle de la collection.
|
||||||
|
*/
|
||||||
|
public function testItemsPerPageIsCappedAtMaximum(): void
|
||||||
|
{
|
||||||
|
$type = $this->createCategoryType();
|
||||||
|
for ($i = 1; $i <= 12; ++$i) {
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'cap_'.$i, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request('GET', '/api/categories?itemsPerPage=99999');
|
||||||
|
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
// Le cap global est 50 : jamais plus d'items par page que le maximum.
|
||||||
|
self::assertLessThanOrEqual(
|
||||||
|
50,
|
||||||
|
count($response->toArray()['member']),
|
||||||
|
'itemsPerPage doit etre plafonne au maximum global (50).',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Une page tres elevee (99999) sur une petite collection ne doit pas
|
||||||
|
* produire une 500 PG (OFFSET negatif ou depassement de capacite) mais
|
||||||
|
* retourner 200 avec un tableau member vide.
|
||||||
|
*/
|
||||||
|
public function testOutOfBoundPageReturnsEmptyCollectionNot500(): void
|
||||||
|
{
|
||||||
|
$type = $this->createCategoryType();
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'oob', $type);
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request('GET', '/api/categories?page=99999');
|
||||||
|
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
// La page 99999 est forcement vide (on a bien moins que 99999*10 items).
|
||||||
|
self::assertSame(
|
||||||
|
[],
|
||||||
|
$response->toArray()['member'],
|
||||||
|
'Une page hors limites doit retourner un member vide, jamais une 500.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ?pagination=false permet au frontend de desactiver la pagination pour
|
||||||
|
* alimenter un select-box. On cree exactement 12 categories dont les noms
|
||||||
|
* commencent par `test_cat_select_` : le filtre sur ce prefixe isole nos
|
||||||
|
* entrees des donnees concurrentes et prouve que les 12 items sont tous
|
||||||
|
* retournes (et pas seulement les 10 premiers de la page 1).
|
||||||
|
*/
|
||||||
|
public function testClientCanDisablePaginationToFeedASelect(): void
|
||||||
|
{
|
||||||
|
$type = $this->createCategoryType();
|
||||||
|
for ($i = 1; $i <= 12; ++$i) {
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'select_'.$i, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request('GET', '/api/categories?pagination=false');
|
||||||
|
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
$members = $response->toArray()['member'];
|
||||||
|
|
||||||
|
// Filtre sur le sous-prefixe pour ne pas comptabiliser les categories
|
||||||
|
// d'autres tests qui partagent la meme base de donnees.
|
||||||
|
$selectItems = array_values(array_filter(
|
||||||
|
$members,
|
||||||
|
fn (array $m): bool => str_starts_with($m['name'], self::TEST_CATEGORY_PREFIX.'select_'),
|
||||||
|
));
|
||||||
|
|
||||||
|
self::assertCount(
|
||||||
|
12,
|
||||||
|
$selectItems,
|
||||||
|
'?pagination=false doit retourner toutes les categories (pas seulement la page 1).',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* La pagination doit fonctionner conjointement avec le flag ?includeDeleted=true.
|
||||||
|
* On seed 3 categories actives + 2 soft-deleted, on demande itemsPerPage=5 :
|
||||||
|
* la page 1 doit contenir exactement 5 items et totalItems doit valoir >= 5.
|
||||||
|
*/
|
||||||
|
public function testPaginationCombinedWithIncludeDeletedFlag(): void
|
||||||
|
{
|
||||||
|
$type = $this->createCategoryType();
|
||||||
|
|
||||||
|
// 3 categories actives.
|
||||||
|
for ($i = 1; $i <= 3; ++$i) {
|
||||||
|
$this->createCategory(self::TEST_CATEGORY_PREFIX.'pag_active_'.$i, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2 categories soft-deleted.
|
||||||
|
for ($i = 1; $i <= 2; ++$i) {
|
||||||
|
$this->createCategory(
|
||||||
|
self::TEST_CATEGORY_PREFIX.'pag_deleted_'.$i,
|
||||||
|
$type,
|
||||||
|
new DateTimeImmutable(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$response = $client->request('GET', '/api/categories?includeDeleted=true&itemsPerPage=5');
|
||||||
|
|
||||||
|
self::assertSame(200, $response->getStatusCode());
|
||||||
|
|
||||||
|
$data = $response->toArray();
|
||||||
|
// La page retournee ne doit pas exceder itemsPerPage=5.
|
||||||
|
self::assertCount(
|
||||||
|
5,
|
||||||
|
$data['member'],
|
||||||
|
'La page 1 doit contenir exactement 5 items (itemsPerPage=5 avec >= 5 categories disponibles).',
|
||||||
|
);
|
||||||
|
self::assertGreaterThanOrEqual(
|
||||||
|
5,
|
||||||
|
$data['totalItems'],
|
||||||
|
'totalItems doit refleter au moins les 5 categories seedees (actives + soft-deleted).',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
use ApiPlatform\Symfony\Bundle\Test\Client;
|
||||||
|
use App\Module\Catalog\Domain\Entity\Category;
|
||||||
|
use App\Module\Catalog\Domain\Entity\CategoryType;
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
||||||
|
use App\Module\Core\Domain\Entity\Role;
|
||||||
|
use App\Module\Core\Domain\Entity\User;
|
||||||
|
use App\Tests\Module\Core\Api\AbstractApiTestCase;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base des tests fonctionnels du module Commercial (M1 — repertoire clients).
|
||||||
|
*
|
||||||
|
* Etend la base Core : ajoute des factories pour seeder vite des categories
|
||||||
|
* typees (DISTRIBUTEUR / COURTIER / SECTEUR) et des clients, plus un helper
|
||||||
|
* d'authentification admin.
|
||||||
|
*
|
||||||
|
* Cleanup : tearDown purge clients, categories `test_cli_cat_*` et users/roles
|
||||||
|
* `test_*`. Les category_types business sont fetch-or-create (idempotents) et
|
||||||
|
* laisses en place (pas de DELETE pour ne pas entrer en conflit avec d'autres
|
||||||
|
* suites). Pas de DAMA en local -> purge manuelle obligatoire.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
abstract class AbstractCommercialApiTestCase extends AbstractApiTestCase
|
||||||
|
{
|
||||||
|
protected const string TEST_CATEGORY_PREFIX = 'test_cli_cat_';
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
$this->cleanupCommercialTestData();
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createAdminClient(): Client
|
||||||
|
{
|
||||||
|
return $this->authenticatedClient('admin', 'admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recupere (ou cree) un CategoryType par son code metier. Idempotent : la
|
||||||
|
* contrainte d'unicite sur category_type.code interdit les doublons.
|
||||||
|
*/
|
||||||
|
protected function createCategoryType(string $code): CategoryType
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$existing = $em->getRepository(CategoryType::class)->findOneBy(['code' => $code]);
|
||||||
|
if (null !== $existing) {
|
||||||
|
return $existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = new CategoryType();
|
||||||
|
$type->setCode($code);
|
||||||
|
$type->setLabel(ucfirst(strtolower($code)));
|
||||||
|
$em->persist($type);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cree une Category de test rattachee a un type metier donne (code).
|
||||||
|
*/
|
||||||
|
protected function createCategory(string $typeCode = 'SECTEUR'): Category
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$suffix = substr(bin2hex(random_bytes(4)), 0, 8);
|
||||||
|
$category = new Category();
|
||||||
|
$category->setName(self::TEST_CATEGORY_PREFIX.$suffix);
|
||||||
|
$category->setCategoryType($this->createCategoryType($typeCode));
|
||||||
|
$em->persist($category);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seede directement un Client en base (sans passer par l'API), pour les
|
||||||
|
* tests de liste / archivage. Le client porte une categorie SECTEUR.
|
||||||
|
*/
|
||||||
|
protected function seedClient(string $companyName, bool $isArchived = false, string $categoryTypeCode = 'SECTEUR'): ClientEntity
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
$client = new ClientEntity();
|
||||||
|
// Stocke en MAJUSCULES pour refleter l'etat normalise (RG-1.18) qu'aurait
|
||||||
|
// produit le ClientProcessor via l'API.
|
||||||
|
$client->setCompanyName(mb_strtoupper($companyName, 'UTF-8'));
|
||||||
|
$client->setLastName('Seed');
|
||||||
|
$client->setPhonePrimary('0102030405');
|
||||||
|
$client->setEmail(strtolower(str_replace(' ', '', $companyName)).'@seed.test');
|
||||||
|
$client->addCategory($this->createCategory($categoryTypeCode));
|
||||||
|
$client->setIsArchived($isArchived);
|
||||||
|
if ($isArchived) {
|
||||||
|
$client->setArchivedAt(new DateTimeImmutable());
|
||||||
|
}
|
||||||
|
$em->persist($client);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function cleanupCommercialTestData(): void
|
||||||
|
{
|
||||||
|
$em = $this->getEm();
|
||||||
|
|
||||||
|
// Clients d'abord (la jointure client_category est purgee par
|
||||||
|
// ON DELETE CASCADE ; les auto-references distributor/broker sont
|
||||||
|
// ON DELETE SET NULL).
|
||||||
|
$em->createQuery('DELETE FROM '.ClientEntity::class)->execute();
|
||||||
|
|
||||||
|
// Categories de test ensuite (FK client_category deja purgee).
|
||||||
|
$em->createQuery(
|
||||||
|
'DELETE FROM '.Category::class.' c WHERE c.name LIKE :prefix',
|
||||||
|
)->setParameter('prefix', self::TEST_CATEGORY_PREFIX.'%')->execute();
|
||||||
|
|
||||||
|
// Users / roles jetables.
|
||||||
|
$em->createQuery(
|
||||||
|
'DELETE FROM '.User::class.' u WHERE u.username LIKE :prefix',
|
||||||
|
)->setParameter('prefix', 'test_%')->execute();
|
||||||
|
|
||||||
|
$em->createQuery(
|
||||||
|
'DELETE FROM '.Role::class.' r WHERE r.code LIKE :prefix',
|
||||||
|
)->setParameter('prefix', 'test_%')->execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
use App\Module\Sites\Domain\Entity\Site;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests fonctionnels de l'onglet Adresse — combler les trous (ERP-60).
|
||||||
|
*
|
||||||
|
* RG-1.09 (code postal) et RG-1.10 (>= 1 site) sont DEJA couverts par
|
||||||
|
* ClientSubResourceApiTest (ERP-57) et ne sont pas reduplique ici. Ce fichier
|
||||||
|
* cible les contraintes CHECK BDD non encore testees :
|
||||||
|
* - RG-1.06 / RG-1.07 / RG-1.08 : `chk_client_address_prospect_exclusive`
|
||||||
|
* (is_prospect exclusif de is_delivery / is_billing) ;
|
||||||
|
* - RG-1.11 : `chk_client_address_billing_email` (billing_email obligatoire
|
||||||
|
* ssi is_billing).
|
||||||
|
*
|
||||||
|
* Note : ces regles sont portees par des CHECK Postgres (pas d'Assert ni de
|
||||||
|
* regle Processor au M1). On verifie donc que la combinaison invalide est
|
||||||
|
* REJETEE par le serveur (statut >= 400), sans coupler le test au code exact :
|
||||||
|
* une violation CHECK non mappee remonte aujourd'hui en erreur serveur ; un
|
||||||
|
* mapping fin vers 422 serait une amelioration ulterieure (hors perimetre
|
||||||
|
* ERP-60, test-only).
|
||||||
|
*
|
||||||
|
* RG-1.29 (filtrage du type de categorie SECTEUR/AUTRE sur une adresse) n'est
|
||||||
|
* PAS testee : la validation d'ecriture correspondante n'est pas implementee
|
||||||
|
* cote back au M1 (et ne figure pas dans la liste § 8.1). Documentee comme gap
|
||||||
|
* dans le cahier de test #478.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ClientAddressTest extends AbstractCommercialApiTestCase
|
||||||
|
{
|
||||||
|
private const string LD = 'application/ld+json';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.06 / RG-1.07 : une adresse de prospection ne peut pas etre une
|
||||||
|
* adresse de livraison (CHECK chk_client_address_prospect_exclusive).
|
||||||
|
*/
|
||||||
|
public function testProspectAddressCannotBeDelivery(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Prospect Delivery');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isProspect' => true,
|
||||||
|
'isDelivery' => true,
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertGreaterThanOrEqual(400, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.06 / RG-1.08 : une adresse de prospection ne peut pas etre une
|
||||||
|
* adresse de facturation (meme CHECK). On fournit billingEmail pour que la
|
||||||
|
* seule violation possible soit l'exclusivite prospect/billing.
|
||||||
|
*/
|
||||||
|
public function testProspectAddressCannotBeBilling(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Prospect Billing');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isProspect' => true,
|
||||||
|
'isBilling' => true,
|
||||||
|
'billingEmail' => 'facturation@test.fr',
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertGreaterThanOrEqual(400, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.11 : une adresse de facturation exige un billingEmail
|
||||||
|
* (CHECK chk_client_address_billing_email).
|
||||||
|
*/
|
||||||
|
public function testBillingAddressRequiresBillingEmail(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Billing No Email');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isBilling' => true,
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertGreaterThanOrEqual(400, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.11 (sens inverse) : une adresse NON facturable ne peut pas porter un
|
||||||
|
* billingEmail (meme CHECK).
|
||||||
|
*/
|
||||||
|
public function testNonBillingAddressRejectsBillingEmail(): void
|
||||||
|
{
|
||||||
|
$this->skipIfSitesModuleDisabled();
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Non Billing With Email');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'isBilling' => false,
|
||||||
|
'billingEmail' => 'parasite@test.fr',
|
||||||
|
'postalCode' => '86100',
|
||||||
|
'city' => 'Châtellerault',
|
||||||
|
'street' => '1 rue du Test',
|
||||||
|
'sites' => [$this->firstSiteIri()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertGreaterThanOrEqual(400, $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retourne l'IRI du premier site seede (fixtures Sites).
|
||||||
|
*/
|
||||||
|
private function firstSiteIri(): string
|
||||||
|
{
|
||||||
|
$site = $this->getEm()->getRepository(Site::class)->findOneBy([]);
|
||||||
|
self::assertNotNull($site, 'Aucun site seede : impossible de tester les adresses.');
|
||||||
|
|
||||||
|
return '/api/sites/'.$site->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,285 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests fonctionnels de l'API /api/clients (M1) — branche ERP-55.
|
||||||
|
*
|
||||||
|
* Authentifies en ADMIN (bypass RBAC via isAdmin) : on valide ici les regles
|
||||||
|
* METIER (normalisation, unicite, distributor/broker, archivage, liste). Le
|
||||||
|
* gating par permission (accounting.manage / archive / RG-1.28 strict, RG-1.04
|
||||||
|
* Commerciale) est couvert par les tests unitaires du ClientProcessor : il
|
||||||
|
* exige des users non-admin portant des permissions `commercial.clients.*` qui
|
||||||
|
* ne sont declarees qu'en ERP-59 (tests RBAC complets en ERP-60).
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ClientApiTest extends AbstractCommercialApiTestCase
|
||||||
|
{
|
||||||
|
private const string LD = 'application/ld+json';
|
||||||
|
|
||||||
|
public function testPostNormalizesTextFields(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$response = $client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'acme sas',
|
||||||
|
'firstName' => 'JEAN',
|
||||||
|
'lastName' => 'dupont',
|
||||||
|
'phonePrimary' => '06.12.34.56.78',
|
||||||
|
'email' => 'Jean.DUPONT@ACME.FR',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
$data = $response->toArray();
|
||||||
|
// RG-1.18 / 1.19 / 1.20 / 1.21
|
||||||
|
self::assertSame('ACME SAS', $data['companyName']);
|
||||||
|
self::assertSame('Jean', $data['firstName']);
|
||||||
|
self::assertSame('Dupont', $data['lastName']);
|
||||||
|
self::assertSame('0612345678', $data['phonePrimary']);
|
||||||
|
self::assertSame('jean.dupont@acme.fr', $data['email']);
|
||||||
|
self::assertFalse($data['isArchived']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostDuplicateCompanyNameReturns409(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
$iri = '/api/categories/'.$cat->getId();
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
'companyName' => 'Doublon SARL',
|
||||||
|
'firstName' => 'A',
|
||||||
|
'phonePrimary' => '0102030405',
|
||||||
|
'email' => 'dup@test.fr',
|
||||||
|
'categories' => [$iri],
|
||||||
|
];
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload]);
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
|
||||||
|
// Meme nom (insensible a la casse via l'index LOWER) -> 409 (RG-1.16).
|
||||||
|
$payload['email'] = 'dup2@test.fr';
|
||||||
|
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload]);
|
||||||
|
self::assertResponseStatusCodeSame(409);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostWithoutFirstOrLastNameReturns422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'No Contact Name',
|
||||||
|
'phonePrimary' => '0102030405',
|
||||||
|
'email' => 'nc@test.fr',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// RG-1.01
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostWithoutCategoryReturns422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'No Category',
|
||||||
|
'firstName' => 'A',
|
||||||
|
'phonePrimary' => '0102030405',
|
||||||
|
'email' => 'nocat@test.fr',
|
||||||
|
'categories' => [],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert\Count(min: 1)
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostWithDistributorAndBrokerReturns422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
$distributor = $this->seedClient('Distrib Mutex', false, 'DISTRIBUTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Mutex Client',
|
||||||
|
'firstName' => 'A',
|
||||||
|
'phonePrimary' => '0102030405',
|
||||||
|
'email' => 'mutex@test.fr',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
'distributor' => '/api/clients/'.$distributor->getId(),
|
||||||
|
'broker' => '/api/clients/'.$distributor->getId(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// RG-1.03 (exclusivite)
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostDistributorReferencingNonDistributorReturns422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
$notDistro = $this->seedClient('Pas Un Distrib', false, 'SECTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Bad Distrib Ref',
|
||||||
|
'firstName' => 'A',
|
||||||
|
'phonePrimary' => '0102030405',
|
||||||
|
'email' => 'baddistrib@test.fr',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
'distributor' => '/api/clients/'.$notDistro->getId(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// RG-1.03 (le distributor doit etre categorise DISTRIBUTEUR)
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostValidDistributorReturns201(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
$distributor = $this->seedClient('Vrai Distrib', false, 'DISTRIBUTEUR');
|
||||||
|
|
||||||
|
$client->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Client Avec Distrib',
|
||||||
|
'firstName' => 'A',
|
||||||
|
'phonePrimary' => '0102030405',
|
||||||
|
'email' => 'okdistrib@test.fr',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
'distributor' => '/api/clients/'.$distributor->getId(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListSortedByCompanyNameAscAndExcludesArchived(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$this->seedClient('Zebra Co');
|
||||||
|
$this->seedClient('Alpha Co');
|
||||||
|
$this->seedClient('Archivé Co', true);
|
||||||
|
|
||||||
|
$names = $client->request('GET', '/api/clients?pagination=false', [
|
||||||
|
'headers' => ['Accept' => self::LD],
|
||||||
|
])->toArray()['member'];
|
||||||
|
$companyNames = array_map(static fn (array $c): string => $c['companyName'], $names);
|
||||||
|
|
||||||
|
// RG-1.24 : l'archive est exclue par defaut.
|
||||||
|
self::assertNotContains('ARCHIVÉ CO', $companyNames);
|
||||||
|
// RG-1.26 : tri companyName ASC (Alpha avant Zebra).
|
||||||
|
$alpha = array_search('ALPHA CO', $companyNames, true);
|
||||||
|
$zebra = array_search('ZEBRA CO', $companyNames, true);
|
||||||
|
self::assertNotFalse($alpha);
|
||||||
|
self::assertNotFalse($zebra);
|
||||||
|
self::assertLessThan($zebra, $alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListIncludeArchivedReturnsArchived(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$this->seedClient('Hidden Archived', true);
|
||||||
|
|
||||||
|
$members = $client->request('GET', '/api/clients?includeArchived=true&pagination=false', [
|
||||||
|
'headers' => ['Accept' => self::LD],
|
||||||
|
])->toArray()['member'];
|
||||||
|
$names = array_map(static fn (array $c): string => $c['companyName'], $members);
|
||||||
|
|
||||||
|
// RG-1.25
|
||||||
|
self::assertContains('HIDDEN ARCHIVED', $names);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCollectionIsPaginated(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$this->seedClient('Paginated One');
|
||||||
|
|
||||||
|
// Collection Hydra avec total (la cle `view` n'apparait qu'a partir de
|
||||||
|
// 2 pages cote API Platform 4, donc non assertable sur page unique).
|
||||||
|
$page1 = $client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]])->toArray();
|
||||||
|
self::assertArrayHasKey('totalItems', $page1);
|
||||||
|
self::assertNotEmpty($page1['member']);
|
||||||
|
|
||||||
|
// Preuve que la pagination serveur est bien engagee : la page 2 d'un jeu
|
||||||
|
// tenant sur une page est vide (un provider non pagine ignorerait `page`
|
||||||
|
// et renverrait quand meme les items).
|
||||||
|
$page2 = $client->request('GET', '/api/clients?page=2', ['headers' => ['Accept' => self::LD]])->toArray();
|
||||||
|
self::assertSame([], $page2['member']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPatchArchiveSetsArchivedAtThenRestore(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('To Archive');
|
||||||
|
$iri = '/api/clients/'.$seed->getId();
|
||||||
|
|
||||||
|
// Archive (RG-1.22) : admin a la permission archive via bypass isAdmin.
|
||||||
|
$archived = $client->request('PATCH', $iri, [
|
||||||
|
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
||||||
|
'json' => ['isArchived' => true],
|
||||||
|
])->toArray();
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
self::assertTrue($archived['isArchived']);
|
||||||
|
self::assertNotNull($archived['archivedAt']);
|
||||||
|
|
||||||
|
// Restauration (RG-1.23) : archivedAt repasse a null.
|
||||||
|
$restored = $client->request('PATCH', $iri, [
|
||||||
|
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
||||||
|
'json' => ['isArchived' => false],
|
||||||
|
])->toArray();
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
self::assertFalse($restored['isArchived']);
|
||||||
|
self::assertNull($restored['archivedAt']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPatchArchiveWithOtherFieldReturns422(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Archive Plus Field');
|
||||||
|
|
||||||
|
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
||||||
|
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
||||||
|
'json' => ['isArchived' => true, 'companyName' => 'Renamed'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// RG-1.22 : une requete d'archivage ne modifie aucun autre champ.
|
||||||
|
self::assertResponseStatusCodeSame(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetDetailEmbedsSubCollections(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Detail Embed');
|
||||||
|
|
||||||
|
$data = $client->request('GET', '/api/clients/'.$seed->getId(), [
|
||||||
|
'headers' => ['Accept' => self::LD],
|
||||||
|
])->toArray();
|
||||||
|
|
||||||
|
// § 4.2 : le detail embarque contacts / adresses / ribs.
|
||||||
|
self::assertArrayHasKey('contacts', $data);
|
||||||
|
self::assertArrayHasKey('addresses', $data);
|
||||||
|
self::assertArrayHasKey('ribs', $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests d'archivage / restauration — combler les trous (ERP-60).
|
||||||
|
*
|
||||||
|
* Le cas nominal RG-1.22 (archive pose archivedAt) + RG-1.23 (restauration
|
||||||
|
* repasse archivedAt a null) ainsi que le 422 « archive + autre champ » sont
|
||||||
|
* DEJA couverts par ClientApiTest (ERP-55). Ce fichier cible le trou identifie
|
||||||
|
* en revue (P1 review ERP-55) : le 409 de RESTAURATION en conflit d'unicite.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ClientArchiveTest extends AbstractCommercialApiTestCase
|
||||||
|
{
|
||||||
|
private const string MERGE = 'application/merge-patch+json';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.23 : restaurer un client archive dont le nom a ete repris par un
|
||||||
|
* client actif entre-temps doit echouer en 409 (l'index partiel
|
||||||
|
* uq_client_company_name_active n'admet qu'un seul actif portant ce nom).
|
||||||
|
*
|
||||||
|
* Scenario :
|
||||||
|
* 1. un client « ACME CONFLICT » est archive (donc hors index partiel) ;
|
||||||
|
* 2. un autre client actif « ACME CONFLICT » est cree (autorise tant que le
|
||||||
|
* premier reste archive) ;
|
||||||
|
* 3. la restauration du premier le rendrait actif -> collision d'unicite
|
||||||
|
* -> ClientProcessor traduit la UniqueConstraintViolationException en 409.
|
||||||
|
*/
|
||||||
|
public function testRestoreConflictReturns409(): void
|
||||||
|
{
|
||||||
|
$client = $this->createAdminClient();
|
||||||
|
|
||||||
|
$archived = $this->seedClient('Acme Conflict', true);
|
||||||
|
$this->seedClient('Acme Conflict', false);
|
||||||
|
|
||||||
|
$client->request('PATCH', '/api/clients/'.$archived->getId(), [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['isArchived' => false],
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertResponseStatusCodeSame(409);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Module\Commercial\Api;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests Audit + Timestampable/Blamable du repertoire clients (ERP-60).
|
||||||
|
*
|
||||||
|
* Couvre :
|
||||||
|
* - RG-1.27 : createdAt / createdBy figes au POST, updatedBy reflete bien
|
||||||
|
* l'auteur de la modification (POST admin puis PATCH par un autre user) ;
|
||||||
|
* - Audit (§ 6.1) : le RIB est `#[Auditable]` SANS `#[AuditIgnore]` sur iban /
|
||||||
|
* bic — ces champs sensibles DOIVENT donc apparaitre dans le diff audite
|
||||||
|
* (decision Matthieu, revue MR 29/05/2026).
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ClientAuditTest extends AbstractCommercialApiTestCase
|
||||||
|
{
|
||||||
|
private const string LD = 'application/ld+json';
|
||||||
|
private const string MERGE = 'application/merge-patch+json';
|
||||||
|
private const string RIB_TYPE = 'commercial.ClientRib';
|
||||||
|
private const string VALID_IBAN = 'FR1420041010050500013M02606';
|
||||||
|
private const string VALID_BIC = 'BNPAFRPPXXX';
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-1.27 : createdAt / createdBy sont poses au POST puis figes ; updatedBy
|
||||||
|
* suit l'auteur de la derniere modification. On cree en admin puis on
|
||||||
|
* modifie avec un user `commercial.clients.manage` distinct : createdBy reste
|
||||||
|
* l'admin, updatedBy devient le manager, createdAt ne bouge pas.
|
||||||
|
*/
|
||||||
|
public function testCreatedFrozenAndUpdatedByReflectsModifier(): void
|
||||||
|
{
|
||||||
|
// 1. User modificateur (non-admin) cree AVANT le reboot de kernel induit
|
||||||
|
// par les clients authentifies suivants ; il est persiste en base.
|
||||||
|
$manageCreds = $this->createUserWithPermission('commercial.clients.manage');
|
||||||
|
|
||||||
|
// 2. Creation en admin (createdBy = admin).
|
||||||
|
$admin = $this->createAdminClient();
|
||||||
|
$cat = $this->createCategory('SECTEUR');
|
||||||
|
|
||||||
|
$created = $admin->request('POST', '/api/clients', [
|
||||||
|
'headers' => ['Content-Type' => self::LD],
|
||||||
|
'json' => [
|
||||||
|
'companyName' => 'Blamable Co',
|
||||||
|
'firstName' => 'A',
|
||||||
|
'phonePrimary' => '0102030405',
|
||||||
|
'email' => 'blamable@test.fr',
|
||||||
|
'categories' => ['/api/categories/'.$cat->getId()],
|
||||||
|
],
|
||||||
|
])->toArray();
|
||||||
|
self::assertResponseStatusCodeSame(201);
|
||||||
|
$id = (int) $created['id'];
|
||||||
|
$createdAtTs = new DateTimeImmutable((string) $created['createdAt'])->getTimestamp();
|
||||||
|
|
||||||
|
// 3. Modification par le manager (updatedBy = manager).
|
||||||
|
$manage = $this->authenticatedClient($manageCreds['username'], $manageCreds['password']);
|
||||||
|
$manage->request('PATCH', '/api/clients/'.$id, [
|
||||||
|
'headers' => ['Content-Type' => self::MERGE],
|
||||||
|
'json' => ['companyName' => 'Blamable Renamed'],
|
||||||
|
]);
|
||||||
|
self::assertResponseStatusCodeSame(200);
|
||||||
|
|
||||||
|
// 4. Verification cote base (etat re-charge depuis la BDD).
|
||||||
|
$em = $this->getEm();
|
||||||
|
$em->clear();
|
||||||
|
$reloaded = $em->getRepository(ClientEntity::class)->find($id);
|
||||||
|
self::assertNotNull($reloaded);
|
||||||
|
|
||||||
|
self::assertSame('admin', $reloaded->getCreatedBy()?->getUserIdentifier(), 'createdBy doit rester l\'admin createur.');
|
||||||
|
self::assertSame(
|
||||||
|
$manageCreds['username'],
|
||||||
|
$reloaded->getUpdatedBy()?->getUserIdentifier(),
|
||||||
|
'updatedBy doit refleter le dernier modificateur.',
|
||||||
|
);
|
||||||
|
self::assertSame($createdAtTs, $reloaded->getCreatedAt()?->getTimestamp(), 'createdAt doit etre fige au POST.');
|
||||||
|
self::assertNotNull($reloaded->getUpdatedAt());
|
||||||
|
self::assertGreaterThanOrEqual($createdAtTs, $reloaded->getUpdatedAt()->getTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audit § 6.1 : la creation d'un RIB produit une ligne audit_log
|
||||||
|
* `commercial.ClientRib` / `create` dont le snapshot contient iban et bic
|
||||||
|
* (champs volontairement NON ignores).
|
||||||
|
*/
|
||||||
|
public function testRibCreateAuditIncludesIbanAndBic(): void
|
||||||
|
{
|
||||||
|
$admin = $this->createAdminClient();
|
||||||
|
$seed = $this->seedClient('Rib Audit Host');
|
||||||
|
|
||||||
|
$rib = $admin->request('POST', '/api/clients/'.$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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user