src/Repository/__Sale/LegalTextRepository.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Repository\__Sale;
  3. use App\Entity\__Accounting\Supplier;
  4. use App\Entity\__Sale\LegalText;
  5. use App\Entity\ParameterCodes;
  6. use Crea\ParameterBundle\Entity\Parameter;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\ORM\NonUniqueResultException;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. /**
  11.  * @method LegalText|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method LegalText|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method LegalText[] findAll()
  14.  * @method LegalText[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class LegalTextRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registryLegalText::class);
  21.     }
  22.     /**
  23.      * @return array|LegalText[]
  24.      */
  25.     public function findActives(): array
  26.     {
  27.         $qb $this->createQueryBuilder('lt');
  28.         return $qb
  29.             ->where($qb->expr()->eq('lt.active'1))
  30.             ->orderBy('lt.name''asc')
  31.             ->getQuery()
  32.             ->getResult();
  33.     }
  34.     /**
  35.      * @param string $supplierName
  36.      * @param string $categoryCode
  37.      * @param LegalText|null $legalTextToExclude
  38.      * @return LegalText|null
  39.      * @throws NonUniqueResultException
  40.      */
  41.     public function findLegalTextBySupplierNameAndCategoryCode(string $supplierNamestring $categoryCode, ?LegalText $legalTextToExclude null): ?LegalText
  42.     {
  43.         $qb $this->createQueryBuilder('lt');
  44.         $qb
  45.             ->join('lt.category''ltc')
  46.             ->join('lt.supplier''lts')
  47.             ->where($qb->expr()->eq('ltc.code'':categoryCode'))
  48.             ->andWhere($qb->expr()->eq('lts.name'':supplierName'))
  49.             ->andWhere($qb->expr()->eq('lt.active'1))
  50.             ->setParameter('categoryCode'$categoryCode)
  51.             ->setParameter('supplierName'$supplierName);
  52.         if ($legalTextToExclude !== null) {
  53.             $qb->andWhere($qb->expr()->neq('lt.id'$legalTextToExclude->getId()));
  54.         }
  55.         return $qb
  56.             ->getQuery()
  57.             ->getOneOrNullResult();
  58.     }
  59.     /**
  60.      * @param Parameter $category
  61.      * @param Supplier $supplier
  62.      * @param LegalText|null $legalTextToExclude
  63.      * @return LegalText|null
  64.      * @throws NonUniqueResultException
  65.      */
  66.     public function findCurrentLegalTextWithSameAttributes(Parameter $categorySupplier $supplier, ?LegalText $legalTextToExclude null): ?LegalText
  67.     {
  68.         return $this->findLegalTextBySupplierNameAndCategoryCode($supplier->getName(), $category->getCode(), $legalTextToExclude);
  69.     }
  70. }