<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\data\ActiveDataProvider;
use app\models\Auctions;
/* @var $this yii\web\View */
/* @var $model app\models\Auctions */

$this->title = $model->lot->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Auction ID'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$aukname = Yii::t('app', 'AukName ID');
$lot_label = Yii::t('app', 'Predmet ID');
$lot_number_label = Yii::t('app', 'LotNumber ID');
$org_name_label =   Yii::t('app', 'OrgName ID');
if ($model->type_id=="1") { $type_label = Yii::t('app', 'AuctionUp ID'); } else { $type_label = Yii::t('app', 'Concurs ID'); }
$type_action = Yii::t('app', 'AuctionType ID');



// $dataProvider = new ActiveDataProvider(['query' => \app\models\Trade::find()->where(['auk_id' => $model->id])->limit('5')]);

?>
<!-- <script type="text/javascript">
    window.onfocus = function(){ 
        window.location.reload(); 
    }
</script> -->
<div class="container-fluid">
    <div class="col-sm-12">
        <div class="auctions-view">
            <div class="panel panel-primary">
                <div class="panel-heading"><span class="glyphicon glyphicon-tower"></span><strong>  <?= Html::encode($aukname . ": #". $model->id . " " . $model->name) ?></strong></div>
                <div class="panel-body">
                    <dl class="dl-horizontal">

                        <dt><?= Html::encode($type_action) ?>:</dt><dd><?= Html::encode($type_label) ?></dd>
                        <dt><?= Html::encode($org_name_label) ?>:</dt><dd><?= Html::encode($model->user->at_org) ?></dd>
                        <!--ivakhnov<dt><?/*= Html::encode($lot_number_label) */?>:</dt><dd><?/*= Html::encode($model->lot_num) */?></dd>-->
                        <dt><?= Html::encode($lot_label) ?>:</dt><dd><?= Html::encode($this->title) ?></dd>
                        <?php
                        // trade_log php
                        /*
                        GridView::widget([
                            'dataProvider' => $dataProvider,
                            'columns' => [
                                ['class' => 'yii\grid\SerialColumn'],
                                [
                                    'id',
                                    'auk_id',
                                    'date',
                                    'comment',
                                    'user_id',
                                ]
                        ]]);*/
                        ?>
                        <?php
                        if(Yii::$app->user->can('admin') || Yii::$app->user->can('org'))
                        {

                            if($model->status >= "2") // && $model->type_id=="1")
                            {
                                //$auction = Auctions::find()->with('winners')->where(['id' => 48])->one();
                                //$winners = $auction->winners;
                                //print_r($winners[0]->at_org);

                                $winners = $model->winners;
                                if($winners)
                                {
                                    if(count($winners)==2)
                                    {
                                        ?>
                                        <dt><?= Html::encode(Yii::t('app', 'Winner1 ID')) ?>:</dt><dd><?= Html::encode($model->winners['0']->at_org." / ".$model->winners['0']->date." / ".$model->winners['0']->comment) ?></dd>
                                        <dt><?= Html::encode(Yii::t('app', 'Winner2 ID')) ?>:</dt><dd><?= Html::encode($model->winners['1']->at_org." / ".$model->winners['1']->date." / ".$model->winners['1']->comment) ?></dd>
                                        <?php
                                    }
                                    if(count($winners)==1)
                                    {
                                        ?>
                                        <dt><?= Html::encode(Yii::t('app', 'Winner1 ID')) ?>:</dt><dd><?= Html::encode($model->winners['0']->at_org . " / " . $model->winners['0']['date'] . " / " . $model->winners['0']['comment']) ?></dd>
                                        <?php
                                    }
                                }

                            }
                        }
                        ?>
                    </dl>
                </div>
            </div>
        </div>
    </div>
</div>


<?php

if(Yii::$app->user->can('admin') || Yii::$app->user->can('member') || Yii::$app->user->can('watcher'))
{
    echo $this->render('../../web/ws.html',['model' => $model]);

    //echo Html::a(Yii::t('app','Завантажити повний лог торгiв'), ['/auctions/tradelog', 'id' => $model->id], ['class' => 'glyphicon glyphicon-circle-arrow-down row1']);
}
elseif(Yii::$app->user->can('org'))
{
    // echo $this->render('../../web/ws.html',['model' => $model]);
    echo $this->render('../../web/ws_org.html',['model' => $model]);
}
?>


