Browse Source

[Command] Activation de distributions à l'avance #1381

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
4723c0f991
5 changed files with 39 additions and 30 deletions
  1. +10
    -0
      common/components/BusinessLogic.php
  2. +5
    -1
      common/helpers/GlobalParam.php
  3. +3
    -2
      console/commands/ActiveDistributionsInAdvanceController.php
  4. +21
    -0
      console/commands/ClosingOrdersController.php
  5. +0
    -27
      console/commands/DemoAccountController.php

+ 10
- 0
common/components/BusinessLogic.php View File

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();

+ 5
- 1
common/helpers/GlobalParam.php View File

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;
} }



+ 3
- 2
console/commands/ActiveDistributionsInAdvanceController.php View File

$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";
} }
} }
} }

+ 21
- 0
console/commands/ClosingOrdersController.php View File

<?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) {

}
}
}

?>

+ 0
- 27
console/commands/DemoAccountController.php View File

<?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);
}
}
}

?>

Loading…
Cancel
Save