public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = $this->getLogic()->getTaxRateContainer()->getFactory()->create(); | |||||
$model = $this->getTaxRateManager()->createTaxRate(); | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
$this->setFlash('success', 'Taxe créé.'); | |||||
$this->setFlash('success', 'Taxe créée.'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
$this->setFlash('success', 'Taxe édité.'); | |||||
$this->setFlash('success', 'Taxe éditée.'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ |
namespace common\components; | namespace common\components; | ||||
use common\logic\Config\TaxRate\TaxRateContainer; | use common\logic\Config\TaxRate\TaxRateContainer; | ||||
use common\logic\Config\TaxRate\TaxRateManager; | |||||
use common\logic\Distribution\Distribution\DistributionContainer; | use common\logic\Distribution\Distribution\DistributionContainer; | ||||
use common\logic\Distribution\Distribution\DistributionManager; | |||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer; | use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer; | ||||
use common\logic\Distribution\ProductDistribution\ProductDistributionContainer; | use common\logic\Distribution\ProductDistribution\ProductDistributionContainer; | ||||
use common\logic\Document\Document\DocumentContainer; | use common\logic\Document\Document\DocumentContainer; | ||||
return new OrderManager(); | return new OrderManager(); | ||||
} | } | ||||
public function getTaxRateManager(): TaxRateManager | |||||
{ | |||||
return new TaxRateManager(); | |||||
} | |||||
public function getDistributionManager(): DistributionManager | |||||
{ | |||||
return new DistributionManager(); | |||||
} | |||||
public function getUserContainer(): UserContainer | public function getUserContainer(): UserContainer | ||||
{ | { | ||||
return new UserContainer(); | return new UserContainer(); |
class TaxRateBuilder extends BaseService implements BuilderInterface | class TaxRateBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
public function instanciate(): TaxRate | |||||
public function instanciateTaxRate(): TaxRate | |||||
{ | { | ||||
$taxRate = new TaxRate(); | $taxRate = new TaxRate(); | ||||
return $taxRate; | return $taxRate; | ||||
} | } | ||||
public function createTaxRate(): TaxRate | |||||
{ | |||||
$taxRate = $this->instanciateTaxRate(); | |||||
$taxRate->save(); | |||||
return $taxRate; | |||||
} | |||||
} | } |
<?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()); | |||||
} | |||||
} |
$this->productOrderBuilder = $this->loadService(ProductOrderBuilder::class); | $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(); | $distribution = new Distribution(); | ||||
} | } | ||||
// initDistribution | // 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(); | $distribution->save(); | ||||
$this->initPointSaleDistribution($distribution); | $this->initPointSaleDistribution($distribution); | ||||
return $distribution; | 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); | $distribution = $this->distributionRepository->getOne($producer, $date); | ||||
if (!$distribution) { | if (!$distribution) { | ||||
$distribution = $this->create($producer, $date, 1); | |||||
$distribution = $this->createDistribution($producer, $date, 1); | |||||
} | } | ||||
return $distribution; | return $distribution; |
<?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()); | |||||
} | |||||
} |
]); | ]); | ||||
} | } | ||||
public function getOne(Producer $producer, string $date) | |||||
public function getOne(Producer $producer, string $date): ?Distribution | |||||
{ | { | ||||
$paramsDistribution = [ | $paramsDistribution = [ | ||||
'date' => $date, | 'date' => $date, | ||||
return Distribution::searchOne($paramsDistribution); | return Distribution::searchOne($paramsDistribution); | ||||
} | } | ||||
public function getOneByDate(string $date) | |||||
public function getOneByDate(string $date): ?Distribution | |||||
{ | { | ||||
return Distribution::searchOne([ | return Distribution::searchOne([ | ||||
'distribution.date' => $date | 'distribution.date' => $date |
use common\logic\User\UserProducer\UserProducerRepository; | use common\logic\User\UserProducer\UserProducerRepository; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
/** | |||||
* | |||||
*/ | |||||
class OrderBuilder extends BaseService implements BuilderInterface | class OrderBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
protected UserSolver $userSolver; | protected UserSolver $userSolver; |
if (isset($paymentIntentMetadata->order_id)) { | if (isset($paymentIntentMetadata->order_id)) { | ||||
$order = $this->getOrderManager()->findOneById($paymentIntentMetadata->order_id); | $order = $this->getOrderManager()->findOneById($paymentIntentMetadata->order_id); | ||||
$pointSale = $this->getLogic()->getPointSaleContainer()->getRepostory()->getOneById($order->id_point_sale); | $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 | // Handle the event |
$params['order'] = $order; | $params['order'] = $order; | ||||
} | } | ||||
if ($this->getDistributionContainer()->getRepository()->isDateAvailable($producer, $date)) { | |||||
if ($this->getDistributionManager()->isDateAvailable($producer, $date)) { | |||||
$params['date'] = $date; | $params['date'] = $date; | ||||
} | } | ||||
$json['points_sale'] = $this->ajaxInfosPointsSale($producer); | $json['points_sale'] = $this->ajaxInfosPointsSale($producer); | ||||
if ($dateObject && $dateObject->format($format) === $date) { | if ($dateObject && $dateObject->format($format) === $date) { | ||||
$distribution = $this->getDistributionContainer()->getBuilder()->createIfNotExist($producer, $date); | |||||
$distribution = $this->getDistributionManager()->createDistributionIfNotExist($producer, $date); | |||||
$json['distribution'] = $distribution; | $json['distribution'] = $distribution; | ||||
$json['points_sale'] = $this->ajaxInfosPointsSale($producer, $distribution); | $json['points_sale'] = $this->ajaxInfosPointsSale($producer, $distribution); | ||||
$json['categories'] = $this->ajaxInfosProductCategories($producer); | $json['categories'] = $this->ajaxInfosProductCategories($producer); |