@@ -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)) { |
@@ -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' | |||
]); | |||
]) : ''); | |||
} | |||
], | |||
], |
@@ -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) ; | |||
} | |||
} |