Browse Source

Factures : fix reference

packProduct
Guillaume 2 years ago
parent
commit
89c55041e5
3 changed files with 43 additions and 2 deletions
  1. +10
    -1
      Container/File/DocumentContainer.php
  2. +17
    -0
      Repository/File/DocumentRepositoryQuery.php
  3. +16
    -1
      Repository/File/DocumentStore.php

+ 10
- 1
Container/File/DocumentContainer.php View File

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Container\File;

use Lc\CaracoleBundle\Factory\File\DocumentFactory;
use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator;
use Lc\CaracoleBundle\Repository\File\DocumentRepositoryQuery;
use Lc\CaracoleBundle\Repository\File\DocumentStore;

@@ -11,15 +12,18 @@ class DocumentContainer
protected DocumentFactory $factory;
protected DocumentRepositoryQuery $repositoryQuery;
protected DocumentStore $store;
protected DocumentReferenceGenerator $referenceGenerator;

public function __construct(
DocumentFactory $factory,
DocumentRepositoryQuery $repositoryQuery,
DocumentStore $store
DocumentStore $store,
DocumentReferenceGenerator $referenceGenerator
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->referenceGenerator = $referenceGenerator;
}

public function getFactory(): DocumentFactory
@@ -38,4 +42,9 @@ class DocumentContainer

return $this->store;
}

public function getReferenceGenerator(): DocumentReferenceGenerator
{
return $this->referenceGenerator;
}
}

+ 17
- 0
Repository/File/DocumentRepositoryQuery.php View File

@@ -28,4 +28,21 @@ class DocumentRepositoryQuery extends AbstractRepositoryQuery
->andWhere('.buyerAddress = :buyerAddress')
->setParameter('buyerAddress', $buyerAddress);
}

public function filterByReference(string $reference = null)
{
if(is_null($reference)) {
return $this->andWhere('.reference IS NULL');
}
else {
return $this
->andWhere('.reference LIKE :reference')
->setParameter('reference', $reference);
}
}

public function filterIsReferenceNotNull()
{
return $this->andWhere('.reference IS NOT NULL');
}
}

+ 16
- 1
Repository/File/DocumentStore.php View File

@@ -4,6 +4,7 @@ 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;
@@ -22,7 +23,6 @@ class DocumentStore extends AbstractStore

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->orderBy('id');
return $query;
}

@@ -43,12 +43,27 @@ class DocumentStore extends AbstractStore
return $query;
}

public function getOneByReference(string $reference = null, string $type = null, $query = null)
{
$query = $this->createDefaultQuery($query);

$query
->filterByReference($reference)
->orderBy('createdAt', 'ASC');

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');


Loading…
Cancel
Save