Browse Source

Modification d'un document : amélioration de la gestion des status #166

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
cc0379687b
3 changed files with 24 additions and 4 deletions
  1. +6
    -0
      backend/controllers/DocumentController.php
  2. +4
    -4
      backend/views/invoice/index.php
  3. +14
    -0
      common/models/Document.php

+ 6
- 0
backend/controllers/DocumentController.php View File

@@ -43,6 +43,7 @@ use common\models\User ;
use common\models\Document ;
use common\helpers\GlobalParam ;
use common\models\Order ;
use yii\base\UserException;

class DocumentController extends BackendController
{
@@ -110,6 +111,10 @@ class DocumentController extends BackendController
'id' => $id
]) ;

if($model->isStatusValid()) {
throw new UserException('Vous ne pouvez pas modifier un document validé.');
}

if ($model && $model->load(Yii::$app->request->post()) && $model->save()) {

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('update', $model));
@@ -215,6 +220,7 @@ class DocumentController extends BackendController
public function actionAjaxAddProduct($idDocument, $classDocument, $idProduct, $quantity, $price)
{

\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if(Document::isValidClass($classDocument)) {

+ 4
- 4
backend/views/invoice/index.php View File

@@ -100,14 +100,14 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]);
]) : '');
},
'delete' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
]) : '');
}
],
],

+ 14
- 0
common/models/Document.php View File

@@ -220,5 +220,19 @@ class Document extends ActiveRecordCommon
return '<span class="label label-'.$classLabel.'">'.$label.'</span>' ;
}

public function isStatus($status)
{
return $this->status == $status ;
}

public function isStatusDraft()
{
return $this->isStatus(self::STATUS_DRAFT) ;
}

public function isStatusValid()
{
return $this->isStatus(self::STATUS_VALID) ;
}

}

Loading…
Cancel
Save