@@ -29,7 +29,7 @@ abstract class CreditHistoryModel extends AbstractLightEntity implements PayoffI | |||
const MEAN_PAYMENT_CASH = 'cash'; | |||
/** | |||
/**$merchant | |||
* @ORM\Column(type="float", nullable=true) | |||
*/ | |||
protected $amount; |
@@ -2,13 +2,59 @@ | |||
namespace Lc\CaracoleBundle\Repository\Credit; | |||
use App\Entity\Merchant\Merchant; | |||
use App\Entity\User\UserMerchant; | |||
use Knp\Component\Pager\PaginatorInterface; | |||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | |||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||
use DateTime; | |||
class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
protected $isJoinUserMerchants = false; | |||
public function __construct(CreditHistoryRepository $repository, PaginatorInterface $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); | |||
} | |||
} |
@@ -2,14 +2,45 @@ | |||
namespace Lc\CaracoleBundle\Repository\Credit; | |||
use App\Entity\User\UserMerchant; | |||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
use DateTime; | |||
class CreditHistoryStore extends AbstractStore | |||
{ | |||
use MerchantStoreTrait; | |||
protected CreditHistoryRepositoryQuery $query; | |||
public function __construct(CreditHistoryRepositoryQuery $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(); | |||
} | |||
} |
@@ -30,7 +30,7 @@ class UserRepositoryQuery extends SovUserRepositoryQuery | |||
->andWhere('um.active = 1'); | |||
} | |||
public function filterByUserMerchant(Merchant $merchant): self | |||
public function filterByJoinUserMerchant(Merchant $merchant): self | |||
{ | |||
$this->joinUserMerchants(); | |||
return $this |
@@ -18,7 +18,7 @@ class UserStore extends SovUserStore | |||
if ($this->merchant) { | |||
$query | |||
->filterByUserMerchant($this->merchant) | |||
->filterByJoinUserMerchant($this->merchant) | |||
->filterMerchantIsActive(); | |||
} | |||