add ticket type model + crud ( bérlet típus)

This commit is contained in:
rocho 2015-09-22 11:59:58 +02:00
parent ab885b13e9
commit db8fca5630
9 changed files with 242 additions and 106 deletions

View File

@ -23,19 +23,35 @@ $this->params['breadcrumbs'][] = $this->title;
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'columns' => [ 'columns' => [
'name', 'name',
'max_usage_count',
'price_brutto', 'price_brutto',
'time_unit_type', 'max_usage_count',
'time_unit_count', 'time_unit_count',
'id_account', [
'flag_student',
'status', 'attribute' =>'time_unit_type',
'created_at', 'value' =>'timeUnitHuman',
'updated_at', ],
[
'attribute' => 'id_account',
'value' => 'accountName',
],
[
'attribute' =>'flag_student',
'value' =>function($model, $key, $index, $column){
return $model->isStudent() ? Yii::t('common', "Yes") : Yii::t('common', "No") ;
},
],
[
'attribute' =>'status',
'value' =>'statusHuman',
],
'created_at:datetime',
'updated_at:datetime',
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' =>'{view} {edit}' 'template' =>'{view} {update}'
], ],
], ],

View File

@ -4,10 +4,9 @@ use yii\helpers\Html;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\TicketType */ /* @var $model common\models\TicketType */
/* @var $accounts common\models\Account[] */
$this->title = Yii::t('common/ticket_type', 'Update {modelClass}: ', [ $this->title = Yii::t('common/ticket_type', 'Update ticket type:' ) . ' ' . $model->name;
'modelClass' => 'Ticket Type',
]) . ' ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket_type', 'Ticket Types'), 'url' => ['index']]; $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'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_ticket_type]];
$this->params['breadcrumbs'][] = Yii::t('common/ticket_type', 'Update'); $this->params['breadcrumbs'][] = Yii::t('common/ticket_type', 'Update');
@ -18,6 +17,8 @@ $this->params['breadcrumbs'][] = Yii::t('common/ticket_type', 'Update');
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'accounts' => $accounts,
]) ?> ]) ?>
</div> </div>

View File

@ -48,10 +48,12 @@ $this->params['breadcrumbs'][] = $this->title;
'price_brutto', 'price_brutto',
[ [
'attribute' => 'id_account', 'attribute' => 'id_account',
'value' => $model->account->name, 'value' => $model->accountName,
'label' => Yii::t('common/ticket_type','Account')
], ],
'flag_student', [
'attribute' => 'flag_student',
'value' => ( $model->isStudent() ? Yii::t('common', 'Yes' ) : Yii::t('common', 'No' ) ),
],
[ [
'attribute' => 'status', 'attribute' => 'status',
'value' => $model->statusHuman 'value' => $model->statusHuman

View File

@ -17,18 +17,18 @@
* NOTE: this file must be saved in UTF-8 encoding. * NOTE: this file must be saved in UTF-8 encoding.
*/ */
return [ return [
'Aktív' => '', 'Aktív' => 'Aktív',
'Are you sure you want to delete this item?' => '', 'Are you sure you want to delete this item?' => 'Biztosan törölni szeretné ezt az element?',
'Delete' => '', 'Delete' => 'Törlés',
'Felhasználók' => '', 'Felhasználók' => 'Felhasználók',
'Inaktív' => '', 'Inaktív' => 'Inaktív',
'Jelszó' => '', 'Jelszó' => 'Jelszó',
'Jelszó és jelszó újra nem egyezik!' => '', 'Jelszó és jelszó újra nem egyezik!' => 'Jelszó és jelszó újra nem egyezik!',
'Jelszó újra' => '', 'Jelszó újra' => 'Jelszó újra',
'Keresés' => '', 'Keresés' => 'Keresés',
'Mentés' => '', 'Mentés' => 'Mentés',
'Update' => '', 'Update' => 'Update',
'Update {modelClass}: ' => '', 'Update {modelClass}: ' => '{modelClass} módosítása: ',
'Users' => '', 'Users' => 'Felhasználók',
'Új felhasználó' => '', 'Új felhasználó' => 'Új felhasználó',
]; ];

View File

@ -17,5 +17,6 @@
* NOTE: this file must be saved in UTF-8 encoding. * NOTE: this file must be saved in UTF-8 encoding.
*/ */
return [ return [
'Create' => 'Mentés', 'No' => 'Nem',
'Yes' => 'Igen',
]; ];

View File

@ -18,11 +18,9 @@
*/ */
return [ return [
'Active' => 'Aktív', 'Active' => 'Aktív',
'Are you sure you want to delete this item?' => 'Biztosan törölni szeretné a termék kategóriát?',
'Create' => 'Mentés', 'Create' => 'Mentés',
'Create Product Category' => 'Új termék kategória', 'Create Product Category' => 'Új termék kategória',
'Created At' => 'Létrehozás ideje', 'Created At' => 'Létrehozás ideje',
'Delete' => 'Törlés',
'Id Product Category' => 'Azonosító', 'Id Product Category' => 'Azonosító',
'Inactive' => 'Inaktív', 'Inactive' => 'Inaktív',
'Name' => 'Név', 'Name' => 'Név',

View File

@ -0,0 +1,48 @@
<?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 [
'Update ticket type:' => 'Bérlet módosítása: ',
'Active' => 'Aktív',
'Create' => 'Mentés',
'Create Ticket Type' => 'Új bérlet típus',
'Created At' => 'Létrehozás ideje',
'Day' => 'Nap',
'Flag Student' => 'Diák',
'Id Account' => 'Kassza',
'Id Ticket Type' => 'Bérlet típus',
'Inactive' => 'Inaktív',
'Invalid account (inactive)!' => 'Érvénytelen kassza (inaktív)!',
'Invalid account!' => 'Érvénytelen kassza!',
'Max Usage Count' => 'Akalmak',
'Month' => 'Hónap',
'Name' => 'Név',
'Normal' => 'Normál',
'Price Brutto' => 'Bruttó ár',
'Reference month' => 'Tárgyhónap',
'Reset' => 'Reset',
'Search' => 'Keresés',
'Status' => 'Státusz',
'Student' => 'Diák',
'Ticket Types' => 'Bérlet típusok',
'Time Unit Count' => 'Idő egység mennyiség',
'Time Unit Type' => 'Idő egység típus',
'Type' => 'Típus',
'Update' => 'Módosítás',
'Updated At' => 'Módosítás ideje',
];

View File

@ -103,4 +103,9 @@ class Account extends \yii\db\ActiveRecord
} }
return $result; return $result;
} }
public function isInactive(){
return $this->status == self::STATUS_DELETED;
}
} }

View File

@ -20,37 +20,74 @@ use Yii;
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
*/ */
class TicketType extends \common\models\BaseFitnessActiveRecord class TicketType extends \common\models\BaseFitnessActiveRecord {
{
const STATUS_DELETED = 0; const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10; const STATUS_ACTIVE = 10;
CONST TIME_UNIT_DAY = 10;//nap
CONST TIME_UNIT_DAY = 10; CONST TIME_UNIT_MONTH = 20;//hónap
CONST TIME_UNIT_MONTH = 20; CONST TIME_UNIT_MONTH_REFERENCE = 30; //tárgy hónap
CONST TIME_UNIT_MONTH_REFERENCE = 30;
const TYPE_NORMAL = 10; const TYPE_NORMAL = 10;
const TYPE_DEFAULT = self::TYPE_NORMAL; const TYPE_DEFAULT = self::TYPE_NORMAL;
/** const FLAG_STUDENT_OFF = 0;
* @inheritdoc const FLAG_STUDENT_ON = 1;
*/
public static function tableName() /**
{ * @inheritdoc
return 'ticket_type'; */
} public static function tableName() {
return 'ticket_type';
/** }
/**
* @formatter:off
* @inheritdoc * @inheritdoc
*/ */
public function rules() public function rules()
{ {
return [ return [
[['name', 'id_account'], 'required'], [['name', 'id_account','time_unit_count','type' ,'time_unit_type' ,'max_usage_count','price_brutto'], 'required'],
[['type', 'max_usage_count', 'time_unit_type', 'time_unit_count', 'price_brutto', 'id_account', 'flag_student', 'status'], 'integer'], ////////////////
[['created_at', 'updated_at'], 'safe'], //price brutto
[['name'], 'string', 'max' => 64] ////////////////
[[ 'price_brutto', ], 'integer'],
////////////////
//time_unit_type
////////////////
[['time_unit_type',], 'integer'],
[['time_unit_type',], 'in', 'range' => [ self::TIME_UNIT_DAY,self::TIME_UNIT_MONTH,self::TIME_UNIT_MONTH_REFERENCE] ],
////////////////
//time_unit_count
////////////////
[['time_unit_count',], 'integer','min' => 1 , 'max' => 100],
////////////////
//max_usage_count
////////////////
[['max_usage_count',], 'integer','min' => 0 , 'max' => 10000],
////////////////
//flag_student
////////////////
[['flag_student',], 'integer'],
[['flag_student',], 'in', 'range' => [ self::FLAG_STUDENT_OFF, self::FLAG_STUDENT_ON ]],
////////////////
//status
////////////////
[['status',], 'integer'],
[['status',], 'in', 'range' => [ self::STATUS_ACTIVE, self::STATUS_DELETED ]],
////////////////
//type
////////////////
[['type',], 'integer'],
[['type',], 'in', 'range' => [ self::TYPE_NORMAL ]],
////////////////
//name
////////////////
[['name'], 'string', 'max' => 64],
////////////////
//id_account
////////////////
[['id_account',], 'integer'],
[['id_account',], 'validateIdAccount'],
]; ];
} }
@ -75,58 +112,86 @@ class TicketType extends \common\models\BaseFitnessActiveRecord
]; ];
} }
/**
static function statuses() { * @formatter:on
return [ */
self::STATUS_ACTIVE => Yii::t('common/ticket_type', 'Active'), static function statuses() {
self::STATUS_DELETED => Yii::t('common/ticket_type', 'Inactive'), return [
]; self::STATUS_ACTIVE => Yii::t ( 'common/ticket_type', 'Active' ),
} self::STATUS_DELETED => Yii::t ( 'common/ticket_type', 'Inactive' )
];
public function getStatusHuman(){ }
$result = null; public function getStatusHuman() {
$s = self::statuses($this->status); $result = null;
if ( array_key_exists($this->status, $s)){ $s = self::statuses ( $this->status );
$result = $s[$this->status]; if (array_key_exists ( $this->status, $s )) {
} $result = $s [$this->status];
return $result; }
} return $result;
}
static function timeUnitTypes() {
static function timeUnitTypes() { return [
return [ self::TIME_UNIT_DAY => Yii::t ( 'common/ticket_type', 'Day' ),
self::TIME_UNIT_DAY => Yii::t('common/ticket_type', 'Nap'), self::TIME_UNIT_MONTH => Yii::t ( 'common/ticket_type', 'Month' ),
self::TIME_UNIT_MONTH => Yii::t('common/ticket_type', 'Hónap'), self::TIME_UNIT_MONTH_REFERENCE => Yii::t ( 'common/ticket_type', 'Reference month' )
self::TIME_UNIT_MONTH_REFERENCE => Yii::t('common/ticket_type', 'Tárgyhónap'), ];
]; }
} public function getTimeUnitHuman() {
$result = null;
public function getTimeUnitHuman(){ $s = self::timeUnitTypes ( $this->time_unit_type );
$result = null; if (array_key_exists ( $this->time_unit_type, $s )) {
$s = self::timeUnitTypes($this->time_unit_type); $result = $s [$this->time_unit_type];
if ( array_key_exists($this->time_unit_type, $s)){ }
$result = $s[$this->time_unit_type]; return $result;
} }
return $result; static function ticketTypes() {
} return [
static function ticketTypes() { self::TYPE_NORMAL => Yii::t ( 'common/ticket_type', 'Normal' )
return [ ];
self::TYPE_NORMAL => Yii::t('common/ticket_type', 'Normal'), }
]; public function getTypeHuman() {
} $result = null;
$s = self::ticketTypes ();
public function getTypeHuman(){ if (array_key_exists ( $this->type, $s )) {
$result = null; $result = $s [$this->type];
$s = self::ticketTypes( ); }
if ( array_key_exists($this->type, $s)){ return $result;
$result = $s[$this->type]; }
} public function getAccount() {
return $result; return $this->hasOne ( Account::className (), [
} 'id_account' => 'id_account'
] );
}
public function getAccount(){ public function getAccountName() {
return $this->hasOne(Account::className(), [ 'id_account' => 'id_account' ]); return $this->account->name;
} }
public function isStudent(){
return $this->flag_student == ( self::FLAG_STUDENT_ON);
}
public function validateIdAccount($attribute,$params){
$account = null;
if ( !$this->hasErrors("id_account")){
$account = Account::findOne($this->$attribute);
if ( !isset($account)){
$this->addError($attribute,Yii::t('common/ticket_type','Invalid account!'));
}else{
//on update
if ( !$this->isNewRecord ){
//if selected account is inactive ...
if ( $account->isInactive() ){
//... and changed
if ( $this->isAttributeChanged('id_account')){
$this->addError($attribute,Yii::t('common/ticket_type','Invalid account (inactive)!'));
}
}
}
}
}
}
} }