add changes to ticket_type
This commit is contained in:
parent
44c3cc18a7
commit
ab885b13e9
@ -39,6 +39,7 @@ class AdminMenuStructure{
|
|||||||
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
|
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
|
||||||
$items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
|
$items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
|
||||||
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
|
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
|
||||||
|
$items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/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,
|
||||||
|
|||||||
119
backend/controllers/TicketTypeController.php
Normal file
119
backend/controllers/TicketTypeController.php
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace backend\controllers;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use common\models\TicketType;
|
||||||
|
use backend\models\TicketTypeSearch;
|
||||||
|
use yii\web\Controller;
|
||||||
|
use yii\web\NotFoundHttpException;
|
||||||
|
use yii\filters\VerbFilter;
|
||||||
|
use common\models\Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TicketTypeController implements the CRUD actions for TicketType model.
|
||||||
|
*/
|
||||||
|
class TicketTypeController extends Controller
|
||||||
|
{
|
||||||
|
public function behaviors()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'verbs' => [
|
||||||
|
'class' => VerbFilter::className(),
|
||||||
|
'actions' => [
|
||||||
|
'delete' => ['post'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all TicketType models.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionIndex()
|
||||||
|
{
|
||||||
|
$searchModel = new TicketTypeSearch();
|
||||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
|
return $this->render('index', [
|
||||||
|
'searchModel' => $searchModel,
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a single TicketType model.
|
||||||
|
* @param integer $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionView($id)
|
||||||
|
{
|
||||||
|
return $this->render('view', [
|
||||||
|
'model' => $this->findModel($id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new TicketType model.
|
||||||
|
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionCreate()
|
||||||
|
{
|
||||||
|
$model = new TicketType();
|
||||||
|
|
||||||
|
$model->type = TicketType::TYPE_DEFAULT;
|
||||||
|
$model->status = TicketType::STATUS_ACTIVE;
|
||||||
|
$model->time_unit_type = TicketType::TIME_UNIT_MONTH;
|
||||||
|
$model->time_unit_count = 1;
|
||||||
|
$model->max_usage_count = 0;
|
||||||
|
$accounts = Account::find()->andWhere(['status' => Account::STATUS_ACTIVE])->all();
|
||||||
|
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
|
return $this->redirect(['view', 'id' => $model->id_ticket_type]);
|
||||||
|
} else {
|
||||||
|
return $this->render('create', [
|
||||||
|
'model' => $model,
|
||||||
|
'accounts' => $accounts
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing TicketType 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);
|
||||||
|
$accounts = Account::find()->andWhere( ['or', ['status' => Account::STATUS_ACTIVE], ['id_account' => $model->id_account] ])->all();
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
|
return $this->redirect(['view', 'id' => $model->id_ticket_type]);
|
||||||
|
} else {
|
||||||
|
return $this->render('update', [
|
||||||
|
'model' => $model,
|
||||||
|
'accounts' => $accounts
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the TicketType model based on its primary key value.
|
||||||
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||||
|
* @param integer $id
|
||||||
|
* @return TicketType the loaded model
|
||||||
|
* @throws NotFoundHttpException if the model cannot be found
|
||||||
|
*/
|
||||||
|
protected function findModel($id)
|
||||||
|
{
|
||||||
|
if (($model = TicketType::findOne($id)) !== null) {
|
||||||
|
return $model;
|
||||||
|
} else {
|
||||||
|
throw new NotFoundHttpException('The requested page does not exist.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
backend/models/TicketTypeSearch.php
Normal file
76
backend/models/TicketTypeSearch.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace backend\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use yii\data\ActiveDataProvider;
|
||||||
|
use common\models\TicketType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TicketTypeSearch represents the model behind the search form about `common\models\TicketType`.
|
||||||
|
*/
|
||||||
|
class TicketTypeSearch extends TicketType
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['id_ticket_type', 'type', 'max_usage_count', 'time_unit_type', 'time_unit_count', 'price_brutto', 'id_account', 'flag_student', 'status'], '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 = TicketType::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_ticket_type' => $this->id_ticket_type,
|
||||||
|
'type' => $this->type,
|
||||||
|
'max_usage_count' => $this->max_usage_count,
|
||||||
|
'time_unit_type' => $this->time_unit_type,
|
||||||
|
'time_unit_count' => $this->time_unit_count,
|
||||||
|
'price_brutto' => $this->price_brutto,
|
||||||
|
'id_account' => $this->id_account,
|
||||||
|
'flag_student' => $this->flag_student,
|
||||||
|
'status' => $this->status,
|
||||||
|
'created_at' => $this->created_at,
|
||||||
|
'updated_at' => $this->updated_at,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$query->andFilterWhere(['like', 'name', $this->name]);
|
||||||
|
|
||||||
|
return $dataProvider;
|
||||||
|
}
|
||||||
|
}
|
||||||
68
backend/views/ticket-type/_form.php
Normal file
68
backend/views/ticket-type/_form.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
use common\models\TicketType;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\TicketType */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
<?php
|
||||||
|
function mkTitle($name){
|
||||||
|
$s = "";
|
||||||
|
$tag = "h4";
|
||||||
|
$s .= "<hr>";
|
||||||
|
$s .= Html::beginTag($tag);
|
||||||
|
$s .= $name;
|
||||||
|
$s .= Html::endTag($tag);
|
||||||
|
$s .= "<hr>";
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
$account_options = ArrayHelper::map($accounts, 'id_account', 'name');
|
||||||
|
?>
|
||||||
|
<div class="ticket-type-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
<?= mkTitle("Általános")?>
|
||||||
|
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'type')->dropDownList(TicketType::ticketTypes() ) ?>
|
||||||
|
|
||||||
|
<?= mkTitle("Alkalmak")?>
|
||||||
|
<?= $form->field($model, 'max_usage_count')->textInput() ?>
|
||||||
|
|
||||||
|
<?= mkTitle("Érvényességi idő belállítások")?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'time_unit_count')->textInput() ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'time_unit_type')->dropDownList(TicketType::timeUnitTypes()) ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<?= mkTitle("Ár és kassza")?>
|
||||||
|
<?= $form->field($model, 'price_brutto')->textInput() ?>
|
||||||
|
|
||||||
|
|
||||||
|
<?= $form->field($model, 'id_account')->dropDownList($account_options) ?>
|
||||||
|
|
||||||
|
<?= mkTitle("További beállítások")?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/ticket_type', "Active") ]) ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'flag_student')->checkbox( ['value' => 1, 'label' => Yii::t('common/ticket_type', "Student") ]) ?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/ticket_type', 'Create') : Yii::t('common/ticket_type', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
49
backend/views/ticket-type/_search.php
Normal file
49
backend/views/ticket-type/_search.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model backend\models\TicketTypeSearch */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="ticket-type-search">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin([
|
||||||
|
'action' => ['index'],
|
||||||
|
'method' => 'get',
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'id_ticket_type') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'name') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'type') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'max_usage_count') ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'time_unit_type') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'time_unit_count') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'price_brutto') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'id_account') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'flag_student') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'status') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'created_at') ?>
|
||||||
|
|
||||||
|
<?php // echo $form->field($model, 'updated_at') ?>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton(Yii::t('common/ticket_type', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||||
|
<?= Html::resetButton(Yii::t('common/ticket_type', 'Reset'), ['class' => 'btn btn-default']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
22
backend/views/ticket-type/create.php
Normal file
22
backend/views/ticket-type/create.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\TicketType */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/ticket_type', 'Create Ticket Type');
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket_type', 'Ticket Types'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="ticket-type-create">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form', [
|
||||||
|
'model' => $model,
|
||||||
|
'accounts' => $accounts,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
44
backend/views/ticket-type/index.php
Normal file
44
backend/views/ticket-type/index.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\grid\GridView;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $searchModel backend\models\TicketTypeSearch */
|
||||||
|
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/ticket_type', 'Ticket Types');
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="ticket-type-index">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?= Html::a(Yii::t('common/ticket_type', 'Create Ticket Type'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?= GridView::widget([
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
'columns' => [
|
||||||
|
'name',
|
||||||
|
'max_usage_count',
|
||||||
|
'price_brutto',
|
||||||
|
'time_unit_type',
|
||||||
|
'time_unit_count',
|
||||||
|
'id_account',
|
||||||
|
'flag_student',
|
||||||
|
'status',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
|
||||||
|
[
|
||||||
|
'class' => 'yii\grid\ActionColumn',
|
||||||
|
'template' =>'{view} {edit}'
|
||||||
|
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
23
backend/views/ticket-type/update.php
Normal file
23
backend/views/ticket-type/update.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\TicketType */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/ticket_type', 'Update {modelClass}: ', [
|
||||||
|
'modelClass' => 'Ticket Type',
|
||||||
|
]) . ' ' . $model->name;
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket_type', 'Ticket Types'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_ticket_type]];
|
||||||
|
$this->params['breadcrumbs'][] = Yii::t('common/ticket_type', 'Update');
|
||||||
|
?>
|
||||||
|
<div class="ticket-type-update">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form', [
|
||||||
|
'model' => $model,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
64
backend/views/ticket-type/view.php
Normal file
64
backend/views/ticket-type/view.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\DetailView;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\TicketType */
|
||||||
|
|
||||||
|
$this->title = $model->name;
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket_type', 'Ticket Types'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="ticket-type-view">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?= Html::a(Yii::t('common/ticket_type', 'Update'), ['update', 'id' => $model->id_ticket_type], ['class' => 'btn btn-primary']) ?>
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
echo Html::a(Yii::t('common/ticket_type', 'Delete'), ['delete', 'id' => $model->id_ticket_type], [
|
||||||
|
'class' => 'btn btn-danger',
|
||||||
|
'data' => [
|
||||||
|
'confirm' => Yii::t('common/ticket_type', 'Are you sure you want to delete this item?'),
|
||||||
|
'method' => 'post',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?= DetailView::widget([
|
||||||
|
'model' => $model,
|
||||||
|
'attributes' => [
|
||||||
|
'name',
|
||||||
|
[
|
||||||
|
'attribute' => 'type',
|
||||||
|
'value' => $model->typeHuman
|
||||||
|
],
|
||||||
|
'max_usage_count',
|
||||||
|
[
|
||||||
|
'attribute' => 'time_unit_count',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'time_unit_type',
|
||||||
|
'value' => $model->timeUnitHuman
|
||||||
|
],
|
||||||
|
'price_brutto',
|
||||||
|
[
|
||||||
|
'attribute' => 'id_account',
|
||||||
|
'value' => $model->account->name,
|
||||||
|
'label' => Yii::t('common/ticket_type','Account')
|
||||||
|
],
|
||||||
|
'flag_student',
|
||||||
|
[
|
||||||
|
'attribute' => 'status',
|
||||||
|
'value' => $model->statusHuman
|
||||||
|
],
|
||||||
|
'created_at:datetime',
|
||||||
|
'updated_at:datetime',
|
||||||
|
],
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
132
common/models/TicketType.php
Normal file
132
common/models/TicketType.php
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace common\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the model class for table "ticket_type".
|
||||||
|
*
|
||||||
|
* @property integer $id_ticket_type
|
||||||
|
* @property string $name
|
||||||
|
* @property integer $type
|
||||||
|
* @property integer $max_usage_count
|
||||||
|
* @property integer $time_unit_type
|
||||||
|
* @property integer $time_unit_count
|
||||||
|
* @property integer $price_brutto
|
||||||
|
* @property integer $id_account
|
||||||
|
* @property integer $flag_student
|
||||||
|
* @property integer $status
|
||||||
|
* @property string $created_at
|
||||||
|
* @property string $updated_at
|
||||||
|
*/
|
||||||
|
class TicketType extends \common\models\BaseFitnessActiveRecord
|
||||||
|
{
|
||||||
|
|
||||||
|
const STATUS_DELETED = 0;
|
||||||
|
const STATUS_ACTIVE = 10;
|
||||||
|
|
||||||
|
CONST TIME_UNIT_DAY = 10;
|
||||||
|
CONST TIME_UNIT_MONTH = 20;
|
||||||
|
CONST TIME_UNIT_MONTH_REFERENCE = 30;
|
||||||
|
|
||||||
|
const TYPE_NORMAL = 10;
|
||||||
|
const TYPE_DEFAULT = self::TYPE_NORMAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public static function tableName()
|
||||||
|
{
|
||||||
|
return 'ticket_type';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['name', 'id_account'], 'required'],
|
||||||
|
[['type', 'max_usage_count', 'time_unit_type', 'time_unit_count', 'price_brutto', 'id_account', 'flag_student', 'status'], 'integer'],
|
||||||
|
[['created_at', 'updated_at'], 'safe'],
|
||||||
|
[['name'], 'string', 'max' => 64]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function attributeLabels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id_ticket_type' => Yii::t('common/ticket_type', 'Id Ticket Type'),
|
||||||
|
'name' => Yii::t('common/ticket_type', 'Name'),
|
||||||
|
'type' => Yii::t('common/ticket_type', 'Type'),
|
||||||
|
'max_usage_count' => Yii::t('common/ticket_type', 'Max Usage Count'),
|
||||||
|
'time_unit_type' => Yii::t('common/ticket_type', 'Time Unit Type'),
|
||||||
|
'time_unit_count' => Yii::t('common/ticket_type', 'Time Unit Count'),
|
||||||
|
'price_brutto' => Yii::t('common/ticket_type', 'Price Brutto'),
|
||||||
|
'id_account' => Yii::t('common/ticket_type', 'Id Account'),
|
||||||
|
'flag_student' => Yii::t('common/ticket_type', 'Flag Student'),
|
||||||
|
'status' => Yii::t('common/ticket_type', 'Status'),
|
||||||
|
'created_at' => Yii::t('common/ticket_type', 'Created At'),
|
||||||
|
'updated_at' => Yii::t('common/ticket_type', 'Updated At'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static function statuses() {
|
||||||
|
return [
|
||||||
|
self::STATUS_ACTIVE => Yii::t('common/ticket_type', 'Active'),
|
||||||
|
self::STATUS_DELETED => Yii::t('common/ticket_type', '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 timeUnitTypes() {
|
||||||
|
return [
|
||||||
|
self::TIME_UNIT_DAY => Yii::t('common/ticket_type', 'Nap'),
|
||||||
|
self::TIME_UNIT_MONTH => Yii::t('common/ticket_type', 'Hónap'),
|
||||||
|
self::TIME_UNIT_MONTH_REFERENCE => Yii::t('common/ticket_type', 'Tárgyhónap'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTimeUnitHuman(){
|
||||||
|
$result = null;
|
||||||
|
$s = self::timeUnitTypes($this->time_unit_type);
|
||||||
|
if ( array_key_exists($this->time_unit_type, $s)){
|
||||||
|
$result = $s[$this->time_unit_type];
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
static function ticketTypes() {
|
||||||
|
return [
|
||||||
|
self::TYPE_NORMAL => Yii::t('common/ticket_type', 'Normal'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTypeHuman(){
|
||||||
|
$result = null;
|
||||||
|
$s = self::ticketTypes( );
|
||||||
|
if ( array_key_exists($this->type, $s)){
|
||||||
|
$result = $s[$this->type];
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getAccount(){
|
||||||
|
return $this->hasOne(Account::className(), [ 'id_account' => 'id_account' ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Schema;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m150921_162327_add__table__ticket_type 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('{{%ticket_type}}', [
|
||||||
|
'id_ticket_type' => $this->primaryKey(),
|
||||||
|
'name' => $this->string(64)->notNull(),
|
||||||
|
'type' => $this->integer(),
|
||||||
|
'max_usage_count' => $this->integer(),
|
||||||
|
'time_unit_type' => $this->integer(),
|
||||||
|
'time_unit_count' => $this->integer(),
|
||||||
|
'price_brutto' => $this->integer(),
|
||||||
|
'id_account' => $this->integer()->notNull(),
|
||||||
|
'flag_student' => $this->smallInteger()->notNull()->defaultValue(0),
|
||||||
|
'status' => $this->smallInteger()->notNull()->defaultValue(10),
|
||||||
|
'created_at' => $this->timestamp()->notNull(),
|
||||||
|
'updated_at' => $this->timestamp()->notNull(),
|
||||||
|
], $tableOptions );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
echo "m150921_162327_add__table__ticket_type 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