<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\data\ArrayDataProvider;
use backend\components\AdminCustomerTabWidget;
use common\models\Ticket;
use yii\helpers\Url;

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

$customer = $customer->name;
if ( isset($card)){
	$customer .= " (" .$card->number . ")";
}

$this->title = Yii::t('common/ticket', '{customer} Tickets', ['customer'=>$customer]);
$this->params['breadcrumbs'][] = "Vendég";
$this->params['breadcrumbs'][] = "Befizetések";



?>
<?php echo AdminCustomerTabWidget::widget(['customer' => $searchModel->customer]) ?>
<div class="ticket-index">

    <?php   echo $this->render('_search_customer', ['model' => $searchModel]); ?>

    
    <?php /*?>
    <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 */?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
        	[
        		'attribute' => 'ticket_id_ticket',
        		'label' => 'Bérlet azonosító'
        	],
//         	[
//         		'attribute' => 'card_number',
//         		'label' => 'Kártyaszám'
//         	],
        	[
        		'attribute' => 'ticket_start',
        		'label' => 'Érvényesség kezdete',
        		'format' => 'datetime'
        	],
        	[
        		'attribute' => 'ticket_end',
        		'label' => 'Érvényesség vége',
        		'format' => 'datetime'
        	],
        	[
        		'attribute' => 'user_username',
        		'label' => 'Kiadta',
        	],
        	[
	           'attribute' => 'paid_by_username',
        		'label' => 'Fizette'
    		],
        	[
        		'attribute' => 'ticket_type_name',
        		'label' => 'Típus'
        	],
        	[
        		'attribute' => 'account_name',
        		'label' => 'Kassza'
        	],
        	[
        		'attribute' => 'ticket_status',
        		'label' => 'Státusz',
        		'value' => function ($model, $key, $index, $column){
        			return Ticket::toStatusName($model['ticket_status']);
    			}
        	],
        	[
        	'attribute' => 'ticket_price_brutto',
        	'label' => 'Ár'
        			],
//             'max_usage_count',
//             'usage_count',

            ['class' => 'yii\grid\ActionColumn',
            	'template' => '{view} {update}'	,
            	'urlCreator' =>  function($action, $model, $key, $index){
            		if ( $action == 'view' ){
            			return Url::toRoute( [ 'ticket/view' , 'id' => $model['ticket_id_ticket' ] ] );
            		}else if ( $action == 'update' ){
            			return Url::toRoute( [ 'ticket/update' , 'id' => $model['ticket_id_ticket' ] ] );
            		}
            		return null;
        		},
    		],
        ],
    ]); ?>

</div>
