diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 3020108..67d11cb 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -9,7 +9,7 @@ class AdminMenuStructure{ public $menuItems; - public function AdminMenu(){ + public function __construct(){ $this->menuItems = []; } diff --git a/backend/controllers/TicketController.php b/backend/controllers/TicketController.php index ea687ff..68793a6 100644 --- a/backend/controllers/TicketController.php +++ b/backend/controllers/TicketController.php @@ -12,6 +12,8 @@ use common\models\Discount; use common\models\TicketType; use common\models\Account; use common\models\User; +use common\models\Customer; +use common\models\Card; /** * TicketController implements the CRUD actions for Ticket model. @@ -19,6 +21,25 @@ use common\models\User; class TicketController extends \backend\controllers\BackendController { + + public function behaviors() + { + return [ + 'access' => [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => ['create','index','view','update','index-customer'], + 'allow' => true, + 'roles' => ['admin','employee','reception'], + ], + // everything else is denied + ], + ], + ]; + } + /** * Lists all Ticket models. * @return mixed @@ -40,6 +61,42 @@ class TicketController extends \backend\controllers\BackendController 'dataProvider' => $dataProvider, ]); } + + + /** + * Lists all Ticket models. + * @return mixed + */ + public function actionIndexCustomer($id) + { + + $customer = Customer::findOne($id); + $card = Card::findOne($id); + + + if ( $customer == null ){ + throw new NotFoundHttpException('The requested page does not exist.'); + } + + $searchModel = new TicketSearch(); + $searchModel->id_card = $customer->id_customer_card; + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $searchModel->searchTotals(); + + $searchModel->users = User::read(); + $searchModel->accounts = Account::read(); + $searchModel->ticketTypes = TicketType::read(); + + + + return $this->render('index_customer', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'customer' => $customer, + 'card' => $card + ]); + } + /** * Displays a single Ticket model. diff --git a/backend/models/TicketSearch.php b/backend/models/TicketSearch.php index 46f7b46..c71bbf5 100644 --- a/backend/models/TicketSearch.php +++ b/backend/models/TicketSearch.php @@ -30,16 +30,17 @@ class TicketSearch extends Ticket public $statistics; public $statisticsTotal; + /** * @inheritdoc */ public function rules() { return [ - [['id_ticket', 'id_user', 'id_ticket_type', 'id_account', 'id_discount', 'max_usage_count', 'usage_count', 'status', 'price_brutto'], 'integer'], + [[ 'id_user', 'id_ticket_type', 'id_account'], 'integer'], [[ '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'] + [['valid_in_interval','created_in_interval','expire_in_interval'],'boolean'] , ]; } @@ -96,6 +97,10 @@ class TicketSearch extends Ticket $dataProvider = new ActiveDataProvider([ 'query' => $query, + 'sort' =>[ + 'defaultOrder' => ['end' => SORT_DESC], + 'attributes' => ['end'] + ] ]); $this->load($params); @@ -111,9 +116,11 @@ class TicketSearch extends Ticket 'id_user' => $this->id_user, 'id_ticket_type' => $this->id_ticket_type, 'id_account' => $this->id_account, + 'id_card' => $this->id_card, ]); + $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); @@ -150,7 +157,7 @@ class TicketSearch extends Ticket public function searchTotals(){ - $query = Ticket::mkStatisticQuery($this->timestampStart, $this->timestampEnd); + $query = Ticket::mkStatisticQuery($this->timestampStart, $this->timestampEnd,$this->id_card); $this->statistics = $query->all(); $this->statisticsTotal =[ diff --git a/backend/views/customer/index.php b/backend/views/customer/index.php index db4c9e4..a4c7a25 100644 --- a/backend/views/customer/index.php +++ b/backend/views/customer/index.php @@ -2,6 +2,7 @@ use yii\helpers\Html; use yii\grid\GridView; +use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $searchModel backend\models\CustomerSearch */ @@ -24,30 +25,31 @@ $this->params['breadcrumbs'][] = $this->title; 'columns' => [ [ 'attribute' => 'customerCardNumber' , -// 'value' => 'customerCardNumber' ], -// 'id_user', -// 'id_partner_card', -// 'id_proposer', 'name', 'email:email', - // 'password', 'phone', - // 'sex', - // 'date_stundent_card_expire', - // 'birthdate', - // 'image', - // 'description', - // 'tax_number', - // 'country', - // 'zip', - // 'city', - // 'address', 'created_at:datetime', - // 'updated_at', ['class' => 'yii\grid\ActionColumn', - 'template' =>'{view}{update}' + 'template' =>'{view} {update} {ticket/index-customer}', + 'buttons' => [ + 'ticket/index-customer' => function ($url) { return Html::a( ' ', $url, [ 'title' => 'Bérletek' ] ); } + ], + 'urlCreator' =>function ($action, $model, $key, $index){ + $params = is_array($key) ? $key : ['id' => (string) $key]; + if ( $action == 'ticket/index-customer' ){ + $today = \Yii::$app->formatter->asDate( strtotime('today UTC') ); + $tomorrow = \Yii::$app->formatter->asDate( strtotime( 'tomorrow UTC' )); + + $params['TicketSearch[start]'] = $today; + $params['TicketSearch[end]'] = $tomorrow; + + } + $params[0] = $action; + + return Url::toRoute($params); + } ], ], diff --git a/backend/views/ticket/_search_customer.php b/backend/views/ticket/_search_customer.php new file mode 100644 index 0000000..04e7bf5 --- /dev/null +++ b/backend/views/ticket/_search_customer.php @@ -0,0 +1,76 @@ + + + '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'); + +?> + +
Bérlet statisztika a kiválasztott időszakra
+ 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'] + ] + + ] + ]); + + ?> +