Browse Source

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

dev
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

use common\models\Document ; use common\models\Document ;
use common\helpers\GlobalParam ; use common\helpers\GlobalParam ;
use common\models\Order ; use common\models\Order ;
use yii\base\UserException;


class DocumentController extends BackendController class DocumentController extends BackendController
{ {
'id' => $id '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()) { if ($model && $model->load(Yii::$app->request->post()) && $model->save()) {


Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('update', $model)); Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('update', $model));
public function actionAjaxAddProduct($idDocument, $classDocument, $idProduct, $quantity, $price) public function actionAjaxAddProduct($idDocument, $classDocument, $idProduct, $quantity, $price)
{ {

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

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

'contentOptions' => ['class' => 'column-actions'], 'contentOptions' => ['class' => 'column-actions'],
'buttons' => [ 'buttons' => [
'update' => function ($url, $model) { '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' 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]);
]) : '');
}, },
'delete' => function ($url, $model) { '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' 'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
]) : '');
} }
], ],
], ],

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

return '<span class="label label-'.$classLabel.'">'.$label.'</span>' ; 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