Browse Source

Merge branch 'fix/commandes_annulee' into dev

refactoring
Guillaume Bourgeois 6 years ago
parent
commit
e12bceb343
3 changed files with 36 additions and 22 deletions
  1. +4
    -4
      producer/controllers/CommandeController.php
  2. +3
    -2
      producer/views/commande/_form.php
  3. +29
    -16
      producer/views/commande/historique.php

+ 4
- 4
producer/controllers/CommandeController.php View File

'id_user' => Yii::$app->user->id, 'id_user' => Yii::$app->user->id,
'production.id_etablissement' => $this->getProducer()->id 'production.id_etablissement' => $this->getProducer()->id
]) ])
->andWhere('date_delete IS NULL')
->orderBy('production.date DESC'), ->orderBy('production.date DESC'),
'pagination' => [ 'pagination' => [
'pageSize' => 10, 'pageSize' => 10,
*/ */
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 {

+ 3
- 2
producer/views/commande/_form.php View File

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

+ 29
- 16
producer/views/commande/historique.php View File

'label' => 'Statut', 'label' => 'Statut',
'format' => 'raw', 'format' => 'raw',
'value' => function($c) { 'value' => function($c) {
if($c->getEtat() == Commande::ETAT_LIVREE) {
return 'Livrée' ;
$html = '' ;
if($c->date_delete) {
$html .= '<span class="label label-danger">Annulée</span><br />' ;
if($c->getEtat() == Commande::ETAT_MODIFIABLE) {
$html .= '<a href="'.Yii::$app->urlManager->createUrl(['commande/update','id'=>$c->id, 'id_etablissement'=>$c->production->etablissement->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>' ;
}
} }
elseif($c->getEtat() == Commande::ETAT_PREPARATION) {
return 'En préparation' ;
}
elseif($c->getEtat() == Commande::ETAT_MODIFIABLE) {
return '<div class="btn-group">
<a href="'.Yii::$app->urlManager->createUrl(['commande/update','id'=>$c->id, 'id_etablissement'=>$c->production->etablissement->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="'.Yii::$app->urlManager->createUrl(['commande/annuler','id'=>$c->id]).'"><span class="glyphicon glyphicon-trash"></span> Annuler la commande</a></li>
</ul>
</div>' ;
else {
if($c->getEtat() == Commande::ETAT_LIVREE) {
$html .= '<span class="label label-success">Livrée</span>' ;
}
elseif($c->getEtat() == Commande::ETAT_PREPARATION) {
$html .= '<span class="label label-warning">En préparation</span>' ;
}
elseif($c->getEtat() == Commande::ETAT_MODIFIABLE) {
$html .= '<span class="label label-default">Ouverte</span><br />' ;
$html .= '<div class="btn-group">
<a href="'.Yii::$app->urlManager->createUrl(['commande/update','id'=>$c->id, 'id_etablissement'=>$c->production->etablissement->id]).'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="'.Yii::$app->urlManager->createUrl(['commande/annuler','id'=>$c->id]).'"><span class="glyphicon glyphicon-trash"></span> Annuler la commande</a></li>
</ul>
</div>' ;
}
} }
return $html ;
} }
], ],
] ]

Loading…
Cancel
Save