<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\components\AccountTotalWidget;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel frontend\models\CollectionSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('frontend/collection', 'Vendégek');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="collection-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php  echo $this->render('_search', ['model' => $searchModel]); ?>



    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
			[
				'attribute' => 'card_number',
				'label' => 'Kártyaszám',
			],
			[
				'attribute' => 'customer_name',
				'label' => 'Név',
			],
			[
				'attribute' => 'customer_phone',
				'label' => 'Tel',
			],
			[
				'attribute' => 'customer_email',
				'label' => 'E-mail',
			],
// 			[
// 				'attribute' => 'customer.name',
// 				'value' => 'customer.name',
// 			],
            

            ['class' => 'yii\grid\ActionColumn',
             'template' => '{ticket} {product} {ticket_history} {keys} {contract}',
             'buttons' => [
             		'ticket' =>  function ($url, $model, $key) {
		               return   Html::a('Új bérlet', $url, ['class'=> 'btn btn-xs btn-success' ])  ;
		           },
             		'product' =>  function ($url, $model, $key) {
		               return   Html::a('Új termék', $url, ['class'=> 'btn btn-xs btn-success' ])  ;
		           },
		           'ticket_history' =>  function ($url, $model, $key) {
		           return   Html::a('Befizetések', $url, ['class'=> 'btn btn-xs btn-success' ])  ;
		           },
		           'keys' =>  function ($url, $model, $key) {
		           return   Html::a('Kulcsok', $url, ['class'=> 'btn btn-xs btn-success' ])  ;
		           },
		           'contract' =>  function ($url, $model, $key) {
		           return   Html::a('Szerződések', $url, ['class'=> 'btn btn-xs btn-success' ])  ;
		           },
			],
           'urlCreator' => function ($action, $model, $key, $index){
           		$url = "";
           		if ( 'ticket' == $action ){
           			$url = Url::to(['ticket/create','number' => $model['card_number']]);
           		}else if ( 'product' == $action ){
           			$url = Url::to(['product/sale','number' => $model['card_number']]);
           		}else if ( 'ticket_history' == $action ){
           			$url = Url::to(['ticket/index','number' => $model['card_number']]);
           		}else if ( 'keys' == $action ){
           			$url = Url::to(['key/index','id_card' => $model['card_id_card']]);
           		}else if ( 'contract' == $action ){
           			$url = Url::to(['contract/index','id_card' => $model['card_id_card']]);
           		}
           		return $url;
           }
    ],
        ],
    ]); ?>

</div>
