Просмотр исходного кода

Mise en place de la fonctionnalité activer/désactiver les productions d'une semaine en fonction des jours de livraison des points de vente

refactoring
keun 6 лет назад
Родитель
Сommit
b984bc4bcb
2 измененных файлов: 82 добавлений и 29 удалений
  1. +50
    -29
      backend/controllers/CommandeController.php
  2. +32
    -0
      common/models/Production.php

+ 50
- 29
backend/controllers/CommandeController.php Просмотреть файл

@@ -242,33 +242,7 @@ class CommandeController extends BackendController {
}

// création du jour de production
$production = null;
if ($date != '') {
$production = Production::find()
->where(['date' => $date])
->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->one();
if (!$production) {
$production = new Production;
$production->date = $date;
$production->livraison = 1;
$production->id_etablissement = Yii::$app->user->identity->id_etablissement;
$production->save();
}
}

// production_point_vente à définir s'ils ne sont pas initialisés
if ($production) {
$count_productions_point_vente = ProductionPointVente::find()->
where([
'id_production' => $production->id
])
->count();

if (!$count_productions_point_vente) {
ProductionPointVente::setAll($production->id, true);
}
}
$production = Production::initProduction($date) ;

// points de vente
if ($production) {
@@ -847,9 +821,10 @@ class CommandeController extends BackendController {
$this->redirect(['index', 'date' => $date]);
}

public function actionChangeState($date, $actif) {
public function actionChangeState($date, $actif, $redirect = true) {
// changement état
$production = Production::find()->where(['date' => $date, 'id_etablissement' => Yii::$app->user->identity->id_etablissement])->one();
$production = Production::initProduction($date) ;
$production->actif = $actif;
$production->save();

@@ -858,6 +833,52 @@ class CommandeController extends BackendController {
CommandeAuto::addAll($date);
}

if($redirect)
$this->redirect(['index', 'date' => $date]);
}
public function actionChangeStateSemaine($date, $actif) {
$week = sprintf('%02d',date('W',strtotime($date)));
$start = strtotime(date('Y',strtotime($date)).'W'.$week);
$date_lundi = date('Y-m-d',strtotime('Monday',$start)) ;
$date_mardi = date('Y-m-d',strtotime('Tuesday',$start)) ;
$date_mercredi = date('Y-m-d',strtotime('Wednesday',$start)) ;
$date_jeudi = date('Y-m-d',strtotime('Thursday',$start)) ;
$date_vendredi = date('Y-m-d',strtotime('Friday',$start)) ;
$date_samedi = date('Y-m-d',strtotime('Saturday',$start)) ;
$date_dimanche = date('Y-m-d',strtotime('Sunday',$start)) ;
$points_vente = PointVente::find()
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement,])
->all();
$lundi_active = false ;
$mardi_active = false ;
$mercredi_active = false ;
$jeudi_active = false ;
$vendredi_active = false ;
$samedi_active = false ;
$dimanche_active = false ;
foreach($points_vente as $pv) {
if($pv->livraison_lundi) $lundi_active = true ;
if($pv->livraison_mardi) $mardi_active = true ;
if($pv->livraison_mercredi) $mercredi_active = true ;
if($pv->livraison_jeudi) $jeudi_active = true ;
if($pv->livraison_vendredi) $vendredi_active = true ;
if($pv->livraison_samedi) $samedi_active = true ;
if($pv->livraison_dimanche) $dimanche_active = true ;
}
if($lundi_active || !$actif) $this->actionChangeState($date_lundi, $actif, false) ;
if($mardi_active || !$actif) $this->actionChangeState($date_mardi, $actif, false) ;
if($mercredi_active || !$actif) $this->actionChangeState($date_mercredi, $actif, false) ;
if($jeudi_active || !$actif) $this->actionChangeState($date_jeudi, $actif, false) ;
if($vendredi_active || !$actif) $this->actionChangeState($date_vendredi, $actif, false) ;
if($samedi_active || !$actif) $this->actionChangeState($date_samedi, $actif, false) ;
if($dimanche_active || !$actif) $this->actionChangeState($date_dimanche, $actif, false) ;

$this->redirect(['index', 'date' => $date]);
}


+ 32
- 0
common/models/Production.php Просмотреть файл

@@ -70,5 +70,37 @@ class Production extends \yii\db\ActiveRecord {

return false;
}
public static function initProduction($date) {
$production = null ;
if ($date != '') {
$production = Production::find()
->where(['date' => $date])
->andWhere(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->one();
if (!$production) {
$production = new Production;
$production->date = $date;
$production->livraison = 1;
$production->id_etablissement = Yii::$app->user->identity->id_etablissement;
$production->save();
}
}

// production_point_vente à définir s'ils ne sont pas initialisés
if ($production) {
$count_productions_point_vente = ProductionPointVente::find()->
where([
'id_production' => $production->id
])
->count();

if (!$count_productions_point_vente) {
ProductionPointVente::setAll($production->id, true);
}
}
return $production ;
}

}

Загрузка…
Отмена
Сохранить