feat(commercial) : entités M2 fournisseurs + repositories (ERP-86)
Entités jumelles du M1 client, mapping ORM aligné sur la migration ERP-85, sans contact inline (ERP-106) : - Supplier (#[Auditable] + Timestampable/Blamable) : formulaire principal, Information (+ volumeForecast), Comptabilité (FK référentiels M1), archivage, soft-delete préparé. Catégories M2M via CategoryInterface (règle n°1). - SupplierContact / SupplierAddress (enum addressType, bennes, triageProvider) / SupplierRib. - Repositories : interfaces Domain + impls Doctrine. DoctrineSupplierRepository porte les fetch-joins anti-N+1 de la liste (categories + addresses.sites en 2 passes, pattern ERP-100) et les filtres (search companyName + contacts, categoryCode, siteId, archivage). Contrat de sérialisation (RETEX M1, 3 maillons posés sur l'entité) : read-groups sur les propriétés, getters isArchived/isTriageProvider avec SerializedName, embed contacts/addresses (supplier:item:read) et ribs (supplier:read:accounting). L'#[ApiResource] + Provider/Processor sont au ticket suivant (ERP-87). Validation FR (ERP-107) : messages FR sur toutes les contraintes, Length(max) calé sur les colonnes. Garde-fou EntityConstraintsHaveFrenchMessageTest étendu (Assert\Choice + whitelist addressType/postalCode). Clés i18n audit des 4 entités ajoutées. make test : 483/483 OK.
This commit is contained in:
@@ -259,7 +259,11 @@
|
|||||||
"commercial_client": "Client",
|
"commercial_client": "Client",
|
||||||
"commercial_clientaddress": "Adresse client",
|
"commercial_clientaddress": "Adresse client",
|
||||||
"commercial_clientcontact": "Contact client",
|
"commercial_clientcontact": "Contact client",
|
||||||
"commercial_clientrib": "RIB client"
|
"commercial_clientrib": "RIB client",
|
||||||
|
"commercial_supplier": "Fournisseur",
|
||||||
|
"commercial_supplieraddress": "Adresse fournisseur",
|
||||||
|
"commercial_suppliercontact": "Contact fournisseur",
|
||||||
|
"commercial_supplierrib": "RIB fournisseur"
|
||||||
},
|
},
|
||||||
"empty": "Aucune activité enregistrée",
|
"empty": "Aucune activité enregistrée",
|
||||||
"no_results": "Aucun résultat pour ces filtres",
|
"no_results": "Aucun résultat pour ces filtres",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierAddress;
|
||||||
|
use App\Module\Commercial\Domain\Repository\SupplierAddressRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<SupplierAddress>
|
||||||
|
*/
|
||||||
|
class DoctrineSupplierAddressRepository extends ServiceEntityRepository implements SupplierAddressRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, SupplierAddress::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?SupplierAddress
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(SupplierAddress $address): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($address);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierContact;
|
||||||
|
use App\Module\Commercial\Domain\Repository\SupplierContactRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<SupplierContact>
|
||||||
|
*/
|
||||||
|
class DoctrineSupplierContactRepository extends ServiceEntityRepository implements SupplierContactRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, SupplierContact::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?SupplierContact
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(SupplierContact $contact): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($contact);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\Supplier;
|
||||||
|
use App\Module\Commercial\Domain\Repository\SupplierRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Supplier>
|
||||||
|
*/
|
||||||
|
class DoctrineSupplierRepository extends ServiceEntityRepository implements SupplierRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Supplier::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?Supplier
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(Supplier $supplier): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($supplier);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createListQueryBuilder(
|
||||||
|
bool $includeArchived = false,
|
||||||
|
?string $search = null,
|
||||||
|
array $categoryCodes = [],
|
||||||
|
array $siteIds = [],
|
||||||
|
bool $archivedOnly = false,
|
||||||
|
): QueryBuilder {
|
||||||
|
// SELECTION uniquement (filtres + tri) : pas de fetch-join to-many ici.
|
||||||
|
// L'hydratation des collections affichees (Catégories / Site(s)) est
|
||||||
|
// deleguee a hydrateListCollections() une fois le jeu borne, pour ne pas
|
||||||
|
// imposer un produit cartesien aux chemins non pagines (export,
|
||||||
|
// ?pagination=false) — § 2.12 (cf. M1/ERP-100).
|
||||||
|
$qb = $this->createQueryBuilder('s')
|
||||||
|
->andWhere('s.deletedAt IS NULL')
|
||||||
|
->orderBy('s.companyName', 'ASC')
|
||||||
|
;
|
||||||
|
|
||||||
|
// Perimetre d'archivage : archivedOnly prioritaire sur includeArchived.
|
||||||
|
if ($archivedOnly) {
|
||||||
|
$qb->andWhere('s.isArchived = true');
|
||||||
|
} elseif (!$includeArchived) {
|
||||||
|
$qb->andWhere('s.isArchived = false');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->applySearch($qb, $search);
|
||||||
|
$this->applyCategoryCodes($qb, $categoryCodes);
|
||||||
|
$this->applySiteIds($qb, $siteIds);
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hydrateListCollections(array $suppliers): void
|
||||||
|
{
|
||||||
|
if ([] === $suppliers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ids des fournisseurs deja charges (entites managees). Les requetes
|
||||||
|
// ci-dessous renvoient les MEMES instances Supplier (identity map), dont
|
||||||
|
// les collections sont alors remplies — anti N+1 a la serialisation.
|
||||||
|
$ids = [];
|
||||||
|
foreach ($suppliers as $supplier) {
|
||||||
|
$id = $supplier->getId();
|
||||||
|
if (null !== $id) {
|
||||||
|
$ids[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ([] === $ids) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1re passe : categories (colonne « Catégories »). Produit s x cat seul.
|
||||||
|
$this->createQueryBuilder('s')
|
||||||
|
->leftJoin('s.categories', 'cat')->addSelect('cat')
|
||||||
|
->where('s.id IN (:ids)')->setParameter('ids', $ids)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
// 2e passe : adresses + sites (colonne « Site(s) », sites portes par les
|
||||||
|
// adresses — RG-2.06). Le join addr -> site reste imbrique mais n'est plus
|
||||||
|
// multiplie par les categories : le cartesien global est casse.
|
||||||
|
$this->createQueryBuilder('s')
|
||||||
|
->leftJoin('s.addresses', 'addr')->addSelect('addr')
|
||||||
|
->leftJoin('addr.sites', 'site')->addSelect('site')
|
||||||
|
->where('s.id IN (:ids)')->setParameter('ids', $ids)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recherche fuzzy insensible a la casse sur companyName ET sur les contacts
|
||||||
|
* lies (firstName / lastName / email) — decision D1, refonte-contact (§ 4.1).
|
||||||
|
* Les deux criteres sont unis par OR : un fournisseur matche si son nom de
|
||||||
|
* societe OU l'un de ses contacts matche. Le critere contact passe par une
|
||||||
|
* sous-requete IN (plutot qu'un JOIN sur la collection) pour ne pas perturber
|
||||||
|
* le DISTINCT / ORDER BY / pagination principal. Les metacaracteres LIKE
|
||||||
|
* (%, _, \) saisis sont echappes pour rester litteraux.
|
||||||
|
*/
|
||||||
|
private function applySearch(QueryBuilder $qb, ?string $search): void
|
||||||
|
{
|
||||||
|
if (null === $search || '' === trim($search)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$escaped = str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], trim($search));
|
||||||
|
$pattern = '%'.mb_strtolower($escaped, 'UTF-8').'%';
|
||||||
|
|
||||||
|
$contactSub = $this->getEntityManager()->createQueryBuilder()
|
||||||
|
->select('s2.id')
|
||||||
|
->from(Supplier::class, 's2')
|
||||||
|
->join('s2.contacts', 'sc2')
|
||||||
|
->where('LOWER(sc2.firstName) LIKE :search')
|
||||||
|
->orWhere('LOWER(sc2.lastName) LIKE :search')
|
||||||
|
->orWhere('LOWER(sc2.email) LIKE :search')
|
||||||
|
;
|
||||||
|
|
||||||
|
$qb->andWhere(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
'LOWER(s.companyName) LIKE :search',
|
||||||
|
$qb->expr()->in('s.id', $contactSub->getDQL()),
|
||||||
|
),
|
||||||
|
)->setParameter('search', $pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restreint aux fournisseurs possedant au moins une categorie dont le code
|
||||||
|
* figure dans la liste (OR). Alimente le filtre « Catégories » du drawer.
|
||||||
|
* Sous-requete IN (plutot qu'un JOIN sur la collection M2M) pour ne pas
|
||||||
|
* perturber le DISTINCT / ORDER BY principal.
|
||||||
|
*
|
||||||
|
* @param list<string> $categoryCodes
|
||||||
|
*/
|
||||||
|
private function applyCategoryCodes(QueryBuilder $qb, array $categoryCodes): void
|
||||||
|
{
|
||||||
|
$codes = $this->normalizeStringList($categoryCodes);
|
||||||
|
if ([] === $codes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sub = $this->getEntityManager()->createQueryBuilder()
|
||||||
|
->select('s3.id')
|
||||||
|
->from(Supplier::class, 's3')
|
||||||
|
->join('s3.categories', 'cat3')
|
||||||
|
->where('cat3.code IN (:categoryCodes)')
|
||||||
|
;
|
||||||
|
|
||||||
|
$qb->andWhere($qb->expr()->in('s.id', $sub->getDQL()))
|
||||||
|
->setParameter('categoryCodes', $codes)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restreint aux fournisseurs ayant au moins une adresse rattachee a l'un des
|
||||||
|
* sites donnes (OR — RG-2.06 : les sites vivent sur les adresses). Sous-requete
|
||||||
|
* IN pour ne pas perturber le tri/pagination principal.
|
||||||
|
*
|
||||||
|
* @param list<int> $siteIds
|
||||||
|
*/
|
||||||
|
private function applySiteIds(QueryBuilder $qb, array $siteIds): void
|
||||||
|
{
|
||||||
|
$ids = $this->normalizeIntList($siteIds);
|
||||||
|
if ([] === $ids) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sub = $this->getEntityManager()->createQueryBuilder()
|
||||||
|
->select('s4.id')
|
||||||
|
->from(Supplier::class, 's4')
|
||||||
|
->join('s4.addresses', 'addr4')
|
||||||
|
->join('addr4.sites', 'site4')
|
||||||
|
->where('site4.id IN (:siteIds)')
|
||||||
|
;
|
||||||
|
|
||||||
|
$qb->andWhere($qb->expr()->in('s.id', $sub->getDQL()))
|
||||||
|
->setParameter('siteIds', $ids)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nettoie une liste de chaines : trim, retrait des vides, reindexation.
|
||||||
|
* Defensive : tolere des elements scalaires non-string (cast) et ignore le
|
||||||
|
* reste sans lever de TypeError, le contrat etant de normaliser une entree
|
||||||
|
* potentiellement brute (query params).
|
||||||
|
*
|
||||||
|
* @param array<mixed> $values
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function normalizeStringList(array $values): array
|
||||||
|
{
|
||||||
|
$out = [];
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (is_string($value) || is_int($value) || is_float($value)) {
|
||||||
|
$trimmed = trim((string) $value);
|
||||||
|
if ('' !== $trimmed) {
|
||||||
|
$out[] = $trimmed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nettoie une liste d'identifiants : cast int, retrait des <= 0, reindexation.
|
||||||
|
* Defensive (cf. normalizeStringList) : accepte des entiers ou des chaines
|
||||||
|
* numeriques ('1', '2') sans TypeError, ignore le reste.
|
||||||
|
*
|
||||||
|
* @param array<mixed> $values
|
||||||
|
*
|
||||||
|
* @return list<int>
|
||||||
|
*/
|
||||||
|
private function normalizeIntList(array $values): array
|
||||||
|
{
|
||||||
|
$out = [];
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (is_numeric($value) && (int) $value > 0) {
|
||||||
|
$out[] = (int) $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Commercial\Infrastructure\Doctrine;
|
||||||
|
|
||||||
|
use App\Module\Commercial\Domain\Entity\SupplierRib;
|
||||||
|
use App\Module\Commercial\Domain\Repository\SupplierRibRepositoryInterface;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<SupplierRib>
|
||||||
|
*/
|
||||||
|
class DoctrineSupplierRibRepository extends ServiceEntityRepository implements SupplierRibRepositoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, SupplierRib::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findById(int $id): ?SupplierRib
|
||||||
|
{
|
||||||
|
return $this->find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(SupplierRib $rib): void
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($rib);
|
||||||
|
$this->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,6 +52,10 @@ final class EntityConstraintsHaveFrenchMessageTest extends TestCase
|
|||||||
private const array EXCLUDED_LENGTH_MIRROR = [
|
private const array EXCLUDED_LENGTH_MIRROR = [
|
||||||
// Le Regex /^[0-9]{4,5}$/ borne deja la longueur a 5 caracteres (< 20).
|
// Le Regex /^[0-9]{4,5}$/ borne deja la longueur a 5 caracteres (< 20).
|
||||||
'ClientAddress::postalCode' => 'Regex {4,5} borne deja la longueur.',
|
'ClientAddress::postalCode' => 'Regex {4,5} borne deja la longueur.',
|
||||||
|
// Idem cote fournisseur (meme Regex CP).
|
||||||
|
'SupplierAddress::postalCode' => 'Regex {4,5} borne deja la longueur.',
|
||||||
|
// Le Choice {PROSPECT,DEPART,RENDU} borne les valeurs (<= 8 < 20).
|
||||||
|
'SupplierAddress::addressType' => 'Choice {PROSPECT,DEPART,RENDU} borne deja les valeurs.',
|
||||||
// Le Regex /^#[0-9A-Fa-f]{6}$/ borne la longueur a exactement 7 caracteres.
|
// Le Regex /^#[0-9A-Fa-f]{6}$/ borne la longueur a exactement 7 caracteres.
|
||||||
'Site::color' => 'Regex code hex #RRGGBB borne deja la longueur.',
|
'Site::color' => 'Regex code hex #RRGGBB borne deja la longueur.',
|
||||||
];
|
];
|
||||||
@@ -70,6 +74,7 @@ final class EntityConstraintsHaveFrenchMessageTest extends TestCase
|
|||||||
Assert\NotBlank::class,
|
Assert\NotBlank::class,
|
||||||
Assert\NotNull::class,
|
Assert\NotNull::class,
|
||||||
Assert\Email::class,
|
Assert\Email::class,
|
||||||
|
Assert\Choice::class,
|
||||||
Assert\Regex::class,
|
Assert\Regex::class,
|
||||||
Assert\Bic::class,
|
Assert\Bic::class,
|
||||||
Assert\Iban::class,
|
Assert\Iban::class,
|
||||||
|
|||||||
Reference in New Issue
Block a user