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 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/account', "Active") ]) ?> + + field($model, 'type')->dropDownList(Account::types()) ?> + + +
+ isNewRecord ? Yii::t('common/account', 'Create') : Yii::t('common/account', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/account/_search.php b/backend/views/account/_search.php new file mode 100644 index 0000000..35b39c8 --- /dev/null +++ b/backend/views/account/_search.php @@ -0,0 +1,37 @@ + + + diff --git a/backend/views/account/create.php b/backend/views/account/create.php new file mode 100644 index 0000000..c30047a --- /dev/null +++ b/backend/views/account/create.php @@ -0,0 +1,21 @@ +title = Yii::t('common/account', 'Create Account'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/account', 'Accounts'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/account/index.php b/backend/views/account/index.php new file mode 100644 index 0000000..e6405a1 --- /dev/null +++ b/backend/views/account/index.php @@ -0,0 +1,44 @@ +title = Yii::t('common/account', 'Accounts'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'columns' => [ + 'name', + [ + 'attribute' => 'status', + 'value' => 'statusHuman', + ], + [ + 'attribute' => 'type', + 'value' => 'typeHuman', + ], + 'created_at:datetime', + 'updated_at:datetime', + + ['class' => 'yii\grid\ActionColumn', + 'template' => '{view} {update}' + + ], + ], + ]); ?> + +
diff --git a/backend/views/account/update.php b/backend/views/account/update.php new file mode 100644 index 0000000..3510e0c --- /dev/null +++ b/backend/views/account/update.php @@ -0,0 +1,23 @@ +title = Yii::t('common/account', 'Update {modelClass}: ', [ + 'modelClass' => Yii::t('common/account', 'Account'), +]) . ' ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/account', 'Accounts'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_account]]; +$this->params['breadcrumbs'][] = Yii::t('common/account', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/account/view.php b/backend/views/account/view.php new file mode 100644 index 0000000..16a1f80 --- /dev/null +++ b/backend/views/account/view.php @@ -0,0 +1,48 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/account', 'Accounts'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $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', + ], + ]) */ + ?> +

+ + $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', + ], + ]) ?> + +
diff --git a/backend/views/warehouse/update.php b/backend/views/warehouse/update.php index f66f77e..96f31aa 100644 --- a/backend/views/warehouse/update.php +++ b/backend/views/warehouse/update.php @@ -6,7 +6,7 @@ use yii\helpers\Html; /* @var $model common\models\Warehouse */ $this->title = Yii::t('common/warehouse', 'Update {modelClass}: ', [ - 'modelClass' => 'Warehouse', + 'modelClass' => Yii::t("common/warehouse", "Warehouse"), ]) . ' ' . $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('common/warehouse', 'Warehouses'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_warehouse]]; diff --git a/common/messages/hu/common/account.php b/common/messages/hu/common/account.php new file mode 100644 index 0000000..ada5708 --- /dev/null +++ b/common/messages/hu/common/account.php @@ -0,0 +1,38 @@ + 'Kasszák', + 'Account' => 'Kassza', + 'Active' => 'Aktív', + 'Create' => 'Inaktív', + 'Create Account' => 'Új kassza', + 'Created At' => 'Létrehozás ideje', + 'Id Account' => 'Azonosító', + 'Inactive' => 'Inaktív', + 'Name' => 'Név', + 'Only the name is visible' => 'Csak a név látható', + 'Reset' => '', + 'Search' => 'Keresés', + 'Status' => 'Státusz', + 'Type' => 'Típus', + 'Update' => 'Módosítás', + 'Update {modelClass}: ' => '{modelClass} módosítása: ', + 'Updated At' => 'Módosítás ideje', + 'Visible for all' => 'Mindenkinek látható', +]; diff --git a/common/messages/hu/common/warehouse.php b/common/messages/hu/common/warehouse.php index e3f71d8..264d8f3 100644 --- a/common/messages/hu/common/warehouse.php +++ b/common/messages/hu/common/warehouse.php @@ -31,4 +31,5 @@ return [ 'Update {modelClass}: ' => '{modelClass} módosítása: ', 'Updated At' => 'Módosítás ideje', 'Warehouses' => 'Raktárak', + 'Warehouse' => 'Raktár', ]; diff --git a/common/models/Account.php b/common/models/Account.php new file mode 100644 index 0000000..d4db0bd --- /dev/null +++ b/common/models/Account.php @@ -0,0 +1,106 @@ + TimestampBehavior::className(), + 'value' => function(){ return date('Y-m-d H:i:s' ); } + ] + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['name', 'type'], 'required'], + [['name', ], 'unique'], + [['status', 'type'], 'integer'], + [['name'], 'string', 'max' => 64] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id_account' => Yii::t('common/account', 'Id Account'), + 'name' => Yii::t('common/account', 'Name'), + 'status' => Yii::t('common/account', 'Status'), + 'type' => Yii::t('common/account', 'Type'), + 'created_at' => Yii::t('common/account', 'Created At'), + 'updated_at' => Yii::t('common/account', 'Updated At'), + ]; + } + + static function statuses() { + return [ + self::STATUS_ACTIVE => Yii::t('common/account', 'Active'), + self::STATUS_DELETED => Yii::t('common/account', 'Inactive'), + ]; + } + + public function getStatusHuman(){ + $result = null; + $s = self::statuses($this->status); + if ( array_key_exists($this->status, $s)){ + $result = $s[$this->status]; + } + return $result; + } + + static function types() { + return [ + self::TYPE_ALL => Yii::t('common/account', 'Visible for all'), + self::TYPE_VALUE_HIDDEN => Yii::t('common/account', 'Only the name is visible'), + ]; + } + + public function getTypeHuman(){ + $result = null; + $s = self::types($this->type); + if ( array_key_exists($this->type, $s)){ + $result = $s[$this->status]; + } + return $result; + } +} diff --git a/console/migrations/m150920_191201_add__table__account.php b/console/migrations/m150920_191201_add__table__account.php new file mode 100644 index 0000000..02c766c --- /dev/null +++ b/console/migrations/m150920_191201_add__table__account.php @@ -0,0 +1,40 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('{{%account}}', [ + 'id_account' => $this->primaryKey(), + 'name' => $this->string(64)->notNull(), + 'status' => $this->smallInteger()->notNull()->defaultValue(10), + 'type' => $this->integer(11)->notNull(), + 'created_at' => $this->timestamp()->notNull(), + 'updated_at' => $this->timestamp()->notNull(), + ], $tableOptions); + } + + public function down() + { + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +}