<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Contract;
use yii\helpers\Url;

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

$this->title = "Szerződések";
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="contract-index">

    <h1><?php echo "Szerződések" ?></h1>
    <?php   echo $this->render('_search', ['model' => $searchModel]); ?>


    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
			/*
			 * 'contract.id_contract as contract_id_contract',
        		'user.username as user_name',
        		'customer.id_customer as customer_id_customer',
        		'customer.name as customer_name',
        		'customer.status as customer_status',
        		'customer.flags as customer_flags',*/
        	[
        		'attribute' => 'contract_id_contract'	,
        		'label' =>'Szerződés azonosító'
    		],
        	[
        		'attribute' => 'user_name'	,
        		'label' =>'Felhasználó'
    		],
        	[
        		'attribute' => 'customer_id_customer'	,
        		'label' =>'Vendég azonosító'
    		],
        	[
        		'attribute' => 'customer_name'	,
        		'label' =>'Vendég név'
    		],
        	[
        		'attribute' => 'contract_status'	,
        		'label' =>'Státusz',
        		'value' => function ($model, $key, $index, $column){
        			return Contract::toStatusName($model['contract_status']);
        		}
    		],
        	[
        		'attribute' => 'contract_flag'	,
        		'label' =>'Állapot',
        			'value' => function ($model, $key, $index, $column){
        			return Contract::toFlangName($model['contract_flag']);
    		}
    		],
    		[
    			'attribute' => 'contract_part_count'	,
    			'label' =>'Összes részlet'
    		],
    		[
    			'attribute' => 'contract_part_required'	,
    			'label' =>'Esedékes részletek'
    		],
    		[
    			'attribute' => 'contract_part_paid'	,
    			'label' =>'Részletek fizetve'
    		],
    		[
    			'attribute' => 'contract_created_at'	,
    			'label' =>'Létrehozva',
    			'format' => 'date'
    		],
    		[
    			'attribute' => 'contract_started_at'	,
    			'label' =>'Érvényes tól',
    			'format' => 'date'
    		],
    		[
    			'attribute' => 'contract_expired_at'	,
    			'label' =>'Lejárat',
    			'format' => 'date'
    		],
    		[
    			'class' => 'yii\grid\ActionColumn',
    			'template' =>'{details}',
    			'urlCreator' => function  ($action, $model, $key, $index){
    				$result = "";
    				if ( $action == 'details' ){
    					$result = Url::toRoute(['contract/details','id' => $model['contract_id_contract']]);
    				}
    				return $result;
    				},
    			'buttons' => [
	    			 'details' => function ($url, $model, $key) {
	    				   return   Html::a('Részletek', $url , ['class' => 'btn btn-primary btn-xs' ])   ;
	    		     },
    		    
    			],
    		],
        ],
    ]); ?>

</div>
