<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use frontend\components\CustomerTabWidget;

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

$this->title = $searchModel->customer->name . " szerződései";
$this->params['breadcrumbs'][] =  $this->title;
?>

<?php echo CustomerTabWidget::widget(['card' => $searchModel->card])?>

<div class="contract-index">

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

<?php 

echo Html::a( "Új szerződés",['contract/make' ,  'id' => $searchModel->customer->id_customer   ], ['class' => 'btn btn-success'])
?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            'id_contract',
        		[
        				'attribute' => 'id_customer',
        				'value' => 'customerName'
        		],
        		[
        				'attribute' => 'id_user',
        				'value' => 'userName'
        		],
        		[
        			'attribute' => 'flag',
        			'value' => "flagName"
        		],
            // 'part_paid',
            // 'part_count',
            // 'part_required',
            'expired_at:datetime',
            'created_at:datetime',
            // 'updated_at',

            ['class' => 'yii\grid\ActionColumn',
            		'template' => '{details}',
            		'buttons' => [
            				'details' =>  function ($url, $model, $key) {
            					return   Html::a('Fizetési részletek', $url, ['class'=> 'btn btn-xs btn-success' ])  ;
            					},
            				],
            				'urlCreator' => function ($action, $model, $key, $index){
            				$url = "";
            				if ( 'details' == $action ){
            					$url = Url::to(['contract/view','id' => $model->id_contract]);
            				} 
            				return $url;
            				}	
            		
    ],
        ],
    ]); ?>

</div>
