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