add backend ticket stat basics
This commit is contained in:
parent
e752352e8a
commit
de8991b88f
@ -58,6 +58,7 @@ class AdminMenuStructure{
|
||||
$items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ];
|
||||
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
|
||||
$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
|
||||
$items[] = ['label' => 'Bérletek', 'url' => ['/ticket/index' , 'TicketSearch[start]' =>$today,'TicketSearch[end]' => $tomorrow ] ];
|
||||
|
||||
if ( count($items) > 0 ){
|
||||
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
|
||||
|
||||
@ -11,6 +11,7 @@ use yii\filters\VerbFilter;
|
||||
use common\models\Discount;
|
||||
use common\models\TicketType;
|
||||
use common\models\Account;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* TicketController implements the CRUD actions for Ticket model.
|
||||
@ -27,6 +28,12 @@ class TicketController extends \backend\controllers\BackendController
|
||||
$searchModel = new TicketSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
$searchModel->users = User::read();
|
||||
$searchModel->accounts = Account::read();
|
||||
$searchModel->ticketTypes = TicketType::read();
|
||||
|
||||
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
|
||||
@ -6,12 +6,26 @@ use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Ticket;
|
||||
use common\components\Helper;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* TicketSearch represents the model behind the search form about `common\models\Ticket`.
|
||||
*/
|
||||
class TicketSearch extends Ticket
|
||||
{
|
||||
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
public $users;
|
||||
public $accounts;
|
||||
public $ticketTypes;
|
||||
|
||||
public $valid_in_interval;
|
||||
public $created_in_interval;
|
||||
public $expire_in_interval;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -19,7 +33,10 @@ class TicketSearch extends Ticket
|
||||
{
|
||||
return [
|
||||
[['id_ticket', 'id_user', 'id_ticket_type', 'id_account', 'id_discount', 'max_usage_count', 'usage_count', 'status', 'price_brutto'], 'integer'],
|
||||
[['start', 'end', 'comment', 'created_at', 'updated_at'], 'safe'],
|
||||
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[['valid_in_interval','created_in_interval','expire_in_interval'],'boolean']
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@ -43,35 +60,60 @@ class TicketSearch extends Ticket
|
||||
{
|
||||
$query = Ticket::find();
|
||||
|
||||
Helper::queryAccountConstraint($query, 'ticket.id_account');
|
||||
|
||||
$query->with('ticketType' );
|
||||
$query->with('user');
|
||||
|
||||
$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->where('0=1');
|
||||
// return $dataProvider;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_ticket' => $this->id_ticket,
|
||||
'id_user' => $this->id_user,
|
||||
'id_ticket_type' => $this->id_ticket_type,
|
||||
'id_account' => $this->id_account,
|
||||
'id_discount' => $this->id_discount,
|
||||
'start' => $this->start,
|
||||
'end' => $this->end,
|
||||
'max_usage_count' => $this->max_usage_count,
|
||||
'usage_count' => $this->usage_count,
|
||||
'status' => $this->status,
|
||||
'price_brutto' => $this->price_brutto,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'comment', $this->comment]);
|
||||
|
||||
$all = (!($this->valid_in_interval) && !($this->expire_in_interval) && !($this->created_in_interval) )
|
||||
||
|
||||
($this->valid_in_interval == true && $this->expire_in_interval == true && $this->created_in_interval);
|
||||
|
||||
$dateConditions = [];
|
||||
$start = $this->timestampStart;
|
||||
$end = $this->timestampEnd;
|
||||
Yii::info('valid all: ' .$all);
|
||||
|
||||
if( $all || $this->created_in_interval ){
|
||||
$dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end);
|
||||
}
|
||||
|
||||
if ( $all || $this->valid_in_interval ){
|
||||
$dateConditions[] = Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end);
|
||||
}
|
||||
|
||||
if ( $all || $this->expire_in_interval ){
|
||||
$dateConditions[] = Helper::queryExpireRule('ticket.start', 'ticket.end', $start, $end);
|
||||
}
|
||||
|
||||
if ( count($dateConditions) == 1 ){
|
||||
$query->andWhere($dateConditions[0]);
|
||||
}else if ( count($dateConditions) > 1 ){
|
||||
$cond = ['or'];
|
||||
foreach ($dateConditions as $c){
|
||||
$cond[] = $c;
|
||||
}
|
||||
$query->andWhere($cond);
|
||||
}
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
@ -2,12 +2,21 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use kartik\widgets\DatePicker;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\models\TicketSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<?php
|
||||
$ticketTypeOptions = ['' => 'Mind'] + ArrayHelper::map($model->ticketTypes, 'id_ticket_type', 'name');
|
||||
$accountOptions = ['' => 'Mind'] + ArrayHelper::map($model->accounts, 'id_account', 'name');
|
||||
$userOptions = ['' => 'Mind'] + ArrayHelper::map($model->users, 'id', 'username');
|
||||
|
||||
?>
|
||||
|
||||
<div class="ticket-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
@ -15,37 +24,51 @@ use yii\widgets\ActiveForm;
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id_ticket') ?>
|
||||
|
||||
<?= $form->field($model, 'id_user') ?>
|
||||
<div class='row'>
|
||||
<div class='col-md-4'>
|
||||
<?= $form->field($model, 'id_user')->dropDownList($userOptions) ?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<?= $form->field($model, 'id_ticket_type')->dropDownList($ticketTypeOptions) ?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $form->field($model, 'id_ticket_type') ?>
|
||||
|
||||
<?= $form->field($model, 'id_account') ?>
|
||||
|
||||
<?= $form->field($model, 'id_discount') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'start') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'end') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'max_usage_count') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'usage_count') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'status') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'price_brutto') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'comment') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'created_at') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'updated_at') ?>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
|
||||
'pluginOptions' => [
|
||||
'autoclose'=>true,
|
||||
'format' => 'yyyy.mm.dd'
|
||||
]
|
||||
]) ?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'end') ->widget(DatePicker::classname(), [
|
||||
'pluginOptions' => [
|
||||
'autoclose'=>true,
|
||||
'format' => 'yyyy.mm.dd'
|
||||
]
|
||||
]) ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class='row'>
|
||||
<div class='col-md-4'>
|
||||
<?php echo $form->field($model, 'valid_in_interval')->checkbox( ) ?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<?php echo $form->field($model, 'created_in_interval')->checkbox( ) ?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<?php echo $form->field($model, 'expire_in_interval')->checkbox( ) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/ticket', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton(Yii::t('common/ticket', 'Reset'), ['class' => 'btn btn-default']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\models\TicketSearch */
|
||||
@ -9,38 +10,41 @@ use yii\grid\GridView;
|
||||
|
||||
$this->title = Yii::t('common/ticket', 'Tickets');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<div class="ticket-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/ticket', 'Create Ticket'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id_ticket',
|
||||
'id_user',
|
||||
'id_ticket_type',
|
||||
'id_account',
|
||||
'id_discount',
|
||||
// 'start',
|
||||
// 'end',
|
||||
// 'max_usage_count',
|
||||
// 'usage_count',
|
||||
// 'status',
|
||||
// 'price_brutto',
|
||||
// 'comment',
|
||||
// 'created_at',
|
||||
// 'updated_at',
|
||||
[
|
||||
'attribute' => 'id_user',
|
||||
'value' => 'userName'
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_ticket_type',
|
||||
'value' => 'ticketTypeName'
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_account',
|
||||
'value' => 'accountName'
|
||||
],
|
||||
'start:date',
|
||||
'end:date',
|
||||
'max_usage_count',
|
||||
'usage_count',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view}'
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
@ -14,16 +14,6 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/ticket', 'Update'), ['update', 'id' => $model->id_ticket], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a(Yii::t('common/ticket', 'Delete'), ['delete', 'id' => $model->id_ticket], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('common/ticket', 'Are you sure you want to delete this item?'),
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
|
||||
@ -23,6 +23,27 @@ class Helper
|
||||
$query->andFilterWhere([ '<' , $field , $end ] );
|
||||
}
|
||||
|
||||
public static function queryInIntervalRule( $field , $start,$end ){
|
||||
return ['and',[ '>=', $field , $start ] , [ '<' , $field , $end ] ];
|
||||
}
|
||||
|
||||
public static function queryExpireRule( $field_start,$field_end , $start,$end ){
|
||||
|
||||
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ], ['<' , $field_end , $end ] ];
|
||||
}
|
||||
|
||||
public static function queryValidRule( $field_start ,$field_end , $start,$end ){
|
||||
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ] ];
|
||||
}
|
||||
|
||||
public static function queryAccountConstraint($query,$field){
|
||||
if ( !RoleDefinition::isAdmin() ){
|
||||
$query->innerJoin("user_account_assignment", $field . ' = user_account_assignment.id_account' );
|
||||
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function roleLabels(){
|
||||
return [
|
||||
'reception' => Yii::t('common/role' ,'Reception'),
|
||||
|
||||
@ -4,6 +4,8 @@ namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
* This is the model class for table "ticket".
|
||||
@ -148,4 +150,47 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function statistic($start,$end){
|
||||
// $sql = "select
|
||||
// ticket_type.name,
|
||||
// count(ticket.id_ticket) as total ,
|
||||
// sum(case when ticket.end > '2015-11-05' and ticket.start <= '2015-11-05' then 1 else 0 end) as valid,
|
||||
// sum(case when ticket.created_at < '2015-11-06' and ticket.created_at >= '2015-11-05' then 1 else 0 end) as created,
|
||||
// sum(case when ticket.created_at < '2015-11-06' and ticket.created_at >= '2015-11-05' then transfer.money else 0 end) as created_money,
|
||||
// sum(case when ticket.created_at < '2015-11-06' and ticket.created_at >= '2015-11-05' and transfer.paid_at is not null then transfer.money else 0 end) as created_money_paid,
|
||||
// sum(case when ticket.created_at < '2015-11-06' and ticket.created_at >= '2015-11-05' and transfer.paid_at is null then transfer.money else 0 end) as created_money_not_paid,
|
||||
// sum(case when ticket.created_at >= '2015-11-06' and ticket.created_at < '2015-11-05' and transfer.paid_at < '2015-11-06' and transfer.paid_at >= '2015-11-05' then transfer.money else 0 end) as dept_paid,
|
||||
// sum(case when ticket.end < '2015-11-06' and ticket.created_at >= '2015-11-05' then 1 else 0 end) as expired
|
||||
// from ticket_type
|
||||
// inner join ticket on ticket.id_ticket_type = ticket_type.id_ticket_type
|
||||
// inner join transfer on ticket.id_ticket = transfer.id_object and transfer.type = 20
|
||||
// group by ticket_type.name;";
|
||||
|
||||
$query = new Query();
|
||||
$query->addSelect( [
|
||||
new Expression( 'ticket_type.id as id'),
|
||||
new Expression( 'ticket_type.name as name'),
|
||||
new Expression( 'count(ticket.id_ticket) as total'),
|
||||
new Expression( "sum( case when ticket.end > ':start' and ticket.start <= ':end' then 1 else 0 end) as valid" ),
|
||||
new Expression( "sum(case when ticket.created_at < ':end' and ticket.created_at >= ':start' then 1 else 0 end) as created" ),
|
||||
new Expression( "sum(case when ticket.created_at < ':end' and ticket.created_at >= ':start' then transfer.money else 0 end) as created_money" ),
|
||||
new Expression( "sum(case when ticket.created_at < '2015-11-06' and ticket.created_at >= '2015-11-05' and transfer.paid_at is not null then transfer.money else 0 end) as created_money_paid" ),
|
||||
new Expression( "sum(case when ticket.created_at < '2015-11-06' and ticket.created_at >= '2015-11-05' and transfer.paid_at is null then transfer.money else 0 end) as created_money_not_paid" ),
|
||||
new Expression( "sum(case when ticket.created_at >= '2015-11-06' and ticket.created_at < '2015-11-05' and transfer.paid_at < '2015-11-06' and transfer.paid_at >= '2015-11-05' then transfer.money else 0 end) as dept_paid" ),
|
||||
new Expression( "sum(case when ticket.end < '2015-11-06' and ticket.created_at >= '2015-11-05' then 1 else 0 end) as expired" ),
|
||||
|
||||
|
||||
]);
|
||||
|
||||
$query->from('ticket_type');
|
||||
$query->innerJoin('ticket', 'ticket.id_ticket_type = ticket_type.id_ticket_type');
|
||||
$query->innerJoin('transfer', 'ticket.id_ticket = transfer.id_object and transfer.type = 20');
|
||||
|
||||
$query->groupBy("ticket_type.id_ticket, ticket_type.name");
|
||||
|
||||
$query->params([':start' => $start, ':end' => $end]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user