|
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\models\TaxRate;
- use Yii;
- use common\models\User;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- use common\helpers\Upload;
- use common\models\Producer;
- use yii\data\ActiveDataProvider;
- use common\models\Invoice;
-
-
- class TaxRateAdminController extends BackendController
- {
-
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['post'],
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return User::getCurrentStatus() == USER::STATUS_ADMIN;
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $dataProviderTaxRate = new ActiveDataProvider([
- 'query' => TaxRate::find()
- ]);
-
- return $this->render('index', [
- 'dataProviderTaxRate' => $dataProviderTaxRate,
- ]);
- }
-
-
-
- public function actionCreate()
- {
- $model = new TaxRate();
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- Yii::$app->getSession()->setFlash('success', 'Taxe créé.');
- return $this->redirect(['index']);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionUpdate($id)
- {
-
-
- $model = $this->findModel($id);
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- Yii::$app->getSession()->setFlash('success', 'Taxe édité.');
- return $this->redirect(['index']);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionDelete($id)
- {
- $taxeRate = TaxRate::searchOne([
- 'id' => $id
- ]) ;
- $taxeRate->delete();
-
- Yii::$app->getSession()->setFlash('success', 'Taxe supprimé');
- return $this->redirect(['tax-rate-admin/index']);
- }
-
-
-
-
- protected function findModel($id)
- {
- if (($model = TaxRate::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|