Add backend ticket changes

This commit is contained in:
2015-11-06 14:42:16 +01:00
parent de8991b88f
commit a6e34bff61
7 changed files with 254 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
<?php
namespace common\components;
use \Yii;
class Helper
{
@@ -29,13 +31,25 @@ class Helper
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 ){
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){
if ( !RoleDefinition::isAdmin() ){
$query->innerJoin("user_account_assignment", $field . ' = user_account_assignment.id_account' );

View 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',
];

View File

@@ -17,13 +17,10 @@
* NOTE: this file must be saved in UTF-8 encoding.
*/
return [
'Reset' => 'Reset',
'Are you sure you want to delete this item?' => 'Biztosan törölni szeretné a bérletet?',
'Comment' => 'Megjegyzés',
'Create' => 'Mentés',
'Create Ticket' => 'Új bérlet',
'Created At' => 'Hozzáadva',
'Delete' => 'Törlés',
'End' => 'Érvényesség vége',
'Id Account' => 'Kassza',
'Id Discount' => 'Kedvezmény',
@@ -32,6 +29,7 @@ return [
'Id User' => 'Felhasználó',
'Max Usage Count' => 'Max alkalmak',
'Price Brutto' => 'Bruttó ár',
'Reset' => 'Reset',
'Search' => 'Keresés',
'Start' => 'Érvényesség kezdete',
'Status' => 'Státusz',

View File

@@ -6,6 +6,7 @@ use Yii;
use yii\db\ActiveRecord;
use yii\db\Query;
use yii\db\Expression;
use common\components\Helper;
/**
* This is the model class for table "ticket".
@@ -71,6 +72,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
'comment' => Yii::t('common/ticket', 'Comment'),
'created_at' => Yii::t('common/ticket', 'Created 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(){
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(){
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
// ticket_type.name,
// count(ticket.id_ticket) as total ,
@@ -169,28 +193,39 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
$query = new Query();
$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( '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" ),
new Expression( 'coalesce( count(ticket.id_ticket),0) as total'),
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( "coalesce( sum( case when ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then 1 else 0 end) , 0) as created" ),//created
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( "coalesce( sum( case when " . Helper::sqlExpireRule('ticket.start', 'ticket.end', ':start', ":end") . " then 1 else 0 end) , 0) 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->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]);
return $query;
}
}