add discount crud + model (kedvezmény)
This commit is contained in:
parent
0fed98d239
commit
2e7b52e5a3
@ -37,6 +37,7 @@ class AdminMenuStructure{
|
|||||||
|
|
||||||
$items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']];
|
$items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']];
|
||||||
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
|
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
|
||||||
|
$items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
|
||||||
|
|
||||||
if ( count($items) > 0 ){
|
if ( count($items) > 0 ){
|
||||||
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
|
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
|
||||||
|
|||||||
123
backend/controllers/DiscountController.php
Normal file
123
backend/controllers/DiscountController.php
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace backend\controllers;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use common\models\Discount;
|
||||||
|
use backend\models\DiscountSearch;
|
||||||
|
use yii\web\Controller;
|
||||||
|
use yii\web\NotFoundHttpException;
|
||||||
|
use yii\filters\VerbFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DiscountController implements the CRUD actions for Discount model.
|
||||||
|
*/
|
||||||
|
class DiscountController extends Controller
|
||||||
|
{
|
||||||
|
public function behaviors()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'verbs' => [
|
||||||
|
'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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
71
backend/models/DiscountSearch.php
Normal file
71
backend/models/DiscountSearch.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace backend\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use yii\data\ActiveDataProvider;
|
||||||
|
use common\models\Discount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DiscountSearch represents the model behind the search form about `common\models\Discount`.
|
||||||
|
*/
|
||||||
|
class DiscountSearch extends Discount
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['id_warehouse', 'status', 'type', 'value'], 'integer'],
|
||||||
|
[['name', 'created_at', 'updated_at'], 'safe'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function scenarios()
|
||||||
|
{
|
||||||
|
// bypass scenarios() implementation in the parent class
|
||||||
|
return Model::scenarios();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates data provider instance with search query applied
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return ActiveDataProvider
|
||||||
|
*/
|
||||||
|
public function search($params)
|
||||||
|
{
|
||||||
|
$query = Discount::find();
|
||||||
|
|
||||||
|
$dataProvider = new ActiveDataProvider([
|
||||||
|
'query' => $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;
|
||||||
|
}
|
||||||
|
}
|
||||||
32
backend/views/discount/_form.php
Normal file
32
backend/views/discount/_form.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
use common\models\Discount;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Discount */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="discount-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/discount', "Active") ]) ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'type')->dropDownList(Discount::types()) ?>
|
||||||
|
|
||||||
|
|
||||||
|
<?= $form->field($model, 'value')->textInput() ?>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/discount', 'Create') : Yii::t('common/discount', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
38
backend/views/discount/_search.php
Normal file
38
backend/views/discount/_search.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model backend\models\DiscountSearch */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="discount-search">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin([
|
||||||
|
'action' => ['index'],
|
||||||
|
'method' => 'get',
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'id_warehouse') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'name') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'status') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'type') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'value') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'created_at') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'updated_at') ?>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton(Yii::t('common/discount', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
21
backend/views/discount/create.php
Normal file
21
backend/views/discount/create.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Discount */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/discount', 'Create Discount');
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/discount', 'Discounts'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="discount-create">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form', [
|
||||||
|
'model' => $model,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
43
backend/views/discount/index.php
Normal file
43
backend/views/discount/index.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\grid\GridView;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $searchModel backend\models\DiscountSearch */
|
||||||
|
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/discount', 'Discounts');
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="discount-index">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?= Html::a(Yii::t('common/discount', 'Create Discount'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?= 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'],
|
||||||
|
],
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
23
backend/views/discount/update.php
Normal file
23
backend/views/discount/update.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Discount */
|
||||||
|
|
||||||
|
$this->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');
|
||||||
|
?>
|
||||||
|
<div class="discount-update">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form', [
|
||||||
|
'model' => $model,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
43
backend/views/discount/view.php
Normal file
43
backend/views/discount/view.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\DetailView;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Discount */
|
||||||
|
|
||||||
|
$this->title = $model->name;
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/discount', 'Discounts'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="discount-view">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?= 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',
|
||||||
|
],
|
||||||
|
])*/
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?= DetailView::widget([
|
||||||
|
'model' => $model,
|
||||||
|
'attributes' => [
|
||||||
|
'id_warehouse',
|
||||||
|
'name',
|
||||||
|
'status',
|
||||||
|
'type',
|
||||||
|
'value',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
],
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
36
common/messages/hu/common/discount.php
Normal file
36
common/messages/hu/common/discount.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Message translations.
|
||||||
|
*
|
||||||
|
* This file is automatically generated by 'yii message' command.
|
||||||
|
* It contains the localizable messages extracted from source code.
|
||||||
|
* You may modify this file by translating the extracted messages.
|
||||||
|
*
|
||||||
|
* Each array element represents the translation (value) of a message (key).
|
||||||
|
* If the value is empty, the message is considered as not translated.
|
||||||
|
* Messages that no longer need translation will have their translations
|
||||||
|
* enclosed between a pair of '@@' marks.
|
||||||
|
*
|
||||||
|
* Message string can be used with plural forms format. Check i18n section
|
||||||
|
* of the guide for details.
|
||||||
|
*
|
||||||
|
* NOTE: this file must be saved in UTF-8 encoding.
|
||||||
|
*/
|
||||||
|
return [
|
||||||
|
'Active' => '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',
|
||||||
|
];
|
||||||
106
common/models/Discount.php
Normal file
106
common/models/Discount.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace common\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\behaviors\TimestampBehavior;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the model class for table "discount".
|
||||||
|
*
|
||||||
|
* @property integer $id_warehouse
|
||||||
|
* @property string $name
|
||||||
|
* @property integer $status
|
||||||
|
* @property integer $type
|
||||||
|
* @property integer $value
|
||||||
|
* @property string $created_at
|
||||||
|
* @property string $updated_at
|
||||||
|
*/
|
||||||
|
class Discount extends \yii\db\ActiveRecord
|
||||||
|
{
|
||||||
|
const STATUS_DELETED = 0;
|
||||||
|
const STATUS_ACTIVE = 10;
|
||||||
|
|
||||||
|
const TYPE_DEFAULT = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public static function tableName()
|
||||||
|
{
|
||||||
|
return 'discount';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function behaviors()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[ 'class' => 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
44
console/migrations/m150921_044020_add__table__discount.php
Normal file
44
console/migrations/m150921_044020_add__table__discount.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Schema;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m150921_044020_add__table__discount extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$tableOptions = null;
|
||||||
|
if ($this->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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user