namespace common\components; | namespace common\components; | ||||
use common\logic\Producer\Producer\Model\Producer; | use common\logic\Producer\Producer\Model\Producer; | ||||
use common\logic\ProducerContextTrait; | |||||
use yii\base\ErrorException; | use yii\base\ErrorException; | ||||
class BusinessLogic | class BusinessLogic | ||||
{ | { | ||||
protected ?Producer $producerContext = null; | |||||
use BusinessLogicTrait; | use BusinessLogicTrait; | ||||
public function getModules() | public function getModules() | ||||
]; | ]; | ||||
} | } | ||||
public function getProducerContext(): ?Producer | |||||
{ | |||||
return $this->producerContext; | |||||
} | |||||
public function setProducerContext(Producer $producer) | public function setProducerContext(Producer $producer) | ||||
{ | { | ||||
$this->producerContext = $producer; | |||||
foreach($this->getModules() as $module) { | foreach($this->getModules() as $module) { | ||||
foreach($module->getServices() as $serviceClass) { | foreach($module->getServices() as $serviceClass) { | ||||
$instanceService = $serviceClass::getInstance(); | $instanceService = $serviceClass::getInstance(); |
if (!\Yii::$app->user->isGuest) { | if (!\Yii::$app->user->isGuest) { | ||||
return \Yii::$app->user->identity->id_producer; | return \Yii::$app->user->identity->id_producer; | ||||
} | } | ||||
} else { | |||||
} | |||||
elseif(\Yii::$app->controller->module->id == 'app-console') { | |||||
return \Yii::$app->logic->getProducerContext()->id; | |||||
} | |||||
else { | |||||
return \Yii::$app->controller->getProducerCurrent()->id; | return \Yii::$app->controller->getProducerCurrent()->id; | ||||
} | } | ||||
$producersArray = $producerModule->findProducersActive(); | $producersArray = $producerModule->findProducersActive(); | ||||
foreach($producersArray as $producer) { | foreach($producersArray as $producer) { | ||||
\Yii::$app->logic->setProducerContext($producer); | \Yii::$app->logic->setProducerContext($producer); | ||||
$weeksDistributionsActivatedInAdvance = $producerModule->getConfig('option_weeks_distributions_activated_in_advance'); | |||||
$weeksDistributionsActivatedInAdvance = $producerModule->getSolver()->getConfig('option_weeks_distributions_activated_in_advance'); | |||||
if($weeksDistributionsActivatedInAdvance) { | if($weeksDistributionsActivatedInAdvance) { | ||||
$date = new \DateTime('+'.$weeksDistributionsActivatedInAdvance.' weeks'); | $date = new \DateTime('+'.$weeksDistributionsActivatedInAdvance.' weeks'); | ||||
$distributionModule->activeDistributionByDate($date); | |||||
$distributionModule->getBuilder()->activeDistributionByDate($date); | |||||
echo $producer->name. ' : distribution du ' . $date->format('d/m/Y') .' activée' ."\n"; | |||||
} | } | ||||
} | } | ||||
} | } |
<?php | |||||
namespace console\commands; | |||||
use common\logic\Producer\Producer\Module\ProducerModule; | |||||
use yii\console\Controller; | |||||
class ClosingOrdersController extends Controller | |||||
{ | |||||
public function actionIndex() | |||||
{ | |||||
$producerModule = ProducerModule::getInstance(); | |||||
$arrayProducers = $producerModule->getRepository()->findProducers(); | |||||
foreach($arrayProducers as $producer) { | |||||
} | |||||
} | |||||
} | |||||
?> |
<?php | |||||
namespace console\commands; | |||||
use common\logic\Distribution\Distribution\Module\DistributionModule; | |||||
use common\logic\Producer\Producer\Module\ProducerModule; | |||||
use yii\console\Controller; | |||||
class DemoAccountController extends Controller | |||||
{ | |||||
public function actionIndex() | |||||
{ | |||||
$producerModule = ProducerModule::getInstance(); | |||||
$distributionModule =DistributionModule::getInstance(); | |||||
$producerDemo = $producerModule->findOneProducerDemoAccount(); | |||||
\Yii::$app->logic->setProducerContext($producerDemo); | |||||
if ($producerDemo) { | |||||
$dateTime = strtotime("+7 day"); | |||||
$distribution = $distributionModule->createDistributionIfNotExist(date('Y-m-d', $dateTime)); | |||||
$distributionModule->activeDistribution($distribution); | |||||
} | |||||
} | |||||
} | |||||
?> |