Bladeren bron

Refactoring services #885

refactoring
Guillaume 1 jaar geleden
bovenliggende
commit
d9a780a4dc
10 gewijzigde bestanden met toevoegingen van 102 en 18 verwijderingen
  1. +3
    -3
      backend/controllers/TaxRateAdminController.php
  2. +12
    -0
      common/components/BusinessLogicContainerTrait.php
  3. +9
    -1
      common/logic/Config/TaxRate/TaxRateBuilder.php
  4. +21
    -0
      common/logic/Config/TaxRate/TaxRateManager.php
  5. +5
    -5
      common/logic/Distribution/Distribution/DistributionBuilder.php
  6. +47
    -0
      common/logic/Distribution/Distribution/DistributionManager.php
  7. +2
    -2
      common/logic/Distribution/Distribution/DistributionRepository.php
  8. +0
    -4
      common/logic/Order/Order/OrderBuilder.php
  9. +1
    -1
      producer/controllers/CreditController.php
  10. +2
    -2
      producer/controllers/OrderController.php

+ 3
- 3
backend/controllers/TaxRateAdminController.php Bestand weergeven

@@ -87,10 +87,10 @@ class TaxRateAdminController extends BackendController

public function actionCreate()
{
$model = $this->getLogic()->getTaxRateContainer()->getFactory()->create();
$model = $this->getTaxRateManager()->createTaxRate();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->setFlash('success', 'Taxe créé.');
$this->setFlash('success', 'Taxe créée.');
return $this->redirect(['index']);
} else {
return $this->render('create', [
@@ -104,7 +104,7 @@ class TaxRateAdminController extends BackendController
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->setFlash('success', 'Taxe édité.');
$this->setFlash('success', 'Taxe éditée.');
return $this->redirect(['index']);
} else {
return $this->render('update', [

+ 12
- 0
common/components/BusinessLogicContainerTrait.php Bestand weergeven

@@ -3,7 +3,9 @@
namespace common\components;

use common\logic\Config\TaxRate\TaxRateContainer;
use common\logic\Config\TaxRate\TaxRateManager;
use common\logic\Distribution\Distribution\DistributionContainer;
use common\logic\Distribution\Distribution\DistributionManager;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer;
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer;
use common\logic\Document\Document\DocumentContainer;
@@ -34,6 +36,16 @@ trait BusinessLogicContainerTrait
return new OrderManager();
}

public function getTaxRateManager(): TaxRateManager
{
return new TaxRateManager();
}

public function getDistributionManager(): DistributionManager
{
return new DistributionManager();
}

public function getUserContainer(): UserContainer
{
return new UserContainer();

+ 9
- 1
common/logic/Config/TaxRate/TaxRateBuilder.php Bestand weergeven

@@ -7,10 +7,18 @@ use common\logic\BuilderInterface;

class TaxRateBuilder extends BaseService implements BuilderInterface
{
public function instanciate(): TaxRate
public function instanciateTaxRate(): TaxRate
{
$taxRate = new TaxRate();

return $taxRate;
}

public function createTaxRate(): TaxRate
{
$taxRate = $this->instanciateTaxRate();
$taxRate->save();

return $taxRate;
}
}

+ 21
- 0
common/logic/Config/TaxRate/TaxRateManager.php Bestand weergeven

@@ -0,0 +1,21 @@
<?php

namespace common\logic\Config\TaxRate;

use common\logic\BaseManager;

/**
* @see TaxRateRepository
* @method array getAsArray()
*
* @see TaxRateBuilder
* @method TaxRate instanciateTaxRate()
* @method TaxRate createTaxRate()
*/
class TaxRateManager extends BaseManager
{
public function __construct()
{
$this->setContainer(new TaxRateContainer());
}
}

+ 5
- 5
common/logic/Distribution/Distribution/DistributionBuilder.php Bestand weergeven

@@ -47,7 +47,7 @@ class DistributionBuilder extends BaseService implements BuilderInterface
$this->productOrderBuilder = $this->loadService(ProductOrderBuilder::class);
}

public function instanciate(Producer $producer, string $date, bool $delivery = true): Distribution
public function instanciateDistribution(Producer $producer, string $date, bool $delivery = true): Distribution
{
$distribution = new Distribution();

@@ -59,9 +59,9 @@ class DistributionBuilder extends BaseService implements BuilderInterface
}

// initDistribution
public function create(Producer $producer, string $date, bool $delivery = true): Distribution
public function createDistribution(Producer $producer, string $date, bool $delivery = true): Distribution
{
$distribution = $this->instanciate($producer, $date, $delivery);
$distribution = $this->instanciateDistribution($producer, $date, $delivery);
$distribution->save();

$this->initPointSaleDistribution($distribution);
@@ -70,12 +70,12 @@ class DistributionBuilder extends BaseService implements BuilderInterface
return $distribution;
}

public function createIfNotExist(Producer $producer, string $date, int $delivery = 1)
public function createDistributionIfNotExist(Producer $producer, string $date, int $delivery = 1)
{
$distribution = $this->distributionRepository->getOne($producer, $date);

if (!$distribution) {
$distribution = $this->create($producer, $date, 1);
$distribution = $this->createDistribution($producer, $date, 1);
}

return $distribution;

+ 47
- 0
common/logic/Distribution/Distribution/DistributionManager.php Bestand weergeven

@@ -0,0 +1,47 @@
<?php

namespace common\logic\Distribution\Distribution;

use common\logic\BaseManager;
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution;
use common\logic\Distribution\ProductDistribution\ProductDistribution;
use common\logic\PointSale\PointSale\PointSale;
use common\logic\Producer\Producer\Producer;
use common\logic\Product\Product\Product;

/**
* @see DistributionSolver
* @method string getDayAsString(Distribution $distribution)
* @method bool isActiveProduct(Distribution $distribution, Product $product)
* @method bool isAvailable(Distribution $distribution)
* @method array filterDistributionsByDateDelay(array $distributionsArray)
* @method bool isPointSaleActive(Distribution $distribution, PointSale $pointSale)
*
* @see DistributionRepository
* @method array defaultOptionsSearch()
* @method Distribution|null getOneById(int $id)
* @method Distribution|null getOne(Producer $producer, string $date)
* @method Distribution|null getOneByDate(string $date)
* @method array getIncoming()
* @method bool isDateAvailable(Producer $producer, string $date = null)
*
* @see DistributionBuilder
* @method Distribution instanciateDistribution(Producer $producer, string $date, bool $delivery = true)
* @method Distribution createDistribution(Producer $producer, string $date, bool $delivery = true)
* @method Distribution createDistributionIfNotExist(Producer $producer, string $date, int $delivery = 1)
* @method void initPointSaleDistribution(Distribution $distribution)
* @method void initProductDistribution(Distribution $distribution)
* @method ProductDistribution linkProduct(Distribution $distribution, Product $product)
* @method void linkProductIncomingDistributions(Product $product)
* @method PointSaleDistribution linkPointSale(Distribution $distribution, PointSale $pointSale)
* @method void linkPointSaleIncomingDistributions(PointSale $pointSale)
* @method void updateOrderProductPrices(Distribution $distribution, Product $product)
* @method void active(Distribution $distribution, bool $active = true)
*/
class DistributionManager extends BaseManager
{
public function __construct()
{
$this->setContainer(new DistributionContainer());
}
}

+ 2
- 2
common/logic/Distribution/Distribution/DistributionRepository.php Bestand weergeven

@@ -33,7 +33,7 @@ class DistributionRepository extends BaseService implements RepositoryInterface
]);
}

public function getOne(Producer $producer, string $date)
public function getOne(Producer $producer, string $date): ?Distribution
{
$paramsDistribution = [
'date' => $date,
@@ -43,7 +43,7 @@ class DistributionRepository extends BaseService implements RepositoryInterface
return Distribution::searchOne($paramsDistribution);
}

public function getOneByDate(string $date)
public function getOneByDate(string $date): ?Distribution
{
return Distribution::searchOne([
'distribution.date' => $date

+ 0
- 4
common/logic/Order/Order/OrderBuilder.php Bestand weergeven

@@ -32,10 +32,6 @@ use common\logic\User\User\UserSolver;
use common\logic\User\UserProducer\UserProducerRepository;
use yii\web\NotFoundHttpException;

/**
*
*/

class OrderBuilder extends BaseService implements BuilderInterface
{
protected UserSolver $userSolver;

+ 1
- 1
producer/controllers/CreditController.php Bestand weergeven

@@ -217,7 +217,7 @@ class CreditController extends ProducerBaseController
if (isset($paymentIntentMetadata->order_id)) {
$order = $this->getOrderManager()->findOneById($paymentIntentMetadata->order_id);
$pointSale = $this->getLogic()->getPointSaleContainer()->getRepostory()->getOneById($order->id_point_sale);
$distribution = $this->getLogic()->getDistributionContainer()->getRepository()->getOneById($order->id_distribution);
$distribution = $this->getDistributionManager()->getOneById($order->id_distribution);
}

// Handle the event

+ 2
- 2
producer/controllers/OrderController.php Bestand weergeven

@@ -77,7 +77,7 @@ class OrderController extends ProducerBaseController
$params['order'] = $order;
}

if ($this->getDistributionContainer()->getRepository()->isDateAvailable($producer, $date)) {
if ($this->getDistributionManager()->isDateAvailable($producer, $date)) {
$params['date'] = $date;
}

@@ -637,7 +637,7 @@ class OrderController extends ProducerBaseController
$json['points_sale'] = $this->ajaxInfosPointsSale($producer);

if ($dateObject && $dateObject->format($format) === $date) {
$distribution = $this->getDistributionContainer()->getBuilder()->createIfNotExist($producer, $date);
$distribution = $this->getDistributionManager()->createDistributionIfNotExist($producer, $date);
$json['distribution'] = $distribution;
$json['points_sale'] = $this->ajaxInfosPointsSale($producer, $distribution);
$json['categories'] = $this->ajaxInfosProductCategories($producer);

Laden…
Annuleren
Opslaan