Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 034301ceaf | |||
| 8d0a9a67ef | |||
| bc4b1d0492 |
@@ -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` (à lire à la demande, non chargés en permanence).
|
Doc humaine : @README.md — Spec audit : @doc/audit-log.md
|
||||||
|
|
||||||
## 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)
|
||||||
@@ -37,7 +37,7 @@ Doc humaine : `README.md` — Spec audit : `doc/audit-log.md` (à lire à la dem
|
|||||||
@.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)
|
||||||
@@ -70,5 +70,3 @@ 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,41 +169,13 @@ 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 | RBAC métier |
|
| Username | Password | Role |
|
||||||
|----------|----------|------|-------------|
|
|----------|----------|------|
|
||||||
| admin | admin | ROLE_ADMIN | bypass (is_admin) |
|
| admin | admin | ROLE_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,7 +16,6 @@
|
|||||||
"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.*",
|
||||||
@@ -24,7 +23,6 @@
|
|||||||
"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
+80
-514
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "aada2e60fd7563f1498b5505b37e3f4b",
|
"content-hash": "d65a546151abb6b977fbf7f1c86d14fe",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "api-platform/doctrine-common",
|
"name": "api-platform/doctrine-common",
|
||||||
@@ -1160,85 +1160,6 @@
|
|||||||
},
|
},
|
||||||
"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",
|
||||||
@@ -2709,191 +2630,6 @@
|
|||||||
],
|
],
|
||||||
"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",
|
||||||
@@ -3316,115 +3052,6 @@
|
|||||||
},
|
},
|
||||||
"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",
|
||||||
@@ -3886,57 +3513,6 @@
|
|||||||
},
|
},
|
||||||
"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",
|
||||||
@@ -5596,95 +5172,6 @@
|
|||||||
],
|
],
|
||||||
"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",
|
||||||
@@ -8776,6 +8263,85 @@
|
|||||||
],
|
],
|
||||||
"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",
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ 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
|
||||||
@@ -70,16 +66,6 @@ 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,13 +103,6 @@ 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.66'
|
app.version: '0.1.58'
|
||||||
|
|||||||
@@ -118,8 +118,6 @@ Aucun pattern soft delete existant dans Starseed (vérifié, aucune entité ne p
|
|||||||
|
|
||||||
Index unique partiel sur `(LOWER(name), category_type_id) WHERE deleted_at IS NULL`. Permet de recréer une catégorie avec le même `(name, type)` après suppression logique. Postgres supporte nativement (`CREATE UNIQUE INDEX ... WHERE`). Pattern propre, pas besoin de validator applicatif maison côté unicité — la contrainte SQL fait le job.
|
Index unique partiel sur `(LOWER(name), category_type_id) WHERE deleted_at IS NULL`. Permet de recréer une catégorie avec le même `(name, type)` après suppression logique. Postgres supporte nativement (`CREATE UNIQUE INDEX ... WHERE`). Pattern propre, pas besoin de validator applicatif maison côté unicité — la contrainte SQL fait le job.
|
||||||
|
|
||||||
> **🔗 Évolution ERP-78 (refonte taxonomie M1)** : `Category` porte désormais une colonne **`code`** (`VARCHAR(50)`, NOT NULL), slug MAJUSCULE auto-généré du nom (figé à la création, lecture seule via l'API), avec un **second index unique partiel** `uq_category_code (code) WHERE deleted_at IS NULL`. Ce code est la clé métier stable utilisée par le M1 Commercial (RG-1.03 / RG-1.29). Détail : `docs/specs/M1-clients/spec-back.md` § 3.3.
|
|
||||||
|
|
||||||
### 2.5 Audit & traces temporelles — deux niveaux complémentaires
|
### 2.5 Audit & traces temporelles — deux niveaux complémentaires
|
||||||
|
|
||||||
Deux mécanismes **indépendants** cohabitent :
|
Deux mécanismes **indépendants** cohabitent :
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
# 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 → 422 (Assert\Callback + CHECK filet) | `ClientAddressTest::testProspectAddressCannotBeDelivery` ; `::testProspectAddressCannotBeBilling` | ERP-60 / **ERP-76** |
|
|
||||||
| RG-1.09 | Code postal `^[0-9]{4,5}$` → 422 | `ClientSubResourceApiTest::testPostAddressWithInvalidPostalCodeReturns422` | ERP-57 |
|
|
||||||
| RG-1.10 | ≥ 1 site sur adresse → 422 | `ClientSubResourceApiTest::testPostAddressWithoutSiteReturns422` | ERP-57 |
|
|
||||||
| RG-1.11 | billingEmail obligatoire ssi isBilling → 422 (Assert\Callback + CHECK filet) | `ClientAddressTest::testBillingAddressRequiresBillingEmail` ; `::testNonBillingAddressRejectsBillingEmail` | ERP-60 / **ERP-76** |
|
|
||||||
| 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** : `ClientAddress::validateCategoryTypes` (Assert\Callback) rejette une catégorie DISTRIBUTEUR/COURTIER en 422 (violation `categories`). Tests : `ClientAddressTest::testAddressRejectsDistributorCategory` / `::testAddressRejectsBrokerCategory` / `::testAddressAcceptsSectorCategory` / `::testAddressAcceptsOtherCategory` | **ERP-76** |
|
|
||||||
|
|
||||||
## 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)**~~ — **résolu en ERP-76**. La validation
|
|
||||||
d'écriture refuse désormais une catégorie de type `DISTRIBUTEUR`/`COURTIER` sur
|
|
||||||
une `ClientAddress` (→ 422, violation `categories`) via l'Assert\Callback
|
|
||||||
`ClientAddress::validateCategoryTypes`. Le filtrage de lecture reste
|
|
||||||
front-driven (SearchFilter). Couvert par `ClientAddressTest`.
|
|
||||||
- ~~**Violations CHECK → statut HTTP**~~ — **résolu en ERP-76**. Les règles
|
|
||||||
d'adresse RG-1.06/07/08/11 sont désormais rejetées en **422** par des
|
|
||||||
Assert\Callback applicatifs (`validateProspectExclusivity` /
|
|
||||||
`validateBillingEmailPresence`) qui s'exécutent AVANT la base. Les CHECK
|
|
||||||
Postgres (`chk_client_address_prospect_exclusive` /
|
|
||||||
`chk_client_address_billing_email`) restent en filet de sécurité. Les tests
|
|
||||||
`ClientAddressTest` assertent maintenant le 422 explicite (et non plus ≥ 400).
|
|
||||||
@@ -465,32 +465,26 @@ CREATE TABLE client_rib (
|
|||||||
CREATE INDEX idx_client_rib_client ON client_rib(client_id);
|
CREATE INDEX idx_client_rib_client ON client_rib(client_id);
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3.3 Seed taxonomie — type unique `CLIENT` + `Category.code` (refonte ERP-78)
|
### 3.3 Seed `CategoryType` (extension du M0)
|
||||||
|
|
||||||
> **⚠ Refonte ERP-78 (décision produit 01/06) — le modèle ci-dessous remplace l'ancien.**
|
Au M0, la table `category_type` a été créée mais reste vide (HP-1 du M0). Le M1 lève cette restriction avec un seed initial des **types métier** dont le module Tiers a besoin :
|
||||||
> Historique : à l'origine (#38), `DISTRIBUTEUR` / `COURTIER` / `SECTEUR` / `AUTRE` étaient des **`category_type`**. Le modèle a été **inversé** :
|
|
||||||
>
|
|
||||||
> - **UN SEUL `category_type` : `CLIENT`** (code `CLIENT`, label « Client »).
|
|
||||||
> - `Distributeur` / `Courtier` / `Secteur` / `Autre` (+ catégories métier fines) sont désormais des **`Category`** rattachées au type `CLIENT`.
|
|
||||||
> - Le filtrage métier ne se fait plus sur le **type** mais sur un **`code` stable porté par la `Category`** (NOT NULL, unique parmi les actifs — index partiel `uq_category_code`). Le code est un **slug MAJUSCULE auto-généré du nom** (`CategoryCodeGenerator`), figé à la création, et exposé en **lecture seule** (groupe `category:read`). Les codes `DISTRIBUTEUR` / `COURTIER` (anciennement portés par le type) sont reportés sur les `Category` correspondantes.
|
|
||||||
|
|
||||||
Seed cible (migration corrective `Version20260602100000`, namespace racine) :
|
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
-- Type unique
|
INSERT INTO category_type (code, label, position) VALUES
|
||||||
INSERT INTO category_type (code, label) VALUES ('CLIENT', 'Client') ON CONFLICT (code) DO NOTHING;
|
('DISTRIBUTEUR', 'Distributeur', 10),
|
||||||
-- Catégories système sous CLIENT (codes stables pilotant les RG)
|
('COURTIER', 'Courtier', 20),
|
||||||
-- Distributeur -> DISTRIBUTEUR, Courtier -> COURTIER, Secteur -> SECTEUR, Autre -> AUTRE
|
('SECTEUR', 'Secteur', 30),
|
||||||
|
('AUTRE', 'Autre', 99);
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Note** : le CRUD admin de `CategoryType` reste HP (cf. M0). Le `code` de `Category` n'est PAS saisissable via l'API (auto-généré côté serveur).
|
> **Note** : le CRUD admin de `CategoryType` reste HP (cf. M0).
|
||||||
>
|
>
|
||||||
> **Seed en DEUX endroits (décision 29/05, vérifiée empiriquement)** : le `make db-reset` lance les fixtures, dont le purger Doctrine **vide `category` / `category_type`** (entités M0 mappées) avant `load()` → un seed posé uniquement en migration disparaît en dev/test. Donc :
|
> **Seed en DEUX endroits (décision 29/05, vérifiée empiriquement)** : le `make db-reset` lance les fixtures, dont le purger Doctrine **vide `category_type`** (entité M0 mappée) avant `load()` → un seed posé uniquement en migration disparaît en dev/test. Donc :
|
||||||
> 1. **Migration** (`ON CONFLICT` / guards `NOT EXISTS`) → sert en **prod** (pas de fixtures).
|
> 1. **Migration** (`ON CONFLICT (code) DO NOTHING`) → sert en **prod** (pas de fixtures).
|
||||||
> 2. **Fixtures idempotentes** (`CategoryTypeFixtures` → type CLIENT ; `CategoryFixtures` → catégories codées sous CLIENT) → survivent au `db-reset`.
|
> 2. **Fixture Commercial idempotente** (ex. `CommercialReferentialFixtures`) re-seedant les 4 types → survit au `db-reset`, satisfait le critère « 4 types présents après db-reset ».
|
||||||
>
|
>
|
||||||
> ⚠ **À venir en ERP-54** : `tva_mode` / `payment_delay` / `payment_type` / `bank` ne sont pas encore des entités mappées au M1.0 → le purger ne les touche pas, leur seed migration survit. **Dès qu'ERP-54 crée leurs entités, ils seront purgés au db-reset** → il faudra les ajouter à la même fixture référentielle.
|
> ⚠ **À venir en ERP-54** : `tva_mode` / `payment_delay` / `payment_type` / `bank` ne sont pas encore des entités mappées au M1.0 → le purger ne les touche pas, leur seed migration survit. **Dès qu'ERP-54 crée leurs entités, ils seront purgés au db-reset** → il faudra les ajouter à la même fixture référentielle.
|
||||||
> 🔗 **Coordination ERP-68** : ERP-78 (cette refonte) atterrit avant ERP-68. `CategoryFixtures` / `ClientFixtures` ont été adaptées au type unique CLIENT + codes (les tiers distributeur/courtier portent les `Category` de code DISTRIBUTEUR/COURTIER).
|
> 🔗 **Coordination ERP-68** : ERP-53 pose la fixture référentielle minimale (4 category_types). ERP-68 l'**étend** (clients de démo, ~12-15) sans la dupliquer.
|
||||||
|
|
||||||
### 3.4 Entité `Client` — squelette
|
### 3.4 Entité `Client` — squelette
|
||||||
|
|
||||||
@@ -748,7 +742,7 @@ class Client implements TimestampableInterface, BlamableInterface
|
|||||||
- **Security** : `is_granted('commercial.clients.view')`
|
- **Security** : `is_granted('commercial.clients.view')`
|
||||||
- **Query params** :
|
- **Query params** :
|
||||||
- `includeArchived=true|false` (default `false`)
|
- `includeArchived=true|false` (default `false`)
|
||||||
- `categoryCode=<code>` (filtre les clients ayant ≥ 1 `Category` de ce code stable — ERP-78 ; ex. `DISTRIBUTEUR`, `COURTIER`)
|
- `categoryType=<code>` (filtre par type de catégorie via `SearchFilter`)
|
||||||
- `search=<text>` (recherche fuzzy sur companyName + lastName + email)
|
- `search=<text>` (recherche fuzzy sur companyName + lastName + email)
|
||||||
- **Tri par défaut** : `companyName ASC`
|
- **Tri par défaut** : `companyName ASC`
|
||||||
- **Pagination** : front via `<MalioDataTable>` (volumétrie cible faible). Pas de pagination serveur au M1.
|
- **Pagination** : front via `<MalioDataTable>` (volumétrie cible faible). Pas de pagination serveur au M1.
|
||||||
@@ -887,12 +881,11 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
|
|
||||||
- **RG-1.01** : Au moins l'un des champs `firstName` (Prénom du contact principal) ou `lastName` (Nom du contact principal) doit être renseigné. Sinon → 422.
|
- **RG-1.01** : Au moins l'un des champs `firstName` (Prénom du contact principal) ou `lastName` (Nom du contact principal) doit être renseigné. Sinon → 422.
|
||||||
- **RG-1.02** : Le champ `phoneSecondary` est optionnel et apparaît au clic sur un bouton `+` côté front. Maximum 2 téléphones (primary + secondary). Comportement purement front au niveau UI ; côté serveur, les 2 colonnes existent et sont distinctes.
|
- **RG-1.02** : Le champ `phoneSecondary` est optionnel et apparaît au clic sur un bouton `+` côté front. Maximum 2 téléphones (primary + secondary). Comportement purement front au niveau UI ; côté serveur, les 2 colonnes existent et sont distinctes.
|
||||||
- **RG-1.03** : Les champs `distributor` et `broker` sont **mutuellement exclusifs** (au plus une seule des deux est renseignée). Tentative d'envoyer les deux → 422. Contrainte CHECK en base également : `NOT (distributor_id IS NOT NULL AND broker_id IS NOT NULL)`. Un `distributor` référencé doit porter une **`Category` de code `DISTRIBUTEUR`** ; un `broker` une **`Category` de code `COURTIER`** — sinon 422. _(Refonte ERP-78 : le filtrage se fait sur le `code` de la `Category`, plus sur le type — `ClientProcessor::hasCategoryCode`.)_ La liste front de `distributor` = clients ayant une catégorie de code `DISTRIBUTEUR`, via `GET /api/clients?categoryCode=DISTRIBUTEUR` ; idem `broker` avec `COURTIER`.
|
- **RG-1.03** : Les champs `distributor` et `broker` sont **mutuellement exclusifs** (au plus une seule des deux est renseignée). Tentative d'envoyer les deux → 422. Contrainte CHECK en base également : `NOT (distributor_id IS NOT NULL AND broker_id IS NOT NULL)`. La liste front de `distributor` = clients ayant au moins une catégorie de type `DISTRIBUTEUR` ; idem pour `broker` avec `COURTIER`.
|
||||||
|
|
||||||
### Onglet Information
|
### Onglet Information
|
||||||
|
|
||||||
- **RG-1.04** _(durcie — ERP-74)_ : Pour un utilisateur portant le rôle métier **Commerciale**, **tous** les champs de l'onglet Information (`description`, `competitors`, `foundedAt`, `employeesCount`, `revenueAmount`, `directorName`, `profitAmount`) sont obligatoires sur **POST et sur tout PATCH**, **indépendamment des champs réellement envoyés** (la condition d'intersection avec `client:write:information` a été retirée). Pour les autres rôles, ces champs restent optionnels. Implémenté via un validator custom `ClientInformationCompletenessValidator` invoqué systématiquement par le `ClientProcessor` quand le user porte le rôle Commerciale.
|
- **RG-1.04** : Pour un utilisateur portant le rôle métier **Commerciale**, **tous** les champs de l'onglet Information (`description`, `competitors`, `foundedAt`, `employeesCount`, `revenueAmount`, `directorName`, `profitAmount`) deviennent obligatoires lors d'un PATCH sur le groupe `client:write:information`. Pour les autres rôles, ces champs restent optionnels. Implémenté via un validator custom `ClientInformationCompletenessValidator` invoqué par le `ClientProcessor` quand le user porte le rôle Commerciale.
|
||||||
- **Conséquence** : le POST n'exposant que le groupe `client:write:main`, l'onglet Information n'y est pas renseignable → une Commerciale obtient **422** sur tout POST (cf. § 8.1). La complétude se fait donc via les PATCH `client:write:information` ultérieurs. Un Admin (non gaté) crée normalement (201).
|
|
||||||
|
|
||||||
### Onglet Contact
|
### Onglet Contact
|
||||||
|
|
||||||
@@ -952,9 +945,9 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
|
|
||||||
- **RG-1.28** : Si un PATCH contient des champs de **plusieurs groupes** de sérialisation et que l'utilisateur **n'a pas toutes les permissions** correspondantes, le `ClientProcessor` renvoie **403 Forbidden sur l'ensemble du payload** (mode strict — pas de filtrage silencieux). Le front est responsable de ne JAMAIS envoyer de champs hors-permission (les onglets masqués via `usePermissions()` ne génèrent pas de payload). Cette règle protège contre les appels API directs malveillants. Exemple : un Bureau qui envoie `{ "companyName": "...", "siren": "..." }` → 403, le message d'erreur précise « Champ `siren` requiert la permission `commercial.clients.accounting.manage` ».
|
- **RG-1.28** : Si un PATCH contient des champs de **plusieurs groupes** de sérialisation et que l'utilisateur **n'a pas toutes les permissions** correspondantes, le `ClientProcessor` renvoie **403 Forbidden sur l'ensemble du payload** (mode strict — pas de filtrage silencieux). Le front est responsable de ne JAMAIS envoyer de champs hors-permission (les onglets masqués via `usePermissions()` ne génèrent pas de payload). Cette règle protège contre les appels API directs malveillants. Exemple : un Bureau qui envoie `{ "companyName": "...", "siren": "..." }` → 403, le message d'erreur précise « Champ `siren` requiert la permission `commercial.clients.accounting.manage` ».
|
||||||
|
|
||||||
### Catégorie sur ClientAddress (filtrage par code)
|
### Catégorie sur ClientAddress (filtrage par type)
|
||||||
|
|
||||||
- **RG-1.29** _(refonte ERP-78)_ : sur une adresse, les `Category` de **code `DISTRIBUTEUR` ou `COURTIER`** sont **interdites** — elles qualifient une **relation entre clients** (cf. RG-1.03) et n'ont pas de sens sur une adresse physique. **Toute autre** catégorie (type unique CLIENT) est autorisée. Validation du POST/PATCH : poster une catégorie de code DISTRIBUTEUR/COURTIER sur une adresse → **422** avec violation `categories: "Type de catégorie non autorisé sur une adresse."` (`ClientAddress::validateCategoryCodes`). Côté front, le `<MalioSelectCheckbox>` Catégorie de l'onglet Adresse exclut les `Category` de code `DISTRIBUTEUR` / `COURTIER` (le `code` est exposé en lecture sur `/api/categories`).
|
- **RG-1.29** : Le `<MalioSelectCheckbox>` Catégorie de l'onglet Adresse n'expose **que** les `Category` dont `categoryType.code IN ('SECTEUR', 'AUTRE')`. Les types `DISTRIBUTEUR` et `COURTIER` qualifient une **relation entre clients** (cf. RG-1.03) et n'ont pas de sens sur une adresse physique. Implémentation : `ClientAddressProvider` filtre côté serveur via paramètre de requête à l'endpoint `GET /api/categories?categoryType.code[]=SECTEUR&categoryType.code[]=AUTRE` (SearchFilter API Platform). Côté validation du POST/PATCH : si l'utilisateur tente de poster une catégorie de type DISTRIBUTEUR ou COURTIER sur une adresse → **422** avec violation `categories: "Type de catégorie non autorisé sur une adresse."`.
|
||||||
|
|
||||||
## 8. Tests à automatiser
|
## 8. Tests à automatiser
|
||||||
|
|
||||||
@@ -963,7 +956,7 @@ Cf. § 2.6. Pattern Shared standard.
|
|||||||
- [ ] **RG-1.01** : POST sans firstName ni lastName → 422
|
- [ ] **RG-1.01** : POST sans firstName ni lastName → 422
|
||||||
- [ ] **RG-1.02** : POST avec phoneSecondary rempli → persistance OK ; PATCH ajoutant un 3e téléphone → côté API, 2 colonnes uniquement (test que le payload ne peut pas créer un 3e)
|
- [ ] **RG-1.02** : POST avec phoneSecondary rempli → persistance OK ; PATCH ajoutant un 3e téléphone → côté API, 2 colonnes uniquement (test que le payload ne peut pas créer un 3e)
|
||||||
- [ ] **RG-1.03** : POST avec distributor ET broker → 422 ; POST distributor seul → 201
|
- [ ] **RG-1.03** : POST avec distributor ET broker → 422 ; POST distributor seul → 201
|
||||||
- [ ] **RG-1.03** : POST distributor référençant un client SANS catégorie de code DISTRIBUTEUR → 422 (validation custom `ClientProcessor::hasCategoryCode`)
|
- [ ] **RG-1.03** : POST distributor référençant un client SANS catégorie de type DISTRIBUTEUR → 422 (validation custom)
|
||||||
- [ ] **RG-1.04** : PATCH onglet Information par un user Commerciale avec champs incomplets → 422 ; même PATCH par Admin → 200
|
- [ ] **RG-1.04** : PATCH onglet Information par un user Commerciale avec champs incomplets → 422 ; même PATCH par Admin → 200
|
||||||
- [ ] **RG-1.05** : POST contact sans firstName ni lastName → 422 (BDD CHECK lève une exception)
|
- [ ] **RG-1.05** : POST contact sans firstName ni lastName → 422 (BDD CHECK lève une exception)
|
||||||
- [ ] **RG-1.06/07/08** : POST adresse avec isProspect=true ET isDelivery=true → 422 / CHECK
|
- [ ] **RG-1.06/07/08** : POST adresse avec isProspect=true ET isDelivery=true → 422 / CHECK
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ C'est le 1er bloc à remplir. Sans validation de ce formulaire, les onglets ne s
|
|||||||
| **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. |
|
| **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) |
|
| **Email** | `<MalioInputText>` type email | Oui | RG-1.21 (lowercase) |
|
||||||
| **Distributeur / Courtier** | `<MalioSelect>` | Non | Valeurs : `Dépend du distributeur` / `Dépend du courtier` / `Aucun`. RG-1.03 conditionne les 2 champs suivants. |
|
| **Distributeur / Courtier** | `<MalioSelect>` | Non | Valeurs : `Dépend du distributeur` / `Dépend du courtier` / `Aucun`. RG-1.03 conditionne les 2 champs suivants. |
|
||||||
| **Nom du distributeur** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du distributeur ». Liste = clients ayant ≥ 1 catégorie de **code** `DISTRIBUTEUR` (ERP-78), via `GET /api/clients?categoryCode=DISTRIBUTEUR`. RG-1.03. |
|
| **Nom du distributeur** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du distributeur ». Liste = clients ayant ≥ 1 catégorie de type `DISTRIBUTEUR`. RG-1.03. |
|
||||||
| **Nom du courtier** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du courtier ». Liste = clients ayant ≥ 1 catégorie de **code** `COURTIER` (ERP-78), via `GET /api/clients?categoryCode=COURTIER`. RG-1.03. |
|
| **Nom du courtier** | `<MalioSelect>` | Conditionnel | Visible si « Dépend du courtier ». Liste = clients ayant ≥ 1 catégorie de type `COURTIER`. RG-1.03. |
|
||||||
| **Prestation de triage** | `<MalioCheckbox>` | Non | — |
|
| **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 ».
|
**Action** : « Valider » (`<MalioButton>`) → POST `/api/clients` ([`spec-back.md` § 4.3](./spec-back.md)). Si succès, on passe automatiquement à l'onglet « Information ».
|
||||||
@@ -150,7 +150,7 @@ Saisir une ou plusieurs adresses du client, rattachées à un ou plusieurs sites
|
|||||||
| **Prospect** | `<MalioCheckbox>` | Non | RG-1.06 — masque Adresse de livraison + Facturation si coché |
|
| **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é |
|
| **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) |
|
| **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` **hors codes `DISTRIBUTEUR` / `COURTIER`** (ERP-78 — ces codes qualifient une relation entre clients, pas un lieu). Le front exclut ces 2 codes du select (le `code` est exposé en lecture sur `/api/categories`). |
|
| **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 » |
|
| **Pays** | `<MalioSelect>` | Oui | Préremplie « France » |
|
||||||
| **Code postal** | `<MalioInputText>` (masque numérique) | Oui | RG-1.09 — déclenche autocomplete ville via BAN |
|
| **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 |
|
| **Ville** | `<MalioSelect>` | Oui | RG-1.09 — alimentée par api-adresse.data.gouv.fr suivant le CP |
|
||||||
@@ -268,7 +268,7 @@ Le composant `Code postal` + `Ville` + `Adresse` est branché sur **api-adresse.
|
|||||||
|
|
||||||
| # | Zone d'ombre V0 | Résolution (cf. `spec-back.md`) |
|
| # | 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. Refonte ERP-78 : type unique `CLIENT` ; `Distributeur`/`Courtier`/`Secteur`/`Autre` (+ catégories métier) sont des `Category` portant un `code` stable (HP-3 du M0 levé). |
|
| 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. |
|
| 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. |
|
| 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 ». |
|
| 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 ». |
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
},
|
},
|
||||||
"commercial": {
|
"commercial": {
|
||||||
"section": "Commercial",
|
"section": "Commercial",
|
||||||
"clients": "Répertoire clients",
|
|
||||||
"suppliers": "Répertoire fournisseurs"
|
"suppliers": "Répertoire fournisseurs"
|
||||||
},
|
},
|
||||||
"core": {
|
"core": {
|
||||||
@@ -44,63 +43,7 @@
|
|||||||
},
|
},
|
||||||
"commercial": {
|
"commercial": {
|
||||||
"title": "Commercial",
|
"title": "Commercial",
|
||||||
"welcome": "Module Commercial",
|
"welcome": "Module Commercial"
|
||||||
"clients": {
|
|
||||||
"title": "Répertoire clients",
|
|
||||||
"add": "Ajouter",
|
|
||||||
"export": "Exporter",
|
|
||||||
"empty": "Aucun client pour l'instant.",
|
|
||||||
"column": {
|
|
||||||
"companyName": "Nom",
|
|
||||||
"categories": "Catégories",
|
|
||||||
"sites": "Site",
|
|
||||||
"lastActivity": "Dernière activité"
|
|
||||||
},
|
|
||||||
"filters": {
|
|
||||||
"title": "Filtres",
|
|
||||||
"search": "Recherche",
|
|
||||||
"categories": "Catégories",
|
|
||||||
"sites": "Sites",
|
|
||||||
"status": "Statut",
|
|
||||||
"archivedOnly": "Voir les archivés",
|
|
||||||
"apply": "Voir les résultats",
|
|
||||||
"reset": "Réinitialiser"
|
|
||||||
},
|
|
||||||
"tab": {
|
|
||||||
"information": "Information",
|
|
||||||
"contact": "Contact",
|
|
||||||
"address": "Adresse",
|
|
||||||
"transport": "Transport",
|
|
||||||
"accounting": "Comptabilité",
|
|
||||||
"statistics": "Statistiques",
|
|
||||||
"reports": "Rapports",
|
|
||||||
"exchanges": "Échanges"
|
|
||||||
},
|
|
||||||
"action": {
|
|
||||||
"edit": "Modifier",
|
|
||||||
"archive": "Archiver",
|
|
||||||
"restore": "Restaurer"
|
|
||||||
},
|
|
||||||
"toast": {
|
|
||||||
"createSuccess": "Client créé avec succès",
|
|
||||||
"updateSuccess": "Client mis à jour avec succès",
|
|
||||||
"archiveSuccess": "Client archivé avec succès",
|
|
||||||
"restoreSuccess": "Client restauré avec succès",
|
|
||||||
"error": "Une erreur est survenue. Réessayez.",
|
|
||||||
"exportError": "L'export du répertoire clients a échoué. Réessayez."
|
|
||||||
},
|
|
||||||
"validation": {
|
|
||||||
"informationRequiredForCommercial": "Les informations de l'entreprise sont obligatoires pour le rôle Commerciale.",
|
|
||||||
"contactRequired": "Au moins un contact (nom ou prénom) est obligatoire.",
|
|
||||||
"siteRequired": "Au moins un site Starseed doit être rattaché à l'adresse.",
|
|
||||||
"billingEmailRequired": "L'email de facturation est obligatoire pour une adresse de facturation.",
|
|
||||||
"bankRequiredForTransfer": "La banque est obligatoire pour un règlement par virement.",
|
|
||||||
"ribRequiredForLcr": "Au moins un RIB complet est obligatoire pour un règlement par LCR.",
|
|
||||||
"phoneFormat": "Format de téléphone invalide (attendu : XX XX XX XX XX).",
|
|
||||||
"emailFormat": "Format d'email invalide.",
|
|
||||||
"addressCategoryForbidden": "Une catégorie « Distributeur » ou « Courtier » ne peut pas qualifier une adresse."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"login": "Connexion",
|
"login": "Connexion",
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
||||||
import type { HydraCollection } from '~/shared/utils/api'
|
|
||||||
import type { Client } from '../useClientsRepository'
|
|
||||||
|
|
||||||
// `useApi` est un auto-import Nuxt : on le stubbe globalement pour intercepter
|
|
||||||
// les appels declenches par usePaginatedList (que useClientsRepository enveloppe)
|
|
||||||
// et controler les reponses. Meme pattern que useCategoriesAdmin.spec.ts.
|
|
||||||
const mockGet = vi.hoisted(() => vi.fn())
|
|
||||||
vi.stubGlobal('useApi', () => ({
|
|
||||||
get: mockGet,
|
|
||||||
post: vi.fn(),
|
|
||||||
put: vi.fn(),
|
|
||||||
patch: vi.fn(),
|
|
||||||
delete: vi.fn(),
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Import APRES le stub pour que useApi soit bien resolu au top-level du module.
|
|
||||||
const { useClientsRepository } = await import('../useClientsRepository')
|
|
||||||
|
|
||||||
/** Envelope Hydra minimale (la liste reelle des membres importe peu ici). */
|
|
||||||
function makeHydra(total: number): HydraCollection<Client> {
|
|
||||||
return { totalItems: total, member: [] }
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('useClientsRepository', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
mockGet.mockReset()
|
|
||||||
// 25 items → 3 pages a 10/page : permet de tester la navigation page 2.
|
|
||||||
mockGet.mockResolvedValue(makeHydra(25))
|
|
||||||
})
|
|
||||||
|
|
||||||
it('cible la ressource /clients en page 1 par defaut', async () => {
|
|
||||||
const repo = useClientsRepository()
|
|
||||||
await repo.fetch()
|
|
||||||
|
|
||||||
expect(mockGet).toHaveBeenLastCalledWith(
|
|
||||||
'/clients',
|
|
||||||
{ page: 1, itemsPerPage: 10 },
|
|
||||||
expect.objectContaining({ toast: false }),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('pousse les filtres du drawer (categories multi, sites, archives) et retombe en page 1', async () => {
|
|
||||||
const repo = useClientsRepository()
|
|
||||||
await repo.fetch()
|
|
||||||
await repo.goToPage(2)
|
|
||||||
expect(repo.currentPage.value).toBe(2)
|
|
||||||
|
|
||||||
await repo.setFilters(
|
|
||||||
{
|
|
||||||
search: 'acme',
|
|
||||||
'categoryCode[]': ['DISTRIBUTEUR', 'COURTIER'],
|
|
||||||
'siteId[]': ['1', '2'],
|
|
||||||
archivedOnly: true,
|
|
||||||
},
|
|
||||||
{ replace: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(repo.currentPage.value).toBe(1)
|
|
||||||
expect(mockGet).toHaveBeenLastCalledWith(
|
|
||||||
'/clients',
|
|
||||||
{
|
|
||||||
search: 'acme',
|
|
||||||
'categoryCode[]': ['DISTRIBUTEUR', 'COURTIER'],
|
|
||||||
'siteId[]': ['1', '2'],
|
|
||||||
archivedOnly: true,
|
|
||||||
page: 1,
|
|
||||||
itemsPerPage: 10,
|
|
||||||
},
|
|
||||||
expect.objectContaining({ toast: false }),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('repasse a une query propre apres reinitialisation des filtres', async () => {
|
|
||||||
const repo = useClientsRepository()
|
|
||||||
await repo.setFilters({ search: 'acme', archivedOnly: true }, { replace: true })
|
|
||||||
await repo.setFilters({}, { replace: true })
|
|
||||||
|
|
||||||
expect(mockGet).toHaveBeenLastCalledWith(
|
|
||||||
'/clients',
|
|
||||||
{ page: 1, itemsPerPage: 10 },
|
|
||||||
expect.objectContaining({ toast: false }),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
import { usePaginatedList } from '~/shared/composables/usePaginatedList'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Site Starseed rattache a une adresse du client, tel qu'embarque en LISTE
|
|
||||||
* (groupe site:read) pour la colonne « Site(s) » du Repertoire (badges colores).
|
|
||||||
*/
|
|
||||||
export interface ClientSite {
|
|
||||||
id: number
|
|
||||||
name: string
|
|
||||||
color: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Categorie rattachee au client, embarquee en LISTE (groupe category:read).
|
|
||||||
* Seul le `code` (stable, MAJUSCULE — ERP-78) est affiche dans la colonne
|
|
||||||
* « Catégories ». Les autres champs sont presents mais non utilises ici.
|
|
||||||
*/
|
|
||||||
export interface ClientCategory {
|
|
||||||
code: string
|
|
||||||
name?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vue MINIMALE d'un client pour le Repertoire (datatable). Volontairement
|
|
||||||
* partielle : seuls les champs des colonnes + l'id (navigation) sont types ici.
|
|
||||||
* Le detail complet (onglets) est hors perimetre de cet ecran (ERP-62).
|
|
||||||
*/
|
|
||||||
export interface Client {
|
|
||||||
id: number
|
|
||||||
companyName: string
|
|
||||||
categories: ClientCategory[]
|
|
||||||
sites: ClientSite[]
|
|
||||||
/** Date ISO de derniere modification (default:read) — colonne « Dernière activité ». */
|
|
||||||
updatedAt: string | null
|
|
||||||
isArchived: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Repertoire clients (ERP-62) — simple enveloppe de `usePaginatedList<Client>`
|
|
||||||
* sur la ressource `/clients` (RG-13 : pagination serveur obligatoire ; jamais
|
|
||||||
* de chargement integral en memoire).
|
|
||||||
*
|
|
||||||
* Les filtres (recherche, categories, sites, archives) sont pilotes par la page
|
|
||||||
* via `setFilters` du composable partage — la remise en page 1 est garantie.
|
|
||||||
*
|
|
||||||
* Volontairement PAR INSTANCE (pas de singleton module-level) : l'etat tableau
|
|
||||||
* est propre a l'ecran Repertoire et meurt avec lui, comme tout consommateur de
|
|
||||||
* `usePaginatedList` (cf. sites.vue / categories.vue). Aucun reset au logout a
|
|
||||||
* gerer.
|
|
||||||
*/
|
|
||||||
export function useClientsRepository() {
|
|
||||||
return usePaginatedList<Client>({ url: '/clients' })
|
|
||||||
}
|
|
||||||
@@ -1,421 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div>
|
|
||||||
<PageHeader>
|
|
||||||
{{ t('commercial.clients.title') }}
|
|
||||||
<template #actions>
|
|
||||||
<!-- gap-12 = 48px d'espacement entre Ajouter et Filtres. -->
|
|
||||||
<div class="flex items-center gap-12">
|
|
||||||
<MalioButton
|
|
||||||
v-if="canManage"
|
|
||||||
variant="secondary"
|
|
||||||
:label="t('commercial.clients.add')"
|
|
||||||
icon-name="mdi:add-bold"
|
|
||||||
icon-position="left"
|
|
||||||
@click="goToCreate"
|
|
||||||
/>
|
|
||||||
<!-- Bouton Filtres a DROITE d'Ajouter : meme design que
|
|
||||||
l'audit-log. Le compteur reflete les filtres actifs. -->
|
|
||||||
<MalioButton
|
|
||||||
v-if="canView"
|
|
||||||
variant="tertiary"
|
|
||||||
:label="filterButtonLabel"
|
|
||||||
icon-name="mdi:tune"
|
|
||||||
icon-position="left"
|
|
||||||
icon-size="24"
|
|
||||||
button-class="w-[184px] justify-start gap-4 text-black"
|
|
||||||
@click="openFilters"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</PageHeader>
|
|
||||||
|
|
||||||
<!-- Datatable branchee sur usePaginatedList via useClientsRepository :
|
|
||||||
pagination serveur, tri companyName ASC par defaut (cote back). -->
|
|
||||||
<MalioDataTable
|
|
||||||
:columns="columns"
|
|
||||||
:items="rows"
|
|
||||||
:total-items="totalItems"
|
|
||||||
:page="currentPage"
|
|
||||||
:per-page="itemsPerPage"
|
|
||||||
:per-page-options="itemsPerPageOptions"
|
|
||||||
row-clickable
|
|
||||||
table-class="table-fixed"
|
|
||||||
:empty-message="t('commercial.clients.empty')"
|
|
||||||
@row-click="onRowClick"
|
|
||||||
@update:page="goToPage"
|
|
||||||
@update:per-page="setItemsPerPage"
|
|
||||||
>
|
|
||||||
<!-- Categories : codes stables separes par une virgule (ERP-78). -->
|
|
||||||
<template #cell-categories="{ item }">
|
|
||||||
{{ formatCategories(item) }}
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Sites : badges colores (name + color), agreges des adresses. -->
|
|
||||||
<template #cell-sites="{ item }">
|
|
||||||
<span class="flex flex-wrap gap-1">
|
|
||||||
<span
|
|
||||||
v-for="site in (item.sites as ClientSite[])"
|
|
||||||
:key="site.id"
|
|
||||||
class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium text-white"
|
|
||||||
:style="{ backgroundColor: site.color }"
|
|
||||||
>
|
|
||||||
{{ site.name }}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Derniere activite : date de derniere modification (updatedAt). -->
|
|
||||||
<template #cell-lastActivity="{ item }">
|
|
||||||
{{ formatLastActivity(item) }}
|
|
||||||
</template>
|
|
||||||
</MalioDataTable>
|
|
||||||
|
|
||||||
<div class="flex justify-center mt-6">
|
|
||||||
<MalioButton
|
|
||||||
v-if="canView"
|
|
||||||
variant="primary"
|
|
||||||
:label="t('commercial.clients.export')"
|
|
||||||
:disabled="exporting"
|
|
||||||
@click="exportXlsx"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Drawer de filtres : etat BROUILLON, applique uniquement au clic sur
|
|
||||||
« Appliquer ». Meme pattern que l'audit-log. Etat 100 % local, jamais
|
|
||||||
dans l'URL (regle ABSOLUE n°6). -->
|
|
||||||
<MalioDrawer
|
|
||||||
v-model="filterDrawerOpen"
|
|
||||||
drawer-class="max-w-[450px]"
|
|
||||||
body-class="p-0"
|
|
||||||
footer-class="justify-between border-t border-black p-6"
|
|
||||||
>
|
|
||||||
<template #header>
|
|
||||||
<h2 class="text-[24px] font-bold uppercase">{{ t('commercial.clients.filters.title') }}</h2>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<MalioAccordion>
|
|
||||||
<!-- Recherche : nom societe + contact + email (param `search`). -->
|
|
||||||
<MalioAccordionItem :title="t('commercial.clients.filters.search')" value="search">
|
|
||||||
<MalioInputText
|
|
||||||
v-model="draftSearch"
|
|
||||||
icon-name="mdi:magnify"
|
|
||||||
/>
|
|
||||||
</MalioAccordionItem>
|
|
||||||
|
|
||||||
<!-- Categories : cases a cocher (multi). Valeur = code stable. -->
|
|
||||||
<MalioAccordionItem :title="t('commercial.clients.filters.categories')" value="categories">
|
|
||||||
<div class="flex flex-col">
|
|
||||||
<MalioCheckbox
|
|
||||||
v-for="opt in categoryOptions"
|
|
||||||
:id="`filter-category-${opt.value}`"
|
|
||||||
:key="opt.value"
|
|
||||||
:label="opt.label"
|
|
||||||
:model-value="draftCategoryCodes.includes(opt.value)"
|
|
||||||
@update:model-value="(val: boolean) => toggleCategory(opt.value, val)"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</MalioAccordionItem>
|
|
||||||
|
|
||||||
<!-- Sites : cases a cocher (multi). Valeur = id du site. -->
|
|
||||||
<MalioAccordionItem :title="t('commercial.clients.filters.sites')" value="sites">
|
|
||||||
<div class="flex flex-col">
|
|
||||||
<MalioCheckbox
|
|
||||||
v-for="opt in siteOptions"
|
|
||||||
:id="`filter-site-${opt.value}`"
|
|
||||||
:key="opt.value"
|
|
||||||
:label="opt.label"
|
|
||||||
:model-value="draftSiteIds.includes(opt.value)"
|
|
||||||
@update:model-value="(val: boolean) => toggleSite(opt.value, val)"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</MalioAccordionItem>
|
|
||||||
|
|
||||||
<!-- Statut : bool unique. Coche = archives uniquement, sinon actifs. -->
|
|
||||||
<MalioAccordionItem :title="t('commercial.clients.filters.status')" value="status">
|
|
||||||
<MalioCheckbox
|
|
||||||
id="filter-archived-only"
|
|
||||||
:label="t('commercial.clients.filters.archivedOnly')"
|
|
||||||
:model-value="draftArchivedOnly"
|
|
||||||
@update:model-value="(val: boolean) => draftArchivedOnly = val"
|
|
||||||
/>
|
|
||||||
</MalioAccordionItem>
|
|
||||||
</MalioAccordion>
|
|
||||||
|
|
||||||
<template #footer>
|
|
||||||
<MalioButton
|
|
||||||
variant="tertiary"
|
|
||||||
:label="t('commercial.clients.filters.reset')"
|
|
||||||
button-class="w-m-btn-action"
|
|
||||||
@click="resetFilters"
|
|
||||||
/>
|
|
||||||
<MalioButton
|
|
||||||
variant="primary"
|
|
||||||
:label="t('commercial.clients.filters.apply')"
|
|
||||||
button-class="w-[170px]"
|
|
||||||
@click="applyFilters"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</MalioDrawer>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { computed, onMounted, ref } from 'vue'
|
|
||||||
import type { Client, ClientSite } from '~/modules/commercial/composables/useClientsRepository'
|
|
||||||
|
|
||||||
interface FilterOption {
|
|
||||||
value: string
|
|
||||||
label: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
|
||||||
const api = useApi()
|
|
||||||
const router = useRouter()
|
|
||||||
const toast = useToast()
|
|
||||||
const { can } = usePermissions()
|
|
||||||
|
|
||||||
useHead({ title: t('commercial.clients.title') })
|
|
||||||
|
|
||||||
// Bouton « Ajouter » reserve a `manage` (POST /clients garde manage seul →
|
|
||||||
// Compta / Usine ne creent pas). « Exporter » et « Filtres » suivent `view`.
|
|
||||||
const canManage = computed(() => can('commercial.clients.manage'))
|
|
||||||
const canView = computed(() => can('commercial.clients.view'))
|
|
||||||
|
|
||||||
const {
|
|
||||||
items: clients,
|
|
||||||
totalItems,
|
|
||||||
currentPage,
|
|
||||||
itemsPerPage,
|
|
||||||
itemsPerPageOptions,
|
|
||||||
fetch: loadClients,
|
|
||||||
goToPage,
|
|
||||||
setItemsPerPage,
|
|
||||||
setFilters,
|
|
||||||
} = useClientsRepository()
|
|
||||||
|
|
||||||
// Mappe les clients en objets « plats » pour MalioDataTable (items typees
|
|
||||||
// Record<string, unknown>[]) : un objet litteral porte une signature d'index
|
|
||||||
// implicite, contrairement a l'interface Client. Meme pattern que sites.vue.
|
|
||||||
const rows = computed(() => clients.value.map(client => ({
|
|
||||||
id: client.id,
|
|
||||||
companyName: client.companyName,
|
|
||||||
categories: client.categories,
|
|
||||||
sites: client.sites,
|
|
||||||
updatedAt: client.updatedAt,
|
|
||||||
})))
|
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{ key: 'companyName', label: t('commercial.clients.column.companyName') },
|
|
||||||
{ key: 'categories', label: t('commercial.clients.column.categories') },
|
|
||||||
{ key: 'sites', label: t('commercial.clients.column.sites') },
|
|
||||||
{ key: 'lastActivity', label: t('commercial.clients.column.lastActivity') },
|
|
||||||
]
|
|
||||||
|
|
||||||
/** Codes des categories du client, separes par une virgule (ERP-78). */
|
|
||||||
function formatCategories(item: Record<string, unknown>): string {
|
|
||||||
const categories = (item.categories as Client['categories']) ?? []
|
|
||||||
return categories.map(c => c.code).join(', ')
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Derniere activite : faute de suivi d'activite metier au M1, on affiche la
|
|
||||||
* date de derniere modification de la fiche (updatedAt, expose en liste via
|
|
||||||
* default:read). Format court francais jj/mm/aaaa.
|
|
||||||
*/
|
|
||||||
function formatLastActivity(item: Record<string, unknown>): string {
|
|
||||||
const value = item.updatedAt as string | null | undefined
|
|
||||||
if (!value) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// Garde-fou date invalide : un updatedAt mal forme donnerait « Invalid Date ».
|
|
||||||
const date = new Date(value)
|
|
||||||
if (Number.isNaN(date.getTime())) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
return date.toLocaleDateString('fr-FR')
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Clic sur une ligne → ecran Consultation (route a plat /clients/{id}). */
|
|
||||||
function onRowClick(item: Record<string, unknown>): void {
|
|
||||||
router.push(`/clients/${item.id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function goToCreate(): void {
|
|
||||||
router.push('/clients/new')
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Filtres (drawer) ────────────────────────────────────────────────────────
|
|
||||||
// Deux niveaux d'etat (pattern audit-log) :
|
|
||||||
// - APPLIED : pilote la liste/l'export + le compteur du bouton. Modifie
|
|
||||||
// uniquement au clic « Appliquer » / « Réinitialiser ».
|
|
||||||
// - DRAFT : edite librement dans le drawer ; recopie vers applied a la validation.
|
|
||||||
const filterDrawerOpen = ref(false)
|
|
||||||
|
|
||||||
const draftSearch = ref('')
|
|
||||||
const draftCategoryCodes = ref<string[]>([])
|
|
||||||
const draftSiteIds = ref<string[]>([])
|
|
||||||
const draftArchivedOnly = ref(false)
|
|
||||||
|
|
||||||
const appliedSearch = ref('')
|
|
||||||
const appliedCategoryCodes = ref<string[]>([])
|
|
||||||
const appliedSiteIds = ref<string[]>([])
|
|
||||||
const appliedArchivedOnly = ref(false)
|
|
||||||
|
|
||||||
// Options des selects multi, chargees une fois (referentiels courts).
|
|
||||||
const categoryOptions = ref<FilterOption[]>([])
|
|
||||||
const siteOptions = ref<FilterOption[]>([])
|
|
||||||
|
|
||||||
const activeFilterCount = computed(() => {
|
|
||||||
let count = 0
|
|
||||||
if (appliedSearch.value.trim() !== '') count++
|
|
||||||
if (appliedCategoryCodes.value.length > 0) count++
|
|
||||||
if (appliedSiteIds.value.length > 0) count++
|
|
||||||
if (appliedArchivedOnly.value) count++
|
|
||||||
return count
|
|
||||||
})
|
|
||||||
|
|
||||||
const filterButtonLabel = computed(() => {
|
|
||||||
const base = t('commercial.clients.filters.title')
|
|
||||||
return activeFilterCount.value > 0 ? `${base} (${activeFilterCount.value})` : base
|
|
||||||
})
|
|
||||||
|
|
||||||
// Recopie l'etat applique vers le brouillon puis ouvre le drawer : la
|
|
||||||
// reouverture reflete les filtres actifs.
|
|
||||||
function openFilters(): void {
|
|
||||||
draftSearch.value = appliedSearch.value
|
|
||||||
draftCategoryCodes.value = [...appliedCategoryCodes.value]
|
|
||||||
draftSiteIds.value = [...appliedSiteIds.value]
|
|
||||||
draftArchivedOnly.value = appliedArchivedOnly.value
|
|
||||||
filterDrawerOpen.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleCategory(code: string, selected: boolean): void {
|
|
||||||
draftCategoryCodes.value = selected
|
|
||||||
? [...draftCategoryCodes.value, code]
|
|
||||||
: draftCategoryCodes.value.filter(c => c !== code)
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleSite(id: string, selected: boolean): void {
|
|
||||||
draftSiteIds.value = selected
|
|
||||||
? [...draftSiteIds.value, id]
|
|
||||||
: draftSiteIds.value.filter(s => s !== id)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construit le payload de filtres serveur a partir de l'etat applique. Cles
|
|
||||||
* `categoryCode[]` / `siteId[]` pour que PHP les parse en tableaux (OR cote back).
|
|
||||||
* Les filtres vides sont omis pour une query propre.
|
|
||||||
*/
|
|
||||||
function buildFilterPayload(): Record<string, string | string[] | boolean> {
|
|
||||||
const payload: Record<string, string | string[] | boolean> = {}
|
|
||||||
if (appliedSearch.value.trim() !== '') payload.search = appliedSearch.value.trim()
|
|
||||||
if (appliedCategoryCodes.value.length > 0) payload['categoryCode[]'] = [...appliedCategoryCodes.value]
|
|
||||||
if (appliedSiteIds.value.length > 0) payload['siteId[]'] = [...appliedSiteIds.value]
|
|
||||||
if (appliedArchivedOnly.value) payload.archivedOnly = true
|
|
||||||
return payload
|
|
||||||
}
|
|
||||||
|
|
||||||
// « Appliquer » : recopie brouillon → applied, pousse les filtres (retombe en
|
|
||||||
// page 1 via usePaginatedList) et ferme le drawer.
|
|
||||||
function applyFilters(): void {
|
|
||||||
appliedSearch.value = draftSearch.value.trim()
|
|
||||||
appliedCategoryCodes.value = [...draftCategoryCodes.value]
|
|
||||||
appliedSiteIds.value = [...draftSiteIds.value]
|
|
||||||
appliedArchivedOnly.value = draftArchivedOnly.value
|
|
||||||
|
|
||||||
setFilters(buildFilterPayload(), { replace: true })
|
|
||||||
filterDrawerOpen.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// « Réinitialiser » : vide brouillon ET applied, recharge la liste complete.
|
|
||||||
// Le drawer reste ouvert pour montrer le formulaire vide.
|
|
||||||
function resetFilters(): void {
|
|
||||||
draftSearch.value = ''
|
|
||||||
draftCategoryCodes.value = []
|
|
||||||
draftSiteIds.value = []
|
|
||||||
draftArchivedOnly.value = false
|
|
||||||
|
|
||||||
appliedSearch.value = ''
|
|
||||||
appliedCategoryCodes.value = []
|
|
||||||
appliedSiteIds.value = []
|
|
||||||
appliedArchivedOnly.value = false
|
|
||||||
|
|
||||||
setFilters({}, { replace: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Charge les referentiels du drawer (categories + sites) via ?pagination=false. */
|
|
||||||
async function loadFilterOptions(): Promise<void> {
|
|
||||||
const [cats, sites] = await Promise.all([
|
|
||||||
api.get<{ member?: Array<{ code: string, name: string }> }>(
|
|
||||||
'/categories',
|
|
||||||
{ pagination: 'false' },
|
|
||||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
|
||||||
),
|
|
||||||
api.get<{ member?: Array<{ id: number, name: string }> }>(
|
|
||||||
'/sites',
|
|
||||||
{ pagination: 'false' },
|
|
||||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
|
||||||
),
|
|
||||||
])
|
|
||||||
|
|
||||||
categoryOptions.value = (cats.member ?? []).map(c => ({ value: c.code, label: c.name }))
|
|
||||||
siteOptions.value = (sites.member ?? []).map(s => ({ value: String(s.id), label: s.name }))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Export XLSX ─────────────────────────────────────────────────────────────
|
|
||||||
// Memes filtres que la vue. La colonne SIREN n'est dans le fichier que si
|
|
||||||
// l'utilisateur a accounting.view (gere cote back).
|
|
||||||
const exporting = ref(false)
|
|
||||||
|
|
||||||
async function exportXlsx(): Promise<void> {
|
|
||||||
if (exporting.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
exporting.value = true
|
|
||||||
try {
|
|
||||||
// useApi type ses options en JSON ; l'export renvoie un binaire, donc on
|
|
||||||
// force responseType:'blob' (transmis tel quel a ofetch au runtime). Cast
|
|
||||||
// contenu faute d'overload blob sur le client partage — a generaliser via
|
|
||||||
// un ticket dedie si d'autres exports binaires arrivent.
|
|
||||||
const blob = await api.get<Blob>('/clients/export.xlsx', buildFilterPayload(), {
|
|
||||||
responseType: 'blob',
|
|
||||||
toast: false,
|
|
||||||
} as unknown as Parameters<typeof api.get>[2])
|
|
||||||
|
|
||||||
triggerDownload(blob, 'repertoire-clients.xlsx')
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
toast.error({
|
|
||||||
title: t('commercial.clients.toast.error'),
|
|
||||||
message: t('commercial.clients.toast.exportError'),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
exporting.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Declenche le telechargement d'un blob via un lien temporaire. */
|
|
||||||
function triggerDownload(blob: Blob, filename: string): void {
|
|
||||||
const url = URL.createObjectURL(blob)
|
|
||||||
const link = document.createElement('a')
|
|
||||||
link.href = url
|
|
||||||
link.download = filename
|
|
||||||
document.body.appendChild(link)
|
|
||||||
link.click()
|
|
||||||
link.remove()
|
|
||||||
URL.revokeObjectURL(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadClients()
|
|
||||||
// Echec du chargement des referentiels non bloquant : la liste s'affiche,
|
|
||||||
// l'utilisateur perd juste les options de filtre.
|
|
||||||
loadFilterOptions().catch(() => {
|
|
||||||
categoryOptions.value = []
|
|
||||||
siteOptions.value = []
|
|
||||||
})
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { describe, it, expect } from 'vitest'
|
|
||||||
import { formatPhoneFR } from '../phone'
|
|
||||||
|
|
||||||
describe('formatPhoneFR', () => {
|
|
||||||
it('formate un numero 10 chiffres en XX XX XX XX XX', () => {
|
|
||||||
expect(formatPhoneFR('0612345678')).toBe('06 12 34 56 78')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('tolere une saisie deja pointee ou espacee', () => {
|
|
||||||
expect(formatPhoneFR('06.12.34.56.78')).toBe('06 12 34 56 78')
|
|
||||||
expect(formatPhoneFR('06 12 34 56 78')).toBe('06 12 34 56 78')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('retourne une chaine vide pour une valeur vide ou nulle', () => {
|
|
||||||
expect(formatPhoneFR('')).toBe('')
|
|
||||||
expect(formatPhoneFR(null)).toBe('')
|
|
||||||
expect(formatPhoneFR(undefined)).toBe('')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('groupe par 2 meme un nombre impair de chiffres (dernier groupe seul)', () => {
|
|
||||||
expect(formatPhoneFR('123')).toBe('12 3')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/**
|
|
||||||
* Formatage d'un numero de telephone francais en groupes de 2 chiffres
|
|
||||||
* (`XX XX XX XX XX`).
|
|
||||||
*
|
|
||||||
* Helper PARTAGE volontaire : les telephones sont presents un peu partout dans
|
|
||||||
* l'app (fiches clients, contacts, fournisseurs, prestataires...). Introduit ici
|
|
||||||
* comme util transverse stable plutot que duplique a chaque ecran. La signature
|
|
||||||
* `formatPhoneFR(value): string` est coordonnee avec ERP-66, qui pourra enrichir
|
|
||||||
* l'implementation (validation, indicatif international) sans casser les appelants.
|
|
||||||
*
|
|
||||||
* - Ne garde que les chiffres puis groupe par 2 (tolere une saisie deja espacee
|
|
||||||
* ou pointee, ex: `06.12.34.56.78` ou `0612345678`).
|
|
||||||
* - Retourne une chaine vide si la valeur est vide/nulle (cellule vide propre).
|
|
||||||
*/
|
|
||||||
export function formatPhoneFR(value: string | null | undefined): string {
|
|
||||||
const digits = (value ?? '').replace(/\D/g, '')
|
|
||||||
if (digits.length === 0) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// Groupe par paquets de 2 ; un dernier groupe impair reste tel quel.
|
|
||||||
return digits.match(/.{1,2}/g)?.join(' ') ?? digits
|
|
||||||
}
|
|
||||||
@@ -65,16 +65,6 @@ 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,21 +198,15 @@ 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 -> seed-rbac : fixtures:load purge la table
|
# 3. fixtures -> sync-permissions : fixtures:load purge la table permission,
|
||||||
# permission, donc sync doit passer apres. seed-rbac (matrice RBAC § 2.7)
|
# donc sync doit passer apres.
|
||||||
# passe ensuite, car attachMatrix() exige les permissions en base. Les
|
# 4. recreation index `uq_category_name_type_active` : schema:update drop
|
||||||
# comptes demo sont crees par RbacDemoFixtures au load (sans la matrice,
|
# les index orphelins du mapping ORM. L'index partiel (LOWER + WHERE) du
|
||||||
# attachee ici). Cf. ERP-74.
|
# M0 Catalog n'est pas exprimable via les attributs Doctrine ORM 3
|
||||||
# 4. recreation des index partiels uniques : schema:update drop les index
|
# (fonctionnel + partiel), donc il disparait apres schema:update. On le
|
||||||
# orphelins du mapping ORM. Les index partiels (LOWER + WHERE) ne sont pas
|
# recree par dbal:run-sql pour que les tests RG-1.07 (unicite
|
||||||
# exprimables via les attributs Doctrine ORM (fonctionnel + partiel), donc
|
# case-insensitive) voient bien la contrainte SQL. Sans ce restore, les
|
||||||
# ils disparaissent apres schema:update. On les recree par dbal:run-sql :
|
# POST doublons remontent 201 au lieu de 409.
|
||||||
# - `uq_category_name_type_active` (M0 Catalog) : tests RG-1.07.
|
|
||||||
# - `uq_category_code` (Catalog ERP-78) : unicite du code categorie parmi
|
|
||||||
# les actifs (slug du nom), pilote RG-1.03/1.29.
|
|
||||||
# - `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
|
||||||
@@ -225,10 +219,7 @@ 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_category_code ON category (code) WHERE deleted_at IS NULL"
|
|
||||||
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_client_company_name_active ON client (LOWER(company_name)) WHERE is_archived = FALSE AND deleted_at IS NULL"
|
|
||||||
|
|
||||||
fixtures:
|
fixtures:
|
||||||
$(SYMFONY_CONSOLE) --no-interaction doctrine:fixtures:load
|
$(SYMFONY_CONSOLE) --no-interaction doctrine:fixtures:load
|
||||||
@@ -238,15 +229,6 @@ 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
|
||||||
@@ -256,7 +238,6 @@ 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,53 +39,14 @@ final class Version20260528120000 extends AbstractMigration
|
|||||||
|
|
||||||
public function up(Schema $schema): void
|
public function up(Schema $schema): void
|
||||||
{
|
{
|
||||||
// Ne commente que les tables ET colonnes deja presentes a ce stade de la
|
foreach (ColumnCommentsCatalog::toSqlStatements() as $sql) {
|
||||||
// chaine de migrations. Les tables des modules crees plus tard (M1
|
$this->addSql($sql);
|
||||||
// Commercial, 06-01) ET les colonnes ajoutees ensuite sur une table
|
|
||||||
// existante (ex: category.code, ERP-78 06-02) figurent desormais dans le
|
|
||||||
// catalogue partage mais n'existent pas encore ici : elles posent leur
|
|
||||||
// propre COMMENT dans leur migration dediee (regle ABSOLUE n°12). Garde-fou
|
|
||||||
// indispensable (table + colonne), sinon enrichir le catalogue casse ce
|
|
||||||
// retrofit avec un "relation/column X does not exist".
|
|
||||||
foreach (ColumnCommentsCatalog::comments() as $table => $entries) {
|
|
||||||
if (!$schema->hasTable($table)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dbTable = $schema->getTable($table);
|
|
||||||
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
|
||||||
|
|
||||||
foreach ($entries as $column => $description) {
|
|
||||||
if ('_table' === $column) {
|
|
||||||
$this->addSql(sprintf('COMMENT ON TABLE %s IS $_$%s$_$', $quotedTable, $description));
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$dbTable->hasColumn($column)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->addSql(sprintf(
|
|
||||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
|
||||||
$quotedTable,
|
|
||||||
'"'.str_replace('"', '""', $column).'"',
|
|
||||||
$description,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
@@ -1,189 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace DoctrineMigrations;
|
|
||||||
|
|
||||||
use App\Shared\Infrastructure\Database\CategoryCodeSql;
|
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
|
||||||
use Doctrine\Migrations\AbstractMigration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ERP-78 — Refonte de la taxonomie Categories (M0/M1).
|
|
||||||
*
|
|
||||||
* Modele AVANT (merge via Version20260527164000 + Version20260601000000) :
|
|
||||||
* DISTRIBUTEUR / COURTIER / SECTEUR / AUTRE sont des `category_type`.
|
|
||||||
*
|
|
||||||
* Modele APRES (decision produit 01/06) :
|
|
||||||
* - UN SEUL `category_type` : CLIENT (code CLIENT, label « Client ») ;
|
|
||||||
* - Distributeur / Courtier / Secteur / Autre (+ categories metier fines)
|
|
||||||
* deviennent des `Category` rattachees au type CLIENT ;
|
|
||||||
* - filtrage metier sur un `code` stable porte par la `Category` (et non plus
|
|
||||||
* par le type) : on reporte les codes DISTRIBUTEUR / COURTIER sur la categorie
|
|
||||||
* correspondante. RG-1.03 (distributor/broker) et RG-1.29 (categorie interdite
|
|
||||||
* sur adresse) s'appuient desormais sur `category.code`.
|
|
||||||
*
|
|
||||||
* Migration CORRECTIVE et NOUVELLE : la migration mergee Version20260601000000
|
|
||||||
* (qui a pu tourner en CI / chez d'autres devs) n'est PAS editee.
|
|
||||||
*
|
|
||||||
* Namespace racine `DoctrineMigrations` (regle ABSOLUE n°11) et NON modulaire
|
|
||||||
* Catalog : avec plusieurs migrations_paths, Doctrine Migrations 3.x trie par
|
|
||||||
* FQCN alphabetique (AlphabeticalComparator). Introduire la 1re migration
|
|
||||||
* modulaire `App\Module\Catalog\...` la ferait trier AVANT toutes les
|
|
||||||
* `DoctrineMigrations\...` sur base vide -> elle s'executerait avant la creation
|
|
||||||
* des tables et le seed dont elle depend. Le namespace racine garantit l'ordre
|
|
||||||
* par timestamp.
|
|
||||||
*
|
|
||||||
* Idempotence : `ADD COLUMN IF NOT EXISTS`, `INSERT ... ON CONFLICT` / guards
|
|
||||||
* `NOT EXISTS`, `CREATE UNIQUE INDEX IF NOT EXISTS`. En prod la table `category`
|
|
||||||
* est vide (aucune fixture metier) : l'ajout de `code NOT NULL` est sur. En
|
|
||||||
* dev/test, le purger Doctrine vide `category`/`category_type` avant les
|
|
||||||
* fixtures, qui reproduisent le meme etat final (cf. CategoryTypeFixtures /
|
|
||||||
* CategoryFixtures).
|
|
||||||
*/
|
|
||||||
final class Version20260602100000 extends AbstractMigration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Categories systeme reportees depuis les anciens types : nom => code.
|
|
||||||
* Le code est la cle metier stable (RG-1.03 / RG-1.29).
|
|
||||||
*/
|
|
||||||
private const array SYSTEM_CATEGORIES = [
|
|
||||||
'Distributeur' => 'DISTRIBUTEUR',
|
|
||||||
'Courtier' => 'COURTIER',
|
|
||||||
'Secteur' => 'SECTEUR',
|
|
||||||
'Autre' => 'AUTRE',
|
|
||||||
];
|
|
||||||
|
|
||||||
/** Anciens codes de `category_type` devenus inutiles. */
|
|
||||||
private const array LEGACY_TYPE_CODES = ['DISTRIBUTEUR', 'COURTIER', 'SECTEUR', 'AUTRE'];
|
|
||||||
|
|
||||||
public function getDescription(): string
|
|
||||||
{
|
|
||||||
return 'ERP-78 : Category.code + type unique CLIENT (categories Distributeur/Courtier/Secteur/Autre codees, anciens types supprimes).';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function up(Schema $schema): void
|
|
||||||
{
|
|
||||||
// 1. Colonne `code` (nullable d'abord pour pouvoir backfiller, NOT NULL ensuite).
|
|
||||||
$this->addSql('ALTER TABLE category ADD COLUMN IF NOT EXISTS code VARCHAR(50) DEFAULT NULL');
|
|
||||||
|
|
||||||
// 2. Type unique CLIENT (idempotent via l'index unique uq_category_type_code).
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
INSERT INTO category_type (code, label) VALUES ('CLIENT', 'Client')
|
|
||||||
ON CONFLICT (code) DO NOTHING
|
|
||||||
SQL);
|
|
||||||
|
|
||||||
// 3. Re-pointer toute categorie pre-existante (rattachee a un ancien type)
|
|
||||||
// vers le type CLIENT, en lui donnant un code derive du nom si absent.
|
|
||||||
// En prod la table est vide -> no-op ; defensif pour les envs qui
|
|
||||||
// auraient deja seede des categories sous les anciens types. Le slug
|
|
||||||
// SQL est le miroir EXACT de CategoryCodeGenerator::slugify (cf.
|
|
||||||
// CategoryCodeSql + CategoryCodeSqlSlugTest) : un nom accentue produit
|
|
||||||
// le meme code que la generation applicative (« Independant » ->
|
|
||||||
// INDEPENDANT, et non IND_PENDANT).
|
|
||||||
$this->addSql(
|
|
||||||
'UPDATE category c '
|
|
||||||
."SET category_type_id = (SELECT id FROM category_type WHERE code = 'CLIENT'), "
|
|
||||||
.'code = COALESCE(c.code, '.CategoryCodeSql::slugExpression('c.name').') '
|
|
||||||
.'WHERE c.category_type_id IN (SELECT id FROM category_type WHERE code IN (:legacyCodes))',
|
|
||||||
['legacyCodes' => self::LEGACY_TYPE_CODES],
|
|
||||||
['legacyCodes' => \Doctrine\DBAL\ArrayParameterType::STRING],
|
|
||||||
);
|
|
||||||
|
|
||||||
// 4. Creer les 4 categories systeme sous CLIENT (si leur code est libre
|
|
||||||
// parmi les actifs). created_at/updated_at NOT NULL -> now() ; le blame
|
|
||||||
// reste null (seed hors contexte HTTP, libelle « Systeme » cote front).
|
|
||||||
foreach (self::SYSTEM_CATEGORIES as $name => $code) {
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
INSERT INTO category (name, code, category_type_id, created_at, updated_at)
|
|
||||||
SELECT :name, :code, ct.id, NOW(), NOW()
|
|
||||||
FROM category_type ct
|
|
||||||
WHERE ct.code = 'CLIENT'
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM category c WHERE c.code = :code AND c.deleted_at IS NULL
|
|
||||||
)
|
|
||||||
SQL, ['name' => $name, 'code' => $code]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Backfill defensif : toute categorie encore sans code recoit un slug
|
|
||||||
// de son nom (garantit que le SET NOT NULL passe). Meme expression de
|
|
||||||
// slug fidele au generateur applicatif (CategoryCodeSql).
|
|
||||||
$this->addSql(
|
|
||||||
'UPDATE category SET code = '.CategoryCodeSql::slugExpression('name').' WHERE code IS NULL',
|
|
||||||
);
|
|
||||||
|
|
||||||
// 6. Index unique partiel sur le code parmi les actifs (non exprimable en
|
|
||||||
// ORM : recree aussi dans `test-db-setup` apres schema:update).
|
|
||||||
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS uq_category_code ON category (code) WHERE deleted_at IS NULL');
|
|
||||||
|
|
||||||
// 7. Code desormais obligatoire.
|
|
||||||
$this->addSql('ALTER TABLE category ALTER COLUMN code SET NOT NULL');
|
|
||||||
|
|
||||||
// 8. Documentation SQL (regle ABSOLUE n°12). Dollar-quoting Postgres.
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
COMMENT ON COLUMN category.code IS $_$Code technique stable (slug MAJUSCULE du nom, <= 50) — unique parmi les actifs (uq_category_code). Fige a la creation. DISTRIBUTEUR/COURTIER pilotent RG-1.03/1.29.$_$
|
|
||||||
SQL);
|
|
||||||
|
|
||||||
// 9. Supprimer les anciens types devenus orphelins (aucune categorie ne
|
|
||||||
// les reference plus apres le re-pointage de l'etape 3). Le guard
|
|
||||||
// NOT EXISTS evite de casser sur la FK RESTRICT category.category_type_id.
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
DELETE FROM category_type
|
|
||||||
WHERE code IN (:legacyCodes)
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM category c WHERE c.category_type_id = category_type.id
|
|
||||||
)
|
|
||||||
SQL, ['legacyCodes' => self::LEGACY_TYPE_CODES], ['legacyCodes' => \Doctrine\DBAL\ArrayParameterType::STRING]);
|
|
||||||
|
|
||||||
// 10. Realigner la doc SQL de client_address_category (migration mergee
|
|
||||||
// Version20260601000000, non editable) sur le nouveau modele RG-1.29.
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
COMMENT ON TABLE client_address_category IS $_$Jointure M2M client_address <-> category — codes DISTRIBUTEUR/COURTIER interdits sur une adresse (RG-1.29).$_$
|
|
||||||
SQL);
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
COMMENT ON COLUMN client_address_category.category_id IS $_$FK -> category.id, ON DELETE RESTRICT — categorie d adresse (tout code sauf DISTRIBUTEUR/COURTIER, RG-1.29).$_$
|
|
||||||
SQL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(Schema $schema): void
|
|
||||||
{
|
|
||||||
// Best-effort : rollback du modele CLIENT vers les 4 anciens types.
|
|
||||||
// 1. Retirer l'index unique sur le code.
|
|
||||||
$this->addSql('DROP INDEX IF EXISTS uq_category_code');
|
|
||||||
|
|
||||||
// 2. Recreer les 4 anciens types.
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
INSERT INTO category_type (code, label) VALUES
|
|
||||||
('DISTRIBUTEUR', 'Distributeur'),
|
|
||||||
('COURTIER', 'Courtier'),
|
|
||||||
('SECTEUR', 'Secteur'),
|
|
||||||
('AUTRE', 'Autre')
|
|
||||||
ON CONFLICT (code) DO NOTHING
|
|
||||||
SQL);
|
|
||||||
|
|
||||||
// 3. Re-pointer les categories systeme (par code) vers leur type d'origine.
|
|
||||||
// Codes inlines : constantes controlees (self::SYSTEM_CATEGORIES), pas
|
|
||||||
// d'entree utilisateur — evite le binding d'un parametre nomme repete.
|
|
||||||
foreach (self::SYSTEM_CATEGORIES as $name => $code) {
|
|
||||||
$this->addSql(sprintf(
|
|
||||||
"UPDATE category SET category_type_id = (SELECT id FROM category_type WHERE code = '%s') WHERE code = '%s'",
|
|
||||||
$code,
|
|
||||||
$code,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Supprimer le type CLIENT s'il ne reference plus aucune categorie.
|
|
||||||
$this->addSql(<<<'SQL'
|
|
||||||
DELETE FROM category_type
|
|
||||||
WHERE code = 'CLIENT'
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM category c WHERE c.category_type_id = category_type.id
|
|
||||||
)
|
|
||||||
SQL);
|
|
||||||
|
|
||||||
// 5. Retirer la colonne code (les categories libres sans type d'origine
|
|
||||||
// restent sous CLIENT si encore presentes — rollback uniquement
|
|
||||||
// pertinent en prod ou seules les 4 categories systeme existent).
|
|
||||||
$this->addSql('ALTER TABLE category DROP COLUMN IF EXISTS code');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Module\Catalog\Application\Service;
|
|
||||||
|
|
||||||
use App\Module\Catalog\Domain\Repository\CategoryRepositoryInterface;
|
|
||||||
use Symfony\Component\String\Slugger\AsciiSlugger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Genere le code technique stable d'une Category a partir de son nom (ERP-78).
|
|
||||||
*
|
|
||||||
* Regle (decision produit 02/06) : `code` est obligatoire et auto-genere — un
|
|
||||||
* slug MAJUSCULE du nom, sans accent, separateurs non alphanumeriques reduits a
|
|
||||||
* `_`, borne a 50 caracteres (longueur colonne). Exemples :
|
|
||||||
* - « Distributeur » -> DISTRIBUTEUR
|
|
||||||
* - « Agro-alimentaire » -> AGRO_ALIMENTAIRE
|
|
||||||
* - « Transport/Logistique » -> TRANSPORT_LOGISTIQUE
|
|
||||||
*
|
|
||||||
* Le code est FIGE a la creation (jamais recalcule sur renommage) afin de rester
|
|
||||||
* une cle deterministe stable entre environnements (RG-1.03 / RG-1.29 cote M1).
|
|
||||||
*
|
|
||||||
* Unicite : l'index partiel `uq_category_code` (WHERE deleted_at IS NULL) impose
|
|
||||||
* l'unicite parmi les categories actives. Deux noms distincts peuvent produire
|
|
||||||
* le meme slug (« Agro alimentaire » / « Agro-alimentaire ») : on suffixe alors
|
|
||||||
* le code par `_2`, `_3`... jusqu'a obtenir un code libre.
|
|
||||||
*/
|
|
||||||
final class CategoryCodeGenerator
|
|
||||||
{
|
|
||||||
/** Longueur maximale de la colonne `category.code`. */
|
|
||||||
private const int MAX_LENGTH = 50;
|
|
||||||
|
|
||||||
private readonly AsciiSlugger $slugger;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private readonly CategoryRepositoryInterface $categoryRepository,
|
|
||||||
) {
|
|
||||||
$this->slugger = new AsciiSlugger();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Slug brut (sans garantie d'unicite) — utile pour les seeds deterministes.
|
|
||||||
*/
|
|
||||||
public function slugify(string $name): string
|
|
||||||
{
|
|
||||||
$slug = $this->slugger->slug($name, '_')->upper()->toString();
|
|
||||||
|
|
||||||
// Borne a la longueur colonne, puis retire un eventuel `_` terminal
|
|
||||||
// introduit par la troncature.
|
|
||||||
$slug = substr($slug, 0, self::MAX_LENGTH);
|
|
||||||
$slug = trim($slug, '_');
|
|
||||||
|
|
||||||
// Garde-fou : un nom uniquement compose de caracteres non alphanumeriques
|
|
||||||
// (theorique, le nom est NotBlank + Length>=2) donnerait un slug vide.
|
|
||||||
return '' === $slug ? 'CATEGORY' : $slug;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Code unique parmi les categories actives : slug du nom, suffixe `_N` en
|
|
||||||
* cas de collision. `$excludeId` ignore la categorie courante (PATCH).
|
|
||||||
*/
|
|
||||||
public function generateUnique(string $name, ?int $excludeId = null): string
|
|
||||||
{
|
|
||||||
$base = $this->slugify($name);
|
|
||||||
$candidate = $base;
|
|
||||||
$suffix = 2;
|
|
||||||
|
|
||||||
while ($this->categoryRepository->existsActiveByCode($candidate, $excludeId)) {
|
|
||||||
$suffixStr = '_'.$suffix;
|
|
||||||
// Retronque la base pour que `base + suffixe` tienne dans 50 caracteres.
|
|
||||||
$candidate = substr($base, 0, self::MAX_LENGTH - strlen($suffixStr)).$suffixStr;
|
|
||||||
++$suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $candidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,6 @@ 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;
|
||||||
@@ -74,17 +73,16 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
)]
|
)]
|
||||||
#[ORM\Entity(repositoryClass: DoctrineCategoryRepository::class)]
|
#[ORM\Entity(repositoryClass: DoctrineCategoryRepository::class)]
|
||||||
#[ORM\Table(name: 'category')]
|
#[ORM\Table(name: 'category')]
|
||||||
// Index nommes pour matcher la migration (cf. Role/Permission/Site). Les index
|
// Index nommes pour matcher la migration (cf. Role/Permission/Site). L'index
|
||||||
// uniques partiels `uq_category_name_type_active` (LOWER(name), category_type_id
|
// unique partiel `uq_category_name_type_active` (LOWER(name), category_type_id
|
||||||
// WHERE deleted_at IS NULL) et `uq_category_code` (code WHERE deleted_at IS NULL)
|
// WHERE deleted_at IS NULL) reste possede par la seule migration : Doctrine ORM
|
||||||
// restent possedes par la seule migration : Doctrine ORM ne sait pas exprimer un
|
// ne sait pas exprimer un index fonctionnel + partiel via attribut.
|
||||||
// index partiel via attribut.
|
|
||||||
#[ORM\Index(name: 'idx_category_deleted_at', columns: ['deleted_at'])]
|
#[ORM\Index(name: 'idx_category_deleted_at', columns: ['deleted_at'])]
|
||||||
#[ORM\Index(name: 'idx_category_type_id', columns: ['category_type_id'])]
|
#[ORM\Index(name: 'idx_category_type_id', columns: ['category_type_id'])]
|
||||||
#[ORM\Index(name: 'idx_category_created_by', columns: ['created_by'])]
|
#[ORM\Index(name: 'idx_category_created_by', columns: ['created_by'])]
|
||||||
#[ORM\Index(name: 'idx_category_updated_by', columns: ['updated_by'])]
|
#[ORM\Index(name: 'idx_category_updated_by', columns: ['updated_by'])]
|
||||||
#[Auditable]
|
#[Auditable]
|
||||||
class Category implements TimestampableInterface, BlamableInterface, CategoryInterface
|
class Category implements TimestampableInterface, BlamableInterface
|
||||||
{
|
{
|
||||||
// === 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
|
||||||
@@ -110,16 +108,6 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
|||||||
#[Groups(['category:read', 'category:write'])]
|
#[Groups(['category:read', 'category:write'])]
|
||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
|
||||||
// Code technique stable (slug MAJUSCULE du nom) — NOT NULL + unique parmi les
|
|
||||||
// actifs (index partiel `uq_category_code` possede par la migration). Genere
|
|
||||||
// par le CategoryProcessor a la creation puis fige (jamais recalcule sur
|
|
||||||
// renommage) : sert de cle metier deterministe (RG-1.03 / RG-1.29). Lecture
|
|
||||||
// seule cote API (hors groupe category:write) : le front filtre dessus mais
|
|
||||||
// ne le saisit pas.
|
|
||||||
#[ORM\Column(length: 50)]
|
|
||||||
#[Groups(['category:read'])]
|
|
||||||
private ?string $code = null;
|
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: CategoryType::class)]
|
#[ORM\ManyToOne(targetEntity: CategoryType::class)]
|
||||||
#[ORM\JoinColumn(name: 'category_type_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
|
#[ORM\JoinColumn(name: 'category_type_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
|
||||||
#[Assert\NotNull(message: 'Type de catégorie obligatoire.')]
|
#[Assert\NotNull(message: 'Type de catégorie obligatoire.')]
|
||||||
@@ -152,21 +140,6 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implemente CategoryInterface : code technique stable de la categorie.
|
|
||||||
*/
|
|
||||||
public function getCode(): ?string
|
|
||||||
{
|
|
||||||
return $this->code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCode(string $code): static
|
|
||||||
{
|
|
||||||
$this->code = $code;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCategoryType(): ?CategoryType
|
public function getCategoryType(): ?CategoryType
|
||||||
{
|
{
|
||||||
return $this->categoryType;
|
return $this->categoryType;
|
||||||
@@ -179,16 +152,6 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
|||||||
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;
|
||||||
|
|||||||
@@ -13,13 +13,6 @@ interface CategoryRepositoryInterface
|
|||||||
|
|
||||||
public function save(Category $category): void;
|
public function save(Category $category): void;
|
||||||
|
|
||||||
/**
|
|
||||||
* Vrai si une categorie active (deleted_at IS NULL) porte deja ce code.
|
|
||||||
* `$excludeId` exclut une categorie precise du test (cas PATCH). Sert a
|
|
||||||
* garantir l'unicite du code generee par le CategoryCodeGenerator (ERP-78).
|
|
||||||
*/
|
|
||||||
public function existsActiveByCode(string $code, ?int $excludeId = null): bool;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construit un QueryBuilder de liste avec filtre soft-delete et tri par defaut.
|
* Construit un QueryBuilder de liste avec filtre soft-delete et tri par defaut.
|
||||||
* - $includeDeleted = false : exclut les categories soft-deleted (RG-1.08)
|
* - $includeDeleted = false : exclut les categories soft-deleted (RG-1.08)
|
||||||
|
|||||||
+4
-17
@@ -7,7 +7,6 @@ namespace App\Module\Catalog\Infrastructure\ApiPlatform\State\Processor;
|
|||||||
use ApiPlatform\Metadata\DeleteOperationInterface;
|
use ApiPlatform\Metadata\DeleteOperationInterface;
|
||||||
use ApiPlatform\Metadata\Operation;
|
use ApiPlatform\Metadata\Operation;
|
||||||
use ApiPlatform\State\ProcessorInterface;
|
use ApiPlatform\State\ProcessorInterface;
|
||||||
use App\Module\Catalog\Application\Service\CategoryCodeGenerator;
|
|
||||||
use App\Module\Catalog\Domain\Entity\Category;
|
use App\Module\Catalog\Domain\Entity\Category;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||||
@@ -17,13 +16,10 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
|
|||||||
/**
|
/**
|
||||||
* Processor Category : applique les regles de gestion en ecriture.
|
* Processor Category : applique les regles de gestion en ecriture.
|
||||||
*
|
*
|
||||||
* - POST / PATCH : trim du nom (RG-1.03) ; a la CREATION, generation du `code`
|
* - POST / PATCH : trim du nom (RG-1.03) puis delegation au persist_processor
|
||||||
* technique stable (slug MAJUSCULE du nom, unique parmi les actifs — ERP-78)
|
* Doctrine ORM. Toute UniqueConstraintViolationException remontee par Postgres
|
||||||
* via CategoryCodeGenerator ; puis delegation au persist_processor Doctrine
|
* (collision sur l'index partiel uq_category_name_type_active) est traduite
|
||||||
* ORM. Le code est FIGE a la creation (jamais recalcule sur PATCH). Toute
|
* en HTTP 409 avec le message attendu par la spec (RG-1.07).
|
||||||
* UniqueConstraintViolationException remontee par Postgres (collision sur
|
|
||||||
* l'index partiel uq_category_name_type_active) est traduite en HTTP 409 avec
|
|
||||||
* le message attendu par la spec (RG-1.07).
|
|
||||||
* - DELETE : soft delete (RG-1.12). On NE delegue PAS au remove_processor ;
|
* - DELETE : soft delete (RG-1.12). On NE delegue PAS au remove_processor ;
|
||||||
* on pose deletedAt = now() puis on delegue au persist_processor pour que
|
* on pose deletedAt = now() puis on delegue au persist_processor pour que
|
||||||
* le UPDATE Doctrine parte et que le TimestampableBlamableSubscriber mette
|
* le UPDATE Doctrine parte et que le TimestampableBlamableSubscriber mette
|
||||||
@@ -36,7 +32,6 @@ final class CategoryProcessor implements ProcessorInterface
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
||||||
private readonly ProcessorInterface $persistProcessor,
|
private readonly ProcessorInterface $persistProcessor,
|
||||||
private readonly CategoryCodeGenerator $codeGenerator,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
||||||
@@ -67,14 +62,6 @@ final class CategoryProcessor implements ProcessorInterface
|
|||||||
$data->setName(trim($data->getName()));
|
$data->setName(trim($data->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ERP-78 : le code est genere a la CREATION puis fige. On le (re)genere
|
|
||||||
// uniquement s'il est absent (POST, ou entite seedee sans code) — un PATCH
|
|
||||||
// sur une categorie existante conserve son code. Genere depuis le nom
|
|
||||||
// (NotBlank, deja trimme), unique parmi les actifs.
|
|
||||||
if (null === $data->getCode() && null !== $data->getName()) {
|
|
||||||
$data->setCode($this->codeGenerator->generateUnique($data->getName(), $data->getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||||
} catch (UniqueConstraintViolationException $e) {
|
} catch (UniqueConstraintViolationException $e) {
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Module\Catalog\Infrastructure\DataFixtures;
|
|
||||||
|
|
||||||
use App\Module\Catalog\Domain\Entity\Category;
|
|
||||||
use App\Module\Catalog\Domain\Entity\CategoryType;
|
|
||||||
use App\Module\Catalog\Domain\Repository\CategoryTypeRepositoryInterface;
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
use RuntimeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixtures dev/test du module Catalog : ~11 categories de demonstration, toutes
|
|
||||||
* rattachees au type unique CLIENT (refonte taxonomie ERP-78). Chaque categorie
|
|
||||||
* porte un `code` stable. Alimente le repertoire clients (ClientFixtures, module
|
|
||||||
* Commercial) avec des donnees realistes couvrant RG-1.03 (codes DISTRIBUTEUR /
|
|
||||||
* COURTIER) et RG-1.29 (codes interdits sur adresse).
|
|
||||||
*
|
|
||||||
* Depend de CategoryTypeFixtures : le type CLIENT doit etre seede avant de
|
|
||||||
* pouvoir y rattacher des Category.
|
|
||||||
*
|
|
||||||
* Idempotence : lookup par `code` parmi les categories non supprimees (deletedAt
|
|
||||||
* null), coherent avec l'index unique partiel uq_category_code (code WHERE
|
|
||||||
* deleted_at IS NULL). Rejouable sans doublon meme si le purger Doctrine est
|
|
||||||
* desactive.
|
|
||||||
*
|
|
||||||
* Audit / Blamable : persist hors contexte HTTP -> created_by / updated_by
|
|
||||||
* restent null (« Systeme » cote front), c'est attendu.
|
|
||||||
*
|
|
||||||
* Portee : DONNEES DE DEMONSTRATION (dev uniquement). En environnement `test`,
|
|
||||||
* la fixture ne charge rien : les tests seedent et nettoient leurs propres
|
|
||||||
* categories (prefixe dedie) et comptent sur une table `category` vierge — y
|
|
||||||
* injecter des categories de demo casserait comptages et cleanups FK
|
|
||||||
* (client_category). Cf. ClientFixtures (meme garde-fou).
|
|
||||||
*/
|
|
||||||
class CategoryFixtures extends Fixture implements DependentFixtureInterface
|
|
||||||
{
|
|
||||||
/** Code du type unique (cf. CategoryTypeFixtures, migration ERP-78). */
|
|
||||||
private const string CLIENT_TYPE_CODE = 'CLIENT';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Source unique des categories de demonstration : nom => code stable. Les 4
|
|
||||||
* premieres (Distributeur / Courtier / Secteur / Autre) sont les categories
|
|
||||||
* « systeme » reportees des anciens types ; leurs codes pilotent les RG.
|
|
||||||
*
|
|
||||||
* @var array<string, string>
|
|
||||||
*/
|
|
||||||
private const CATEGORIES = [
|
|
||||||
'Distributeur' => 'DISTRIBUTEUR',
|
|
||||||
'Courtier' => 'COURTIER',
|
|
||||||
'Secteur' => 'SECTEUR',
|
|
||||||
'Autre' => 'AUTRE',
|
|
||||||
'BTP' => 'BTP',
|
|
||||||
'Industrie' => 'INDUSTRIE',
|
|
||||||
'Agro-alimentaire' => 'AGRO_ALIMENTAIRE',
|
|
||||||
'Transport/Logistique' => 'TRANSPORT_LOGISTIQUE',
|
|
||||||
'Services' => 'SERVICES',
|
|
||||||
'Association' => 'ASSOCIATION',
|
|
||||||
'Indépendant' => 'INDEPENDANT',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private readonly CategoryTypeRepositoryInterface $categoryTypeRepository,
|
|
||||||
#[Autowire('%kernel.environment%')]
|
|
||||||
private readonly string $environment,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<int, class-string>
|
|
||||||
*/
|
|
||||||
public function getDependencies(): array
|
|
||||||
{
|
|
||||||
return [CategoryTypeFixtures::class];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager): void
|
|
||||||
{
|
|
||||||
// Donnees de demo : dev uniquement. En test, on laisse la table vierge.
|
|
||||||
if ('test' === $this->environment) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$clientType = null;
|
|
||||||
foreach ($this->categoryTypeRepository->findAllOrderedByLabel() as $type) {
|
|
||||||
if (self::CLIENT_TYPE_CODE === $type->getCode()) {
|
|
||||||
$clientType = $type;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$clientType instanceof CategoryType) {
|
|
||||||
// Misconfiguration : CategoryTypeFixtures n'a pas tourne avant.
|
|
||||||
throw new RuntimeException(
|
|
||||||
'CategoryTypeFixtures doit avoir seede le type "CLIENT" avant CategoryFixtures.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (self::CATEGORIES as $name => $code) {
|
|
||||||
$this->ensureCategory($manager, $name, $code, $clientType);
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cree la categorie (name, code) sous le type CLIENT si son code n'existe pas
|
|
||||||
* encore parmi les categories actives, sinon la laisse en place. Lookup
|
|
||||||
* aligne sur l'index unique partiel uq_category_code.
|
|
||||||
*/
|
|
||||||
private function ensureCategory(ObjectManager $manager, string $name, string $code, CategoryType $type): void
|
|
||||||
{
|
|
||||||
$existing = $manager->getRepository(Category::class)->findOneBy([
|
|
||||||
'code' => $code,
|
|
||||||
'deletedAt' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (null !== $existing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = new Category();
|
|
||||||
$category->setName($name);
|
|
||||||
$category->setCode($code);
|
|
||||||
$category->setCategoryType($type);
|
|
||||||
$manager->persist($category);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,19 +10,17 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
|
|||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixtures du module Catalog : seed du type de categorie (M1).
|
* Fixtures du module Catalog : seed des types de categorie metier (M1).
|
||||||
*
|
*
|
||||||
* Refonte taxonomie ERP-78 : le modele n'a plus qu'UN SEUL `category_type`,
|
* La table `category_type` est creee vide au M0 ; le M1 la peuple avec les 4
|
||||||
* CLIENT (code CLIENT, label « Client »). Distributeur / Courtier / Secteur /
|
* types DISTRIBUTEUR / COURTIER / SECTEUR / AUTRE (cf. spec M1 § 3.3).
|
||||||
* Autre (et les categories metier fines) sont desormais des `Category` codees
|
|
||||||
* rattachees a ce type (cf. CategoryFixtures + migration Version20260602100000).
|
|
||||||
*
|
*
|
||||||
* Pourquoi une fixture EN PLUS du seed de la migration : `category_type` est une
|
* Pourquoi une fixture EN PLUS du seed de la migration (Version20260601000000) :
|
||||||
* entite managee par l ORM, donc le purger Doctrine la vide avant chaque
|
* `category_type` est une entite managee par l ORM, donc le purger Doctrine la
|
||||||
* `doctrine:fixtures:load`. Sans cette fixture, le type CLIENT seede par la
|
* vide avant chaque `doctrine:fixtures:load`. Sans cette fixture, les 4 types
|
||||||
* migration disparaitrait apres `make db-reset` / setup de test. Le seed
|
* seedes par la migration disparaitraient apres `make db-reset` / setup de test.
|
||||||
* migration couvre la prod (ou les fixtures ne tournent pas) ; cette fixture
|
* Le seed migration couvre la prod (ou les fixtures ne tournent pas) ; cette
|
||||||
* re-aligne dev et test. Les deux chemins produisent un etat identique.
|
* fixture re-aligne dev et test. Les deux chemins produisent un etat identique.
|
||||||
*
|
*
|
||||||
* Idempotence : lookup par `code` parmi les types existants avant insertion,
|
* Idempotence : lookup par `code` parmi les types existants avant insertion,
|
||||||
* sur le modele d AppFixtures::ensureSystemRole. Rejouable sans doublon meme
|
* sur le modele d AppFixtures::ensureSystemRole. Rejouable sans doublon meme
|
||||||
@@ -31,11 +29,14 @@ use Doctrine\Persistence\ObjectManager;
|
|||||||
class CategoryTypeFixtures extends Fixture
|
class CategoryTypeFixtures extends Fixture
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Source unique du type : code technique => libelle FR. Doit rester aligne
|
* Source unique des 4 types metier : code technique => libelle FR.
|
||||||
* sur le seed de la migration Version20260602100000 (type unique CLIENT).
|
* Doit rester aligne sur le seed de la migration Version20260601000000.
|
||||||
*/
|
*/
|
||||||
private const TYPES = [
|
private const TYPES = [
|
||||||
'CLIENT' => 'Client',
|
'DISTRIBUTEUR' => 'Distributeur',
|
||||||
|
'COURTIER' => 'Courtier',
|
||||||
|
'SECTEUR' => 'Secteur',
|
||||||
|
'AUTRE' => 'Autre',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|||||||
@@ -31,23 +31,6 @@ class DoctrineCategoryRepository extends ServiceEntityRepository implements Cate
|
|||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function existsActiveByCode(string $code, ?int $excludeId = null): bool
|
|
||||||
{
|
|
||||||
$qb = $this->createQueryBuilder('c')
|
|
||||||
->select('1')
|
|
||||||
->andWhere('c.code = :code')
|
|
||||||
->andWhere('c.deletedAt IS NULL')
|
|
||||||
->setParameter('code', $code)
|
|
||||||
->setMaxResults(1)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (null !== $excludeId) {
|
|
||||||
$qb->andWhere('c.id != :excludeId')->setParameter('excludeId', $excludeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [] !== $qb->getQuery()->getResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createListQueryBuilder(bool $includeDeleted = false): QueryBuilder
|
public function createListQueryBuilder(bool $includeDeleted = false): QueryBuilder
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('c')
|
$qb = $this->createQueryBuilder('c')
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
<?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
@@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Module\Commercial\Application\Validator;
|
|
||||||
|
|
||||||
use ApiPlatform\Validator\Exception\ValidationException;
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client;
|
|
||||||
use Symfony\Component\Validator\ConstraintViolation;
|
|
||||||
use Symfony\Component\Validator\ConstraintViolationList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validator metier RG-1.04 (durcie ERP-74) : pour un utilisateur portant le
|
|
||||||
* role metier Commerciale, TOUS les champs de l'onglet Information sont
|
|
||||||
* obligatoires sur POST comme sur tout PATCH, independamment des champs
|
|
||||||
* reellement envoyes.
|
|
||||||
*
|
|
||||||
* Invoque par le ClientProcessor des que l'utilisateur courant porte le role
|
|
||||||
* Commerciale (plus de condition d'intersection avec l'onglet Information).
|
|
||||||
* Pour les autres roles, ces champs restent optionnels — le validator n'est
|
|
||||||
* pas appele.
|
|
||||||
*
|
|
||||||
* Leve une ValidationException (HTTP 422) listant chaque champ manquant, par
|
|
||||||
* coherence avec les violations Symfony rendues par API Platform.
|
|
||||||
*/
|
|
||||||
final class ClientInformationCompletenessValidator
|
|
||||||
{
|
|
||||||
public function validate(Client $client): void
|
|
||||||
{
|
|
||||||
// Map champ -> valeur courante de l'onglet Information.
|
|
||||||
$fields = [
|
|
||||||
'description' => $client->getDescription(),
|
|
||||||
'competitors' => $client->getCompetitors(),
|
|
||||||
'foundedAt' => $client->getFoundedAt(),
|
|
||||||
'employeesCount' => $client->getEmployeesCount(),
|
|
||||||
'revenueAmount' => $client->getRevenueAmount(),
|
|
||||||
'directorName' => $client->getDirectorName(),
|
|
||||||
'profitAmount' => $client->getProfitAmount(),
|
|
||||||
];
|
|
||||||
|
|
||||||
$violations = new ConstraintViolationList();
|
|
||||||
|
|
||||||
foreach ($fields as $property => $value) {
|
|
||||||
if ($this->isMissing($value)) {
|
|
||||||
$violations->add(new ConstraintViolation(
|
|
||||||
sprintf('Ce champ est obligatoire pour le role Commerciale (champ "%s").', $property),
|
|
||||||
null,
|
|
||||||
[],
|
|
||||||
$client,
|
|
||||||
$property,
|
|
||||||
$value,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($violations) > 0) {
|
|
||||||
throw new ValidationException($violations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Une valeur est manquante si null ou, pour une chaine, vide apres trim.
|
|
||||||
* Les zeros numeriques (employeesCount = 0, profitAmount = "0.00") sont des
|
|
||||||
* valeurs valides : on ne les considere pas manquants.
|
|
||||||
*/
|
|
||||||
private function isMissing(mixed $value): bool
|
|
||||||
{
|
|
||||||
if (null === $value) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return is_string($value) && '' === trim($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,36 +9,4 @@ 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'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,762 +0,0 @@
|
|||||||
<?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\SiteInterface;
|
|
||||||
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')",
|
|
||||||
// La liste embarque les categories (avec leur code, groupe
|
|
||||||
// category:read) et les sites agreges des adresses (groupe
|
|
||||||
// site:read) pour alimenter les colonnes « Catégories » et
|
|
||||||
// « Site(s) » du Repertoire (ERP-62). Cf. getSites() plus bas.
|
|
||||||
normalizationContext: ['groups' => ['client:read', 'default:read', 'category:read', 'site:read']],
|
|
||||||
provider: ClientProvider::class,
|
|
||||||
),
|
|
||||||
new Get(
|
|
||||||
security: "is_granted('commercial.clients.view')",
|
|
||||||
// Detail : client + sous-collections embarquees.
|
|
||||||
// - client:read:accounting est ajoute par le context builder selon la
|
|
||||||
// permission (gate les scalaires comptables ET les RIB embarques),
|
|
||||||
// donc absent ici volontairement.
|
|
||||||
// - client_rib:read N'EST PLUS dans le contexte : le contenu des RIB
|
|
||||||
// embarques est desormais porte par client:read:accounting (gate),
|
|
||||||
// ce qui retire la fuite IBAN/BIC vers les users sans accounting.view.
|
|
||||||
// - category:read et site:read sont indispensables pour embarquer le
|
|
||||||
// code/libelle des categories et des sites (sinon stub IRI nu) :
|
|
||||||
// Category.code/name vivent sous category:read, Site.name sous site:read.
|
|
||||||
normalizationContext: ['groups' => [
|
|
||||||
'client:read',
|
|
||||||
'client:item:read',
|
|
||||||
'client_contact:read',
|
|
||||||
'client_address:read',
|
|
||||||
'category:read',
|
|
||||||
'site:read',
|
|
||||||
'default:read',
|
|
||||||
]],
|
|
||||||
provider: ClientProvider::class,
|
|
||||||
),
|
|
||||||
new Post(
|
|
||||||
security: "is_granted('commercial.clients.manage')",
|
|
||||||
normalizationContext: ['groups' => ['client:read', 'default:read', 'category:read', 'site: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', 'category:read', 'site: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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sites distincts rattaches a au moins une adresse du client (RG-1.10).
|
|
||||||
* Le Client ne porte pas de sites en propre : ils vivent sur les adresses.
|
|
||||||
* Agrege en lecture seule pour la colonne « Site(s) » du Repertoire (badges
|
|
||||||
* colores) — expose en LISTE via le groupe client:read (les adresses
|
|
||||||
* completes restent reservees au detail, client:item:read).
|
|
||||||
*
|
|
||||||
* @return list<SiteInterface>
|
|
||||||
*/
|
|
||||||
#[Groups(['client:read'])]
|
|
||||||
public function getSites(): array
|
|
||||||
{
|
|
||||||
$sites = [];
|
|
||||||
foreach ($this->addresses as $address) {
|
|
||||||
foreach ($address->getSites() as $site) {
|
|
||||||
// Deduplication par identite d'objet : un meme site peut etre
|
|
||||||
// rattache a plusieurs adresses du client.
|
|
||||||
$sites[spl_object_id($site)] = $site;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_values($sites);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Embed gate sur le groupe COMPTABLE (et non client:item:read comme contacts/
|
|
||||||
// adresses) : client:read:accounting n'est ajoute au contexte que si l'user a
|
|
||||||
// accounting.view (ClientReadGroupContextBuilder). Resultat : la cle `ribs` est
|
|
||||||
// TOTALEMENT ABSENTE du detail pour un user sans accounting.view (ex. Commerciale),
|
|
||||||
// au meme titre que les scalaires comptables — corrige la fuite de RIB ou la
|
|
||||||
// Commerciale recevait IBAN/BIC en clair.
|
|
||||||
/** @return Collection<int, ClientRib> */
|
|
||||||
#[Groups(['client:read:accounting'])]
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,482 +0,0 @@
|
|||||||
<?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\Serializer\Attribute\SerializedName;
|
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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). Un email de facturation est obligatoire ssi isBilling
|
|
||||||
* (RG-1.11). Au moins un site doit etre rattache (RG-1.10, Assert\Count). Ces
|
|
||||||
* regles sont portees par des Assert\Callback (cf. validateProspectExclusivity /
|
|
||||||
* validateBillingEmailPresence, ERP-76) qui remontent une 422 avant la base ;
|
|
||||||
* les CHECK Postgres (chk_client_address_prospect_exclusive /
|
|
||||||
* chk_client_address_billing_email) restent en filet de securite.
|
|
||||||
*
|
|
||||||
* Relations M2M :
|
|
||||||
* - sites : SiteInterface (module Sites) via resolve_target_entities
|
|
||||||
* - contacts : ClientContact (meme module)
|
|
||||||
* - categories : CategoryInterface (module Catalog) via resolve_target_entities
|
|
||||||
* — codes DISTRIBUTEUR/COURTIER interdits (RG-1.29, validateCategoryCodes, ERP-78)
|
|
||||||
*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.29 (ERP-78) : ces codes de categorie decrivent une relation entre
|
|
||||||
* clients (distributeur / courtier) et n'ont pas de sens sur une adresse.
|
|
||||||
* Toute autre categorie du type CLIENT est autorisee.
|
|
||||||
*/
|
|
||||||
private const array FORBIDDEN_CATEGORY_CODES = ['DISTRIBUTEUR', 'COURTIER'];
|
|
||||||
|
|
||||||
#[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;
|
|
||||||
|
|
||||||
// Groupe d'ECRITURE uniquement sur la propriete (denormalisation PATCH/POST).
|
|
||||||
// Le groupe de LECTURE est porte par le getter isProspect()/isDelivery()/
|
|
||||||
// isBilling() avec SerializedName : sans cela, Symfony strip le prefixe "is"
|
|
||||||
// des getters booleens et exposerait les cles "prospect"/"delivery"/"billing"
|
|
||||||
// — en pratique le #[Groups] etant sur la propriete `isX` et le getter
|
|
||||||
// derivant l'attribut `x`, la cle etait totalement DROPPEE du JSON (meme bug
|
|
||||||
// que Client::isArchived). Pattern corrige : Groups + SerializedName sur le getter.
|
|
||||||
#[ORM\Column(name: 'is_prospect', options: ['default' => false])]
|
|
||||||
#[Groups(['client_address:write'])]
|
|
||||||
private bool $isProspect = false;
|
|
||||||
|
|
||||||
#[ORM\Column(name: 'is_delivery', options: ['default' => false])]
|
|
||||||
#[Groups(['client_address:write'])]
|
|
||||||
private bool $isDelivery = false;
|
|
||||||
|
|
||||||
#[ORM\Column(name: 'is_billing', options: ['default' => false])]
|
|
||||||
#[Groups(['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 (validateBillingEmailPresence + CHECK BDD).
|
|
||||||
#[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 code DISTRIBUTEUR/COURTIER interdites (validateCategoryCodes).
|
|
||||||
/** @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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.06 / RG-1.07 / RG-1.08 : une adresse de prospection est exclusive
|
|
||||||
* d'une adresse de livraison ou de facturation. Mirror applicatif (422) du
|
|
||||||
* CHECK chk_client_address_prospect_exclusive, joue avant la base afin de
|
|
||||||
* remonter une violation Hydra plutot qu'une 500 DBAL.
|
|
||||||
*/
|
|
||||||
#[Assert\Callback]
|
|
||||||
public function validateProspectExclusivity(ExecutionContextInterface $context): void
|
|
||||||
{
|
|
||||||
if ($this->isProspect && ($this->isDelivery || $this->isBilling)) {
|
|
||||||
$context->buildViolation('Une adresse de prospection ne peut pas être une adresse de livraison ni de facturation.')
|
|
||||||
->atPath('isProspect')
|
|
||||||
->addViolation()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.11 : l'email de facturation est obligatoire si l'adresse est de
|
|
||||||
* facturation, et interdit sinon. Mirror applicatif (422) du CHECK
|
|
||||||
* chk_client_address_billing_email.
|
|
||||||
*
|
|
||||||
* On raisonne sur la PRESENCE effective de l'email : null ET chaine vide
|
|
||||||
* sont traites comme « absent », car le ClientAddressProcessor normalise une
|
|
||||||
* chaine vide en null APRES la validation (RG-1.21). Sans ce traitement,
|
|
||||||
* billingEmail="" passerait les callbacks (null === "" est faux) puis serait
|
|
||||||
* persiste en null avec is_billing=true -> violation du CHECK -> 500 au lieu
|
|
||||||
* du 422 attendu (et symetriquement, "" sur une adresse non facturable
|
|
||||||
* serait rejete a tort).
|
|
||||||
*/
|
|
||||||
#[Assert\Callback]
|
|
||||||
public function validateBillingEmailPresence(ExecutionContextInterface $context): void
|
|
||||||
{
|
|
||||||
$hasBillingEmail = null !== $this->billingEmail && '' !== trim($this->billingEmail);
|
|
||||||
|
|
||||||
if ($this->isBilling && !$hasBillingEmail) {
|
|
||||||
$context->buildViolation('L\'email de facturation est obligatoire pour une adresse de facturation.')
|
|
||||||
->atPath('billingEmail')
|
|
||||||
->addViolation()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->isBilling && $hasBillingEmail) {
|
|
||||||
$context->buildViolation('L\'email de facturation n\'est autorisé que sur une adresse de facturation.')
|
|
||||||
->atPath('billingEmail')
|
|
||||||
->addViolation()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.29 (ERP-78) : une adresse interdit les categories de code
|
|
||||||
* DISTRIBUTEUR / COURTIER — elles decrivent une relation entre clients
|
|
||||||
* (RG-1.03) et n'ont pas de sens sur une adresse physique -> 422 avec
|
|
||||||
* violation sur le champ `categories`. Toute autre categorie (type unique
|
|
||||||
* CLIENT) est acceptee. S'appuie sur CategoryInterface::getCode() (pas
|
|
||||||
* d'import du module Catalog — regle ABSOLUE n°1).
|
|
||||||
*/
|
|
||||||
#[Assert\Callback]
|
|
||||||
public function validateCategoryCodes(ExecutionContextInterface $context): void
|
|
||||||
{
|
|
||||||
foreach ($this->categories as $category) {
|
|
||||||
if ($category instanceof CategoryInterface
|
|
||||||
&& in_array($category->getCode(), self::FORBIDDEN_CATEGORY_CODES, true)) {
|
|
||||||
$context->buildViolation('Type de catégorie non autorisé sur une adresse.')
|
|
||||||
->atPath('categories')
|
|
||||||
->addViolation()
|
|
||||||
;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Groupe de lecture + nom serialise explicite (cf. note sur la propriete) :
|
|
||||||
// sans SerializedName, Symfony exposerait la cle "prospect" (strip du prefixe
|
|
||||||
// "is" sur les getters) et, le groupe etant declare sur la propriete `isProspect`,
|
|
||||||
// droppait silencieusement la cle du JSON.
|
|
||||||
#[Groups(['client_address:read'])]
|
|
||||||
#[SerializedName('isProspect')]
|
|
||||||
public function isProspect(): bool
|
|
||||||
{
|
|
||||||
return $this->isProspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIsProspect(bool $isProspect): static
|
|
||||||
{
|
|
||||||
$this->isProspect = $isProspect;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Groups(['client_address:read'])]
|
|
||||||
#[SerializedName('isDelivery')]
|
|
||||||
public function isDelivery(): bool
|
|
||||||
{
|
|
||||||
return $this->isDelivery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIsDelivery(bool $isDelivery): static
|
|
||||||
{
|
|
||||||
$this->isDelivery = $isDelivery;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Groups(['client_address:read'])]
|
|
||||||
#[SerializedName('isBilling')]
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
<?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;
|
|
||||||
|
|
||||||
// Double groupe de lecture :
|
|
||||||
// - `client_rib:read` : sous-ressource autonome GET /api/client_ribs/{id}
|
|
||||||
// (deja securisee par commercial.clients.accounting.view).
|
|
||||||
// - `client:read:accounting` : embed des RIB sous le detail Client, ajoute
|
|
||||||
// DYNAMIQUEMENT par ClientReadGroupContextBuilder uniquement si l'user a
|
|
||||||
// accounting.view. Ce double marquage gate les RIB embarques au meme titre
|
|
||||||
// que les scalaires comptables (RG : la Commerciale ne voit aucun RIB).
|
|
||||||
#[ORM\Id]
|
|
||||||
#[ORM\GeneratedValue]
|
|
||||||
#[ORM\Column]
|
|
||||||
#[Groups(['client_rib:read', 'client:read:accounting'])]
|
|
||||||
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:read:accounting', 'client_rib:write'])]
|
|
||||||
private ?string $label = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 20)]
|
|
||||||
#[Assert\NotBlank]
|
|
||||||
#[Assert\Bic]
|
|
||||||
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
|
||||||
private ?string $bic = null;
|
|
||||||
|
|
||||||
#[ORM\Column(length: 34)]
|
|
||||||
#[Assert\NotBlank]
|
|
||||||
#[Assert\Iban]
|
|
||||||
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
|
||||||
private ?string $iban = null;
|
|
||||||
|
|
||||||
#[ORM\Column(options: ['default' => 0])]
|
|
||||||
#[Groups(['client_rib:read', 'client:read:accounting', '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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?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).
|
|
||||||
* - Archivage (RG-1.25) :
|
|
||||||
* - $archivedOnly = true -> uniquement les archives (is_archived = true) ;
|
|
||||||
* - sinon $includeArchived = true -> actifs + archives (echappatoire) ;
|
|
||||||
* - sinon (defaut) -> uniquement les actifs (is_archived = false).
|
|
||||||
* $archivedOnly a la priorite sur $includeArchived.
|
|
||||||
* - 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.
|
|
||||||
* - $categoryCodes : restreint aux clients possedant au moins une categorie
|
|
||||||
* dont le code est dans la liste (OR — ERP-78). Liste vide = pas de filtre.
|
|
||||||
* - $siteIds : restreint aux clients ayant au moins une adresse rattachee a
|
|
||||||
* l'un des sites donnes (OR — RG-1.10). Liste vide = pas de filtre.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* @param list<string> $categoryCodes
|
|
||||||
* @param list<int> $siteIds
|
|
||||||
*/
|
|
||||||
public function createListQueryBuilder(
|
|
||||||
bool $includeArchived = false,
|
|
||||||
?string $search = null,
|
|
||||||
array $categoryCodes = [],
|
|
||||||
array $siteIds = [],
|
|
||||||
bool $archivedOnly = false,
|
|
||||||
): QueryBuilder;
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?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
@@ -1,74 +0,0 @@
|
|||||||
<?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
@@ -1,65 +0,0 @@
|
|||||||
<?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
@@ -1,71 +0,0 @@
|
|||||||
<?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
@@ -1,92 +0,0 @@
|
|||||||
<?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
@@ -1,151 +0,0 @@
|
|||||||
<?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.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,639 +0,0 @@
|
|||||||
<?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 portant la categorie de code DISTRIBUTEUR (idem
|
|
||||||
* broker -> COURTIER). Depuis ERP-78, le filtrage se fait sur le code de la
|
|
||||||
* Category (et non plus sur le type, devenu unique CLIENT).
|
|
||||||
*/
|
|
||||||
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->hasCategoryCode($distributor, 'DISTRIBUTEUR')) {
|
|
||||||
$this->throwViolation(
|
|
||||||
'distributor',
|
|
||||||
'Le distributeur référencé doit être un client de catégorie DISTRIBUTEUR.',
|
|
||||||
$data,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $broker && !$this->hasCategoryCode($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 code donne. S'appuie sur
|
|
||||||
* CategoryInterface::getCode() (pas d'import de Category — regle ABSOLUE n°1).
|
|
||||||
*/
|
|
||||||
private function hasCategoryCode(Client $client, string $code): bool
|
|
||||||
{
|
|
||||||
foreach ($client->getCategories() as $category) {
|
|
||||||
if ($category instanceof CategoryInterface && $category->getCode() === $code) {
|
|
||||||
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
@@ -1,104 +0,0 @@
|
|||||||
<?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.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
<?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
|
|
||||||
* ?categoryCode=<code> (clients ayant >= 1 categorie de ce code — ERP-78) ;
|
|
||||||
* - 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);
|
|
||||||
$archivedOnly = $this->readBool($filters['archivedOnly'] ?? false);
|
|
||||||
$search = $filters['search'] ?? null;
|
|
||||||
// categoryCode accepte un code unique (?categoryCode=DISTRIBUTEUR, selects
|
|
||||||
// RG-1.03) OU une liste (?categoryCode[]=A&categoryCode[]=B, drawer multi).
|
|
||||||
$categoryCodes = $this->readStringList($filters['categoryCode'] ?? []);
|
|
||||||
$siteIds = $this->readIntList($filters['siteId'] ?? []);
|
|
||||||
|
|
||||||
// Filtrage delegue au repository (logique partagee avec l'export XLSX).
|
|
||||||
$qb = $this->repository->createListQueryBuilder(
|
|
||||||
$includeArchived,
|
|
||||||
is_string($search) ? $search : null,
|
|
||||||
$categoryCodes,
|
|
||||||
$siteIds,
|
|
||||||
$archivedOnly,
|
|
||||||
);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalise un filtre en liste de chaines. Tolere un code unique (string)
|
|
||||||
* ou une liste (?key[]=a&key[]=b). Trim + retrait des vides.
|
|
||||||
*
|
|
||||||
* @return list<string>
|
|
||||||
*/
|
|
||||||
private function readStringList(mixed $raw): array
|
|
||||||
{
|
|
||||||
$values = is_array($raw) ? $raw : [$raw];
|
|
||||||
|
|
||||||
$out = [];
|
|
||||||
foreach ($values as $value) {
|
|
||||||
if (is_string($value) && '' !== trim($value)) {
|
|
||||||
$out[] = trim($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalise un filtre en liste d'identifiants entiers positifs. Tolere une
|
|
||||||
* valeur unique ou une liste (?key[]=1&key[]=2).
|
|
||||||
*
|
|
||||||
* @return list<int>
|
|
||||||
*/
|
|
||||||
private function readIntList(mixed $raw): array
|
|
||||||
{
|
|
||||||
$values = is_array($raw) ? $raw : [$raw];
|
|
||||||
|
|
||||||
$out = [];
|
|
||||||
foreach ($values as $value) {
|
|
||||||
if ((is_int($value) || (is_string($value) && ctype_digit($value))) && (int) $value > 0) {
|
|
||||||
$out[] = (int) $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,248 +0,0 @@
|
|||||||
<?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'));
|
|
||||||
$archivedOnly = $this->readBool($request->query->get('archivedOnly'));
|
|
||||||
$search = $request->query->getString('search') ?: null;
|
|
||||||
|
|
||||||
// Memes filtres que la vue liste : categoryCode/siteId tolerent une valeur
|
|
||||||
// unique ou une liste (?categoryCode[]=A&siteId[]=1). On lit via all() pour
|
|
||||||
// ne pas lever d'exception sur une valeur scalaire.
|
|
||||||
$query = $request->query->all();
|
|
||||||
$categoryCodes = $this->readStringList($query['categoryCode'] ?? []);
|
|
||||||
$siteIds = $this->readIntList($query['siteId'] ?? []);
|
|
||||||
|
|
||||||
/** @var list<Client> $clients */
|
|
||||||
$clients = $this->repository
|
|
||||||
->createListQueryBuilder($includeArchived, $search, $categoryCodes, $siteIds, $archivedOnly)
|
|
||||||
->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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalise un filtre en liste de chaines (valeur unique ou liste).
|
|
||||||
* Aligne sur ClientProvider pour un comportement identique a la liste.
|
|
||||||
*
|
|
||||||
* @return list<string>
|
|
||||||
*/
|
|
||||||
private function readStringList(mixed $raw): array
|
|
||||||
{
|
|
||||||
$values = is_array($raw) ? $raw : [$raw];
|
|
||||||
|
|
||||||
$out = [];
|
|
||||||
foreach ($values as $value) {
|
|
||||||
if (is_string($value) && '' !== trim($value)) {
|
|
||||||
$out[] = trim($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalise un filtre en liste d'identifiants entiers positifs (valeur unique
|
|
||||||
* ou liste). Aligne sur ClientProvider.
|
|
||||||
*
|
|
||||||
* @return list<int>
|
|
||||||
*/
|
|
||||||
private function readIntList(mixed $raw): array
|
|
||||||
{
|
|
||||||
$values = is_array($raw) ? $raw : [$raw];
|
|
||||||
|
|
||||||
$out = [];
|
|
||||||
foreach ($values as $value) {
|
|
||||||
if ((is_int($value) || (is_string($value) && ctype_digit($value))) && (int) $value > 0) {
|
|
||||||
$out[] = (int) $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,555 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Module\Commercial\Infrastructure\DataFixtures;
|
|
||||||
|
|
||||||
use App\Module\Catalog\Infrastructure\DataFixtures\CategoryFixtures;
|
|
||||||
use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
|
|
||||||
use App\Module\Commercial\Domain\Entity\Bank;
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientContact;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientRib;
|
|
||||||
use App\Module\Commercial\Domain\Entity\PaymentType;
|
|
||||||
use App\Module\Sites\Infrastructure\DataFixtures\SitesFixtures;
|
|
||||||
use App\Shared\Domain\Contract\CategoryInterface;
|
|
||||||
use App\Shared\Domain\Contract\SiteInterface;
|
|
||||||
use App\Shared\Domain\Contract\SiteProviderInterface;
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
use RuntimeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixtures dev/test du module Commercial : ~14 clients de demonstration couvrant
|
|
||||||
* l'ensemble des cas metier RG-1.xx du repertoire clients (M1) :
|
|
||||||
* - client basique ; dependant distributeur / courtier (RG-1.03) ;
|
|
||||||
* - reglement LCR avec 2 RIB (RG-1.13) ; reglement Cheque sans RIB ;
|
|
||||||
* - multi-adresses Prospect / Livraison / Facturation (RG-1.06/07/08/11) ;
|
|
||||||
* - prospect seul ; 3 contacts dont un avec telephone secondaire (RG-1.05/1.02) ;
|
|
||||||
* - client archive (RG-1.22) ; onglet Information complet ; multi-categories M2M.
|
|
||||||
*
|
|
||||||
* Resolution inter-modules conforme a la regle n°1 (pas d'import direct) :
|
|
||||||
* - categories resolues via le contrat Shared CategoryInterface
|
|
||||||
* (resolve_target_entities -> Category) ;
|
|
||||||
* - sites resolus via le contrat Shared SiteProviderInterface.
|
|
||||||
*
|
|
||||||
* Normalisation : les valeurs sont fournies BRUTES (casse libre, telephones
|
|
||||||
* formates) et normalisees par ClientFieldNormalizer avant persist, exactement
|
|
||||||
* comme le ferait le ClientProcessor via l'API (companyName UPPERCASE,
|
|
||||||
* first/last Capitalize, telephones chiffres seuls, emails lowercase).
|
|
||||||
*
|
|
||||||
* Distributeur / courtier auto-references (RG-1.03) : les tiers referencables
|
|
||||||
* (GSO distributeur, Cabinet Leonard courtier) sont crees AVANT les clients qui
|
|
||||||
* les referencent ; un unique flush en fin de load ordonne correctement les
|
|
||||||
* inserts auto-references.
|
|
||||||
*
|
|
||||||
* Idempotence : lookup par companyName normalise (coherent avec l'index unique
|
|
||||||
* partiel uq_client_company_name_active). Un client deja present n'est pas
|
|
||||||
* reconstruit (ses sous-collections ne sont pas redupliquees). Rejouable sans
|
|
||||||
* doublon meme si le purger Doctrine est desactive.
|
|
||||||
*
|
|
||||||
* Audit / Blamable : persist hors contexte HTTP -> created_by / updated_by
|
|
||||||
* restent null (« Systeme » cote front), c'est attendu. Les donnees respectent
|
|
||||||
* les CHECK BDD ET les validators applicatifs (exclusivite Prospect, billingEmail
|
|
||||||
* ssi facturation, aucune categorie de code DISTRIBUTEUR/COURTIER sur une adresse
|
|
||||||
* — RG-1.29, ERP-78).
|
|
||||||
*
|
|
||||||
* Depend de CategoryFixtures (categories), SitesFixtures (sites) et
|
|
||||||
* CommercialReferentialFixtures (referentiels comptables Bank / PaymentType).
|
|
||||||
*
|
|
||||||
* Portee : DONNEES DE DEMONSTRATION (dev uniquement). En environnement `test`,
|
|
||||||
* la fixture ne charge rien : les tests seedent et nettoient leurs propres
|
|
||||||
* clients et comptent sur une table `client` vierge — y injecter 14 clients de
|
|
||||||
* demo casserait les comptages de liste et les cleanups. Meme garde-fou que
|
|
||||||
* CategoryFixtures.
|
|
||||||
*/
|
|
||||||
class ClientFixtures extends Fixture implements DependentFixtureInterface
|
|
||||||
{
|
|
||||||
/** Cache des categories resolues par nom (evite des requetes repetees). */
|
|
||||||
private array $categoryCache = [];
|
|
||||||
|
|
||||||
/** Cache des sites resolus par nom. */
|
|
||||||
private array $siteCache = [];
|
|
||||||
|
|
||||||
/** ObjectManager courant, capture en debut de load (resolution categories). */
|
|
||||||
private ObjectManager $manager;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private readonly ClientFieldNormalizer $normalizer,
|
|
||||||
private readonly SiteProviderInterface $siteProvider,
|
|
||||||
#[Autowire('%kernel.environment%')]
|
|
||||||
private readonly string $environment,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<int, class-string>
|
|
||||||
*/
|
|
||||||
public function getDependencies(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
CategoryFixtures::class,
|
|
||||||
SitesFixtures::class,
|
|
||||||
CommercialReferentialFixtures::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager): void
|
|
||||||
{
|
|
||||||
// Donnees de demo : dev uniquement. En test, on laisse la table vierge.
|
|
||||||
if ('test' === $this->environment) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->manager = $manager;
|
|
||||||
|
|
||||||
// === Tiers referencables (RG-1.03) : crees en premier ===
|
|
||||||
|
|
||||||
// Distributeur reference par d'autres clients.
|
|
||||||
[$gso, $gsoIsNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Distrib Grand Sud-Ouest',
|
|
||||||
firstName: 'Paul',
|
|
||||||
lastName: 'Garnier',
|
|
||||||
phonePrimary: '05 56 10 20 30',
|
|
||||||
email: 'contact@distrib-gso.fr',
|
|
||||||
categoryNames: ['Distributeur'],
|
|
||||||
);
|
|
||||||
if ($gsoIsNew) {
|
|
||||||
$this->addContact($gso, 'Paul', 'Garnier', 'Directeur commercial', '05 56 10 20 30', null, 'paul.garnier@distrib-gso.fr');
|
|
||||||
$this->addAddress($gso, ['Pommevic'], '82400', 'Pommevic', '1 Av. Jean Duquesne', isDelivery: true, categoryNames: ['Transport/Logistique']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Courtier reference par d'autres clients.
|
|
||||||
[$leonard, $leonardIsNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Cabinet Léonard Assurances',
|
|
||||||
firstName: 'Sophie',
|
|
||||||
lastName: 'Léonard',
|
|
||||||
phonePrimary: '05 49 11 22 33',
|
|
||||||
email: 'contact@cabinet-leonard.fr',
|
|
||||||
categoryNames: ['Courtier'],
|
|
||||||
);
|
|
||||||
if ($leonardIsNew) {
|
|
||||||
$this->addContact($leonard, 'Sophie', 'Léonard', 'Gérante', '05 49 11 22 33', null, 'sophie.leonard@cabinet-leonard.fr');
|
|
||||||
$this->addAddress($leonard, ['Chatellerault'], '86100', 'Châtellerault', '5 rue des Courtiers', isBilling: true, billingEmail: 'Factures@Cabinet-Leonard.FR');
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Client basique ===
|
|
||||||
[$dubois, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Menuiserie Dubois',
|
|
||||||
firstName: 'Jean',
|
|
||||||
lastName: 'Dubois',
|
|
||||||
phonePrimary: '05 49 00 00 01',
|
|
||||||
email: 'contact@menuiserie-dubois.fr',
|
|
||||||
categoryNames: ['BTP'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$dubois->setPaymentType($this->paymentType($manager, 'VIREMENT'));
|
|
||||||
$dubois->setBank($this->bank($manager, 'SG'));
|
|
||||||
$this->addContact($dubois, 'Jean', 'Dubois', 'Gérant', '05 49 00 00 01', null, 'jean.dubois@menuiserie-dubois.fr');
|
|
||||||
$this->addAddress($dubois, ['Chatellerault'], '86100', 'Châtellerault', '12 rue de l\'Atelier', isDelivery: true, categoryNames: ['BTP']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Dependant d'un distributeur (RG-1.03) ===
|
|
||||||
[$garage, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Garage Martin',
|
|
||||||
firstName: 'Luc',
|
|
||||||
lastName: 'Martin',
|
|
||||||
phonePrimary: '05 56 44 55 66',
|
|
||||||
email: 'accueil@garage-martin.fr',
|
|
||||||
categoryNames: ['Services'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$garage->setDistributor($gso);
|
|
||||||
$this->addContact($garage, 'Luc', 'Martin', 'Gérant', '05 56 44 55 66', null, 'luc.martin@garage-martin.fr');
|
|
||||||
$this->addAddress($garage, ['Pommevic'], '82400', 'Pommevic', '8 route de Moissac', isDelivery: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Dependant d'un courtier (RG-1.03) ===
|
|
||||||
[$boulangerie, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Boulangerie Lemoine',
|
|
||||||
firstName: 'Marie',
|
|
||||||
lastName: 'Lemoine',
|
|
||||||
phonePrimary: '05 49 77 88 99',
|
|
||||||
email: 'bonjour@boulangerie-lemoine.fr',
|
|
||||||
categoryNames: ['Agro-alimentaire'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$boulangerie->setBroker($leonard);
|
|
||||||
$this->addContact($boulangerie, 'Marie', 'Lemoine', 'Gérante', '05 49 77 88 99', null, 'marie.lemoine@boulangerie-lemoine.fr');
|
|
||||||
$this->addAddress($boulangerie, ['Chatellerault'], '86100', 'Châtellerault', '3 place du Marché', isDelivery: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Reglement LCR avec 2 RIB (RG-1.13) ===
|
|
||||||
[$transports, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Transports Rapides',
|
|
||||||
firstName: null,
|
|
||||||
lastName: 'Bernard',
|
|
||||||
phonePrimary: '05 56 12 13 14',
|
|
||||||
email: 'exploitation@transports-rapides.fr',
|
|
||||||
categoryNames: ['Transport/Logistique'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$transports->setPaymentType($this->paymentType($manager, 'LCR'));
|
|
||||||
$this->addContact($transports, null, 'Bernard', 'Responsable exploitation', '05 56 12 13 14', null, 'expl@transports-rapides.fr');
|
|
||||||
$this->addAddress($transports, ['Saint-Jean'], '17400', 'Fontenet', '2 zone industrielle', isDelivery: true, categoryNames: ['Transport/Logistique']);
|
|
||||||
$this->addRib($transports, 'Compte principal', 'BNPAFRPPXXX', 'FR1420041010050500013M02606', 0);
|
|
||||||
$this->addRib($transports, 'Compte secondaire', 'SOGEFRPPXXX', 'FR7630006000011234567890189', 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Multi-adresses Prospect / Livraison / Facturation (RG-1.06/07/08/11) ===
|
|
||||||
[$industries, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Industries Vertes',
|
|
||||||
firstName: 'Claire',
|
|
||||||
lastName: 'Moreau',
|
|
||||||
phonePrimary: '05 49 21 22 23',
|
|
||||||
email: 'contact@industries-vertes.fr',
|
|
||||||
categoryNames: ['Industrie'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$this->addContact($industries, 'Claire', 'Moreau', 'Directrice', '05 49 21 22 23', null, 'claire.moreau@industries-vertes.fr');
|
|
||||||
// Prospect : exclusif de livraison/facturation (sans billingEmail).
|
|
||||||
$this->addAddress($industries, ['Chatellerault'], '86100', 'Châtellerault', '1 avenue de la Prospection', isProspect: true, position: 0);
|
|
||||||
// Livraison.
|
|
||||||
$this->addAddress($industries, ['Saint-Jean'], '17400', 'Fontenet', '4 rue de la Livraison', isDelivery: true, categoryNames: ['Industrie'], position: 1);
|
|
||||||
// Facturation : billingEmail obligatoire.
|
|
||||||
$this->addAddress($industries, ['Chatellerault'], '86100', 'Châtellerault', '7 boulevard des Factures', isBilling: true, billingEmail: 'Compta@Industries-Vertes.FR', position: 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === 3 contacts dont un avec telephone secondaire (RG-1.05/1.02) ===
|
|
||||||
[$agro, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Agro Distribution Sud',
|
|
||||||
firstName: 'Thomas',
|
|
||||||
lastName: 'Petit',
|
|
||||||
phonePrimary: '05 56 31 32 33',
|
|
||||||
email: 'contact@agro-sud.fr',
|
|
||||||
categoryNames: ['Agro-alimentaire'],
|
|
||||||
phoneSecondary: '06 01 02 03 04',
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$this->addContact($agro, 'Thomas', 'Petit', 'Directeur des achats', '05 56 31 32 33', '06 01 02 03 04', 'thomas.petit@agro-sud.fr', 0);
|
|
||||||
$this->addContact($agro, 'Julie', 'Roux', 'Assistante commerciale', '05 56 31 32 34', null, 'julie.roux@agro-sud.fr', 1);
|
|
||||||
$this->addContact($agro, 'Marc', 'Girard', 'Logistique', '05 56 31 32 35', null, 'marc.girard@agro-sud.fr', 2);
|
|
||||||
$this->addAddress($agro, ['Pommevic'], '82400', 'Pommevic', '10 rue des Producteurs', isDelivery: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Client archive (RG-1.22) ===
|
|
||||||
[$ancienne, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Ancienne Société Oubliée',
|
|
||||||
firstName: null,
|
|
||||||
lastName: 'Durand',
|
|
||||||
phonePrimary: '05 49 99 99 99',
|
|
||||||
email: 'contact@ancienne-societe.fr',
|
|
||||||
categoryNames: ['Association'],
|
|
||||||
isArchived: true,
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$this->addContact($ancienne, null, 'Durand', 'Ancien contact', '05 49 99 99 99', null, 'contact@ancienne-societe.fr');
|
|
||||||
$this->addAddress($ancienne, ['Chatellerault'], '86100', 'Châtellerault', '99 rue Fermée', isDelivery: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Reglement Cheque sans RIB ===
|
|
||||||
[$services, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Services Pro Conseil',
|
|
||||||
firstName: 'Nadia',
|
|
||||||
lastName: 'Benali',
|
|
||||||
phonePrimary: '05 49 41 42 43',
|
|
||||||
email: 'contact@services-pro.fr',
|
|
||||||
categoryNames: ['Services'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$services->setPaymentType($this->paymentType($manager, 'CHEQUE'));
|
|
||||||
$this->addContact($services, 'Nadia', 'Benali', 'Consultante', '05 49 41 42 43', null, 'nadia.benali@services-pro.fr');
|
|
||||||
$this->addAddress($services, ['Chatellerault'], '86100', 'Châtellerault', '15 rue du Conseil', isDelivery: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Onglet Information complet (RG-1.04) ===
|
|
||||||
[$holding, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Holding Premium Invest',
|
|
||||||
firstName: 'Antoine',
|
|
||||||
lastName: 'Lefèvre',
|
|
||||||
phonePrimary: '05 56 51 52 53',
|
|
||||||
email: 'direction@holding-premium.fr',
|
|
||||||
categoryNames: ['Industrie'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$holding->setDescription('Holding industrielle diversifiée, présente sur le Grand Sud-Ouest.');
|
|
||||||
$holding->setCompetitors('Groupe Atlantique, Sud Industries');
|
|
||||||
$holding->setFoundedAt(new DateTimeImmutable('2005-03-15'));
|
|
||||||
$holding->setEmployeesCount(240);
|
|
||||||
$holding->setRevenueAmount('18500000.00');
|
|
||||||
$holding->setDirectorName('Antoine Lefèvre');
|
|
||||||
$holding->setProfitAmount('1250000.00');
|
|
||||||
$this->addContact($holding, 'Antoine', 'Lefèvre', 'PDG', '05 56 51 52 53', null, 'antoine.lefevre@holding-premium.fr');
|
|
||||||
$this->addAddress($holding, ['Pommevic'], '82400', 'Pommevic', '1 allée des Investisseurs', isDelivery: true, categoryNames: ['Industrie']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Multi-categories M2M ===
|
|
||||||
[$conglo, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Conglomérat Multi Activités',
|
|
||||||
firstName: 'Hélène',
|
|
||||||
lastName: 'Faure',
|
|
||||||
phonePrimary: '05 49 61 62 63',
|
|
||||||
email: 'contact@conglomerat-multi.fr',
|
|
||||||
categoryNames: ['BTP', 'Industrie', 'Services'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$this->addContact($conglo, 'Hélène', 'Faure', 'Directrice générale', '05 49 61 62 63', null, 'helene.faure@conglomerat-multi.fr');
|
|
||||||
$this->addAddress($conglo, ['Chatellerault', 'Saint-Jean'], '86100', 'Châtellerault', '20 rue des Activités', isDelivery: true, categoryNames: ['BTP', 'Services']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Prospect seul ===
|
|
||||||
[$prospect, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Prospect Futur Client',
|
|
||||||
firstName: 'Olivier',
|
|
||||||
lastName: 'Renard',
|
|
||||||
phonePrimary: '05 56 71 72 73',
|
|
||||||
email: 'olivier.renard@prospect-futur.fr',
|
|
||||||
categoryNames: ['BTP'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$this->addContact($prospect, 'Olivier', 'Renard', 'Responsable projet', '05 56 71 72 73', null, 'olivier.renard@prospect-futur.fr');
|
|
||||||
$this->addAddress($prospect, ['Chatellerault'], '86100', 'Châtellerault', '30 rue de la Découverte', isProspect: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Categorie AUTRE ===
|
|
||||||
[$association, $isNew] = $this->ensureClient(
|
|
||||||
$manager,
|
|
||||||
companyName: 'Association des Riverains',
|
|
||||||
firstName: null,
|
|
||||||
lastName: 'Caron',
|
|
||||||
phonePrimary: '05 49 81 82 83',
|
|
||||||
email: 'contact@asso-riverains.fr',
|
|
||||||
categoryNames: ['Association'],
|
|
||||||
);
|
|
||||||
if ($isNew) {
|
|
||||||
$this->addContact($association, null, 'Caron', 'Président', '05 49 81 82 83', null, 'president@asso-riverains.fr');
|
|
||||||
$this->addAddress($association, ['Saint-Jean'], '17400', 'Fontenet', '6 chemin du Village', isDelivery: true, categoryNames: ['Association']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cree un client (base normalisee + categories) s'il n'existe pas encore,
|
|
||||||
* sinon retourne l'existant. Retourne [Client, isNew] : isNew=false bloque la
|
|
||||||
* reconstruction des sous-collections (idempotence sans doublon).
|
|
||||||
*
|
|
||||||
* @param list<string> $categoryNames
|
|
||||||
*
|
|
||||||
* @return array{0: Client, 1: bool}
|
|
||||||
*/
|
|
||||||
private function ensureClient(
|
|
||||||
ObjectManager $manager,
|
|
||||||
string $companyName,
|
|
||||||
?string $firstName,
|
|
||||||
?string $lastName,
|
|
||||||
string $phonePrimary,
|
|
||||||
string $email,
|
|
||||||
array $categoryNames,
|
|
||||||
?string $phoneSecondary = null,
|
|
||||||
bool $isArchived = false,
|
|
||||||
): array {
|
|
||||||
$normalizedName = (string) $this->normalizer->normalizeCompanyName($companyName);
|
|
||||||
|
|
||||||
$existing = $manager->getRepository(Client::class)->findOneBy(['companyName' => $normalizedName]);
|
|
||||||
if ($existing instanceof Client) {
|
|
||||||
return [$existing, false];
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client();
|
|
||||||
$client->setCompanyName($normalizedName);
|
|
||||||
$client->setFirstName($this->normalizer->normalizePersonName($firstName));
|
|
||||||
$client->setLastName($this->normalizer->normalizePersonName($lastName));
|
|
||||||
$client->setPhonePrimary((string) $this->normalizer->normalizePhone($phonePrimary));
|
|
||||||
$client->setPhoneSecondary($this->normalizer->normalizePhone($phoneSecondary));
|
|
||||||
$client->setEmail((string) $this->normalizer->normalizeEmail($email));
|
|
||||||
|
|
||||||
foreach ($categoryNames as $categoryName) {
|
|
||||||
$client->addCategory($this->category($manager, $categoryName));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($isArchived) {
|
|
||||||
$client->setIsArchived(true);
|
|
||||||
$client->setArchivedAt(new DateTimeImmutable());
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->persist($client);
|
|
||||||
|
|
||||||
return [$client, true];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ajoute un contact normalise au client (cascade persist via Client.contacts).
|
|
||||||
* Au moins lastName est toujours fourni (RG-1.05, chk_client_contact_name).
|
|
||||||
*/
|
|
||||||
private function addContact(
|
|
||||||
Client $client,
|
|
||||||
?string $firstName,
|
|
||||||
?string $lastName,
|
|
||||||
?string $jobTitle,
|
|
||||||
?string $phonePrimary,
|
|
||||||
?string $phoneSecondary,
|
|
||||||
?string $email,
|
|
||||||
int $position = 0,
|
|
||||||
): void {
|
|
||||||
$contact = new ClientContact();
|
|
||||||
$contact->setFirstName($this->normalizer->normalizePersonName($firstName));
|
|
||||||
$contact->setLastName($this->normalizer->normalizePersonName($lastName));
|
|
||||||
$contact->setJobTitle($jobTitle);
|
|
||||||
$contact->setPhonePrimary($this->normalizer->normalizePhone($phonePrimary));
|
|
||||||
$contact->setPhoneSecondary($this->normalizer->normalizePhone($phoneSecondary));
|
|
||||||
$contact->setEmail($this->normalizer->normalizeEmail($email));
|
|
||||||
$contact->setPosition($position);
|
|
||||||
|
|
||||||
$client->addContact($contact);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ajoute une adresse au client (cascade persist via Client.addresses). Les
|
|
||||||
* donnees respectent les validators : exclusivite Prospect, billingEmail ssi
|
|
||||||
* facturation, aucune categorie de code DISTRIBUTEUR/COURTIER (RG-1.29).
|
|
||||||
*
|
|
||||||
* @param list<string> $siteNames au moins un site (RG-1.10)
|
|
||||||
* @param list<string> $categoryNames categories hors DISTRIBUTEUR/COURTIER (RG-1.29)
|
|
||||||
*/
|
|
||||||
private function addAddress(
|
|
||||||
Client $client,
|
|
||||||
array $siteNames,
|
|
||||||
string $postalCode,
|
|
||||||
string $city,
|
|
||||||
string $street,
|
|
||||||
bool $isProspect = false,
|
|
||||||
bool $isDelivery = false,
|
|
||||||
bool $isBilling = false,
|
|
||||||
?string $billingEmail = null,
|
|
||||||
array $categoryNames = [],
|
|
||||||
int $position = 0,
|
|
||||||
): void {
|
|
||||||
$address = new ClientAddress();
|
|
||||||
$address->setIsProspect($isProspect);
|
|
||||||
$address->setIsDelivery($isDelivery);
|
|
||||||
$address->setIsBilling($isBilling);
|
|
||||||
$address->setBillingEmail($this->normalizer->normalizeEmail($billingEmail));
|
|
||||||
$address->setPostalCode($postalCode);
|
|
||||||
$address->setCity($city);
|
|
||||||
$address->setStreet($street);
|
|
||||||
$address->setPosition($position);
|
|
||||||
|
|
||||||
foreach ($siteNames as $siteName) {
|
|
||||||
$address->addSite($this->site($siteName));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($categoryNames as $categoryName) {
|
|
||||||
$address->addCategory($this->category($this->manager, $categoryName));
|
|
||||||
}
|
|
||||||
|
|
||||||
$client->addAddress($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ajoute un RIB au client (cascade persist via Client.ribs). IBAN/BIC valides
|
|
||||||
* (Assert\Iban/Bic non rejouee sur persist direct mais donnees coherentes).
|
|
||||||
*/
|
|
||||||
private function addRib(Client $client, string $label, string $bic, string $iban, int $position = 0): void
|
|
||||||
{
|
|
||||||
$rib = new ClientRib();
|
|
||||||
$rib->setLabel($label);
|
|
||||||
$rib->setBic($bic);
|
|
||||||
$rib->setIban($iban);
|
|
||||||
$rib->setPosition($position);
|
|
||||||
|
|
||||||
$client->addRib($rib);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resout une categorie par son nom via le contrat Shared CategoryInterface
|
|
||||||
* (resolve_target_entities -> Category), sans importer le module Catalog
|
|
||||||
* (regle n°1). Mise en cache par nom.
|
|
||||||
*/
|
|
||||||
private function category(ObjectManager $manager, string $name): CategoryInterface
|
|
||||||
{
|
|
||||||
if (isset($this->categoryCache[$name])) {
|
|
||||||
return $this->categoryCache[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = $manager->getRepository(CategoryInterface::class)->findOneBy([
|
|
||||||
'name' => $name,
|
|
||||||
'deletedAt' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!$category instanceof CategoryInterface) {
|
|
||||||
throw new RuntimeException(sprintf(
|
|
||||||
'Categorie "%s" introuvable : CategoryFixtures doit tourner avant ClientFixtures.',
|
|
||||||
$name,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->categoryCache[$name] = $category;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resout un site par son nom via le contrat Shared SiteProviderInterface,
|
|
||||||
* sans importer le module Sites (regle n°1). Mise en cache par nom.
|
|
||||||
*/
|
|
||||||
private function site(string $name): SiteInterface
|
|
||||||
{
|
|
||||||
if (isset($this->siteCache[$name])) {
|
|
||||||
return $this->siteCache[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
$site = $this->siteProvider->findByName($name);
|
|
||||||
|
|
||||||
if (!$site instanceof SiteInterface) {
|
|
||||||
throw new RuntimeException(sprintf(
|
|
||||||
'Site "%s" introuvable : SitesFixtures doit tourner avant ClientFixtures.',
|
|
||||||
$name,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->siteCache[$name] = $site;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function paymentType(ObjectManager $manager, string $code): PaymentType
|
|
||||||
{
|
|
||||||
$type = $manager->getRepository(PaymentType::class)->findOneBy(['code' => $code]);
|
|
||||||
|
|
||||||
if (!$type instanceof PaymentType) {
|
|
||||||
throw new RuntimeException(sprintf(
|
|
||||||
'PaymentType "%s" introuvable : CommercialReferentialFixtures doit tourner avant ClientFixtures.',
|
|
||||||
$code,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function bank(ObjectManager $manager, string $code): Bank
|
|
||||||
{
|
|
||||||
$bank = $manager->getRepository(Bank::class)->findOneBy(['code' => $code]);
|
|
||||||
|
|
||||||
if (!$bank instanceof Bank) {
|
|
||||||
throw new RuntimeException(sprintf(
|
|
||||||
'Bank "%s" introuvable : CommercialReferentialFixtures doit tourner avant ClientFixtures.',
|
|
||||||
$code,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $bank;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?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()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
<?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,
|
|
||||||
array $categoryCodes = [],
|
|
||||||
array $siteIds = [],
|
|
||||||
bool $archivedOnly = false,
|
|
||||||
): QueryBuilder {
|
|
||||||
$qb = $this->createQueryBuilder('c')
|
|
||||||
// Jointures + addSelect pour hydrater en une seule requete les
|
|
||||||
// collections affichees par le Repertoire (colonnes Catégories /
|
|
||||||
// Site(s)) : sans cela, la serialisation declenche un N+1 (une
|
|
||||||
// requete par client, puis par adresse). Le Paginator ORM
|
|
||||||
// (fetchJoinCollection: true, cf. ClientProvider) gere le COUNT
|
|
||||||
// malgre ces jointures to-many.
|
|
||||||
->leftJoin('c.categories', 'cat')->addSelect('cat')
|
|
||||||
->leftJoin('c.addresses', 'addr')->addSelect('addr')
|
|
||||||
->leftJoin('addr.sites', 'site')->addSelect('site')
|
|
||||||
->andWhere('c.deletedAt IS NULL')
|
|
||||||
->orderBy('c.companyName', 'ASC')
|
|
||||||
;
|
|
||||||
|
|
||||||
// Perimetre d'archivage : archivedOnly prioritaire sur includeArchived.
|
|
||||||
if ($archivedOnly) {
|
|
||||||
$qb->andWhere('c.isArchived = true');
|
|
||||||
} elseif (!$includeArchived) {
|
|
||||||
$qb->andWhere('c.isArchived = false');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->applySearch($qb, $search);
|
|
||||||
$this->applyCategoryCodes($qb, $categoryCodes);
|
|
||||||
$this->applySiteIds($qb, $siteIds);
|
|
||||||
|
|
||||||
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 dont le code figure
|
|
||||||
* dans la liste (OR — ERP-78). Alimente le filtre « Catégories » du drawer
|
|
||||||
* (multi) ainsi que les selects « distributeur »/« courtier » (un seul code,
|
|
||||||
* RG-1.03). Sous-requete IN (plutot qu'un JOIN sur la collection M2M) pour ne
|
|
||||||
* pas perturber le DISTINCT / ORDER BY principal.
|
|
||||||
*
|
|
||||||
* @param list<string> $categoryCodes
|
|
||||||
*/
|
|
||||||
private function applyCategoryCodes(QueryBuilder $qb, array $categoryCodes): void
|
|
||||||
{
|
|
||||||
$codes = $this->normalizeStringList($categoryCodes);
|
|
||||||
if ([] === $codes) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sub = $this->getEntityManager()->createQueryBuilder()
|
|
||||||
->select('c2.id')
|
|
||||||
->from(Client::class, 'c2')
|
|
||||||
->join('c2.categories', 'cat2')
|
|
||||||
->where('cat2.code IN (:categoryCodes)')
|
|
||||||
;
|
|
||||||
|
|
||||||
$qb->andWhere($qb->expr()->in('c.id', $sub->getDQL()))
|
|
||||||
->setParameter('categoryCodes', $codes)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restreint aux clients ayant au moins une adresse rattachee a l'un des
|
|
||||||
* sites donnes (OR — RG-1.10 : les sites vivent sur les adresses, pas sur le
|
|
||||||
* client). Sous-requete IN pour ne pas perturber le tri/pagination principal.
|
|
||||||
*
|
|
||||||
* @param list<int> $siteIds
|
|
||||||
*/
|
|
||||||
private function applySiteIds(QueryBuilder $qb, array $siteIds): void
|
|
||||||
{
|
|
||||||
$ids = $this->normalizeIntList($siteIds);
|
|
||||||
if ([] === $ids) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sub = $this->getEntityManager()->createQueryBuilder()
|
|
||||||
->select('c3.id')
|
|
||||||
->from(Client::class, 'c3')
|
|
||||||
->join('c3.addresses', 'addr3')
|
|
||||||
->join('addr3.sites', 'site3')
|
|
||||||
->where('site3.id IN (:siteIds)')
|
|
||||||
;
|
|
||||||
|
|
||||||
$qb->andWhere($qb->expr()->in('c.id', $sub->getDQL()))
|
|
||||||
->setParameter('siteIds', $ids)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Nettoie une liste de chaines : trim, retrait des vides, reindexation.
|
|
||||||
* Defensive : tolere des elements scalaires non-string (cast) et ignore le
|
|
||||||
* reste sans lever de TypeError, le contrat etant justement de normaliser une
|
|
||||||
* entree potentiellement brute (query params).
|
|
||||||
*
|
|
||||||
* @param array<mixed> $values
|
|
||||||
*
|
|
||||||
* @return list<string>
|
|
||||||
*/
|
|
||||||
private function normalizeStringList(array $values): array
|
|
||||||
{
|
|
||||||
$out = [];
|
|
||||||
foreach ($values as $value) {
|
|
||||||
if (is_string($value) || is_int($value) || is_float($value)) {
|
|
||||||
$trimmed = trim((string) $value);
|
|
||||||
if ('' !== $trimmed) {
|
|
||||||
$out[] = $trimmed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Nettoie une liste d'identifiants : cast int, retrait des <= 0, reindexation.
|
|
||||||
* Defensive (cf. normalizeStringList) : accepte des entiers ou des chaines
|
|
||||||
* numeriques ('1', '2') sans TypeError, ignore le reste.
|
|
||||||
*
|
|
||||||
* @param array<mixed> $values
|
|
||||||
*
|
|
||||||
* @return list<int>
|
|
||||||
*/
|
|
||||||
private function normalizeIntList(array $values): array
|
|
||||||
{
|
|
||||||
$out = [];
|
|
||||||
foreach ($values as $value) {
|
|
||||||
if (is_numeric($value) && (int) $value > 0) {
|
|
||||||
$out[] = (int) $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?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()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?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()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?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()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
<?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,7 +22,6 @@ 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;
|
||||||
@@ -76,7 +75,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, BusinessRoleAwareInterface
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||||
{
|
{
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
@@ -338,23 +337,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Busines
|
|||||||
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;
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
<?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,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -186,15 +186,6 @@ 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',
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,11 +28,6 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|||||||
* systeme de maniere idempotente avant de rattacher les utilisateurs, afin
|
* systeme de maniere idempotente avant de rattacher les utilisateurs, afin
|
||||||
* que le workflow "make db-reset && make fixtures" reste one-shot.
|
* que le workflow "make db-reset && make fixtures" reste one-shot.
|
||||||
*
|
*
|
||||||
* Idempotence complete (y compris `doctrine:fixtures:load --append`, sans
|
|
||||||
* purge) : roles via ensureSystemRole, utilisateurs via ensureUser (lookup par
|
|
||||||
* username). Rejouer la fixture ne cree donc aucun doublon ni violation
|
|
||||||
* d'unicite de username.
|
|
||||||
*
|
|
||||||
* Dependance explicite a SitesFixtures (ticket 2) : les 3 sites Chatellerault,
|
* Dependance explicite a SitesFixtures (ticket 2) : les 3 sites Chatellerault,
|
||||||
* Saint-Jean et Pommevic doivent etre presents en base avant d'etre rattaches
|
* Saint-Jean et Pommevic doivent etre presents en base avant d'etre rattaches
|
||||||
* aux users. L'inversion volontaire de l'ordre (AppFixtures ← SitesFixtures)
|
* aux users. L'inversion volontaire de l'ordre (AppFixtures ← SitesFixtures)
|
||||||
@@ -80,7 +75,8 @@ class AppFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
$saintJean = $this->requireSite('Saint-Jean');
|
$saintJean = $this->requireSite('Saint-Jean');
|
||||||
$pommevic = $this->requireSite('Pommevic');
|
$pommevic = $this->requireSite('Pommevic');
|
||||||
|
|
||||||
$admin = $this->ensureUser($manager, 'admin');
|
$admin = new User();
|
||||||
|
$admin->setUsername('admin');
|
||||||
$admin->setIsAdmin(true);
|
$admin->setIsAdmin(true);
|
||||||
$admin->setPassword($this->passwordHasher->hashPassword($admin, 'admin'));
|
$admin->setPassword($this->passwordHasher->hashPassword($admin, 'admin'));
|
||||||
$admin->addRbacRole($adminRole);
|
$admin->addRbacRole($adminRole);
|
||||||
@@ -91,7 +87,8 @@ class AppFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
$admin->setCurrentSite($chatellerault);
|
$admin->setCurrentSite($chatellerault);
|
||||||
$manager->persist($admin);
|
$manager->persist($admin);
|
||||||
|
|
||||||
$alice = $this->ensureUser($manager, 'alice');
|
$alice = new User();
|
||||||
|
$alice->setUsername('alice');
|
||||||
$alice->setPassword($this->passwordHasher->hashPassword($alice, 'alice'));
|
$alice->setPassword($this->passwordHasher->hashPassword($alice, 'alice'));
|
||||||
$alice->addRbacRole($userRole);
|
$alice->addRbacRole($userRole);
|
||||||
// Alice : un seul site, site courant = ce site.
|
// Alice : un seul site, site courant = ce site.
|
||||||
@@ -99,7 +96,8 @@ class AppFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
$alice->setCurrentSite($chatellerault);
|
$alice->setCurrentSite($chatellerault);
|
||||||
$manager->persist($alice);
|
$manager->persist($alice);
|
||||||
|
|
||||||
$bob = $this->ensureUser($manager, 'bob');
|
$bob = new User();
|
||||||
|
$bob->setUsername('bob');
|
||||||
$bob->setPassword($this->passwordHasher->hashPassword($bob, 'bob'));
|
$bob->setPassword($this->passwordHasher->hashPassword($bob, 'bob'));
|
||||||
$bob->addRbacRole($userRole);
|
$bob->addRbacRole($userRole);
|
||||||
// Bob : site different de Alice, pour prouver le filtrage par site
|
// Bob : site different de Alice, pour prouver le filtrage par site
|
||||||
@@ -137,27 +135,6 @@ class AppFixtures extends Fixture implements DependentFixtureInterface
|
|||||||
return $role;
|
return $role;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retourne l'utilisateur correspondant au username, en le creant s'il
|
|
||||||
* n'existe pas encore. Rend la fixture idempotente y compris en
|
|
||||||
* `doctrine:fixtures:load --append` (sans purge) : sans ce lookup, recreer
|
|
||||||
* « admin » / « alice » / « bob » violerait l'unicite de username. Meme
|
|
||||||
* esprit que ensureSystemRole ci-dessus et RbacDemoFixtures::ensureDemoUsers.
|
|
||||||
*/
|
|
||||||
private function ensureUser(ObjectManager $manager, string $username): User
|
|
||||||
{
|
|
||||||
$user = $manager->getRepository(User::class)->findOneBy(['username' => $username]);
|
|
||||||
|
|
||||||
if (null !== $user) {
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = new User();
|
|
||||||
$user->setUsername($username);
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function requireSite(string $name): SiteInterface
|
private function requireSite(string $name): SiteInterface
|
||||||
{
|
{
|
||||||
$site = $this->siteProvider->findByName($name);
|
$site = $this->siteProvider->findByName($name);
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<?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 technique stable de la categorie (Category::code), ou null si non
|
|
||||||
* encore renseigne. Slug MAJUSCULE derive du nom a la creation, fige ensuite.
|
|
||||||
* Expose pour permettre a un module tiers de filtrer/valider par categorie
|
|
||||||
* metier sans dependre du libelle (`name`) ni de l'`id` (non deterministe
|
|
||||||
* entre environnements) ni importer la classe concrete Category (regle
|
|
||||||
* ABSOLUE n°1). Pilote, cote M1 Commercial :
|
|
||||||
* - RG-1.03 : un distributor doit referencer un client portant la categorie
|
|
||||||
* de code DISTRIBUTEUR (resp. COURTIER pour broker) ;
|
|
||||||
* - RG-1.29 : une adresse interdit les categories de code DISTRIBUTEUR /
|
|
||||||
* COURTIER (relations entre clients, pas des attributs d'adresse).
|
|
||||||
*/
|
|
||||||
public function getCode(): ?string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Code du type de categorie rattache (CategoryType::code), ou null si la
|
|
||||||
* categorie n'a pas de type. Depuis ERP-78, le modele n'a plus qu'un seul
|
|
||||||
* type (CLIENT) : le filtrage metier passe desormais par getCode() ci-dessus.
|
|
||||||
* Conserve pour l'affichage / la retrocompatibilite.
|
|
||||||
*/
|
|
||||||
public function getCategoryTypeCode(): ?string;
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?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.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Shared\Infrastructure\Database;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Miroir SQL de `CategoryCodeGenerator::slugify()` (module Catalog, ERP-78).
|
|
||||||
*
|
|
||||||
* Le `code` d'une `Category` est un slug MAJUSCULE deterministe du nom. A
|
|
||||||
* l'execution (POST/PATCH API), il est genere en PHP par `CategoryCodeGenerator`
|
|
||||||
* via `AsciiSlugger`. Mais la migration corrective `Version20260602100000` doit
|
|
||||||
* backfiller le `code` des categories pre-existantes en SQL pur (le backfill
|
|
||||||
* tourne dans le plan `addSql`, sans acces aux services applicatifs).
|
|
||||||
*
|
|
||||||
* Deux implementations d'un meme slug = risque de derive : un nom accentue
|
|
||||||
* comme « Independant » doit produire le MEME code (`INDEPENDANT`) quel que soit
|
|
||||||
* le chemin. Cette classe est la SOURCE UNIQUE de l'expression SQL ; son egalite
|
|
||||||
* avec le générateur PHP est verrouillee par `CategoryCodeSqlSlugTest`.
|
|
||||||
*
|
|
||||||
* Domaine couvert : noms francais / Latin-1 (tous les accents, minuscule +
|
|
||||||
* majuscule, translitteres vers l'ASCII comme le fait `AsciiSlugger`). Limite
|
|
||||||
* connue et assumee : les ligatures (`Œ`->`OE`, `ß`->`SS`) ne sont PAS gerees
|
|
||||||
* par `translate()` (mapping 1->1 uniquement) ; elles n'apparaissent pas dans
|
|
||||||
* les noms de categories CLIENT et le backfill ne s'execute de toute facon que
|
|
||||||
* sur des bases dev deja peuplees (en prod la table `category` est vide).
|
|
||||||
*/
|
|
||||||
final class CategoryCodeSql
|
|
||||||
{
|
|
||||||
/** Longueur maximale de la colonne `category.code` (cf. CategoryCodeGenerator). */
|
|
||||||
private const int MAX_LENGTH = 50;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accents Latin-1 (minuscules puis majuscules) translitteres vers leur
|
|
||||||
* equivalent ASCII minuscule — `UPPER()` repasse tout en majuscule ensuite.
|
|
||||||
* `translate()` mappe caractere a caractere : `ACCENT_FROM` et `ACCENT_TO`
|
|
||||||
* doivent avoir EXACTEMENT le meme nombre de caracteres.
|
|
||||||
*/
|
|
||||||
private const string ACCENT_FROM = 'àâäáãåçéèêëíìîïñóòôöõúùûüýÿÀÂÄÁÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸ';
|
|
||||||
private const string ACCENT_TO = 'aaaaaaceeeeiiiinooooouuuuyyaaaaaaceeeeiiiinooooouuuuyy';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expression SQL produisant le slug du `$column` donne (ex: `name`, `c.name`).
|
|
||||||
* Reproduit fidelement `CategoryCodeGenerator::slugify` : translitteration des
|
|
||||||
* accents, separateurs non alphanumeriques reduits a `_`, MAJUSCULE, borne a
|
|
||||||
* 50, `_` de bord retires, fallback `CATEGORY` si vide.
|
|
||||||
*/
|
|
||||||
public static function slugExpression(string $column): string
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
"COALESCE(NULLIF(TRIM(BOTH '_' FROM "
|
|
||||||
."LEFT(UPPER(REGEXP_REPLACE(translate(%s, '%s', '%s'), '[^A-Za-z0-9]+', '_', 'g')), %d)"
|
|
||||||
."), ''), 'CATEGORY')",
|
|
||||||
$column,
|
|
||||||
self::ACCENT_FROM,
|
|
||||||
self::ACCENT_TO,
|
|
||||||
self::MAX_LENGTH,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -53,7 +53,6 @@ final class ColumnCommentsCatalog
|
|||||||
'_table' => 'Categories M0 — referentiel type par category_type, soft-delete via deleted_at, unicite (LOWER(name), category_type_id) parmi les actifs.',
|
'_table' => 'Categories M0 — referentiel type par category_type, soft-delete via deleted_at, unicite (LOWER(name), category_type_id) parmi les actifs.',
|
||||||
'id' => 'Identifiant interne auto-incremente.',
|
'id' => 'Identifiant interne auto-incremente.',
|
||||||
'name' => 'Libelle de la categorie (≤ 120 caracteres) — unique par type parmi les actifs (RG-1.06).',
|
'name' => 'Libelle de la categorie (≤ 120 caracteres) — unique par type parmi les actifs (RG-1.06).',
|
||||||
'code' => 'Code technique stable (slug MAJUSCULE du nom, ≤ 50) — unique parmi les actifs (uq_category_code). Fige a la creation. DISTRIBUTEUR/COURTIER pilotent RG-1.03/1.29.',
|
|
||||||
'category_type_id' => 'Reference au type de la categorie — FK -> category_type.id, ON DELETE RESTRICT (un type ne peut etre supprime tant qu il a des categories).',
|
'category_type_id' => 'Reference au type de la categorie — FK -> category_type.id, ON DELETE RESTRICT (un type ne peut etre supprime tant qu il a des categories).',
|
||||||
'deleted_at' => 'Horodatage UTC du soft-delete (archivage logique) — null si la categorie est active.',
|
'deleted_at' => 'Horodatage UTC du soft-delete (archivage logique) — null si la categorie est active.',
|
||||||
] + self::timestampableBlamableComments(),
|
] + self::timestampableBlamableComments(),
|
||||||
@@ -129,135 +128,6 @@ 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(),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,25 +151,12 @@ 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 $onlyTables = null): array
|
public static function toSqlStatements(): 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) {
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,10 +5,6 @@ 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;
|
||||||
@@ -53,11 +49,6 @@ 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.
|
||||||
*/
|
*/
|
||||||
@@ -67,10 +58,6 @@ 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
|
||||||
|
|||||||
@@ -83,9 +83,6 @@ abstract class AbstractCatalogApiTestCase extends AbstractApiTestCase
|
|||||||
$suffix = substr(bin2hex(random_bytes(4)), 0, 8);
|
$suffix = substr(bin2hex(random_bytes(4)), 0, 8);
|
||||||
$category = new Category();
|
$category = new Category();
|
||||||
$category->setName($name ?? self::TEST_CATEGORY_PREFIX.$suffix);
|
$category->setName($name ?? self::TEST_CATEGORY_PREFIX.$suffix);
|
||||||
// ERP-78 : code NOT NULL + unique parmi les actifs (uq_category_code).
|
|
||||||
// Nonce aleatoire -> unicite garantie entre seeds successifs du test.
|
|
||||||
$category->setCode('TEST_'.strtoupper($suffix));
|
|
||||||
$category->setCategoryType($type);
|
$category->setCategoryType($type);
|
||||||
if (null !== $deletedAt) {
|
if (null !== $deletedAt) {
|
||||||
$category->setDeletedAt($deletedAt);
|
$category->setDeletedAt($deletedAt);
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Catalog\Api;
|
|
||||||
|
|
||||||
use App\Module\Catalog\Application\Service\CategoryCodeGenerator;
|
|
||||||
use App\Shared\Infrastructure\Database\CategoryCodeSql;
|
|
||||||
use Doctrine\DBAL\Connection;
|
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Garde-fou ERP-78 : l'expression SQL de slug (CategoryCodeSql, utilisee par le
|
|
||||||
* backfill de la migration Version20260602100000) doit produire EXACTEMENT le
|
|
||||||
* meme code que le generateur applicatif (CategoryCodeGenerator::slugify), sur
|
|
||||||
* tout le domaine de noms francais / Latin-1.
|
|
||||||
*
|
|
||||||
* Verrouille la cause racine du bug initial : deux implementations d'un meme
|
|
||||||
* slug qui derivent silencieusement (« Independant » -> IND_PENDANT cote SQL
|
|
||||||
* faute de translitteration des accents, vs INDEPENDANT cote PHP). On ne couvre
|
|
||||||
* volontairement PAS les ligatures (`Œ`, `ß`) : `translate()` est 1->1 et ne
|
|
||||||
* peut produire `OE`/`SS` ; elles sont hors du domaine des categories CLIENT.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class CategoryCodeSqlSlugTest extends KernelTestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Noms representatifs du domaine reel : accents, cedille, apostrophe,
|
|
||||||
* separateurs varies, parentheses, majuscules accentuees.
|
|
||||||
*
|
|
||||||
* @return iterable<string, array{string}>
|
|
||||||
*/
|
|
||||||
public static function nameProvider(): iterable
|
|
||||||
{
|
|
||||||
yield 'sans accent' => ['Distributeur'];
|
|
||||||
yield 'tiret' => ['Agro-alimentaire'];
|
|
||||||
yield 'slash' => ['Transport/Logistique'];
|
|
||||||
yield 'accent aigu' => ['Indépendant'];
|
|
||||||
yield 'apostrophe + accent' => ["L'Oréal"];
|
|
||||||
yield 'esperluette' => ['Forêt & Bûcheron'];
|
|
||||||
yield 'cedille majuscule' => ['Ça va'];
|
|
||||||
yield 'accents multiples' => ['Naïve façade'];
|
|
||||||
yield 'circonflexe' => ["Côte d'Azur"];
|
|
||||||
yield 'parentheses' => ['Zone (Sud)'];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[DataProvider('nameProvider')]
|
|
||||||
public function testSqlSlugMatchesPhpSlug(string $name): void
|
|
||||||
{
|
|
||||||
self::bootKernel();
|
|
||||||
$container = self::getContainer();
|
|
||||||
|
|
||||||
/** @var Connection $conn */
|
|
||||||
$conn = $container->get('doctrine')->getConnection();
|
|
||||||
/** @var CategoryCodeGenerator $generator */
|
|
||||||
$generator = $container->get(CategoryCodeGenerator::class);
|
|
||||||
|
|
||||||
// Evaluation pure de l'expression (aucune table requise) : le nom est
|
|
||||||
// passe en parametre lie a la place de la colonne.
|
|
||||||
$sqlSlug = $conn->fetchOne(
|
|
||||||
'SELECT '.CategoryCodeSql::slugExpression(':name'),
|
|
||||||
['name' => $name],
|
|
||||||
);
|
|
||||||
|
|
||||||
self::assertSame(
|
|
||||||
$generator->slugify($name),
|
|
||||||
$sqlSlug,
|
|
||||||
sprintf('SQL et PHP doivent produire le meme slug pour "%s".', $name),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Catalog\Api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests ERP-78 : le `code` technique stable de Category.
|
|
||||||
*
|
|
||||||
* Cas couverts :
|
|
||||||
* - POST : le code est auto-genere (slug MAJUSCULE du nom) et expose en lecture ;
|
|
||||||
* - le code est en lecture seule : un `code` envoye dans le payload est ignore
|
|
||||||
* (genere depuis le nom) ;
|
|
||||||
* - deux noms produisant le meme slug recoivent des codes distincts (suffixe).
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class CategoryCodeTest extends AbstractCatalogApiTestCase
|
|
||||||
{
|
|
||||||
public function testPostGeneratesAndExposesCode(): void
|
|
||||||
{
|
|
||||||
$type = $this->createCategoryType();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
|
|
||||||
$response = $client->request('POST', '/api/categories', [
|
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
|
||||||
'json' => [
|
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'Agro-alimentaire',
|
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
|
|
||||||
$payload = $response->toArray();
|
|
||||||
// Slug MAJUSCULE du nom, separateurs non alphanumeriques -> `_`.
|
|
||||||
self::assertSame(
|
|
||||||
strtoupper(self::TEST_CATEGORY_PREFIX).'AGRO_ALIMENTAIRE',
|
|
||||||
$payload['code'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCodeIsReadOnlyAndIgnoredFromPayload(): void
|
|
||||||
{
|
|
||||||
$type = $this->createCategoryType();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
|
|
||||||
$response = $client->request('POST', '/api/categories', [
|
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
|
||||||
'json' => [
|
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'readonly',
|
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
|
||||||
// Le client tente d'imposer un code : doit etre ignore.
|
|
||||||
'code' => 'CLIENT_FORGED',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
|
|
||||||
$payload = $response->toArray();
|
|
||||||
self::assertNotSame('CLIENT_FORGED', $payload['code']);
|
|
||||||
self::assertSame(strtoupper(self::TEST_CATEGORY_PREFIX).'READONLY', $payload['code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCollidingSlugsGetDistinctCodes(): void
|
|
||||||
{
|
|
||||||
$type = $this->createCategoryType();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
|
|
||||||
// Deux noms differents (donc autorises par uq_category_name_type_active)
|
|
||||||
// mais qui produisent le meme slug -> codes distincts (suffixe `_2`).
|
|
||||||
$first = $client->request('POST', '/api/categories', [
|
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
|
||||||
'json' => [
|
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'Agro Plus',
|
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
|
||||||
],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
$second = $client->request('POST', '/api/categories', [
|
|
||||||
'headers' => ['Content-Type' => 'application/ld+json'],
|
|
||||||
'json' => [
|
|
||||||
'name' => self::TEST_CATEGORY_PREFIX.'Agro-Plus',
|
|
||||||
'categoryType' => '/api/category_types/'.$type->getId(),
|
|
||||||
],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
self::assertNotSame($first['code'], $second['code']);
|
|
||||||
self::assertStringEndsWith('_2', (string) $second['code']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
<?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
|
|
||||||
* codees (DISTRIBUTEUR / COURTIER / SECTEUR...) sous le type unique CLIENT et
|
|
||||||
* des clients, plus un helper d'authentification admin.
|
|
||||||
*
|
|
||||||
* Refonte taxonomie ERP-78 : il n'y a plus qu'un type CLIENT ; le code metier
|
|
||||||
* vit desormais sur la Category. `createCategory($code)` est un fetch-or-create
|
|
||||||
* PAR CODE (idempotent) sous CLIENT — deux clients d'un meme test partagent ainsi
|
|
||||||
* la categorie de meme code sans violer l'index unique partiel uq_category_code.
|
|
||||||
*
|
|
||||||
* Cleanup : tearDown purge clients, categories `test_cli_cat_*` et users/roles
|
|
||||||
* `test_*`. Le type CLIENT est fetch-or-create (idempotent) et laisse en place.
|
|
||||||
* Pas de DAMA en local -> purge manuelle obligatoire.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
abstract class AbstractCommercialApiTestCase extends AbstractApiTestCase
|
|
||||||
{
|
|
||||||
protected const string TEST_CATEGORY_PREFIX = 'test_cli_cat_';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Codes pilotant les RG (RG-1.03 distributor/broker, RG-1.29 adresse) : ils
|
|
||||||
* doivent matcher exactement, donc createCategory() les fetch-or-create par
|
|
||||||
* code. Les autres codes sont traites comme de simples libelles generiques et
|
|
||||||
* produisent une categorie a code UNIQUE (cf. createCategory).
|
|
||||||
*/
|
|
||||||
private const array RG_EXACT_CODES = ['DISTRIBUTEUR', 'COURTIER'];
|
|
||||||
|
|
||||||
protected function tearDown(): void
|
|
||||||
{
|
|
||||||
$this->cleanupCommercialTestData();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createAdminClient(): Client
|
|
||||||
{
|
|
||||||
return $this->authenticatedClient('admin', 'admin');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recupere (ou cree) le type unique CLIENT (refonte ERP-78). Idempotent : la
|
|
||||||
* contrainte d'unicite sur category_type.code interdit les doublons.
|
|
||||||
*/
|
|
||||||
protected function clientCategoryType(): CategoryType
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
$existing = $em->getRepository(CategoryType::class)->findOneBy(['code' => 'CLIENT']);
|
|
||||||
if (null !== $existing) {
|
|
||||||
return $existing;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = new CategoryType();
|
|
||||||
$type->setCode('CLIENT');
|
|
||||||
$type->setLabel('Client');
|
|
||||||
$em->persist($type);
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
return $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cree une Category de test sous le type unique CLIENT (ERP-78).
|
|
||||||
*
|
|
||||||
* - Code RG (DISTRIBUTEUR / COURTIER) : fetch-or-create par code EXACT — le
|
|
||||||
* code doit matcher la regle de gestion, et l'appel repete dans un test
|
|
||||||
* renvoie la meme categorie (pas de violation de uq_category_code).
|
|
||||||
* - Autre code (SECTEUR, AUTRE, ...) : simple libelle generique -> categorie
|
|
||||||
* a code UNIQUE (suffixe aleatoire). Garantit que deux categories
|
|
||||||
* « generiques » d'un meme test sont DISTINCTES (ex: detection de
|
|
||||||
* changement de categorie dans les tests RBAC).
|
|
||||||
*/
|
|
||||||
protected function createCategory(string $code = 'SECTEUR'): Category
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
|
|
||||||
if (in_array($code, self::RG_EXACT_CODES, true)) {
|
|
||||||
$existing = $em->getRepository(Category::class)->findOneBy(['code' => $code, 'deletedAt' => null]);
|
|
||||||
if (null !== $existing) {
|
|
||||||
return $existing;
|
|
||||||
}
|
|
||||||
|
|
||||||
$effectiveCode = $code;
|
|
||||||
$name = self::TEST_CATEGORY_PREFIX.strtolower($code);
|
|
||||||
} else {
|
|
||||||
$suffix = substr(bin2hex(random_bytes(4)), 0, 8);
|
|
||||||
$effectiveCode = strtoupper($code).'_'.strtoupper($suffix);
|
|
||||||
$name = self::TEST_CATEGORY_PREFIX.strtolower($code).'_'.$suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = new Category();
|
|
||||||
$category->setName($name);
|
|
||||||
$category->setCode($effectiveCode);
|
|
||||||
$category->setCategoryType($this->clientCategoryType());
|
|
||||||
$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 du code donne
|
|
||||||
* (defaut SECTEUR — categorie generique non interdite sur adresse).
|
|
||||||
*/
|
|
||||||
protected function seedClient(string $companyName, bool $isArchived = false, string $categoryCode = '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($categoryCode));
|
|
||||||
$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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,299 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use App\Module\Sites\Domain\Entity\Site;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests fonctionnels de l'onglet Adresse.
|
|
||||||
*
|
|
||||||
* 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 :
|
|
||||||
* - RG-1.06 / RG-1.07 / RG-1.08 : exclusivite is_prospect vs
|
|
||||||
* is_delivery / is_billing ;
|
|
||||||
* - RG-1.11 : billing_email obligatoire ssi is_billing ;
|
|
||||||
* - RG-1.29 (ERP-78) : les categories de code DISTRIBUTEUR / COURTIER sont
|
|
||||||
* interdites sur une adresse (-> 422) ; toute autre categorie est acceptee.
|
|
||||||
*
|
|
||||||
* Depuis ERP-76, ces regles sont portees par des Assert\Callback sur l'entite
|
|
||||||
* ClientAddress (mirror applicatif des CHECK Postgres) : la combinaison invalide
|
|
||||||
* est donc rejetee en 422 AVANT la base, et non plus par une violation CHECK
|
|
||||||
* remontant en 500. Les CHECK BDD restent en filet de securite (non testes ici,
|
|
||||||
* inatteignables tant que les validators applicatifs passent en premier).
|
|
||||||
*
|
|
||||||
* @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 -> 422 (Assert\Callback, mirror du CHECK
|
|
||||||
* chk_client_address_prospect_exclusive).
|
|
||||||
*/
|
|
||||||
public function testProspectAddressCannotBeDelivery(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Prospect Delivery');
|
|
||||||
|
|
||||||
$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::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.06 / RG-1.08 : une adresse de prospection ne peut pas etre une
|
|
||||||
* adresse de facturation -> 422. 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');
|
|
||||||
|
|
||||||
$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::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.11 : une adresse de facturation exige un billingEmail -> 422.
|
|
||||||
*/
|
|
||||||
public function testBillingAddressRequiresBillingEmail(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Billing No Email');
|
|
||||||
|
|
||||||
$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::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.11 (cas chaine vide) : une adresse de facturation avec un billingEmail
|
|
||||||
* vide ("") doit etre rejetee en 422, et NON passer la validation pour finir
|
|
||||||
* en 500 sur le CHECK BDD. Le ClientAddressProcessor normalise "" -> null
|
|
||||||
* APRES la validation : le callback doit donc traiter "" comme « absent ».
|
|
||||||
*/
|
|
||||||
public function testBillingAddressRejectsEmptyBillingEmail(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Billing Empty Email');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'isBilling' => true,
|
|
||||||
'billingEmail' => '',
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$this->firstSiteIri()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.11 (sens inverse) : une adresse NON facturable ne peut pas porter un
|
|
||||||
* billingEmail -> 422.
|
|
||||||
*/
|
|
||||||
public function testNonBillingAddressRejectsBillingEmail(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Non Billing With Email');
|
|
||||||
|
|
||||||
$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::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.11 (sens inverse, cas chaine vide) : une adresse NON facturable avec
|
|
||||||
* un billingEmail vide ("") est ACCEPTEE (201). Le "" equivaut a « pas
|
|
||||||
* d'email » : il ne doit pas declencher la violation « email interdit hors
|
|
||||||
* facturation » (sinon un champ simplement vide serait refuse a tort).
|
|
||||||
*/
|
|
||||||
public function testNonBillingAddressAcceptsEmptyBillingEmail(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Non Billing Empty Email');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'isBilling' => false,
|
|
||||||
'billingEmail' => '',
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$this->firstSiteIri()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.29 : poster une categorie de type DISTRIBUTEUR sur une adresse -> 422
|
|
||||||
* avec violation sur le champ `categories`.
|
|
||||||
*/
|
|
||||||
public function testAddressRejectsDistributorCategory(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address Distributor Cat');
|
|
||||||
$category = $this->createCategory('DISTRIBUTEUR');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$this->firstSiteIri()],
|
|
||||||
'categories' => ['/api/categories/'.$category->getId()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
self::assertStringContainsString(
|
|
||||||
'Type de catégorie non autorisé sur une adresse.',
|
|
||||||
(string) $client->getResponse()->getContent(false),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.29 : poster une categorie de type COURTIER sur une adresse -> 422.
|
|
||||||
*/
|
|
||||||
public function testAddressRejectsBrokerCategory(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address Broker Cat');
|
|
||||||
$category = $this->createCategory('COURTIER');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$this->firstSiteIri()],
|
|
||||||
'categories' => ['/api/categories/'.$category->getId()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.29 : une categorie de type SECTEUR est autorisee sur une adresse.
|
|
||||||
*/
|
|
||||||
public function testAddressAcceptsSectorCategory(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address Sector Cat');
|
|
||||||
$category = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$this->firstSiteIri()],
|
|
||||||
'categories' => ['/api/categories/'.$category->getId()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.29 : une categorie de type AUTRE est autorisee sur une adresse.
|
|
||||||
*/
|
|
||||||
public function testAddressAcceptsOtherCategory(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address Other Cat');
|
|
||||||
$category = $this->createCategory('AUTRE');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$this->firstSiteIri()],
|
|
||||||
'categories' => ['/api/categories/'.$category->getId()],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,475 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use ApiPlatform\Symfony\Bundle\Test\Client;
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
|
||||||
use App\Module\Sites\Domain\Entity\Site;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 testPostBrokerReferencingNonBrokerReturns422(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
$notBroker = $this->seedClient('Pas Un Courtier', false, 'SECTEUR');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'companyName' => 'Bad Broker Ref',
|
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'badbroker@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
|
||||||
'broker' => '/api/clients/'.$notBroker->getId(),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// RG-1.03 (le broker doit porter la categorie de code COURTIER)
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPostValidBrokerReturns201(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
$broker = $this->seedClient('Vrai Courtier', false, 'COURTIER');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'companyName' => 'Client Avec Courtier',
|
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'okbroker@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
|
||||||
'broker' => '/api/clients/'.$broker->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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ERP-62 : la LISTE doit alimenter les colonnes « Catégories » (codes) et
|
|
||||||
* « Site(s) » (badges name + color) du Repertoire. On verifie donc que la
|
|
||||||
* collection embarque le `code` de chaque categorie et les sites agreges des
|
|
||||||
* adresses (accessoire Client::getSites()).
|
|
||||||
*/
|
|
||||||
public function testListEmbedsCategoryCodesAndAggregatedSites(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
|
|
||||||
// Client seede + une adresse rattachee a un site (fixtures Sites).
|
|
||||||
$seed = $this->seedClient('Embed List Co', false, 'DISTRIBUTEUR');
|
|
||||||
$em = $this->getEm();
|
|
||||||
$site = $em->getRepository(Site::class)->findOneBy([]);
|
|
||||||
self::assertNotNull($site, 'Aucun site seede : impossible de tester la colonne Site(s).');
|
|
||||||
|
|
||||||
$address = new ClientAddress();
|
|
||||||
$address->setClient($seed);
|
|
||||||
$address->setPostalCode('86100');
|
|
||||||
$address->setCity('Châtellerault');
|
|
||||||
$address->setStreet('1 rue du Test');
|
|
||||||
$address->addSite($site);
|
|
||||||
$em->persist($address);
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
$member = $client->request('GET', '/api/clients?pagination=false', [
|
|
||||||
'headers' => ['Accept' => self::LD],
|
|
||||||
])->toArray()['member'];
|
|
||||||
|
|
||||||
$row = null;
|
|
||||||
foreach ($member as $candidate) {
|
|
||||||
if ('EMBED LIST CO' === $candidate['companyName']) {
|
|
||||||
$row = $candidate;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self::assertNotNull($row, 'Le client seede doit figurer dans la liste.');
|
|
||||||
|
|
||||||
// Colonne « Catégories » : chaque categorie embarquee porte son code.
|
|
||||||
self::assertNotEmpty($row['categories']);
|
|
||||||
self::assertArrayHasKey('code', $row['categories'][0]);
|
|
||||||
self::assertSame('DISTRIBUTEUR', $row['categories'][0]['code']);
|
|
||||||
|
|
||||||
// Colonne « Site(s) » : sites agreges des adresses, avec name + color.
|
|
||||||
self::assertArrayHasKey('sites', $row);
|
|
||||||
self::assertNotEmpty($row['sites']);
|
|
||||||
self::assertArrayHasKey('name', $row['sites'][0]);
|
|
||||||
self::assertArrayHasKey('color', $row['sites'][0]);
|
|
||||||
self::assertSame($site->getName(), $row['sites'][0]['name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ERP-62 (drawer) : filtre Catégories multi (?categoryCode[]=A&categoryCode[]=B)
|
|
||||||
* — union des clients possedant l'un OU l'autre code.
|
|
||||||
*/
|
|
||||||
public function testListFilterByMultipleCategoryCodes(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$this->seedClient('Filtre Distrib Co', false, 'DISTRIBUTEUR');
|
|
||||||
$this->seedClient('Filtre Courtier Co', false, 'COURTIER');
|
|
||||||
$this->seedClient('Filtre Secteur Co', false, 'SECTEUR');
|
|
||||||
|
|
||||||
$names = $this->companyNames($client, '/api/clients?pagination=false&categoryCode[]=DISTRIBUTEUR&categoryCode[]=COURTIER');
|
|
||||||
|
|
||||||
self::assertContains('FILTRE DISTRIB CO', $names);
|
|
||||||
self::assertContains('FILTRE COURTIER CO', $names);
|
|
||||||
self::assertNotContains('FILTRE SECTEUR CO', $names);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ERP-62 (drawer) : filtre Sites (?siteId[]=X) — clients ayant >= 1 adresse
|
|
||||||
* rattachee au site donne.
|
|
||||||
*/
|
|
||||||
public function testListFilterBySite(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$em = $this->getEm();
|
|
||||||
|
|
||||||
$sites = $em->getRepository(Site::class)->findBy([], null, 2);
|
|
||||||
self::assertCount(2, $sites, 'Deux sites seedes requis pour ce test.');
|
|
||||||
[$siteA, $siteB] = $sites;
|
|
||||||
|
|
||||||
$onSiteA = $this->seedClient('Client Sur Site A');
|
|
||||||
$this->attachAddressWithSite($onSiteA, $siteA);
|
|
||||||
|
|
||||||
$onSiteB = $this->seedClient('Client Sur Site B');
|
|
||||||
$this->attachAddressWithSite($onSiteB, $siteB);
|
|
||||||
|
|
||||||
$names = $this->companyNames($client, '/api/clients?pagination=false&siteId[]='.$siteA->getId());
|
|
||||||
|
|
||||||
self::assertContains('CLIENT SUR SITE A', $names);
|
|
||||||
self::assertNotContains('CLIENT SUR SITE B', $names);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ERP-62 (drawer) : statut « Archivés » (?archivedOnly=true) — uniquement les
|
|
||||||
* archives, contrairement a includeArchived qui ajoute les archives aux actifs.
|
|
||||||
*/
|
|
||||||
public function testListArchivedOnlyReturnsOnlyArchived(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$this->seedClient('Actif Visible Co');
|
|
||||||
$this->seedClient('Archive Visible Co', true);
|
|
||||||
|
|
||||||
$names = $this->companyNames($client, '/api/clients?pagination=false&archivedOnly=true');
|
|
||||||
|
|
||||||
self::assertContains('ARCHIVE VISIBLE CO', $names);
|
|
||||||
self::assertNotContains('ACTIF VISIBLE CO', $names);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rattache une adresse minimale portant un site au client (les sites vivent
|
|
||||||
* sur les adresses, RG-1.10).
|
|
||||||
*/
|
|
||||||
private function attachAddressWithSite(ClientEntity $client, Site $site): void
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
$address = new ClientAddress();
|
|
||||||
$address->setClient($client);
|
|
||||||
$address->setPostalCode('86100');
|
|
||||||
$address->setCity('Châtellerault');
|
|
||||||
$address->setStreet('1 rue du Test');
|
|
||||||
$address->addSite($site);
|
|
||||||
$em->persist($address);
|
|
||||||
$em->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper : recupere les companyName d'une collection /api/clients.
|
|
||||||
*
|
|
||||||
* @return list<string>
|
|
||||||
*/
|
|
||||||
private function companyNames(Client $client, string $url): array
|
|
||||||
{
|
|
||||||
$members = $client->request('GET', $url, [
|
|
||||||
'headers' => ['Accept' => self::LD],
|
|
||||||
])->toArray()['member'];
|
|
||||||
|
|
||||||
return array_map(static fn (array $c): string => $c['companyName'], $members);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
<?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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests fonctionnels de l'export XLSX du repertoire clients (M1, § 4.6).
|
|
||||||
*
|
|
||||||
* Couvre : reponse 200 (Content-Type + Content-Disposition), exclusion des
|
|
||||||
* archives par defaut, respect des filtres ?search / ?categoryType, gating de
|
|
||||||
* la colonne SIREN selon commercial.clients.accounting.view, 403 sans
|
|
||||||
* commercial.clients.view, 401 anonyme.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientExportControllerTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string XLSX_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
||||||
private const string EXPORT_URL = '/api/clients/export.xlsx';
|
|
||||||
|
|
||||||
public function testExportReturnsXlsxResponseWithAttachmentFilename(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$this->seedClient('Export Alpha');
|
|
||||||
|
|
||||||
$response = $client->request('GET', self::EXPORT_URL);
|
|
||||||
|
|
||||||
self::assertResponseIsSuccessful();
|
|
||||||
$headers = $response->getHeaders(false);
|
|
||||||
self::assertStringContainsString(self::XLSX_MIME, $headers['content-type'][0] ?? '');
|
|
||||||
|
|
||||||
$disposition = $headers['content-disposition'][0] ?? '';
|
|
||||||
self::assertStringContainsString('attachment; filename="repertoire-clients-', $disposition);
|
|
||||||
self::assertMatchesRegularExpression(
|
|
||||||
'/filename="repertoire-clients-\d{8}\.xlsx"/',
|
|
||||||
$disposition,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Le binaire est un XLSX relisible dont la 1re ligne porte les en-tetes.
|
|
||||||
$grid = $this->gridFromResponse($response->getContent());
|
|
||||||
$headers = $grid[0];
|
|
||||||
self::assertSame('Nom entreprise', $headers[0]);
|
|
||||||
self::assertContains('Catégories', $headers);
|
|
||||||
self::assertContains('Sites', $headers);
|
|
||||||
self::assertContains('Date de création', $headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testExportExcludesArchivedByDefault(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$this->seedClient('Active One');
|
|
||||||
$this->seedClient('Archived One', true);
|
|
||||||
|
|
||||||
$names = $this->companyNames($client->request('GET', self::EXPORT_URL)->getContent());
|
|
||||||
|
|
||||||
self::assertContains('ACTIVE ONE', $names);
|
|
||||||
self::assertNotContains('ARCHIVED ONE', $names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testExportRespectsSearchFilter(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$this->seedClient('Searchable Alpha');
|
|
||||||
$this->seedClient('Other Beta');
|
|
||||||
|
|
||||||
$names = $this->companyNames(
|
|
||||||
$client->request('GET', self::EXPORT_URL.'?search=alpha')->getContent(),
|
|
||||||
);
|
|
||||||
|
|
||||||
self::assertContains('SEARCHABLE ALPHA', $names);
|
|
||||||
self::assertNotContains('OTHER BETA', $names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testExportRespectsCategoryCodeFilter(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$this->seedClient('Distrib Co', false, 'DISTRIBUTEUR');
|
|
||||||
$this->seedClient('Secteur Co', false, 'SECTEUR');
|
|
||||||
|
|
||||||
$names = $this->companyNames(
|
|
||||||
$client->request('GET', self::EXPORT_URL.'?categoryCode=DISTRIBUTEUR')->getContent(),
|
|
||||||
);
|
|
||||||
|
|
||||||
self::assertContains('DISTRIB CO', $names);
|
|
||||||
self::assertNotContains('SECTEUR CO', $names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSirenColumnPresentWithAccountingView(): void
|
|
||||||
{
|
|
||||||
// L'admin bypass le RBAC : il a donc accounting.view -> colonne SIREN.
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Siren Co');
|
|
||||||
$em = $this->getEm();
|
|
||||||
$seed->setSiren('123456789');
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
$grid = $this->gridFromResponse($client->request('GET', self::EXPORT_URL)->getContent());
|
|
||||||
|
|
||||||
self::assertContains('SIREN', $grid[0]);
|
|
||||||
self::assertStringContainsString('123456789', $this->flatten($grid));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSirenColumnAbsentWithoutAccountingView(): void
|
|
||||||
{
|
|
||||||
// Seed via admin, puis relecture par un user qui n'a QUE clients.view.
|
|
||||||
$admin = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('No Siren Co');
|
|
||||||
$em = $this->getEm();
|
|
||||||
$seed->setSiren('987654321');
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
$creds = $this->createUserWithPermission('commercial.clients.view');
|
|
||||||
$viewer = $this->authenticatedClient($creds['username'], $creds['password']);
|
|
||||||
|
|
||||||
$grid = $this->gridFromResponse($viewer->request('GET', self::EXPORT_URL)->getContent());
|
|
||||||
|
|
||||||
self::assertNotContains('SIREN', $grid[0]);
|
|
||||||
self::assertStringNotContainsString('987654321', $this->flatten($grid));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testForbiddenWithoutClientsViewPermission(): void
|
|
||||||
{
|
|
||||||
$creds = $this->createUserWithPermission('core.users.view');
|
|
||||||
$client = $this->authenticatedClient($creds['username'], $creds['password']);
|
|
||||||
|
|
||||||
$client->request('GET', self::EXPORT_URL);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUnauthorizedWhenAnonymous(): void
|
|
||||||
{
|
|
||||||
$client = self::createClient();
|
|
||||||
$client->request('GET', self::EXPORT_URL);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Relit le binaire XLSX d'une reponse et renvoie la grille de cellules.
|
|
||||||
*
|
|
||||||
* @return array<int, array<int, mixed>>
|
|
||||||
*/
|
|
||||||
private function gridFromResponse(string $binary): array
|
|
||||||
{
|
|
||||||
$tmp = tempnam(sys_get_temp_dir(), 'xlsx_export_test_');
|
|
||||||
self::assertIsString($tmp);
|
|
||||||
file_put_contents($tmp, $binary);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return IOFactory::load($tmp)->getActiveSheet()->toArray();
|
|
||||||
} finally {
|
|
||||||
@unlink($tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extrait la colonne « Nom entreprise » (1re colonne) des lignes de donnees.
|
|
||||||
*
|
|
||||||
* @return list<string>
|
|
||||||
*/
|
|
||||||
private function companyNames(string $binary): array
|
|
||||||
{
|
|
||||||
$grid = $this->gridFromResponse($binary);
|
|
||||||
$rows = array_slice($grid, 1); // saute l'en-tete
|
|
||||||
|
|
||||||
return array_values(array_map(static fn (array $row): string => (string) ($row[0] ?? ''), $rows));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aplatit toute la grille en une chaine, pour les assertions de presence.
|
|
||||||
*
|
|
||||||
* @param array<int, array<int, mixed>> $grid
|
|
||||||
*/
|
|
||||||
private function flatten(array $grid): string
|
|
||||||
{
|
|
||||||
return implode('|', array_map(
|
|
||||||
static fn (array $row): string => implode('|', array_map(static fn ($cell): string => (string) $cell, $row)),
|
|
||||||
$grid,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests fonctionnels du formulaire principal — combler les trous (ERP-60).
|
|
||||||
*
|
|
||||||
* RG-1.01 (prenom OU nom obligatoire) et RG-1.03 (distributor/broker exclusifs
|
|
||||||
* + type de categorie) sont DEJA couverts par ClientApiTest (ERP-55) : on ne les
|
|
||||||
* reduplique pas ici. Ce fichier ne couvre que RG-1.02 (telephone secondaire),
|
|
||||||
* non encore testee.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientFormulaireMainTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.02 : le telephone secondaire est optionnel mais persiste (2 colonnes
|
|
||||||
* distinctes). Verifie aussi la normalisation chiffres-seuls (RG-1.20) sur
|
|
||||||
* la colonne secondaire.
|
|
||||||
*/
|
|
||||||
public function testPostPersistsSecondaryPhoneNormalized(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
$data = $client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'companyName' => 'Two Phones SARL',
|
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '06.12.34.56.78',
|
|
||||||
'phoneSecondary' => '05 49 00 11 22',
|
|
||||||
'email' => 'twophones@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
|
||||||
],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
self::assertSame('0612345678', $data['phonePrimary']);
|
|
||||||
self::assertSame('0549001122', $data['phoneSecondary']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.02 : maximum 2 telephones — le modele n'expose que phonePrimary et
|
|
||||||
* phoneSecondary. Un eventuel 3e champ envoye par un appel API direct est
|
|
||||||
* ignore (aucune 3e colonne), il ne peut donc pas creer un troisieme numero.
|
|
||||||
*/
|
|
||||||
public function testThirdPhoneFieldIsIgnored(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
$data = $client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'companyName' => 'Third Phone SARL',
|
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0612345678',
|
|
||||||
'phoneSecondary' => '0549001122',
|
|
||||||
'phoneTertiary' => '0700000000',
|
|
||||||
'email' => 'thirdphone@test.fr',
|
|
||||||
'categories' => ['/api/categories/'.$cat->getId()],
|
|
||||||
],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
// Le champ inconnu est ignore par le denormaliseur : il n'apparait pas
|
|
||||||
// dans la representation et n'a pas ete persiste.
|
|
||||||
self::assertArrayNotHasKey('phoneTertiary', $data);
|
|
||||||
|
|
||||||
// Confirmation cote base : seules les 2 colonnes telephone existent.
|
|
||||||
$persisted = $this->getEm()->getRepository(ClientEntity::class)->find($data['id']);
|
|
||||||
self::assertNotNull($persisted);
|
|
||||||
self::assertSame('0612345678', $persisted->getPhonePrimary());
|
|
||||||
self::assertSame('0549001122', $persisted->getPhoneSecondary());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests de structure / migration M1 (ERP-60).
|
|
||||||
*
|
|
||||||
* Verifie la decision Q4 (29/05/2026) au niveau du schema Postgres :
|
|
||||||
* - l'unique index partiel fonctionnel uq_client_company_name_active existe
|
|
||||||
* (un seul, sur LOWER(company_name), partiel sur les actifs non archives /
|
|
||||||
* non supprimes) — seule unicite metier conservee (RG-1.16) ;
|
|
||||||
* - les anciens index uq_client_siren_active (RG-1.15) et uq_client_email_active
|
|
||||||
* (RG-1.17) ont ete supprimes / ne sont jamais crees.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientMigrationTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
public function testCompanyNameActivePartialIndexExistsExactlyOnce(): void
|
|
||||||
{
|
|
||||||
$rows = $this->clientIndexes();
|
|
||||||
|
|
||||||
$companyNameIndexes = array_filter(
|
|
||||||
$rows,
|
|
||||||
static fn (array $r): bool => 'uq_client_company_name_active' === $r['indexname'],
|
|
||||||
);
|
|
||||||
|
|
||||||
self::assertCount(
|
|
||||||
1,
|
|
||||||
$companyNameIndexes,
|
|
||||||
'Il doit exister exactement UN index uq_client_company_name_active.',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Confirme la nature fonctionnelle (LOWER) + partielle (WHERE) de l'index.
|
|
||||||
// Postgres serialise l'expression sous la forme `lower((company_name)::text)`,
|
|
||||||
// d'ou des verifications de sous-chaines distinctes.
|
|
||||||
$def = strtolower((string) array_values($companyNameIndexes)[0]['indexdef']);
|
|
||||||
self::assertStringContainsString('unique', $def);
|
|
||||||
self::assertStringContainsString('lower', $def);
|
|
||||||
self::assertStringContainsString('company_name', $def);
|
|
||||||
self::assertStringContainsString('where', $def, 'L\'index doit etre partiel (clause WHERE sur les actifs).');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNoSirenOrEmailUniqueIndex(): void
|
|
||||||
{
|
|
||||||
$names = array_map(static fn (array $r): string => $r['indexname'], $this->clientIndexes());
|
|
||||||
|
|
||||||
// RG-1.15 / RG-1.17 supprimees (Q4) : aucun index unique siren / email.
|
|
||||||
self::assertNotContains('uq_client_siren_active', $names);
|
|
||||||
self::assertNotContains('uq_client_email_active', $names);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return list<array{indexname: string, indexdef: string}>
|
|
||||||
*/
|
|
||||||
private function clientIndexes(): array
|
|
||||||
{
|
|
||||||
self::bootKernel();
|
|
||||||
|
|
||||||
/** @var list<array{indexname: string, indexdef: string}> $rows */
|
|
||||||
return $this->getEm()->getConnection()->fetchAllAssociative(
|
|
||||||
"SELECT indexname, indexdef FROM pg_indexes WHERE schemaname = 'public' AND tablename = 'client'",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test fonctionnel du mode strict PATCH multi-groupes (RG-1.28) — ERP-60.
|
|
||||||
*
|
|
||||||
* Le cas est deja couvert en unitaire (ClientProcessorTest) ; on en ajoute la
|
|
||||||
* preuve fonctionnelle HTTP, SANS dependre d'un role metier : un utilisateur
|
|
||||||
* portant `commercial.clients.manage` mais PAS `commercial.clients.accounting.manage`
|
|
||||||
* qui envoie un PATCH melant un champ principal (companyName) et un champ
|
|
||||||
* comptable (siren) recoit un 403 sur l'ENSEMBLE du payload — aucun champ n'est
|
|
||||||
* applique (pas de filtrage silencieux).
|
|
||||||
*
|
|
||||||
* ⚠ La matrice differenciee par role metier (Bureau / Compta / Commerciale) est
|
|
||||||
* DELEGUEE a ERP-74 (#493). Ici on n'utilise qu'un user mono-permission.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientPatchStrictTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string MERGE = 'application/merge-patch+json';
|
|
||||||
|
|
||||||
public function testMixedGroupsPatchWithoutAccountingPermissionIsForbidden(): void
|
|
||||||
{
|
|
||||||
$seed = $this->seedClient('Strict Mix');
|
|
||||||
$credentials = $this->createUserWithPermission('commercial.clients.manage');
|
|
||||||
$client = $this->authenticatedClient($credentials['username'], $credentials['password']);
|
|
||||||
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => [
|
|
||||||
'companyName' => 'Renamed Strict',
|
|
||||||
'siren' => '123456789',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// RG-1.28 : 403 strict (le champ comptable siren exige accounting.manage).
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
// Aucun champ applique : le companyName d'origine est intact.
|
|
||||||
$em = $this->getEm();
|
|
||||||
$em->clear();
|
|
||||||
$reloaded = $em->getRepository(ClientEntity::class)->find($seed->getId());
|
|
||||||
self::assertNotNull($reloaded);
|
|
||||||
self::assertSame('STRICT MIX', $reloaded->getCompanyName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,299 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use ApiPlatform\Symfony\Bundle\Test\Client;
|
|
||||||
use App\Module\Core\Infrastructure\DataFixtures\RbacDemoFixtures;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Matrice RBAC complete du repertoire clients par role metier (spec-back M1
|
|
||||||
* § 2.7 + cahier ERP-74). Valide 200/403 par verbe et par onglet pour
|
|
||||||
* bureau / compta / commerciale / usine, plus le durcissement RG-1.04
|
|
||||||
* (Commerciale) au POST.
|
|
||||||
*
|
|
||||||
* Les comptes demo et la matrice sont seedes via la commande reelle
|
|
||||||
* `app:seed-rbac --with-demo-users` (le MEME chemin qu'en recette), idempotente.
|
|
||||||
* Pre-requis du run : `app:sync-permissions` a tourne (cf. make test-db-setup).
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientRBACMatrixTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
private const string MERGE = 'application/merge-patch+json';
|
|
||||||
private const string PWD = RbacDemoFixtures::DEMO_PASSWORD;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
// Seed idempotent via la commande applicative (roles + matrice § 2.7 +
|
|
||||||
// comptes demo). Exerce aussi le chemin de code prod.
|
|
||||||
self::bootKernel();
|
|
||||||
$application = new Application(self::$kernel);
|
|
||||||
$application->setAutoExit(false);
|
|
||||||
$exit = $application->run(
|
|
||||||
new ArrayInput([
|
|
||||||
'command' => 'app:seed-rbac',
|
|
||||||
'--with-demo-users' => true,
|
|
||||||
'--password' => self::PWD,
|
|
||||||
]),
|
|
||||||
new NullOutput(),
|
|
||||||
);
|
|
||||||
self::assertSame(
|
|
||||||
0,
|
|
||||||
$exit,
|
|
||||||
'app:seed-rbac a echoue : les permissions commercial.clients.* sont-elles synchronisees (app:sync-permissions) ?',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Liberer le kernel pour que authenticatedClient()/createClient() reparte propre.
|
|
||||||
self::ensureKernelShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUsineIsForbiddenEverywhere(): void
|
|
||||||
{
|
|
||||||
$seed = $this->seedClient('Usine Target');
|
|
||||||
$client = $this->authAs('usine');
|
|
||||||
|
|
||||||
// Aucune permission : 403 sur tous les verbes.
|
|
||||||
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
$client->request('GET', '/api/clients/'.$seed->getId(), ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('Usine Post'),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['companyName' => 'Renamed By Usine'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBureauHasViewAndManageButNoAccountingNoArchive(): void
|
|
||||||
{
|
|
||||||
$seed = $this->seedClient('Bureau Target');
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
$client = $this->authAs('bureau');
|
|
||||||
|
|
||||||
// view
|
|
||||||
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
|
|
||||||
// manage : creation OK
|
|
||||||
$client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('Bureau Created', $cat->getId()),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
|
|
||||||
// manage : edition onglet principal OK
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['companyName' => 'Bureau Renamed'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
|
|
||||||
// PAS accounting : edition onglet Comptabilite refusee
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['siren' => '123456789'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
// PAS archive : archivage refuse
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['isArchived' => true],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testComptaCanEditAccountingOnly(): void
|
|
||||||
{
|
|
||||||
$seed = $this->seedClient('Compta Target');
|
|
||||||
$client = $this->authAs('compta');
|
|
||||||
|
|
||||||
// view
|
|
||||||
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
|
|
||||||
// PAS manage : creation refusee
|
|
||||||
$client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('Compta Post'),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
// accounting.manage : edition onglet Comptabilite OK
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['siren' => '123456789'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
|
|
||||||
// PAS manage : edition onglet principal refusee (guardManage)
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['companyName' => 'Compta Renamed'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
// PAS manage : edition onglet Information refusee (guardManage)
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['description' => 'Une description'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
// PAS archive : archivage refuse
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['isArchived' => true],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCommercialeHasViewAndManageButNoAccountingNoArchive(): void
|
|
||||||
{
|
|
||||||
$seed = $this->seedClient('Commerciale Target');
|
|
||||||
$client = $this->authAs('commerciale');
|
|
||||||
|
|
||||||
// view
|
|
||||||
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
|
|
||||||
// manage : la creation passe la security d'operation (pas un 403 comme
|
|
||||||
// Compta) mais bute sur RG-1.04 (onglet Information incomplet) -> 422.
|
|
||||||
// C'est la preuve que Commerciale porte `manage` (sinon 403).
|
|
||||||
$client->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('Commerciale Post'),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
|
|
||||||
// PAS accounting : edition onglet Comptabilite refusee
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['siren' => '123456789'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
// PAS archive : archivage refuse
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['isArchived' => true],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRG104CommercialePostIncompleteIs422AdminIs201(): void
|
|
||||||
{
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
|
|
||||||
// RG-1.04 durcie : Commerciale POST sans onglet Information complet -> 422.
|
|
||||||
$commerciale = $this->authAs('commerciale');
|
|
||||||
$commerciale->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('RG104 Commerciale', $cat->getId()),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
|
|
||||||
// Meme payload par un Admin (non gate par RG-1.04) -> 201.
|
|
||||||
$admin = $this->createAdminClient();
|
|
||||||
$admin->request('POST', '/api/clients', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => $this->validMainPayload('RG104 Admin', $cat->getId()),
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testComptaFullRepresentationPatchWithUnchangedCategoriesIsNotForbidden(): void
|
|
||||||
{
|
|
||||||
// FIX review MR #40 : un Compta (accounting.manage, PAS manage) faisant un
|
|
||||||
// PATCH representation complete de l'onglet Comptabilite et reincluant ses
|
|
||||||
// categories INCHANGEES ne doit PAS prendre de 403. guardManage compare
|
|
||||||
// desormais les categories par valeur (et non par simple presence) : seul
|
|
||||||
// l'onglet Comptabilite change ici -> 200.
|
|
||||||
$seed = $this->seedClient('Compta Cat Unchanged');
|
|
||||||
$category = $seed->getCategories()->first();
|
|
||||||
self::assertNotFalse($category);
|
|
||||||
$catId = $category->getId();
|
|
||||||
$client = $this->authAs('compta');
|
|
||||||
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => [
|
|
||||||
'siren' => '123456789',
|
|
||||||
'categories' => ['/api/categories/'.$catId],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testComptaChangingCategoriesIsForbidden(): void
|
|
||||||
{
|
|
||||||
// Non-regression : si le Compta change REELLEMENT l'ensemble des
|
|
||||||
// categories (sans manage) -> 403 via guardManage. La comparaison par
|
|
||||||
// valeur detecte bien le changement.
|
|
||||||
$seed = $this->seedClient('Compta Cat Change');
|
|
||||||
$newCat = $this->createCategory('SECTEUR');
|
|
||||||
$client = $this->authAs('compta');
|
|
||||||
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['categories' => ['/api/categories/'.$newCat->getId()]],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBureauChangingCategoriesIsAllowed(): void
|
|
||||||
{
|
|
||||||
// Non-regression : un role porteur de `manage` (Bureau) peut changer les
|
|
||||||
// categories -> 200.
|
|
||||||
$seed = $this->seedClient('Bureau Cat Change');
|
|
||||||
$newCat = $this->createCategory('SECTEUR');
|
|
||||||
$client = $this->authAs('bureau');
|
|
||||||
|
|
||||||
$client->request('PATCH', '/api/clients/'.$seed->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['categories' => ['/api/categories/'.$newCat->getId()]],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function authAs(string $role): Client
|
|
||||||
{
|
|
||||||
return $this->authenticatedClient($role, self::PWD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Payload minimal valide de l'onglet principal (RG-1.01 : un nom de contact ;
|
|
||||||
* une categorie SECTEUR). Si $categoryId est null, une categorie est creee a
|
|
||||||
* la volee.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
private function validMainPayload(string $companyName, ?int $categoryId = null): array
|
|
||||||
{
|
|
||||||
$categoryId ??= $this->createCategory('SECTEUR')->getId();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'companyName' => $companyName,
|
|
||||||
'firstName' => 'Jean',
|
|
||||||
'phonePrimary' => '0612345678',
|
|
||||||
'email' => strtolower(str_replace(' ', '', $companyName)).'@matrix.test',
|
|
||||||
'categories' => ['/api/categories/'.$categoryId],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests de securite GENERIQUE de /api/clients (ERP-60).
|
|
||||||
*
|
|
||||||
* Couvre les garde-fous non dependants des roles metier :
|
|
||||||
* - 401 si requete anonyme (firewall JWT) ;
|
|
||||||
* - 403 si l'utilisateur authentifie ne porte pas `commercial.clients.view`.
|
|
||||||
*
|
|
||||||
* ⚠ La matrice RBAC differenciee par role metier (bureau / compta / commerciale
|
|
||||||
* / usine) et le test fonctionnel RG-1.04 sont DELEGUES a ERP-74 (#493) : ils
|
|
||||||
* exigent les roles seedes apres le merge de la stack. NE PAS les ajouter ici.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientSecurityTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
|
|
||||||
public function testAnonymousGetCollectionReturns401(): void
|
|
||||||
{
|
|
||||||
$client = self::createClient();
|
|
||||||
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAnonymousGetItemReturns401(): void
|
|
||||||
{
|
|
||||||
$seed = $this->seedClient('Anon Item');
|
|
||||||
$client = self::createClient();
|
|
||||||
|
|
||||||
$client->request('GET', '/api/clients/'.$seed->getId(), ['headers' => ['Accept' => self::LD]]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testForbiddenWithoutClientsViewPermission(): void
|
|
||||||
{
|
|
||||||
// User authentifie portant une permission SANS rapport avec les clients.
|
|
||||||
$seed = $this->seedClient('Forbidden Target');
|
|
||||||
$credentials = $this->createUserWithPermission('core.users.view');
|
|
||||||
$client = $this->authenticatedClient($credentials['username'], $credentials['password']);
|
|
||||||
|
|
||||||
// Collection.
|
|
||||||
$client->request('GET', '/api/clients', ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
// Detail.
|
|
||||||
$client->request('GET', '/api/clients/'.$seed->getId(), ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientAddress;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientContact;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientRib;
|
|
||||||
use App\Module\Sites\Domain\Entity\Site;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests anti-regression du CONTRAT DE SERIALISATION du repertoire clients (M1).
|
|
||||||
*
|
|
||||||
* Captures reelles du 02/06/2026 (cf. docs/specs/M2-suppliers/spec-back.md
|
|
||||||
* § 4.0.ter) ayant revele 4 bugs silencieux du contrat (aucune erreur levee) :
|
|
||||||
* - #81 : booleens d'adresse (isProspect/isDelivery/isBilling) absents du JSON
|
|
||||||
* (Groups sur la propriete `isX`, getter `isX()` derivant l'attribut `x`).
|
|
||||||
* - #80 : fuite RIB (IBAN/BIC) vers un user sans accounting.view.
|
|
||||||
* - #82 : code/libelle de Category et Site non embarques (stub IRI nu).
|
|
||||||
* - enveloppe AP4 : member/totalItems/view sans prefixe `hydra:`, archives exclus.
|
|
||||||
*
|
|
||||||
* REGLE D'OR : ces tests assertent sur le CORPS JSON reel, jamais sur les
|
|
||||||
* annotations. Toute regression de groupe de serialisation casse ici.
|
|
||||||
*
|
|
||||||
* Limite connue (dependance module Sites) : l'entite Site ne porte PAS de champ
|
|
||||||
* `code` (ni SiteInterface) — son libelle est `name`. Les « codes 86/17/82 » de
|
|
||||||
* la spec M2 correspondent en realite au prefixe du code postal des 3 sites
|
|
||||||
* fixtures (86100/17400/82400). On asserte donc le libelle `name` du site
|
|
||||||
* embarque ; l'ajout d'un `Site.code` reste un ticket cote module Sites.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientSerializationContractTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
private const string VALID_IBAN = 'FR1420041010050500013M02606';
|
|
||||||
private const string VALID_BIC = 'BNPAFRPPXXX';
|
|
||||||
|
|
||||||
// === #81 — Booleens d'adresse presents dans le JSON ===
|
|
||||||
|
|
||||||
public function testAddressBooleansArePresentInDetail(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
|
|
||||||
$seed = $this->seedCompleteClient('Bool Addr Co');
|
|
||||||
$id = $seed->getId();
|
|
||||||
|
|
||||||
$http = $this->createAdminClient();
|
|
||||||
$data = $http->request('GET', '/api/clients/'.$id, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
|
|
||||||
self::assertArrayHasKey('addresses', $data);
|
|
||||||
self::assertNotEmpty($data['addresses']);
|
|
||||||
$address = $data['addresses'][0];
|
|
||||||
|
|
||||||
// Le bug droppait TOTALEMENT ces cles. Apres correctif (Groups +
|
|
||||||
// SerializedName sur le getter), elles sont presentes ET typees bool.
|
|
||||||
self::assertArrayHasKey('isProspect', $address);
|
|
||||||
self::assertArrayHasKey('isDelivery', $address);
|
|
||||||
self::assertArrayHasKey('isBilling', $address);
|
|
||||||
|
|
||||||
// L'adresse seedee est livraison + facturation (prospect exclusif, RG-1.06).
|
|
||||||
// Prouve qu'un booleen `true` est bien serialise (le bug masquait meme les true).
|
|
||||||
self::assertFalse($address['isProspect']);
|
|
||||||
self::assertTrue($address['isDelivery']);
|
|
||||||
self::assertTrue($address['isBilling']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === #80 — Gating des RIB par accounting.view ===
|
|
||||||
|
|
||||||
public function testRibsPresentForAdminWithAccountingView(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
|
|
||||||
$seed = $this->seedCompleteClient('Rib Admin Co');
|
|
||||||
$id = $seed->getId();
|
|
||||||
|
|
||||||
$http = $this->createAdminClient();
|
|
||||||
$data = $http->request('GET', '/api/clients/'.$id, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
|
|
||||||
// Admin bypass RBAC -> accounting.view -> RIB embarques (label/bic/iban).
|
|
||||||
self::assertArrayHasKey('ribs', $data);
|
|
||||||
self::assertNotEmpty($data['ribs']);
|
|
||||||
self::assertSame('Compte principal', $data['ribs'][0]['label']);
|
|
||||||
self::assertSame(self::VALID_IBAN, $data['ribs'][0]['iban']);
|
|
||||||
self::assertSame(self::VALID_BIC, $data['ribs'][0]['bic']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRibsAbsentForUserWithoutAccountingView(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
|
|
||||||
$seed = $this->seedCompleteClient('Rib Commerciale Co');
|
|
||||||
$id = $seed->getId();
|
|
||||||
|
|
||||||
// Commerciale : commercial.clients.view SANS accounting.view.
|
|
||||||
$creds = $this->createUserWithPermission('commercial.clients.view');
|
|
||||||
$http = $this->authenticatedClient($creds['username'], $creds['password']);
|
|
||||||
|
|
||||||
$data = $http->request('GET', '/api/clients/'.$id, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
|
|
||||||
// La cle `ribs` est ABSENTE (pas null) : le groupe client:read:accounting
|
|
||||||
// n'est pas ajoute au contexte -> getRibs() jamais serialise. Fin de la
|
|
||||||
// fuite IBAN/BIC.
|
|
||||||
self::assertArrayNotHasKey('ribs', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === #80.bis — Gating par OMISSION des scalaires comptables ===
|
|
||||||
|
|
||||||
public function testAccountingScalarsGatedByOmission(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
|
|
||||||
$seed = $this->seedCompleteClient('Compta Gating Co');
|
|
||||||
$id = $seed->getId();
|
|
||||||
|
|
||||||
// Admin : scalaires comptables presents.
|
|
||||||
$admin = $this->createAdminClient();
|
|
||||||
$adminData = $admin->request('GET', '/api/clients/'.$id, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
self::assertArrayHasKey('siren', $adminData);
|
|
||||||
self::assertSame('123456789', $adminData['siren']);
|
|
||||||
self::assertArrayHasKey('accountNumber', $adminData);
|
|
||||||
|
|
||||||
// Commerciale : scalaires comptables ABSENTS (omission, pas null).
|
|
||||||
$creds = $this->createUserWithPermission('commercial.clients.view');
|
|
||||||
$http = $this->authenticatedClient($creds['username'], $creds['password']);
|
|
||||||
$data = $http->request('GET', '/api/clients/'.$id, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
|
|
||||||
self::assertArrayNotHasKey('siren', $data);
|
|
||||||
self::assertArrayNotHasKey('accountNumber', $data);
|
|
||||||
self::assertArrayNotHasKey('nTva', $data);
|
|
||||||
self::assertArrayNotHasKey('ribs', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === #82 — Embed code/libelle des Category et Site ===
|
|
||||||
|
|
||||||
public function testCategoriesEmbedCodeAndLabel(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
|
|
||||||
$seed = $this->seedCompleteClient('Embed Cat Co');
|
|
||||||
$id = $seed->getId();
|
|
||||||
|
|
||||||
$http = $this->createAdminClient();
|
|
||||||
$data = $http->request('GET', '/api/clients/'.$id, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
|
|
||||||
self::assertNotEmpty($data['categories']);
|
|
||||||
$category = $data['categories'][0];
|
|
||||||
// Avant correctif : seuls @id/@type/createdAt/updatedAt (category:read
|
|
||||||
// absent du contexte). Apres : code + name (libelle) embarques.
|
|
||||||
self::assertArrayHasKey('code', $category);
|
|
||||||
self::assertArrayHasKey('name', $category);
|
|
||||||
self::assertNotSame('', $category['code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAddressSitesEmbedLabel(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
|
|
||||||
$seed = $this->seedCompleteClient('Embed Site Co');
|
|
||||||
$id = $seed->getId();
|
|
||||||
|
|
||||||
$http = $this->createAdminClient();
|
|
||||||
$data = $http->request('GET', '/api/clients/'.$id, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
|
|
||||||
$address = $data['addresses'][0];
|
|
||||||
self::assertArrayHasKey('sites', $address);
|
|
||||||
self::assertNotEmpty($address['sites']);
|
|
||||||
// Site embarque : libelle `name` present (avant : stub @id/@type nu).
|
|
||||||
// NB : Site n'a pas de champ `code` (cf. note de classe) -> on asserte name.
|
|
||||||
self::assertArrayHasKey('name', $address['sites'][0]);
|
|
||||||
self::assertNotSame('', $address['sites'][0]['name']);
|
|
||||||
|
|
||||||
// L'adresse seedee est multi-sites : preuve que l'embed parcourt la collection.
|
|
||||||
self::assertGreaterThanOrEqual(2, count($address['sites']));
|
|
||||||
|
|
||||||
// Categories d'adresse : code embarque (category:read dans le contexte).
|
|
||||||
self::assertArrayHasKey('categories', $address);
|
|
||||||
self::assertNotEmpty($address['categories']);
|
|
||||||
self::assertArrayHasKey('code', $address['categories'][0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Enveloppe AP4 (sans prefixe hydra:) + exclusion des archives ===
|
|
||||||
|
|
||||||
public function testCollectionEnvelopeShapeAndArchivedExcluded(): void
|
|
||||||
{
|
|
||||||
$http = $this->createAdminClient();
|
|
||||||
$prefix = 'EnvCheck'.substr(bin2hex(random_bytes(3)), 0, 6);
|
|
||||||
|
|
||||||
$this->seedClient($prefix.' Active');
|
|
||||||
$this->seedClient($prefix.' Archived', true);
|
|
||||||
|
|
||||||
// Liste par defaut filtree sur le prefixe : enveloppe member/totalItems
|
|
||||||
// sans prefixe hydra:, archive EXCLU du totalItems (RG-1.24).
|
|
||||||
$default = $http->request('GET', '/api/clients?search='.$prefix, ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
|
|
||||||
self::assertArrayHasKey('member', $default);
|
|
||||||
self::assertArrayHasKey('totalItems', $default);
|
|
||||||
self::assertArrayNotHasKey('hydra:member', $default);
|
|
||||||
self::assertArrayNotHasKey('hydra:totalItems', $default);
|
|
||||||
self::assertSame(1, $default['totalItems'], 'Archive exclu du totalItems par defaut.');
|
|
||||||
|
|
||||||
// includeArchived : l'archive reintegre le total.
|
|
||||||
$all = $http->request('GET', '/api/clients?search='.$prefix.'&includeArchived=true', ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
self::assertSame(2, $all['totalItems']);
|
|
||||||
|
|
||||||
// `view` (PartialCollectionView) sans prefixe hydra: : force le multi-page
|
|
||||||
// via itemsPerPage=1 sur les 2 resultats archives inclus.
|
|
||||||
$paged = $http->request('GET', '/api/clients?search='.$prefix.'&includeArchived=true&itemsPerPage=1', ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
self::assertArrayHasKey('view', $paged);
|
|
||||||
self::assertArrayNotHasKey('hydra:view', $paged);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Helper ===
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Seede un client COMPLET (sans passer par l'API, validations applicatives
|
|
||||||
* non rejouees mais CHECK BDD respectes) : bloc comptable non nul, >= 1 RIB,
|
|
||||||
* >= 1 adresse multi-sites avec categories, >= 1 contact, >= 1 categorie.
|
|
||||||
*
|
|
||||||
* L'adresse est livraison + facturation (prospect exclusif, RG-1.06 ; email
|
|
||||||
* de facturation present, RG-1.11) afin de poser des booleens `true`
|
|
||||||
* serialisables tout en respectant les CHECK Postgres.
|
|
||||||
*/
|
|
||||||
private function seedCompleteClient(string $companyName): ClientEntity
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
|
|
||||||
// Nom unique parmi les actifs (index partiel uq_client_company_name_active).
|
|
||||||
$suffix = substr(bin2hex(random_bytes(3)), 0, 6);
|
|
||||||
|
|
||||||
$client = new ClientEntity();
|
|
||||||
$client->setCompanyName(mb_strtoupper($companyName.' '.$suffix, 'UTF-8'));
|
|
||||||
$client->setLastName('Complet');
|
|
||||||
$client->setPhonePrimary('0102030405');
|
|
||||||
$client->setEmail('complet'.$suffix.'@seed.test');
|
|
||||||
$client->addCategory($this->createCategory('SECTEUR'));
|
|
||||||
// Bloc comptable non nul (gating par omission cote Commerciale).
|
|
||||||
$client->setSiren('123456789');
|
|
||||||
$client->setAccountNumber('C0001');
|
|
||||||
$client->setNTva('FR00123456789');
|
|
||||||
$em->persist($client);
|
|
||||||
|
|
||||||
// >= 2 sites fixtures pour une adresse multi-sites (RG-1.10).
|
|
||||||
$sites = $em->getRepository(Site::class)->findBy([], null, 2);
|
|
||||||
self::assertGreaterThanOrEqual(2, count($sites), 'Au moins 2 sites fixtures requis (SitesFixtures).');
|
|
||||||
|
|
||||||
$address = new ClientAddress();
|
|
||||||
$address->setClient($client);
|
|
||||||
$address->setIsProspect(false);
|
|
||||||
$address->setIsDelivery(true);
|
|
||||||
$address->setIsBilling(true);
|
|
||||||
$address->setBillingEmail('billing'.$suffix.'@seed.test');
|
|
||||||
$address->setPostalCode('86000');
|
|
||||||
$address->setCity('Poitiers');
|
|
||||||
$address->setStreet('12 rue des Acacias');
|
|
||||||
foreach ($sites as $site) {
|
|
||||||
$address->addSite($site);
|
|
||||||
}
|
|
||||||
$address->addCategory($this->createCategory('SECTEUR'));
|
|
||||||
$em->persist($address);
|
|
||||||
|
|
||||||
$rib = new ClientRib();
|
|
||||||
$rib->setClient($client);
|
|
||||||
$rib->setLabel('Compte principal');
|
|
||||||
$rib->setBic(self::VALID_BIC);
|
|
||||||
$rib->setIban(self::VALID_IBAN);
|
|
||||||
$em->persist($rib);
|
|
||||||
|
|
||||||
$contact = new ClientContact();
|
|
||||||
$contact->setClient($client);
|
|
||||||
$contact->setFirstName('Marie');
|
|
||||||
$contact->setLastName('Martin');
|
|
||||||
$em->persist($contact);
|
|
||||||
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
return $client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,320 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientContact;
|
|
||||||
use App\Module\Commercial\Domain\Entity\ClientRib;
|
|
||||||
use App\Module\Commercial\Domain\Entity\PaymentType;
|
|
||||||
use App\Module\Sites\Domain\Entity\Site;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests fonctionnels des sous-ressources Contacts / Adresses / RIB (ERP-57,
|
|
||||||
* spec § 4.5). Couvrent : CRUD via admin, normalisation serveur
|
|
||||||
* (RG-1.19/1.20/1.21), validations (Assert\Count sites RG-1.10, Assert\Iban/Bic),
|
|
||||||
* regles metier RG-1.13 (DELETE dernier RIB sous LCR -> 409) et RG-1.14 (DELETE
|
|
||||||
* dernier contact -> 409), plus le gating comptable (POST/PATCH/DELETE de
|
|
||||||
* client_ribs sans accounting.manage -> 403).
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientSubResourceApiTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
private const string MERGE = 'application/merge-patch+json';
|
|
||||||
private const string VALID_IBAN = 'FR1420041010050500013M02606';
|
|
||||||
private const string VALID_BIC = 'BNPAFRPPXXX';
|
|
||||||
|
|
||||||
// === Contacts ===
|
|
||||||
|
|
||||||
public function testPostContactNormalizesFields(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Contact Host');
|
|
||||||
|
|
||||||
$data = $client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'firstName' => 'JEAN',
|
|
||||||
'lastName' => 'dupont',
|
|
||||||
'phonePrimary' => '06.12.34.56.78',
|
|
||||||
'email' => 'Jean.DUPONT@ACME.FR',
|
|
||||||
],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
// RG-1.19 / 1.20 / 1.21
|
|
||||||
self::assertSame('Jean', $data['firstName']);
|
|
||||||
self::assertSame('Dupont', $data['lastName']);
|
|
||||||
self::assertSame('0612345678', $data['phonePrimary']);
|
|
||||||
self::assertSame('jean.dupont@acme.fr', $data['email']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPostContactWithoutNameReturns422(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Contact No Name');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/contacts', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => ['jobTitle' => 'Directeur'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// RG-1.05
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPatchContactNormalizes(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Contact Patch');
|
|
||||||
$contact = $this->seedContact($seed, 'Paul');
|
|
||||||
|
|
||||||
$data = $client->request('PATCH', '/api/client_contacts/'.$contact->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['lastName' => 'martin'],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
self::assertSame('Martin', $data['lastName']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeleteContactWhenSeveralReturns204(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Contact Multi');
|
|
||||||
$this->seedContact($seed, 'Premier');
|
|
||||||
$second = $this->seedContact($seed, 'Second');
|
|
||||||
|
|
||||||
$client->request('DELETE', '/api/client_contacts/'.$second->getId());
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeleteLastContactReturns409(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Contact Solo');
|
|
||||||
$only = $this->seedContact($seed, 'Unique');
|
|
||||||
|
|
||||||
$client->request('DELETE', '/api/client_contacts/'.$only->getId());
|
|
||||||
|
|
||||||
// RG-1.14
|
|
||||||
self::assertResponseStatusCodeSame(409);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Adresses ===
|
|
||||||
|
|
||||||
public function testPostAddressNormalizesBillingEmail(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address Host');
|
|
||||||
$siteIri = $this->firstSiteIri();
|
|
||||||
|
|
||||||
$data = $client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'isBilling' => true,
|
|
||||||
'billingEmail' => 'Facturation@ACME.FR',
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$siteIri],
|
|
||||||
],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
// RG-1.21
|
|
||||||
self::assertSame('facturation@acme.fr', $data['billingEmail']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPostAddressWithoutSiteReturns422(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address No Site');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'postalCode' => '86100',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// RG-1.10 (Assert\Count min 1)
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPostAddressWithInvalidPostalCodeReturns422(): void
|
|
||||||
{
|
|
||||||
$this->skipIfSitesModuleDisabled();
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Address Bad CP');
|
|
||||||
$siteIri = $this->firstSiteIri();
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/addresses', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'postalCode' => '123',
|
|
||||||
'city' => 'Châtellerault',
|
|
||||||
'street' => '1 rue du Test',
|
|
||||||
'sites' => [$siteIri],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// RG-1.09 (Assert\Regex ^[0-9]{4,5}$)
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === RIBs ===
|
|
||||||
|
|
||||||
public function testPostRibByAdminReturns201(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Rib Host');
|
|
||||||
|
|
||||||
$data = $client->request('POST', '/api/clients/'.$seed->getId().'/ribs', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'label' => 'Compte principal',
|
|
||||||
'bic' => self::VALID_BIC,
|
|
||||||
'iban' => self::VALID_IBAN,
|
|
||||||
],
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
self::assertSame('Compte principal', $data['label']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPostRibWithInvalidIbanReturns422(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Rib Bad Iban');
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/ribs', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => [
|
|
||||||
'label' => 'Compte invalide',
|
|
||||||
'bic' => self::VALID_BIC,
|
|
||||||
'iban' => 'INVALID-IBAN',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Assert\Iban
|
|
||||||
self::assertResponseStatusCodeSame(422);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeleteRibNonLcrReturns204(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Rib Non LCR');
|
|
||||||
$rib = $this->seedRib($seed);
|
|
||||||
|
|
||||||
$client->request('DELETE', '/api/client_ribs/'.$rib->getId());
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(204);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDeleteLastRibUnderLcrReturns409(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$seed = $this->seedClient('Rib LCR Solo');
|
|
||||||
$this->setPaymentType($seed, 'LCR');
|
|
||||||
$rib = $this->seedRib($seed);
|
|
||||||
|
|
||||||
$client->request('DELETE', '/api/client_ribs/'.$rib->getId());
|
|
||||||
|
|
||||||
// RG-1.13
|
|
||||||
self::assertResponseStatusCodeSame(409);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRibWriteWithoutAccountingManageReturns403(): void
|
|
||||||
{
|
|
||||||
// Un utilisateur portant seulement commercial.clients.manage (sans
|
|
||||||
// accounting.manage) ne peut ni creer, ni modifier, ni supprimer un RIB.
|
|
||||||
$seed = $this->seedClient('Rib Forbidden');
|
|
||||||
$rib = $this->seedRib($seed);
|
|
||||||
$credentials = $this->createUserWithPermission('commercial.clients.manage');
|
|
||||||
$client = $this->authenticatedClient($credentials['username'], $credentials['password']);
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients/'.$seed->getId().'/ribs', [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => ['label' => 'X', 'bic' => self::VALID_BIC, 'iban' => self::VALID_IBAN],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
$client->request('PATCH', '/api/client_ribs/'.$rib->getId(), [
|
|
||||||
'headers' => ['Content-Type' => self::MERGE],
|
|
||||||
'json' => ['label' => 'Y'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
|
|
||||||
$client->request('DELETE', '/api/client_ribs/'.$rib->getId());
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Helpers ===
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Seede un ClientContact rattache a un client (sans passer par l'API).
|
|
||||||
*/
|
|
||||||
private function seedContact(ClientEntity $client, string $firstName): ClientContact
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
$contact = new ClientContact();
|
|
||||||
$contact->setFirstName($firstName);
|
|
||||||
$contact->setClient($client);
|
|
||||||
$em->persist($contact);
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
return $contact;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Seede un ClientRib valide rattache a un client (sans passer par l'API).
|
|
||||||
*/
|
|
||||||
private function seedRib(ClientEntity $client): ClientRib
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
$rib = new ClientRib();
|
|
||||||
$rib->setLabel('Seed RIB');
|
|
||||||
$rib->setBic(self::VALID_BIC);
|
|
||||||
$rib->setIban(self::VALID_IBAN);
|
|
||||||
$rib->setClient($client);
|
|
||||||
$em->persist($rib);
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
return $rib;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Affecte un type de reglement (par code) au client seede.
|
|
||||||
*/
|
|
||||||
private function setPaymentType(ClientEntity $client, string $code): void
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
$type = $em->getRepository(PaymentType::class)->findOneBy(['code' => $code]);
|
|
||||||
self::assertNotNull($type, sprintf('PaymentType "%s" introuvable (fixtures).', $code));
|
|
||||||
|
|
||||||
$managed = $em->getRepository(ClientEntity::class)->find($client->getId());
|
|
||||||
$managed->setPaymentType($type);
|
|
||||||
$em->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retourne l'IRI du premier site seede (fixtures Sites). Skip en amont si le
|
|
||||||
* module Sites est desactive.
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use App\Module\Commercial\Domain\Entity\Client as ClientEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests d'unicite — combler les trous (ERP-60).
|
|
||||||
*
|
|
||||||
* RG-1.16 (doublon de companyName parmi les actifs -> 409) est DEJA couvert par
|
|
||||||
* ClientApiTest::testPostDuplicateCompanyNameReturns409 (ERP-55). Ce fichier
|
|
||||||
* verifie l'envers de la decision Q4 (29/05/2026) : le SIREN (RG-1.15 supprimee)
|
|
||||||
* et l'email (RG-1.17 supprimee) NE SONT PLUS contraints uniques.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ClientUniquenessTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.16 / RG-1.17 (Q4) : deux clients actifs peuvent partager le meme
|
|
||||||
* email principal — aucune contrainte d'unicite (un email peut servir
|
|
||||||
* plusieurs clients).
|
|
||||||
*/
|
|
||||||
public function testDuplicateEmailIsAllowed(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$cat = $this->createCategory('SECTEUR');
|
|
||||||
$iri = '/api/categories/'.$cat->getId();
|
|
||||||
|
|
||||||
$payload = static fn (string $name): array => [
|
|
||||||
'companyName' => $name,
|
|
||||||
'firstName' => 'A',
|
|
||||||
'phonePrimary' => '0102030405',
|
|
||||||
'email' => 'partage@test.fr',
|
|
||||||
'categories' => [$iri],
|
|
||||||
];
|
|
||||||
|
|
||||||
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload('Email Share One')]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
|
|
||||||
// Meme email, nom different -> doit passer (pas d'index unique email).
|
|
||||||
$client->request('POST', '/api/clients', ['headers' => ['Content-Type' => self::LD], 'json' => $payload('Email Share Two')]);
|
|
||||||
self::assertResponseStatusCodeSame(201);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RG-1.15 (Q4) : deux clients peuvent partager le meme SIREN (etablissements
|
|
||||||
* multiples). Le SIREN n'est pas ecrivable au POST (groupe accounting), on
|
|
||||||
* seede donc directement via l'ORM et on prouve que le flush ne leve aucune
|
|
||||||
* violation d'unicite.
|
|
||||||
*/
|
|
||||||
public function testDuplicateSirenIsAllowed(): void
|
|
||||||
{
|
|
||||||
// Boot kernel pour disposer de l'EM (pas d'appel HTTP necessaire ici).
|
|
||||||
self::bootKernel();
|
|
||||||
$em = $this->getEm();
|
|
||||||
|
|
||||||
$one = $this->seedClient('Siren Share One');
|
|
||||||
$two = $this->seedClient('Siren Share Two');
|
|
||||||
|
|
||||||
$one->setSiren('123456789');
|
|
||||||
$two->setSiren('123456789');
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
// Aucune exception : preuve qu'il n'existe pas d'index unique sur siren.
|
|
||||||
self::assertSame('123456789', $em->getRepository(ClientEntity::class)->find($one->getId())->getSiren());
|
|
||||||
self::assertSame('123456789', $em->getRepository(ClientEntity::class)->find($two->getId())->getSiren());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,253 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Api;
|
|
||||||
|
|
||||||
use App\Module\Commercial\Domain\Entity\TvaMode;
|
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests fonctionnels des 4 referentiels comptables lecture seule (ERP-56) :
|
|
||||||
* tva_mode, payment_delay, payment_type, bank. Cf. spec-back M1 § 4.7.
|
|
||||||
*
|
|
||||||
* Couvre les criteres d'acceptation du ticket :
|
|
||||||
* - les 4 GetCollection repondent 200 avec le seed (CommercialReferentialFixtures) ;
|
|
||||||
* - tri par defaut position ASC puis label ASC ;
|
|
||||||
* - POST / PATCH / DELETE -> 405 (aucune operation d'ecriture declaree) ;
|
|
||||||
* - user authentifie sans commercial.clients.view -> 403 ;
|
|
||||||
* - anonyme -> 401 ;
|
|
||||||
* - pagination serveur active (ERP-72) + echappatoire ?pagination=false.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class ReferentialApiTest extends AbstractCommercialApiTestCase
|
|
||||||
{
|
|
||||||
private const string LD = 'application/ld+json';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Endpoint => codes attendus dans le seed (sous-ensemble verifie present).
|
|
||||||
*
|
|
||||||
* @var array<string, list<string>>
|
|
||||||
*/
|
|
||||||
private const SEED = [
|
|
||||||
'/api/tva_modes' => ['FRANCE_VENTES', 'EXPORT_VENTES', 'INTRACOM_VENTES'],
|
|
||||||
'/api/payment_delays' => ['J15', 'J30', 'A_RECEPTION'],
|
|
||||||
'/api/payment_types' => ['VIREMENT', 'LCR', 'NON_SOUMISE', 'CHEQUE'],
|
|
||||||
'/api/banks' => ['SG', 'CIC', 'CA'],
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Purge les eventuelles lignes de test inserees dans tva_mode (tri label).
|
|
||||||
* Les codes du seed ne commencent jamais par TEST_, donc cette purge ne
|
|
||||||
* touche pas les referentiels metier.
|
|
||||||
*/
|
|
||||||
protected function tearDown(): void
|
|
||||||
{
|
|
||||||
$this->getEm()
|
|
||||||
->createQuery('DELETE FROM '.TvaMode::class.' t WHERE t.code LIKE :prefix')
|
|
||||||
->setParameter('prefix', 'TEST\_%')
|
|
||||||
->execute()
|
|
||||||
;
|
|
||||||
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : chaque endpoint repond 200 et expose le seed (id, code, label,
|
|
||||||
* position) sous le groupe de lecture du referentiel.
|
|
||||||
*
|
|
||||||
* @param list<string> $expectedCodes
|
|
||||||
*/
|
|
||||||
#[DataProvider('endpointProvider')]
|
|
||||||
public function testCollectionReturns200WithSeed(string $endpoint, array $expectedCodes): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$response = $client->request('GET', $endpoint.'?pagination=false', ['headers' => ['Accept' => self::LD]]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
|
|
||||||
$members = $response->toArray()['member'];
|
|
||||||
$codes = array_map(static fn (array $m): string => $m['code'], $members);
|
|
||||||
|
|
||||||
foreach ($expectedCodes as $expected) {
|
|
||||||
self::assertContains($expected, $codes, $endpoint.' doit exposer le code seede '.$expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Le DTO de lecture expose bien id / code / label / position.
|
|
||||||
$first = $members[0];
|
|
||||||
self::assertArrayHasKey('id', $first);
|
|
||||||
self::assertArrayHasKey('label', $first);
|
|
||||||
self::assertArrayHasKey('position', $first);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : GET item repond 200 (recupere via un id reel de la collection).
|
|
||||||
*/
|
|
||||||
public function testGetItemReturns200(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
|
|
||||||
$first = $client->request('GET', '/api/tva_modes?pagination=false', ['headers' => ['Accept' => self::LD]])
|
|
||||||
->toArray()['member'][0]
|
|
||||||
;
|
|
||||||
|
|
||||||
$client->request('GET', '/api/tva_modes/'.$first['id'], ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : tri par defaut position ASC. Le seed tva_mode est ordonne
|
|
||||||
* FRANCE_VENTES (10) < EXPORT_VENTES (20) < INTRACOM_VENTES (30).
|
|
||||||
*/
|
|
||||||
public function testDefaultSortByPositionAsc(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
|
|
||||||
$codes = array_map(
|
|
||||||
static fn (array $m): string => $m['code'],
|
|
||||||
$client->request('GET', '/api/tva_modes?pagination=false', ['headers' => ['Accept' => self::LD]])->toArray()['member'],
|
|
||||||
);
|
|
||||||
|
|
||||||
$expectedOrder = ['FRANCE_VENTES', 'EXPORT_VENTES', 'INTRACOM_VENTES'];
|
|
||||||
$filtered = array_values(array_intersect($codes, $expectedOrder));
|
|
||||||
|
|
||||||
self::assertSame(
|
|
||||||
$expectedOrder,
|
|
||||||
$filtered,
|
|
||||||
'Les modes de TVA doivent etre tries position ASC (§ 4.7).',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : a position egale, tri label ASC (departage). On insere deux
|
|
||||||
* lignes de test partageant la meme position, labels volontairement dans le
|
|
||||||
* desordre alphabetique ; le tearDown les purge ensuite.
|
|
||||||
*/
|
|
||||||
public function testTieBreakSortByLabelAsc(): void
|
|
||||||
{
|
|
||||||
$em = $this->getEm();
|
|
||||||
foreach ([['TEST_TIE_Z', 'ZZZ Tie'], ['TEST_TIE_A', 'AAA Tie']] as [$code, $label]) {
|
|
||||||
$mode = new TvaMode();
|
|
||||||
$mode->setCode($code);
|
|
||||||
$mode->setLabel($label);
|
|
||||||
$mode->setPosition(9000);
|
|
||||||
$em->persist($mode);
|
|
||||||
}
|
|
||||||
$em->flush();
|
|
||||||
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$codes = array_map(
|
|
||||||
static fn (array $m): string => $m['code'],
|
|
||||||
$client->request('GET', '/api/tva_modes?pagination=false', ['headers' => ['Accept' => self::LD]])->toArray()['member'],
|
|
||||||
);
|
|
||||||
|
|
||||||
$tie = array_values(array_intersect($codes, ['TEST_TIE_A', 'TEST_TIE_Z']));
|
|
||||||
self::assertSame(
|
|
||||||
['TEST_TIE_A', 'TEST_TIE_Z'],
|
|
||||||
$tie,
|
|
||||||
'A position egale, le tri secondaire doit etre label ASC (§ 4.7).',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere ERP-72 : la collection est paginee par defaut. Preuve : une page
|
|
||||||
* au-dela des donnees est vide (un provider non pagine ignorerait `page`).
|
|
||||||
* Avec ?pagination=false, le parametre `page` est ignore -> tout revient.
|
|
||||||
*/
|
|
||||||
public function testPaginationActiveAndClientToggle(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
|
|
||||||
// Page 2 d'un referentiel tenant sur une page : vide -> pagination active.
|
|
||||||
$page2 = $client->request('GET', '/api/tva_modes?page=2', ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
self::assertArrayHasKey('totalItems', $page2);
|
|
||||||
self::assertSame([], $page2['member'], 'La page 2 doit etre vide : pagination serveur active.');
|
|
||||||
|
|
||||||
// ?pagination=false : `page` ignore, le seed complet est renvoye.
|
|
||||||
$all = $client->request('GET', '/api/tva_modes?pagination=false&page=2', ['headers' => ['Accept' => self::LD]])->toArray();
|
|
||||||
self::assertNotEmpty($all['member'], '?pagination=false doit desactiver la pagination (page ignoree).');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : aucune operation d'ecriture n'est declaree -> POST sur la
|
|
||||||
* collection renvoie 405 Method Not Allowed sur les 4 referentiels.
|
|
||||||
*
|
|
||||||
* @param list<string> $expectedCodes
|
|
||||||
*/
|
|
||||||
#[DataProvider('endpointProvider')]
|
|
||||||
public function testPostReturns405(string $endpoint, array $expectedCodes): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$client->request('POST', $endpoint, [
|
|
||||||
'headers' => ['Content-Type' => self::LD],
|
|
||||||
'json' => ['code' => 'X', 'label' => 'X', 'position' => 1],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(405);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : PATCH et DELETE sur un item renvoient 405 (lecture seule).
|
|
||||||
*/
|
|
||||||
public function testPatchAndDeleteReturn405(): void
|
|
||||||
{
|
|
||||||
$client = $this->createAdminClient();
|
|
||||||
$first = $client->request('GET', '/api/tva_modes?pagination=false', ['headers' => ['Accept' => self::LD]])
|
|
||||||
->toArray()['member'][0]
|
|
||||||
;
|
|
||||||
$iri = '/api/tva_modes/'.$first['id'];
|
|
||||||
|
|
||||||
$client->request('PATCH', $iri, [
|
|
||||||
'headers' => ['Content-Type' => 'application/merge-patch+json'],
|
|
||||||
'json' => ['label' => 'Renamed'],
|
|
||||||
]);
|
|
||||||
self::assertResponseStatusCodeSame(405);
|
|
||||||
|
|
||||||
$client->request('DELETE', $iri);
|
|
||||||
self::assertResponseStatusCodeSame(405);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : un utilisateur authentifie sans la permission
|
|
||||||
* commercial.clients.view obtient 403 sur les 4 endpoints.
|
|
||||||
*
|
|
||||||
* @param list<string> $expectedCodes
|
|
||||||
*/
|
|
||||||
#[DataProvider('endpointProvider')]
|
|
||||||
public function testForbiddenWithoutPermission(string $endpoint, array $expectedCodes): void
|
|
||||||
{
|
|
||||||
// User jetable portant une permission SANS rapport (existe en base mais
|
|
||||||
// ne donne pas commercial.clients.view).
|
|
||||||
$creds = $this->createUserWithPermission('core.users.view');
|
|
||||||
$client = $this->authenticatedClient($creds['username'], $creds['password']);
|
|
||||||
|
|
||||||
$client->request('GET', $endpoint, ['headers' => ['Accept' => self::LD]]);
|
|
||||||
self::assertResponseStatusCodeSame(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Critere : un appel anonyme (non authentifie) obtient 401 sur les 4
|
|
||||||
* endpoints.
|
|
||||||
*
|
|
||||||
* @param list<string> $expectedCodes
|
|
||||||
*/
|
|
||||||
#[DataProvider('endpointProvider')]
|
|
||||||
public function testUnauthorizedWhenAnonymous(string $endpoint, array $expectedCodes): void
|
|
||||||
{
|
|
||||||
$client = self::createClient();
|
|
||||||
$client->request('GET', $endpoint, ['headers' => ['Accept' => self::LD]]);
|
|
||||||
|
|
||||||
self::assertResponseStatusCodeSame(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return iterable<string, array{string, list<string>}>
|
|
||||||
*/
|
|
||||||
public static function endpointProvider(): iterable
|
|
||||||
{
|
|
||||||
foreach (self::SEED as $endpoint => $codes) {
|
|
||||||
yield $endpoint => [$endpoint, $codes];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Tests\Module\Commercial\Unit;
|
|
||||||
|
|
||||||
use ApiPlatform\Metadata\IriConverterInterface;
|
|
||||||
use App\Module\Commercial\Infrastructure\ApiPlatform\Serializer\CategoryReferenceDenormalizer;
|
|
||||||
use App\Shared\Domain\Contract\CategoryInterface;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use stdClass;
|
|
||||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests unitaires du CategoryReferenceDenormalizer : resolution d'un IRI vers
|
|
||||||
* une Category concrete, et rejet explicite d'un IRI pointant sur une autre
|
|
||||||
* ressource (au lieu d'un null silencieux qui perdrait la reference).
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class CategoryReferenceDenormalizerTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testResolvesCategoryIri(): void
|
|
||||||
{
|
|
||||||
$category = $this->createStub(CategoryInterface::class);
|
|
||||||
$iriConverter = $this->createMock(IriConverterInterface::class);
|
|
||||||
$iriConverter->method('getResourceFromIri')->willReturn($category);
|
|
||||||
|
|
||||||
$denormalizer = new CategoryReferenceDenormalizer($iriConverter);
|
|
||||||
|
|
||||||
self::assertSame(
|
|
||||||
$category,
|
|
||||||
$denormalizer->denormalize('/api/categories/1', CategoryInterface::class),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRejectsIriOfWrongType(): void
|
|
||||||
{
|
|
||||||
// Bug review ERP-55 : un IRI syntaxiquement valide mais pointant sur une
|
|
||||||
// autre ressource (ex: /api/clients/5) doit lever une exception au lieu
|
|
||||||
// d'etre silencieusement ignore.
|
|
||||||
$iriConverter = $this->createMock(IriConverterInterface::class);
|
|
||||||
$iriConverter->method('getResourceFromIri')->willReturn(new stdClass());
|
|
||||||
|
|
||||||
$denormalizer = new CategoryReferenceDenormalizer($iriConverter);
|
|
||||||
|
|
||||||
$this->expectException(UnexpectedValueException::class);
|
|
||||||
$denormalizer->denormalize('/api/clients/5', CategoryInterface::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReturnsNullForEmptyData(): void
|
|
||||||
{
|
|
||||||
// Valeur vide deleguee par l'ArrayDenormalizer : aucun appel a
|
|
||||||
// l'IriConverter, retour null.
|
|
||||||
$iriConverter = $this->createMock(IriConverterInterface::class);
|
|
||||||
$iriConverter->expects(self::never())->method('getResourceFromIri');
|
|
||||||
|
|
||||||
$denormalizer = new CategoryReferenceDenormalizer($iriConverter);
|
|
||||||
|
|
||||||
self::assertNull($denormalizer->denormalize('', CategoryInterface::class));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user