diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 9c6cc74..1461ab4 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -36,6 +36,7 @@ class AdminMenuStructure{ // } $items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']]; + $items[] = ['label' => 'Kasszák', 'url' =>['/account/index']]; if ( count($items) > 0 ){ $userMainMenu = ['label' => 'Beállítások', 'url' => null, diff --git a/backend/controllers/AccountController.php b/backend/controllers/AccountController.php new file mode 100644 index 0000000..eae1482 --- /dev/null +++ b/backend/controllers/AccountController.php @@ -0,0 +1,121 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Account models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new AccountSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Account model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Account model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Account(); + $model->status = Account::STATUS_ACTIVE; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Account model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Account model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ +// public function actionDelete($id) +// { +// $this->findModel($id)->delete(); + +// return $this->redirect(['index']); +// } + + /** + * Finds the Account model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Account the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Account::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/WarehouseController.php b/backend/controllers/WarehouseController.php index 72358a6..f4097d4 100644 --- a/backend/controllers/WarehouseController.php +++ b/backend/controllers/WarehouseController.php @@ -97,15 +97,15 @@ class WarehouseController extends Controller * @param integer $id * @return mixed */ - public function actionDelete($id) - { - $warehouse = $this->findModel($id); +// public function actionDelete($id) +// { +// $warehouse = $this->findModel($id); - $warehouse->updateAttributes(['status' => Warehouse::STATUS_DELETED]); +// $warehouse->updateAttributes(['status' => Warehouse::STATUS_DELETED]); - return $this->redirect(['index']); - } +// return $this->redirect(['index']); +// } /** * Finds the Warehouse model based on its primary key value. diff --git a/backend/models/AccountController.php b/backend/models/AccountController.php new file mode 100644 index 0000000..dadd3eb --- /dev/null +++ b/backend/models/AccountController.php @@ -0,0 +1,121 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Account models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new AccountSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Account model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Account model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Account(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Account model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Account model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Account model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Account the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Account::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/AccountSearch.php b/backend/models/AccountSearch.php new file mode 100644 index 0000000..7543b38 --- /dev/null +++ b/backend/models/AccountSearch.php @@ -0,0 +1,70 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_account' => $this->id_account, + 'status' => $this->status, + 'type' => $this->type, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/views/account/_form.php b/backend/views/account/_form.php new file mode 100644 index 0000000..a4c110a --- /dev/null +++ b/backend/views/account/_form.php @@ -0,0 +1,29 @@ + + +
+ = Html::a(Yii::t('common/account', 'Create Account'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + 'name', + [ + 'attribute' => 'status', + 'value' => 'statusHuman', + ], + [ + 'attribute' => 'type', + 'value' => 'typeHuman', + ], + 'created_at:datetime', + 'updated_at:datetime', + + ['class' => 'yii\grid\ActionColumn', + 'template' => '{view} {update}' + + ], + ], + ]); ?> + ++ = Html::a(Yii::t('common/account', 'Update'), ['update', 'id' => $model->id_account], ['class' => 'btn btn-primary']) ?> + $model->id_account], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('common/account', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) */ + ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'name', + [ + 'attribute' => 'status', + 'label' => Yii::t('common/account', "Active"), + 'value' => $model->statusHuman + ], + [ + 'attribute' => 'type', + 'value' => $model->typeHuman + ], + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + +