<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\data\ArrayDataProvider;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\TicketSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$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]); ?>
    <div class="row">
		<div class="col-md-3">
            <div class="clearfix" style="margin-bottom: 6px;">
			<span class="pull-left">
                Exportálás:
            </span>
            <?php
               /* echo Html::a(
                    "PDF",\yii\helpers\Url::current( [ Html::getInputName($searchModel,'output') => 'pdf'  ]),
                    ['class' => 'btn btn-primary pull-left','style'=> 'margin-left: 12px;']
                );*/
            ?>
            <?php
                echo Html::a(
                    "XLS",\yii\helpers\Url::current( [ Html::getInputName($searchModel,'output') => 'xls'  ]),
                    ['class' => 'btn btn-primary pull-left','style'=> 'margin-left: 12px;']
                );
            ?>
            </div>
		</div>
	</div>
    <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>
	<?php
		echo GridView::widget([
			'dataProvider' => $dataProvider,
			'columns' => [
        	[
        		'attribute' => 'ticket_id_ticket',
				'label' => 'B. Azonosító'
        	],
			[
        		'attribute' => 'customer_name',
				'label' => 'Vendég'
        	],
			[
        		'attribute' => 'card_number',
				'label' => 'Kártya'
        	],
			[
        		'attribute' => 'ticket_start',
				'label' => 'Érvényes -tól',
				'format' => 'date'
        	],
			[
        		'attribute' => 'ticket_end',
				'label' => 'Érvényes -ig',
				'format' => 'date'
        	],
            [
                'attribute' => 'ticket_type_name',
                'label' => 'Bérlet típus',
            ],
			[
        		'attribute' => 'ticket_created_at',
				'label' => 'Létrehozva',
				'format' => 'datetime'
        	],
			[
        		'attribute' => 'user_username',
				'label' => 'Felhasználó',
        	],
			[
        		'attribute' => 'account_name',
				'label' => 'Kassza',
        	],
			[
        		'attribute' => 'ticket_status',
				'label' => 'Státusz',
                'value' => function ($model, $key, $index, $column){
                    return \common\models\Ticket::toStatusName($model['ticket_status']);
                }
        	],
			[
				'class' => 'yii\grid\ActionColumn',
				'template' => '{view}',
                'urlCreator' => function($action, $model, $key, $index){
                    $result = "";

                    if ( $action == 'view'){
                        $result = \yii\helpers\Url::toRoute(['ticket/view','id' => $model['ticket_id_ticket']]);
                    }

                    return $result;
                }
    		],
			]

		]);
	?>
</div>