<?php
namespace App\Repository\Accounting;
use App\Entity\Accounting\Payment;
use App\Entity\Booking\Quote;
use App\Entity\ParameterCodes;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Payment|null find($id, $lockMode = null, $lockVersion = null)
* @method Payment|null findOneBy(array $criteria, array $orderBy = null)
* @method Payment[] findAll()
* @method Payment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PaymentRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Payment::class);
}
/**
* @return Collection|Payment[]
*/
public function findByQuote(Quote $quote, ?string $statusCode = null, bool $manual = false, array $orderBy = ["paymentAt", "ASC"])
{
$qb = $this->createQueryBuilder('p')
->innerJoin('p.status', 's')
->innerJoin('p.quote', 'q')
->innerJoin('p.mode', 'm')
->innerJoin('m.parameterAttributeValues', 'pav')
->innerJoin('pav.parameterTypeAttribute', 'pta');
$qb->where($qb->expr()->eq('q.id', ':quote'))->setParameter('quote', $quote->getId());
if (null !== $statusCode) {
$qb->andWhere($qb->expr()->eq('s.code', ':status'))->setParameter('status', $statusCode);
}
return $qb
->andWhere($qb->expr()->eq('pta.code', ':attributeCode'))->setParameter('attributeCode', ParameterCodes::PAYMENT_MODE_ORIGIN)
->andWhere($qb->expr()->eq('pav.value', ':manual'))->setParameter('manual', $manual ? "Paiement manuel" : "Paiement bancaire")
->addOrderBy('p.'.$orderBy[0], $orderBy[1])
->getQuery()
->getResult();
}
}