Przeglądaj źródła

Refactoring repositories #1084

feature/souke
Guillaume 1 rok temu
rodzic
commit
19df9ea630
32 zmienionych plików z 387 dodań i 260 usunięć
  1. +14
    -0
      common/logic/AbstractRepositoryQuery.php
  2. +2
    -2
      common/logic/AbstractSingleton.php
  3. +3
    -1
      common/logic/Document/DeliveryNote/Repository/DeliveryNoteRepository.php
  4. +0
    -2
      common/logic/Document/DeliveryNote/Repository/DeliveryNoteRepositoryQuery.php
  5. +3
    -1
      common/logic/Document/Invoice/Repository/InvoiceRepository.php
  6. +3
    -1
      common/logic/Document/Quotation/Repository/QuotationRepository.php
  7. +41
    -82
      common/logic/Order/Order/Repository/OrderRepository.php
  8. +45
    -0
      common/logic/Order/Order/Repository/OrderRepositoryQuery.php
  9. +6
    -4
      common/logic/Order/ProductOrder/Repository/ProductOrderRepository.php
  10. +8
    -0
      common/logic/Order/ProductOrder/Repository/ProductOrderRepositoryQuery.php
  11. +31
    -34
      common/logic/PointSale/PointSale/Repository/PointSaleRepository.php
  12. +28
    -0
      common/logic/PointSale/PointSale/Repository/PointSaleRepositoryQuery.php
  13. +7
    -8
      common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepository.php
  14. +16
    -0
      common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepositoryQuery.php
  15. +18
    -37
      common/logic/Producer/Producer/Repository/ProducerRepository.php
  16. +18
    -0
      common/logic/Producer/Producer/Repository/ProducerRepositoryQuery.php
  17. +6
    -6
      common/logic/Producer/ProducerPriceRange/Repository/ProducerPriceRangeRepository.php
  18. +20
    -36
      common/logic/Product/Product/Repository/ProductRepository.php
  19. +26
    -0
      common/logic/Product/Product/Repository/ProductRepositoryQuery.php
  20. +10
    -18
      common/logic/Product/ProductCategory/Repository/ProductCategoryRepository.php
  21. +10
    -7
      common/logic/Product/ProductPrice/Repository/ProductPriceRepository.php
  22. +34
    -0
      common/logic/Product/ProductPrice/Repository/ProductPriceRepositoryQuery.php
  23. +3
    -3
      common/logic/Subscription/ProductSubscription/Repository/ProductSubscriptionRepository.php
  24. +7
    -0
      common/logic/Subscription/ProductSubscription/Repository/ProductSubscriptionRepositoryQuery.php
  25. +8
    -9
      common/logic/Subscription/Subscription/Repository/SubscriptionRepository.php
  26. +7
    -0
      common/logic/Subscription/Subscription/Repository/SubscriptionRepositoryQuery.php
  27. +3
    -3
      common/logic/User/CreditHistory/Repository/CreditHistoryRepository.php
  28. +7
    -0
      common/logic/User/CreditHistory/Repository/CreditHistoryRepositoryQuery.php
  29. +0
    -2
      common/logic/User/User/Repository/UserRepositoryQuery.php
  30. +1
    -1
      producer/controllers/OrderController.php
  31. +1
    -1
      producer/controllers/SiteController.php
  32. +1
    -2
      producer/views/layouts/main.php

+ 14
- 0
common/logic/AbstractRepositoryQuery.php Wyświetl plik

@@ -35,6 +35,11 @@ abstract class AbstractRepositoryQuery extends AbstractService implements Reposi
return $this;
}

public function query()
{
return $this->query;
}

public function count()
{
$class = $this->definition->getEntityFqcn();
@@ -59,4 +64,13 @@ abstract class AbstractRepositoryQuery extends AbstractService implements Reposi

return $this;
}

public function filterByCondition(string $condition = ''): self
{
if($condition && strlen($condition) > 0) {
$this->andWhere($condition);
}

return $this;
}
}

+ 2
- 2
common/logic/AbstractSingleton.php Wyświetl plik

@@ -10,10 +10,10 @@ abstract class AbstractSingleton
{
}

final public function __clone()
/*final public function __clone()
{
trigger_error("Le clonage n'est pas autorisé.", E_USER_ERROR);
}
}*/

final public static function getInstance(): self
{

+ 3
- 1
common/logic/Document/DeliveryNote/Repository/DeliveryNoteRepository.php Wyświetl plik

@@ -26,6 +26,8 @@ class DeliveryNoteRepository extends AbstractRepository

public function findOneDeliveryNoteById(int $id): ?DeliveryNote
{
return DeliveryNote::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}
}

+ 0
- 2
common/logic/Document/DeliveryNote/Repository/DeliveryNoteRepositoryQuery.php Wyświetl plik

@@ -3,9 +3,7 @@
namespace common\logic\Document\DeliveryNote\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\DeliveryNote\Service\DeliveryNoteDefinition;
use yii\db\ActiveQuery;

class DeliveryNoteRepositoryQuery extends AbstractRepositoryQuery
{

+ 3
- 1
common/logic/Document/Invoice/Repository/InvoiceRepository.php Wyświetl plik

@@ -26,6 +26,8 @@ class InvoiceRepository extends AbstractRepository

public function findOneInvoiceById(int $id): ?Invoice
{
return Invoice::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}
}

+ 3
- 1
common/logic/Document/Quotation/Repository/QuotationRepository.php Wyświetl plik

@@ -26,6 +26,8 @@ class QuotationRepository extends AbstractRepository

public function findOneQuotationById(int $id): ?Quotation
{
return Quotation::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}
}

+ 41
- 82
common/logic/Order/Order/Repository/OrderRepository.php Wyświetl plik

@@ -5,18 +5,21 @@ namespace common\logic\Order\Order\Repository;
use common\helpers\MeanPayment;
use common\logic\AbstractRepository;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\Distribution\Repository\DistributionRepository;
use common\logic\Distribution\ProductDistribution\Repository\ProductDistributionRepository;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderBuilder;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Order\ProductOrder\Repository\ProductOrderRepository;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Repository\PointSaleRepository;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\Product\Service\ProductSolver;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserProducer\Repository\UserProducerRepository;
use yii\helpers\Html;

class OrderRepository extends AbstractRepository
@@ -27,6 +30,9 @@ class OrderRepository extends AbstractRepository
protected OrderSolver $orderSolver;
protected ProductDistributionRepository $productDistributionRepository;
protected ProductSolver $productSolver;
protected UserProducerRepository $userProducerRepository;
protected DistributionRepository $distributionRepository;
protected PointSaleRepository $pointSaleRepository;

public function loadDependencies(): void
{
@@ -36,6 +42,9 @@ class OrderRepository extends AbstractRepository
$this->orderSolver = $this->loadService(OrderSolver::class);
$this->productDistributionRepository = $this->loadService(ProductDistributionRepository::class);
$this->productSolver = $this->loadService(ProductSolver::class);
$this->userProducerRepository = $this->loadService(UserProducerRepository::class);
$this->distributionRepository = $this->loadService(DistributionRepository::class);
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class);
}

public function getDefaultOptionsSearch(): array
@@ -60,87 +69,41 @@ class OrderRepository extends AbstractRepository

public function findOneOrderById(int $id)
{
return Order::searchOne(['order.id' => $id]);;
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findOrdersByDate(string $date): array
{
return Order::searchAll([
'distribution.date' => $date
]);
return $this->createDefaultQuery()
->filterByDistributionDate($date)
->find();
}

/**
* Recherche et initialise des commandes.
*/
// searchBy
// findBy
public function findOrdersBy(array $params = [], array $options = [])
{
$orderBuilder = OrderBuilder::getInstance();
$orders = Order::searchBy($params, $options);

/*
* Initialisation des commandes
*/
if (is_array($orders)) {
if (count($orders)) {
foreach ($orders as $order) {
if (is_a($order, 'common\logic\Order\Order\Model\Order')) {
$orderBuilder->initOrder($order);
}
}
return $orders;
}
} else {
$order = $orders;
if (is_a($order, 'common\logic\Order\Order\Model\Order')) {
$orderBuilder->initOrder($order);
return $order;
} // count
else {
return $order;
}
}

return false;
}

// findByDistribution
public function findOrdersByDistribution(Distribution $distribution, string $conditionAppend = '')
{
return Order::searchAll([
'distribution.date' => $distribution->date,
'distribution.id_producer' => $distribution->id_producer
],
[
'conditions' => 'date_delete IS NULL ' . $conditionAppend
]);
return $this->createDefaultQuery()
->filterByDistributionDate($distribution->date)
->filterIsValid()
->filterByCondition($conditionAppend)
->find();
}

// queryHistory
public function queryOrdersHistory(Producer $producer, User $user)
{
$query = Order::find()
->with('productOrder', 'pointSale', 'creditHistory')
->joinWith('distribution', 'distribution.producer')
->where([
'id_user' => $user->id,
'distribution.id_producer' => $producer->id
])
->params([':date_today' => date('Y-m-d')]);

$queryIncoming = clone $query;
$queryIncoming
->andWhere('distribution.date >= :date_today')
->orderBy('distribution.date ASC');

$queryPassed = clone $query;
$queryPassed
->andWhere('distribution.date < :date_today')
->orderBy('distribution.date DESC');

return ['incoming' => $queryIncoming, 'passed' => $queryPassed];
$queryIncoming = clone $this->createDefaultQuery()
->filterByUser($user)
->filterIsIncoming();

$queryPassed = clone $this->createDefaultQuery()
->filterByUser($user)
->filterIsPassed();

return [
'incoming' => $queryIncoming,
'passed' => $queryPassed
];
}

/**
@@ -274,17 +237,14 @@ class OrderRepository extends AbstractRepository

public function findOneOrderLastOfYear(Producer $producer)
{
return Order::find()->innerJoinWith('distribution', true)
return $this->createDefaultQuery()
->innerJoinWith('distribution', true)
->where(['>=', 'distribution.date', date('Y') . '-01-01'])
->andWhere([
'distribution.id_producer' => $producer->id
])
->andWhere(['not', ['order.reference' => null]])
->orderBy('order.reference DESC')
->one();
->findOne();
}

// searchByDistribution
public function findProductDistributionsByDistribution(Distribution $distribution): array
{
$orderArray = $this->findOrdersByDistribution($distribution);
@@ -307,8 +267,8 @@ class OrderRepository extends AbstractRepository

public function isCreditAutoPayment(Order $order)
{
$pointSale = PointSale::findOne($order->id_point_sale);
$distribution = Distribution::findOne($order->id_distribution);
$pointSale = $this->pointSaleRepository->findOnePointSaleById($order->id_point_sale);
$distribution = $this->distributionRepository->findOneDistributionById($order->id_distribution);

if($pointSale) {
$creditFunctioning = $this->producerRepository->getPointSaleCreditFunctioning($pointSale);
@@ -321,10 +281,10 @@ class OrderRepository extends AbstractRepository
return 0;
}
elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) {
$userProducer = UserProducer::searchOne([
'id_user' => $order->id_user,
'id_producer' => $distribution->id_producer
]);
$userProducer = $this->userProducerRepository->findOneUserProducer(
$order->user,
$distribution->producer
);
if ($userProducer) {
return $userProducer->credit_active;
}
@@ -334,5 +294,4 @@ class OrderRepository extends AbstractRepository

return 0;
}

}

+ 45
- 0
common/logic/Order/Order/Repository/OrderRepositoryQuery.php Wyświetl plik

@@ -4,6 +4,7 @@ namespace common\logic\Order\Order\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Order\Order\Service\OrderDefinition;
use common\logic\User\User\Model\User;

class OrderRepositoryQuery extends AbstractRepositoryQuery
{
@@ -13,4 +14,48 @@ class OrderRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(OrderDefinition::class);
}

public function filterById(int $id): self
{
$this->andWhere(['order.id' => $id]);

return $this;
}

public function filterByDistributionDate(string $date): self
{
$this->andWhere(['distribution.date' => $date]);

return $this;
}

public function filterIsValid(): self
{
$this->andWhere('date_delete IS NULL');

return $this;
}

public function filterByUser(User $user): self
{
$this->andWhere(['order.id_user' => $user->id]);

return $this;
}

public function filterIsIncoming(): self
{
$this->andWhere('distribution.date >= :date_today')
->params([':date_today' => date('Y-m-d')]);

return $this;
}

public function filterIsPassed(): self
{
$this->andWhere('distribution.date < :date_today')
->params([':date_today' => date('Y-m-d')]);

return $this;
}
}

+ 6
- 4
common/logic/Order/ProductOrder/Repository/ProductOrderRepository.php Wyświetl plik

@@ -27,13 +27,15 @@ class ProductOrderRepository extends AbstractRepository

public function findOneProductOrderById(int $id)
{
return $productOrder = ProductOrder::searchOne([
'id' => $id
]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findProductOrdersByOrder(Order $order): array
{
return ProductOrder::find()->where(['id_order' => $order->id])->all();
return $this->createDefaultQuery()
->filterByOrder($order)
->find();
}
}

+ 8
- 0
common/logic/Order/ProductOrder/Repository/ProductOrderRepositoryQuery.php Wyświetl plik

@@ -3,6 +3,7 @@
namespace common\logic\Order\ProductOrder\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\Order\ProductOrder\Service\ProductOrderDefinition;
use yii\db\ActiveQuery;
@@ -15,4 +16,11 @@ class ProductOrderRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(ProductOrderDefinition::class);
}

public function filterByOrder(Order $order): self
{
$this->andWhere(['id_order' => $order->id]);

return $this;
}
}

+ 31
- 34
common/logic/PointSale/PointSale/Repository/PointSaleRepository.php Wyświetl plik

@@ -2,7 +2,6 @@

namespace common\logic\PointSale\PointSale\Repository;

use common\helpers\GlobalParam;
use common\logic\AbstractRepository;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\PointSale\PointSale\Model\PointSale;
@@ -30,60 +29,61 @@ class PointSaleRepository extends AbstractRepository

public function findOnePointSaleById(int $id): ?PointSale
{
return PointSale::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findOnePointSaleByIdUser(int $idUser): ?PointSale
{
return PointSale::searchOne([
'id_user' => $idUser
]);
return $this->createDefaultQuery()
->filterIsOnline()
->filterByIdUser($idUser)
->findOne();
}

public function findOnePointSaleByName(string $name): ?PointSale
{
return PointSale::searchOne([
'name' => $name
]);
return $this->createDefaultQuery()
->filterIsOnline()
->filterByName($name)
->fineOne();
}

public function findPointSalesByDistribution(Distribution $distribution)
{
return PointSale::find()
return $this->createDefaultQuery()
->filterIsOnline()
->with(['pointSaleDistribution' => function ($q) use ($distribution) {
$q->where(['id_distribution' => $distribution->id]);
}])
->where([
'id_producer' => $distribution->producer->id,
])
->all();
->find();
}

/**
* Retourne le nombre de points de vente pour le producteur courant.
*/
public static function countPointSales(): int
public function countPointSales(): int
{
return PointSale::searchCount(['id_producer' => GlobalParam::getCurrentProducerId()]);
return $this->createDefaultQuery()
->filterIsOnline()
->count();
}

public function findPointSales()
{
return PointSale::find()
->where('id_producer = ' . GlobalParam::getCurrentProducerId())
->all();;
return $this->createDefaultQuery()
->filterIsOnline()
->find();
}

public function queryPointSalesPublic(Producer $producer)
{
return PointSale::find()
->where([
'id_producer' => $producer->id,
'restricted_access' => 0,
'status' => 1
])->orderBy(
'code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC'
);
return $this->createDefaultQuery()
->filterIsOnline()
->filterByRestrictedAccess(0)
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC')
->query();
}

public function populatePointSaleDropdownList(): array
@@ -100,13 +100,10 @@ class PointSaleRepository extends AbstractRepository

public function findByBillingUser(User $user)
{
return PointSale::find()
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
'status' => 1,
'id_user' => $user->id
])->orderBy(
'name ASC'
)->all();
return $this->createDefaultQuery()
->filterIsOnline()
->filterByIdUser($user->id)
->orderBy('name ASC')
->find();
}
}

+ 28
- 0
common/logic/PointSale/PointSale/Repository/PointSaleRepositoryQuery.php Wyświetl plik

@@ -15,4 +15,32 @@ class PointSaleRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(PointSaleDefinition::class);
}

public function filterByIdUser(int $idUser): self
{
$this->andWhere(['id_user' => $idUser]);

return $this;
}

public function filterByName(string $name): self
{
$this->andWhere(['name' => $name]);

return $this;
}

public function filterIsOnline(): self
{
$this->andWhere(['status' => 1]);

return $this;
}

public function filterByRestrictedAccess(int $restrictedAccess): self
{
$this->andWhere(['restricted_access' => $restrictedAccess]);

return $this;
}
}

+ 7
- 8
common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepository.php Wyświetl plik

@@ -28,9 +28,9 @@ class UserPointSaleRepository extends AbstractRepository

public function findUserPointSalesByUser(User $user): array
{
return UserPointSale::searchAll([
'id_user' => $user->id
]);
return $this->createDefaultQuery()
->filterByUser($user)
->find();
}

public function findOneUserPointSale(User $user = null, PointSale $pointSale = null)
@@ -39,10 +39,9 @@ class UserPointSaleRepository extends AbstractRepository
return null;
}

return UserPointSale::find()
->where([
'id_user' => $user->id,
'id_point_sale' => $pointSale->id
])->one();
return $this->createDefaultQuery()
->filterByUser($user)
->filterByPointSale($pointSale)
->findOne();
}
}

+ 16
- 0
common/logic/PointSale/UserPointSale/Repository/UserPointSaleRepositoryQuery.php Wyświetl plik

@@ -3,8 +3,10 @@
namespace common\logic\PointSale\UserPointSale\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\UserPointSale\Model\UserPointSale;
use common\logic\PointSale\UserPointSale\Service\UserPointSaleDefinition;
use common\logic\User\User\Model\User;
use yii\db\ActiveQuery;

class UserPointSaleRepositoryQuery extends AbstractRepositoryQuery
@@ -15,4 +17,18 @@ class UserPointSaleRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(UserPointSaleDefinition::class);
}

public function filterByUser(User $user): self
{
$this->andWhere(['id_user' => $user->id]);

return $this;
}

public function filterByPointSale(PointSale $pointSale): self
{
$this->andWhere(['id_point_sale' => $pointSale->id]);

return $this;
}
}

+ 18
- 37
common/logic/Producer/Producer/Repository/ProducerRepository.php Wyświetl plik

@@ -37,7 +37,7 @@ class ProducerRepository extends AbstractRepository
public function getDefaultOptionsSearch(): array
{
return [
self::WITH => ['taxRate'],
self::WITH => ['taxRate', 'contact'],
self::JOIN_WITH => [],
self::ORDER_BY => 'name ASC',
self::ATTRIBUTE_ID_PRODUCER => 'id'
@@ -46,43 +46,43 @@ class ProducerRepository extends AbstractRepository

public function findOneProducerById(int $id)
{
return Producer::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findOneProducerBySlug(string $slug)
{
return Producer::searchOne(['slug' => $slug]);
return $this->createDefaultQuery()
->filterBySlug($slug)
->findOne();
}

public function queryProducersActive()
{
return Producer::find()
->where([
'active' => true,
])
->orderBy('name ASC');
return $this->createDefaultQuery()
->filterIsActive();
}

/**
* Retourne le compte producteur de démonstration.
*
*/
public function findOneProducerDemoAccount()
{
return Producer::find()->where('name LIKE \'Démo\'')->one();
return $this->createDefaultQuery()
->filterIsDemoAccount()
->findOne();
}

/**
* Retourne la liste des établissements pour l'initialisation d'une listesélective.
*/
public static function populateProducerDropdown(): array
public function populateProducerDropdown(): array
{
$producers = Producer::find()
->where([
'active' => true,
])
return $this->createDefaultQuery()
->filterIsActive()
->orderBy('postcode, city ASC')
->all();
->find();

$departments = Departments::get();
$dataProducers = [];
@@ -222,7 +222,6 @@ class ProducerRepository extends AbstractRepository

/**
* Retourne une configuration d'un producteur donné
*
*/
public function getConfig(string $config = '', int $idProducer = 0)
{
@@ -240,23 +239,6 @@ class ProducerRepository extends AbstractRepository
return null;
}

/**
* Retourne les établissements liés à l'utilisateur.
*/
// getBookmarked
public function findProducersBookmarked(User $user): array
{
$producers = (new \yii\db\Query())
->select('*')
->from(['user_producer', 'producer'])
->where('user_producer.id_producer = producer.id')
->andWhere(['user_producer.id_user' => $user->id])
->andWhere(['user_producer.active' => 1])
->all();

return $producers;
}

public function getNameProducer(User $user): string
{
$producer = $this->findOneProducerById($user->id_producer);
@@ -273,7 +255,6 @@ class ProducerRepository extends AbstractRepository
/**
* Retourne le mode de fonctionnement du crédit d'un point de vente.
*/
// getCreditFunctioning
public function getPointSaleCreditFunctioning(PointSale $pointSale): string
{
return strlen($pointSale->credit_functioning) > 0 ?
@@ -283,11 +264,11 @@ class ProducerRepository extends AbstractRepository

public function findProducersActive()
{
return Producer::find()->where(['producer.active' => 1])->with(['contact'])->all();
return $this->queryProducersActive()->find();
}

public function findProducers()
{
return Producer::find()->with(['contact'])->all();
return $this->createDefaultQuery()->find();
}
}

+ 18
- 0
common/logic/Producer/Producer/Repository/ProducerRepositoryQuery.php Wyświetl plik

@@ -15,4 +15,22 @@ class ProducerRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(ProducerDefinition::class);
}

public function filterBySlug(int $slug): self
{
$this->andWhere(['slug' => $slug]);
return $this;
}

public function filterIsActive(): self
{
$this->andWhere(['producer.active' => true]);
return $this;
}

public function filterIsDemoAccount(): self
{
$this->andWhere('name LIKE \'Démo\'');
return $this;
}
}

+ 6
- 6
common/logic/Producer/ProducerPriceRange/Repository/ProducerPriceRangeRepository.php Wyświetl plik

@@ -17,28 +17,28 @@ class ProducerPriceRangeRepository extends AbstractRepository

/**
* Retourne les options de base nécessaires à la fonction de recherche.
*
*/
public function getDefaultOptionsSearch(): array
{
return [
self::WITH => [],
self::JOIN_WITH => [],
self::ORDER_BY => '',
self::ORDER_BY => 'range_begin ASC',
self::ATTRIBUTE_ID_PRODUCER => ''
];
}

public function findOneProducerPriceRangeById(int $id)
{
return ProducerPriceRange::searchOne([
'id' => $id
]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function queryProducerPriceRanges()
{
return ProducerPriceRange::find()->orderBy('range_begin ASC');
return $this->createDefaultQuery()
->find();
}

public function findProducerPriceRanges()

+ 20
- 36
common/logic/Product/Product/Repository/ProductRepository.php Wyświetl plik

@@ -34,51 +34,48 @@ class ProductRepository extends AbstractRepository
return [
self::WITH => ['taxRate', 'productPointSale'],
self::JOIN_WITH => [],
self::ORDER_BY => 'order ASC',
self::ORDER_BY => 'product.order ASC',
self::ATTRIBUTE_ID_PRODUCER => 'product.id_producer'
];
}

public function findOneProductById(int $id): ?Product
{
return Product::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findOneProductByName(string $name): ?Product
{
return Product::searchOne(['name' => $name]);
return $this->createDefaultQuery()
->filterByName($name)
->findOne();
}

public function findProducts(): array
{
return Product::searchAll([], [
'orderby' => 'product.order ASC'
]);
return $this->createDefaultQuery()->find();
}

/**
* Retourne le nombre de produits du producteur courant.
*/
public static function countProducts(): int
public function countProducts(): int
{
return Product::searchCount();
return $this->createDefaultQuery()->count();
}

/**
* Retourne les produits d'une production donnée.
*/
// searchByDistribution
// getByDistribution
public function findProductsByDistribution(Distribution $distribution)
{
$productArray = Product::find()
$productArray = $this->createDefaultQuery()
->leftJoin('product_distribution', 'product.id = product_distribution.id_product')
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
'product_distribution.id_distribution' => $distribution->id
])
->filterByDistribution($distribution)
->orderBy('product_distribution.active DESC, product.order ASC')
->all();
->find();

$productArrayById = [];
foreach($productArray as $product) {
@@ -88,32 +85,19 @@ class ProductRepository extends AbstractRepository
return $productArrayById;
}

// queryByProductCategory
public function queryProductsByProductCategory(ProductCategory $productCategory)
{
return Product::find()
->andWhere([
'id_producer' => $this->getProducerContext()->id,
'active' => true,
])
->andWhere(
'product.id_product_category = :id_product_category'
)
->params(
[':id_product_category' => $productCategory->id]
)
->orderBy(
'order ASC'
);
return $this->createDefaultQuery()
->filterIsActive()
->filterByProductCategory($productCategory);
}

public function countProductsWithoutCategory(Producer $producer): int
{
return Product::searchCount([
'id_producer' => $producer->id,
'product.active' => 1,
'product.id_product_category' => null
]);
return $this->createDefaultQuery()
->filterIsActive()
->filterByProductCategory(null)
->count();
}

public function getPriceArray(Product $product, User $user = null, PointSale $pointSale = null): array

+ 26
- 0
common/logic/Product/Product/Repository/ProductRepositoryQuery.php Wyświetl plik

@@ -3,7 +3,9 @@
namespace common\logic\Product\Product\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Product\Product\Service\ProductDefinition;
use common\logic\Product\ProductCategory\Model\ProductCategory;

class ProductRepositoryQuery extends AbstractRepositoryQuery
{
@@ -13,4 +15,28 @@ class ProductRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(ProductDefinition::class);
}

public function filterByName(string $name): self
{
$this->andWhere(['name' => $name]);
return $this;
}

public function filterByDistribution(Distribution $distribution): self
{
$this->andWhere(['product_distribution.id_distribution' => $distribution->id]);
return $this;
}

public function filterIsActive(): self
{
$this->andWhere(['product.active' => true]);
return $this;
}

public function filterByProductCategory(ProductCategory $productCategory = null) : self
{
$this->andWhere(['product.id_product_category' => $productCategory->id]);
return $this;
}
}

+ 10
- 18
common/logic/Product/ProductCategory/Repository/ProductCategoryRepository.php Wyświetl plik

@@ -19,39 +19,31 @@ class ProductCategoryRepository extends AbstractRepository
return [
self::WITH => [],
self::JOIN_WITH => [],
self::ORDER_BY => '',
self::ORDER_BY => 'product_category.position ASC',
self::ATTRIBUTE_ID_PRODUCER => 'id_producer'
];
}

public function findOneProductCategoryById(int $id)
{
return ProductCategory::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findProductCategories()
{
return ProductCategory::searchAll([
'id_producer' => $this->getProducerContext()->id
],
[
'orderby' => 'product_category.position ASC'
]
);
return $this->createDefaultQuery()->find();
}

public function findProductCategoriesAsArray()
public function findProductCategoriesAsArray(): array
{
return ProductCategory::searchAll(
[],
[
'orderby' => 'product_category.position ASC',
'as_array' => true
]
);
return $this->createDefaultQuery()
->asArray()
->find();
}

public function populateProductCategoriesDropdownList()
public function populateProductCategoriesDropdownList(): array
{
$productCategoriesArrayDropdown = ['' => '--'];
$productCategoriesArray = $this->findProductCategories();

+ 10
- 7
common/logic/Product/ProductPrice/Repository/ProductPriceRepository.php Wyświetl plik

@@ -33,29 +33,32 @@ class ProductPriceRepository extends AbstractRepository

public function findOneProductPriceById(int $id): ?ProductPrice
{
return ProductPrice::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findOneProductPriceBy(Product $product, User $user = null, UserGroup $userGroup = null, PointSale $pointSale = null, float $fromQuantity = null)
{
$params = ['id_product' => $product->id];
$query = $this->createDefaultQuery()
->filterByProduct($product);

if($user) {
$params['id_user'] = $user->id;
$query->filterByUser($user);
}

if($userGroup) {
$params['id_user_group'] = $userGroup->id;
$query->filterByUserGroup($userGroup);
}

if($pointSale) {
$params['id_point_sale'] = $pointSale->id;
$query->filterByPointSale($pointSale);
}

if($fromQuantity) {
$params['from_quantity'] = $fromQuantity;
$query->filterByFromQuantity($fromQuantity);
}

return ProductPrice::searchOne($params);
return $query->findOne();
}
}

+ 34
- 0
common/logic/Product/ProductPrice/Repository/ProductPriceRepositoryQuery.php Wyświetl plik

@@ -3,8 +3,12 @@
namespace common\logic\Product\ProductPrice\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Product\Product\Model\Product;
use common\logic\Product\ProductPrice\Model\ProductPrice;
use common\logic\Product\ProductPrice\Service\ProductPriceDefinition;
use common\logic\User\User\Model\User;
use common\logic\User\UserGroup\Model\UserGroup;
use yii\db\ActiveQuery;

class ProductPriceRepositoryQuery extends AbstractRepositoryQuery
@@ -15,4 +19,34 @@ class ProductPriceRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(ProductPriceDefinition::class);
}

public function filterByProduct(Product $product): self
{
$this->andWhere(['id_product' => $product->id]);
return $this;
}

public function filterByUser(User $user): self
{
$this->andWhere(['id_user' => $user->id]);
return $this;
}

public function filterByUserGroup(UserGroup $userGroup): self
{
$this->andWhere(['id_user_group' => $userGroup->id]);
return $this;
}

public function filterByPointSale(PointSale $pointSale): self
{
$this->andWhere(['id_point_sale' => $pointSale->id]);
return $this;
}

public function filterByFromQuantity(float $fromQuantity): self
{
$this->andWhere(['from_quantity' => $fromQuantity]);
return $this;
}
}

+ 3
- 3
common/logic/Subscription/ProductSubscription/Repository/ProductSubscriptionRepository.php Wyświetl plik

@@ -30,8 +30,8 @@ class ProductSubscriptionRepository extends AbstractRepository

public function findProductSubscriptionsBySubscription(Subscription $subscription): array
{
return ProductSubscription::searchAll([
'id_subscription' => $subscription->id
]);
return $this->createDefaultQuery()
->filterBySubscription($subscription)
->find();
}
}

+ 7
- 0
common/logic/Subscription/ProductSubscription/Repository/ProductSubscriptionRepositoryQuery.php Wyświetl plik

@@ -5,6 +5,7 @@ namespace common\logic\Subscription\ProductSubscription\Repository;
use common\logic\AbstractRepositoryQuery;
use common\logic\Subscription\ProductSubscription\Model\ProductSubscription;
use common\logic\Subscription\ProductSubscription\Service\ProductSubscriptionDefinition;
use common\logic\Subscription\Subscription\Model\Subscription;
use yii\db\ActiveQuery;

class ProductSubscriptionRepositoryQuery extends AbstractRepositoryQuery
@@ -15,4 +16,10 @@ class ProductSubscriptionRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(ProductSubscriptionDefinition::class);
}

public function filterBySubscription(Subscription $subscription): self
{
$this->andWhere(['id_subscription' => $subscription->id]);
return $this;
}
}

+ 8
- 9
common/logic/Subscription/Subscription/Repository/SubscriptionRepository.php Wyświetl plik

@@ -31,18 +31,19 @@ class SubscriptionRepository extends AbstractRepository

public function findOneSubscriptionById(int $id): ?Subscription
{
return Subscription::searchOne(['id' => $id]);
return $this->createDefaultQuery()
->filterById($id)
->findOne();
}

public function findSubscriptions()
{
return Subscription::searchAll();
return $this->createDefaultQuery()->find();
}

/**
* Retourne les abonnements pour une date donnée.
*/
// searchByDate, getByDate
public function findSubscriptionsByDate(string $date)
{
$date = date('Y-m-d', strtotime($date));
@@ -60,12 +61,10 @@ class SubscriptionRepository extends AbstractRepository
return $subscriptionReturnArray;
}

public function countSubscriptionsByUser(User $user, Producer $producer)
public function countSubscriptionsByUser(User $user)
{
return Subscription::find()
->where([
'subscription.id_user' => $user->id,
'subscription.id_producer' => $producer->id,
])->count();
return $this->createDefaultQuery()
->filterByUser($user)
->count();
}
}

+ 7
- 0
common/logic/Subscription/Subscription/Repository/SubscriptionRepositoryQuery.php Wyświetl plik

@@ -4,6 +4,7 @@ namespace common\logic\Subscription\Subscription\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Subscription\Subscription\Service\SubscriptionDefinition;
use common\logic\User\User\Model\User;

class SubscriptionRepositoryQuery extends AbstractRepositoryQuery
{
@@ -13,4 +14,10 @@ class SubscriptionRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(SubscriptionDefinition::class);
}

public function filterByUser(User $user): self
{
$this->andWhere(['subscription.id_user' => $user->id]);
return $this;
}
}

+ 3
- 3
common/logic/User/CreditHistory/Repository/CreditHistoryRepository.php Wyświetl plik

@@ -27,8 +27,8 @@ class CreditHistoryRepository extends AbstractRepository

public function getByOrder(Order $order)
{
return CreditHistory::find()
->where(['id_order' => $order->id])
->all();
return $this->createDefaultQuery()
->filterByOrder($order)
->find();
}
}

+ 7
- 0
common/logic/User/CreditHistory/Repository/CreditHistoryRepositoryQuery.php Wyświetl plik

@@ -3,6 +3,7 @@
namespace common\logic\User\CreditHistory\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Order\Order\Model\Order;
use common\logic\User\CreditHistory\Service\CreditHistoryDefinition;

class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery
@@ -13,4 +14,10 @@ class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery
{
$this->loadDefinition(CreditHistoryDefinition::class);
}

public function filterByOrder(Order $order): self
{
$this->andWhere(['id_order' => $order->id]);
return $this;
}
}

+ 0
- 2
common/logic/User/User/Repository/UserRepositoryQuery.php Wyświetl plik

@@ -3,9 +3,7 @@
namespace common\logic\User\User\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\User\User\Model\User;
use common\logic\User\User\Service\UserDefinition;
use yii\db\ActiveQuery;

class UserRepositoryQuery extends AbstractRepositoryQuery
{

+ 1
- 1
producer/controllers/OrderController.php Wyświetl plik

@@ -117,7 +117,7 @@ class OrderController extends ProducerBaseController
$queryHistoryPassed = $queryHistoryArray['passed'];

$dataProviderOrders = new ActiveDataProvider([
'query' => ($type == 'incoming') ? $queryHistoryIncoming : $queryHistoryPassed,
'query' => ($type == 'incoming') ? $queryHistoryIncoming->query() : $queryHistoryPassed->query(),
'pagination' => [
'pageSize' => 10,
],

+ 1
- 1
producer/controllers/SiteController.php Wyświetl plik

@@ -104,7 +104,7 @@ class SiteController extends ProducerBaseController
$dataProviderProductsByCategories = [];
foreach ($productCategoryArray as $productCategory) {
$dataProviderProductsByCategories[$productCategory->id] = new ActiveDataProvider([
'query' => $productManager->queryProductsByProductCategory($productCategory),
'query' => $productManager->queryProductsByProductCategory($productCategory)->query(),
'pagination' => [
'pageSize' => 500,
],

+ 1
- 2
producer/views/layouts/main.php Wyświetl plik

@@ -152,8 +152,7 @@ if (!Yii::$app->user->isGuest) {
$countSubcriptions = 0;
if($userCurrent) {
$countSubcriptions = $this->getSubscriptionManager()->countSubscriptionsByUser(
$userCurrent,
GlobalParam::getCurrentProducer()
$userCurrent
);
}


Ładowanie…
Anuluj
Zapisz