|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\File;
-
- use App\Entity\Address\Address;
- use Lc\CaracoleBundle\Model\File\DocumentInterface;
- use Lc\CaracoleBundle\Model\File\DocumentModel;
- 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 MerchantStoreTrait;
-
- protected DocumentRepositoryQuery $query;
-
- public function __construct(DocumentRepositoryQuery $query)
- {
- $this->query = $query;
- }
-
- public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- return $query;
- }
-
- public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- $query->filterIsOnlineAndOffline();
-
-
- if(isset($this->merchant) && $this->merchant) {
- $query->filterByMerchant($this->merchant);
- }
-
- return $query;
- }
-
- public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
- {
- return $query;
- }
-
- public function getOneByReference(string $reference = null, string $type = null, $query = null)
- {
- $query = $this->createDefaultQuery($query);
-
- $query
- ->filterByReference($reference)
- ->orderBy('createdAt', 'ASC')
- ->innerJoin('.orderShops', 'orderShops')
- ;
-
- if(!is_null($type)) {
- $query->filterByType($type);
- }
-
- return $query->findOne();
- }
-
- public function getOneLatestByType(string $documentType, $query = null): ?DocumentInterface
- {
- $query = $this->createDefaultQuery($query);
-
- $query
- ->filterIsReferenceNotNull()
- ->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();
- }
-
- }
|