Browse Source

CreditHistory répo

packProduct
Charly 3 years ago
parent
commit
a0411ca896
5 changed files with 80 additions and 3 deletions
  1. +1
    -1
      Model/Credit/CreditHistoryModel.php
  2. +46
    -0
      Repository/Credit/CreditHistoryRepositoryQuery.php
  3. +31
    -0
      Repository/Credit/CreditHistoryStore.php
  4. +1
    -1
      Repository/User/UserRepositoryQuery.php
  5. +1
    -1
      Repository/User/UserStore.php

+ 1
- 1
Model/Credit/CreditHistoryModel.php View File

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;

+ 46
- 0
Repository/Credit/CreditHistoryRepositoryQuery.php View File



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

+ 31
- 0
Repository/Credit/CreditHistoryStore.php View File



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

+ 1
- 1
Repository/User/UserRepositoryQuery.php View File

->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

+ 1
- 1
Repository/User/UserStore.php View File



if ($this->merchant) { if ($this->merchant) {
$query $query
->filterByUserMerchant($this->merchant)
->filterByJoinUserMerchant($this->merchant)
->filterMerchantIsActive(); ->filterMerchantIsActive();
} }



Loading…
Cancel
Save