Adaptation des fonctionnalités dépendantes suite à l'ajout du champs "actif" dans la table "user_etablissement".prodstable
@@ -798,10 +798,10 @@ class CommandeController extends BackendController { | |||
{ | |||
// changement état | |||
$production = Production::find()->where(['date' => $date])->one(); | |||
$production = Production::find()->where(['date' => $date, 'id_etablissement' => Yii::$app->user->identity->id_etablissement])->one(); | |||
$production->actif = $actif; | |||
$production->save(); | |||
// add commandes automatiques | |||
if($actif) | |||
{ |
@@ -66,6 +66,7 @@ class UserController extends BackendController | |||
->select('*') | |||
->from('user, user_etablissement') | |||
->where('user.id = user_etablissement.id_user') | |||
->andWhere('user_etablissement.actif = 1') | |||
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) | |||
]); | |||
@@ -108,6 +109,8 @@ class UserController extends BackendController | |||
$user_etablissement = new UserEtablissement() ; | |||
$user_etablissement->id_user = $model->id ; | |||
$user_etablissement->id_etablissement = Yii::$app->user->identity->id_etablissement ; | |||
$user_etablissement->credit = 0 ; | |||
$user_etablissement->actif = 1 ; | |||
$user_etablissement->save() ; | |||
// send mail | |||
@@ -196,6 +199,7 @@ PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compt | |||
->select('*') | |||
->from('user, user_etablissement') | |||
->where('user.id = user_etablissement.id_user') | |||
->andWhere('user_etablissement.actif = 1') | |||
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) | |||
->all() ; | |||
@@ -203,7 +203,7 @@ foreach ($produits as $p) { | |||
</span> | |||
<span class="the-title"></span> | |||
<span class="choix-user"> | |||
<?= Html::activeDropDownList(new User, 'id', ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->all(), 'id', function($model, $defaultValue) { | |||
<?= Html::activeDropDownList(new User, 'id', ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->andWhere('user_etablissement.actif = 1')->all(), 'id', function($model, $defaultValue) { | |||
return $model['nom'].' '.$model['prenom']; | |||
}), ['prompt' => '--','class' => 'form-control user-id']) ?> | |||
OU <input type="text" class="form-control username" placeholder="Choisissez un nom" /> |
@@ -11,7 +11,7 @@ use common\models\PointVente ; | |||
<div class="commandeauto-form"> | |||
<?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?> | |||
<div class="col-md-5" id="bloc-select-user"> | |||
<?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->orderBy('nom ASC, prenom ASC')->all(), 'id', function($model, $defaultValue) { | |||
<?= $form->field($model, 'id_user')->dropDownList( ArrayHelper::map(User::find()->joinWith('userEtablissement')->where('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)->andWhere('user_etablissement.actif = 1')->orderBy('nom ASC, prenom ASC')->all(), 'id', function($model, $defaultValue) { | |||
return $model['nom'].' '.$model['prenom']; | |||
}), ['prompt' => '--','class' => 'form-control user-id', ]) ?> | |||
</div> |
@@ -249,6 +249,7 @@ class User extends ActiveRecord implements IdentityInterface | |||
->from(['user_etablissement', 'etablissement']) | |||
->where('user_etablissement.id_etablissement = etablissement.id') | |||
->andWhere(['user_etablissement.id_user' => $this->id]) | |||
->andWhere(['user_etablissement.actif' => 1]) | |||
->all(); | |||
$arr_etabs = array() ; |
@@ -203,7 +203,9 @@ class CommandeController extends \yii\web\Controller { | |||
->where(['id_etablissement'=>$id, 'id_user' => Yii::$app->user->identity->id]) | |||
->one() ; | |||
$user_etablissement->delete() ; | |||
$user_etablissement->actif = 0 ; | |||
$user_etablissement->save() ; | |||
$this->redirect(['commande/index']) ; | |||
} | |||
@@ -33,7 +33,11 @@ class AddEtablissementForm extends Model | |||
} | |||
$user_etablissement_exist = UserEtablissement::find() | |||
->where(['id_user'=>Yii::$app->user->identity->id, 'id_etablissement' =>$this->id_etablissement]) | |||
->where([ | |||
'id_user' => Yii::$app->user->identity->id, | |||
'id_etablissement' => $this->id_etablissement, | |||
'actif' => 1 | |||
]) | |||
->one() ; | |||
if($user_etablissement_exist) | |||
@@ -84,11 +88,28 @@ class AddEtablissementForm extends Model | |||
{ | |||
$etablissement = Etablissement::findOne($this->id_etablissement) ; | |||
$user_etablissement = new UserEtablissement() ; | |||
$user_etablissement->id_user = Yii::$app->user->identity->id ; | |||
$user_etablissement->id_etablissement = $this->id_etablissement ; | |||
$user_etablissement->save() ; | |||
$user_etablissement_exist = UserEtablissement::find() | |||
->where([ | |||
'id_user' => Yii::$app->user->identity->id, | |||
'id_etablissement' => $this->id_etablissement, | |||
'actif' => 0 | |||
]) | |||
->one() ; | |||
if($user_etablissement_exist) | |||
{ | |||
$user_etablissement_exist->actif = 1 ; | |||
$user_etablissement_exist->save() ; | |||
} | |||
else { | |||
$user_etablissement = new UserEtablissement() ; | |||
$user_etablissement->id_user = Yii::$app->user->identity->id ; | |||
$user_etablissement->id_etablissement = $this->id_etablissement ; | |||
$user_etablissement->credit = 0 ; | |||
$user_etablissement->actif = 1 ; | |||
$user_etablissement->save() ; | |||
} | |||
Yii::$app->session->setFlash('success', 'La boulangerie <strong>'.Html::encode($etablissement->nom).'</strong> a bien été ajoutée à votre tableau de bord.') ; | |||
} | |||
} |
@@ -230,6 +230,8 @@ Guillaume" ; | |||
$etab_user = new UserEtablissement ; | |||
$etab_user->id_etablissement = $this->id_etablissement ; | |||
$etab_user->id_user = $user->id ; | |||
$etab_user->credit = 0 ; | |||
$etab_user->actif = 1 ; | |||
$etab_user->save() ; | |||
} | |||
} | |||
@@ -240,6 +242,8 @@ Guillaume" ; | |||
$etab_user = new UserEtablissement ; | |||
$etab_user->id_etablissement = $etablissement->id ; | |||
$etab_user->id_user = $user->id ; | |||
$etab_user->credit = 0 ; | |||
$etab_user->actif = 1 ; | |||
$etab_user->save() ; | |||
} | |||