const MEAN_PAYMENT_CASH = 'cash'; | const MEAN_PAYMENT_CASH = 'cash'; | ||||
/** | |||||
/**$merchant | |||||
* @ORM\Column(type="float", nullable=true) | * @ORM\Column(type="float", nullable=true) | ||||
*/ | */ | ||||
protected $amount; | protected $amount; |
namespace Lc\CaracoleBundle\Repository\Credit; | namespace Lc\CaracoleBundle\Repository\Credit; | ||||
use App\Entity\Merchant\Merchant; | |||||
use App\Entity\User\UserMerchant; | |||||
use Knp\Component\Pager\PaginatorInterface; | use Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | use Lc\SovBundle\Repository\AbstractRepositoryQuery; | ||||
use DateTime; | |||||
class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery | class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery | ||||
{ | { | ||||
protected $isJoinUserMerchants = false; | |||||
public function __construct(CreditHistoryRepository $repository, PaginatorInterface $paginator) | public function __construct(CreditHistoryRepository $repository, PaginatorInterface $paginator) | ||||
{ | { | ||||
parent::__construct($repository, 'r', $paginator); | parent::__construct($repository, 'r', $paginator); | ||||
} | } | ||||
public function joinUserMerchant(): self | |||||
{ | |||||
if (!$this->isJoinUserMerchants) { | |||||
$this->isJoinUserMerchants = true; | |||||
return $this | |||||
->innerJoin('.userMerchant', 'um'); | |||||
} | |||||
return $this; | |||||
} | |||||
public function filterByJoinUserMerchant(Merchant $merchant): self | |||||
{ | |||||
$this->joinUserMerchant(); | |||||
return $this | |||||
->andWhere('um.merchant = :merchant') | |||||
->setParameter('merchant', $merchant); | |||||
} | |||||
public function filterByUserMerchant(UserMerchant $userMerchant): self | |||||
{ | |||||
return $this | |||||
->andWhere('.userMerchant = :userMerchant') | |||||
->setParameter('userMerchant', $userMerchant); | |||||
} | |||||
public function filterByDateStart(DateTime $dateStart): self | |||||
{ | |||||
return $this | |||||
->andWhere('.createdAt >= :dateStart') | |||||
->setParameter(':dateStart', $dateStart); | |||||
} | |||||
public function filterByDateEnd(DateTime $dateEnd): self | |||||
{ | |||||
return $this | |||||
->andWhere('.createdAt <= :dateEnd') | |||||
->setParameter(':dateEnd', $dateEnd); | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\Credit; | namespace Lc\CaracoleBundle\Repository\Credit; | ||||
use App\Entity\User\UserMerchant; | |||||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
use DateTime; | |||||
class CreditHistoryStore extends AbstractStore | class CreditHistoryStore extends AbstractStore | ||||
{ | { | ||||
use MerchantStoreTrait; | |||||
protected CreditHistoryRepositoryQuery $query; | protected CreditHistoryRepositoryQuery $query; | ||||
public function __construct(CreditHistoryRepositoryQuery $query) | public function __construct(CreditHistoryRepositoryQuery $query) | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
//findAllByDateStartEnd | |||||
public function getByDateStartEnd(DateTime $dateStart, DateTime $dateEnd): array | |||||
{ | |||||
$query = $this->query->create(); | |||||
$query | |||||
->filterByJoinUserMerchant($this->merchant) | |||||
->filterByDateStart($dateStart) | |||||
->filterByDateEnd($dateEnd) | |||||
->orderBy('.createdAt'); | |||||
return $query->find(); | |||||
} | |||||
//findAllByUserMerchant | |||||
public function getByUserMerchant(UserMerchant $userMerchant): array | |||||
{ | |||||
$query = $this->query->create(); | |||||
$query | |||||
->filterByUserMerchant($userMerchant) | |||||
->orderBy('.createdAt', 'DESC'); | |||||
return $query->find(); | |||||
} | |||||
} | } |
->andWhere('um.active = 1'); | ->andWhere('um.active = 1'); | ||||
} | } | ||||
public function filterByUserMerchant(Merchant $merchant): self | |||||
public function filterByJoinUserMerchant(Merchant $merchant): self | |||||
{ | { | ||||
$this->joinUserMerchants(); | $this->joinUserMerchants(); | ||||
return $this | return $this |
if ($this->merchant) { | if ($this->merchant) { | ||||
$query | $query | ||||
->filterByUserMerchant($this->merchant) | |||||
->filterByJoinUserMerchant($this->merchant) | |||||
->filterMerchantIsActive(); | ->filterMerchantIsActive(); | ||||
} | } | ||||