diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php
index 1461ab4..1ff13bb 100644
--- a/backend/components/AdminMenuStructure.php
+++ b/backend/components/AdminMenuStructure.php
@@ -37,6 +37,7 @@ class AdminMenuStructure{
$items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']];
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
+ $items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
if ( count($items) > 0 ){
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
diff --git a/backend/controllers/DiscountController.php b/backend/controllers/DiscountController.php
new file mode 100644
index 0000000..ec82815
--- /dev/null
+++ b/backend/controllers/DiscountController.php
@@ -0,0 +1,123 @@
+ [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => ['post'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * Lists all Discount models.
+ * @return mixed
+ */
+ public function actionIndex()
+ {
+ $searchModel = new DiscountSearch();
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+
+ return $this->render('index', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+
+ /**
+ * Displays a single Discount model.
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionView($id)
+ {
+ return $this->render('view', [
+ 'model' => $this->findModel($id),
+ ]);
+ }
+
+ /**
+ * Creates a new Discount model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ * @return mixed
+ */
+ public function actionCreate()
+ {
+ $model = new Discount();
+
+ $model->status = Discount::STATUS_ACTIVE;
+
+ 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 Discount 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 Discount 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 Discount model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ * @param integer $id
+ * @return Discount the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id)
+ {
+ if (($model = Discount::findOne($id)) !== null) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+ }
+}
diff --git a/backend/models/DiscountSearch.php b/backend/models/DiscountSearch.php
new file mode 100644
index 0000000..8c97f7f
--- /dev/null
+++ b/backend/models/DiscountSearch.php
@@ -0,0 +1,71 @@
+ $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,
+ 'type' => $this->type,
+ 'value' => $this->value,
+ 'created_at' => $this->created_at,
+ 'updated_at' => $this->updated_at,
+ ]);
+
+ $query->andFilterWhere(['like', 'name', $this->name]);
+
+ return $dataProvider;
+ }
+}
diff --git a/backend/views/discount/_form.php b/backend/views/discount/_form.php
new file mode 100644
index 0000000..971db92
--- /dev/null
+++ b/backend/views/discount/_form.php
@@ -0,0 +1,32 @@
+
+
+
diff --git a/backend/views/discount/_search.php b/backend/views/discount/_search.php
new file mode 100644
index 0000000..6a49578
--- /dev/null
+++ b/backend/views/discount/_search.php
@@ -0,0 +1,38 @@
+
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+ = $form->field($model, 'id_warehouse') ?>
+
+ = $form->field($model, 'name') ?>
+
+ = $form->field($model, 'status') ?>
+
+ = $form->field($model, 'type') ?>
+
+ = $form->field($model, 'value') ?>
+
+ field($model, 'created_at') ?>
+
+ field($model, 'updated_at') ?>
+
+
+ = Html::submitButton(Yii::t('common/discount', 'Search'), ['class' => 'btn btn-primary']) ?>
+
+
+
+
+
diff --git a/backend/views/discount/create.php b/backend/views/discount/create.php
new file mode 100644
index 0000000..b8a7e00
--- /dev/null
+++ b/backend/views/discount/create.php
@@ -0,0 +1,21 @@
+title = Yii::t('common/discount', 'Create Discount');
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/discount', 'Discounts'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/views/discount/index.php b/backend/views/discount/index.php
new file mode 100644
index 0000000..a7eba8f
--- /dev/null
+++ b/backend/views/discount/index.php
@@ -0,0 +1,43 @@
+title = Yii::t('common/discount', 'Discounts');
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+ render('_search', ['model' => $searchModel]); ?>
+
+
+ = Html::a(Yii::t('common/discount', 'Create Discount'), ['create'], ['class' => 'btn btn-success']) ?>
+
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'filterModel' => $searchModel,
+ 'columns' => [
+ 'name',
+ [
+ 'attribute' => 'status',
+ 'value' => 'statusHuman',
+ ],
+ [
+ 'attribute' => 'type',
+ 'value' => 'typeHuman',
+ ],
+ 'value',
+ 'created_at:datetime',
+ 'updated_at:datetime',
+
+ ['class' => 'yii\grid\ActionColumn'],
+ ],
+ ]); ?>
+
+
diff --git a/backend/views/discount/update.php b/backend/views/discount/update.php
new file mode 100644
index 0000000..8fc2572
--- /dev/null
+++ b/backend/views/discount/update.php
@@ -0,0 +1,23 @@
+title = Yii::t('common/discount', 'Update {modelClass}: ', [
+ 'modelClass' => 'Discount',
+]) . ' ' . $model->name;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/discount', 'Discounts'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_warehouse]];
+$this->params['breadcrumbs'][] = Yii::t('common/discount', 'Update');
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/views/discount/view.php b/backend/views/discount/view.php
new file mode 100644
index 0000000..75091c1
--- /dev/null
+++ b/backend/views/discount/view.php
@@ -0,0 +1,43 @@
+title = $model->name;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/discount', 'Discounts'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = Html::a(Yii::t('common/discount', 'Update'), ['update', 'id' => $model->id_warehouse], ['class' => 'btn btn-primary']) ?>
+ =
+/* Html::a(Yii::t('common/discount', 'Delete'), ['delete', 'id' => $model->id_warehouse], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => Yii::t('common/discount', 'Are you sure you want to delete this item?'),
+ 'method' => 'post',
+ ],
+ ])*/
+ ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id_warehouse',
+ 'name',
+ 'status',
+ 'type',
+ 'value',
+ 'created_at',
+ 'updated_at',
+ ],
+ ]) ?>
+
+
diff --git a/common/messages/hu/common/discount.php b/common/messages/hu/common/discount.php
new file mode 100644
index 0000000..9001980
--- /dev/null
+++ b/common/messages/hu/common/discount.php
@@ -0,0 +1,36 @@
+ 'Aktív',
+ 'Create' => 'Mentés',
+ 'Create Discount' => 'Új kedvezmény',
+ 'Created At' => 'Létrehozás ideje',
+ 'Discounts' => 'Kedvezmények',
+ 'Discount' => 'Kedvezmény',
+ 'Id Warehouse' => 'Azonosító',
+ 'Inactive' => 'Inaktív',
+ 'Name' => 'Név',
+ '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',
+ 'Value' => 'Kedvezmény mérétke',
+];
diff --git a/common/models/Discount.php b/common/models/Discount.php
new file mode 100644
index 0000000..9e6bb4c
--- /dev/null
+++ b/common/models/Discount.php
@@ -0,0 +1,106 @@
+ TimestampBehavior::className(),
+ 'value' => function(){ return date('Y-m-d H:i:s' ); }
+ ]
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function rules()
+ {
+ return [
+ [['name','value'], 'required'],
+ [['status', 'type', 'value'], 'integer'],
+ [['name'], 'string', 'max' => 64]
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id_warehouse' => Yii::t('common/discount', 'Id Warehouse'),
+ 'name' => Yii::t('common/discount', 'Name'),
+ 'status' => Yii::t('common/discount', 'Status'),
+ 'type' => Yii::t('common/discount', 'Type'),
+ 'value' => Yii::t('common/discount', 'Value'),
+ 'created_at' => Yii::t('common/discount', 'Created At'),
+ 'updated_at' => Yii::t('common/discount', 'Updated At'),
+ ];
+ }
+
+
+ static function statuses() {
+ return [
+ self::STATUS_ACTIVE => Yii::t('common/discount', 'Active'),
+ self::STATUS_DELETED => Yii::t('common/discount', '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_DEFAULT => Yii::t('common/discount', 'Discount'),
+ ];
+ }
+
+ 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/m150921_044020_add__table__discount.php b/console/migrations/m150921_044020_add__table__discount.php
new file mode 100644
index 0000000..1de2054
--- /dev/null
+++ b/console/migrations/m150921_044020_add__table__discount.php
@@ -0,0 +1,44 @@
+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('{{%discount}}', [
+ 'id_warehouse' => $this->primaryKey(),
+ 'name' => $this->string(64)->notNull(),
+ 'status' => $this->smallInteger()->notNull()->defaultValue(10),
+ 'type' => $this->integer()->notNull()->defaultValue(10),
+ 'value' => $this->integer()->notNull()->defaultValue(10),
+ 'created_at' => $this->timestamp()->notNull(),
+ 'updated_at' => $this->timestamp()->notNull(),
+ ], $tableOptions);
+ }
+
+ public function down()
+ {
+ echo "m150921_044020_add__table__discount cannot be reverted.\n";
+
+ return false;
+ }
+
+ /*
+ // Use safeUp/safeDown to run migration code within a transaction
+ public function safeUp()
+ {
+ }
+
+ public function safeDown()
+ {
+ }
+ */
+}