Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d5d7d2e2aa | |||
| 36149dd521 | |||
| 681fca9aeb | |||
| a650fe8132 | |||
| 335d2ed207 | |||
| f2c06aed43 | |||
| 5349c3c4d5 | |||
| 68e7205793 | |||
| 4dcc247436 | |||
| b438838465 | |||
| 9f3fe4da4e | |||
| ef7bf69980 | |||
| 117dcdbdcc |
@@ -12,6 +12,7 @@
|
||||
"doctrine/doctrine-bundle": "^3.2",
|
||||
"doctrine/doctrine-migrations-bundle": "^4.0",
|
||||
"doctrine/orm": "^3.6",
|
||||
"dompdf/dompdf": "^3.0",
|
||||
"lexik/jwt-authentication-bundle": "^3.2",
|
||||
"nelmio/cors-bundle": "^2.6",
|
||||
"nyholm/psr7": "^1.8",
|
||||
|
||||
Generated
+446
-1
@@ -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": "b029c1484227c926d39dfd3ae5cb0699",
|
||||
"content-hash": "224bae08ec63f217eabf5b2b611deaa0",
|
||||
"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.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Masterminds/html5-php.git",
|
||||
"reference": "fd5018f6815fff903946d0564977b44ce8010e29"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Masterminds/html5-php/zipball/fd5018f6815fff903946d0564977b44ce8010e29",
|
||||
"reference": "fd5018f6815fff903946d0564977b44ce8010e29",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9 || ^10"
|
||||
},
|
||||
"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.1"
|
||||
},
|
||||
"time": "2026-06-23T18:43:15+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.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/MyIntervals/PHP-CSS-Parser.git",
|
||||
"reference": "fd3bf9fb173e0df649bc4e3e0d088a1b2417c08f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/MyIntervals/PHP-CSS-Parser/zipball/fd3bf9fb173e0df649bc4e3e0d088a1b2417c08f",
|
||||
"reference": "fd3bf9fb173e0df649bc4e3e0d088a1b2417c08f",
|
||||
"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.33 || 2.2.2",
|
||||
"phpstan/phpstan-phpunit": "1.4.2 || 2.0.16",
|
||||
"phpstan/phpstan-strict-rules": "1.6.2 || 2.0.11",
|
||||
"phpunit/phpunit": "8.5.52",
|
||||
"rawr/phpunit-data-provider": "3.3.1",
|
||||
"rector/rector": "1.2.10 || 2.4.6",
|
||||
"rector/type-perfect": "1.0.0 || 2.1.3",
|
||||
"squizlabs/php_codesniffer": "4.0.1",
|
||||
"thecodingmachine/phpstan-safe-rule": "1.2.0 || 1.4.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "for parsing UTF-8 CSS"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "9.5.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.4.0"
|
||||
},
|
||||
"time": "2026-06-18T15:10:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/asset",
|
||||
"version": "v8.0.8",
|
||||
@@ -8779,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",
|
||||
|
||||
+21
-20
@@ -38,7 +38,27 @@ declare(strict_types=1);
|
||||
*/
|
||||
|
||||
return [
|
||||
// Section "Commerciale" : pole metier principal, remontee en tete de sidebar (ERP-71).
|
||||
// Section "Logistique" (M5, ERP-181) : nouveau pole "operations physiques sur
|
||||
// site", distinct du repertoire Transport (M4, desormais rattache a la section
|
||||
// Administration cote develop). Porte le ticket de pesee au pont bascule.
|
||||
// Placee en tete de sidebar (avant Commerciale). L'item est gate par
|
||||
// `logistique.weighing_tickets.view` ; la section disparait automatiquement
|
||||
// (SidebarProvider) si le module `logistique` est desactive ou si l'user n'a
|
||||
// pas la permission (Compta / Commerciale).
|
||||
[
|
||||
'label' => 'sidebar.logistique.section',
|
||||
'icon' => 'mdi:truck-outline',
|
||||
'items' => [
|
||||
[
|
||||
'label' => 'sidebar.logistique.weighing_tickets',
|
||||
'to' => '/weighing-tickets',
|
||||
'icon' => 'mdi:truck-outline',
|
||||
'module' => 'logistique',
|
||||
'permission' => 'logistique.weighing_tickets.view',
|
||||
],
|
||||
],
|
||||
],
|
||||
// Section "Commerciale" : pole metier principal (ERP-71).
|
||||
// L'ordre interne des onglets et les permissions restent inchanges (simple deplacement
|
||||
// du bloc, aucun gate touche).
|
||||
[
|
||||
@@ -78,25 +98,6 @@ return [
|
||||
],
|
||||
],
|
||||
],
|
||||
// Section "Logistique" (M5, ERP-181) : nouveau pole "operations physiques sur
|
||||
// site", distinct du repertoire Transport (M4, desormais rattache a la section
|
||||
// Administration cote develop). Porte le ticket de pesee au pont bascule.
|
||||
// L'item est gate par `logistique.weighing_tickets.view` ; la section disparait
|
||||
// automatiquement (SidebarProvider) si le module `logistique` est desactive ou
|
||||
// si l'user n'a pas la permission (Compta / Commerciale).
|
||||
[
|
||||
'label' => 'sidebar.logistique.section',
|
||||
'icon' => 'mdi:scale',
|
||||
'items' => [
|
||||
[
|
||||
'label' => 'sidebar.logistique.weighing_tickets',
|
||||
'to' => '/weighing-tickets',
|
||||
'icon' => 'mdi:scale',
|
||||
'module' => 'logistique',
|
||||
'permission' => 'logistique.weighing_tickets.view',
|
||||
],
|
||||
],
|
||||
],
|
||||
// Section "Administration" : regroupe toutes les pages de configuration
|
||||
// applicative (RBAC, users, sites, audit log).
|
||||
//
|
||||
|
||||
@@ -691,6 +691,69 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"logistique": {
|
||||
"weighingTickets": {
|
||||
"title": "Tickets de pesée",
|
||||
"add": "Ajouter",
|
||||
"export": "Exporter",
|
||||
"empty": "Aucun ticket de pesée pour l'instant.",
|
||||
"column": {
|
||||
"number": "Numéro",
|
||||
"client": "Client",
|
||||
"supplier": "Fournisseur",
|
||||
"other": "Autre",
|
||||
"date": "Date",
|
||||
"weight": "Poids"
|
||||
},
|
||||
"form": {
|
||||
"back": "Retour à la liste",
|
||||
"addTitle": "Ajouter un ticket de pesée",
|
||||
"emptyBlock": "Poids à vide",
|
||||
"fullBlock": "Poids à plein",
|
||||
"date": "Date",
|
||||
"weight": "Poids (Kg)",
|
||||
"dsd": "DSD",
|
||||
"immatriculation": "Immatriculation",
|
||||
"plateFreeFormat": "Tout format",
|
||||
"save": "Enregistrer",
|
||||
"validate": "Valider",
|
||||
"print": "Imprimer",
|
||||
"weightRequired": "Le poids est obligatoire : effectuez une pesée.",
|
||||
"dsdRequired": "Le DSD est obligatoire : effectuez une pesée.",
|
||||
"counterparty": {
|
||||
"type": "Fournisseur / Client / Autre",
|
||||
"supplier": "Fournisseur",
|
||||
"client": "Client",
|
||||
"other": "Autre"
|
||||
},
|
||||
"weighbridge": {
|
||||
"auto": "Pesée bascule",
|
||||
"manual": "Pesée manuelle",
|
||||
"confirmTitle": "Êtes-vous sûr de vouloir déclencher une pesée ?",
|
||||
"validate": "Valider",
|
||||
"unavailable": "Pont bascule indisponible — passez en pesée manuelle."
|
||||
},
|
||||
"manual": {
|
||||
"title": "Pesée manuelle",
|
||||
"weight": "Poids (Kg)",
|
||||
"number": "Numéro de pesée",
|
||||
"save": "Enregistrer",
|
||||
"weightRequired": "Le poids est obligatoire.",
|
||||
"numberRequired": "Le numéro de pesée est obligatoire."
|
||||
}
|
||||
},
|
||||
"edit": {
|
||||
"title": "Ticket de pesée {number}",
|
||||
"titleFallback": "Modifier un ticket de pesée",
|
||||
"loading": "Chargement du ticket…",
|
||||
"notFound": "Ticket de pesée introuvable."
|
||||
},
|
||||
"toast": {
|
||||
"error": "Une erreur est survenue. Réessayez.",
|
||||
"exportError": "L'export des tickets de pesée a échoué. Réessayez."
|
||||
}
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
"login": "Connexion",
|
||||
"logout": "Deconnexion",
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<template>
|
||||
<div class="bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||
<!-- En-tête du bloc : titre + boutons de pesée (bascule / manuelle). -->
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 class="text-[20px] font-semibold text-m-primary">{{ title }}</h2>
|
||||
<div class="flex items-center gap-8">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
icon-name="mdi:weight"
|
||||
icon-position="left"
|
||||
:label="t('logistique.weighingTickets.form.weighbridge.auto')"
|
||||
:disabled="disabled"
|
||||
@click="$emit('request-auto')"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
icon-name="mdi:weight"
|
||||
icon-position="left"
|
||||
:label="t('logistique.weighingTickets.form.weighbridge.manual')"
|
||||
:disabled="disabled"
|
||||
@click="$emit('request-manual')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex flex-col gap-4">
|
||||
<!-- Ligne 1 : contrepartie (type en col 1 + champ conditionnel en col 2),
|
||||
rendue par le parent (bloc vide uniquement) via le slot. -->
|
||||
<div v-if="$slots.counterparty" class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<slot name="counterparty" />
|
||||
</div>
|
||||
|
||||
<!-- Ligne 2 : Date, Poids, DSD, Immatriculation. -->
|
||||
<div class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<!-- Date/heure de la pesée — date du jour + heure courante par défaut
|
||||
(RG-5.07). MalioDateTime : on enregistre l'instant réel de la pesée
|
||||
(jamais 00:00:00), le back stocke un TIMESTAMP. -->
|
||||
<MalioDateTime
|
||||
:model-value="block.date"
|
||||
:label="t('logistique.weighingTickets.form.date')"
|
||||
:required="true"
|
||||
:editable="true"
|
||||
:disabled="disabled"
|
||||
:error="errors.date"
|
||||
@update:model-value="(v: string | null) => emitBlock('date', v)"
|
||||
/>
|
||||
|
||||
<!-- Poids : champ texte verrouillé sur les chiffres, toujours désactivé
|
||||
(rempli par la pesée, jamais saisi à la main — RG-5.07). Unité Kg
|
||||
dans le label. -->
|
||||
<MalioInputText
|
||||
:model-value="weightDisplay"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.weight')"
|
||||
:required="true"
|
||||
:disabled="true"
|
||||
:error="errors.weight"
|
||||
/>
|
||||
|
||||
<!-- DSD : champ texte verrouillé sur les chiffres, toujours désactivé
|
||||
(rempli par la pesée — RG-5.04 / RG-5.07). -->
|
||||
<MalioInputText
|
||||
:model-value="dsdDisplay"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.dsd')"
|
||||
:required="true"
|
||||
:disabled="true"
|
||||
:error="errors.dsd"
|
||||
/>
|
||||
|
||||
<!-- Immatriculation : masque XX-000-XX (plaque FR SIV) ; en « Tout format »,
|
||||
masque ÉLARGI (lettres/chiffres/espace/tiret, MAJ) pour les plaques
|
||||
anciennes/étrangères, mais sans laisser passer n'importe quoi.
|
||||
PARTAGÉE entre les 2 blocs (RG-5.01) — v-model remonté au form parent.
|
||||
TODO migrer le masque plaque quand @malio/layer-ui couvrira le format. -->
|
||||
<MalioInputText
|
||||
:model-value="immatriculation"
|
||||
:mask="plateFreeFormat ? FREE_PLATE_MASK : PLATE_MASK"
|
||||
:label="t('logistique.weighingTickets.form.immatriculation')"
|
||||
:required="true"
|
||||
:disabled="disabled"
|
||||
:error="errors.immatriculation"
|
||||
@update:model-value="(v: string | null) => $emit('update:immatriculation', v)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Ligne 3 : « Tout format » (désactive le masque plaque). Partagé entre
|
||||
blocs (RG-5.01). Sur sa propre ligne. -->
|
||||
<div class="grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||
<MalioCheckbox
|
||||
:id="`${blockId}-plate-free-format`"
|
||||
:model-value="plateFreeFormat"
|
||||
:label="t('logistique.weighingTickets.form.plateFreeFormat')"
|
||||
group-class="self-center"
|
||||
:disabled="disabled"
|
||||
@update:model-value="(v: boolean) => $emit('update:plateFreeFormat', v)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { WeighingBlockState } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
import { NUMERIC_MASK, PLATE_MASK, FREE_PLATE_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
|
||||
/**
|
||||
* Bloc de pesée (« Poids à vide » ou « Poids à plein ») de l'écran Ticket de pesée.
|
||||
* Champs Date / Poids / DSD / Immatriculation / « Tout format » + boutons de pesée.
|
||||
* L'immatriculation et « Tout format » sont PARTAGÉS entre les 2 blocs (RG-5.01) :
|
||||
* portés par le form parent et remontés en `update:*`. Le slot `counterparty`
|
||||
* permet au parent d'injecter la contrepartie sur le seul bloc vide (RG-5.03).
|
||||
* Masques de saisie factorisés dans `utils/weighingMasks`.
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
/** Identifiant technique du bloc (pour les `id` de champs uniques). */
|
||||
blockId: string
|
||||
title: string
|
||||
block: WeighingBlockState
|
||||
/** Immatriculation partagée (RG-5.01) — portée par le form parent. */
|
||||
immatriculation: string | null
|
||||
/** « Tout format » partagé (RG-5.01) — porté par le form parent. */
|
||||
plateFreeFormat: boolean
|
||||
/** Erreurs 422 par champ (propertyPath → message). */
|
||||
errors?: Record<string, string>
|
||||
disabled?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:block': [field: keyof WeighingBlockState, value: unknown]
|
||||
'update:immatriculation': [value: string | null]
|
||||
'update:plateFreeFormat': [value: boolean]
|
||||
'request-auto': []
|
||||
'request-manual': []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const errors = computed(() => props.errors ?? {})
|
||||
|
||||
// Poids / DSD : champs texte → on présente l'entier sous forme de chaîne (vide
|
||||
// tant que la pesée n'a pas rempli la valeur).
|
||||
const weightDisplay = computed(() => (props.block.weight === null ? '' : String(props.block.weight)))
|
||||
const dsdDisplay = computed(() => (props.block.dsd === null ? '' : String(props.block.dsd)))
|
||||
|
||||
/** Remonte la mutation d'un champ du bloc au parent (état des pesées centralisé). */
|
||||
function emitBlock(field: keyof WeighingBlockState, value: unknown): void {
|
||||
emit('update:block', field, value)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
// useApi / useI18n sont des auto-imports Nuxt : on les expose en globals.
|
||||
const mockPost = vi.hoisted(() => vi.fn())
|
||||
vi.stubGlobal('useApi', () => ({ post: mockPost }))
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
|
||||
const { useWeighbridge } = await import('../useWeighbridge')
|
||||
|
||||
describe('useWeighbridge', () => {
|
||||
beforeEach(() => {
|
||||
mockPost.mockReset()
|
||||
})
|
||||
|
||||
it('AUTO : POST { mode: AUTO } sans toast et renvoie la lecture', async () => {
|
||||
mockPost.mockResolvedValue({ weight: 23187, dsd: 42, mode: 'AUTO' })
|
||||
const { triggerAuto } = useWeighbridge()
|
||||
|
||||
const reading = await triggerAuto()
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith(
|
||||
'/weighbridge_readings',
|
||||
{ mode: 'AUTO' },
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
expect(reading).toEqual({ weight: 23187, dsd: 42, mode: 'AUTO' })
|
||||
})
|
||||
|
||||
it('MANUAL : POST { mode: MANUAL, weight, manualNumber } et renvoie la lecture', async () => {
|
||||
mockPost.mockResolvedValue({ weight: 5000, dsd: 43, manualNumber: 'PAP-555', mode: 'MANUAL' })
|
||||
const { triggerManual } = useWeighbridge()
|
||||
|
||||
const reading = await triggerManual(5000, 'PAP-555')
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith(
|
||||
'/weighbridge_readings',
|
||||
{ mode: 'MANUAL', weight: 5000, manualNumber: 'PAP-555' },
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
expect(reading.dsd).toBe(43)
|
||||
})
|
||||
|
||||
it('erreur (RG-5.06) : extractWeighbridgeError privilégie le detail du 503', () => {
|
||||
const { extractWeighbridgeError } = useWeighbridge()
|
||||
const error = { response: { status: 503, _data: { title: 'Pont bascule indisponible', detail: 'Passez en pesée manuelle.' } } }
|
||||
expect(extractWeighbridgeError(error)).toBe('Passez en pesée manuelle.')
|
||||
})
|
||||
|
||||
it('erreur sans payload exploitable : retombe sur le libellé i18n générique', () => {
|
||||
const { extractWeighbridgeError } = useWeighbridge()
|
||||
expect(extractWeighbridgeError(new Error('network')))
|
||||
.toBe('logistique.weighingTickets.form.weighbridge.unavailable')
|
||||
})
|
||||
|
||||
it('triggerAuto propage l\'erreur API (gestion par l\'écran)', async () => {
|
||||
mockPost.mockRejectedValue({ response: { status: 503 } })
|
||||
const { triggerAuto } = useWeighbridge()
|
||||
await expect(triggerAuto()).rejects.toBeDefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,195 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
|
||||
// `nowIsoDateTime` est importé par le composable : on le stubbe pour un instant déterministe.
|
||||
vi.mock('~/shared/utils/date', () => ({ nowIsoDateTime: () => '2026-06-22T08:30:00' }))
|
||||
|
||||
const { useWeighingTicketForm } = await import('../useWeighingTicketForm')
|
||||
|
||||
describe('useWeighingTicketForm', () => {
|
||||
it('initialise les 2 blocs à la date/heure courante (RG-5.07), sans poids ni DSD', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
expect(form.empty.date).toBe('2026-06-22T08:30:00')
|
||||
expect(form.full.date).toBe('2026-06-22T08:30:00')
|
||||
expect(form.empty.weight).toBeNull()
|
||||
expect(form.empty.dsd).toBeNull()
|
||||
expect(form.counterpartyType.value).toBeNull()
|
||||
})
|
||||
|
||||
// ── Omission des requis vides (compact) ──────────────────────────────────
|
||||
it('buildCreatePayload omet les clés null (requis vides absents, pas envoyés à null)', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
// Formulaire vierge : counterpartyType / immatriculation non remplis.
|
||||
const payload = form.buildCreatePayload()
|
||||
// Absents (et non null) → le back applique NotBlank (message métier) plutôt
|
||||
// qu'une erreur de type opaque (« doit être de type string »).
|
||||
expect(payload).not.toHaveProperty('counterpartyType')
|
||||
expect(payload).not.toHaveProperty('immatriculation')
|
||||
expect(payload).not.toHaveProperty('emptyWeight')
|
||||
// Les non-null restent : date/heure courante + booléen Tout format.
|
||||
expect(payload.emptyDate).toBe('2026-06-22T08:30:00')
|
||||
expect(payload.plateFreeFormat).toBe(false)
|
||||
})
|
||||
|
||||
// ── Pesée obligatoire front-only (RG-5.07) ───────────────────────────────
|
||||
it('missingWeighingFields liste Poids/DSD manquants, puis vide après pesée', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
expect(form.missingWeighingFields('empty')).toEqual(['emptyWeight', 'emptyDsd'])
|
||||
expect(form.missingWeighingFields('full')).toEqual(['fullWeight', 'fullDsd'])
|
||||
|
||||
form.applyReading(form.empty, { weight: 7150, dsd: 1, mode: 'AUTO' })
|
||||
expect(form.missingWeighingFields('empty')).toEqual([])
|
||||
})
|
||||
|
||||
// ── Contrepartie conditionnelle (RG-5.03) ────────────────────────────────
|
||||
it('CLIENT : ne conserve que le client, purge supplier et otherLabel', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.supplierIri.value = '/api/suppliers/3'
|
||||
form.otherLabel.value = 'Particulier'
|
||||
|
||||
form.setCounterpartyType('CLIENT')
|
||||
form.clientIri.value = '/api/clients/629'
|
||||
|
||||
expect(form.counterpartyField.value).toBe('client')
|
||||
expect(form.supplierIri.value).toBeNull()
|
||||
expect(form.otherLabel.value).toBeNull()
|
||||
|
||||
const payload = form.buildCreatePayload()
|
||||
expect(payload.counterpartyType).toBe('CLIENT')
|
||||
expect(payload.client).toBe('/api/clients/629')
|
||||
expect(payload).not.toHaveProperty('supplier')
|
||||
expect(payload).not.toHaveProperty('otherLabel')
|
||||
})
|
||||
|
||||
it('FOURNISSEUR : ne conserve que le supplier', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.clientIri.value = '/api/clients/1'
|
||||
form.setCounterpartyType('FOURNISSEUR')
|
||||
form.supplierIri.value = '/api/suppliers/7'
|
||||
|
||||
expect(form.counterpartyField.value).toBe('supplier')
|
||||
expect(form.clientIri.value).toBeNull()
|
||||
expect(form.buildCreatePayload().supplier).toBe('/api/suppliers/7')
|
||||
})
|
||||
|
||||
it('AUTRE : ne conserve que le libellé libre', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.clientIri.value = '/api/clients/1'
|
||||
form.setCounterpartyType('AUTRE')
|
||||
form.otherLabel.value = 'Reprise interne'
|
||||
|
||||
expect(form.counterpartyField.value).toBe('other')
|
||||
expect(form.clientIri.value).toBeNull()
|
||||
expect(form.buildCreatePayload().otherLabel).toBe('Reprise interne')
|
||||
})
|
||||
|
||||
// ── Immatriculation / « Tout format » partagés entre blocs (RG-5.01) ──────
|
||||
it('immatriculation et plateFreeFormat sont partagés (une seule valeur)', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.immatriculation.value = 'AB-123-CD'
|
||||
form.plateFreeFormat.value = true
|
||||
|
||||
// Les 2 payloads (création + finalisation) reflètent la même valeur.
|
||||
expect(form.buildCreatePayload().immatriculation).toBe('AB-123-CD')
|
||||
expect(form.buildCreatePayload().plateFreeFormat).toBe(true)
|
||||
expect(form.buildFullPayload().immatriculation).toBe('AB-123-CD')
|
||||
expect(form.buildFullPayload().plateFreeFormat).toBe(true)
|
||||
})
|
||||
|
||||
// ── Application d'une lecture de pesée ────────────────────────────────────
|
||||
it('applyReading remplit poids / DSD / mode et ré-horodate le bloc à l\'instant de la pesée', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
// Date périmée (ouverture du formulaire bien avant la pesée).
|
||||
form.empty.date = '2020-01-01T00:00:00'
|
||||
form.applyReading(form.empty, { weight: 7150, dsd: 1, mode: 'AUTO' })
|
||||
// La pesée validée ré-horodate le bloc à maintenant (stub 2026-06-22T08:30:00).
|
||||
expect(form.empty.date).toBe('2026-06-22T08:30:00')
|
||||
expect(form.empty.weight).toBe(7150)
|
||||
expect(form.empty.dsd).toBe(1)
|
||||
expect(form.empty.mode).toBe('AUTO')
|
||||
expect(form.empty.manualNumber).toBeNull()
|
||||
|
||||
form.applyReading(form.full, { weight: 14300, dsd: 2, mode: 'MANUAL', manualNumber: 'PAP-555' })
|
||||
expect(form.full.weight).toBe(14300)
|
||||
expect(form.full.manualNumber).toBe('PAP-555')
|
||||
})
|
||||
|
||||
it('buildCreatePayload porte la pesée à vide, buildFullPayload la pesée à plein', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.setCounterpartyType('CLIENT')
|
||||
form.clientIri.value = '/api/clients/1'
|
||||
form.applyReading(form.empty, { weight: 7150, dsd: 1, mode: 'AUTO' })
|
||||
form.applyReading(form.full, { weight: 14300, dsd: 2, mode: 'AUTO' })
|
||||
|
||||
const create = form.buildCreatePayload()
|
||||
expect(create.emptyWeight).toBe(7150)
|
||||
expect(create.emptyDsd).toBe(1)
|
||||
expect(create.emptyMode).toBe('AUTO')
|
||||
expect(create).not.toHaveProperty('fullWeight')
|
||||
|
||||
const full = form.buildFullPayload()
|
||||
expect(full.fullWeight).toBe(14300)
|
||||
expect(full.fullDsd).toBe(2)
|
||||
expect(full.fullMode).toBe('AUTO')
|
||||
})
|
||||
|
||||
// ── Pré-remplissage (écran Modification, ERP-190) ─────────────────────────
|
||||
it('hydrate pré-remplit l\'état depuis le détail (datetime ISO ramené en local, heure conservée)', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.hydrate({
|
||||
id: 9,
|
||||
counterpartyType: 'CLIENT',
|
||||
client: { '@id': '/api/clients/629' },
|
||||
immatriculation: 'AB-123-CD',
|
||||
plateFreeFormat: false,
|
||||
emptyDate: '2026-06-17T09:00:00+02:00',
|
||||
emptyWeight: 7150,
|
||||
emptyDsd: 1,
|
||||
emptyMode: 'AUTO',
|
||||
fullDate: '2026-06-17T09:12:00+02:00',
|
||||
fullWeight: 14300,
|
||||
fullDsd: 2,
|
||||
fullMode: 'AUTO',
|
||||
})
|
||||
|
||||
expect(form.ticketId.value).toBe(9)
|
||||
expect(form.counterpartyType.value).toBe('CLIENT')
|
||||
expect(form.counterpartyField.value).toBe('client')
|
||||
expect(form.clientIri.value).toBe('/api/clients/629')
|
||||
expect(form.immatriculation.value).toBe('AB-123-CD')
|
||||
// Datetime back (avec fuseau) -> local sans fuseau, heure conservée pour MalioDateTime.
|
||||
expect(form.empty.date).toBe('2026-06-17T09:00:00')
|
||||
expect(form.full.date).toBe('2026-06-17T09:12:00')
|
||||
expect(form.empty.weight).toBe(7150)
|
||||
expect(form.full.weight).toBe(14300)
|
||||
})
|
||||
|
||||
it('hydrate gère les champs null omis (skip_null_values) avec des défauts', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.hydrate({ id: 5, counterpartyType: 'AUTRE', otherLabel: 'Reprise' })
|
||||
expect(form.otherLabel.value).toBe('Reprise')
|
||||
expect(form.supplierIri.value).toBeNull()
|
||||
expect(form.plateFreeFormat.value).toBe(false)
|
||||
// Pas de date back -> repli sur l'instant courant (stub 2026-06-22T08:30:00).
|
||||
expect(form.empty.date).toBe('2026-06-22T08:30:00')
|
||||
expect(form.empty.weight).toBeNull()
|
||||
})
|
||||
|
||||
it('buildUpdatePayload fusionne contrepartie + véhicule + les 2 pesées', () => {
|
||||
const form = useWeighingTicketForm()
|
||||
form.hydrate({
|
||||
id: 9,
|
||||
counterpartyType: 'CLIENT',
|
||||
client: { '@id': '/api/clients/629' },
|
||||
immatriculation: 'AB-123-CD',
|
||||
emptyWeight: 7150, emptyDsd: 1, emptyMode: 'AUTO',
|
||||
fullWeight: 14300, fullDsd: 2, fullMode: 'AUTO',
|
||||
})
|
||||
|
||||
const payload = form.buildUpdatePayload()
|
||||
expect(payload.counterpartyType).toBe('CLIENT')
|
||||
expect(payload.client).toBe('/api/clients/629')
|
||||
expect(payload.emptyWeight).toBe(7150)
|
||||
expect(payload.fullWeight).toBe(14300)
|
||||
expect(payload.immatriculation).toBe('AB-123-CD')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Pesée au pont bascule (M5, ERP-189) — déclenche une lecture de poids via
|
||||
* `POST /api/weighbridge_readings` (spec-back § 4.2). Action autonome : le ticket
|
||||
* n'existe pas encore quand on pèse depuis le formulaire principal.
|
||||
*
|
||||
* Deux modes :
|
||||
* - AUTO (« Pesée bascule ») : le serveur résout le site courant, lit le poids
|
||||
* (stub aléatoire au M5) et alloue le DSD. Peut échouer (RG-5.06 → 503) : le
|
||||
* pont est indisponible, on invite l'utilisateur à passer en pesée manuelle.
|
||||
* - MANUAL (« Pesée manuelle ») : poids + numéro de pesée saisis ; le serveur
|
||||
* calcule le DSD = dernier + 1 (RG-5.04).
|
||||
*
|
||||
* Composable UI-agnostique : il appelle l'API (`useApi`, jamais `$fetch`) et
|
||||
* renvoie la lecture, ou lève l'erreur — la gestion de la modal/de l'affichage
|
||||
* reste à la charge de l'écran. `extractWeighbridgeError` factorise la lecture
|
||||
* du message d'erreur 503 (RG-5.06) pour l'afficher dans la modal.
|
||||
*/
|
||||
|
||||
/** Mode de pesée — miroir de l'enum back. */
|
||||
export type WeighbridgeMode = 'AUTO' | 'MANUAL'
|
||||
|
||||
/** Lecture renvoyée par le pont bascule (spec-back § 4.2). */
|
||||
export interface WeighbridgeReading {
|
||||
weight: number
|
||||
dsd: number
|
||||
mode: WeighbridgeMode
|
||||
/** Numéro de pesée saisi en mode MANUAL (absent en AUTO). */
|
||||
manualNumber?: string
|
||||
}
|
||||
|
||||
export function useWeighbridge() {
|
||||
const api = useApi()
|
||||
const { t } = useI18n()
|
||||
|
||||
/**
|
||||
* Pesée bascule (AUTO). Le site courant est résolu serveur — rien à envoyer.
|
||||
* `toast: false` : l'erreur (RG-5.06) est affichée inline dans la modal, pas
|
||||
* en toast global.
|
||||
*/
|
||||
async function triggerAuto(): Promise<WeighbridgeReading> {
|
||||
return await api.post<WeighbridgeReading>(
|
||||
'/weighbridge_readings',
|
||||
{ mode: 'AUTO' },
|
||||
{ toast: false },
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Pesée manuelle (MANUAL). Le DSD est calculé serveur (dernier + 1, RG-5.04) ;
|
||||
* le `manualNumber` est la référence du ticket papier / autre bascule.
|
||||
*/
|
||||
async function triggerManual(weight: number, manualNumber: string): Promise<WeighbridgeReading> {
|
||||
return await api.post<WeighbridgeReading>(
|
||||
'/weighbridge_readings',
|
||||
{ mode: 'MANUAL', weight, manualNumber },
|
||||
{ toast: false },
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Message d'erreur de pesée bascule (RG-5.06). Le back renvoie un 503
|
||||
* `{ title, detail }` (« Pont bascule indisponible » / « Passez en pesée
|
||||
* manuelle. ») — on privilégie le `detail`, puis le `title`, sinon un libellé
|
||||
* générique invitant à la pesée manuelle.
|
||||
*/
|
||||
function extractWeighbridgeError(error: unknown): string {
|
||||
const data = (error as { response?: { _data?: unknown } })?.response?._data as
|
||||
| { detail?: string, title?: string }
|
||||
| undefined
|
||||
return data?.detail || data?.title || t('logistique.weighingTickets.form.weighbridge.unavailable')
|
||||
}
|
||||
|
||||
return { triggerAuto, triggerManual, extractWeighbridgeError }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { WeighbridgeMode } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import type { CounterpartyType } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
|
||||
/**
|
||||
* Détail d'un ticket de pesée (`GET /api/weighing_tickets/{id}`, spec-back
|
||||
* § 4.0.bis). Champs null OMIS du JSON (`skip_null_values`) → tous optionnels,
|
||||
* lus avec un défaut côté hydratation du formulaire.
|
||||
*/
|
||||
export interface WeighingTicketDetail {
|
||||
id: number
|
||||
/** Numéro `{siteCode}-TP-{NNNN}` — immuable (RG-5.09). */
|
||||
number: string
|
||||
/** Site rattaché (embarqué) — immuable (RG-5.09). */
|
||||
site?: { id: number, name: string, code: string } | null
|
||||
counterpartyType: CounterpartyType
|
||||
client?: { '@id': string, companyName: string } | null
|
||||
supplier?: { '@id': string, companyName: string } | null
|
||||
otherLabel?: string | null
|
||||
immatriculation?: string | null
|
||||
plateFreeFormat?: boolean
|
||||
// Pesée à vide
|
||||
emptyDate?: string | null
|
||||
emptyWeight?: number | null
|
||||
emptyDsd?: number | null
|
||||
emptyMode?: WeighbridgeMode | null
|
||||
emptyManualNumber?: string | null
|
||||
// Pesée à plein
|
||||
fullDate?: string | null
|
||||
fullWeight?: number | null
|
||||
fullDsd?: number | null
|
||||
fullMode?: WeighbridgeMode | null
|
||||
fullManualNumber?: string | null
|
||||
netWeight?: number | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge le détail d'un ticket de pesée pour l'écran de modification (M5,
|
||||
* ERP-190). `Accept: application/ld+json` impose l'enveloppe Hydra (relations
|
||||
* embarquées : client/supplier/site). Appel via `useApi()` (jamais `$fetch`).
|
||||
*/
|
||||
export function useWeighingTicket() {
|
||||
const api = useApi()
|
||||
|
||||
async function fetchTicket(id: number | string): Promise<WeighingTicketDetail> {
|
||||
return await api.get<WeighingTicketDetail>(
|
||||
`/weighing_tickets/${id}`,
|
||||
{},
|
||||
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||
)
|
||||
}
|
||||
|
||||
return { fetchTicket }
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { nowIsoDateTime } from '~/shared/utils/date'
|
||||
import type { WeighbridgeMode } from '~/modules/logistique/composables/useWeighbridge'
|
||||
|
||||
/**
|
||||
* État et logique du formulaire « Ajouter / Modifier un ticket de pesée » (M5,
|
||||
* ERP-189). L'écran est composé de DEUX blocs empilés — pesée à vide puis pesée
|
||||
* à plein — qui partagent un même véhicule.
|
||||
*
|
||||
* Points clés (spec-front § Écran Ajouter, spec-back § 2.4 / 2.9 / 2.10) :
|
||||
* - **Contrepartie conditionnelle (RG-5.03)** : `counterpartyType` (CLIENT /
|
||||
* FOURNISSEUR / AUTRE) pilote le champ requis (client / supplier / otherLabel).
|
||||
* Changer de type purge les champs des autres types — aucune donnée fantôme.
|
||||
* - **Immatriculation + « Tout format » partagés entre les 2 blocs (RG-5.01)** :
|
||||
* une seule valeur (refs uniques) — modifier l'un met à jour l'autre puisque
|
||||
* les 2 blocs bindent la même ref.
|
||||
* - **Workflow 2 temps** : `buildCreatePayload()` (POST à l'« Enregistrer » du
|
||||
* bloc vide) crée le ticket avec la pesée à vide ; `buildFullPayload()` (PATCH
|
||||
* au « Valider ») ajoute la pesée à plein (net recalculé serveur, RG-5.05).
|
||||
*
|
||||
* Composable UI-agnostique et testable : aucune dépendance API ici (les appels
|
||||
* vivent dans l'écran via `useApi`). Instancié PAR écran (refs locales).
|
||||
*/
|
||||
|
||||
/** Type de contrepartie — miroir de l'enum back (spec-back § 2.9). */
|
||||
export type CounterpartyType = 'CLIENT' | 'FOURNISSEUR' | 'AUTRE'
|
||||
|
||||
/** Saisie d'une pesée (bloc vide OU bloc plein). */
|
||||
export interface WeighingBlockState {
|
||||
/** Date/heure de la pesée (ISO local `YYYY-MM-DDTHH:mm:ss`) — date du jour + heure courante par défaut (RG-5.07). */
|
||||
date: string | null
|
||||
/** Poids en kg — readonly, rempli par la pesée (bascule ou manuelle). */
|
||||
weight: number | null
|
||||
/** DSD — readonly, rempli par la pesée (RG-5.04). */
|
||||
dsd: number | null
|
||||
/** Mode de la dernière pesée appliquée au bloc. */
|
||||
mode: WeighbridgeMode | null
|
||||
/** Numéro de pesée (rempli uniquement en pesée manuelle). */
|
||||
manualNumber: string | null
|
||||
}
|
||||
|
||||
/** Forme minimale d'un détail de ticket consommée par `hydrate` (cf. useWeighingTicket). */
|
||||
export interface WeighingTicketHydration {
|
||||
id: number
|
||||
counterpartyType: CounterpartyType
|
||||
client?: { '@id': string } | null
|
||||
supplier?: { '@id': string } | null
|
||||
otherLabel?: string | null
|
||||
immatriculation?: string | null
|
||||
plateFreeFormat?: boolean
|
||||
emptyDate?: string | null
|
||||
emptyWeight?: number | null
|
||||
emptyDsd?: number | null
|
||||
emptyMode?: WeighbridgeMode | null
|
||||
emptyManualNumber?: string | null
|
||||
fullDate?: string | null
|
||||
fullWeight?: number | null
|
||||
fullDsd?: number | null
|
||||
fullMode?: WeighbridgeMode | null
|
||||
fullManualNumber?: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Ramène une chaîne ISO datetime du back (`2026-06-17T09:00:00+02:00`) au format
|
||||
* local `YYYY-MM-DDTHH:mm:ss` attendu par MalioDateTime (secondes, sans fuseau) :
|
||||
* on garde les 19 premiers caractères (date + heure), on retire l'offset. Null si
|
||||
* absente.
|
||||
*/
|
||||
function toLocalIsoDateTime(value: string | null | undefined): string | null {
|
||||
return value ? value.slice(0, 19) : null
|
||||
}
|
||||
|
||||
/**
|
||||
* Retire les clés à valeur `null` d'un payload (pattern « omission des requis
|
||||
* vides » M1). Avec `collectDenormalizationErrors` côté back, envoyer `null` sur
|
||||
* un scalaire requis (ex. `counterpartyType`) produit une violation de TYPE
|
||||
* opaque (« Cette valeur doit être de type string. ») au lieu du message métier
|
||||
* `NotBlank` : une clé ABSENTE laisse au contraire jouer la contrainte `NotBlank`
|
||||
* et son message FR. On omet donc les null ; les champs réellement requis non
|
||||
* remplis déclenchent leur vrai message, les optionnels restent simplement absents.
|
||||
*/
|
||||
function compact(payload: Record<string, unknown>): Record<string, unknown> {
|
||||
return Object.fromEntries(Object.entries(payload).filter(([, value]) => value !== null))
|
||||
}
|
||||
|
||||
/** Crée l'état initial d'un bloc de pesée (date/heure = maintenant, RG-5.07). */
|
||||
function emptyBlock(now: string): WeighingBlockState {
|
||||
return {
|
||||
date: now,
|
||||
weight: null,
|
||||
dsd: null,
|
||||
mode: null,
|
||||
manualNumber: null,
|
||||
}
|
||||
}
|
||||
|
||||
export function useWeighingTicketForm() {
|
||||
const now = nowIsoDateTime()
|
||||
|
||||
// ── Contrepartie (RG-5.03) ───────────────────────────────────────────────
|
||||
const counterpartyType = ref<CounterpartyType | null>(null)
|
||||
const clientIri = ref<string | null>(null)
|
||||
const supplierIri = ref<string | null>(null)
|
||||
const otherLabel = ref<string | null>(null)
|
||||
|
||||
/**
|
||||
* Change le type de contrepartie et purge les champs devenus hors-sujet :
|
||||
* un seul de client / supplier / otherLabel est conservé selon le type
|
||||
* (RG-5.03 — pas de FK fantôme envoyée au back).
|
||||
*/
|
||||
function setCounterpartyType(type: CounterpartyType | null): void {
|
||||
counterpartyType.value = type
|
||||
if (type !== 'CLIENT') clientIri.value = null
|
||||
if (type !== 'FOURNISSEUR') supplierIri.value = null
|
||||
if (type !== 'AUTRE') otherLabel.value = null
|
||||
}
|
||||
|
||||
// ── Véhicule : partagé entre les 2 blocs (RG-5.01) ────────────────────────
|
||||
// Refs UNIQUES : les 2 blocs bindent la même valeur → connexion automatique.
|
||||
const immatriculation = ref<string | null>(null)
|
||||
const plateFreeFormat = ref<boolean>(false)
|
||||
|
||||
// ── Les deux pesées ───────────────────────────────────────────────────────
|
||||
const empty = reactive<WeighingBlockState>(emptyBlock(now))
|
||||
const full = reactive<WeighingBlockState>(emptyBlock(now))
|
||||
|
||||
// Id du ticket créé (POST du bloc vide) — pilote le PATCH du bloc plein.
|
||||
const ticketId = ref<number | null>(null)
|
||||
|
||||
/**
|
||||
* Champ de contrepartie attendu selon le type courant — utilisé par l'écran
|
||||
* pour afficher conditionnellement le bon champ (RG-5.03).
|
||||
*/
|
||||
const counterpartyField = computed<'client' | 'supplier' | 'other' | null>(() => {
|
||||
switch (counterpartyType.value) {
|
||||
case 'CLIENT': return 'client'
|
||||
case 'FOURNISSEUR': return 'supplier'
|
||||
case 'AUTRE': return 'other'
|
||||
default: return null
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Champs de pesée manquants d'un bloc (Poids / DSD), RG-5.07. Le back rend ces
|
||||
* colonnes nullable (workflow 2 temps) : l'obligation « une pesée a été
|
||||
* effectuée » est donc portée côté front (règle front-only, ERP-101). Renvoie
|
||||
* les `propertyPath` manquants (ex. `['emptyWeight', 'emptyDsd']`), prêts à
|
||||
* être posés en erreur inline via `useFormErrors.setError`.
|
||||
*/
|
||||
function missingWeighingFields(which: 'empty' | 'full'): string[] {
|
||||
const block = which === 'empty' ? empty : full
|
||||
const missing: string[] = []
|
||||
if (block.weight === null) missing.push(`${which}Weight`)
|
||||
if (block.dsd === null) missing.push(`${which}Dsd`)
|
||||
return missing
|
||||
}
|
||||
|
||||
/**
|
||||
* Applique une lecture de pesée (bascule/manuelle) à un bloc. La pesée étant
|
||||
* effectuée À CET INSTANT, on (ré)horodate le bloc à maintenant : la date/heure
|
||||
* du ticket reflète le moment réel de la pesée validée, pas l'ouverture du
|
||||
* formulaire (RG-5.07).
|
||||
*/
|
||||
function applyReading(
|
||||
block: WeighingBlockState,
|
||||
reading: { weight: number, dsd: number, mode: WeighbridgeMode, manualNumber?: string },
|
||||
): void {
|
||||
block.date = nowIsoDateTime()
|
||||
block.weight = reading.weight
|
||||
block.dsd = reading.dsd
|
||||
block.mode = reading.mode
|
||||
block.manualNumber = reading.manualNumber ?? null
|
||||
}
|
||||
|
||||
/** Partie « contrepartie » du payload (FK en IRI ou libellé libre). */
|
||||
function counterpartyPayload(): Record<string, unknown> {
|
||||
switch (counterpartyType.value) {
|
||||
case 'CLIENT': return { client: clientIri.value }
|
||||
case 'FOURNISSEUR': return { supplier: supplierIri.value }
|
||||
case 'AUTRE': return { otherLabel: otherLabel.value || null }
|
||||
default: return {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload de CRÉATION (POST /weighing_tickets, spec-back § 4.3) : contrepartie
|
||||
* + véhicule + pesée à VIDE. Le numéro, le site et le net sont attribués
|
||||
* serveur (rien à envoyer). Les noms de champs miroir des `propertyPath` back
|
||||
* pour que `useFormErrors` mappe les 422 inline.
|
||||
*/
|
||||
function buildCreatePayload(): Record<string, unknown> {
|
||||
return compact({
|
||||
counterpartyType: counterpartyType.value,
|
||||
...counterpartyPayload(),
|
||||
immatriculation: immatriculation.value || null,
|
||||
plateFreeFormat: plateFreeFormat.value,
|
||||
emptyDate: empty.date || null,
|
||||
emptyWeight: empty.weight,
|
||||
emptyDsd: empty.dsd,
|
||||
emptyMode: empty.mode,
|
||||
emptyManualNumber: empty.manualNumber || null,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Pré-remplit le formulaire à partir du détail d'un ticket existant (écran
|
||||
* Modification, ERP-190). Le numéro et le site sont immuables (RG-5.09) →
|
||||
* non repris dans l'état éditable (affichés en lecture seule par l'écran).
|
||||
* Les dates ISO du back (datetime + fuseau) sont ramenées au format local
|
||||
* `YYYY-MM-DDTHH:mm:ss` attendu par MalioDateTime (heure conservée).
|
||||
*/
|
||||
function hydrate(detail: WeighingTicketHydration): void {
|
||||
ticketId.value = detail.id
|
||||
counterpartyType.value = detail.counterpartyType ?? null
|
||||
clientIri.value = detail.client?.['@id'] ?? null
|
||||
supplierIri.value = detail.supplier?.['@id'] ?? null
|
||||
otherLabel.value = detail.otherLabel ?? null
|
||||
immatriculation.value = detail.immatriculation ?? null
|
||||
plateFreeFormat.value = detail.plateFreeFormat ?? false
|
||||
|
||||
empty.date = toLocalIsoDateTime(detail.emptyDate) ?? now
|
||||
empty.weight = detail.emptyWeight ?? null
|
||||
empty.dsd = detail.emptyDsd ?? null
|
||||
empty.mode = detail.emptyMode ?? null
|
||||
empty.manualNumber = detail.emptyManualNumber ?? null
|
||||
|
||||
full.date = toLocalIsoDateTime(detail.fullDate) ?? now
|
||||
full.weight = detail.fullWeight ?? null
|
||||
full.dsd = detail.fullDsd ?? null
|
||||
full.mode = detail.fullMode ?? null
|
||||
full.manualNumber = detail.fullManualNumber ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload de MODIFICATION (PATCH /weighing_tickets/{id}, ERP-190) : tous les
|
||||
* champs éditables (contrepartie + véhicule + les 2 pesées). Le numéro et le
|
||||
* site sont immuables (RG-5.09, ignorés par le back même si envoyés). Le net
|
||||
* est recalculé serveur (RG-5.05).
|
||||
*/
|
||||
function buildUpdatePayload(): Record<string, unknown> {
|
||||
return { ...buildCreatePayload(), ...buildFullPayload() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload de FINALISATION (PATCH /weighing_tickets/{id}, spec-back § 4.4) :
|
||||
* pesée à PLEIN. Le véhicule (immat / tout format) peut avoir été ajusté entre
|
||||
* les 2 blocs → on le repousse aussi (valeur partagée, RG-5.01). Le net est
|
||||
* recalculé serveur (RG-5.05).
|
||||
*/
|
||||
function buildFullPayload(): Record<string, unknown> {
|
||||
return compact({
|
||||
immatriculation: immatriculation.value || null,
|
||||
plateFreeFormat: plateFreeFormat.value,
|
||||
fullDate: full.date || null,
|
||||
fullWeight: full.weight,
|
||||
fullDsd: full.dsd,
|
||||
fullMode: full.mode,
|
||||
fullManualNumber: full.manualNumber || null,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
// contrepartie
|
||||
counterpartyType,
|
||||
counterpartyField,
|
||||
clientIri,
|
||||
supplierIri,
|
||||
otherLabel,
|
||||
setCounterpartyType,
|
||||
// véhicule partagé
|
||||
immatriculation,
|
||||
plateFreeFormat,
|
||||
// pesées
|
||||
empty,
|
||||
full,
|
||||
applyReading,
|
||||
missingWeighingFields,
|
||||
// workflow
|
||||
ticketId,
|
||||
hydrate,
|
||||
buildCreatePayload,
|
||||
buildFullPayload,
|
||||
buildUpdatePayload,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
/**
|
||||
* Référentiels alimentant les selects de contrepartie de l'écran « Ticket de
|
||||
* pesée » (M5, ERP-189) : liste des clients (M1) et des fournisseurs (M2).
|
||||
*
|
||||
* Collections récupérées en entier via l'échappatoire `?pagination=false`
|
||||
* (référentiels de quelques dizaines d'entrées), avec l'en-tête
|
||||
* `Accept: application/ld+json` imposé par API Platform 4 pour obtenir
|
||||
* l'enveloppe Hydra (`member`). La valeur d'option est l'IRI Hydra (`@id`) —
|
||||
* renvoyée telle quelle dans le payload POST/PATCH (relation ManyToOne).
|
||||
*
|
||||
* Miroir de `useClientReferentials` (M1). État 100 % local à l'instance.
|
||||
*/
|
||||
|
||||
/** Option au format attendu par MalioSelect ({ label, value }). */
|
||||
export interface RefOption {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
interface PartyMember {
|
||||
'@id': string
|
||||
companyName: string
|
||||
}
|
||||
|
||||
const LD_JSON_HEADERS = { Accept: 'application/ld+json' }
|
||||
|
||||
export function useWeighingTicketReferentials() {
|
||||
const api = useApi()
|
||||
|
||||
const clients = ref<RefOption[]>([])
|
||||
const suppliers = ref<RefOption[]>([])
|
||||
|
||||
/** Récupère une collection complète (pagination désactivée) en Hydra. */
|
||||
async function fetchAll(url: string): Promise<PartyMember[]> {
|
||||
const res = await api.get<{ member?: PartyMember[] }>(
|
||||
url,
|
||||
{ pagination: 'false' },
|
||||
{ headers: LD_JSON_HEADERS, toast: false },
|
||||
)
|
||||
return res.member ?? []
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge en parallèle clients + fournisseurs (résilient : un référentiel en
|
||||
* échec — ex. 403 selon le rôle — laisse simplement son select vide sans
|
||||
* faire échouer l'autre).
|
||||
*/
|
||||
async function load(): Promise<void> {
|
||||
await Promise.allSettled([
|
||||
fetchAll('/clients').then((list) => {
|
||||
clients.value = list.map(c => ({ value: c['@id'], label: c.companyName }))
|
||||
}),
|
||||
fetchAll('/suppliers').then((list) => {
|
||||
suppliers.value = list.map(s => ({ value: s['@id'], label: s.companyName }))
|
||||
}),
|
||||
])
|
||||
}
|
||||
|
||||
return { clients, suppliers, load }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { usePaginatedList } from '~/shared/composables/usePaginatedList'
|
||||
|
||||
/**
|
||||
* Vue MINIMALE d'une contrepartie embarquee (Client M1 ou Fournisseur M2) dans la
|
||||
* LISTE des tickets de pesee. Seul `companyName` alimente les colonnes
|
||||
* « Client » / « Fournisseur » ; l'objet sort embarque (`client:read` /
|
||||
* `supplier:read`) ou est carrement absent du JSON quand null (`skip_null_values`,
|
||||
* spec-back § 4.0.bis) — d'ou le `?? null` systematique cote page.
|
||||
*/
|
||||
export interface WeighingTicketParty {
|
||||
id: number
|
||||
companyName: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Vue MINIMALE d'un ticket de pesee pour la datatable (M5, ERP-188). Volontairement
|
||||
* partielle : seuls les champs des colonnes (docx p.3) + l'id (navigation) sont
|
||||
* types. Le detail complet (pesees vide/plein, immatriculation, site, DSD) releve
|
||||
* de l'ecran Modification (ERP-190) — hors perimetre de cet ecran.
|
||||
*
|
||||
* Contrepartie mutuellement exclusive (RG-5.03) : un seul de `client` / `supplier`
|
||||
* / `otherLabel` est renseigne ; les deux autres sont omis du JSON (null).
|
||||
* `displayDate` = getter serveur `fullDate ?? emptyDate` (spec-back § 4.0).
|
||||
* `netWeight` = plein − vide en kg (RG-5.05).
|
||||
*/
|
||||
export interface WeighingTicket {
|
||||
id: number
|
||||
/** Numero metier `{siteCode}-TP-{NNNN}` attribue par site (RG-5.02). */
|
||||
number: string
|
||||
/** Embarque uniquement si contrepartie = Client (RG-5.03), sinon absent. */
|
||||
client: WeighingTicketParty | null
|
||||
/** Embarque uniquement si contrepartie = Fournisseur (RG-5.03), sinon absent. */
|
||||
supplier: WeighingTicketParty | null
|
||||
/** Libelle libre si contrepartie = Autre (RG-5.03), sinon absent. */
|
||||
otherLabel: string | null
|
||||
/** Date ISO du ticket (`fullDate ?? emptyDate`) — colonne « Date ». */
|
||||
displayDate: string | null
|
||||
/** Poids net en kg (= plein − vide, RG-5.05) — colonne « Poids ». */
|
||||
netWeight: number | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Filtres de la liste des tickets de pesee, branches sur les query params de
|
||||
* `GET /api/weighing_tickets` (spec-back § 4.1). La liste est par ailleurs
|
||||
* cloisonnee par site courant cote back (`SiteScopedQueryExtension`, § 2.3) — le
|
||||
* front n'a pas a envoyer le site.
|
||||
*/
|
||||
export interface WeighingTicketFilters {
|
||||
search?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste des tickets de pesee (M5, ERP-188) — simple enveloppe de
|
||||
* `usePaginatedList<WeighingTicket>` sur la ressource `/weighing_tickets`
|
||||
* (URL API en snake_case ; la route Nuxt reste `/weighing-tickets`). Pagination
|
||||
* serveur obligatoire (regle ABSOLUE n°13), etat 100 % local (regle ABSOLUE n°6).
|
||||
*
|
||||
* Miroir de `useCarriersRepository` (M4). Volontairement PAR INSTANCE (pas de
|
||||
* singleton) : l'etat tableau est propre a l'ecran et meurt avec lui.
|
||||
*/
|
||||
export function useWeighingTicketsRepository() {
|
||||
return usePaginatedList<WeighingTicket, WeighingTicketFilters>({ url: '/weighing_tickets' })
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { defineComponent, h, ref, reactive, Suspense } from 'vue'
|
||||
|
||||
// ── Mocks des composables modules (le form RÉEL est conservé pour vérifier le
|
||||
// pré-remplissage via hydrate). ─────────────────────────────────────────────
|
||||
const mockFetchTicket = vi.hoisted(() => vi.fn())
|
||||
const mockPatch = vi.hoisted(() => vi.fn())
|
||||
const mockPush = vi.hoisted(() => vi.fn())
|
||||
const mockOpen = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('~/modules/logistique/composables/useWeighingTicket', () => ({
|
||||
useWeighingTicket: () => ({ fetchTicket: mockFetchTicket }),
|
||||
}))
|
||||
vi.mock('~/modules/logistique/composables/useWeighingTicketReferentials', () => ({
|
||||
useWeighingTicketReferentials: () => ({ clients: ref([]), suppliers: ref([]), load: vi.fn().mockResolvedValue(undefined) }),
|
||||
}))
|
||||
vi.mock('~/modules/logistique/composables/useWeighbridge', () => ({
|
||||
useWeighbridge: () => ({ triggerAuto: vi.fn(), triggerManual: vi.fn(), extractWeighbridgeError: () => 'err' }),
|
||||
}))
|
||||
|
||||
// ── Auto-imports Nuxt stubbes globalement ───────────────────────────────────
|
||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||
vi.stubGlobal('useHead', () => undefined)
|
||||
vi.stubGlobal('useApi', () => ({ get: vi.fn(), post: vi.fn(), patch: mockPatch }))
|
||||
vi.stubGlobal('useRoute', () => ({ params: { id: '9' } }))
|
||||
vi.stubGlobal('useRouter', () => ({ push: mockPush }))
|
||||
vi.stubGlobal('usePermissions', () => ({ can: () => true }))
|
||||
vi.stubGlobal('navigateTo', vi.fn())
|
||||
vi.stubGlobal('useFormErrors', () => ({ errors: reactive({}), setError: vi.fn(), clearErrors: vi.fn(), handleApiError: vi.fn() }))
|
||||
globalThis.open = mockOpen
|
||||
|
||||
const EditPage = (await import('../weighing-tickets/[id]/edit.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 InputStub = defineComponent({
|
||||
props: { label: { type: String, default: '' }, modelValue: { default: null } },
|
||||
setup(props) {
|
||||
return () => h('input', { 'data-label': props.label, 'value': props.modelValue as string })
|
||||
},
|
||||
})
|
||||
|
||||
// WeighingBlock stubbe : rend le slot counterparty (présent sur le bloc vide).
|
||||
const BlockStub = defineComponent({
|
||||
setup(_, { slots }) { return () => h('div', { 'data-testid': 'block' }, slots.counterparty?.()) },
|
||||
})
|
||||
|
||||
const ModalStub = defineComponent({
|
||||
props: { modelValue: { type: Boolean, default: false } },
|
||||
setup(_, { slots }) { return () => h('div', {}, [slots.header?.(), slots.default?.(), slots.footer?.()]) },
|
||||
})
|
||||
|
||||
const stubs = {
|
||||
MalioButtonIcon: ButtonStub,
|
||||
MalioButton: ButtonStub,
|
||||
MalioInputText: InputStub,
|
||||
MalioInputNumber: InputStub,
|
||||
MalioSelect: InputStub,
|
||||
MalioDateTime: InputStub,
|
||||
MalioCheckbox: InputStub,
|
||||
MalioModal: ModalStub,
|
||||
WeighingBlock: BlockStub,
|
||||
}
|
||||
|
||||
// Monte la page (setup async : top-level await) via Suspense.
|
||||
async function mountPage() {
|
||||
const wrapper = mount(defineComponent({
|
||||
components: { EditPage },
|
||||
setup: () => () => h(Suspense, null, { default: () => h(EditPage) }),
|
||||
}), { global: { stubs } })
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
const DETAIL = {
|
||||
id: 9,
|
||||
number: '86-TP-0001',
|
||||
site: { id: 1, name: 'Chatellerault', code: '86' },
|
||||
counterpartyType: 'CLIENT',
|
||||
client: { '@id': '/api/clients/629', companyName: 'NÉGOCE MÉTAUX ATLANTIQUE' },
|
||||
immatriculation: 'AB-123-CD',
|
||||
plateFreeFormat: false,
|
||||
emptyDate: '2026-06-17T09:00:00+02:00', emptyWeight: 7150, emptyDsd: 1, emptyMode: 'AUTO',
|
||||
fullDate: '2026-06-17T09:12:00+02:00', fullWeight: 14300, fullDsd: 2, fullMode: 'AUTO',
|
||||
}
|
||||
|
||||
describe('Écran Modification ticket de pesée (page /weighing-tickets/{id}/edit)', () => {
|
||||
beforeEach(() => {
|
||||
mockFetchTicket.mockReset().mockResolvedValue({ ...DETAIL })
|
||||
mockPatch.mockReset().mockResolvedValue({})
|
||||
mockPush.mockReset()
|
||||
mockOpen.mockReset()
|
||||
})
|
||||
|
||||
it('charge le ticket au montage (pré-remplissage via hydrate)', async () => {
|
||||
await mountPage()
|
||||
expect(mockFetchTicket).toHaveBeenCalledWith('9')
|
||||
})
|
||||
|
||||
it('bascule des boutons : « Enregistrer » + « Imprimer » présents, pas de « Valider »', async () => {
|
||||
const wrapper = await mountPage()
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.save"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.print"]').exists()).toBe(true)
|
||||
// « Valider » est le bouton de l'écran d'AJOUT — absent en modification (RG-5.08).
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.form.validate"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('« Imprimer » ouvre le bon de pesée PDF servi par le back (RG-5.08)', async () => {
|
||||
const wrapper = await mountPage()
|
||||
await wrapper.find('[data-label="logistique.weighingTickets.form.print"]').trigger('click')
|
||||
expect(mockOpen).toHaveBeenCalledWith('/api/weighing_tickets/9/print.pdf', '_blank')
|
||||
})
|
||||
|
||||
it('« Enregistrer » PATCH le ticket puis revient à la liste', async () => {
|
||||
const wrapper = await mountPage()
|
||||
await wrapper.find('[data-label="logistique.weighingTickets.form.save"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(mockPatch).toHaveBeenCalledWith(
|
||||
'/weighing_tickets/9',
|
||||
expect.objectContaining({ counterpartyType: 'CLIENT', client: '/api/clients/629', fullWeight: 14300 }),
|
||||
expect.objectContaining({ toast: false }),
|
||||
)
|
||||
expect(mockPush).toHaveBeenCalledWith('/weighing-tickets')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,200 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { mount, flushPromises, type VueWrapper } 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 specs M1→M4.
|
||||
const mockPush = vi.hoisted(() => vi.fn())
|
||||
const mockApiGet = vi.hoisted(() => vi.fn())
|
||||
const mockCan = vi.hoisted(() => vi.fn())
|
||||
const mockFetch = vi.hoisted(() => vi.fn())
|
||||
const mockReset = 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 }))
|
||||
// Site courant (switcher global) : ref pilotable pour simuler un changement de site.
|
||||
const currentSiteRef = ref<{ id: number } | null>(null)
|
||||
vi.stubGlobal('useCurrentSite', () => ({ currentSite: currentSiteRef }))
|
||||
|
||||
// Le repository est lui aussi un auto-import : on controle les items renvoyes.
|
||||
// Contrepartie CLIENT (RG-5.03) → supplier / otherLabel absents (skip_null_values).
|
||||
vi.stubGlobal('useWeighingTicketsRepository', () => ({
|
||||
items: ref([
|
||||
{
|
||||
id: 9,
|
||||
number: '86-TP-0001',
|
||||
client: { id: 629, companyName: 'NÉGOCE MÉTAUX ATLANTIQUE' },
|
||||
supplier: null,
|
||||
otherLabel: null,
|
||||
displayDate: '2026-06-17T09:12:00+02:00',
|
||||
netWeight: 7150,
|
||||
},
|
||||
]),
|
||||
totalItems: ref(1),
|
||||
currentPage: ref(1),
|
||||
itemsPerPage: ref(10),
|
||||
itemsPerPageOptions: ref([10, 25, 50]),
|
||||
fetch: mockFetch,
|
||||
goToPage: vi.fn(),
|
||||
setItemsPerPage: vi.fn(),
|
||||
setFilters: vi.fn(),
|
||||
reset: mockReset,
|
||||
}))
|
||||
|
||||
// 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 WeighingTicketsIndex = (await import('../weighing-tickets/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)
|
||||
},
|
||||
})
|
||||
|
||||
// Capture les `items` (rows) passes par la page : on rend chaque ligne avec ses
|
||||
// cellules formatees (date / poids) pour pouvoir asserter le mapping des colonnes.
|
||||
const capturedRows = ref<Array<Record<string, unknown>>>([])
|
||||
const DataTableStub = defineComponent({
|
||||
props: { items: { type: Array, default: () => [] } },
|
||||
emits: ['row-click', 'update:page', 'update:per-page'],
|
||||
setup(props, { emit }) {
|
||||
return () => {
|
||||
capturedRows.value = props.items as Array<Record<string, unknown>>
|
||||
return h('div', { 'data-testid': 'datatable' },
|
||||
(props.items as Array<Record<string, unknown>>).map(it =>
|
||||
h('tr', { 'data-row-id': it.id as number, onClick: () => emit('row-click', it) }, [
|
||||
h('td', { 'data-cell': 'displayDate' }, it.displayDate as string),
|
||||
h('td', { 'data-cell': 'netWeight' }, it.netWeight as string),
|
||||
h('td', { 'data-cell': 'client' }, it.client as string),
|
||||
h('td', { 'data-cell': 'supplier' }, it.supplier as string),
|
||||
]),
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const PageHeaderStub = defineComponent({
|
||||
setup(_, { slots }) { return () => h('div', {}, [slots.default?.(), slots.actions?.()]) },
|
||||
})
|
||||
|
||||
// Suivi des wrappers montés pour les démonter entre tests : sans cela, les
|
||||
// watchers sur la ref module-level `currentSiteRef` (site courant) fuiteraient
|
||||
// d'un test à l'autre et se déclencheraient en double.
|
||||
const mountedWrappers: VueWrapper[] = []
|
||||
|
||||
function mountPage() {
|
||||
const wrapper = mount(WeighingTicketsIndex, {
|
||||
global: {
|
||||
stubs: {
|
||||
PageHeader: PageHeaderStub,
|
||||
MalioButton: ButtonStub,
|
||||
MalioDataTable: DataTableStub,
|
||||
},
|
||||
},
|
||||
})
|
||||
mountedWrappers.push(wrapper)
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('Liste des tickets de pesée (page /weighing-tickets)', () => {
|
||||
beforeEach(() => {
|
||||
mockPush.mockReset()
|
||||
mockApiGet.mockReset().mockResolvedValue(new Blob())
|
||||
mockCan.mockReset().mockReturnValue(true)
|
||||
mockFetch.mockReset()
|
||||
mockReset.mockReset()
|
||||
mockToastError.mockReset()
|
||||
capturedRows.value = []
|
||||
currentSiteRef.value = null
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
// Démonte les composants montés → libère leurs watchers (site courant).
|
||||
while (mountedWrappers.length > 0) {
|
||||
mountedWrappers.pop()?.unmount()
|
||||
}
|
||||
})
|
||||
|
||||
it('charge la liste au montage', async () => {
|
||||
mountPage()
|
||||
await flushPromises()
|
||||
expect(mockFetch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('recharge la liste (page 1) quand le site courant change', async () => {
|
||||
mountPage()
|
||||
await flushPromises()
|
||||
expect(mockReset).not.toHaveBeenCalled()
|
||||
|
||||
// Simule un switch de site via le switcher global.
|
||||
currentSiteRef.value = { id: 2 }
|
||||
await flushPromises()
|
||||
expect(mockReset).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('formate la date au format JJ-MM-AAAA', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-cell="displayDate"]').text()).toBe('17-06-2026')
|
||||
})
|
||||
|
||||
it('formate le poids net en kg avec separateur de milliers', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-cell="netWeight"]').text()).toBe('7 150 Kg')
|
||||
})
|
||||
|
||||
it('mappe la contrepartie Client (supplier vide car contrepartie ≠ Fournisseur)', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-cell="client"]').text()).toBe('NÉGOCE MÉTAUX ATLANTIQUE')
|
||||
expect(wrapper.find('[data-cell="supplier"]').text()).toBe('')
|
||||
})
|
||||
|
||||
it('affiche « + Ajouter » uniquement avec la permission manage', async () => {
|
||||
mockCan.mockImplementation((perm: string) => perm === 'logistique.weighing_tickets.manage')
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.add"]').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('masque « + Ajouter » sans la permission manage (view seul)', async () => {
|
||||
mockCan.mockImplementation((perm: string) => perm === 'logistique.weighing_tickets.view')
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[data-label="logistique.weighingTickets.add"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('navigue vers la modification au clic sur une ligne', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
await wrapper.find('tr[data-row-id="9"]').trigger('click')
|
||||
expect(mockPush).toHaveBeenCalledWith('/weighing-tickets/9/edit')
|
||||
})
|
||||
|
||||
it('appelle l\'export XLSX sur /weighing_tickets/export.xlsx en blob', async () => {
|
||||
const wrapper = mountPage()
|
||||
await flushPromises()
|
||||
await wrapper.find('[data-label="logistique.weighingTickets.export"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(mockApiGet).toHaveBeenCalledWith(
|
||||
'/weighing_tickets/export.xlsx',
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseType: 'blob', toast: false }),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,393 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tête : retour vers la liste + titre. -->
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
variant="ghost"
|
||||
:title="t('logistique.weighingTickets.form.back')"
|
||||
v-bind="{ ariaLabel: t('logistique.weighingTickets.form.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ headerTitle }}</h1>
|
||||
</div>
|
||||
|
||||
<!-- États de chargement / introuvable. -->
|
||||
<p v-if="loading" class="mt-12 text-center text-black/60">{{ t('logistique.weighingTickets.edit.loading') }}</p>
|
||||
<p v-else-if="error" class="mt-12 text-center text-m-danger">{{ t('logistique.weighingTickets.edit.notFound') }}</p>
|
||||
|
||||
<template v-else>
|
||||
<!-- Numéro + site : immuables (RG-5.09), rappelés dans le titre de l'écran. -->
|
||||
<div class="mt-[48px] flex flex-col gap-8">
|
||||
<!-- ── Bloc « Poids à vide » (porte la contrepartie, RG-5.03) ──── -->
|
||||
<WeighingBlock
|
||||
block-id="empty"
|
||||
:title="t('logistique.weighingTickets.form.emptyBlock')"
|
||||
:block="form.empty"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="emptyBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('empty', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('empty')"
|
||||
@request-manual="openManual('empty')"
|
||||
>
|
||||
<template #counterparty>
|
||||
<MalioSelect
|
||||
:model-value="form.counterpartyType.value"
|
||||
:options="counterpartyOptions"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.type')"
|
||||
:required="true"
|
||||
empty-option-label=""
|
||||
:error="errors.counterpartyType"
|
||||
@update:model-value="onCounterpartyTypeChange"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="form.counterpartyField.value === 'supplier'"
|
||||
:model-value="form.supplierIri.value"
|
||||
:options="referentials.suppliers.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.supplier')"
|
||||
:required="true"
|
||||
empty-option-label=""
|
||||
:error="errors.supplier"
|
||||
@update:model-value="(v: string | number | null) => form.supplierIri.value = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-else-if="form.counterpartyField.value === 'client'"
|
||||
:model-value="form.clientIri.value"
|
||||
:options="referentials.clients.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.client')"
|
||||
:required="true"
|
||||
empty-option-label=""
|
||||
:error="errors.client"
|
||||
@update:model-value="(v: string | number | null) => form.clientIri.value = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-else-if="form.counterpartyField.value === 'other'"
|
||||
:model-value="form.otherLabel.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.other')"
|
||||
:required="true"
|
||||
:error="errors.otherLabel"
|
||||
@update:model-value="(v: string | null) => form.otherLabel.value = v"
|
||||
/>
|
||||
</template>
|
||||
</WeighingBlock>
|
||||
|
||||
<!-- Bloc « Poids à plein » : le bouton « Enregistrer » du bloc vide
|
||||
DISPARAÎT en modification (RG-5.08) — on enregistre via le bas. -->
|
||||
<WeighingBlock
|
||||
block-id="full"
|
||||
:title="t('logistique.weighingTickets.form.fullBlock')"
|
||||
:block="form.full"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="fullBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('full', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('full')"
|
||||
@request-manual="openManual('full')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Bas d'écran : « Enregistrer » (remplace « Valider », RG-5.08) +
|
||||
« Imprimer » (absent à l'ajout, RG-5.08). -->
|
||||
<div class="mt-12 flex justify-center gap-6">
|
||||
<MalioButton
|
||||
variant="secondary"
|
||||
icon-name="mdi:printer-outline"
|
||||
icon-position="left"
|
||||
:label="t('logistique.weighingTickets.form.print')"
|
||||
@click="printTicket"
|
||||
/>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.save')"
|
||||
:disabled="saving"
|
||||
@click="submitSave"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ── Modal « Confirmation pesée bascule » (RG-5.06) ──────────────────-->
|
||||
<!-- La question est portée par le titre ; pas de texte de corps. Bouton
|
||||
« Valider » seul, centré (l'annulation se fait via la croix). -->
|
||||
<MalioModal v-model="autoModal.open" modal-class="max-w-md" footer-class="justify-center pb-6">
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold">{{ t('logistique.weighingTickets.form.weighbridge.confirmTitle') }}</h2>
|
||||
</template>
|
||||
<p v-if="autoModal.error" class="text-m-danger">{{ autoModal.error }}</p>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.weighbridge.validate')"
|
||||
:disabled="autoModal.loading"
|
||||
@click="confirmAuto"
|
||||
/>
|
||||
</template>
|
||||
</MalioModal>
|
||||
|
||||
<!-- ── Modal « Pesée manuelle » ────────────────────────────────────────-->
|
||||
<!-- Marges : titre UPPERCASE à 24px du haut (pt-6), 28px horizontaux (mx-7 header
|
||||
/ px-7 body+footer), bordure à 12px sous le titre (pb-3) et insérée (mx-7,
|
||||
ne touche pas les bords), formulaire à 36px sous la bordure (pt-9). -->
|
||||
<MalioModal
|
||||
v-model="manualModal.open"
|
||||
modal-class="max-w-md"
|
||||
header-class="mx-7 px-0 pt-6 pb-3 border-b border-black"
|
||||
body-class="px-7 pt-9"
|
||||
footer-class="px-7 justify-center pb-6"
|
||||
>
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold uppercase">{{ t('logistique.weighingTickets.form.manual.title') }}</h2>
|
||||
</template>
|
||||
<div class="flex flex-col gap-2">
|
||||
<!-- Poids : champ texte verrouillé sur les chiffres (comme le formulaire). -->
|
||||
<MalioInputText
|
||||
v-model="manualModal.weight"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.manual.weight')"
|
||||
:required="true"
|
||||
:error="manualModal.errors.weight"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="manualModal.manualNumber"
|
||||
:label="t('logistique.weighingTickets.form.manual.number')"
|
||||
:required="true"
|
||||
:error="manualModal.errors.manualNumber"
|
||||
/>
|
||||
</div>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.manual.save')"
|
||||
:disabled="manualModal.loading"
|
||||
@click="confirmManual"
|
||||
/>
|
||||
</template>
|
||||
</MalioModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useWeighingTicketForm, type WeighingBlockState } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
import { useWeighbridge } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import { useWeighingTicket } from '~/modules/logistique/composables/useWeighingTicket'
|
||||
import { useWeighingTicketReferentials, type RefOption } from '~/modules/logistique/composables/useWeighingTicketReferentials'
|
||||
import { NUMERIC_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { can } = usePermissions()
|
||||
|
||||
// Modification réservée à `manage` (Admin / Bureau / Usine) — sinon retour liste.
|
||||
if (!can('logistique.weighing_tickets.manage')) {
|
||||
await navigateTo('/weighing-tickets')
|
||||
}
|
||||
|
||||
const ticketId = route.params.id as string
|
||||
|
||||
const form = useWeighingTicketForm()
|
||||
const weighbridge = useWeighbridge()
|
||||
const referentials = useWeighingTicketReferentials()
|
||||
const { fetchTicket } = useWeighingTicket()
|
||||
const { errors, setError, clearErrors, handleApiError } = useFormErrors()
|
||||
|
||||
/**
|
||||
* Marque Poids/DSD manquants d'un bloc (RG-5.07). `emptyWeight` est validé côté
|
||||
* back (NotBlank → renvoyé avec les autres violations) ; `fullWeight` n'a pas
|
||||
* d'équivalent back (workflow 2 temps) et reste donc front-only. Le DSD est
|
||||
* alloué serveur → simple repère front en miroir du poids. Retourne false si une
|
||||
* pesée manque.
|
||||
*/
|
||||
function validateWeighing(which: 'empty' | 'full'): boolean {
|
||||
const missing = form.missingWeighingFields(which)
|
||||
for (const path of missing) {
|
||||
setError(path, path.endsWith('Weight')
|
||||
? t('logistique.weighingTickets.form.weightRequired')
|
||||
: t('logistique.weighingTickets.form.dsdRequired'))
|
||||
}
|
||||
return missing.length === 0
|
||||
}
|
||||
|
||||
const loading = ref(true)
|
||||
const error = ref(false)
|
||||
const saving = ref(false)
|
||||
|
||||
// Numéro immuable (RG-5.09), rappelé dans le titre de l'écran.
|
||||
const ticketNumber = ref<string>('')
|
||||
|
||||
const headerTitle = computed(() =>
|
||||
ticketNumber.value
|
||||
? t('logistique.weighingTickets.edit.title', { number: ticketNumber.value })
|
||||
: t('logistique.weighingTickets.edit.titleFallback'),
|
||||
)
|
||||
|
||||
useHead({ title: t('logistique.weighingTickets.edit.titleFallback') })
|
||||
|
||||
/** Retour vers la liste (flèche d'en-tête). */
|
||||
function goBack(): void {
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
|
||||
// ── Contrepartie (RG-5.03) ───────────────────────────────────────────────────
|
||||
const counterpartyOptions = computed<RefOption[]>(() => [
|
||||
{ value: 'FOURNISSEUR', label: t('logistique.weighingTickets.form.counterparty.supplier') },
|
||||
{ value: 'CLIENT', label: t('logistique.weighingTickets.form.counterparty.client') },
|
||||
{ value: 'AUTRE', label: t('logistique.weighingTickets.form.counterparty.other') },
|
||||
])
|
||||
|
||||
function onCounterpartyTypeChange(value: string | number | null): void {
|
||||
const type = (value === null || value === '') ? null : (String(value) as 'CLIENT' | 'FOURNISSEUR' | 'AUTRE')
|
||||
form.setCounterpartyType(type)
|
||||
}
|
||||
|
||||
// ── Erreurs par bloc (mapping propertyPath back → champs du composant) ────────
|
||||
const emptyBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.emptyDate,
|
||||
weight: errors.emptyWeight,
|
||||
dsd: errors.emptyDsd,
|
||||
immatriculation: errors.immatriculation,
|
||||
}))
|
||||
// Immatriculation volontairement ABSENTE ici : partagée entre les 2 blocs
|
||||
// (RG-5.01) mais affichée/validée sur le bloc « Poids à vide » uniquement — pas
|
||||
// de doublon d'erreur sur le bloc « Poids à plein ».
|
||||
const fullBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.fullDate,
|
||||
weight: errors.fullWeight,
|
||||
dsd: errors.fullDsd,
|
||||
}))
|
||||
|
||||
/** Mute un champ d'un bloc de pesée (état centralisé dans le form). */
|
||||
function updateBlock(target: 'empty' | 'full', field: keyof WeighingBlockState, value: unknown): void {
|
||||
(form[target] as Record<string, unknown>)[field as string] = value
|
||||
}
|
||||
|
||||
// ── Modal pesée bascule (AUTO) ────────────────────────────────────────────────
|
||||
const autoModal = reactive({
|
||||
open: false,
|
||||
error: '',
|
||||
loading: false,
|
||||
target: 'empty' as 'empty' | 'full',
|
||||
})
|
||||
|
||||
function openAuto(target: 'empty' | 'full'): void {
|
||||
autoModal.target = target
|
||||
autoModal.error = ''
|
||||
autoModal.open = true
|
||||
}
|
||||
|
||||
async function confirmAuto(): Promise<void> {
|
||||
if (autoModal.loading) return
|
||||
autoModal.loading = true
|
||||
autoModal.error = ''
|
||||
try {
|
||||
const reading = await weighbridge.triggerAuto()
|
||||
form.applyReading(form[autoModal.target], reading)
|
||||
autoModal.open = false
|
||||
}
|
||||
catch (e) {
|
||||
autoModal.error = weighbridge.extractWeighbridgeError(e)
|
||||
}
|
||||
finally {
|
||||
autoModal.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Modal pesée manuelle (MANUAL) ─────────────────────────────────────────────
|
||||
const manualModal = reactive({
|
||||
open: false,
|
||||
loading: false,
|
||||
target: 'empty' as 'empty' | 'full',
|
||||
weight: null as string | null,
|
||||
manualNumber: null as string | null,
|
||||
errors: {} as Record<string, string>,
|
||||
})
|
||||
|
||||
function openManual(target: 'empty' | 'full'): void {
|
||||
manualModal.target = target
|
||||
manualModal.weight = null
|
||||
manualModal.manualNumber = null
|
||||
manualModal.errors = {}
|
||||
manualModal.open = true
|
||||
}
|
||||
|
||||
async function confirmManual(): Promise<void> {
|
||||
if (manualModal.loading) return
|
||||
manualModal.errors = {}
|
||||
|
||||
const weight = manualModal.weight === null || manualModal.weight === '' ? null : Number(manualModal.weight)
|
||||
const manualNumber = (manualModal.manualNumber ?? '').trim()
|
||||
if (weight === null || Number.isNaN(weight)) {
|
||||
manualModal.errors = { ...manualModal.errors, weight: t('logistique.weighingTickets.form.manual.weightRequired') }
|
||||
}
|
||||
if (manualNumber === '') {
|
||||
manualModal.errors = { ...manualModal.errors, manualNumber: t('logistique.weighingTickets.form.manual.numberRequired') }
|
||||
}
|
||||
if (Object.keys(manualModal.errors).length > 0) return
|
||||
|
||||
manualModal.loading = true
|
||||
try {
|
||||
const reading = await weighbridge.triggerManual(weight as number, manualNumber)
|
||||
form.applyReading(form[manualModal.target], reading)
|
||||
manualModal.open = false
|
||||
}
|
||||
catch (e) {
|
||||
manualModal.errors = { weight: weighbridge.extractWeighbridgeError(e) }
|
||||
}
|
||||
finally {
|
||||
manualModal.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Soumission / impression ───────────────────────────────────────────────────
|
||||
/** « Enregistrer » : PATCH /weighing_tickets/{id} (recalcul net serveur, RG-5.05). */
|
||||
async function submitSave(): Promise<void> {
|
||||
if (saving.value) return
|
||||
clearErrors()
|
||||
// Vide : marqué seulement (le back garde emptyWeight et renvoie tout d'un coup).
|
||||
// Plein : bloquant côté front (pas de règle back, workflow 2 temps).
|
||||
validateWeighing('empty')
|
||||
if (!validateWeighing('full')) return
|
||||
saving.value = true
|
||||
try {
|
||||
await api.patch(`/weighing_tickets/${ticketId}`, form.buildUpdatePayload(), { toast: false })
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
catch (e) {
|
||||
handleApiError(e, { fallbackMessage: t('logistique.weighingTickets.toast.error') })
|
||||
}
|
||||
finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* « Imprimer » : ouvre le bon de pesée PDF servi par le back (Twig, ERP-192).
|
||||
* Le front ne dessine AUCUN gabarit — il ouvre seulement l'URL (RG-5.08).
|
||||
*/
|
||||
function printTicket(): void {
|
||||
window.open(`/api/weighing_tickets/${ticketId}/print.pdf`, '_blank')
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// Référentiels (selects contrepartie) en parallèle, non bloquants.
|
||||
referentials.load().catch(() => {})
|
||||
try {
|
||||
const detail = await fetchTicket(ticketId)
|
||||
ticketNumber.value = detail.number
|
||||
form.hydrate(detail)
|
||||
}
|
||||
catch {
|
||||
error.value = true
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,168 @@
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader>
|
||||
{{ t('logistique.weighingTickets.title') }}
|
||||
<template #actions>
|
||||
<MalioButton
|
||||
v-if="canManage"
|
||||
variant="secondary"
|
||||
:label="t('logistique.weighingTickets.add')"
|
||||
icon-name="mdi:add-bold"
|
||||
icon-position="left"
|
||||
@click="goToCreate"
|
||||
/>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<!-- Datatable branchee sur usePaginatedList via useWeighingTicketsRepository :
|
||||
pagination serveur (defaut 10), tri number DESC par defaut (cote back),
|
||||
liste cloisonnee par site courant (spec-back § 2.3). Etat 100 % local
|
||||
(regle ABSOLUE n°6). -->
|
||||
<MalioDataTable
|
||||
:columns="columns"
|
||||
:items="rows"
|
||||
:total-items="totalItems"
|
||||
:page="currentPage"
|
||||
:per-page="itemsPerPage"
|
||||
:per-page-options="itemsPerPageOptions"
|
||||
row-clickable
|
||||
:empty-message="t('logistique.weighingTickets.empty')"
|
||||
@row-click="onRowClick"
|
||||
@update:page="goToPage"
|
||||
@update:per-page="setItemsPerPage"
|
||||
/>
|
||||
|
||||
<div class="flex justify-center mt-4">
|
||||
<MalioButton
|
||||
v-if="canView"
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.export')"
|
||||
:disabled="exporting"
|
||||
@click="exportXlsx"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { formatDateFr, formatWeightKg } from '~/modules/logistique/utils/weighingTicketFormat'
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const router = useRouter()
|
||||
const toast = useToast()
|
||||
const { can } = usePermissions()
|
||||
// Site courant (switcher global) : la liste est cloisonnée par site côté back
|
||||
// (spec-back § 2.3). Le front n'envoie PAS le site (résolu serveur) — il se
|
||||
// contente de recharger quand le site change pour refléter le bon périmètre.
|
||||
const { currentSite } = useCurrentSite()
|
||||
|
||||
useHead({ title: t('logistique.weighingTickets.title') })
|
||||
|
||||
// Bouton « + Ajouter » reserve a `manage` (Admin / Bureau / Usine). « Exporter »
|
||||
// suit `view`. Compta et Commerciale n'ont aucun acces (item sidebar masque cote
|
||||
// back) — spec-front § Acces.
|
||||
const canManage = computed(() => can('logistique.weighing_tickets.manage'))
|
||||
const canView = computed(() => can('logistique.weighing_tickets.view'))
|
||||
|
||||
const {
|
||||
items: tickets,
|
||||
totalItems,
|
||||
currentPage,
|
||||
itemsPerPage,
|
||||
itemsPerPageOptions,
|
||||
fetch: loadTickets,
|
||||
goToPage,
|
||||
setItemsPerPage,
|
||||
reset: reloadFromFirstPage,
|
||||
} = useWeighingTicketsRepository()
|
||||
|
||||
// Mappe les tickets en objets « plats » formates pour MalioDataTable (items typees
|
||||
// Record<string, unknown>[]). La contrepartie est mutuellement exclusive (RG-5.03) :
|
||||
// une seule des colonnes client / supplier / otherLabel est renseignee, les autres
|
||||
// restent vides. Date et poids sont formates ici (cf. helpers ci-dessous).
|
||||
const rows = computed(() => tickets.value.map(ticket => ({
|
||||
id: ticket.id,
|
||||
number: ticket.number,
|
||||
client: ticket.client?.companyName ?? '',
|
||||
supplier: ticket.supplier?.companyName ?? '',
|
||||
otherLabel: ticket.otherLabel ?? '',
|
||||
displayDate: formatDateFr(ticket.displayDate),
|
||||
netWeight: formatWeightKg(ticket.netWeight),
|
||||
})))
|
||||
|
||||
const columns = [
|
||||
{ key: 'number', label: t('logistique.weighingTickets.column.number') },
|
||||
{ key: 'client', label: t('logistique.weighingTickets.column.client') },
|
||||
{ key: 'supplier', label: t('logistique.weighingTickets.column.supplier') },
|
||||
{ key: 'otherLabel', label: t('logistique.weighingTickets.column.other') },
|
||||
{ key: 'displayDate', label: t('logistique.weighingTickets.column.date') },
|
||||
{ key: 'netWeight', label: t('logistique.weighingTickets.column.weight') },
|
||||
]
|
||||
|
||||
/** Clic sur une ligne → ecran Modification (pas de consultation separee, spec § Navigation). */
|
||||
function onRowClick(item: Record<string, unknown>): void {
|
||||
router.push(`/weighing-tickets/${item.id}/edit`)
|
||||
}
|
||||
|
||||
function goToCreate(): void {
|
||||
router.push('/weighing-tickets/new')
|
||||
}
|
||||
|
||||
// ── Export XLSX ─────────────────────────────────────────────────────────────
|
||||
// Exporte toute la liste (site courant applique cote back, spec-back § 4.5).
|
||||
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 (meme pattern M2/M3/M4).
|
||||
const blob = await api.get<Blob>('/weighing_tickets/export.xlsx', {}, {
|
||||
responseType: 'blob',
|
||||
toast: false,
|
||||
} as unknown as Parameters<typeof api.get>[2])
|
||||
|
||||
triggerDownload(blob, 'tickets-pesee.xlsx')
|
||||
}
|
||||
catch {
|
||||
toast.error({
|
||||
title: t('logistique.weighingTickets.toast.error'),
|
||||
message: t('logistique.weighingTickets.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)
|
||||
}
|
||||
|
||||
// Changement de site courant → recharge la liste en page 1 (nouveau périmètre).
|
||||
// usePaginatedList ne passe pas par useAsyncData : le refreshNuxtData() de
|
||||
// switchSite ne l'atteint pas, d'où ce watcher explicite. On compare l'id pour
|
||||
// ignorer l'hydratation initiale (même site) et les ré-affectations sans réel
|
||||
// changement.
|
||||
watch(() => currentSite.value?.id, (id, previousId) => {
|
||||
if (id !== previousId) {
|
||||
reloadFromFirstPage()
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(loadTickets)
|
||||
</script>
|
||||
@@ -0,0 +1,399 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- En-tête : retour vers la liste + titre. -->
|
||||
<div class="flex items-center gap-3 pt-11">
|
||||
<MalioButtonIcon
|
||||
icon="mdi:arrow-left-bold"
|
||||
icon-size="24"
|
||||
variant="ghost"
|
||||
:title="t('logistique.weighingTickets.form.back')"
|
||||
v-bind="{ ariaLabel: t('logistique.weighingTickets.form.back') }"
|
||||
@click="goBack"
|
||||
/>
|
||||
<h1 class="text-[30px] font-semibold text-m-primary">{{ t('logistique.weighingTickets.form.addTitle') }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="mt-[48px] flex flex-col gap-8">
|
||||
<!-- ── Bloc « Poids à vide » (porte la contrepartie, RG-5.03) ──────── -->
|
||||
<WeighingBlock
|
||||
block-id="empty"
|
||||
:title="t('logistique.weighingTickets.form.emptyBlock')"
|
||||
:block="form.empty"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="emptyBlockErrors"
|
||||
:disabled="emptyLocked"
|
||||
@update:block="(field, value) => updateBlock('empty', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('empty')"
|
||||
@request-manual="openManual('empty')"
|
||||
>
|
||||
<!-- Contrepartie : sélecteur + champ conditionnel (RG-5.03). -->
|
||||
<template #counterparty>
|
||||
<MalioSelect
|
||||
:model-value="form.counterpartyType.value"
|
||||
:options="counterpartyOptions"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.type')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
empty-option-label=""
|
||||
:error="errors.counterpartyType"
|
||||
@update:model-value="onCounterpartyTypeChange"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-if="form.counterpartyField.value === 'supplier'"
|
||||
:model-value="form.supplierIri.value"
|
||||
:options="referentials.suppliers.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.supplier')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
empty-option-label=""
|
||||
:error="errors.supplier"
|
||||
@update:model-value="(v: string | number | null) => form.supplierIri.value = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioSelect
|
||||
v-else-if="form.counterpartyField.value === 'client'"
|
||||
:model-value="form.clientIri.value"
|
||||
:options="referentials.clients.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.client')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
empty-option-label=""
|
||||
:error="errors.client"
|
||||
@update:model-value="(v: string | number | null) => form.clientIri.value = v === null ? null : String(v)"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-else-if="form.counterpartyField.value === 'other'"
|
||||
:model-value="form.otherLabel.value"
|
||||
:label="t('logistique.weighingTickets.form.counterparty.other')"
|
||||
:required="true"
|
||||
:disabled="emptyLocked"
|
||||
:error="errors.otherLabel"
|
||||
@update:model-value="(v: string | null) => form.otherLabel.value = v"
|
||||
/>
|
||||
</template>
|
||||
</WeighingBlock>
|
||||
|
||||
<!-- « Enregistrer » du bloc vide : POST initial du ticket (disparaît une
|
||||
fois le ticket créé — RG-5.08). -->
|
||||
<div v-if="form.ticketId.value === null" class="flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.save')"
|
||||
:disabled="creating"
|
||||
@click="submitCreate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ── Bloc « Poids à plein » ───────────────────────────────────────-->
|
||||
<WeighingBlock
|
||||
block-id="full"
|
||||
:title="t('logistique.weighingTickets.form.fullBlock')"
|
||||
:block="form.full"
|
||||
:immatriculation="form.immatriculation.value"
|
||||
:plate-free-format="form.plateFreeFormat.value"
|
||||
:errors="fullBlockErrors"
|
||||
@update:block="(field, value) => updateBlock('full', field, value)"
|
||||
@update:immatriculation="(v) => form.immatriculation.value = v"
|
||||
@update:plate-free-format="(v) => form.plateFreeFormat.value = v"
|
||||
@request-auto="openAuto('full')"
|
||||
@request-manual="openManual('full')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- « Valider » (bas d'écran) : PATCH de la pesée à plein puis ouverture du
|
||||
bon de pesée PDF (RG-5.08). Indisponible tant que le ticket n'est pas créé. -->
|
||||
<div class="mt-12 flex justify-center">
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.validate')"
|
||||
:disabled="validating || form.ticketId.value === null"
|
||||
@click="submitValidate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ── Modal « Confirmation pesée bascule » (RG-5.06) ──────────────────-->
|
||||
<!-- La question est portée par le titre ; pas de texte de corps. Bouton
|
||||
« Valider » seul, centré (l'annulation se fait via la croix). -->
|
||||
<MalioModal v-model="autoModal.open" modal-class="max-w-md" footer-class="justify-center pb-6">
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold">{{ t('logistique.weighingTickets.form.weighbridge.confirmTitle') }}</h2>
|
||||
</template>
|
||||
<!-- Erreur de pont indisponible affichée INLINE dans la modal + invite
|
||||
à la pesée manuelle (RG-5.06). -->
|
||||
<p v-if="autoModal.error" class="text-m-danger">{{ autoModal.error }}</p>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.weighbridge.validate')"
|
||||
:disabled="autoModal.loading"
|
||||
@click="confirmAuto"
|
||||
/>
|
||||
</template>
|
||||
</MalioModal>
|
||||
|
||||
<!-- ── Modal « Pesée manuelle » ────────────────────────────────────────-->
|
||||
<!-- Marges : titre UPPERCASE à 24px du haut (pt-6), 28px horizontaux (mx-7 header
|
||||
/ px-7 body+footer), bordure à 12px sous le titre (pb-3) et insérée (mx-7,
|
||||
ne touche pas les bords), formulaire à 36px sous la bordure (pt-9). -->
|
||||
<MalioModal
|
||||
v-model="manualModal.open"
|
||||
modal-class="max-w-md"
|
||||
header-class="mx-7 px-0 pt-6 pb-3 border-b border-black"
|
||||
body-class="px-7 pt-9"
|
||||
footer-class="px-7 justify-center pb-6"
|
||||
>
|
||||
<template #header>
|
||||
<h2 class="text-[24px] font-bold uppercase">{{ t('logistique.weighingTickets.form.manual.title') }}</h2>
|
||||
</template>
|
||||
<div class="flex flex-col gap-2">
|
||||
<!-- Poids : champ texte verrouillé sur les chiffres (comme le formulaire). -->
|
||||
<MalioInputText
|
||||
v-model="manualModal.weight"
|
||||
:mask="NUMERIC_MASK"
|
||||
:label="t('logistique.weighingTickets.form.manual.weight')"
|
||||
:required="true"
|
||||
:error="manualModal.errors.weight"
|
||||
/>
|
||||
<MalioInputText
|
||||
v-model="manualModal.manualNumber"
|
||||
:label="t('logistique.weighingTickets.form.manual.number')"
|
||||
:required="true"
|
||||
:error="manualModal.errors.manualNumber"
|
||||
/>
|
||||
</div>
|
||||
<template #footer>
|
||||
<MalioButton
|
||||
variant="primary"
|
||||
:label="t('logistique.weighingTickets.form.manual.save')"
|
||||
:disabled="manualModal.loading"
|
||||
@click="confirmManual"
|
||||
/>
|
||||
</template>
|
||||
</MalioModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useWeighingTicketForm, type WeighingBlockState } from '~/modules/logistique/composables/useWeighingTicketForm'
|
||||
import { useWeighbridge } from '~/modules/logistique/composables/useWeighbridge'
|
||||
import { useWeighingTicketReferentials, type RefOption } from '~/modules/logistique/composables/useWeighingTicketReferentials'
|
||||
import { NUMERIC_MASK } from '~/modules/logistique/utils/weighingMasks'
|
||||
|
||||
const { t } = useI18n()
|
||||
const api = useApi()
|
||||
const router = useRouter()
|
||||
const { can } = usePermissions()
|
||||
|
||||
useHead({ title: t('logistique.weighingTickets.form.addTitle') })
|
||||
|
||||
// Création réservée à `manage` (Admin / Bureau / Usine) — sinon retour à la liste.
|
||||
if (!can('logistique.weighing_tickets.manage')) {
|
||||
await navigateTo('/weighing-tickets')
|
||||
}
|
||||
|
||||
const form = useWeighingTicketForm()
|
||||
const weighbridge = useWeighbridge()
|
||||
const referentials = useWeighingTicketReferentials()
|
||||
const { errors, setError, clearErrors, handleApiError } = useFormErrors()
|
||||
|
||||
/**
|
||||
* Validation front-only de la pesée d'un bloc (Poids + DSD obligatoires, RG-5.07).
|
||||
* Le back rend ces colonnes nullable (workflow 2 temps), l'obligation est donc
|
||||
* portée côté front (ERP-101). Pose l'erreur inline sous chaque champ manquant et
|
||||
* retourne false si une pesée manque.
|
||||
*/
|
||||
function validateWeighing(which: 'empty' | 'full'): boolean {
|
||||
const missing = form.missingWeighingFields(which)
|
||||
for (const path of missing) {
|
||||
setError(path, path.endsWith('Weight')
|
||||
? t('logistique.weighingTickets.form.weightRequired')
|
||||
: t('logistique.weighingTickets.form.dsdRequired'))
|
||||
}
|
||||
return missing.length === 0
|
||||
}
|
||||
|
||||
// Le bloc vide se verrouille une fois le ticket créé (numéro/site attribués).
|
||||
const emptyLocked = computed(() => form.ticketId.value !== null)
|
||||
|
||||
const creating = ref(false)
|
||||
const validating = ref(false)
|
||||
|
||||
/** Retour vers la liste (flèche d'en-tête). */
|
||||
function goBack(): void {
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
|
||||
// ── Contrepartie (RG-5.03) ───────────────────────────────────────────────────
|
||||
// Ordre maquette : Fournisseur / Client / Autre.
|
||||
const counterpartyOptions = computed<RefOption[]>(() => [
|
||||
{ value: 'FOURNISSEUR', label: t('logistique.weighingTickets.form.counterparty.supplier') },
|
||||
{ value: 'CLIENT', label: t('logistique.weighingTickets.form.counterparty.client') },
|
||||
{ value: 'AUTRE', label: t('logistique.weighingTickets.form.counterparty.other') },
|
||||
])
|
||||
|
||||
function onCounterpartyTypeChange(value: string | number | null): void {
|
||||
const type = (value === null || value === '') ? null : (String(value) as 'CLIENT' | 'FOURNISSEUR' | 'AUTRE')
|
||||
form.setCounterpartyType(type)
|
||||
}
|
||||
|
||||
// ── Erreurs par bloc (mapping propertyPath back → champs du composant) ────────
|
||||
const emptyBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.emptyDate,
|
||||
weight: errors.emptyWeight,
|
||||
dsd: errors.emptyDsd,
|
||||
immatriculation: errors.immatriculation,
|
||||
}))
|
||||
// Immatriculation volontairement ABSENTE ici : elle est partagée entre les 2 blocs
|
||||
// (RG-5.01) mais saisie/validée sur le bloc « Poids à vide ». On n'affiche donc
|
||||
// son erreur que sur le 1er bloc, pas en double sur le bloc « Poids à plein »
|
||||
// (le formulaire se valide en 2 temps).
|
||||
const fullBlockErrors = computed<Record<string, string>>(() => ({
|
||||
date: errors.fullDate,
|
||||
weight: errors.fullWeight,
|
||||
dsd: errors.fullDsd,
|
||||
}))
|
||||
|
||||
/** Mute un champ d'un bloc de pesée (état centralisé dans le form). */
|
||||
function updateBlock(target: 'empty' | 'full', field: keyof WeighingBlockState, value: unknown): void {
|
||||
// Affectation typée via l'index du bloc reactif (date est le seul champ éditable).
|
||||
(form[target] as Record<string, unknown>)[field as string] = value
|
||||
}
|
||||
|
||||
// ── Modal pesée bascule (AUTO) ────────────────────────────────────────────────
|
||||
const autoModal = reactive({
|
||||
open: false,
|
||||
error: '',
|
||||
loading: false,
|
||||
target: 'empty' as 'empty' | 'full',
|
||||
})
|
||||
|
||||
function openAuto(target: 'empty' | 'full'): void {
|
||||
autoModal.target = target
|
||||
autoModal.error = ''
|
||||
autoModal.open = true
|
||||
}
|
||||
|
||||
/** Déclenche la pesée bascule ; erreur (RG-5.06) affichée dans la modal. */
|
||||
async function confirmAuto(): Promise<void> {
|
||||
if (autoModal.loading) return
|
||||
autoModal.loading = true
|
||||
autoModal.error = ''
|
||||
try {
|
||||
const reading = await weighbridge.triggerAuto()
|
||||
form.applyReading(form[autoModal.target], reading)
|
||||
autoModal.open = false
|
||||
}
|
||||
catch (error) {
|
||||
// Pont indisponible : message inline + invite à la pesée manuelle.
|
||||
autoModal.error = weighbridge.extractWeighbridgeError(error)
|
||||
}
|
||||
finally {
|
||||
autoModal.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Modal pesée manuelle (MANUAL) ─────────────────────────────────────────────
|
||||
const manualModal = reactive({
|
||||
open: false,
|
||||
loading: false,
|
||||
target: 'empty' as 'empty' | 'full',
|
||||
weight: null as string | null,
|
||||
manualNumber: null as string | null,
|
||||
errors: {} as Record<string, string>,
|
||||
})
|
||||
|
||||
function openManual(target: 'empty' | 'full'): void {
|
||||
manualModal.target = target
|
||||
manualModal.weight = null
|
||||
manualModal.manualNumber = null
|
||||
manualModal.errors = {}
|
||||
manualModal.open = true
|
||||
}
|
||||
|
||||
/** Valide la saisie manuelle puis remplit le bloc (DSD calculé serveur, RG-5.04). */
|
||||
async function confirmManual(): Promise<void> {
|
||||
if (manualModal.loading) return
|
||||
manualModal.errors = {}
|
||||
|
||||
const weight = manualModal.weight === null || manualModal.weight === '' ? null : Number(manualModal.weight)
|
||||
const manualNumber = (manualModal.manualNumber ?? '').trim()
|
||||
if (weight === null || Number.isNaN(weight)) {
|
||||
manualModal.errors = { ...manualModal.errors, weight: t('logistique.weighingTickets.form.manual.weightRequired') }
|
||||
}
|
||||
if (manualNumber === '') {
|
||||
manualModal.errors = { ...manualModal.errors, manualNumber: t('logistique.weighingTickets.form.manual.numberRequired') }
|
||||
}
|
||||
if (Object.keys(manualModal.errors).length > 0) return
|
||||
|
||||
manualModal.loading = true
|
||||
try {
|
||||
const reading = await weighbridge.triggerManual(weight as number, manualNumber)
|
||||
form.applyReading(form[manualModal.target], reading)
|
||||
manualModal.open = false
|
||||
}
|
||||
catch (error) {
|
||||
manualModal.errors = { weight: weighbridge.extractWeighbridgeError(error) }
|
||||
}
|
||||
finally {
|
||||
manualModal.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
// ── Soumissions ──────────────────────────────────────────────────────────────
|
||||
interface TicketResponse { id: number }
|
||||
|
||||
/** « Enregistrer » du bloc vide : POST /weighing_tickets (création + pesée à vide). */
|
||||
async function submitCreate(): Promise<void> {
|
||||
if (creating.value) return
|
||||
clearErrors()
|
||||
// Marque Poids/DSD manquants pour un retour immédiat, mais on POSTe quand même :
|
||||
// le back renvoie TOUTES les violations d'un coup (counterparty / immat / poids,
|
||||
// NotBlank sur emptyWeight), comme les autres modules. Le DSD est alloué serveur
|
||||
// (pas de règle back) → simple repère front en miroir du poids.
|
||||
validateWeighing('empty')
|
||||
creating.value = true
|
||||
try {
|
||||
const created = await api.post<TicketResponse>('/weighing_tickets', form.buildCreatePayload(), {
|
||||
headers: { Accept: 'application/ld+json' },
|
||||
toast: false,
|
||||
})
|
||||
form.ticketId.value = created.id
|
||||
}
|
||||
catch (error) {
|
||||
handleApiError(error, { fallbackMessage: t('logistique.weighingTickets.toast.error') })
|
||||
}
|
||||
finally {
|
||||
creating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** « Valider » : PATCH de la pesée à plein puis ouverture du bon de pesée PDF (RG-5.08). */
|
||||
async function submitValidate(): Promise<void> {
|
||||
if (validating.value || form.ticketId.value === null) return
|
||||
clearErrors()
|
||||
// Pesée à plein obligatoire (front-only) avant finalisation/impression.
|
||||
if (!validateWeighing('full')) return
|
||||
validating.value = true
|
||||
try {
|
||||
await api.patch(`/weighing_tickets/${form.ticketId.value}`, form.buildFullPayload(), { toast: false })
|
||||
// Bon de pesée = PDF généré côté back (Twig, ERP-192) — on l'ouvre, on ne
|
||||
// dessine aucun gabarit côté front (RG-5.08).
|
||||
window.open(`/api/weighing_tickets/${form.ticketId.value}/print.pdf`, '_blank')
|
||||
router.push('/weighing-tickets')
|
||||
}
|
||||
catch (error) {
|
||||
handleApiError(error, { fallbackMessage: t('logistique.weighingTickets.toast.error') })
|
||||
}
|
||||
finally {
|
||||
validating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// Échec du chargement des référentiels non bloquant : les selects restent vides.
|
||||
referentials.load().catch(() => {})
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { formatDateFr, formatWeightKg, formatPlate } from '../weighingTicketFormat'
|
||||
|
||||
describe('weighingTicketFormat', () => {
|
||||
// ── Date JJ-MM-AAAA ───────────────────────────────────────────────────────
|
||||
describe('formatDateFr', () => {
|
||||
it('formate un datetime ISO en JJ-MM-AAAA', () => {
|
||||
expect(formatDateFr('2026-06-17T09:12:00+02:00')).toBe('17-06-2026')
|
||||
})
|
||||
|
||||
it('zéro-pad le jour et le mois', () => {
|
||||
expect(formatDateFr('2026-01-05T00:00:00Z')).toBe('05-01-2026')
|
||||
})
|
||||
|
||||
it('retourne une chaîne vide si absente ou invalide', () => {
|
||||
expect(formatDateFr(null)).toBe('')
|
||||
expect(formatDateFr(undefined)).toBe('')
|
||||
expect(formatDateFr('pas-une-date')).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
// ── Poids « X XXX Kg » ────────────────────────────────────────────────────
|
||||
describe('formatWeightKg', () => {
|
||||
it('ajoute un séparateur de milliers (espace) et le suffixe Kg', () => {
|
||||
expect(formatWeightKg(7150)).toBe('7 150 Kg')
|
||||
expect(formatWeightKg(14300)).toBe('14 300 Kg')
|
||||
expect(formatWeightKg(1000000)).toBe('1 000 000 Kg')
|
||||
})
|
||||
|
||||
it('gère les petits nombres sans séparateur', () => {
|
||||
expect(formatWeightKg(0)).toBe('0 Kg')
|
||||
expect(formatWeightKg(999)).toBe('999 Kg')
|
||||
})
|
||||
|
||||
it('retourne une chaîne vide si le poids est absent', () => {
|
||||
expect(formatWeightKg(null)).toBe('')
|
||||
expect(formatWeightKg(undefined)).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
// ── Immatriculation UPPER ─────────────────────────────────────────────────
|
||||
describe('formatPlate', () => {
|
||||
it('met en majuscules et trim', () => {
|
||||
expect(formatPlate(' ab-123-cd ')).toBe('AB-123-CD')
|
||||
})
|
||||
|
||||
it('retourne une chaîne vide si absente', () => {
|
||||
expect(formatPlate(null)).toBe('')
|
||||
expect(formatPlate('')).toBe('')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { MaskInputOptions } from 'maska'
|
||||
|
||||
/**
|
||||
* Masques de saisie du module « Tickets de pesée » (M5). Partagés entre le
|
||||
* composant de bloc (`WeighingBlock`) et les modales de pesée (écrans Ajouter /
|
||||
* Modifier). La validation de format reste autoritaire côté serveur (RG-5.01).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Masque « chiffres uniquement » (longueur libre) — Poids et DSD. Verrouille la
|
||||
* saisie sur des entiers.
|
||||
*/
|
||||
export const NUMERIC_MASK: MaskInputOptions = {
|
||||
mask: 'D',
|
||||
tokens: { D: { pattern: /[0-9]/, multiple: true } },
|
||||
}
|
||||
|
||||
/**
|
||||
* Masque plaque FR SIV `XX-000-XX` : 2 lettres, 3 chiffres, 2 lettres, majuscules
|
||||
* forcées. Utilisé quand « Tout format » n'est pas coché (RG-5.01).
|
||||
*/
|
||||
export const PLATE_MASK: MaskInputOptions = {
|
||||
mask: 'AA-###-AA',
|
||||
tokens: { A: { pattern: /[A-Za-z]/, transform: (c: string) => c.toUpperCase() } },
|
||||
}
|
||||
|
||||
/**
|
||||
* Masque « Tout format » (RG-5.01) : plaques anciennes / étrangères / engins. On
|
||||
* autorise lettres, chiffres, espace et tiret, en MAJUSCULES, longueur libre —
|
||||
* mais on filtre tout le reste (accents, ponctuation, symboles : « &é"'(_ç… »).
|
||||
* Pattern maska charset du projet (cf. shared/utils/textSanitize) : `preProcess`
|
||||
* retire d'abord les caractères hors charset (le token `multiple` glouton
|
||||
* s'arrêterait sinon au 1er invalide), puis le token laisse passer le reste.
|
||||
*/
|
||||
export const FREE_PLATE_MASK: MaskInputOptions = {
|
||||
mask: 'P',
|
||||
tokens: { P: { pattern: /[A-Z0-9 -]/, multiple: true } },
|
||||
preProcess: (value: string) => value.toUpperCase().replace(/[^A-Z0-9 -]/g, ''),
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Filtres d'affichage du module « Tickets de pesée » (M5, ERP-191). Helpers PURS
|
||||
* et testables, partagés par la liste et les écrans. Le serveur reste l'autorité
|
||||
* de normalisation (spec-front § Règles de formatage) : ces helpers ne font que
|
||||
* mettre en forme la valeur déjà normalisée renvoyée par l'API.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Date courte française `JJ-MM-AAAA` (spec M5). Chaîne vide si la valeur est
|
||||
* absente ou invalide. Lit les composantes locales (cohérent avec l'affichage
|
||||
* des autres répertoires M1→M4).
|
||||
*/
|
||||
export function formatDateFr(value: string | null | undefined): string {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return ''
|
||||
}
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
return `${day}-${month}-${date.getFullYear()}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Poids en kg avec séparateur de milliers (espace) + suffixe « Kg »
|
||||
* (spec-front : « 7 150 Kg »). Chaîne vide si le poids est absent (ticket dont la
|
||||
* pesée à plein n'est pas finalisée). Groupement manuel (espace ASCII) pour un
|
||||
* rendu déterministe, indépendant de l'ICU de l'environnement.
|
||||
*/
|
||||
export function formatWeightKg(value: number | null | undefined): string {
|
||||
if (value === null || value === undefined) {
|
||||
return ''
|
||||
}
|
||||
const grouped = String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ' ')
|
||||
return `${grouped} Kg`
|
||||
}
|
||||
|
||||
/**
|
||||
* Immatriculation en MAJUSCULES (cohérent avec la normalisation serveur RG-5.01 :
|
||||
* trim + UPPER). Chaîne vide si absente.
|
||||
*/
|
||||
export function formatPlate(value: string | null | undefined): string {
|
||||
return value ? value.trim().toUpperCase() : ''
|
||||
}
|
||||
@@ -15,3 +15,18 @@ export function todayIso(now: Date = new Date()): string {
|
||||
const day = String(now.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Date-heure courante au format ISO LOCAL `YYYY-MM-DDTHH:mm:ss` (sans fuseau).
|
||||
*
|
||||
* C'est le format attendu par `MalioDateTime` (secondes incluses, pas d'offset
|
||||
* horaire). Comme `todayIso`, on lit les composantes LOCALES (jamais
|
||||
* `toISOString()`/UTC) pour ne pas décaler l'heure réelle. Paramètre `now`
|
||||
* injectable pour les tests.
|
||||
*/
|
||||
export function nowIsoDateTime(now: Date = new Date()): string {
|
||||
const hours = String(now.getHours()).padStart(2, '0')
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0')
|
||||
return `${todayIso(now)}T${hours}:${minutes}:${seconds}`
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use ApiPlatform\Metadata\Post;
|
||||
use App\Module\Commercial\Domain\Entity\Client; // relation ORM partagee (§ 2.1)
|
||||
use App\Module\Commercial\Domain\Entity\Supplier; // relation ORM partagee (§ 2.1)
|
||||
use App\Module\Logistique\Infrastructure\ApiPlatform\State\Processor\WeighingTicketProcessor;
|
||||
use App\Module\Logistique\Infrastructure\ApiPlatform\State\Provider\WeighingTicketPrintProvider;
|
||||
use App\Module\Logistique\Infrastructure\ApiPlatform\State\Provider\WeighingTicketProvider;
|
||||
use App\Module\Logistique\Infrastructure\Doctrine\DoctrineWeighingTicketRepository;
|
||||
use App\Module\Sites\Domain\Entity\Site; // relation ORM partagee (§ 2.1)
|
||||
@@ -84,6 +85,18 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
]],
|
||||
provider: WeighingTicketProvider::class,
|
||||
),
|
||||
// Bon de pesee PDF (RG-5.08, spec § 2.12 / § 4.6) : operation dediee qui
|
||||
// sert un binaire (pas une representation Hydra). Le provider retourne une
|
||||
// Response -> la serialisation est court-circuitee. Pas de controller
|
||||
// (decision spec § 4.6). Pas de format API Platform negocie : `.pdf` est
|
||||
// litteral dans l'URI.
|
||||
new Get(
|
||||
uriTemplate: '/weighing_tickets/{id}/print.pdf',
|
||||
security: "is_granted('logistique.weighing_tickets.view')",
|
||||
provider: WeighingTicketPrintProvider::class,
|
||||
output: false,
|
||||
read: true,
|
||||
),
|
||||
new Post(
|
||||
security: "is_granted('logistique.weighing_tickets.manage')",
|
||||
normalizationContext: ['groups' => [
|
||||
@@ -95,6 +108,10 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
'default:read',
|
||||
]],
|
||||
denormalizationContext: ['groups' => ['weighing_ticket:write']],
|
||||
// Erreurs de denormalisation (date non parsable, type/IRI invalide)
|
||||
// remontees en 422 avec propertyPath (et non 400 opaque) -> mapping
|
||||
// inline par champ cote front via useFormErrors (miroir M1 Client).
|
||||
collectDenormalizationErrors: true,
|
||||
processor: WeighingTicketProcessor::class,
|
||||
),
|
||||
new Patch(
|
||||
@@ -108,6 +125,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
'default:read',
|
||||
]],
|
||||
denormalizationContext: ['groups' => ['weighing_ticket:write']],
|
||||
collectDenormalizationErrors: true,
|
||||
provider: WeighingTicketProvider::class,
|
||||
processor: WeighingTicketProcessor::class,
|
||||
),
|
||||
@@ -190,8 +208,15 @@ class WeighingTicket implements TimestampableInterface, BlamableInterface
|
||||
#[Groups(['weighing_ticket:item:read', 'weighing_ticket:write'])]
|
||||
private ?DateTimeImmutable $emptyDate = null;
|
||||
|
||||
/** Poids a vide (tare) en kg — readonly UI, rempli par la pesee (RG-5.07). */
|
||||
/**
|
||||
* Poids a vide (tare) en kg — readonly UI, rempli par la pesee (RG-5.07).
|
||||
* Obligatoire : un ticket est cree APRES la pesee a vide (POST). NotBlank ici
|
||||
* (et non sur empty_dsd, alloue serveur) rend la 422 « poids obligatoire »
|
||||
* coherente avec les autres champs requis (counterpartyType / immatriculation),
|
||||
* toutes renvoyees d'un coup -> mapping inline front (ERP-101).
|
||||
*/
|
||||
#[ORM\Column(name: 'empty_weight', nullable: true)]
|
||||
#[Assert\NotBlank(message: 'Le poids est obligatoire : effectuez une pesée.')]
|
||||
#[Groups(['weighing_ticket:item:read', 'weighing_ticket:write'])]
|
||||
private ?int $emptyWeight = null;
|
||||
|
||||
|
||||
+15
-11
@@ -84,7 +84,7 @@ final class WeighingTicketProcessor implements ProcessorInterface
|
||||
// depuis la base. Garde defensive si jamais il manque (ne devrait pas).
|
||||
$site = $data->getSite();
|
||||
if ($site instanceof Site) {
|
||||
$this->allocateAutoDsd($data, $site, $isNew);
|
||||
$this->allocateAutoDsd($data, $site);
|
||||
}
|
||||
|
||||
$this->computeNetWeight($data);
|
||||
@@ -162,21 +162,25 @@ final class WeighingTicketProcessor implements ProcessorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* RG-5.04 : (re)attribution AUTORITAIRE du DSD pour chaque pesee AUTO via
|
||||
* DsdAllocator (verrou FOR UPDATE). A la creation, le DSD prévisionnel envoye
|
||||
* par le client (issu de POST /api/weighbridge_readings) est ecrase. Sur PATCH,
|
||||
* on n'alloue que pour une pesee AUTO encore depourvue de DSD (ex. la pesee a
|
||||
* plein realisee apres coup) — sinon on churne le compteur a chaque edition.
|
||||
* Les pesees MANUELLES conservent leur DSD (deja alloue par l'endpoint de
|
||||
* pesee, « dernier + 1 »).
|
||||
* RG-5.04 : le DSD d'une pesee est attribue A LA PESEE (POST /api/weighbridge_readings)
|
||||
* et CONSERVE tel quel sur le ticket — on ne le reattribue PAS au save. Raison :
|
||||
* le DSD est l'index de pesee du pont, deja verrouille (FOR UPDATE) a l'emission ;
|
||||
* demain il proviendra directement du materiel (driver reel derriere
|
||||
* WeighbridgeReaderInterface) et devra etre persiste a l'identique. Reallouer ici
|
||||
* ecraserait cet index (double comptage aujourd'hui, perte de l'index reel demain)
|
||||
* et ferait diverger le DSD previsionnel affiche du DSD enregistre.
|
||||
*
|
||||
* On n'alloue donc qu'en FILET DE SECURITE : pesee AUTO sans DSD (ex. ticket cree
|
||||
* sans passer par l'endpoint de pesee). Les pesees MANUELLES conservent egalement
|
||||
* leur DSD (alloue « dernier + 1 » par l'endpoint de pesee).
|
||||
*/
|
||||
private function allocateAutoDsd(WeighingTicket $data, Site $site, bool $isNew): void
|
||||
private function allocateAutoDsd(WeighingTicket $data, Site $site): void
|
||||
{
|
||||
if ('AUTO' === $data->getEmptyMode() && ($isNew || null === $data->getEmptyDsd())) {
|
||||
if ('AUTO' === $data->getEmptyMode() && null === $data->getEmptyDsd()) {
|
||||
$data->setEmptyDsd($this->dsdAllocator->next($site));
|
||||
}
|
||||
|
||||
if ('AUTO' === $data->getFullMode() && ($isNew || null === $data->getFullDsd())) {
|
||||
if ('AUTO' === $data->getFullMode() && null === $data->getFullDsd()) {
|
||||
$data->setFullDsd($this->dsdAllocator->next($site));
|
||||
}
|
||||
}
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Logistique\Infrastructure\ApiPlatform\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Module\Logistique\Domain\Entity\WeighingTicket;
|
||||
use App\Module\Logistique\Domain\Repository\WeighingTicketRepositoryInterface;
|
||||
use App\Module\Logistique\Infrastructure\Pdf\WeighingTicketPdfRenderer;
|
||||
use App\Module\Sites\Application\Service\CurrentSiteProviderInterface;
|
||||
use App\Module\Sites\Domain\Entity\Site;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Provider de l'operation `GET /api/weighing_tickets/{id}/print.pdf` : sert le bon
|
||||
* de pesee en PDF (M5, spec-back § 2.12 / § 4.6 — RG-5.08). Operation API Platform
|
||||
* dediee (pas de controller, decision spec § 4.6) ; le binaire est genere par
|
||||
* {@see WeighingTicketPdfRenderer} (template Twig -> Dompdf).
|
||||
*
|
||||
* Le provider retourne directement une {@see Response} : API Platform court-circuite
|
||||
* alors la serialisation Hydra (le SerializeListener/RespondListener detectent une
|
||||
* Response et la renvoient telle quelle). `Content-Type: application/pdf`,
|
||||
* disposition `inline` (le front ouvre l'apercu — RG-5.08).
|
||||
*
|
||||
* Securite & visibilite — miroir de {@see WeighingTicketProvider::provideItem()} :
|
||||
* - permission `logistique.weighing_tickets.view` portee par l'operation (403) ;
|
||||
* - 404 si ticket introuvable, soft-delete (non expose au M5 — § 2.13), ou hors
|
||||
* perimetre du site courant (anti-enumeration, § 2.3 / RG-5.09).
|
||||
*
|
||||
* @implements ProviderInterface<WeighingTicket>
|
||||
*/
|
||||
final class WeighingTicketPrintProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
#[Autowire(service: 'App\Module\Logistique\Infrastructure\Doctrine\DoctrineWeighingTicketRepository')]
|
||||
private readonly WeighingTicketRepositoryInterface $repository,
|
||||
private readonly WeighingTicketPdfRenderer $renderer,
|
||||
private readonly CurrentSiteProviderInterface $currentSiteProvider,
|
||||
private readonly Security $security,
|
||||
) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): Response
|
||||
{
|
||||
$ticket = $this->findVisibleTicket($uriVariables['id'] ?? null);
|
||||
if (null === $ticket) {
|
||||
throw new NotFoundHttpException('Ticket de pesée introuvable.');
|
||||
}
|
||||
|
||||
$pdf = $this->renderer->render($ticket);
|
||||
|
||||
$response = new Response($pdf);
|
||||
$response->headers->set('Content-Type', 'application/pdf');
|
||||
$response->headers->set(
|
||||
'Content-Disposition',
|
||||
sprintf('inline; filename="bon-pesee-%s.pdf"', $ticket->getNumber() ?? (string) $ticket->getId()),
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge le ticket visible par l'utilisateur courant, ou null (-> 404) :
|
||||
* introuvable, soft-delete, ou hors perimetre du site courant. Logique
|
||||
* identique a WeighingTicketProvider::provideItem() (cloisonnement § 2.3).
|
||||
*/
|
||||
private function findVisibleTicket(mixed $id): ?WeighingTicket
|
||||
{
|
||||
if (!is_int($id) && !(is_string($id) && ctype_digit($id))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ticket = $this->repository->findById((int) $id);
|
||||
if (null === $ticket || null !== $ticket->getDeletedAt()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$scopeSite = $this->currentScopeSite();
|
||||
if (null !== $scopeSite && $ticket->getSite()?->getId() !== $scopeSite->getId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Site servant a cloisonner, ou null si aucun cloisonnement ne s'applique
|
||||
* (user `sites.bypass_scope`, ou pas de site courant). Miroir de
|
||||
* WeighingTicketProvider::currentScopeSite().
|
||||
*/
|
||||
private function currentScopeSite(): ?Site
|
||||
{
|
||||
if ($this->security->isGranted('sites.bypass_scope')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->currentSiteProvider->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Logistique\Infrastructure\Pdf;
|
||||
|
||||
use App\Module\Logistique\Domain\Entity\WeighingTicket;
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Options;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* Rend le ticket de pesee (M5, spec-back § 2.12 / § 4.6 — RG-5.08) : hydrate le
|
||||
* template Twig `logistique/weighing_ticket_print.html.twig` avec le ticket, puis
|
||||
* convertit le HTML en PDF via Dompdf (pur PHP, aucune dependance systeme — choix
|
||||
* valide avec Matthieu, ERP-192).
|
||||
*
|
||||
* Le gabarit reproduit le modele fourni (ticket_pesee.pdf) : en-tete FIXE (logo +
|
||||
* identite societe), titre, les deux pesees (poids / N° pesee / DSD + date) et le
|
||||
* poids net. Le rendu ne depend PAS du site (decision Tristan, ERP-192) : le logo
|
||||
* et l'identite societe sont constants.
|
||||
*
|
||||
* Service technique d'infrastructure (pas de logique metier) : le contenu/affiche
|
||||
* est decide par le template ; ICI on ne fait que charger le logo et generer le
|
||||
* binaire.
|
||||
*/
|
||||
final class WeighingTicketPdfRenderer
|
||||
{
|
||||
/** Logo societe embarque dans l'en-tete (fixe, hors versioning par site). */
|
||||
private const string LOGO_PATH = __DIR__.'/assets/logo-lpc-liot.png';
|
||||
|
||||
public function __construct(
|
||||
private readonly Environment $twig,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Genere le binaire PDF du ticket de pesee pour un ticket donne.
|
||||
*
|
||||
* Dompdf : remote desactive (aucune ressource externe chargee — securite ; le
|
||||
* logo passe en data-URI), A4 portrait, police par defaut DejaVu Sans (UTF-8
|
||||
* -> accents FR et « ° » corrects).
|
||||
*/
|
||||
public function render(WeighingTicket $ticket): string
|
||||
{
|
||||
$html = $this->twig->render('logistique/weighing_ticket_print.html.twig', [
|
||||
'ticket' => $ticket,
|
||||
'logoSrc' => $this->logoDataUri(),
|
||||
]);
|
||||
|
||||
$options = new Options();
|
||||
$options->set('isRemoteEnabled', false);
|
||||
$options->set('defaultFont', 'DejaVu Sans');
|
||||
|
||||
$dompdf = new Dompdf($options);
|
||||
$dompdf->loadHtml($html, 'UTF-8');
|
||||
$dompdf->setPaper('A4', 'portrait');
|
||||
$dompdf->render();
|
||||
|
||||
return (string) $dompdf->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logo societe encode en data-URI base64, ou null s'il est introuvable (le
|
||||
* template degrade alors sans bloquer la generation du PDF).
|
||||
*/
|
||||
private function logoDataUri(): ?string
|
||||
{
|
||||
$binary = @file_get_contents(self::LOGO_PATH);
|
||||
if (false === $binary) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return 'data:image/png;base64,'.base64_encode($binary);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
@@ -0,0 +1,81 @@
|
||||
{#
|
||||
Ticket de pesée (M5 Logistique) — gabarit imprimable hydraté côté serveur puis
|
||||
converti en PDF par WeighingTicketPdfRenderer (Dompdf). Cf. spec-back M5 § 2.12
|
||||
/ § 4.6 (RG-5.08). Reproduit fidèlement le modèle fourni (ticket_pesee.pdf).
|
||||
|
||||
En-tête FIXE (logo + identité société) : le ticket ne change pas en fonction du
|
||||
site (décision Tristan, ERP-192). Le logo est injecté en data-URI par le renderer
|
||||
(logoSrc) ; l'identité société est en dur ci-dessous.
|
||||
|
||||
Contraintes Dompdf : CSS2.1 (pas de flexbox/grid), mise en page par tableaux.
|
||||
Police DejaVu Sans (UTF-8 — accents FR et « ° » rendus correctement).
|
||||
#}
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
@page { margin: 18mm 16mm; }
|
||||
|
||||
* { font-family: "DejaVu Sans", sans-serif; }
|
||||
|
||||
body { color: #000; font-size: 10px; margin: 0; }
|
||||
|
||||
.logo { margin-bottom: 16px; }
|
||||
.logo img { height: 100px; }
|
||||
|
||||
.company-name { font-weight: bold; font-size: 12px; }
|
||||
.company-line { font-size: 12px; }
|
||||
|
||||
.title { font-size: 22px; font-weight: bold; margin: 22px 0 18px; }
|
||||
|
||||
/* Lignes des deux pesées : tableau sans bordure, colonnes alignées. */
|
||||
.weighings { border-collapse: collapse; font-size: 12px; }
|
||||
.weighings td { vertical-align: top; white-space: nowrap; }
|
||||
.weighings .c-label { width: 130px; }
|
||||
.weighings .c-weight { width: 95px; }
|
||||
.weighings .c-num { width: 175px; }
|
||||
.weighings .c-dsd { width: auto; }
|
||||
|
||||
.net { font-size: 18px; font-weight: bold; margin-top: 26px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{% if logoSrc %}
|
||||
<div class="logo"><img src="{{ logoSrc }}" alt="LPC LIOT"></div>
|
||||
{% endif %}
|
||||
|
||||
<div class="company-name">SA LIOT Châtellerault</div>
|
||||
<div class="company-line">Email : lpc.contacts@lpc-liot.fr</div>
|
||||
<div class="company-line">RCS Châtellerault B 339 505 612</div>
|
||||
|
||||
<div class="title">Ticket de pesée</div>
|
||||
|
||||
{#
|
||||
Référence de pesée affichée au client = un seul numéro, présenté comme un
|
||||
DSD : en pesée MANUELLE c'est le numéro de pesée saisi (manualNumber), en
|
||||
pesée AUTO c'est le DSD du pont. « N° pesée » et « DSD » sont la même chose
|
||||
pour le client (RG-5.04) — on n'expose donc pas le compteur interne du pont
|
||||
quand une pesée manuelle porte son propre numéro.
|
||||
#}
|
||||
{% set emptyRef = (ticket.emptyMode == 'MANUAL' and ticket.emptyManualNumber) ? ticket.emptyManualNumber : ticket.emptyDsd %}
|
||||
{% set fullRef = (ticket.fullMode == 'MANUAL' and ticket.fullManualNumber) ? ticket.fullManualNumber : ticket.fullDsd %}
|
||||
|
||||
<table class="weighings">
|
||||
<tr>
|
||||
<td class="c-label">Poids à vide</td>
|
||||
<td class="c-weight">{{ ticket.emptyWeight is not null ? ticket.emptyWeight ~ ' kg' : '' }}</td>
|
||||
<td class="c-num">N° pesée à vide</td>
|
||||
<td class="c-dsd">{% if emptyRef is not null %}DSD : {{ emptyRef }}{% endif %}{% if ticket.emptyDate %} {{ ticket.emptyDate|date('d/m/Y H:i:s') }}{% endif %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="c-label">Poids à plein</td>
|
||||
<td class="c-weight">{{ ticket.fullWeight is not null ? ticket.fullWeight ~ ' kg' : '' }}</td>
|
||||
<td class="c-num">N° pesée à plein</td>
|
||||
<td class="c-dsd">{% if fullRef is not null %}DSD : {{ fullRef }}{% endif %}{% if ticket.fullDate %} {{ ticket.fullDate|date('d/m/Y H:i:s') }}{% endif %}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="net">Poids : {{ ticket.netWeight is not null ? ticket.netWeight ~ ' kg' : '—' }}</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Module\Logistique\Api;
|
||||
|
||||
/**
|
||||
* Tests fonctionnels de l'impression du bon de pesee PDF (M5, spec-back § 2.12 /
|
||||
* § 4.6 — RG-5.08, ERP-192) : operation `GET /api/weighing_tickets/{id}/print.pdf`.
|
||||
*
|
||||
* Couvre la verification du ticket :
|
||||
* - 200 + PDF non vide (Content-Type application/pdf, disposition inline,
|
||||
* signature %PDF) pour un ticket existant et visible ;
|
||||
* - 403 sans la permission `logistique.weighing_tickets.view` ;
|
||||
* - 404 pour un ticket inexistant.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class WeighingTicketPrintApiTest extends AbstractWeighingTicketApiTestCase
|
||||
{
|
||||
public function testPrintReturnsNonEmptyPdfForExistingTicket(): void
|
||||
{
|
||||
$site = $this->firstSite();
|
||||
$http = $this->authManageOnSite($site);
|
||||
$client = $this->seedTestClient('Print');
|
||||
|
||||
$created = $this->postTicket($http, $this->validClientTicketPayload($client));
|
||||
self::assertResponseStatusCodeSame(201);
|
||||
$ticketId = $created->toArray()['id'];
|
||||
|
||||
$response = $http->request('GET', sprintf('/api/weighing_tickets/%d/print.pdf', $ticketId));
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
|
||||
$headers = $response->getHeaders(false);
|
||||
self::assertStringContainsString('application/pdf', $headers['content-type'][0] ?? '');
|
||||
self::assertStringContainsString('inline', $headers['content-disposition'][0] ?? '');
|
||||
|
||||
// PDF non vide + signature de fichier PDF (« %PDF-1.x »).
|
||||
$binary = $response->getContent(false);
|
||||
self::assertNotSame('', $binary, 'Le PDF du bon de pesée ne doit pas être vide.');
|
||||
self::assertStringStartsWith('%PDF', $binary);
|
||||
}
|
||||
|
||||
public function testForbiddenWithoutViewPermission(): void
|
||||
{
|
||||
// On seede un ticket reel via un user habilite, puis on tente l'impression
|
||||
// avec un user depourvu de `logistique.weighing_tickets.view`.
|
||||
$site = $this->firstSite();
|
||||
$manager = $this->authManageOnSite($site);
|
||||
$client = $this->seedTestClient('Forbidden');
|
||||
|
||||
$created = $this->postTicket($manager, $this->validClientTicketPayload($client));
|
||||
self::assertResponseStatusCodeSame(201);
|
||||
$ticketId = $created->toArray()['id'];
|
||||
|
||||
$creds = $this->createUserWithPermission('core.users.view');
|
||||
$intrus = $this->authenticatedClient($creds['username'], $creds['password']);
|
||||
|
||||
$intrus->request('GET', sprintf('/api/weighing_tickets/%d/print.pdf', $ticketId));
|
||||
|
||||
self::assertResponseStatusCodeSame(403);
|
||||
}
|
||||
|
||||
public function testNotFoundForUnknownTicket(): void
|
||||
{
|
||||
$http = $this->authManageOnSite($this->firstSite());
|
||||
|
||||
$http->request('GET', '/api/weighing_tickets/99999999/print.pdf');
|
||||
|
||||
self::assertResponseStatusCodeSame(404);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user