refactor(commercial) : RG-1.03 distributor/broker by category code

ClientProcessor::hasCategoryCode (ex hasCategoryType) verifie le code de la
Category (DISTRIBUTEUR/COURTIER) et non plus le type. Filtre liste/export
renomme categoryType -> categoryCode (filtre sur category.code). Tests RG-1.03
distributor + courtier ajoutes ; factory de test adaptee au type unique CLIENT.
This commit is contained in:
Matthieu
2026-06-02 09:20:58 +02:00
parent 636f2ccb8e
commit 596f716076
8 changed files with 129 additions and 47 deletions
@@ -34,7 +34,7 @@ class DoctrineClientRepository extends ServiceEntityRepository implements Client
public function createListQueryBuilder(
bool $includeArchived = false,
?string $search = null,
?string $categoryType = null,
?string $categoryCode = null,
): QueryBuilder {
$qb = $this->createQueryBuilder('c')
->andWhere('c.deletedAt IS NULL')
@@ -46,7 +46,7 @@ class DoctrineClientRepository extends ServiceEntityRepository implements Client
}
$this->applySearch($qb, $search);
$this->applyCategoryType($qb, $categoryType);
$this->applyCategoryCode($qb, $categoryCode);
return $qb;
}
@@ -73,13 +73,15 @@ class DoctrineClientRepository extends ServiceEntityRepository implements Client
}
/**
* Restreint aux clients possedant au moins une categorie du type donne.
* Sous-requete IN (plutot qu'un JOIN sur la collection M2M) pour ne pas
* perturber le DISTINCT / ORDER BY de la requete principale.
* Restreint aux clients possedant au moins une categorie du code donne
* (ERP-78 : filtrage par code de Category, plus par type). Alimente notamment
* les selects « distributeur » (categoryCode=DISTRIBUTEUR) et « courtier »
* (COURTIER) cote front (RG-1.03). Sous-requete IN (plutot qu'un JOIN sur la
* collection M2M) pour ne pas perturber le DISTINCT / ORDER BY principal.
*/
private function applyCategoryType(QueryBuilder $qb, ?string $categoryType): void
private function applyCategoryCode(QueryBuilder $qb, ?string $categoryCode): void
{
if (null === $categoryType || '' === trim($categoryType)) {
if (null === $categoryCode || '' === trim($categoryCode)) {
return;
}
@@ -87,12 +89,11 @@ class DoctrineClientRepository extends ServiceEntityRepository implements Client
->select('c2.id')
->from(Client::class, 'c2')
->join('c2.categories', 'cat2')
->join('cat2.categoryType', 'ct2')
->where('ct2.code = :categoryType')
->where('cat2.code = :categoryCode')
;
$qb->andWhere($qb->expr()->in('c.id', $sub->getDQL()))
->setParameter('categoryType', trim($categoryType))
->setParameter('categoryCode', trim($categoryCode))
;
}
}