Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2424cc7c55 | |||
| f8793ab359 | |||
| 7d8a633eee | |||
| df9451a5f4 | |||
| f8f7571cc0 | |||
| 0052eab1fe | |||
| be9204eca7 | |||
| de4aaa1d64 | |||
| cb12490ba0 | |||
| a442d124a3 | |||
| 431d831c8b | |||
| 3f356f0679 | |||
| c1ce940c98 | |||
| c594a76d47 | |||
| 59bae8c5e6 | |||
| 477f77a6b5 | |||
| d6790dd37d | |||
| 3c1fc39eee | |||
| 1b0339bf1c | |||
| cc7a657df9 | |||
| d72f67d374 | |||
| 26b1f2c39b | |||
| 8490de99da | |||
| b3ab23ee8f | |||
| 222338e5a4 | |||
| d4a5df50a7 | |||
| 191fd42406 | |||
| edfb2b1619 | |||
| c5c650c599 | |||
| e598a92f94 | |||
| b8dc3cb696 | |||
| 843e4b0a0c | |||
| a9c14704b7 | |||
| 43b2251ef1 | |||
| 9cda225bdf | |||
| f031c70393 | |||
| e050a7b910 | |||
| b35deed8fe | |||
| 6f9bb68170 | |||
| 97459e798f | |||
| 58cbfe4437 | |||
| 54091be60e | |||
| e265a008bc | |||
| 145d4362db | |||
| cd36c45b67 | |||
| e77c6378d3 | |||
| 3e138e1c17 | |||
| 6a01067746 | |||
| cd98817b0a | |||
| 1a29bcf76c |
@@ -75,7 +75,7 @@ jobs:
|
||||
- name: Bootstrap test database
|
||||
# Aligne sur la cible `test-db-setup` du makefile : apres
|
||||
# `schema:update --force`, on RECREE manuellement l'index unique
|
||||
# partiel `uq_category_name_type_active` car Doctrine ORM ne sait
|
||||
# partiel `uq_category_name_active` car Doctrine ORM ne sait
|
||||
# pas exprimer les index fonctionnels partiels (LOWER(name) + WHERE
|
||||
# deleted_at IS NULL) et `schema:update` les considere comme
|
||||
# orphelins et les DROP — collisions non detectees, tests d'unicite
|
||||
@@ -89,7 +89,7 @@ jobs:
|
||||
php bin/console app:apply-column-comments --env=test --no-interaction
|
||||
php bin/console doctrine:fixtures:load --env=test --no-interaction
|
||||
php bin/console app:sync-permissions --env=test --no-interaction
|
||||
php bin/console --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_name_type_active ON category (LOWER(name), category_type_id) WHERE deleted_at IS NULL"
|
||||
php bin/console --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_name_active ON category (LOWER(name)) WHERE deleted_at IS NULL"
|
||||
|
||||
- name: Run PHPUnit
|
||||
run: php -d memory_limit=512M vendor/bin/phpunit
|
||||
|
||||
@@ -141,7 +141,7 @@ Disponibles uniquement après `make db-reset` / `make fixtures` (état « avec s
|
||||
| `bob` | `bob` | ROLE_USER | — |
|
||||
| `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) |
|
||||
| `commerciale` | `demo` | ROLE_USER | clients : view + manage |
|
||||
| `usine` | `demo` | ROLE_USER | aucun accès clients |
|
||||
|
||||
---
|
||||
|
||||
+3
-2
@@ -12,6 +12,7 @@
|
||||
"doctrine/doctrine-bundle": "^3.2",
|
||||
"doctrine/doctrine-migrations-bundle": "^4.0",
|
||||
"doctrine/orm": "^3.6",
|
||||
"dompdf/dompdf": "^3.1",
|
||||
"lexik/jwt-authentication-bundle": "^3.2",
|
||||
"nelmio/cors-bundle": "^2.6",
|
||||
"nyholm/psr7": "^1.8",
|
||||
@@ -24,6 +25,7 @@
|
||||
"symfony/expression-language": "8.0.*",
|
||||
"symfony/flex": "^2",
|
||||
"symfony/framework-bundle": "8.0.*",
|
||||
"symfony/http-client": "8.0.*",
|
||||
"symfony/intl": "8.0.*",
|
||||
"symfony/mime": "8.0.*",
|
||||
"symfony/monolog-bundle": "^4.0",
|
||||
@@ -95,7 +97,6 @@
|
||||
"doctrine/doctrine-fixtures-bundle": "^4.3",
|
||||
"friendsofphp/php-cs-fixer": "^3.94",
|
||||
"phpunit/phpunit": "^13.0",
|
||||
"symfony/browser-kit": "8.0.*",
|
||||
"symfony/http-client": "8.0.*"
|
||||
"symfony/browser-kit": "8.0.*"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+620
-175
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "2dc5db01e7f5d6aecd5956749b21a092",
|
||||
"content-hash": "b9a204bab17aa0371f8419362f3bee0c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "api-platform/doctrine-common",
|
||||
@@ -2520,6 +2520,161 @@
|
||||
},
|
||||
"time": "2026-02-08T16:21:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dompdf/dompdf",
|
||||
"version": "v3.1.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dompdf/dompdf.git",
|
||||
"reference": "f11ead23a8a76d0ff9bbc6c7c8fd7e05ca328496"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/dompdf/dompdf/zipball/f11ead23a8a76d0ff9bbc6c7c8fd7e05ca328496",
|
||||
"reference": "f11ead23a8a76d0ff9bbc6c7c8fd7e05ca328496",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"dompdf/php-font-lib": "^1.0.0",
|
||||
"dompdf/php-svg-lib": "^1.0.0",
|
||||
"ext-dom": "*",
|
||||
"ext-mbstring": "*",
|
||||
"masterminds/html5": "^2.0",
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-gd": "*",
|
||||
"ext-json": "*",
|
||||
"ext-zip": "*",
|
||||
"mockery/mockery": "^1.3",
|
||||
"phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10 || ^11",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
"symfony/process": "^4.4 || ^5.4 || ^6.2 || ^7.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-gd": "Needed to process images",
|
||||
"ext-gmagick": "Improves image processing performance",
|
||||
"ext-imagick": "Improves image processing performance",
|
||||
"ext-zlib": "Needed for pdf stream compression"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dompdf\\": "src/"
|
||||
},
|
||||
"classmap": [
|
||||
"lib/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-2.1"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "The Dompdf Community",
|
||||
"homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md"
|
||||
}
|
||||
],
|
||||
"description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
|
||||
"homepage": "https://github.com/dompdf/dompdf",
|
||||
"support": {
|
||||
"issues": "https://github.com/dompdf/dompdf/issues",
|
||||
"source": "https://github.com/dompdf/dompdf/tree/v3.1.5"
|
||||
},
|
||||
"time": "2026-03-03T13:54:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dompdf/php-font-lib",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dompdf/php-font-lib.git",
|
||||
"reference": "a6e9a688a2a80016ac080b97be73d3e10c444c9a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/a6e9a688a2a80016ac080b97be73d3e10c444c9a",
|
||||
"reference": "a6e9a688a2a80016ac080b97be73d3e10c444c9a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10 || ^11 || ^12"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"FontLib\\": "src/FontLib"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-2.1-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "The FontLib Community",
|
||||
"homepage": "https://github.com/dompdf/php-font-lib/blob/master/AUTHORS.md"
|
||||
}
|
||||
],
|
||||
"description": "A library to read, parse, export and make subsets of different types of font files.",
|
||||
"homepage": "https://github.com/dompdf/php-font-lib",
|
||||
"support": {
|
||||
"issues": "https://github.com/dompdf/php-font-lib/issues",
|
||||
"source": "https://github.com/dompdf/php-font-lib/tree/1.0.2"
|
||||
},
|
||||
"time": "2026-01-20T14:10:26+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dompdf/php-svg-lib",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dompdf/php-svg-lib.git",
|
||||
"reference": "8259ffb930817e72b1ff1caef5d226501f3dfeb1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/8259ffb930817e72b1ff1caef5d226501f3dfeb1",
|
||||
"reference": "8259ffb930817e72b1ff1caef5d226501f3dfeb1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": "^7.1 || ^8.0",
|
||||
"sabberworm/php-css-parser": "^8.4 || ^9.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10 || ^11"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Svg\\": "src/Svg"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "The SvgLib Community",
|
||||
"homepage": "https://github.com/dompdf/php-svg-lib/blob/master/AUTHORS.md"
|
||||
}
|
||||
],
|
||||
"description": "A library to read, parse and export to PDF SVG files.",
|
||||
"homepage": "https://github.com/dompdf/php-svg-lib",
|
||||
"support": {
|
||||
"issues": "https://github.com/dompdf/php-svg-lib/issues",
|
||||
"source": "https://github.com/dompdf/php-svg-lib/tree/1.0.2"
|
||||
},
|
||||
"time": "2026-01-02T16:01:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "lcobucci/jwt",
|
||||
"version": "5.6.0",
|
||||
@@ -2894,6 +3049,73 @@
|
||||
},
|
||||
"time": "2022-12-02T22:17:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "masterminds/html5",
|
||||
"version": "2.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Masterminds/html5-php.git",
|
||||
"reference": "fcf91eb64359852f00d921887b219479b4f21251"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Masterminds/html5-php/zipball/fcf91eb64359852f00d921887b219479b4f21251",
|
||||
"reference": "fcf91eb64359852f00d921887b219479b4f21251",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.7-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Masterminds\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Matt Butcher",
|
||||
"email": "technosophos@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Matt Farina",
|
||||
"email": "matt@mattfarina.com"
|
||||
},
|
||||
{
|
||||
"name": "Asmir Mustafic",
|
||||
"email": "goetas@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "An HTML5 parser and serializer.",
|
||||
"homepage": "http://masterminds.github.io/html5-php",
|
||||
"keywords": [
|
||||
"HTML5",
|
||||
"dom",
|
||||
"html",
|
||||
"parser",
|
||||
"querypath",
|
||||
"serializer",
|
||||
"xml"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Masterminds/html5-php/issues",
|
||||
"source": "https://github.com/Masterminds/html5-php/tree/2.10.0"
|
||||
},
|
||||
"time": "2025-07-25T09:04:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "3.10.0",
|
||||
@@ -3937,6 +4159,86 @@
|
||||
},
|
||||
"time": "2021-10-29T13:26:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sabberworm/php-css-parser",
|
||||
"version": "v9.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/MyIntervals/PHP-CSS-Parser.git",
|
||||
"reference": "88dbd0f7f91abbfe4402d0a3071e9ff4d81ed949"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/MyIntervals/PHP-CSS-Parser/zipball/88dbd0f7f91abbfe4402d0a3071e9ff4d81ed949",
|
||||
"reference": "88dbd0f7f91abbfe4402d0a3071e9ff4d81ed949",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-iconv": "*",
|
||||
"php": "^7.2.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
|
||||
"thecodingmachine/safe": "^1.3 || ^2.5 || ^3.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-parallel-lint/php-parallel-lint": "1.4.0",
|
||||
"phpstan/extension-installer": "1.4.3",
|
||||
"phpstan/phpstan": "1.12.32 || 2.1.32",
|
||||
"phpstan/phpstan-phpunit": "1.4.2 || 2.0.8",
|
||||
"phpstan/phpstan-strict-rules": "1.6.2 || 2.0.7",
|
||||
"phpunit/phpunit": "8.5.52",
|
||||
"rawr/phpunit-data-provider": "3.3.1",
|
||||
"rector/rector": "1.2.10 || 2.2.8",
|
||||
"rector/type-perfect": "1.0.0 || 2.1.0",
|
||||
"squizlabs/php_codesniffer": "4.0.1",
|
||||
"thecodingmachine/phpstan-safe-rule": "1.2.0 || 1.4.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "for parsing UTF-8 CSS"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "9.4.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/Rule/Rule.php",
|
||||
"src/RuleSet/RuleContainer.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Sabberworm\\CSS\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Raphael Schweikert"
|
||||
},
|
||||
{
|
||||
"name": "Oliver Klee",
|
||||
"email": "github@oliverklee.de"
|
||||
},
|
||||
{
|
||||
"name": "Jake Hotson",
|
||||
"email": "jake.github@qzdesign.co.uk"
|
||||
}
|
||||
],
|
||||
"description": "Parser for CSS Files written in PHP",
|
||||
"homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser",
|
||||
"keywords": [
|
||||
"css",
|
||||
"parser",
|
||||
"stylesheet"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/MyIntervals/PHP-CSS-Parser/issues",
|
||||
"source": "https://github.com/MyIntervals/PHP-CSS-Parser/tree/v9.3.0"
|
||||
},
|
||||
"time": "2026-03-03T17:31:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/asset",
|
||||
"version": "v8.0.8",
|
||||
@@ -5412,6 +5714,180 @@
|
||||
],
|
||||
"time": "2026-03-30T15:14:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/http-client",
|
||||
"version": "v8.0.13",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-client.git",
|
||||
"reference": "c7f40f9103233630167c25c9a4570acf805fdade"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-client/zipball/c7f40f9103233630167c25c9a4570acf805fdade",
|
||||
"reference": "c7f40f9103233630167c25c9a4570acf805fdade",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.4",
|
||||
"psr/log": "^1|^2|^3",
|
||||
"symfony/http-client-contracts": "~3.4.4|^3.5.2",
|
||||
"symfony/service-contracts": "^2.5|^3"
|
||||
},
|
||||
"conflict": {
|
||||
"amphp/amp": "<3",
|
||||
"php-http/discovery": "<1.15"
|
||||
},
|
||||
"provide": {
|
||||
"php-http/async-client-implementation": "*",
|
||||
"php-http/client-implementation": "*",
|
||||
"psr/http-client-implementation": "1.0",
|
||||
"symfony/http-client-implementation": "3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"amphp/http-client": "^5.3.2",
|
||||
"amphp/http-tunnel": "^2.0",
|
||||
"guzzlehttp/promises": "^1.4|^2.0",
|
||||
"nyholm/psr7": "^1.0",
|
||||
"php-http/httplug": "^1.0|^2.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"symfony/cache": "^7.4|^8.0",
|
||||
"symfony/dependency-injection": "^7.4|^8.0",
|
||||
"symfony/http-kernel": "^7.4|^8.0",
|
||||
"symfony/messenger": "^7.4|^8.0",
|
||||
"symfony/process": "^7.4|^8.0",
|
||||
"symfony/rate-limiter": "^7.4|^8.0",
|
||||
"symfony/stopwatch": "^7.4|^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\HttpClient\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"http"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/http-client/tree/v8.0.13"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/nicolas-grekas",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-05-24T09:58:02+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/http-client-contracts",
|
||||
"version": "v3.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-client-contracts.git",
|
||||
"reference": "75d7043853a42837e68111812f4d964b01e5101c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/75d7043853a42837e68111812f4d964b01e5101c",
|
||||
"reference": "75d7043853a42837e68111812f4d964b01e5101c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/contracts",
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.6-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Contracts\\HttpClient\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Test/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Generic abstractions related to HTTP clients",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"abstractions",
|
||||
"contracts",
|
||||
"decoupling",
|
||||
"interfaces",
|
||||
"interoperability",
|
||||
"standards"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/http-client-contracts/tree/v3.6.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-04-29T11:18:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/http-foundation",
|
||||
"version": "v8.0.8",
|
||||
@@ -8605,6 +9081,149 @@
|
||||
],
|
||||
"time": "2026-03-30T15:14:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "thecodingmachine/safe",
|
||||
"version": "v3.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thecodingmachine/safe.git",
|
||||
"reference": "705683a25bacf0d4860c7dea4d7947bfd09eea19"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thecodingmachine/safe/zipball/705683a25bacf0d4860c7dea4d7947bfd09eea19",
|
||||
"reference": "705683a25bacf0d4860c7dea4d7947bfd09eea19",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-parallel-lint/php-parallel-lint": "^1.4",
|
||||
"phpstan/phpstan": "^2",
|
||||
"phpunit/phpunit": "^10",
|
||||
"squizlabs/php_codesniffer": "^3.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"lib/special_cases.php",
|
||||
"generated/apache.php",
|
||||
"generated/apcu.php",
|
||||
"generated/array.php",
|
||||
"generated/bzip2.php",
|
||||
"generated/calendar.php",
|
||||
"generated/classobj.php",
|
||||
"generated/com.php",
|
||||
"generated/cubrid.php",
|
||||
"generated/curl.php",
|
||||
"generated/datetime.php",
|
||||
"generated/dir.php",
|
||||
"generated/eio.php",
|
||||
"generated/errorfunc.php",
|
||||
"generated/exec.php",
|
||||
"generated/fileinfo.php",
|
||||
"generated/filesystem.php",
|
||||
"generated/filter.php",
|
||||
"generated/fpm.php",
|
||||
"generated/ftp.php",
|
||||
"generated/funchand.php",
|
||||
"generated/gettext.php",
|
||||
"generated/gmp.php",
|
||||
"generated/gnupg.php",
|
||||
"generated/hash.php",
|
||||
"generated/ibase.php",
|
||||
"generated/ibmDb2.php",
|
||||
"generated/iconv.php",
|
||||
"generated/image.php",
|
||||
"generated/imap.php",
|
||||
"generated/info.php",
|
||||
"generated/inotify.php",
|
||||
"generated/json.php",
|
||||
"generated/ldap.php",
|
||||
"generated/libxml.php",
|
||||
"generated/lzf.php",
|
||||
"generated/mailparse.php",
|
||||
"generated/mbstring.php",
|
||||
"generated/misc.php",
|
||||
"generated/mysql.php",
|
||||
"generated/mysqli.php",
|
||||
"generated/network.php",
|
||||
"generated/oci8.php",
|
||||
"generated/opcache.php",
|
||||
"generated/openssl.php",
|
||||
"generated/outcontrol.php",
|
||||
"generated/pcntl.php",
|
||||
"generated/pcre.php",
|
||||
"generated/pgsql.php",
|
||||
"generated/posix.php",
|
||||
"generated/ps.php",
|
||||
"generated/pspell.php",
|
||||
"generated/readline.php",
|
||||
"generated/rnp.php",
|
||||
"generated/rpminfo.php",
|
||||
"generated/rrd.php",
|
||||
"generated/sem.php",
|
||||
"generated/session.php",
|
||||
"generated/shmop.php",
|
||||
"generated/sockets.php",
|
||||
"generated/sodium.php",
|
||||
"generated/solr.php",
|
||||
"generated/spl.php",
|
||||
"generated/sqlsrv.php",
|
||||
"generated/ssdeep.php",
|
||||
"generated/ssh2.php",
|
||||
"generated/stream.php",
|
||||
"generated/strings.php",
|
||||
"generated/swoole.php",
|
||||
"generated/uodbc.php",
|
||||
"generated/uopz.php",
|
||||
"generated/url.php",
|
||||
"generated/var.php",
|
||||
"generated/xdiff.php",
|
||||
"generated/xml.php",
|
||||
"generated/xmlrpc.php",
|
||||
"generated/yaml.php",
|
||||
"generated/yaz.php",
|
||||
"generated/zip.php",
|
||||
"generated/zlib.php"
|
||||
],
|
||||
"classmap": [
|
||||
"lib/DateTime.php",
|
||||
"lib/DateTimeImmutable.php",
|
||||
"lib/Exceptions/",
|
||||
"generated/Exceptions/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "PHP core functions that throw exceptions instead of returning FALSE on error",
|
||||
"support": {
|
||||
"issues": "https://github.com/thecodingmachine/safe/issues",
|
||||
"source": "https://github.com/thecodingmachine/safe/tree/v3.4.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/OskarStark",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/shish",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/silasjoisten",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/staabm",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2026-02-04T18:08:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v3.24.0",
|
||||
@@ -11785,180 +12404,6 @@
|
||||
],
|
||||
"time": "2026-03-30T15:14:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/http-client",
|
||||
"version": "v8.0.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-client.git",
|
||||
"reference": "356e43d6994ae9d7761fd404d40f78691deabe0e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-client/zipball/356e43d6994ae9d7761fd404d40f78691deabe0e",
|
||||
"reference": "356e43d6994ae9d7761fd404d40f78691deabe0e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.4",
|
||||
"psr/log": "^1|^2|^3",
|
||||
"symfony/http-client-contracts": "~3.4.4|^3.5.2",
|
||||
"symfony/service-contracts": "^2.5|^3"
|
||||
},
|
||||
"conflict": {
|
||||
"amphp/amp": "<3",
|
||||
"php-http/discovery": "<1.15"
|
||||
},
|
||||
"provide": {
|
||||
"php-http/async-client-implementation": "*",
|
||||
"php-http/client-implementation": "*",
|
||||
"psr/http-client-implementation": "1.0",
|
||||
"symfony/http-client-implementation": "3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"amphp/http-client": "^5.3.2",
|
||||
"amphp/http-tunnel": "^2.0",
|
||||
"guzzlehttp/promises": "^1.4|^2.0",
|
||||
"nyholm/psr7": "^1.0",
|
||||
"php-http/httplug": "^1.0|^2.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"symfony/cache": "^7.4|^8.0",
|
||||
"symfony/dependency-injection": "^7.4|^8.0",
|
||||
"symfony/http-kernel": "^7.4|^8.0",
|
||||
"symfony/messenger": "^7.4|^8.0",
|
||||
"symfony/process": "^7.4|^8.0",
|
||||
"symfony/rate-limiter": "^7.4|^8.0",
|
||||
"symfony/stopwatch": "^7.4|^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\HttpClient\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"http"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/http-client/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/http-client-contracts",
|
||||
"version": "v3.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-client-contracts.git",
|
||||
"reference": "75d7043853a42837e68111812f4d964b01e5101c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/75d7043853a42837e68111812f4d964b01e5101c",
|
||||
"reference": "75d7043853a42837e68111812f4d964b01e5101c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/contracts",
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.6-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Contracts\\HttpClient\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Test/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Generic abstractions related to HTTP clients",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"abstractions",
|
||||
"contracts",
|
||||
"decoupling",
|
||||
"interfaces",
|
||||
"interoperability",
|
||||
"standards"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/http-client-contracts/tree/v3.6.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-04-29T11:18:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/process",
|
||||
"version": "v8.0.8",
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
use App\Module\Catalog\CatalogModule;
|
||||
use App\Module\Commercial\CommercialModule;
|
||||
use App\Module\Core\CoreModule;
|
||||
use App\Module\FieldSales\FieldSalesModule;
|
||||
use App\Module\Sites\SitesModule;
|
||||
|
||||
return [
|
||||
@@ -11,4 +12,5 @@ return [
|
||||
CommercialModule::class,
|
||||
SitesModule::class,
|
||||
CatalogModule::class,
|
||||
FieldSalesModule::class,
|
||||
];
|
||||
|
||||
@@ -12,6 +12,11 @@ api_platform:
|
||||
# Resources virtuelles (sans entite Doctrine) declarees via #[ApiResource]
|
||||
# en dehors de Domain/Entity : AuditLogResource, etc.
|
||||
- '%kernel.project_dir%/src/Module/Core/Infrastructure/ApiPlatform/Resource'
|
||||
# Module FieldSales (M6) : entites ApiResource Tour / TourStop.
|
||||
- '%kernel.project_dir%/src/Module/FieldSales/Domain/Entity'
|
||||
# Module FieldSales (M6) : resources virtuelles sans entite Doctrine
|
||||
# (VisitableTierResource — pins de la carte, lecture DBAL).
|
||||
- '%kernel.project_dir%/src/Module/FieldSales/Infrastructure/ApiPlatform/Resource'
|
||||
formats:
|
||||
jsonld: ['application/ld+json']
|
||||
json: ['application/json']
|
||||
|
||||
@@ -41,6 +41,13 @@ doctrine:
|
||||
# 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
|
||||
# NOTE (M6 / VisitableInterface) : VisitableInterface n'apparait PAS ici.
|
||||
# resolve_target_entities mappe un contrat -> UNE seule classe concrete,
|
||||
# or ce contrat a plusieurs implementations (Client M1, Supplier M2, et
|
||||
# Prestataire a venir). FieldSales ne reference donc pas un Tiers via une
|
||||
# association Doctrine mais via le couple polymorphe (tier_type, tier_id)
|
||||
# de tour_stop, resolu par un service a partir de getVisitableType()
|
||||
# (ERP-124). Aucune ligne resolve_target_entities n'est requise/possible.
|
||||
mappings:
|
||||
Core:
|
||||
type: attribute
|
||||
@@ -80,6 +87,16 @@ doctrine:
|
||||
dir: '%kernel.project_dir%/src/Module/Commercial/Domain/Entity'
|
||||
prefix: 'App\Module\Commercial\Domain\Entity'
|
||||
alias: Commercial
|
||||
# Mapping inconditionnel du module FieldSales (M6 — meme logique que
|
||||
# Commercial) : les tables tour / tour_stop creees par la migration
|
||||
# M6.3 (Version20260611140000) doivent etre connues de l'ORM.
|
||||
# L'activation fonctionnelle passe par config/modules.php.
|
||||
FieldSales:
|
||||
type: attribute
|
||||
is_bundle: false
|
||||
dir: '%kernel.project_dir%/src/Module/FieldSales/Domain/Entity'
|
||||
prefix: 'App\Module\FieldSales\Domain\Entity'
|
||||
alias: FieldSales
|
||||
controller_resolver:
|
||||
auto_mapping: false
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
doctrine:
|
||||
dbal:
|
||||
connections:
|
||||
# Force le profiling DBAL en environnement de test independamment de
|
||||
# APP_DEBUG. Sans cela, la CI tourne en APP_DEBUG=0 (prod-like) et le
|
||||
# service `doctrine.debug_data_holder` n'est pas enregistre : le test
|
||||
# anti-N+1 (SupplierListTest::testListQueryCountDoesNotGrowWithRowCount)
|
||||
# qui compte les requetes via ce holder echoue alors en CI alors qu'il
|
||||
# passe en local (APP_DEBUG=1). Activer le profiling ici garde le test
|
||||
# actif precisement la ou il compte (CI), sans impacter la prod.
|
||||
default:
|
||||
profiling: true
|
||||
@@ -1,6 +1,8 @@
|
||||
# yaml-language-server: $schema=../vendor/symfony/dependency-injection/Loader/schema/services.schema.json
|
||||
|
||||
parameters:
|
||||
# Vitesse moyenne (km/h) du moteur de trajet V1 Haversine (M6 § 3.4).
|
||||
field_sales.route_average_speed_kmh: 50.0
|
||||
|
||||
imports:
|
||||
- { resource: version.yaml }
|
||||
@@ -33,3 +35,25 @@ services:
|
||||
|
||||
App\Module\Sites\Application\Service\CurrentSiteProviderInterface:
|
||||
alias: App\Module\Sites\Application\Service\CurrentSiteProvider
|
||||
|
||||
# Geocodage des adresses Tiers (M6.1) : BAN api-adresse.data.gouv.fr.
|
||||
App\Shared\Domain\Contract\GeocoderInterface:
|
||||
alias: App\Shared\Infrastructure\Geocoding\BanGeocoder
|
||||
|
||||
# Moteur de trajet V1 (M6 § 3.4) : Haversine + plus proche voisin. La V2
|
||||
# rebranchera OrsRouteEngine ici sans toucher au calculateur ni au front.
|
||||
App\Module\FieldSales\Domain\Route\RouteEngineInterface:
|
||||
alias: App\Module\FieldSales\Infrastructure\Route\HaversineRouteEngine
|
||||
|
||||
# Rendu PDF (feuille de route M6.4, etc.) : Dompdf.
|
||||
App\Shared\Domain\Contract\PdfRendererInterface:
|
||||
alias: App\Shared\Infrastructure\Pdf\DompdfRenderer
|
||||
|
||||
# En test : geocodeur en memoire, deterministe et sans reseau (les tests
|
||||
# fonctionnels d'adresse ne doivent jamais appeler la BAN reelle).
|
||||
when@test:
|
||||
services:
|
||||
App\Tests\Fixtures\Geocoding\InMemoryGeocoder: ~
|
||||
|
||||
App\Shared\Domain\Contract\GeocoderInterface:
|
||||
alias: App\Tests\Fixtures\Geocoding\InMemoryGeocoder
|
||||
|
||||
+22
-4
@@ -45,6 +45,13 @@ return [
|
||||
'label' => 'sidebar.commercial.section',
|
||||
'icon' => 'mdi:account-arrow-left-outline',
|
||||
'items' => [
|
||||
[
|
||||
'label' => 'sidebar.commercial.suppliers',
|
||||
'to' => '/suppliers',
|
||||
'icon' => 'mdi:account-arrow-left-outline',
|
||||
'module' => 'commercial',
|
||||
'permission' => 'commercial.suppliers.view',
|
||||
],
|
||||
[
|
||||
'label' => 'sidebar.commercial.clients',
|
||||
'to' => '/clients',
|
||||
@@ -52,11 +59,22 @@ return [
|
||||
'module' => 'commercial',
|
||||
'permission' => 'commercial.clients.view',
|
||||
],
|
||||
],
|
||||
],
|
||||
// Section "Tournées" (module field_sales, M6) : planification de tournees
|
||||
// commerciales terrain. Transverse Clients/Fournisseurs. Masquee si le module
|
||||
// field_sales est desactivee (cle `module`) ou si l'user n'a pas la
|
||||
// permission field_sales.tours.view.
|
||||
[
|
||||
'label' => 'sidebar.field_sales.section',
|
||||
'icon' => 'mdi:map-marker-path',
|
||||
'items' => [
|
||||
[
|
||||
'label' => 'sidebar.commercial.suppliers',
|
||||
'to' => '/suppliers',
|
||||
'icon' => 'mdi:account-arrow-left-outline',
|
||||
'module' => 'commercial',
|
||||
'label' => 'sidebar.field_sales.tours',
|
||||
'to' => '/tours',
|
||||
'icon' => 'mdi:map-marker-path',
|
||||
'module' => 'field_sales',
|
||||
'permission' => 'field_sales.tours.view',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '0.1.84'
|
||||
app.version: '0.1.109'
|
||||
|
||||
@@ -10,8 +10,8 @@ trous, zéro duplication »).
|
||||
|
||||
ERP-60 n'écrit QUE les tests des RG non déjà couvertes par la stack, et mappe ici
|
||||
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
|
||||
des **rôles métier** (matrice RBAC bureau/compta/commerciale/usine) sont
|
||||
**délégués à ERP-74 (#493)** : ces rôles n'existent qu'après le
|
||||
merge de la stack.
|
||||
|
||||
## Mapping RG → test
|
||||
@@ -21,7 +21,7 @@ merge de la stack.
|
||||
| ~~RG-1.01~~ | _(supprimée V1 — refonte-contact)_ contact inline retiré du Client ; complétude couverte par RG-1.05 / RG-1.14 (`ClientContact`) | — | refonte-contact |
|
||||
| ~~RG-1.02~~ | _(supprimée du Client V1)_ téléphones inline retirés du Client (testés sur `ClientContact`) | — | refonte-contact |
|
||||
| RG-1.03 | distributor/broker exclusifs + type catégorie | `ClientApiTest::testPostWithDistributorAndBrokerReturns422` ; `::testPostDistributorReferencingNonDistributorReturns422` ; `::testPostValidDistributorReturns201` ; `ClientProcessorTest` (unit) | ERP-55 |
|
||||
| RG-1.04 | Onglet Information obligatoire pour rôle Commerciale | `ClientProcessorTest::testCommercialeIncompleteInformationIsUnprocessable` ; `::testNonCommercialeSkipsInformationCompleteness` (unit, dormant). **Test fonctionnel + durcissement → ERP-74** | ERP-55 / **ERP-74** |
|
||||
| ~~RG-1.04~~ | _(SUPPRIMÉE)_ Onglet Information désormais facultatif pour tous les rôles (validation de complétude retirée) | — | ERP-55 / ERP-74 |
|
||||
| RG-1.05 | Contact : prénom OU nom → 422 (CHECK) | `ClientSubResourceApiTest::testPostContactWithoutNameReturns422` | ERP-57 |
|
||||
| RG-1.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 |
|
||||
@@ -60,8 +60,7 @@ merge de la stack.
|
||||
|
||||
- **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).
|
||||
- ~~**RG-1.04 fonctionnel**~~ : _(SUPPRIMÉE)_ l'onglet Information est désormais facultatif pour tous les rôles.
|
||||
- Raison : ces rôles métier ne sont seedés qu'après le merge de la stack M1.
|
||||
|
||||
## Gaps & suivi
|
||||
|
||||
@@ -310,7 +310,7 @@ CREATE TABLE client (
|
||||
distributor_id INT REFERENCES client(id) ON DELETE SET NULL,
|
||||
broker_id INT REFERENCES client(id) ON DELETE SET NULL,
|
||||
triage_service BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
-- Onglet Information (Commerciale obligatoire — RG-1.04 — null sinon)
|
||||
-- Onglet Information (facultatif pour tous — RG-1.04 supprimée)
|
||||
description TEXT,
|
||||
competitors VARCHAR(255),
|
||||
founded_at DATE,
|
||||
@@ -864,8 +864,7 @@ Cf. § 2.6. Pattern Shared standard.
|
||||
|
||||
### 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.
|
||||
- **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).
|
||||
- ~~**RG-1.04**~~ _(SUPPRIMÉE)_ : l'onglet Information est désormais **facultatif pour tous les rôles**, y compris Commerciale. Les champs `description`, `competitors`, `foundedAt`, `employeesCount`, `revenueAmount`, `directorName`, `profitAmount` restent optionnels (colonnes nullable, aucune validation de complétude). Le validator `ClientInformationCompletenessValidator` et le gating par rôle métier dans le `ClientProcessor` ont été retirés.
|
||||
|
||||
### Onglet Contact
|
||||
|
||||
@@ -883,7 +882,7 @@ Cf. § 2.6. Pattern Shared standard.
|
||||
|
||||
### Onglet Comptabilité
|
||||
|
||||
- **RG-1.30** _(ajoutée — correctif incohérence spec-front/spec-back)_ : à la **validation complète de l'onglet Comptabilité**, les six champs scalaires `siren`, `accountNumber`, `tvaMode`, `nTva`, `paymentDelay`, `paymentType` sont **obligatoires** (alignement sur spec-front § Onglet Comptabilité). Colonnes `nullable` en base (l'onglet est rempli dans un second temps, et l'onglet principal ne les envoie pas) + validateur contextuel `ClientAccountingCompletenessValidator` invoqué par le `ClientProcessor` — même parti que RG-1.04 (Information). Déclenchement : uniquement quand **les six champs sont présents dans le payload** (le front les envoie toujours ensemble via « Valider ») ; un PATCH ciblant un sous-ensemble de champs comptables (édition ponctuelle) n'est pas soumis à la complétude. Chaque champ manquant → 422 sur son `propertyPath` (mapping inline front, ERP-101). `bank` reste hors complétude (conditionnel RG-1.12).
|
||||
- **RG-1.30** _(ajoutée — correctif incohérence spec-front/spec-back)_ : à la **validation complète de l'onglet Comptabilité**, les six champs scalaires `siren`, `accountNumber`, `tvaMode`, `nTva`, `paymentDelay`, `paymentType` sont **obligatoires** (alignement sur spec-front § Onglet Comptabilité). Colonnes `nullable` en base (l'onglet est rempli dans un second temps, et l'onglet principal ne les envoie pas) + validateur contextuel `ClientAccountingCompletenessValidator` invoqué par le `ClientProcessor` (parti pris : nullable + validateur d'onglet plutôt qu'un `Assert\NotBlank` sur l'entité). Déclenchement : uniquement quand **les six champs sont présents dans le payload** (le front les envoie toujours ensemble via « Valider ») ; un PATCH ciblant un sous-ensemble de champs comptables (édition ponctuelle) n'est pas soumis à la complétude. Chaque champ manquant → 422 sur son `propertyPath` (mapping inline front, ERP-101). `bank` reste hors complétude (conditionnel RG-1.12).
|
||||
- **RG-1.12** : Le champ `bank` est visible et obligatoire **uniquement** si `paymentType.code = 'VIREMENT'`. Validation server-side dans le `ClientProcessor` : si `payment_type.code = VIREMENT` et `bank IS NULL` → 422.
|
||||
- **RG-1.13** : Les champs RIB (`label`, `bic`, `iban`) sont obligatoires si **au moins un bloc RIB est présent ET** `paymentType.code = 'LCR'`. C'est-à-dire :
|
||||
- Si `paymentType.code = LCR` ET `client.ribs.count() = 0` → 422 « Au moins un RIB est obligatoire pour le type LCR ».
|
||||
@@ -938,7 +937,7 @@ Cf. § 2.6. Pattern Shared standard.
|
||||
- [ ] ~~RG-1.02~~ _(supprimée du Client V1)_ : plus de téléphones inline sur le Client (téléphones testés sur `ClientContact`)
|
||||
- [ ] **RG-1.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.04** : PATCH onglet Information par un user Commerciale avec champs incomplets → 422 ; même PATCH par Admin → 200
|
||||
- [x] ~~**RG-1.04**~~ _(SUPPRIMÉE)_ : onglet Information facultatif pour tous les rôles (plus de validation de complétude)
|
||||
- [ ] **RG-1.05** : POST contact sans firstName ni lastName → 422 (BDD CHECK lève une exception)
|
||||
- [ ] **RG-1.06/07/08** : POST adresse avec isProspect=true ET isDelivery=true → 422 / CHECK
|
||||
- [ ] **RG-1.09** : POST adresse avec postalCode invalide (3 chiffres) → 422 ; CP/ville incohérents → 200 (pas de validation stricte côté serveur)
|
||||
|
||||
@@ -13,7 +13,7 @@ date_redaction: 2026-05-28
|
||||
|
||||
# === LIENS ===
|
||||
maquette_figma: "https://www.figma.com/design/jRYgT0T9c03VsEbjGhCwwS/Composants---Design-System?node-id=1132-31898"
|
||||
regles_metier: [RG-1.01, RG-1.02, RG-1.03, RG-1.04, RG-1.05, RG-1.06, RG-1.07, RG-1.08, RG-1.09, RG-1.10, RG-1.11, RG-1.12, RG-1.13, RG-1.14, RG-1.15, RG-1.16, RG-1.17, RG-1.18, RG-1.19, RG-1.20, RG-1.21, RG-1.22, RG-1.23, RG-1.24, RG-1.25, RG-1.26, RG-1.27, RG-1.28, RG-1.29]
|
||||
regles_metier: [RG-1.01, RG-1.02, RG-1.03, RG-1.05, RG-1.06, RG-1.07, RG-1.08, RG-1.09, RG-1.10, RG-1.11, RG-1.12, RG-1.13, RG-1.14, RG-1.15, RG-1.16, RG-1.17, RG-1.18, RG-1.19, RG-1.20, RG-1.21, RG-1.22, RG-1.23, RG-1.24, RG-1.25, RG-1.26, RG-1.27, RG-1.28, RG-1.29]
|
||||
roles: [Admin, Bureau, Compta, Commerciale, Usine]
|
||||
lien_spec_back: ./spec-back.md
|
||||
|
||||
@@ -105,13 +105,13 @@ Saisir les informations de l'entreprise.
|
||||
|
||||
| Champ | Type | Obligatoire | Règle |
|
||||
|---|---|---|---|
|
||||
| **Description** | `<MalioInputTextArea>` | Conditionnel | RG-1.04 (obligatoire pour rôle Commerciale) |
|
||||
| **Concurrents** | `<MalioInputText>` | Conditionnel | RG-1.04 |
|
||||
| **Date de création** (de l'entreprise) | `<input type="date">` (exception Malio — pas de composant date couvert) | Conditionnel | RG-1.04 |
|
||||
| **Nombre de salariés** | `<MalioInputNumber>` | Conditionnel | RG-1.04 |
|
||||
| **CA €** | `<MalioInputAmount>` | Conditionnel | RG-1.04 |
|
||||
| **Dirigeant** | `<MalioInputText>` | Conditionnel | RG-1.04 |
|
||||
| **Résultat €** | `<MalioInputAmount>` | Conditionnel | RG-1.04 |
|
||||
| **Description** | `<MalioInputTextArea>` | Non | — _(onglet facultatif, RG-1.04 supprimée)_ |
|
||||
| **Concurrents** | `<MalioInputText>` | Non | — |
|
||||
| **Date de création** (de l'entreprise) | `<input type="date">` (exception Malio — pas de composant date couvert) | Non | — |
|
||||
| **Nombre de salariés** | `<MalioInputNumber>` | Non | — |
|
||||
| **CA €** | `<MalioInputAmount>` | Non | — |
|
||||
| **Dirigeant** | `<MalioInputText>` | Non | — |
|
||||
| **Résultat €** | `<MalioInputAmount>` | Non | — |
|
||||
|
||||
**Action** : « Valider » → PATCH partiel `/api/clients/{id}` (groupe `client:write:information`).
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ Toutes les entités métier nouvelles implémentent `TimestampableInterface` + `
|
||||
|
||||
Notes (miroir M1) :
|
||||
- **Compta édite uniquement l'onglet Comptabilité** (`accounting.manage`) d'un fournisseur existant. Compta ne peut pas **créer** un fournisseur (pas de `manage` global).
|
||||
- **Commerciale** a `view` + `manage` mais **pas** `accounting.view` → l'onglet Comptabilité est masqué (front) et filtré (back, 2 niveaux : `security` API Platform + `SupplierProvider`).
|
||||
- **Commerciale** a `view` + `manage` mais **pas** `accounting.view` → l'onglet Comptabilité est masqué (front) et filtré (back). Mécanisme réel (le code fait foi) : le groupe de lecture `supplier:read:accounting` n'est **pas** dans le contexte de sérialisation par défaut ; le `SupplierReadGroupContextBuilder` ne l'**ajoute** dynamiquement que si l'utilisateur porte `commercial.suppliers.accounting.view` (gating **par ajout** de groupe, jamais par retrait). Sans la permission, les champs comptables (et les RIB) ne sont donc jamais sérialisés. La colonne SIREN de l'export XLSX suit la même règle (`accounting.view`).
|
||||
- **Bureau** : `view` + `manage` (tout sauf Comptabilité).
|
||||
- **Usine** : aucune permission → item sidebar invisible, accès direct 403.
|
||||
|
||||
@@ -159,9 +159,11 @@ final class SupplierFieldNormalizer
|
||||
|
||||
Le formatage `XX XX XX XX XX` est fait à l'affichage côté front. Le back stocke `0612345678` (chiffres seuls).
|
||||
|
||||
### 2.12 Liste : embed catégories + sites + fetch-joins (cohérence M1/ERP-62)
|
||||
### 2.12 Liste : embed catégories + sites + hydratation anti-N+1 (cohérence M1/ERP-62)
|
||||
|
||||
Décision d'alignement (02/06/2026) : la **liste** `GET /api/suppliers` **embarque** les `categories[]` (avec `code`/`name`) et les `sites[]` (avec `name`/`postalCode` — pas de `code`), comme la liste Clients après ERP-62 — et **non** des champs dérivés aplatis. Conséquence performance : le `DoctrineSupplierRepository` **DOIT** poser des **fetch-joins** (`leftJoin`+`addSelect`) sur `categories` et `addresses.sites` dans la requête de liste pour éviter le N+1. Les `sites` de la liste sont agrégés/dédoublonnés via `Supplier::getSites()` (cf. § 3.3). Le contrat de sérialisation (groupes `category:read` / `site:read` dans le contexte) est posé **une seule fois** sur l'entité — source de vérité unique, le front ne le redéfinit pas.
|
||||
Décision d'alignement (02/06/2026) : la **liste** `GET /api/suppliers` **embarque** les `categories[]` (avec `code`/`name`) et les `sites[]` (avec `name`/`postalCode` — pas de `code`), comme la liste Clients après ERP-62 — et **non** des champs dérivés aplatis.
|
||||
|
||||
Conséquence performance — **implémentation réelle (le code fait foi)** : le `DoctrineSupplierRepository` **ne fetch-joine PAS** les to-many dans la requête de sélection (`createListQueryBuilder` ne fait que filtres + tri). L'anti-N+1 passe par `hydrateListCollections()` (puis `hydrateContacts()`) : une fois le jeu de fournisseurs borné (page ou export), des requêtes **`IN` bornées séparées** remplissent `categories`, puis `addresses.sites`, puis `contacts` sur les **mêmes** instances `Supplier` (identity map). Ce découpage évite le **produit cartésien** qu'un fetch-join combiné `categories × addresses.sites` imposerait aux chemins non paginés (export, `?pagination=false`). Les `sites` de la liste sont agrégés/dédoublonnés via `Supplier::getSites()` (cf. § 3.3). Le contrat de sérialisation (groupes `category:read` / `site:read` dans le contexte) est posé **une seule fois** sur l'entité — source de vérité unique, le front ne le redéfinit pas.
|
||||
|
||||
> Dépendance confirmée sur le JSON réel (#82 mergé) : `Category` expose `code`/`name` sous `category:read` ; `Site` expose `name`/`postalCode`/`city`/`color` sous `site:read` (**pas de `code`**). L'embed est pleinement matérialisé.
|
||||
|
||||
@@ -213,6 +215,8 @@ Namespace : **`DoctrineMigrations` (racine `migrations/`)** — fichier `migrati
|
||||
|
||||
> **Rappel règle ABSOLUE n°12** : chaque colonne créée ci-dessous DOIT recevoir son `COMMENT ON COLUMN`. Les 4 colonnes Timestampable/Blamable passent par le helper `addStandardTimestampableBlamableComments($schema, '<table>')`. Le SQL ci-dessous montre la structure ; les `COMMENT ON COLUMN` (un par colonne métier) sont à écrire dans la migration (exemples §3.2.bis).
|
||||
|
||||
> **Types réels de la migration (le code fait foi)** : le SQL ci-dessous est *illustratif*. La migration mergée (`Version20260605130000`) utilise le **style aligné M1** : clés primaires en `INT GENERATED BY DEFAULT AS IDENTITY` (et **non** `SERIAL`) et horodatages en `TIMESTAMP(0) WITHOUT TIME ZONE` (et **non** `TIMESTAMPTZ`, car le `TimestampableBlamableTrait` mappe `datetime_immutable`). Garantit que `schema:update` reste un no-op une fois les entités mappées.
|
||||
|
||||
```sql
|
||||
-- =====================================================================
|
||||
-- Seed taxonomie : nouveau type FOURNISSEUR (référentiels comptables = M1, non recréés)
|
||||
@@ -422,8 +426,10 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
// Cohérence M1/ERP-62 : la LISTE embarque catégories + sites (pas de
|
||||
// champ dérivé aplati). Maillon (c) : category:read + site:read dans
|
||||
// le contexte pour exposer Category(code/name) + Site(name/postalCode).
|
||||
// ⚠ Le SupplierRepository DOIT fetch-join categories + addresses.sites
|
||||
// pour éviter le N+1 sur la liste (cf. § 2.12).
|
||||
// ⚠ Anti-N+1 : pas de fetch-join dans la requête de liste — le
|
||||
// SupplierRepository hydrate categories/sites/contacts via des requêtes
|
||||
// IN bornées séparées (hydrateListCollections), pour éviter le produit
|
||||
// cartésien sur les chemins non paginés (export) — cf. § 2.12.
|
||||
normalizationContext: ['groups' => [
|
||||
'supplier:read',
|
||||
'category:read',
|
||||
@@ -442,13 +448,14 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
normalizationContext: ['groups' => [
|
||||
'supplier:read',
|
||||
'supplier:item:read', // embed contacts / addresses
|
||||
'supplier:read:accounting', // scalaires compta + embed ribs (filtré par le Provider selon accounting.view)
|
||||
// ⚠ supplier:read:accounting est volontairement ABSENT ici : il est
|
||||
// AJOUTÉ dynamiquement par le SupplierReadGroupContextBuilder quand
|
||||
// l'user porte accounting.view (gating par ajout, pas par retrait —
|
||||
// parade bug #4 M1). Il porte les scalaires compta + l'embed ribs.
|
||||
'category:read', // embed des Category (id/code/name) — relation imbriquée
|
||||
'site:read', // embed des Site (id/name/postalCode/city/color, pas de code) — relation imbriquée
|
||||
'default:read',
|
||||
]],
|
||||
// Le Provider RETIRE supplier:read:accounting du contexte si l'user
|
||||
// n'a pas is_granted('commercial.suppliers.accounting.view').
|
||||
provider: SupplierProvider::class,
|
||||
),
|
||||
new Post(
|
||||
@@ -458,10 +465,13 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
processor: SupplierProcessor::class,
|
||||
),
|
||||
new Patch(
|
||||
security: "is_granted('commercial.suppliers.manage')",
|
||||
// Le SupplierProcessor inspecte les groupes envoyés pour autoriser
|
||||
// onglet par onglet (cf. § 2.10 + § 5). Patch des champs comptables
|
||||
// exige is_granted('commercial.suppliers.accounting.manage') ;
|
||||
// Security élargie : `manage` OU `accounting.manage` — le rôle Compta
|
||||
// n'a pas `manage` mais doit pouvoir éditer l'onglet Comptabilité d'un
|
||||
// fournisseur existant (§ 2.9). Le SupplierProcessor re-gate ensuite
|
||||
// onglet par onglet (mode strict RG-2.16) :
|
||||
security: "is_granted('commercial.suppliers.manage') or is_granted('commercial.suppliers.accounting.manage')",
|
||||
// Patch des champs comptables exige accounting.manage (guardAccounting) ;
|
||||
// champs main/information exigent manage (guardManage) ;
|
||||
// patch isArchived exige is_granted('commercial.suppliers.archive').
|
||||
normalizationContext: ['groups' => ['supplier:read', 'default:read']],
|
||||
denormalizationContext: ['groups' => [
|
||||
@@ -711,91 +721,108 @@ Même pattern que les jumelles `Client*` (`#[Auditable]`, `TimestampableBlamable
|
||||
| Scalaires Comptabilité (siren, refs…) | `supplier:read:accounting` | ✅ (gated) | refs (`tvaMode`…) id+label ∈ `supplier:read:accounting` |
|
||||
| `ribs[]` (label/bic/iban) | `ribs` ∈ `supplier:read:accounting` | ✅ (gated) | — |
|
||||
|
||||
### 4.0.bis Réponses JSON de référence (DoD — à confirmer sur l'API réelle)
|
||||
### 4.0.bis Réponses JSON de référence (DoD — RÉELLES, capturées ERP-92)
|
||||
|
||||
> **Definition of Done de cette spec back (RETEX M1 §3)** : avant d'écrire les tickets front, créer un fournisseur de test et **coller ici les réponses RÉELLES** de `GET /api/suppliers` et `GET /api/suppliers/{id}`. Les containers n'étant pas lancés au moment de la rédaction, le JSON ci-dessous est le **contrat CIBLE** — à valider/remplacer par la réponse réelle (`make start` puis `curl`). Toute donnée affichée par le front DOIT apparaître dans ce JSON.
|
||||
> **Definition of Done CLÔTURÉE (ERP-92, 2026-06-05)** : les réponses ci-dessous sont **réelles**, capturées sur l'API de test via PHPUnit (`SupplierSerializationContractTest`, fournisseur complet seedé). Les `id`/timestamps sont illustratifs (run de test). Toute donnée affichée par le front DOIT apparaître dans ce JSON. Front #93→#96 peuvent démarrer.
|
||||
>
|
||||
> **2 constats validés à la capture** (cf. § 4.0.ter) :
|
||||
> 1. 🔧 **Fix ERP-92** : les réfs comptables (`tvaMode`/`paymentDelay`/`paymentType`/`bank`) sortaient en **IRI nu** (les entités partagées ne portaient que `client:read:accounting`, pas `supplier:read:accounting`). Corrigé → objet `{id, code, label}` embarqué (le front consultation/édition affiche le libellé sans fetch).
|
||||
> 2. ℹ️ **Liste « riche »** : le groupe `supplier:read` étant partagé liste+détail, la **collection embarque tout le bloc Information** (et, pour un user `accounting.view`, les scalaires compta + `ribs[]`). Comportement identique au M1 (groupe `client:read` partagé) — la datatable n'affiche que Nom/Catégories/Site(s)/MAJ, mais le payload est complet. Le gating `accounting` reste effectif (Commerciale ne voit ni compta ni `ribs` en liste comme en détail).
|
||||
|
||||
> **Forme d'enveloppe confirmée sur le M1 réel** (API Platform 4.2) : JSON-LD **sans préfixe `hydra:`** → clés `member` / `totalItems` / `view`, avec `@type: "Collection"` et `view.@type: "PartialCollectionView"`. `Content-Type: application/ld+json; charset=utf-8`. Pagination défaut 10 confirmée. Login réel = `POST /api/login_check` (nginx réécrit vers `/login_check`), réponse `204` + cookie HttpOnly `BEARER`.
|
||||
|
||||
`GET /api/suppliers` (liste, ADMIN) :
|
||||
`GET /api/suppliers?search=…` (liste, ADMIN — un membre) :
|
||||
```json
|
||||
{
|
||||
"@context": "/api/contexts/Supplier",
|
||||
"@id": "/api/suppliers",
|
||||
"@type": "Collection",
|
||||
"totalItems": 13,
|
||||
"totalItems": 1,
|
||||
"member": [
|
||||
{
|
||||
"@id": "/api/suppliers/1",
|
||||
"@id": "/api/suppliers/85",
|
||||
"@type": "Supplier",
|
||||
"id": 1,
|
||||
"companyName": "RECYCLA SAS",
|
||||
"id": 85,
|
||||
"companyName": "DOD59393F 862875",
|
||||
"categories": [
|
||||
{"@id": "/api/categories/12", "id": 12, "code": "NEGOCIANT", "name": "Négociant"}
|
||||
{"@type": "Category", "@id": "/api/categories/2279", "id": 2279, "name": "test_cli_cat_fr_negociant", "code": "NEGOCIANT",
|
||||
"categoryType": {"@id": "/api/category_types/602", "@type": "CategoryType", "id": 602, "code": "FOURNISSEUR", "label": "Fournisseur"},
|
||||
"createdAt": "…", "updatedAt": "…"}
|
||||
],
|
||||
"description": "Fournisseur de test complet.",
|
||||
"competitors": "Concurrent A, Concurrent B",
|
||||
"foundedAt": "2008-04-01T00:00:00+02:00",
|
||||
"employeesCount": 42,
|
||||
"revenueAmount": "1500000.00",
|
||||
"directorName": "Jean Dupont",
|
||||
"profitAmount": "120000.00",
|
||||
"volumeForecast": 8000,
|
||||
"siren": "123456789",
|
||||
"accountNumber": "F0001",
|
||||
"tvaMode": {"@id": "/api/tva_modes/30", "@type": "TvaMode", "id": 30, "code": "FRANCE_VENTES", "label": "France (ventes)"},
|
||||
"nTva": "FR00123456789",
|
||||
"paymentDelay": {"@id": "/api/payment_delays/11", "@type": "PaymentDelay", "id": 11, "code": "J30", "label": "30 jours"},
|
||||
"paymentType": {"@id": "/api/payment_types/14", "@type": "PaymentType", "id": 14, "code": "LCR", "label": "LCR"},
|
||||
"ribs": [
|
||||
{"@id": "/api/supplier_ribs/27", "@type": "SupplierRib", "id": 27, "label": "Compte principal", "bic": "BNPAFRPPXXX", "iban": "FR1420041010050500013M02606", "createdAt": "…", "updatedAt": "…"}
|
||||
],
|
||||
"createdAt": "…", "updatedAt": "…",
|
||||
"sites": [
|
||||
{"@id": "/api/sites/1", "id": 1, "name": "Chatellerault", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2"},
|
||||
{"@id": "/api/sites/2", "id": 2, "name": "Saint-Jean", "postalCode": "17400", "city": "Fontenet", "color": "#…"}
|
||||
{"@type": "Site", "@id": "/api/sites/87", "id": 87, "name": "Chatellerault", "street": "14 All. d'Argenson", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2", "fullAddress": "14 All. d'Argenson\n86100 Châtellerault"},
|
||||
{"@type": "Site", "@id": "/api/sites/88", "id": 88, "name": "Saint-Jean", "street": "Z i", "postalCode": "17400", "city": "Fontenet", "color": "#F3CB00", "fullAddress": "Z i\n17400 Fontenet"}
|
||||
],
|
||||
"updatedAt": "2026-02-17T09:30:00+00:00",
|
||||
"isArchived": false
|
||||
}
|
||||
],
|
||||
"view": {
|
||||
"@id": "/api/suppliers?page=1",
|
||||
"@type": "PartialCollectionView",
|
||||
"first": "/api/suppliers?page=1",
|
||||
"last": "/api/suppliers?page=2",
|
||||
"next": "/api/suppliers?page=2"
|
||||
}
|
||||
"view": {"@id": "/api/suppliers?search=…", "@type": "PartialCollectionView"}
|
||||
}
|
||||
```
|
||||
|
||||
> Les fournisseurs archivés sont **exclus** du `totalItems` (sur le M1, 14 clients en base → `totalItems: 13` car 1 archivé filtré par le Provider). `categories[]` (avec `code`/`name`) et `sites[]` (avec `name`/`postalCode` — **pas de `code`**) sont **embarqués** (cohérence M1/ERP-62, § 2.12) ; `sites` est l'agrégat dédoublonné des adresses via `Supplier::getSites()`. Fetch-joins repository obligatoires (anti N+1).
|
||||
> Les fournisseurs archivés sont **exclus** du `totalItems` (RG-2.17 — filtré par le Provider). `categories[]` (avec `code`/`name`) et `sites[]` (avec `name`/`postalCode` — **pas de `code`**) sont **embarqués** (cohérence M1/ERP-62, § 2.12) ; `sites` est l'agrégat dédoublonné des adresses via `Supplier::getSites()`. Fetch-joins repository (anti N+1) **vérifiés par test** (`SupplierListTest::testListQueryCountDoesNotGrowWithRowCount` : nombre de requêtes constant entre 2 et 4 fournisseurs). ⚠️ Le membre embarque aussi l'**Information complète** et — pour un user `accounting.view` (ici admin) — les **scalaires compta + `ribs[]`** (groupe `supplier:read` partagé liste/détail). Pour la **Commerciale** (sans `accounting.view`), `siren`/`tvaMode`/`paymentType`/`ribs`… **disparaissent** de chaque membre.
|
||||
|
||||
`GET /api/suppliers/1` (détail — user avec `accounting.view`) :
|
||||
`GET /api/suppliers/85` (détail — user avec `accounting.view`) :
|
||||
```json
|
||||
{
|
||||
"@id": "/api/suppliers/1",
|
||||
"@context": "/api/contexts/Supplier",
|
||||
"@id": "/api/suppliers/85",
|
||||
"@type": "Supplier",
|
||||
"id": 1,
|
||||
"companyName": "RECYCLA SAS",
|
||||
"id": 85,
|
||||
"companyName": "DOD59393F 862875",
|
||||
"categories": [
|
||||
{"@id": "/api/categories/12", "id": 12, "code": "NEGOCIANT", "name": "Négociant"}
|
||||
{"@type": "Category", "@id": "/api/categories/2279", "id": 2279, "name": "test_cli_cat_fr_negociant", "code": "NEGOCIANT",
|
||||
"categoryType": {"@id": "/api/category_types/602", "@type": "CategoryType", "id": 602, "code": "FOURNISSEUR", "label": "Fournisseur"}}
|
||||
],
|
||||
"description": "…", "competitors": "…", "foundedAt": "2008-04-01",
|
||||
"employeesCount": 42, "revenueAmount": "1500000.00", "directorName": "…",
|
||||
"profitAmount": "120000.00", "volumeForecast": 8000,
|
||||
"description": "Fournisseur de test complet.", "competitors": "Concurrent A, Concurrent B",
|
||||
"foundedAt": "2008-04-01T00:00:00+02:00", "employeesCount": 42, "revenueAmount": "1500000.00",
|
||||
"directorName": "Jean Dupont", "profitAmount": "120000.00", "volumeForecast": 8000,
|
||||
"siren": "123456789", "accountNumber": "F0001",
|
||||
"tvaMode": {"@id": "/api/tva_modes/30", "@type": "TvaMode", "id": 30, "code": "FRANCE_VENTES", "label": "France (ventes)"},
|
||||
"nTva": "FR00123456789",
|
||||
"paymentDelay": {"@id": "/api/payment_delays/11", "@type": "PaymentDelay", "id": 11, "code": "J30", "label": "30 jours"},
|
||||
"paymentType": {"@id": "/api/payment_types/14", "@type": "PaymentType", "id": 14, "code": "LCR", "label": "LCR"},
|
||||
"contacts": [
|
||||
{"@id": "/api/supplier_contacts/1", "id": 1, "firstName": "Marie", "lastName": "Martin",
|
||||
"jobTitle": "Responsable achats", "phonePrimary": "0612345678", "phoneSecondary": null,
|
||||
"email": "marie.martin@recycla.fr"}
|
||||
{"@id": "/api/supplier_contacts/39", "@type": "SupplierContact", "id": 39, "firstName": "Marie", "lastName": "Martin",
|
||||
"jobTitle": "Responsable achats", "phonePrimary": "0612345678", "email": "marie.martin@seed.test"}
|
||||
],
|
||||
"addresses": [
|
||||
{"@id": "/api/supplier_addresses/1", "id": 1, "addressType": "DEPART",
|
||||
"country": "France", "postalCode": "86000", "city": "Poitiers",
|
||||
"street": "12 rue des Acacias", "streetComplement": null,
|
||||
{"@id": "/api/supplier_addresses/33", "@type": "SupplierAddress", "id": 33, "addressType": "DEPART",
|
||||
"country": "France", "postalCode": "86000", "city": "Poitiers", "street": "12 rue des Acacias",
|
||||
"bennes": 3, "triageProvider": true,
|
||||
"sites": [{"@id": "/api/sites/1", "id": 1, "name": "Chatellerault", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2"}],
|
||||
"categories": [{"@id": "/api/categories/12", "id": 12, "code": "NEGOCIANT", "name": "Négociant"}],
|
||||
"contacts": [{"@id": "/api/supplier_contacts/1", "id": 1, "firstName": "Marie", "lastName": "Martin"}]}
|
||||
"sites": [
|
||||
{"@type": "Site", "@id": "/api/sites/87", "id": 87, "name": "Chatellerault", "postalCode": "86100", "city": "Châtellerault", "color": "#056CF2"},
|
||||
{"@type": "Site", "@id": "/api/sites/88", "id": 88, "name": "Saint-Jean", "postalCode": "17400", "city": "Fontenet", "color": "#F3CB00"}
|
||||
],
|
||||
"contacts": [{"@id": "/api/supplier_contacts/39", "@type": "SupplierContact", "id": 39, "firstName": "Marie", "lastName": "Martin"}],
|
||||
"categories": [{"@type": "Category", "@id": "/api/categories/2279", "id": 2279, "name": "test_cli_cat_fr_negociant", "code": "NEGOCIANT"}]}
|
||||
],
|
||||
"siren": "123456789", "accountNumber": "F0001",
|
||||
"tvaMode": {"@id": "/api/tva_modes/1", "id": 1, "label": "France (ventes)"},
|
||||
"nTva": "FR00123456789",
|
||||
"paymentDelay": {"@id": "/api/payment_delays/2", "id": 2, "label": "30 jours"},
|
||||
"paymentType": {"@id": "/api/payment_types/2", "id": 2, "code": "LCR", "label": "LCR"},
|
||||
"bank": null,
|
||||
"ribs": [
|
||||
{"@id": "/api/supplier_ribs/1", "id": 1, "label": "Compte principal",
|
||||
"bic": "SOGEFRPP", "iban": "FR7630003035400005000000123"}
|
||||
{"@id": "/api/supplier_ribs/27", "@type": "SupplierRib", "id": 27, "label": "Compte principal", "bic": "BNPAFRPPXXX", "iban": "FR1420041010050500013M02606"}
|
||||
],
|
||||
"isArchived": false, "archivedAt": null,
|
||||
"updatedAt": "2026-02-17T09:30:00+00:00"
|
||||
"isArchived": false
|
||||
}
|
||||
```
|
||||
|
||||
> Pour un user **sans** `accounting.view` (ex. Commerciale) : les clés `siren`, `accountNumber`, `tvaMode`, `nTva`, `paymentDelay`, `paymentType`, `bank`, `ribs` **sont absentes** (pas `null` — réellement non sérialisées car le Provider retire le groupe). Le gating par **omission de clé** est confirmé confortable côté front. Le blame `updatedBy` est sérialisé en **IRI** (`"/api/me"` quand c'est l'user courant) — en tenir compte côté front.
|
||||
> Pour un user **sans** `accounting.view` (ex. Commerciale) : les clés `siren`, `accountNumber`, `tvaMode`, `nTva`, `paymentDelay`, `paymentType`, `bank`, `ribs` **sont absentes** (pas `null` — réellement non sérialisées : le `SupplierReadGroupContextBuilder` n'ajoute pas le groupe). Gating par **omission de clé** confirmé sur le JSON réel (`SupplierSerializationContractTest::testRibsAbsentForCommercialeWithoutAccountingView` + `testAccountingScalarsGatedByOmission`). `bennes`/`triageProvider`/`addressType`/`addresses[].contacts` restent visibles (onglet Adresse non gaté). NB : ici `bank` est absent (paymentType=LCR sans banque) ; avec un VIREMENT, `bank` est embarqué `{id, code, label}` (fix ERP-92).
|
||||
|
||||
### 4.0.ter Pièges de sérialisation CONSTATÉS sur le M1 réel → parade M2 (OBLIGATOIRE)
|
||||
|
||||
@@ -1046,7 +1073,7 @@ Le M1 a subi un aller-retour (ERP-68) faute de fixtures alignées. Pour le M2, p
|
||||
|
||||
- [x] 3 maillons de sérialisation documentés pour chaque champ liste + détail (§ 4.0)
|
||||
- [x] Décision embed vs GetCollection explicite et câblée (embed détail + sous-ressources write — § 3.3 / § 3.4 / § 4.5), **pas de POST-only**
|
||||
- [ ] **Réponses JSON RÉELLES** collées (§ 4.0.bis) — *en attente de `make start` + curl (DoD avant tickets front)*
|
||||
- [x] **Réponses JSON RÉELLES** collées (§ 4.0.bis) — capturées via PHPUnit (ERP-92, 2026-06-05) ; fix réfs compta IRI→{id,label} inclus
|
||||
- [x] Matrice RBAC rôle × onglet + mode strict PATCH (§ 2.9 / RG-2.16)
|
||||
- [x] Pagination (n°13), COMMENT ON COLUMN (n°12), Timestampable/Blamable, Audit, routes à plat : rappelés
|
||||
- [x] Réutilisations M1 identifiées (référentiels compta partagés, taxonomie code/type, `usePaginatedList`, blocs, archive, normalisation)
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
---
|
||||
# === IDENTITÉ ===
|
||||
module: M6
|
||||
nom: "Tournées commerciales terrain"
|
||||
ecran: tournees-terrain
|
||||
owner_spec: Matthieu
|
||||
backup_spec: ""
|
||||
version: V0.2
|
||||
# Historique :
|
||||
# V0.2 (2026-06-11) — RÉDUCTION DE SCOPE : suppression du volet « rapport de visite »
|
||||
# (entité VisitReport, fichiers, offres de prix, note /5, saisie vocale, historique des
|
||||
# visites) et du mode terrain mobile dédié. Périmètre recentré sur : géolocalisation,
|
||||
# carte interactive, planification de tournées, et onglet « Carte » dans les fiches Tiers.
|
||||
# V0.1 (2026-06-11) — Rédaction initiale (inspirée de Badger Maps, SPOTIO, Portatour, Nomadia).
|
||||
date_redaction: 2026-06-11
|
||||
|
||||
# === LIENS ===
|
||||
spec_front: ./spec-front.md
|
||||
maquette_figma: ""
|
||||
|
||||
# === LIEN LESSTIME ===
|
||||
lesstime_taskgroup_id: 28 # M6 — Tournées commerciales terrain (projet STARSEED #6)
|
||||
lesstime_project_id: 6
|
||||
statut_global: en_dev
|
||||
|
||||
# === DÉPENDANCES AMONT ===
|
||||
depend_de:
|
||||
- M1-clients # Client / ClientAddress (cible de visite + onglet Carte)
|
||||
- M2-suppliers # Supplier / SupplierAddress (cible de visite + onglet Carte)
|
||||
- Sites # rattachement site d'une adresse (déjà en place)
|
||||
- Core # User (commercial), Role, Permission, JWT
|
||||
- Shared # TimestampableBlamableTrait + contrats inter-modules
|
||||
---
|
||||
|
||||
# Spec — Module 6 : Tournées commerciales terrain (`field_sales`)
|
||||
|
||||
> **Périmètre V0.2 (réduit)** : géolocalisation des adresses Tiers, carte interactive, planification
|
||||
> de tournées (étapes, optimisation, navigation Waze/Maps, feuille de route PDF) et onglet « Carte »
|
||||
> dans les fiches Client/Fournisseur. **Hors scope : tout rapport de visite** (compte-rendu, note,
|
||||
> offres de prix, fichiers, saisie vocale) et le mode terrain mobile dédié.
|
||||
|
||||
## 1. Contexte & objectif
|
||||
|
||||
Donner aux commerciaux terrain (technico-commerciaux agricoles : visites d'exploitations, coopératives,
|
||||
négoces) un outil de **planification de tournées** intégré à Starseed, reposant sur le référentiel Tiers
|
||||
existant (Clients M1 + Fournisseurs M2). Fonctionne sur **desktop et mobile/tablette** (responsive, pas
|
||||
d'offline en V1).
|
||||
|
||||
Le commercial doit pouvoir :
|
||||
|
||||
1. Voir ses Tiers sur une **carte interactive** (pins colorés par type : client / fournisseur / prospect / custom).
|
||||
2. **Construire une tournée lui-même** : ajouter des étapes (une étape = une adresse précise d'un Tiers ou un
|
||||
point libre), les **réordonner en drag & drop**, fixer une **heure de départ**.
|
||||
3. Obtenir le **temps total** et le **temps entre chaque étape** (calcul auto), avec heure d'arrivée estimée.
|
||||
4. Cliquer **« Trajet logique »** (V1, heuristique gratuite) puis **« Optimiser »** (V2, routier réel) pour
|
||||
ordonner les étapes au mieux.
|
||||
5. **Lancer la navigation** (Waze / Google Maps / Plan) vers une étape en un tap.
|
||||
6. **Dupliquer** une tournée et **exporter une feuille de route PDF**.
|
||||
7. Consulter un **onglet « Carte »** dans la fiche Client/Fournisseur affichant les adresses géolocalisées du Tiers.
|
||||
|
||||
## 2. Inspiration — logiciels de tournée de référence
|
||||
|
||||
| Logiciel | Pattern repris | Application Starseed |
|
||||
|---|---|---|
|
||||
| **Badger Maps** | *Lasso tool* : on entoure des Tiers sur la carte → route optimisée auto. Pins colorés par type. | Sélection lasso/rectangle sur la carte pour bâtir la tournée. Pins par type. |
|
||||
| **SPOTIO** | Réordonnancement **drag & drop**, lieu de départ + bouton *Optimize*. | Liste d'étapes draggable, point de départ paramétrable, boutons « Trajet logique » / « Optimiser ». |
|
||||
| **Portatour** | Optimisation en quelques secondes, temps entre RDV. | Durée de visite paramétrable par étape, intégrée au temps total. |
|
||||
| **Nomadia Field Sales** | Carte + tournée dans un outil mobile responsive. | Écran de planification responsive desktop + mobile. |
|
||||
|
||||
## 3. Décisions d'architecture
|
||||
|
||||
### 3.1 Nouveau module `field_sales`
|
||||
|
||||
La tournée est **transverse** : elle vise aussi bien des Clients (M1) que des Fournisseurs (M2). Module dédié
|
||||
`src/Module/FieldSales/` (ID `field_sales`, label « Tournées »), `REQUIRED = false` (activable via
|
||||
`config/modules.php`).
|
||||
|
||||
**Règle ABSOLUE n°1 respectée** : `FieldSales` n'importe **aucune** classe de `Commercial`. Il référence les
|
||||
Tiers visités via un **contrat partagé** `App\Shared\Domain\Contract\VisitableInterface` (`getId()`,
|
||||
`getDisplayName()`, `getVisitableType()` = `client|supplier`) résolu par `resolve_target_entities`, comme
|
||||
`ClientAddress` référence `SiteInterface` / `CategoryInterface`.
|
||||
|
||||
### 3.1.bis Une étape vise tout Tiers — et même un point libre
|
||||
|
||||
Une étape n'est pas limitée à Client/Fournisseur : elle vise **tout type de Tiers** (Client, Fournisseur,
|
||||
**Prestataire** à venir) via `VisitableInterface` (extensible sans toucher au module FieldSales), **ou un point
|
||||
`custom`** (prospect/RDV sans fiche : libellé + adresse + coordonnées saisis à la main). L'enum `tier_type` est
|
||||
volontairement **ouvert** (string + Assert\Choice = types Visitable enregistrés + `custom`).
|
||||
|
||||
### 3.2 Géolocalisation portée par l'adresse Tiers — **FAIT (ticket M6.1 / ERP-122)**
|
||||
|
||||
`latitude` / `longitude` / `geo_manual` / `geocoded_at` sur `client_address` et `supplier_address`, géocodage
|
||||
api-adresse.data.gouv.fr + pin ajustable. Prérequis routage : une étape sans coordonnées reste utilisable mais
|
||||
**exclue du calcul de trajet** (badge « à géolocaliser »).
|
||||
|
||||
### 3.3 Carte interactive — Leaflet + OpenStreetMap (pas Google Maps JS)
|
||||
|
||||
Pour l'**affichage** carte/pins : **Leaflet** + tuiles **OpenStreetMap** (ou IGN). Gratuit, RGPD-friendly, pas
|
||||
de clé facturée pour le rendu. Composant carte encapsulé dans `frontend/modules/field-sales/` ; côté
|
||||
formulaire/filtre on reste sur les composants `Malio*`. La carte est une **exception documentée** à
|
||||
`@malio/layer-ui` (type non couvert). Le **routing réel** (matrice de temps) est un service distinct (§ 3.4).
|
||||
|
||||
### 3.4 Stratégie de calcul de trajet — phasée
|
||||
|
||||
| Phase | Bouton | Moteur | Coût |
|
||||
|---|---|---|---|
|
||||
| **V1** | « Trajet logique » | Heuristique maison **plus proche voisin** (Haversine), départ fixé. Temps estimé = distance × vitesse moyenne paramétrable. | 0 € |
|
||||
| **V2** | « Optimiser » | **Matrix API** (temps routiers réels) + optimisation TSP (OpenRouteService / OSRM / Mapbox). | Par appel (cache, debounce) |
|
||||
|
||||
Contrat `RouteEngineInterface` (`computeMatrix`, `optimizeOrder`, `estimateLegDurations`) posé dès la V1 avec
|
||||
`HaversineRouteEngine`. La V2 ajoute `OrsRouteEngine` sans toucher au front. **On n'écrit jamais l'algo routier
|
||||
— on branche un fournisseur.**
|
||||
|
||||
### 3.5 IDs entier auto-increment, Audit, Timestampable/Blamable
|
||||
|
||||
Cohérent avec M0/M1/M2. Toutes les entités métier : `#[Auditable]`, `implements TimestampableInterface,
|
||||
BlamableInterface` + `use TimestampableBlamableTrait`. Entités auditées : `Tour`, `TourStop`.
|
||||
|
||||
## 4. Modèle de données
|
||||
|
||||
### 4.1 Adresses Tiers (M1 + M2) — **FAIT (ERP-122)**
|
||||
|
||||
Colonnes `latitude` NUMERIC(10,7), `longitude` NUMERIC(10,7), `geo_manual` BOOLEAN, `geocoded_at` TIMESTAMPTZ
|
||||
sur `client_address` et `supplier_address` ; contrat `GeolocatableAddressInterface` côté `Shared`.
|
||||
|
||||
### 4.2 `Tour` (tournée) — `tour`
|
||||
|
||||
| Champ | Type | Règle |
|
||||
|---|---|---|
|
||||
| `id` | int PK | |
|
||||
| `owner_id` | FK User | Commercial propriétaire. Tournée **personnelle** (RG-6.01). |
|
||||
| `label` | varchar(120) | Nom libre. NotBlank. |
|
||||
| `tour_date` | date | Date de réalisation. NotBlank. |
|
||||
| `departure_time` | time | Heure de départ (alimente les ETA). Défaut 08:00. |
|
||||
| `start_latitude` / `start_longitude` | numeric null | Point de départ (site commercial ou adresse libre). NULL → départ = 1re étape. |
|
||||
| `start_label` | varchar(180) null | Libellé du point de départ. |
|
||||
| `default_visit_minutes` | smallint default 30 | Durée de visite par défaut (temps total). |
|
||||
| `status` | enum `draft\|planned\|in_progress\|done` | Cycle de vie (RG-6.02). |
|
||||
| `total_distance_m` / `total_duration_s` | int null | Derniers totaux calculés (cache d'affichage). |
|
||||
|
||||
`#[Auditable]`, Timestampable/Blamable, soft delete (`deleted_at`). `GetCollection` paginée, filtrée par owner.
|
||||
|
||||
### 4.3 `TourStop` (étape) — `tour_stop`
|
||||
|
||||
| Champ | Type | Règle |
|
||||
|---|---|---|
|
||||
| `id` | int PK | |
|
||||
| `tour_id` | FK Tour | onDelete CASCADE. |
|
||||
| `tier_type` | string `client\|supplier\|…\|custom` | Cible (résolue via `VisitableInterface`). `custom` = point libre. |
|
||||
| `tier_id` | int null | ID du Tiers référentiel. NULL si `custom`. |
|
||||
| `address_id` | int null | Adresse précise visitée (un Tiers a plusieurs adresses — RG-6.03). NULL si `custom`. |
|
||||
| `custom_label` | varchar(180) null | Libellé du point libre (obligatoire ssi `custom`). |
|
||||
| `custom_address` | varchar(255) null | Adresse texte du point libre (ssi `custom`), géocodée. |
|
||||
| `custom_latitude` / `custom_longitude` | numeric null | Coordonnées du point libre (pin ajustable). |
|
||||
| `position` | smallint | Ordre dans la tournée (drag & drop). |
|
||||
| `visit_minutes` | smallint null | Durée de visite spécifique (sinon `tour.default_visit_minutes`). |
|
||||
| `leg_distance_m` / `leg_duration_s` | int null | Distance/temps **depuis l'étape précédente** (calculés). |
|
||||
| `eta` | time null | Heure d'arrivée estimée. |
|
||||
|
||||
`#[Auditable]`, Timestampable/Blamable. Unicité `(tour_id, position)`. **Pas** de rapport rattaché (scope réduit).
|
||||
|
||||
> Deux étapes peuvent viser le même Tiers (RG-6.07) — pas d'unicité sur `tier_id`.
|
||||
|
||||
## 5. API (API Platform — providers/processors, jamais de controller)
|
||||
|
||||
| Méthode | Endpoint | Sécurité | Note |
|
||||
|---|---|---|---|
|
||||
| GET | `/api/tours` | `field_sales.tours.view` | Paginé, filtré sur `owner` courant (admin/bureau voient tout). |
|
||||
| POST | `/api/tours` | `field_sales.tours.manage` | Crée une tournée draft. |
|
||||
| GET/PATCH/DELETE | `/api/tours/{id}` | view / manage | DELETE = soft delete. |
|
||||
| POST | `/api/tours/{tourId}/stops` | `field_sales.tours.manage` | Sous-ressource (Link toProperty `tour`, pattern ClientAddress). |
|
||||
| PATCH/DELETE | `/api/tour_stops/{id}` | `field_sales.tours.manage` | PATCH `position` = drag & drop. |
|
||||
| POST | `/api/tours/{id}/compute` | `field_sales.tours.manage` | Recalcule legs + ETA + totaux (`HaversineRouteEngine`). |
|
||||
| POST | `/api/tours/{id}/optimize` | `field_sales.tours.manage` | Réordonne via `optimizeOrder()` puis recompute. |
|
||||
| POST | `/api/tours/{id}/duplicate` | `field_sales.tours.manage` | Duplique étapes + départ à une nouvelle `tourDate` (RG-6.13). |
|
||||
| GET | `/api/tours/{id}/roadbook.pdf` | `field_sales.tours.view` | Feuille de route PDF (skill `pdf`). |
|
||||
| GET | `/api/visitable_tiers?bbox=...&q=...&type=client,supplier` | `field_sales.tours.view` | Pins dans la zone visible (carte). Paginé / `?pagination=false`. |
|
||||
|
||||
Toutes les collections sont **paginées** (règle ABSOLUE n°13). `/api/visitable_tiers` retourne un Paginator,
|
||||
borné par `bbox`.
|
||||
|
||||
## 6. Écrans
|
||||
|
||||
### 6.1 Planification de tournée (carte interactive — responsive desktop + mobile)
|
||||
|
||||
Layout **split** inspiré de Badger/SPOTIO :
|
||||
|
||||
- **Carte interactive Leaflet** : pins des Tiers de la zone (couleur par type, filtrables). Sélection
|
||||
**lasso/rectangle** → ajoute les Tiers entourés comme étapes. Clic pin → popup (nom, adresse, « + Ajouter »).
|
||||
Tracé de la tournée dessiné par-dessus (polyline numérotée).
|
||||
- **Panneau tournée** : nom, date, **heure de départ**, point de départ, liste d'**étapes draggable**
|
||||
(n° + nom + adresse + ETA + temps depuis étape précédente), totaux (distance / durée / nb visites).
|
||||
Boutons **« Trajet logique »**, **« Optimiser »**, **« Dupliquer »**, **« PDF »**.
|
||||
- Chaque étape : menu **« Y aller »** (Waze / Google Maps / Plan via deep links), « Voir le Tiers ».
|
||||
- Ajout d'un **point libre `custom`** (libellé + adresse + pin).
|
||||
- En mobile, layout empilé : la navigation se fait via le bouton « Y aller » de chaque étape (pas de mode
|
||||
terrain dédié).
|
||||
|
||||
### 6.2 Onglet « Carte » dans la fiche Client / Fournisseur
|
||||
|
||||
Nouvel onglet **« Carte »** dans la fiche **Client (M1)** et **Fournisseur (M2)** : **mini-carte Leaflet**
|
||||
affichant **toutes les adresses géolocalisées du Tiers** (un marqueur par adresse, popup avec le libellé de
|
||||
l'adresse). Vue d'ensemble des implantations du Tiers. Le **pin reste ajustable** par adresse (réutilise le
|
||||
composant de l'onglet Adresse, déjà livré en ERP-122). Adresses sans coordonnées listées comme
|
||||
« à géolocaliser ». Onglet visible sous `field_sales.tours.view` ; masqué si le module `field_sales` est désactivé.
|
||||
|
||||
### 6.3 Ajustement du pin (fiche adresse) — **FAIT (ERP-122)**
|
||||
|
||||
Mini-carte Leaflet avec marqueur déplaçable dans le bloc adresse M1/M2 ; drag → `latitude/longitude` +
|
||||
`geo_manual = true` ; bouton « Re-géocoder depuis l'adresse ».
|
||||
|
||||
## 7. Géocodage des adresses — **FAIT (ERP-122)**
|
||||
|
||||
Service `GeocoderInterface` / `BanGeocoder` (api-adresse.data.gouv.fr). Correction manuelle systématique via le
|
||||
pin (`geo_manual = true` fige — RG-6.08).
|
||||
|
||||
## 8. RBAC — 3 miroirs obligatoires
|
||||
|
||||
Permissions du module `field_sales` (méthode `permissions()` de `FieldSalesModule.php`) — **uniquement les
|
||||
tournées** (plus de permissions `reports.*` depuis la réduction de scope) :
|
||||
|
||||
| Permission | Sens | Admin | Commerciale | Bureau |
|
||||
|---|---|---|---|---|
|
||||
| `field_sales.tours.view` | Voir les tournées + l'onglet Carte. | ✅ (toutes) | ✅ (les siennes) | ✅ (consultation) |
|
||||
| `field_sales.tours.manage` | Créer/éditer/optimiser/dupliquer/supprimer une tournée. | ✅ | ✅ | ❌ |
|
||||
|
||||
Attribution : **Commerciale + Admin** = manage ; **Bureau** = view ; Compta exclue. À synchroniser dans les
|
||||
**3 miroirs** (règle ABSOLUE n°8) : `config/sidebar.php` (section « Tournées » : item `tours` + i18n
|
||||
`sidebar.field_sales.*`), `frontend/tests/e2e/_fixtures/personas.ts`, `SeedE2ECommand.php`. Sync :
|
||||
`app:sync-permissions`.
|
||||
|
||||
## 9. Conventions & garde-fous (rappel)
|
||||
|
||||
- `declare(strict_types=1);` partout ; commentaires FR, code EN.
|
||||
- Entités métier : `#[Auditable]` + Timestampable/Blamable. Libellés i18n `audit.entity.field_sales_tour` /
|
||||
`_tourstop` dans `fr.json` (sinon `AuditableEntitiesHaveI18nLabelTest` casse `make test`).
|
||||
- Migration modulaire : `COMMENT ON COLUMN` sur **chaque** colonne (FR ≤ 200 car.) + helper
|
||||
`addStandardTimestampableBlamableComments()`.
|
||||
- Toute collection paginée (`CollectionsArePaginatedTest`).
|
||||
- Front : `useApi()` uniquement, composants `Malio*`, `MalioDataTable` + `usePaginatedList` pour les listes,
|
||||
**pas d'état de tableau dans l'URL**. Carte Leaflet = exception documentée.
|
||||
|
||||
## 10. Règles de gestion (RG)
|
||||
|
||||
| RG | Règle | Garde-fou |
|
||||
|---|---|---|
|
||||
| **RG-6.01** | Tournée **personnelle** (`owner`). Commerciale ne voit/édite que les siennes ; Admin/Bureau voient tout en lecture. | Filtre Provider sur `owner` + RBAC. |
|
||||
| **RG-6.02** | Cycle de vie `draft → planned → in_progress → done` (transitions libres en V1). | Enum + Assert\Choice. |
|
||||
| **RG-6.03** | Une étape sur Tiers référentiel vise une adresse de ce Tiers (qui en a plusieurs). Ne s'applique pas aux `custom`. | Assert\Callback. |
|
||||
| **RG-6.05** | Une étape n'entre dans le calcul que si son adresse a `latitude` ET `longitude`. Sinon « à géolocaliser », exclue des totaux. | `RouteEngine` + signalement front. |
|
||||
| **RG-6.07** | Deux étapes peuvent viser le même Tiers (repasser plus tard). Unicité uniquement sur `(tour_id, position)`. | Index unique partiel. |
|
||||
| **RG-6.08** | `geo_manual = true` fige les coordonnées (le géocodage auto ne réécrit plus). | Garde dans le géocodeur (FAIT). |
|
||||
| **RG-6.11** | `eta` = `departure_time` + Σ(trajets précédents) + Σ(durées de visite précédentes). | `RouteEngine::estimateLegDurations()`. |
|
||||
| **RG-6.12** | Une étape vise tout Tiers ou un point `custom`. Si `custom` : `tier_id`/`address_id` NULL, `custom_label` + coordonnées obligatoires. | Assert\Choice + Assert\Callback. |
|
||||
| **RG-6.13** | Dupliquer copie départ + étapes (ordre/adresses/durées) à une nouvelle date ; ne copie pas les calculs (ETA/legs recalculés). | Service `TourDuplicator`. |
|
||||
|
||||
## 11. Tests à automatiser
|
||||
|
||||
- **Architecture (cassent `make test`)** : `ColumnsHaveSqlCommentTest`, `AuditableEntitiesHaveI18nLabelTest`
|
||||
(`audit.entity.field_sales_tour` / `_tourstop`), `EntitiesAreTimestampableBlamableTest` (Tour, TourStop),
|
||||
`CollectionsArePaginatedTest`, `EntityConstraintsHaveFrenchMessageTest`.
|
||||
- **Back (PHPUnit)** : RG-6.03 (adresse hors Tiers → 422), RG-6.05 (étape sans coord exclue), RG-6.07 (doublon
|
||||
Tiers accepté), RG-6.11 (ETA), RG-6.12 (custom cohérent), RG-6.13 (duplication sans calculs), filtre `owner`,
|
||||
`HaversineRouteEngine` (ordre plus proche voisin sur un jeu de coordonnées connu).
|
||||
- **Front (Vitest)** : `usePaginatedList` sur tournées, composable de planification (réordonnancement, totaux,
|
||||
deep links), onglet Carte (marqueurs des adresses). **Pas de E2E** (règle d'or).
|
||||
|
||||
## 12. Hors-périmètre (HP)
|
||||
|
||||
- **HP-M6-1** : **rapport de visite** (compte-rendu, note /5, offres de prix, fichiers, catégorie, saisie
|
||||
vocale, historique des visites) — **retiré du scope (V0.2)**, à réintroduire dans un module/lot ultérieur si besoin.
|
||||
- **HP-M6-2** : mode terrain mobile dédié (vue du jour + check-in) — retiré ; navigation via l'écran de
|
||||
planification responsive.
|
||||
- **HP-M6-3** : routing routier réel + optimisation TSP (Matrix API) — V2 (V1 = heuristique Haversine).
|
||||
- **HP-M6-4** : suggestion automatique des Tiers « à visiter » (façon Portatour) — V2.
|
||||
- **HP-M6-5** : offline réel (PWA + synchro) — V3.
|
||||
- **HP-M6-6** : partage / affectation de tournées entre commerciaux, planning d'équipe — V3.
|
||||
- **HP-M6-7** : navigation multi-étapes poussée dans Waze (impossible techniquement) — navigation étape par étape.
|
||||
|
||||
## 13. Phasage
|
||||
|
||||
- **V1 (livrable)** : géoloc adresses + pin (FAIT) ; carte interactive + lasso ; tournée (création, drag & drop,
|
||||
heure de départ, point de départ) sur tout Tiers + point `custom` ; **« Trajet logique »** + ETA + totaux ;
|
||||
deep links Waze/Maps ; **duplication** ; **feuille de route PDF** ; **onglet Carte** dans les fiches
|
||||
Client/Fournisseur ; responsive desktop + mobile.
|
||||
- **V2** : bouton **« Optimiser »** (routing routier réel ORS/OSRM), temps trafic, suggestion des Tiers proches.
|
||||
- **V3** : offline réel, partage/affectation de tournées.
|
||||
|
||||
## 14. Risques / points ouverts
|
||||
|
||||
- **Coût/quota routing en V2** : multi-tenant → cache, debounce, plafonds par tenant.
|
||||
- **Limite Waze multi-étapes** : Waze ne prend qu'une destination → navigation étape par étape (assumé).
|
||||
- **Reste à cadrer techniquement** : périmètre de visibilité Bureau (toutes les tournées vs les siennes).
|
||||
|
||||
---
|
||||
|
||||
## 📦 Tickets Lesstime (scope réduit V0.2)
|
||||
|
||||
TaskGroup Lesstime : **#28 — M6 Tournées commerciales terrain** (projet STARSEED #6). Tickets gros grain, chacun
|
||||
avec un **prompt Fable** prêt à coller (consigne « adapte-toi à la config actuelle » incluse).
|
||||
|
||||
| # | Réf | Ticket | Effort | Tag | État |
|
||||
|---|---|---|---|---|---|
|
||||
| M6.1 | ERP-122 | Géolocaliser les adresses Tiers (lat/lng + pin) | L | Back+Front | ✅ Fait |
|
||||
| M6.2 | ERP-123 | Fondations module field_sales + VisitableInterface + RBAC (tournées) | M | Back | Prêt à dev |
|
||||
| M6.3 | ERP-124 | Entités & API Tournée + Étape | L | Back | Prêt à dev |
|
||||
| M6.4 | ERP-125 | Calcul trajet, optimisation, duplication & roadbook PDF | L | Back | Prêt à dev |
|
||||
| M6.5 | ERP-127 | Carte interactive + écran planification (responsive) | L | Front | Prêt à dev |
|
||||
| M6.6 | ERP-129 | Onglet « Carte » dans les fiches Client & Fournisseur | M | Front | Prêt à dev |
|
||||
| M6.7 | ERP-130 | Vérification : garde-fous archi, tests RG & golden path | M | Back+Front | Prêt à dev |
|
||||
|
||||
Supprimés à la réduction de scope : **ERP-126** (rapport de visite) et **ERP-128** (mode terrain mobile + formulaire rapport).
|
||||
|
||||
Ordre d'exécution : M6.2 → M6.3 → M6.4 → M6.5 → M6.6 → M6.7.
|
||||
|
||||
---
|
||||
|
||||
### Sources d'inspiration (logiciels de référence)
|
||||
- Badger Maps — *Lasso* + carte : https://www.badgermapping.com/features/
|
||||
- SPOTIO — drag & drop des étapes + optimize : https://support.spotio.com/hc/en-us/articles/360061370754-Routing-How-to-Build-and-Manage-Routes
|
||||
- Portatour — multi-stop + recalcul auto : https://www.portatour.com/features/en
|
||||
- Nomadia Field Sales — carte + tournée mobile : https://www.nomadia.com/ressources/blog/logiciel-commerciaux-itinerants/
|
||||
@@ -2,7 +2,9 @@
|
||||
Valeurs en dur issues de la maquette Figma (design Starseed) :
|
||||
- sidebar depliee : 232px (w-[232px], repli laisse par defaut 72px)
|
||||
- marge horizontale du contenu sur desktop : 170px (xl:px-[170px])
|
||||
- bande blanche sticky sous la navbar : 47px (h-[47px])
|
||||
La marge haute du contenu (44px) vit desormais DANS l'entete (PageHeader,
|
||||
pt-11) et non sur le <main> : sinon, l'entete etant sticky, ce padding
|
||||
laissait un trou blanc entre le SiteSelector et l'entete.
|
||||
A faire evoluer uniquement avec une mise a jour de maquette.
|
||||
-->
|
||||
<template>
|
||||
@@ -25,9 +27,6 @@
|
||||
<SiteSelector v-if="showSiteSelector"/>
|
||||
<main
|
||||
class="flex flex-1 flex-col overflow-y-auto overflow-x-hidden bg-white px-4 pb-10 sm:px-6 lg:px-12 xl:px-11">
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none sticky top-0 z-30 h-11 flex-shrink-0 bg-white"/>
|
||||
<slot/>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -40,15 +40,267 @@
|
||||
},
|
||||
"catalog": {
|
||||
"categories": "Gestion des catégories"
|
||||
},
|
||||
"field_sales": {
|
||||
"section": "Tournées",
|
||||
"tours": "Tournées"
|
||||
}
|
||||
},
|
||||
"dashboard": {
|
||||
"title": "Tableau de bord",
|
||||
"welcome": "Bienvenue sur Starseed"
|
||||
},
|
||||
"field_sales": {
|
||||
"tours": {
|
||||
"title": "Tournées",
|
||||
"add": "Nouvelle tournée",
|
||||
"empty": "Aucune tournée pour l'instant.",
|
||||
"column": {
|
||||
"label": "Nom",
|
||||
"date": "Date",
|
||||
"status": "Statut",
|
||||
"stops": "Étapes",
|
||||
"distance": "Distance",
|
||||
"duration": "Durée"
|
||||
},
|
||||
"status": {
|
||||
"draft": "Brouillon",
|
||||
"planned": "Planifiée",
|
||||
"in_progress": "En cours",
|
||||
"done": "Terminée"
|
||||
},
|
||||
"new": {
|
||||
"title": "Nouvelle tournée",
|
||||
"label": "Nom de la tournée",
|
||||
"date": "Date",
|
||||
"create": "Créer la tournée",
|
||||
"cancel": "Annuler",
|
||||
"error": "Impossible de créer la tournée."
|
||||
}
|
||||
},
|
||||
"plan": {
|
||||
"title": "Planification",
|
||||
"back": "Retour aux tournées",
|
||||
"panel": {
|
||||
"title": "Tournée",
|
||||
"label": "Nom de la tournée",
|
||||
"date": "Date",
|
||||
"departureTime": "Heure de départ",
|
||||
"startLabel": "Point de départ",
|
||||
"defaultVisitMinutes": "Durée de visite (min)",
|
||||
"stops": "Étapes",
|
||||
"noStops": "Aucune étape. Sélectionnez des Tiers sur la carte ou ajoutez un point libre.",
|
||||
"distance": "Distance",
|
||||
"duration": "Durée totale",
|
||||
"visits": "Visites"
|
||||
},
|
||||
"actions": {
|
||||
"compute": "Trajet logique",
|
||||
"optimize": "Optimiser",
|
||||
"duplicate": "Dupliquer",
|
||||
"pdf": "PDF",
|
||||
"save": "Enregistrer"
|
||||
},
|
||||
"stop": {
|
||||
"eta": "Arrivée",
|
||||
"fromPrevious": "depuis l'étape précédente",
|
||||
"toGeolocate": "À géolocaliser",
|
||||
"goThere": "Y aller",
|
||||
"viewTier": "Voir le Tiers",
|
||||
"remove": "Supprimer l'étape",
|
||||
"waze": "Waze",
|
||||
"google": "Google Maps",
|
||||
"apple": "Plan (Apple)"
|
||||
},
|
||||
"custom": {
|
||||
"add": "Ajouter un point libre",
|
||||
"title": "Point libre",
|
||||
"label": "Libellé",
|
||||
"address": "Adresse",
|
||||
"confirm": "Ajouter le point",
|
||||
"cancel": "Annuler",
|
||||
"geocodeFailed": "Adresse introuvable — ajustez le pin sur la carte.",
|
||||
"hint": "Saisissez une adresse, elle sera géolocalisée automatiquement."
|
||||
},
|
||||
"map": {
|
||||
"typeClient": "Clients",
|
||||
"typeSupplier": "Fournisseurs",
|
||||
"search": "Rechercher un Tiers",
|
||||
"add": "Ajouter",
|
||||
"lassoHint": "Maintenez Maj et dessinez un rectangle pour sélectionner plusieurs Tiers."
|
||||
},
|
||||
"duplicateModal": {
|
||||
"title": "Dupliquer la tournée",
|
||||
"date": "Date de la nouvelle tournée",
|
||||
"confirm": "Dupliquer",
|
||||
"cancel": "Annuler"
|
||||
},
|
||||
"toast": {
|
||||
"computeError": "Le calcul du trajet a échoué.",
|
||||
"optimizeError": "L'optimisation a échoué.",
|
||||
"duplicateError": "La duplication a échoué.",
|
||||
"saveError": "L'enregistrement a échoué.",
|
||||
"loadError": "Impossible de charger la tournée.",
|
||||
"stopError": "L'opération sur l'étape a échoué.",
|
||||
"duplicated": "Tournée dupliquée."
|
||||
}
|
||||
}
|
||||
},
|
||||
"commercial": {
|
||||
"title": "Commercial",
|
||||
"welcome": "Module Commercial",
|
||||
"geo": {
|
||||
"title": "Position géographique",
|
||||
"toGeolocate": "À géolocaliser",
|
||||
"manualPin": "Pin ajusté manuellement",
|
||||
"dragHint": "Déplacez le marqueur pour ajuster la position exacte (lieu-dit, entrée de site...).",
|
||||
"regeocode": "Re-géocoder depuis l'adresse",
|
||||
"regeocodeFailed": "Adresse introuvable — position inchangée."
|
||||
},
|
||||
"suppliers": {
|
||||
"title": "Répertoire fournisseurs",
|
||||
"add": "Ajouter",
|
||||
"export": "Exporter",
|
||||
"empty": "Aucun fournisseur 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",
|
||||
"includeArchived": "Inclure les archivés",
|
||||
"apply": "Voir les résultats",
|
||||
"reset": "Réinitialiser"
|
||||
},
|
||||
"toast": {
|
||||
"error": "Une erreur est survenue. Réessayez.",
|
||||
"exportError": "L'export du répertoire fournisseurs a échoué. Réessayez.",
|
||||
"createSuccess": "Fournisseur créé avec succès",
|
||||
"updateSuccess": "Fournisseur mis à jour avec succès",
|
||||
"addComplete": "Fournisseur ajouté",
|
||||
"archiveSuccess": "Fournisseur archivé avec succès",
|
||||
"restoreSuccess": "Fournisseur restauré avec succès",
|
||||
"restoreConflict": "Impossible de restaurer : un fournisseur actif portant ce nom existe déjà."
|
||||
},
|
||||
"comingSoon": "À venir",
|
||||
"tab": {
|
||||
"information": "Information",
|
||||
"contacts": "Contacts",
|
||||
"addresses": "Adresses",
|
||||
"transport": "Transport",
|
||||
"accounting": "Comptabilité",
|
||||
"statistics": "Statistiques",
|
||||
"reports": "Rapports",
|
||||
"exchanges": "Échanges"
|
||||
},
|
||||
"action": {
|
||||
"edit": "Modifier",
|
||||
"archive": "Archiver",
|
||||
"restore": "Restaurer"
|
||||
},
|
||||
"consultation": {
|
||||
"title": "Consultation fournisseur",
|
||||
"back": "Retour au répertoire",
|
||||
"loading": "Chargement du fournisseur…",
|
||||
"notFound": "Fournisseur introuvable.",
|
||||
"confirmArchive": {
|
||||
"title": "Archiver le fournisseur",
|
||||
"message": "Ce fournisseur n'apparaîtra plus dans le répertoire actif. Confirmer l'archivage ?"
|
||||
},
|
||||
"confirmRestore": {
|
||||
"title": "Restaurer le fournisseur",
|
||||
"message": "Ce fournisseur réapparaîtra dans le répertoire actif. Confirmer la restauration ?"
|
||||
}
|
||||
},
|
||||
"edit": {
|
||||
"title": "Modifier le fournisseur",
|
||||
"back": "Retour au répertoire",
|
||||
"loading": "Chargement du fournisseur…",
|
||||
"notFound": "Fournisseur introuvable.",
|
||||
"save": "Valider"
|
||||
},
|
||||
"form": {
|
||||
"title": "Ajouter un fournisseur",
|
||||
"back": "Précédent",
|
||||
"submit": "Valider",
|
||||
"duplicateCompany": "Un fournisseur portant ce nom de société existe déjà.",
|
||||
"main": {
|
||||
"companyName": "Nom du fournisseur (Entreprise)",
|
||||
"categories": "Catégorie"
|
||||
},
|
||||
"information": {
|
||||
"description": "Description",
|
||||
"competitors": "Concurrent",
|
||||
"foundedAt": "Date de création",
|
||||
"employeesCount": "Nombre de salariés",
|
||||
"revenueAmount": "CA",
|
||||
"profitAmount": "Résultat",
|
||||
"directorName": "Dirigeant",
|
||||
"volumeForecast": "Volume prévisionnel"
|
||||
},
|
||||
"contact": {
|
||||
"title": "Contact {n}",
|
||||
"lastName": "Nom",
|
||||
"firstName": "Prénom",
|
||||
"jobTitle": "Fonction",
|
||||
"email": "Email",
|
||||
"phonePrimary": "Téléphone",
|
||||
"phoneSecondary": "Téléphone (2)",
|
||||
"addPhone": "Ajouter un numéro",
|
||||
"remove": "Supprimer le contact",
|
||||
"add": "Nouveau contact"
|
||||
},
|
||||
"address": {
|
||||
"title": "Adresse {n}",
|
||||
"addressType": "Type d'adresse",
|
||||
"addressTypeProspect": "Prospect",
|
||||
"addressTypeDepart": "Départ",
|
||||
"addressTypeRendu": "Rendu",
|
||||
"categories": "Catégorie",
|
||||
"country": "Pays",
|
||||
"postalCode": "Code postal",
|
||||
"city": "Ville",
|
||||
"street": "Adresse",
|
||||
"streetNotFound": "Adresse introuvable ? Saisissez-la directement.",
|
||||
"streetComplement": "Adresse complémentaire",
|
||||
"sites": "Sites",
|
||||
"contacts": "Contact(s) rattaché(s)",
|
||||
"bennes": "Benne(s)",
|
||||
"triageProvider": "Prestation de triage",
|
||||
"remove": "Supprimer l'adresse",
|
||||
"add": "Nouvelle adresse",
|
||||
"degraded": "Service d'adresse indisponible : saisie de la ville et de l'adresse en mode libre."
|
||||
},
|
||||
"accounting": {
|
||||
"siren": "SIREN",
|
||||
"accountNumber": "Numéro de compte",
|
||||
"tvaMode": "Mode de TVA",
|
||||
"nTva": "N° de TVA",
|
||||
"paymentDelay": "Délai de règlement",
|
||||
"paymentType": "Type de règlement",
|
||||
"bank": "Banque",
|
||||
"ribLabel": "Libellé",
|
||||
"ribBic": "BIC",
|
||||
"ribIban": "IBAN",
|
||||
"addRib": "Ajouter un RIB",
|
||||
"removeRib": "Supprimer le RIB"
|
||||
},
|
||||
"confirmDelete": {
|
||||
"title": "Confirmer la suppression",
|
||||
"contact": "Supprimer ce contact ?",
|
||||
"address": "Supprimer cette adresse ?",
|
||||
"rib": "Supprimer ce RIB ?",
|
||||
"cancel": "Annuler",
|
||||
"confirm": "Confirmer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"clients": {
|
||||
"title": "Répertoire clients",
|
||||
"add": "Ajouter",
|
||||
@@ -88,6 +340,7 @@
|
||||
"toast": {
|
||||
"createSuccess": "Client créé avec succès",
|
||||
"updateSuccess": "Client mis à jour avec succès",
|
||||
"addComplete": "Client ajouté",
|
||||
"archiveSuccess": "Client archivé avec succès",
|
||||
"restoreSuccess": "Client restauré avec succès",
|
||||
"error": "Une erreur est survenue. Réessayez.",
|
||||
@@ -173,15 +426,20 @@
|
||||
"addressTypeDelivery": "Livraison",
|
||||
"addressTypeBilling": "Facturation",
|
||||
"addressTypeDeliveryBilling": "Adresse + Facturation",
|
||||
"addressTypeBroker": "Adresse Courtier",
|
||||
"addressTypeDistributor": "Adresse Distributeur",
|
||||
"categories": "Catégorie",
|
||||
"country": "Pays",
|
||||
"postalCode": "Code postal",
|
||||
"city": "Ville",
|
||||
"street": "Adresse",
|
||||
"streetNotFound": "Adresse introuvable ? Saisissez-la directement.",
|
||||
"streetComplement": "Adresse complémentaire",
|
||||
"sites": "Sites",
|
||||
"contacts": "Contact(s) rattaché(s)",
|
||||
"billingEmail": "Email de facturation",
|
||||
"billingEmailSecondary": "Email de facturation secondaire",
|
||||
"addBillingEmail": "Ajouter un email",
|
||||
"remove": "Supprimer l'adresse",
|
||||
"add": "Nouvelle adresse",
|
||||
"degraded": "Service d'adresse indisponible : saisie de la ville et de l'adresse en mode libre."
|
||||
@@ -259,7 +517,13 @@
|
||||
"commercial_client": "Client",
|
||||
"commercial_clientaddress": "Adresse client",
|
||||
"commercial_clientcontact": "Contact client",
|
||||
"commercial_clientrib": "RIB client"
|
||||
"commercial_clientrib": "RIB client",
|
||||
"commercial_supplier": "Fournisseur",
|
||||
"commercial_supplieraddress": "Adresse fournisseur",
|
||||
"commercial_suppliercontact": "Contact fournisseur",
|
||||
"commercial_supplierrib": "RIB fournisseur",
|
||||
"fieldsales_tour": "Tournée",
|
||||
"fieldsales_tourstop": "Étape de tournée"
|
||||
},
|
||||
"empty": "Aucune activité enregistrée",
|
||||
"no_results": "Aucun résultat pour ces filtres",
|
||||
@@ -412,21 +676,26 @@
|
||||
"newCategory": "Ajouter",
|
||||
"editCategory": "Modifier la catégorie",
|
||||
"createCategory": "Créer une catégorie",
|
||||
"viewCategory": "Détail de la catégorie",
|
||||
"noCategories": "Aucune catégorie pour l'instant.",
|
||||
"table": {
|
||||
"name": "Nom",
|
||||
"type": "Type"
|
||||
"types": "Types"
|
||||
},
|
||||
"filters": {
|
||||
"title": "Filtres",
|
||||
"search": "Recherche",
|
||||
"types": "Types de catégorie",
|
||||
"apply": "Voir les résultats",
|
||||
"reset": "Réinitialiser"
|
||||
},
|
||||
"form": {
|
||||
"name": "Nom",
|
||||
"type": "Type de catégorie",
|
||||
"typePlaceholder": "Sélectionner un type"
|
||||
"types": "Types de catégorie"
|
||||
},
|
||||
"validation": {
|
||||
"nameRequired": "Le nom est obligatoire.",
|
||||
"nameLength": "Le nom doit faire entre 2 et 120 caractères.",
|
||||
"typeRequired": "Le type de catégorie est obligatoire."
|
||||
"typesRequired": "Sélectionnez au moins un type de catégorie."
|
||||
},
|
||||
"delete": {
|
||||
"title": "Supprimer la catégorie",
|
||||
@@ -436,7 +705,7 @@
|
||||
"created": "Catégorie créée avec succès",
|
||||
"updated": "Catégorie mise à jour avec succès",
|
||||
"deleted": "Catégorie supprimée avec succès",
|
||||
"duplicate": "Une catégorie nommée « {name} » existe déjà pour ce type.",
|
||||
"duplicate": "Une catégorie nommée « {name} » existe déjà.",
|
||||
"typesLoadFailed": "Impossible de charger les types de catégorie. Réessayez."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,16 +24,17 @@
|
||||
required
|
||||
/>
|
||||
|
||||
<!-- Type (RG-1.05 obligatoire). MalioSelect porte la valeur en
|
||||
number (categoryType id) ; conversion en IRI au moment du save
|
||||
par le composable useCategoryForm. -->
|
||||
<MalioSelect
|
||||
v-model="form.categoryTypeId.value"
|
||||
<!-- Types (RG-1.05 : au moins un obligatoire). MalioSelectCheckbox
|
||||
porte un tableau d'ids (categoryType id) ; conversion en tableau
|
||||
d'IRI au moment du save par le composable useCategoryForm. -->
|
||||
<MalioSelectCheckbox
|
||||
v-model="form.categoryTypeIds.value"
|
||||
:options="typeOptions"
|
||||
:label="t('admin.categories.form.type')"
|
||||
:empty-option-label="t('admin.categories.form.typePlaceholder')"
|
||||
:error="form.errors.categoryType"
|
||||
:label="t('admin.categories.form.types')"
|
||||
:error="form.errors.categoryTypes"
|
||||
:display-tag="true"
|
||||
:disabled="loadingTypes"
|
||||
required
|
||||
/>
|
||||
</form>
|
||||
|
||||
@@ -89,28 +90,17 @@ const emit = defineEmits<{
|
||||
delete: []
|
||||
}>()
|
||||
|
||||
/**
|
||||
* Mode du drawer (dérivé du composable `useCategoryForm`) :
|
||||
* - 'create' : pas de category prop, formulaire vide, POST au save.
|
||||
* - 'view' : category prop set, formulaire pre-rempli, save MASQUE
|
||||
* jusqu'a ce que l'utilisateur modifie un champ.
|
||||
* - 'edit' : category prop set et formulaire « dirty » (au moins un
|
||||
* champ different de l'original), PATCH au save.
|
||||
*/
|
||||
type DrawerMode = 'create' | 'view' | 'edit'
|
||||
|
||||
// Mode du drawer : creation (pas de category prop, POST au save) ou
|
||||
// modification d'une categorie existante (PATCH au save). Pas de distinction
|
||||
// view/edit : comme les autres drawers, le titre et le bouton Enregistrer sont
|
||||
// stables quel que soit l'etat « dirty » du formulaire.
|
||||
const isCreateMode = computed(() => props.category === null)
|
||||
|
||||
const mode = computed<DrawerMode>(() => {
|
||||
if (isCreateMode.value) return 'create'
|
||||
return form.isDirty.value ? 'edit' : 'view'
|
||||
})
|
||||
|
||||
const headerLabel = computed(() => {
|
||||
if (mode.value === 'create') return t('admin.categories.createCategory')
|
||||
if (mode.value === 'edit') return t('admin.categories.editCategory')
|
||||
return t('admin.categories.viewCategory')
|
||||
})
|
||||
const headerLabel = computed(() =>
|
||||
isCreateMode.value
|
||||
? t('admin.categories.createCategory')
|
||||
: t('admin.categories.editCategory'),
|
||||
)
|
||||
|
||||
// Le bouton Supprimer n'est visible qu'en consultation/edition d'une categorie
|
||||
// existante et seulement pour les users ayant la permission manage. En mode
|
||||
@@ -119,10 +109,12 @@ const canShowDelete = computed(
|
||||
() => !isCreateMode.value && can('catalog.categories.manage'),
|
||||
)
|
||||
|
||||
// Save : visible en creation, ou en edition (apres modification d'un champ).
|
||||
// Masque en view tant que rien n'a change.
|
||||
// Save : visible en creation, et en consultation/edition d'une categorie
|
||||
// existante (l'utilisateur doit pouvoir enregistrer sans qu'un champ ait
|
||||
// d'abord ete modifie). Le bouton reste neanmoins protege par son `disabled`
|
||||
// pendant la soumission / le chargement des types.
|
||||
const canShowSave = computed(
|
||||
() => mode.value === 'create' || mode.value === 'edit',
|
||||
() => isCreateMode.value || can('catalog.categories.manage'),
|
||||
)
|
||||
|
||||
const typeOptions = computed(() =>
|
||||
@@ -152,18 +144,18 @@ watch(
|
||||
)
|
||||
|
||||
/**
|
||||
* Sauvegarde : delegue au composable (POST en mode create, PATCH en mode
|
||||
* edit). Le toast succes + mapping erreur 409/422 est gere par le composable.
|
||||
* En cas de succes, on ferme le drawer et on previent le parent pour qu'il
|
||||
* refresh la liste.
|
||||
* Sauvegarde : delegue au composable (POST en creation, PATCH en modification).
|
||||
* Le toast succes + mapping erreur 409/422 est gere par le composable. Le PATCH
|
||||
* envoie le payload complet, donc le bouton Enregistrer sauvegarde a tout
|
||||
* moment (meme sans modification). En cas de succes, on ferme le drawer et on
|
||||
* previent le parent pour qu'il refresh la liste.
|
||||
*/
|
||||
async function handleSave(): Promise<void> {
|
||||
let result: Category | null = null
|
||||
if (mode.value === 'create') {
|
||||
result = await form.submitCreate()
|
||||
} else if (mode.value === 'edit' && props.category) {
|
||||
result = await form.submitUpdate(props.category.id)
|
||||
}
|
||||
const result = isCreateMode.value
|
||||
? await form.submitCreate()
|
||||
: props.category
|
||||
? await form.submitUpdate(props.category.id)
|
||||
: null
|
||||
if (result) {
|
||||
emit('saved')
|
||||
emit('update:modelValue', false)
|
||||
|
||||
@@ -39,7 +39,7 @@ const TYPE_ACHAT: CategoryType = { id: 2, code: 'ACHAT', label: 'Achat' }
|
||||
const CAT: Category = {
|
||||
id: 42,
|
||||
name: 'Vis',
|
||||
categoryType: TYPE_VENTE,
|
||||
categoryTypes: [TYPE_VENTE],
|
||||
deletedAt: null,
|
||||
createdAt: '2026-01-01T10:00:00+00:00',
|
||||
updatedAt: '2026-01-01T10:00:00+00:00',
|
||||
@@ -58,25 +58,25 @@ describe('useCategoryForm', () => {
|
||||
})
|
||||
|
||||
describe('loadFrom', () => {
|
||||
it('pre-remplit le formulaire depuis une categorie existante', () => {
|
||||
it('pre-remplit le formulaire depuis une categorie existante (multi-types)', () => {
|
||||
const form = useCategoryForm()
|
||||
|
||||
form.loadFrom(CAT)
|
||||
form.loadFrom({ ...CAT, categoryTypes: [TYPE_VENTE, TYPE_ACHAT] })
|
||||
|
||||
expect(form.name.value).toBe('Vis')
|
||||
expect(form.categoryTypeId.value).toBe(1)
|
||||
expect(form.categoryTypeIds.value).toEqual([1, 2])
|
||||
expect(form.errors).toEqual({})
|
||||
})
|
||||
|
||||
it('vide le formulaire en mode creation (null)', () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'old'
|
||||
form.categoryTypeId.value = 99
|
||||
form.categoryTypeIds.value = [99]
|
||||
|
||||
form.loadFrom(null)
|
||||
|
||||
expect(form.name.value).toBe('')
|
||||
expect(form.categoryTypeId.value).toBeNull()
|
||||
expect(form.categoryTypeIds.value).toEqual([])
|
||||
})
|
||||
|
||||
it('reinitialise le snapshot initial → isDirty=false juste apres', () => {
|
||||
@@ -98,13 +98,32 @@ describe('useCategoryForm', () => {
|
||||
|
||||
expect(form.isDirty.value).toBe(true)
|
||||
})
|
||||
|
||||
it('passe a true quand on ajoute un type (selection multi)', () => {
|
||||
const form = useCategoryForm()
|
||||
form.loadFrom(CAT)
|
||||
expect(form.isDirty.value).toBe(false)
|
||||
|
||||
form.categoryTypeIds.value = [1, 2]
|
||||
|
||||
expect(form.isDirty.value).toBe(true)
|
||||
})
|
||||
|
||||
it('reste false si la selection est identique dans un autre ordre', () => {
|
||||
const form = useCategoryForm()
|
||||
form.loadFrom({ ...CAT, categoryTypes: [TYPE_VENTE, TYPE_ACHAT] })
|
||||
|
||||
form.categoryTypeIds.value = [2, 1]
|
||||
|
||||
expect(form.isDirty.value).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('validate', () => {
|
||||
it('signale une erreur si name est vide (RG-1.02)', () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = ''
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const ok = form.validate()
|
||||
|
||||
@@ -115,7 +134,7 @@ describe('useCategoryForm', () => {
|
||||
it('signale erreur si name est whitespace-only (trim → vide)', () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = ' '
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const ok = form.validate()
|
||||
|
||||
@@ -126,7 +145,7 @@ describe('useCategoryForm', () => {
|
||||
it('signale erreur si name fait 1 caractere (< 2, RG-1.04)', () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'A'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const ok = form.validate()
|
||||
|
||||
@@ -137,7 +156,7 @@ describe('useCategoryForm', () => {
|
||||
it('signale erreur si name fait 121 caracteres (> 120, RG-1.04)', () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'A'.repeat(121)
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const ok = form.validate()
|
||||
|
||||
@@ -145,21 +164,21 @@ describe('useCategoryForm', () => {
|
||||
expect(form.errors.name).toBe('admin.categories.validation.nameLength')
|
||||
})
|
||||
|
||||
it('signale erreur si categoryTypeId est null (RG-1.05)', () => {
|
||||
it('signale erreur si aucun type selectionne (RG-1.05)', () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = null
|
||||
form.categoryTypeIds.value = []
|
||||
|
||||
const ok = form.validate()
|
||||
|
||||
expect(ok).toBe(false)
|
||||
expect(form.errors.categoryType).toBe('admin.categories.validation.typeRequired')
|
||||
expect(form.errors.categoryTypes).toBe('admin.categories.validation.typesRequired')
|
||||
})
|
||||
|
||||
it('passe quand name et categoryType sont valides', () => {
|
||||
it('passe quand name et au moins un type sont valides', () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1, 2]
|
||||
|
||||
const ok = form.validate()
|
||||
|
||||
@@ -171,7 +190,7 @@ describe('useCategoryForm', () => {
|
||||
const form = useCategoryForm()
|
||||
// Erreur prealable : une validation en echec peuple errors.name.
|
||||
form.name.value = ''
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
form.validate()
|
||||
expect(form.errors.name).toBeTruthy()
|
||||
|
||||
@@ -184,17 +203,17 @@ describe('useCategoryForm', () => {
|
||||
})
|
||||
|
||||
describe('submitCreate', () => {
|
||||
it('appelle POST /categories avec body { name trimme, categoryType en IRI }', async () => {
|
||||
it('appelle POST /categories avec body { name trimme, categoryTypes en IRI[] }', async () => {
|
||||
mockPost.mockResolvedValueOnce(CAT)
|
||||
const form = useCategoryForm()
|
||||
form.name.value = ' Vis '
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1, 2]
|
||||
|
||||
const result = await form.submitCreate()
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith(
|
||||
'/categories',
|
||||
{ name: 'Vis', categoryType: '/api/category_types/1' },
|
||||
{ name: 'Vis', categoryTypes: ['/api/category_types/1', '/api/category_types/2'] },
|
||||
{ toast: false },
|
||||
)
|
||||
expect(result).toEqual(CAT)
|
||||
@@ -203,7 +222,7 @@ describe('useCategoryForm', () => {
|
||||
it('ne declenche aucun appel API si la validation client echoue', async () => {
|
||||
const form = useCategoryForm()
|
||||
form.name.value = ''
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const result = await form.submitCreate()
|
||||
|
||||
@@ -215,7 +234,7 @@ describe('useCategoryForm', () => {
|
||||
mockPost.mockResolvedValueOnce(CAT)
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
await form.submitCreate()
|
||||
|
||||
@@ -231,7 +250,7 @@ describe('useCategoryForm', () => {
|
||||
})
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const result = await form.submitCreate()
|
||||
|
||||
@@ -258,7 +277,7 @@ describe('useCategoryForm', () => {
|
||||
})
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const result = await form.submitCreate()
|
||||
|
||||
@@ -269,24 +288,24 @@ describe('useCategoryForm', () => {
|
||||
expect(mockToastError).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('mappe aussi hydra:violations (negociation de format alternative)', async () => {
|
||||
it('mappe une violation sur categoryTypes (hydra:violations alternative)', async () => {
|
||||
mockPost.mockRejectedValueOnce({
|
||||
response: {
|
||||
status: 422,
|
||||
_data: {
|
||||
'hydra:violations': [
|
||||
{ propertyPath: 'categoryType', message: 'Type invalide.' },
|
||||
{ propertyPath: 'categoryTypes', message: 'Sélectionnez au moins un type de catégorie.' },
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
await form.submitCreate()
|
||||
|
||||
expect(form.errors.categoryType).toBe('Type invalide.')
|
||||
expect(form.errors.categoryTypes).toBe('Sélectionnez au moins un type de catégorie.')
|
||||
})
|
||||
|
||||
it('fallback en toast generique si le status n est ni 409 ni 422', async () => {
|
||||
@@ -295,7 +314,7 @@ describe('useCategoryForm', () => {
|
||||
})
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
await form.submitCreate()
|
||||
|
||||
@@ -314,7 +333,7 @@ describe('useCategoryForm', () => {
|
||||
)
|
||||
const form = useCategoryForm()
|
||||
form.name.value = 'Vis'
|
||||
form.categoryTypeId.value = 1
|
||||
form.categoryTypeIds.value = [1]
|
||||
|
||||
const pending = form.submitCreate()
|
||||
expect(form.submitting.value).toBe(true)
|
||||
@@ -327,45 +346,52 @@ describe('useCategoryForm', () => {
|
||||
})
|
||||
|
||||
describe('submitUpdate', () => {
|
||||
it('appelle PATCH /categories/{id} uniquement avec les champs modifies', async () => {
|
||||
it('appelle PATCH /categories/{id} avec le payload complet (name + categoryTypes)', async () => {
|
||||
mockPatch.mockResolvedValueOnce({ ...CAT, name: 'Vis V2' })
|
||||
const form = useCategoryForm()
|
||||
form.loadFrom(CAT)
|
||||
form.name.value = 'Vis V2' // categoryTypeId inchange
|
||||
form.name.value = 'Vis V2' // types inchanges
|
||||
|
||||
await form.submitUpdate(42)
|
||||
|
||||
// Payload complet : meme si seul le name change, on renvoie aussi
|
||||
// les categoryTypes (PATCH full payload, cf. drawers simples).
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/categories/42',
|
||||
{ name: 'Vis V2', categoryTypes: ['/api/category_types/1'] },
|
||||
{ toast: false },
|
||||
)
|
||||
})
|
||||
|
||||
it('envoie categoryTypes en IRI[] quand on ajoute un type', async () => {
|
||||
mockPatch.mockResolvedValueOnce({ ...CAT, categoryTypes: [TYPE_VENTE, TYPE_ACHAT] })
|
||||
const form = useCategoryForm()
|
||||
form.loadFrom(CAT)
|
||||
form.categoryTypeIds.value = [1, 2]
|
||||
|
||||
await form.submitUpdate(42)
|
||||
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/categories/42',
|
||||
{ name: 'Vis V2' }, // pas de categoryType car non modifie
|
||||
{ name: CAT.name, categoryTypes: ['/api/category_types/1', '/api/category_types/2'] },
|
||||
{ toast: false },
|
||||
)
|
||||
})
|
||||
|
||||
it('envoie categoryType en IRI quand seul le type a change', async () => {
|
||||
mockPatch.mockResolvedValueOnce({ ...CAT, categoryType: TYPE_ACHAT })
|
||||
it('envoie un PATCH complet meme sans modification (save a tout moment)', async () => {
|
||||
mockPatch.mockResolvedValueOnce(CAT)
|
||||
const form = useCategoryForm()
|
||||
form.loadFrom(CAT)
|
||||
form.categoryTypeId.value = 2
|
||||
|
||||
await form.submitUpdate(42)
|
||||
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/categories/42',
|
||||
{ categoryType: '/api/category_types/2' },
|
||||
{ toast: false },
|
||||
)
|
||||
})
|
||||
|
||||
it('court-circuite l appel API si aucun champ n a change', async () => {
|
||||
const form = useCategoryForm()
|
||||
form.loadFrom(CAT)
|
||||
// Aucune modification — isDirty=false, patch payload vide.
|
||||
// Aucune modification : le PATCH part quand meme avec le payload complet.
|
||||
|
||||
const result = await form.submitUpdate(42)
|
||||
|
||||
expect(mockPatch).not.toHaveBeenCalled()
|
||||
expect(result).toBeNull()
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/categories/42',
|
||||
{ name: CAT.name, categoryTypes: ['/api/category_types/1'] },
|
||||
{ toast: false },
|
||||
)
|
||||
expect(result).toEqual(CAT)
|
||||
expect(form.submitting.value).toBe(false)
|
||||
})
|
||||
|
||||
@@ -438,7 +464,7 @@ describe('useCategoryForm', () => {
|
||||
form.reset()
|
||||
|
||||
expect(form.name.value).toBe('')
|
||||
expect(form.categoryTypeId.value).toBeNull()
|
||||
expect(form.categoryTypeIds.value).toEqual([])
|
||||
expect(form.errors).toEqual({})
|
||||
expect(form.submitting.value).toBe(false)
|
||||
})
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
* revalide toujours (defense en profondeur).
|
||||
*
|
||||
* Erreurs par champ : delegue a `useFormErrors` (convention ERP-101). Les
|
||||
* violations 422 sont mappees par `propertyPath` (`name`, `categoryType`) ;
|
||||
* violations 422 sont mappees par `propertyPath` (`name`, `categoryTypes`) ;
|
||||
* l'erreur globale (status != 422 exploitable) part en toast. Le 409 (doublon
|
||||
* RG-1.07) reste un cas metier specifique : erreur inline sur `name` + toast.
|
||||
* de nom GLOBAL, RG-1.07) reste un cas metier specifique : erreur inline sur
|
||||
* `name` + toast.
|
||||
*/
|
||||
import { computed, ref } from 'vue'
|
||||
import type { Category } from '~/modules/catalog/types/category'
|
||||
@@ -42,20 +43,29 @@ export function useCategoryForm() {
|
||||
// State local du formulaire — pas singleton, chaque appel a useCategoryForm
|
||||
// cree son propre state (cohérent avec le pattern « un drawer = un form »).
|
||||
const name = ref('')
|
||||
const categoryTypeId = ref<number | null>(null)
|
||||
const categoryTypeIds = ref<number[]>([])
|
||||
|
||||
// Snapshot des valeurs initiales : sert a calculer `isDirty` pour le
|
||||
// pattern view → edit du drawer (le bouton Enregistrer reste masque tant
|
||||
// que rien n'a change en mode consultation).
|
||||
const initialName = ref('')
|
||||
const initialCategoryTypeId = ref<number | null>(null)
|
||||
const initialCategoryTypeIds = ref<number[]>([])
|
||||
|
||||
const submitting = ref(false)
|
||||
|
||||
// Compare deux listes d'ids sans tenir compte de l'ordre (la selection
|
||||
// multi-types n'est pas ordonnee).
|
||||
function sameIds(a: number[], b: number[]): boolean {
|
||||
if (a.length !== b.length) return false
|
||||
const sortedA = [...a].sort((x, y) => x - y)
|
||||
const sortedB = [...b].sort((x, y) => x - y)
|
||||
return sortedA.every((v, i) => v === sortedB[i])
|
||||
}
|
||||
|
||||
const isDirty = computed(
|
||||
() =>
|
||||
name.value !== initialName.value
|
||||
|| categoryTypeId.value !== initialCategoryTypeId.value,
|
||||
|| !sameIds(categoryTypeIds.value, initialCategoryTypeIds.value),
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -66,15 +76,16 @@ export function useCategoryForm() {
|
||||
function loadFrom(category: Category | null): void {
|
||||
formErrors.clearErrors()
|
||||
if (category) {
|
||||
const ids = category.categoryTypes.map(t => t.id)
|
||||
name.value = category.name
|
||||
categoryTypeId.value = category.categoryType.id
|
||||
categoryTypeIds.value = [...ids]
|
||||
initialName.value = category.name
|
||||
initialCategoryTypeId.value = category.categoryType.id
|
||||
initialCategoryTypeIds.value = [...ids]
|
||||
} else {
|
||||
name.value = ''
|
||||
categoryTypeId.value = null
|
||||
categoryTypeIds.value = []
|
||||
initialName.value = ''
|
||||
initialCategoryTypeId.value = null
|
||||
initialCategoryTypeIds.value = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,23 +106,23 @@ export function useCategoryForm() {
|
||||
formErrors.setError('name', t('admin.categories.validation.nameLength'))
|
||||
}
|
||||
|
||||
// RG-1.05 — categoryType obligatoire.
|
||||
if (categoryTypeId.value === null) {
|
||||
formErrors.setError('categoryType', t('admin.categories.validation.typeRequired'))
|
||||
// RG-1.05 — au moins un type obligatoire.
|
||||
if (categoryTypeIds.value.length === 0) {
|
||||
formErrors.setError('categoryTypes', t('admin.categories.validation.typesRequired'))
|
||||
}
|
||||
|
||||
return !formErrors.errors.name && !formErrors.errors.categoryType
|
||||
return !formErrors.errors.name && !formErrors.errors.categoryTypes
|
||||
}
|
||||
|
||||
/**
|
||||
* Construit le payload POST a partir du state. Le `categoryType` est
|
||||
* envoye en IRI Hydra (`/api/category_types/{id}`) — convention API
|
||||
* Platform pour referencer une ressource liee.
|
||||
* Construit le payload POST a partir du state. Les `categoryTypes` sont
|
||||
* envoyes en tableau d'IRI Hydra (`/api/category_types/{id}`) — convention
|
||||
* API Platform pour referencer une collection de ressources liees.
|
||||
*/
|
||||
function buildCreatePayload(): Record<string, unknown> {
|
||||
return {
|
||||
name: name.value.trim(),
|
||||
categoryType: `/api/category_types/${categoryTypeId.value}`,
|
||||
categoryTypes: categoryTypeIds.value.map(id => `/api/category_types/${id}`),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,26 +174,18 @@ export function useCategoryForm() {
|
||||
}
|
||||
|
||||
/**
|
||||
* PATCH /api/categories/{id}. Envoie uniquement les champs modifies pour
|
||||
* coller a la semantique merge-patch (Content-Type pose par useApi).
|
||||
* Renvoie la categorie mise a jour, ou `null` en cas d'echec.
|
||||
* PATCH /api/categories/{id}. Envoie le payload complet (name +
|
||||
* categoryTypes), comme les autres drawers du projet : le bouton
|
||||
* Enregistrer sauvegarde a tout moment, meme sans modification, et renvoie
|
||||
* toujours un retour (toast succes + refresh). Renvoie la categorie mise a
|
||||
* jour, ou `null` en cas d'echec.
|
||||
*/
|
||||
async function submitUpdate(id: number): Promise<Category | null> {
|
||||
if (!validate()) return null
|
||||
submitting.value = true
|
||||
const payload: Record<string, unknown> = {}
|
||||
if (name.value !== initialName.value) {
|
||||
payload.name = name.value.trim()
|
||||
}
|
||||
if (categoryTypeId.value !== initialCategoryTypeId.value) {
|
||||
payload.categoryType = `/api/category_types/${categoryTypeId.value}`
|
||||
}
|
||||
// Garde-fou : un PATCH sans changement ne sert a rien. Theoriquement
|
||||
// empeche par le drawer (bouton Enregistrer masque si !isDirty) mais
|
||||
// on protege le composable contre un appel direct mal utilise.
|
||||
if (Object.keys(payload).length === 0) {
|
||||
submitting.value = false
|
||||
return null
|
||||
const payload: Record<string, unknown> = {
|
||||
name: name.value.trim(),
|
||||
categoryTypes: categoryTypeIds.value.map(id => `/api/category_types/${id}`),
|
||||
}
|
||||
try {
|
||||
const updated = await api.patch<Category>(`/categories/${id}`, payload, {
|
||||
@@ -233,9 +236,9 @@ export function useCategoryForm() {
|
||||
*/
|
||||
function reset(): void {
|
||||
name.value = ''
|
||||
categoryTypeId.value = null
|
||||
categoryTypeIds.value = []
|
||||
initialName.value = ''
|
||||
initialCategoryTypeId.value = null
|
||||
initialCategoryTypeIds.value = []
|
||||
formErrors.clearErrors()
|
||||
submitting.value = false
|
||||
}
|
||||
@@ -243,7 +246,7 @@ export function useCategoryForm() {
|
||||
return {
|
||||
// State
|
||||
name,
|
||||
categoryTypeId,
|
||||
categoryTypeIds,
|
||||
errors: formErrors.errors,
|
||||
submitting,
|
||||
isDirty,
|
||||
|
||||
@@ -3,13 +3,28 @@
|
||||
<PageHeader>
|
||||
{{ t('admin.categories.title') }}
|
||||
<template #actions>
|
||||
<MalioButton
|
||||
v-if="canManage"
|
||||
:label="t('admin.categories.newCategory')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@click="openCreateDrawer"
|
||||
/>
|
||||
<!-- gap-8 = 32px d'espacement entre Filtres et Ajouter (meme
|
||||
design que le Repertoire Clients). -->
|
||||
<div class="flex items-center gap-8">
|
||||
<!-- Bouton Filtres a GAUCHE d'Ajouter. Le compteur reflete
|
||||
les filtres actifs. -->
|
||||
<MalioButton
|
||||
variant="tertiary"
|
||||
:label="filterButtonLabel"
|
||||
icon-name="mdi:tune"
|
||||
icon-position="left"
|
||||
icon-size="24"
|
||||
@click="openFilters"
|
||||
/>
|
||||
<MalioButton
|
||||
v-if="canManage"
|
||||
variant="secondary"
|
||||
:label="t('admin.categories.newCategory')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@click="openCreateDrawer"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
@@ -47,6 +62,60 @@
|
||||
:loading="deleting"
|
||||
@confirm="handleDelete"
|
||||
/>
|
||||
|
||||
<!-- Drawer de filtres : etat BROUILLON, applique uniquement au clic sur
|
||||
« Appliquer ». Meme pattern que le Repertoire Clients. Etat 100 %
|
||||
local, jamais dans l'URL (regle ABSOLUE n°6). -->
|
||||
<MalioDrawer
|
||||
v-model="filterDrawerOpen"
|
||||
drawer-class="max-w-[450px]"
|
||||
body-class="p-0"
|
||||
footer-class="justify-between border-t border-black p-6"
|
||||
>
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold uppercase">{{ t('admin.categories.filters.title') }}</h2>
|
||||
</template>
|
||||
|
||||
<MalioAccordion>
|
||||
<!-- Recherche par nom (param `name`, partiel insensible a la casse). -->
|
||||
<MalioAccordionItem :title="t('admin.categories.filters.search')" value="search">
|
||||
<MalioInputText
|
||||
v-model="draftSearch"
|
||||
icon-name="mdi:magnify"
|
||||
/>
|
||||
</MalioAccordionItem>
|
||||
|
||||
<!-- Type(s) : cases a cocher (multi). Une categorie remonte si
|
||||
elle porte AU MOINS UN des types coches (OR cote back). -->
|
||||
<MalioAccordionItem :title="t('admin.categories.filters.types')" value="types">
|
||||
<div class="flex flex-col">
|
||||
<MalioCheckbox
|
||||
v-for="opt in typeFilterOptions"
|
||||
:id="`filter-type-${opt.value}`"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:model-value="draftTypeIds.includes(opt.value)"
|
||||
@update:model-value="(val: boolean) => toggleType(opt.value, val)"
|
||||
/>
|
||||
</div>
|
||||
</MalioAccordionItem>
|
||||
</MalioAccordion>
|
||||
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="tertiary"
|
||||
:label="t('admin.categories.filters.reset')"
|
||||
button-class="w-m-btn-action"
|
||||
@click="resetFilters"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('admin.categories.filters.apply')"
|
||||
button-class="w-[170px]"
|
||||
@click="applyFilters"
|
||||
/>
|
||||
</template>
|
||||
</MalioDrawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -55,7 +124,7 @@ import type { Category } from '~/modules/catalog/types/category'
|
||||
|
||||
const { t } = useI18n()
|
||||
const { can } = usePermissions()
|
||||
const { fetchTypes } = useCategoriesAdmin()
|
||||
const { types, fetchTypes } = useCategoriesAdmin()
|
||||
const { submitDelete } = useCategoryForm()
|
||||
|
||||
useHead({ title: t('admin.categories.title') })
|
||||
@@ -74,6 +143,7 @@ const {
|
||||
fetch: fetchCategories,
|
||||
goToPage,
|
||||
setItemsPerPage,
|
||||
setFilters,
|
||||
} = usePaginatedList<Category>({ url: '/categories' })
|
||||
|
||||
const drawerOpen = ref(false)
|
||||
@@ -82,21 +152,96 @@ const deleteModalOpen = ref(false)
|
||||
const categoryToDelete = ref<Category | null>(null)
|
||||
const deleting = ref(false)
|
||||
|
||||
// Colonnes du datatable. Le type est embarque cote API (cf. spec-back § 3.4) —
|
||||
// on aplatit en label lisible pour l'affichage.
|
||||
// Colonnes du datatable. Les types sont embarques cote API (ManyToMany) — on
|
||||
// aplatit en libelles joints par une virgule pour l'affichage.
|
||||
const columns = [
|
||||
{ key: 'name', label: t('admin.categories.table.name') },
|
||||
{ key: 'typeLabel', label: t('admin.categories.table.type') },
|
||||
{ key: 'typesLabel', label: t('admin.categories.table.types') },
|
||||
]
|
||||
|
||||
const categoryItems = computed(() =>
|
||||
categories.value.map(cat => ({
|
||||
id: cat.id,
|
||||
name: cat.name,
|
||||
typeLabel: cat.categoryType?.label ?? '',
|
||||
typesLabel: (cat.categoryTypes ?? []).map(ct => ct.label).join(', '),
|
||||
})),
|
||||
)
|
||||
|
||||
// ── Filtres (drawer) ────────────────────────────────────────────────────────
|
||||
// Deux niveaux d'etat (pattern Repertoire Clients) :
|
||||
// - APPLIED : pilote la liste + le compteur du bouton. Modifie uniquement au
|
||||
// clic « Appliquer » / « Réinitialiser ».
|
||||
// - DRAFT : edite librement dans le drawer ; recopie vers applied a la validation.
|
||||
const filterDrawerOpen = ref(false)
|
||||
|
||||
const draftSearch = ref('')
|
||||
const draftTypeIds = ref<number[]>([])
|
||||
|
||||
const appliedSearch = ref('')
|
||||
const appliedTypeIds = ref<number[]>([])
|
||||
|
||||
// Options du filtre Type(s), derivees du referentiel deja charge (fetchTypes).
|
||||
const typeFilterOptions = computed(() =>
|
||||
types.value.map(ct => ({ value: ct.id, label: ct.label })),
|
||||
)
|
||||
|
||||
const activeFilterCount = computed(() => {
|
||||
let count = 0
|
||||
if (appliedSearch.value.trim() !== '') count++
|
||||
if (appliedTypeIds.value.length > 0) count++
|
||||
return count
|
||||
})
|
||||
|
||||
const filterButtonLabel = computed(() => {
|
||||
const base = t('admin.categories.filters.title')
|
||||
return activeFilterCount.value > 0 ? `${base} (${activeFilterCount.value})` : base
|
||||
})
|
||||
|
||||
// Recopie l'etat applique vers le brouillon puis ouvre le drawer.
|
||||
function openFilters(): void {
|
||||
draftSearch.value = appliedSearch.value
|
||||
draftTypeIds.value = [...appliedTypeIds.value]
|
||||
filterDrawerOpen.value = true
|
||||
}
|
||||
|
||||
function toggleType(id: number, selected: boolean): void {
|
||||
draftTypeIds.value = selected
|
||||
? [...draftTypeIds.value, id]
|
||||
: draftTypeIds.value.filter(t => t !== id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Construit le payload de filtres serveur a partir de l'etat applique. Cle
|
||||
* `typeId[]` pour que PHP la parse en tableau (OR cote back). Filtres vides omis.
|
||||
*/
|
||||
function buildFilterPayload(): Record<string, string | string[]> {
|
||||
const payload: Record<string, string | string[]> = {}
|
||||
if (appliedSearch.value.trim() !== '') payload.name = appliedSearch.value.trim()
|
||||
if (appliedTypeIds.value.length > 0) payload['typeId[]'] = appliedTypeIds.value.map(String)
|
||||
return payload
|
||||
}
|
||||
|
||||
// « Appliquer » : recopie brouillon → applied, pousse les filtres (retombe en
|
||||
// page 1 via usePaginatedList) et ferme le drawer.
|
||||
function applyFilters(): void {
|
||||
appliedSearch.value = draftSearch.value.trim()
|
||||
appliedTypeIds.value = [...draftTypeIds.value]
|
||||
|
||||
setFilters(buildFilterPayload(), { replace: true })
|
||||
filterDrawerOpen.value = false
|
||||
}
|
||||
|
||||
// « Réinitialiser » : vide brouillon ET applied, recharge la liste complete.
|
||||
// Le drawer reste ouvert pour montrer le formulaire vide.
|
||||
function resetFilters(): void {
|
||||
draftSearch.value = ''
|
||||
draftTypeIds.value = []
|
||||
appliedSearch.value = ''
|
||||
appliedTypeIds.value = []
|
||||
|
||||
setFilters({}, { replace: true })
|
||||
}
|
||||
|
||||
function getCategoryById(id: number): Category | undefined {
|
||||
return categories.value.find(c => c.id === id)
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
* Contrats API consommes :
|
||||
* - GET /api/categories → HydraCollection<Category>
|
||||
* - GET /api/categories/{id} → Category
|
||||
* - POST /api/categories → body { name, categoryType: IRI }
|
||||
* - PATCH /api/categories/{id} → body partiel { name?, categoryType?: IRI }
|
||||
* - POST /api/categories → body { name, categoryTypes: IRI[] }
|
||||
* - PATCH /api/categories/{id} → body partiel { name?, categoryTypes?: IRI[] }
|
||||
* - DELETE /api/categories/{id} → 204 (soft delete via CategoryProcessor)
|
||||
* - GET /api/category_types → HydraCollection<CategoryType>
|
||||
*
|
||||
* Notes :
|
||||
* - Les IRI sont envoyes en POST/PATCH (ex. "/api/category_types/3").
|
||||
* - `categoryType` est embarque (groupe Serializer `category:read` sur les
|
||||
* proprietes de CategoryType, cf. spec-back § 3.4).
|
||||
* - Les IRI sont envoyes en POST/PATCH (ex. ["/api/category_types/3"]).
|
||||
* - `categoryTypes` est embarque (groupe Serializer `category:read` sur les
|
||||
* proprietes de CategoryType) : tableau d'objets type en lecture.
|
||||
* - `createdBy` / `updatedBy` peuvent etre `null` (hors contexte HTTP,
|
||||
* ON DELETE SET NULL en BDD). Affichage : libelle "Systeme" si null.
|
||||
*/
|
||||
@@ -43,7 +43,8 @@ export interface CategoryType {
|
||||
export interface Category {
|
||||
id: number
|
||||
name: string
|
||||
categoryType: CategoryType
|
||||
/** Types de la categorie (>= 1, ManyToMany embarque en lecture). */
|
||||
categoryTypes: CategoryType[]
|
||||
/** Soft delete : null = active, valeur = supprimee logiquement le {date}. */
|
||||
deletedAt: string | null
|
||||
createdAt: string
|
||||
@@ -53,12 +54,12 @@ export interface Category {
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload accepte en POST /api/categories. `categoryType` est envoye en
|
||||
* IRI Hydra (ex. `/api/category_types/3`).
|
||||
* Payload accepte en POST /api/categories. `categoryTypes` est un tableau
|
||||
* d'IRI Hydra (ex. `['/api/category_types/3', '/api/category_types/5']`).
|
||||
*/
|
||||
export interface CategoryCreateInput {
|
||||
name: string
|
||||
categoryType: string
|
||||
categoryTypes: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,5 +68,5 @@ export interface CategoryCreateInput {
|
||||
*/
|
||||
export interface CategoryUpdateInput {
|
||||
name?: string
|
||||
categoryType?: string
|
||||
categoryTypes?: string[]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
<template>
|
||||
<div data-testid="geo-pin">
|
||||
<div class="mb-1 flex items-center gap-2">
|
||||
<span class="text-sm font-medium text-gray-700">{{ t('commercial.geo.title') }}</span>
|
||||
<!-- Badge « a geolocaliser » : adresse valide mais sans coordonnees
|
||||
(spec M6 § 3.2 — exclue du calcul de tournee, RG-6.05). -->
|
||||
<span
|
||||
v-if="!hasCoords"
|
||||
class="inline-flex items-center rounded-full bg-yellow-100 px-2 py-0.5 text-xs font-medium text-yellow-800"
|
||||
data-testid="geo-badge-missing"
|
||||
>
|
||||
{{ t('commercial.geo.toGeolocate') }}
|
||||
</span>
|
||||
<!-- Pin fige a la main (RG-6.08) : informatif. -->
|
||||
<span
|
||||
v-else-if="geoManual"
|
||||
class="inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-xs font-medium text-blue-800"
|
||||
data-testid="geo-badge-manual"
|
||||
>
|
||||
{{ t('commercial.geo.manualPin') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Mini-carte Leaflet (exception documentee a @malio/layer-ui : carte
|
||||
interactive, type non couvert par la lib — cf. frontend.md
|
||||
§ Composants formulaires). TODO : migrer si la lib couvre un jour
|
||||
les cartes. -->
|
||||
<div
|
||||
v-if="hasCoords"
|
||||
ref="mapEl"
|
||||
class="h-48 w-full rounded border border-gray-200"
|
||||
data-testid="geo-map"
|
||||
/>
|
||||
<p v-if="hasCoords && !readonly" class="mt-1 text-xs text-gray-500">
|
||||
{{ t('commercial.geo.dragHint') }}
|
||||
</p>
|
||||
|
||||
<div v-if="!readonly" class="mt-2 flex items-center gap-4">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
:label="t('commercial.geo.regeocode')"
|
||||
:disabled="regeocoding || !canRegeocode"
|
||||
data-testid="geo-regeocode"
|
||||
@click="regeocode"
|
||||
/>
|
||||
<span v-if="regeocodeFailed" class="text-xs text-red-600" data-testid="geo-regeocode-failed">
|
||||
{{ t('commercial.geo.regeocodeFailed') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Map as LeafletMap, Marker } from 'leaflet'
|
||||
import { useAddressAutocomplete } from '~/shared/composables/useAddressAutocomplete'
|
||||
|
||||
/**
|
||||
* Mini-carte d'ajustement du pin d'une adresse Tiers (M6.1, spec § 8.3).
|
||||
*
|
||||
* - Marqueur deplacable : au drag, emet les coordonnees corrigees avec
|
||||
* geoManual = true (RG-6.08 : le geocodage auto ne reecrira plus). Le parent
|
||||
* met a jour le brouillon ; la persistance suit le submit du formulaire
|
||||
* (POST/PATCH de l'adresse), comme tous les champs du bloc.
|
||||
* - « Re-geocoder depuis l'adresse » : previsualise la position BAN cote front
|
||||
* et emet geoManual = false — au save, le back (BanGeocoder) refait autorite
|
||||
* et pose geocodedAt.
|
||||
* - Sans coordonnees : pas de carte, badge « a geolocaliser ».
|
||||
*/
|
||||
const props = defineProps<{
|
||||
/** Latitude WGS84 (chaine decimale) ou null si non geolocalisee. */
|
||||
latitude: string | null
|
||||
/** Longitude WGS84 (chaine decimale) ou null si non geolocalisee. */
|
||||
longitude: string | null
|
||||
/** RG-6.08 : pin deja corrige a la main. */
|
||||
geoManual: boolean
|
||||
/** Adresse postale a re-geocoder (« rue, code postal ville »). */
|
||||
geocodeQuery: string | null
|
||||
readonly?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** Nouveau positionnement du pin (drag manuel ou re-geocodage previsualise). */
|
||||
'update:coords': [value: { latitude: string, longitude: string, geoManual: boolean }]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const autocomplete = useAddressAutocomplete()
|
||||
|
||||
const mapEl = ref<HTMLElement | null>(null)
|
||||
const regeocoding = ref(false)
|
||||
const regeocodeFailed = ref(false)
|
||||
|
||||
const hasCoords = computed(() =>
|
||||
props.latitude !== null && props.latitude !== ''
|
||||
&& props.longitude !== null && props.longitude !== '',
|
||||
)
|
||||
|
||||
const canRegeocode = computed(() => (props.geocodeQuery ?? '').trim().length >= 3)
|
||||
|
||||
// Instances Leaflet (hors reactivite Vue : un proxy sur la Map casse Leaflet).
|
||||
let map: LeafletMap | null = null
|
||||
let marker: Marker | null = null
|
||||
|
||||
/** Zoom d'affichage du pin (niveau rue). */
|
||||
const PIN_ZOOM = 16
|
||||
|
||||
/**
|
||||
* Monte la carte Leaflet dans le conteneur (import dynamique : la lib n'est
|
||||
* chargee que si l'adresse a des coordonnees).
|
||||
*/
|
||||
async function ensureMap(): Promise<void> {
|
||||
if (map !== null || mapEl.value === null || !hasCoords.value) {
|
||||
return
|
||||
}
|
||||
|
||||
const mod = await import('leaflet')
|
||||
const L = mod.default ?? mod
|
||||
await import('leaflet/dist/leaflet.css')
|
||||
|
||||
// Le conteneur peut avoir disparu pendant le chargement async (v-if).
|
||||
if (mapEl.value === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const position: [number, number] = [Number(props.latitude), Number(props.longitude)]
|
||||
|
||||
map = L.map(mapEl.value, { scrollWheelZoom: false }).setView(position, PIN_ZOOM)
|
||||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
||||
maxZoom: 19,
|
||||
}).addTo(map)
|
||||
|
||||
// divIcon SVG inline : evite les assets PNG de Leaflet (chemins casses par
|
||||
// le bundler Vite sans configuration dediee).
|
||||
const icon = L.divIcon({
|
||||
className: '',
|
||||
html: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="28" height="40" fill="#2563eb" stroke="#1e40af" stroke-width="0.5"><path d="M12 0C7 0 3 4 3 9c0 6.6 9 15 9 15s9-8.4 9-15c0-5-4-9-9-9zm0 12.5A3.5 3.5 0 1 1 12 5.5a3.5 3.5 0 0 1 0 7z"/></svg>',
|
||||
iconSize: [28, 40],
|
||||
iconAnchor: [14, 40],
|
||||
})
|
||||
|
||||
marker = L.marker(position, { icon, draggable: !props.readonly }).addTo(map)
|
||||
marker.on('dragend', onMarkerDragEnd)
|
||||
}
|
||||
|
||||
/** Drag du pin -> coordonnees corrigees + geoManual (RG-6.08). */
|
||||
function onMarkerDragEnd(): void {
|
||||
if (marker === null) {
|
||||
return
|
||||
}
|
||||
const position = marker.getLatLng()
|
||||
emit('update:coords', {
|
||||
latitude: position.lat.toFixed(7),
|
||||
longitude: position.lng.toFixed(7),
|
||||
geoManual: true,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* « Re-geocoder depuis l'adresse » : previsualisation BAN cote front. Emet
|
||||
* geoManual = false — le geocodage serveur refait autorite au save.
|
||||
*/
|
||||
async function regeocode(): Promise<void> {
|
||||
regeocodeFailed.value = false
|
||||
const query = (props.geocodeQuery ?? '').trim()
|
||||
if (query.length < 3) {
|
||||
regeocodeFailed.value = true
|
||||
return
|
||||
}
|
||||
|
||||
regeocoding.value = true
|
||||
try {
|
||||
const coords = await autocomplete.geocode(query)
|
||||
if (coords === null) {
|
||||
regeocodeFailed.value = true
|
||||
return
|
||||
}
|
||||
emit('update:coords', { ...coords, geoManual: false })
|
||||
}
|
||||
catch {
|
||||
// BAN indisponible : position inchangee, message inline.
|
||||
regeocodeFailed.value = true
|
||||
}
|
||||
finally {
|
||||
regeocoding.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Coordonnees modifiees par le parent (drag deja applique, re-geocodage,
|
||||
// rechargement) : recale le marqueur, ou monte la carte si elle n'existe pas
|
||||
// encore (premieres coordonnees d'une adresse « a geolocaliser »).
|
||||
watch(
|
||||
() => [props.latitude, props.longitude] as const,
|
||||
async () => {
|
||||
if (!hasCoords.value) {
|
||||
return
|
||||
}
|
||||
if (map === null) {
|
||||
await nextTick()
|
||||
await ensureMap()
|
||||
return
|
||||
}
|
||||
const position: [number, number] = [Number(props.latitude), Number(props.longitude)]
|
||||
marker?.setLatLng(position)
|
||||
map.panTo(position)
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(ensureMap)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
map?.remove()
|
||||
map = null
|
||||
marker = null
|
||||
})
|
||||
</script>
|
||||
@@ -14,12 +14,15 @@
|
||||
remplacant les 3 cases. Les options encodent les combinaisons valides
|
||||
(exclusivite Prospect, RG-1.06/07/08) ; le back recoit toujours les
|
||||
drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). -->
|
||||
<!-- Erreur portee sur `isProspect` cote back (Callback type obligatoire +
|
||||
exclusivite prospect) -> affichee sous le select Type d'adresse. -->
|
||||
<MalioSelect
|
||||
:model-value="addressType"
|
||||
:options="addressTypeOptions"
|
||||
:label="t('commercial.clients.form.address.addressType')"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.isProspect"
|
||||
@update:model-value="onAddressTypeChange"
|
||||
/>
|
||||
|
||||
@@ -31,6 +34,7 @@
|
||||
:display-tag="true"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.sites"
|
||||
@update:model-value="(v: (string | number)[]) => update('siteIris', v.map(String))"
|
||||
/>
|
||||
|
||||
@@ -43,9 +47,10 @@
|
||||
@update:model-value="(v: (string | number)[]) => update('contactIris', v.map(String))"
|
||||
/>
|
||||
|
||||
<!-- Email de facturation : ligne 1 colonne 4, visible/obligatoire
|
||||
seulement si Facturation (RG-1.11). Sinon un filler comble la
|
||||
colonne pour que Categorie reparte au debut de la ligne 2. -->
|
||||
<!-- Email(s) de facturation : visible/obligatoire seulement si Facturation
|
||||
(RG-1.11). Le « + » revele un 2e email optionnel (max 2, pendant du
|
||||
telephone secondaire) qui coule dans la grille. Sinon un filler comble
|
||||
la colonne pour que Categorie reparte au debut de la ligne suivante. -->
|
||||
<MalioInputEmail
|
||||
v-if="isBillingEmailRequired(model)"
|
||||
:model-value="model.billingEmail"
|
||||
@@ -54,10 +59,23 @@
|
||||
:readonly="readonly"
|
||||
:lowercase="true"
|
||||
:error="errors?.billingEmail"
|
||||
:addable="!model.hasSecondaryBillingEmail && !readonly"
|
||||
:add-button-label="t('commercial.clients.form.address.addBillingEmail')"
|
||||
@update:model-value="(v: string) => update('billingEmail', v)"
|
||||
@add="revealSecondaryBillingEmail"
|
||||
/>
|
||||
<div v-else aria-hidden="true" />
|
||||
|
||||
<MalioInputEmail
|
||||
v-if="isBillingEmailRequired(model) && model.hasSecondaryBillingEmail"
|
||||
:model-value="model.billingEmailSecondary"
|
||||
:label="t('commercial.clients.form.address.billingEmailSecondary')"
|
||||
:readonly="readonly"
|
||||
:lowercase="true"
|
||||
:error="errors?.billingEmailSecondary"
|
||||
@update:model-value="(v: string) => update('billingEmailSecondary', v)"
|
||||
/>
|
||||
|
||||
<MalioSelectCheckbox
|
||||
:model-value="model.categoryIris"
|
||||
:options="categoryOptions"
|
||||
@@ -65,6 +83,7 @@
|
||||
:display-tag="true"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.categories"
|
||||
@update:model-value="(v: (string | number)[]) => update('categoryIris', v.map(String))"
|
||||
/>
|
||||
|
||||
@@ -87,8 +106,9 @@
|
||||
@update:model-value="onPostalCodeChange"
|
||||
/>
|
||||
|
||||
<!-- Ville : MalioSelect alimente par le code postal (BAN). En mode
|
||||
degrade (service indisponible), bascule en saisie libre. -->
|
||||
<!-- Ville : MalioSelect alimente par le code postal (BAN). Si la BAN est
|
||||
indisponible, bascule en saisie libre — recuperable : re-saisir le
|
||||
code postal relance la recherche et repasse en select au succes. -->
|
||||
<MalioSelect
|
||||
v-if="!degraded"
|
||||
:model-value="model.city"
|
||||
@@ -115,11 +135,14 @@
|
||||
sur l'input interne, pas sur la cellule de grille. Le wrapper porte
|
||||
le col-span-2, le champ le remplit (w-full). -->
|
||||
<div class="col-span-2">
|
||||
<!-- Adresse : saisie assistee (BAN) en edition ; champ texte simple en
|
||||
mode degrade OU en lecture seule (MalioInputAutocomplete ne reaffiche
|
||||
pas sa valeur liee, il n'afficherait rien en readonly). -->
|
||||
<!-- Adresse : saisie assistee (BAN) en edition ; champ texte simple
|
||||
seulement en lecture seule (MalioInputAutocomplete ne reaffiche pas
|
||||
sa valeur liee, il n'afficherait rien en readonly). allow-create :
|
||||
si la BAN ne propose rien (ou erreur), le texte saisi est CONSERVE au
|
||||
blur/Entree (saisie manuelle) — sinon il serait efface. La ville reste
|
||||
pilotee par le code postal ; choisir une suggestion remplit rue+ville+CP. -->
|
||||
<MalioInputAutocomplete
|
||||
v-if="!degraded && !readonly"
|
||||
v-if="!readonly"
|
||||
:model-value="model.street"
|
||||
:options="addressOptions"
|
||||
:loading="addressLoading"
|
||||
@@ -128,6 +151,8 @@
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.street"
|
||||
:allow-create="true"
|
||||
:no-results-text="t('commercial.clients.form.address.streetNotFound')"
|
||||
@update:model-value="(v: string | number | null) => update('street', v === null ? null : String(v))"
|
||||
@search="onAddressSearch"
|
||||
@select="onAddressSelect"
|
||||
@@ -143,7 +168,7 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-2">
|
||||
<div class="col-span-1">
|
||||
<MalioInputText
|
||||
:model-value="model.streetComplement"
|
||||
:label="t('commercial.clients.form.address.streetComplement')"
|
||||
@@ -153,6 +178,19 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Pin geographique de l'adresse (M6.1, spec § 8.3) : mini-carte avec
|
||||
marqueur ajustable, persiste au submit comme le reste du bloc. -->
|
||||
<div class="col-span-4">
|
||||
<AddressGeoPin
|
||||
:latitude="model.latitude"
|
||||
:longitude="model.longitude"
|
||||
:geo-manual="model.geoManual"
|
||||
:geocode-query="geocodeQuery"
|
||||
:readonly="readonly"
|
||||
@update:coords="onCoordsUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -209,6 +247,8 @@ const addressTypeOptions = computed<RefOption[]>(() => [
|
||||
{ value: 'delivery', label: t('commercial.clients.form.address.addressTypeDelivery') },
|
||||
{ value: 'billing', label: t('commercial.clients.form.address.addressTypeBilling') },
|
||||
{ value: 'delivery_billing', label: t('commercial.clients.form.address.addressTypeDeliveryBilling') },
|
||||
{ value: 'broker', label: t('commercial.clients.form.address.addressTypeBroker') },
|
||||
{ value: 'distributor', label: t('commercial.clients.form.address.addressTypeDistributor') },
|
||||
])
|
||||
|
||||
/** Applique le type choisi en repercutant les 3 drapeaux back (immutabilite). */
|
||||
@@ -217,8 +257,12 @@ function onAddressTypeChange(value: string | number | null): void {
|
||||
emit('update:modelValue', { ...props.modelValue, ...addressFlagsFromType(value as AddressType) })
|
||||
}
|
||||
|
||||
// Mode degrade : service BAN indisponible → Ville/Adresse en saisie libre.
|
||||
// Repli saisie libre de la VILLE quand la BAN est indisponible (recuperable :
|
||||
// remis a false des qu'une recherche de ville aboutit). N'affecte plus le champ
|
||||
// Adresse, qui reste en autocompletion et reessaie a chaque frappe.
|
||||
const degraded = ref(false)
|
||||
// Avertissement « service indisponible » envoye au parent une seule fois.
|
||||
let unavailableNotified = false
|
||||
// Villes proposees par la BAN (alimentees a la saisie du code postal).
|
||||
const banCityOptions = ref<RefOption[]>([])
|
||||
// Adresses proposees par la BAN (alimentees a la saisie d'adresse).
|
||||
@@ -258,10 +302,33 @@ function update<K extends keyof AddressFormDraft>(field: K, value: AddressFormDr
|
||||
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
||||
}
|
||||
|
||||
/** Bascule définitivement en mode degrade et previent le parent (toast unique). */
|
||||
function enterDegraded(): void {
|
||||
if (!degraded.value) {
|
||||
degraded.value = true
|
||||
// Adresse postale a re-geocoder (« rue, code postal ville ») — miroir du
|
||||
// getDisplayLabel() serveur (le complement bruite le geocodage, exclu).
|
||||
const geocodeQuery = computed<string | null>(() => {
|
||||
const locality = [model.value.postalCode, model.value.city].filter(Boolean).join(' ')
|
||||
const parts = [model.value.street, locality].filter(part => part && String(part).trim() !== '')
|
||||
return parts.length > 0 ? parts.join(', ') : null
|
||||
})
|
||||
|
||||
/** Pin deplace / re-geocode : repercute coordonnees + drapeau manuel (RG-6.08). */
|
||||
function onCoordsUpdate(coords: { latitude: string, longitude: string, geoManual: boolean }): void {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
latitude: coords.latitude,
|
||||
longitude: coords.longitude,
|
||||
geoManual: coords.geoManual,
|
||||
})
|
||||
}
|
||||
|
||||
/** Revele le 2e champ email de facturation (clic sur le « + »). */
|
||||
function revealSecondaryBillingEmail(): void {
|
||||
emit('update:modelValue', { ...props.modelValue, hasSecondaryBillingEmail: true })
|
||||
}
|
||||
|
||||
/** Previent le parent (toast unique) que l'autocompletion est indisponible. */
|
||||
function notifyUnavailable(): void {
|
||||
if (!unavailableNotified) {
|
||||
unavailableNotified = true
|
||||
emit('degraded')
|
||||
}
|
||||
}
|
||||
@@ -270,9 +337,6 @@ function enterDegraded(): void {
|
||||
async function onPostalCodeChange(value: string): Promise<void> {
|
||||
update('postalCode', value)
|
||||
|
||||
if (degraded.value) {
|
||||
return
|
||||
}
|
||||
const digits = (value ?? '').replace(/\D/g, '')
|
||||
if (digits.length < 5) {
|
||||
return
|
||||
@@ -280,15 +344,22 @@ async function onPostalCodeChange(value: string): Promise<void> {
|
||||
try {
|
||||
const suggestions = await autocomplete.searchCity(digits)
|
||||
banCityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
|
||||
// Service repondu : on (re)passe la Ville en select assiste.
|
||||
degraded.value = false
|
||||
}
|
||||
catch {
|
||||
enterDegraded()
|
||||
// BAN indispo : Ville en saisie libre (recuperable au prochain essai).
|
||||
degraded.value = true
|
||||
notifyUnavailable()
|
||||
}
|
||||
}
|
||||
|
||||
/** Recherche d'adresse assistee (event de MalioInputAutocomplete). */
|
||||
async function onAddressSearch(query: string): Promise<void> {
|
||||
if (degraded.value) {
|
||||
// La BAN exige au moins 3 caracteres : on n'envoie rien en deca (evite un 400)
|
||||
// et on vide les suggestions devenues obsoletes.
|
||||
if (query.trim().length < 3) {
|
||||
banAddressOptions.value = []
|
||||
return
|
||||
}
|
||||
addressLoading.value = true
|
||||
@@ -299,7 +370,10 @@ async function onAddressSearch(query: string): Promise<void> {
|
||||
banAddressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
||||
}
|
||||
catch {
|
||||
enterDegraded()
|
||||
// Erreur transitoire : on vide les suggestions, la prochaine frappe reessaie
|
||||
// (pas de bascule definitive — c'etait le bug). Avertissement une seule fois.
|
||||
banAddressOptions.value = []
|
||||
notifyUnavailable()
|
||||
}
|
||||
finally {
|
||||
addressLoading.value = false
|
||||
|
||||
@@ -26,13 +26,18 @@
|
||||
:error="errors?.firstName"
|
||||
@update:model-value="(v: string) => update('firstName', v)"
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="model.jobTitle"
|
||||
:label="t('commercial.clients.form.contact.jobTitle')"
|
||||
:readonly="readonly"
|
||||
:error="errors?.jobTitle"
|
||||
@update:model-value="(v: string) => update('jobTitle', v)"
|
||||
/>
|
||||
<!-- Fonction sur 2 colonnes : on wrappe car MalioInputText
|
||||
(inheritAttrs:false) renvoie `class` sur l'input interne, pas sur la
|
||||
cellule de grille. Le wrapper porte le col-span-2, le champ le remplit. -->
|
||||
<div class="col-span-2">
|
||||
<MalioInputText
|
||||
:model-value="model.jobTitle"
|
||||
:label="t('commercial.clients.form.contact.jobTitle')"
|
||||
:readonly="readonly"
|
||||
:error="errors?.jobTitle"
|
||||
@update:model-value="(v: string) => update('jobTitle', v)"
|
||||
/>
|
||||
</div>
|
||||
<MalioInputEmail
|
||||
:model-value="model.email"
|
||||
:label="t('commercial.clients.form.contact.email')"
|
||||
|
||||
@@ -0,0 +1,345 @@
|
||||
<template>
|
||||
<div class="relative grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- Suppression : modal de confirmation cote parent. -->
|
||||
<MalioButtonIcon
|
||||
v-if="removable && !readonly"
|
||||
icon="mdi:delete-outline"
|
||||
variant="ghost"
|
||||
button-class="absolute top-3 right-3"
|
||||
v-bind="{ ariaLabel: t('commercial.suppliers.form.address.remove') }"
|
||||
@click="$emit('remove')"
|
||||
/>
|
||||
|
||||
<!-- Type d'adresse : Prospect / Depart / Rendu (RG-2.09). Select en attendant
|
||||
l'arbitrage metier (radio vs select) ; l'erreur 422 (propertyPath
|
||||
`addressType`) s'affiche via la prop native :error de MalioSelect. -->
|
||||
<MalioSelect
|
||||
:model-value="model.addressType"
|
||||
:options="addressTypeOptions"
|
||||
:label="t('commercial.suppliers.form.address.addressType')"
|
||||
:readonly="readonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="errors?.addressType"
|
||||
@update:model-value="(v: string | number | null) => update('addressType', v === null ? null : (v as SupplierAddressType))"
|
||||
/>
|
||||
|
||||
<!-- Sites Starseed : multiselect a tags (>= 1 obligatoire, RG-2.06). -->
|
||||
<MalioSelectCheckbox
|
||||
:model-value="model.siteIris"
|
||||
:options="siteOptions"
|
||||
:label="t('commercial.suppliers.form.address.sites')"
|
||||
:display-tag="true"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.sites"
|
||||
@update:model-value="(v: (string | number)[]) => update('siteIris', v.map(String))"
|
||||
/>
|
||||
|
||||
<!-- Contacts rattaches (M2M, facultatif). -->
|
||||
<MalioSelectCheckbox
|
||||
:model-value="model.contactIris"
|
||||
:options="contactOptions"
|
||||
:label="t('commercial.suppliers.form.address.contacts')"
|
||||
:display-tag="true"
|
||||
:readonly="readonly"
|
||||
@update:model-value="(v: (string | number)[]) => update('contactIris', v.map(String))"
|
||||
/>
|
||||
|
||||
<!-- Filler : aligne le debut de ligne suivant sur la grille (le bloc client
|
||||
porte ici l'email de facturation, absent cote fournisseur). -->
|
||||
<div aria-hidden="true" />
|
||||
|
||||
<!-- Categories de type FOURNISSEUR (>= 1 obligatoire, RG-2.10). -->
|
||||
<MalioSelectCheckbox
|
||||
:model-value="model.categoryIris"
|
||||
:options="categoryOptions"
|
||||
:label="t('commercial.suppliers.form.address.categories')"
|
||||
:display-tag="true"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.categories"
|
||||
@update:model-value="(v: (string | number)[]) => update('categoryIris', v.map(String))"
|
||||
/>
|
||||
|
||||
<MalioSelect
|
||||
:model-value="model.country"
|
||||
:options="countryOptions"
|
||||
:label="t('commercial.suppliers.form.address.country')"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
@update:model-value="(v: string | number | null) => update('country', String(v ?? 'France'))"
|
||||
/>
|
||||
|
||||
<MalioInputText
|
||||
:model-value="model.postalCode"
|
||||
:label="t('commercial.suppliers.form.address.postalCode')"
|
||||
:mask="POSTAL_CODE_MASK"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.postalCode"
|
||||
@update:model-value="onPostalCodeChange"
|
||||
/>
|
||||
|
||||
<!-- Ville : MalioSelect alimente par le code postal (BAN). Saisie libre si BAN indispo. -->
|
||||
<MalioSelect
|
||||
v-if="!degraded"
|
||||
:model-value="model.city"
|
||||
:options="cityOptions"
|
||||
:label="t('commercial.suppliers.form.address.city')"
|
||||
:readonly="readonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="errors?.city"
|
||||
@update:model-value="(v: string | number | null) => update('city', v === null ? null : String(v))"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-else
|
||||
:model-value="model.city"
|
||||
:label="t('commercial.suppliers.form.address.city')"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.city"
|
||||
@update:model-value="(v: string) => update('city', v)"
|
||||
/>
|
||||
|
||||
<!-- Adresse (BAN) sur 2 colonnes + Adresse complementaire. allow-create : le
|
||||
texte saisi est conserve si la BAN ne propose rien (saisie manuelle). -->
|
||||
<div class="col-span-2">
|
||||
<MalioInputAutocomplete
|
||||
v-if="!readonly"
|
||||
:model-value="model.street"
|
||||
:options="addressOptions"
|
||||
:loading="addressLoading"
|
||||
:min-search-length="3"
|
||||
:label="t('commercial.suppliers.form.address.street')"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.street"
|
||||
:allow-create="true"
|
||||
:no-results-text="t('commercial.suppliers.form.address.streetNotFound')"
|
||||
@update:model-value="(v: string | number | null) => update('street', v === null ? null : String(v))"
|
||||
@search="onAddressSearch"
|
||||
@select="onAddressSelect"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-else
|
||||
:model-value="model.street"
|
||||
:label="t('commercial.suppliers.form.address.street')"
|
||||
:readonly="readonly"
|
||||
:required="true"
|
||||
:error="errors?.street"
|
||||
@update:model-value="(v: string) => update('street', v)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1">
|
||||
<MalioInputText
|
||||
:model-value="model.streetComplement"
|
||||
:label="t('commercial.suppliers.form.address.streetComplement')"
|
||||
:readonly="readonly"
|
||||
:error="errors?.streetComplement"
|
||||
@update:model-value="(v: string) => update('streetComplement', v)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Bennes : stepper (specifique fournisseur, defaut 0). -->
|
||||
<MalioInputNumber
|
||||
:model-value="model.bennes"
|
||||
:label="t('commercial.suppliers.form.address.bennes')"
|
||||
:min="0"
|
||||
:readonly="readonly"
|
||||
:error="errors?.bennes"
|
||||
@update:model-value="(v: string) => update('bennes', v)"
|
||||
/>
|
||||
|
||||
<!-- Prestation de triage : booleen porte par l'adresse (specifique fournisseur). -->
|
||||
<MalioCheckbox
|
||||
id="address-triage-provider"
|
||||
:label="t('commercial.suppliers.form.address.triageProvider')"
|
||||
:model-value="model.triageProvider"
|
||||
group-class="self-center"
|
||||
:readonly="readonly"
|
||||
@update:model-value="(v: boolean) => update('triageProvider', v)"
|
||||
/>
|
||||
|
||||
<!-- Pin geographique de l'adresse (M6.1, spec § 8.3) : mini-carte avec
|
||||
marqueur ajustable, persiste au submit comme le reste du bloc. -->
|
||||
<div class="col-span-4">
|
||||
<AddressGeoPin
|
||||
:latitude="model.latitude"
|
||||
:longitude="model.longitude"
|
||||
:geo-manual="model.geoManual"
|
||||
:geocode-query="geocodeQuery"
|
||||
:readonly="readonly"
|
||||
@update:coords="onCoordsUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAddressAutocomplete, type AddressSuggestion } from '~/shared/composables/useAddressAutocomplete'
|
||||
import type { CategoryOption, RefOption } from '~/modules/commercial/composables/useSupplierReferentials'
|
||||
import type { SupplierAddressFormDraft, SupplierAddressType } from '~/modules/commercial/types/supplierForm'
|
||||
|
||||
// Masque code postal FR : 5 chiffres.
|
||||
const POSTAL_CODE_MASK = '#####'
|
||||
|
||||
const props = defineProps<{
|
||||
/** Brouillon de l'adresse (v-model). */
|
||||
modelValue: SupplierAddressFormDraft
|
||||
title: string
|
||||
/** Categories autorisees sur une adresse (type FOURNISSEUR). */
|
||||
categoryOptions: CategoryOption[]
|
||||
/** Sites Starseed disponibles. */
|
||||
siteOptions: RefOption[]
|
||||
/** Contacts deja saisis, rattachables a l'adresse. */
|
||||
contactOptions: RefOption[]
|
||||
/** Pays disponibles (France par defaut). */
|
||||
countryOptions: RefOption[]
|
||||
removable?: boolean
|
||||
readonly?: boolean
|
||||
/** Erreurs serveur 422 de cette ligne, indexees par champ (ERP-101). */
|
||||
errors?: Record<string, string>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: SupplierAddressFormDraft]
|
||||
'remove': []
|
||||
/** Emis une fois quand le service d'autocompletion bascule en indisponible. */
|
||||
'degraded': []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const autocomplete = useAddressAutocomplete()
|
||||
|
||||
const model = computed(() => props.modelValue)
|
||||
|
||||
const addressTypeOptions = computed<{ value: SupplierAddressType, label: string }[]>(() => [
|
||||
{ value: 'PROSPECT', label: t('commercial.suppliers.form.address.addressTypeProspect') },
|
||||
{ value: 'DEPART', label: t('commercial.suppliers.form.address.addressTypeDepart') },
|
||||
{ value: 'RENDU', label: t('commercial.suppliers.form.address.addressTypeRendu') },
|
||||
])
|
||||
|
||||
// Repli saisie libre de la VILLE quand la BAN est indisponible (recuperable).
|
||||
const degraded = ref(false)
|
||||
let unavailableNotified = false
|
||||
const banCityOptions = ref<RefOption[]>([])
|
||||
const banAddressOptions = ref<RefOption[]>([])
|
||||
|
||||
// Options ville effectives : on garantit que la ville courante figure toujours
|
||||
// dans la liste, sinon MalioSelect afficherait un champ vide en lecture seule.
|
||||
const cityOptions = computed<RefOption[]>(() => {
|
||||
const current = props.modelValue.city
|
||||
if (current && !banCityOptions.value.some(o => o.value === current)) {
|
||||
return [{ value: current, label: current }, ...banCityOptions.value]
|
||||
}
|
||||
return banCityOptions.value
|
||||
})
|
||||
|
||||
// Meme garantie pour le champ Adresse : la rue courante doit toujours figurer
|
||||
// dans les options, sinon MalioInputAutocomplete laisse le champ vide.
|
||||
const addressOptions = computed<RefOption[]>(() => {
|
||||
const current = props.modelValue.street
|
||||
if (current && !banAddressOptions.value.some(o => o.value === current)) {
|
||||
return [{ value: current, label: current }, ...banAddressOptions.value]
|
||||
}
|
||||
return banAddressOptions.value
|
||||
})
|
||||
const addressLoading = ref(false)
|
||||
// Conserve les suggestions d'adresse pour retrouver ville/CP au moment du select.
|
||||
let lastAddressSuggestions: AddressSuggestion[] = []
|
||||
|
||||
/** Emet un nouveau brouillon avec le champ modifie (immutabilite). */
|
||||
function update<K extends keyof SupplierAddressFormDraft>(field: K, value: SupplierAddressFormDraft[K]): void {
|
||||
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
||||
}
|
||||
|
||||
// Adresse postale a re-geocoder (« rue, code postal ville ») — miroir du
|
||||
// getDisplayLabel() serveur (le complement bruite le geocodage, exclu).
|
||||
const geocodeQuery = computed<string | null>(() => {
|
||||
const locality = [model.value.postalCode, model.value.city].filter(Boolean).join(' ')
|
||||
const parts = [model.value.street, locality].filter(part => part && String(part).trim() !== '')
|
||||
return parts.length > 0 ? parts.join(', ') : null
|
||||
})
|
||||
|
||||
/** Pin deplace / re-geocode : repercute coordonnees + drapeau manuel (RG-6.08). */
|
||||
function onCoordsUpdate(coords: { latitude: string, longitude: string, geoManual: boolean }): void {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
latitude: coords.latitude,
|
||||
longitude: coords.longitude,
|
||||
geoManual: coords.geoManual,
|
||||
})
|
||||
}
|
||||
|
||||
/** Previent le parent (toast unique) que l'autocompletion est indisponible. */
|
||||
function notifyUnavailable(): void {
|
||||
if (!unavailableNotified) {
|
||||
unavailableNotified = true
|
||||
emit('degraded')
|
||||
}
|
||||
}
|
||||
|
||||
/** Saisie du code postal → met a jour le champ + interroge la BAN pour la ville. */
|
||||
async function onPostalCodeChange(value: string): Promise<void> {
|
||||
update('postalCode', value)
|
||||
|
||||
const digits = (value ?? '').replace(/\D/g, '')
|
||||
if (digits.length < 5) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const suggestions = await autocomplete.searchCity(digits)
|
||||
banCityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
|
||||
degraded.value = false
|
||||
}
|
||||
catch {
|
||||
degraded.value = true
|
||||
notifyUnavailable()
|
||||
}
|
||||
}
|
||||
|
||||
/** Recherche d'adresse assistee (event de MalioInputAutocomplete). */
|
||||
async function onAddressSearch(query: string): Promise<void> {
|
||||
// La BAN exige au moins 3 caracteres : on n'envoie rien en deca (evite un 400).
|
||||
if (query.trim().length < 3) {
|
||||
banAddressOptions.value = []
|
||||
return
|
||||
}
|
||||
addressLoading.value = true
|
||||
try {
|
||||
const postalCode = (model.value.postalCode ?? '').replace(/\D/g, '') || undefined
|
||||
const suggestions = await autocomplete.searchAddress(query, postalCode)
|
||||
lastAddressSuggestions = suggestions
|
||||
banAddressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
||||
}
|
||||
catch {
|
||||
// Erreur transitoire : on vide les suggestions, la prochaine frappe reessaie.
|
||||
banAddressOptions.value = []
|
||||
notifyUnavailable()
|
||||
}
|
||||
finally {
|
||||
addressLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** Selection d'une suggestion d'adresse → remplit rue + ville + CP. */
|
||||
function onAddressSelect(option: { label: string, value: string | number } | null): void {
|
||||
if (option === null) {
|
||||
return
|
||||
}
|
||||
const suggestion = lastAddressSuggestions.find(s => s.street === option.value)
|
||||
if (!suggestion) {
|
||||
update('street', String(option.value))
|
||||
return
|
||||
}
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
street: suggestion.street,
|
||||
city: suggestion.city,
|
||||
postalCode: suggestion.postalCode,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<div class="relative grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- Suppression : ouvre une modal de confirmation cote parent. Masquee si
|
||||
non supprimable (1er bloc, RG-2.13) ou en lecture seule. -->
|
||||
<MalioButtonIcon
|
||||
v-if="removable && !readonly"
|
||||
icon="mdi:delete-outline"
|
||||
variant="ghost"
|
||||
button-class="absolute top-3 right-3"
|
||||
v-bind="{ ariaLabel: t('commercial.suppliers.form.contact.remove') }"
|
||||
@click="$emit('remove')"
|
||||
/>
|
||||
|
||||
<MalioInputText
|
||||
:model-value="model.lastName"
|
||||
:label="t('commercial.suppliers.form.contact.lastName')"
|
||||
:readonly="readonly"
|
||||
:error="errors?.lastName"
|
||||
@update:model-value="(v: string) => update('lastName', v)"
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="model.firstName"
|
||||
:label="t('commercial.suppliers.form.contact.firstName')"
|
||||
:readonly="readonly"
|
||||
:error="errors?.firstName"
|
||||
@update:model-value="(v: string) => update('firstName', v)"
|
||||
/>
|
||||
<!-- Fonction sur 2 colonnes : on wrappe car MalioInputText
|
||||
(inheritAttrs:false) renvoie `class` sur l'input interne, pas sur la
|
||||
cellule de grille. Le wrapper porte le col-span-2, le champ le remplit. -->
|
||||
<div class="col-span-2">
|
||||
<MalioInputText
|
||||
:model-value="model.jobTitle"
|
||||
:label="t('commercial.suppliers.form.contact.jobTitle')"
|
||||
:readonly="readonly"
|
||||
:error="errors?.jobTitle"
|
||||
@update:model-value="(v: string) => update('jobTitle', v)"
|
||||
/>
|
||||
</div>
|
||||
<MalioInputEmail
|
||||
:model-value="model.email"
|
||||
:label="t('commercial.suppliers.form.contact.email')"
|
||||
:readonly="readonly"
|
||||
:lowercase="true"
|
||||
:error="errors?.email"
|
||||
@update:model-value="(v: string) => update('email', v)"
|
||||
/>
|
||||
<MalioInputPhone
|
||||
:model-value="model.phonePrimary"
|
||||
:label="t('commercial.suppliers.form.contact.phonePrimary')"
|
||||
:mask="PHONE_MASK"
|
||||
:readonly="readonly"
|
||||
:error="errors?.phonePrimary"
|
||||
:addable="!model.hasSecondaryPhone && !readonly"
|
||||
:add-button-label="t('commercial.suppliers.form.contact.addPhone')"
|
||||
@update:model-value="(v: string) => update('phonePrimary', v)"
|
||||
@add="revealSecondaryPhone"
|
||||
/>
|
||||
<MalioInputPhone
|
||||
v-if="model.hasSecondaryPhone"
|
||||
:model-value="model.phoneSecondary"
|
||||
:label="t('commercial.suppliers.form.contact.phoneSecondary')"
|
||||
:mask="PHONE_MASK"
|
||||
:readonly="readonly"
|
||||
:error="errors?.phoneSecondary"
|
||||
@update:model-value="(v: string) => update('phoneSecondary', v)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { SupplierContactFormDraft } from '~/modules/commercial/types/supplierForm'
|
||||
|
||||
// Masque telephone FR : 5 groupes de 2 chiffres (la normalisation finale reste serveur).
|
||||
const PHONE_MASK = '## ## ## ## ##'
|
||||
|
||||
const props = defineProps<{
|
||||
/** Brouillon du contact (v-model). */
|
||||
modelValue: SupplierContactFormDraft
|
||||
/** Titre du bloc (ex: « Contact 1 »). */
|
||||
title: string
|
||||
/** Affiche l'icone de suppression (1er bloc non supprimable, RG-2.13). */
|
||||
removable?: boolean
|
||||
/** Bloc en lecture seule (onglet valide). */
|
||||
readonly?: boolean
|
||||
/** Erreurs serveur 422 de cette ligne, indexees par champ (ERP-101). */
|
||||
errors?: Record<string, string>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: SupplierContactFormDraft]
|
||||
'remove': []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
// Alias local pour la lisibilite du template.
|
||||
const model = computed(() => props.modelValue)
|
||||
|
||||
/** Emet un nouveau brouillon avec le champ modifie (immutabilite). */
|
||||
function update<K extends keyof SupplierContactFormDraft>(field: K, value: SupplierContactFormDraft[K]): void {
|
||||
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
||||
}
|
||||
|
||||
/** Revele le 2e numero (max 1 secondaire, le « + » disparait). */
|
||||
function revealSecondaryPhone(): void {
|
||||
emit('update:modelValue', { ...props.modelValue, hasSecondaryPhone: true })
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,151 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
|
||||
import AddressGeoPin from '../AddressGeoPin.vue'
|
||||
|
||||
// Mock Leaflet (hoisted) : capture le handler `dragend` et pilote la position
|
||||
// renvoyee par getLatLng — permet de simuler un drag du marqueur sans DOM reel.
|
||||
const leafletState = vi.hoisted(() => ({
|
||||
dragendHandler: null as (() => void) | null,
|
||||
markerPosition: { lat: 0, lng: 0 },
|
||||
}))
|
||||
|
||||
vi.mock('leaflet', () => {
|
||||
const marker = {
|
||||
addTo: vi.fn().mockReturnThis(),
|
||||
on: vi.fn((event: string, handler: () => void) => {
|
||||
if (event === 'dragend') {
|
||||
leafletState.dragendHandler = handler
|
||||
}
|
||||
}),
|
||||
getLatLng: vi.fn(() => leafletState.markerPosition),
|
||||
setLatLng: vi.fn(),
|
||||
}
|
||||
const map = {
|
||||
setView: vi.fn().mockReturnThis(),
|
||||
panTo: vi.fn(),
|
||||
remove: vi.fn(),
|
||||
}
|
||||
const L = {
|
||||
map: vi.fn(() => map),
|
||||
tileLayer: vi.fn(() => ({ addTo: vi.fn() })),
|
||||
divIcon: vi.fn(() => ({})),
|
||||
marker: vi.fn(() => marker),
|
||||
}
|
||||
return { default: L, ...L }
|
||||
})
|
||||
vi.mock('leaflet/dist/leaflet.css', () => ({ default: {} }))
|
||||
|
||||
// Mock controlable du geocodage BAN (bouton « Re-geocoder »).
|
||||
const { geocodeMock } = vi.hoisted(() => ({ geocodeMock: vi.fn() }))
|
||||
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
||||
useAddressAutocomplete: () => ({ geocode: geocodeMock }),
|
||||
}))
|
||||
|
||||
// Auto-imports Nuxt/Vue utilises sans import explicite par le composant.
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
vi.stubGlobal('ref', ref)
|
||||
vi.stubGlobal('computed', computed)
|
||||
vi.stubGlobal('watch', watch)
|
||||
vi.stubGlobal('nextTick', nextTick)
|
||||
vi.stubGlobal('onMounted', onMounted)
|
||||
vi.stubGlobal('onBeforeUnmount', onBeforeUnmount)
|
||||
|
||||
interface PinProps {
|
||||
latitude?: string | null
|
||||
longitude?: string | null
|
||||
geoManual?: boolean
|
||||
geocodeQuery?: string | null
|
||||
readonly?: boolean
|
||||
}
|
||||
|
||||
function mountPin(props: PinProps = {}) {
|
||||
return mount(AddressGeoPin, {
|
||||
props: {
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
geoManual: false,
|
||||
geocodeQuery: '1 rue du Test, 86100 Châtellerault',
|
||||
...props,
|
||||
},
|
||||
global: {
|
||||
stubs: { MalioButton: true },
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
leafletState.dragendHandler = null
|
||||
geocodeMock.mockReset()
|
||||
})
|
||||
|
||||
describe('AddressGeoPin — adresse sans coordonnees', () => {
|
||||
it('affiche le badge « a geolocaliser » et aucune carte', () => {
|
||||
const wrapper = mountPin()
|
||||
|
||||
expect(wrapper.find('[data-testid="geo-badge-missing"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-testid="geo-map"]').exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('AddressGeoPin — drag du marqueur (RG-6.08)', () => {
|
||||
it('emet les coordonnees corrigees avec geoManual=true au dragend', async () => {
|
||||
const wrapper = mountPin({ latitude: '46.5802596', longitude: '0.3404333' })
|
||||
await flushPromises() // import dynamique de Leaflet + montage carte
|
||||
|
||||
expect(leafletState.dragendHandler).not.toBeNull()
|
||||
|
||||
// L'utilisateur depose le pin ailleurs (lieu-dit mal geocode).
|
||||
leafletState.markerPosition = { lat: 48.1234567, lng: -1.6543217 }
|
||||
leafletState.dragendHandler?.()
|
||||
|
||||
const emitted = wrapper.emitted('update:coords')
|
||||
expect(emitted).toHaveLength(1)
|
||||
expect(emitted?.[0]?.[0]).toEqual({
|
||||
latitude: '48.1234567',
|
||||
longitude: '-1.6543217',
|
||||
geoManual: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('affiche le badge « pin manuel » quand geoManual est vrai', () => {
|
||||
const wrapper = mountPin({ latitude: '46.58', longitude: '0.34', geoManual: true })
|
||||
|
||||
expect(wrapper.find('[data-testid="geo-badge-manual"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-testid="geo-badge-missing"]').exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('AddressGeoPin — re-geocodage depuis l\'adresse', () => {
|
||||
it('emet la position BAN avec geoManual=false (le back refera autorite au save)', async () => {
|
||||
geocodeMock.mockResolvedValueOnce({ latitude: '46.5802596', longitude: '0.3404333' })
|
||||
const wrapper = mountPin()
|
||||
|
||||
await wrapper.find('[data-testid="geo-regeocode"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(geocodeMock).toHaveBeenCalledWith('1 rue du Test, 86100 Châtellerault')
|
||||
expect(wrapper.emitted('update:coords')?.[0]?.[0]).toEqual({
|
||||
latitude: '46.5802596',
|
||||
longitude: '0.3404333',
|
||||
geoManual: false,
|
||||
})
|
||||
})
|
||||
|
||||
it('signale l\'echec sans emettre quand la BAN ne trouve rien', async () => {
|
||||
geocodeMock.mockResolvedValueOnce(null)
|
||||
const wrapper = mountPin()
|
||||
|
||||
await wrapper.find('[data-testid="geo-regeocode"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.emitted('update:coords')).toBeUndefined()
|
||||
expect(wrapper.find('[data-testid="geo-regeocode-failed"]').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('masque le bouton en lecture seule', () => {
|
||||
const wrapper = mountPin({ readonly: true })
|
||||
|
||||
expect(wrapper.find('[data-testid="geo-regeocode"]').exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -1,16 +1,21 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { defineComponent, h, ref, computed } from 'vue'
|
||||
import { emptyAddress } from '~/modules/commercial/types/clientForm'
|
||||
import ClientAddressBlock from '../ClientAddressBlock.vue'
|
||||
|
||||
// Le composable BAN est mocke : aucun appel reseau, aucune suggestion chargee.
|
||||
// On reproduit ainsi l'etat « adresse persistee, mais liste de suggestions
|
||||
// vide » (remontage apres validation / edition d'une adresse existante).
|
||||
// Mocks controlables du composable BAN (hoisted) : chaque test configure le
|
||||
// comportement de searchCity / searchAddress (succes, rejet, rejet-puis-succes).
|
||||
// Par defaut ils renvoient undefined (aucune suggestion) — etat « adresse
|
||||
// persistee mais liste vide » couvert par les tests d'affichage.
|
||||
const { searchCityMock, searchAddressMock } = vi.hoisted(() => ({
|
||||
searchCityMock: vi.fn(),
|
||||
searchAddressMock: vi.fn(),
|
||||
}))
|
||||
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
||||
useAddressAutocomplete: () => ({
|
||||
searchCity: vi.fn(),
|
||||
searchAddress: vi.fn(),
|
||||
searchCity: searchCityMock,
|
||||
searchAddress: searchAddressMock,
|
||||
}),
|
||||
}))
|
||||
|
||||
@@ -31,6 +36,7 @@ const MalioInputAutocompleteStub = defineComponent({
|
||||
minSearchLength: { type: Number, default: 0 },
|
||||
label: { type: String, default: '' },
|
||||
readonly: { type: Boolean, default: false },
|
||||
allowCreate: { type: Boolean, default: false },
|
||||
},
|
||||
emits: ['update:modelValue', 'search', 'select'],
|
||||
setup(props) {
|
||||
@@ -59,6 +65,8 @@ function mountBlock(street: string | null) {
|
||||
MalioSelectCheckbox: true,
|
||||
MalioInputText: true,
|
||||
MalioInputAutocomplete: MalioInputAutocompleteStub,
|
||||
// Pin geographique (M6.1) : teste dans AddressGeoPin.spec.ts.
|
||||
AddressGeoPin: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -73,6 +81,14 @@ describe('ClientAddressBlock — affichage de l\'adresse persistee', () => {
|
||||
|
||||
expect(values).toContain('8 Boulevard du Port')
|
||||
})
|
||||
|
||||
// ERP-119 : saisie manuelle possible quand la BAN ne trouve rien -> allow-create
|
||||
// (sans cette prop, MalioInputAutocomplete efface le texte non selectionne au blur).
|
||||
it('active allow-create sur le champ Adresse (saisie manuelle libre)', () => {
|
||||
const wrapper = mountBlock(null)
|
||||
|
||||
expect(wrapper.findComponent(MalioInputAutocompleteStub).props('allowCreate')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -116,6 +132,8 @@ describe('ClientAddressBlock — mapping erreur par champ (ERP-101)', () => {
|
||||
MalioSelectCheckbox: true,
|
||||
MalioInputAutocomplete: MalioInputAutocompleteStub,
|
||||
MalioInputText: MalioInputTextProbe,
|
||||
// Pin geographique (M6.1) : teste dans AddressGeoPin.spec.ts.
|
||||
AddressGeoPin: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -129,4 +147,84 @@ describe('ClientAddressBlock — mapping erreur par champ (ERP-101)', () => {
|
||||
)
|
||||
expect(field?.attributes('data-error')).toBe('Code postal invalide.')
|
||||
})
|
||||
|
||||
// ERP-119 : type d'adresse (propertyPath back `isProspect`), sites et
|
||||
// categories sont obligatoires ; leurs violations 422 doivent s'afficher sous
|
||||
// le champ correspondant (bindings :error de ClientAddressBlock).
|
||||
it('affiche l\'erreur serveur sur type d\'adresse (propertyPath isProspect)', () => {
|
||||
const wrapper = mountWithErrors({ isProspect: 'Le type d\'adresse est obligatoire.' })
|
||||
|
||||
const field = wrapper.findAll('malio-select-stub').find(
|
||||
el => el.attributes('label') === 'commercial.clients.form.address.addressType',
|
||||
)
|
||||
expect(field?.attributes('error')).toBe('Le type d\'adresse est obligatoire.')
|
||||
})
|
||||
|
||||
it('affiche les erreurs serveur sur sites et categories', () => {
|
||||
const wrapper = mountWithErrors({
|
||||
sites: 'Au moins un site est obligatoire.',
|
||||
categories: 'Au moins une catégorie est obligatoire.',
|
||||
})
|
||||
|
||||
const checkboxes = wrapper.findAll('malio-select-checkbox-stub')
|
||||
const sitesField = checkboxes.find(el => el.attributes('label') === 'commercial.clients.form.address.sites')
|
||||
const categoriesField = checkboxes.find(el => el.attributes('label') === 'commercial.clients.form.address.categories')
|
||||
|
||||
expect(sitesField?.attributes('error')).toBe('Au moins un site est obligatoire.')
|
||||
expect(categoriesField?.attributes('error')).toBe('Au moins une catégorie est obligatoire.')
|
||||
})
|
||||
})
|
||||
|
||||
describe('ClientAddressBlock — recherche adresse robuste (erreur BAN)', () => {
|
||||
beforeEach(() => {
|
||||
searchAddressMock.mockReset()
|
||||
})
|
||||
|
||||
it('n\'appelle pas la BAN en deca de 3 caracteres', async () => {
|
||||
const wrapper = mountBlock(null)
|
||||
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||
|
||||
auto.vm.$emit('search', 'ab')
|
||||
await flushPromises()
|
||||
|
||||
expect(searchAddressMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('relance la recherche apres une erreur (pas de bascule definitive)', async () => {
|
||||
searchAddressMock
|
||||
.mockRejectedValueOnce(new Error('BAN indisponible'))
|
||||
.mockResolvedValueOnce([
|
||||
{ label: '8 Boulevard du Port, Paris', street: '8 Boulevard du Port', postalCode: '75001', city: 'Paris' },
|
||||
])
|
||||
|
||||
const wrapper = mountBlock(null)
|
||||
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||
|
||||
// 1er essai -> erreur BAN.
|
||||
auto.vm.$emit('search', 'boulevard du port')
|
||||
await flushPromises()
|
||||
expect(searchAddressMock).toHaveBeenCalledTimes(1)
|
||||
|
||||
// 2e essai -> DOIT relancer l'appel (c'etait le bug : plus aucune recherche).
|
||||
auto.vm.$emit('search', 'boulevard du porte')
|
||||
await flushPromises()
|
||||
expect(searchAddressMock).toHaveBeenCalledTimes(2)
|
||||
|
||||
// L'autocompletion reste montee (aucune bascule en saisie libre).
|
||||
expect(wrapper.find('[data-testid="addr-autocomplete"]').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('emet « degraded » une seule fois malgre plusieurs erreurs', async () => {
|
||||
searchAddressMock.mockRejectedValue(new Error('BAN indisponible'))
|
||||
|
||||
const wrapper = mountBlock(null)
|
||||
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||
|
||||
auto.vm.$emit('search', 'rue de la paix')
|
||||
await flushPromises()
|
||||
auto.vm.$emit('search', 'rue de la paixx')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.emitted('degraded')).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { defineComponent, h, ref, computed } from 'vue'
|
||||
import { emptyAddress } from '~/modules/commercial/types/supplierForm'
|
||||
import SupplierAddressBlock from '../SupplierAddressBlock.vue'
|
||||
|
||||
// Mocks controlables du composable BAN (hoisted).
|
||||
const { searchCityMock, searchAddressMock } = vi.hoisted(() => ({
|
||||
searchCityMock: vi.fn(),
|
||||
searchAddressMock: vi.fn(),
|
||||
}))
|
||||
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
||||
useAddressAutocomplete: () => ({
|
||||
searchCity: searchCityMock,
|
||||
searchAddress: searchAddressMock,
|
||||
}),
|
||||
}))
|
||||
|
||||
// Auto-imports Nuxt/Vue utilises sans import explicite par le composant.
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
vi.stubGlobal('ref', ref)
|
||||
vi.stubGlobal('computed', computed)
|
||||
|
||||
// Stub de MalioInputAutocomplete : expose les `value` des options + allowCreate.
|
||||
const MalioInputAutocompleteStub = defineComponent({
|
||||
name: 'MalioInputAutocomplete',
|
||||
props: {
|
||||
modelValue: { type: [String, Number, null], default: undefined },
|
||||
options: { type: Array as () => { value: string | number, label: string }[], default: () => [] },
|
||||
loading: { type: Boolean, default: false },
|
||||
minSearchLength: { type: Number, default: 0 },
|
||||
label: { type: String, default: '' },
|
||||
readonly: { type: Boolean, default: false },
|
||||
allowCreate: { type: Boolean, default: false },
|
||||
},
|
||||
emits: ['update:modelValue', 'search', 'select'],
|
||||
setup(props) {
|
||||
return () => h('div', {
|
||||
'data-testid': 'addr-autocomplete',
|
||||
'data-options': JSON.stringify(props.options.map(o => o.value)),
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
function mountBlock(overrides: Record<string, unknown> = {}, errors?: Record<string, string>) {
|
||||
return mount(SupplierAddressBlock, {
|
||||
props: {
|
||||
modelValue: { ...emptyAddress(), ...overrides },
|
||||
title: 'Adresse 1',
|
||||
categoryOptions: [],
|
||||
siteOptions: [],
|
||||
contactOptions: [],
|
||||
countryOptions: [],
|
||||
...(errors ? { errors } : {}),
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
MalioButtonIcon: true,
|
||||
MalioCheckbox: true,
|
||||
MalioInputNumber: true,
|
||||
MalioSelect: true,
|
||||
MalioSelectCheckbox: true,
|
||||
MalioInputText: true,
|
||||
MalioInputAutocomplete: MalioInputAutocompleteStub,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
describe('SupplierAddressBlock — specificites M2 (type, bennes, triage)', () => {
|
||||
it('rend un select de type d\'adresse (en attendant l\'arbitrage metier)', () => {
|
||||
const wrapper = mountBlock()
|
||||
const addressTypeSelect = wrapper.findAll('malio-select-stub').find(
|
||||
el => el.attributes('label') === 'commercial.suppliers.form.address.addressType',
|
||||
)
|
||||
expect(addressTypeSelect).toBeDefined()
|
||||
})
|
||||
|
||||
it('rend le stepper Bennes et la case Prestation de triage (champs specifiques fournisseur)', () => {
|
||||
const wrapper = mountBlock()
|
||||
expect(wrapper.find('malio-input-number-stub').exists()).toBe(true)
|
||||
expect(wrapper.find('malio-checkbox-stub').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('ne rend aucun champ d\'email de facturation (difference M1)', () => {
|
||||
const wrapper = mountBlock()
|
||||
// Aucun MalioInputEmail dans le bloc adresse fournisseur.
|
||||
expect(wrapper.find('malio-input-email-stub').exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('SupplierAddressBlock — mapping erreur par champ (ERP-101)', () => {
|
||||
it('affiche l\'erreur serveur du type d\'adresse (propertyPath addressType) sur le select', () => {
|
||||
const wrapper = mountBlock({}, { addressType: 'Le type d\'adresse est obligatoire.' })
|
||||
const addressTypeSelect = wrapper.findAll('malio-select-stub').find(
|
||||
el => el.attributes('label') === 'commercial.suppliers.form.address.addressType',
|
||||
)
|
||||
expect(addressTypeSelect?.attributes('error')).toBe('Le type d\'adresse est obligatoire.')
|
||||
})
|
||||
|
||||
it('affiche les erreurs serveur sur sites et categories', () => {
|
||||
const wrapper = mountBlock({}, {
|
||||
sites: 'Au moins un site est obligatoire.',
|
||||
categories: 'Au moins une catégorie est obligatoire.',
|
||||
})
|
||||
const checkboxes = wrapper.findAll('malio-select-checkbox-stub')
|
||||
const sitesField = checkboxes.find(el => el.attributes('label') === 'commercial.suppliers.form.address.sites')
|
||||
const categoriesField = checkboxes.find(el => el.attributes('label') === 'commercial.suppliers.form.address.categories')
|
||||
|
||||
expect(sitesField?.attributes('error')).toBe('Au moins un site est obligatoire.')
|
||||
expect(categoriesField?.attributes('error')).toBe('Au moins une catégorie est obligatoire.')
|
||||
})
|
||||
|
||||
it('affiche l\'erreur serveur sur le code postal', () => {
|
||||
const wrapper = mountBlock({}, { postalCode: 'Code postal invalide.' })
|
||||
const field = wrapper.findAll('malio-input-text-stub').find(
|
||||
el => el.attributes('label') === 'commercial.suppliers.form.address.postalCode',
|
||||
)
|
||||
expect(field?.attributes('error')).toBe('Code postal invalide.')
|
||||
})
|
||||
})
|
||||
|
||||
describe('SupplierAddressBlock — autocompletion adresse (BAN) robuste', () => {
|
||||
beforeEach(() => {
|
||||
searchAddressMock.mockReset()
|
||||
})
|
||||
|
||||
it('n\'appelle pas la BAN en deca de 3 caracteres', async () => {
|
||||
const wrapper = mountBlock()
|
||||
wrapper.findComponent(MalioInputAutocompleteStub).vm.$emit('search', 'ab')
|
||||
await flushPromises()
|
||||
expect(searchAddressMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('relance la recherche apres une erreur (pas de bascule definitive)', async () => {
|
||||
searchAddressMock
|
||||
.mockRejectedValueOnce(new Error('BAN indisponible'))
|
||||
.mockResolvedValueOnce([
|
||||
{ label: '8 Boulevard du Port, Paris', street: '8 Boulevard du Port', postalCode: '75001', city: 'Paris' },
|
||||
])
|
||||
|
||||
const wrapper = mountBlock()
|
||||
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||
|
||||
auto.vm.$emit('search', 'boulevard du port')
|
||||
await flushPromises()
|
||||
auto.vm.$emit('search', 'boulevard du porte')
|
||||
await flushPromises()
|
||||
|
||||
expect(searchAddressMock).toHaveBeenCalledTimes(2)
|
||||
expect(wrapper.find('[data-testid="addr-autocomplete"]').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('emet « degraded » une seule fois malgre plusieurs erreurs', async () => {
|
||||
searchAddressMock.mockRejectedValue(new Error('BAN indisponible'))
|
||||
|
||||
const wrapper = mountBlock()
|
||||
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||
|
||||
auto.vm.$emit('search', 'rue de la paix')
|
||||
await flushPromises()
|
||||
auto.vm.$emit('search', 'rue de la paixx')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.emitted('degraded')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('active allow-create sur le champ Adresse (saisie manuelle libre)', () => {
|
||||
const wrapper = mountBlock()
|
||||
expect(wrapper.findComponent(MalioInputAutocompleteStub).props('allowCreate')).toBe(true)
|
||||
})
|
||||
|
||||
it('inclut la rue courante dans les options meme sans recherche BAN', () => {
|
||||
const wrapper = mountBlock({ street: '8 Boulevard du Port' })
|
||||
const values = JSON.parse(wrapper.find('[data-testid="addr-autocomplete"]').attributes('data-options') ?? '[]')
|
||||
expect(values).toContain('8 Boulevard du Port')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { defineComponent, h, ref, computed } from 'vue'
|
||||
import { emptyContact } from '~/modules/commercial/types/supplierForm'
|
||||
import SupplierContactBlock from '../SupplierContactBlock.vue'
|
||||
|
||||
// Auto-imports Nuxt/Vue utilises sans import explicite par le composant.
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
vi.stubGlobal('ref', ref)
|
||||
vi.stubGlobal('computed', computed)
|
||||
|
||||
/** Stub d'un champ Malio qui re-expose la prop `error` recue dans un data-* attribut. */
|
||||
function errorProbe(testid: string) {
|
||||
return defineComponent({
|
||||
name: `Probe-${testid}`,
|
||||
props: {
|
||||
modelValue: { type: [String, Number, null], default: undefined },
|
||||
error: { type: String, default: '' },
|
||||
label: { type: String, default: '' },
|
||||
readonly: { type: Boolean, default: false },
|
||||
},
|
||||
setup(props) {
|
||||
return () => h('div', { 'data-testid': testid, 'data-error': props.error })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function mountBlock(errors?: Record<string, string>) {
|
||||
return mount(SupplierContactBlock, {
|
||||
props: {
|
||||
modelValue: emptyContact(),
|
||||
title: 'Contact 1',
|
||||
...(errors ? { errors } : {}),
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
MalioButtonIcon: true,
|
||||
MalioInputPhone: true,
|
||||
MalioInputText: errorProbe('contact-text'),
|
||||
MalioInputEmail: errorProbe('contact-email'),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
describe('SupplierContactBlock — mapping erreur par champ (ERP-101)', () => {
|
||||
it('affiche l\'erreur serveur sur le champ email via la prop errors', () => {
|
||||
const wrapper = mountBlock({ email: 'Adresse e-mail invalide.' })
|
||||
expect(wrapper.find('[data-testid="contact-email"]').attributes('data-error')).toBe('Adresse e-mail invalide.')
|
||||
})
|
||||
|
||||
it('laisse les champs sans erreur quand errors est absent', () => {
|
||||
const wrapper = mountBlock()
|
||||
expect(wrapper.find('[data-testid="contact-email"]').attributes('data-error')).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -30,6 +30,10 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
||||
if (url === '/sites') {
|
||||
return Promise.resolve({ member: [{ '@id': '/api/sites/1', name: 'Chatellerault', postalCode: '86100' }] })
|
||||
}
|
||||
if (url === '/countries') {
|
||||
// Pays : value === label === name (l'adresse stocke le nom).
|
||||
return Promise.resolve({ member: [{ '@id': '/api/countries/1', code: 'FR', name: 'France' }] })
|
||||
}
|
||||
return Promise.resolve({
|
||||
member: [{ '@id': '/api/x/1', code: 'X', label: 'Libelle X' }],
|
||||
})
|
||||
@@ -44,6 +48,8 @@ describe('useClientReferentials.loadCommon (resilience ERP-102)', () => {
|
||||
expect(refs.sites.value).toEqual([{ value: '/api/sites/1', label: '86' }])
|
||||
expect(refs.tvaModes.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
||||
expect(refs.banks.value).toEqual([{ value: '/api/x/1', label: 'Libelle X' }])
|
||||
// Pays : value = nom du pays (et non l'IRI).
|
||||
expect(refs.countries.value).toEqual([{ value: 'France', label: 'France' }])
|
||||
|
||||
// Seul le select en echec reste vide.
|
||||
expect(refs.categories.value).toEqual([])
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
// Mocks des composables auto-importes par Nuxt (indisponibles sous happy-dom).
|
||||
const mockGet = vi.hoisted(() => vi.fn())
|
||||
const mockPatch = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.stubGlobal('useApi', () => ({
|
||||
get: mockGet,
|
||||
post: vi.fn(),
|
||||
put: vi.fn(),
|
||||
patch: mockPatch,
|
||||
delete: vi.fn(),
|
||||
}))
|
||||
|
||||
const { useSupplier } = await import('../useSupplier')
|
||||
|
||||
const SAMPLE = { '@id': '/api/suppliers/85', id: 85, companyName: 'DOD59393F 862875', isArchived: false }
|
||||
|
||||
describe('useSupplier', () => {
|
||||
beforeEach(() => {
|
||||
mockGet.mockReset()
|
||||
mockPatch.mockReset()
|
||||
mockGet.mockResolvedValue(SAMPLE)
|
||||
mockPatch.mockResolvedValue({ ...SAMPLE, isArchived: true })
|
||||
})
|
||||
|
||||
it('charge le detail via GET /suppliers/{id} en Hydra, sans toast', async () => {
|
||||
const { supplier, load } = useSupplier(85)
|
||||
await load()
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith(
|
||||
'/suppliers/85',
|
||||
{},
|
||||
expect.objectContaining({
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
}),
|
||||
)
|
||||
expect(supplier.value).toEqual(SAMPLE)
|
||||
})
|
||||
|
||||
it('bascule loading pendant le chargement et le retombe a false', async () => {
|
||||
const { loading, load } = useSupplier(85)
|
||||
const promise = load()
|
||||
expect(loading.value).toBe(true)
|
||||
await promise
|
||||
expect(loading.value).toBe(false)
|
||||
})
|
||||
|
||||
it('marque error et laisse supplier null si le GET echoue (404...)', async () => {
|
||||
mockGet.mockRejectedValueOnce(new Error('not found'))
|
||||
const { supplier, error, load } = useSupplier(99)
|
||||
await load()
|
||||
expect(error.value).toBe(true)
|
||||
expect(supplier.value).toBeNull()
|
||||
})
|
||||
|
||||
it('archive() PATCHe { isArchived: true } sans toast puis RECHARGE le detail complet', async () => {
|
||||
// 1er GET = chargement initial, 2e GET = rechargement post-archivage.
|
||||
mockGet.mockResolvedValueOnce(SAMPLE)
|
||||
mockGet.mockResolvedValueOnce({ ...SAMPLE, isArchived: true })
|
||||
const { supplier, load, archive } = useSupplier(85)
|
||||
await load()
|
||||
await archive()
|
||||
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/suppliers/85',
|
||||
{ isArchived: true },
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
// Le detail est re-fetch (le PATCH ne renvoie pas l'embed complet).
|
||||
expect(mockGet).toHaveBeenCalledTimes(2)
|
||||
expect(supplier.value?.isArchived).toBe(true)
|
||||
})
|
||||
|
||||
it('restore() PATCHe { isArchived: false } (payload isArchived SEUL)', async () => {
|
||||
const { load, restore } = useSupplier(85)
|
||||
await load()
|
||||
await restore()
|
||||
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/suppliers/85',
|
||||
{ isArchived: false },
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('propage l\'erreur (ex: 403 sans permission archive, 409 conflit homonyme) au lieu de l\'avaler', async () => {
|
||||
const forbidden = { response: { status: 403 } }
|
||||
mockPatch.mockRejectedValueOnce(forbidden)
|
||||
const { load, archive } = useSupplier(85)
|
||||
await load()
|
||||
await expect(archive()).rejects.toBe(forbidden)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
// `useApi` est un auto-import Nuxt : on le stubbe globalement pour intercepter
|
||||
// les appels de chargement des referentiels et controler les reponses Hydra.
|
||||
const mockGet = vi.hoisted(() => vi.fn())
|
||||
vi.stubGlobal('useApi', () => ({ get: mockGet }))
|
||||
|
||||
const { useSupplierReferentials } = await import('../useSupplierReferentials')
|
||||
|
||||
describe('useSupplierReferentials', () => {
|
||||
beforeEach(() => {
|
||||
mockGet.mockReset()
|
||||
mockGet.mockResolvedValue({ member: [] })
|
||||
})
|
||||
|
||||
it('charge les categories filtrees sur le type FOURNISSEUR (RG-2.10)', async () => {
|
||||
await useSupplierReferentials().loadCommon()
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith(
|
||||
'/categories',
|
||||
expect.objectContaining({ pagination: 'false', typeCode: 'FOURNISSEUR' }),
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('mappe les categories en options { value: IRI, label: name, code }', async () => {
|
||||
mockGet.mockImplementation((url: string) => {
|
||||
if (url === '/categories') {
|
||||
return Promise.resolve({ member: [{ '@id': '/api/categories/9', code: 'NEGOCIANT', name: 'Négociant' }] })
|
||||
}
|
||||
return Promise.resolve({ member: [] })
|
||||
})
|
||||
|
||||
const refs = useSupplierReferentials()
|
||||
await refs.loadCommon()
|
||||
|
||||
expect(refs.categories.value).toEqual([{ value: '/api/categories/9', label: 'Négociant', code: 'NEGOCIANT' }])
|
||||
})
|
||||
|
||||
it('ne charge ni distributeurs ni courtiers (absents du modele fournisseur)', async () => {
|
||||
await useSupplierReferentials().loadCommon()
|
||||
|
||||
const urls = mockGet.mock.calls.map(c => c[0])
|
||||
expect(urls).not.toContain('/clients')
|
||||
expect(urls).toEqual(
|
||||
expect.arrayContaining(['/categories', '/sites', '/tva_modes', '/payment_delays', '/payment_types', '/banks']),
|
||||
)
|
||||
})
|
||||
|
||||
it('reste resilient : un referentiel en echec n\'empeche pas les autres', async () => {
|
||||
mockGet.mockImplementation((url: string) => {
|
||||
if (url === '/categories') return Promise.reject(new Error('403'))
|
||||
if (url === '/banks') return Promise.resolve({ member: [{ '@id': '/api/banks/1', code: 'SG', label: 'Société Générale' }] })
|
||||
return Promise.resolve({ member: [] })
|
||||
})
|
||||
|
||||
const refs = useSupplierReferentials()
|
||||
await refs.loadCommon()
|
||||
|
||||
expect(refs.categories.value).toEqual([])
|
||||
expect(refs.banks.value).toEqual([{ value: '/api/banks/1', label: 'Société Générale' }])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,85 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import type { HydraCollection } from '~/shared/utils/api'
|
||||
import type { Supplier } from '../useSuppliersRepository'
|
||||
|
||||
// `useApi` est un auto-import Nuxt : on le stubbe globalement pour intercepter
|
||||
// les appels declenches par usePaginatedList (que useSuppliersRepository enveloppe)
|
||||
// et controler les reponses. Meme pattern que useClientsRepository.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 { useSuppliersRepository } = await import('../useSuppliersRepository')
|
||||
|
||||
/** Envelope Hydra minimale (la liste reelle des membres importe peu ici). */
|
||||
function makeHydra(total: number): HydraCollection<Supplier> {
|
||||
return { totalItems: total, member: [] }
|
||||
}
|
||||
|
||||
describe('useSuppliersRepository', () => {
|
||||
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 /suppliers en page 1 par defaut', async () => {
|
||||
const repo = useSuppliersRepository()
|
||||
await repo.fetch()
|
||||
|
||||
expect(mockGet).toHaveBeenLastCalledWith(
|
||||
'/suppliers',
|
||||
{ page: 1, itemsPerPage: 10 },
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('pousse les filtres du drawer (categories multi, sites, archives inclus) et retombe en page 1', async () => {
|
||||
const repo = useSuppliersRepository()
|
||||
await repo.fetch()
|
||||
await repo.goToPage(2)
|
||||
expect(repo.currentPage.value).toBe(2)
|
||||
|
||||
await repo.setFilters(
|
||||
{
|
||||
search: 'acme',
|
||||
'categoryCode[]': ['NEGOCIANT', 'TRANSPORTEUR'],
|
||||
'siteId[]': ['86', '17'],
|
||||
includeArchived: true,
|
||||
},
|
||||
{ replace: true },
|
||||
)
|
||||
|
||||
expect(repo.currentPage.value).toBe(1)
|
||||
expect(mockGet).toHaveBeenLastCalledWith(
|
||||
'/suppliers',
|
||||
{
|
||||
search: 'acme',
|
||||
'categoryCode[]': ['NEGOCIANT', 'TRANSPORTEUR'],
|
||||
'siteId[]': ['86', '17'],
|
||||
includeArchived: true,
|
||||
page: 1,
|
||||
itemsPerPage: 10,
|
||||
},
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('repasse a une query propre apres reinitialisation des filtres', async () => {
|
||||
const repo = useSuppliersRepository()
|
||||
await repo.setFilters({ search: 'acme', includeArchived: true }, { replace: true })
|
||||
await repo.setFilters({}, { replace: true })
|
||||
|
||||
expect(mockGet).toHaveBeenLastCalledWith(
|
||||
'/suppliers',
|
||||
{ page: 1, itemsPerPage: 10 },
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -3,7 +3,7 @@ import { ref } from 'vue'
|
||||
/**
|
||||
* Charge les referentiels (listes courtes) alimentant les selects de l'ecran
|
||||
* « Ajouter un client » : categories, sites, modes de TVA, delais et types de
|
||||
* reglement, banques, et les listes distributeurs / courtiers.
|
||||
* reglement, banques, pays, et les listes distributeurs / courtiers.
|
||||
*
|
||||
* Toutes les collections sont recuperees en entier via l'echappatoire prevue
|
||||
* `?pagination=false` (referentiels de quelques dizaines d'entrees max), avec
|
||||
@@ -57,6 +57,11 @@ interface ClientMember extends HydraMember {
|
||||
companyName: string
|
||||
}
|
||||
|
||||
interface CountryMember extends HydraMember {
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
const LD_JSON_HEADERS = { Accept: 'application/ld+json' }
|
||||
|
||||
export function useClientReferentials() {
|
||||
@@ -68,6 +73,7 @@ export function useClientReferentials() {
|
||||
const paymentDelays = ref<RefOption[]>([])
|
||||
const paymentTypes = ref<PaymentTypeOption[]>([])
|
||||
const banks = ref<RefOption[]>([])
|
||||
const countries = ref<RefOption[]>([])
|
||||
const distributors = ref<ClientOption[]>([])
|
||||
const brokers = ref<ClientOption[]>([])
|
||||
|
||||
@@ -99,7 +105,9 @@ export function useClientReferentials() {
|
||||
*/
|
||||
async function loadCommon(): Promise<void> {
|
||||
await Promise.allSettled([
|
||||
fetchAll<CategoryMember>('/categories')
|
||||
// Taxonomie multi-types (ERP-84) : un client ne porte que des categories
|
||||
// de type CLIENT (pas FOURNISSEUR) -> on filtre la collection cote API.
|
||||
fetchAll<CategoryMember>('/categories', { typeCode: 'CLIENT' })
|
||||
.then((cats) => { categories.value = cats.map(c => ({ value: c['@id'], label: c.name, code: c.code })) }),
|
||||
fetchAll<SiteMember>('/sites')
|
||||
// Libelle = numero de departement (2 premiers chiffres du code
|
||||
@@ -114,6 +122,12 @@ export function useClientReferentials() {
|
||||
.then((types) => { paymentTypes.value = types.map(t => ({ value: t['@id'], label: t.label, code: t.code })) }),
|
||||
fetchAll<ReferentialMember>('/banks')
|
||||
.then((banksList) => { banks.value = banksList.map(b => ({ value: b['@id'], label: b.label })) }),
|
||||
// Pays (ERP-116) : la valeur d'option est le NOM du pays (et non l'IRI),
|
||||
// car l'adresse stocke `country` en chaine libre (« France »...). On
|
||||
// conserve ainsi la compatibilite avec les adresses existantes sans FK
|
||||
// ni migration de donnees a ce stade. value === label.
|
||||
fetchAll<CountryMember>('/countries')
|
||||
.then((list) => { countries.value = list.map(c => ({ value: c.name, label: c.name })) }),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -142,6 +156,7 @@ export function useClientReferentials() {
|
||||
paymentDelays,
|
||||
paymentTypes,
|
||||
banks,
|
||||
countries,
|
||||
distributors,
|
||||
brokers,
|
||||
loadCommon,
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { ref } from 'vue'
|
||||
import type { SupplierDetail } from '~/modules/commercial/utils/supplierConsultation'
|
||||
|
||||
/**
|
||||
* Chargement et actions d'archivage d'un fournisseur unique (ecran « Consultation
|
||||
* fournisseur », ERP-95). Miroir de `useClient` (M1). Lit le detail embarque via
|
||||
* `GET /api/suppliers/{id}` (contacts / adresses / ribs sous `supplier:item:read` /
|
||||
* `supplier:read:accounting`) et expose les bascules d'archivage (PATCH `isArchived`
|
||||
* SEUL — tout autre champ => 422).
|
||||
*
|
||||
* L'en-tete `Accept: application/ld+json` est impose pour obtenir le payload
|
||||
* Hydra complet (sans lui, API Platform 4 renvoie une representation reduite).
|
||||
*
|
||||
* Etat 100 % local a l'instance (refs) — aucune persistance URL. Les erreurs
|
||||
* d'archivage/restauration (notamment le 409 d'homonyme actif a la restauration)
|
||||
* sont PROPAGEES a l'appelant, qui decide du toast a afficher.
|
||||
*/
|
||||
export function useSupplier(id: number | string) {
|
||||
const api = useApi()
|
||||
|
||||
const supplier = ref<SupplierDetail | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(false)
|
||||
|
||||
/** Recupere le detail complet (embed contacts/adresses/ribs + comptabilite). */
|
||||
function fetchDetail(): Promise<SupplierDetail> {
|
||||
return api.get<SupplierDetail>(
|
||||
`/suppliers/${id}`,
|
||||
{},
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
}
|
||||
|
||||
/** Charge le detail du fournisseur. En cas d'echec : `error = true`, `supplier = null`. */
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
error.value = false
|
||||
try {
|
||||
supplier.value = await fetchDetail()
|
||||
}
|
||||
catch {
|
||||
error.value = true
|
||||
supplier.value = null
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bascule l'archivage (PATCH `isArchived` SEUL — tout autre champ => 422),
|
||||
* puis RECHARGE le detail complet : la reponse du PATCH ne porte que le groupe
|
||||
* `supplier:read` (ni l'embed contacts/adresses/ribs ni les libelles des
|
||||
* referentiels comptables), un simple merge laisserait l'affichage incoherent.
|
||||
* Toute erreur (notamment le 409 d'homonyme actif a la restauration) est
|
||||
* propagee a l'appelant AVANT le rechargement.
|
||||
*/
|
||||
async function setArchived(isArchived: boolean): Promise<void> {
|
||||
await api.patch(`/suppliers/${id}`, { isArchived }, { toast: false })
|
||||
supplier.value = await fetchDetail()
|
||||
}
|
||||
|
||||
return {
|
||||
supplier,
|
||||
loading,
|
||||
error,
|
||||
load,
|
||||
archive: () => setArchived(true),
|
||||
restore: () => setArchived(false),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Composable d'erreurs partage des ecrans fournisseur (creation + edition, M2
|
||||
* Commercial). Miroir de `useClientFormErrors` (M1) :
|
||||
* - un `useFormErrors` par groupe scalaire (Principal / Information /
|
||||
* Comptabilite) : violations 422 affichees inline sous chaque champ ;
|
||||
* - un tableau d'erreurs PAR LIGNE pour chaque collection (contacts /
|
||||
* adresses / RIB), aligne sur l'index du `v-for`.
|
||||
*
|
||||
* `mapRowError` ne toaste PAS lui-meme : il retourne un booleen (true = mappe
|
||||
* inline). Chaque page conserve ainsi son propre fallback dans le `catch`.
|
||||
*/
|
||||
import { ref, type Ref } from 'vue'
|
||||
import { mapViolationsToRecord } from '~/shared/utils/api'
|
||||
|
||||
export function useSupplierFormErrors() {
|
||||
const mainErrors = useFormErrors()
|
||||
const informationErrors = useFormErrors()
|
||||
const accountingErrors = useFormErrors()
|
||||
const contactErrors = ref<Record<string, string>[]>([])
|
||||
const addressErrors = ref<Record<string, string>[]>([])
|
||||
const ribErrors = ref<Record<string, string>[]>([])
|
||||
|
||||
/**
|
||||
* Mappe l'erreur d'une ligne de collection sur le tableau cible (par index).
|
||||
* 422 avec violations exploitables → erreurs inline sous les champs de la
|
||||
* ligne + retourne true. Sinon → ne touche pas la cible et retourne false.
|
||||
*/
|
||||
function mapRowError(
|
||||
error: unknown,
|
||||
target: Ref<Record<string, string>[]>,
|
||||
index: number,
|
||||
): boolean {
|
||||
const response = (error as { response?: { status?: number, _data?: unknown } })?.response
|
||||
const mapped = response?.status === 422 ? mapViolationsToRecord(response._data) : {}
|
||||
if (Object.keys(mapped).length > 0) {
|
||||
target.value[index] = mapped
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Soumet TOUS les blocs d'une collection (contacts / adresses / RIB) en
|
||||
* collectant les erreurs par index : on n'arrete PAS au premier bloc en echec
|
||||
* (decision ERP-110 / ERP-101). Reinitialise le tableau d'erreurs cible, tente
|
||||
* chaque ligne via `saveRow`, mappe les 422 inline (mapRowError) ou delegue le
|
||||
* fallback a `onUnmappedError`. `shouldSkip` permet d'ignorer les blocs vides.
|
||||
* Retourne true si au moins un bloc a echoue.
|
||||
*/
|
||||
async function submitRows<T>(
|
||||
rows: T[],
|
||||
target: Ref<Record<string, string>[]>,
|
||||
saveRow: (row: T, index: number) => Promise<void>,
|
||||
onUnmappedError: (error: unknown, index: number) => void,
|
||||
shouldSkip?: (row: T, index: number) => boolean,
|
||||
): Promise<boolean> {
|
||||
target.value = []
|
||||
let hasError = false
|
||||
for (let index = 0; index < rows.length; index++) {
|
||||
const row = rows[index] as T
|
||||
if (shouldSkip?.(row, index)) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
await saveRow(row, index)
|
||||
}
|
||||
catch (error) {
|
||||
if (!mapRowError(error, target, index)) {
|
||||
onUnmappedError(error, index)
|
||||
}
|
||||
hasError = true
|
||||
}
|
||||
}
|
||||
|
||||
return hasError
|
||||
}
|
||||
|
||||
return {
|
||||
mainErrors,
|
||||
informationErrors,
|
||||
accountingErrors,
|
||||
contactErrors,
|
||||
addressErrors,
|
||||
ribErrors,
|
||||
mapRowError,
|
||||
submitRows,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
/**
|
||||
* Charge les referentiels (listes courtes) alimentant les selects de l'ecran
|
||||
* « Ajouter un fournisseur » : categories (type FOURNISSEUR), sites, modes de TVA,
|
||||
* delais et types de reglement, banques. Miroir de `useClientReferentials` (M1).
|
||||
*
|
||||
* Toutes les collections sont recuperees en entier via l'echappatoire prevue
|
||||
* `?pagination=false` (referentiels de quelques dizaines d'entrees max), avec
|
||||
* l'en-tete `Accept: application/ld+json` impose par API Platform 4 pour obtenir
|
||||
* l'enveloppe Hydra (`member`). Les valeurs d'option sont les IRI Hydra (`@id`)
|
||||
* renvoyees telles quelles dans les payloads POST/PATCH (relations M:1 / M:N).
|
||||
*
|
||||
* Difference M2 : pas de distributeurs/courtiers (absents du modele fournisseur).
|
||||
*
|
||||
* Etat 100 % local a l'instance (refs) — aucune persistance URL.
|
||||
*/
|
||||
|
||||
/** Option generique au format attendu par MalioSelect / MalioSelectCheckbox. */
|
||||
export interface RefOption {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
/** Option de type de reglement enrichie de son code stable (RG-2.07 / RG-2.08). */
|
||||
export interface PaymentTypeOption extends RefOption {
|
||||
code: string
|
||||
}
|
||||
|
||||
/** Option de categorie enrichie de son code stable. */
|
||||
export interface CategoryOption extends RefOption {
|
||||
code: string
|
||||
}
|
||||
|
||||
interface HydraMember {
|
||||
'@id': string
|
||||
}
|
||||
|
||||
interface CategoryMember extends HydraMember {
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
interface SiteMember extends HydraMember {
|
||||
name: string
|
||||
postalCode: string
|
||||
}
|
||||
|
||||
interface ReferentialMember extends HydraMember {
|
||||
code: string
|
||||
label: string
|
||||
}
|
||||
|
||||
interface CountryMember extends HydraMember {
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
const LD_JSON_HEADERS = { Accept: 'application/ld+json' }
|
||||
|
||||
export function useSupplierReferentials() {
|
||||
const api = useApi()
|
||||
|
||||
const categories = ref<CategoryOption[]>([])
|
||||
const sites = ref<RefOption[]>([])
|
||||
const tvaModes = ref<RefOption[]>([])
|
||||
const paymentDelays = ref<RefOption[]>([])
|
||||
const paymentTypes = ref<PaymentTypeOption[]>([])
|
||||
const banks = ref<RefOption[]>([])
|
||||
const countries = ref<RefOption[]>([])
|
||||
|
||||
/** Recupere une collection complete (pagination desactivee) en Hydra. */
|
||||
async function fetchAll<T extends HydraMember>(
|
||||
url: string,
|
||||
query: Record<string, string | string[]> = {},
|
||||
): Promise<T[]> {
|
||||
const res = await api.get<{ member?: T[] }>(
|
||||
url,
|
||||
{ pagination: 'false', ...query },
|
||||
{ headers: LD_JSON_HEADERS, toast: false },
|
||||
)
|
||||
return res.member ?? []
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge en parallele les referentiels communs.
|
||||
*
|
||||
* Chargement RESILIENT (Promise.allSettled) : chaque referentiel est isole.
|
||||
* Necessaire pour les roles metier qui n'ont pas toutes les permissions de
|
||||
* lecture (ex. Compta a `commercial.suppliers.view` mais pas forcement
|
||||
* `catalog.categories.view` ni `sites.view`). Un referentiel en echec reste
|
||||
* simplement vide.
|
||||
*/
|
||||
async function loadCommon(): Promise<void> {
|
||||
await Promise.allSettled([
|
||||
// Taxonomie multi-types (ERP-84) : un fournisseur ne porte que des
|
||||
// categories de type FOURNISSEUR (RG-2.10) -> on filtre cote API.
|
||||
fetchAll<CategoryMember>('/categories', { typeCode: 'FOURNISSEUR' })
|
||||
.then((cats) => { categories.value = cats.map(c => ({ value: c['@id'], label: c.name, code: c.code })) }),
|
||||
fetchAll<SiteMember>('/sites')
|
||||
// Libelle = numero de departement (2 premiers chiffres du code
|
||||
// postal du site), ex: 86100 -> « 86 ».
|
||||
.then((sitesList) => { sites.value = sitesList.map(s => ({ value: s['@id'], label: (s.postalCode ?? '').slice(0, 2) })) }),
|
||||
fetchAll<ReferentialMember>('/tva_modes')
|
||||
.then((tva) => { tvaModes.value = tva.map(t => ({ value: t['@id'], label: t.label })) }),
|
||||
fetchAll<ReferentialMember>('/payment_delays')
|
||||
.then((delays) => { paymentDelays.value = delays.map(d => ({ value: d['@id'], label: d.label })) }),
|
||||
fetchAll<ReferentialMember>('/payment_types')
|
||||
.then((types) => { paymentTypes.value = types.map(t => ({ value: t['@id'], label: t.label, code: t.code })) }),
|
||||
fetchAll<ReferentialMember>('/banks')
|
||||
.then((banksList) => { banks.value = banksList.map(b => ({ value: b['@id'], label: b.label })) }),
|
||||
// Pays (ERP-116) : la valeur d'option est le NOM du pays (et non l'IRI),
|
||||
// car l'adresse stocke `country` en chaine libre (« France »...). On
|
||||
// conserve ainsi la compatibilite avec les adresses existantes sans FK
|
||||
// ni migration de donnees a ce stade. value === label. Aligne sur les
|
||||
// clients (`useClientReferentials`) pour une liste de pays identique.
|
||||
fetchAll<CountryMember>('/countries')
|
||||
.then((list) => { countries.value = list.map(c => ({ value: c.name, label: c.name })) }),
|
||||
])
|
||||
}
|
||||
|
||||
return {
|
||||
categories,
|
||||
sites,
|
||||
tvaModes,
|
||||
paymentDelays,
|
||||
paymentTypes,
|
||||
banks,
|
||||
countries,
|
||||
loadCommon,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { usePaginatedList } from '~/shared/composables/usePaginatedList'
|
||||
|
||||
/**
|
||||
* Site Starseed rattache a une adresse du fournisseur, tel qu'embarque en LISTE
|
||||
* (groupe site:read) pour la colonne « Site » du Repertoire (badges colores).
|
||||
* Agrege des adresses cote back via Supplier::getSites() (cf. spec-back M2).
|
||||
*/
|
||||
export interface SupplierSite {
|
||||
id: number
|
||||
name: string
|
||||
color: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Categorie (type FOURNISSEUR) rattachee au fournisseur, embarquee en LISTE
|
||||
* (groupe category:read). La colonne « Catégories » affiche le `name` (et non le
|
||||
* `code` comme au M1 clients — decision spec-front M2 § Datatable).
|
||||
*/
|
||||
export interface SupplierCategory {
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Vue MINIMALE d'un fournisseur 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-93).
|
||||
*/
|
||||
export interface Supplier {
|
||||
id: number
|
||||
companyName: string
|
||||
categories: SupplierCategory[]
|
||||
sites: SupplierSite[]
|
||||
/** Date ISO de derniere modification (default:read) — colonne « Dernière activité ». */
|
||||
updatedAt: string | null
|
||||
isArchived: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Repertoire fournisseurs (ERP-93) — simple enveloppe de `usePaginatedList<Supplier>`
|
||||
* sur la ressource `/suppliers` (RG-13 : pagination serveur obligatoire ; jamais
|
||||
* de chargement integral en memoire). Miroir de `useClientsRepository` (M1).
|
||||
*
|
||||
* Les filtres (recherche, categories, sites, inclusion des 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`. Aucun reset au logout a gerer.
|
||||
*/
|
||||
export function useSuppliersRepository() {
|
||||
return usePaginatedList<Supplier>({ url: '/suppliers' })
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { defineComponent, h, ref } from 'vue'
|
||||
|
||||
// ── Auto-imports Nuxt stubbes globalement ───────────────────────────────────
|
||||
// La page ne les importe pas (auto-import) : on les expose en globals pour le
|
||||
// runtime de test (happy-dom). Meme philosophie que les autres specs commercial.
|
||||
const mockPush = vi.hoisted(() => vi.fn())
|
||||
const mockApiGet = vi.hoisted(() => vi.fn())
|
||||
const mockCan = vi.hoisted(() => vi.fn())
|
||||
const mockSetFilters = vi.hoisted(() => vi.fn())
|
||||
const mockFetch = vi.hoisted(() => vi.fn())
|
||||
const mockToastError = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
vi.stubGlobal('useHead', () => undefined)
|
||||
vi.stubGlobal('useApi', () => ({ get: mockApiGet }))
|
||||
vi.stubGlobal('useRouter', () => ({ push: mockPush }))
|
||||
vi.stubGlobal('useToast', () => ({ error: mockToastError, success: vi.fn() }))
|
||||
vi.stubGlobal('usePermissions', () => ({ can: mockCan }))
|
||||
|
||||
// Le repository est lui aussi un auto-import : on controle items + setFilters.
|
||||
vi.stubGlobal('useSuppliersRepository', () => ({
|
||||
items: ref([
|
||||
{
|
||||
id: 7,
|
||||
companyName: 'ACME',
|
||||
categories: [{ code: 'NEG', name: 'Négociant' }],
|
||||
sites: [{ id: 86, name: '86', color: '#123456' }],
|
||||
updatedAt: '2026-01-15T10:00:00+00:00',
|
||||
},
|
||||
]),
|
||||
totalItems: ref(1),
|
||||
currentPage: ref(1),
|
||||
itemsPerPage: ref(10),
|
||||
itemsPerPageOptions: ref([10, 25, 50]),
|
||||
fetch: mockFetch,
|
||||
goToPage: vi.fn(),
|
||||
setItemsPerPage: vi.fn(),
|
||||
setFilters: mockSetFilters,
|
||||
}))
|
||||
|
||||
// happy-dom n'implemente pas createObjectURL : on ajoute les methodes statiques
|
||||
// sur la classe URL existante (sans la remplacer — sinon `new URL()` casse).
|
||||
globalThis.URL.createObjectURL = vi.fn(() => 'blob:fake')
|
||||
globalThis.URL.revokeObjectURL = vi.fn()
|
||||
|
||||
// Import APRES les stubs (la page resout les auto-imports au top-level du module).
|
||||
const SuppliersIndex = (await import('../suppliers/index.vue')).default
|
||||
|
||||
// ── Stubs de composants ──────────────────────────────────────────────────────
|
||||
const ButtonStub = defineComponent({
|
||||
props: { label: { type: String, default: '' }, disabled: { type: Boolean, default: false } },
|
||||
emits: ['click'],
|
||||
setup(props, { emit }) {
|
||||
return () => h('button', { 'data-label': props.label, onClick: () => emit('click') }, props.label)
|
||||
},
|
||||
})
|
||||
|
||||
const DataTableStub = defineComponent({
|
||||
props: { items: { type: Array, default: () => [] } },
|
||||
emits: ['row-click', 'update:page', 'update:per-page'],
|
||||
setup(props, { emit }) {
|
||||
return () => h('div', { 'data-testid': 'datatable' },
|
||||
(props.items as Array<{ id: number }>).map(it =>
|
||||
h('tr', { 'data-row-id': it.id, onClick: () => emit('row-click', it) }),
|
||||
),
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
const DrawerStub = defineComponent({
|
||||
props: { modelValue: { type: Boolean, default: false } },
|
||||
setup(_, { slots }) {
|
||||
return () => h('div', {}, [slots.header?.(), slots.default?.(), slots.footer?.()])
|
||||
},
|
||||
})
|
||||
|
||||
const SlotStub = defineComponent({ setup(_, { slots }) { return () => h('div', {}, slots.default?.()) } })
|
||||
|
||||
const PageHeaderStub = defineComponent({
|
||||
setup(_, { slots }) { return () => h('div', {}, [slots.default?.(), slots.actions?.()]) },
|
||||
})
|
||||
|
||||
const CheckboxStub = defineComponent({
|
||||
props: { id: { type: String, default: '' }, modelValue: { type: Boolean, default: false } },
|
||||
emits: ['update:model-value'],
|
||||
setup(props, { emit }) {
|
||||
return () => h('input', {
|
||||
'type': 'checkbox',
|
||||
'data-id': props.id,
|
||||
'onChange': (e: Event) => emit('update:model-value', (e.target as HTMLInputElement).checked),
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const InputTextStub = defineComponent({ setup() { return () => h('input') } })
|
||||
|
||||
function mountPage() {
|
||||
return mount(SuppliersIndex, {
|
||||
global: {
|
||||
stubs: {
|
||||
PageHeader: PageHeaderStub,
|
||||
MalioButton: ButtonStub,
|
||||
MalioDataTable: DataTableStub,
|
||||
MalioDrawer: DrawerStub,
|
||||
MalioAccordion: SlotStub,
|
||||
MalioAccordionItem: SlotStub,
|
||||
MalioInputText: InputTextStub,
|
||||
MalioCheckbox: CheckboxStub,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
describe('Répertoire fournisseurs (page /suppliers)', () => {
|
||||
beforeEach(() => {
|
||||
mockPush.mockReset()
|
||||
mockApiGet.mockReset().mockResolvedValue({ member: [] })
|
||||
mockCan.mockReset().mockReturnValue(true)
|
||||
mockSetFilters.mockReset()
|
||||
mockFetch.mockReset()
|
||||
mockToastError.mockReset()
|
||||
})
|
||||
|
||||
it('charge la liste au montage', async () => {
|
||||
mountPage()
|
||||
await flushPromises()
|
||||
expect(mockFetch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('affiche « + Ajouter » uniquement avec la permission manage', async () => {
|
||||
mockCan.mockImplementation((perm: string) => perm === 'commercial.suppliers.manage')
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-label="commercial.suppliers.add"]').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('masque « + Ajouter » sans la permission manage (view seul)', async () => {
|
||||
mockCan.mockImplementation((perm: string) => perm === 'commercial.suppliers.view')
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-label="commercial.suppliers.add"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('navigue vers la consultation au clic sur une ligne', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
await wrapper.find('tr[data-row-id="7"]').trigger('click')
|
||||
expect(mockPush).toHaveBeenCalledWith('/suppliers/7')
|
||||
})
|
||||
|
||||
it('charge les categories de type FOURNISSEUR pour le filtre', async () => {
|
||||
mountPage()
|
||||
await flushPromises()
|
||||
expect(mockApiGet).toHaveBeenCalledWith(
|
||||
'/categories',
|
||||
expect.objectContaining({ pagination: 'false', typeCode: 'FOURNISSEUR' }),
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('appelle l\'export XLSX sur /suppliers/export.xlsx en blob', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
await wrapper.find('[data-label="commercial.suppliers.export"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(mockApiGet).toHaveBeenCalledWith(
|
||||
'/suppliers/export.xlsx',
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseType: 'blob', toast: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('repercute le filtre « Inclure les archivés » dans setFilters sans toucher l\'URL', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
|
||||
// Coche « Inclure les archivés » puis applique les filtres.
|
||||
await wrapper.find('input[data-id="filter-include-archived"]').setValue(true)
|
||||
await wrapper.find('[data-label="commercial.suppliers.filters.apply"]').trigger('click')
|
||||
|
||||
expect(mockSetFilters).toHaveBeenLastCalledWith(
|
||||
{ includeArchived: true },
|
||||
{ replace: true },
|
||||
)
|
||||
// Etat 100 % local (regle n°6) : aucune navigation/query string declenchee.
|
||||
expect(mockPush).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('badge filtres actifs + Réinitialiser vide l\'etat applique', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('input[data-id="filter-include-archived"]').setValue(true)
|
||||
await wrapper.find('[data-label="commercial.suppliers.filters.apply"]').trigger('click')
|
||||
|
||||
// Le libelle du bouton Filtrer porte le compteur (1 filtre actif).
|
||||
expect(wrapper.find('[data-label="commercial.suppliers.filters.title (1)"]').exists()).toBe(true)
|
||||
|
||||
// Réinitialiser → query propre (setFilters avec objet vide).
|
||||
await wrapper.find('[data-label="commercial.suppliers.filters.reset"]').trigger('click')
|
||||
expect(mockSetFilters).toHaveBeenLastCalledWith({}, { replace: true })
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tete : retour repertoire + nom du client. -->
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
@@ -9,7 +9,7 @@
|
||||
v-bind="{ ariaLabel: t('commercial.clients.edit.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[32px] font-bold text-m-primary">{{ headerTitle }}</h1>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ headerTitle }}</h1>
|
||||
</div>
|
||||
|
||||
<!-- Etats de chargement / introuvable. -->
|
||||
@@ -41,6 +41,7 @@
|
||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="showRelationAndTriage"
|
||||
:model-value="main.relationType"
|
||||
:options="relationOptions"
|
||||
:label="t('commercial.clients.form.main.relation')"
|
||||
@@ -49,7 +50,7 @@
|
||||
@update:model-value="onRelationChange"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="main.relationType === 'courtier'"
|
||||
v-if="showRelationAndTriage && main.relationType === 'courtier'"
|
||||
:model-value="main.brokerIri"
|
||||
:options="brokerOptions"
|
||||
:label="t('commercial.clients.form.main.brokerName')"
|
||||
@@ -59,7 +60,7 @@
|
||||
@update:model-value="(v: string | number | null) => main.brokerIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="main.relationType === 'distributeur'"
|
||||
v-if="showRelationAndTriage && main.relationType === 'distributeur'"
|
||||
:model-value="main.distributorIri"
|
||||
:options="distributorOptions"
|
||||
:label="t('commercial.clients.form.main.distributorName')"
|
||||
@@ -69,6 +70,7 @@
|
||||
@update:model-value="(v: string | number | null) => main.distributorIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioCheckbox
|
||||
v-if="showRelationAndTriage"
|
||||
v-model="main.triageService"
|
||||
:label="t('commercial.clients.form.main.triageService')"
|
||||
group-class="self-center"
|
||||
@@ -80,7 +82,7 @@
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.edit.save')"
|
||||
:disabled="!isMainValid || mainSubmitting"
|
||||
:disabled="mainSubmitting"
|
||||
@click="submitMain"
|
||||
/>
|
||||
</div>
|
||||
@@ -90,11 +92,14 @@
|
||||
<!-- Onglet Information -->
|
||||
<template #information>
|
||||
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- pt-1/pb-1 alignent le textarea (h-full) en haut ET en bas
|
||||
sur les inputs (champ 40px centre dans un h-12 -> ~4px de
|
||||
coussin de chaque cote). -->
|
||||
<MalioInputTextArea
|
||||
v-model="information.description"
|
||||
:label="t('commercial.clients.form.information.description')"
|
||||
resize="none"
|
||||
group-class="row-span-2 pt-1"
|
||||
group-class="row-span-2 pt-1 pb-1"
|
||||
text-input="h-full text-lg"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.description"
|
||||
@@ -109,6 +114,7 @@
|
||||
v-model="information.foundedAt"
|
||||
:label="t('commercial.clients.form.information.foundedAt')"
|
||||
:readonly="businessReadonly"
|
||||
:editable="true"
|
||||
:error="informationErrors.errors.foundedAt"
|
||||
/>
|
||||
<MalioInputText
|
||||
@@ -173,7 +179,7 @@
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.edit.save')"
|
||||
:disabled="!canValidateContacts || tabSubmitting"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitContacts"
|
||||
/>
|
||||
</div>
|
||||
@@ -205,12 +211,13 @@
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.clients.form.address.add')"
|
||||
:disabled="!canAddAddress"
|
||||
@click="addAddress"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.edit.save')"
|
||||
:disabled="!canValidateAddresses || tabSubmitting"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAddresses"
|
||||
/>
|
||||
</div>
|
||||
@@ -289,14 +296,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Blocs RIB (0..n) — obligatoires si type de reglement = LCR (RG-1.13). -->
|
||||
<!-- Blocs RIB — affiches uniquement si type de reglement = LCR (RG-1.13). -->
|
||||
<div
|
||||
v-for="(rib, index) in ribs"
|
||||
v-for="(rib, index) in visibleRibs"
|
||||
:key="rib.id ?? `new-${index}`"
|
||||
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||
>
|
||||
<MalioButtonIcon
|
||||
v-if="!accountingReadonly"
|
||||
v-if="!accountingReadonly && visibleRibs.length > 1"
|
||||
icon="mdi:delete-outline"
|
||||
variant="ghost"
|
||||
button-class="absolute top-3 right-3"
|
||||
@@ -330,16 +337,18 @@
|
||||
|
||||
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
v-if="isRibRequired"
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.clients.form.accounting.addRib')"
|
||||
:disabled="!canAddRib"
|
||||
@click="addRib"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.edit.save')"
|
||||
:disabled="!canValidateAccounting || tabSubmitting"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAccounting"
|
||||
/>
|
||||
</div>
|
||||
@@ -379,7 +388,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useClient } from '~/modules/commercial/composables/useClient'
|
||||
import { useClientReferentials, type CategoryOption, type RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
||||
import { useClientFormErrors } from '~/modules/commercial/composables/useClientFormErrors'
|
||||
@@ -410,16 +419,16 @@ import {
|
||||
type MainFormDraft,
|
||||
} from '~/modules/commercial/utils/clientEdit'
|
||||
import {
|
||||
addressTypeFromFlags,
|
||||
buildClientFormTabKeys,
|
||||
hasAllRequiredAccountingFields,
|
||||
hasAtLeastOneValidContact,
|
||||
isAddressValid,
|
||||
isBankRequiredForPaymentType,
|
||||
isBillingEmailRequired,
|
||||
isContactBlank,
|
||||
isContactNamed,
|
||||
isRibBlank,
|
||||
isRibComplete,
|
||||
isRibRequiredForPaymentType,
|
||||
showsRelationAndTriageFields,
|
||||
} from '~/modules/commercial/utils/clientFormRules'
|
||||
import {
|
||||
emptyAddress,
|
||||
@@ -430,6 +439,7 @@ import {
|
||||
type RibFormDraft,
|
||||
} from '~/modules/commercial/types/clientForm'
|
||||
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||
import { readHistoryTab } from '~/shared/utils/historyTab'
|
||||
|
||||
// Masques de saisie (la normalisation finale reste serveur).
|
||||
const SIREN_MASK = '#########'
|
||||
@@ -500,7 +510,9 @@ function hydrate(detail: ClientDetail): void {
|
||||
// un bloc vierge (non persiste tant qu'incomplet — cf. submit*/canValidate*).
|
||||
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
||||
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
// RIB : amorce un bloc vide seulement si le type de reglement est une LCR
|
||||
// (sinon la section reste masquee — RG-1.13).
|
||||
if (isRibRequired.value && ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
// Charge les listes distributeur / courtier si une relation est deja posee.
|
||||
if (main.relationType === 'distributeur') referentials.loadDistributors().catch(() => {})
|
||||
if (main.relationType === 'courtier') referentials.loadBrokers().catch(() => {})
|
||||
@@ -541,16 +553,49 @@ const contactOptions = computed<RefOption[]>(() =>
|
||||
})),
|
||||
)
|
||||
|
||||
const countryOptions: RefOption[] = [
|
||||
{ value: 'France', label: 'France' },
|
||||
{ value: 'Espagne', label: 'Espagne' },
|
||||
]
|
||||
// Pays : referentiel `country` charge via l'API (ERP-116), en remplacement de
|
||||
// l'ancienne liste codee en dur. Valeur = nom du pays (l'adresse stocke
|
||||
// `country` en chaine libre, donc value === label). On merge la valeur deja
|
||||
// stockee sur chaque adresse (embed) — comme les autres selects de cet ecran —
|
||||
// pour ne pas vider le select si `/countries` echoue (resilience ERP-102) ou si
|
||||
// un pays historique n'appartient pas au referentiel.
|
||||
const embedCountryOptions = computed<RefOption[]>(() =>
|
||||
mergeOptions([], (client.value?.addresses ?? [])
|
||||
.map(a => a.country)
|
||||
.filter((c): c is string => !!c)
|
||||
.map(c => ({ value: c, label: c }))),
|
||||
)
|
||||
const countryOptions = computed<RefOption[]>(() =>
|
||||
mergeOptions(referentials.countries.value, embedCountryOptions.value),
|
||||
)
|
||||
|
||||
const relationOptions = computed<RefOption[]>(() => [
|
||||
{ value: 'distributeur', label: t('commercial.clients.form.main.relationDistributor') },
|
||||
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||
])
|
||||
|
||||
// Codes des categories selectionnees (resolus depuis l'union referentiel + embed).
|
||||
const selectedCategoryCodes = computed(() =>
|
||||
main.categoryIris
|
||||
.map(iri => mainCategoryOptions.value.find(c => c.value === iri)?.code)
|
||||
.filter((code): code is string => code !== undefined),
|
||||
)
|
||||
|
||||
// « Relation » + « Prestation de triage » masques par defaut, reveles des qu'une
|
||||
// categorie ordinaire (autre que Distributeur/Courtier) est selectionnee.
|
||||
const showRelationAndTriage = computed(() => showsRelationAndTriageFields(selectedCategoryCodes.value))
|
||||
|
||||
// Masquer ces champs reinitialise leurs valeurs : pas de relation/triage fantome
|
||||
// soumis pour un client Distributeur/Courtier.
|
||||
watch(showRelationAndTriage, (visible) => {
|
||||
if (!visible) {
|
||||
main.relationType = null
|
||||
main.distributorIri = null
|
||||
main.brokerIri = null
|
||||
main.triageService = false
|
||||
}
|
||||
})
|
||||
|
||||
// Distributeur / courtier : referentiel charge a la demande UNION valeur courante.
|
||||
const currentDistributorOption = computed<RefOption[]>(() => {
|
||||
const d = client.value?.distributor
|
||||
@@ -592,11 +637,13 @@ const tabs = computed(() => tabKeys.value.map(key => ({
|
||||
icon: TAB_ICONS[key],
|
||||
})))
|
||||
|
||||
const activeTab = ref('information')
|
||||
// Onglet initial : repris de la consultation (history.state), sinon Information.
|
||||
const activeTab = ref(readHistoryTab(tabKeys.value) ?? 'information')
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
/** Retour consultation en conservant l'onglet courant (via history.state). */
|
||||
function goBack(): void {
|
||||
router.push(`/clients/${clientId}`)
|
||||
router.push({ path: `/clients/${clientId}`, state: { tab: activeTab.value } })
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -636,17 +683,6 @@ const {
|
||||
} = useClientFormErrors()
|
||||
|
||||
// ── Bloc principal ───────────────────────────────────────────────────────────
|
||||
const isMainValid = computed(() => {
|
||||
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
||||
const relationValid
|
||||
= main.relationType === null
|
||||
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
||||
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
||||
return filled(main.companyName)
|
||||
&& main.categoryIris.length >= 1
|
||||
&& relationValid
|
||||
})
|
||||
|
||||
async function onRelationChange(value: string | number | null): Promise<void> {
|
||||
const relation = (value === null || value === '') ? null : (String(value) as 'distributeur' | 'courtier')
|
||||
main.relationType = relation
|
||||
@@ -660,11 +696,11 @@ async function onRelationChange(value: string | number | null): Promise<void> {
|
||||
|
||||
/** PATCH /clients/{id} — groupe client:write:main UNIQUEMENT (mode strict). */
|
||||
async function submitMain(): Promise<void> {
|
||||
if (businessReadonly.value || !isMainValid.value || mainSubmitting.value) return
|
||||
if (businessReadonly.value || mainSubmitting.value) return
|
||||
mainSubmitting.value = true
|
||||
mainErrors.clearErrors()
|
||||
try {
|
||||
const updated = await api.patch<ClientDetail>(`/clients/${clientId}`, buildMainPayload(main), {
|
||||
const updated = await api.patch<ClientDetail>(`/clients/${clientId}`, buildMainPayload(main, { forUpdate: true }), {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
@@ -713,9 +749,6 @@ const canAddContact = computed(() => {
|
||||
const last = contacts.value[contacts.value.length - 1]
|
||||
return last === undefined || isContactNamed(last)
|
||||
})
|
||||
// RG-1.14 : au moins un contact nomme pour finaliser l'onglet.
|
||||
const canValidateContacts = computed(() => hasAtLeastOneValidContact(contacts.value))
|
||||
|
||||
function addContact(): void {
|
||||
if (canAddContact.value) contacts.value.push(emptyContact())
|
||||
}
|
||||
@@ -737,7 +770,7 @@ function askRemoveContact(index: number): void {
|
||||
* collection contacts (endpoints client_contact dedies).
|
||||
*/
|
||||
async function submitContacts(): Promise<void> {
|
||||
if (businessReadonly.value || !canValidateContacts.value || tabSubmitting.value) return
|
||||
if (businessReadonly.value || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
contactErrors.value = []
|
||||
try {
|
||||
@@ -746,6 +779,11 @@ async function submitContacts(): Promise<void> {
|
||||
}
|
||||
removedContactIds.value = []
|
||||
|
||||
// RG-1.14 : au moins un contact requis. Si l'onglet ne contient QUE des
|
||||
// amorces neuves vides (ex. tous les contacts existants supprimes), on ne
|
||||
// les skippe pas -> le back renvoie la 422 RG-1.05 « prénom ou nom
|
||||
// obligatoire » inline (la RG-1.14 n'a pas d'equivalent back au POST).
|
||||
const hasSubmittableContact = contacts.value.some(c => c.id !== null || !isContactBlank(c))
|
||||
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
||||
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
||||
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
||||
@@ -768,10 +806,10 @@ async function submitContacts(): Promise<void> {
|
||||
}
|
||||
},
|
||||
error => showError(error),
|
||||
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||
// bloc existant vide est soumis -> 422 RG-1.05 inline (sinon la modif
|
||||
// serait perdue en silence avec un faux toast de succes).
|
||||
contact => contact.id === null && isContactBlank(contact),
|
||||
// On ne saute une amorce neuve (id null) totalement vide QUE si un autre
|
||||
// bloc sera soumis : sinon on la soumet pour declencher la 422 RG-1.05
|
||||
// (un onglet Contact vide ne doit pas passer en faux succes).
|
||||
contact => hasSubmittableContact && contact.id === null && isContactBlank(contact),
|
||||
)
|
||||
// Tant qu'un bloc reste en erreur : pas de toast succes.
|
||||
if (hasError) return
|
||||
@@ -786,19 +824,14 @@ async function submitContacts(): Promise<void> {
|
||||
}
|
||||
|
||||
// ── Onglet Adresse ───────────────────────────────────────────────────────────
|
||||
const canValidateAddresses = computed(() =>
|
||||
addresses.value.length > 0
|
||||
&& addresses.value.every((a) => {
|
||||
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
||||
return addressTypeFromFlags(a) !== null
|
||||
&& a.siteIris.length >= 1
|
||||
&& a.categoryIris.length >= 1
|
||||
&& (!isBillingEmailRequired(a) || filledBillingEmail)
|
||||
}),
|
||||
)
|
||||
// « + Adresse » desactive tant que la derniere adresse n'est pas valide.
|
||||
const canAddAddress = computed(() => {
|
||||
const last = addresses.value[addresses.value.length - 1]
|
||||
return last !== undefined && isAddressValid(last)
|
||||
})
|
||||
|
||||
function addAddress(): void {
|
||||
addresses.value.push(emptyAddress())
|
||||
if (canAddAddress.value) addresses.value.push(emptyAddress())
|
||||
}
|
||||
|
||||
function askRemoveAddress(index: number): void {
|
||||
@@ -823,7 +856,7 @@ function onAddressDegraded(): void {
|
||||
|
||||
/** Valide l'onglet Adresse : DELETE des adresses retirees puis POST/PATCH. */
|
||||
async function submitAddresses(): Promise<void> {
|
||||
if (businessReadonly.value || !canValidateAddresses.value || tabSubmitting.value) return
|
||||
if (businessReadonly.value || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
addressErrors.value = []
|
||||
try {
|
||||
@@ -837,7 +870,10 @@ async function submitAddresses(): Promise<void> {
|
||||
addresses.value,
|
||||
addressErrors,
|
||||
async (address) => {
|
||||
const body = buildAddressPayload(address, isBillingEmailRequired(address))
|
||||
// Edition d'une adresse existante : champ requis vide envoye en `''`
|
||||
// (NotBlank 422) au lieu d'etre omis — sinon le PATCH garderait
|
||||
// l'ancienne valeur (faux 200). Creation (id null) : omit classique.
|
||||
const body = buildAddressPayload(address, isBillingEmailRequired(address), { forUpdate: address.id !== null })
|
||||
if (address.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/clients/${clientId}/addresses`,
|
||||
@@ -870,25 +906,34 @@ const selectedPaymentTypeCode = computed(() =>
|
||||
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
|
||||
// Les blocs RIB ne sont affiches que pour une LCR (RG-1.13).
|
||||
const visibleRibs = computed(() => isRibRequired.value ? ribs.value : [])
|
||||
|
||||
function onPaymentTypeChange(value: string | number | null): void {
|
||||
accounting.paymentTypeIri = value === null ? null : String(value)
|
||||
if (!isBankRequired.value) accounting.bankIri = null
|
||||
// ERP-121 : un RIB est une coordonnee bancaire du client, decouplee du mode de
|
||||
// reglement. Au passage hors-LCR on ne SUPPRIME plus les RIB existants : ils
|
||||
// restent en base, simplement masques a l'ecran (visibleRibs = []), et
|
||||
// reapparaissent tels quels si l'on repasse en LCR. Seule la corbeille d'un
|
||||
// bloc (askRemoveRib) retire reellement un RIB.
|
||||
if (isRibRequired.value) {
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
}
|
||||
else {
|
||||
// Hors-LCR : on nettoie seulement les erreurs inline (plus affichees).
|
||||
ribErrors.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function ribIsComplete(rib: { label: string | null, bic: string | null, iban: string | null }): boolean {
|
||||
const filled = (v: string | null) => v !== null && v.trim() !== ''
|
||||
return filled(rib.label) && filled(rib.bic) && filled(rib.iban)
|
||||
}
|
||||
|
||||
const canValidateAccounting = computed(() => {
|
||||
if (!hasAllRequiredAccountingFields(accounting)) return false
|
||||
if (isBankRequired.value && accounting.bankIri === null) return false
|
||||
if (isRibRequired.value && !ribs.value.some(ribIsComplete)) return false
|
||||
return true
|
||||
// « + RIB » desactive tant que le dernier bloc RIB n'est pas complet.
|
||||
const canAddRib = computed(() => {
|
||||
const last = ribs.value[ribs.value.length - 1]
|
||||
return last !== undefined && isRibComplete(last)
|
||||
})
|
||||
|
||||
function addRib(): void {
|
||||
ribs.value.push(emptyRib())
|
||||
if (canAddRib.value) ribs.value.push(emptyRib())
|
||||
}
|
||||
|
||||
function askRemoveRib(index: number): void {
|
||||
@@ -903,21 +948,62 @@ function askRemoveRib(index: number): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Valide l'onglet Comptabilite : PATCH des scalaires (groupe client:write:accounting,
|
||||
* exige accounting.manage cote back) PUIS DELETE/POST/PATCH des RIB sur la
|
||||
* sous-ressource. Aucun champ main/information dans le payload (mode strict
|
||||
* Valide l'onglet Comptabilite : POST/PATCH des RIB sur la sous-ressource PUIS
|
||||
* PATCH des scalaires (groupe client:write:accounting, exige accounting.manage cote
|
||||
* back) PUIS DELETE des RIB explicitement retires. Les RIB crees d'abord : le back
|
||||
* valide RG-1.13 (LCR => au moins un RIB persiste) sur le PATCH scalaires.
|
||||
*
|
||||
* ERP-121 : les RIB ne sont (re)soumis QUE sous LCR — hors-LCR ce sont des
|
||||
* coordonnees dormantes conservees telles quelles, masquees a l'ecran et jamais
|
||||
* re-ecrites. `removedRibIds` ne contient plus que les suppressions EXPLICITES
|
||||
* (corbeille d'un bloc, toujours sous LCR), plus l'auto-suppression au changement
|
||||
* de type de reglement. Aucun champ main/information dans le payload (mode strict
|
||||
* RG-1.28 : sinon 403 sur tout le payload).
|
||||
*/
|
||||
async function submitAccounting(): Promise<void> {
|
||||
if (accountingReadonly.value || !canValidateAccounting.value || tabSubmitting.value) return
|
||||
if (accountingReadonly.value || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
accountingErrors.clearErrors()
|
||||
// Reset des erreurs RIB des le debut : l'etape 1 (PATCH scalaires) peut
|
||||
// echouer et `return` avant submitRows (qui porte sinon le reset), laissant
|
||||
// des erreurs de RIB obsoletes affichees sous les blocs.
|
||||
ribErrors.value = []
|
||||
try {
|
||||
// 1) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||
// 1) POST/PATCH des RIB d'abord — UNIQUEMENT sous LCR (erreurs inline par
|
||||
// ligne, tous les blocs tentes). Le back exige >=1 RIB persiste pour valider
|
||||
// une LCR a l'etape 2. Hors-LCR (ERP-121), les RIB sont des coordonnees
|
||||
// dormantes : rien d'editable n'est affiche, on ne les re-soumet pas.
|
||||
// On ne saute une amorce neuve vide QUE s'il reste un autre RIB soumettable :
|
||||
// sinon (ex. l'unique RIB existant supprime, remplace par un bloc vide), on la
|
||||
// soumet pour declencher la 422 NotBlank inline plutot que de laisser le DELETE
|
||||
// echouer en « dernier RIB d'une LCR » (message plat sans propertyPath).
|
||||
if (isRibRequired.value) {
|
||||
const hasSubmittableRib = ribs.value.some(r => r.id !== null || !isRibBlank(r))
|
||||
const ribHasError = await submitRows(
|
||||
ribs.value,
|
||||
ribErrors,
|
||||
async (rib) => {
|
||||
// Edition d'un RIB existant : champ requis vide envoye en `''` (NotBlank
|
||||
// 422) au lieu d'etre omis (sinon le PATCH garderait l'ancienne valeur).
|
||||
const body = buildRibPayload(rib, { forUpdate: rib.id !== null })
|
||||
if (rib.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/clients/${clientId}/ribs`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
rib.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/client_ribs/${rib.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => showError(error),
|
||||
// On ne saute une amorce neuve (id null) totalement vide que si un autre RIB
|
||||
// est soumettable. Un RIB existant vide est toujours soumis -> 422 NotBlank
|
||||
// inline (sinon la modif serait perdue en silence avec un faux toast succes).
|
||||
rib => hasSubmittableRib && rib.id === null && isRibBlank(rib),
|
||||
)
|
||||
if (ribHasError) return
|
||||
}
|
||||
|
||||
// 2) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||
try {
|
||||
await api.patch(`/clients/${clientId}`, buildAccountingPayload(accounting, isBankRequired.value), { toast: false })
|
||||
}
|
||||
@@ -926,38 +1012,14 @@ async function submitAccounting(): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
// 3) DELETE des RIB explicitement retires (corbeille d'un bloc) : APRES le
|
||||
// PATCH scalaires (le guard back refuse la suppression du dernier RIB d'une
|
||||
// LCR). ERP-121 : plus aucune suppression automatique au passage hors-LCR.
|
||||
for (const id of removedRibIds.value) {
|
||||
await api.delete(`/client_ribs/${id}`, {}, { toast: false })
|
||||
}
|
||||
removedRibIds.value = []
|
||||
|
||||
// 2) POST/PATCH des RIB (erreurs inline par ligne, tous les blocs tentes).
|
||||
// Seuls les blocs RIB TOTALEMENT vides sont ignores : un RIB partiel (ex.
|
||||
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
||||
const ribHasError = await submitRows(
|
||||
ribs.value,
|
||||
ribErrors,
|
||||
async (rib) => {
|
||||
const body = buildRibPayload(rib)
|
||||
if (rib.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/clients/${clientId}/ribs`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
rib.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/client_ribs/${rib.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => showError(error),
|
||||
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||
// RIB existant vide est soumis -> 422 NotBlank inline (sinon la modif
|
||||
// serait perdue en silence avec un faux toast de succes).
|
||||
rib => rib.id === null && isRibBlank(rib),
|
||||
)
|
||||
if (ribHasError) return
|
||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tete : retour repertoire + nom du client + actions (Modifier / Archiver|Restaurer). -->
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
@@ -9,7 +9,7 @@
|
||||
v-bind="{ ariaLabel: t('commercial.clients.consultation.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[32px] font-bold text-m-primary">{{ headerTitle }}</h1>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ headerTitle }}</h1>
|
||||
|
||||
<!-- gap-12 = 48px : meme espacement que Ajouter / Filtres du repertoire. -->
|
||||
<div class="ml-auto flex items-center gap-12">
|
||||
@@ -88,11 +88,14 @@
|
||||
<!-- Onglet Information -->
|
||||
<template #information>
|
||||
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- pt-1/pb-1 alignent le textarea (h-full) en haut ET en bas
|
||||
sur les inputs (champ 40px centre dans un h-12 -> ~4px de
|
||||
coussin de chaque cote). -->
|
||||
<MalioInputTextArea
|
||||
:model-value="information.description"
|
||||
:label="t('commercial.clients.form.information.description')"
|
||||
resize="none"
|
||||
group-class="row-span-2 pt-1"
|
||||
group-class="row-span-2 pt-1 pb-1"
|
||||
text-input="h-full text-lg"
|
||||
readonly
|
||||
/>
|
||||
@@ -277,7 +280,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useClient } from '~/modules/commercial/composables/useClient'
|
||||
import { buildClientFormTabKeys } from '~/modules/commercial/utils/clientFormRules'
|
||||
import { buildClientFormTabKeys, isRibRequiredForPaymentType } from '~/modules/commercial/utils/clientFormRules'
|
||||
import { readHistoryTab } from '~/shared/utils/historyTab'
|
||||
import {
|
||||
canEditClient,
|
||||
categoryOptionsOf,
|
||||
@@ -286,6 +290,7 @@ import {
|
||||
mapAddressView,
|
||||
mapContactToDraft,
|
||||
mapRibToDraft,
|
||||
paymentTypeCodeOf,
|
||||
referentialOptionOf,
|
||||
relationOf,
|
||||
showArchiveAction,
|
||||
@@ -293,7 +298,7 @@ import {
|
||||
type ClientDetail,
|
||||
type SelectOption,
|
||||
} from '~/modules/commercial/utils/clientConsultation'
|
||||
import { emptyAddress, emptyContact, emptyRib } from '~/modules/commercial/types/clientForm'
|
||||
import { emptyAddress, emptyContact } from '~/modules/commercial/types/clientForm'
|
||||
|
||||
// Masque d'affichage (purement visuel, la donnee reste celle du serveur).
|
||||
const SIREN_MASK = '#########'
|
||||
@@ -350,10 +355,17 @@ const addressViews = computed(() => {
|
||||
const views = (client.value?.addresses ?? []).map(mapAddressView)
|
||||
return views.length ? views : [{ draft: emptyAddress(), siteOptions: [], categoryOptions: [] }]
|
||||
})
|
||||
const ribs = computed(() => {
|
||||
const list = (client.value?.ribs ?? []).map(mapRibToDraft)
|
||||
return list.length ? list : [emptyRib()]
|
||||
})
|
||||
// Exception au placeholder ci-dessus : on n'affiche AUCUN bloc RIB quand le
|
||||
// client n'en a pas. Pas de bloc vierge fantome en consultation.
|
||||
// ERP-121 : un client peut desormais conserver des RIB « dormants » apres etre
|
||||
// repasse hors-LCR (on ne les supprime plus). En consultation, decision metier =
|
||||
// on les masque TOTALEMENT : on n'affiche les RIB que si le type de reglement
|
||||
// courant est LCR (le `code` est embarque sous client:read:accounting).
|
||||
const ribs = computed(() =>
|
||||
isRibRequiredForPaymentType(paymentTypeCodeOf(client.value?.paymentType))
|
||||
? (client.value?.ribs ?? []).map(mapRibToDraft)
|
||||
: [],
|
||||
)
|
||||
// Draft comptable (tout null si l'utilisateur n'a pas accounting.view).
|
||||
const accounting = computed(() => mapAccountingDraft(client.value ?? ({} as ClientDetail)))
|
||||
|
||||
@@ -380,10 +392,18 @@ const relationOptions = computed<SelectOption[]>(() => [
|
||||
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||
])
|
||||
|
||||
const countryOptions: SelectOption[] = [
|
||||
{ value: 'France', label: 'France' },
|
||||
{ value: 'Espagne', label: 'Espagne' },
|
||||
]
|
||||
// Pays (ERP-116) : options construites depuis l'EMBED des adresses (jamais via
|
||||
// GET /countries, sur le meme principe que les autres selects de consultation
|
||||
// — en 403 pour les roles metier non-admin). Valeur = nom du pays stocke tel
|
||||
// quel dans l'adresse, donc value === label ; suffit a afficher le libelle en
|
||||
// lecture seule.
|
||||
const countryOptions = computed<SelectOption[]>(() =>
|
||||
[...new Set(
|
||||
(client.value?.addresses ?? [])
|
||||
.map(a => a.country)
|
||||
.filter((c): c is string => !!c),
|
||||
)].map(c => ({ value: c, label: c })),
|
||||
)
|
||||
|
||||
// Selects comptables : libelle issu de l'embed (option unique ou vide).
|
||||
const tvaModeOptions = computed(() => referentialOptionOf(client.value?.tvaMode))
|
||||
@@ -413,15 +433,17 @@ const tabs = computed(() => tabKeys.value.map(key => ({
|
||||
icon: TAB_ICONS[key],
|
||||
})))
|
||||
|
||||
const activeTab = ref('information')
|
||||
// Onglet initial : repris de l'edition au retour (history.state), sinon Information.
|
||||
const activeTab = ref(readHistoryTab(tabKeys.value) ?? 'information')
|
||||
|
||||
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||
function goBack(): void {
|
||||
router.push('/clients')
|
||||
}
|
||||
|
||||
/** Bascule en edition en conservant l'onglet courant (via history.state). */
|
||||
function goEdit(): void {
|
||||
router.push(`/clients/${clientId}/edit`)
|
||||
router.push({ path: `/clients/${clientId}/edit`, state: { tab: activeTab.value } })
|
||||
}
|
||||
|
||||
// ── Archivage / Restauration ────────────────────────────────────────────────
|
||||
|
||||
@@ -3,18 +3,9 @@
|
||||
<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. -->
|
||||
<!-- gap-8 = 32px d'espacement entre Filtres et Ajouter. -->
|
||||
<div class="flex items-center gap-8">
|
||||
<!-- Bouton Filtres a GAUCHE d'Ajouter. Le compteur reflete les filtres actifs. -->
|
||||
<MalioButton
|
||||
v-if="canView"
|
||||
variant="tertiary"
|
||||
@@ -22,9 +13,16 @@
|
||||
icon-name="mdi:tune"
|
||||
icon-position="left"
|
||||
icon-size="24"
|
||||
button-class="w-[184px] justify-start gap-4 text-black"
|
||||
@click="openFilters"
|
||||
/>
|
||||
<MalioButton
|
||||
v-if="canManage"
|
||||
variant="secondary"
|
||||
:label="t('commercial.clients.add')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@click="goToCreate"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</PageHeader>
|
||||
@@ -39,7 +37,7 @@
|
||||
:per-page="itemsPerPage"
|
||||
:per-page-options="itemsPerPageOptions"
|
||||
row-clickable
|
||||
table-class="table-fixed"
|
||||
table-class="table-fixed clients-table"
|
||||
:empty-message="t('commercial.clients.empty')"
|
||||
@row-click="onRowClick"
|
||||
@update:page="goToPage"
|
||||
@@ -56,7 +54,7 @@
|
||||
<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"
|
||||
class="inline-flex items-center rounded-full px-2 py-0.5 font-medium text-white"
|
||||
:style="{ backgroundColor: site.color }"
|
||||
>
|
||||
{{ site.name }}
|
||||
@@ -70,7 +68,7 @@
|
||||
</template>
|
||||
</MalioDataTable>
|
||||
|
||||
<div class="flex justify-center mt-6">
|
||||
<div class="flex justify-center mt-4">
|
||||
<MalioButton
|
||||
v-if="canView"
|
||||
variant="primary"
|
||||
@@ -350,7 +348,9 @@ async function loadFilterOptions(): Promise<void> {
|
||||
const [cats, sites] = await Promise.all([
|
||||
api.get<{ member?: Array<{ code: string, name: string }> }>(
|
||||
'/categories',
|
||||
{ pagination: 'false' },
|
||||
// Taxonomie multi-types (ERP-84) : le filtre du repertoire client ne
|
||||
// propose que les categories de type CLIENT (pas les FOURNISSEUR).
|
||||
{ pagination: 'false', typeCode: 'CLIENT' },
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
),
|
||||
api.get<{ member?: Array<{ id: number, name: string }> }>(
|
||||
@@ -419,3 +419,16 @@ onMounted(() => {
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/*
|
||||
* Colonne Sites uniquement (3e colonne : companyName, categories, SITES,
|
||||
* lastActivity) : ses badges rendent la cellule trop haute. On reduit le padding
|
||||
* vertical de SON td (16px Malio -> 8px) sans toucher les autres colonnes ni les
|
||||
* couleurs/tailles (qui restent sur les defauts Malio).
|
||||
*/
|
||||
:deep(.clients-table tbody td:nth-child(3)) {
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tete : retour vers le repertoire + titre. -->
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
@@ -9,7 +9,7 @@
|
||||
v-bind="{ ariaLabel: t('commercial.clients.form.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[32px] font-bold text-m-primary">{{ t('commercial.clients.form.title') }}</h1>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ t('commercial.clients.form.title') }}</h1>
|
||||
</div>
|
||||
|
||||
<!-- ── Formulaire principal (pre-onglets) ─────────────────────────────
|
||||
@@ -35,6 +35,7 @@
|
||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="showRelationAndTriage"
|
||||
:model-value="main.relationType"
|
||||
:options="relationOptions"
|
||||
:label="t('commercial.clients.form.main.relation')"
|
||||
@@ -43,7 +44,7 @@
|
||||
@update:model-value="onRelationChange"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="main.relationType === 'courtier'"
|
||||
v-if="showRelationAndTriage && main.relationType === 'courtier'"
|
||||
:model-value="main.brokerIri"
|
||||
:options="referentials.brokers.value"
|
||||
:label="t('commercial.clients.form.main.brokerName')"
|
||||
@@ -53,7 +54,7 @@
|
||||
@update:model-value="(v: string | number | null) => main.brokerIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="main.relationType === 'distributeur'"
|
||||
v-if="showRelationAndTriage && main.relationType === 'distributeur'"
|
||||
:model-value="main.distributorIri"
|
||||
:options="referentials.distributors.value"
|
||||
:label="t('commercial.clients.form.main.distributorName')"
|
||||
@@ -63,6 +64,7 @@
|
||||
@update:model-value="(v: string | number | null) => main.distributorIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioCheckbox
|
||||
v-if="showRelationAndTriage"
|
||||
v-model="main.triageService"
|
||||
:label="t('commercial.clients.form.main.triageService')"
|
||||
group-class="self-center"
|
||||
@@ -74,7 +76,7 @@
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.form.submit')"
|
||||
:disabled="!isMainValid || mainSubmitting"
|
||||
:disabled="mainSubmitting"
|
||||
@click="submitMain"
|
||||
/>
|
||||
</div>
|
||||
@@ -84,13 +86,15 @@
|
||||
<!-- Onglet Information -->
|
||||
<template #information>
|
||||
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- pt-1 : aligne le bord superieur du textarea sur celui des
|
||||
inputs (centres dans un conteneur h-12, soit ~4px de retrait haut). -->
|
||||
<!-- pt-1/pb-1 alignent le textarea (h-full) sur les inputs, dont
|
||||
le champ de 40px est centre dans un conteneur h-12 (~4px de
|
||||
coussin en HAUT et en BAS). Sans pb-1, le textarea descend ~4px
|
||||
plus bas que les champs voisins. -->
|
||||
<MalioInputTextArea
|
||||
v-model="information.description"
|
||||
:label="t('commercial.clients.form.information.description')"
|
||||
resize="none"
|
||||
group-class="row-span-2 pt-1"
|
||||
group-class="row-span-2 pt-1 pb-1"
|
||||
text-input="h-full text-lg"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.description"
|
||||
@@ -105,6 +109,7 @@
|
||||
v-model="information.foundedAt"
|
||||
:label="t('commercial.clients.form.information.foundedAt')"
|
||||
:readonly="isValidated('information')"
|
||||
:editable="true"
|
||||
:error="informationErrors.errors.foundedAt"
|
||||
/>
|
||||
<MalioInputText
|
||||
@@ -134,9 +139,10 @@
|
||||
/>
|
||||
</div>
|
||||
<div v-if="!isValidated('information')" class="mt-12 flex justify-center">
|
||||
<!-- Desactive tant que le client n'est pas cree : evite un PATCH
|
||||
avant le POST si l'utilisateur clique trop tot (le panneau
|
||||
Information est l'onglet actif par defaut). -->
|
||||
<!-- Desactive tant que le client n'est pas cree (evite un PATCH
|
||||
avant le POST si clic trop tot, Information etant l'onglet
|
||||
actif par defaut). Onglet facultatif : un enregistrement a
|
||||
vide reste possible, c'est le back qui valide. -->
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.form.submit')"
|
||||
@@ -172,7 +178,7 @@
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.form.submit')"
|
||||
:disabled="!canValidateContacts || tabSubmitting"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitContacts"
|
||||
/>
|
||||
</div>
|
||||
@@ -204,12 +210,13 @@
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.clients.form.address.add')"
|
||||
:disabled="!canAddAddress"
|
||||
@click="addAddress"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.form.submit')"
|
||||
:disabled="!canValidateAddresses || tabSubmitting"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAddresses"
|
||||
/>
|
||||
</div>
|
||||
@@ -287,15 +294,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Blocs RIB (0..n) — obligatoires si type de reglement = LCR. -->
|
||||
<!-- Blocs RIB — affiches uniquement si type de reglement = LCR (RG-1.13). -->
|
||||
<div
|
||||
v-for="(rib, index) in ribs"
|
||||
v-for="(rib, index) in visibleRibs"
|
||||
:key="index"
|
||||
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||
>
|
||||
<!-- ariaLabel via v-bind objet (prop camelCase ; aria-* serait un attribut HTML). -->
|
||||
<MalioButtonIcon
|
||||
v-if="!accountingReadonly"
|
||||
v-if="!accountingReadonly && visibleRibs.length > 1"
|
||||
icon="mdi:delete-outline"
|
||||
variant="ghost"
|
||||
button-class="absolute top-3 right-3"
|
||||
@@ -329,16 +336,18 @@
|
||||
|
||||
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
v-if="isRibRequired"
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.clients.form.accounting.addRib')"
|
||||
:disabled="!canAddRib"
|
||||
@click="addRib"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.clients.form.submit')"
|
||||
:disabled="!canValidateAccounting || tabSubmitting"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAccounting"
|
||||
/>
|
||||
</div>
|
||||
@@ -380,18 +389,24 @@ import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useClientReferentials, type RefOption } from '~/modules/commercial/composables/useClientReferentials'
|
||||
import { useClientFormErrors } from '~/modules/commercial/composables/useClientFormErrors'
|
||||
import {
|
||||
addressTypeFromFlags,
|
||||
buildClientFormTabKeys,
|
||||
CLIENT_FORM_PLACEHOLDER_TABS,
|
||||
hasAllRequiredAccountingFields,
|
||||
hasAtLeastOneValidContact,
|
||||
isAddressValid,
|
||||
isBankRequiredForPaymentType,
|
||||
isBillingEmailRequired,
|
||||
isContactBlank,
|
||||
isContactNamed,
|
||||
isRibBlank,
|
||||
isRibComplete,
|
||||
isRibRequiredForPaymentType,
|
||||
lastFillableTabKey,
|
||||
showsRelationAndTriageFields,
|
||||
} from '~/modules/commercial/utils/clientFormRules'
|
||||
import {
|
||||
buildAddressPayload,
|
||||
buildMainPayload,
|
||||
buildRibPayload,
|
||||
} from '~/modules/commercial/utils/clientEdit'
|
||||
import {
|
||||
emptyAddress,
|
||||
emptyContact,
|
||||
@@ -483,23 +498,26 @@ const relationOptions = computed<RefOption[]>(() => [
|
||||
{ value: 'courtier', label: t('commercial.clients.form.main.relationBroker') },
|
||||
])
|
||||
|
||||
// Validation du formulaire principal (gate le bouton « Valider ») :
|
||||
// - companyName / >= 1 categorie obligatoires ;
|
||||
// - relation Distributeur/Courtier optionnelle, mais le nom correspondant
|
||||
// devient requis si l'un des deux est choisi (spec fonctionnelle).
|
||||
// Les coordonnees de contact ne sont plus saisies ici : elles vivent dans
|
||||
// l'onglet Contacts (RG-1.05/1.14 garantissent >= 1 contact valide).
|
||||
const isMainValid = computed(() => {
|
||||
const filled = (v: string | null | undefined) => v !== null && v !== undefined && v.trim() !== ''
|
||||
// Relation Distributeur/Courtier OPTIONNELLE ; mais si « Depend du
|
||||
// distributeur/courtier » est choisi, le nom correspondant devient requis.
|
||||
const relationValid
|
||||
= main.relationType === null
|
||||
|| (main.relationType === 'distributeur' && filled(main.distributorIri))
|
||||
|| (main.relationType === 'courtier' && filled(main.brokerIri))
|
||||
return filled(main.companyName)
|
||||
&& main.categoryIris.length >= 1
|
||||
&& relationValid
|
||||
// Codes des categories selectionnees (resolus depuis les IRI du brouillon).
|
||||
const selectedCategoryCodes = computed(() =>
|
||||
main.categoryIris
|
||||
.map(iri => referentials.categories.value.find(c => c.value === iri)?.code)
|
||||
.filter((code): code is string => code !== undefined),
|
||||
)
|
||||
|
||||
// « Relation » + « Prestation de triage » masques par defaut, reveles des qu'une
|
||||
// categorie ordinaire (autre que Distributeur/Courtier) est selectionnee.
|
||||
const showRelationAndTriage = computed(() => showsRelationAndTriageFields(selectedCategoryCodes.value))
|
||||
|
||||
// Masquer ces champs reinitialise leurs valeurs : pas de relation/triage fantome
|
||||
// soumis pour un client Distributeur/Courtier.
|
||||
watch(showRelationAndTriage, (visible) => {
|
||||
if (!visible) {
|
||||
main.relationType = null
|
||||
main.distributorIri = null
|
||||
main.brokerIri = null
|
||||
main.triageService = false
|
||||
}
|
||||
})
|
||||
|
||||
async function onRelationChange(value: string | number | null): Promise<void> {
|
||||
@@ -517,18 +535,13 @@ async function onRelationChange(value: string | number | null): Promise<void> {
|
||||
|
||||
/** POST /clients (groupe client:write:main). Au succes : verrouille + bascule Information. */
|
||||
async function submitMain(): Promise<void> {
|
||||
if (!isMainValid.value || mainSubmitting.value) return
|
||||
if (mainSubmitting.value) return
|
||||
mainSubmitting.value = true
|
||||
mainErrors.clearErrors()
|
||||
try {
|
||||
const payload: Record<string, unknown> = {
|
||||
companyName: main.companyName,
|
||||
categories: main.categoryIris,
|
||||
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
||||
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
||||
triageService: main.triageService,
|
||||
}
|
||||
const created = await api.post<ClientResponse>('/clients', payload, {
|
||||
// Payload partage avec l'edition (buildMainPayload) : meme logique
|
||||
// d'omission des requis vides et meme envoi de relationType (ERP-119).
|
||||
const created = await api.post<ClientResponse>('/clients', buildMainPayload(main), {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
@@ -538,7 +551,9 @@ async function submitMain(): Promise<void> {
|
||||
main.companyName = created.companyName ?? main.companyName
|
||||
|
||||
mainLocked.value = true
|
||||
unlockedIndex.value = 0
|
||||
// Information est facultatif : on deverrouille jusqu'a Contact (index 1)
|
||||
// pour que l'utilisateur puisse y aller directement sans valider Information.
|
||||
unlockedIndex.value = tabIndex('contact')
|
||||
activeTab.value = 'information'
|
||||
toast.success({ title: t('commercial.clients.toast.createSuccess') })
|
||||
}
|
||||
@@ -570,6 +585,12 @@ const validated = reactive<Record<string, boolean>>({})
|
||||
|
||||
const tabKeys = computed(() => buildClientFormTabKeys(canAccountingView.value))
|
||||
|
||||
// Dernier onglet REMPLISSABLE par le role (cf. lastFillableTabKey) : deja role-aware
|
||||
// via tabKeys (accounting present ssi accounting.view, et a la creation « present » =
|
||||
// « editable » : aucun role createur n'a la Compta en lecture seule). Sa validation
|
||||
// cloture l'ajout -> redirection vers la liste.
|
||||
const lastFillableTab = computed(() => lastFillableTabKey(tabKeys.value))
|
||||
|
||||
// Icone (Iconify) affichee dans l'onglet, par cle. A ajuster librement.
|
||||
const TAB_ICONS: Record<string, string> = {
|
||||
information: 'mdi:account-outline',
|
||||
@@ -597,12 +618,23 @@ function tabIndex(key: string): number {
|
||||
return tabKeys.value.indexOf(key)
|
||||
}
|
||||
|
||||
/** Marque l'onglet valide, deverrouille et avance automatiquement au suivant. */
|
||||
function completeTab(key: string): void {
|
||||
/**
|
||||
* Marque l'onglet valide. Si c'est le dernier onglet remplissable, l'ajout est
|
||||
* termine : toast final + redirection vers la liste, et on retourne true pour que
|
||||
* l'appelant n'affiche pas son toast « mis a jour ». Sinon, deverrouille et avance
|
||||
* a l'onglet suivant, et retourne false.
|
||||
*/
|
||||
function completeTab(key: string): boolean {
|
||||
validated[key] = true
|
||||
if (key === lastFillableTab.value) {
|
||||
toast.success({ title: t('commercial.clients.toast.addComplete') })
|
||||
router.push('/clients')
|
||||
return true
|
||||
}
|
||||
const next = tabKeys.value[tabIndex(key) + 1]
|
||||
unlockedIndex.value = Math.max(unlockedIndex.value, tabIndex(key) + 1)
|
||||
if (next) activeTab.value = next
|
||||
return false
|
||||
}
|
||||
|
||||
// Passage automatique sur les onglets coquille (Transport, Stats, Rapports, Echanges).
|
||||
@@ -640,7 +672,7 @@ async function submitInformation(): Promise<void> {
|
||||
profitAmount: information.profitAmount || null,
|
||||
directorName: information.directorName || null,
|
||||
}, { toast: false })
|
||||
completeTab('information')
|
||||
if (completeTab('information')) return
|
||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||
}
|
||||
catch (error) {
|
||||
@@ -662,9 +694,6 @@ const canAddContact = computed(() => {
|
||||
return last !== undefined && isContactNamed(last)
|
||||
})
|
||||
|
||||
// RG-1.14 : au moins un contact nomme pour finaliser l'onglet.
|
||||
const canValidateContacts = computed(() => hasAtLeastOneValidContact(contacts.value))
|
||||
|
||||
function addContact(): void {
|
||||
if (canAddContact.value) contacts.value.push(emptyContact())
|
||||
}
|
||||
@@ -678,9 +707,14 @@ function askRemoveContact(index: number): void {
|
||||
|
||||
/** POST/PATCH des contacts sur la sous-ressource /clients/{id}/contacts. */
|
||||
async function submitContacts(): Promise<void> {
|
||||
if (clientId.value === null || !canValidateContacts.value || tabSubmitting.value) return
|
||||
if (clientId.value === null || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
try {
|
||||
// RG-1.14 : au moins un contact requis. Si l'onglet ne contient QUE des
|
||||
// amorces neuves vides, on ne les skippe pas -> le bloc vide est POSTe et
|
||||
// le back renvoie la 422 RG-1.05 « prénom ou nom obligatoire » inline (la
|
||||
// RG-1.14 n'a pas d'equivalent back au POST, on la materialise via RG-1.05).
|
||||
const hasSubmittableContact = contacts.value.some(c => c.id !== null || !isContactBlank(c))
|
||||
// On tente TOUS les blocs (collecte des erreurs par index, ERP-110). Seuls
|
||||
// les blocs TOTALEMENT vides sont ignores : un bloc partiellement rempli
|
||||
// sans nom (email seul) est soumis -> 422 RG-1.05 inline sous le bloc.
|
||||
@@ -710,14 +744,14 @@ async function submitContacts(): Promise<void> {
|
||||
}
|
||||
},
|
||||
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||
// bloc existant vide est soumis -> 422 RG-1.05 inline (sinon la modif
|
||||
// serait perdue en silence avec un faux toast de succes).
|
||||
contact => contact.id === null && isContactBlank(contact),
|
||||
// On ne saute une amorce neuve (id null) totalement vide QUE si un autre
|
||||
// bloc sera soumis : sinon on la soumet pour declencher la 422 RG-1.05
|
||||
// (un onglet Contact vide ne doit pas passer en faux succes).
|
||||
contact => hasSubmittableContact && contact.id === null && isContactBlank(contact),
|
||||
)
|
||||
// Tant qu'un bloc reste en erreur : pas de validation d'onglet ni de toast succes.
|
||||
if (hasError) return
|
||||
completeTab('contact')
|
||||
if (completeTab('contact')) return
|
||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||
}
|
||||
finally {
|
||||
@@ -744,27 +778,26 @@ const contactOptions = computed<RefOption[]>(() =>
|
||||
})),
|
||||
)
|
||||
|
||||
// Pays disponibles (France preselectionnee par defaut sur chaque adresse).
|
||||
const countryOptions: RefOption[] = [
|
||||
{ value: 'France', label: 'France' },
|
||||
{ value: 'Espagne', label: 'Espagne' },
|
||||
]
|
||||
// Pays disponibles : referentiel `country` charge via l'API (ERP-116), en
|
||||
// remplacement de l'ancienne liste codee en dur. France reste preselectionnee
|
||||
// par defaut sur chaque adresse (cf. valeur initiale du draft d'adresse) : on
|
||||
// garantit donc sa presence en fallback si `/countries` echoue (resilience
|
||||
// ERP-102), pour ne pas afficher un select vide sur une valeur deja soumise.
|
||||
const countryOptions = computed<RefOption[]>(() => {
|
||||
const list = referentials.countries.value
|
||||
return list.some(c => c.value === 'France')
|
||||
? list
|
||||
: [{ value: 'France', label: 'France' }, ...list]
|
||||
})
|
||||
|
||||
// Type d'adresse (Select) obligatoire + RG-1.10 (>= 1 site) + RG-1.11 (email
|
||||
// facturation si Facturation) sur chaque adresse.
|
||||
const canValidateAddresses = computed(() =>
|
||||
addresses.value.length > 0
|
||||
&& addresses.value.every((a) => {
|
||||
const filledBillingEmail = a.billingEmail !== null && a.billingEmail.trim() !== ''
|
||||
return addressTypeFromFlags(a) !== null
|
||||
&& a.siteIris.length >= 1
|
||||
&& a.categoryIris.length >= 1
|
||||
&& (!isBillingEmailRequired(a) || filledBillingEmail)
|
||||
}),
|
||||
)
|
||||
// « + Adresse » desactive tant que la derniere adresse n'est pas valide.
|
||||
const canAddAddress = computed(() => {
|
||||
const last = addresses.value[addresses.value.length - 1]
|
||||
return last !== undefined && isAddressValid(last)
|
||||
})
|
||||
|
||||
function addAddress(): void {
|
||||
addresses.value.push(emptyAddress())
|
||||
if (canAddAddress.value) addresses.value.push(emptyAddress())
|
||||
}
|
||||
|
||||
function askRemoveAddress(index: number): void {
|
||||
@@ -786,7 +819,7 @@ function onAddressDegraded(): void {
|
||||
|
||||
/** POST des adresses sur la sous-ressource /clients/{id}/addresses. */
|
||||
async function submitAddresses(): Promise<void> {
|
||||
if (clientId.value === null || !canValidateAddresses.value || tabSubmitting.value) return
|
||||
if (clientId.value === null || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
try {
|
||||
// On tente TOUS les blocs d'adresse (collecte des erreurs par index, ERP-110).
|
||||
@@ -794,20 +827,8 @@ async function submitAddresses(): Promise<void> {
|
||||
addresses.value,
|
||||
addressErrors,
|
||||
async (address) => {
|
||||
const body = {
|
||||
isProspect: address.isProspect,
|
||||
isDelivery: address.isDelivery,
|
||||
isBilling: address.isBilling,
|
||||
country: address.country,
|
||||
postalCode: address.postalCode || null,
|
||||
city: address.city || null,
|
||||
street: address.street || null,
|
||||
streetComplement: address.streetComplement || null,
|
||||
categories: address.categoryIris,
|
||||
sites: address.siteIris,
|
||||
contacts: address.contactIris,
|
||||
billingEmail: isBillingEmailRequired(address) ? (address.billingEmail || null) : null,
|
||||
}
|
||||
// Payload partage avec l'edition (buildAddressPayload, ERP-119).
|
||||
const body = buildAddressPayload(address, isBillingEmailRequired(address))
|
||||
if (address.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/clients/${clientId.value}/addresses`,
|
||||
@@ -823,7 +844,7 @@ async function submitAddresses(): Promise<void> {
|
||||
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||
)
|
||||
if (hasError) return
|
||||
completeTab('address')
|
||||
if (completeTab('address')) return
|
||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||
}
|
||||
finally {
|
||||
@@ -853,29 +874,33 @@ const selectedPaymentTypeCode = computed(() =>
|
||||
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
|
||||
// Les blocs RIB ne sont affiches que pour une LCR (RG-1.13).
|
||||
const visibleRibs = computed(() => isRibRequired.value ? ribs.value : [])
|
||||
|
||||
function onPaymentTypeChange(value: string | number | null): void {
|
||||
accounting.paymentTypeIri = value === null ? null : String(value)
|
||||
// La banque n'a de sens que pour un virement : on la vide sinon (RG-1.12).
|
||||
if (!isBankRequired.value) accounting.bankIri = null
|
||||
// ERP-121 : on ne jette plus la saisie RIB au passage hors-LCR. Les blocs sont
|
||||
// masques (visibleRibs = []) mais conserves, et reapparaissent si l'on repasse
|
||||
// en LCR. Ils ne sont persistes qu'a la validation SOUS LCR (cf. submitAccounting),
|
||||
// donc une saisie abandonnee hors-LCR ne cree aucun RIB orphelin.
|
||||
if (isRibRequired.value) {
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
}
|
||||
else {
|
||||
ribErrors.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function ribIsComplete(rib: RibFormDraft): boolean {
|
||||
const filled = (v: string | null) => v !== null && v.trim() !== ''
|
||||
return filled(rib.label) && filled(rib.bic) && filled(rib.iban)
|
||||
}
|
||||
|
||||
// RG-1.30 : les 6 champs scalaires obligatoires (comme les onglets Contact /
|
||||
// Adresse, le bouton reste desactive tant que l'onglet n'est pas complet).
|
||||
// RG-1.12 : banque requise si VIREMENT. RG-1.13 : >= 1 RIB complet si LCR.
|
||||
const canValidateAccounting = computed(() => {
|
||||
if (!hasAllRequiredAccountingFields(accounting)) return false
|
||||
if (isBankRequired.value && (accounting.bankIri === null)) return false
|
||||
if (isRibRequired.value && !ribs.value.some(ribIsComplete)) return false
|
||||
return true
|
||||
// « + RIB » desactive tant que le dernier bloc RIB n'est pas complet.
|
||||
const canAddRib = computed(() => {
|
||||
const last = ribs.value[ribs.value.length - 1]
|
||||
return last !== undefined && isRibComplete(last)
|
||||
})
|
||||
|
||||
function addRib(): void {
|
||||
ribs.value.push(emptyRib())
|
||||
if (canAddRib.value) ribs.value.push(emptyRib())
|
||||
}
|
||||
|
||||
function askRemoveRib(index: number): void {
|
||||
@@ -888,20 +913,55 @@ function askRemoveRib(index: number): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Valide l'onglet Comptabilite : PATCH des scalaires (groupe client:write:accounting)
|
||||
* PUIS POST des RIB sur /clients/{id}/ribs. Deux appels distincts (mode strict
|
||||
* RG-1.28 : il n'existe pas d'endpoint /accounting, cf. recon back).
|
||||
* Valide l'onglet Comptabilite : POST/PATCH des RIB sur /clients/{id}/ribs PUIS
|
||||
* PATCH des scalaires (groupe client:write:accounting). Les RIB d'abord : le back
|
||||
* valide RG-1.13 (LCR => au moins un RIB persiste) sur le PATCH scalaires, les RIB
|
||||
* doivent donc exister en base AVANT (sinon 422 « Au moins un RIB est obligatoire
|
||||
* pour le type de reglement LCR »). Deux appels distincts (mode strict RG-1.28 :
|
||||
* il n'existe pas d'endpoint /accounting, cf. recon back).
|
||||
*/
|
||||
async function submitAccounting(): Promise<void> {
|
||||
if (clientId.value === null || !canValidateAccounting.value || tabSubmitting.value) return
|
||||
if (clientId.value === null || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
accountingErrors.clearErrors()
|
||||
// Reset des erreurs RIB des le debut : l'etape 1 (PATCH scalaires) peut
|
||||
// echouer et `return` avant submitRows (qui porte sinon le reset), laissant
|
||||
// des erreurs de RIB obsoletes affichees sous les blocs.
|
||||
ribErrors.value = []
|
||||
try {
|
||||
// 1) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||
// 1) POST/PATCH des RIB d'abord — UNIQUEMENT sous LCR (erreurs inline par
|
||||
// ligne, tous les blocs tentes). Le back exige >=1 RIB persiste pour valider
|
||||
// une LCR a l'etape 2. Hors-LCR (ERP-121), une saisie RIB eventuellement
|
||||
// restee dans le brouillon est masquee et n'est PAS persistee (pas de RIB
|
||||
// orphelin sur un client en virement).
|
||||
// On ne saute une amorce neuve vide QUE s'il reste un autre RIB soumettable :
|
||||
// sinon (LCR sans aucun RIB rempli) on la soumet -> 422 NotBlank inline.
|
||||
if (isRibRequired.value) {
|
||||
const hasSubmittableRib = ribs.value.some(r => r.id !== null || !isRibBlank(r))
|
||||
const ribHasError = await submitRows(
|
||||
ribs.value,
|
||||
ribErrors,
|
||||
async (rib) => {
|
||||
// Payload partage avec l'edition (buildRibPayload, ERP-119).
|
||||
const body = buildRibPayload(rib)
|
||||
if (rib.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/clients/${clientId.value}/ribs`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
rib.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/client_ribs/${rib.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||
// On ne saute une amorce neuve (id null) totalement vide que si un autre RIB
|
||||
// est soumettable. Un RIB existant vide est toujours soumis -> 422 NotBlank
|
||||
// inline (sinon la modif serait perdue en silence avec un faux toast succes).
|
||||
rib => hasSubmittableRib && rib.id === null && isRibBlank(rib),
|
||||
)
|
||||
if (ribHasError) return
|
||||
}
|
||||
|
||||
// 2) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||
try {
|
||||
await api.patch(`/clients/${clientId.value}`, {
|
||||
siren: accounting.siren || null,
|
||||
@@ -918,35 +978,7 @@ async function submitAccounting(): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
// 2) POST/PATCH des RIB (erreurs inline par ligne, tous les blocs tentes).
|
||||
// Seuls les blocs RIB TOTALEMENT vides sont ignores : un RIB partiel (ex.
|
||||
// IBAN seul) est soumis -> 422 NotBlank (label / bic / iban) inline.
|
||||
const ribHasError = await submitRows(
|
||||
ribs.value,
|
||||
ribErrors,
|
||||
async (rib) => {
|
||||
const body = { label: rib.label, bic: rib.bic, iban: rib.iban }
|
||||
if (rib.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/clients/${clientId.value}/ribs`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
rib.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/client_ribs/${rib.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => toast.error({ title: t('commercial.clients.toast.error'), message: apiErrorMessage(error) }),
|
||||
// On ne saute QUE les amorces neuves (id null) totalement vides. Un
|
||||
// RIB existant vide est soumis -> 422 NotBlank inline (sinon la modif
|
||||
// serait perdue en silence avec un faux toast de succes).
|
||||
rib => rib.id === null && isRibBlank(rib),
|
||||
)
|
||||
if (ribHasError) return
|
||||
|
||||
completeTab('accounting')
|
||||
if (completeTab('accounting')) return
|
||||
toast.success({ title: t('commercial.clients.toast.updateSuccess') })
|
||||
}
|
||||
finally {
|
||||
@@ -987,8 +1019,7 @@ interface ContactResponse {
|
||||
onMounted(() => {
|
||||
// Echec du chargement des referentiels non bloquant : les selects restent vides.
|
||||
referentials.loadCommon().catch(() => {})
|
||||
// Au moins un bloc RIB toujours visible en creation : on amorce un bloc vide
|
||||
// (non persiste tant qu'incomplet — RG-1.13).
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
// Pas d'amorce de RIB ici : un bloc vide n'apparait que si LCR est choisi
|
||||
// (cf. onPaymentTypeChange).
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,945 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tete : retour consultation + nom du fournisseur. -->
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
variant="ghost"
|
||||
v-bind="{ ariaLabel: t('commercial.suppliers.edit.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ headerTitle }}</h1>
|
||||
</div>
|
||||
|
||||
<!-- Etats de chargement / introuvable. -->
|
||||
<p v-if="loading" class="mt-12 text-center text-black/60">{{ t('commercial.suppliers.edit.loading') }}</p>
|
||||
<p v-else-if="error" class="mt-12 text-center text-m-danger">{{ t('commercial.suppliers.edit.notFound') }}</p>
|
||||
|
||||
<template v-else-if="supplier">
|
||||
<!-- ── Bloc principal (pre-rempli, editable si `manage`) ──────────────
|
||||
Conserve en modification (miroir client) ; edite via son propre
|
||||
PATCH scope sur le groupe supplier:write:main. Readonly pour les
|
||||
roles sans `manage` (ex. Compta). Pas de contact inline (ERP-106). -->
|
||||
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
v-model="main.companyName"
|
||||
:label="t('commercial.suppliers.form.main.companyName')"
|
||||
:required="true"
|
||||
:readonly="businessReadonly"
|
||||
:error="mainErrors.errors.companyName"
|
||||
/>
|
||||
<MalioSelectCheckbox
|
||||
:model-value="main.categoryIris"
|
||||
:options="mainCategoryOptions"
|
||||
:label="t('commercial.suppliers.form.main.categories')"
|
||||
:display-tag="true"
|
||||
:readonly="businessReadonly"
|
||||
:required="true"
|
||||
:error="mainErrors.errors.categories"
|
||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="!businessReadonly" class="mt-12 flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.edit.save')"
|
||||
:disabled="mainSubmitting"
|
||||
@click="submitMain"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ── Onglets : navigation LIBRE, edition independante par onglet ──── -->
|
||||
<MalioTabList v-model="activeTab" :tabs="tabs" :max-visible-tabs="5" :max-width="1100" class="mt-[60px]">
|
||||
<!-- Onglet Information -->
|
||||
<template #information>
|
||||
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- pt-1/pb-1 alignent le textarea (h-full) sur les inputs. -->
|
||||
<MalioInputTextArea
|
||||
v-model="information.description"
|
||||
:label="t('commercial.suppliers.form.information.description')"
|
||||
resize="none"
|
||||
group-class="row-span-2 pt-1 pb-1"
|
||||
text-input="h-full text-lg"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.description"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="information.competitors"
|
||||
:label="t('commercial.suppliers.form.information.competitors')"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.competitors"
|
||||
/>
|
||||
<MalioDate
|
||||
v-model="information.foundedAt"
|
||||
:label="t('commercial.suppliers.form.information.foundedAt')"
|
||||
:readonly="businessReadonly"
|
||||
:editable="true"
|
||||
:error="informationErrors.errors.foundedAt"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="information.employeesCount"
|
||||
:label="t('commercial.suppliers.form.information.employeesCount')"
|
||||
:mask="EMPLOYEES_MASK"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.employeesCount"
|
||||
/>
|
||||
<MalioInputAmount
|
||||
v-model="information.revenueAmount"
|
||||
:label="t('commercial.suppliers.form.information.revenueAmount')"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.revenueAmount"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="information.directorName"
|
||||
:label="t('commercial.suppliers.form.information.directorName')"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.directorName"
|
||||
/>
|
||||
<MalioInputAmount
|
||||
v-model="information.profitAmount"
|
||||
:label="t('commercial.suppliers.form.information.profitAmount')"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.profitAmount"
|
||||
/>
|
||||
<!-- Volume previsionnel : specifique fournisseur (entier). -->
|
||||
<MalioInputText
|
||||
v-model="information.volumeForecast"
|
||||
:label="t('commercial.suppliers.form.information.volumeForecast')"
|
||||
:mask="VOLUME_FORECAST_MASK"
|
||||
:readonly="businessReadonly"
|
||||
:error="informationErrors.errors.volumeForecast"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="!businessReadonly" class="mt-12 flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.edit.save')"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitInformation"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Contacts -->
|
||||
<template #contacts>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<SupplierContactBlock
|
||||
v-for="(contact, index) in contacts"
|
||||
:key="contact.id ?? `new-${index}`"
|
||||
:model-value="contact"
|
||||
:title="t('commercial.suppliers.form.contact.title', { n: index + 1 })"
|
||||
:removable="contacts.length > 1"
|
||||
:readonly="businessReadonly"
|
||||
:errors="contactErrors[index]"
|
||||
@update:model-value="(v) => contacts[index] = v"
|
||||
@remove="askRemoveContact(index)"
|
||||
/>
|
||||
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.form.contact.add')"
|
||||
:disabled="!canAddContact"
|
||||
@click="addContact"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.edit.save')"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitContacts"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Adresses -->
|
||||
<template #addresses>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<SupplierAddressBlock
|
||||
v-for="(address, index) in addresses"
|
||||
:key="address.id ?? `new-${index}`"
|
||||
:model-value="address"
|
||||
:title="t('commercial.suppliers.form.address.title', { n: index + 1 })"
|
||||
:category-options="mainCategoryOptions"
|
||||
:site-options="siteOptions"
|
||||
:contact-options="contactOptions"
|
||||
:country-options="countryOptions"
|
||||
:removable="addresses.length > 1"
|
||||
:readonly="businessReadonly"
|
||||
:errors="addressErrors[index]"
|
||||
@update:model-value="(v) => addresses[index] = v"
|
||||
@remove="askRemoveAddress(index)"
|
||||
@degraded="onAddressDegraded"
|
||||
/>
|
||||
<div v-if="!businessReadonly" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.form.address.add')"
|
||||
:disabled="!canAddAddress"
|
||||
@click="addAddress"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.edit.save')"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAddresses"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Comptabilite (present uniquement si accounting.view ;
|
||||
editable uniquement si accounting.manage). -->
|
||||
<template v-if="canAccountingView" #accounting>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
v-model="accounting.siren"
|
||||
:label="t('commercial.suppliers.form.accounting.siren')"
|
||||
:mask="SIREN_MASK"
|
||||
:readonly="accountingReadonly"
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.siren"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="accounting.accountNumber"
|
||||
:label="t('commercial.suppliers.form.accounting.accountNumber')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.accountNumber"
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.tvaModeIri"
|
||||
:options="tvaModeOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.tvaMode')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.tvaMode"
|
||||
@update:model-value="(v: string | number | null) => accounting.tvaModeIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="accounting.nTva"
|
||||
:label="t('commercial.suppliers.form.accounting.nTva')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.nTva"
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.paymentDelayIri"
|
||||
:options="paymentDelayOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.paymentDelay')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.paymentDelay"
|
||||
@update:model-value="(v: string | number | null) => accounting.paymentDelayIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.paymentTypeIri"
|
||||
:options="paymentTypeOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.paymentType')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.paymentType"
|
||||
@update:model-value="onPaymentTypeChange"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="isBankRequired"
|
||||
:model-value="accounting.bankIri"
|
||||
:options="bankOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.bank')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.bank"
|
||||
@update:model-value="(v: string | number | null) => accounting.bankIri = v === null ? null : String(v)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Blocs RIB — affiches uniquement si type de reglement = LCR (RG-2.08). -->
|
||||
<div
|
||||
v-for="(rib, index) in visibleRibs"
|
||||
:key="rib.id ?? `new-${index}`"
|
||||
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||
>
|
||||
<MalioButtonIcon
|
||||
v-if="!accountingReadonly && visibleRibs.length > 1"
|
||||
icon="mdi:delete-outline"
|
||||
variant="ghost"
|
||||
button-class="absolute top-3 right-3"
|
||||
v-bind="{ ariaLabel: t('commercial.suppliers.form.accounting.removeRib') }"
|
||||
@click="askRemoveRib(index)"
|
||||
/>
|
||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
v-model="rib.label"
|
||||
:label="t('commercial.suppliers.form.accounting.ribLabel')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="isRibRequired"
|
||||
:error="ribErrors[index]?.label"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="rib.bic"
|
||||
:label="t('commercial.suppliers.form.accounting.ribBic')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="isRibRequired"
|
||||
:error="ribErrors[index]?.bic"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="rib.iban"
|
||||
:label="t('commercial.suppliers.form.accounting.ribIban')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="isRibRequired"
|
||||
:error="ribErrors[index]?.iban"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
v-if="isRibRequired"
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.form.accounting.addRib')"
|
||||
:disabled="!canAddRib"
|
||||
@click="addRib"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.edit.save')"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAccounting"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
||||
<template #transport><ComingSoonPlaceholder /></template>
|
||||
<template #statistics><ComingSoonPlaceholder /></template>
|
||||
<template #reports><ComingSoonPlaceholder /></template>
|
||||
<template #exchanges><ComingSoonPlaceholder /></template>
|
||||
</MalioTabList>
|
||||
</template>
|
||||
|
||||
<!-- Modal de confirmation generique (suppression contact / adresse / RIB). -->
|
||||
<MalioModal v-model="confirmModal.open" modal-class="max-w-md">
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold">{{ t('commercial.suppliers.form.confirmDelete.title') }}</h2>
|
||||
</template>
|
||||
<p>{{ confirmModal.message }}</p>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
button-class="flex-1"
|
||||
:label="t('commercial.suppliers.form.confirmDelete.cancel')"
|
||||
@click="confirmModal.open = false"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="danger"
|
||||
button-class="flex-1"
|
||||
:label="t('commercial.suppliers.form.confirmDelete.confirm')"
|
||||
@click="runConfirm"
|
||||
/>
|
||||
</template>
|
||||
</MalioModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useSupplier } from '~/modules/commercial/composables/useSupplier'
|
||||
import { useSupplierReferentials, type CategoryOption, type RefOption } from '~/modules/commercial/composables/useSupplierReferentials'
|
||||
import { useSupplierFormErrors } from '~/modules/commercial/composables/useSupplierFormErrors'
|
||||
import {
|
||||
canEditSupplier,
|
||||
categoryOptionsOf,
|
||||
referentialOptionOf,
|
||||
siteOptionsOf,
|
||||
mapContactToDraft,
|
||||
mapAddressToDraft,
|
||||
mapRibToDraft,
|
||||
type SupplierDetail,
|
||||
} from '~/modules/commercial/utils/supplierConsultation'
|
||||
import {
|
||||
buildAccountingPayload,
|
||||
buildAddressPayload,
|
||||
buildContactPayload,
|
||||
buildInformationPayload,
|
||||
buildMainPayload,
|
||||
buildRibPayload,
|
||||
mapAccountingFormDraft,
|
||||
mapInformationDraft,
|
||||
mapMainDraft,
|
||||
resolveTabEditability,
|
||||
type AccountingFormDraft,
|
||||
type InformationFormDraft,
|
||||
type MainFormDraft,
|
||||
type SupplierEditAbilities,
|
||||
} from '~/modules/commercial/utils/supplierEdit'
|
||||
import {
|
||||
buildSupplierFormTabKeys,
|
||||
isAddressValid,
|
||||
isBankRequiredForPaymentType,
|
||||
isContactBlank,
|
||||
isContactNamed,
|
||||
isRibBlank,
|
||||
isRibComplete,
|
||||
isRibRequiredForPaymentType,
|
||||
} from '~/modules/commercial/utils/supplierFormRules'
|
||||
import {
|
||||
emptyAddress,
|
||||
emptyContact,
|
||||
emptyRib,
|
||||
type SupplierAddressFormDraft,
|
||||
type SupplierContactFormDraft,
|
||||
type SupplierRibFormDraft,
|
||||
} from '~/modules/commercial/types/supplierForm'
|
||||
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||
import { readHistoryTab } from '~/shared/utils/historyTab'
|
||||
|
||||
// Masques de saisie (la normalisation finale reste serveur).
|
||||
const SIREN_MASK = '#########'
|
||||
const EMPLOYEES_MASK = '#######'
|
||||
// Volume previsionnel : champ texte borne aux chiffres (entier >= 0 cote back).
|
||||
const VOLUME_FORECAST_MASK = '##########'
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const toast = useToast()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { can, canAny } = usePermissions()
|
||||
|
||||
// Gating de la route : l'edition exige de pouvoir editer au moins un onglet
|
||||
// (`manage` OU `accounting.manage`). Usine et roles en lecture seule sont
|
||||
// rediriges vers le repertoire (lui-meme protege).
|
||||
if (!canEditSupplier(canAny)) {
|
||||
await navigateTo('/suppliers')
|
||||
}
|
||||
|
||||
const supplierId = route.params.id as string
|
||||
|
||||
const { supplier, loading, error, load } = useSupplier(supplierId)
|
||||
const referentials = useSupplierReferentials()
|
||||
|
||||
// ── Permissions / editabilite par zone (option 1 ERP-74) ────────────────────
|
||||
const abilities = computed<SupplierEditAbilities>(() => ({
|
||||
canManage: can('commercial.suppliers.manage'),
|
||||
canAccountingView: can('commercial.suppliers.accounting.view'),
|
||||
canAccountingManage: can('commercial.suppliers.accounting.manage'),
|
||||
}))
|
||||
const editability = computed(() => resolveTabEditability(abilities.value))
|
||||
// Bloc principal + onglets Information / Contacts / Adresses.
|
||||
const businessReadonly = computed(() => !editability.value.businessEditable)
|
||||
const canAccountingView = computed(() => editability.value.accountingVisible)
|
||||
const accountingReadonly = computed(() => !editability.value.accountingEditable)
|
||||
|
||||
const headerTitle = computed(() => supplier.value?.companyName ?? t('commercial.suppliers.edit.title'))
|
||||
|
||||
// ── Brouillons editables (pre-remplis depuis le detail) ─────────────────────
|
||||
const main = reactive<MainFormDraft>(mapMainDraft({} as SupplierDetail))
|
||||
const information = reactive<InformationFormDraft>(mapInformationDraft({} as SupplierDetail))
|
||||
const accounting = reactive<AccountingFormDraft>(mapAccountingFormDraft({} as SupplierDetail))
|
||||
const contacts = ref<SupplierContactFormDraft[]>([])
|
||||
const addresses = ref<SupplierAddressFormDraft[]>([])
|
||||
const ribs = ref<SupplierRibFormDraft[]>([])
|
||||
|
||||
// Ids des sous-ressources existantes supprimees (DELETE differe au « Valider »).
|
||||
const removedContactIds = ref<number[]>([])
|
||||
const removedAddressIds = ref<number[]>([])
|
||||
const removedRibIds = ref<number[]>([])
|
||||
|
||||
const mainSubmitting = ref(false)
|
||||
const tabSubmitting = ref(false)
|
||||
const addressDegradedNotified = ref(false)
|
||||
|
||||
/** Recopie le detail charge dans les brouillons editables. */
|
||||
function hydrate(detail: SupplierDetail): void {
|
||||
Object.assign(main, mapMainDraft(detail))
|
||||
Object.assign(information, mapInformationDraft(detail))
|
||||
Object.assign(accounting, mapAccountingFormDraft(detail))
|
||||
contacts.value = (detail.contacts ?? []).map(mapContactToDraft)
|
||||
addresses.value = (detail.addresses ?? []).map(mapAddressToDraft)
|
||||
ribs.value = (detail.ribs ?? []).map(mapRibToDraft)
|
||||
// Chaque bloc reste visible meme vide : si une collection est vide, on amorce
|
||||
// un bloc vierge (non persiste tant qu'incomplet — cf. submit*/canAdd*).
|
||||
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
||||
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
||||
// RIB : amorce un bloc vide seulement si le type de reglement est une LCR
|
||||
// (sinon la section reste masquee — RG-2.08).
|
||||
if (isRibRequired.value && ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
}
|
||||
|
||||
// ── Options de selects (referentiels UNION valeurs courantes de l'embed) ─────
|
||||
// L'union garantit que les valeurs deja posees s'affichent meme quand le
|
||||
// referentiel complet n'est pas chargeable (roles metier sans
|
||||
// catalog.categories.view / sites.view → 403, cf. matrice § 2.7).
|
||||
function mergeOptions<T extends { value: string }>(primary: T[], extra: T[]): T[] {
|
||||
const seen = new Set(primary.map(o => o.value))
|
||||
return [...primary, ...extra.filter(o => !seen.has(o.value))]
|
||||
}
|
||||
|
||||
// Categories issues de l'embed (fournisseur + adresses), role-independantes.
|
||||
const embedCategoryOptions = computed<CategoryOption[]>(() => {
|
||||
const fromSupplier = categoryOptionsOf(supplier.value?.categories)
|
||||
const fromAddresses = (supplier.value?.addresses ?? []).flatMap(a => categoryOptionsOf(a.categories))
|
||||
return mergeOptions(fromSupplier, fromAddresses)
|
||||
})
|
||||
// Toutes les categories de type FOURNISSEUR sont autorisees, sur le bloc principal
|
||||
// comme sur une adresse (pas de restriction Distributeur/Courtier comme au M1 — RG-2.10).
|
||||
const mainCategoryOptions = computed(() => mergeOptions(referentials.categories.value, embedCategoryOptions.value))
|
||||
|
||||
const embedSiteOptions = computed<RefOption[]>(() =>
|
||||
mergeOptions([], (supplier.value?.addresses ?? []).flatMap(a => siteOptionsOf(a.sites))),
|
||||
)
|
||||
const siteOptions = computed(() => mergeOptions(referentials.sites.value, embedSiteOptions.value))
|
||||
|
||||
// Contacts deja persistes (iri non null), rattachables a une adresse (M2M).
|
||||
const contactOptions = computed<RefOption[]>(() =>
|
||||
contacts.value
|
||||
.filter(c => c.iri !== null)
|
||||
.map(c => ({
|
||||
value: c.iri as string,
|
||||
label: [c.firstName, c.lastName].filter(Boolean).join(' ') || (c.email ?? ''),
|
||||
})),
|
||||
)
|
||||
|
||||
// Pays : referentiel `country` charge via l'API (ERP-116), aligne sur l'ecran
|
||||
// client. On merge la valeur deja stockee sur chaque adresse (embed) — comme les
|
||||
// autres selects de cet ecran — pour ne pas vider le select si `/countries`
|
||||
// echoue (resilience ERP-102) ou si un pays historique n'est plus au referentiel.
|
||||
const embedCountryOptions = computed<RefOption[]>(() =>
|
||||
mergeOptions([], (supplier.value?.addresses ?? [])
|
||||
.map(a => a.country)
|
||||
.filter((c): c is string => !!c)
|
||||
.map(c => ({ value: c, label: c }))),
|
||||
)
|
||||
const countryOptions = computed<RefOption[]>(() =>
|
||||
mergeOptions(referentials.countries.value, embedCountryOptions.value),
|
||||
)
|
||||
|
||||
// Selects comptables : referentiel UNION valeur courante de l'embed (libelle).
|
||||
const tvaModeOptions = computed(() => mergeOptions(referentials.tvaModes.value, referentialOptionOf(supplier.value?.tvaMode)))
|
||||
const paymentDelayOptions = computed(() => mergeOptions(referentials.paymentDelays.value, referentialOptionOf(supplier.value?.paymentDelay)))
|
||||
const paymentTypeOptions = computed(() => mergeOptions(
|
||||
referentials.paymentTypes.value.map(p => ({ value: p.value, label: p.label })),
|
||||
referentialOptionOf(supplier.value?.paymentType),
|
||||
))
|
||||
const bankOptions = computed(() => mergeOptions(referentials.banks.value, referentialOptionOf(supplier.value?.bank)))
|
||||
|
||||
// ── Onglets : navigation libre (3 actifs + Compta + 4 coquilles) ────────────
|
||||
const tabKeys = computed(() => buildSupplierFormTabKeys(canAccountingView.value, { includeEditOnlyTabs: true }))
|
||||
|
||||
const TAB_ICONS: Record<string, string> = {
|
||||
information: 'mdi:account-outline',
|
||||
contacts: 'mdi:account-box-plus-outline',
|
||||
addresses: 'mdi:map-marker-outline',
|
||||
transport: 'mdi:truck-delivery-outline',
|
||||
accounting: 'mdi:bank-circle-outline',
|
||||
statistics: 'mdi:finance',
|
||||
reports: 'mdi:file-document-edit-outline',
|
||||
exchanges: 'mdi:account-group-outline',
|
||||
}
|
||||
|
||||
const tabs = computed(() => tabKeys.value.map(key => ({
|
||||
key,
|
||||
label: t(`commercial.suppliers.tab.${key}`),
|
||||
icon: TAB_ICONS[key],
|
||||
})))
|
||||
|
||||
// Onglet initial : repris de la consultation (history.state), sinon Information.
|
||||
const activeTab = ref(readHistoryTab(tabKeys.value) ?? 'information')
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
/** Retour consultation en conservant l'onglet courant (via history.state). */
|
||||
function goBack(): void {
|
||||
router.push({ path: `/suppliers/${supplierId}`, state: { tab: activeTab.value } })
|
||||
}
|
||||
|
||||
/**
|
||||
* Message d'erreur a afficher : violation 422 / detail renvoye par le serveur,
|
||||
* sinon un libelle generique. Le 409 d'unicite de nom (bloc principal) est
|
||||
* traduit explicitement par l'appelant.
|
||||
*/
|
||||
function apiErrorMessage(e: unknown): string {
|
||||
const data = (e as { data?: unknown })?.data
|
||||
return extractApiErrorMessage(data) || t('commercial.suppliers.toast.error')
|
||||
}
|
||||
|
||||
function showError(e: unknown): void {
|
||||
toast.error({ title: t('commercial.suppliers.toast.error'), message: apiErrorMessage(e) })
|
||||
}
|
||||
|
||||
// ── Erreurs de validation par champ (ERP-101) ───────────────────────────────
|
||||
const {
|
||||
mainErrors,
|
||||
informationErrors,
|
||||
accountingErrors,
|
||||
contactErrors,
|
||||
addressErrors,
|
||||
ribErrors,
|
||||
submitRows,
|
||||
} = useSupplierFormErrors()
|
||||
|
||||
// ── Bloc principal ───────────────────────────────────────────────────────────
|
||||
/** PATCH /suppliers/{id} — groupe supplier:write:main UNIQUEMENT (mode strict). */
|
||||
async function submitMain(): Promise<void> {
|
||||
if (businessReadonly.value || mainSubmitting.value) return
|
||||
mainSubmitting.value = true
|
||||
mainErrors.clearErrors()
|
||||
try {
|
||||
const updated = await api.patch<SupplierDetail>(`/suppliers/${supplierId}`, buildMainPayload(main, { forUpdate: true }), {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
// Reaffiche les valeurs normalisees renvoyees par le serveur (UPPERCASE, RG-2.12).
|
||||
Object.assign(main, mapMainDraft(updated))
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
catch (e) {
|
||||
// 409 = doublon nom de societe → erreur inline + toast ; 422 → mapping
|
||||
// inline par champ ; autre → toast de fallback. Cf. ERP-101.
|
||||
const status = (e as { response?: { status?: number } })?.response?.status
|
||||
if (status === 409) {
|
||||
const message = t('commercial.suppliers.form.duplicateCompany')
|
||||
mainErrors.setError('companyName', message)
|
||||
toast.error({ title: t('commercial.suppliers.toast.error'), message })
|
||||
}
|
||||
else {
|
||||
mainErrors.handleApiError(e, { fallbackMessage: t('commercial.suppliers.toast.error') })
|
||||
}
|
||||
}
|
||||
finally {
|
||||
mainSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglet Information ───────────────────────────────────────────────────────
|
||||
/** PATCH /suppliers/{id} — groupe supplier:write:information UNIQUEMENT. */
|
||||
async function submitInformation(): Promise<void> {
|
||||
if (businessReadonly.value || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
informationErrors.clearErrors()
|
||||
try {
|
||||
await api.patch(`/suppliers/${supplierId}`, buildInformationPayload(information), { toast: false })
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
catch (e) {
|
||||
informationErrors.handleApiError(e, { fallbackMessage: t('commercial.suppliers.toast.error') })
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglet Contacts ───────────────────────────────────────────────────────────
|
||||
const canAddContact = computed(() => {
|
||||
const last = contacts.value[contacts.value.length - 1]
|
||||
return last === undefined || isContactNamed(last)
|
||||
})
|
||||
function addContact(): void {
|
||||
if (canAddContact.value) contacts.value.push(emptyContact())
|
||||
}
|
||||
|
||||
function askRemoveContact(index: number): void {
|
||||
askConfirm(t('commercial.suppliers.form.confirmDelete.contact'), () => {
|
||||
const removed = contacts.value[index]
|
||||
if (removed?.id != null) removedContactIds.value.push(removed.id)
|
||||
contacts.value.splice(index, 1)
|
||||
contactErrors.value.splice(index, 1)
|
||||
// Garde au moins un bloc visible (cf. amorce a l'hydratation).
|
||||
if (contacts.value.length === 0) contacts.value.push(emptyContact())
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Valide l'onglet Contacts : DELETE des contacts retires (existants), puis
|
||||
* POST/PATCH des blocs restants sur la sous-ressource. Strictement scope a la
|
||||
* collection contacts (endpoints supplier_contact dedies).
|
||||
*/
|
||||
async function submitContacts(): Promise<void> {
|
||||
if (businessReadonly.value || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
contactErrors.value = []
|
||||
try {
|
||||
for (const id of removedContactIds.value) {
|
||||
await api.delete(`/supplier_contacts/${id}`, {}, { toast: false })
|
||||
}
|
||||
removedContactIds.value = []
|
||||
|
||||
// RG-2.13 : au moins un contact requis. Si l'onglet ne contient QUE des
|
||||
// amorces neuves vides, on les soumet -> 422 RG-2.04 inline (nom OU prenom).
|
||||
const hasSubmittableContact = contacts.value.some(c => c.id !== null || !isContactBlank(c))
|
||||
const hasError = await submitRows(
|
||||
contacts.value,
|
||||
contactErrors,
|
||||
async (contact) => {
|
||||
const body = buildContactPayload(contact)
|
||||
if (contact.id === null) {
|
||||
const created = await api.post<{ '@id'?: string, id: number }>(
|
||||
`/suppliers/${supplierId}/contacts`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
contact.id = created.id
|
||||
contact.iri = created['@id'] ?? null
|
||||
}
|
||||
else {
|
||||
await api.patch(`/supplier_contacts/${contact.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => showError(error),
|
||||
contact => hasSubmittableContact && contact.id === null && isContactBlank(contact),
|
||||
)
|
||||
if (hasError) return
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
catch (e) {
|
||||
showError(e)
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglet Adresses ───────────────────────────────────────────────────────────
|
||||
// « + Adresse » desactive tant que la derniere adresse n'est pas valide.
|
||||
const canAddAddress = computed(() => {
|
||||
const last = addresses.value[addresses.value.length - 1]
|
||||
return last !== undefined && isAddressValid(last)
|
||||
})
|
||||
|
||||
function addAddress(): void {
|
||||
if (canAddAddress.value) addresses.value.push(emptyAddress())
|
||||
}
|
||||
|
||||
function askRemoveAddress(index: number): void {
|
||||
askConfirm(t('commercial.suppliers.form.confirmDelete.address'), () => {
|
||||
const removed = addresses.value[index]
|
||||
if (removed?.id != null) removedAddressIds.value.push(removed.id)
|
||||
addresses.value.splice(index, 1)
|
||||
addressErrors.value.splice(index, 1)
|
||||
// Garde au moins un bloc visible (cf. amorce a l'hydratation).
|
||||
if (addresses.value.length === 0) addresses.value.push(emptyAddress())
|
||||
})
|
||||
}
|
||||
|
||||
function onAddressDegraded(): void {
|
||||
if (addressDegradedNotified.value) return
|
||||
addressDegradedNotified.value = true
|
||||
toast.warning({
|
||||
title: t('commercial.suppliers.toast.error'),
|
||||
message: t('commercial.suppliers.form.address.degraded'),
|
||||
})
|
||||
}
|
||||
|
||||
/** Valide l'onglet Adresses : DELETE des adresses retirees puis POST/PATCH. */
|
||||
async function submitAddresses(): Promise<void> {
|
||||
if (businessReadonly.value || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
addressErrors.value = []
|
||||
try {
|
||||
for (const id of removedAddressIds.value) {
|
||||
await api.delete(`/supplier_addresses/${id}`, {}, { toast: false })
|
||||
}
|
||||
removedAddressIds.value = []
|
||||
|
||||
const hasError = await submitRows(
|
||||
addresses.value,
|
||||
addressErrors,
|
||||
async (address) => {
|
||||
// Edition d'une adresse existante : champ requis vide envoye en `''`
|
||||
// (NotBlank 422) au lieu d'etre omis — sinon le PATCH garderait
|
||||
// l'ancienne valeur (faux 200). Creation (id null) : omit classique.
|
||||
const body = buildAddressPayload(address, { forUpdate: address.id !== null })
|
||||
if (address.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/suppliers/${supplierId}/addresses`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
address.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/supplier_addresses/${address.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => showError(error),
|
||||
)
|
||||
if (hasError) return
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
catch (e) {
|
||||
showError(e)
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglet Comptabilite ──────────────────────────────────────────────────────
|
||||
const selectedPaymentTypeCode = computed(() =>
|
||||
referentials.paymentTypes.value.find(p => p.value === accounting.paymentTypeIri)?.code ?? null,
|
||||
)
|
||||
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
|
||||
// Les blocs RIB ne sont affiches que pour une LCR (RG-2.08).
|
||||
const visibleRibs = computed(() => isRibRequired.value ? ribs.value : [])
|
||||
|
||||
function onPaymentTypeChange(value: string | number | null): void {
|
||||
accounting.paymentTypeIri = value === null ? null : String(value)
|
||||
if (!isBankRequired.value) accounting.bankIri = null
|
||||
// ERP-121 : un RIB est une coordonnee bancaire du fournisseur, decouplee du mode
|
||||
// de reglement. Au passage hors-LCR on ne SUPPRIME plus les RIB existants : ils
|
||||
// restent en base, simplement masques a l'ecran (visibleRibs = []), et
|
||||
// reapparaissent tels quels si l'on repasse en LCR. Seule la corbeille d'un
|
||||
// bloc (askRemoveRib) retire reellement un RIB.
|
||||
if (isRibRequired.value) {
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
}
|
||||
else {
|
||||
// Hors-LCR : on nettoie seulement les erreurs inline (plus affichees).
|
||||
ribErrors.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// « + RIB » desactive tant que le dernier bloc RIB n'est pas complet.
|
||||
const canAddRib = computed(() => {
|
||||
const last = ribs.value[ribs.value.length - 1]
|
||||
return last !== undefined && isRibComplete(last)
|
||||
})
|
||||
|
||||
function addRib(): void {
|
||||
if (canAddRib.value) ribs.value.push(emptyRib())
|
||||
}
|
||||
|
||||
function askRemoveRib(index: number): void {
|
||||
askConfirm(t('commercial.suppliers.form.confirmDelete.rib'), () => {
|
||||
const removed = ribs.value[index]
|
||||
if (removed?.id != null) removedRibIds.value.push(removed.id)
|
||||
ribs.value.splice(index, 1)
|
||||
ribErrors.value.splice(index, 1)
|
||||
// Garde au moins un bloc RIB visible (cf. amorce a l'hydratation).
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Valide l'onglet Comptabilite : POST/PATCH des RIB sur la sous-ressource PUIS
|
||||
* PATCH des scalaires (groupe supplier:write:accounting, exige accounting.manage
|
||||
* cote back) PUIS DELETE des RIB explicitement retires. Les RIB crees d'abord : le
|
||||
* back valide RG-2.08 (LCR => au moins un RIB persiste) sur le PATCH scalaires.
|
||||
*
|
||||
* ERP-121 : les RIB ne sont (re)soumis QUE sous LCR — hors-LCR ce sont des
|
||||
* coordonnees dormantes conservees telles quelles, masquees a l'ecran et jamais
|
||||
* re-ecrites. `removedRibIds` ne contient plus que les suppressions EXPLICITES
|
||||
* (corbeille d'un bloc, toujours sous LCR). Aucun champ main/information dans le
|
||||
* payload (mode strict RG-2.16 : sinon 403 sur tout le payload).
|
||||
*/
|
||||
async function submitAccounting(): Promise<void> {
|
||||
if (accountingReadonly.value || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
accountingErrors.clearErrors()
|
||||
try {
|
||||
// 1) POST/PATCH des RIB d'abord — UNIQUEMENT sous LCR (erreurs inline par
|
||||
// ligne, tous les blocs tentes). Hors-LCR (ERP-121), les RIB sont des
|
||||
// coordonnees dormantes : rien d'editable n'est affiche, on ne les re-soumet
|
||||
// pas. On ne saute une amorce neuve vide QUE s'il reste un autre RIB
|
||||
// soumettable : sinon (ex. l'unique RIB existant supprime, remplace par un
|
||||
// bloc vide), on la soumet pour declencher la 422 NotBlank inline plutot que
|
||||
// de laisser le DELETE echouer en « dernier RIB d'une LCR » (message plat).
|
||||
if (isRibRequired.value) {
|
||||
const hasSubmittableRib = ribs.value.some(r => r.id !== null || !isRibBlank(r))
|
||||
const ribHasError = await submitRows(
|
||||
ribs.value,
|
||||
ribErrors,
|
||||
async (rib) => {
|
||||
// Edition d'un RIB existant : champ requis vide envoye en `''` (NotBlank
|
||||
// 422) au lieu d'etre omis (sinon le PATCH garderait l'ancienne valeur).
|
||||
const body = buildRibPayload(rib, { forUpdate: rib.id !== null })
|
||||
if (rib.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/suppliers/${supplierId}/ribs`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
rib.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/supplier_ribs/${rib.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => showError(error),
|
||||
rib => hasSubmittableRib && rib.id === null && isRibBlank(rib),
|
||||
)
|
||||
if (ribHasError) return
|
||||
}
|
||||
|
||||
// 2) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||
try {
|
||||
await api.patch(`/suppliers/${supplierId}`, buildAccountingPayload(accounting, isBankRequired.value), { toast: false })
|
||||
}
|
||||
catch (error) {
|
||||
accountingErrors.handleApiError(error, { fallbackMessage: t('commercial.suppliers.toast.error') })
|
||||
return
|
||||
}
|
||||
|
||||
// 3) DELETE des RIB explicitement retires (corbeille d'un bloc) : APRES le
|
||||
// PATCH scalaires (le guard back refuse la suppression du dernier RIB d'une
|
||||
// LCR). ERP-121 : plus aucune suppression automatique au passage hors-LCR.
|
||||
for (const id of removedRibIds.value) {
|
||||
await api.delete(`/supplier_ribs/${id}`, {}, { toast: false })
|
||||
}
|
||||
removedRibIds.value = []
|
||||
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
catch (e) {
|
||||
showError(e)
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Modal de confirmation generique ──────────────────────────────────────────
|
||||
const confirmModal = reactive({
|
||||
open: false,
|
||||
message: '',
|
||||
action: null as null | (() => void),
|
||||
})
|
||||
|
||||
function askConfirm(message: string, action: () => void): void {
|
||||
confirmModal.message = message
|
||||
confirmModal.action = action
|
||||
confirmModal.open = true
|
||||
}
|
||||
|
||||
function runConfirm(): void {
|
||||
confirmModal.action?.()
|
||||
confirmModal.action = null
|
||||
confirmModal.open = false
|
||||
}
|
||||
|
||||
useHead({ title: headerTitle })
|
||||
|
||||
onMounted(async () => {
|
||||
// Referentiels en best-effort (echec non bloquant : l'embed alimente les
|
||||
// libelles des valeurs courantes).
|
||||
referentials.loadCommon().catch(() => {})
|
||||
await load()
|
||||
if (supplier.value) hydrate(supplier.value)
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,468 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tete : retour repertoire + nom du fournisseur + actions (Modifier / Archiver|Restaurer). -->
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
variant="ghost"
|
||||
v-bind="{ ariaLabel: t('commercial.suppliers.consultation.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ headerTitle }}</h1>
|
||||
|
||||
<!-- gap-12 = 48px : meme espacement que Ajouter / Filtres du repertoire. -->
|
||||
<div class="ml-auto flex items-center gap-12">
|
||||
<MalioButton
|
||||
v-if="canEdit"
|
||||
variant="secondary"
|
||||
icon-name="mdi:pencil-outline"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.action.edit')"
|
||||
@click="goEdit"
|
||||
/>
|
||||
<MalioButton
|
||||
v-if="showArchive"
|
||||
variant="secondary"
|
||||
icon-name="mdi:archive-arrow-down-outline"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.action.archive')"
|
||||
@click="askToggleArchive"
|
||||
/>
|
||||
<MalioButton
|
||||
v-if="showRestore"
|
||||
variant="secondary"
|
||||
icon-name="mdi:archive-arrow-up-outline"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.action.restore')"
|
||||
@click="askToggleArchive"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Etats de chargement / introuvable. -->
|
||||
<p v-if="loading" class="mt-12 text-center text-black/60">{{ t('commercial.suppliers.consultation.loading') }}</p>
|
||||
<p v-else-if="error" class="mt-12 text-center text-m-danger">{{ t('commercial.suppliers.consultation.notFound') }}</p>
|
||||
|
||||
<template v-else-if="supplier">
|
||||
<!-- ── Formulaire principal (lecture seule) ──────────────────────── -->
|
||||
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
:model-value="supplier.companyName"
|
||||
:label="t('commercial.suppliers.form.main.companyName')"
|
||||
readonly
|
||||
/>
|
||||
<MalioSelectCheckbox
|
||||
:model-value="categoryIris"
|
||||
:options="mainCategoryOptions"
|
||||
:label="t('commercial.suppliers.form.main.categories')"
|
||||
:display-tag="true"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ── Onglets (navigation libre, tout en lecture seule) ─────────── -->
|
||||
<MalioTabList v-model="activeTab" :tabs="tabs" :max-visible-tabs="5" :max-width="1100" class="mt-[60px]">
|
||||
<!-- Onglet Information -->
|
||||
<template #information>
|
||||
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- pt-1/pb-1 alignent le textarea (h-full) en haut ET en bas
|
||||
sur les inputs (champ 40px centre dans un h-12). -->
|
||||
<MalioInputTextArea
|
||||
:model-value="information.description"
|
||||
:label="t('commercial.suppliers.form.information.description')"
|
||||
resize="none"
|
||||
group-class="row-span-2 pt-1 pb-1"
|
||||
text-input="h-full text-lg"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="information.competitors"
|
||||
:label="t('commercial.suppliers.form.information.competitors')"
|
||||
readonly
|
||||
/>
|
||||
<MalioDate
|
||||
:model-value="information.foundedAt"
|
||||
:label="t('commercial.suppliers.form.information.foundedAt')"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="information.employeesCount"
|
||||
:label="t('commercial.suppliers.form.information.employeesCount')"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputAmount
|
||||
:model-value="information.revenueAmount"
|
||||
:label="t('commercial.suppliers.form.information.revenueAmount')"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="information.directorName"
|
||||
:label="t('commercial.suppliers.form.information.directorName')"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputAmount
|
||||
:model-value="information.profitAmount"
|
||||
:label="t('commercial.suppliers.form.information.profitAmount')"
|
||||
readonly
|
||||
/>
|
||||
<!-- Volume previsionnel : specifique fournisseur (entier). -->
|
||||
<MalioInputText
|
||||
:model-value="information.volumeForecast"
|
||||
:label="t('commercial.suppliers.form.information.volumeForecast')"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Contacts -->
|
||||
<template #contacts>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<SupplierContactBlock
|
||||
v-for="(contact, index) in contacts"
|
||||
:key="contact.id ?? index"
|
||||
:model-value="contact"
|
||||
:title="t('commercial.suppliers.form.contact.title', { n: index + 1 })"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Adresses -->
|
||||
<template #addresses>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<SupplierAddressBlock
|
||||
v-for="(view, index) in addressViews"
|
||||
:key="view.draft.id ?? index"
|
||||
:model-value="view.draft"
|
||||
:title="t('commercial.suppliers.form.address.title', { n: index + 1 })"
|
||||
:category-options="view.categoryOptions"
|
||||
:site-options="allSiteOptions"
|
||||
:contact-options="contactOptions"
|
||||
:country-options="countryOptions"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Comptabilite (present uniquement si accounting.view). -->
|
||||
<template v-if="canAccountingView" #accounting>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
:model-value="accounting.siren"
|
||||
:label="t('commercial.suppliers.form.accounting.siren')"
|
||||
:mask="SIREN_MASK"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="accounting.accountNumber"
|
||||
:label="t('commercial.suppliers.form.accounting.accountNumber')"
|
||||
readonly
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.tvaModeIri"
|
||||
:options="tvaModeOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.tvaMode')"
|
||||
empty-option-label=""
|
||||
readonly
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="accounting.nTva"
|
||||
:label="t('commercial.suppliers.form.accounting.nTva')"
|
||||
readonly
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.paymentDelayIri"
|
||||
:options="paymentDelayOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.paymentDelay')"
|
||||
empty-option-label=""
|
||||
readonly
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.paymentTypeIri"
|
||||
:options="paymentTypeOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.paymentType')"
|
||||
empty-option-label=""
|
||||
readonly
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="accounting.bankIri"
|
||||
:model-value="accounting.bankIri"
|
||||
:options="bankOptions"
|
||||
:label="t('commercial.suppliers.form.accounting.bank')"
|
||||
empty-option-label=""
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Blocs RIB (0..n), lecture seule. -->
|
||||
<div
|
||||
v-for="(rib, index) in ribs"
|
||||
:key="rib.id ?? index"
|
||||
class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||
>
|
||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
:model-value="rib.label"
|
||||
:label="t('commercial.suppliers.form.accounting.ribLabel')"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="rib.bic"
|
||||
:label="t('commercial.suppliers.form.accounting.ribBic')"
|
||||
readonly
|
||||
/>
|
||||
<MalioInputText
|
||||
:model-value="rib.iban"
|
||||
:label="t('commercial.suppliers.form.accounting.ribIban')"
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglets non encore implementes : frame vide (navigation libre). -->
|
||||
<template #transport><ComingSoonPlaceholder /></template>
|
||||
<template #statistics><ComingSoonPlaceholder /></template>
|
||||
<template #reports><ComingSoonPlaceholder /></template>
|
||||
<template #exchanges><ComingSoonPlaceholder /></template>
|
||||
</MalioTabList>
|
||||
</template>
|
||||
|
||||
<!-- Modal de confirmation Archiver / Restaurer. -->
|
||||
<MalioModal v-model="confirmOpen" modal-class="max-w-md">
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold">
|
||||
{{ isArchived ? t('commercial.suppliers.consultation.confirmRestore.title') : t('commercial.suppliers.consultation.confirmArchive.title') }}
|
||||
</h2>
|
||||
</template>
|
||||
<p>{{ isArchived ? t('commercial.suppliers.consultation.confirmRestore.message') : t('commercial.suppliers.consultation.confirmArchive.message') }}</p>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
button-class="flex-1"
|
||||
:label="t('commercial.suppliers.form.confirmDelete.cancel')"
|
||||
@click="confirmOpen = false"
|
||||
/>
|
||||
<MalioButton
|
||||
:variant="isArchived ? 'primary' : 'danger'"
|
||||
button-class="flex-1"
|
||||
:label="t('commercial.suppliers.form.confirmDelete.confirm')"
|
||||
:disabled="toggling"
|
||||
@click="confirmToggleArchive"
|
||||
/>
|
||||
</template>
|
||||
</MalioModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useSupplier } from '~/modules/commercial/composables/useSupplier'
|
||||
import { buildSupplierFormTabKeys, isRibRequiredForPaymentType } from '~/modules/commercial/utils/supplierFormRules'
|
||||
import { readHistoryTab } from '~/shared/utils/historyTab'
|
||||
import {
|
||||
canEditSupplier,
|
||||
categoryOptionsOf,
|
||||
contactOptionsOf,
|
||||
emptyAddress,
|
||||
mapAccountingDraft,
|
||||
mapAddressView,
|
||||
mapContactToDraft,
|
||||
mapRibToDraft,
|
||||
paymentTypeCodeOf,
|
||||
referentialOptionOf,
|
||||
showArchiveAction,
|
||||
showRestoreAction,
|
||||
type SelectOption,
|
||||
type SupplierDetail,
|
||||
} from '~/modules/commercial/utils/supplierConsultation'
|
||||
import { emptyContact } from '~/modules/commercial/types/supplierForm'
|
||||
|
||||
// Masque d'affichage (purement visuel, la donnee reste celle du serveur).
|
||||
const SIREN_MASK = '#########'
|
||||
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const toast = useToast()
|
||||
const { can, canAny } = usePermissions()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Gating de la route : la consultation exige `view`. Usine (sans view) est
|
||||
// redirige vers le repertoire (lui-meme protege). Cf. matrice § 2.7.
|
||||
if (!can('commercial.suppliers.view')) {
|
||||
await navigateTo('/suppliers')
|
||||
}
|
||||
|
||||
const supplierId = route.params.id as string
|
||||
|
||||
const { supplier, loading, error, load, archive, restore } = useSupplier(supplierId)
|
||||
|
||||
// ── Permissions / visibilite des actions ───────────────────────────────────
|
||||
const canAccountingView = computed(() => can('commercial.suppliers.accounting.view'))
|
||||
const canEdit = computed(() => canEditSupplier(canAny))
|
||||
const isArchived = computed(() => supplier.value?.isArchived === true)
|
||||
const showArchive = computed(() => showArchiveAction(can, isArchived.value))
|
||||
const showRestore = computed(() => showRestoreAction(can, isArchived.value))
|
||||
|
||||
const headerTitle = computed(() => supplier.value?.companyName ?? t('commercial.suppliers.consultation.title'))
|
||||
|
||||
// ── Donnees derivees du payload (lecture seule) ────────────────────────────
|
||||
const categoryIris = computed(() => (supplier.value?.categories ?? []).map(c => c['@id']))
|
||||
|
||||
const information = computed(() => ({
|
||||
description: supplier.value?.description ?? null,
|
||||
competitors: supplier.value?.competitors ?? null,
|
||||
// MalioDate attend strictement YYYY-MM-DD : on tronque l'ISO datetime renvoye.
|
||||
foundedAt: supplier.value?.foundedAt ? supplier.value.foundedAt.slice(0, 10) : null,
|
||||
employeesCount: supplier.value?.employeesCount != null ? String(supplier.value.employeesCount) : null,
|
||||
revenueAmount: supplier.value?.revenueAmount ?? null,
|
||||
profitAmount: supplier.value?.profitAmount ?? null,
|
||||
directorName: supplier.value?.directorName ?? null,
|
||||
volumeForecast: supplier.value?.volumeForecast != null ? String(supplier.value.volumeForecast) : null,
|
||||
}))
|
||||
|
||||
// Chaque bloc reste visible meme vide en consultation : si la collection est
|
||||
// vide, on affiche un bloc vierge en lecture seule (pas de message « Aucun … »).
|
||||
const contacts = computed(() => {
|
||||
const list = (supplier.value?.contacts ?? []).map(mapContactToDraft)
|
||||
return list.length ? list : [emptyContact()]
|
||||
})
|
||||
// Vue par adresse : brouillon + options (sites/categories) propres a l'adresse.
|
||||
const addressViews = computed(() => {
|
||||
const views = (supplier.value?.addresses ?? []).map(mapAddressView)
|
||||
return views.length ? views : [{ draft: emptyAddress(), siteOptions: [], categoryOptions: [] }]
|
||||
})
|
||||
// Exception au placeholder ci-dessus : on n'affiche AUCUN bloc RIB quand le
|
||||
// fournisseur n'en a pas. ERP-121 : un fournisseur peut desormais conserver des RIB
|
||||
// « dormants » apres etre repasse hors-LCR (on ne les supprime plus). En consultation,
|
||||
// decision metier = on les masque TOTALEMENT : on n'affiche les RIB que si le type de
|
||||
// reglement courant est LCR (le `code` est embarque sous supplier:read:accounting).
|
||||
const ribs = computed(() =>
|
||||
isRibRequiredForPaymentType(paymentTypeCodeOf(supplier.value?.paymentType))
|
||||
? (supplier.value?.ribs ?? []).map(mapRibToDraft)
|
||||
: [],
|
||||
)
|
||||
// Draft comptable (tout null si l'utilisateur n'a pas accounting.view).
|
||||
const accounting = computed(() => mapAccountingDraft(supplier.value ?? ({} as SupplierDetail)))
|
||||
|
||||
// ── Options des selects (construites depuis l'EMBED, jamais via un GET de
|
||||
// referentiel : /categories et /sites sont en 403 pour les roles metier
|
||||
// non-admin, ce qui laisserait les libelles vides). ───────────────────────
|
||||
const mainCategoryOptions = computed(() => categoryOptionsOf(supplier.value?.categories))
|
||||
const contactOptions = computed(() => contactOptionsOf(supplier.value?.contacts))
|
||||
|
||||
// Liste COMPLETE des sites disponibles, issue de /api/me (groupe me:read — donc
|
||||
// pas de 403 pour les roles metier, contrairement a GET /sites). Libelle = numero
|
||||
// de departement (2 premiers chiffres du code postal). Permet d'afficher TOUJOURS
|
||||
// toutes les cases « Sites » (86 / 17 / 82) dans le bloc adresse, meme celles non
|
||||
// rattachees a l'adresse consultee (les rattachees restent cochees via siteIris).
|
||||
const allSiteOptions = computed<SelectOption[]>(() =>
|
||||
(authStore.user?.sites ?? []).map(s => ({
|
||||
value: `/api/sites/${s.id}`,
|
||||
label: (s.postalCode ?? '').slice(0, 2),
|
||||
})),
|
||||
)
|
||||
|
||||
// Pays (consultation, lecture seule) : derive des adresses du fournisseur, comme
|
||||
// l'ecran client. Le referentiel `country` (ERP-116) n'est pas charge ici, l'ecran
|
||||
// n'affiche que les valeurs deja stockees.
|
||||
const countryOptions = computed<SelectOption[]>(() =>
|
||||
[...new Set(
|
||||
(supplier.value?.addresses ?? [])
|
||||
.map(a => a.country)
|
||||
.filter((c): c is string => !!c),
|
||||
)].map(c => ({ value: c, label: c })),
|
||||
)
|
||||
|
||||
// Selects comptables : libelle issu de l'embed (option unique ou vide).
|
||||
const tvaModeOptions = computed(() => referentialOptionOf(supplier.value?.tvaMode))
|
||||
const paymentDelayOptions = computed(() => referentialOptionOf(supplier.value?.paymentDelay))
|
||||
const paymentTypeOptions = computed(() => referentialOptionOf(supplier.value?.paymentType))
|
||||
const bankOptions = computed(() => referentialOptionOf(supplier.value?.bank))
|
||||
|
||||
// ── Onglets : navigation LIBRE (pas de sequence forcee en consultation) ────
|
||||
// 3 onglets actifs (Information, Contacts, Adresses, + Comptabilite si droit) et
|
||||
// 4 coquilles (Transport, Statistiques, Rapports, Echanges).
|
||||
const tabKeys = computed(() => buildSupplierFormTabKeys(canAccountingView.value, { includeEditOnlyTabs: true }))
|
||||
|
||||
const TAB_ICONS: Record<string, string> = {
|
||||
information: 'mdi:account-outline',
|
||||
contacts: 'mdi:account-box-plus-outline',
|
||||
addresses: 'mdi:map-marker-outline',
|
||||
transport: 'mdi:truck-delivery-outline',
|
||||
accounting: 'mdi:bank-circle-outline',
|
||||
statistics: 'mdi:finance',
|
||||
reports: 'mdi:file-document-edit-outline',
|
||||
exchanges: 'mdi:account-group-outline',
|
||||
}
|
||||
|
||||
const tabs = computed(() => tabKeys.value.map(key => ({
|
||||
key,
|
||||
label: t(`commercial.suppliers.tab.${key}`),
|
||||
icon: TAB_ICONS[key],
|
||||
})))
|
||||
|
||||
// Onglet initial : repris de l'edition au retour (history.state), sinon Information.
|
||||
const activeTab = ref(readHistoryTab(tabKeys.value) ?? 'information')
|
||||
|
||||
// ── Navigation ─────────────────────────────────────────────────────────────
|
||||
function goBack(): void {
|
||||
router.push('/suppliers')
|
||||
}
|
||||
|
||||
/** Bascule en edition en conservant l'onglet courant (via history.state). */
|
||||
function goEdit(): void {
|
||||
router.push({ path: `/suppliers/${supplierId}/edit`, state: { tab: activeTab.value } })
|
||||
}
|
||||
|
||||
// ── Archivage / Restauration ────────────────────────────────────────────────
|
||||
const confirmOpen = ref(false)
|
||||
const toggling = ref(false)
|
||||
|
||||
function askToggleArchive(): void {
|
||||
confirmOpen.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirme l'archivage ou la restauration (PATCH isArchived seul). Gere le 409
|
||||
* de conflit d'homonyme actif a la restauration avec un message dedie.
|
||||
*/
|
||||
async function confirmToggleArchive(): Promise<void> {
|
||||
if (toggling.value) return
|
||||
toggling.value = true
|
||||
const restoring = isArchived.value
|
||||
try {
|
||||
if (restoring) {
|
||||
await restore()
|
||||
toast.success({ title: t('commercial.suppliers.toast.restoreSuccess') })
|
||||
}
|
||||
else {
|
||||
await archive()
|
||||
toast.success({ title: t('commercial.suppliers.toast.archiveSuccess') })
|
||||
}
|
||||
confirmOpen.value = false
|
||||
}
|
||||
catch (e) {
|
||||
const status = (e as { response?: { status?: number } })?.response?.status
|
||||
toast.error({
|
||||
title: t('commercial.suppliers.toast.error'),
|
||||
message: restoring && status === 409
|
||||
? t('commercial.suppliers.toast.restoreConflict')
|
||||
: t('commercial.suppliers.toast.error'),
|
||||
})
|
||||
}
|
||||
finally {
|
||||
toggling.value = false
|
||||
}
|
||||
}
|
||||
|
||||
useHead({ title: headerTitle })
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
@@ -0,0 +1,434 @@
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader>
|
||||
{{ t('commercial.suppliers.title') }}
|
||||
<template #actions>
|
||||
<!-- gap-8 = 32px d'espacement entre Filtres et Ajouter. -->
|
||||
<div class="flex items-center gap-8">
|
||||
<!-- Bouton Filtres a GAUCHE d'Ajouter. Le compteur reflete les filtres actifs. -->
|
||||
<MalioButton
|
||||
v-if="canView"
|
||||
variant="tertiary"
|
||||
:label="filterButtonLabel"
|
||||
icon-name="mdi:tune"
|
||||
icon-position="left"
|
||||
icon-size="24"
|
||||
@click="openFilters"
|
||||
/>
|
||||
<MalioButton
|
||||
v-if="canManage"
|
||||
variant="secondary"
|
||||
:label="t('commercial.suppliers.add')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@click="goToCreate"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<!-- Datatable branchee sur usePaginatedList via useSuppliersRepository :
|
||||
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 suppliers-table"
|
||||
:empty-message="t('commercial.suppliers.empty')"
|
||||
@row-click="onRowClick"
|
||||
@update:page="goToPage"
|
||||
@update:per-page="setItemsPerPage"
|
||||
>
|
||||
<!-- Categories : libelles (name) separes par une virgule (spec M2). -->
|
||||
<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 SupplierSite[])"
|
||||
:key="site.id"
|
||||
class="inline-flex items-center rounded-full px-2 py-0.5 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-4">
|
||||
<MalioButton
|
||||
v-if="canView"
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.export')"
|
||||
:disabled="exporting"
|
||||
@click="exportXlsx"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Drawer de filtres : etat BROUILLON, applique uniquement au clic sur
|
||||
« Appliquer ». Meme pattern que le repertoire clients. Etat 100 % local,
|
||||
jamais dans l'URL (regle ABSOLUE n°6). -->
|
||||
<MalioDrawer
|
||||
v-model="filterDrawerOpen"
|
||||
drawer-class="max-w-[450px]"
|
||||
body-class="p-0"
|
||||
footer-class="justify-between border-t border-black p-6"
|
||||
>
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold uppercase">{{ t('commercial.suppliers.filters.title') }}</h2>
|
||||
</template>
|
||||
|
||||
<MalioAccordion>
|
||||
<!-- Recherche : nom societe + contact + email (param `search`, decision D1). -->
|
||||
<MalioAccordionItem :title="t('commercial.suppliers.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.suppliers.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.suppliers.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 = inclut aussi les archives (sinon actifs seuls). -->
|
||||
<MalioAccordionItem :title="t('commercial.suppliers.filters.status')" value="status">
|
||||
<MalioCheckbox
|
||||
id="filter-include-archived"
|
||||
:label="t('commercial.suppliers.filters.includeArchived')"
|
||||
:model-value="draftIncludeArchived"
|
||||
@update:model-value="(val: boolean) => draftIncludeArchived = val"
|
||||
/>
|
||||
</MalioAccordionItem>
|
||||
</MalioAccordion>
|
||||
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="tertiary"
|
||||
:label="t('commercial.suppliers.filters.reset')"
|
||||
button-class="w-m-btn-action"
|
||||
@click="resetFilters"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.filters.apply')"
|
||||
button-class="w-[170px]"
|
||||
@click="applyFilters"
|
||||
/>
|
||||
</template>
|
||||
</MalioDrawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import type { Supplier, SupplierSite } from '~/modules/commercial/composables/useSuppliersRepository'
|
||||
|
||||
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.suppliers.title') })
|
||||
|
||||
// Bouton « Ajouter » reserve a `manage` (POST /suppliers garde manage seul →
|
||||
// Compta / Usine ne creent pas). « Exporter » et « Filtres » suivent `view`.
|
||||
const canManage = computed(() => can('commercial.suppliers.manage'))
|
||||
const canView = computed(() => can('commercial.suppliers.view'))
|
||||
|
||||
const {
|
||||
items: suppliers,
|
||||
totalItems,
|
||||
currentPage,
|
||||
itemsPerPage,
|
||||
itemsPerPageOptions,
|
||||
fetch: loadSuppliers,
|
||||
goToPage,
|
||||
setItemsPerPage,
|
||||
setFilters,
|
||||
} = useSuppliersRepository()
|
||||
|
||||
// Mappe les fournisseurs en objets « plats » pour MalioDataTable (items typees
|
||||
// Record<string, unknown>[]) : un objet litteral porte une signature d'index
|
||||
// implicite, contrairement a l'interface Supplier. Meme pattern que clients.
|
||||
const rows = computed(() => suppliers.value.map(supplier => ({
|
||||
id: supplier.id,
|
||||
companyName: supplier.companyName,
|
||||
categories: supplier.categories,
|
||||
sites: supplier.sites,
|
||||
updatedAt: supplier.updatedAt,
|
||||
})))
|
||||
|
||||
const columns = [
|
||||
{ key: 'companyName', label: t('commercial.suppliers.column.companyName') },
|
||||
{ key: 'categories', label: t('commercial.suppliers.column.categories') },
|
||||
{ key: 'sites', label: t('commercial.suppliers.column.sites') },
|
||||
{ key: 'lastActivity', label: t('commercial.suppliers.column.lastActivity') },
|
||||
]
|
||||
|
||||
/** Libelles des categories du fournisseur, separes par une virgule (spec M2 : name). */
|
||||
function formatCategories(item: Record<string, unknown>): string {
|
||||
const categories = (item.categories as Supplier['categories']) ?? []
|
||||
return categories.map(c => c.name).join(', ')
|
||||
}
|
||||
|
||||
/**
|
||||
* Derniere activite : faute de suivi d'activite metier au M2, 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 /suppliers/{id}). */
|
||||
function onRowClick(item: Record<string, unknown>): void {
|
||||
router.push(`/suppliers/${item.id}`)
|
||||
}
|
||||
|
||||
function goToCreate(): void {
|
||||
router.push('/suppliers/new')
|
||||
}
|
||||
|
||||
// ── Filtres (drawer) ────────────────────────────────────────────────────────
|
||||
// Deux niveaux d'etat (pattern repertoire clients) :
|
||||
// - 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 draftIncludeArchived = ref(false)
|
||||
|
||||
const appliedSearch = ref('')
|
||||
const appliedCategoryCodes = ref<string[]>([])
|
||||
const appliedSiteIds = ref<string[]>([])
|
||||
const appliedIncludeArchived = 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 (appliedIncludeArchived.value) count++
|
||||
return count
|
||||
})
|
||||
|
||||
const filterButtonLabel = computed(() => {
|
||||
const base = t('commercial.suppliers.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]
|
||||
draftIncludeArchived.value = appliedIncludeArchived.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 (appliedIncludeArchived.value) payload.includeArchived = 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]
|
||||
appliedIncludeArchived.value = draftIncludeArchived.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 = []
|
||||
draftIncludeArchived.value = false
|
||||
|
||||
appliedSearch.value = ''
|
||||
appliedCategoryCodes.value = []
|
||||
appliedSiteIds.value = []
|
||||
appliedIncludeArchived.value = false
|
||||
|
||||
setFilters({}, { replace: true })
|
||||
}
|
||||
|
||||
/** Charge les referentiels du drawer (categories FOURNISSEUR + sites) via ?pagination=false. */
|
||||
async function loadFilterOptions(): Promise<void> {
|
||||
const [cats, sites] = await Promise.all([
|
||||
api.get<{ member?: Array<{ code: string, name: string }> }>(
|
||||
'/categories',
|
||||
// Taxonomie multi-types (ERP-84) : le filtre du repertoire fournisseurs
|
||||
// ne propose que les categories de type FOURNISSEUR (pas les CLIENT).
|
||||
{ pagination: 'false', typeCode: 'FOURNISSEUR' },
|
||||
{ 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>('/suppliers/export.xlsx', buildFilterPayload(), {
|
||||
responseType: 'blob',
|
||||
toast: false,
|
||||
} as unknown as Parameters<typeof api.get>[2])
|
||||
|
||||
triggerDownload(blob, 'repertoire-fournisseurs.xlsx')
|
||||
}
|
||||
catch {
|
||||
toast.error({
|
||||
title: t('commercial.suppliers.toast.error'),
|
||||
message: t('commercial.suppliers.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(() => {
|
||||
loadSuppliers()
|
||||
// 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>
|
||||
|
||||
<style scoped>
|
||||
/*
|
||||
* Colonne Sites uniquement (3e colonne : companyName, categories, SITES,
|
||||
* lastActivity) : ses badges rendent la cellule trop haute. On reduit le padding
|
||||
* vertical de SON td (16px Malio -> 8px) sans toucher les autres colonnes ni les
|
||||
* couleurs/tailles (qui restent sur les defauts Malio).
|
||||
*/
|
||||
:deep(.suppliers-table tbody td:nth-child(3)) {
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,876 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tete : retour vers le repertoire + titre. -->
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
variant="ghost"
|
||||
v-bind="{ ariaLabel: t('commercial.suppliers.form.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ t('commercial.suppliers.form.title') }}</h1>
|
||||
</div>
|
||||
|
||||
<!-- ── Formulaire principal (pre-onglets) ─────────────────────────────
|
||||
Sans validation de ce bloc, les onglets restent inaccessibles. Au
|
||||
succes du POST, les champs passent en lecture seule et on bascule
|
||||
automatiquement sur l'onglet Information. Pas de contact inline (ERP-106). -->
|
||||
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
v-model="main.companyName"
|
||||
:label="t('commercial.suppliers.form.main.companyName')"
|
||||
:required="true"
|
||||
:readonly="mainLocked"
|
||||
:error="mainErrors.errors.companyName"
|
||||
/>
|
||||
<MalioSelectCheckbox
|
||||
:model-value="main.categoryIris"
|
||||
:options="referentials.categories.value"
|
||||
:label="t('commercial.suppliers.form.main.categories')"
|
||||
:display-tag="true"
|
||||
:readonly="mainLocked"
|
||||
:required="true"
|
||||
:error="mainErrors.errors.categories"
|
||||
@update:model-value="(v: (string | number)[]) => main.categoryIris = v.map(String)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="!mainLocked" class="mt-12 flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.form.submit')"
|
||||
:disabled="mainSubmitting"
|
||||
@click="submitMain"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ── Onglets a validation incrementale ─────────────────────────────-->
|
||||
<MalioTabList v-model="activeTab" :tabs="tabs" class="mt-[60px]">
|
||||
<!-- Onglet Information -->
|
||||
<template #information>
|
||||
<div class="mt-12 grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<MalioInputTextArea
|
||||
v-model="information.description"
|
||||
:label="t('commercial.suppliers.form.information.description')"
|
||||
resize="none"
|
||||
group-class="row-span-2 pt-1 pb-1"
|
||||
text-input="h-full text-lg"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.description"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="information.competitors"
|
||||
:label="t('commercial.suppliers.form.information.competitors')"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.competitors"
|
||||
/>
|
||||
<MalioDate
|
||||
v-model="information.foundedAt"
|
||||
:label="t('commercial.suppliers.form.information.foundedAt')"
|
||||
:readonly="isValidated('information')"
|
||||
:editable="true"
|
||||
:error="informationErrors.errors.foundedAt"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="information.employeesCount"
|
||||
:label="t('commercial.suppliers.form.information.employeesCount')"
|
||||
:mask="EMPLOYEES_MASK"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.employeesCount"
|
||||
/>
|
||||
<MalioInputAmount
|
||||
v-model="information.revenueAmount"
|
||||
:label="t('commercial.suppliers.form.information.revenueAmount')"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.revenueAmount"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="information.directorName"
|
||||
:label="t('commercial.suppliers.form.information.directorName')"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.directorName"
|
||||
/>
|
||||
<MalioInputAmount
|
||||
v-model="information.profitAmount"
|
||||
:label="t('commercial.suppliers.form.information.profitAmount')"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.profitAmount"
|
||||
/>
|
||||
<!-- Volume previsionnel : specifique fournisseur. Champ texte
|
||||
masque (chiffres uniquement) ; l'entier est resolu au PATCH. -->
|
||||
<MalioInputText
|
||||
v-model="information.volumeForecast"
|
||||
:label="t('commercial.suppliers.form.information.volumeForecast')"
|
||||
:mask="VOLUME_FORECAST_MASK"
|
||||
:readonly="isValidated('information')"
|
||||
:error="informationErrors.errors.volumeForecast"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="!isValidated('information')" class="mt-12 flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.form.submit')"
|
||||
:disabled="tabSubmitting || supplierId === null"
|
||||
@click="submitInformation"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Contacts -->
|
||||
<template #contacts>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<SupplierContactBlock
|
||||
v-for="(contact, index) in contacts"
|
||||
:key="index"
|
||||
:model-value="contact"
|
||||
:title="t('commercial.suppliers.form.contact.title', { n: index + 1 })"
|
||||
:removable="index > 0"
|
||||
:readonly="isValidated('contacts')"
|
||||
:errors="contactErrors[index]"
|
||||
@update:model-value="(v) => contacts[index] = v"
|
||||
@remove="askRemoveContact(index)"
|
||||
/>
|
||||
<div v-if="!isValidated('contacts')" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.form.contact.add')"
|
||||
:disabled="!canAddContact"
|
||||
@click="addContact"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.form.submit')"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitContacts"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Adresses -->
|
||||
<template #addresses>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<SupplierAddressBlock
|
||||
v-for="(address, index) in addresses"
|
||||
:key="index"
|
||||
:model-value="address"
|
||||
:title="t('commercial.suppliers.form.address.title', { n: index + 1 })"
|
||||
:category-options="referentials.categories.value"
|
||||
:site-options="referentials.sites.value"
|
||||
:contact-options="contactOptions"
|
||||
:country-options="countryOptions"
|
||||
:removable="index > 0"
|
||||
:readonly="isValidated('addresses')"
|
||||
:errors="addressErrors[index]"
|
||||
@update:model-value="(v) => addresses[index] = v"
|
||||
@remove="askRemoveAddress(index)"
|
||||
@degraded="onAddressDegraded"
|
||||
/>
|
||||
<div v-if="!isValidated('addresses')" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.form.address.add')"
|
||||
:disabled="!canAddAddress"
|
||||
@click="addAddress"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.form.submit')"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAddresses"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet Comptabilite (present uniquement si accounting.view) -->
|
||||
<template v-if="canAccountingView" #accounting>
|
||||
<div class="mt-12 flex flex-col gap-6">
|
||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
v-model="accounting.siren"
|
||||
:label="t('commercial.suppliers.form.accounting.siren')"
|
||||
:mask="SIREN_MASK"
|
||||
:readonly="accountingReadonly"
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.siren"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="accounting.accountNumber"
|
||||
:label="t('commercial.suppliers.form.accounting.accountNumber')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.accountNumber"
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.tvaModeIri"
|
||||
:options="referentials.tvaModes.value"
|
||||
:label="t('commercial.suppliers.form.accounting.tvaMode')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.tvaMode"
|
||||
@update:model-value="(v: string | number | null) => accounting.tvaModeIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="accounting.nTva"
|
||||
:label="t('commercial.suppliers.form.accounting.nTva')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.nTva"
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.paymentDelayIri"
|
||||
:options="referentials.paymentDelays.value"
|
||||
:label="t('commercial.suppliers.form.accounting.paymentDelay')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.paymentDelay"
|
||||
@update:model-value="(v: string | number | null) => accounting.paymentDelayIri = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioSelect
|
||||
:model-value="accounting.paymentTypeIri"
|
||||
:options="referentials.paymentTypes.value"
|
||||
:label="t('commercial.suppliers.form.accounting.paymentType')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.paymentType"
|
||||
@update:model-value="onPaymentTypeChange"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="isBankRequired"
|
||||
:model-value="accounting.bankIri"
|
||||
:options="referentials.banks.value"
|
||||
:label="t('commercial.suppliers.form.accounting.bank')"
|
||||
:readonly="accountingReadonly"
|
||||
empty-option-label=""
|
||||
:required="true"
|
||||
:error="accountingErrors.errors.bank"
|
||||
@update:model-value="(v: string | number | null) => accounting.bankIri = v === null ? null : String(v)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Blocs RIB — affiches uniquement si type de reglement = LCR (RG-2.08). -->
|
||||
<div
|
||||
v-for="(rib, index) in visibleRibs"
|
||||
:key="index"
|
||||
class="relative bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]"
|
||||
>
|
||||
<MalioButtonIcon
|
||||
v-if="!accountingReadonly && visibleRibs.length > 1"
|
||||
icon="mdi:delete-outline"
|
||||
variant="ghost"
|
||||
button-class="absolute top-3 right-3"
|
||||
v-bind="{ ariaLabel: t('commercial.suppliers.form.accounting.removeRib') }"
|
||||
@click="askRemoveRib(index)"
|
||||
/>
|
||||
<div class="grid grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioInputText
|
||||
v-model="rib.label"
|
||||
:label="t('commercial.suppliers.form.accounting.ribLabel')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="isRibRequired"
|
||||
:error="ribErrors[index]?.label"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="rib.bic"
|
||||
:label="t('commercial.suppliers.form.accounting.ribBic')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="isRibRequired"
|
||||
:error="ribErrors[index]?.bic"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="rib.iban"
|
||||
:label="t('commercial.suppliers.form.accounting.ribIban')"
|
||||
:readonly="accountingReadonly"
|
||||
:required="isRibRequired"
|
||||
:error="ribErrors[index]?.iban"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!accountingReadonly" class="flex justify-center gap-6">
|
||||
<MalioButton
|
||||
v-if="isRibRequired"
|
||||
variant="secondary"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
:label="t('commercial.suppliers.form.accounting.addRib')"
|
||||
:disabled="!canAddRib"
|
||||
@click="addRib"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('commercial.suppliers.form.submit')"
|
||||
:disabled="tabSubmitting"
|
||||
@click="submitAccounting"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Onglet placeholder : frame vide, passage automatique. -->
|
||||
<template #transport><ComingSoonPlaceholder /></template>
|
||||
</MalioTabList>
|
||||
|
||||
<!-- Modal de confirmation generique (suppression contact/adresse/RIB). -->
|
||||
<MalioModal v-model="confirmModal.open" modal-class="max-w-md">
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold">{{ t('commercial.suppliers.form.confirmDelete.title') }}</h2>
|
||||
</template>
|
||||
<p>{{ confirmModal.message }}</p>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
button-class="flex-1"
|
||||
:label="t('commercial.suppliers.form.confirmDelete.cancel')"
|
||||
@click="confirmModal.open = false"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="danger"
|
||||
button-class="flex-1"
|
||||
:label="t('commercial.suppliers.form.confirmDelete.confirm')"
|
||||
@click="runConfirm"
|
||||
/>
|
||||
</template>
|
||||
</MalioModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useSupplierReferentials, type RefOption } from '~/modules/commercial/composables/useSupplierReferentials'
|
||||
import { useSupplierFormErrors } from '~/modules/commercial/composables/useSupplierFormErrors'
|
||||
import {
|
||||
buildSupplierFormTabKeys,
|
||||
SUPPLIER_FORM_PLACEHOLDER_TABS,
|
||||
isAddressValid,
|
||||
isBankRequiredForPaymentType,
|
||||
isContactBlank,
|
||||
isContactNamed,
|
||||
isRibBlank,
|
||||
isRibComplete,
|
||||
isRibRequiredForPaymentType,
|
||||
lastFillableTabKey,
|
||||
} from '~/modules/commercial/utils/supplierFormRules'
|
||||
import {
|
||||
buildAccountingPayload,
|
||||
buildAddressPayload,
|
||||
buildContactPayload,
|
||||
buildInformationPayload,
|
||||
buildMainPayload,
|
||||
buildRibPayload,
|
||||
} from '~/modules/commercial/utils/supplierEdit'
|
||||
import {
|
||||
emptyAddress,
|
||||
emptyContact,
|
||||
emptyRib,
|
||||
type SupplierAddressFormDraft,
|
||||
type SupplierContactFormDraft,
|
||||
type SupplierRibFormDraft,
|
||||
} from '~/modules/commercial/types/supplierForm'
|
||||
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||
|
||||
// Masques de saisie (la normalisation finale reste serveur).
|
||||
const SIREN_MASK = '#########'
|
||||
const EMPLOYEES_MASK = '#######'
|
||||
// Volume previsionnel : champ texte borne aux chiffres (entier >= 0 cote back).
|
||||
const VOLUME_FORECAST_MASK = '##########'
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const toast = useToast()
|
||||
const router = useRouter()
|
||||
const { can } = usePermissions()
|
||||
|
||||
/** Retour vers le repertoire fournisseurs (fleche d'en-tete). */
|
||||
function goBack(): void {
|
||||
router.push('/suppliers')
|
||||
}
|
||||
|
||||
/**
|
||||
* Message d'erreur a afficher dans un toast a partir d'une erreur d'API. Retourne
|
||||
* TOUJOURS une chaine (le composant de toast plante sur `undefined`).
|
||||
*/
|
||||
function apiErrorMessage(error: unknown): string {
|
||||
const data = (error as { data?: unknown })?.data
|
||||
return extractApiErrorMessage(data) || t('commercial.suppliers.toast.error')
|
||||
}
|
||||
|
||||
// ── Erreurs de validation par champ (ERP-101) ───────────────────────────────
|
||||
const {
|
||||
mainErrors,
|
||||
informationErrors,
|
||||
accountingErrors,
|
||||
contactErrors,
|
||||
addressErrors,
|
||||
ribErrors,
|
||||
submitRows,
|
||||
} = useSupplierFormErrors()
|
||||
|
||||
useHead({ title: t('commercial.suppliers.form.title') })
|
||||
|
||||
// Gating de la route : la creation est reservee a `manage`. Compta (accounting
|
||||
// seul) et Usine sont rediriges vers le repertoire.
|
||||
if (!can('commercial.suppliers.manage')) {
|
||||
await navigateTo('/suppliers')
|
||||
}
|
||||
|
||||
const canAccountingView = computed(() => can('commercial.suppliers.accounting.view'))
|
||||
const canAccountingManage = computed(() => can('commercial.suppliers.accounting.manage'))
|
||||
|
||||
const referentials = useSupplierReferentials()
|
||||
|
||||
// ── Etat du fournisseur cree ────────────────────────────────────────────────
|
||||
const supplierId = ref<number | null>(null)
|
||||
const mainLocked = ref(false)
|
||||
const mainSubmitting = ref(false)
|
||||
const tabSubmitting = ref(false)
|
||||
|
||||
// ── Formulaire principal ────────────────────────────────────────────────────
|
||||
const main = reactive({
|
||||
companyName: null as string | null,
|
||||
categoryIris: [] as string[],
|
||||
})
|
||||
|
||||
/** POST /suppliers (groupe supplier:write:main). Au succes : verrouille + bascule Information. */
|
||||
async function submitMain(): Promise<void> {
|
||||
if (mainSubmitting.value) return
|
||||
mainSubmitting.value = true
|
||||
mainErrors.clearErrors()
|
||||
try {
|
||||
const created = await api.post<SupplierResponse>('/suppliers', buildMainPayload(main), {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
|
||||
supplierId.value = created.id
|
||||
// Reaffiche la valeur normalisee renvoyee par le serveur (UPPERCASE, RG-2.12).
|
||||
main.companyName = created.companyName ?? main.companyName
|
||||
|
||||
mainLocked.value = true
|
||||
// Information est facultatif : on deverrouille jusqu'a Contacts (index 1).
|
||||
unlockedIndex.value = tabIndex('contacts')
|
||||
activeTab.value = 'information'
|
||||
toast.success({ title: t('commercial.suppliers.toast.createSuccess') })
|
||||
}
|
||||
catch (error) {
|
||||
// 409 = doublon nom de societe (RG d'unicite) → erreur inline + toast ;
|
||||
// 422 → mapping inline par champ ; autre → toast de fallback (ERP-101).
|
||||
const status = (error as { response?: { status?: number } })?.response?.status
|
||||
if (status === 409) {
|
||||
const message = t('commercial.suppliers.form.duplicateCompany')
|
||||
mainErrors.setError('companyName', message)
|
||||
toast.error({ title: t('commercial.suppliers.toast.error'), message })
|
||||
}
|
||||
else {
|
||||
mainErrors.handleApiError(error, { fallbackMessage: t('commercial.suppliers.toast.error') })
|
||||
}
|
||||
}
|
||||
finally {
|
||||
mainSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglets : ordre + gating progressif ─────────────────────────────────────
|
||||
const activeTab = ref('information')
|
||||
// Index du dernier onglet deverrouille (-1 tant que le fournisseur n'est pas cree).
|
||||
const unlockedIndex = ref(-1)
|
||||
// Onglets valides (passent en lecture seule).
|
||||
const validated = reactive<Record<string, boolean>>({})
|
||||
|
||||
const tabKeys = computed(() => buildSupplierFormTabKeys(canAccountingView.value))
|
||||
|
||||
// Dernier onglet REMPLISSABLE par le role : sa validation cloture l'ajout.
|
||||
const lastFillableTab = computed(() => lastFillableTabKey(tabKeys.value))
|
||||
|
||||
// Icone (Iconify) affichee dans l'onglet, par cle.
|
||||
const TAB_ICONS: Record<string, string> = {
|
||||
information: 'mdi:account-outline',
|
||||
contacts: 'mdi:account-box-plus-outline',
|
||||
addresses: 'mdi:map-marker-outline',
|
||||
transport: 'mdi:truck-delivery-outline',
|
||||
accounting: 'mdi:bank-circle-outline',
|
||||
}
|
||||
|
||||
const tabs = computed(() => tabKeys.value.map((key, index) => ({
|
||||
key,
|
||||
label: t(`commercial.suppliers.tab.${key}`),
|
||||
icon: TAB_ICONS[key],
|
||||
disabled: index > unlockedIndex.value,
|
||||
})))
|
||||
|
||||
function isValidated(key: string): boolean {
|
||||
return validated[key] === true
|
||||
}
|
||||
|
||||
function tabIndex(key: string): number {
|
||||
return tabKeys.value.indexOf(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* Marque l'onglet valide. Si c'est le dernier onglet remplissable, l'ajout est
|
||||
* termine : toast final + redirection vers la liste, et on retourne true. Sinon,
|
||||
* deverrouille et avance a l'onglet suivant, et retourne false.
|
||||
*/
|
||||
function completeTab(key: string): boolean {
|
||||
validated[key] = true
|
||||
if (key === lastFillableTab.value) {
|
||||
toast.success({ title: t('commercial.suppliers.toast.addComplete') })
|
||||
router.push('/suppliers')
|
||||
return true
|
||||
}
|
||||
const next = tabKeys.value[tabIndex(key) + 1]
|
||||
unlockedIndex.value = Math.max(unlockedIndex.value, tabIndex(key) + 1)
|
||||
if (next) activeTab.value = next
|
||||
return false
|
||||
}
|
||||
|
||||
// Passage automatique sur les onglets coquille (Transport).
|
||||
watch(activeTab, (key) => {
|
||||
if ((SUPPLIER_FORM_PLACEHOLDER_TABS as readonly string[]).includes(key)) {
|
||||
const next = tabKeys.value[tabIndex(key) + 1]
|
||||
unlockedIndex.value = Math.max(unlockedIndex.value, tabIndex(key) + 1)
|
||||
if (next) activeTab.value = next
|
||||
}
|
||||
})
|
||||
|
||||
// ── Onglet Information ──────────────────────────────────────────────────────
|
||||
const information = reactive({
|
||||
description: null as string | null,
|
||||
competitors: null as string | null,
|
||||
foundedAt: null as string | null,
|
||||
employeesCount: null as string | null,
|
||||
revenueAmount: null as string | null,
|
||||
profitAmount: null as string | null,
|
||||
directorName: null as string | null,
|
||||
volumeForecast: null as string | null,
|
||||
})
|
||||
|
||||
/** PATCH /suppliers/{id} — mode strict : uniquement les champs du groupe information. */
|
||||
async function submitInformation(): Promise<void> {
|
||||
if (supplierId.value === null || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
informationErrors.clearErrors()
|
||||
try {
|
||||
await api.patch(`/suppliers/${supplierId.value}`, buildInformationPayload(information), { toast: false })
|
||||
if (completeTab('information')) return
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
catch (error) {
|
||||
informationErrors.handleApiError(error, { fallbackMessage: t('commercial.suppliers.toast.error') })
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglet Contacts ─────────────────────────────────────────────────────────
|
||||
const contacts = ref<SupplierContactFormDraft[]>([emptyContact()])
|
||||
|
||||
// « + Nouveau contact » desactive tant que le dernier bloc n'a ni nom ni prenom.
|
||||
const canAddContact = computed(() => {
|
||||
const last = contacts.value[contacts.value.length - 1]
|
||||
return last !== undefined && isContactNamed(last)
|
||||
})
|
||||
|
||||
function addContact(): void {
|
||||
if (canAddContact.value) contacts.value.push(emptyContact())
|
||||
}
|
||||
|
||||
function askRemoveContact(index: number): void {
|
||||
askConfirm(t('commercial.suppliers.form.confirmDelete.contact'), () => {
|
||||
contacts.value.splice(index, 1)
|
||||
contactErrors.value.splice(index, 1)
|
||||
})
|
||||
}
|
||||
|
||||
/** POST/PATCH des contacts sur la sous-ressource /suppliers/{id}/contacts. */
|
||||
async function submitContacts(): Promise<void> {
|
||||
if (supplierId.value === null || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
try {
|
||||
// RG-2.13 : au moins un contact requis. Si l'onglet ne contient QUE des
|
||||
// amorces vides, on les soumet pour declencher la 422 RG-2.04 inline.
|
||||
const hasSubmittableContact = contacts.value.some(c => c.id !== null || !isContactBlank(c))
|
||||
const hasError = await submitRows(
|
||||
contacts.value,
|
||||
contactErrors,
|
||||
async (contact) => {
|
||||
const body = buildContactPayload(contact)
|
||||
if (contact.id === null) {
|
||||
const created = await api.post<ContactResponse>(
|
||||
`/suppliers/${supplierId.value}/contacts`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
contact.id = created.id
|
||||
contact.iri = created['@id'] ?? null
|
||||
}
|
||||
else {
|
||||
await api.patch(`/supplier_contacts/${contact.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => toast.error({ title: t('commercial.suppliers.toast.error'), message: apiErrorMessage(error) }),
|
||||
contact => hasSubmittableContact && contact.id === null && isContactBlank(contact),
|
||||
)
|
||||
if (hasError) return
|
||||
if (completeTab('contacts')) return
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglet Adresses ─────────────────────────────────────────────────────────
|
||||
const addresses = ref<SupplierAddressFormDraft[]>([emptyAddress()])
|
||||
const addressDegradedNotified = ref(false)
|
||||
|
||||
// Contacts deja crees, rattachables a une adresse (M2M, via leur IRI).
|
||||
const contactOptions = computed<RefOption[]>(() =>
|
||||
contacts.value
|
||||
.filter(c => c.iri !== null)
|
||||
.map(c => ({
|
||||
value: c.iri as string,
|
||||
label: [c.firstName, c.lastName].filter(Boolean).join(' ') || (c.email ?? ''),
|
||||
})),
|
||||
)
|
||||
|
||||
// Pays : referentiel `country` charge via l'API (ERP-116), aligne sur l'ecran
|
||||
// client. France garantie en tete pour rester preselectionnable par defaut sur
|
||||
// chaque adresse meme si `/countries` echoue (resilience ERP-102).
|
||||
const countryOptions = computed<RefOption[]>(() => {
|
||||
const list = referentials.countries.value
|
||||
return list.some(c => c.value === 'France')
|
||||
? list
|
||||
: [{ value: 'France', label: 'France' }, ...list]
|
||||
})
|
||||
|
||||
// « + Adresse » desactive tant que la derniere adresse n'est pas valide.
|
||||
const canAddAddress = computed(() => {
|
||||
const last = addresses.value[addresses.value.length - 1]
|
||||
return last !== undefined && isAddressValid(last)
|
||||
})
|
||||
|
||||
function addAddress(): void {
|
||||
if (canAddAddress.value) addresses.value.push(emptyAddress())
|
||||
}
|
||||
|
||||
function askRemoveAddress(index: number): void {
|
||||
askConfirm(t('commercial.suppliers.form.confirmDelete.address'), () => {
|
||||
addresses.value.splice(index, 1)
|
||||
addressErrors.value.splice(index, 1)
|
||||
})
|
||||
}
|
||||
|
||||
/** Avertit une seule fois quand l'autocompletion d'adresse bascule en degrade. */
|
||||
function onAddressDegraded(): void {
|
||||
if (addressDegradedNotified.value) return
|
||||
addressDegradedNotified.value = true
|
||||
toast.warning({
|
||||
title: t('commercial.suppliers.toast.error'),
|
||||
message: t('commercial.suppliers.form.address.degraded'),
|
||||
})
|
||||
}
|
||||
|
||||
/** POST/PATCH des adresses sur la sous-ressource /suppliers/{id}/addresses. */
|
||||
async function submitAddresses(): Promise<void> {
|
||||
if (supplierId.value === null || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
try {
|
||||
const hasError = await submitRows(
|
||||
addresses.value,
|
||||
addressErrors,
|
||||
async (address) => {
|
||||
const body = buildAddressPayload(address)
|
||||
if (address.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/suppliers/${supplierId.value}/addresses`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
address.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/supplier_addresses/${address.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => toast.error({ title: t('commercial.suppliers.toast.error'), message: apiErrorMessage(error) }),
|
||||
)
|
||||
if (hasError) return
|
||||
if (completeTab('addresses')) return
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Onglet Comptabilite ─────────────────────────────────────────────────────
|
||||
const accounting = reactive({
|
||||
siren: null as string | null,
|
||||
accountNumber: null as string | null,
|
||||
tvaModeIri: null as string | null,
|
||||
nTva: null as string | null,
|
||||
paymentDelayIri: null as string | null,
|
||||
paymentTypeIri: null as string | null,
|
||||
bankIri: null as string | null,
|
||||
})
|
||||
const ribs = ref<SupplierRibFormDraft[]>([])
|
||||
|
||||
// L'onglet est editable seulement avec accounting.manage (sinon lecture seule).
|
||||
const accountingReadonly = computed(() => isValidated('accounting') || !canAccountingManage.value)
|
||||
|
||||
// Code du type de reglement selectionne (pour RG-2.07 / RG-2.08).
|
||||
const selectedPaymentTypeCode = computed(() =>
|
||||
referentials.paymentTypes.value.find(p => p.value === accounting.paymentTypeIri)?.code ?? null,
|
||||
)
|
||||
const isBankRequired = computed(() => isBankRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
const isRibRequired = computed(() => isRibRequiredForPaymentType(selectedPaymentTypeCode.value))
|
||||
|
||||
// Les blocs RIB ne sont affiches que pour une LCR (RG-2.08).
|
||||
const visibleRibs = computed(() => isRibRequired.value ? ribs.value : [])
|
||||
|
||||
function onPaymentTypeChange(value: string | number | null): void {
|
||||
accounting.paymentTypeIri = value === null ? null : String(value)
|
||||
// La banque n'a de sens que pour un virement : on la vide sinon (RG-2.07).
|
||||
if (!isBankRequired.value) accounting.bankIri = null
|
||||
// ERP-121 : on ne jette plus la saisie RIB au passage hors-LCR. Les blocs sont
|
||||
// masques (visibleRibs = []) mais conserves, et reapparaissent si l'on repasse
|
||||
// en LCR. Ils ne sont persistes qu'a la validation SOUS LCR (cf. submitAccounting),
|
||||
// donc une saisie abandonnee hors-LCR ne cree aucun RIB orphelin.
|
||||
if (isRibRequired.value) {
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
}
|
||||
else {
|
||||
ribErrors.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// « + RIB » desactive tant que le dernier bloc RIB n'est pas complet.
|
||||
const canAddRib = computed(() => {
|
||||
const last = ribs.value[ribs.value.length - 1]
|
||||
return last !== undefined && isRibComplete(last)
|
||||
})
|
||||
|
||||
function addRib(): void {
|
||||
if (canAddRib.value) ribs.value.push(emptyRib())
|
||||
}
|
||||
|
||||
function askRemoveRib(index: number): void {
|
||||
askConfirm(t('commercial.suppliers.form.confirmDelete.rib'), () => {
|
||||
ribs.value.splice(index, 1)
|
||||
ribErrors.value.splice(index, 1)
|
||||
// Garde au moins un bloc RIB visible.
|
||||
if (ribs.value.length === 0) ribs.value.push(emptyRib())
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Valide l'onglet Comptabilite : POST/PATCH des RIB sur /suppliers/{id}/ribs PUIS
|
||||
* PATCH des scalaires (groupe supplier:write:accounting). Les RIB d'abord : le back
|
||||
* valide RG-2.08 (LCR => au moins un RIB persiste) sur le PATCH scalaires, les RIB
|
||||
* doivent donc exister en base AVANT. Deux appels distincts (mode strict).
|
||||
*/
|
||||
async function submitAccounting(): Promise<void> {
|
||||
if (supplierId.value === null || tabSubmitting.value) return
|
||||
tabSubmitting.value = true
|
||||
accountingErrors.clearErrors()
|
||||
try {
|
||||
// 1) POST/PATCH des RIB d'abord — UNIQUEMENT sous LCR (erreurs inline par
|
||||
// ligne). Hors-LCR (ERP-121), une saisie RIB eventuellement restee dans le
|
||||
// brouillon est masquee et n'est PAS persistee (pas de RIB orphelin sur un
|
||||
// fournisseur en virement). On ne saute une amorce neuve vide QUE s'il reste
|
||||
// un autre RIB soumettable : sinon (LCR sans aucun RIB rempli) on la soumet
|
||||
// pour declencher la 422 NotBlank inline.
|
||||
if (isRibRequired.value) {
|
||||
const hasSubmittableRib = ribs.value.some(r => r.id !== null || !isRibBlank(r))
|
||||
const ribHasError = await submitRows(
|
||||
ribs.value,
|
||||
ribErrors,
|
||||
async (rib) => {
|
||||
const body = buildRibPayload(rib)
|
||||
if (rib.id === null) {
|
||||
const created = await api.post<{ id: number }>(
|
||||
`/suppliers/${supplierId.value}/ribs`,
|
||||
body,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
rib.id = created.id
|
||||
}
|
||||
else {
|
||||
await api.patch(`/supplier_ribs/${rib.id}`, body, { toast: false })
|
||||
}
|
||||
},
|
||||
error => toast.error({ title: t('commercial.suppliers.toast.error'), message: apiErrorMessage(error) }),
|
||||
rib => hasSubmittableRib && rib.id === null && isRibBlank(rib),
|
||||
)
|
||||
if (ribHasError) return
|
||||
}
|
||||
|
||||
// 2) PATCH des scalaires comptables (erreurs inline sur leurs champs).
|
||||
try {
|
||||
await api.patch(
|
||||
`/suppliers/${supplierId.value}`,
|
||||
buildAccountingPayload(accounting, isBankRequired.value),
|
||||
{ toast: false },
|
||||
)
|
||||
}
|
||||
catch (error) {
|
||||
accountingErrors.handleApiError(error, { fallbackMessage: t('commercial.suppliers.toast.error') })
|
||||
return
|
||||
}
|
||||
|
||||
if (completeTab('accounting')) return
|
||||
toast.success({ title: t('commercial.suppliers.toast.updateSuccess') })
|
||||
}
|
||||
finally {
|
||||
tabSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Modal de confirmation generique ─────────────────────────────────────────
|
||||
const confirmModal = reactive({
|
||||
open: false,
|
||||
message: '',
|
||||
action: null as null | (() => void),
|
||||
})
|
||||
|
||||
function askConfirm(message: string, action: () => void): void {
|
||||
confirmModal.message = message
|
||||
confirmModal.action = action
|
||||
confirmModal.open = true
|
||||
}
|
||||
|
||||
function runConfirm(): void {
|
||||
confirmModal.action?.()
|
||||
confirmModal.action = null
|
||||
confirmModal.open = false
|
||||
}
|
||||
|
||||
// ── Types de reponse API ────────────────────────────────────────────────────
|
||||
interface SupplierResponse {
|
||||
id: number
|
||||
companyName: string | null
|
||||
}
|
||||
|
||||
interface ContactResponse {
|
||||
'@id'?: string
|
||||
id: number
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// Echec du chargement des referentiels non bloquant : les selects restent vides.
|
||||
referentials.loadCommon().catch(() => {})
|
||||
})
|
||||
</script>
|
||||
@@ -30,6 +30,10 @@ export interface AddressFormDraft {
|
||||
isProspect: boolean
|
||||
isDelivery: boolean
|
||||
isBilling: boolean
|
||||
/** Adresse Courtier — type autonome exclusif. */
|
||||
isBroker: boolean
|
||||
/** Adresse Distributeur — type autonome exclusif. */
|
||||
isDistributor: boolean
|
||||
country: string
|
||||
postalCode: string | null
|
||||
city: string | null
|
||||
@@ -43,6 +47,16 @@ export interface AddressFormDraft {
|
||||
contactIris: string[]
|
||||
/** Email de facturation (obligatoire si isBilling — RG-1.11). */
|
||||
billingEmail: string | null
|
||||
/** 2e email de facturation, optionnel (max 2 — pendant du telephone secondaire). */
|
||||
billingEmailSecondary: string | null
|
||||
/** Drapeau UI : 2e champ email revele (comme hasSecondaryPhone). */
|
||||
hasSecondaryBillingEmail: boolean
|
||||
/** Latitude WGS84 (chaine decimale NUMERIC(10,7)), null si non geolocalisee (M6.1). */
|
||||
latitude: string | null
|
||||
/** Longitude WGS84 (chaine decimale NUMERIC(10,7)), null si non geolocalisee (M6.1). */
|
||||
longitude: string | null
|
||||
/** RG-6.08 : pin corrige a la main — le geocodage auto ne reecrit plus. */
|
||||
geoManual: boolean
|
||||
}
|
||||
|
||||
/** Un RIB du client (onglet Comptabilite). */
|
||||
@@ -75,6 +89,8 @@ export function emptyAddress(): AddressFormDraft {
|
||||
isProspect: false,
|
||||
isDelivery: false,
|
||||
isBilling: false,
|
||||
isBroker: false,
|
||||
isDistributor: false,
|
||||
country: 'France',
|
||||
postalCode: null,
|
||||
city: null,
|
||||
@@ -84,6 +100,11 @@ export function emptyAddress(): AddressFormDraft {
|
||||
siteIris: [],
|
||||
contactIris: [],
|
||||
billingEmail: null,
|
||||
billingEmailSecondary: null,
|
||||
hasSecondaryBillingEmail: false,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
geoManual: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Types « brouillon » de l'ecran « Ajouter un fournisseur » (M2 Commercial).
|
||||
*
|
||||
* Miroir de `types/clientForm.ts` (M1). Ces interfaces decrivent l'etat LOCAL du
|
||||
* formulaire (refs Vue), distinct des DTO de l'API : elles portent en plus des
|
||||
* champs purement UI (`hasSecondaryPhone`) et l'`iri` Hydra des entites creees
|
||||
* (necessaire pour rattacher une adresse a des contacts deja persistes, M2M).
|
||||
* Partage par la page de creation et les blocs `SupplierContactBlock` /
|
||||
* `SupplierAddressBlock` (reutilises par la consultation/modification 95/96).
|
||||
*
|
||||
* Differences M2 vs M1 (cf. spec-front § « Differences notables ») :
|
||||
* - Adresse : type via enum exclusif `addressType` (PROSPECT/DEPART/RENDU,
|
||||
* RG-2.09) — pas de drapeaux isProspect/isDelivery/isBilling.
|
||||
* - Adresse : champs specifiques fournisseur `bennes` (nombre) et
|
||||
* `triageProvider` (prestation de triage). Pas d'email de facturation.
|
||||
* - Pas de relation Distributeur/Courtier ni de triage sur le bloc principal.
|
||||
*/
|
||||
|
||||
/** Type d'adresse fournisseur (enum exclusif RG-2.09). */
|
||||
export type SupplierAddressType = 'PROSPECT' | 'DEPART' | 'RENDU'
|
||||
|
||||
/** Un contact du fournisseur (onglet Contacts). */
|
||||
export interface SupplierContactFormDraft {
|
||||
/** Id serveur une fois le contact cree (null tant que non persiste). */
|
||||
id: number | null
|
||||
/** IRI Hydra du contact cree — utilise pour le rattachement M2M cote adresse. */
|
||||
iri: string | null
|
||||
firstName: string | null
|
||||
lastName: string | null
|
||||
jobTitle: string | null
|
||||
phonePrimary: string | null
|
||||
phoneSecondary: string | null
|
||||
email: string | null
|
||||
/** UI : le 2e numero a ete revele via le bouton « + ». */
|
||||
hasSecondaryPhone: boolean
|
||||
}
|
||||
|
||||
/** Une adresse du fournisseur (onglet Adresses). */
|
||||
export interface SupplierAddressFormDraft {
|
||||
id: number | null
|
||||
/** Type exclusif Prospect / Depart / Rendu (RG-2.09). null tant que non choisi. */
|
||||
addressType: SupplierAddressType | null
|
||||
country: string
|
||||
postalCode: string | null
|
||||
city: string | null
|
||||
street: string | null
|
||||
streetComplement: string | null
|
||||
/** IRI des categories rattachees (type FOURNISSEUR, RG-2.10). */
|
||||
categoryIris: string[]
|
||||
/** IRI des sites Starseed rattaches (>= 1 obligatoire — RG-2.06). */
|
||||
siteIris: string[]
|
||||
/** IRI des contacts rattaches (= blocs Contact deja crees). */
|
||||
contactIris: string[]
|
||||
/** Nombre de bennes (stepper, defaut 0). Chaine pour MalioInputNumber, convertie au payload. */
|
||||
bennes: string | null
|
||||
/** Prestation de triage (specifique fournisseur, portee par l'adresse — RG). */
|
||||
triageProvider: boolean
|
||||
/** Latitude WGS84 (chaine decimale NUMERIC(10,7)), null si non geolocalisee (M6.1). */
|
||||
latitude: string | null
|
||||
/** Longitude WGS84 (chaine decimale NUMERIC(10,7)), null si non geolocalisee (M6.1). */
|
||||
longitude: string | null
|
||||
/** RG-6.08 : pin corrige a la main — le geocodage auto ne reecrit plus. */
|
||||
geoManual: boolean
|
||||
}
|
||||
|
||||
/** Un RIB du fournisseur (onglet Comptabilite). */
|
||||
export interface SupplierRibFormDraft {
|
||||
id: number | null
|
||||
label: string | null
|
||||
bic: string | null
|
||||
iban: string | null
|
||||
}
|
||||
|
||||
/** Fabrique un contact vierge. */
|
||||
export function emptyContact(): SupplierContactFormDraft {
|
||||
return {
|
||||
id: null,
|
||||
iri: null,
|
||||
firstName: null,
|
||||
lastName: null,
|
||||
jobTitle: null,
|
||||
phonePrimary: null,
|
||||
phoneSecondary: null,
|
||||
email: null,
|
||||
hasSecondaryPhone: false,
|
||||
}
|
||||
}
|
||||
|
||||
/** Fabrique une adresse vierge (pays prerempli « France », 0 benne). */
|
||||
export function emptyAddress(): SupplierAddressFormDraft {
|
||||
return {
|
||||
id: null,
|
||||
addressType: null,
|
||||
country: 'France',
|
||||
postalCode: null,
|
||||
city: null,
|
||||
street: null,
|
||||
streetComplement: null,
|
||||
categoryIris: [],
|
||||
siteIris: [],
|
||||
contactIris: [],
|
||||
bennes: '0',
|
||||
triageProvider: false,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
geoManual: false,
|
||||
}
|
||||
}
|
||||
|
||||
/** Fabrique un RIB vierge. */
|
||||
export function emptyRib(): SupplierRibFormDraft {
|
||||
return {
|
||||
id: null,
|
||||
label: null,
|
||||
bic: null,
|
||||
iban: null,
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
mapAddressView,
|
||||
mapContactToDraft,
|
||||
mapRibToDraft,
|
||||
paymentTypeCodeOf,
|
||||
referentialOptionOf,
|
||||
relationOf,
|
||||
showArchiveAction,
|
||||
@@ -233,3 +234,17 @@ describe('showArchiveAction / showRestoreAction', () => {
|
||||
expect(showRestoreAction(can([]), true)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('paymentTypeCodeOf (ERP-121 : RIB masques hors-LCR en consultation)', () => {
|
||||
it('retourne le code metier quand le type de reglement est embarque', () => {
|
||||
expect(paymentTypeCodeOf({ '@id': '/api/payment_types/1', code: 'LCR' })).toBe('LCR')
|
||||
expect(paymentTypeCodeOf({ '@id': '/api/payment_types/2', code: 'VIREMENT' })).toBe('VIREMENT')
|
||||
})
|
||||
|
||||
it('retourne null pour un IRI nu, un objet sans code, ou une relation absente', () => {
|
||||
expect(paymentTypeCodeOf('/api/payment_types/1')).toBeNull()
|
||||
expect(paymentTypeCodeOf({ '@id': '/api/payment_types/1' })).toBeNull()
|
||||
expect(paymentTypeCodeOf(null)).toBeNull()
|
||||
expect(paymentTypeCodeOf(undefined)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -61,7 +61,9 @@ function accountingDraft(overrides: Partial<AccountingFormDraft> = {}): Accounti
|
||||
// Le contact inline (nom/prenom/telephones/email) ne fait plus partie du groupe
|
||||
// main : les coordonnees vivent desormais sur la sous-ressource ClientContact.
|
||||
const MAIN_KEYS = [
|
||||
'companyName', 'categories', 'distributor', 'broker', 'triageService',
|
||||
// relationType : champ transitoire envoye au back pour la validation croisee
|
||||
// « relation choisie => FK obligatoire » (RG-1.03 bis, ERP-119).
|
||||
'companyName', 'categories', 'relationType', 'distributor', 'broker', 'triageService',
|
||||
]
|
||||
const INFORMATION_KEYS = [
|
||||
'description', 'competitors', 'foundedAt', 'employeesCount',
|
||||
@@ -99,6 +101,27 @@ describe('buildMainPayload — scoping strict groupe client:write:main', () => {
|
||||
expect(payload.distributor).toBeNull()
|
||||
expect(payload.broker).toBeNull()
|
||||
})
|
||||
|
||||
it('transmet relationType au back pour la validation croisee (RG-1.03 bis)', () => {
|
||||
expect(buildMainPayload(mainDraft({ relationType: 'distributeur' })).relationType).toBe('distributeur')
|
||||
expect(buildMainPayload(mainDraft({ relationType: 'courtier' })).relationType).toBe('courtier')
|
||||
expect(buildMainPayload(mainDraft({ relationType: null })).relationType).toBeNull()
|
||||
})
|
||||
|
||||
// ERP-119 : companyName est requis ET adosse a une colonne NON-nullable. Si le
|
||||
// champ est vide, on OMET la cle (au lieu d'envoyer null) pour que le back
|
||||
// renvoie une 422 NotBlank (propertyPath companyName) et non un 400 de type.
|
||||
it('omet companyName quand il est vide (null) -> 422 NotBlank cote back', () => {
|
||||
expect('companyName' in buildMainPayload(mainDraft({ companyName: null }))).toBe(false)
|
||||
})
|
||||
|
||||
it('omet companyName quand il est une chaine vide', () => {
|
||||
expect('companyName' in buildMainPayload(mainDraft({ companyName: '' }))).toBe(false)
|
||||
})
|
||||
|
||||
it('conserve companyName quand il est renseigne', () => {
|
||||
expect(buildMainPayload(mainDraft({ companyName: 'ACME' })).companyName).toBe('ACME')
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildInformationPayload — scoping strict groupe client:write:information', () => {
|
||||
@@ -142,19 +165,82 @@ describe('buildContactPayload / buildAddressPayload / buildRibPayload', () => {
|
||||
|
||||
it('adresse : email facturation conserve uniquement si requis (RG-1.11)', () => {
|
||||
const address: AddressFormDraft = {
|
||||
id: 3, isProspect: false, isDelivery: false, isBilling: true, country: 'France',
|
||||
id: 3, isProspect: false, isDelivery: false, isBilling: true, isBroker: false, isDistributor: false, country: 'France',
|
||||
postalCode: '86100', city: 'Châtellerault', street: '1 rue X', streetComplement: null,
|
||||
categoryIris: ['/api/categories/2'], siteIris: ['/api/sites/1'], contactIris: [],
|
||||
billingEmail: 'facturation@acme.fr',
|
||||
billingEmail: 'facturation@acme.fr', billingEmailSecondary: 'compta@acme.fr', hasSecondaryBillingEmail: true,
|
||||
}
|
||||
expect(buildAddressPayload(address, true).billingEmail).toBe('facturation@acme.fr')
|
||||
expect(buildAddressPayload(address, false).billingEmail).toBeNull()
|
||||
// 2e email : transmis si facturation + revele, sinon null (ERP-119).
|
||||
expect(buildAddressPayload(address, true).billingEmailSecondary).toBe('compta@acme.fr')
|
||||
expect(buildAddressPayload(address, false).billingEmailSecondary).toBeNull()
|
||||
expect(buildAddressPayload({ ...address, hasSecondaryBillingEmail: false }, true).billingEmailSecondary).toBeNull()
|
||||
})
|
||||
|
||||
it('rib : label / bic / iban transmis tels quels', () => {
|
||||
const rib: RibFormDraft = { id: 1, label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' }
|
||||
expect(buildRibPayload(rib)).toEqual({ label: 'Compte principal', bic: 'BNPAFRPP', iban: 'FR76...' })
|
||||
})
|
||||
|
||||
// ERP-119 : un RIB partiel (IBAN seul) doit omettre label/bic vides pour
|
||||
// declencher la 422 NotBlank par champ, pas un 400 de type a la deserialisation.
|
||||
it('rib partiel : omet label / bic vides, conserve iban', () => {
|
||||
const rib: RibFormDraft = { id: null, label: null, bic: null, iban: 'FR7612345' }
|
||||
const payload = buildRibPayload(rib)
|
||||
expect('label' in payload).toBe(false)
|
||||
expect('bic' in payload).toBe(false)
|
||||
expect(payload.iban).toBe('FR7612345')
|
||||
})
|
||||
|
||||
// ERP-119 : une adresse partielle omet postalCode/city/street vides (NotBlank).
|
||||
it('adresse partielle : omet postalCode / city / street vides', () => {
|
||||
const address: AddressFormDraft = {
|
||||
id: null, isProspect: false, isDelivery: true, isBilling: false, isBroker: false, isDistributor: false, country: 'France',
|
||||
postalCode: null, city: '', street: null, streetComplement: null,
|
||||
categoryIris: ['/api/categories/2'], siteIris: ['/api/sites/1'], contactIris: [],
|
||||
billingEmail: null, billingEmailSecondary: null, hasSecondaryBillingEmail: false,
|
||||
}
|
||||
const payload = buildAddressPayload(address, false)
|
||||
expect('postalCode' in payload).toBe(false)
|
||||
expect('city' in payload).toBe(false)
|
||||
expect('street' in payload).toBe(false)
|
||||
// Les champs non requis / booleens restent presents.
|
||||
expect(payload.isDelivery).toBe(true)
|
||||
expect(payload.sites).toEqual(['/api/sites/1'])
|
||||
})
|
||||
})
|
||||
|
||||
// Bug edition : en PATCH (merge), une cle de champ requis OMISE laisse la valeur
|
||||
// serveur inchangee -> faux 200 quand l'utilisateur vide le champ. En `forUpdate`,
|
||||
// on envoie `''` (chaine valide, pas de 400 de type) -> NotBlank 422 inline.
|
||||
describe('forUpdate (EDITION/PATCH) : champ requis vide -> `\'\'` au lieu d\'etre omis', () => {
|
||||
it('buildMainPayload : companyName vide envoye en `\'\'`', () => {
|
||||
const payload = buildMainPayload(mainDraft({ companyName: '' }), { forUpdate: true })
|
||||
expect('companyName' in payload).toBe(true)
|
||||
expect(payload.companyName).toBe('')
|
||||
})
|
||||
|
||||
it('buildAddressPayload : postalCode / city / street vides envoyes en `\'\'`', () => {
|
||||
const address: AddressFormDraft = {
|
||||
id: 7, isProspect: false, isDelivery: true, isBilling: false, isBroker: false, isDistributor: false, country: 'France',
|
||||
postalCode: '', city: null, street: '1 rue X', streetComplement: null,
|
||||
categoryIris: ['/api/categories/2'], siteIris: ['/api/sites/1'], contactIris: [],
|
||||
billingEmail: null, billingEmailSecondary: null, hasSecondaryBillingEmail: false,
|
||||
}
|
||||
const payload = buildAddressPayload(address, false, { forUpdate: true })
|
||||
expect(payload.postalCode).toBe('')
|
||||
expect(payload.city).toBe('')
|
||||
// Un champ requis renseigne reste tel quel.
|
||||
expect(payload.street).toBe('1 rue X')
|
||||
})
|
||||
|
||||
it('buildRibPayload : label / bic vides envoyes en `\'\'`, iban conserve', () => {
|
||||
const payload = buildRibPayload({ id: 4, label: '', bic: null, iban: 'FR7612345' }, { forUpdate: true })
|
||||
expect(payload.label).toBe('')
|
||||
expect(payload.bic).toBe('')
|
||||
expect(payload.iban).toBe('FR7612345')
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapMainDraft — pre-remplissage bloc principal', () => {
|
||||
|
||||
@@ -7,14 +7,22 @@ import {
|
||||
canSelectDeliveryOrBilling,
|
||||
canSelectProspect,
|
||||
hasAllRequiredAccountingFields,
|
||||
hasAtLeastOneInformationField,
|
||||
hasAtLeastOneValidContact,
|
||||
isAddressValid,
|
||||
isBankRequiredForPaymentType,
|
||||
isBillingEmailRequired,
|
||||
isBlankRow,
|
||||
isContactBlank,
|
||||
isContactNamed,
|
||||
isRibBlank,
|
||||
isRibComplete,
|
||||
isRibRequiredForPaymentType,
|
||||
lastFillableTabKey,
|
||||
omitEmptyRequired,
|
||||
showsRelationAndTriageFields,
|
||||
type AddressFlagsDraft,
|
||||
type AddressValidityDraft,
|
||||
type ContactDraft,
|
||||
type ContactFillableDraft,
|
||||
} from '../clientFormRules'
|
||||
@@ -63,6 +71,24 @@ describe('buildClientFormTabKeys (gating onglet Comptabilite + onglets edit-only
|
||||
})
|
||||
})
|
||||
|
||||
describe('lastFillableTabKey (redirection fin d\'ajout, role-aware)', () => {
|
||||
it('Adresse pour un role sans Comptabilite (Bureau / Commerciale)', () => {
|
||||
expect(lastFillableTabKey(buildClientFormTabKeys(false))).toBe('address')
|
||||
})
|
||||
|
||||
it('Comptabilite pour un role avec accounting.view (Admin)', () => {
|
||||
expect(lastFillableTabKey(buildClientFormTabKeys(true))).toBe('accounting')
|
||||
})
|
||||
|
||||
it('ignore les onglets placeholder (Transport en dernier ne compte pas)', () => {
|
||||
expect(lastFillableTabKey(['information', 'contact', 'address', 'transport'])).toBe('address')
|
||||
})
|
||||
|
||||
it('undefined si aucun onglet remplissable (que des placeholders)', () => {
|
||||
expect(lastFillableTabKey(['transport', 'statistics'])).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isContactNamed (RG-1.05)', () => {
|
||||
it('vrai si le prenom est renseigne', () => {
|
||||
expect(isContactNamed({ firstName: 'Alice', lastName: null })).toBe(true)
|
||||
@@ -143,83 +169,79 @@ describe('hasAtLeastOneValidContact (RG-1.14)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
/** Drapeaux d'adresse complets (5 types) avec surcharge partielle. */
|
||||
function flags(overrides: Partial<AddressFlagsDraft> = {}): AddressFlagsDraft {
|
||||
return {
|
||||
isProspect: false, isDelivery: false, isBilling: false, isBroker: false, isDistributor: false,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
describe('exclusivite Prospect / Livraison / Facturation (RG-1.06/07/08)', () => {
|
||||
it('Prospect est selectionnable tant que ni Livraison ni Facturation', () => {
|
||||
expect(canSelectProspect({ isProspect: false, isDelivery: false, isBilling: false })).toBe(true)
|
||||
expect(canSelectProspect({ isProspect: false, isDelivery: true, isBilling: false })).toBe(false)
|
||||
expect(canSelectProspect({ isProspect: false, isDelivery: false, isBilling: true })).toBe(false)
|
||||
expect(canSelectProspect(flags())).toBe(true)
|
||||
expect(canSelectProspect(flags({ isDelivery: true }))).toBe(false)
|
||||
expect(canSelectProspect(flags({ isBilling: true }))).toBe(false)
|
||||
})
|
||||
|
||||
it('Livraison / Facturation selectionnables tant que pas Prospect', () => {
|
||||
expect(canSelectDeliveryOrBilling({ isProspect: false, isDelivery: false, isBilling: false })).toBe(true)
|
||||
expect(canSelectDeliveryOrBilling({ isProspect: true, isDelivery: false, isBilling: false })).toBe(false)
|
||||
expect(canSelectDeliveryOrBilling(flags())).toBe(true)
|
||||
expect(canSelectDeliveryOrBilling(flags({ isProspect: true }))).toBe(false)
|
||||
})
|
||||
|
||||
it('cocher Prospect efface Livraison et Facturation', () => {
|
||||
const next = applyProspectExclusivity(
|
||||
{ isProspect: false, isDelivery: true, isBilling: true },
|
||||
'isProspect',
|
||||
true,
|
||||
)
|
||||
expect(next).toEqual({ isProspect: true, isDelivery: false, isBilling: false })
|
||||
const next = applyProspectExclusivity(flags({ isDelivery: true, isBilling: true }), 'isProspect', true)
|
||||
expect(next).toEqual(flags({ isProspect: true }))
|
||||
})
|
||||
|
||||
it('cocher Livraison efface Prospect', () => {
|
||||
const next = applyProspectExclusivity(
|
||||
{ isProspect: true, isDelivery: false, isBilling: false },
|
||||
'isDelivery',
|
||||
true,
|
||||
)
|
||||
expect(next).toEqual({ isProspect: false, isDelivery: true, isBilling: false })
|
||||
const next = applyProspectExclusivity(flags({ isProspect: true }), 'isDelivery', true)
|
||||
expect(next).toEqual(flags({ isDelivery: true }))
|
||||
})
|
||||
|
||||
it('cocher Facturation efface Prospect mais conserve Livraison', () => {
|
||||
const next = applyProspectExclusivity(
|
||||
{ isProspect: true, isDelivery: true, isBilling: false },
|
||||
'isBilling',
|
||||
true,
|
||||
)
|
||||
expect(next).toEqual({ isProspect: false, isDelivery: true, isBilling: true })
|
||||
const next = applyProspectExclusivity(flags({ isProspect: true, isDelivery: true }), 'isBilling', true)
|
||||
expect(next).toEqual(flags({ isDelivery: true, isBilling: true }))
|
||||
})
|
||||
|
||||
it('decocher un drapeau ne reactive rien d autre', () => {
|
||||
const next = applyProspectExclusivity(
|
||||
{ isProspect: false, isDelivery: true, isBilling: true },
|
||||
'isBilling',
|
||||
false,
|
||||
)
|
||||
expect(next).toEqual({ isProspect: false, isDelivery: true, isBilling: false })
|
||||
const next = applyProspectExclusivity(flags({ isDelivery: true, isBilling: true }), 'isBilling', false)
|
||||
expect(next).toEqual(flags({ isDelivery: true }))
|
||||
})
|
||||
})
|
||||
|
||||
describe('isBillingEmailRequired (RG-1.11)', () => {
|
||||
it('obligatoire uniquement si Facturation est coche', () => {
|
||||
expect(isBillingEmailRequired({ isProspect: false, isDelivery: false, isBilling: true })).toBe(true)
|
||||
expect(isBillingEmailRequired({ isProspect: false, isDelivery: true, isBilling: false })).toBe(false)
|
||||
expect(isBillingEmailRequired(flags({ isBilling: true }))).toBe(true)
|
||||
expect(isBillingEmailRequired(flags({ isDelivery: true }))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('type d\'adresse (Select front) <-> drapeaux back', () => {
|
||||
it('addressFlagsFromType mappe chaque type vers les bons drapeaux', () => {
|
||||
expect(addressFlagsFromType('prospect')).toEqual({ isProspect: true, isDelivery: false, isBilling: false })
|
||||
expect(addressFlagsFromType('delivery')).toEqual({ isProspect: false, isDelivery: true, isBilling: false })
|
||||
expect(addressFlagsFromType('billing')).toEqual({ isProspect: false, isDelivery: false, isBilling: true })
|
||||
expect(addressFlagsFromType('delivery_billing')).toEqual({ isProspect: false, isDelivery: true, isBilling: true })
|
||||
expect(addressFlagsFromType('prospect')).toEqual(flags({ isProspect: true }))
|
||||
expect(addressFlagsFromType('delivery')).toEqual(flags({ isDelivery: true }))
|
||||
expect(addressFlagsFromType('billing')).toEqual(flags({ isBilling: true }))
|
||||
expect(addressFlagsFromType('delivery_billing')).toEqual(flags({ isDelivery: true, isBilling: true }))
|
||||
expect(addressFlagsFromType('broker')).toEqual(flags({ isBroker: true }))
|
||||
expect(addressFlagsFromType('distributor')).toEqual(flags({ isDistributor: true }))
|
||||
})
|
||||
|
||||
it('addressTypeFromFlags reconstruit le type (Prospect prioritaire, livraison+facturation groupes)', () => {
|
||||
expect(addressTypeFromFlags({ isProspect: true, isDelivery: false, isBilling: false })).toBe('prospect')
|
||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: true, isBilling: false })).toBe('delivery')
|
||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: false, isBilling: true })).toBe('billing')
|
||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: true, isBilling: true })).toBe('delivery_billing')
|
||||
it('addressTypeFromFlags reconstruit le type (Prospect/Courtier/Distributeur autonomes, livraison+facturation groupes)', () => {
|
||||
expect(addressTypeFromFlags(flags({ isProspect: true }))).toBe('prospect')
|
||||
expect(addressTypeFromFlags(flags({ isDelivery: true }))).toBe('delivery')
|
||||
expect(addressTypeFromFlags(flags({ isBilling: true }))).toBe('billing')
|
||||
expect(addressTypeFromFlags(flags({ isDelivery: true, isBilling: true }))).toBe('delivery_billing')
|
||||
expect(addressTypeFromFlags(flags({ isBroker: true }))).toBe('broker')
|
||||
expect(addressTypeFromFlags(flags({ isDistributor: true }))).toBe('distributor')
|
||||
})
|
||||
|
||||
it('addressTypeFromFlags retourne null quand aucun drapeau (amorce vierge -> bouton bloque)', () => {
|
||||
expect(addressTypeFromFlags({ isProspect: false, isDelivery: false, isBilling: false })).toBeNull()
|
||||
expect(addressTypeFromFlags(flags())).toBeNull()
|
||||
})
|
||||
|
||||
it('aller-retour type -> drapeaux -> type stable pour les 4 types', () => {
|
||||
for (const type of ['prospect', 'delivery', 'billing', 'delivery_billing'] as const) {
|
||||
it('aller-retour type -> drapeaux -> type stable pour les 6 types', () => {
|
||||
for (const type of ['prospect', 'delivery', 'billing', 'delivery_billing', 'broker', 'distributor'] as const) {
|
||||
expect(addressTypeFromFlags(addressFlagsFromType(type))).toBe(type)
|
||||
}
|
||||
})
|
||||
@@ -271,3 +293,128 @@ describe('hasAllRequiredAccountingFields (RG-1.30)', () => {
|
||||
})).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('showsRelationAndTriageFields (affichage Relation + Triage selon categorie)', () => {
|
||||
it('faux par defaut (aucune categorie selectionnee)', () => {
|
||||
expect(showsRelationAndTriageFields([])).toBe(false)
|
||||
})
|
||||
|
||||
it('faux si seules des categories Distributeur / Courtier sont selectionnees', () => {
|
||||
expect(showsRelationAndTriageFields(['DISTRIBUTEUR'])).toBe(false)
|
||||
expect(showsRelationAndTriageFields(['COURTIER'])).toBe(false)
|
||||
expect(showsRelationAndTriageFields(['DISTRIBUTEUR', 'COURTIER'])).toBe(false)
|
||||
})
|
||||
|
||||
it('vrai des qu\'une categorie ordinaire est selectionnee', () => {
|
||||
expect(showsRelationAndTriageFields(['CLIENT'])).toBe(true)
|
||||
expect(showsRelationAndTriageFields(['DISTRIBUTEUR', 'CLIENT'])).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('hasAtLeastOneInformationField (pas de validation a vide a la creation)', () => {
|
||||
const blank = {
|
||||
description: null,
|
||||
competitors: null,
|
||||
foundedAt: null,
|
||||
employeesCount: null,
|
||||
revenueAmount: null,
|
||||
profitAmount: null,
|
||||
directorName: null,
|
||||
}
|
||||
|
||||
it('faux quand aucun champ n\'est rempli (onglet vierge)', () => {
|
||||
expect(hasAtLeastOneInformationField(blank)).toBe(false)
|
||||
expect(hasAtLeastOneInformationField({ ...blank, description: ' ' })).toBe(false)
|
||||
})
|
||||
|
||||
it('vrai des qu\'un champ porte une valeur', () => {
|
||||
expect(hasAtLeastOneInformationField({ ...blank, description: 'Acteur majeur' })).toBe(true)
|
||||
expect(hasAtLeastOneInformationField({ ...blank, employeesCount: '42' })).toBe(true)
|
||||
expect(hasAtLeastOneInformationField({ ...blank, foundedAt: '2020-01-01' })).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isAddressValid (gating « + Adresse » + validation onglet)', () => {
|
||||
/** Adresse de livraison valide (type + site + categorie ; pas de facturation). */
|
||||
function validDelivery(): AddressValidityDraft {
|
||||
return {
|
||||
isProspect: false,
|
||||
isDelivery: true,
|
||||
isBilling: false,
|
||||
isBroker: false,
|
||||
isDistributor: false,
|
||||
categoryIris: ['/api/client_categories/1'],
|
||||
siteIris: ['/api/sites/1'],
|
||||
billingEmail: null,
|
||||
}
|
||||
}
|
||||
|
||||
it('vrai quand type + >= 1 site + >= 1 categorie (sans facturation)', () => {
|
||||
expect(isAddressValid(validDelivery())).toBe(true)
|
||||
})
|
||||
|
||||
it('faux si aucun drapeau (type d\'adresse non renseigne, amorce vierge)', () => {
|
||||
expect(isAddressValid({ ...validDelivery(), isDelivery: false })).toBe(false)
|
||||
})
|
||||
|
||||
it('faux si aucun site (RG-1.10)', () => {
|
||||
expect(isAddressValid({ ...validDelivery(), siteIris: [] })).toBe(false)
|
||||
})
|
||||
|
||||
it('faux si aucune categorie', () => {
|
||||
expect(isAddressValid({ ...validDelivery(), categoryIris: [] })).toBe(false)
|
||||
})
|
||||
|
||||
it('RG-1.11 : email de facturation obligatoire quand l\'adresse est de facturation', () => {
|
||||
const billing: AddressValidityDraft = { ...validDelivery(), isBilling: true }
|
||||
expect(isAddressValid({ ...billing, billingEmail: null })).toBe(false)
|
||||
expect(isAddressValid({ ...billing, billingEmail: ' ' })).toBe(false)
|
||||
expect(isAddressValid({ ...billing, billingEmail: 'facture@acme.fr' })).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isRibComplete (gating « + RIB » + RG-1.13)', () => {
|
||||
it('vrai quand label + BIC + IBAN sont remplis', () => {
|
||||
expect(isRibComplete({ label: 'Compte courant', bic: 'BNPAFRPP', iban: 'FR1420041010050500013M02606' })).toBe(true)
|
||||
})
|
||||
|
||||
it('faux si un champ manque (null ou vide apres trim)', () => {
|
||||
expect(isRibComplete({ label: null, bic: 'BNPAFRPP', iban: 'FR14...' })).toBe(false)
|
||||
expect(isRibComplete({ label: 'Compte', bic: ' ', iban: 'FR14...' })).toBe(false)
|
||||
expect(isRibComplete({ label: 'Compte', bic: 'BNPAFRPP', iban: null })).toBe(false)
|
||||
})
|
||||
|
||||
it('faux pour un bloc totalement vide (amorce)', () => {
|
||||
expect(isRibComplete({ label: null, bic: null, iban: null })).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('omitEmptyRequired (ERP-119 : 422 NotBlank au lieu de 400 de type)', () => {
|
||||
it('retire les cles requises vides (null / vide / undefined)', () => {
|
||||
const payload = omitEmptyRequired(
|
||||
{ companyName: null, label: '', iban: undefined, categories: ['/api/categories/1'] },
|
||||
['companyName', 'label', 'iban'],
|
||||
)
|
||||
expect('companyName' in payload).toBe(false)
|
||||
expect('label' in payload).toBe(false)
|
||||
expect('iban' in payload).toBe(false)
|
||||
// Les cles hors liste ne sont jamais touchees.
|
||||
expect(payload.categories).toEqual(['/api/categories/1'])
|
||||
})
|
||||
|
||||
it('conserve les cles requises renseignees', () => {
|
||||
const payload = omitEmptyRequired({ companyName: 'ACME', bic: 'BNPAFRPP' }, ['companyName', 'bic'])
|
||||
expect(payload).toEqual({ companyName: 'ACME', bic: 'BNPAFRPP' })
|
||||
})
|
||||
|
||||
it('ne retire jamais une cle hors de la liste requise, meme vide', () => {
|
||||
const payload = omitEmptyRequired({ streetComplement: null }, ['street'])
|
||||
expect('streetComplement' in payload).toBe(true)
|
||||
expect(payload.streetComplement).toBeNull()
|
||||
})
|
||||
|
||||
it('false / 0 ne sont pas consideres vides (booleens / nombres preserves)', () => {
|
||||
const payload = omitEmptyRequired({ isDelivery: false, position: 0 }, ['isDelivery', 'position'])
|
||||
expect(payload).toEqual({ isDelivery: false, position: 0 })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
canEditSupplier,
|
||||
categoryOptionsOf,
|
||||
contactOptionsOf,
|
||||
iriOf,
|
||||
mapAccountingDraft,
|
||||
mapAddressToDraft,
|
||||
mapAddressView,
|
||||
mapContactToDraft,
|
||||
mapRibToDraft,
|
||||
paymentTypeCodeOf,
|
||||
referentialOptionOf,
|
||||
showArchiveAction,
|
||||
showRestoreAction,
|
||||
siteOptionsOf,
|
||||
type SupplierDetail,
|
||||
} from '../supplierConsultation'
|
||||
|
||||
describe('iriOf', () => {
|
||||
it('retourne l\'@id d\'une relation embarquee (objet)', () => {
|
||||
expect(iriOf({ '@id': '/api/payment_types/14', code: 'LCR' })).toBe('/api/payment_types/14')
|
||||
})
|
||||
|
||||
it('retourne la chaine telle quelle si la relation est deja un IRI', () => {
|
||||
expect(iriOf('/api/banks/3')).toBe('/api/banks/3')
|
||||
})
|
||||
|
||||
it('retourne null pour une relation absente (null / undefined / skip_null_values)', () => {
|
||||
expect(iriOf(null)).toBeNull()
|
||||
expect(iriOf(undefined)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapContactToDraft', () => {
|
||||
it('formate les telephones en XX XX XX XX XX et conserve l\'iri', () => {
|
||||
const draft = mapContactToDraft({
|
||||
'@id': '/api/supplier_contacts/39',
|
||||
id: 39,
|
||||
firstName: 'Marie',
|
||||
lastName: 'Martin',
|
||||
jobTitle: 'Responsable achats',
|
||||
phonePrimary: '0612345678',
|
||||
email: 'marie.martin@seed.test',
|
||||
})
|
||||
expect(draft.id).toBe(39)
|
||||
expect(draft.iri).toBe('/api/supplier_contacts/39')
|
||||
expect(draft.phonePrimary).toBe('06 12 34 56 78')
|
||||
expect(draft.hasSecondaryPhone).toBe(false)
|
||||
})
|
||||
|
||||
it('revele le 2e telephone quand phoneSecondary est present', () => {
|
||||
const draft = mapContactToDraft({
|
||||
'@id': '/api/supplier_contacts/40',
|
||||
id: 40,
|
||||
phonePrimary: '0600000000',
|
||||
phoneSecondary: '0611111111',
|
||||
})
|
||||
expect(draft.hasSecondaryPhone).toBe(true)
|
||||
expect(draft.phoneSecondary).toBe('06 11 11 11 11')
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapAddressToDraft', () => {
|
||||
it('mappe l\'enum addressType, les champs fournisseur et extrait les iris', () => {
|
||||
const draft = mapAddressToDraft({
|
||||
'@id': '/api/supplier_addresses/33',
|
||||
id: 33,
|
||||
addressType: 'DEPART',
|
||||
country: 'France',
|
||||
postalCode: '86000',
|
||||
city: 'Poitiers',
|
||||
street: '12 rue des Acacias',
|
||||
bennes: 3,
|
||||
triageProvider: true,
|
||||
sites: [{ '@id': '/api/sites/87', name: 'Chatellerault', color: '#056CF2' }],
|
||||
categories: [{ '@id': '/api/categories/2279', code: 'NEGOCIANT' }],
|
||||
contacts: [{ '@id': '/api/supplier_contacts/39' }, '/api/supplier_contacts/41'],
|
||||
})
|
||||
expect(draft.addressType).toBe('DEPART')
|
||||
expect(draft.siteIris).toEqual(['/api/sites/87'])
|
||||
expect(draft.categoryIris).toEqual(['/api/categories/2279'])
|
||||
expect(draft.contactIris).toEqual(['/api/supplier_contacts/39', '/api/supplier_contacts/41'])
|
||||
// bennes (entier) → chaine pour MalioInputNumber.
|
||||
expect(draft.bennes).toBe('3')
|
||||
expect(draft.triageProvider).toBe(true)
|
||||
expect(draft.city).toBe('Poitiers')
|
||||
expect(draft.country).toBe('France')
|
||||
})
|
||||
|
||||
it('tolere les champs absents (defauts : France, bennes « 0 », triage faux, type null)', () => {
|
||||
const draft = mapAddressToDraft({ '@id': '/api/supplier_addresses/9', id: 9 })
|
||||
expect(draft.addressType).toBeNull()
|
||||
expect(draft.siteIris).toEqual([])
|
||||
expect(draft.categoryIris).toEqual([])
|
||||
expect(draft.contactIris).toEqual([])
|
||||
expect(draft.country).toBe('France')
|
||||
expect(draft.bennes).toBe('0')
|
||||
expect(draft.triageProvider).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapRibToDraft', () => {
|
||||
it('mappe label / bic / iban et l\'id serveur', () => {
|
||||
const draft = mapRibToDraft({ '@id': '/api/supplier_ribs/27', id: 27, label: 'Compte principal', bic: 'BNPAFRPPXXX', iban: 'FR14...' })
|
||||
expect(draft).toEqual({ id: 27, label: 'Compte principal', bic: 'BNPAFRPPXXX', iban: 'FR14...' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapAccountingDraft', () => {
|
||||
it('mappe les scalaires et resout les iris des referentiels embarques', () => {
|
||||
const acc = mapAccountingDraft({
|
||||
'@id': '/api/suppliers/85',
|
||||
id: 85,
|
||||
siren: '123456789',
|
||||
accountNumber: 'F0001',
|
||||
nTva: 'FR00123456789',
|
||||
tvaMode: { '@id': '/api/tva_modes/30' },
|
||||
paymentDelay: { '@id': '/api/payment_delays/11' },
|
||||
paymentType: { '@id': '/api/payment_types/14', code: 'LCR' },
|
||||
bank: { '@id': '/api/banks/3' },
|
||||
} as SupplierDetail)
|
||||
expect(acc).toEqual({
|
||||
siren: '123456789',
|
||||
accountNumber: 'F0001',
|
||||
nTva: 'FR00123456789',
|
||||
tvaModeIri: '/api/tva_modes/30',
|
||||
paymentDelayIri: '/api/payment_delays/11',
|
||||
paymentTypeIri: '/api/payment_types/14',
|
||||
bankIri: '/api/banks/3',
|
||||
})
|
||||
})
|
||||
|
||||
it('renvoie des null quand les champs comptables sont absents (gating par omission, sans accounting.view)', () => {
|
||||
const acc = mapAccountingDraft({} as SupplierDetail)
|
||||
expect(acc).toEqual({
|
||||
siren: null,
|
||||
accountNumber: null,
|
||||
nTva: null,
|
||||
tvaModeIri: null,
|
||||
paymentDelayIri: null,
|
||||
paymentTypeIri: null,
|
||||
bankIri: null,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('options construites depuis l\'embed (role-independantes)', () => {
|
||||
it('categoryOptionsOf expose value=IRI, label=nom, code', () => {
|
||||
expect(categoryOptionsOf([{ '@id': '/api/categories/2279', name: 'Negociant', code: 'NEGOCIANT' }])).toEqual([
|
||||
{ value: '/api/categories/2279', label: 'Negociant', code: 'NEGOCIANT' },
|
||||
])
|
||||
})
|
||||
|
||||
it('siteOptionsOf expose value=IRI, label=nom', () => {
|
||||
expect(siteOptionsOf([{ '@id': '/api/sites/87', name: 'Chatellerault', color: '#000' }])).toEqual([
|
||||
{ value: '/api/sites/87', label: 'Chatellerault' },
|
||||
])
|
||||
})
|
||||
|
||||
it('contactOptionsOf compose le libelle (nom complet, sinon email)', () => {
|
||||
expect(contactOptionsOf([
|
||||
{ '@id': '/api/supplier_contacts/1', id: 1, firstName: 'Marie', lastName: 'Martin' },
|
||||
{ '@id': '/api/supplier_contacts/2', id: 2, email: 'a@b.fr' },
|
||||
])).toEqual([
|
||||
{ value: '/api/supplier_contacts/1', label: 'Marie Martin' },
|
||||
{ value: '/api/supplier_contacts/2', label: 'a@b.fr' },
|
||||
])
|
||||
})
|
||||
|
||||
it('referentialOptionOf : option unique depuis l\'embed, vide pour IRI nu / absent', () => {
|
||||
expect(referentialOptionOf({ '@id': '/api/payment_types/14', label: 'LCR' })).toEqual([
|
||||
{ value: '/api/payment_types/14', label: 'LCR' },
|
||||
])
|
||||
expect(referentialOptionOf('/api/banks/3')).toEqual([])
|
||||
expect(referentialOptionOf(null)).toEqual([])
|
||||
})
|
||||
|
||||
it('mapAddressView assemble brouillon + options propres a l\'adresse', () => {
|
||||
const view = mapAddressView({
|
||||
'@id': '/api/supplier_addresses/33',
|
||||
id: 33,
|
||||
addressType: 'RENDU',
|
||||
city: 'Poitiers',
|
||||
sites: [{ '@id': '/api/sites/87', name: 'Chatellerault' }],
|
||||
categories: [{ '@id': '/api/categories/2279', name: 'Negociant', code: 'NEGOCIANT' }],
|
||||
})
|
||||
expect(view.draft.id).toBe(33)
|
||||
expect(view.draft.addressType).toBe('RENDU')
|
||||
expect(view.siteOptions).toEqual([{ value: '/api/sites/87', label: 'Chatellerault' }])
|
||||
expect(view.categoryOptions).toEqual([{ value: '/api/categories/2279', label: 'Negociant', code: 'NEGOCIANT' }])
|
||||
})
|
||||
})
|
||||
|
||||
describe('canEditSupplier', () => {
|
||||
const can = (granted: string[]) => (codes: string[]) => codes.some(c => granted.includes(c))
|
||||
|
||||
it('visible pour manage', () => {
|
||||
expect(canEditSupplier(can(['commercial.suppliers.manage']))).toBe(true)
|
||||
})
|
||||
|
||||
it('visible pour accounting.manage (role Compta)', () => {
|
||||
expect(canEditSupplier(can(['commercial.suppliers.accounting.manage']))).toBe(true)
|
||||
})
|
||||
|
||||
it('masque sans aucune des deux permissions (role Usine)', () => {
|
||||
expect(canEditSupplier(can(['commercial.suppliers.view']))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('showArchiveAction / showRestoreAction', () => {
|
||||
const can = (granted: string[]) => (code: string) => granted.includes(code)
|
||||
|
||||
it('Archiver : visible avec la permission archive ET fournisseur non archive', () => {
|
||||
expect(showArchiveAction(can(['commercial.suppliers.archive']), false)).toBe(true)
|
||||
expect(showArchiveAction(can(['commercial.suppliers.archive']), true)).toBe(false)
|
||||
expect(showArchiveAction(can([]), false)).toBe(false)
|
||||
})
|
||||
|
||||
it('Restaurer : visible avec la permission archive ET fournisseur archive', () => {
|
||||
expect(showRestoreAction(can(['commercial.suppliers.archive']), true)).toBe(true)
|
||||
expect(showRestoreAction(can(['commercial.suppliers.archive']), false)).toBe(false)
|
||||
expect(showRestoreAction(can([]), true)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('paymentTypeCodeOf (ERP-121 : RIB masques hors-LCR en consultation)', () => {
|
||||
it('retourne le code metier quand le type de reglement est embarque', () => {
|
||||
expect(paymentTypeCodeOf({ '@id': '/api/payment_types/1', code: 'LCR' })).toBe('LCR')
|
||||
expect(paymentTypeCodeOf({ '@id': '/api/payment_types/2', code: 'VIREMENT' })).toBe('VIREMENT')
|
||||
})
|
||||
|
||||
it('retourne null pour un IRI nu, un objet sans code, ou une relation absente', () => {
|
||||
expect(paymentTypeCodeOf('/api/payment_types/1')).toBeNull()
|
||||
expect(paymentTypeCodeOf({ '@id': '/api/payment_types/1' })).toBeNull()
|
||||
expect(paymentTypeCodeOf(null)).toBeNull()
|
||||
expect(paymentTypeCodeOf(undefined)).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,218 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
buildAccountingPayload,
|
||||
buildAddressPayload,
|
||||
buildContactPayload,
|
||||
buildInformationPayload,
|
||||
buildMainPayload,
|
||||
buildRibPayload,
|
||||
mapAccountingFormDraft,
|
||||
mapInformationDraft,
|
||||
mapMainDraft,
|
||||
resolveTabEditability,
|
||||
} from '../supplierEdit'
|
||||
import type { SupplierDetail } from '~/modules/commercial/utils/supplierConsultation'
|
||||
import { emptyAddress, emptyContact, emptyRib } from '~/modules/commercial/types/supplierForm'
|
||||
|
||||
describe('buildMainPayload (groupe supplier:write:main)', () => {
|
||||
it('envoie companyName + categories quand renseignes', () => {
|
||||
expect(buildMainPayload({ companyName: 'ACME', categoryIris: ['/api/categories/1'] })).toEqual({
|
||||
companyName: 'ACME',
|
||||
categories: ['/api/categories/1'],
|
||||
})
|
||||
})
|
||||
|
||||
it('CREATION : omet companyName vide (-> 422 NotBlank, ERP-119)', () => {
|
||||
const payload = buildMainPayload({ companyName: null, categoryIris: [] })
|
||||
expect('companyName' in payload).toBe(false)
|
||||
expect(payload.categories).toEqual([])
|
||||
})
|
||||
|
||||
it('EDITION (forUpdate) : companyName vide envoye en `\'\'` (PATCH -> 422 NotBlank, pas un faux 200)', () => {
|
||||
const payload = buildMainPayload({ companyName: '', categoryIris: [] }, { forUpdate: true })
|
||||
expect('companyName' in payload).toBe(true)
|
||||
expect(payload.companyName).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildInformationPayload (groupe supplier:write:information)', () => {
|
||||
const base = {
|
||||
description: null, competitors: null, foundedAt: null, employeesCount: null,
|
||||
revenueAmount: null, profitAmount: null, directorName: null, volumeForecast: null,
|
||||
}
|
||||
|
||||
it('convertit employeesCount et volumeForecast en nombre, null si vide', () => {
|
||||
expect(buildInformationPayload({ ...base, employeesCount: '42', volumeForecast: '1000' })).toMatchObject({
|
||||
employeesCount: 42,
|
||||
volumeForecast: 1000,
|
||||
})
|
||||
expect(buildInformationPayload(base)).toMatchObject({ employeesCount: null, volumeForecast: null })
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildContactPayload (sous-ressource supplier_contact)', () => {
|
||||
it('n\'envoie le 2e telephone que si revele (hasSecondaryPhone)', () => {
|
||||
const contact = { ...emptyContact(), phonePrimary: '0102030405', phoneSecondary: '0607080910' }
|
||||
expect(buildContactPayload({ ...contact, hasSecondaryPhone: false }).phoneSecondary).toBeNull()
|
||||
expect(buildContactPayload({ ...contact, hasSecondaryPhone: true }).phoneSecondary).toBe('0607080910')
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildAddressPayload (sous-ressource supplier_address — specificites M2)', () => {
|
||||
it('envoie addressType (enum), bennes (nombre) et triageProvider', () => {
|
||||
const address = {
|
||||
...emptyAddress(),
|
||||
addressType: 'RENDU' as const,
|
||||
postalCode: '86100', city: 'Châtellerault', street: '1 rue de la Paix',
|
||||
siteIris: ['/api/sites/1'], categoryIris: ['/api/categories/2'],
|
||||
bennes: '3', triageProvider: true,
|
||||
}
|
||||
expect(buildAddressPayload(address)).toMatchObject({
|
||||
addressType: 'RENDU',
|
||||
bennes: 3,
|
||||
triageProvider: true,
|
||||
sites: ['/api/sites/1'],
|
||||
categories: ['/api/categories/2'],
|
||||
})
|
||||
})
|
||||
|
||||
it('bennes null quand le champ est vide', () => {
|
||||
expect(buildAddressPayload({ ...emptyAddress(), bennes: '' }).bennes).toBeNull()
|
||||
})
|
||||
|
||||
it('omet postalCode / city / street vides (-> 422 NotBlank, ERP-119)', () => {
|
||||
const payload = buildAddressPayload({ ...emptyAddress(), addressType: 'PROSPECT' })
|
||||
expect('postalCode' in payload).toBe(false)
|
||||
expect('city' in payload).toBe(false)
|
||||
expect('street' in payload).toBe(false)
|
||||
// Les champs non requis restent presents.
|
||||
expect('streetComplement' in payload).toBe(true)
|
||||
expect(payload.addressType).toBe('PROSPECT')
|
||||
})
|
||||
|
||||
it('omet addressType quand aucun radio n\'est choisi (-> 422 NotBlank au lieu d\'un 400 de type)', () => {
|
||||
// emptyAddress() laisse addressType a null : la cle doit etre absente du
|
||||
// payload pour que le back renvoie une 422 propertyPath addressType.
|
||||
const payload = buildAddressPayload(emptyAddress())
|
||||
expect('addressType' in payload).toBe(false)
|
||||
})
|
||||
|
||||
it('EDITION (forUpdate) : un champ requis vide est envoye en `\'\'` (et NON omis) pour declencher la 422 NotBlank au PATCH', () => {
|
||||
// Bug edition : omettre la cle d'un champ requis vide laisse le PATCH garder
|
||||
// l'ancienne valeur (faux 200). En `forUpdate`, on envoie `''` -> NotBlank 422.
|
||||
const payload = buildAddressPayload({ ...emptyAddress(), addressType: 'DEPART', postalCode: '' }, { forUpdate: true })
|
||||
expect('postalCode' in payload).toBe(true)
|
||||
expect(payload.postalCode).toBe('')
|
||||
// Un champ requis renseigne reste tel quel.
|
||||
expect(payload.addressType).toBe('DEPART')
|
||||
})
|
||||
|
||||
it('n\'expose jamais d\'email de facturation (difference M1)', () => {
|
||||
const payload = buildAddressPayload({ ...emptyAddress(), addressType: 'DEPART' })
|
||||
expect('billingEmail' in payload).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildAccountingPayload (groupe supplier:write:accounting)', () => {
|
||||
const base = {
|
||||
siren: '123456789', accountNumber: '00012345678', nTva: 'FR123',
|
||||
tvaModeIri: '/api/tva_modes/1', paymentDelayIri: '/api/payment_delays/1',
|
||||
paymentTypeIri: '/api/payment_types/1', bankIri: '/api/banks/1',
|
||||
}
|
||||
|
||||
it('envoie la banque seulement si requise (VIREMENT, RG-2.07)', () => {
|
||||
expect(buildAccountingPayload(base, true).bank).toBe('/api/banks/1')
|
||||
expect(buildAccountingPayload(base, false).bank).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildRibPayload (sous-ressource supplier_rib)', () => {
|
||||
it('omet les champs requis vides (-> 422 NotBlank, ERP-119)', () => {
|
||||
const payload = buildRibPayload({ ...emptyRib(), iban: 'FR1420041010050500013M02606' })
|
||||
expect('label' in payload).toBe(false)
|
||||
expect('bic' in payload).toBe(false)
|
||||
expect(payload.iban).toBe('FR1420041010050500013M02606')
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapMainDraft — pre-remplissage bloc principal (companyName + categories, pas de relation M2)', () => {
|
||||
it('extrait companyName et les IRI de categories', () => {
|
||||
const draft = mapMainDraft({
|
||||
'@id': '/api/suppliers/85', id: 85,
|
||||
companyName: 'DOD862875',
|
||||
categories: [{ '@id': '/api/categories/2279', code: 'NEGOCIANT' }],
|
||||
} as SupplierDetail)
|
||||
expect(draft.companyName).toBe('DOD862875')
|
||||
expect(draft.categoryIris).toEqual(['/api/categories/2279'])
|
||||
})
|
||||
|
||||
it('gere les cles omises (skip_null_values) sans planter', () => {
|
||||
const draft = mapMainDraft({ '@id': '/api/suppliers/2', id: 2 } as SupplierDetail)
|
||||
expect(draft.companyName).toBeNull()
|
||||
expect(draft.categoryIris).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapInformationDraft — pre-remplissage onglet Information (+ volumeForecast M2)', () => {
|
||||
it('tronque foundedAt, stringifie employeesCount et volumeForecast', () => {
|
||||
const draft = mapInformationDraft({
|
||||
'@id': '/api/suppliers/85', id: 85,
|
||||
foundedAt: '2008-04-01T00:00:00+02:00', employeesCount: 42, volumeForecast: 8000,
|
||||
} as SupplierDetail)
|
||||
expect(draft.foundedAt).toBe('2008-04-01')
|
||||
expect(draft.employeesCount).toBe('42')
|
||||
expect(draft.volumeForecast).toBe('8000')
|
||||
})
|
||||
|
||||
it('cles omises -> null (volumeForecast inclus)', () => {
|
||||
const draft = mapInformationDraft({ '@id': '/api/suppliers/1', id: 1 } as SupplierDetail)
|
||||
expect(draft.foundedAt).toBeNull()
|
||||
expect(draft.employeesCount).toBeNull()
|
||||
expect(draft.volumeForecast).toBeNull()
|
||||
expect(draft.description).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('mapAccountingFormDraft — pre-remplissage onglet Comptabilite', () => {
|
||||
it('extrait les scalaires et les IRI des referentiels embarques', () => {
|
||||
const draft = mapAccountingFormDraft({
|
||||
'@id': '/api/suppliers/85', id: 85,
|
||||
siren: '123456789', accountNumber: 'F0001', nTva: 'FR00123456789',
|
||||
tvaMode: { '@id': '/api/tva_modes/30', label: 'France (ventes)' },
|
||||
paymentType: '/api/payment_types/14',
|
||||
} as SupplierDetail)
|
||||
expect(draft.siren).toBe('123456789')
|
||||
expect(draft.tvaModeIri).toBe('/api/tva_modes/30')
|
||||
expect(draft.paymentTypeIri).toBe('/api/payment_types/14')
|
||||
expect(draft.bankIri).toBeNull()
|
||||
})
|
||||
|
||||
it('cles comptables absentes (gating par omission) -> scalaires/IRI null', () => {
|
||||
const draft = mapAccountingFormDraft({ '@id': '/api/suppliers/1', id: 1 } as SupplierDetail)
|
||||
expect(draft.siren).toBeNull()
|
||||
expect(draft.tvaModeIri).toBeNull()
|
||||
expect(draft.bankIri).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveTabEditability — gating par role (matrice § 2.7)', () => {
|
||||
it('Admin : tout editable', () => {
|
||||
expect(resolveTabEditability({ canManage: true, canAccountingView: true, canAccountingManage: true }))
|
||||
.toEqual({ businessEditable: true, accountingVisible: true, accountingEditable: true })
|
||||
})
|
||||
|
||||
it('Bureau / Commerciale (manage seul) : metier editable, Comptabilite masquee', () => {
|
||||
expect(resolveTabEditability({ canManage: true, canAccountingView: false, canAccountingManage: false }))
|
||||
.toEqual({ businessEditable: true, accountingVisible: false, accountingEditable: false })
|
||||
})
|
||||
|
||||
it('Compta (accounting seul) : metier readonly, Comptabilite editable', () => {
|
||||
expect(resolveTabEditability({ canManage: false, canAccountingView: true, canAccountingManage: true }))
|
||||
.toEqual({ businessEditable: false, accountingVisible: true, accountingEditable: true })
|
||||
})
|
||||
|
||||
it('Sans permission d\'edition : rien d\'editable', () => {
|
||||
expect(resolveTabEditability({ canManage: false, canAccountingView: false, canAccountingManage: false }))
|
||||
.toEqual({ businessEditable: false, accountingVisible: false, accountingEditable: false })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,190 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
buildSupplierFormTabKeys,
|
||||
hasAtLeastOneValidContact,
|
||||
isAddressValid,
|
||||
isBankRequiredForPaymentType,
|
||||
isBlankRow,
|
||||
isContactBlank,
|
||||
isContactNamed,
|
||||
isRibBlank,
|
||||
isRibComplete,
|
||||
isRibRequiredForPaymentType,
|
||||
lastFillableTabKey,
|
||||
omitEmptyRequired,
|
||||
type AddressValidityDraft,
|
||||
type ContactDraft,
|
||||
type ContactFillableDraft,
|
||||
} from '../supplierFormRules'
|
||||
|
||||
/** Bloc contact totalement vide (amorce par defaut). */
|
||||
function blankContact(): ContactFillableDraft {
|
||||
return {
|
||||
firstName: null,
|
||||
lastName: null,
|
||||
jobTitle: null,
|
||||
phonePrimary: null,
|
||||
phoneSecondary: null,
|
||||
email: null,
|
||||
}
|
||||
}
|
||||
|
||||
describe('buildSupplierFormTabKeys (gating onglet Comptabilite + onglets edit-only)', () => {
|
||||
it('inclut l onglet accounting si l utilisateur a accounting.view', () => {
|
||||
expect(buildSupplierFormTabKeys(true)).toContain('accounting')
|
||||
})
|
||||
|
||||
it('exclut l onglet accounting sinon (Bureau / Commerciale)', () => {
|
||||
expect(buildSupplierFormTabKeys(false)).not.toContain('accounting')
|
||||
})
|
||||
|
||||
it('a la creation, ordre = information / contacts / addresses / transport (+ accounting si vu)', () => {
|
||||
expect(buildSupplierFormTabKeys(true)).toEqual(['information', 'contacts', 'addresses', 'transport', 'accounting'])
|
||||
expect(buildSupplierFormTabKeys(false)).toEqual(['information', 'contacts', 'addresses', 'transport'])
|
||||
})
|
||||
|
||||
it('a la creation, exclut Statistiques / Rapports / Echanges', () => {
|
||||
const keys = buildSupplierFormTabKeys(true)
|
||||
expect(keys).not.toContain('statistics')
|
||||
expect(keys).not.toContain('reports')
|
||||
expect(keys).not.toContain('exchanges')
|
||||
})
|
||||
|
||||
it('en modification (includeEditOnlyTabs), ajoute les onglets edit-only en fin', () => {
|
||||
expect(buildSupplierFormTabKeys(true, { includeEditOnlyTabs: true })).toEqual([
|
||||
'information', 'contacts', 'addresses', 'transport', 'accounting', 'statistics', 'reports', 'exchanges',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('lastFillableTabKey (redirection fin d\'ajout, role-aware)', () => {
|
||||
it('addresses pour un role sans Comptabilite (Bureau / Commerciale)', () => {
|
||||
expect(lastFillableTabKey(buildSupplierFormTabKeys(false))).toBe('addresses')
|
||||
})
|
||||
|
||||
it('accounting pour un role avec accounting.view (Admin)', () => {
|
||||
expect(lastFillableTabKey(buildSupplierFormTabKeys(true))).toBe('accounting')
|
||||
})
|
||||
|
||||
it('ignore les onglets placeholder (Transport en dernier ne compte pas)', () => {
|
||||
expect(lastFillableTabKey(['information', 'contacts', 'addresses', 'transport'])).toBe('addresses')
|
||||
})
|
||||
|
||||
it('undefined si aucun onglet remplissable (que des placeholders)', () => {
|
||||
expect(lastFillableTabKey(['transport', 'statistics'])).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isContactNamed (RG-2.04)', () => {
|
||||
it('vrai si le prenom ou le nom est renseigne', () => {
|
||||
expect(isContactNamed({ firstName: 'Alice', lastName: null })).toBe(true)
|
||||
expect(isContactNamed({ firstName: null, lastName: 'Martin' })).toBe(true)
|
||||
})
|
||||
|
||||
it('faux si les deux sont vides ou espaces uniquement', () => {
|
||||
expect(isContactNamed({ firstName: null, lastName: null })).toBe(false)
|
||||
expect(isContactNamed({ firstName: ' ', lastName: '' })).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('hasAtLeastOneValidContact (RG-2.13)', () => {
|
||||
it('faux sur une liste vide ou sans contact nomme', () => {
|
||||
expect(hasAtLeastOneValidContact([])).toBe(false)
|
||||
const contacts: ContactDraft[] = [{ firstName: null, lastName: null }, { firstName: '', lastName: ' ' }]
|
||||
expect(hasAtLeastOneValidContact(contacts)).toBe(false)
|
||||
})
|
||||
|
||||
it('vrai des qu un contact a un nom ou un prenom', () => {
|
||||
expect(hasAtLeastOneValidContact([{ firstName: null, lastName: null }, { firstName: 'Bob', lastName: null }])).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isBlankRow / isContactBlank / isRibBlank (blocs vides vs partiels)', () => {
|
||||
it('isBlankRow vrai si toutes les valeurs sont vides', () => {
|
||||
expect(isBlankRow([null, undefined, '', ' '])).toBe(true)
|
||||
expect(isBlankRow([null, 'x', ''])).toBe(false)
|
||||
})
|
||||
|
||||
it('isContactBlank faux si un email seul est saisi (bloc a soumettre -> 422 RG-2.04 inline)', () => {
|
||||
expect(isContactBlank(blankContact())).toBe(true)
|
||||
expect(isContactBlank({ ...blankContact(), email: 'jean@acme.fr' })).toBe(false)
|
||||
})
|
||||
|
||||
it('isRibBlank faux si un IBAN seul est saisi (bloc a soumettre -> 422 NotBlank inline)', () => {
|
||||
expect(isRibBlank({ label: null, bic: null, iban: null })).toBe(true)
|
||||
expect(isRibBlank({ label: null, bic: null, iban: 'FR1420041010050500013M02606' })).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isRibComplete (gating « + RIB » + RG-2.08)', () => {
|
||||
it('vrai quand label + BIC + IBAN sont remplis', () => {
|
||||
expect(isRibComplete({ label: 'Compte courant', bic: 'BNPAFRPP', iban: 'FR1420041010050500013M02606' })).toBe(true)
|
||||
})
|
||||
|
||||
it('faux si un champ manque', () => {
|
||||
expect(isRibComplete({ label: null, bic: 'BNPAFRPP', iban: 'FR14...' })).toBe(false)
|
||||
expect(isRibComplete({ label: 'Compte', bic: ' ', iban: 'FR14...' })).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('regles type de reglement (RG-2.07 / RG-2.08)', () => {
|
||||
it('banque obligatoire si VIREMENT', () => {
|
||||
expect(isBankRequiredForPaymentType('VIREMENT')).toBe(true)
|
||||
expect(isBankRequiredForPaymentType('LCR')).toBe(false)
|
||||
expect(isBankRequiredForPaymentType(null)).toBe(false)
|
||||
})
|
||||
|
||||
it('RIB obligatoire si LCR', () => {
|
||||
expect(isRibRequiredForPaymentType('LCR')).toBe(true)
|
||||
expect(isRibRequiredForPaymentType('VIREMENT')).toBe(false)
|
||||
expect(isRibRequiredForPaymentType(null)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isAddressValid (enum addressType, RG-2.06/2.09/2.10 ; pas d\'email facturation)', () => {
|
||||
function validAddress(): AddressValidityDraft {
|
||||
return {
|
||||
addressType: 'DEPART',
|
||||
categoryIris: ['/api/categories/1'],
|
||||
siteIris: ['/api/sites/1'],
|
||||
}
|
||||
}
|
||||
|
||||
it('vrai quand type + >= 1 site + >= 1 categorie', () => {
|
||||
expect(isAddressValid(validAddress())).toBe(true)
|
||||
})
|
||||
|
||||
it('faux si le type d\'adresse n\'est pas renseigne (amorce vierge)', () => {
|
||||
expect(isAddressValid({ ...validAddress(), addressType: null })).toBe(false)
|
||||
})
|
||||
|
||||
it('faux si aucun site (RG-2.06)', () => {
|
||||
expect(isAddressValid({ ...validAddress(), siteIris: [] })).toBe(false)
|
||||
})
|
||||
|
||||
it('faux si aucune categorie (RG-2.10)', () => {
|
||||
expect(isAddressValid({ ...validAddress(), categoryIris: [] })).toBe(false)
|
||||
})
|
||||
|
||||
it('accepte les trois valeurs d\'enum PROSPECT / DEPART / RENDU', () => {
|
||||
for (const type of ['PROSPECT', 'DEPART', 'RENDU'] as const) {
|
||||
expect(isAddressValid({ ...validAddress(), addressType: type })).toBe(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('omitEmptyRequired (ERP-119 : 422 NotBlank au lieu de 400 de type)', () => {
|
||||
it('retire les cles requises vides et conserve le reste', () => {
|
||||
const payload = omitEmptyRequired(
|
||||
{ companyName: null, sites: ['/api/sites/1'] },
|
||||
['companyName'],
|
||||
)
|
||||
expect('companyName' in payload).toBe(false)
|
||||
expect(payload.sites).toEqual(['/api/sites/1'])
|
||||
})
|
||||
|
||||
it('false / 0 ne sont pas consideres vides (booleens / nombres preserves)', () => {
|
||||
const payload = omitEmptyRequired({ triageProvider: false, bennes: 0 }, ['triageProvider', 'bennes'])
|
||||
expect(payload).toEqual({ triageProvider: false, bennes: 0 })
|
||||
})
|
||||
})
|
||||
@@ -63,9 +63,16 @@ export interface AddressRead extends HydraRef {
|
||||
street?: string | null
|
||||
streetComplement?: string | null
|
||||
billingEmail?: string | null
|
||||
billingEmailSecondary?: string | null
|
||||
isProspect?: boolean
|
||||
isDelivery?: boolean
|
||||
isBilling?: boolean
|
||||
isBroker?: boolean
|
||||
isDistributor?: boolean
|
||||
/** Geolocalisation (M6.1) : chaines decimales NUMERIC(10,7) cote API. */
|
||||
latitude?: string | null
|
||||
longitude?: string | null
|
||||
geoManual?: boolean
|
||||
sites?: SiteRead[]
|
||||
categories?: CategoryRead[]
|
||||
// L'embed M2M des contacts d'adresse peut etre un objet (partiel) ou un IRI nu.
|
||||
@@ -209,6 +216,8 @@ export function mapAddressToDraft(address: AddressRead): AddressFormDraft {
|
||||
isProspect: address.isProspect ?? false,
|
||||
isDelivery: address.isDelivery ?? false,
|
||||
isBilling: address.isBilling ?? false,
|
||||
isBroker: address.isBroker ?? false,
|
||||
isDistributor: address.isDistributor ?? false,
|
||||
country: address.country ?? 'France',
|
||||
postalCode: address.postalCode ?? null,
|
||||
city: address.city ?? null,
|
||||
@@ -218,6 +227,11 @@ export function mapAddressToDraft(address: AddressRead): AddressFormDraft {
|
||||
siteIris: (address.sites ?? []).map(s => s['@id']),
|
||||
contactIris: (address.contacts ?? []).map(c => (typeof c === 'string' ? c : c['@id'])),
|
||||
billingEmail: address.billingEmail ?? null,
|
||||
billingEmailSecondary: address.billingEmailSecondary ?? null,
|
||||
hasSecondaryBillingEmail: (address.billingEmailSecondary ?? null) !== null && address.billingEmailSecondary !== '',
|
||||
latitude: address.latitude ?? null,
|
||||
longitude: address.longitude ?? null,
|
||||
geoManual: address.geoManual === true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +300,21 @@ export function referentialOptionOf(relation: Relation): SelectOption[] {
|
||||
return [{ value: relation['@id'], label }]
|
||||
}
|
||||
|
||||
/**
|
||||
* Code metier d'un referentiel embarque (ex: PaymentType.code = 'LCR' / 'VIREMENT'),
|
||||
* ou null si la relation est absente / serialisee en IRI nu. Type-safe : la branche
|
||||
* chaine (IRI nu) et l'absence sont court-circuitees avant l'acces au code. Sert a
|
||||
* conditionner l'affichage selon le type de reglement courant (ERP-121 : RIB masques
|
||||
* hors-LCR en consultation).
|
||||
*/
|
||||
export function paymentTypeCodeOf(relation: Relation): string | null {
|
||||
if (!relation || typeof relation === 'string') {
|
||||
return null
|
||||
}
|
||||
|
||||
return (relation.code as string | undefined) ?? null
|
||||
}
|
||||
|
||||
/** Vue d'une adresse (brouillon + options de select propres a l'adresse). */
|
||||
export function mapAddressView(address: AddressRead): AddressView {
|
||||
return {
|
||||
|
||||
@@ -12,10 +12,8 @@
|
||||
*
|
||||
* Ces helpers ne touchent ni a l'API ni a l'etat reactif.
|
||||
*
|
||||
* NOTE RG-1.04 (Information obligatoire pour la Commerciale) : volontairement NON
|
||||
* miroitee cote front (cf. clientFormRules.ts) — /api/me n'expose pas le code de
|
||||
* role et Bureau partage les permissions de Commerciale. Le back l'applique de
|
||||
* maniere fiable (422) ; on laisse remonter ce 422 en toast.
|
||||
* NOTE : l'onglet Information est facultatif pour tous les roles (RG-1.04
|
||||
* « Information obligatoire pour la Commerciale » retiree cote back).
|
||||
*/
|
||||
|
||||
import {
|
||||
@@ -23,6 +21,13 @@ import {
|
||||
relationOf,
|
||||
type ClientDetail,
|
||||
} from '~/modules/commercial/utils/clientConsultation'
|
||||
import {
|
||||
ADDRESS_REQUIRED_NON_NULLABLE_KEYS,
|
||||
blankEmptyRequired,
|
||||
MAIN_REQUIRED_NON_NULLABLE_KEYS,
|
||||
omitEmptyRequired,
|
||||
RIB_REQUIRED_NON_NULLABLE_KEYS,
|
||||
} from '~/modules/commercial/utils/clientFormRules'
|
||||
import type { AddressFormDraft, ContactFormDraft, RibFormDraft } from '~/modules/commercial/types/clientForm'
|
||||
|
||||
/**
|
||||
@@ -135,19 +140,50 @@ export function mapAccountingFormDraft(client: ClientDetail): AccountingFormDraf
|
||||
|
||||
// ── Scoping strict des payloads PATCH ────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Options de construction d'un payload d'ecriture.
|
||||
* - `forUpdate: false` (defaut, CREATION/POST) : champs requis vides OMIS -> 422
|
||||
* NotBlank (le back ne reçoit pas la cle, la propriete garde son defaut).
|
||||
* - `forUpdate: true` (EDITION/PATCH d'une ligne existante) : champs requis vides
|
||||
* envoyes en `''` -> 422 NotBlank (sinon une cle omise laisse la valeur serveur
|
||||
* inchangee, faux 200 — cf. blankEmptyRequired).
|
||||
*/
|
||||
export interface BuildPayloadOptions {
|
||||
forUpdate?: boolean
|
||||
}
|
||||
|
||||
/** Selectionne le finaliseur des champs requis selon création (omit) vs édition (blank). */
|
||||
function finalizeRequired<T extends Record<string, unknown>>(
|
||||
payload: T,
|
||||
requiredKeys: readonly string[],
|
||||
options: BuildPayloadOptions,
|
||||
): T {
|
||||
return options.forUpdate
|
||||
? blankEmptyRequired(payload, requiredKeys)
|
||||
: omitEmptyRequired(payload, requiredKeys)
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload du bloc principal — groupe client:write:main UNIQUEMENT. La relation
|
||||
* Distributeur/Courtier est mutuellement exclusive (RG-1.03) : on ne renseigne
|
||||
* que la FK correspondant au type choisi, l'autre est forcee a null.
|
||||
*/
|
||||
export function buildMainPayload(main: MainFormDraft): Record<string, unknown> {
|
||||
return {
|
||||
export function buildMainPayload(main: MainFormDraft, options: BuildPayloadOptions = {}): Record<string, unknown> {
|
||||
// companyName omis si vide -> 422 NotBlank au lieu d'un 400 de type (ERP-119).
|
||||
// relationType : champ transitoire (non persiste cote back) qui porte
|
||||
// l'intention UI « ce client depend d'un distributeur / courtier ». Il sert
|
||||
// a la validation croisee serveur (RG-1.03 bis) : si une relation est choisie,
|
||||
// la FK correspondante devient obligatoire -> 422 sur distributor / broker.
|
||||
// Sans equivalent derivable cote back (FK nullable), c'est la seule facon de
|
||||
// rester sur « on soumet, le back tranche » plutot qu'une garde front-only.
|
||||
return finalizeRequired({
|
||||
companyName: main.companyName,
|
||||
categories: main.categoryIris,
|
||||
relationType: main.relationType,
|
||||
distributor: main.relationType === 'distributeur' ? main.distributorIri : null,
|
||||
broker: main.relationType === 'courtier' ? main.brokerIri : null,
|
||||
triageService: main.triageService,
|
||||
}
|
||||
}, MAIN_REQUIRED_NON_NULLABLE_KEYS, options)
|
||||
}
|
||||
|
||||
/** Payload de l'onglet Information — groupe client:write:information UNIQUEMENT. */
|
||||
@@ -199,11 +235,15 @@ export function buildContactPayload(contact: ContactFormDraft): Record<string, u
|
||||
export function buildAddressPayload(
|
||||
address: AddressFormDraft,
|
||||
isBillingEmailRequired: boolean,
|
||||
options: BuildPayloadOptions = {},
|
||||
): Record<string, unknown> {
|
||||
return {
|
||||
// postalCode / city / street : omis a la creation, `''` en edition -> 422 NotBlank (ERP-119).
|
||||
return finalizeRequired({
|
||||
isProspect: address.isProspect,
|
||||
isDelivery: address.isDelivery,
|
||||
isBilling: address.isBilling,
|
||||
isBroker: address.isBroker,
|
||||
isDistributor: address.isDistributor,
|
||||
country: address.country,
|
||||
postalCode: address.postalCode || null,
|
||||
city: address.city || null,
|
||||
@@ -213,16 +253,24 @@ export function buildAddressPayload(
|
||||
sites: address.siteIris,
|
||||
contacts: address.contactIris,
|
||||
billingEmail: isBillingEmailRequired ? (address.billingEmail || null) : null,
|
||||
}
|
||||
billingEmailSecondary: isBillingEmailRequired && address.hasSecondaryBillingEmail ? (address.billingEmailSecondary || null) : null,
|
||||
// Geolocalisation (M6.1) : pin manuel persiste avec geoManual=true ;
|
||||
// geoManual=false laisse le back regeocoder depuis l'adresse postale.
|
||||
latitude: address.latitude || null,
|
||||
longitude: address.longitude || null,
|
||||
geoManual: address.geoManual,
|
||||
}, ADDRESS_REQUIRED_NON_NULLABLE_KEYS, options)
|
||||
}
|
||||
|
||||
/** Payload d'un RIB (sous-ressource client_rib). */
|
||||
export function buildRibPayload(rib: RibFormDraft): Record<string, unknown> {
|
||||
return {
|
||||
export function buildRibPayload(rib: RibFormDraft, options: BuildPayloadOptions = {}): Record<string, unknown> {
|
||||
// label / bic / iban : omis a la creation, `''` en edition -> 422 NotBlank au lieu
|
||||
// d'un 400 de type (ou d'un faux 200 PATCH qui garderait l'ancienne valeur). ERP-119.
|
||||
return finalizeRequired({
|
||||
label: rib.label,
|
||||
bic: rib.bic,
|
||||
iban: rib.iban,
|
||||
}
|
||||
}, RIB_REQUIRED_NON_NULLABLE_KEYS, options)
|
||||
}
|
||||
|
||||
// ── Gating par permission ────────────────────────────────────────────────────
|
||||
|
||||
@@ -9,12 +9,9 @@
|
||||
* Le back reste la source de verite (les RG sont re-validees serveur) ; ces
|
||||
* regles ne servent qu'au feedback UI immediat (gating de boutons, visibilite).
|
||||
*
|
||||
* NOTE RG-1.04 (Information obligatoire pour la Commerciale) : volontairement
|
||||
* NON miroite cote front pour l'instant. Le payload /api/me ne porte pas le code
|
||||
* de role (roles = IRIs opaques) et Bureau partage les memes permissions que
|
||||
* Commerciale : aucun signal fiable pour distinguer le role cote front. Le back
|
||||
* (ClientProcessor, via BusinessRoleAware) applique la regle de maniere fiable ;
|
||||
* a rebrancher ici des qu'un code de role sera expose dans /api/me.
|
||||
* NOTE : l'onglet Information est facultatif pour tous les roles. L'ancienne
|
||||
* RG-1.04 (« Information obligatoire pour la Commerciale ») a ete retiree cote
|
||||
* back — rien a miroiter ici.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -53,6 +50,38 @@ export function buildClientFormTabKeys(
|
||||
return keys
|
||||
}
|
||||
|
||||
/**
|
||||
* Dernier onglet REMPLISSABLE d'un jeu d'onglets : le dernier qui n'est pas un
|
||||
* placeholder (coquille). Role-aware sans regle ad hoc — il suffit de lui passer
|
||||
* les `tabKeys` deja filtres par permission (l'onglet Comptabilite n'y figure que
|
||||
* si accounting.view). Sa validation marque la fin de l'ajout (redirection liste).
|
||||
*/
|
||||
export function lastFillableTabKey(tabKeys: string[]): string | undefined {
|
||||
return [...tabKeys].reverse().find(
|
||||
key => !(CLIENT_FORM_PLACEHOLDER_TABS as readonly string[]).includes(key),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Codes de categorie « intermediaire » : un client dont la categorie est
|
||||
* Distributeur ou Courtier n'a ni relation amont (il EST le distributeur /
|
||||
* courtier) ni prestation de triage. Sert a conditionner l'affichage des champs
|
||||
* « Relation » et « Prestation de triage » du formulaire principal.
|
||||
*/
|
||||
export const DISTRIBUTOR_BROKER_CATEGORY_CODES = ['DISTRIBUTEUR', 'COURTIER'] as const
|
||||
|
||||
/**
|
||||
* Vrai des qu'au moins une categorie « ordinaire » (autre que Distributeur /
|
||||
* Courtier) est selectionnee. Les champs « Relation » (depend du distributeur /
|
||||
* courtier) et « Prestation de triage » du formulaire principal sont masques par
|
||||
* defaut et reveles uniquement dans ce cas.
|
||||
*/
|
||||
export function showsRelationAndTriageFields(selectedCategoryCodes: string[]): boolean {
|
||||
return selectedCategoryCodes.some(
|
||||
code => !(DISTRIBUTOR_BROKER_CATEGORY_CODES as readonly string[]).includes(code),
|
||||
)
|
||||
}
|
||||
|
||||
/** Sous-ensemble d'un contact necessaire aux regles de nommage (RG-1.05/1.14). */
|
||||
export interface ContactDraft {
|
||||
firstName: string | null
|
||||
@@ -64,6 +93,10 @@ export interface AddressFlagsDraft {
|
||||
isProspect: boolean
|
||||
isDelivery: boolean
|
||||
isBilling: boolean
|
||||
/** Adresse Courtier — type autonome exclusif (comme isProspect). */
|
||||
isBroker: boolean
|
||||
/** Adresse Distributeur — type autonome exclusif (comme isProspect). */
|
||||
isDistributor: boolean
|
||||
}
|
||||
|
||||
/** Vrai si une chaine porte au moins un caractere non-espace. */
|
||||
@@ -138,6 +171,16 @@ export function isRibBlank(rib: RibFillableDraft): boolean {
|
||||
return isBlankRow([rib.label, rib.bic, rib.iban])
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-1.13 : un RIB est complet quand ses trois champs sont remplis (label, BIC,
|
||||
* IBAN). Predicat par-bloc partage entre le gating du bouton « + RIB » (le
|
||||
* dernier bloc doit etre complet avant d'en ajouter un autre) et la validation
|
||||
* de l'onglet (au moins un RIB complet si reglement LCR).
|
||||
*/
|
||||
export function isRibComplete(rib: RibFillableDraft): boolean {
|
||||
return isFilled(rib.label) && isFilled(rib.bic) && isFilled(rib.iban)
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-1.06/07/08 : une adresse de prospection est exclusive d'une adresse de
|
||||
* livraison/facturation. Prospect n'est selectionnable que si ni Livraison ni
|
||||
@@ -193,22 +236,30 @@ export function isBillingEmailRequired(flags: AddressFlagsDraft): boolean {
|
||||
* drapeaux isProspect / isDelivery / isBilling (aucune RG modifiee). Les seules
|
||||
* combinaisons proposees respectent l'exclusivite Prospect (RG-1.06/07/08).
|
||||
*/
|
||||
export type AddressType = 'prospect' | 'delivery' | 'billing' | 'delivery_billing'
|
||||
export type AddressType = 'prospect' | 'delivery' | 'billing' | 'delivery_billing' | 'broker' | 'distributor'
|
||||
|
||||
/**
|
||||
* Mappe le type d'adresse choisi vers les trois drapeaux back.
|
||||
* Mappe le type d'adresse choisi vers les cinq drapeaux back.
|
||||
* « Adresse + Facturation » = livraison ET facturation sur la meme adresse.
|
||||
* Courtier / Distributeur sont autonomes (un seul drapeau, exclusif du reste).
|
||||
*/
|
||||
export function addressFlagsFromType(type: AddressType): AddressFlagsDraft {
|
||||
const none: AddressFlagsDraft = {
|
||||
isProspect: false, isDelivery: false, isBilling: false, isBroker: false, isDistributor: false,
|
||||
}
|
||||
switch (type) {
|
||||
case 'prospect':
|
||||
return { isProspect: true, isDelivery: false, isBilling: false }
|
||||
return { ...none, isProspect: true }
|
||||
case 'delivery':
|
||||
return { isProspect: false, isDelivery: true, isBilling: false }
|
||||
return { ...none, isDelivery: true }
|
||||
case 'billing':
|
||||
return { isProspect: false, isDelivery: false, isBilling: true }
|
||||
return { ...none, isBilling: true }
|
||||
case 'delivery_billing':
|
||||
return { isProspect: false, isDelivery: true, isBilling: true }
|
||||
return { ...none, isDelivery: true, isBilling: true }
|
||||
case 'broker':
|
||||
return { ...none, isBroker: true }
|
||||
case 'distributor':
|
||||
return { ...none, isDistributor: true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +270,8 @@ export function addressFlagsFromType(type: AddressType): AddressFlagsDraft {
|
||||
*/
|
||||
export function addressTypeFromFlags(flags: AddressFlagsDraft): AddressType | null {
|
||||
if (flags.isProspect) return 'prospect'
|
||||
if (flags.isBroker) return 'broker'
|
||||
if (flags.isDistributor) return 'distributor'
|
||||
if (flags.isDelivery && flags.isBilling) return 'delivery_billing'
|
||||
if (flags.isDelivery) return 'delivery'
|
||||
if (flags.isBilling) return 'billing'
|
||||
@@ -226,6 +279,31 @@ export function addressTypeFromFlags(flags: AddressFlagsDraft): AddressType | nu
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Sous-ensemble d'une adresse necessaire a sa validite par-bloc : drapeaux
|
||||
* d'usage (pour le type + l'email de facturation conditionnel), sites et
|
||||
* categories rattaches, email de facturation.
|
||||
*/
|
||||
export interface AddressValidityDraft extends AddressFlagsDraft {
|
||||
categoryIris: string[]
|
||||
siteIris: string[]
|
||||
billingEmail: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Validite par-bloc d'une adresse : type renseigne (RG-1.06/07/08), >= 1 site
|
||||
* (RG-1.10), >= 1 categorie, et email de facturation rempli si l'adresse est de
|
||||
* facturation (RG-1.11). Predicat partage entre le gating du bouton « + Adresse »
|
||||
* (le dernier bloc doit etre valide avant d'en ajouter un autre) et la
|
||||
* validation de l'onglet (toutes les adresses valides).
|
||||
*/
|
||||
export function isAddressValid(address: AddressValidityDraft): boolean {
|
||||
return addressTypeFromFlags(address) !== null
|
||||
&& address.siteIris.length >= 1
|
||||
&& address.categoryIris.length >= 1
|
||||
&& (!isBillingEmailRequired(address) || isFilled(address.billingEmail))
|
||||
}
|
||||
|
||||
/** Code stable du type de reglement « virement » (cf. PaymentType.code, RG-1.12). */
|
||||
const PAYMENT_TYPE_TRANSFER = 'VIREMENT'
|
||||
|
||||
@@ -248,6 +326,36 @@ export function isRibRequiredForPaymentType(code: string | null | undefined): bo
|
||||
return code === PAYMENT_TYPE_LCR
|
||||
}
|
||||
|
||||
/** Champs saisissables de l'onglet Information (tous facultatifs). */
|
||||
export interface InformationFieldsDraft {
|
||||
description: string | null
|
||||
competitors: string | null
|
||||
foundedAt: string | null
|
||||
employeesCount: string | null
|
||||
revenueAmount: string | null
|
||||
profitAmount: string | null
|
||||
directorName: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrai si au moins un champ de l'onglet Information est rempli. L'onglet est
|
||||
* facultatif (aucun champ obligatoire), mais on n'autorise pas une validation
|
||||
* « a vide » a la creation : sans donnee, rien a enregistrer, l'utilisateur
|
||||
* passe directement a l'onglet Contact. (En edition, vider tous les champs reste
|
||||
* une action legitime : ce gate n'y est pas applique.)
|
||||
*/
|
||||
export function hasAtLeastOneInformationField(information: InformationFieldsDraft): boolean {
|
||||
return !isBlankRow([
|
||||
information.description,
|
||||
information.competitors,
|
||||
information.foundedAt,
|
||||
information.employeesCount,
|
||||
information.revenueAmount,
|
||||
information.profitAmount,
|
||||
information.directorName,
|
||||
])
|
||||
}
|
||||
|
||||
/** Sous-ensemble du brouillon comptable portant les six champs obligatoires. */
|
||||
export interface AccountingRequiredDraft {
|
||||
siren: string | null
|
||||
@@ -276,3 +384,63 @@ export function hasAllRequiredAccountingFields(accounting: AccountingRequiredDra
|
||||
&& filled(accounting.paymentDelayIri)
|
||||
&& filled(accounting.paymentTypeIri)
|
||||
}
|
||||
|
||||
// ── Champs requis adosses a une colonne NON-nullable (ERP-119) ───────────────
|
||||
// Ces champs requis (NotBlank back) sont portes par une colonne Doctrine NON
|
||||
// nullable. Si le front envoie `null` (champ vide, desormais possible : le bouton
|
||||
// « Valider » n'est plus desactive), API Platform rejette la valeur en 400 de TYPE
|
||||
// a la deserialisation (« The type of the X attribute must be string, NULL given »)
|
||||
// AVANT le Validator -> pas de violation, donc pas d'erreur rouge cote champ.
|
||||
// La parade : OMETTRE la cle du payload quand elle est vide. Sans la cle, la
|
||||
// propriete garde son defaut null cote entite et #[Assert\NotBlank] se declenche
|
||||
// normalement -> 422 avec propertyPath, mappee en rouge sous le champ.
|
||||
// (Les champs requis a colonne NULLABLE — contacts, scalaires compta — acceptent
|
||||
// deja `null` et renvoient une 422 : inutile de les omettre.)
|
||||
export const MAIN_REQUIRED_NON_NULLABLE_KEYS = ['companyName'] as const
|
||||
export const ADDRESS_REQUIRED_NON_NULLABLE_KEYS = ['postalCode', 'city', 'street'] as const
|
||||
export const RIB_REQUIRED_NON_NULLABLE_KEYS = ['label', 'bic', 'iban'] as const
|
||||
|
||||
/**
|
||||
* Retire d'un payload d'ecriture les cles requises laissees vides (null / ''
|
||||
* / undefined), pour laisser le back produire une 422 NotBlank par champ plutot
|
||||
* qu'un 400 de type sur une colonne non-nullable. Mute et retourne le payload.
|
||||
* A n'appliquer QU'aux cles ci-dessus (champs requis a colonne non-nullable).
|
||||
*/
|
||||
export function omitEmptyRequired<T extends Record<string, unknown>>(
|
||||
payload: T,
|
||||
requiredKeys: readonly string[],
|
||||
): T {
|
||||
for (const key of requiredKeys) {
|
||||
const value = payload[key]
|
||||
if (value === null || value === undefined || value === '') {
|
||||
delete payload[key]
|
||||
}
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
/**
|
||||
* Variante PATCH (edition d'une ligne EXISTANTE) : remplace les cles requises
|
||||
* laissees vides par une chaine vide `''` au lieu de les OMETTRE.
|
||||
*
|
||||
* Pourquoi pas `omitEmptyRequired` en edition : un PATCH a semantique merge — une
|
||||
* cle absente laisse la valeur serveur INCHANGEE. Vider un champ requis puis valider
|
||||
* renverrait alors un 200 trompeur (l'ancienne valeur est conservee). En envoyant
|
||||
* `''` (chaine valide), on evite le 400 de type (« must be string, NULL given ») et
|
||||
* le Validator `NotBlank(trim)` rejette la valeur -> 422 avec propertyPath, mappee
|
||||
* inline sous le champ. Mute et retourne le payload.
|
||||
*/
|
||||
export function blankEmptyRequired<T extends Record<string, unknown>>(
|
||||
payload: T,
|
||||
requiredKeys: readonly string[],
|
||||
): T {
|
||||
for (const key of requiredKeys) {
|
||||
const value = payload[key]
|
||||
if (value === null || value === undefined || value === '') {
|
||||
(payload as Record<string, unknown>)[key] = ''
|
||||
}
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
/**
|
||||
* Helpers purs de l'ecran « Consultation fournisseur » (M2 Commercial, lecture
|
||||
* seule). Miroir de `clientConsultation.ts` (M1), adapte aux differences M2.
|
||||
*
|
||||
* Mappent le payload `GET /api/suppliers/{id}` (relations embarquees, cf. groupe
|
||||
* `supplier:item:read` + `supplier:read:accounting`) vers les brouillons « plats »
|
||||
* partages avec les blocs reutilisables `SupplierContactBlock` / `SupplierAddressBlock`
|
||||
* et l'onglet Comptabilite. Ne touchent ni a l'API ni a l'etat reactif : testables
|
||||
* unitairement (cf. supplierConsultation.spec.ts).
|
||||
*
|
||||
* Rappels de contrat back (verifies sur le JSON reel fige — ERP-92, spec-back § 4.0.bis) :
|
||||
* - les relations ManyToOne (tvaMode/paymentDelay/paymentType/bank) sont
|
||||
* serialisees en OBJETS embarques (`{id, code, label}`), pas en IRI nu ;
|
||||
* - les champs nuls sont OMIS du JSON (skip_null_values) → toujours lire avec `?? null` ;
|
||||
* - les champs comptables et `ribs` sont TOTALEMENT ABSENTS (cle omise, pas `null`)
|
||||
* sans permission accounting.view (gate serveur via SupplierReadGroupContextBuilder).
|
||||
*
|
||||
* Differences M2 vs M1 :
|
||||
* - Adresse via enum `addressType` (PROSPECT/DEPART/RENDU, RG-2.09) — pas de
|
||||
* drapeaux isProspect/isDelivery/isBilling.
|
||||
* - Adresse : champs specifiques fournisseur `bennes` (nombre) et `triageProvider`.
|
||||
* Pas d'email de facturation.
|
||||
* - Information : champ specifique fournisseur `volumeForecast`.
|
||||
* - Pas de relation Distributeur/Courtier ni de triage sur le bloc principal.
|
||||
*/
|
||||
|
||||
import { formatPhoneFR } from '~/shared/utils/phone'
|
||||
import {
|
||||
emptyAddress,
|
||||
type SupplierAddressFormDraft,
|
||||
type SupplierAddressType,
|
||||
type SupplierContactFormDraft,
|
||||
type SupplierRibFormDraft,
|
||||
} from '~/modules/commercial/types/supplierForm'
|
||||
|
||||
/** Reference Hydra embarquee minimale (@id toujours present). */
|
||||
export interface HydraRef {
|
||||
'@id': string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/** Une relation peut etre embarquee (objet), un IRI nu (chaine) ou absente. */
|
||||
export type Relation = HydraRef | string | null | undefined
|
||||
|
||||
/** Site embarque dans une adresse (groupe site:read). */
|
||||
export interface SiteRead extends HydraRef {
|
||||
name?: string
|
||||
color?: string
|
||||
}
|
||||
|
||||
/** Categorie embarquee (groupe category:read). */
|
||||
export interface CategoryRead extends HydraRef {
|
||||
code?: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
/** Contact embarque (groupe supplier_contact:read). */
|
||||
export interface ContactRead extends HydraRef {
|
||||
id: number
|
||||
firstName?: string | null
|
||||
lastName?: string | null
|
||||
jobTitle?: string | null
|
||||
phonePrimary?: string | null
|
||||
phoneSecondary?: string | null
|
||||
email?: string | null
|
||||
}
|
||||
|
||||
/** Adresse embarquee (groupe supplier_address:read). */
|
||||
export interface AddressRead extends HydraRef {
|
||||
id: number
|
||||
addressType?: SupplierAddressType | null
|
||||
country?: string | null
|
||||
postalCode?: string | null
|
||||
city?: string | null
|
||||
street?: string | null
|
||||
streetComplement?: string | null
|
||||
bennes?: number | null
|
||||
triageProvider?: boolean
|
||||
/** Geolocalisation (M6.1) : chaines decimales NUMERIC(10,7) cote API. */
|
||||
latitude?: string | null
|
||||
longitude?: string | null
|
||||
geoManual?: boolean
|
||||
sites?: SiteRead[]
|
||||
categories?: CategoryRead[]
|
||||
// L'embed M2M des contacts d'adresse peut etre un objet (partiel) ou un IRI nu.
|
||||
contacts?: Array<HydraRef | string>
|
||||
}
|
||||
|
||||
/** RIB embarque (groupe supplier:read:accounting, present ssi accounting.view). */
|
||||
export interface RibRead extends HydraRef {
|
||||
id: number
|
||||
label?: string | null
|
||||
bic?: string | null
|
||||
iban?: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Detail d'un fournisseur tel que renvoye par `GET /api/suppliers/{id}`. Tous les
|
||||
* champs sont optionnels : skip_null_values cote serveur et gating accounting
|
||||
* peuvent omettre n'importe quelle cle.
|
||||
*/
|
||||
export interface SupplierDetail extends HydraRef {
|
||||
id: number
|
||||
companyName?: string | null
|
||||
isArchived?: boolean
|
||||
categories?: CategoryRead[]
|
||||
contacts?: ContactRead[]
|
||||
addresses?: AddressRead[]
|
||||
ribs?: RibRead[]
|
||||
// Onglet Information
|
||||
description?: string | null
|
||||
competitors?: string | null
|
||||
foundedAt?: string | null
|
||||
employeesCount?: number | null
|
||||
revenueAmount?: string | null
|
||||
profitAmount?: string | null
|
||||
directorName?: string | null
|
||||
/** Volume previsionnel (entier, specifique fournisseur). */
|
||||
volumeForecast?: number | null
|
||||
// Onglet Comptabilite (present ssi accounting.view)
|
||||
siren?: string | null
|
||||
accountNumber?: string | null
|
||||
nTva?: string | null
|
||||
tvaMode?: Relation
|
||||
paymentDelay?: Relation
|
||||
paymentType?: Relation
|
||||
bank?: Relation
|
||||
}
|
||||
|
||||
/** Etat « plat » de l'onglet Comptabilite (miroir lecture du formulaire). */
|
||||
export interface AccountingDraft {
|
||||
siren: string | null
|
||||
accountNumber: string | null
|
||||
nTva: string | null
|
||||
tvaModeIri: string | null
|
||||
paymentDelayIri: string | null
|
||||
paymentTypeIri: string | null
|
||||
bankIri: string | null
|
||||
}
|
||||
|
||||
/** Option de select ({ value, label }) construite a partir de l'embed. */
|
||||
export interface SelectOption {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
/** Option de categorie enrichie de son code (compatible CategoryOption des blocs). */
|
||||
export interface CategorySelectOption extends SelectOption {
|
||||
code: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Vue d'une adresse pour la consultation : le brouillon + ses options de select
|
||||
* construites a partir de l'embed (sites/categories propres a CETTE adresse).
|
||||
*/
|
||||
export interface AddressView {
|
||||
draft: SupplierAddressFormDraft
|
||||
siteOptions: SelectOption[]
|
||||
categoryOptions: CategorySelectOption[]
|
||||
}
|
||||
|
||||
/** Extrait l'IRI d'une relation (objet embarque, IRI nu, ou null si absente). */
|
||||
export function iriOf(relation: Relation): string | null {
|
||||
if (relation === null || relation === undefined) {
|
||||
return null
|
||||
}
|
||||
if (typeof relation === 'string') {
|
||||
return relation
|
||||
}
|
||||
return relation['@id'] ?? null
|
||||
}
|
||||
|
||||
/** Mappe un contact embarque vers un brouillon (telephones formates XX XX XX XX XX). */
|
||||
export function mapContactToDraft(contact: ContactRead): SupplierContactFormDraft {
|
||||
const phoneSecondary = contact.phoneSecondary ?? null
|
||||
return {
|
||||
id: contact.id,
|
||||
iri: contact['@id'] ?? null,
|
||||
firstName: contact.firstName ?? null,
|
||||
lastName: contact.lastName ?? null,
|
||||
jobTitle: contact.jobTitle ?? null,
|
||||
phonePrimary: contact.phonePrimary ? formatPhoneFR(contact.phonePrimary) : null,
|
||||
phoneSecondary: phoneSecondary ? formatPhoneFR(phoneSecondary) : null,
|
||||
email: contact.email ?? null,
|
||||
hasSecondaryPhone: phoneSecondary !== null && phoneSecondary !== '',
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mappe une adresse embarquee vers un brouillon (IRI extraits des sous-collections).
|
||||
* `bennes` (entier) est converti en chaine pour MalioInputNumber (defaut « 0 »).
|
||||
*/
|
||||
export function mapAddressToDraft(address: AddressRead): SupplierAddressFormDraft {
|
||||
return {
|
||||
id: address.id,
|
||||
addressType: address.addressType ?? null,
|
||||
country: address.country ?? 'France',
|
||||
postalCode: address.postalCode ?? null,
|
||||
city: address.city ?? null,
|
||||
street: address.street ?? null,
|
||||
streetComplement: address.streetComplement ?? null,
|
||||
categoryIris: (address.categories ?? []).map(c => c['@id']),
|
||||
siteIris: (address.sites ?? []).map(s => s['@id']),
|
||||
contactIris: (address.contacts ?? []).map(c => (typeof c === 'string' ? c : c['@id'])),
|
||||
bennes: address.bennes != null ? String(address.bennes) : '0',
|
||||
triageProvider: address.triageProvider ?? false,
|
||||
latitude: address.latitude ?? null,
|
||||
longitude: address.longitude ?? null,
|
||||
geoManual: address.geoManual === true,
|
||||
}
|
||||
}
|
||||
|
||||
/** Mappe un RIB embarque vers un brouillon. */
|
||||
export function mapRibToDraft(rib: RibRead): SupplierRibFormDraft {
|
||||
return {
|
||||
id: rib.id,
|
||||
label: rib.label ?? null,
|
||||
bic: rib.bic ?? null,
|
||||
iban: rib.iban ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
/** Mappe les champs comptables du fournisseur (scalaires + IRI des referentiels). */
|
||||
export function mapAccountingDraft(supplier: SupplierDetail): AccountingDraft {
|
||||
return {
|
||||
siren: supplier.siren ?? null,
|
||||
accountNumber: supplier.accountNumber ?? null,
|
||||
nTva: supplier.nTva ?? null,
|
||||
tvaModeIri: iriOf(supplier.tvaMode),
|
||||
paymentDelayIri: iriOf(supplier.paymentDelay),
|
||||
paymentTypeIri: iriOf(supplier.paymentType),
|
||||
bankIri: iriOf(supplier.bank),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options de categories (value=IRI, label=nom, code) construites depuis l'embed.
|
||||
* Source role-independante : evite de dependre de `GET /categories` (403 pour les
|
||||
* roles metier non-admin), qui laisserait les libelles vides.
|
||||
*/
|
||||
export function categoryOptionsOf(categories: CategoryRead[] | undefined): CategorySelectOption[] {
|
||||
return (categories ?? []).map(c => ({
|
||||
value: c['@id'],
|
||||
label: c.name ?? c.code ?? c['@id'],
|
||||
code: c.code ?? '',
|
||||
}))
|
||||
}
|
||||
|
||||
/** Options de sites (value=IRI, label=nom) construites depuis l'embed d'une adresse. */
|
||||
export function siteOptionsOf(sites: SiteRead[] | undefined): SelectOption[] {
|
||||
return (sites ?? []).map(s => ({ value: s['@id'], label: s.name ?? s['@id'] }))
|
||||
}
|
||||
|
||||
/** Options de contacts (value=IRI, label=nom complet ou email) depuis l'embed fournisseur. */
|
||||
export function contactOptionsOf(contacts: ContactRead[] | undefined): SelectOption[] {
|
||||
return (contacts ?? []).map(c => ({
|
||||
value: c['@id'],
|
||||
label: [c.firstName, c.lastName].filter(Boolean).join(' ') || (c.email ?? c['@id']),
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste a une seule option (ou vide) construite depuis un referentiel embarque
|
||||
* (TvaMode / PaymentDelay / PaymentType / Bank) pour alimenter un MalioSelect en
|
||||
* lecture seule. Le libelle vient de l'embed (`label` ou `name`), jamais d'un
|
||||
* `GET` de referentiel — l'affichage reste correct quel que soit le role.
|
||||
*/
|
||||
export function referentialOptionOf(relation: Relation): SelectOption[] {
|
||||
if (!relation || typeof relation === 'string') {
|
||||
return []
|
||||
}
|
||||
const label = (relation.label as string | undefined)
|
||||
?? (relation.name as string | undefined)
|
||||
?? relation['@id']
|
||||
return [{ value: relation['@id'], label }]
|
||||
}
|
||||
|
||||
/**
|
||||
* Code metier d'un referentiel embarque (ex: PaymentType.code = 'LCR' / 'VIREMENT'),
|
||||
* ou null si la relation est absente / serialisee en IRI nu. Type-safe : la branche
|
||||
* chaine (IRI nu) et l'absence sont court-circuitees avant l'acces au code. Sert a
|
||||
* conditionner l'affichage selon le type de reglement courant (ERP-121 : RIB masques
|
||||
* hors-LCR en consultation).
|
||||
*/
|
||||
export function paymentTypeCodeOf(relation: Relation): string | null {
|
||||
if (!relation || typeof relation === 'string') {
|
||||
return null
|
||||
}
|
||||
|
||||
return (relation.code as string | undefined) ?? null
|
||||
}
|
||||
|
||||
/** Vue d'une adresse (brouillon + options de select propres a l'adresse). */
|
||||
export function mapAddressView(address: AddressRead): AddressView {
|
||||
return {
|
||||
draft: mapAddressToDraft(address),
|
||||
siteOptions: siteOptionsOf(address.sites),
|
||||
categoryOptions: categoryOptionsOf(address.categories),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bouton « Modifier » : visible si l'utilisateur peut editer au moins un onglet
|
||||
* — `manage` (formulaire/onglets metier) OU `accounting.manage` (le role Compta
|
||||
* doit pouvoir ouvrir l'edition pour son onglet Comptabilite). Le readonly fin
|
||||
* par onglet est gere sur l'ecran d'edition (96).
|
||||
*/
|
||||
export function canEditSupplier(canAny: (codes: string[]) => boolean): boolean {
|
||||
return canAny(['commercial.suppliers.manage', 'commercial.suppliers.accounting.manage'])
|
||||
}
|
||||
|
||||
/** Bouton « Archiver » : permission archive ET fournisseur encore actif. */
|
||||
export function showArchiveAction(can: (code: string) => boolean, isArchived: boolean): boolean {
|
||||
return can('commercial.suppliers.archive') && !isArchived
|
||||
}
|
||||
|
||||
/** Bouton « Restaurer » : permission archive ET fournisseur deja archive. */
|
||||
export function showRestoreAction(can: (code: string) => boolean, isArchived: boolean): boolean {
|
||||
return can('commercial.suppliers.archive') && isArchived
|
||||
}
|
||||
|
||||
/** Brouillon d'adresse vierge (reexport pour la page : 1 bloc vide si aucune adresse). */
|
||||
export { emptyAddress }
|
||||
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
* Helpers purs des ecrans « Ajouter » / « Modifier » un fournisseur (M2
|
||||
* Commercial) — miroir de `clientEdit.ts` (M1). Deux responsabilites, toutes deux
|
||||
* testables unitairement (cf. supplierEdit.spec.ts) :
|
||||
* 1. Pre-remplissage : mapper le payload `GET /api/suppliers/{id}` (embed +
|
||||
* scalaires) vers les brouillons « plats » edites par la page de modification.
|
||||
* 2. Scoping STRICT des payloads PATCH (mode strict RG-2.16 / ERP-74) : chaque
|
||||
* onglet n'envoie QUE les champs de SON groupe de serialisation, jamais un
|
||||
* payload mixte (un champ hors-permission = 403 sur l'integralite cote back).
|
||||
*
|
||||
* Ces helpers ne touchent ni a l'API ni a l'etat reactif.
|
||||
*/
|
||||
|
||||
import {
|
||||
ADDRESS_REQUIRED_NON_NULLABLE_KEYS,
|
||||
blankEmptyRequired,
|
||||
MAIN_REQUIRED_NON_NULLABLE_KEYS,
|
||||
omitEmptyRequired,
|
||||
RIB_REQUIRED_NON_NULLABLE_KEYS,
|
||||
} from '~/modules/commercial/utils/supplierFormRules'
|
||||
import { iriOf, type SupplierDetail } from '~/modules/commercial/utils/supplierConsultation'
|
||||
import type {
|
||||
SupplierAddressFormDraft,
|
||||
SupplierContactFormDraft,
|
||||
SupplierRibFormDraft,
|
||||
} from '~/modules/commercial/types/supplierForm'
|
||||
|
||||
/** Etat « plat » du bloc principal (groupe supplier:write:main). */
|
||||
export interface MainFormDraft {
|
||||
companyName: string | null
|
||||
/** IRI des categories rattachees (M2M, type FOURNISSEUR). */
|
||||
categoryIris: string[]
|
||||
}
|
||||
|
||||
/** Etat « plat » de l'onglet Information (groupe supplier:write:information). */
|
||||
export interface InformationFormDraft {
|
||||
description: string | null
|
||||
competitors: string | null
|
||||
/** Date de creation de l'entreprise au format YYYY-MM-DD (MalioDate). */
|
||||
foundedAt: string | null
|
||||
/** Nombre de salaries en chaine (saisie masquee), converti en number au PATCH. */
|
||||
employeesCount: string | null
|
||||
revenueAmount: string | null
|
||||
profitAmount: string | null
|
||||
directorName: string | null
|
||||
/** Volume previsionnel (entier >= 0, specifique fournisseur) en chaine. */
|
||||
volumeForecast: string | null
|
||||
}
|
||||
|
||||
/** Etat « plat » de l'onglet Comptabilite (groupe supplier:write:accounting). */
|
||||
export interface AccountingFormDraft {
|
||||
siren: string | null
|
||||
accountNumber: string | null
|
||||
nTva: string | null
|
||||
tvaModeIri: string | null
|
||||
paymentDelayIri: string | null
|
||||
paymentTypeIri: string | null
|
||||
bankIri: string | null
|
||||
}
|
||||
|
||||
/** Permissions de l'utilisateur courant pertinentes pour l'edition d'un fournisseur. */
|
||||
export interface SupplierEditAbilities {
|
||||
/** `commercial.suppliers.manage` : bloc principal + onglets metier. */
|
||||
canManage: boolean
|
||||
/** `commercial.suppliers.accounting.view` : visibilite de l'onglet Comptabilite. */
|
||||
canAccountingView: boolean
|
||||
/** `commercial.suppliers.accounting.manage` : edition de l'onglet Comptabilite. */
|
||||
canAccountingManage: boolean
|
||||
}
|
||||
|
||||
/** Editabilite resolue par zone d'onglet (deduite des permissions). */
|
||||
export interface TabEditability {
|
||||
/** Bloc principal + onglets Information / Contacts / Adresses editables. */
|
||||
businessEditable: boolean
|
||||
/** Onglet Comptabilite present (affiche). */
|
||||
accountingVisible: boolean
|
||||
/** Onglet Comptabilite editable. */
|
||||
accountingEditable: boolean
|
||||
}
|
||||
|
||||
// ── Pre-remplissage (GET detail -> brouillons) ──────────────────────────────
|
||||
|
||||
/** Mappe le detail fournisseur vers le brouillon du bloc principal. */
|
||||
export function mapMainDraft(supplier: SupplierDetail): MainFormDraft {
|
||||
return {
|
||||
companyName: supplier.companyName ?? null,
|
||||
categoryIris: (supplier.categories ?? []).map(c => c['@id']),
|
||||
}
|
||||
}
|
||||
|
||||
/** Mappe le detail fournisseur vers le brouillon de l'onglet Information. */
|
||||
export function mapInformationDraft(supplier: SupplierDetail): InformationFormDraft {
|
||||
return {
|
||||
description: supplier.description ?? null,
|
||||
competitors: supplier.competitors ?? null,
|
||||
// MalioDate attend strictement YYYY-MM-DD : on tronque l'ISO datetime.
|
||||
foundedAt: supplier.foundedAt ? supplier.foundedAt.slice(0, 10) : null,
|
||||
employeesCount: supplier.employeesCount != null ? String(supplier.employeesCount) : null,
|
||||
revenueAmount: supplier.revenueAmount ?? null,
|
||||
profitAmount: supplier.profitAmount ?? null,
|
||||
directorName: supplier.directorName ?? null,
|
||||
// Volume previsionnel (entier, specifique fournisseur) en chaine pour la saisie.
|
||||
volumeForecast: supplier.volumeForecast != null ? String(supplier.volumeForecast) : null,
|
||||
}
|
||||
}
|
||||
|
||||
/** Mappe les champs comptables du detail vers le brouillon de l'onglet (scalaires + IRI). */
|
||||
export function mapAccountingFormDraft(supplier: SupplierDetail): AccountingFormDraft {
|
||||
return {
|
||||
siren: supplier.siren ?? null,
|
||||
accountNumber: supplier.accountNumber ?? null,
|
||||
nTva: supplier.nTva ?? null,
|
||||
tvaModeIri: iriOf(supplier.tvaMode),
|
||||
paymentDelayIri: iriOf(supplier.paymentDelay),
|
||||
paymentTypeIri: iriOf(supplier.paymentType),
|
||||
bankIri: iriOf(supplier.bank),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resout l'editabilite par zone a partir des permissions (option 1 ERP-74,
|
||||
* miroir UI du re-gating champ-par-champ du SupplierProcessor) :
|
||||
* - bloc principal + Information/Contacts/Adresses : editables ssi `manage` ;
|
||||
* - Comptabilite : visible ssi `accounting.view`, editable ssi `accounting.manage`.
|
||||
*
|
||||
* Produit le comportement attendu :
|
||||
* - Admin : tout editable.
|
||||
* - Bureau / Commerciale (manage, sans accounting) : metier editable, Compta masquee.
|
||||
* - Compta (accounting seul, sans manage) : metier readonly, Compta editable.
|
||||
*/
|
||||
export function resolveTabEditability(abilities: SupplierEditAbilities): TabEditability {
|
||||
return {
|
||||
businessEditable: abilities.canManage,
|
||||
accountingVisible: abilities.canAccountingView,
|
||||
accountingEditable: abilities.canAccountingManage,
|
||||
}
|
||||
}
|
||||
|
||||
// ── Scoping strict des payloads PATCH/POST ──────────────────────────────────
|
||||
|
||||
/**
|
||||
* Options de construction d'un payload d'ecriture.
|
||||
* - `forUpdate: false` (defaut, CREATION/POST) : les champs requis vides sont OMIS
|
||||
* -> 422 NotBlank a l'insert (le back ne reçoit pas la cle).
|
||||
* - `forUpdate: true` (EDITION/PATCH d'une ligne existante) : les champs requis
|
||||
* vides sont envoyes en `''` -> 422 NotBlank (sinon une cle omise laisse la valeur
|
||||
* serveur inchangee, faux 200 — cf. blankEmptyRequired).
|
||||
*/
|
||||
export interface BuildPayloadOptions {
|
||||
forUpdate?: boolean
|
||||
}
|
||||
|
||||
/** Selectionne le finaliseur des champs requis selon création (omit) vs édition (blank). */
|
||||
function finalizeRequired<T extends Record<string, unknown>>(
|
||||
payload: T,
|
||||
requiredKeys: readonly string[],
|
||||
options: BuildPayloadOptions,
|
||||
): T {
|
||||
return options.forUpdate
|
||||
? blankEmptyRequired(payload, requiredKeys)
|
||||
: omitEmptyRequired(payload, requiredKeys)
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload du bloc principal — groupe supplier:write:main UNIQUEMENT.
|
||||
* companyName vide -> 422 NotBlank (omis a la creation, `''` en edition — ERP-119).
|
||||
*/
|
||||
export function buildMainPayload(main: MainFormDraft, options: BuildPayloadOptions = {}): Record<string, unknown> {
|
||||
return finalizeRequired({
|
||||
companyName: main.companyName,
|
||||
categories: main.categoryIris,
|
||||
}, MAIN_REQUIRED_NON_NULLABLE_KEYS, options)
|
||||
}
|
||||
|
||||
/** Payload de l'onglet Information — groupe supplier:write:information UNIQUEMENT. */
|
||||
export function buildInformationPayload(information: InformationFormDraft): Record<string, unknown> {
|
||||
return {
|
||||
description: information.description || null,
|
||||
competitors: information.competitors || null,
|
||||
foundedAt: information.foundedAt || null,
|
||||
employeesCount: information.employeesCount ? Number(information.employeesCount) : null,
|
||||
revenueAmount: information.revenueAmount || null,
|
||||
profitAmount: information.profitAmount || null,
|
||||
directorName: information.directorName || null,
|
||||
volumeForecast: information.volumeForecast ? Number(information.volumeForecast) : null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload des scalaires de l'onglet Comptabilite — groupe supplier:write:accounting
|
||||
* UNIQUEMENT (les RIB passent par la sous-ressource /suppliers/{id}/ribs). La
|
||||
* banque n'a de sens que pour un Virement (RG-2.07) : forcee a null sinon.
|
||||
*/
|
||||
export function buildAccountingPayload(
|
||||
accounting: AccountingFormDraft,
|
||||
isBankRequired: boolean,
|
||||
): Record<string, unknown> {
|
||||
return {
|
||||
siren: accounting.siren || null,
|
||||
accountNumber: accounting.accountNumber || null,
|
||||
tvaMode: accounting.tvaModeIri,
|
||||
nTva: accounting.nTva || null,
|
||||
paymentDelay: accounting.paymentDelayIri,
|
||||
paymentType: accounting.paymentTypeIri,
|
||||
bank: isBankRequired ? accounting.bankIri : null,
|
||||
}
|
||||
}
|
||||
|
||||
/** Payload d'un contact (sous-ressource supplier_contact). */
|
||||
export function buildContactPayload(contact: SupplierContactFormDraft): Record<string, unknown> {
|
||||
return {
|
||||
firstName: contact.firstName || null,
|
||||
lastName: contact.lastName || null,
|
||||
jobTitle: contact.jobTitle || null,
|
||||
phonePrimary: contact.phonePrimary || null,
|
||||
phoneSecondary: contact.hasSecondaryPhone ? (contact.phoneSecondary || null) : null,
|
||||
email: contact.email || null,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload d'une adresse (sous-ressource supplier_address). postalCode / city /
|
||||
* street omis si vides -> 422 NotBlank (ERP-119). Specifique fournisseur :
|
||||
* `bennes` (entier, 0 par defaut) + `triageProvider` (booleen). Pas d'email de
|
||||
* facturation (difference M1).
|
||||
*/
|
||||
export function buildAddressPayload(address: SupplierAddressFormDraft, options: BuildPayloadOptions = {}): Record<string, unknown> {
|
||||
return finalizeRequired({
|
||||
addressType: address.addressType,
|
||||
country: address.country,
|
||||
postalCode: address.postalCode || null,
|
||||
city: address.city || null,
|
||||
street: address.street || null,
|
||||
streetComplement: address.streetComplement || null,
|
||||
categories: address.categoryIris,
|
||||
sites: address.siteIris,
|
||||
contacts: address.contactIris,
|
||||
bennes: address.bennes !== null && address.bennes !== '' ? Number(address.bennes) : null,
|
||||
triageProvider: address.triageProvider,
|
||||
// Geolocalisation (M6.1) : pin manuel persiste avec geoManual=true ;
|
||||
// geoManual=false laisse le back regeocoder depuis l'adresse postale.
|
||||
latitude: address.latitude || null,
|
||||
longitude: address.longitude || null,
|
||||
geoManual: address.geoManual,
|
||||
}, ADDRESS_REQUIRED_NON_NULLABLE_KEYS, options)
|
||||
}
|
||||
|
||||
/** Payload d'un RIB (sous-ressource supplier_rib). */
|
||||
export function buildRibPayload(rib: SupplierRibFormDraft, options: BuildPayloadOptions = {}): Record<string, unknown> {
|
||||
return finalizeRequired({
|
||||
label: rib.label,
|
||||
bic: rib.bic,
|
||||
iban: rib.iban,
|
||||
}, RIB_REQUIRED_NON_NULLABLE_KEYS, options)
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* Regles metier pures de l'ecran « Ajouter un fournisseur » (M2 Commercial).
|
||||
*
|
||||
* Miroir de `clientFormRules.ts` (M1), centralisees ici (hors composant) pour
|
||||
* rester testables unitairement et partagees entre la creation et les ecrans
|
||||
* d'edition/consultation (95/96). Ces helpers ne touchent ni a l'API ni a l'etat
|
||||
* reactif : ils prennent des brouillons « plats » et retournent des booleens.
|
||||
*
|
||||
* Le back reste la source de verite (les RG sont re-validees serveur, mode
|
||||
* strict) ; ces regles ne servent qu'au feedback UI immediat (gating de boutons).
|
||||
*
|
||||
* Differences M2 vs M1 :
|
||||
* - Adresse via enum `addressType` (PROSPECT/DEPART/RENDU, RG-2.09) — pas de
|
||||
* drapeaux ni d'exclusivite a gerer cote front (le radio est exclusif par nature).
|
||||
* - Pas d'email de facturation, pas de relation Distributeur/Courtier.
|
||||
*/
|
||||
|
||||
import type { SupplierAddressType } from '~/modules/commercial/types/supplierForm'
|
||||
|
||||
/**
|
||||
* Onglets « coquille » (non encore implementes) : frame vide, passage
|
||||
* automatique a l'onglet suivant (aligne M1).
|
||||
*/
|
||||
export const SUPPLIER_FORM_PLACEHOLDER_TABS = ['transport', 'statistics', 'reports', 'exchanges'] as const
|
||||
|
||||
/**
|
||||
* Onglets affiches uniquement en MODIFICATION/CONSULTATION (jamais a la
|
||||
* creation) : Statistiques / Rapports / Echanges. A rebrancher dans les ecrans
|
||||
* 95/96 via l'option `includeEditOnlyTabs`.
|
||||
*/
|
||||
export const SUPPLIER_FORM_EDIT_ONLY_TABS = ['statistics', 'reports', 'exchanges'] as const
|
||||
|
||||
/**
|
||||
* Construit l'ordre des onglets du formulaire fournisseur.
|
||||
* - L'onglet Comptabilite n'est present que si l'utilisateur a `accounting.view`
|
||||
* (Bureau / Commerciale ne le voient pas).
|
||||
* - Les onglets edit-only sont exclus par defaut (creation) ; passer
|
||||
* `includeEditOnlyTabs: true` pour les afficher en modification/consultation.
|
||||
* Ordre aligne sur la spec M2 § Ecran « Ajouter un fournisseur » (barre 5 onglets).
|
||||
*/
|
||||
export function buildSupplierFormTabKeys(
|
||||
canAccountingView: boolean,
|
||||
options: { includeEditOnlyTabs?: boolean } = {},
|
||||
): string[] {
|
||||
const keys = ['information', 'contacts', 'addresses', 'transport']
|
||||
if (canAccountingView) {
|
||||
keys.push('accounting')
|
||||
}
|
||||
if (options.includeEditOnlyTabs) {
|
||||
keys.push(...SUPPLIER_FORM_EDIT_ONLY_TABS)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
/**
|
||||
* Dernier onglet REMPLISSABLE d'un jeu d'onglets : le dernier qui n'est pas un
|
||||
* placeholder. Role-aware sans regle ad hoc — il suffit de lui passer les
|
||||
* `tabKeys` deja filtres par permission. Sa validation marque la fin de l'ajout.
|
||||
*/
|
||||
export function lastFillableTabKey(tabKeys: string[]): string | undefined {
|
||||
return [...tabKeys].reverse().find(
|
||||
key => !(SUPPLIER_FORM_PLACEHOLDER_TABS as readonly string[]).includes(key),
|
||||
)
|
||||
}
|
||||
|
||||
/** Sous-ensemble d'un contact necessaire aux regles de nommage (RG-2.04/2.13). */
|
||||
export interface ContactDraft {
|
||||
firstName: string | null
|
||||
lastName: string | null
|
||||
}
|
||||
|
||||
/** Vrai si une chaine porte au moins un caractere non-espace. */
|
||||
function isFilled(value: string | null | undefined): boolean {
|
||||
return value !== null && value !== undefined && value.trim() !== ''
|
||||
}
|
||||
|
||||
/** RG-2.04 : un contact est valide des qu'il porte un nom OU un prenom. */
|
||||
export function isContactNamed(contact: ContactDraft): boolean {
|
||||
return isFilled(contact.firstName) || isFilled(contact.lastName)
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-2.13 : l'onglet Contacts ne peut etre finalise que s'il reste au moins un
|
||||
* contact nomme (nom ou prenom).
|
||||
*/
|
||||
export function hasAtLeastOneValidContact(contacts: ContactDraft[]): boolean {
|
||||
return contacts.some(isContactNamed)
|
||||
}
|
||||
|
||||
/**
|
||||
* Primitive reutilisable : vrai si TOUTES les valeurs fournies sont vides. Sert a
|
||||
* detecter un bloc de collection totalement vide (amorce non remplie). Un bloc qui
|
||||
* porte la moindre donnee n'est PAS « blank » : il doit etre soumis pour declencher
|
||||
* sa 422 inline plutot que d'etre saute silencieusement.
|
||||
*/
|
||||
export function isBlankRow(values: (string | null | undefined)[]): boolean {
|
||||
return values.every(value => !isFilled(value))
|
||||
}
|
||||
|
||||
/** Champs saisissables d'un bloc contact (pour detecter un bloc totalement vide). */
|
||||
export interface ContactFillableDraft extends ContactDraft {
|
||||
jobTitle: string | null
|
||||
phonePrimary: string | null
|
||||
phoneSecondary: string | null
|
||||
email: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrai si AUCUN champ saisissable du bloc contact n'est rempli. Distingue un bloc
|
||||
* d'amorce vide (a ignorer au submit) d'un bloc partiellement rempli sans nom
|
||||
* (email/telephone/fonction seul) : ce dernier doit etre soumis pour declencher la
|
||||
* 422 RG-2.04 affichee inline.
|
||||
*/
|
||||
export function isContactBlank(contact: ContactFillableDraft): boolean {
|
||||
return isBlankRow([
|
||||
contact.firstName,
|
||||
contact.lastName,
|
||||
contact.jobTitle,
|
||||
contact.phonePrimary,
|
||||
contact.phoneSecondary,
|
||||
contact.email,
|
||||
])
|
||||
}
|
||||
|
||||
/** Champs saisissables d'un bloc RIB (pour detecter un bloc totalement vide). */
|
||||
export interface RibFillableDraft {
|
||||
label: string | null
|
||||
bic: string | null
|
||||
iban: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrai si AUCUN champ du bloc RIB n'est rempli. Un RIB partiellement rempli (ex.
|
||||
* IBAN seul) n'est PAS « blank » : il doit etre soumis pour declencher les 422
|
||||
* NotBlank inline plutot que d'etre saute silencieusement.
|
||||
*/
|
||||
export function isRibBlank(rib: RibFillableDraft): boolean {
|
||||
return isBlankRow([rib.label, rib.bic, rib.iban])
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-2.08 : un RIB est complet quand ses trois champs sont remplis (label, BIC,
|
||||
* IBAN). Predicat partage entre le gating du bouton « + RIB » et la validation de
|
||||
* l'onglet (au moins un RIB complet si reglement LCR).
|
||||
*/
|
||||
export function isRibComplete(rib: RibFillableDraft): boolean {
|
||||
return isFilled(rib.label) && isFilled(rib.bic) && isFilled(rib.iban)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sous-ensemble d'une adresse necessaire a sa validite par-bloc : type (enum),
|
||||
* sites et categories rattaches.
|
||||
*/
|
||||
export interface AddressValidityDraft {
|
||||
addressType: SupplierAddressType | null
|
||||
categoryIris: string[]
|
||||
siteIris: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Validite par-bloc d'une adresse : type renseigne (RG-2.09), >= 1 site (RG-2.06)
|
||||
* et >= 1 categorie (RG-2.10). Predicat partage entre le gating du bouton
|
||||
* « + Adresse » (le dernier bloc doit etre valide avant d'en ajouter un autre) et
|
||||
* la validation de l'onglet (toutes les adresses valides). Pas d'email de
|
||||
* facturation cote fournisseur (difference M1).
|
||||
*/
|
||||
export function isAddressValid(address: AddressValidityDraft): boolean {
|
||||
return address.addressType !== null
|
||||
&& address.siteIris.length >= 1
|
||||
&& address.categoryIris.length >= 1
|
||||
}
|
||||
|
||||
/** Code stable du type de reglement « virement » (RG-2.07). */
|
||||
const PAYMENT_TYPE_TRANSFER = 'VIREMENT'
|
||||
|
||||
/** Code stable du type de reglement « lettre de change » (RG-2.08). */
|
||||
const PAYMENT_TYPE_LCR = 'LCR'
|
||||
|
||||
/** RG-2.07 : la banque est obligatoire lorsque le type de reglement est un virement. */
|
||||
export function isBankRequiredForPaymentType(code: string | null | undefined): boolean {
|
||||
return code === PAYMENT_TYPE_TRANSFER
|
||||
}
|
||||
|
||||
/** RG-2.08 : au moins un RIB complet est obligatoire lorsque le type de reglement est une LCR. */
|
||||
export function isRibRequiredForPaymentType(code: string | null | undefined): boolean {
|
||||
return code === PAYMENT_TYPE_LCR
|
||||
}
|
||||
|
||||
// ── Champs requis adosses a une colonne NON-nullable (ERP-119) ───────────────
|
||||
// Memes contraintes qu'au M1 : un champ requis (NotBlank) porte par une colonne
|
||||
// Doctrine NON nullable rejette `null` en 400 de TYPE avant le Validator. Parade :
|
||||
// OMETTRE la cle du payload quand elle est vide -> le back produit une 422 NotBlank
|
||||
// avec propertyPath, mappee en rouge sous le champ.
|
||||
export const MAIN_REQUIRED_NON_NULLABLE_KEYS = ['companyName'] as const
|
||||
// addressType : colonne non-nullable + NotBlank cote back. Envoyer `null` (radio
|
||||
// non choisi) provoque un 400 de TYPE a la deserialisation AVANT le Validator
|
||||
// (« must be string, NULL given ») -> pas de violation, pas d'erreur inline. On
|
||||
// omet donc la cle quand elle est vide pour obtenir une 422 NotBlank propertyPath.
|
||||
export const ADDRESS_REQUIRED_NON_NULLABLE_KEYS = ['addressType', 'postalCode', 'city', 'street'] as const
|
||||
export const RIB_REQUIRED_NON_NULLABLE_KEYS = ['label', 'bic', 'iban'] as const
|
||||
|
||||
/**
|
||||
* Retire d'un payload d'ecriture les cles requises laissees vides (null / '' /
|
||||
* undefined), pour laisser le back produire une 422 NotBlank par champ plutot
|
||||
* qu'un 400 de type sur une colonne non-nullable. Mute et retourne le payload.
|
||||
*/
|
||||
export function omitEmptyRequired<T extends Record<string, unknown>>(
|
||||
payload: T,
|
||||
requiredKeys: readonly string[],
|
||||
): T {
|
||||
for (const key of requiredKeys) {
|
||||
const value = payload[key]
|
||||
if (value === null || value === undefined || value === '') {
|
||||
delete payload[key]
|
||||
}
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
/**
|
||||
* Variante PATCH (edition d'une ligne EXISTANTE) : remplace les cles requises
|
||||
* laissees vides par une chaine vide `''` au lieu de les OMETTRE.
|
||||
*
|
||||
* Pourquoi pas `omitEmptyRequired` en edition : un PATCH a semantique merge — une
|
||||
* cle absente laisse la valeur serveur INCHANGEE. Vider un champ requis puis valider
|
||||
* renverrait alors un 200 trompeur (l'ancienne valeur est conservee). En envoyant
|
||||
* `''`, la propriete `?string` est bien deserialisee (pas de 400 de type, contrairement
|
||||
* a `null` sur une colonne non-nullable), puis le Validator `NotBlank(trim)` la rejette
|
||||
* -> 422 avec propertyPath, mappee inline sous le champ. Mute et retourne le payload.
|
||||
*/
|
||||
export function blankEmptyRequired<T extends Record<string, unknown>>(
|
||||
payload: T,
|
||||
requiredKeys: readonly string[],
|
||||
): T {
|
||||
for (const key of requiredKeys) {
|
||||
const value = payload[key]
|
||||
if (value === null || value === undefined || value === '') {
|
||||
(payload as Record<string, unknown>)[key] = ''
|
||||
}
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
icon-name="mdi:tune"
|
||||
icon-position="left"
|
||||
icon-size="24"
|
||||
button-class="w-[184px] justify-start gap-4 text-black"
|
||||
@click="openFilters"
|
||||
/>
|
||||
</template>
|
||||
@@ -30,7 +29,7 @@
|
||||
>
|
||||
<template #cell-action="{ item }">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium"
|
||||
class="inline-flex items-center rounded-full px-2 py-0.5 font-medium"
|
||||
:class="actionBadgeClass(item.action as string)"
|
||||
>
|
||||
{{ t(`audit.action.${item.action}`) }}
|
||||
@@ -38,15 +37,14 @@
|
||||
</template>
|
||||
<template #cell-entityType="{ item }">
|
||||
<span
|
||||
class="text-xs"
|
||||
:title="item.entityType as string"
|
||||
>{{ formatEntityType(item.entityType as string) }}</span>
|
||||
</template>
|
||||
<template #cell-entityId="{ item }">
|
||||
<span class="font-mono text-xs">{{ item.entityId }}</span>
|
||||
<span>{{ item.entityId }}</span>
|
||||
</template>
|
||||
<template #cell-summary="{ item }">
|
||||
<span class="text-xs text-gray-600">{{ item.summary }}</span>
|
||||
<span class="text-gray-600">{{ item.summary }}</span>
|
||||
</template>
|
||||
</MalioDataTable>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<template #actions>
|
||||
<MalioButton
|
||||
v-if="can('core.roles.manage')"
|
||||
variant="secondary"
|
||||
:label="t('admin.roles.newRole')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@@ -28,7 +29,7 @@
|
||||
@update:per-page="setItemsPerPage"
|
||||
>
|
||||
<template #cell-code="{ item }">
|
||||
<span class="font-mono text-xs">{{ item.code }}</span>
|
||||
<span>{{ item.code }}</span>
|
||||
</template>
|
||||
<template #cell-permissions="{ item }">
|
||||
{{ item.permissions }}
|
||||
@@ -36,7 +37,7 @@
|
||||
<template #cell-system="{ item }">
|
||||
<span
|
||||
v-if="item.isSystem"
|
||||
class="inline-flex items-center rounded-full bg-blue-100 px-2.5 py-0.5 text-xs font-medium text-blue-800"
|
||||
class="inline-flex items-center rounded-full bg-blue-100 px-2.5 py-0.5 font-medium text-blue-800"
|
||||
>
|
||||
{{ t('admin.roles.table.system') }}
|
||||
</span>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<template #cell-admin="{ item }">
|
||||
<span
|
||||
v-if="item.admin"
|
||||
class="inline-flex items-center rounded-full bg-purple-100 px-2.5 py-0.5 text-xs font-medium text-purple-800"
|
||||
class="inline-flex items-center rounded-full bg-purple-100 px-2.5 py-0.5 font-medium text-purple-800"
|
||||
>
|
||||
{{ t('admin.users.table.admin') }}
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,353 @@
|
||||
<template>
|
||||
<!-- Carte Leaflet (exception documentee a @malio/layer-ui : carte interactive,
|
||||
type non couvert par la lib — cf. frontend.md § Composants formulaires).
|
||||
TODO : migrer si la lib couvre un jour les cartes. -->
|
||||
<div class="relative h-full w-full">
|
||||
<div ref="mapEl" class="h-full w-full" data-testid="tour-map" />
|
||||
<!-- Aide a la selection rectangle (lasso facon Badger Maps). -->
|
||||
<div class="pointer-events-none absolute bottom-2 left-2 z-[400] rounded bg-white/90 px-2 py-1 text-xs text-gray-600 shadow">
|
||||
{{ t('field_sales.plan.map.lassoHint') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Map as LeafletMap, Marker, Polyline, Rectangle } from 'leaflet'
|
||||
import type { PlanningStop } from '~/modules/field-sales/composables/useTourPlanning'
|
||||
import type { VisitableTier } from '~/modules/field-sales/types/tour'
|
||||
|
||||
/**
|
||||
* Carte interactive de planification de tournee (M6.5, spec § 6.1).
|
||||
*
|
||||
* - Charge les pins des Tiers geolocalises de la zone visible
|
||||
* (GET /api/visitable_tiers?bbox=...), colores par type (client/fournisseur),
|
||||
* filtrables (types + recherche). Recharge au deplacement/zoom (debounce).
|
||||
* - Popup au clic : nom, adresse, bouton « + Ajouter » (emet `add-tier`).
|
||||
* - Selection rectangle (Maj + glisser) : ajoute tous les Tiers entoures
|
||||
* (emet `add-tiers`).
|
||||
* - Trace la tournee par-dessus : polyline + marqueurs numerotes suivant l'ordre
|
||||
* des etapes geolocalisees.
|
||||
*
|
||||
* Instances Leaflet hors reactivite Vue (un proxy casse l'API Leaflet).
|
||||
*/
|
||||
const props = withDefaults(defineProps<{
|
||||
/** Etapes geolocalisees a tracer (polyline numerotee). */
|
||||
stops: PlanningStop[]
|
||||
/** Types de pins affiches. */
|
||||
types: Array<'client' | 'supplier'>
|
||||
/** Recherche raison sociale / ville. */
|
||||
search: string
|
||||
/** Centre initial (defaut : Nantes). */
|
||||
center?: [number, number]
|
||||
}>(), {
|
||||
center: () => [47.218, -1.553],
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** Ajout d'un seul Tiers (popup « + Ajouter »). */
|
||||
'add-tier': [tier: VisitableTier]
|
||||
/** Ajout d'un lot de Tiers (selection rectangle). */
|
||||
'add-tiers': [tiers: VisitableTier[]]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
|
||||
const mapEl = ref<HTMLElement | null>(null)
|
||||
|
||||
// Instances Leaflet (hors reactivite).
|
||||
let L: typeof import('leaflet') | null = null
|
||||
let map: LeafletMap | null = null
|
||||
let pinLayer: Marker[] = []
|
||||
let pinTiers: Array<{ tier: VisitableTier, marker: Marker }> = []
|
||||
let routeLine: Polyline | null = null
|
||||
let stopMarkers: Marker[] = []
|
||||
let selectionRect: Rectangle | null = null
|
||||
|
||||
/** Zoom initial (niveau agglomeration). */
|
||||
const INITIAL_ZOOM = 12
|
||||
|
||||
/** Couleur du pin par type de Tiers. */
|
||||
const PIN_COLORS: Record<string, string> = {
|
||||
client: '#2563eb', // bleu
|
||||
supplier: '#16a34a', // vert
|
||||
}
|
||||
|
||||
/** Debounce du rechargement des pins au deplacement de la carte. */
|
||||
let fetchTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
async function ensureMap(): Promise<void> {
|
||||
if (map !== null || mapEl.value === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const mod = await import('leaflet')
|
||||
L = mod.default ?? mod
|
||||
await import('leaflet/dist/leaflet.css')
|
||||
|
||||
if (mapEl.value === null) {
|
||||
return
|
||||
}
|
||||
|
||||
map = L.map(mapEl.value).setView(props.center, INITIAL_ZOOM)
|
||||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
||||
maxZoom: 19,
|
||||
}).addTo(map)
|
||||
|
||||
// Selection rectangle a la place du box-zoom natif (Maj + glisser).
|
||||
map.boxZoom.disable()
|
||||
map.on('mousedown', onMouseDown)
|
||||
|
||||
// Rechargement des pins quand la zone visible change.
|
||||
map.on('moveend', scheduleFetch)
|
||||
|
||||
drawRoute()
|
||||
await fetchPins()
|
||||
}
|
||||
|
||||
/** bbox de la zone visible au format Leaflet (minLng,minLat,maxLng,maxLat). */
|
||||
function currentBbox(): string | null {
|
||||
if (map === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return map.getBounds().toBBoxString()
|
||||
}
|
||||
|
||||
function scheduleFetch(): void {
|
||||
if (fetchTimer !== null) {
|
||||
clearTimeout(fetchTimer)
|
||||
}
|
||||
fetchTimer = setTimeout(() => {
|
||||
void fetchPins()
|
||||
}, 300)
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge les pins de la zone visible. `?pagination=false` : la carte affiche
|
||||
* TOUS les pins de la bbox (le volume est borne par la zone, pas par la page).
|
||||
*/
|
||||
async function fetchPins(): Promise<void> {
|
||||
if (map === null || L === null) {
|
||||
return
|
||||
}
|
||||
if (props.types.length === 0) {
|
||||
clearPins()
|
||||
return
|
||||
}
|
||||
|
||||
const bbox = currentBbox()
|
||||
if (bbox === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const query: Record<string, string> = {
|
||||
bbox,
|
||||
type: props.types.join(','),
|
||||
pagination: 'false',
|
||||
}
|
||||
if (props.search.trim() !== '') {
|
||||
query.q = props.search.trim()
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await api.get<{ member?: VisitableTier[] }>(
|
||||
'/visitable_tiers',
|
||||
query,
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
renderPins(response.member ?? [])
|
||||
}
|
||||
catch {
|
||||
// Echec non bloquant : la carte reste utilisable, les pins ne se mettent
|
||||
// simplement pas a jour.
|
||||
}
|
||||
}
|
||||
|
||||
function clearPins(): void {
|
||||
pinLayer.forEach(m => m.remove())
|
||||
pinLayer = []
|
||||
pinTiers = []
|
||||
}
|
||||
|
||||
function renderPins(tiers: VisitableTier[]): void {
|
||||
if (map === null || L === null) {
|
||||
return
|
||||
}
|
||||
clearPins()
|
||||
|
||||
for (const tier of tiers) {
|
||||
const marker = L.marker([tier.latitude, tier.longitude], {
|
||||
icon: pinIcon(PIN_COLORS[tier.tierType] ?? '#6b7280'),
|
||||
}).addTo(map)
|
||||
|
||||
marker.bindPopup(popupHtml(tier))
|
||||
marker.on('popupopen', () => bindPopupButton(tier))
|
||||
|
||||
pinLayer.push(marker)
|
||||
pinTiers.push({ tier, marker })
|
||||
}
|
||||
}
|
||||
|
||||
/** divIcon SVG inline colore (evite les assets PNG Leaflet casses par Vite). */
|
||||
function pinIcon(color: string) {
|
||||
return L!.divIcon({
|
||||
className: '',
|
||||
html: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="26" height="38" fill="${color}" stroke="#ffffff" stroke-width="1"><path d="M12 0C7 0 3 4 3 9c0 6.6 9 15 9 15s9-8.4 9-15c0-5-4-9-9-9zm0 12.5A3.5 3.5 0 1 1 12 5.5a3.5 3.5 0 0 1 0 7z"/></svg>`,
|
||||
iconSize: [26, 38],
|
||||
iconAnchor: [13, 38],
|
||||
popupAnchor: [0, -34],
|
||||
})
|
||||
}
|
||||
|
||||
/** Contenu HTML du popup (le bouton est cable a l'ouverture, cf. bindPopupButton). */
|
||||
function popupHtml(tier: VisitableTier): string {
|
||||
const name = escapeHtml(tier.displayName)
|
||||
const address = escapeHtml(tier.address)
|
||||
|
||||
return `<div class="text-sm">
|
||||
<div class="font-semibold">${name}</div>
|
||||
<div class="text-gray-600">${address}</div>
|
||||
<button type="button" data-add-tier class="mt-2 rounded bg-blue-600 px-2 py-1 text-xs font-medium text-white">${t('field_sales.plan.map.add')}</button>
|
||||
</div>`
|
||||
}
|
||||
|
||||
/** Cable le bouton « + Ajouter » du popup ouvert vers l'emit `add-tier`. */
|
||||
function bindPopupButton(tier: VisitableTier): void {
|
||||
const el = map?.getContainer().querySelector('[data-add-tier]')
|
||||
el?.addEventListener('click', () => {
|
||||
emit('add-tier', tier)
|
||||
map?.closePopup()
|
||||
}, { once: true })
|
||||
}
|
||||
|
||||
// ── Selection rectangle (lasso) ─────────────────────────────────────────────
|
||||
let selectStart: import('leaflet').LatLng | null = null
|
||||
|
||||
function onMouseDown(e: import('leaflet').LeafletMouseEvent): void {
|
||||
if (map === null || L === null || !e.originalEvent.shiftKey) {
|
||||
return
|
||||
}
|
||||
// Empeche le drag de la carte pendant la selection.
|
||||
map.dragging.disable()
|
||||
selectStart = e.latlng
|
||||
selectionRect = L.rectangle(L.latLngBounds(e.latlng, e.latlng), {
|
||||
color: '#2563eb',
|
||||
weight: 1,
|
||||
fillOpacity: 0.1,
|
||||
}).addTo(map)
|
||||
|
||||
map.on('mousemove', onMouseMove)
|
||||
map.on('mouseup', onMouseUp)
|
||||
}
|
||||
|
||||
function onMouseMove(e: import('leaflet').LeafletMouseEvent): void {
|
||||
if (selectStart === null || selectionRect === null || L === null) {
|
||||
return
|
||||
}
|
||||
selectionRect.setBounds(L.latLngBounds(selectStart, e.latlng))
|
||||
}
|
||||
|
||||
function onMouseUp(): void {
|
||||
if (map === null) {
|
||||
return
|
||||
}
|
||||
const bounds = selectionRect?.getBounds() ?? null
|
||||
cleanupSelection()
|
||||
|
||||
if (bounds === null) {
|
||||
return
|
||||
}
|
||||
const selected = pinTiers
|
||||
.filter(({ marker }) => bounds.contains(marker.getLatLng()))
|
||||
.map(({ tier }) => tier)
|
||||
|
||||
if (selected.length > 0) {
|
||||
emit('add-tiers', selected)
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupSelection(): void {
|
||||
selectionRect?.remove()
|
||||
selectionRect = null
|
||||
selectStart = null
|
||||
map?.off('mousemove', onMouseMove)
|
||||
map?.off('mouseup', onMouseUp)
|
||||
map?.dragging.enable()
|
||||
}
|
||||
|
||||
// ── Trace de la tournee ──────────────────────────────────────────────────────
|
||||
function drawRoute(): void {
|
||||
if (map === null || L === null) {
|
||||
return
|
||||
}
|
||||
routeLine?.remove()
|
||||
routeLine = null
|
||||
stopMarkers.forEach(m => m.remove())
|
||||
stopMarkers = []
|
||||
|
||||
const located = props.stops.filter(s => s.latitude != null && s.longitude != null)
|
||||
const points = located.map(s => [s.latitude as number, s.longitude as number] as [number, number])
|
||||
|
||||
if (points.length >= 2) {
|
||||
routeLine = L.polyline(points, { color: '#1e40af', weight: 3, opacity: 0.7 }).addTo(map)
|
||||
}
|
||||
|
||||
located.forEach((stop, index) => {
|
||||
const marker = L!.marker([stop.latitude as number, stop.longitude as number], {
|
||||
icon: numberedIcon(index + 1),
|
||||
zIndexOffset: 1000,
|
||||
}).addTo(map!)
|
||||
marker.bindTooltip(stop.label, { direction: 'top' })
|
||||
stopMarkers.push(marker)
|
||||
})
|
||||
}
|
||||
|
||||
/** Pastille numerotee pour une etape de la tournee. */
|
||||
function numberedIcon(n: number) {
|
||||
return L!.divIcon({
|
||||
className: '',
|
||||
html: `<div style="display:flex;align-items:center;justify-content:center;width:24px;height:24px;border-radius:9999px;background:#1e40af;color:#fff;font-size:12px;font-weight:700;border:2px solid #fff;box-shadow:0 1px 2px rgba(0,0,0,.4)">${n}</div>`,
|
||||
iconSize: [24, 24],
|
||||
iconAnchor: [12, 12],
|
||||
})
|
||||
}
|
||||
|
||||
function escapeHtml(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
}
|
||||
|
||||
// Recharge les pins quand les filtres changent.
|
||||
watch(() => [props.types, props.search], scheduleFetch, { deep: true })
|
||||
|
||||
// Redessine le trace quand les etapes changent.
|
||||
watch(() => props.stops, drawRoute, { deep: true })
|
||||
|
||||
onMounted(ensureMap)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (fetchTimer !== null) {
|
||||
clearTimeout(fetchTimer)
|
||||
}
|
||||
map?.remove()
|
||||
map = null
|
||||
L = null
|
||||
pinLayer = []
|
||||
pinTiers = []
|
||||
stopMarkers = []
|
||||
routeLine = null
|
||||
selectionRect = null
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
/** Recentre la carte sur une cible (ex: depuis le panneau). */
|
||||
panTo(target: { latitude: number, longitude: number }) {
|
||||
map?.panTo([target.latitude, target.longitude])
|
||||
},
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,148 @@
|
||||
<template>
|
||||
<div>
|
||||
<p v-if="stops.length === 0" class="py-6 text-center text-sm text-gray-500" data-testid="stops-empty">
|
||||
{{ t('field_sales.plan.panel.noStops') }}
|
||||
</p>
|
||||
|
||||
<!-- Liste draggable (vuedraggable / SortableJS) : au drop, on emet le
|
||||
nouvel ordre. La poignee limite le drag a l'icone (le reste de la
|
||||
ligne reste cliquable). Etat 100 % local cote parent. -->
|
||||
<draggable
|
||||
v-else
|
||||
:model-value="stops"
|
||||
item-key="id"
|
||||
handle=".drag-handle"
|
||||
ghost-class="opacity-50"
|
||||
class="flex flex-col gap-2"
|
||||
@update:model-value="onReorder"
|
||||
>
|
||||
<template #item="{ element, index }">
|
||||
<div
|
||||
class="flex items-start gap-2 rounded border border-gray-200 bg-white p-2"
|
||||
:data-testid="`stop-${element.id}`"
|
||||
>
|
||||
<!-- Poignee de drag + numero d'ordre. -->
|
||||
<button
|
||||
type="button"
|
||||
class="drag-handle mt-0.5 flex h-7 w-7 shrink-0 cursor-grab items-center justify-center rounded-full bg-blue-800 text-xs font-bold text-white"
|
||||
:aria-label="t('field_sales.plan.panel.stops')"
|
||||
>
|
||||
{{ index + 1 }}
|
||||
</button>
|
||||
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="truncate font-medium text-gray-900">{{ element.label }}</span>
|
||||
<span
|
||||
v-if="!isStopLocated(element)"
|
||||
class="shrink-0 rounded-full bg-yellow-100 px-2 py-0.5 text-xs font-medium text-yellow-800"
|
||||
>
|
||||
{{ t('field_sales.plan.stop.toGeolocate') }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="truncate text-xs text-gray-500">{{ element.displayAddress }}</p>
|
||||
|
||||
<!-- ETA + temps depuis l'etape precedente. -->
|
||||
<p v-if="isStopLocated(element)" class="mt-0.5 text-xs text-gray-600">
|
||||
<span class="font-medium">{{ t('field_sales.plan.stop.eta') }}</span>
|
||||
{{ formatTime(element.eta) }}
|
||||
<span v-if="index > 0" class="text-gray-400">
|
||||
· {{ formatDuration(element.legDurationS) }} / {{ formatDistance(element.legDistanceM) }}
|
||||
{{ t('field_sales.plan.stop.fromPrevious') }}
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<!-- Actions : Y aller (deep links) · Voir le Tiers. -->
|
||||
<div class="mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs">
|
||||
<div class="relative">
|
||||
<button
|
||||
type="button"
|
||||
class="font-medium text-blue-700 hover:underline disabled:text-gray-300"
|
||||
:disabled="navLinks(element) === null"
|
||||
@click="toggleMenu(element.id)"
|
||||
>
|
||||
{{ t('field_sales.plan.stop.goThere') }}
|
||||
</button>
|
||||
<div
|
||||
v-if="openMenuId === element.id && navLinks(element) !== null"
|
||||
class="absolute z-10 mt-1 flex flex-col rounded border border-gray-200 bg-white py-1 shadow-lg"
|
||||
>
|
||||
<a :href="navLinks(element)!.waze" target="_blank" rel="noopener" class="px-3 py-1 hover:bg-gray-100" @click="openMenuId = null">{{ t('field_sales.plan.stop.waze') }}</a>
|
||||
<a :href="navLinks(element)!.google" target="_blank" rel="noopener" class="px-3 py-1 hover:bg-gray-100" @click="openMenuId = null">{{ t('field_sales.plan.stop.google') }}</a>
|
||||
<a :href="navLinks(element)!.apple" target="_blank" rel="noopener" class="px-3 py-1 hover:bg-gray-100" @click="openMenuId = null">{{ t('field_sales.plan.stop.apple') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
v-if="element.tierType !== 'custom'"
|
||||
type="button"
|
||||
class="text-gray-600 hover:underline"
|
||||
@click="emit('view-tier', element)"
|
||||
>
|
||||
{{ t('field_sales.plan.stop.viewTier') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Suppression de l'etape. -->
|
||||
<button
|
||||
type="button"
|
||||
class="mt-0.5 shrink-0 text-gray-400 hover:text-red-600"
|
||||
:aria-label="t('field_sales.plan.stop.remove')"
|
||||
@click="emit('remove', element)"
|
||||
>
|
||||
<Icon name="mdi:close" size="18" />
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import draggable from 'vuedraggable'
|
||||
import {
|
||||
buildNavigationLinks,
|
||||
isStopLocated,
|
||||
formatDistance,
|
||||
formatDuration,
|
||||
formatTime,
|
||||
type PlanningStop,
|
||||
} from '~/modules/field-sales/composables/useTourPlanning'
|
||||
import type { NavigationLinks } from '~/modules/field-sales/types/tour'
|
||||
|
||||
/**
|
||||
* Liste ordonnee et draggable des etapes d'une tournee (panneau de
|
||||
* planification, M6.5). Le reordonnancement (drag & drop) emet le nouvel ordre ;
|
||||
* la persistance (POST /reorder) est a la charge de la page.
|
||||
*/
|
||||
defineProps<{
|
||||
stops: PlanningStop[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** Nouvel ordre des etapes apres drop. */
|
||||
'reorder': [stops: PlanningStop[]]
|
||||
/** Retrait d'une etape. */
|
||||
'remove': [stop: PlanningStop]
|
||||
/** « Voir le Tiers » (etape sur Tiers referentiel). */
|
||||
'view-tier': [stop: PlanningStop]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
/** Menu « Y aller » ouvert (id de l'etape) ou null. */
|
||||
const openMenuId = ref<number | null>(null)
|
||||
|
||||
function toggleMenu(id: number): void {
|
||||
openMenuId.value = openMenuId.value === id ? null : id
|
||||
}
|
||||
|
||||
function navLinks(stop: PlanningStop): NavigationLinks | null {
|
||||
return buildNavigationLinks(stop)
|
||||
}
|
||||
|
||||
function onReorder(next: PlanningStop[]): void {
|
||||
emit('reorder', next)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,132 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
reorderStops,
|
||||
computeTotals,
|
||||
buildNavigationLinks,
|
||||
isStopLocated,
|
||||
formatDistance,
|
||||
formatDuration,
|
||||
formatTime,
|
||||
type PlanningStop,
|
||||
} from '../useTourPlanning'
|
||||
|
||||
/** Fabrique une etape de planification minimale pour les tests. */
|
||||
function makeStop(overrides: Partial<PlanningStop> = {}): PlanningStop {
|
||||
return {
|
||||
id: overrides.id ?? 1,
|
||||
tierType: overrides.tierType ?? 'client',
|
||||
tierId: overrides.tierId ?? null,
|
||||
addressId: overrides.addressId ?? null,
|
||||
customLabel: null,
|
||||
customAddress: null,
|
||||
customLatitude: null,
|
||||
customLongitude: null,
|
||||
position: overrides.position ?? 0,
|
||||
visitMinutes: overrides.visitMinutes ?? null,
|
||||
legDistanceM: overrides.legDistanceM ?? null,
|
||||
legDurationS: overrides.legDurationS ?? null,
|
||||
eta: overrides.eta ?? null,
|
||||
label: overrides.label ?? 'Étape',
|
||||
displayAddress: overrides.displayAddress ?? '',
|
||||
latitude: overrides.latitude ?? null,
|
||||
longitude: overrides.longitude ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
describe('reorderStops', () => {
|
||||
it('deplace une etape et renumerote les positions de maniere contigue', () => {
|
||||
const stops = [
|
||||
makeStop({ id: 1, position: 0, label: 'A' }),
|
||||
makeStop({ id: 2, position: 1, label: 'B' }),
|
||||
makeStop({ id: 3, position: 2, label: 'C' }),
|
||||
]
|
||||
|
||||
// Deplace C (index 2) en tete (index 0).
|
||||
const result = reorderStops(stops, 2, 0)
|
||||
|
||||
expect(result.map(s => s.label)).toEqual(['C', 'A', 'B'])
|
||||
expect(result.map(s => s.position)).toEqual([0, 1, 2])
|
||||
})
|
||||
|
||||
it('ne mute pas le tableau source', () => {
|
||||
const stops = [makeStop({ id: 1, position: 0 }), makeStop({ id: 2, position: 1 })]
|
||||
reorderStops(stops, 0, 1)
|
||||
expect(stops.map(s => s.id)).toEqual([1, 2])
|
||||
})
|
||||
|
||||
it('retourne une copie inchangee si un index est hors borne', () => {
|
||||
const stops = [makeStop({ id: 1, position: 0 })]
|
||||
const result = reorderStops(stops, 0, 5)
|
||||
expect(result.map(s => s.id)).toEqual([1])
|
||||
})
|
||||
})
|
||||
|
||||
describe('computeTotals', () => {
|
||||
it('somme distances/trajets et ajoute les visites (defaut + specifique)', () => {
|
||||
const stops = [
|
||||
// 1re etape : pas de leg (point de depart). Visite = defaut 30 min.
|
||||
makeStop({ id: 1, legDistanceM: null, legDurationS: null }),
|
||||
// 2e : 10 km / 12 min de trajet, visite specifique 15 min.
|
||||
makeStop({ id: 2, legDistanceM: 10_000, legDurationS: 720, visitMinutes: 15 }),
|
||||
// 3e : 5 km / 6 min, visite par defaut.
|
||||
makeStop({ id: 3, legDistanceM: 5_000, legDurationS: 360, visitMinutes: null }),
|
||||
]
|
||||
|
||||
const totals = computeTotals(stops, 30)
|
||||
|
||||
expect(totals.totalDistanceM).toBe(15_000)
|
||||
expect(totals.travelDurationS).toBe(1_080)
|
||||
// Visites : 30 + 15 + 30 = 75 min = 4500 s.
|
||||
expect(totals.visitDurationS).toBe(4_500)
|
||||
expect(totals.totalDurationS).toBe(1_080 + 4_500)
|
||||
expect(totals.visitCount).toBe(3)
|
||||
})
|
||||
|
||||
it('renvoie des totaux nuls pour une tournee vide', () => {
|
||||
const totals = computeTotals([], 30)
|
||||
expect(totals.totalDistanceM).toBe(0)
|
||||
expect(totals.totalDurationS).toBe(0)
|
||||
expect(totals.visitCount).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildNavigationLinks', () => {
|
||||
it('construit les trois deep links Waze/Google/Apple', () => {
|
||||
const links = buildNavigationLinks({ latitude: 47.218, longitude: -1.553 })
|
||||
|
||||
expect(links).not.toBeNull()
|
||||
expect(links!.waze).toBe('https://waze.com/ul?ll=47.218,-1.553&navigate=yes')
|
||||
expect(links!.google).toBe('https://www.google.com/maps/dir/?api=1&destination=47.218,-1.553')
|
||||
expect(links!.apple).toBe('https://maps.apple.com/?daddr=47.218,-1.553')
|
||||
})
|
||||
|
||||
it('retourne null sans coordonnees (etape a geolocaliser)', () => {
|
||||
expect(buildNavigationLinks(null)).toBeNull()
|
||||
expect(buildNavigationLinks({ latitude: 47.2 })).toBeNull()
|
||||
expect(buildNavigationLinks({ latitude: null, longitude: null })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isStopLocated', () => {
|
||||
it('distingue une etape geolocalisee d\'une etape sans coordonnees', () => {
|
||||
expect(isStopLocated({ latitude: 47.2, longitude: -1.5 })).toBe(true)
|
||||
expect(isStopLocated({ latitude: null, longitude: null })).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatteurs', () => {
|
||||
it('formate distances et durees', () => {
|
||||
expect(formatDistance(850)).toBe('850 m')
|
||||
expect(formatDistance(12_340)).toBe('12,3 km')
|
||||
expect(formatDistance(null)).toBe('—')
|
||||
|
||||
expect(formatDuration(1_500)).toBe('25 min')
|
||||
expect(formatDuration(5_100)).toBe('1 h 25')
|
||||
expect(formatDuration(null)).toBe('—')
|
||||
})
|
||||
|
||||
it('extrait l\'heure HH:MM d\'une chaine ISO', () => {
|
||||
expect(formatTime('1970-01-01T08:30:00+00:00')).toBe('08:30')
|
||||
expect(formatTime(null)).toBe('—')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,178 @@
|
||||
import type { NavigationLinks, TierType, TourStop, TourTotals } from '~/modules/field-sales/types/tour'
|
||||
|
||||
/**
|
||||
* Composable de planification de tournee (M6.5).
|
||||
*
|
||||
* Porte la logique PURE de l'ecran de planification, isolee de Vue/Nuxt pour
|
||||
* etre testable directement (Vitest) :
|
||||
* - reordonnancement des etapes (drag & drop) + renumerotation des positions ;
|
||||
* - recalcul instantane des totaux (trajets + visites) pour le feedback UI,
|
||||
* avant le retour serveur du /compute ;
|
||||
* - construction des deep links de navigation « Y aller » (Waze/Google/Apple).
|
||||
*
|
||||
* Les coordonnees et libelles des etapes sur Tiers referentiel ne sont pas
|
||||
* portes par tour_stop:read : l'ecran les resout via GET /visitable_tiers/{id}
|
||||
* et alimente un `PlanningStop` enrichi, sur lequel operent ces fonctions.
|
||||
*/
|
||||
|
||||
/** Coordonnees WGS84 minimales d'une cible. */
|
||||
export interface LatLng {
|
||||
latitude: number
|
||||
longitude: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Etape « enrichie » manipulee par l'ecran : l'etape API + le libelle, l'adresse
|
||||
* et les coordonnees resolus (depuis le Tiers pour une etape referentiel, depuis
|
||||
* les colonnes custom_* pour un point libre).
|
||||
*/
|
||||
export interface PlanningStop extends TourStop {
|
||||
/** Nom affichable (raison sociale du Tiers ou libelle du point libre). */
|
||||
label: string
|
||||
/** Adresse formatee sur une ligne. */
|
||||
displayAddress: string
|
||||
/** Coordonnees resolues, ou null si l'etape n'est pas geolocalisee (RG-6.05). */
|
||||
latitude: number | null
|
||||
longitude: number | null
|
||||
}
|
||||
|
||||
/** Vitesse moyenne par defaut (km/h) — alignee sur HaversineRouteEngine (back). */
|
||||
const DEFAULT_SPEED_KMH = 50
|
||||
|
||||
/**
|
||||
* Deplace l'etape `fromIndex` vers `toIndex` et renumerote toutes les positions
|
||||
* (0-indexees, contigues). Retourne un NOUVEAU tableau (pas de mutation).
|
||||
*/
|
||||
export function reorderStops<T extends { position: number }>(stops: readonly T[], fromIndex: number, toIndex: number): T[] {
|
||||
const next = [...stops]
|
||||
if (fromIndex < 0 || fromIndex >= next.length || toIndex < 0 || toIndex >= next.length) {
|
||||
return next
|
||||
}
|
||||
const [moved] = next.splice(fromIndex, 1)
|
||||
if (moved === undefined) {
|
||||
return next
|
||||
}
|
||||
next.splice(toIndex, 0, moved)
|
||||
|
||||
return next.map((stop, index) => ({ ...stop, position: index }))
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalcule les totaux d'une tournee a partir des legs deja calcules et des
|
||||
* durees de visite (RG-6.11). Duree totale = trajets + visites.
|
||||
*/
|
||||
export function computeTotals(stops: readonly PlanningStop[], defaultVisitMinutes: number): TourTotals {
|
||||
let totalDistanceM = 0
|
||||
let travelDurationS = 0
|
||||
let visitDurationS = 0
|
||||
|
||||
for (const stop of stops) {
|
||||
totalDistanceM += stop.legDistanceM ?? 0
|
||||
travelDurationS += stop.legDurationS ?? 0
|
||||
visitDurationS += (stop.visitMinutes ?? defaultVisitMinutes) * 60
|
||||
}
|
||||
|
||||
return {
|
||||
totalDistanceM,
|
||||
travelDurationS,
|
||||
visitDurationS,
|
||||
totalDurationS: travelDurationS + visitDurationS,
|
||||
visitCount: stops.length,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep links de navigation vers une cible geolocalisee (spec M6 § 6.1).
|
||||
* Waze/Google Maps ne prennent qu'UNE destination -> navigation etape par etape
|
||||
* (HP-M6-7 assume). Retourne null si la cible n'a pas de coordonnees.
|
||||
*/
|
||||
export function buildNavigationLinks(target: { latitude?: number | null, longitude?: number | null } | null): NavigationLinks | null {
|
||||
if (target == null || target.latitude == null || target.longitude == null) {
|
||||
return null
|
||||
}
|
||||
const lat = target.latitude
|
||||
const lng = target.longitude
|
||||
|
||||
return {
|
||||
waze: `https://waze.com/ul?ll=${lat},${lng}&navigate=yes`,
|
||||
google: `https://www.google.com/maps/dir/?api=1&destination=${lat},${lng}`,
|
||||
apple: `https://maps.apple.com/?daddr=${lat},${lng}`,
|
||||
}
|
||||
}
|
||||
|
||||
/** Vrai si l'etape est geolocalisee (entre dans le calcul de trajet, RG-6.05). */
|
||||
export function isStopLocated(stop: Pick<PlanningStop, 'latitude' | 'longitude'>): boolean {
|
||||
return stop.latitude != null && stop.longitude != null
|
||||
}
|
||||
|
||||
/** Estime une duree de trajet (s) a partir d'une distance (m) et la vitesse moyenne. */
|
||||
export function estimateDurationSeconds(distanceMeters: number, speedKmh: number = DEFAULT_SPEED_KMH): number {
|
||||
if (speedKmh <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Math.round((distanceMeters / 1000) / speedKmh * 3600)
|
||||
}
|
||||
|
||||
/** Formate une distance (m) en « 12,3 km » ou « 850 m ». */
|
||||
export function formatDistance(meters: number | null): string {
|
||||
if (meters == null) {
|
||||
return '—'
|
||||
}
|
||||
if (meters < 1000) {
|
||||
return `${Math.round(meters)} m`
|
||||
}
|
||||
|
||||
return `${(meters / 1000).toFixed(1).replace('.', ',')} km`
|
||||
}
|
||||
|
||||
/** Formate une duree (s) en « 1 h 25 » ou « 25 min ». */
|
||||
export function formatDuration(seconds: number | null): string {
|
||||
if (seconds == null) {
|
||||
return '—'
|
||||
}
|
||||
const totalMinutes = Math.round(seconds / 60)
|
||||
const hours = Math.floor(totalMinutes / 60)
|
||||
const minutes = totalMinutes % 60
|
||||
if (hours === 0) {
|
||||
return `${minutes} min`
|
||||
}
|
||||
|
||||
return `${hours} h ${String(minutes).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
/** Extrait l'heure « HH:MM » d'une chaine ISO (eta / departureTime). */
|
||||
export function formatTime(iso: string | null): string {
|
||||
if (iso == null || iso === '') {
|
||||
return '—'
|
||||
}
|
||||
const match = iso.match(/(\d{2}):(\d{2})/)
|
||||
|
||||
return match ? `${match[1]}:${match[2]}` : '—'
|
||||
}
|
||||
|
||||
/** Libelle FR court d'un type de Tiers (pour la couleur/le badge du pin). */
|
||||
export function tierTypeLabel(type: TierType): string {
|
||||
switch (type) {
|
||||
case 'client':
|
||||
return 'Client'
|
||||
case 'supplier':
|
||||
return 'Fournisseur'
|
||||
default:
|
||||
return 'Point libre'
|
||||
}
|
||||
}
|
||||
|
||||
export function useTourPlanning() {
|
||||
return {
|
||||
reorderStops,
|
||||
computeTotals,
|
||||
buildNavigationLinks,
|
||||
isStopLocated,
|
||||
estimateDurationSeconds,
|
||||
formatDistance,
|
||||
formatDuration,
|
||||
formatTime,
|
||||
tierTypeLabel,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { usePaginatedList } from '~/shared/composables/usePaginatedList'
|
||||
import type { Tour } from '~/modules/field-sales/types/tour'
|
||||
|
||||
/**
|
||||
* Liste paginee des tournees (GET /api/tours), branchee sur usePaginatedList
|
||||
* (regle ABSOLUE n°13 : toute collection est paginee). Tri par date decroissante
|
||||
* par defaut. Le filtre `owner` est applique cote back (RG-6.01) — rien a passer
|
||||
* ici.
|
||||
*/
|
||||
export function useToursRepository() {
|
||||
return usePaginatedList<Tour>({
|
||||
url: '/tours',
|
||||
defaultSort: { field: 'tourDate', direction: 'desc' },
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Layer Nuxt du module « Tournées » (field_sales, M6). Auto-detecte par le
|
||||
// shell via le scan de frontend/modules/*/. Config minimale : pages,
|
||||
// composants et composables sont decouverts par convention.
|
||||
export default defineNuxtConfig({})
|
||||
@@ -0,0 +1,648 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- Entete : retour + nom de la tournee. -->
|
||||
<div class="flex items-center gap-3 pt-6 pb-4">
|
||||
<MalioButtonIcon icon="mdi:arrow-left" :aria-label="t('field_sales.plan.back')" @click="goBack" />
|
||||
<h1 class="truncate text-[24px] font-semibold text-primary-500">
|
||||
{{ tour?.label ?? t('field_sales.plan.title') }}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<!-- Layout split responsive : carte + panneau cote a cote en desktop,
|
||||
empile en mobile (carte au-dessus). Etat 100 % local. -->
|
||||
<div class="flex flex-col gap-4 lg:h-[calc(100vh-180px)] lg:flex-row">
|
||||
<!-- Carte interactive. -->
|
||||
<div class="relative h-[45vh] overflow-hidden rounded border border-gray-200 lg:h-auto lg:flex-1">
|
||||
<TourMap
|
||||
ref="mapRef"
|
||||
:stops="stops"
|
||||
:types="activeTypes"
|
||||
:search="mapSearch"
|
||||
:center="mapCenter"
|
||||
@add-tier="addTier"
|
||||
@add-tiers="addTiers"
|
||||
/>
|
||||
<!-- Filtres de la carte (types + recherche). -->
|
||||
<div class="absolute right-2 top-2 z-[400] flex flex-col gap-2 rounded bg-white/95 p-2 shadow">
|
||||
<MalioInputText
|
||||
v-model="mapSearch"
|
||||
:placeholder="t('field_sales.plan.map.search')"
|
||||
icon-name="mdi:magnify"
|
||||
:reserve-message-space="false"
|
||||
input-class="w-44"
|
||||
/>
|
||||
<div class="flex gap-3 text-xs">
|
||||
<label class="flex items-center gap-1">
|
||||
<input v-model="showClients" type="checkbox" class="accent-blue-600"> {{ t('field_sales.plan.map.typeClient') }}
|
||||
</label>
|
||||
<label class="flex items-center gap-1">
|
||||
<input v-model="showSuppliers" type="checkbox" class="accent-green-600"> {{ t('field_sales.plan.map.typeSupplier') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Panneau tournee. -->
|
||||
<div class="flex flex-col gap-4 overflow-y-auto rounded border border-gray-200 p-4 lg:w-[420px]">
|
||||
<!-- Parametres de la tournee. -->
|
||||
<div class="flex flex-col gap-3">
|
||||
<MalioInputText
|
||||
v-model="panel.label"
|
||||
:label="t('field_sales.plan.panel.label')"
|
||||
@update:model-value="debouncedSaveLabel"
|
||||
/>
|
||||
<div class="flex gap-3">
|
||||
<MalioDate v-model="panel.tourDate" :label="t('field_sales.plan.panel.date')" class="flex-1" @update:model-value="saveDate" />
|
||||
<MalioTime v-model="panel.departureTime" :label="t('field_sales.plan.panel.departureTime')" class="flex-1" @update:model-value="saveDepartureTime" />
|
||||
</div>
|
||||
<MalioInputText
|
||||
v-model="panel.startLabel"
|
||||
:label="t('field_sales.plan.panel.startLabel')"
|
||||
@update:model-value="debouncedSaveStart"
|
||||
/>
|
||||
<MalioInputNumber
|
||||
v-model="panel.defaultVisitMinutes"
|
||||
:label="t('field_sales.plan.panel.defaultVisitMinutes')"
|
||||
:min="0"
|
||||
@update:model-value="debouncedSaveVisitMinutes"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Totaux. -->
|
||||
<div class="grid grid-cols-3 gap-2 rounded bg-gray-50 p-3 text-center">
|
||||
<div>
|
||||
<p class="text-xs text-gray-500">{{ t('field_sales.plan.panel.distance') }}</p>
|
||||
<p class="font-semibold">{{ formatDistance(totals.totalDistanceM) }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-gray-500">{{ t('field_sales.plan.panel.duration') }}</p>
|
||||
<p class="font-semibold">{{ formatDuration(totals.totalDurationS) }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-gray-500">{{ t('field_sales.plan.panel.visits') }}</p>
|
||||
<p class="font-semibold">{{ totals.visitCount }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions tournee. -->
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<MalioButton variant="primary" :label="t('field_sales.plan.actions.compute')" :disabled="busy" @click="runCompute" />
|
||||
<MalioButton variant="secondary" :label="t('field_sales.plan.actions.optimize')" :disabled="busy" @click="runOptimize" />
|
||||
<MalioButton variant="tertiary" :label="t('field_sales.plan.actions.duplicate')" :disabled="busy" @click="duplicateOpen = true" />
|
||||
<MalioButton variant="tertiary" :label="t('field_sales.plan.actions.pdf')" @click="openPdf" />
|
||||
</div>
|
||||
|
||||
<!-- Etapes draggables. -->
|
||||
<div>
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<h2 class="font-semibold text-gray-800">{{ t('field_sales.plan.panel.stops') }}</h2>
|
||||
<MalioButton
|
||||
variant="tertiary"
|
||||
:label="t('field_sales.plan.custom.add')"
|
||||
icon-name="mdi:map-marker-plus"
|
||||
icon-position="left"
|
||||
@click="customOpen = true"
|
||||
/>
|
||||
</div>
|
||||
<TourStopList
|
||||
:stops="stops"
|
||||
@reorder="onReorder"
|
||||
@remove="removeStop"
|
||||
@view-tier="viewTier"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modale : point libre custom. -->
|
||||
<MalioModal v-model="customOpen" modal-class="max-w-md">
|
||||
<template #header>
|
||||
<h2 class="text-[22px] font-bold">{{ t('field_sales.plan.custom.title') }}</h2>
|
||||
</template>
|
||||
<div class="flex flex-col gap-3">
|
||||
<MalioInputText v-model="customForm.label" :label="t('field_sales.plan.custom.label')" required :error="customErrors.label" />
|
||||
<MalioInputText v-model="customForm.address" :label="t('field_sales.plan.custom.address')" required :error="customErrors.address" :hint="t('field_sales.plan.custom.hint')" />
|
||||
<p v-if="customGeocodeFailed" class="text-xs text-red-600">{{ t('field_sales.plan.custom.geocodeFailed') }}</p>
|
||||
</div>
|
||||
<template #footer>
|
||||
<MalioButton variant="secondary" :label="t('field_sales.plan.custom.cancel')" button-class="flex-1" @click="customOpen = false" />
|
||||
<MalioButton variant="primary" :label="t('field_sales.plan.custom.confirm')" button-class="flex-1" :disabled="busy" @click="confirmCustom" />
|
||||
</template>
|
||||
</MalioModal>
|
||||
|
||||
<!-- Modale : duplication. -->
|
||||
<MalioModal v-model="duplicateOpen" modal-class="max-w-md">
|
||||
<template #header>
|
||||
<h2 class="text-[22px] font-bold">{{ t('field_sales.plan.duplicateModal.title') }}</h2>
|
||||
</template>
|
||||
<MalioDate v-model="duplicateDate" :label="t('field_sales.plan.duplicateModal.date')" required :error="duplicateError" />
|
||||
<template #footer>
|
||||
<MalioButton variant="secondary" :label="t('field_sales.plan.duplicateModal.cancel')" button-class="flex-1" @click="duplicateOpen = false" />
|
||||
<MalioButton variant="primary" :label="t('field_sales.plan.duplicateModal.confirm')" button-class="flex-1" :disabled="busy" @click="confirmDuplicate" />
|
||||
</template>
|
||||
</MalioModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import TourMap from '~/modules/field-sales/components/TourMap.vue'
|
||||
import TourStopList from '~/modules/field-sales/components/TourStopList.vue'
|
||||
import {
|
||||
computeTotals,
|
||||
formatDistance,
|
||||
formatDuration,
|
||||
formatTime,
|
||||
type PlanningStop,
|
||||
} from '~/modules/field-sales/composables/useTourPlanning'
|
||||
import { useAddressAutocomplete } from '~/shared/composables/useAddressAutocomplete'
|
||||
import type { Tour, TourStop, VisitableTier } from '~/modules/field-sales/types/tour'
|
||||
|
||||
/**
|
||||
* Ecran de planification d'une tournee (M6.5, spec § 6.1).
|
||||
*
|
||||
* Carte interactive (pins + lasso + trace) a gauche, panneau (parametres,
|
||||
* totaux, actions, etapes draggables) a droite ; empile en mobile. Etat 100 %
|
||||
* LOCAL (jamais dans l'URL, regle ABSOLUE n°6).
|
||||
*
|
||||
* Les etapes sur Tiers referentiel ne portent pas leurs coordonnees/nom dans
|
||||
* tour_stop:read : on les resout via GET /visitable_tiers/{type}-{addressId}
|
||||
* (cache local) pour alimenter des `PlanningStop` enrichis.
|
||||
*/
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const toast = useToast()
|
||||
const autocomplete = useAddressAutocomplete()
|
||||
|
||||
const tourId = computed(() => Number(route.params.id))
|
||||
|
||||
const tour = ref<Tour | null>(null)
|
||||
const stops = ref<PlanningStop[]>([])
|
||||
const busy = ref(false)
|
||||
const mapRef = ref<InstanceType<typeof TourMap> | null>(null)
|
||||
|
||||
useHead({ title: () => tour.value?.label ?? t('field_sales.plan.title') })
|
||||
|
||||
// Cache des infos Tiers (nom/adresse/coords) par cle « type-addressId » : evite
|
||||
// de refetcher /visitable_tiers/{id} a chaque recompute.
|
||||
const tierCache = new Map<string, { label: string, displayAddress: string, latitude: number, longitude: number }>()
|
||||
|
||||
// ── Panneau (formulaire local synchronise avec la tournee) ──────────────────
|
||||
// defaultVisitMinutes est une chaine (MalioInputNumber est un v-model string).
|
||||
const panel = reactive<{
|
||||
label: string
|
||||
tourDate: string | null
|
||||
departureTime: string | null
|
||||
startLabel: string
|
||||
defaultVisitMinutes: string
|
||||
}>({
|
||||
label: '',
|
||||
tourDate: null,
|
||||
departureTime: null,
|
||||
startLabel: '',
|
||||
defaultVisitMinutes: '30',
|
||||
})
|
||||
|
||||
/** Debounce simple (les saves lisent l'etat `panel`, donc sans argument). */
|
||||
function debounce(fn: () => void, ms: number): () => void {
|
||||
let handle: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
return () => {
|
||||
if (handle !== null) {
|
||||
clearTimeout(handle)
|
||||
}
|
||||
handle = setTimeout(fn, ms)
|
||||
}
|
||||
}
|
||||
const debouncedSaveLabel = debounce(() => { void saveLabel() }, 600)
|
||||
const debouncedSaveStart = debounce(() => { void saveStart() }, 800)
|
||||
const debouncedSaveVisitMinutes = debounce(() => { void saveVisitMinutes() }, 600)
|
||||
|
||||
// ── Carte : filtres ──────────────────────────────────────────────────────────
|
||||
const showClients = ref(true)
|
||||
const showSuppliers = ref(true)
|
||||
const mapSearch = ref('')
|
||||
const activeTypes = computed<Array<'client' | 'supplier'>>(() => {
|
||||
const types: Array<'client' | 'supplier'> = []
|
||||
if (showClients.value) {
|
||||
types.push('client')
|
||||
}
|
||||
if (showSuppliers.value) {
|
||||
types.push('supplier')
|
||||
}
|
||||
|
||||
return types
|
||||
})
|
||||
const mapCenter = ref<[number, number]>([47.218, -1.553])
|
||||
|
||||
// ── Totaux recalcules localement (feedback instantane) ──────────────────────
|
||||
const totals = computed(() => computeTotals(stops.value, Number(panel.defaultVisitMinutes) || 0))
|
||||
|
||||
// ── Modales ──────────────────────────────────────────────────────────────────
|
||||
const customOpen = ref(false)
|
||||
const customForm = reactive({ label: '', address: '' })
|
||||
const customErrors = reactive<{ label: string, address: string }>({ label: '', address: '' })
|
||||
const customGeocodeFailed = ref(false)
|
||||
|
||||
const duplicateOpen = ref(false)
|
||||
const duplicateDate = ref<string | null>(null)
|
||||
const duplicateError = ref('')
|
||||
|
||||
// =============================================================================
|
||||
// Chargement + enrichissement
|
||||
// =============================================================================
|
||||
onMounted(loadTour)
|
||||
|
||||
async function loadTour(): Promise<void> {
|
||||
try {
|
||||
const raw = await api.get<Tour>(`/tours/${tourId.value}`, {}, {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
await applyTour(raw, true)
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t('field_sales.plan.toast.loadError') })
|
||||
router.push('/tours')
|
||||
}
|
||||
}
|
||||
|
||||
/** Applique une reponse Tour au state local. `withStops` re-enrichit les etapes. */
|
||||
async function applyTour(raw: Tour, withStops: boolean): Promise<void> {
|
||||
tour.value = raw
|
||||
panel.label = raw.label
|
||||
panel.tourDate = raw.tourDate ? raw.tourDate.slice(0, 10) : null
|
||||
panel.departureTime = extractTime(raw.departureTime)
|
||||
panel.startLabel = raw.startLabel ?? ''
|
||||
panel.defaultVisitMinutes = String(raw.defaultVisitMinutes)
|
||||
|
||||
if (withStops) {
|
||||
stops.value = await enrichStops(raw.stops ?? [])
|
||||
recenterOnFirstStop()
|
||||
}
|
||||
}
|
||||
|
||||
/** Resout nom/adresse/coords de chaque etape en `PlanningStop`. */
|
||||
async function enrichStops(rawStops: TourStop[]): Promise<PlanningStop[]> {
|
||||
const ordered = [...rawStops].sort((a, b) => a.position - b.position)
|
||||
|
||||
return Promise.all(ordered.map(async (stop): Promise<PlanningStop> => {
|
||||
if (stop.tierType === 'custom') {
|
||||
return {
|
||||
...stop,
|
||||
label: stop.customLabel ?? '',
|
||||
displayAddress: stop.customAddress ?? '',
|
||||
latitude: stop.customLatitude != null ? Number(stop.customLatitude) : null,
|
||||
longitude: stop.customLongitude != null ? Number(stop.customLongitude) : null,
|
||||
}
|
||||
}
|
||||
|
||||
const info = await resolveTier(stop.tierType, stop.addressId)
|
||||
|
||||
return {
|
||||
...stop,
|
||||
label: info?.label ?? `#${stop.tierId}`,
|
||||
displayAddress: info?.displayAddress ?? '',
|
||||
latitude: info?.latitude ?? null,
|
||||
longitude: info?.longitude ?? null,
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/** Infos d'un Tiers (cache + GET /visitable_tiers/{type-addressId}). */
|
||||
async function resolveTier(tierType: string, addressId: number | null) {
|
||||
if (addressId === null) {
|
||||
return null
|
||||
}
|
||||
const key = `${tierType}-${addressId}`
|
||||
const cached = tierCache.get(key)
|
||||
if (cached) {
|
||||
return cached
|
||||
}
|
||||
try {
|
||||
const tier = await api.get<VisitableTier>(`/visitable_tiers/${key}`, {}, {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
const info = {
|
||||
label: tier.displayName,
|
||||
displayAddress: tier.address,
|
||||
latitude: tier.latitude,
|
||||
longitude: tier.longitude,
|
||||
}
|
||||
tierCache.set(key, info)
|
||||
|
||||
return info
|
||||
}
|
||||
catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function recenterOnFirstStop(): void {
|
||||
const located = stops.value.find(s => s.latitude != null && s.longitude != null)
|
||||
if (located) {
|
||||
mapCenter.value = [located.latitude as number, located.longitude as number]
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Ajout d'etapes (carte)
|
||||
// =============================================================================
|
||||
async function addTier(tier: VisitableTier): Promise<void> {
|
||||
// Pre-alimente le cache (la carte connait deja nom/adresse/coords du pin).
|
||||
tierCache.set(`${tier.tierType}-${tier.addressId}`, {
|
||||
label: tier.displayName,
|
||||
displayAddress: tier.address,
|
||||
latitude: tier.latitude,
|
||||
longitude: tier.longitude,
|
||||
})
|
||||
await postStop({
|
||||
tierType: tier.tierType,
|
||||
tierId: tier.tierId,
|
||||
addressId: tier.addressId,
|
||||
position: stops.value.length,
|
||||
})
|
||||
}
|
||||
|
||||
async function addTiers(tiers: VisitableTier[]): Promise<void> {
|
||||
if (busy.value) {
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
try {
|
||||
let position = stops.value.length
|
||||
for (const tier of tiers) {
|
||||
tierCache.set(`${tier.tierType}-${tier.addressId}`, {
|
||||
label: tier.displayName,
|
||||
displayAddress: tier.address,
|
||||
latitude: tier.latitude,
|
||||
longitude: tier.longitude,
|
||||
})
|
||||
await api.post('/tours/' + tourId.value + '/stops', {
|
||||
tierType: tier.tierType,
|
||||
tierId: tier.tierId,
|
||||
addressId: tier.addressId,
|
||||
position: position++,
|
||||
}, { toast: false })
|
||||
}
|
||||
await runCompute()
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t('field_sales.plan.toast.stopError') })
|
||||
}
|
||||
finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** POST d'une etape puis recompute (factorise add tier / custom). */
|
||||
async function postStop(payload: Record<string, unknown>): Promise<void> {
|
||||
if (busy.value) {
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
try {
|
||||
await api.post('/tours/' + tourId.value + '/stops', payload, { toast: false })
|
||||
await runCompute()
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t('field_sales.plan.toast.stopError') })
|
||||
}
|
||||
finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmCustom(): Promise<void> {
|
||||
customErrors.label = customForm.label.trim() === '' ? t('field_sales.plan.custom.label') : ''
|
||||
customErrors.address = customForm.address.trim() === '' ? t('field_sales.plan.custom.address') : ''
|
||||
if (customErrors.label || customErrors.address) {
|
||||
return
|
||||
}
|
||||
customGeocodeFailed.value = false
|
||||
|
||||
// Geocodage de l'adresse libre (BAN). Echec -> point non geolocalise (exclu
|
||||
// du calcul, RG-6.05) mais l'etape est tout de meme creee.
|
||||
let coords: { latitude: string, longitude: string } | null = null
|
||||
try {
|
||||
coords = await autocomplete.geocode(customForm.address.trim())
|
||||
}
|
||||
catch {
|
||||
coords = null
|
||||
}
|
||||
if (coords === null) {
|
||||
customGeocodeFailed.value = true
|
||||
}
|
||||
|
||||
await postStop({
|
||||
tierType: 'custom',
|
||||
customLabel: customForm.label.trim(),
|
||||
customAddress: customForm.address.trim(),
|
||||
customLatitude: coords?.latitude ?? null,
|
||||
customLongitude: coords?.longitude ?? null,
|
||||
position: stops.value.length,
|
||||
})
|
||||
|
||||
if (!customGeocodeFailed.value) {
|
||||
customOpen.value = false
|
||||
customForm.label = ''
|
||||
customForm.address = ''
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Reordonnancement / suppression / navigation
|
||||
// =============================================================================
|
||||
async function onReorder(next: PlanningStop[]): Promise<void> {
|
||||
if (busy.value) {
|
||||
return
|
||||
}
|
||||
// Optimisme : on reflete l'ordre immediatement, le serveur recalcule ensuite.
|
||||
stops.value = next.map((s, i) => ({ ...s, position: i }))
|
||||
busy.value = true
|
||||
try {
|
||||
const raw = await api.post<Tour>('/tours/' + tourId.value + '/reorder', {
|
||||
stopIds: next.map(s => s.id),
|
||||
}, { headers: { Accept: 'application/ld+json' }, toast: false })
|
||||
await applyTour(raw, true)
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t('field_sales.plan.toast.stopError') })
|
||||
await loadTour()
|
||||
}
|
||||
finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function removeStop(stop: PlanningStop): Promise<void> {
|
||||
if (busy.value) {
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
try {
|
||||
await api.delete(`/tour_stops/${stop.id}`, {}, { toast: false })
|
||||
await runCompute()
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t('field_sales.plan.toast.stopError') })
|
||||
}
|
||||
finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function viewTier(stop: PlanningStop): void {
|
||||
if (stop.tierId === null) {
|
||||
return
|
||||
}
|
||||
router.push(stop.tierType === 'supplier' ? `/suppliers/${stop.tierId}` : `/clients/${stop.tierId}`)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Actions tournee : compute / optimize / duplicate / pdf
|
||||
// =============================================================================
|
||||
async function runCompute(): Promise<void> {
|
||||
await runTourAction('/compute', 'computeError')
|
||||
}
|
||||
|
||||
async function runOptimize(): Promise<void> {
|
||||
await runTourAction('/optimize', 'optimizeError')
|
||||
}
|
||||
|
||||
/** Factorise compute/optimize : POST sans corps -> reapplique la tournee. */
|
||||
async function runTourAction(path: string, errorKey: string): Promise<void> {
|
||||
const wasBusy = busy.value
|
||||
busy.value = true
|
||||
try {
|
||||
const raw = await api.post<Tour>('/tours/' + tourId.value + path, {}, {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
await applyTour(raw, true)
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t(`field_sales.plan.toast.${errorKey}`) })
|
||||
}
|
||||
finally {
|
||||
busy.value = wasBusy ? busy.value : false
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDuplicate(): Promise<void> {
|
||||
duplicateError.value = ''
|
||||
if (duplicateDate.value === null || duplicateDate.value === '') {
|
||||
duplicateError.value = t('field_sales.plan.duplicateModal.date')
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
try {
|
||||
const copy = await api.post<Tour>('/tours/' + tourId.value + '/duplicate', {
|
||||
tourDate: duplicateDate.value,
|
||||
}, { headers: { Accept: 'application/ld+json' }, toast: false })
|
||||
toast.success({ title: t('field_sales.tours.title'), message: t('field_sales.plan.toast.duplicated') })
|
||||
duplicateOpen.value = false
|
||||
router.push(`/tours/${copy.id}/plan`)
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t('field_sales.plan.toast.duplicateError') })
|
||||
}
|
||||
finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** Ouvre la feuille de route PDF (le cookie JWT est envoye avec la requete). */
|
||||
function openPdf(): void {
|
||||
window.open(`/api/tours/${tourId.value}/roadbook.pdf`, '_blank')
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Sauvegarde des parametres du panneau (PATCH, recompute si ETA impactee)
|
||||
// =============================================================================
|
||||
async function saveLabel(): Promise<void> {
|
||||
if (panel.label.trim() !== '' && panel.label !== tour.value?.label) {
|
||||
await patchTour({ label: panel.label.trim() }, false)
|
||||
}
|
||||
}
|
||||
|
||||
async function saveDate(): Promise<void> {
|
||||
if (panel.tourDate) {
|
||||
await patchTour({ tourDate: panel.tourDate }, false)
|
||||
}
|
||||
}
|
||||
|
||||
async function saveDepartureTime(): Promise<void> {
|
||||
if (panel.departureTime) {
|
||||
await patchTour({ departureTime: panel.departureTime }, true)
|
||||
}
|
||||
}
|
||||
|
||||
async function saveVisitMinutes(): Promise<void> {
|
||||
const minutes = Number(panel.defaultVisitMinutes)
|
||||
if (!Number.isFinite(minutes) || minutes < 0) {
|
||||
return
|
||||
}
|
||||
await patchTour({ defaultVisitMinutes: minutes }, true)
|
||||
}
|
||||
|
||||
/** Geocode le point de depart (ou le vide) puis recompute. */
|
||||
async function saveStart(): Promise<void> {
|
||||
const label = panel.startLabel.trim()
|
||||
if (label === '' && (tour.value?.startLabel ?? '') === '') {
|
||||
return
|
||||
}
|
||||
let coords: { latitude: string, longitude: string } | null = null
|
||||
if (label !== '') {
|
||||
try {
|
||||
coords = await autocomplete.geocode(label)
|
||||
}
|
||||
catch {
|
||||
coords = null
|
||||
}
|
||||
}
|
||||
await patchTour({
|
||||
startLabel: label === '' ? null : label,
|
||||
startLatitude: coords?.latitude ?? null,
|
||||
startLongitude: coords?.longitude ?? null,
|
||||
}, true)
|
||||
}
|
||||
|
||||
/** PATCH /tours/{id}. `recompute` enchaine /compute (ETA impactee). */
|
||||
async function patchTour(partial: Record<string, unknown>, recompute: boolean): Promise<void> {
|
||||
busy.value = true
|
||||
try {
|
||||
const raw = await api.patch<Tour>(`/tours/${tourId.value}`, partial, {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
// PATCH renvoie tour:read SANS etapes : on ne touche pas a `stops`.
|
||||
await applyTour(raw, false)
|
||||
if (recompute) {
|
||||
await runCompute()
|
||||
}
|
||||
}
|
||||
catch {
|
||||
toast.error({ title: t('errors.title'), message: t('field_sales.plan.toast.saveError') })
|
||||
}
|
||||
finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Utilitaires
|
||||
// =============================================================================
|
||||
function extractTime(iso: string | null): string | null {
|
||||
const formatted = formatTime(iso)
|
||||
|
||||
return formatted === '—' ? null : formatted
|
||||
}
|
||||
|
||||
function goBack(): void {
|
||||
router.push('/tours')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,124 @@
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader>
|
||||
{{ t('field_sales.tours.title') }}
|
||||
<template #actions>
|
||||
<MalioButton
|
||||
v-if="canManage"
|
||||
variant="secondary"
|
||||
:label="t('field_sales.tours.add')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@click="goToCreate"
|
||||
/>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<MalioDataTable
|
||||
:columns="columns"
|
||||
:items="rows"
|
||||
:total-items="totalItems"
|
||||
:page="currentPage"
|
||||
:per-page="itemsPerPage"
|
||||
:per-page-options="itemsPerPageOptions"
|
||||
row-clickable
|
||||
:empty-message="t('field_sales.tours.empty')"
|
||||
@row-click="onRowClick"
|
||||
@update:page="goToPage"
|
||||
@update:per-page="setItemsPerPage"
|
||||
>
|
||||
<template #cell-tourDate="{ item }">
|
||||
{{ formatDate(item.tourDate as string) }}
|
||||
</template>
|
||||
<template #cell-status="{ item }">
|
||||
<span class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium" :class="statusClass(item.status as TourStatus)">
|
||||
{{ t(`field_sales.tours.status.${item.status}`) }}
|
||||
</span>
|
||||
</template>
|
||||
<template #cell-distance="{ item }">
|
||||
{{ formatDistance((item.totalDistanceM as number | null) ?? null) }}
|
||||
</template>
|
||||
<template #cell-duration="{ item }">
|
||||
{{ formatDuration((item.totalDurationS as number | null) ?? null) }}
|
||||
</template>
|
||||
</MalioDataTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { useToursRepository } from '~/modules/field-sales/composables/useToursRepository'
|
||||
import { formatDistance, formatDuration } from '~/modules/field-sales/composables/useTourPlanning'
|
||||
import type { Tour, TourStatus } from '~/modules/field-sales/types/tour'
|
||||
|
||||
const { t } = useI18n()
|
||||
const router = useRouter()
|
||||
const { can } = usePermissions()
|
||||
|
||||
useHead({ title: t('field_sales.tours.title') })
|
||||
|
||||
const canManage = computed(() => can('field_sales.tours.manage'))
|
||||
|
||||
const {
|
||||
items: tours,
|
||||
totalItems,
|
||||
currentPage,
|
||||
itemsPerPage,
|
||||
itemsPerPageOptions,
|
||||
fetch: loadTours,
|
||||
goToPage,
|
||||
setItemsPerPage,
|
||||
} = useToursRepository()
|
||||
|
||||
const rows = computed(() => tours.value.map(tour => ({
|
||||
id: tour.id,
|
||||
label: tour.label,
|
||||
tourDate: tour.tourDate,
|
||||
status: tour.status,
|
||||
totalDistanceM: tour.totalDistanceM,
|
||||
totalDurationS: tour.totalDurationS,
|
||||
})))
|
||||
|
||||
const columns = [
|
||||
{ key: 'label', label: t('field_sales.tours.column.label') },
|
||||
{ key: 'tourDate', label: t('field_sales.tours.column.date') },
|
||||
{ key: 'status', label: t('field_sales.tours.column.status') },
|
||||
{ key: 'distance', label: t('field_sales.tours.column.distance') },
|
||||
{ key: 'duration', label: t('field_sales.tours.column.duration') },
|
||||
]
|
||||
|
||||
/** Couleur du badge de statut. */
|
||||
function statusClass(status: TourStatus): string {
|
||||
switch (status) {
|
||||
case 'planned':
|
||||
return 'bg-blue-100 text-blue-800'
|
||||
case 'in_progress':
|
||||
return 'bg-amber-100 text-amber-800'
|
||||
case 'done':
|
||||
return 'bg-green-100 text-green-800'
|
||||
default:
|
||||
return 'bg-gray-100 text-gray-700'
|
||||
}
|
||||
}
|
||||
|
||||
/** Date courte FR (la date arrive en ISO depuis l'API). */
|
||||
function formatDate(iso: string): string {
|
||||
if (!iso) {
|
||||
return ''
|
||||
}
|
||||
const date = new Date(iso)
|
||||
|
||||
return Number.isNaN(date.getTime()) ? '' : date.toLocaleDateString('fr-FR')
|
||||
}
|
||||
|
||||
/** Clic ligne → ecran de planification de la tournee. */
|
||||
function onRowClick(item: Record<string, unknown>): void {
|
||||
router.push(`/tours/${(item as { id: Tour['id'] }).id}/plan`)
|
||||
}
|
||||
|
||||
function goToCreate(): void {
|
||||
router.push('/tours/new')
|
||||
}
|
||||
|
||||
onMounted(loadTours)
|
||||
</script>
|
||||
@@ -0,0 +1,96 @@
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader>
|
||||
{{ t('field_sales.tours.new.title') }}
|
||||
</PageHeader>
|
||||
|
||||
<div class="mx-auto max-w-xl">
|
||||
<form class="flex flex-col gap-4" @submit.prevent="submit">
|
||||
<MalioInputText
|
||||
v-model="form.label"
|
||||
:label="t('field_sales.tours.new.label')"
|
||||
required
|
||||
:error="errors.label"
|
||||
/>
|
||||
<MalioDate
|
||||
v-model="form.tourDate"
|
||||
:label="t('field_sales.tours.new.date')"
|
||||
required
|
||||
:error="errors.tourDate"
|
||||
/>
|
||||
|
||||
<div class="mt-2 flex justify-end gap-3">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
:label="t('field_sales.tours.new.cancel')"
|
||||
type="button"
|
||||
@click="cancel"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('field_sales.tours.new.create')"
|
||||
type="submit"
|
||||
:disabled="submitting"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useFormErrors } from '~/shared/composables/useFormErrors'
|
||||
import type { Tour } from '~/modules/field-sales/types/tour'
|
||||
|
||||
/**
|
||||
* Creation d'une tournee (draft). Formulaire minimal (nom + date) : le reste de
|
||||
* la planification (etapes, point de depart, heure) se fait sur l'ecran de
|
||||
* planification une fois la tournee creee. Validation inline 422 via useFormErrors.
|
||||
*/
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const router = useRouter()
|
||||
const { can } = usePermissions()
|
||||
const { errors, clearErrors, handleApiError } = useFormErrors()
|
||||
|
||||
useHead({ title: t('field_sales.tours.new.title') })
|
||||
|
||||
// Garde-fou : sans manage, on renvoie vers la liste (le back refuse de toute facon).
|
||||
if (!can('field_sales.tours.manage')) {
|
||||
router.replace('/tours')
|
||||
}
|
||||
|
||||
const form = reactive<{ label: string, tourDate: string | null }>({
|
||||
label: '',
|
||||
tourDate: null,
|
||||
})
|
||||
const submitting = ref(false)
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
if (submitting.value) {
|
||||
return
|
||||
}
|
||||
clearErrors()
|
||||
submitting.value = true
|
||||
try {
|
||||
const tour = await api.post<Tour>('/tours', {
|
||||
label: form.label,
|
||||
tourDate: form.tourDate,
|
||||
}, { toast: false })
|
||||
|
||||
// Enchaine directement sur la planification de la tournee creee.
|
||||
router.push(`/tours/${tour.id}/plan`)
|
||||
}
|
||||
catch (e) {
|
||||
handleApiError(e, { fallbackMessage: t('field_sales.tours.new.error') })
|
||||
}
|
||||
finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function cancel(): void {
|
||||
router.push('/tours')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Types du module « Tournées » (field_sales, M6.5).
|
||||
*
|
||||
* Reflet des DTO exposes par l'API (groupes `tour:read` / `tour_stop:read` /
|
||||
* VisitableTier). Les dates/heures arrivent en chaines ISO 8601 ; le formatage
|
||||
* d'affichage (HH:MM, jj/mm/aaaa) est fait dans les ecrans.
|
||||
*/
|
||||
|
||||
/** Type de Tiers visitable cote front (aligne sur l'enum ouvert du back). */
|
||||
export type TierType = 'client' | 'supplier' | 'custom'
|
||||
|
||||
/** Cycle de vie d'une tournee (RG-6.02). */
|
||||
export type TourStatus = 'draft' | 'planned' | 'in_progress' | 'done'
|
||||
|
||||
/** Une etape de tournee (tour_stop:read). */
|
||||
export interface TourStop {
|
||||
id: number
|
||||
tierType: TierType
|
||||
tierId: number | null
|
||||
addressId: number | null
|
||||
customLabel: string | null
|
||||
customAddress: string | null
|
||||
customLatitude: string | null
|
||||
customLongitude: string | null
|
||||
position: number
|
||||
visitMinutes: number | null
|
||||
/** Distance depuis l'etape precedente (m), calculee (compute). */
|
||||
legDistanceM: number | null
|
||||
/** Duree de trajet depuis l'etape precedente (s), calculee. */
|
||||
legDurationS: number | null
|
||||
/** Heure d'arrivee estimee (ISO time), calculee (RG-6.11). */
|
||||
eta: string | null
|
||||
}
|
||||
|
||||
/** Une tournee (tour:read + stops embarquees en tour:item:read). */
|
||||
export interface Tour {
|
||||
id: number
|
||||
label: string
|
||||
/** Date de realisation (ISO date). */
|
||||
tourDate: string
|
||||
/** Heure de depart (ISO time). */
|
||||
departureTime: string
|
||||
startLatitude: string | null
|
||||
startLongitude: string | null
|
||||
startLabel: string | null
|
||||
defaultVisitMinutes: number
|
||||
status: TourStatus
|
||||
totalDistanceM: number | null
|
||||
totalDurationS: number | null
|
||||
stops?: TourStop[]
|
||||
}
|
||||
|
||||
/** Un pin de la carte = une adresse geolocalisee d'un Tiers (VisitableTier). */
|
||||
export interface VisitableTier {
|
||||
id: string
|
||||
tierType: Exclude<TierType, 'custom'>
|
||||
tierId: number
|
||||
addressId: number
|
||||
displayName: string
|
||||
address: string
|
||||
latitude: number
|
||||
longitude: number
|
||||
}
|
||||
|
||||
/** Liens d'ouverture de navigation externe (« Y aller »). */
|
||||
export interface NavigationLinks {
|
||||
waze: string
|
||||
google: string
|
||||
apple: string
|
||||
}
|
||||
|
||||
/** Totaux d'une tournee recalcules cote front (feedback instantane). */
|
||||
export interface TourTotals {
|
||||
/** Distance cumulee des trajets (m). */
|
||||
totalDistanceM: number
|
||||
/** Duree totale = trajets + visites (s). */
|
||||
totalDurationS: number
|
||||
/** Duree de trajet seule (s). */
|
||||
travelDurationS: number
|
||||
/** Duree de visite cumulee (s). */
|
||||
visitDurationS: number
|
||||
/** Nombre de visites (etapes). */
|
||||
visitCount: number
|
||||
}
|
||||
@@ -62,7 +62,7 @@
|
||||
<MalioInputText
|
||||
v-model="form.color"
|
||||
placeholder="#RRGGBB"
|
||||
input-class="w-full font-mono"
|
||||
input-class="w-full"
|
||||
required
|
||||
/>
|
||||
<!-- pb-4 sur le wrapper : simule le slot message du
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<template #actions>
|
||||
<MalioButton
|
||||
v-if="can('sites.manage')"
|
||||
variant="secondary"
|
||||
:label="t('admin.sites.newSite')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@@ -33,11 +34,11 @@
|
||||
:style="{ backgroundColor: item.color }"
|
||||
class="inline-block size-5 rounded-full border border-neutral-200"
|
||||
/>
|
||||
<span class="font-mono text-xs">{{ item.color }}</span>
|
||||
<span>{{ item.color }}</span>
|
||||
</span>
|
||||
</template>
|
||||
<template #cell-fullAddress="{ item }">
|
||||
<span class="line-clamp-2 text-xs text-neutral-600">
|
||||
<span class="line-clamp-2 text-neutral-600">
|
||||
{{ item.fullAddress }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
Generated
+83
-30
@@ -7,16 +7,19 @@
|
||||
"name": "starseed-frontend",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@malio/layer-ui": "^1.7.4",
|
||||
"@malio/layer-ui": "^1.7.8",
|
||||
"@nuxt/icon": "^2.2.1",
|
||||
"@nuxtjs/i18n": "^10.2.3",
|
||||
"@nuxtjs/tailwindcss": "^6.14.0",
|
||||
"@pinia/nuxt": "^0.11.3",
|
||||
"@types/leaflet": "^1.9.21",
|
||||
"leaflet": "^1.9.4",
|
||||
"nuxt": "^4.3.1",
|
||||
"nuxt-toast": "^1.4.0",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.29",
|
||||
"vue-router": "^4.6.4"
|
||||
"vue-router": "^4.6.4",
|
||||
"vuedraggable": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nuxt/eslint-config": "^1.9.0",
|
||||
@@ -85,6 +88,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.0.tgz",
|
||||
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.29.0",
|
||||
"@babel/generator": "^7.29.0",
|
||||
@@ -582,31 +586,10 @@
|
||||
"integrity": "sha512-/B8YJGPzaYq1NbsQmwgP8EZqg40NpTw4ZB3suuI0TplbxKHeK94jeaawLmVhCv+YwUnOpiWEz9U6SeThku/8JQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz",
|
||||
"integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "1.2.1",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz",
|
||||
"integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/wasi-threads": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
|
||||
"integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==",
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz",
|
||||
"integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -1303,6 +1286,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.7.6.tgz",
|
||||
"integrity": "sha512-9gZSAI5XM36880PPMm//9dfiEngYoC6Am2izES1FF406YFsjvyBMmeJ2g4SAju3xWwtuynNRFL2s9hgxpLI5SQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@floating-ui/core": "^1.7.5",
|
||||
"@floating-ui/utils": "^0.2.11"
|
||||
@@ -1866,9 +1850,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@malio/layer-ui": {
|
||||
"version": "1.7.4",
|
||||
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.4/layer-ui-1.7.4.tgz",
|
||||
"integrity": "sha512-JNXwBelj5UQ35Qv5VmnassXKt8niX9jDXjM1vUSukJQiyeUXRxAiZr16QumVgBN9P9YGDyjXVKrwCHltTXvPtQ==",
|
||||
"version": "1.7.8",
|
||||
"resolved": "https://gitea.malio.fr/api/packages/MALIO-DEV/npm/%40malio%2Flayer-ui/-/1.7.8/layer-ui-1.7.8.tgz",
|
||||
"integrity": "sha512-gUMAZzBsPCfQUF3OQSjN/OFzjONvQZYfwqH0u5VUbxaqwBdX1hUGtjD4ym6RvZkyNsKulrxkncFZYTWCS+IdGA==",
|
||||
"dependencies": {
|
||||
"@nuxt/icon": "^2.2.1",
|
||||
"@nuxtjs/tailwindcss": "^6.14.0",
|
||||
@@ -2221,6 +2205,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@nuxt/kit/-/kit-4.4.2.tgz",
|
||||
"integrity": "sha512-5+IPRNX2CjkBhuWUwz0hBuLqiaJPRoKzQ+SvcdrQDbAyE+VDeFt74VpSFr5/R0ujrK4b+XnSHUJWdS72w6hsog==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"c12": "^3.3.3",
|
||||
"consola": "^3.4.2",
|
||||
@@ -2323,6 +2308,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@nuxt/schema/-/schema-4.4.2.tgz",
|
||||
"integrity": "sha512-/q6C7Qhiricgi+PKR7ovBnJlKTL0memCbA1CzRT+itCW/oeYzUfeMdQ35mGntlBoyRPNrMXbzuSUhfDbSCU57w==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@vue/shared": "^3.5.30",
|
||||
"defu": "^6.1.4",
|
||||
@@ -4638,6 +4624,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.23.2.tgz",
|
||||
"integrity": "sha512-yjv2N7gaQMbIVfsSZHBMscLoybgetcTraXsSMrELAerl/jfRipg5S1dBXMFvgRy8Kh48+TGoH+5nqshxdOEGoQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ueberdosis"
|
||||
@@ -4886,6 +4873,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@tiptap/extension-list/-/extension-list-3.23.2.tgz",
|
||||
"integrity": "sha512-tRbbjpOPrY4ApIHtn3ctnKIhkkioewMsZa5gJzqVB47LJFNyzLXLo/aID4sJRKTIMi1wd1fA9TiBKPe6KqczPA==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ueberdosis"
|
||||
@@ -4991,6 +4979,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@tiptap/extension-text-style/-/extension-text-style-3.23.2.tgz",
|
||||
"integrity": "sha512-K2o1gMwn09nrd5ewftSy08U6LMC1cW3Cmml5+vHT9P/VeMtYwkbNg+9Mt1uFh7VfAZmlkj8d3u7RYqfl8xMVJA==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ueberdosis"
|
||||
@@ -5017,6 +5006,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@tiptap/extensions/-/extensions-3.23.2.tgz",
|
||||
"integrity": "sha512-kRHQ3nSbAfkFdxj9FtDdr4hpREndGgWFA6ZEAwlLeGUxf8QYTpuF9zb2yxdBPBlTc5+JsbPcskNt+u1PazGKYw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ueberdosis"
|
||||
@@ -5031,6 +5021,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@tiptap/pm/-/pm-3.23.2.tgz",
|
||||
"integrity": "sha512-1kvsBqGNu2ZJ0P/lkxN0pAMqSyUcpkMIzE4xwGUIyAiD0pZV6dr+OCMwGWOTLllSyrn91xI5K7OLk3pYeCPKqA==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"prosemirror-changeset": "^2.3.0",
|
||||
"prosemirror-commands": "^1.6.2",
|
||||
@@ -5140,12 +5131,27 @@
|
||||
"integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/geojson": {
|
||||
"version": "7946.0.16",
|
||||
"resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.16.tgz",
|
||||
"integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
|
||||
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/leaflet": {
|
||||
"version": "1.9.21",
|
||||
"resolved": "https://registry.npmjs.org/@types/leaflet/-/leaflet-1.9.21.tgz",
|
||||
"integrity": "sha512-TbAd9DaPGSnzp6QvtYngntMZgcRk+igFELwR2N99XZn7RXUdKgsXMR+28bUO0rPsWp8MIu/f47luLIQuSLYv/w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/geojson": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/linkify-it": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.5.tgz",
|
||||
@@ -5174,6 +5180,7 @@
|
||||
"integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~7.19.0"
|
||||
}
|
||||
@@ -5236,6 +5243,7 @@
|
||||
"integrity": "sha512-/Zb/xaIDfxeJnvishjGdcR4jmr7S+bda8PKNhRGdljDM+elXhlvN0FyPSsMnLmJUrVG9aPO6dof80wjMawsASg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.58.2",
|
||||
"@typescript-eslint/types": "8.58.2",
|
||||
@@ -6015,6 +6023,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.5.32.tgz",
|
||||
"integrity": "sha512-8UYUYo71cP/0YHMO814TRZlPuUUw3oifHuMR7Wp9SNoRSrxRQnhMLNlCeaODNn6kNTJsjFoQ/kqIj4qGvya4Xg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.29.2",
|
||||
"@vue/compiler-core": "3.5.32",
|
||||
@@ -6258,6 +6267,7 @@
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz",
|
||||
"integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -6645,6 +6655,7 @@
|
||||
"resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.8.2.tgz",
|
||||
"integrity": "sha512-riJjyv1/mHLIPX4RwiK+oW9/4c3TEUeORHKefKAKnZ5kyslbN+HXowtbaVEqt4IMUB7OXlfixcs6gsFeo/jhiQ==",
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"peerDependencies": {
|
||||
"bare-abort-controller": "*"
|
||||
},
|
||||
@@ -6842,6 +6853,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"baseline-browser-mapping": "^2.10.12",
|
||||
"caniuse-lite": "^1.0.30001782",
|
||||
@@ -6956,6 +6968,7 @@
|
||||
"resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz",
|
||||
"integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
@@ -7150,7 +7163,8 @@
|
||||
"version": "0.2.2",
|
||||
"resolved": "https://registry.npmjs.org/citty/-/citty-0.2.2.tgz",
|
||||
"integrity": "sha512-+6vJA3L98yv+IdfKGZHBNiGW5KHn22e/JwID0Strsz8h4S/csAu/OuICwxrg44k5MRiZHWIo8XXuJgQTriRP4w==",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/clean-regexp": {
|
||||
"version": "1.0.0",
|
||||
@@ -8203,6 +8217,7 @@
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.4.tgz",
|
||||
"integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.8.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@@ -9361,6 +9376,7 @@
|
||||
"integrity": "sha512-GZZ9mKe8r646NUAf/zemnGbjYh4Bt8/MqASJY+pSm5ZDtc3YQox+4gsLI7yi1hba6o+eCsGxpHn5+iEVn31/FQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/node": ">=20.0.0",
|
||||
"@types/whatwg-mimetype": "^3.0.2",
|
||||
@@ -10532,6 +10548,12 @@
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/leaflet": {
|
||||
"version": "1.9.4",
|
||||
"resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.4.tgz",
|
||||
"integrity": "sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==",
|
||||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/levn": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
|
||||
@@ -11807,6 +11829,7 @@
|
||||
"resolved": "https://registry.npmjs.org/nuxt/-/nuxt-4.4.2.tgz",
|
||||
"integrity": "sha512-iWVFpr/YEqVU/CenqIHMnIkvb2HE/9f+q8oxZ+pj2et+60NljGRClCgnmbvGPdmNFE0F1bEhoBCYfqbDOCim3Q==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@dxup/nuxt": "^0.4.0",
|
||||
"@nuxt/cli": "^3.34.0",
|
||||
@@ -12865,6 +12888,7 @@
|
||||
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz",
|
||||
"integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"deep-is": "^0.1.3",
|
||||
"fast-levenshtein": "^2.0.6",
|
||||
@@ -12922,6 +12946,7 @@
|
||||
"resolved": "https://registry.npmjs.org/oxc-parser/-/oxc-parser-0.112.0.tgz",
|
||||
"integrity": "sha512-7rQ3QdJwobMQLMZwQaPuPYMEF2fDRZwf51lZ//V+bA37nejjKW5ifMHbbCwvA889Y4RLhT+/wLJpPRhAoBaZYw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@oxc-project/types": "^0.112.0"
|
||||
},
|
||||
@@ -13188,6 +13213,7 @@
|
||||
"resolved": "https://registry.npmjs.org/pinia/-/pinia-3.0.4.tgz",
|
||||
"integrity": "sha512-l7pqLUFTI/+ESXn6k3nu30ZIzW5E2WZF/LaHJEpoq6ElcLD+wduZoB2kBN19du6K/4FDpPMazY2wJr+IndBtQw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@vue/devtools-api": "^7.7.7"
|
||||
},
|
||||
@@ -13313,6 +13339,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"nanoid": "^3.3.11",
|
||||
"picocolors": "^1.1.1",
|
||||
@@ -13856,6 +13883,7 @@
|
||||
"resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.1.tgz",
|
||||
"integrity": "sha512-orRsuYpJVw8LdAwqqLykBj9ecS5/cRHlI5+nvTo8LcCKmzDmqVORXtOIYEEQuL9D4BxtA1lm5isAqzQZCoQ6Eg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"cssesc": "^3.0.0",
|
||||
"util-deprecate": "^1.0.2"
|
||||
@@ -14646,6 +14674,7 @@
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.60.1.tgz",
|
||||
"integrity": "sha512-VmtB2rFU/GroZ4oL8+ZqXgSA38O6GR8KSIvWmEFv63pQ0G6KaBH9s07PO8XTXP4vI+3UJUEypOfjkGfmSBBR0w==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/estree": "1.0.8"
|
||||
},
|
||||
@@ -15038,6 +15067,12 @@
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/sortablejs": {
|
||||
"version": "1.14.0",
|
||||
"resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.14.0.tgz",
|
||||
"integrity": "sha512-pBXvQCs5/33fdN1/39pPL0NZF20LeRbLQ5jtnheIPN9JQAaufGjKdWduZn4U7wCtVuzKhmRkI0DFYHYRbB2H1w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
@@ -15549,6 +15584,7 @@
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.19.tgz",
|
||||
"integrity": "sha512-3ofp+LL8E+pK/JuPLPggVAIaEuhvIz4qNcf3nA1Xn2o/7fb7s/TYpHhwGDv1ZU3PkBluUVaF8PyCHcm48cKLWQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@alloc/quick-lru": "^5.2.0",
|
||||
"arg": "^5.0.2",
|
||||
@@ -16228,6 +16264,7 @@
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"napi-postinstall": "^0.3.0"
|
||||
},
|
||||
@@ -16494,6 +16531,7 @@
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-7.3.2.tgz",
|
||||
"integrity": "sha512-Bby3NOsna2jsjfLVOHKes8sGwgl4TT0E6vvpYgnAYDIF/tie7MRaFthmKuHx1NSXjiTueXH3do80FMQgvEktRg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.27.0",
|
||||
"fdir": "^6.5.0",
|
||||
@@ -17412,6 +17450,7 @@
|
||||
"resolved": "https://registry.npmjs.org/vue/-/vue-3.5.32.tgz",
|
||||
"integrity": "sha512-vM4z4Q9tTafVfMAK7IVzmxg34rSzTFMyIe0UUEijUCkn9+23lj0WRfA83dg7eQZIUlgOSGrkViIaCfqSAUXsMw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@vue/compiler-dom": "3.5.32",
|
||||
"@vue/compiler-sfc": "3.5.32",
|
||||
@@ -17456,6 +17495,7 @@
|
||||
"integrity": "sha512-Vxi9pJdbN3ZnVGLODVtZ7y4Y2kzAAE2Cm0CZ3ZDRvydVYxZ6VrnBhLikBsRS+dpwj4Jv4UCv21PTEwF5rQ9WXg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"debug": "^4.4.0",
|
||||
"eslint-scope": "^8.2.0 || ^9.0.0",
|
||||
@@ -17492,6 +17532,7 @@
|
||||
"resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-11.3.1.tgz",
|
||||
"integrity": "sha512-azq8fhVnCwJAw0iXW7i44h9P+Bj+snNuevBAaJ9bxn0I3YVsRU3deVFPNnTfZ2uxVJefGp83JUmL68ddCPw5Pw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@intlify/core-base": "11.3.1",
|
||||
"@intlify/devtools-types": "11.3.1",
|
||||
@@ -17535,6 +17576,18 @@
|
||||
"integrity": "sha512-sGhTPMuXqZ1rVOk32RylztWkfXTRhuS7vgAKv0zjqk8gbsHkJ7xfFf+jbySxt7tWObEJwyKaHMikV/WGDiQm8g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/vuedraggable": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/vuedraggable/-/vuedraggable-4.1.0.tgz",
|
||||
"integrity": "sha512-FU5HCWBmsf20GpP3eudURW3WdWTKIbEIQxh9/8GE806hydR9qZqRRxRE3RjqX7PkuLuMQG/A7n3cfj9rCEchww==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"sortablejs": "1.14.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vue": "^3.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/w3c-keyname": {
|
||||
"version": "2.2.8",
|
||||
"resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz",
|
||||
|
||||
@@ -17,16 +17,19 @@
|
||||
"test:e2e:ui": "playwright test --ui"
|
||||
},
|
||||
"dependencies": {
|
||||
"@malio/layer-ui": "^1.7.4",
|
||||
"@malio/layer-ui": "^1.7.8",
|
||||
"@nuxt/icon": "^2.2.1",
|
||||
"@nuxtjs/i18n": "^10.2.3",
|
||||
"@nuxtjs/tailwindcss": "^6.14.0",
|
||||
"@pinia/nuxt": "^0.11.3",
|
||||
"@types/leaflet": "^1.9.21",
|
||||
"leaflet": "^1.9.4",
|
||||
"nuxt": "^4.3.1",
|
||||
"nuxt-toast": "^1.4.0",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.29",
|
||||
"vue-router": "^4.6.4"
|
||||
"vue-router": "^4.6.4",
|
||||
"vuedraggable": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nuxt/eslint-config": "^1.9.0",
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(diff, field) in updateDiff" :key="field" class="border-t border-gray-200">
|
||||
<td class="px-2 py-1 font-mono">{{ field }}</td>
|
||||
<td class="px-2 py-1">{{ field }}</td>
|
||||
<td class="px-2 py-1 text-red-700">{{ formatValue(diff.old) }}</td>
|
||||
<td class="px-2 py-1 text-green-700">{{ formatValue(diff.new) }}</td>
|
||||
</tr>
|
||||
@@ -31,7 +31,7 @@
|
||||
{ added: [ids], removed: [ids] } → affiche + et - sur
|
||||
la meme ligne pour garder une colonne field unique. -->
|
||||
<tr v-for="(diff, field) in collectionDiff" :key="`col-${field}`" class="border-t border-gray-200">
|
||||
<td class="px-2 py-1 font-mono">{{ field }}</td>
|
||||
<td class="px-2 py-1">{{ field }}</td>
|
||||
<td class="px-2 py-1 text-red-700">
|
||||
<span v-if="diff.removed.length">− {{ diff.removed.join(', ') }}</span>
|
||||
<span v-else class="text-gray-400">∅</span>
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
<div v-else class="space-y-1">
|
||||
<div v-for="(value, key) in entry.changes" :key="key" class="flex gap-2">
|
||||
<span class="font-mono text-xs text-gray-600">{{ key }}:</span>
|
||||
<span class="text-xs text-gray-600">{{ key }}:</span>
|
||||
<span class="text-xs">{{ formatValue(value) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<template>
|
||||
<!-- Entete de page standard : source unique du style des titres.
|
||||
Slot par defaut = texte du titre, slot #actions = boutons a droite. -->
|
||||
<div class="mb-[44px] flex items-center justify-between gap-4">
|
||||
<h1 class="text-[32px] font-semibold text-primary-500">
|
||||
Slot par defaut = texte du titre, slot #actions = boutons a droite.
|
||||
Sticky en haut du <main> scrollable : reste visible au scroll. Fond blanc
|
||||
+ pt-[38px]/pb-[30px] (au lieu de marges) pour que le contenu defilant soit
|
||||
masque sous l'entete (espaces haut ET bas compris) et que l'entete soit
|
||||
collee sous le SiteSelector sans trou. pt = marge haute (38px),
|
||||
pb = espace titre -> contenu (30px). z-20 < drawers/modales. -->
|
||||
<div class="sticky top-0 z-20 flex items-center justify-between gap-4 bg-white pt-[38px] pb-[30px]">
|
||||
<h1 class="text-[30px] font-semibold text-primary-500">
|
||||
<slot/>
|
||||
</h1>
|
||||
<div v-if="$slots.actions" class="shrink-0">
|
||||
|
||||
@@ -31,9 +31,21 @@ export interface AddressSuggestion {
|
||||
city: string
|
||||
}
|
||||
|
||||
/** Coordonnees WGS84 d'une adresse geocodee (chaines decimales, format API). */
|
||||
export interface GeocodedCoordinates {
|
||||
latitude: string
|
||||
longitude: string
|
||||
}
|
||||
|
||||
export interface AddressAutocomplete {
|
||||
searchCity(postalCode: string): Promise<CitySuggestion[]>
|
||||
searchAddress(query: string, postalCode?: string): Promise<AddressSuggestion[]>
|
||||
/**
|
||||
* Geocode une adresse complete en coordonnees (M6.1) — previsualisation du
|
||||
* pin cote front uniquement : la valeur persistee reste celle du geocodage
|
||||
* serveur (BanGeocoder) au save. `null` si la BAN ne trouve rien.
|
||||
*/
|
||||
geocode(query: string): Promise<GeocodedCoordinates | null>
|
||||
}
|
||||
|
||||
/** Erreur signalant que le service d'autocompletion BAN n'est pas disponible. */
|
||||
@@ -57,7 +69,11 @@ interface BanFeatureProperties {
|
||||
|
||||
/** Reponse GeoJSON FeatureCollection de la BAN. */
|
||||
interface BanResponse {
|
||||
features?: { properties?: BanFeatureProperties }[]
|
||||
features?: {
|
||||
properties?: BanFeatureProperties
|
||||
/** GeoJSON : coordinates = [longitude, latitude]. */
|
||||
geometry?: { coordinates?: [number, number] }
|
||||
}[]
|
||||
}
|
||||
|
||||
export function useAddressAutocomplete(): AddressAutocomplete {
|
||||
@@ -113,5 +129,32 @@ export function useAddressAutocomplete(): AddressAutocomplete {
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async geocode(query: string): Promise<GeocodedCoordinates | null> {
|
||||
if (query.trim().length < 3) {
|
||||
return null
|
||||
}
|
||||
|
||||
let res: BanResponse
|
||||
try {
|
||||
res = await httpExternal<BanResponse>(BAN_SEARCH_URL, {
|
||||
query: { q: query, limit: '1' },
|
||||
})
|
||||
}
|
||||
catch {
|
||||
throw new AddressAutocompleteUnavailableError()
|
||||
}
|
||||
|
||||
const coordinates = res.features?.[0]?.geometry?.coordinates
|
||||
if (!coordinates || coordinates.length < 2) {
|
||||
return null
|
||||
}
|
||||
|
||||
// GeoJSON = [longitude, latitude] ; 7 decimales = format NUMERIC(10,7).
|
||||
return {
|
||||
latitude: coordinates[1].toFixed(7),
|
||||
longitude: coordinates[0].toFixed(7),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest'
|
||||
import { readHistoryTab } from '../historyTab'
|
||||
|
||||
const KEYS = ['information', 'contact', 'address', 'accounting']
|
||||
|
||||
describe('readHistoryTab', () => {
|
||||
afterEach(() => {
|
||||
window.history.replaceState(null, '')
|
||||
})
|
||||
|
||||
it('retourne la cle d\'onglet quand elle est presente et valide', () => {
|
||||
window.history.replaceState({ tab: 'address' }, '')
|
||||
expect(readHistoryTab(KEYS)).toBe('address')
|
||||
})
|
||||
|
||||
it('retourne null quand l\'onglet n\'est pas dans les cles valides (ex: role sans Comptabilite)', () => {
|
||||
window.history.replaceState({ tab: 'accounting' }, '')
|
||||
expect(readHistoryTab(['information', 'contact', 'address'])).toBeNull()
|
||||
})
|
||||
|
||||
it('retourne null sans onglet dans l\'etat d\'historique (navigation directe / refresh)', () => {
|
||||
window.history.replaceState(null, '')
|
||||
expect(readHistoryTab(KEYS)).toBeNull()
|
||||
|
||||
window.history.replaceState({ foo: 'bar' }, '')
|
||||
expect(readHistoryTab(KEYS)).toBeNull()
|
||||
})
|
||||
|
||||
it('retourne null quand la valeur n\'est pas une chaine', () => {
|
||||
window.history.replaceState({ tab: 42 }, '')
|
||||
expect(readHistoryTab(KEYS)).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Onglet actif transmis d'une page a l'autre via l'etat d'historique
|
||||
* (`history.state`), SANS le mettre dans l'URL. Sert a preserver l'onglet courant
|
||||
* au passage consultation <-> edition d'un client (dans les deux sens).
|
||||
*
|
||||
* On reste donc fidele a la regle « etat d'UI local, pas dans l'URL » : l'onglet
|
||||
* voyage dans l'entree d'historique de la navigation, l'URL ne change pas.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Lit la cle d'onglet posee par la page precedente (`history.state.tab`) si elle
|
||||
* fait partie des onglets valides pour l'utilisateur. Retourne `null` sinon :
|
||||
* navigation directe / deep link, rechargement de page, ou onglet inexistant
|
||||
* pour ce role (ex: Comptabilite sans la permission).
|
||||
*/
|
||||
export function readHistoryTab(validKeys: string[]): string | null {
|
||||
if (typeof window === 'undefined') {
|
||||
return null
|
||||
}
|
||||
const tab = (window.history.state as Record<string, unknown> | null)?.tab
|
||||
return typeof tab === 'string' && validKeys.includes(tab) ? tab : null
|
||||
}
|
||||
@@ -75,6 +75,21 @@ export const personas: Record<PersonaKey, Persona> = {
|
||||
'commercial.clients.accounting.view',
|
||||
'commercial.clients.accounting.manage',
|
||||
'commercial.clients.archive',
|
||||
// Commercial — Repertoire fournisseurs (M2, ERP-90). Meme logique que
|
||||
// les clients : mappe sur le persona "tout", pas de nouveau persona
|
||||
// (regle ABSOLUE n°7). commercial.suppliers.view n'ajoute pas de lien
|
||||
// dans la section Administration, donc expectedAdminLinks reste inchange.
|
||||
'commercial.suppliers.view',
|
||||
'commercial.suppliers.manage',
|
||||
'commercial.suppliers.accounting.view',
|
||||
'commercial.suppliers.accounting.manage',
|
||||
'commercial.suppliers.archive',
|
||||
// FieldSales — Tournees (M6, ERP-123). Mappe sur le persona "tout",
|
||||
// pas de nouveau persona (regle ABSOLUE n°7). La section "Tournées"
|
||||
// n'est pas dans Administration, donc expectedAdminLinks inchange.
|
||||
// Miroir de SeedE2ECommand.php.
|
||||
'field_sales.tours.view',
|
||||
'field_sales.tours.manage',
|
||||
],
|
||||
expectedAdminLinks: ['users', 'roles', 'sites', 'categories', 'audit-log'],
|
||||
},
|
||||
|
||||
@@ -207,7 +207,8 @@ migration-migrate:
|
||||
# orphelins du mapping ORM. Les index partiels (LOWER + WHERE) ne sont pas
|
||||
# exprimables via les attributs Doctrine ORM (fonctionnel + partiel), donc
|
||||
# ils disparaissent apres schema:update. On les recree par dbal:run-sql :
|
||||
# - `uq_category_name_type_active` (M0 Catalog) : tests RG-1.07.
|
||||
# - `uq_category_name_active` (M0 Catalog) : unicite GLOBALE du nom parmi
|
||||
# les actifs (M:N categorie<->type), tests RG-1.07.
|
||||
# - `uq_category_code` (Catalog ERP-78) : unicite du code categorie parmi
|
||||
# les actifs (slug du nom), pilote RG-1.03/1.29.
|
||||
# - `uq_client_company_name_active` (M1 Commercial) : unicite nom societe
|
||||
@@ -226,9 +227,10 @@ test-db-setup:
|
||||
$(SYMFONY_CONSOLE) --env=test --no-interaction doctrine:fixtures:load
|
||||
$(SYMFONY_CONSOLE) --env=test --no-interaction 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_active ON category (LOWER(name)) WHERE deleted_at IS NULL"
|
||||
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_category_code ON category (code) WHERE deleted_at IS NULL"
|
||||
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_client_company_name_active ON client (LOWER(company_name)) WHERE is_archived = FALSE AND deleted_at IS NULL"
|
||||
$(SYMFONY_CONSOLE) --env=test dbal:run-sql "CREATE UNIQUE INDEX IF NOT EXISTS uq_supplier_company_name_active ON supplier (LOWER(company_name)) WHERE is_archived = FALSE AND deleted_at IS NULL"
|
||||
|
||||
fixtures:
|
||||
$(SYMFONY_CONSOLE) --no-interaction doctrine:fixtures:load
|
||||
|
||||
@@ -256,13 +256,13 @@ final class Version20260601000000 extends AbstractMigration
|
||||
$this->comment('client', 'distributor_id', 'FK auto-referente vers un client porteur de la categorie DISTRIBUTEUR — exclusive avec broker_id (RG-1.03, chk_client_distrib_or_broker). FK -> client.id, ON DELETE SET NULL.');
|
||||
$this->comment('client', 'broker_id', 'FK auto-referente vers un client porteur de la categorie COURTIER — exclusive avec distributor_id (RG-1.03). FK -> client.id, ON DELETE SET NULL.');
|
||||
$this->comment('client', 'triage_service', 'Drapeau service triage active pour le client. Faux par defaut.');
|
||||
$this->comment('client', 'description', 'Onglet Information : description libre. Obligatoire pour le role Commerciale (RG-1.04), optionnel sinon.');
|
||||
$this->comment('client', 'competitors', 'Onglet Information : concurrents identifies (texte libre ≤ 255). Obligatoire role Commerciale (RG-1.04).');
|
||||
$this->comment('client', 'founded_at', 'Onglet Information : date de creation de l entreprise. Obligatoire role Commerciale (RG-1.04).');
|
||||
$this->comment('client', 'employees_count', 'Onglet Information : effectif (entier >= 0). Obligatoire role Commerciale (RG-1.04).');
|
||||
$this->comment('client', 'revenue_amount', 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).');
|
||||
$this->comment('client', 'director_name', 'Onglet Information : nom du dirigeant. Obligatoire role Commerciale (RG-1.04).');
|
||||
$this->comment('client', 'profit_amount', 'Onglet Information : resultat / benefice (NUMERIC 15,2). Obligatoire role Commerciale (RG-1.04).');
|
||||
$this->comment('client', 'description', 'Onglet Information : description libre. Facultatif.');
|
||||
$this->comment('client', 'competitors', 'Onglet Information : concurrents identifies (texte libre ≤ 255). Facultatif.');
|
||||
$this->comment('client', 'founded_at', 'Onglet Information : date de creation de l entreprise. Facultatif.');
|
||||
$this->comment('client', 'employees_count', 'Onglet Information : effectif (entier >= 0). Facultatif.');
|
||||
$this->comment('client', 'revenue_amount', 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Facultatif.');
|
||||
$this->comment('client', 'director_name', 'Onglet Information : nom du dirigeant. Facultatif.');
|
||||
$this->comment('client', 'profit_amount', 'Onglet Information : resultat / benefice (NUMERIC 15,2). Facultatif.');
|
||||
$this->comment('client', 'siren', 'Onglet Comptabilite : SIREN (9 chiffres attendus). NON unique — peut etre partage entre etablissements (RG-1.15 supprimee, Q4).');
|
||||
$this->comment('client', 'account_number', 'Onglet Comptabilite : numero de compte comptable du client.');
|
||||
$this->comment('client', 'tva_mode_id', 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id, ON DELETE RESTRICT.');
|
||||
|
||||
@@ -0,0 +1,438 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use App\Shared\Infrastructure\Database\ColumnCommentsCatalog;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* M2 — Repertoire fournisseurs (ERP-85) : creation de toute la structure BDD
|
||||
* des fournisseurs sous le module Commercial (jumeau du M1 client).
|
||||
*
|
||||
* Tables creees :
|
||||
* - Table principale : supplier (formulaire principal + Information +
|
||||
* Comptabilite + archive + soft-delete + Timestampable/Blamable).
|
||||
* - Sous-collections : supplier_category (M2M), supplier_contact (1:n),
|
||||
* supplier_address (1:n), supplier_rib (1:n).
|
||||
* - Jointures de supplier_address : supplier_address_site,
|
||||
* supplier_address_contact, supplier_address_category.
|
||||
*
|
||||
* Differences vs le M1 `client` (cf. spec M2 § 2.4 / § 3.1) :
|
||||
* - PAS de contact inline sur supplier (first_name / last_name / phone_* /
|
||||
* email retires en V0.2, refonte-contact ERP-106). Les contacts vivent
|
||||
* uniquement dans supplier_contact (onglet Contacts).
|
||||
* - PAS d'auto-reference distributor_id / broker_id (pas de CHECK associe).
|
||||
* - Ajout du champ Information volume_forecast (entier).
|
||||
* - supplier_address remplace les 3 booleens M1 (is_prospect / is_delivery /
|
||||
* is_billing + billing_email) par un seul enum address_type
|
||||
* (PROSPECT | DEPART | RENDU, radio exclusif, CHECK chk_supplier_address_type)
|
||||
* et ajoute bennes (int nullable) + triage_provider (bool).
|
||||
*
|
||||
* Referentiels comptables NON recrees : tva_mode / payment_delay / payment_type
|
||||
* / bank sont ceux du M1 (FK partagees, zero duplication — spec § 2.3).
|
||||
*
|
||||
* CategoryType FOURNISSEUR NON re-seede : il est cree par ERP-84
|
||||
* (Version20260605120000) avec ses categories de demonstration. Le M2M
|
||||
* supplier_category / supplier_address_category s'appuie sur ce type existant.
|
||||
*
|
||||
* Namespace racine `DoctrineMigrations` (regle ABSOLUE Starseed n°11) et NON
|
||||
* `App\Module\Commercial\...` : la migration cree un schema avec FK cross-module
|
||||
* (user, category, site, et les referentiels comptables M1). Avec plusieurs
|
||||
* migrations_paths, Doctrine Migrations 3.x trie par FQCN alphabetique — un
|
||||
* namespace modulaire s'executerait avant la creation de user/category/site sur
|
||||
* base vide -> echec des FK. Le namespace racine garantit l'ordre par timestamp.
|
||||
*
|
||||
* Style DDL aligne sur le M1 (Version20260601000000) : `INT GENERATED BY DEFAULT
|
||||
* AS IDENTITY` (et non SERIAL), `TIMESTAMP(0) WITHOUT TIME ZONE` (et non
|
||||
* TIMESTAMPTZ, car le TimestampableBlamableTrait mappe `datetime_immutable`).
|
||||
* Garantit que `schema:update` restera un no-op quand les entites arriveront
|
||||
* (ticket ERP-86).
|
||||
*
|
||||
* Decision unicite (Matthieu 02/06, alignee Q4 du M1) : unicite metier sur le
|
||||
* NOM DE SOCIETE uniquement (uq_supplier_company_name_active, partiel). Pas
|
||||
* d'index unique sur siren ni email.
|
||||
*
|
||||
* Chaque colonne porte un `COMMENT ON COLUMN` (regle ABSOLUE n°12, garde-fou
|
||||
* ColumnsHaveSqlCommentTest). Les tables n'etant pas encore mappees par l'ORM
|
||||
* (entites a ERP-86), ces commentaires survivent au `schema:update --force` du
|
||||
* setup de test (additif, ne drop pas les tables non mappees).
|
||||
*/
|
||||
final class Version20260605130000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'ERP-85 (M2) : tables supplier + sous-collections + jointures M2M (referentiels comptables et CategoryType FOURNISSEUR reutilises).';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->createSupplierTable();
|
||||
$this->createSupplierCategory();
|
||||
$this->createSupplierContact();
|
||||
$this->createSupplierAddress();
|
||||
$this->createSupplierAddressJoinTables();
|
||||
$this->createSupplierRib();
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// Ordre inverse des dependances FK : jointures et sous-collections
|
||||
// d'abord, puis supplier. Les referentiels comptables et le
|
||||
// CategoryType FOURNISSEUR ne sont pas touches (crees ailleurs).
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier_address_category');
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier_address_contact');
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier_address_site');
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier_rib');
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier_address');
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier_contact');
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier_category');
|
||||
$this->addSql('DROP TABLE IF EXISTS supplier');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Table principale `supplier`
|
||||
// =================================================================
|
||||
|
||||
private function createSupplierTable(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier (
|
||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
company_name VARCHAR(180) NOT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
competitors VARCHAR(255) DEFAULT NULL,
|
||||
founded_at DATE DEFAULT NULL,
|
||||
employees_count INT DEFAULT NULL,
|
||||
revenue_amount NUMERIC(15, 2) DEFAULT NULL,
|
||||
director_name VARCHAR(120) DEFAULT NULL,
|
||||
profit_amount NUMERIC(15, 2) DEFAULT NULL,
|
||||
volume_forecast INT DEFAULT NULL,
|
||||
siren VARCHAR(20) DEFAULT NULL,
|
||||
account_number VARCHAR(40) DEFAULT NULL,
|
||||
tva_mode_id INT DEFAULT NULL,
|
||||
n_tva VARCHAR(40) DEFAULT NULL,
|
||||
payment_delay_id INT DEFAULT NULL,
|
||||
payment_type_id INT DEFAULT NULL,
|
||||
bank_id INT DEFAULT NULL,
|
||||
is_archived BOOLEAN DEFAULT FALSE NOT NULL,
|
||||
archived_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
|
||||
deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
created_by INT DEFAULT NULL,
|
||||
updated_by INT DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT fk_supplier_tva_mode
|
||||
FOREIGN KEY (tva_mode_id) REFERENCES tva_mode (id) ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_supplier_payment_delay
|
||||
FOREIGN KEY (payment_delay_id) REFERENCES payment_delay (id) ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_supplier_payment_type
|
||||
FOREIGN KEY (payment_type_id) REFERENCES payment_type (id) ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_supplier_bank
|
||||
FOREIGN KEY (bank_id) REFERENCES bank (id) ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_supplier_created_by
|
||||
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_supplier_updated_by
|
||||
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql('CREATE INDEX idx_supplier_is_archived ON supplier (is_archived)');
|
||||
$this->addSql('CREATE INDEX idx_supplier_deleted_at ON supplier (deleted_at)');
|
||||
$this->addSql('CREATE INDEX idx_supplier_created_by ON supplier (created_by)');
|
||||
$this->addSql('CREATE INDEX idx_supplier_updated_by ON supplier (updated_by)');
|
||||
|
||||
// Index sur les FK des referentiels comptables (Postgres n'indexe pas
|
||||
// automatiquement les colonnes portant une FOREIGN KEY).
|
||||
$this->addSql('CREATE INDEX idx_supplier_tva_mode_id ON supplier (tva_mode_id)');
|
||||
$this->addSql('CREATE INDEX idx_supplier_payment_delay_id ON supplier (payment_delay_id)');
|
||||
$this->addSql('CREATE INDEX idx_supplier_payment_type_id ON supplier (payment_type_id)');
|
||||
$this->addSql('CREATE INDEX idx_supplier_bank_id ON supplier (bank_id)');
|
||||
|
||||
// Unicite metier partielle : nom de societe insensible a la casse, parmi
|
||||
// les non-archives ET non soft-deletes uniquement (spec § 2.6). Pas
|
||||
// d'index unique sur siren ni email.
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE UNIQUE INDEX uq_supplier_company_name_active
|
||||
ON supplier (LOWER(company_name))
|
||||
WHERE is_archived = FALSE AND deleted_at IS NULL
|
||||
SQL);
|
||||
|
||||
$this->comment('supplier', '_table', 'Repertoire fournisseurs (M2 Commercial) — entites archivables (is_archived) et soft-deletables (deleted_at, HP M3).');
|
||||
$this->comment('supplier', 'id', 'Identifiant interne auto-incremente.');
|
||||
$this->comment('supplier', 'company_name', 'Raison sociale du fournisseur (stockee en MAJUSCULES). Unique case-insensitive parmi les actifs non archives/non supprimes (uq_supplier_company_name_active, § 2.6).');
|
||||
$this->comment('supplier', 'description', 'Onglet Information : description libre. Obligatoire pour le role Commerciale (RG-2.03), optionnel sinon.');
|
||||
$this->comment('supplier', 'competitors', 'Onglet Information : concurrents identifies (texte libre ≤ 255). Obligatoire role Commerciale (RG-2.03).');
|
||||
$this->comment('supplier', 'founded_at', 'Onglet Information : date de creation de l entreprise. Obligatoire role Commerciale (RG-2.03).');
|
||||
$this->comment('supplier', 'employees_count', 'Onglet Information : effectif (entier >= 0). Obligatoire role Commerciale (RG-2.03).');
|
||||
$this->comment('supplier', 'revenue_amount', 'Onglet Information : chiffre d affaires (NUMERIC 15,2). Obligatoire role Commerciale (RG-2.03).');
|
||||
$this->comment('supplier', 'director_name', 'Onglet Information : nom du dirigeant. Obligatoire role Commerciale (RG-2.03).');
|
||||
$this->comment('supplier', 'profit_amount', 'Onglet Information : resultat / benefice (NUMERIC 15,2). Obligatoire role Commerciale (RG-2.03).');
|
||||
$this->comment('supplier', 'volume_forecast', 'Onglet Information : volume previsionnel (entier >= 0) — specifique fournisseur. Obligatoire role Commerciale (RG-2.03).');
|
||||
$this->comment('supplier', 'siren', 'Onglet Comptabilite : SIREN (9 chiffres attendus). NON unique — peut etre partage entre etablissements (§ 2.6).');
|
||||
$this->comment('supplier', 'account_number', 'Onglet Comptabilite : numero de compte comptable du fournisseur.');
|
||||
$this->comment('supplier', 'tva_mode_id', 'Onglet Comptabilite : mode de TVA applique — FK -> tva_mode.id (referentiel partage M1), ON DELETE RESTRICT.');
|
||||
$this->comment('supplier', 'n_tva', 'Onglet Comptabilite : numero de TVA intracommunautaire.');
|
||||
$this->comment('supplier', 'payment_delay_id', 'Onglet Comptabilite : delai de reglement — FK -> payment_delay.id (M1), ON DELETE RESTRICT.');
|
||||
$this->comment('supplier', 'payment_type_id', 'Onglet Comptabilite : type de reglement — FK -> payment_type.id (M1), ON DELETE RESTRICT. Pilote RG-2.07 (Banque si VIREMENT) et RG-2.08 (RIB).');
|
||||
$this->comment('supplier', 'bank_id', 'Onglet Comptabilite : banque — FK -> bank.id (M1), ON DELETE RESTRICT. Obligatoire ssi payment_type = VIREMENT (RG-2.07), null sinon.');
|
||||
$this->comment('supplier', 'is_archived', 'Drapeau fonctionnel d archivage — masque par defaut dans la liste. Bascule via permission commercial.suppliers.archive.');
|
||||
$this->comment('supplier', 'archived_at', 'Horodatage de l archivage — pose quand is_archived passe a vrai, remis a null a la restauration.');
|
||||
$this->comment('supplier', 'deleted_at', 'Horodatage du soft-delete technique (HP M3) — non expose par l API au M2. Null = ligne active.');
|
||||
$this->addTimestampableBlamableComments('supplier');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// M2M supplier <-> category (type FOURNISSEUR — RG-2.10)
|
||||
// =================================================================
|
||||
|
||||
private function createSupplierCategory(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier_category (
|
||||
supplier_id INT NOT NULL,
|
||||
category_id INT NOT NULL,
|
||||
PRIMARY KEY (supplier_id, category_id),
|
||||
CONSTRAINT fk_supplier_category_supplier
|
||||
FOREIGN KEY (supplier_id) REFERENCES supplier (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_supplier_category_category
|
||||
FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE RESTRICT
|
||||
)
|
||||
SQL);
|
||||
$this->addSql('CREATE INDEX idx_supplier_category_category ON supplier_category (category_id)');
|
||||
|
||||
$this->comment('supplier_category', '_table', 'Jointure M2M supplier <-> category (Catalog) — categories de type FOURNISSEUR du fournisseur, au moins une obligatoire (RG-2.10).');
|
||||
$this->comment('supplier_category', 'supplier_id', 'FK -> supplier.id, ON DELETE CASCADE — fournisseur porteur de la categorie.');
|
||||
$this->comment('supplier_category', 'category_id', 'FK -> category.id, ON DELETE RESTRICT — categorie de type FOURNISSEUR rattachee au fournisseur (RG-2.10).');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Sous-collection : contacts (1:n)
|
||||
// =================================================================
|
||||
|
||||
private function createSupplierContact(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier_contact (
|
||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
supplier_id INT NOT NULL,
|
||||
first_name VARCHAR(120) DEFAULT NULL,
|
||||
last_name VARCHAR(120) DEFAULT NULL,
|
||||
job_title VARCHAR(120) DEFAULT NULL,
|
||||
phone_primary VARCHAR(20) DEFAULT NULL,
|
||||
phone_secondary VARCHAR(20) DEFAULT NULL,
|
||||
email VARCHAR(180) DEFAULT NULL,
|
||||
position INT DEFAULT 0 NOT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
created_by INT DEFAULT NULL,
|
||||
updated_by INT DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT chk_supplier_contact_name
|
||||
CHECK (first_name IS NOT NULL OR last_name IS NOT NULL),
|
||||
CONSTRAINT fk_supplier_contact_supplier
|
||||
FOREIGN KEY (supplier_id) REFERENCES supplier (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_supplier_contact_created_by
|
||||
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_supplier_contact_updated_by
|
||||
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||
)
|
||||
SQL);
|
||||
$this->addSql('CREATE INDEX idx_supplier_contact_supplier ON supplier_contact (supplier_id)');
|
||||
|
||||
$this->comment('supplier_contact', '_table', 'Contacts d un fournisseur (1:n) — au moins firstName OU lastName par contact (RG-2.04).');
|
||||
$this->comment('supplier_contact', 'id', 'Identifiant interne auto-incremente.');
|
||||
$this->comment('supplier_contact', 'supplier_id', 'FK -> supplier.id, ON DELETE CASCADE — fournisseur proprietaire du contact.');
|
||||
$this->comment('supplier_contact', 'first_name', 'Prenom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-2.04, chk_supplier_contact_name).');
|
||||
$this->comment('supplier_contact', 'last_name', 'Nom du contact (capitalise serveur). first_name OU last_name obligatoire (RG-2.04, chk_supplier_contact_name).');
|
||||
$this->comment('supplier_contact', 'job_title', 'Fonction / intitule de poste du contact (≤ 120 caracteres).');
|
||||
$this->comment('supplier_contact', 'phone_primary', 'Telephone principal du contact — chiffres uniquement (normalisation serveur).');
|
||||
$this->comment('supplier_contact', 'phone_secondary', 'Telephone secondaire du contact — chiffres uniquement (normalisation serveur).');
|
||||
$this->comment('supplier_contact', 'email', 'Email du contact (lowercase serveur).');
|
||||
$this->comment('supplier_contact', 'position', 'Ordre d affichage du contact dans la liste du fournisseur (croissant).');
|
||||
$this->addTimestampableBlamableComments('supplier_contact');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Sous-collection : adresses (1:n)
|
||||
// =================================================================
|
||||
|
||||
private function createSupplierAddress(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier_address (
|
||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
supplier_id INT NOT NULL,
|
||||
address_type VARCHAR(20) NOT NULL,
|
||||
country VARCHAR(80) DEFAULT 'France' NOT NULL,
|
||||
postal_code VARCHAR(20) NOT NULL,
|
||||
city VARCHAR(120) NOT NULL,
|
||||
street VARCHAR(255) NOT NULL,
|
||||
street_complement VARCHAR(255) DEFAULT NULL,
|
||||
bennes INT DEFAULT NULL,
|
||||
triage_provider BOOLEAN DEFAULT FALSE NOT NULL,
|
||||
position INT DEFAULT 0 NOT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
created_by INT DEFAULT NULL,
|
||||
updated_by INT DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT chk_supplier_address_type
|
||||
CHECK (address_type IN ('PROSPECT', 'DEPART', 'RENDU')),
|
||||
CONSTRAINT fk_supplier_address_supplier
|
||||
FOREIGN KEY (supplier_id) REFERENCES supplier (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_supplier_address_created_by
|
||||
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_supplier_address_updated_by
|
||||
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||
)
|
||||
SQL);
|
||||
$this->addSql('CREATE INDEX idx_supplier_address_supplier ON supplier_address (supplier_id)');
|
||||
|
||||
$this->comment('supplier_address', '_table', 'Adresses d un fournisseur (1:n) — type PROSPECT/DEPART/RENDU exclusif (RG-2.09), >= 1 site rattache (RG-2.06).');
|
||||
$this->comment('supplier_address', 'id', 'Identifiant interne auto-incremente.');
|
||||
$this->comment('supplier_address', 'supplier_id', 'FK -> supplier.id, ON DELETE CASCADE — fournisseur proprietaire de l adresse.');
|
||||
$this->comment('supplier_address', 'address_type', 'Type d adresse : PROSPECT | DEPART | RENDU (radio exclusif par construction — RG-2.09, chk_supplier_address_type).');
|
||||
$this->comment('supplier_address', 'country', 'Pays de l adresse — defaut France.');
|
||||
$this->comment('supplier_address', 'postal_code', 'Code postal (4-5 chiffres attendus).');
|
||||
$this->comment('supplier_address', 'city', 'Ville — preremplie depuis le code postal via API BAN cote front.');
|
||||
$this->comment('supplier_address', 'street', 'Numero et voie de l adresse.');
|
||||
$this->comment('supplier_address', 'street_complement', 'Complement d adresse (etage, batiment...) — optionnel.');
|
||||
$this->comment('supplier_address', 'bennes', 'Nombre de bennes sur le site fournisseur (entier nullable) — specifique fournisseur.');
|
||||
$this->comment('supplier_address', 'triage_provider', 'Le fournisseur est prestataire de triage sur cette adresse. Faux par defaut.');
|
||||
$this->comment('supplier_address', 'position', 'Ordre d affichage de l adresse dans la liste du fournisseur (croissant).');
|
||||
$this->addTimestampableBlamableComments('supplier_address');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Jointures de supplier_address (M2M)
|
||||
// =================================================================
|
||||
|
||||
private function createSupplierAddressJoinTables(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier_address_site (
|
||||
supplier_address_id INT NOT NULL,
|
||||
site_id INT NOT NULL,
|
||||
PRIMARY KEY (supplier_address_id, site_id),
|
||||
CONSTRAINT fk_supplier_address_site_address
|
||||
FOREIGN KEY (supplier_address_id) REFERENCES supplier_address (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_supplier_address_site_site
|
||||
FOREIGN KEY (site_id) REFERENCES site (id) ON DELETE RESTRICT
|
||||
)
|
||||
SQL);
|
||||
$this->comment('supplier_address_site', '_table', 'Jointure M2M supplier_address <-> site (Sites) — sites rattaches a l adresse (>= 1 obligatoire, RG-2.06).');
|
||||
$this->comment('supplier_address_site', 'supplier_address_id', 'FK -> supplier_address.id, ON DELETE CASCADE — adresse concernee.');
|
||||
$this->comment('supplier_address_site', 'site_id', 'FK -> site.id, ON DELETE RESTRICT — site rattache a l adresse.');
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier_address_contact (
|
||||
supplier_address_id INT NOT NULL,
|
||||
supplier_contact_id INT NOT NULL,
|
||||
PRIMARY KEY (supplier_address_id, supplier_contact_id),
|
||||
CONSTRAINT fk_supplier_address_contact_address
|
||||
FOREIGN KEY (supplier_address_id) REFERENCES supplier_address (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_supplier_address_contact_contact
|
||||
FOREIGN KEY (supplier_contact_id) REFERENCES supplier_contact (id) ON DELETE CASCADE
|
||||
)
|
||||
SQL);
|
||||
$this->comment('supplier_address_contact', '_table', 'Jointure M2M supplier_address <-> supplier_contact — contacts associes a une adresse.');
|
||||
$this->comment('supplier_address_contact', 'supplier_address_id', 'FK -> supplier_address.id, ON DELETE CASCADE — adresse concernee.');
|
||||
$this->comment('supplier_address_contact', 'supplier_contact_id', 'FK -> supplier_contact.id, ON DELETE CASCADE — contact associe a l adresse.');
|
||||
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier_address_category (
|
||||
supplier_address_id INT NOT NULL,
|
||||
category_id INT NOT NULL,
|
||||
PRIMARY KEY (supplier_address_id, category_id),
|
||||
CONSTRAINT fk_supplier_address_category_address
|
||||
FOREIGN KEY (supplier_address_id) REFERENCES supplier_address (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_supplier_address_category_category
|
||||
FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE RESTRICT
|
||||
)
|
||||
SQL);
|
||||
$this->comment('supplier_address_category', '_table', 'Jointure M2M supplier_address <-> category — categories d adresse de type FOURNISSEUR (RG-2.10).');
|
||||
$this->comment('supplier_address_category', 'supplier_address_id', 'FK -> supplier_address.id, ON DELETE CASCADE — adresse concernee.');
|
||||
$this->comment('supplier_address_category', 'category_id', 'FK -> category.id, ON DELETE RESTRICT — categorie d adresse de type FOURNISSEUR (RG-2.10).');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Sous-collection : RIB (1:n)
|
||||
// =================================================================
|
||||
|
||||
private function createSupplierRib(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE supplier_rib (
|
||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
supplier_id INT NOT NULL,
|
||||
label VARCHAR(120) NOT NULL,
|
||||
bic VARCHAR(20) NOT NULL,
|
||||
iban VARCHAR(34) NOT NULL,
|
||||
position INT DEFAULT 0 NOT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
created_by INT DEFAULT NULL,
|
||||
updated_by INT DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT fk_supplier_rib_supplier
|
||||
FOREIGN KEY (supplier_id) REFERENCES supplier (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_supplier_rib_created_by
|
||||
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_supplier_rib_updated_by
|
||||
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||
)
|
||||
SQL);
|
||||
$this->addSql('CREATE INDEX idx_supplier_rib_supplier ON supplier_rib (supplier_id)');
|
||||
|
||||
$this->comment('supplier_rib', '_table', 'Coordonnees bancaires d un fournisseur (1:n) — >= 1 RIB attendu selon le type de reglement (RG-2.08). Tous les champs audites (pas d AuditIgnore).');
|
||||
$this->comment('supplier_rib', 'id', 'Identifiant interne auto-incremente.');
|
||||
$this->comment('supplier_rib', 'supplier_id', 'FK -> supplier.id, ON DELETE CASCADE — fournisseur proprietaire du RIB.');
|
||||
$this->comment('supplier_rib', 'label', 'Libelle du RIB (ex: compte principal).');
|
||||
$this->comment('supplier_rib', 'bic', 'Code BIC/SWIFT de la banque (8 ou 11 caracteres).');
|
||||
$this->comment('supplier_rib', 'iban', 'IBAN du compte (≤ 34 caracteres).');
|
||||
$this->comment('supplier_rib', 'position', 'Ordre d affichage du RIB dans la liste du fournisseur (croissant).');
|
||||
$this->addTimestampableBlamableComments('supplier_rib');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Helpers
|
||||
// =================================================================
|
||||
|
||||
/**
|
||||
* Pose les 4 commentaires standardises Timestampable/Blamable sur une table,
|
||||
* en reutilisant le catalogue partage (source unique, cf. ERP-67).
|
||||
*/
|
||||
private function addTimestampableBlamableComments(string $table): void
|
||||
{
|
||||
foreach (ColumnCommentsCatalog::timestampableBlamableComments() as $column => $description) {
|
||||
$this->comment($table, $column, $description);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emet un `COMMENT ON TABLE` (colonne speciale `_table`) ou
|
||||
* `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour eviter
|
||||
* tout echappement d apostrophe.
|
||||
*/
|
||||
private function comment(string $table, string $column, string $description): void
|
||||
{
|
||||
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
||||
|
||||
if ('_table' === $column) {
|
||||
$this->addSql(sprintf('COMMENT ON TABLE %s IS $_$%s$_$', $quotedTable, $description));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addSql(sprintf(
|
||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||
$quotedTable,
|
||||
'"'.str_replace('"', '""', $column).'"',
|
||||
$description,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Catalog — Category multi-types : passage de la relation Category -> CategoryType
|
||||
* de ManyToOne a ManyToMany.
|
||||
*
|
||||
* Ordre critique :
|
||||
* 1. Creation de la table de jonction `category_category_type` (FK category ON
|
||||
* DELETE CASCADE, FK category_type ON DELETE RESTRICT — conserve le garde-fou
|
||||
* « on ne supprime pas un type encore reference »).
|
||||
* 2. Backfill : chaque categorie existante recoit une ligne de jonction vers son
|
||||
* ancien `category_type_id` (avant de dropper la colonne).
|
||||
* 3. Drop de l'index unique (LOWER(name), category_type_id), de l'index FK et de
|
||||
* la colonne `category.category_type_id` (Postgres drope la FK dependante).
|
||||
* 4. Nouvel index unique GLOBAL sur le nom : LOWER(name) WHERE deleted_at IS NULL
|
||||
* (l'unicite n'est plus liee au type — RG-1.07 reformulee).
|
||||
*
|
||||
* Sur base fraiche, les categories seedees CLIENT (Distributeur/Courtier/Secteur/
|
||||
* Autre) et FOURNISSEUR (Negociant/Cooperative/...) n'ont aucun nom en collision
|
||||
* -> l'index unique global passe sans conflit.
|
||||
*
|
||||
* Migration placee au namespace racine `DoctrineMigrations` (regle ABSOLUE n°11) :
|
||||
* Doctrine Migrations 3.x trie par FQCN puis version ; le namespace racine garantit
|
||||
* l'ordre par timestamp apres les migrations d'init des tables.
|
||||
*/
|
||||
final class Version20260608120000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Catalog : Category <-> CategoryType en ManyToMany (jonction category_category_type), unicite du nom globalisee.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// 1. Table de jonction.
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE category_category_type (
|
||||
category_id INT NOT NULL,
|
||||
category_type_id INT NOT NULL,
|
||||
PRIMARY KEY (category_id, category_type_id),
|
||||
CONSTRAINT fk_category_category_type_category
|
||||
FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_category_category_type_type
|
||||
FOREIGN KEY (category_type_id) REFERENCES category_type (id) ON DELETE RESTRICT
|
||||
)
|
||||
SQL);
|
||||
$this->addSql('CREATE INDEX idx_cat_cat_type_type ON category_category_type (category_type_id)');
|
||||
|
||||
$this->comment('category_category_type', '_table', 'Jointure M2M category <-> category_type (Catalog) — types portes par la categorie, au moins un obligatoire (RG-1.05).');
|
||||
$this->comment('category_category_type', 'category_id', 'FK -> category.id, ON DELETE CASCADE — categorie portant le type.');
|
||||
$this->comment('category_category_type', 'category_type_id', 'FK -> category_type.id, ON DELETE RESTRICT — type rattache (un type ne peut etre supprime tant qu il reste reference).');
|
||||
|
||||
// 2. Backfill depuis l'ancienne colonne ManyToOne (chaque categorie -> 1 type).
|
||||
$this->addSql(<<<'SQL'
|
||||
INSERT INTO category_category_type (category_id, category_type_id)
|
||||
SELECT id, category_type_id FROM category
|
||||
SQL);
|
||||
|
||||
// 3. Suppression de l'ancien modele : index unique par type, index FK, colonne.
|
||||
$this->addSql('DROP INDEX uq_category_name_type_active');
|
||||
$this->addSql('DROP INDEX idx_category_type_id');
|
||||
// DROP COLUMN drope automatiquement la FK fk_category_type qui en depend.
|
||||
$this->addSql('ALTER TABLE category DROP COLUMN category_type_id');
|
||||
|
||||
// 4. Unicite du nom desormais GLOBALE parmi les actifs (RG-1.07 reformulee).
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE UNIQUE INDEX uq_category_name_active
|
||||
ON category (LOWER(name))
|
||||
WHERE deleted_at IS NULL
|
||||
SQL);
|
||||
|
||||
// Realignement de la doc SQL de `category` (le type n'est plus une colonne).
|
||||
$this->comment('category', '_table', 'Categories — referentiel multi-types via la jonction category_category_type, soft-delete via deleted_at, unicite LOWER(name) GLOBALE parmi les actifs (uq_category_name_active).');
|
||||
$this->comment('category', 'name', 'Libelle de la categorie (≤ 120 caracteres) — unique GLOBALEMENT parmi les actifs (RG-1.07, uq_category_name_active).');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// Restauration best-effort de l'ancien modele ManyToOne (1 type par categorie).
|
||||
$this->addSql('DROP INDEX IF EXISTS uq_category_name_active');
|
||||
|
||||
$this->addSql('ALTER TABLE category ADD COLUMN category_type_id INT DEFAULT NULL');
|
||||
|
||||
// Reprend le premier type de chaque categorie (l'ordre des types perdus
|
||||
// au-dela du premier est best-effort : le modele cible n'en gardait qu'un).
|
||||
$this->addSql(<<<'SQL'
|
||||
UPDATE category c
|
||||
SET category_type_id = (
|
||||
SELECT cct.category_type_id
|
||||
FROM category_category_type cct
|
||||
WHERE cct.category_id = c.id
|
||||
ORDER BY cct.category_type_id ASC
|
||||
LIMIT 1
|
||||
)
|
||||
SQL);
|
||||
|
||||
// Categories sans aucun type (theorique) : on les rattache a defaut au
|
||||
// premier type existant pour pouvoir reposer le NOT NULL.
|
||||
$this->addSql(<<<'SQL'
|
||||
UPDATE category
|
||||
SET category_type_id = (SELECT id FROM category_type ORDER BY id ASC LIMIT 1)
|
||||
WHERE category_type_id IS NULL
|
||||
SQL);
|
||||
|
||||
$this->addSql('ALTER TABLE category ALTER COLUMN category_type_id SET NOT NULL');
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE category
|
||||
ADD CONSTRAINT fk_category_type
|
||||
FOREIGN KEY (category_type_id) REFERENCES category_type (id) ON DELETE RESTRICT
|
||||
SQL);
|
||||
$this->addSql('CREATE INDEX idx_category_type_id ON category (category_type_id)');
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE UNIQUE INDEX uq_category_name_type_active
|
||||
ON category (LOWER(name), category_type_id)
|
||||
WHERE deleted_at IS NULL
|
||||
SQL);
|
||||
|
||||
$this->addSql('DROP TABLE category_category_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Emet un `COMMENT ON TABLE` (colonne speciale `_table`) ou `COMMENT ON COLUMN`
|
||||
* en dollar-quoting Postgres ($_$...$_$) pour eviter tout echappement.
|
||||
*/
|
||||
private function comment(string $table, string $column, string $description): void
|
||||
{
|
||||
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
||||
|
||||
if ('_table' === $column) {
|
||||
$this->addSql(sprintf('COMMENT ON TABLE %s IS $_$%s$_$', $quotedTable, $description));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addSql(sprintf(
|
||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||
$quotedTable,
|
||||
'"'.str_replace('"', '""', $column).'"',
|
||||
$description,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* ERP-116 — Referentiel Pays (Country), 1re iteration : creation de la table
|
||||
* `country` + seed des 7 pays (France, Allemagne, Belgique, Espagne, Italie,
|
||||
* Royaume-Uni, Suisse). Devient la source unique du select pays, en
|
||||
* remplacement de la liste codee en dur cote front.
|
||||
*
|
||||
* Perimetre minimal voulu : code ISO 3166-1 alpha-2 + libelle FR + ordre
|
||||
* d'affichage UNIQUEMENT. Aucune longueur bancaire/fiscale (numero de compte,
|
||||
* IBAN, TVA, BIC, SIREN) a ce stade — iteration ulterieure du meme ticket.
|
||||
*
|
||||
* Pas de FK posee sur les adresses (client_address.country / supplier_address)
|
||||
* a cette etape : ces colonnes restent des chaines libres (« France »...), donc
|
||||
* aucune migration de donnees ni rupture de l'existant.
|
||||
*
|
||||
* Namespace racine `DoctrineMigrations` (regle ABSOLUE Starseed n°11) comme les
|
||||
* migrations M1/M2 du module Commercial : pas de migrations_path modulaire
|
||||
* configure pour Commercial, et le tri par timestamp reste garanti.
|
||||
*
|
||||
* Seed idempotent `ON CONFLICT (code) DO NOTHING` : la table peut deja porter
|
||||
* des donnees en prod lors d'un rejeu. Chaque colonne porte un `COMMENT ON
|
||||
* COLUMN` (regle ABSOLUE n°12, garde-fou ColumnsHaveSqlCommentTest) ; la table
|
||||
* est aussi mirroree dans ColumnCommentsCatalog pour survivre au
|
||||
* `schema:update --force` du setup de test.
|
||||
*/
|
||||
final class Version20260609100000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'ERP-116 : table country (referentiel pays) + seed des 7 pays.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE country (
|
||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
code VARCHAR(2) NOT NULL,
|
||||
name VARCHAR(80) NOT NULL,
|
||||
position INT DEFAULT 0 NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
SQL);
|
||||
$this->addSql('CREATE UNIQUE INDEX uq_country_code ON country (code)');
|
||||
|
||||
$this->comment('country', '_table', 'Referentiel des pays selectionnables dans les adresses (clients/fournisseurs). Perimetre minimal : code ISO + libelle + ordre (pas de longueurs bancaires/fiscales).');
|
||||
$this->comment('country', 'id', 'Identifiant interne auto-incremente.');
|
||||
$this->comment('country', 'code', 'Code pays ISO 3166-1 alpha-2 (2 lettres MAJUSCULES, ex: FR) — unique (uq_country_code), fige a la creation.');
|
||||
$this->comment('country', 'name', 'Libelle FR du pays (≤ 80 caracteres) — valeur stockee telle quelle dans les adresses (country en chaine libre a ce stade).');
|
||||
$this->comment('country', 'position', 'Ordre d affichage croissant dans le selecteur pays (tri position ASC puis name ASC ; France en tete).');
|
||||
|
||||
// Seed initial. France en tete (position 10) puis ordre alphabetique.
|
||||
// Table fraichement creee, mais ON CONFLICT pour rejouabilite en prod.
|
||||
$this->addSql(<<<'SQL'
|
||||
INSERT INTO country (code, name, position) VALUES
|
||||
('FR', 'France', 10),
|
||||
('DE', 'Allemagne', 20),
|
||||
('BE', 'Belgique', 30),
|
||||
('ES', 'Espagne', 40),
|
||||
('IT', 'Italie', 50),
|
||||
('GB', 'Royaume-Uni', 60),
|
||||
('CH', 'Suisse', 70)
|
||||
ON CONFLICT (code) DO NOTHING
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE country');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pose un `COMMENT ON TABLE` (colonne speciale `_table`) ou
|
||||
* `COMMENT ON COLUMN`. Quoting defensif des identifiants + delimiteur $_$
|
||||
* pour ne pas casser sur les apostrophes des descriptions.
|
||||
*/
|
||||
private function comment(string $table, string $column, string $description): void
|
||||
{
|
||||
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
||||
|
||||
if ('_table' === $column) {
|
||||
$this->addSql(sprintf('COMMENT ON TABLE %s IS $_$%s$_$', $quotedTable, $description));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addSql(sprintf(
|
||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||
$quotedTable,
|
||||
'"'.str_replace('"', '""', $column).'"',
|
||||
$description,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Commercial — deux nouveaux types d'adresse client : Courtier et Distributeur.
|
||||
*
|
||||
* Ajoute les drapeaux `is_broker` / `is_distributor` sur `client_address`, au
|
||||
* meme titre que `is_prospect` / `is_delivery` / `is_billing`. Ce sont des types
|
||||
* AUTONOMES (comme la Prospection) : exclusifs de tout autre usage. Deux CHECK
|
||||
* Postgres miroitent l'exclusivite applicative (validateExclusiveAddressTypes),
|
||||
* en filet de securite (comme chk_client_address_prospect_exclusive).
|
||||
*
|
||||
* NB Postgres : `ADD COLUMN` ajoute en derniere position physique (pas de clause
|
||||
* AFTER) — l'ordre physique est cosmetique, on adresse par nom. Les colonnes sont
|
||||
* declarees juste apres isBilling dans l'entite (ERP-119).
|
||||
*
|
||||
* Migration au namespace racine `DoctrineMigrations` (regle ABSOLUE n°11) : le
|
||||
* tri par version garantit son passage apres l'init des tables.
|
||||
*/
|
||||
final class Version20260609120000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Commercial : types d\'adresse Courtier / Distributeur (is_broker / is_distributor) sur client_address, exclusifs (CHECK).';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE client_address ADD COLUMN is_broker BOOLEAN DEFAULT FALSE NOT NULL');
|
||||
$this->addSql('ALTER TABLE client_address ADD COLUMN is_distributor BOOLEAN DEFAULT FALSE NOT NULL');
|
||||
|
||||
// Exclusivite miroir (filet de securite DBAL) : un type autonome interdit
|
||||
// tout autre drapeau. Livraison + Facturation restent cumulables entre eux.
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE client_address
|
||||
ADD CONSTRAINT chk_client_address_broker_exclusive
|
||||
CHECK (NOT (is_broker = TRUE AND (is_prospect = TRUE OR is_delivery = TRUE OR is_billing = TRUE OR is_distributor = TRUE)))
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE client_address
|
||||
ADD CONSTRAINT chk_client_address_distributor_exclusive
|
||||
CHECK (NOT (is_distributor = TRUE AND (is_prospect = TRUE OR is_delivery = TRUE OR is_billing = TRUE OR is_broker = TRUE)))
|
||||
SQL);
|
||||
|
||||
$this->comment('client_address', 'is_broker', 'Adresse Courtier — type autonome exclusif de tout autre usage (chk_client_address_broker_exclusive). Faux par defaut.');
|
||||
$this->comment('client_address', 'is_distributor', 'Adresse Distributeur — type autonome exclusif de tout autre usage (chk_client_address_distributor_exclusive). Faux par defaut.');
|
||||
|
||||
// Le commentaire de table mentionnait seulement prospect/livraison/facturation :
|
||||
// on y ajoute les types autonomes Courtier / Distributeur (cf. ColumnCommentsCatalog).
|
||||
$this->addSql('COMMENT ON TABLE client_address IS $_$Adresses d un client (1:n) — types prospect / livraison / facturation (exclusivites RG-1.06/07/08) + Courtier / Distributeur autonomes (exclusifs de tout autre usage), >= 1 site rattache (RG-1.10).$_$');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('COMMENT ON TABLE client_address IS $_$Adresses d un client (1:n) — prospect exclusif de livraison/facturation (RG-1.06/07/08), >= 1 site rattache (RG-1.10).$_$');
|
||||
$this->addSql('ALTER TABLE client_address DROP CONSTRAINT IF EXISTS chk_client_address_broker_exclusive');
|
||||
$this->addSql('ALTER TABLE client_address DROP CONSTRAINT IF EXISTS chk_client_address_distributor_exclusive');
|
||||
$this->addSql('ALTER TABLE client_address DROP COLUMN is_distributor');
|
||||
$this->addSql('ALTER TABLE client_address DROP COLUMN is_broker');
|
||||
}
|
||||
|
||||
/**
|
||||
* Emet un `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour
|
||||
* eviter tout echappement.
|
||||
*/
|
||||
private function comment(string $table, string $column, string $description): void
|
||||
{
|
||||
$this->addSql(sprintf(
|
||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||
'"'.str_replace('"', '""', $table).'"',
|
||||
'"'.str_replace('"', '""', $column).'"',
|
||||
$description,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Commercial — second email de facturation (optionnel) sur une adresse client.
|
||||
*
|
||||
* Ajoute `billing_email_secondary` sur `client_address`, pendant du telephone
|
||||
* secondaire du contact (max 2 emails). Optionnel ; comme l'email principal, il
|
||||
* n'a de sens que sur une adresse de facturation (validateBillingEmailPresence).
|
||||
*
|
||||
* Migration au namespace racine `DoctrineMigrations` (regle ABSOLUE n°11).
|
||||
*/
|
||||
final class Version20260609140000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Commercial : 2e email de facturation optionnel (billing_email_secondary) sur client_address.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE client_address ADD COLUMN billing_email_secondary VARCHAR(180) DEFAULT NULL');
|
||||
|
||||
$this->comment('client_address', 'billing_email_secondary', '2e email de facturation, optionnel (max 2). Interdit hors facturation (validateBillingEmailPresence), normalise en minuscules (RG-1.21).');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE client_address DROP COLUMN billing_email_secondary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Emet un `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour
|
||||
* eviter tout echappement.
|
||||
*/
|
||||
private function comment(string $table, string $column, string $description): void
|
||||
{
|
||||
$this->addSql(sprintf(
|
||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||
'"'.str_replace('"', '""', $table).'"',
|
||||
'"'.str_replace('"', '""', $column).'"',
|
||||
$description,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Commercial — geolocalisation des adresses Tiers (M6.1 / ERP-122, spec M6
|
||||
* § 3.2 / § 4.1).
|
||||
*
|
||||
* Ajoute sur `client_address` ET `supplier_address` :
|
||||
* - latitude / longitude NUMERIC(10,7) null : coordonnees WGS84, alimentees
|
||||
* par le geocodage BAN automatique ou par le pin manuel ;
|
||||
* - geo_manual BOOLEAN default false : RG-6.08, un pin corrige a la main fige
|
||||
* les coordonnees (le geocodage auto ne reecrit plus) ;
|
||||
* - geocoded_at TIMESTAMPTZ null : date du dernier geocodage auto reussi.
|
||||
*
|
||||
* Migration au namespace racine `DoctrineMigrations` (pratique effective du
|
||||
* projet : le namespace modulaire Commercial n'est pas enregistre dans
|
||||
* doctrine_migrations.yaml et souffrirait du tri FQCN inter-namespaces sur
|
||||
* base vide — cf. regle ABSOLUE n°11 / architecture.md § Migrations).
|
||||
*/
|
||||
final class Version20260611130000 extends AbstractMigration
|
||||
{
|
||||
private const array TABLES = ['client_address', 'supplier_address'];
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Commercial : geolocalisation des adresses Tiers (latitude/longitude/geo_manual/geocoded_at sur client_address et supplier_address).';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
foreach (self::TABLES as $table) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD COLUMN latitude NUMERIC(10, 7) DEFAULT NULL', $table));
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD COLUMN longitude NUMERIC(10, 7) DEFAULT NULL', $table));
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD COLUMN geo_manual BOOLEAN DEFAULT false NOT NULL', $table));
|
||||
$this->addSql(sprintf('ALTER TABLE %s ADD COLUMN geocoded_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL', $table));
|
||||
|
||||
$this->comment($table, 'latitude', 'Latitude WGS84 de l adresse (geocodage BAN ou pin manuel). NULL = non geolocalisee, exclue du calcul de tournee (RG-6.05).');
|
||||
$this->comment($table, 'longitude', 'Longitude WGS84 de l adresse (geocodage BAN ou pin manuel). NULL = non geolocalisee.');
|
||||
$this->comment($table, 'geo_manual', 'Pin positionne/corrige a la main : si vrai, le geocodage auto ne reecrit plus les coordonnees (RG-6.08). Faux par defaut.');
|
||||
$this->comment($table, 'geocoded_at', 'Date du dernier geocodage automatique reussi (NULL si jamais geocode ou pin 100% manuel).');
|
||||
}
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
foreach (self::TABLES as $table) {
|
||||
$this->addSql(sprintf('ALTER TABLE %s DROP COLUMN latitude', $table));
|
||||
$this->addSql(sprintf('ALTER TABLE %s DROP COLUMN longitude', $table));
|
||||
$this->addSql(sprintf('ALTER TABLE %s DROP COLUMN geo_manual', $table));
|
||||
$this->addSql(sprintf('ALTER TABLE %s DROP COLUMN geocoded_at', $table));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emet un `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour
|
||||
* eviter tout echappement.
|
||||
*/
|
||||
private function comment(string $table, string $column, string $description): void
|
||||
{
|
||||
$this->addSql(sprintf(
|
||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||
'"'.str_replace('"', '""', $table).'"',
|
||||
'"'.str_replace('"', '""', $column).'"',
|
||||
$description,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use App\Shared\Infrastructure\Database\ColumnCommentsCatalog;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* M6.3 (ERP-124) — Tournees commerciales terrain : creation des tables `tour`
|
||||
* (tournee) et `tour_stop` (etape) du module FieldSales.
|
||||
*
|
||||
* SCOPE REDUIT (V0.2) : pas de rapport de visite -> `tour_stop` SANS report_id ni
|
||||
* arrived_at / check-in.
|
||||
*
|
||||
* Particularites de modelisation :
|
||||
* - tour.owner_id : FK -> "user".id, ON DELETE RESTRICT (tournee personnelle,
|
||||
* RG-6.01 ; un user proprietaire d'une tournee ne peut etre supprime).
|
||||
* - tour_stop.tier_id / address_id : entiers SANS FK. La cible d'une etape est
|
||||
* polymorphe (Client M1 / Fournisseur M2 / point custom) resolue via
|
||||
* tier_type ; aucune FK unique possible (RG-6.07 : pas d'unicite sur tier_id).
|
||||
* - Unicite (tour_id, position) : un seul ordre par tournee (uq_tour_stop_position).
|
||||
* - tour_stop.tour_id : FK -> tour.id, ON DELETE CASCADE.
|
||||
*
|
||||
* Namespace racine `DoctrineMigrations` (regle ABSOLUE Starseed n°11) et non
|
||||
* modulaire : la migration cree des FK cross-module (vers "user"). Avec plusieurs
|
||||
* migrations_paths, Doctrine Migrations 3.x trie par FQCN alphabetique — un
|
||||
* namespace modulaire s'executerait avant la creation de "user" sur base vide.
|
||||
* Le namespace racine garantit l'ordre par timestamp.
|
||||
*
|
||||
* Style DDL aligne sur M1/M2 (INT GENERATED BY DEFAULT AS IDENTITY,
|
||||
* TIMESTAMP(0) WITHOUT TIME ZONE car le trait T/B mappe datetime_immutable),
|
||||
* pour que `schema:update` reste un no-op. Chaque colonne porte son
|
||||
* `COMMENT ON COLUMN` (regle ABSOLUE n°12) ; les 4 colonnes T/B via le catalogue
|
||||
* partage. Les tables sont egalement mirorees dans ColumnCommentsCatalog pour
|
||||
* que `app:apply-column-comments` rejoue les COMMENT apres le schema:update du
|
||||
* setup de test (qui les drope sur les tables mappees par l'ORM).
|
||||
*/
|
||||
final class Version20260611140000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'ERP-124 (M6.3) : tables tour + tour_stop (module FieldSales), sans rapport de visite (scope reduit V0.2).';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->createTourTable();
|
||||
$this->createTourStopTable();
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// Ordre inverse des dependances FK : tour_stop (FK -> tour) puis tour.
|
||||
$this->addSql('DROP TABLE IF EXISTS tour_stop');
|
||||
$this->addSql('DROP TABLE IF EXISTS tour');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Table `tour`
|
||||
// =================================================================
|
||||
|
||||
private function createTourTable(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE tour (
|
||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
owner_id INT NOT NULL,
|
||||
label VARCHAR(120) NOT NULL,
|
||||
tour_date DATE NOT NULL,
|
||||
departure_time TIME(0) WITHOUT TIME ZONE NOT NULL,
|
||||
start_latitude NUMERIC(10, 7) DEFAULT NULL,
|
||||
start_longitude NUMERIC(10, 7) DEFAULT NULL,
|
||||
start_label VARCHAR(180) DEFAULT NULL,
|
||||
default_visit_minutes SMALLINT DEFAULT 30 NOT NULL,
|
||||
status VARCHAR(20) DEFAULT 'draft' NOT NULL,
|
||||
total_distance_m INT DEFAULT NULL,
|
||||
total_duration_s INT DEFAULT NULL,
|
||||
deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
created_by INT DEFAULT NULL,
|
||||
updated_by INT DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT fk_tour_owner
|
||||
FOREIGN KEY (owner_id) REFERENCES "user" (id) ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_tour_created_by
|
||||
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_tour_updated_by
|
||||
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql('CREATE INDEX idx_tour_owner ON tour (owner_id)');
|
||||
$this->addSql('CREATE INDEX idx_tour_status ON tour (status)');
|
||||
$this->addSql('CREATE INDEX idx_tour_deleted_at ON tour (deleted_at)');
|
||||
$this->addSql('CREATE INDEX idx_tour_created_by ON tour (created_by)');
|
||||
$this->addSql('CREATE INDEX idx_tour_updated_by ON tour (updated_by)');
|
||||
|
||||
$this->comment('tour', '_table', 'Tournees commerciales terrain (M6 FieldSales) — personnelles (owner), soft-deletables (deleted_at).');
|
||||
$this->comment('tour', 'id', 'Identifiant interne auto-incremente.');
|
||||
$this->comment('tour', 'owner_id', 'Commercial proprietaire de la tournee (RG-6.01, personnelle) — FK -> "user".id, ON DELETE RESTRICT. Pose au POST par le TourProcessor.');
|
||||
$this->comment('tour', 'label', 'Nom libre de la tournee (NotBlank, <= 120 caracteres).');
|
||||
$this->comment('tour', 'tour_date', 'Date de realisation de la tournee (NotNull).');
|
||||
$this->comment('tour', 'departure_time', 'Heure de depart, alimente les ETA (RG-6.11). Defaut applicatif 08:00 (constructeur).');
|
||||
$this->comment('tour', 'start_latitude', 'Latitude WGS84 du point de depart (site commercial ou adresse libre). NULL -> depart = 1re etape.');
|
||||
$this->comment('tour', 'start_longitude', 'Longitude WGS84 du point de depart. NULL -> depart = 1re etape.');
|
||||
$this->comment('tour', 'start_label', 'Libelle affichable du point de depart (<= 180 caracteres). Optionnel.');
|
||||
$this->comment('tour', 'default_visit_minutes', 'Duree de visite par defaut d une etape, en minutes (defaut 30) — utilisee si l etape ne fixe pas sa propre duree.');
|
||||
$this->comment('tour', 'status', 'Cycle de vie (RG-6.02) : draft | planned | in_progress | done (enum TourStatus). Transitions libres en V1. Defaut draft.');
|
||||
$this->comment('tour', 'total_distance_m', 'Cache d affichage : derniere distance totale calculee, en metres (RG-6.11). Lecture seule API, alimente par le moteur de trajet (M6.4).');
|
||||
$this->comment('tour', 'total_duration_s', 'Cache d affichage : derniere duree totale calculee, en secondes (RG-6.11). Lecture seule API.');
|
||||
$this->comment('tour', 'deleted_at', 'Horodatage du soft-delete — pose par le DELETE API. Null = tournee active.');
|
||||
$this->addTimestampableBlamableComments('tour');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Table `tour_stop`
|
||||
// =================================================================
|
||||
|
||||
private function createTourStopTable(): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
CREATE TABLE tour_stop (
|
||||
id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
|
||||
tour_id INT NOT NULL,
|
||||
tier_type VARCHAR(30) NOT NULL,
|
||||
tier_id INT DEFAULT NULL,
|
||||
address_id INT DEFAULT NULL,
|
||||
custom_label VARCHAR(180) DEFAULT NULL,
|
||||
custom_address VARCHAR(255) DEFAULT NULL,
|
||||
custom_latitude NUMERIC(10, 7) DEFAULT NULL,
|
||||
custom_longitude NUMERIC(10, 7) DEFAULT NULL,
|
||||
position SMALLINT NOT NULL,
|
||||
visit_minutes SMALLINT DEFAULT NULL,
|
||||
leg_distance_m INT DEFAULT NULL,
|
||||
leg_duration_s INT DEFAULT NULL,
|
||||
eta TIME(0) WITHOUT TIME ZONE DEFAULT NULL,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
created_by INT DEFAULT NULL,
|
||||
updated_by INT DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT fk_tour_stop_tour
|
||||
FOREIGN KEY (tour_id) REFERENCES tour (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_tour_stop_created_by
|
||||
FOREIGN KEY (created_by) REFERENCES "user" (id) ON DELETE SET NULL,
|
||||
CONSTRAINT fk_tour_stop_updated_by
|
||||
FOREIGN KEY (updated_by) REFERENCES "user" (id) ON DELETE SET NULL
|
||||
)
|
||||
SQL);
|
||||
|
||||
$this->addSql('CREATE INDEX idx_tour_stop_tour ON tour_stop (tour_id)');
|
||||
$this->addSql('CREATE INDEX idx_tour_stop_created_by ON tour_stop (created_by)');
|
||||
$this->addSql('CREATE INDEX idx_tour_stop_updated_by ON tour_stop (updated_by)');
|
||||
|
||||
// RG-6.07 : pas d unicite sur tier_id (deux etapes peuvent viser le meme
|
||||
// Tiers). Unicite uniquement sur l ordre dans la tournee.
|
||||
$this->addSql('CREATE UNIQUE INDEX uq_tour_stop_position ON tour_stop (tour_id, position)');
|
||||
|
||||
$this->comment('tour_stop', '_table', 'Etapes ordonnees d une tournee (M6) — cible polymorphe (Tiers referentiel ou point custom). Pas de rapport (scope reduit V0.2).');
|
||||
$this->comment('tour_stop', 'id', 'Identifiant interne auto-incremente.');
|
||||
$this->comment('tour_stop', 'tour_id', 'FK -> tour.id, ON DELETE CASCADE — tournee proprietaire de l etape.');
|
||||
$this->comment('tour_stop', 'tier_type', 'Type de cible : client | supplier | ... | custom (point libre). Resolu via VisitableInterface. Chaine ouverte (Assert\\Choice).');
|
||||
$this->comment('tour_stop', 'tier_id', 'Identifiant du Tiers referentiel cible (NULL si custom). Sans FK (cible polymorphe). RG-6.07 : aucune unicite.');
|
||||
$this->comment('tour_stop', 'address_id', 'Adresse precise visitee chez le Tiers (NULL si custom). Sans FK (client_address OU supplier_address). RG-6.03 : doit appartenir au Tiers.');
|
||||
$this->comment('tour_stop', 'custom_label', 'Libelle du point libre — obligatoire ssi tier_type = custom (RG-6.12), sinon NULL.');
|
||||
$this->comment('tour_stop', 'custom_address', 'Adresse texte du point libre (geocodee) — renseignee uniquement si custom.');
|
||||
$this->comment('tour_stop', 'custom_latitude', 'Latitude WGS84 du point libre (pin ajustable) — obligatoire ssi custom (RG-6.12).');
|
||||
$this->comment('tour_stop', 'custom_longitude', 'Longitude WGS84 du point libre — obligatoire ssi custom (RG-6.12).');
|
||||
$this->comment('tour_stop', 'position', 'Ordre de l etape dans la tournee (drag & drop). Unique par tournee (uq_tour_stop_position).');
|
||||
$this->comment('tour_stop', 'visit_minutes', 'Duree de visite specifique a l etape, en minutes — sinon tour.default_visit_minutes.');
|
||||
$this->comment('tour_stop', 'leg_distance_m', 'Cache : distance depuis l etape precedente, en metres (calcule). Lecture seule API (M6.4).');
|
||||
$this->comment('tour_stop', 'leg_duration_s', 'Cache : temps depuis l etape precedente, en secondes (calcule). Lecture seule API (M6.4).');
|
||||
$this->comment('tour_stop', 'eta', 'Heure d arrivee estimee a l etape (RG-6.11, calculee). Lecture seule API.');
|
||||
$this->addTimestampableBlamableComments('tour_stop');
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Helpers
|
||||
// =================================================================
|
||||
|
||||
/**
|
||||
* Pose les 4 commentaires standardises Timestampable/Blamable sur une table,
|
||||
* en reutilisant le catalogue partage (source unique).
|
||||
*/
|
||||
private function addTimestampableBlamableComments(string $table): void
|
||||
{
|
||||
foreach (ColumnCommentsCatalog::timestampableBlamableComments() as $column => $description) {
|
||||
$this->comment($table, $column, $description);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emet un `COMMENT ON TABLE` (colonne speciale `_table`) ou
|
||||
* `COMMENT ON COLUMN` en dollar-quoting Postgres ($_$...$_$) pour eviter
|
||||
* tout echappement d apostrophe.
|
||||
*/
|
||||
private function comment(string $table, string $column, string $description): void
|
||||
{
|
||||
$quotedTable = '"'.str_replace('"', '""', $table).'"';
|
||||
|
||||
if ('_table' === $column) {
|
||||
$this->addSql(sprintf('COMMENT ON TABLE %s IS $_$%s$_$', $quotedTable, $description));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addSql(sprintf(
|
||||
'COMMENT ON COLUMN %s.%s IS $_$%s$_$',
|
||||
$quotedTable,
|
||||
'"'.str_replace('"', '""', $column).'"',
|
||||
$description,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,18 @@ use App\Shared\Domain\Contract\CategoryInterface;
|
||||
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Categorie : referentiel metier classifiant les futurs tiers (clients,
|
||||
* fournisseurs, prestataires). Porte un `name` libre et un `categoryType`
|
||||
* (FK vers le referentiel statique CategoryType).
|
||||
* fournisseurs, prestataires). Porte un `name` libre et un ou plusieurs
|
||||
* `categoryTypes` (ManyToMany vers le referentiel statique CategoryType,
|
||||
* table de jonction `category_category_type`). Une categorie peut appartenir
|
||||
* a plusieurs types simultanement (>= 1 obligatoire, RG-1.05).
|
||||
*
|
||||
* - Soft delete via `deletedAt` (pas de hard delete) : la liste exclut par
|
||||
* defaut les categories supprimees (cf. CategoryProvider, ticket 0.3).
|
||||
@@ -81,12 +85,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
#[ORM\Entity(repositoryClass: DoctrineCategoryRepository::class)]
|
||||
#[ORM\Table(name: 'category')]
|
||||
// Index nommes pour matcher la migration (cf. Role/Permission/Site). Les index
|
||||
// uniques partiels `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)
|
||||
// restent possedes par la seule migration : Doctrine ORM ne sait pas exprimer un
|
||||
// index partiel via attribut.
|
||||
// uniques partiels `uq_category_name_active` (LOWER(name) WHERE deleted_at IS
|
||||
// NULL — unicite GLOBALE du nom parmi les actifs) et `uq_category_code` (code
|
||||
// WHERE deleted_at IS NULL) restent possedes par la seule migration : Doctrine
|
||||
// ORM ne sait pas exprimer un index partiel via attribut.
|
||||
#[ORM\Index(name: 'idx_category_deleted_at', columns: ['deleted_at'])]
|
||||
#[ORM\Index(name: 'idx_category_type_id', columns: ['category_type_id'])]
|
||||
#[ORM\Index(name: 'idx_category_created_by', columns: ['created_by'])]
|
||||
#[ORM\Index(name: 'idx_category_updated_by', columns: ['updated_by'])]
|
||||
#[Auditable]
|
||||
@@ -126,11 +129,21 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
||||
#[Groups(['category:read'])]
|
||||
private ?string $code = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: CategoryType::class)]
|
||||
#[ORM\JoinColumn(name: 'category_type_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
|
||||
#[Assert\NotNull(message: 'Type de catégorie obligatoire.')]
|
||||
/**
|
||||
* Types de la categorie (>= 1 obligatoire, RG-1.05). ManyToMany vers le
|
||||
* referentiel statique CategoryType via la jonction `category_category_type`.
|
||||
* Cote inverse (category_type) en ON DELETE RESTRICT : un type ne peut etre
|
||||
* supprime tant qu'il reste reference par une categorie.
|
||||
*
|
||||
* @var Collection<int, CategoryType>
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: CategoryType::class)]
|
||||
#[ORM\JoinTable(name: 'category_category_type')]
|
||||
#[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
#[ORM\InverseJoinColumn(name: 'category_type_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||
#[Assert\Count(min: 1, minMessage: 'Sélectionnez au moins un type de catégorie.')]
|
||||
#[Groups(['category:read', 'category:write'])]
|
||||
private ?CategoryType $categoryType = null;
|
||||
private Collection $categoryTypes;
|
||||
|
||||
/**
|
||||
* Soft delete : null = active, valeur = supprimee logiquement le {date}.
|
||||
@@ -141,6 +154,11 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
||||
#[Groups(['category:read'])]
|
||||
private ?DateTimeImmutable $deletedAt = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->categoryTypes = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -173,26 +191,42 @@ class Category implements TimestampableInterface, BlamableInterface, CategoryInt
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategoryType(): ?CategoryType
|
||||
/**
|
||||
* @return Collection<int, CategoryType>
|
||||
*/
|
||||
public function getCategoryTypes(): Collection
|
||||
{
|
||||
return $this->categoryType;
|
||||
return $this->categoryTypes;
|
||||
}
|
||||
|
||||
public function setCategoryType(?CategoryType $categoryType): static
|
||||
public function addCategoryType(CategoryType $categoryType): static
|
||||
{
|
||||
$this->categoryType = $categoryType;
|
||||
if (!$this->categoryTypes->contains($categoryType)) {
|
||||
$this->categoryTypes->add($categoryType);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCategoryType(CategoryType $categoryType): static
|
||||
{
|
||||
$this->categoryTypes->removeElement($categoryType);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemente CategoryInterface : code du type rattache (ou null). Permet
|
||||
* aux modules tiers de filtrer/valider par type metier sans dependre de
|
||||
* Catalog.
|
||||
* Implemente CategoryInterface : liste des codes de types rattaches a la
|
||||
* categorie. Permet aux modules tiers de filtrer/valider par type metier
|
||||
* (ex: RG-2.10 « contient FOURNISSEUR ») sans dependre de Catalog.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getCategoryTypeCode(): ?string
|
||||
public function getCategoryTypeCodes(): array
|
||||
{
|
||||
return $this->categoryType?->getCode();
|
||||
return array_values(array_filter(
|
||||
$this->categoryTypes->map(static fn (CategoryType $t): ?string => $t->getCode())->toArray(),
|
||||
));
|
||||
}
|
||||
|
||||
public function getDeletedAt(): ?DateTimeImmutable
|
||||
|
||||
@@ -23,10 +23,26 @@ interface CategoryRepositoryInterface
|
||||
/**
|
||||
* Construit un QueryBuilder de liste avec filtre soft-delete et tri par defaut.
|
||||
* - $includeDeleted = false : exclut les categories soft-deleted (RG-1.08)
|
||||
* - $typeCode non null : ne garde que les categories dont le CategoryType
|
||||
* porte ce code (filtre `?typeCode=`, ex. FOURNISSEUR / CLIENT). Sert au
|
||||
* multi-select Categorie du fournisseur (M2, RG-2.10).
|
||||
* - $typeCode non null : ne garde que les categories PORTANT ce code de type
|
||||
* (filtre `?typeCode=`, ex. FOURNISSEUR / CLIENT). Sert au multi-select
|
||||
* Categorie du fournisseur (M2, RG-2.10).
|
||||
* - $nameSearch non null : recherche partielle case-insensitive sur le nom
|
||||
* (filtre `?name=` de la liste admin).
|
||||
* - $typeIds non vide : ne garde que les categories portant AU MOINS UN des
|
||||
* types (OR, filtre `?typeId[]=` de la liste admin).
|
||||
* - Tri : name ASC (RG-1.10).
|
||||
*
|
||||
* Les categories etant en ManyToMany avec leurs types, la collection
|
||||
* `categoryTypes` est eager-loadee (addSelect) pour eviter un N+1 a la
|
||||
* serialisation, et `distinct` est applique des qu'un filtre type joint la
|
||||
* table de jonction (evite les lignes dupliquees).
|
||||
*
|
||||
* @param list<int> $typeIds
|
||||
*/
|
||||
public function createListQueryBuilder(bool $includeDeleted = false, ?string $typeCode = null): QueryBuilder;
|
||||
public function createListQueryBuilder(
|
||||
bool $includeDeleted = false,
|
||||
?string $typeCode = null,
|
||||
?string $nameSearch = null,
|
||||
array $typeIds = [],
|
||||
): QueryBuilder;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
* via CategoryCodeGenerator ; puis delegation au persist_processor Doctrine
|
||||
* ORM. Le code est FIGE a la creation (jamais recalcule sur PATCH). Toute
|
||||
* 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).
|
||||
* l'index partiel uq_category_name_active — unicite GLOBALE du nom parmi les
|
||||
* actifs) est traduite en HTTP 409 avec le message attendu par la spec (RG-1.07).
|
||||
* - DELETE : soft delete (RG-1.12). On NE delegue PAS au remove_processor ;
|
||||
* on pose deletedAt = now() puis on delegue au persist_processor pour que
|
||||
* le UPDATE Doctrine parte et que le TimestampableBlamableSubscriber mette
|
||||
@@ -78,10 +78,12 @@ final class CategoryProcessor implements ProcessorInterface
|
||||
try {
|
||||
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
// RG-1.07 : doublon (LOWER(name), category_type_id) parmi les non-soft-deleted.
|
||||
// RG-1.07 : doublon de nom GLOBAL (LOWER(name)) parmi les non-soft-deleted
|
||||
// (uq_category_name_active). L'unicite n'est plus liee au type depuis le
|
||||
// passage en ManyToMany.
|
||||
throw new HttpException(
|
||||
409,
|
||||
sprintf('Une catégorie nommée "%s" existe déjà pour ce type.', $data->getName() ?? ''),
|
||||
sprintf('Une catégorie nommée "%s" existe déjà.', $data->getName() ?? ''),
|
||||
$e,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,12 @@ final class CategoryProvider implements ProviderInterface
|
||||
$includeDeleted = $this->readIncludeDeleted($context);
|
||||
|
||||
if ($operation instanceof CollectionOperationInterface) {
|
||||
$qb = $this->repository->createListQueryBuilder($includeDeleted, $this->readTypeCode($context));
|
||||
$qb = $this->repository->createListQueryBuilder(
|
||||
$includeDeleted,
|
||||
$this->readTypeCode($context),
|
||||
$this->readNameSearch($context),
|
||||
$this->readTypeIds($context),
|
||||
);
|
||||
|
||||
// Echappatoire ?pagination=false : retourne la collection complete sans Paginator.
|
||||
// Utile pour les drawers Role/Permission/Site/CategoryType qui alimentent un <select>.
|
||||
@@ -115,4 +120,48 @@ final class CategoryProvider implements ProviderInterface
|
||||
|
||||
return '' === $raw ? null : $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit le filtre `?name=` (recherche partielle sur le nom, liste admin).
|
||||
* Renvoie la valeur trimmee ou null si absente / vide.
|
||||
*/
|
||||
private function readNameSearch(array $context): ?string
|
||||
{
|
||||
$raw = $context['filters']['name'] ?? null;
|
||||
|
||||
if (!is_string($raw)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$raw = trim($raw);
|
||||
|
||||
return '' === $raw ? null : $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit le filtre `?typeId[]=` (liste admin) : ids des types coches (OR).
|
||||
* Tolere une valeur scalaire unique (`?typeId=3`) ou un tableau. Ignore
|
||||
* les entrees non numeriques.
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
private function readTypeIds(array $context): array
|
||||
{
|
||||
$raw = $context['filters']['typeId'] ?? null;
|
||||
|
||||
if (null === $raw) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$values = is_array($raw) ? $raw : [$raw];
|
||||
|
||||
$ids = [];
|
||||
foreach ($values as $value) {
|
||||
if (is_int($value) || (is_string($value) && ctype_digit($value))) {
|
||||
$ids[] = (int) $value;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($ids));
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user