1ff335b3fe
Auto Tag Develop / tag (push) Successful in 7s
## Contexte
Correctifs des 4 bugs de contrat de sérialisation du répertoire clients M1, révélés par la capture du JSON réel le 02/06/2026 (cf. `docs/specs/M2-suppliers/spec-back.md` § 4.0.ter). Tous étaient des oublis **silencieux** (aucune erreur levée).
## Changements
- **ERP-80 — Fuite RIB (sécurité)** : `Client::getRibs()` et les propriétés de `ClientRib` passent sous le groupe gaté `client:read:accounting` (ajouté au contexte par `ClientReadGroupContextBuilder` uniquement si `accounting.view`). La clé `ribs` est désormais **absente** du détail pour la Commerciale. La sous-ressource autonome `/api/client_ribs/{id}` conserve `client_rib:read` (écriture/PATCH intacts).
- **ERP-81 — Booléens d'adresse** : `#[Groups]` + `#[SerializedName]` portés sur les **getters** `isProspect()/isDelivery()/isBilling()` (le getter booléen strippait le préfixe `is` et droppait la clé — même pattern que `Client::isArchived`).
- **ERP-82 — Embed Category/Site** : `category:read` + `site:read` ajoutés au `normalizationContext` du `Get` Client → `categories[].code/.name` et `addresses[].sites[].name` embarqués.
- **ERP-83 — Tests anti-régression** : nouveau `ClientSerializationContractTest` (7 tests, 64 assertions) assertant sur le **corps JSON réel**.
## Dépendance signalée
⚠️ L'entité **`Site` n'a pas de champ `code`** (ni `SiteInterface`) — son libellé est `name`. Les « codes 86/17/82 » de la spec M2 sont en réalité le préfixe du code postal des sites fixtures. À planifier côté module Sites si un `Site.code` est requis (notamment pour `getSiteCodes()` au M2).
## Vérifications
- `make test` : **460 tests, 1535 assertions, exit 0** ✅
- `make php-cs-fixer-allow-risky` : 0 fix ✅
- Capture JSON réelle AVANT/APRÈS (client 6 TRANSPORTS RAPIDES) :
- **Admin** : `ribs` présents, `siren`/`accountNumber`/`nTva` présents, `categories[].code/.name` + `addresses[].sites[].name` embarqués, booléens d'adresse présents.
- **Commerciale** : `ribs` **absent**, scalaires comptables **absents** (omission), embed Category/Site + booléens visibles.
Tickets : ERP-80, ERP-81, ERP-82, ERP-83 (passés « En review »).
---------
Co-authored-by: admin malio <malio@yuno.malio.fr>
Co-authored-by: Matthieu <contact@malio.fr>
Reviewed-on: #45
Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
Co-committed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
186 lines
6.0 KiB
PHP
186 lines
6.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Module\Commercial\Domain\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Delete;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\Link;
|
|
use ApiPlatform\Metadata\Patch;
|
|
use ApiPlatform\Metadata\Post;
|
|
use App\Module\Commercial\Infrastructure\ApiPlatform\State\Processor\ClientRibProcessor;
|
|
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineClientRibRepository;
|
|
use App\Shared\Domain\Attribute\Auditable;
|
|
use App\Shared\Domain\Contract\BlamableInterface;
|
|
use App\Shared\Domain\Contract\TimestampableInterface;
|
|
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
/**
|
|
* Coordonnees bancaires d'un client (1:n) — onglet Comptabilite. Au moins un
|
|
* RIB est obligatoire si le type de reglement du client est LCR (RG-1.13,
|
|
* verifie au ClientRibProcessor : refus du DELETE du dernier RIB sous LCR).
|
|
*
|
|
* Audit (#[Auditable]) : TOUS les champs sont audites, y compris `iban` et
|
|
* `bic` — AUCUN #[AuditIgnore] (decision Matthieu en revue MR 29/05/2026 :
|
|
* l'audit etant admin-only, la tracabilite RIB est necessaire pour le suivi
|
|
* comptable et la conformite, cf. spec § 2.5 / § 6.1).
|
|
*
|
|
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony au M1
|
|
* (HP-M2-14 : pas de controle externe banque reelle). Timestampable/Blamable
|
|
* standard.
|
|
*
|
|
* Sous-ressource API (ERP-57, spec § 4.5) — gating comptable renforce :
|
|
* - POST /api/clients/{clientId}/ribs : creation rattachee au client parent
|
|
* (Link toProperty 'client'), security commercial.clients.accounting.manage.
|
|
* - PATCH / DELETE /api/client_ribs/{id} : security commercial.clients.accounting.manage.
|
|
* - GET /api/client_ribs/{id} : lecture unitaire, security
|
|
* commercial.clients.accounting.view (donnees bancaires sensibles). Pas de
|
|
* GET collection autonome.
|
|
* Tout passe par le ClientRibProcessor (RG-1.13 sur DELETE).
|
|
*/
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(
|
|
security: "is_granted('commercial.clients.accounting.view')",
|
|
normalizationContext: ['groups' => ['client_rib:read']],
|
|
),
|
|
new Post(
|
|
uriTemplate: '/clients/{clientId}/ribs',
|
|
uriVariables: [
|
|
'clientId' => new Link(fromClass: Client::class, toProperty: 'client'),
|
|
],
|
|
security: "is_granted('commercial.clients.accounting.manage')",
|
|
normalizationContext: ['groups' => ['client_rib:read']],
|
|
denormalizationContext: ['groups' => ['client_rib:write']],
|
|
processor: ClientRibProcessor::class,
|
|
),
|
|
new Patch(
|
|
security: "is_granted('commercial.clients.accounting.manage')",
|
|
normalizationContext: ['groups' => ['client_rib:read']],
|
|
denormalizationContext: ['groups' => ['client_rib:write']],
|
|
processor: ClientRibProcessor::class,
|
|
),
|
|
new Delete(
|
|
security: "is_granted('commercial.clients.accounting.manage')",
|
|
processor: ClientRibProcessor::class,
|
|
),
|
|
],
|
|
)]
|
|
#[ORM\Entity(repositoryClass: DoctrineClientRibRepository::class)]
|
|
#[ORM\Table(name: 'client_rib')]
|
|
#[ORM\Index(name: 'idx_client_rib_client', columns: ['client_id'])]
|
|
#[Auditable]
|
|
class ClientRib implements TimestampableInterface, BlamableInterface
|
|
{
|
|
use TimestampableBlamableTrait;
|
|
|
|
// Double groupe de lecture :
|
|
// - `client_rib:read` : sous-ressource autonome GET /api/client_ribs/{id}
|
|
// (deja securisee par commercial.clients.accounting.view).
|
|
// - `client:read:accounting` : embed des RIB sous le detail Client, ajoute
|
|
// DYNAMIQUEMENT par ClientReadGroupContextBuilder uniquement si l'user a
|
|
// accounting.view. Ce double marquage gate les RIB embarques au meme titre
|
|
// que les scalaires comptables (RG : la Commerciale ne voit aucun RIB).
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
#[Groups(['client_rib:read', 'client:read:accounting'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Client::class, inversedBy: 'ribs')]
|
|
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
|
private ?Client $client = null;
|
|
|
|
#[ORM\Column(length: 120)]
|
|
#[Assert\NotBlank]
|
|
#[Assert\Length(max: 120, normalizer: 'trim')]
|
|
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
|
private ?string $label = null;
|
|
|
|
#[ORM\Column(length: 20)]
|
|
#[Assert\NotBlank]
|
|
#[Assert\Bic]
|
|
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
|
private ?string $bic = null;
|
|
|
|
#[ORM\Column(length: 34)]
|
|
#[Assert\NotBlank]
|
|
#[Assert\Iban]
|
|
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
|
private ?string $iban = null;
|
|
|
|
#[ORM\Column(options: ['default' => 0])]
|
|
#[Groups(['client_rib:read', 'client:read:accounting', 'client_rib:write'])]
|
|
private int $position = 0;
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getClient(): ?Client
|
|
{
|
|
return $this->client;
|
|
}
|
|
|
|
public function setClient(?Client $client): static
|
|
{
|
|
$this->client = $client;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getLabel(): ?string
|
|
{
|
|
return $this->label;
|
|
}
|
|
|
|
public function setLabel(string $label): static
|
|
{
|
|
$this->label = $label;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getBic(): ?string
|
|
{
|
|
return $this->bic;
|
|
}
|
|
|
|
public function setBic(string $bic): static
|
|
{
|
|
$this->bic = $bic;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIban(): ?string
|
|
{
|
|
return $this->iban;
|
|
}
|
|
|
|
public function setIban(string $iban): static
|
|
{
|
|
$this->iban = $iban;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPosition(): int
|
|
{
|
|
return $this->position;
|
|
}
|
|
|
|
public function setPosition(int $position): static
|
|
{
|
|
$this->position = $position;
|
|
|
|
return $this;
|
|
}
|
|
}
|