Gestion des points de fabrication. Le boulanger peut définir dans le backend quel point de vente correspond à son lieu de production.prodstable
$model = new PointVente(); | $model = new PointVente(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
$model->gestionPointFabrication() ; | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
$model->gestionPointFabrication() ; | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ |
<?php $form = ActiveForm::begin(); ?> | <?php $form = ActiveForm::begin(); ?> | ||||
<?php //$form->field($model, 'point_fabrication')->checkbox() ?> | |||||
<?= $form->field($model, 'point_fabrication')->checkbox()->hint('Cochez cette case si ce point de vente correspond à votre lieu de production.') ?> | |||||
<?= $form->field($model, 'nom')->textInput(['maxlength' => 255]) ?> | <?= $form->field($model, 'nom')->textInput(['maxlength' => 255]) ?> | ||||
<?= $form->field($model, 'localite')->textInput(['maxlength' => 255]) ?> | |||||
<?= $form->field($model, 'localite')->textInput(['maxlength' => 255]) ?> | |||||
<?= $form->field($model, 'adresse')->textarea(['rows' => 6]) ?> | <?= $form->field($model, 'adresse')->textarea(['rows' => 6]) ?> | ||||
<h2>Horaires</h2> | <h2>Horaires</h2> |
'columns' => [ | 'columns' => [ | ||||
'nom', | 'nom', | ||||
'localite', | 'localite', | ||||
[ | |||||
'attribute' => 'point_fabrication', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
if($model->point_fabrication) | |||||
{ | |||||
return '<span class="label label-success">Oui</span>' ; | |||||
} | |||||
else { | |||||
return '<span class="label label-danger">Non</span>' ; | |||||
} | |||||
} | |||||
], | |||||
[ | [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update} {delete}', | 'template' => '{update} {delete}', |
$this->pain = 1 ; | $this->pain = 1 ; | ||||
return parent::save($runValidation, $attributeNames) ; | return parent::save($runValidation, $attributeNames) ; | ||||
} | } | ||||
public function gestionPointFabrication() | |||||
{ | |||||
if($this->point_fabrication) | |||||
{ | |||||
PointVente::updateAll( | |||||
['point_fabrication' => 0], | |||||
['id_etablissement' => $this->id_etablissement] | |||||
) ; | |||||
$this->point_fabrication = 1 ; | |||||
$this->save() ; | |||||
} | |||||
} | |||||
} | } |