1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace App\Repository;
use App\Entity\Adherent;
use App\Entity\Comptoir;
use App\Entity\Groupe;
use App\Entity\Operation;
use App\Entity\OperationAdherent;
use App\Entity\OperationComptoir;
use App\Entity\OperationGroupe;
use App\Entity\OperationPrestataire;
use App\Entity\OperationSiege;
use App\Entity\Prestataire;
use App\Entity\Siege;
use App\Enum\CurrencyEnum;
use App\Flux\AccountableInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Operation|null find($id, $lockMode = null, $lockVersion = null)
* @method Operation|null findOneBy(array $criteria, array $orderBy = null)
* @method Operation[] findAll()
* @method Operation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class OperationRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Operation::class);
}
/**
* @return Account[] Returns an array of Account objects
*/
public function findByAccountable(AccountableInterface $object, string $currency = null)
{
$query = null;
if ($object instanceof Prestataire) {
$query = $this->getEntityManager()->getRepository(OperationPrestataire::class)->findBy(['account' => $object->getEmlcAccount()], ['createdAt' => 'DESC']);
} elseif ($object instanceof Adherent) {
$query = $this->getEntityManager()->getRepository(OperationAdherent::class)->findBy(['account' => $object->getEmlcAccount()], ['createdAt' => 'DESC']);
} elseif ($object instanceof Groupe) {
$query = $this->getEntityManager()->getRepository(OperationGroupe::class)->findBy(['account' => $object->getMlcAccount()], ['createdAt' => 'DESC']);
} elseif ($object instanceof Comptoir) {
$query = $this->getEntityManager()->getRepository(OperationComptoir::class)->findBy(['account' => $object->getMlcAccount()]);
} elseif ($object instanceof Siege) {
if (null != $currency) {
if (!in_array($currency, CurrencyEnum::getAvailableTypes())) {
throw new \Exception('Opération impossible ! Type de currency ' . $currency . ' inexistant');
}
$siege = $this->getEntityManager()->getRepository(Siege::class)->getTheOne();
$query = $this->getEntityManager()->getRepository(OperationSiege::class)->findBy(['account' => $object->getAccountWithCurrency($currency)], ['createdAt' => 'DESC']);
} else {
$query = $this->em->getRepository(OperationSiege::class)->findBy(['account' => $object->getMlcAccount()], ['createdAt' => 'DESC']);
}
}
if (null == $query) {
return null;
}
return $query
->getQuery()
;
}
}