feat(commercial) : entités + repositories M2 fournisseurs (ERP-86) (#65)
Auto Tag Develop / tag (push) Successful in 7s
Auto Tag Develop / tag (push) Successful in 7s
## ERP-86 — Entités + Repositories M2 Fournisseurs (étape 2/7) PR **empilée sur ERP-85** (#64) : ne contient que le commit ERP-86. À merger après #64 (la base rebascule automatiquement au fil des merges de la chaîne #63 → #64 → develop). Dépend de #64 (migration BDD). Bloque #87 (Provider + Processor) et suivants. ### Contenu 4 entités jumelles du M1 `Client*`, mapping ORM aligné **exactement** sur la migration ERP-85 (noms, types, longueurs, FK, M2M, index), **sans contact inline** (ERP-106) : - **`Supplier`** — `#[Auditable]` + Timestampable/Blamable. Formulaire principal, onglet Information (+ `volumeForecast`, spécifique fournisseur), onglet Comptabilité (FK référentiels M1 partagés), archivage (`isArchived`/`archivedAt`), soft-delete préparé. Catégories M2M via `CategoryInterface` (règle n°1, pas d'import inter-module). Pas de `distributor`/`broker`. - **`SupplierContact`** — onglet Contacts (RG-2.04 : `firstName` OU `lastName`). - **`SupplierAddress`** — enum `addressType` (`PROSPECT`/`DEPART`/`RENDU` via `Assert\Choice`), `bennes`, `triageProvider` ; M2M sites/contacts/categories. - **`SupplierRib`** — RIB, embed gaté comptable. - **Repositories** : interfaces `Domain/Repository/` + impls `Infrastructure/Doctrine/`. ### Points clés - **Contrat de sérialisation (RETEX M1, 3 maillons posés sur l'entité)** : read-groups sur les propriétés ; getters `isArchived()` / `isTriageProvider()` avec `#[Groups]` + `#[SerializedName('isX')]` (parade piège booléen n°3) ; embed `contacts`/`addresses` (`supplier:item:read`) et `ribs` (`supplier:read:accounting`). `getSites()` agrège/dédoublonne les `Site` des adresses (`name`/`postalCode`, pas de `code`). - **Fetch-joins anti-N+1** dans le **repository de liste** : `hydrateListCollections()` en 2 passes (`categories`, puis `addresses.sites`) — évite le produit cartésien (pattern ERP-100). Filtres : recherche `companyName` + contacts liés (D1), `categoryCode`, `siteId`, archivage. - **Pas d'`#[ApiResource]`** : Provider/Processor (gating accounting, archivage, mode strict) sont au ticket **ERP-87**. L'ajouter ici référencerait des classes inexistantes → boot/tests cassés. Les groupes de lecture/écriture sont déjà en place ; le `normalizationContext` viendra avec #87. - **Validation FR (ERP-107)** : messages FR sur toutes les contraintes ; `Assert\Length(max)` calé sur les colonnes. Garde-fou `EntityConstraintsHaveFrenchMessageTest` étendu : `Assert\Choice` ajouté au mapping ; `addressType` et `postalCode` whitelistés du miroir Length (déjà bornés par Choice / Regex). - Clés i18n `audit.entity.commercial_supplier*` ajoutées (garde-fou `AuditableEntitiesHaveI18nLabelTest`). ### Vérifications - `make test` : **483/483 OK** (1965 assertions). - `make php-cs-fixer-allow-risky` : 0 correction. - `doctrine:schema:validate` : mapping correct (bruit d'index FK cosmétique identique au M1 `client`). --------- Co-authored-by: admin malio <malio@yuno.malio.fr> Co-authored-by: Matthieu <contact@malio.fr> Reviewed-on: #65 Co-authored-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr> Co-committed-by: THOLOT DECHENE Matthieu <matthieu@yuno.malio.fr>
This commit was merged in pull request #65.
This commit is contained in:
@@ -0,0 +1,582 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Entity;
|
||||
|
||||
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineSupplierRepository;
|
||||
use App\Shared\Domain\Attribute\Auditable;
|
||||
use App\Shared\Domain\Contract\BlamableInterface;
|
||||
use App\Shared\Domain\Contract\CategoryInterface;
|
||||
use App\Shared\Domain\Contract\SiteInterface;
|
||||
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Fournisseur (M2 Commercial) — entite racine du repertoire fournisseurs,
|
||||
* jumelle du Client (M1). Porte le formulaire principal, l'onglet Information,
|
||||
* l'onglet Comptabilite, le mecanisme d'archivage (is_archived / archived_at) et
|
||||
* le soft-delete technique prepare mais non expose au M2 (deleted_at, HP M3).
|
||||
*
|
||||
* Decisions structurantes (cf. spec M2 § 2 / § 3.3) :
|
||||
* - Contact inline RETIRE (V0.2, refonte-contact ERP-106) : firstName / lastName
|
||||
* / phonePrimary / phoneSecondary / email ne sont plus portes par le
|
||||
* fournisseur — ils vivent uniquement dans SupplierContact (onglet Contacts).
|
||||
* La garantie « au moins un contact nomme » est portee par RG-2.04 + RG-2.13.
|
||||
* - PAS d'auto-reference distributor / broker (contrairement au Client).
|
||||
* - Ajout du champ Information volumeForecast (volume previsionnel, entier),
|
||||
* specifique fournisseur.
|
||||
* - Audit complet (#[Auditable]) sur tous les champs (M2M categories audite
|
||||
* automatiquement). Timestampable / Blamable via le trait Shared.
|
||||
* - PAS de #[ORM\UniqueConstraint] : l'unicite du nom de societe (RG-2.11) est
|
||||
* portee par l'index partiel fonctionnel uq_supplier_company_name_active
|
||||
* (LOWER(company_name) WHERE is_archived = FALSE AND deleted_at IS NULL),
|
||||
* inexprimable en attribut ORM, donc possede par la seule migration. SIREN et
|
||||
* email NE SONT PAS uniques (§ 2.6).
|
||||
* - categories : M2M vers Category (module Catalog) via le contrat
|
||||
* CategoryInterface + resolve_target_entities (regle n°1, pas d'import direct).
|
||||
*
|
||||
* Contrat de serialisation (RETEX M1, 3 maillons — spec § 4.0) : les read-groups
|
||||
* sont poses ICI (source unique). L'#[ApiResource] et le SupplierProvider /
|
||||
* SupplierProcessor (gating accounting, archivage, mode strict) sont branches au
|
||||
* ticket suivant (ERP-87).
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: DoctrineSupplierRepository::class)]
|
||||
#[ORM\Table(name: 'supplier')]
|
||||
// Index nommes pour matcher la migration (Version20260605130000). L'index unique
|
||||
// partiel uq_supplier_company_name_active reste possede par la migration :
|
||||
// Doctrine ORM ne sait pas exprimer un index fonctionnel (LOWER) + partiel
|
||||
// (WHERE) via attribut. Pas de #[ORM\UniqueConstraint] (§ 2.6).
|
||||
#[ORM\Index(name: 'idx_supplier_is_archived', columns: ['is_archived'])]
|
||||
#[ORM\Index(name: 'idx_supplier_deleted_at', columns: ['deleted_at'])]
|
||||
#[ORM\Index(name: 'idx_supplier_created_by', columns: ['created_by'])]
|
||||
#[ORM\Index(name: 'idx_supplier_updated_by', columns: ['updated_by'])]
|
||||
#[Auditable]
|
||||
class Supplier implements TimestampableInterface, BlamableInterface
|
||||
{
|
||||
use TimestampableBlamableTrait;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['supplier:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
// === Formulaire principal ===
|
||||
#[ORM\Column(length: 180)]
|
||||
#[Assert\NotBlank(message: 'Le nom du fournisseur est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Length(min: 2, max: 180, minMessage: 'Le nom du fournisseur doit comporter au moins {{ limit }} caractères.', maxMessage: 'Le nom du fournisseur ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:read', 'supplier:write:main'])]
|
||||
private ?string $companyName = null;
|
||||
|
||||
// RG : au moins une categorie (Count min 1), de type FOURNISSEUR (RG-2.10,
|
||||
// verifiee au Processor/Validator a ERP-89). M2M vers Category via le contrat
|
||||
// CategoryInterface (resolve_target_entities -> Category). Embarquee en LISTE
|
||||
// ET DETAIL (coherence M1/ERP-62) ; maillon (c) : le contexte inclut
|
||||
// 'category:read' pour exposer id/code/name.
|
||||
/** @var Collection<int, CategoryInterface> */
|
||||
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
||||
#[ORM\JoinTable(name: 'supplier_category')]
|
||||
#[ORM\JoinColumn(name: 'supplier_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||
#[Assert\Count(min: 1, minMessage: 'Au moins une catégorie est obligatoire.')]
|
||||
#[Groups(['supplier:read', 'supplier:write:main'])]
|
||||
private Collection $categories;
|
||||
|
||||
// === Onglet Information ===
|
||||
#[ORM\Column(type: 'text', nullable: true)]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Assert\Length(max: 255, maxMessage: 'Ce champ ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?string $competitors = null;
|
||||
|
||||
#[ORM\Column(type: 'date_immutable', nullable: true)]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?DateTimeImmutable $foundedAt = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
#[Assert\PositiveOrZero(message: 'L\'effectif doit être un nombre positif ou nul.')]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?int $employeesCount = null;
|
||||
|
||||
#[ORM\Column(type: 'decimal', precision: 15, scale: 2, nullable: true)]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?string $revenueAmount = null;
|
||||
|
||||
#[ORM\Column(length: 120, nullable: true)]
|
||||
#[Assert\Length(max: 120, maxMessage: 'Le nom du dirigeant ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?string $directorName = null;
|
||||
|
||||
#[ORM\Column(type: 'decimal', precision: 15, scale: 2, nullable: true)]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?string $profitAmount = null;
|
||||
|
||||
// NEW vs Client : Volume previsionnel (entier).
|
||||
#[ORM\Column(nullable: true)]
|
||||
#[Assert\PositiveOrZero(message: 'Le volume prévisionnel doit être un nombre positif ou nul.')]
|
||||
#[Groups(['supplier:read', 'supplier:write:information'])]
|
||||
private ?int $volumeForecast = null;
|
||||
|
||||
// === Onglet Comptabilite ===
|
||||
// Lecture conditionnee via le groupe `supplier:read:accounting` (ajoute au
|
||||
// contexte par le SupplierProvider si l'user a accounting.view, ERP-87).
|
||||
// Ecriture via `supplier:write:accounting` (le Processor exige accounting.manage).
|
||||
#[ORM\Column(length: 20, nullable: true)]
|
||||
#[Assert\Length(max: 20, maxMessage: 'Le SIREN ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?string $siren = null;
|
||||
|
||||
#[ORM\Column(length: 40, nullable: true)]
|
||||
#[Assert\Length(max: 40, maxMessage: 'Le numéro de compte ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?string $accountNumber = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: TvaMode::class)]
|
||||
#[ORM\JoinColumn(name: 'tva_mode_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?TvaMode $tvaMode = null;
|
||||
|
||||
#[ORM\Column(length: 40, nullable: true)]
|
||||
#[Assert\Length(max: 40, maxMessage: 'Le numéro de TVA ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?string $nTva = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: PaymentDelay::class)]
|
||||
#[ORM\JoinColumn(name: 'payment_delay_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?PaymentDelay $paymentDelay = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: PaymentType::class)]
|
||||
#[ORM\JoinColumn(name: 'payment_type_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?PaymentType $paymentType = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Bank::class)]
|
||||
#[ORM\JoinColumn(name: 'bank_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?Bank $bank = null;
|
||||
|
||||
// === Sous-collections — EMBARQUEES dans le DETAIL (RETEX M1 §2) ===
|
||||
// Maillon (a) : le read-group est porte par le GETTER (getContacts / getAddresses
|
||||
// / getRibs) — sans #[Groups], jamais serialisees. Edition via sous-ressources
|
||||
// POST/PATCH/DELETE (ERP-88).
|
||||
/** @var Collection<int, SupplierContact> */
|
||||
#[ORM\OneToMany(mappedBy: 'supplier', targetEntity: SupplierContact::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
private Collection $contacts;
|
||||
|
||||
/** @var Collection<int, SupplierAddress> */
|
||||
#[ORM\OneToMany(mappedBy: 'supplier', targetEntity: SupplierAddress::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
private Collection $addresses;
|
||||
|
||||
/** @var Collection<int, SupplierRib> */
|
||||
#[ORM\OneToMany(mappedBy: 'supplier', targetEntity: SupplierRib::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
private Collection $ribs;
|
||||
|
||||
// === Archive / Soft delete ===
|
||||
// Groupe d'ECRITURE uniquement sur la propriete (denormalisation PATCH archive).
|
||||
// Le groupe de LECTURE est declare sur le getter isArchived() avec
|
||||
// SerializedName('isArchived') : sans cela, Symfony strip le prefixe "is" et
|
||||
// exposerait la cle JSON "archived" — en pratique la cle est totalement
|
||||
// DROPPEE (piege n°3 du M1). Pattern corrige : Groups + SerializedName sur le getter.
|
||||
#[ORM\Column(name: 'is_archived', options: ['default' => false])]
|
||||
#[Groups(['supplier:write:archive'])]
|
||||
private bool $isArchived = false;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
||||
#[Groups(['supplier:read'])]
|
||||
private ?DateTimeImmutable $archivedAt = null;
|
||||
|
||||
// Soft delete technique (HP M3) : non expose en lecture/ecriture au M2.
|
||||
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
||||
private ?DateTimeImmutable $deletedAt = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->categories = new ArrayCollection();
|
||||
$this->contacts = new ArrayCollection();
|
||||
$this->addresses = new ArrayCollection();
|
||||
$this->ribs = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCompanyName(): ?string
|
||||
{
|
||||
return $this->companyName;
|
||||
}
|
||||
|
||||
public function setCompanyName(string $companyName): static
|
||||
{
|
||||
$this->companyName = $companyName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, CategoryInterface> */
|
||||
public function getCategories(): Collection
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
public function addCategory(CategoryInterface $category): static
|
||||
{
|
||||
if (!$this->categories->contains($category)) {
|
||||
$this->categories->add($category);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCategory(CategoryInterface $category): static
|
||||
{
|
||||
$this->categories->removeElement($category);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCompetitors(): ?string
|
||||
{
|
||||
return $this->competitors;
|
||||
}
|
||||
|
||||
public function setCompetitors(?string $competitors): static
|
||||
{
|
||||
$this->competitors = $competitors;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFoundedAt(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->foundedAt;
|
||||
}
|
||||
|
||||
public function setFoundedAt(?DateTimeImmutable $foundedAt): static
|
||||
{
|
||||
$this->foundedAt = $foundedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmployeesCount(): ?int
|
||||
{
|
||||
return $this->employeesCount;
|
||||
}
|
||||
|
||||
public function setEmployeesCount(?int $employeesCount): static
|
||||
{
|
||||
$this->employeesCount = $employeesCount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRevenueAmount(): ?string
|
||||
{
|
||||
return $this->revenueAmount;
|
||||
}
|
||||
|
||||
public function setRevenueAmount(?string $revenueAmount): static
|
||||
{
|
||||
$this->revenueAmount = $revenueAmount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDirectorName(): ?string
|
||||
{
|
||||
return $this->directorName;
|
||||
}
|
||||
|
||||
public function setDirectorName(?string $directorName): static
|
||||
{
|
||||
$this->directorName = $directorName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProfitAmount(): ?string
|
||||
{
|
||||
return $this->profitAmount;
|
||||
}
|
||||
|
||||
public function setProfitAmount(?string $profitAmount): static
|
||||
{
|
||||
$this->profitAmount = $profitAmount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVolumeForecast(): ?int
|
||||
{
|
||||
return $this->volumeForecast;
|
||||
}
|
||||
|
||||
public function setVolumeForecast(?int $volumeForecast): static
|
||||
{
|
||||
$this->volumeForecast = $volumeForecast;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSiren(): ?string
|
||||
{
|
||||
return $this->siren;
|
||||
}
|
||||
|
||||
public function setSiren(?string $siren): static
|
||||
{
|
||||
$this->siren = $siren;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAccountNumber(): ?string
|
||||
{
|
||||
return $this->accountNumber;
|
||||
}
|
||||
|
||||
public function setAccountNumber(?string $accountNumber): static
|
||||
{
|
||||
$this->accountNumber = $accountNumber;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTvaMode(): ?TvaMode
|
||||
{
|
||||
return $this->tvaMode;
|
||||
}
|
||||
|
||||
public function setTvaMode(?TvaMode $tvaMode): static
|
||||
{
|
||||
$this->tvaMode = $tvaMode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNTva(): ?string
|
||||
{
|
||||
return $this->nTva;
|
||||
}
|
||||
|
||||
public function setNTva(?string $nTva): static
|
||||
{
|
||||
$this->nTva = $nTva;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPaymentDelay(): ?PaymentDelay
|
||||
{
|
||||
return $this->paymentDelay;
|
||||
}
|
||||
|
||||
public function setPaymentDelay(?PaymentDelay $paymentDelay): static
|
||||
{
|
||||
$this->paymentDelay = $paymentDelay;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPaymentType(): ?PaymentType
|
||||
{
|
||||
return $this->paymentType;
|
||||
}
|
||||
|
||||
public function setPaymentType(?PaymentType $paymentType): static
|
||||
{
|
||||
$this->paymentType = $paymentType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBank(): ?Bank
|
||||
{
|
||||
return $this->bank;
|
||||
}
|
||||
|
||||
public function setBank(?Bank $bank): static
|
||||
{
|
||||
$this->bank = $bank;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, SupplierContact> */
|
||||
#[Groups(['supplier:item:read'])]
|
||||
public function getContacts(): Collection
|
||||
{
|
||||
return $this->contacts;
|
||||
}
|
||||
|
||||
public function addContact(SupplierContact $contact): static
|
||||
{
|
||||
if (!$this->contacts->contains($contact)) {
|
||||
$this->contacts->add($contact);
|
||||
$contact->setSupplier($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeContact(SupplierContact $contact): static
|
||||
{
|
||||
if ($this->contacts->removeElement($contact) && $contact->getSupplier() === $this) {
|
||||
$contact->setSupplier(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, SupplierAddress> */
|
||||
#[Groups(['supplier:item:read'])]
|
||||
public function getAddresses(): Collection
|
||||
{
|
||||
return $this->addresses;
|
||||
}
|
||||
|
||||
public function addAddress(SupplierAddress $address): static
|
||||
{
|
||||
if (!$this->addresses->contains($address)) {
|
||||
$this->addresses->add($address);
|
||||
$address->setSupplier($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAddress(SupplierAddress $address): static
|
||||
{
|
||||
if ($this->addresses->removeElement($address) && $address->getSupplier() === $this) {
|
||||
$address->setSupplier(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sites distincts rattaches a au moins une adresse du fournisseur (RG-2.06).
|
||||
* Le fournisseur ne porte pas de sites en propre : ils vivent sur les
|
||||
* adresses. Agrege en lecture seule pour la colonne « Site(s) » du Repertoire
|
||||
* (badges colores) — expose en LISTE via le groupe supplier:read (les adresses
|
||||
* completes restent reservees au detail, supplier:item:read). Site n'a pas de
|
||||
* champ `code` : libelle = `name`, prefixe = `postalCode` (§ 2.4 / § 4.0.ter).
|
||||
*
|
||||
* Fetch-join obligatoire (addresses.sites) cote repository pour eviter le N+1
|
||||
* a la serialisation de la liste (cf. DoctrineSupplierRepository, § 2.12).
|
||||
*
|
||||
* @return list<SiteInterface>
|
||||
*/
|
||||
#[Groups(['supplier:read'])]
|
||||
public function getSites(): array
|
||||
{
|
||||
$sites = [];
|
||||
foreach ($this->addresses as $address) {
|
||||
foreach ($address->getSites() as $site) {
|
||||
// Deduplication par identite d'objet : un meme site peut etre
|
||||
// rattache a plusieurs adresses du fournisseur.
|
||||
$sites[spl_object_id($site)] = $site;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($sites);
|
||||
}
|
||||
|
||||
// Embed gate sur le groupe COMPTABLE (et non supplier:item:read comme contacts/
|
||||
// adresses) : supplier:read:accounting n'est ajoute au contexte que si l'user a
|
||||
// accounting.view (SupplierProvider, ERP-87). Resultat : la cle `ribs` est
|
||||
// TOTALEMENT ABSENTE du detail pour un user sans accounting.view (ex. Commerciale),
|
||||
// au meme titre que les scalaires comptables — evite la fuite IBAN/BIC (piege n°4 M1).
|
||||
/** @return Collection<int, SupplierRib> */
|
||||
#[Groups(['supplier:read:accounting'])]
|
||||
public function getRibs(): Collection
|
||||
{
|
||||
return $this->ribs;
|
||||
}
|
||||
|
||||
public function addRib(SupplierRib $rib): static
|
||||
{
|
||||
if (!$this->ribs->contains($rib)) {
|
||||
$this->ribs->add($rib);
|
||||
$rib->setSupplier($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRib(SupplierRib $rib): static
|
||||
{
|
||||
if ($this->ribs->removeElement($rib) && $rib->getSupplier() === $this) {
|
||||
$rib->setSupplier(null);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Groupe de lecture + nom serialise explicite : sans SerializedName, Symfony
|
||||
// exposerait la cle "archived" (strip du prefixe "is" sur les getters) et
|
||||
// droppait silencieusement la cle du JSON (piege n°3 du M1).
|
||||
#[Groups(['supplier:read'])]
|
||||
#[SerializedName('isArchived')]
|
||||
public function isArchived(): bool
|
||||
{
|
||||
return $this->isArchived;
|
||||
}
|
||||
|
||||
public function setIsArchived(bool $isArchived): static
|
||||
{
|
||||
$this->isArchived = $isArchived;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getArchivedAt(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->archivedAt;
|
||||
}
|
||||
|
||||
public function setArchivedAt(?DateTimeImmutable $archivedAt): static
|
||||
{
|
||||
$this->archivedAt = $archivedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDeletedAt(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->deletedAt;
|
||||
}
|
||||
|
||||
public function setDeletedAt(?DateTimeImmutable $deletedAt): static
|
||||
{
|
||||
$this->deletedAt = $deletedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Entity;
|
||||
|
||||
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineSupplierAddressRepository;
|
||||
use App\Shared\Domain\Attribute\Auditable;
|
||||
use App\Shared\Domain\Contract\BlamableInterface;
|
||||
use App\Shared\Domain\Contract\CategoryInterface;
|
||||
use App\Shared\Domain\Contract\SiteInterface;
|
||||
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Adresse d'un fournisseur (1:n) — onglet Adresse. Le type d'adresse est un enum
|
||||
* exclusif PROSPECT | DEPART | RENDU (radio cote front — RG-2.09), qui remplace
|
||||
* les 3 booleens prospect/livraison/facturation du Client (M1) ; pas d'email de
|
||||
* facturation au M2. Ajoute deux champs specifiques fournisseur : `bennes`
|
||||
* (entier nullable) et `triageProvider` (prestataire de triage, booleen).
|
||||
*
|
||||
* Relations M2M :
|
||||
* - sites : SiteInterface (module Sites) via resolve_target_entities — au moins
|
||||
* un site obligatoire (RG-2.06, Assert\Count). Site n'a pas de `code`.
|
||||
* - contacts : SupplierContact (meme module).
|
||||
* - categories : CategoryInterface (module Catalog) via resolve_target_entities —
|
||||
* type FOURNISSEUR attendu (RG-2.10, controle au Processor/Validator ERP-89).
|
||||
*
|
||||
* Embarquee sous `supplier.addresses` au detail (groupe supplier:item:read,
|
||||
* maillon (a)). Edition via la sous-ressource (POST /api/suppliers/{id}/addresses,
|
||||
* PATCH/DELETE /api/supplier_addresses/{id}), branchee a ERP-88.
|
||||
*
|
||||
* Audite (#[Auditable]) + Timestampable / Blamable.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: DoctrineSupplierAddressRepository::class)]
|
||||
#[ORM\Table(name: 'supplier_address')]
|
||||
#[ORM\Index(name: 'idx_supplier_address_supplier', columns: ['supplier_id'])]
|
||||
#[Auditable]
|
||||
class SupplierAddress implements TimestampableInterface, BlamableInterface
|
||||
{
|
||||
use TimestampableBlamableTrait;
|
||||
|
||||
/**
|
||||
* Valeurs autorisees de address_type (RG-2.09). Miroir applicatif du CHECK BDD
|
||||
* chk_supplier_address_type : alimente l'Assert\Choice (422 propre rattachee
|
||||
* au champ avant la base) et reste la source des options cote front.
|
||||
*/
|
||||
public const array ADDRESS_TYPES = ['PROSPECT', 'DEPART', 'RENDU'];
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['supplier:item:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Supplier::class, inversedBy: 'addresses')]
|
||||
#[ORM\JoinColumn(name: 'supplier_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||
private ?Supplier $supplier = null;
|
||||
|
||||
// RG-2.09 : enum exclusif. La valeur est bornee par Assert\Choice (longueur de
|
||||
// fait <= 8), d'ou la whitelist du miroir Assert\Length == ORM length (ERP-107,
|
||||
// EntityConstraintsHaveFrenchMessageTest::EXCLUDED_LENGTH_MIRROR).
|
||||
#[ORM\Column(length: 20)]
|
||||
#[Assert\NotBlank(message: 'Le type d\'adresse est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Choice(choices: self::ADDRESS_TYPES, message: 'Le type d\'adresse doit être Prospect, Départ ou Rendu.')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private ?string $addressType = null;
|
||||
|
||||
#[ORM\Column(length: 80, options: ['default' => 'France'])]
|
||||
#[Assert\Length(max: 80, maxMessage: 'Le pays ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private string $country = 'France';
|
||||
|
||||
// RG-2.05 : code postal a 4 ou 5 chiffres (pas de controle CP/ville serveur).
|
||||
// Le Regex borne deja la longueur (<= 5) : pas de Length redondant (whitelist).
|
||||
#[ORM\Column(length: 20)]
|
||||
#[Assert\NotBlank(message: 'Le code postal est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Regex(pattern: '/^[0-9]{4,5}$/', message: 'Le code postal doit comporter 4 ou 5 chiffres.')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private ?string $postalCode = null;
|
||||
|
||||
#[ORM\Column(length: 120)]
|
||||
#[Assert\NotBlank(message: 'La ville est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Length(max: 120, maxMessage: 'La ville ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private ?string $city = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Assert\NotBlank(message: 'La rue est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Length(max: 255, maxMessage: 'La rue ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private ?string $street = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Assert\Length(max: 255, maxMessage: 'Le complément d\'adresse ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private ?string $streetComplement = null;
|
||||
|
||||
// Specifique fournisseur : nombre de bennes sur le site.
|
||||
#[ORM\Column(nullable: true)]
|
||||
#[Assert\PositiveOrZero(message: 'Le nombre de bennes doit être un nombre positif ou nul.')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private ?int $bennes = null;
|
||||
|
||||
// Specifique fournisseur : prestataire de triage sur cette adresse. Groupe
|
||||
// d'ECRITURE uniquement sur la propriete ; le groupe de LECTURE est porte par
|
||||
// le getter isTriageProvider() avec SerializedName('triageProvider') — sinon
|
||||
// Symfony strip le prefixe "is" et droppe la cle (piege n°3 du M1).
|
||||
#[ORM\Column(name: 'triage_provider', options: ['default' => false])]
|
||||
#[Groups(['supplier:write:addresses'])]
|
||||
private bool $triageProvider = false;
|
||||
|
||||
// Ordre d'affichage de l'adresse (gere serveur, non expose au M2).
|
||||
#[ORM\Column(options: ['default' => 0])]
|
||||
private int $position = 0;
|
||||
|
||||
// RG-2.06 : au moins un site rattache a chaque adresse.
|
||||
/** @var Collection<int, SiteInterface> */
|
||||
#[ORM\ManyToMany(targetEntity: SiteInterface::class)]
|
||||
#[ORM\JoinTable(name: 'supplier_address_site')]
|
||||
#[ORM\JoinColumn(name: 'supplier_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
#[ORM\InverseJoinColumn(name: 'site_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||
#[Assert\Count(min: 1, minMessage: 'Au moins un site est obligatoire.')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private Collection $sites;
|
||||
|
||||
/** @var Collection<int, SupplierContact> */
|
||||
#[ORM\ManyToMany(targetEntity: SupplierContact::class)]
|
||||
#[ORM\JoinTable(name: 'supplier_address_contact')]
|
||||
#[ORM\JoinColumn(name: 'supplier_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
#[ORM\InverseJoinColumn(name: 'supplier_contact_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private Collection $contacts;
|
||||
|
||||
// RG-2.10 : categories d'adresse de type FOURNISSEUR (controle au Processor).
|
||||
/** @var Collection<int, CategoryInterface> */
|
||||
#[ORM\ManyToMany(targetEntity: CategoryInterface::class)]
|
||||
#[ORM\JoinTable(name: 'supplier_address_category')]
|
||||
#[ORM\JoinColumn(name: 'supplier_address_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
|
||||
#[ORM\InverseJoinColumn(name: 'category_id', referencedColumnName: 'id', onDelete: 'RESTRICT')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:addresses'])]
|
||||
private Collection $categories;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->sites = new ArrayCollection();
|
||||
$this->contacts = new ArrayCollection();
|
||||
$this->categories = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getSupplier(): ?Supplier
|
||||
{
|
||||
return $this->supplier;
|
||||
}
|
||||
|
||||
public function setSupplier(?Supplier $supplier): static
|
||||
{
|
||||
$this->supplier = $supplier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAddressType(): ?string
|
||||
{
|
||||
return $this->addressType;
|
||||
}
|
||||
|
||||
public function setAddressType(?string $addressType): static
|
||||
{
|
||||
$this->addressType = $addressType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCountry(): string
|
||||
{
|
||||
return $this->country;
|
||||
}
|
||||
|
||||
public function setCountry(string $country): static
|
||||
{
|
||||
$this->country = $country;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPostalCode(): ?string
|
||||
{
|
||||
return $this->postalCode;
|
||||
}
|
||||
|
||||
public function setPostalCode(?string $postalCode): static
|
||||
{
|
||||
$this->postalCode = $postalCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCity(): ?string
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
public function setCity(?string $city): static
|
||||
{
|
||||
$this->city = $city;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStreet(): ?string
|
||||
{
|
||||
return $this->street;
|
||||
}
|
||||
|
||||
public function setStreet(?string $street): static
|
||||
{
|
||||
$this->street = $street;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStreetComplement(): ?string
|
||||
{
|
||||
return $this->streetComplement;
|
||||
}
|
||||
|
||||
public function setStreetComplement(?string $streetComplement): static
|
||||
{
|
||||
$this->streetComplement = $streetComplement;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBennes(): ?int
|
||||
{
|
||||
return $this->bennes;
|
||||
}
|
||||
|
||||
public function setBennes(?int $bennes): static
|
||||
{
|
||||
$this->bennes = $bennes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Groupe de lecture + nom serialise explicite (cf. note sur la propriete) :
|
||||
// sans SerializedName, Symfony exposerait la cle "triage" (strip du prefixe
|
||||
// "is") et, le groupe etant sur la propriete `triageProvider`, droppait
|
||||
// silencieusement la cle du JSON.
|
||||
#[Groups(['supplier:item:read'])]
|
||||
#[SerializedName('triageProvider')]
|
||||
public function isTriageProvider(): bool
|
||||
{
|
||||
return $this->triageProvider;
|
||||
}
|
||||
|
||||
public function setTriageProvider(bool $triageProvider): static
|
||||
{
|
||||
$this->triageProvider = $triageProvider;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function setPosition(int $position): static
|
||||
{
|
||||
$this->position = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, SiteInterface> */
|
||||
public function getSites(): Collection
|
||||
{
|
||||
return $this->sites;
|
||||
}
|
||||
|
||||
public function addSite(SiteInterface $site): static
|
||||
{
|
||||
if (!$this->sites->contains($site)) {
|
||||
$this->sites->add($site);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeSite(SiteInterface $site): static
|
||||
{
|
||||
$this->sites->removeElement($site);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, SupplierContact> */
|
||||
public function getContacts(): Collection
|
||||
{
|
||||
return $this->contacts;
|
||||
}
|
||||
|
||||
public function addContact(SupplierContact $contact): static
|
||||
{
|
||||
if (!$this->contacts->contains($contact)) {
|
||||
$this->contacts->add($contact);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeContact(SupplierContact $contact): static
|
||||
{
|
||||
$this->contacts->removeElement($contact);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, CategoryInterface> */
|
||||
public function getCategories(): Collection
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
public function addCategory(CategoryInterface $category): static
|
||||
{
|
||||
if (!$this->categories->contains($category)) {
|
||||
$this->categories->add($category);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeCategory(CategoryInterface $category): static
|
||||
{
|
||||
$this->categories->removeElement($category);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Entity;
|
||||
|
||||
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineSupplierContactRepository;
|
||||
use App\Shared\Domain\Attribute\Auditable;
|
||||
use App\Shared\Domain\Contract\BlamableInterface;
|
||||
use App\Shared\Domain\Contract\TimestampableInterface;
|
||||
use App\Shared\Domain\Trait\TimestampableBlamableTrait;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Contact d'un fournisseur (1:n) — onglet Contacts. Au moins firstName OU
|
||||
* lastName doit etre renseigne (RG-2.04) : contrainte portee par un CHECK BDD
|
||||
* (chk_supplier_contact_name) et validee au Processor (ERP-88) ; l'entite reste
|
||||
* permissive (les deux champs sont nullable).
|
||||
*
|
||||
* Embarque sous `supplier.contacts` au detail (groupe supplier:item:read,
|
||||
* maillon (a) du contrat de serialisation). Edition via la sous-ressource
|
||||
* (POST /api/suppliers/{id}/contacts, PATCH/DELETE /api/supplier_contacts/{id}),
|
||||
* branchee a ERP-88 (l'#[ApiResource] sera ajoute alors).
|
||||
*
|
||||
* Audite (#[Auditable]) + Timestampable / Blamable (pattern Shared standard).
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: DoctrineSupplierContactRepository::class)]
|
||||
#[ORM\Table(name: 'supplier_contact')]
|
||||
#[ORM\Index(name: 'idx_supplier_contact_supplier', columns: ['supplier_id'])]
|
||||
#[Auditable]
|
||||
class SupplierContact implements TimestampableInterface, BlamableInterface
|
||||
{
|
||||
use TimestampableBlamableTrait;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['supplier:item:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Supplier::class, inversedBy: 'contacts')]
|
||||
#[ORM\JoinColumn(name: 'supplier_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||
private ?Supplier $supplier = null;
|
||||
|
||||
// RG-2.04 : firstName OU lastName obligatoire (CHECK BDD + Processor). Les
|
||||
// deux restent nullable au niveau ORM.
|
||||
#[ORM\Column(length: 120, nullable: true)]
|
||||
#[Assert\Length(max: 120, maxMessage: 'Le prénom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
||||
private ?string $firstName = null;
|
||||
|
||||
#[ORM\Column(length: 120, nullable: true)]
|
||||
#[Assert\Length(max: 120, maxMessage: 'Le nom ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
||||
private ?string $lastName = null;
|
||||
|
||||
#[ORM\Column(length: 120, nullable: true)]
|
||||
#[Assert\Length(max: 120, maxMessage: 'La fonction ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
||||
private ?string $jobTitle = null;
|
||||
|
||||
// RG : pas de validation de format telephone (saisie libre), mais une
|
||||
// Assert\Length calee sur la colonne VARCHAR(20) evite l'erreur Postgres
|
||||
// (500 non rattachee au champ) au profit d'une 422 propre (ERP-107).
|
||||
#[ORM\Column(length: 20, nullable: true)]
|
||||
#[Assert\Length(max: 20, maxMessage: 'Le téléphone ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
||||
private ?string $phonePrimary = null;
|
||||
|
||||
#[ORM\Column(length: 20, nullable: true)]
|
||||
#[Assert\Length(max: 20, maxMessage: 'Le téléphone secondaire ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
||||
private ?string $phoneSecondary = null;
|
||||
|
||||
#[ORM\Column(length: 180, nullable: true)]
|
||||
#[Assert\Email(message: 'L\'adresse email n\'est pas valide.')]
|
||||
#[Assert\Length(max: 180, maxMessage: 'L\'email ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:item:read', 'supplier:write:contacts'])]
|
||||
private ?string $email = null;
|
||||
|
||||
// Ordre d'affichage du contact (gere serveur, non expose au M2).
|
||||
#[ORM\Column(options: ['default' => 0])]
|
||||
private int $position = 0;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getSupplier(): ?Supplier
|
||||
{
|
||||
return $this->supplier;
|
||||
}
|
||||
|
||||
public function setSupplier(?Supplier $supplier): static
|
||||
{
|
||||
$this->supplier = $supplier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirstName(): ?string
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
public function setFirstName(?string $firstName): static
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastName(): ?string
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
public function setLastName(?string $lastName): static
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getJobTitle(): ?string
|
||||
{
|
||||
return $this->jobTitle;
|
||||
}
|
||||
|
||||
public function setJobTitle(?string $jobTitle): static
|
||||
{
|
||||
$this->jobTitle = $jobTitle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhonePrimary(): ?string
|
||||
{
|
||||
return $this->phonePrimary;
|
||||
}
|
||||
|
||||
public function setPhonePrimary(?string $phonePrimary): static
|
||||
{
|
||||
$this->phonePrimary = $phonePrimary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhoneSecondary(): ?string
|
||||
{
|
||||
return $this->phoneSecondary;
|
||||
}
|
||||
|
||||
public function setPhoneSecondary(?string $phoneSecondary): static
|
||||
{
|
||||
$this->phoneSecondary = $phoneSecondary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(?string $email): static
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function setPosition(int $position): static
|
||||
{
|
||||
$this->position = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Entity;
|
||||
|
||||
use App\Module\Commercial\Infrastructure\Doctrine\DoctrineSupplierRibRepository;
|
||||
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 fournisseur (1:n) — onglet Comptabilite. Au moins un
|
||||
* RIB est obligatoire si le type de reglement est LCR (RG-2.08, verifie au
|
||||
* Processor : refus du DELETE du dernier RIB sous LCR, ERP-88).
|
||||
*
|
||||
* Embarque sous `supplier.ribs` UNIQUEMENT si l'user a accounting.view : le
|
||||
* read-group est `supplier:read:accounting`, retire du contexte par le
|
||||
* SupplierProvider sinon (gating par omission de cle — evite la fuite IBAN/BIC,
|
||||
* piege n°4 du M1). Aucun #[AuditIgnore] sur iban/bic : l'audit etant admin-only,
|
||||
* la tracabilite RIB est conservee (decision M1 reportee, § 2.7).
|
||||
*
|
||||
* Validation IBAN/BIC : Assert\Iban + Assert\Bic standard Symfony (pas de controle
|
||||
* banque reelle). Audite (#[Auditable]) + Timestampable / Blamable.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: DoctrineSupplierRibRepository::class)]
|
||||
#[ORM\Table(name: 'supplier_rib')]
|
||||
#[ORM\Index(name: 'idx_supplier_rib_supplier', columns: ['supplier_id'])]
|
||||
#[Auditable]
|
||||
class SupplierRib implements TimestampableInterface, BlamableInterface
|
||||
{
|
||||
use TimestampableBlamableTrait;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['supplier:read:accounting'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Supplier::class, inversedBy: 'ribs')]
|
||||
#[ORM\JoinColumn(name: 'supplier_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
|
||||
private ?Supplier $supplier = null;
|
||||
|
||||
#[ORM\Column(length: 120)]
|
||||
#[Assert\NotBlank(message: 'Le libellé du RIB est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Length(max: 120, maxMessage: 'Le libellé ne peut dépasser {{ limit }} caractères.', normalizer: 'trim')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?string $label = null;
|
||||
|
||||
// Bic/Iban bornent deja le format (et donc la longueur) : pas de Length
|
||||
// redondant calee sur la colonne (auto-exempte du miroir ERP-107).
|
||||
#[ORM\Column(length: 20)]
|
||||
#[Assert\NotBlank(message: 'Le BIC est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Bic(message: 'Le BIC n\'est pas valide.')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?string $bic = null;
|
||||
|
||||
#[ORM\Column(length: 34)]
|
||||
#[Assert\NotBlank(message: 'L\'IBAN est obligatoire.', normalizer: 'trim')]
|
||||
#[Assert\Iban(message: 'L\'IBAN n\'est pas valide.')]
|
||||
#[Groups(['supplier:read:accounting', 'supplier:write:accounting'])]
|
||||
private ?string $iban = null;
|
||||
|
||||
// Ordre d'affichage du RIB (gere serveur, non expose au M2).
|
||||
#[ORM\Column(options: ['default' => 0])]
|
||||
private int $position = 0;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getSupplier(): ?Supplier
|
||||
{
|
||||
return $this->supplier;
|
||||
}
|
||||
|
||||
public function setSupplier(?Supplier $supplier): static
|
||||
{
|
||||
$this->supplier = $supplier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setLabel(string $label): static
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBic(): ?string
|
||||
{
|
||||
return $this->bic;
|
||||
}
|
||||
|
||||
public function setBic(string $bic): static
|
||||
{
|
||||
$this->bic = $bic;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIban(): ?string
|
||||
{
|
||||
return $this->iban;
|
||||
}
|
||||
|
||||
public function setIban(string $iban): static
|
||||
{
|
||||
$this->iban = $iban;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPosition(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function setPosition(int $position): static
|
||||
{
|
||||
$this->position = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Repository;
|
||||
|
||||
use App\Module\Commercial\Domain\Entity\SupplierAddress;
|
||||
|
||||
interface SupplierAddressRepositoryInterface
|
||||
{
|
||||
public function findById(int $id): ?SupplierAddress;
|
||||
|
||||
public function save(SupplierAddress $address): void;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Repository;
|
||||
|
||||
use App\Module\Commercial\Domain\Entity\SupplierContact;
|
||||
|
||||
interface SupplierContactRepositoryInterface
|
||||
{
|
||||
public function findById(int $id): ?SupplierContact;
|
||||
|
||||
public function save(SupplierContact $contact): void;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Repository;
|
||||
|
||||
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
interface SupplierRepositoryInterface
|
||||
{
|
||||
public function findById(int $id): ?Supplier;
|
||||
|
||||
public function save(Supplier $supplier): void;
|
||||
|
||||
/**
|
||||
* Construit un QueryBuilder de liste pour le repertoire fournisseurs.
|
||||
* - Exclut toujours les fournisseurs soft-deletes (deleted_at IS NOT NULL, RG-2.17).
|
||||
* - Archivage (RG-2.17) :
|
||||
* - $archivedOnly = true -> uniquement les archives (is_archived = true) ;
|
||||
* - sinon $includeArchived = true -> actifs + archives (echappatoire) ;
|
||||
* - sinon (defaut) -> uniquement les actifs (is_archived = false).
|
||||
* $archivedOnly a la priorite sur $includeArchived.
|
||||
* - Tri par defaut : companyName ASC (RG-2.17).
|
||||
* - $search : recherche fuzzy insensible a la casse sur companyName + les
|
||||
* contacts lies (firstName / lastName / email) via sous-requete (D1,
|
||||
* refonte-contact §4.1). Metacaracteres LIKE echappes. Ignore si null/vide.
|
||||
* - $categoryCodes : restreint aux fournisseurs possedant au moins une
|
||||
* categorie dont le code est dans la liste (OR). Liste vide = pas de filtre.
|
||||
* - $siteIds : restreint aux fournisseurs ayant au moins une adresse rattachee
|
||||
* a l'un des sites donnes (OR — RG-2.06). Liste vide = pas de filtre.
|
||||
*
|
||||
* Filtrage centralise ICI (et non dans le provider/controller) pour que la
|
||||
* liste paginee (SupplierProvider) et l'export (SupplierExportController)
|
||||
* partagent strictement la meme logique de selection.
|
||||
*
|
||||
* Contrat = SELECTION uniquement (filtres + tri). Aucun fetch-join to-many :
|
||||
* l'hydratation des collections affichees est deleguee a
|
||||
* {@see self::hydrateListCollections()} pour ne pas imposer le cout d'un
|
||||
* produit cartesien aux chemins non pagines (cf. M1/ERP-100).
|
||||
*
|
||||
* @param list<string> $categoryCodes
|
||||
* @param list<int> $siteIds
|
||||
*/
|
||||
public function createListQueryBuilder(
|
||||
bool $includeArchived = false,
|
||||
?string $search = null,
|
||||
array $categoryCodes = [],
|
||||
array $siteIds = [],
|
||||
bool $archivedOnly = false,
|
||||
): QueryBuilder;
|
||||
|
||||
/**
|
||||
* Hydrate en lot les collections affichees par le repertoire (categories,
|
||||
* adresses et leurs sites) sur un jeu de fournisseurs DEJA charges, via
|
||||
* l'identity map Doctrine (memes instances). A appeler apres une selection
|
||||
* bornee (page courante ou jeu d'export) pour eviter le N+1 a la
|
||||
* serialisation, sans imposer de fetch-join au QueryBuilder de selection
|
||||
* (anti N+1, § 2.12).
|
||||
*
|
||||
* Charge les categories et les adresses/sites en DEUX requetes distinctes
|
||||
* (et non un triple fetch-join) pour ne pas multiplier categories x adresses
|
||||
* x sites en un seul produit cartesien.
|
||||
*
|
||||
* @param list<Supplier> $suppliers
|
||||
*/
|
||||
public function hydrateListCollections(array $suppliers): void;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Module\Commercial\Domain\Repository;
|
||||
|
||||
use App\Module\Commercial\Domain\Entity\SupplierRib;
|
||||
|
||||
interface SupplierRibRepositoryInterface
|
||||
{
|
||||
public function findById(int $id): ?SupplierRib;
|
||||
|
||||
public function save(SupplierRib $rib): void;
|
||||
}
|
||||
Reference in New Issue
Block a user