|
|
@@ -4,6 +4,7 @@ namespace domain\Product\Rotating; |
|
|
|
|
|
|
|
use common\components\Date; |
|
|
|
use domain\_\AbstractManager; |
|
|
|
use domain\Distribution\Distribution\Distribution; |
|
|
|
use domain\Distribution\Distribution\DistributionRepository; |
|
|
|
use domain\Distribution\Distribution\DistributionResolver; |
|
|
|
use domain\Distribution\DistributionRotating\DistributionRotatingManager; |
|
|
@@ -20,8 +21,10 @@ class RotatingManager extends AbstractManager |
|
|
|
protected DistributionRepository $distributionRepository; |
|
|
|
protected DistributionRotatingManager $distributionRotatingManager; |
|
|
|
protected RotatingResolver $rotatingResolver; |
|
|
|
protected DistributionResolver $distributionResolver; |
|
|
|
|
|
|
|
/** |
|
|
|
* @throws ErrorException |
|
|
|
*/ |
|
|
|
public function loadDependencies(): void |
|
|
|
{ |
|
|
|
$this->rotatingBuilder = $this->loadService(RotatingBuilder::class); |
|
|
@@ -30,7 +33,6 @@ class RotatingManager extends AbstractManager |
|
|
|
$this->distributionRepository = $this->loadService(DistributionRepository::class); |
|
|
|
$this->distributionRotatingManager = $this->loadService(DistributionRotatingManager::class); |
|
|
|
$this->rotatingResolver = $this->loadService(RotatingResolver::class); |
|
|
|
$this->distributionResolver = $this->loadService(DistributionResolver::class); |
|
|
|
} |
|
|
|
|
|
|
|
public function createRotating(Producer $producer, string $name, int $day, array $productsIdsArray): Rotating |
|
|
@@ -67,15 +69,23 @@ class RotatingManager extends AbstractManager |
|
|
|
$dateLastDistributionIncoming = $this->distributionResolver->getDateLastDistributionIncoming(); |
|
|
|
|
|
|
|
while($distribution && $date < $dateLastDistributionIncoming) { |
|
|
|
$rotatingProduct = $this->rotatingResolver->deductNextRotatingProductOfDistribution($rotating, $distribution); |
|
|
|
$this->distributionRotatingManager->createDistributionRotatingIfNotExist( |
|
|
|
$distribution, |
|
|
|
$rotatingProduct |
|
|
|
); |
|
|
|
$this->initializeRotatingInDistribution($rotating, $distribution); |
|
|
|
$distribution = $this->rotatingResolver->getNextDistribution($rotating, $date); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @throws ErrorException |
|
|
|
*/ |
|
|
|
public function initializeRotatingInDistribution(Rotating $rotating, Distribution $distribution) |
|
|
|
{ |
|
|
|
$rotatingProduct = $this->rotatingResolver->deductNextRotatingProductOfDistribution($rotating, $distribution); |
|
|
|
$this->distributionRotatingManager->createDistributionRotatingIfNotExist( |
|
|
|
$distribution, |
|
|
|
$rotatingProduct |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public function deleteRotating(Rotating $rotating): bool |
|
|
|
{ |
|
|
|
$this->deleteAllRotatingProducts($rotating); |