Adaptation du formulaire (boutons du bas) de modification en fonction de l'état annulé ou non de la commande.refactoring
*/ | */ | ||||
public function actionUpdate($id) | public function actionUpdate($id) | ||||
{ | { | ||||
$commande = Commande::find() | $commande = Commande::find() | ||||
->with('production') | ->with('production') | ||||
->where(['id' => $id]) | ->where(['id' => $id]) | ||||
$this->gestionForm($commande); | $this->gestionForm($commande); | ||||
} | } | ||||
return $this->render('update', array_merge($this->initForm($commande), [ | return $this->render('update', array_merge($this->initForm($commande), [ | ||||
'model' => $commande, | 'model' => $commande, | ||||
'commande_introuvable' => !$commande, | 'commande_introuvable' => !$commande, | ||||
else | else | ||||
$commande->commentaire_point_vente = ''; | $commande->commentaire_point_vente = ''; | ||||
// la commande est automatiquement réactivée lors d'une modification | |||||
$commande->date_delete = null ; | |||||
// sauvegarde de la commande | // sauvegarde de la commande | ||||
$commande->save(); | $commande->save(); | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
// redirection | // redirection | ||||
$this->redirect(Yii::$app->urlManager->createUrl(['commande/historique', 'commande_ok' => true, 'pate_deja_petrie' => $pate_deja_petrie])); | $this->redirect(Yii::$app->urlManager->createUrl(['commande/historique', 'commande_ok' => true, 'pate_deja_petrie' => $pate_deja_petrie])); | ||||
} else { | } else { |
?> | ?> | ||||
<div id="bar-fixed" class="<?php if($etablissement->credit_pain): ?>credit-pain<?php else: ?>no-credit-pain<?php endif; ?>"> | <div id="bar-fixed" class="<?php if($etablissement->credit_pain): ?>credit-pain<?php else: ?>no-credit-pain<?php endif; ?>"> | ||||
<div class="container"> | <div class="container"> | ||||
<?php if (isset($model->id)): ?> | |||||
<?php if (isset($model->id) && !$model->date_delete): ?> | |||||
<a href="<?php echo Yii::$app->urlManager->createUrl(['commande/annuler', 'id' => $model->id]); ?>" class="btn btn-danger annuler-commande">Annuler ma commande</a> | <a href="<?php echo Yii::$app->urlManager->createUrl(['commande/annuler', 'id' => $model->id]); ?>" class="btn btn-danger annuler-commande">Annuler ma commande</a> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<span id="total-commande-bottom"><span></span> €</span> | <span id="total-commande-bottom"><span></span> €</span> | ||||
<?= $form->field($model, 'commentaire')->textarea(['rows' => 3, 'placeholder' => 'Un commentaire ?'])->label(''); ?> | <?= $form->field($model, 'commentaire')->textarea(['rows' => 3, 'placeholder' => 'Un commentaire ?'])->label(''); ?> | ||||
<div id="bloc-valider-commande"> | <div id="bloc-valider-commande"> | ||||
<?= Html::submitButton('<span class="glyphicon glyphicon-ok"></span> Valider ma commande', ['class' => 'btn btn-primary valider-commande']) ?> | |||||
<?php if($model->date_delete): $str_btn_valider = 'Réactiver ma commande' ; else: $str_btn_valider = 'Valider ma commande' ; endif; ?> | |||||
<?= Html::submitButton('<span class="glyphicon glyphicon-ok"></span> '.$str_btn_valider, ['class' => 'btn btn-primary valider-commande']) ?> | |||||
</div> | </div> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
</div> | </div> |