diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 505192e..9c6cc74 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -35,6 +35,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']]; // } + $items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']]; if ( count($items) > 0 ){ $userMainMenu = ['label' => 'Beállítások', 'url' => null, diff --git a/backend/controllers/WarehouseController.php b/backend/controllers/WarehouseController.php new file mode 100644 index 0000000..72358a6 --- /dev/null +++ b/backend/controllers/WarehouseController.php @@ -0,0 +1,125 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Warehouse models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new WarehouseSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Warehouse model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Warehouse model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Warehouse(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_warehouse]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Warehouse 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_warehouse]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Warehouse model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $warehouse = $this->findModel($id); + + $warehouse->updateAttributes(['status' => Warehouse::STATUS_DELETED]); + + + return $this->redirect(['index']); + } + + /** + * Finds the Warehouse model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Warehouse the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Warehouse::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/WarehouseSearch.php b/backend/models/WarehouseSearch.php new file mode 100644 index 0000000..18aa9f6 --- /dev/null +++ b/backend/models/WarehouseSearch.php @@ -0,0 +1,69 @@ + $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_warehouse' => $this->id_warehouse, + 'status' => $this->status, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/views/warehouse/_form.php b/backend/views/warehouse/_form.php new file mode 100644 index 0000000..64299eb --- /dev/null +++ b/backend/views/warehouse/_form.php @@ -0,0 +1,24 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/warehouse', "Active") ]) ?> + +
+ isNewRecord ? Yii::t('common/warehouse', 'Create') : Yii::t('common/warehouse', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/warehouse/_search.php b/backend/views/warehouse/_search.php new file mode 100644 index 0000000..d7c2548 --- /dev/null +++ b/backend/views/warehouse/_search.php @@ -0,0 +1,35 @@ + + + diff --git a/backend/views/warehouse/create.php b/backend/views/warehouse/create.php new file mode 100644 index 0000000..f387718 --- /dev/null +++ b/backend/views/warehouse/create.php @@ -0,0 +1,21 @@ +title = Yii::t('common/warehouse', 'Create Warehouse'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/warehouse', 'Warehouses'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

title) ?>

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

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

+ + $dataProvider, + 'columns' => [ + 'name', + [ + 'attribute' => 'status', + 'value' => 'statusHuman', + ], + 'created_at:datetime', + 'updated_at:datetime', + + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{view} {update}' + ], + ], + ]); ?> + +
diff --git a/backend/views/warehouse/update.php b/backend/views/warehouse/update.php new file mode 100644 index 0000000..f66f77e --- /dev/null +++ b/backend/views/warehouse/update.php @@ -0,0 +1,23 @@ +title = Yii::t('common/warehouse', 'Update {modelClass}: ', [ + 'modelClass' => '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]]; +$this->params['breadcrumbs'][] = Yii::t('common/warehouse', 'Update'); +?> +
+ +

title) ?>

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

title) ?>

+ +

+ $model->id_warehouse], ['class' => 'btn btn-primary']) ?> + $model->id_warehouse], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('common/warehouse', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) */ + ?> +

+ + $model, + 'attributes' => [ + 'name', + [ + 'attribute' => 'status', + 'label' => Yii::t('common/warehouse', "Active"), + 'value' => $model->statusHuman + ], + 'created_at', + 'updated_at', + ], + ]) ?> + +
diff --git a/common/messages/hu/common/warehouse.php b/common/messages/hu/common/warehouse.php new file mode 100644 index 0000000..e3f71d8 --- /dev/null +++ b/common/messages/hu/common/warehouse.php @@ -0,0 +1,34 @@ + 'Aktív', + 'Inactive' => 'Inaktív', + 'Reset' => '', + 'Create' => 'Mentés', + 'Create Warehouse' => 'Új raktár', + 'Created At' => 'Létrehozás ideje', + 'Id Warehouse' => 'Azonosító', + 'Name' => 'Név', + 'Search' => 'Keresés', + 'Status' => 'Státusz', + 'Update' => 'Módosítás', + 'Update {modelClass}: ' => '{modelClass} módosítása: ', + 'Updated At' => 'Módosítás ideje', + 'Warehouses' => 'Raktárak', +]; diff --git a/common/models/Warehouse.php b/common/models/Warehouse.php new file mode 100644 index 0000000..db5006b --- /dev/null +++ b/common/models/Warehouse.php @@ -0,0 +1,86 @@ + 64] + ]; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + [ 'class' => TimestampBehavior::className(), + 'value' => function(){ return date('Y-m-d H:i' ); } + ] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id_warehouse' => Yii::t('common/warehouse', 'Id Warehouse'), + 'name' => Yii::t('common/warehouse', 'Name'), + 'status' => Yii::t('common/warehouse', 'Status'), + 'created_at' => Yii::t('common/warehouse', 'Created At'), + 'updated_at' => Yii::t('common/warehouse', 'Updated At'), + ]; + } + + + static function statuses() { + return [ + self::STATUS_ACTIVE => Yii::t('common/warehouse', 'Active'), + self::STATUS_DELETED => Yii::t('common/warehouse', 'Inactive'), + ]; + } + + public function getStatusHuman(){ + $result = null; + $s = self::statuses($this->status); + if ( array_key_exists($this->status, $s)){ + $result = $s[$this->status]; + } + return $result; + } + +} diff --git a/console/migrations/m150919_200109_add__table__warehouse.php b/console/migrations/m150919_200109_add__table__warehouse.php new file mode 100644 index 0000000..d324a74 --- /dev/null +++ b/console/migrations/m150919_200109_add__table__warehouse.php @@ -0,0 +1,42 @@ +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('{{%warehouse}}', [ + 'id_warehouse' => $this->primaryKey(), + 'name' => $this->string(64)->notNull(), + 'status' => $this->smallInteger()->notNull()->defaultValue(10), + 'created_at' => $this->timestamp()->notNull(), + 'updated_at' => $this->timestamp()->notNull(), + ], $tableOptions); + } + + public function down() + { +// echo "m150919_200109_add__table__warehouse cannot be reverted.\n"; + +// return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +}