@@ -0,0 +1,18 @@ | |||
<?php | |||
namespace common\logic; | |||
use yii\db\ActiveRecord; | |||
class BaseBuilder extends BaseService | |||
{ | |||
public function create(ActiveRecord $model): void | |||
{ | |||
$model->save(); | |||
} | |||
public function update(ActiveRecord $model): void | |||
{ | |||
$model->save(); | |||
} | |||
} |
@@ -2,10 +2,10 @@ | |||
namespace common\logic\Config\TaxRate; | |||
use common\logic\BaseService; | |||
use common\logic\BaseBuilder; | |||
use common\logic\BuilderInterface; | |||
class TaxRateBuilder extends BaseService implements BuilderInterface | |||
class TaxRateBuilder extends BaseBuilder implements BuilderInterface | |||
{ | |||
public function instanciateTaxRate(): TaxRate | |||
{ | |||
@@ -17,7 +17,8 @@ class TaxRateBuilder extends BaseService implements BuilderInterface | |||
public function createTaxRate(): TaxRate | |||
{ | |||
$taxRate = $this->instanciateTaxRate(); | |||
$taxRate->save(); | |||
$this->create($taxRate); | |||
return $taxRate; | |||
} |
@@ -2,7 +2,7 @@ | |||
namespace common\logic\Distribution\Distribution; | |||
use common\logic\BaseService; | |||
use common\logic\BaseBuilder; | |||
use common\logic\BuilderInterface; | |||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionBuilder; | |||
@@ -18,7 +18,7 @@ use common\logic\Product\Product\Product; | |||
use common\logic\Product\Product\ProductRepository; | |||
use common\logic\User\UserProducer\UserProducerRepository; | |||
class DistributionBuilder extends BaseService implements BuilderInterface | |||
class DistributionBuilder extends BaseBuilder implements BuilderInterface | |||
{ | |||
protected DistributionRepository $distributionRepository; | |||
protected DistributionSolver $distributionSolver; | |||
@@ -59,7 +59,8 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
public function createDistribution(Producer $producer, string $date, bool $delivery = true): Distribution | |||
{ | |||
$distribution = $this->instanciateDistribution($producer, $date, $delivery); | |||
$distribution->save(); | |||
$this->create($distribution); | |||
$this->createPointSaleDistributions($distribution); | |||
$this->createProductDistributions($distribution); | |||
@@ -130,7 +131,7 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
$pointSaleDistribution->delivery = 1; | |||
} | |||
$pointSaleDistribution->save(); | |||
$this->update($pointSaleDistribution); | |||
return $pointSaleDistribution; | |||
} | |||
@@ -159,7 +160,7 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
$userProducer = null; | |||
if (isset($order->user) && $order->user) { | |||
$user = $order->user; | |||
$userProducer = $this->userProducerRepository->getOne($user, $distribution->producer); | |||
$userProducer = $this->userProducerRepository->findOneUserProducer($user, $distribution->producer); | |||
} | |||
$this->productOrderBuilder->updatePrice( | |||
@@ -183,7 +184,8 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
$this->pointSaleDistributionBuilder->createAllPointSaleDistributions($distribution, true); | |||
$distribution->active = (int) $active; | |||
$distribution->save(); | |||
$this->update($distribution); | |||
if ($active) { | |||
// @TODO : gérer avec les événements |
@@ -89,7 +89,7 @@ class DistributionSolver extends BaseService implements SolverInterface | |||
$dateToday = date('Y-m-d'); | |||
foreach ($distributionsArray as $keyDistribution => $distribution) { | |||
if(!$this->isAvailable($distribution)) { | |||
if(!$this->isDistributionAvailable($distribution)) { | |||
unset($distributionsArray[$keyDistribution]); | |||
} | |||
} | |||
@@ -104,17 +104,15 @@ class DistributionSolver extends BaseService implements SolverInterface | |||
public function isPointSaleActive(Distribution $distribution, PointSale $pointSale): bool | |||
{ | |||
$pointSaleActive = false; | |||
if ($distribution->pointSaleDistribution) { | |||
foreach ($distribution->pointSaleDistribution as $pointSaleDistribution) { | |||
if ($pointSaleDistribution->id_point_sale == $pointSale->id && $pointSaleDistribution->delivery) { | |||
$pointSaleActive = true; | |||
return true; | |||
} | |||
} | |||
} | |||
return $pointSaleActive; | |||
return false; | |||
} | |||
} |
@@ -2,15 +2,14 @@ | |||
namespace common\logic\Distribution\PointSaleDistribution; | |||
use common\helpers\GlobalParam; | |||
use common\logic\BaseService; | |||
use common\logic\BaseBuilder; | |||
use common\logic\BuilderInterface; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\Distribution\Distribution\DistributionRepository; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\PointSale\PointSale\PointSaleRepository; | |||
class PointSaleDistributionBuilder extends BaseService implements BuilderInterface | |||
class PointSaleDistributionBuilder extends BaseBuilder implements BuilderInterface | |||
{ | |||
protected PointSaleDistributionRepository $pointSaleDistributionRepository; | |||
protected PointSaleRepository $pointSaleRepository; | |||
@@ -42,20 +41,16 @@ class PointSaleDistributionBuilder extends BaseService implements BuilderInterfa | |||
public function createPointSaleDistribution(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||
{ | |||
$pointSaleDistribution = $this->instanciatePointSaleDistribution($distribution, $pointSale); | |||
$pointSaleDistribution->save(); | |||
$this->create($pointSaleDistribution); | |||
return $pointSaleDistribution; | |||
} | |||
public function createPointSaleDistributionIfNotExist(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||
{ | |||
$pointSaleDistribution = $this->pointSaleDistributionRepository->findOnePointSaleDistribution($distribution, $pointSale); | |||
if (!$pointSaleDistribution) { | |||
$pointSaleDistribution = $this->createPointSaleDistribution($distribution, $pointSale); | |||
} | |||
return $pointSaleDistribution; | |||
return $this->pointSaleDistributionRepository->findOnePointSaleDistribution($distribution, $pointSale) | |||
?? $this->createPointSaleDistribution($distribution, $pointSale); | |||
} | |||
/** | |||
@@ -96,6 +91,6 @@ class PointSaleDistributionBuilder extends BaseService implements BuilderInterfa | |||
$pointSaleDistribution->delivery = 0; | |||
} | |||
$pointSaleDistribution->save(); | |||
$this->update($pointSaleDistribution); | |||
} | |||
} |
@@ -2,14 +2,14 @@ | |||
namespace common\logic\Distribution\ProductDistribution; | |||
use common\logic\BaseService; | |||
use common\logic\BaseBuilder; | |||
use common\logic\BuilderInterface; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\Distribution\Distribution\DistributionSolver; | |||
use common\logic\Product\Product\Product; | |||
use common\logic\Product\Product\ProductSolver; | |||
class ProductDistributionBuilder extends BaseService implements BuilderInterface | |||
class ProductDistributionBuilder extends BaseBuilder implements BuilderInterface | |||
{ | |||
protected ProductDistributionRepository $productDistributionRepository; | |||
protected DistributionSolver $distributionSolver; | |||
@@ -39,7 +39,7 @@ class ProductDistributionBuilder extends BaseService implements BuilderInterface | |||
->initActive($productDistribution) | |||
->initQuantityMax($productDistribution); | |||
$productDistribution->save(); | |||
$this->create($productDistribution); | |||
return $productDistribution; | |||
} |