Add backend ticket changes
This commit is contained in:
parent
de8991b88f
commit
a6e34bff61
@ -27,6 +27,7 @@ class TicketController extends \backend\controllers\BackendController
|
|||||||
{
|
{
|
||||||
$searchModel = new TicketSearch();
|
$searchModel = new TicketSearch();
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
$searchModel->searchTotals();
|
||||||
|
|
||||||
$searchModel->users = User::read();
|
$searchModel->users = User::read();
|
||||||
$searchModel->accounts = Account::read();
|
$searchModel->accounts = Account::read();
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use yii\data\ActiveDataProvider;
|
|||||||
use common\models\Ticket;
|
use common\models\Ticket;
|
||||||
use common\components\Helper;
|
use common\components\Helper;
|
||||||
use yii\db\ActiveRecord;
|
use yii\db\ActiveRecord;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TicketSearch represents the model behind the search form about `common\models\Ticket`.
|
* TicketSearch represents the model behind the search form about `common\models\Ticket`.
|
||||||
@ -26,6 +27,9 @@ class TicketSearch extends Ticket
|
|||||||
public $created_in_interval;
|
public $created_in_interval;
|
||||||
public $expire_in_interval;
|
public $expire_in_interval;
|
||||||
|
|
||||||
|
public $statistics;
|
||||||
|
public $statisticsTotal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
@ -49,6 +53,28 @@ class TicketSearch extends Ticket
|
|||||||
return Model::scenarios();
|
return Model::scenarios();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function attributeLabels(){
|
||||||
|
return ArrayHelper::merge(parent::attributeLabels(), [
|
||||||
|
'start' => Yii::t('backend/ticket','Start of interval'),
|
||||||
|
'end' => Yii::t('backend/ticket','End of interval'),
|
||||||
|
'valid_in_interval' => Yii::t('backend/ticket','Valid in interval'),
|
||||||
|
'created_in_interval' => Yii::t('backend/ticket','Created in interval'),
|
||||||
|
'expire_in_interval' => Yii::t('backend/ticket','Expire in interval'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterValidate(){
|
||||||
|
|
||||||
|
if ( !isset($this->timestampStart)) {
|
||||||
|
$this->timestampStart ='1900-01-01';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !isset($this->timestampEnd)) {
|
||||||
|
$this->timestampEnd ='3000-01-01';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates data provider instance with search query applied
|
* Creates data provider instance with search query applied
|
||||||
*
|
*
|
||||||
@ -64,6 +90,9 @@ class TicketSearch extends Ticket
|
|||||||
|
|
||||||
$query->with('ticketType' );
|
$query->with('ticketType' );
|
||||||
$query->with('user');
|
$query->with('user');
|
||||||
|
$query->with('customer');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$dataProvider = new ActiveDataProvider([
|
$dataProvider = new ActiveDataProvider([
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
@ -74,9 +103,10 @@ class TicketSearch extends Ticket
|
|||||||
|
|
||||||
if (!$this->validate()) {
|
if (!$this->validate()) {
|
||||||
$query->where('0=1');
|
$query->where('0=1');
|
||||||
// return $dataProvider;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$query->andFilterWhere([
|
$query->andFilterWhere([
|
||||||
'id_user' => $this->id_user,
|
'id_user' => $this->id_user,
|
||||||
'id_ticket_type' => $this->id_ticket_type,
|
'id_ticket_type' => $this->id_ticket_type,
|
||||||
@ -91,7 +121,6 @@ class TicketSearch extends Ticket
|
|||||||
$dateConditions = [];
|
$dateConditions = [];
|
||||||
$start = $this->timestampStart;
|
$start = $this->timestampStart;
|
||||||
$end = $this->timestampEnd;
|
$end = $this->timestampEnd;
|
||||||
Yii::info('valid all: ' .$all);
|
|
||||||
|
|
||||||
if( $all || $this->created_in_interval ){
|
if( $all || $this->created_in_interval ){
|
||||||
$dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end);
|
$dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end);
|
||||||
@ -117,4 +146,71 @@ class TicketSearch extends Ticket
|
|||||||
|
|
||||||
return $dataProvider;
|
return $dataProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function searchTotals(){
|
||||||
|
$query = Ticket::mkStatisticQuery($this->timestampStart, $this->timestampEnd);
|
||||||
|
$this->statistics = $query->all();
|
||||||
|
|
||||||
|
$this->statisticsTotal =[
|
||||||
|
'valid' => 0,
|
||||||
|
'created' => 0,
|
||||||
|
'created_at_money' => 0,
|
||||||
|
'expired' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->statisticsTotal['valid'] = array_sum(array_column($this->statistics, 'valid'));
|
||||||
|
$this->statisticsTotal['created'] = array_sum(array_column($this->statistics, 'created'));
|
||||||
|
$this->statisticsTotal['created_money'] = array_sum(array_column($this->statistics, 'created_money'));
|
||||||
|
$this->statisticsTotal['expired'] = array_sum(array_column($this->statistics, 'expired'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function mkSearchCondition( $timestampStart, $timestampEnd, $id_user,$id_ticket_tpye,$id_account,$valid_in_interval ,$expire_in_interval,$created_in_interval ){
|
||||||
|
$query = Ticket::find();
|
||||||
|
|
||||||
|
Helper::queryAccountConstraint($query, 'ticket.id_account');
|
||||||
|
|
||||||
|
$query->with('ticketType' );
|
||||||
|
$query->with('user');
|
||||||
|
$query->with('customer');
|
||||||
|
|
||||||
|
$query->andFilterWhere([
|
||||||
|
'id_user' => $id_user,
|
||||||
|
'id_ticket_type' => $id_ticket_type,
|
||||||
|
'id_account' => $id_account,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$all = (!($valid_in_interval) && !($expire_in_interval) && !($created_in_interval) )
|
||||||
|
||
|
||||||
|
($valid_in_interval == true && $expire_in_interval == true && $created_in_interval);
|
||||||
|
|
||||||
|
$dateConditions = [];
|
||||||
|
$start = $timestampStart;
|
||||||
|
$end = $timestampEnd;
|
||||||
|
|
||||||
|
if( $all || $created_in_interval ){
|
||||||
|
$dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $all || $valid_in_interval ){
|
||||||
|
$dateConditions[] = Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $all || $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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\grid\GridView;
|
use yii\grid\GridView;
|
||||||
use yii\helpers\ArrayHelper;
|
use yii\helpers\ArrayHelper;
|
||||||
|
use yii\data\ArrayDataProvider;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $searchModel backend\models\TicketSearch */
|
/* @var $searchModel backend\models\TicketSearch */
|
||||||
@ -21,10 +22,71 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">Bérlet statisztika</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<p>Bérlet statisztika a kiválasztott időszakra</p>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo GridView::widget([
|
||||||
|
'dataProvider' => new ArrayDataProvider([
|
||||||
|
'allModels' => $searchModel->statistics,
|
||||||
|
'sort' => false,
|
||||||
|
'pagination' => false,
|
||||||
|
]),
|
||||||
|
'showFooter'=>TRUE,
|
||||||
|
'footerRowOptions'=>['style'=>'font-weight:bold; '],
|
||||||
|
'columns' =>[
|
||||||
|
[
|
||||||
|
'attribute' => 'name',
|
||||||
|
'label' => 'Bérlet',
|
||||||
|
'footer' => 'Összesen'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'created',
|
||||||
|
'label' => 'Kiadva (Db)',
|
||||||
|
'footer' => $searchModel->statisticsTotal['created']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'created_money',
|
||||||
|
'label' => 'Kiadott érték (Ft)',
|
||||||
|
'footer' => $searchModel->statisticsTotal['created_money']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'valid',
|
||||||
|
'label' => 'Érvényes (Db)',
|
||||||
|
'footer' => $searchModel->statisticsTotal['valid']
|
||||||
|
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'expired',
|
||||||
|
'label' => 'Lejár az adott időszakban (Db)',
|
||||||
|
'footer' => $searchModel->statisticsTotal['expired']
|
||||||
|
]
|
||||||
|
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?= GridView::widget([
|
<?= GridView::widget([
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'columns' => [
|
'columns' => [
|
||||||
|
[
|
||||||
|
'attribute' => 'id_customer',
|
||||||
|
'value' => 'customerName'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'id_card',
|
||||||
|
'value' => 'cardNumber'
|
||||||
|
],
|
||||||
|
'start:date',
|
||||||
|
'end:date',
|
||||||
[
|
[
|
||||||
'attribute' => 'id_user',
|
'attribute' => 'id_user',
|
||||||
'value' => 'userName'
|
'value' => 'userName'
|
||||||
@ -37,10 +99,8 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'attribute' => 'id_account',
|
'attribute' => 'id_account',
|
||||||
'value' => 'accountName'
|
'value' => 'accountName'
|
||||||
],
|
],
|
||||||
'start:date',
|
// 'max_usage_count',
|
||||||
'end:date',
|
// 'usage_count',
|
||||||
'max_usage_count',
|
|
||||||
'usage_count',
|
|
||||||
|
|
||||||
['class' => 'yii\grid\ActionColumn',
|
['class' => 'yii\grid\ActionColumn',
|
||||||
'template' => '{view}'
|
'template' => '{view}'
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace common\components;
|
namespace common\components;
|
||||||
|
|
||||||
|
use \Yii;
|
||||||
|
|
||||||
class Helper
|
class Helper
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -29,13 +31,25 @@ class Helper
|
|||||||
|
|
||||||
public static function queryExpireRule( $field_start,$field_end , $start,$end ){
|
public static function queryExpireRule( $field_start,$field_end , $start,$end ){
|
||||||
|
|
||||||
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ], ['<' , $field_end , $end ] ];
|
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ], ['<=' , $field_end , $end ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function queryValidRule( $field_start ,$field_end , $start,$end ){
|
public static function queryValidRule( $field_start ,$field_end , $start,$end ){
|
||||||
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ] ];
|
return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function sqlInIntervalRule( $field , $paramStart,$paramEnd ){
|
||||||
|
return ' ' .$field . ' >= ' . $paramStart . ' and ' . $field . ' < ' . $paramEnd ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function sqlExpireRule( $field_start,$field_end , $paramStart,$paramEnd ){
|
||||||
|
return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' < ' . $paramEnd ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function sqlValidRule( $field_start ,$field_end , $paramStart,$paramEnd ){
|
||||||
|
return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' >=' . $paramStart ;
|
||||||
|
}
|
||||||
|
|
||||||
public static function queryAccountConstraint($query,$field){
|
public static function queryAccountConstraint($query,$field){
|
||||||
if ( !RoleDefinition::isAdmin() ){
|
if ( !RoleDefinition::isAdmin() ){
|
||||||
$query->innerJoin("user_account_assignment", $field . ' = user_account_assignment.id_account' );
|
$query->innerJoin("user_account_assignment", $field . ' = user_account_assignment.id_account' );
|
||||||
|
|||||||
27
common/messages/hu/backend/ticket.php
Normal file
27
common/messages/hu/backend/ticket.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?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 [
|
||||||
|
'Card' => 'Bérlet kártya',
|
||||||
|
'Customer' => 'Vendég',
|
||||||
|
'Created in interval' => 'Létrehozva az időszakban',
|
||||||
|
'End of interval' => 'Időszak vége',
|
||||||
|
'Expire in interval' => 'Lejár az időszakban',
|
||||||
|
'Start of interval' => 'Idászak kezdete',
|
||||||
|
'Valid in interval' => 'Érvényes az időszakban',
|
||||||
|
];
|
||||||
@ -17,13 +17,10 @@
|
|||||||
* NOTE: this file must be saved in UTF-8 encoding.
|
* NOTE: this file must be saved in UTF-8 encoding.
|
||||||
*/
|
*/
|
||||||
return [
|
return [
|
||||||
'Reset' => 'Reset',
|
|
||||||
'Are you sure you want to delete this item?' => 'Biztosan törölni szeretné a bérletet?',
|
|
||||||
'Comment' => 'Megjegyzés',
|
'Comment' => 'Megjegyzés',
|
||||||
'Create' => 'Mentés',
|
'Create' => 'Mentés',
|
||||||
'Create Ticket' => 'Új bérlet',
|
'Create Ticket' => 'Új bérlet',
|
||||||
'Created At' => 'Hozzáadva',
|
'Created At' => 'Hozzáadva',
|
||||||
'Delete' => 'Törlés',
|
|
||||||
'End' => 'Érvényesség vége',
|
'End' => 'Érvényesség vége',
|
||||||
'Id Account' => 'Kassza',
|
'Id Account' => 'Kassza',
|
||||||
'Id Discount' => 'Kedvezmény',
|
'Id Discount' => 'Kedvezmény',
|
||||||
@ -32,6 +29,7 @@ return [
|
|||||||
'Id User' => 'Felhasználó',
|
'Id User' => 'Felhasználó',
|
||||||
'Max Usage Count' => 'Max alkalmak',
|
'Max Usage Count' => 'Max alkalmak',
|
||||||
'Price Brutto' => 'Bruttó ár',
|
'Price Brutto' => 'Bruttó ár',
|
||||||
|
'Reset' => 'Reset',
|
||||||
'Search' => 'Keresés',
|
'Search' => 'Keresés',
|
||||||
'Start' => 'Érvényesség kezdete',
|
'Start' => 'Érvényesség kezdete',
|
||||||
'Status' => 'Státusz',
|
'Status' => 'Státusz',
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use Yii;
|
|||||||
use yii\db\ActiveRecord;
|
use yii\db\ActiveRecord;
|
||||||
use yii\db\Query;
|
use yii\db\Query;
|
||||||
use yii\db\Expression;
|
use yii\db\Expression;
|
||||||
|
use common\components\Helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the model class for table "ticket".
|
* This is the model class for table "ticket".
|
||||||
@ -71,6 +72,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
|||||||
'comment' => Yii::t('common/ticket', 'Comment'),
|
'comment' => Yii::t('common/ticket', 'Comment'),
|
||||||
'created_at' => Yii::t('common/ticket', 'Created At'),
|
'created_at' => Yii::t('common/ticket', 'Created At'),
|
||||||
'updated_at' => Yii::t('common/ticket', 'Updated At'),
|
'updated_at' => Yii::t('common/ticket', 'Updated At'),
|
||||||
|
'id_card' => Yii::t('backend/ticket','Card'),
|
||||||
|
'id_customer' => Yii::t('backend/ticket','Customer'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +81,27 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
|||||||
public function getCard(){
|
public function getCard(){
|
||||||
return $this->hasOne( Card::className(), ["id_card" =>"id_card" ] );
|
return $this->hasOne( Card::className(), ["id_card" =>"id_card" ] );
|
||||||
}
|
}
|
||||||
|
public function getCardNumber(){
|
||||||
|
$result = "";
|
||||||
|
$card = $this->card;
|
||||||
|
if ( isset($card)){
|
||||||
|
$result = $card->number;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomer(){
|
||||||
|
return $this->hasOne( Customer::className(), ["id_customer_card" =>"id_card" ] )->via('card');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomerName(){
|
||||||
|
$result = "";
|
||||||
|
$customer = $this->customer;
|
||||||
|
if ( isset($customer)){
|
||||||
|
$result = $customer->name;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUser(){
|
public function getUser(){
|
||||||
return $this->hasOne( User::className(), ["id" =>"id_user" ] );
|
return $this->hasOne( User::className(), ["id" =>"id_user" ] );
|
||||||
@ -151,7 +175,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function statistic($start,$end){
|
public static function mkStatisticQuery($start,$end){
|
||||||
// $sql = "select
|
// $sql = "select
|
||||||
// ticket_type.name,
|
// ticket_type.name,
|
||||||
// count(ticket.id_ticket) as total ,
|
// count(ticket.id_ticket) as total ,
|
||||||
@ -169,28 +193,39 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
|||||||
|
|
||||||
$query = new Query();
|
$query = new Query();
|
||||||
$query->addSelect( [
|
$query->addSelect( [
|
||||||
new Expression( 'ticket_type.id as id'),
|
new Expression( 'ticket_type.id_ticket_type as id'),
|
||||||
new Expression( 'ticket_type.name as name'),
|
new Expression( 'ticket_type.name as name'),
|
||||||
new Expression( 'count(ticket.id_ticket) as total'),
|
new Expression( 'coalesce( count(ticket.id_ticket),0) 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( "coalesce( sum( case when ". Helper::sqlValidRule('ticket.start', 'ticket.end', ':start', ':end') . " then 1 else 0 end) , 0) as valid" ), //valid
|
||||||
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( "coalesce( sum( case when ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then 1 else 0 end) , 0) as created" ),//created
|
||||||
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( "coalesce( sum( case when ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then transfer.money else 0 end) , 0) as created_money" ),//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 null then transfer.money else 0 end) as created_money_not_paid" ),
|
new Expression( "coalesce( sum( case when " . Helper::sqlExpireRule('ticket.start', 'ticket.end', ':start', ":end") . " then 1 else 0 end) , 0) as expired" ),
|
||||||
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->from('ticket_type');
|
||||||
$query->innerJoin('ticket', 'ticket.id_ticket_type = ticket_type.id_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->innerJoin('transfer', 'ticket.id_ticket = transfer.id_object and transfer.type = '. Transfer::TYPE_TICKET );
|
||||||
|
|
||||||
$query->groupBy("ticket_type.id_ticket, ticket_type.name");
|
Helper::queryAccountConstraint($query, 'ticket.id_account');
|
||||||
|
|
||||||
|
$query->andWhere(
|
||||||
|
[
|
||||||
|
'or',
|
||||||
|
Helper::queryInIntervalRule('ticket.created_at', $start, $end),
|
||||||
|
Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end),
|
||||||
|
Helper::queryExpireRule('ticket.start', 'ticket.end', $start, $end),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$query->groupBy("ticket_type.id_ticket_type, ticket_type.name");
|
||||||
|
|
||||||
$query->params([':start' => $start, ':end' => $end]);
|
$query->params([':start' => $start, ':end' => $end]);
|
||||||
|
|
||||||
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user