|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\File;
-
- use App\Entity\Address\Address;
- use Lc\CaracoleBundle\Model\File\DocumentInterface;
- use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
- use Lc\CaracoleBundle\Repository\SectionStoreTrait;
- use Lc\CaracoleBundle\Repository\AbstractStore;
- use Lc\SovBundle\Repository\RepositoryQueryInterface;
-
- class DocumentStore extends AbstractStore
- {
- use SectionStoreTrait;
- use MerchantStoreTrait;
-
- protected DocumentRepositoryQuery $query;
-
- public function __construct(DocumentRepositoryQuery $query)
- {
- $this->query = $query;
- }
-
- public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- $query->orderBy('id');
- return $query;
- }
-
- public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- $query->filterIsOnlineAndOffline();
-
- if(isset($this->section) && $this->section) {
- $query->filterBySection($this->section);
- }
-
- if(isset($this->merchant) && $this->merchant) {
- $query->filterByMerchantViaSection($this->merchant);
- }
-
- return $query;
- }
-
- public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- return $query;
- }
-
-
- public function getOneLatestByType(string $documentType, $query = null): DocumentInterface
- {
- $query = $this->createDefaultQuery($query);
-
- $query
- ->filterByType($documentType)
- ->orderBy('createdAt', 'DESC');
-
- return $query->findOne();
- }
-
- // findLastInvoice
- public function getOneLastInvoice($query = null)
- {
- $query = $this->createDefaultQuery($query);
-
- $query
- ->orderBy('createdAt', 'DESC');
-
- return $query->findOne();
- }
-
- public function getByBuyerAddress(Address $buyerAddress, $query = null)
- {
- $query = $this->createDefaultQuery($query);
- $query->filterByBuyerAddress($buyerAddress);
- return $query->find();
- }
-
- }
|