@@ -3,10 +3,13 @@ | |||
namespace common\components; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use common\logic\ProducerContextTrait; | |||
use yii\base\ErrorException; | |||
class BusinessLogic | |||
{ | |||
protected ?Producer $producerContext = null; | |||
use BusinessLogicTrait; | |||
public function getModules() | |||
@@ -44,8 +47,15 @@ class BusinessLogic | |||
]; | |||
} | |||
public function getProducerContext(): ?Producer | |||
{ | |||
return $this->producerContext; | |||
} | |||
public function setProducerContext(Producer $producer) | |||
{ | |||
$this->producerContext = $producer; | |||
foreach($this->getModules() as $module) { | |||
foreach($module->getServices() as $serviceClass) { | |||
$instanceService = $serviceClass::getInstance(); |
@@ -80,7 +80,11 @@ class GlobalParam | |||
if (!\Yii::$app->user->isGuest) { | |||
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; | |||
} | |||
@@ -16,10 +16,11 @@ class ActiveDistributionsInAdvanceController extends Controller | |||
$producersArray = $producerModule->findProducersActive(); | |||
foreach($producersArray as $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) { | |||
$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"; | |||
} | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
<?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) { | |||
} | |||
} | |||
} | |||
?> |
@@ -1,27 +0,0 @@ | |||
<?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); | |||
} | |||
} | |||
} | |||
?> |