<?php
/**
 * Created by PhpStorm.
 * User: NeiroN
 * Date: 19.11.2015
 * Time: 9:27
 */
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Bidding ID');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="panel panel-primary">
    <div class="panel-heading"><span class="glyphicon glyphicon-list"></span><strong> <?= Html::encode($this->title) ?></strong></div>
    <div class="panel-body">
        <div class="bidding-index">

            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'columns' => [
                    ['class' => 'yii\grid\SerialColumn'],
                    'auctionName',
                    [
                        'header' => Yii::t('app','LotName ID'),
                        'value' =>  function($model)
                        {
                            if(ArrayHelper::getValue($model->auction,'lot_id')) {
                                $lot = app\models\Lots::find()->where(['id' => $model->auction->lot_id])->one();
                                return $lot->name;
                            }
                            return false;
                        }
                    ],
                    'fileName',
                    [
                        'header' => Yii::t('app', 'BiddingDate ID'),
                        'value' => function($model){
                            if(ArrayHelper::getValue($model->auction,'bidding_date')) {
                                return $model->auction->bidding_date;
                            }
                            return false;
                        }
                    ],
                    [
                        'header' => Yii::t('app', 'Рахунки'),
                        'value' => function($model){
                            $status = true;
                            foreach($model->bills as $bill){                                
                                if( $bill->payed == 0 || $bill->payed == 2 ){
                                    $status = false;
                                    break;
                                }
                            }
                            if ($status)
                            {
                                return Html::a('Сплачено', ['view'], ['class' => 'label label-success']);
                                ///return Html::a(Yii::t('app', 'WaitConfirm ID'), ['view'], ['class' => 'label label-warning']);
                            } else {
                                return Html::a('Не сплачено', ['/bills'], ['class' => 'label label-danger']);
                            }
                        },
                        'format' => 'raw',
                    ],                    
                    [
                        'header' => Yii::t('app', 'Заявка'),//'header' => Yii::t('app', 'Status ID'),
                        'value' => function($model){
                            if ($model['status']==0)
                            {
                                return Html::a(Yii::t('app', 'WaitConfirm ID'), ['view'], ['class' => 'label label-warning']);
                            }
                            if ($model['status']==1)
                            {
                                return Html::a(Yii::t('app', 'Success ID'), ['view'], ['class' => 'label label-success']);
                            }
                            if ($model['status']==2)
                            {
                                return Html::a(Yii::t('app', 'Rejected ID'), ['view'], ['class' => 'label label-danger']);
                            }
                        },
                        'format' => 'raw',
                    ],
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'template' => '{enter} {download} {delete}',
                        'buttons' => [
                            'enter' => function ($url,$model,$key) {
                                return Html::a('', '/auctions/view?id='.$model->auction_id,['title'=>Yii::t('app','GoAuction ID'),'class' => 'glyphicon glyphicon-log-in']);
                            },
                            'download'  =>  function ($url,$model,$key) {
                                return Html::a('', '/files/download?id='.$model->file_id,['title'=>Yii::t('app','Download ID'),'class' => 'glyphicon glyphicon-circle-arrow-down']);
                            }
                        ],
                    ],
                ],
            ]); ?>
        </div>
    </div>
</div>