<?php

$this->title = 'Exceedance Reports';
/** 
* @var  \yii\web\View $this
* @var  \yii\data\ArrayDataProvider $dtProvider
*/
use yii\helpers\Html;
use common\widgets\GridView;
use modules\forms\models\Dt058;

$excesscodes = Dt058::excessCodes();
$reason = Dt058::reasonCodes();
$method = Dt058::methodOfRequest();
?>


<?php
echo GridView::widget([
    'dataProvider' => $dtProvider,
    'new' => '&nbsp;',
    'title' => $this->title,
    'columns' => [
        [
            'label' => 'Actions',
            'format' => 'raw',
            'value' => function($model) {
                return Html::a(Html::tag('span', '', ['class' => 'fas fa-eye']), ['/forms/dt058/view', 'id' => $model['id'], 'form' => 'dt058'], ['target' => '_blank', 'rel' => 'noopener noreferrer']);
            }
        ],
        [
            'attribute' => 'date', 
            'format' => 'raw',
            'label' => 'Date',
            'value' => function($model) {
                return !empty($model->date) ? date('d/m/Y', strtotime($model->date)) : null;
            }
        ],
        'clientl.account_name', // Client name via relation
        [
            'attribute' => 'employeename1', 
            'label' => 'Employee',
            'format' => 'raw',
            'value' => function($model) {
                return join('<br/>', [$model->employeename1, $model->employeename2, $model->employeename3]);

            }
        ],
        [
            'attribute' => 'excesscode1', 
            'label' => 'Excess Code',
            'value' => function($model) use ($excesscodes) {
                return isset($excesscodes[$model->excesscode1]) ? $excesscodes[$model->excesscode1] : $model->excesscode1;
            }
        ],
        [
            'attribute' => 'reasoncode1', 
            'label' => 'Reason',
            'value' => function($model) use ($reason) {
                return isset($reason[$model->reasoncode1]) ? $reason[$model->reasoncode1] : $model->reasoncode1;
            }
        ],
    ],
]);
?>

<!-- Fallback exceedances removed; only DT058 forms are shown -->
