|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?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();
- }
-
- }
|