<?php
use yii\helpers\Html;
use common\widgets\GridView;
use Yii\helpers\URL;
use common\widgets\ActionColumn;
use yii\data\ArrayDataProvider;
$fileProvider = new ArrayDataProvider([
	'allModels' => $uploads
])
?>
<div class="details">
    <div class="card mb-2">
        <div class="card-header">
            Job Details - <?= ucfirst($model->type) ?>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col">
                    <label class="control-label"><?= $model->getAttributeLabel('jobno') ?>:
                    </label>
                    <?= $model->jobno ?><?= !empty($model->visitno) ? '/'. str_pad($model->visitno, 3, '0', STR_PAD_LEFT) : null ?>
                </div>
                <div class="col">
                    <label class="control-label">
                        <?= $model->getAttributeLabel('welders') ?>:
                    </label> 
                    <?= $model->welder ?>
                </div>
                <div class="col">
                    <label class="control-label">
                        <?= $model->getAttributeLabel('company') ?>:
                    </label>
                    <?=  $model->account ? $model->account->account_name : print_r($model->account) ?>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-12 col-md-4">
            <div class="card mb-2">
                <div class="card-header">
                    Time
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('sdate').':</label> '. $model->sdate ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('shiftlength').':</label> '. $model->shiftlength ?>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('edate').':</label> '. $model->edate ?>

                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('day').':</label> '. $model->day ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('shift').':</label> '. $model->shift ?>


                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-12 col-md-4">
            <div class="card  mb-2">
                <div class="card-header">
                    Travel
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('location').':</label> '.$model->location ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('postcode').':</label> '.$model->postcode ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-6">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('googletime').':</label> '.$model->googletime ?>
                        </div>
                        <div class="col-6">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('googledistance').':</label> '.$model->googledistance ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('journey').':</label> '.$model->journey ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('travelstarttime').':</label> '.$model->travelstarttime ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('accesspoint').':</label> '.$model->accesspoint ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-12 col-md-4">
            <?php if($model->type == 'welding'){ ?>
                <div class="card mb-2">
                    <div class="card-header">
                        Job Details
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-12">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('elr').':</label> '.$model->elr ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-4">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('noofshifts').':</label> '.$model->noofshifts ?>
                            </div>
                            <div class="col-4">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('noofteams').':</label> '.$model->noofteams ?>
                            </div>
                            <div class="col-4">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('noofwelds').':</label> '.$model->noofwelds ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-12">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('weekno').':</label> '.$model->weekno ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-6">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('customerpono').':</label> '.$model->customerpono ?>
                            </div>
                            <div class="col-6">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('ordertitle').':</label> '.$model->ordertitle ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-12">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('travelfinishtime').':</label> '.$model->travelfinishtime ?>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-6">
                                <label class="control-label"><?= $model->getAttributeLabel('actualshifttime').':</label> '.$model->actualshifttime ?>
                            </div>
                            <div class="col-6">
                                <label
                                    class="control-label"><?= $model->getAttributeLabel('predictedshifttime').':</label> '.$model->predictedshifttime ?>
                            </div>
                        </div>
                    </div>
                </div>
            <?php } elseif($model->type == 'administration'){ ?>
                 <?php $administration = $model->data['Administration']; ?>
                <div class="card mb-2">
                    <div class="card-header"><?= Ucwords($model->type)?></div>
                    <div class="card-body">
                        <div class="row">
                            <?php foreach($administration->localAttributes() as $attribute => $array){ ?>
                                <?php if(in_array($attribute, ['id', 'jobid', 'created_at', 'createdby', 'updated_at', 'updatedby'])){ continue; } ?>
                                    <div class="col-12">
                                        <label class="control-label">
                                        <?= $administration->getAttributeLabel($attribute) ?>
                                        :</label>
                                        <?= $administration->$attribute ?>
                                    </div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            <?php } elseif($model->type == 'training'){ ?>
                <?php $training = $model->data['Training']; ?>
                <div class="card mb-2">
                    <div class="card-header"><?= Ucwords($model->type)?></div>
                    <div class="card-body">
                        <div class="row">
                            <?php foreach($training->localAttributes() as $attribute => $array){ ?>
                                <?php if(in_array($attribute, ['id', 'jobid', 'created_at', 'createdby', 'updated_at', 'updatedby'])){ continue; } ?>
                                    <div class="col-12">
                                        <label class="control-label">
                                        <?= $training->getAttributeLabel($attribute) ?>
                                        :</label>
                                        <?= $training->$attribute ?>
                                    </div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            <?php } ?>
        </div>
    </div>
    <?php if($model->type == 'welding'){ ?>
    <div class="row">
        <div class="col-12">
            <div class="card mb-2">
                <div class="card-header">
                    Comments / Job Details
                </div>
                <div class="card-body">
                    <?= $model->orderdata ?>
                </div>
            </div>
            <div class="card mb-2">
                <div class="card-header">
                    Job Specification
                </div>
                <div class="card-body mb-2">
                    <div class="row">
                        <div class="col-6">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('jobtype').':</label> '.$model->jobtype ?>
                        </div>
                        <div class="col-6">
                            <label
                                class="control-label"><?= $model->getAttributeLabel('weldtype').':</label> '.$model->weldtype ?>
                        </div>
                    </div>
                </div>
                <div class="card-header">
                    Technical Details for Work Instruction
                </div>
                <div class="card-body mb-2">
                    <div class="row">
                        <div class="col-12 col-md-1 text-center">
                            <div class="row">
                                <div class="col-12  text-center">

                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-11 text-center">
                            <div class="row">
                                <div class="col-12 col-md-1">
                                    <label class="control-label">
                                        <?= $model->getAttributeLabel('railgrade')  ?>
                                    </label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('railsection')?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('railsupport') ?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('railwear')?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('railtrack') ?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('weld') ?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('noofwelds1') ?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('defectno1') ?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('weldprocess1') ?></label>
                                </div>
                                <div class="col-12 col-md-1">
                                    <label class="control-label"><?= $model->getAttributeLabel('fuelgas') ?></label>
                                </div>
                                <div class="col-12 col-md-2">
                                    <label class="control-label"><?= $model->getAttributeLabel('notes') ?></label>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="row">
                        <div class="col-12 col-md-1 text-center">
                            <div class="row">
                                <div class="col-12  text-center">
                                    1
                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-11 text-center">
                            <div class="row">

                                <div class="col-12 col-md-1">
                                    <?= $model->railgrade  ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railsection?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railsupport ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railwear?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railtrack ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->weld ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->noofwelds1 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->defectno1 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= !empty($model->weldprocess1) ? $model->dtwps1->process : false ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->fuelgas ?>
                                </div>
                                <div class="col-12 col-md-2">
                                    <?= $model->notes ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12 col-md-1 text-center">
                            <div class="row">
                                <div class="col-12  text-center">
                                    2
                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-11 text-center">
                            <div class="row">
                                <div class="col-12 col-md-1">
                                    <?= $model->railgrade2  ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railsection2 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railsupport2  ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railwear2 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railtrack2 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->weld2 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->noofwelds2 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->defectno2 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= !empty($model->weldprocess2) ? $model->dtwps2->process : false ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->fuelgas2 ?>
                                </div>
                                <div class="col-12 col-md-2">
                                    <?= $model->notes2 ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12 col-md-1 text-center">
                            <div class="row">
                                <div class="col-12  text-center">
                                    3
                                </div>
                            </div>
                        </div>
                        <div class="col-12 col-md-11 text-center">
                            <div class="row">
                                <div class="col-12 col-md-1">
                                    <?= $model->railgrade3  ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railsection3 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railsupport3 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railwear3 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->railtrack3 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->weld3 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->noofwelds3 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->defectno3 ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= !empty($model->weldprocess3) ? $model->dtwps3->process : false ?>
                                </div>
                                <div class="col-12 col-md-1">
                                    <?= $model->fuelgas3 ?>
                                </div>
                                <div class="col-12 col-md-2">
                                    <?= $model->notes3 ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-12 col-md-12">

            <div class="card mb-3">
                <div class="card-header">
                    Contacts
                </div>
                <div class="card-body p-0">
                    <table class="table table-bordered tabled-stripped">
                        <thead>
                            <tr>
                                <th>
                                    Name
                                </th>
                                <th>
                                    Email
                                </th>
                                <th>
                                    Phone Number
                                </th>
                            </tr>

                        </thead>
                        <?php $x = null; ?>
                        <?php $field = 'contact'.$x; ?>
                        <?php $fielda = 'contactemail'.$x; ?>
                        <?php $fieldb = 'contact'.$x.'l'; ?>
                        <?php $fieldc = 'contactno'.$x; ?>
                        <tr>
                            <td>
                                <?= $model->$fieldb ? $model->$fieldb->fullname : null; ?>
                            </td>
                            <td>
                                <?= $model->$fielda; ?>
                            </td>
                            <td>
                                <?= $model->$fieldc; ?>
                            </td>
                        </tr>
                        <?php $x = 2; ?>
                        <?php while ($x <= 10){ ?>
                        <?php $field = 'contact'.$x; ?>
                        <?php $fielda = 'contactemail'.$x; ?>
                        <?php $fieldb = 'contact'.$x.'l'; ?>
                        <?php $fieldc = 'contactno'.$x; ?>

                        <?php if(empty($model->$field) == false) { ?>
                        <tr>
                            <td>
                                <?= $model->$fieldb ? $model->$fieldb->fullname : null; ?>
                            </td>
                            <td>
                                <?= $model->$fielda; ?>
                            </td>
                            <td>
                                <?= $model->$fieldc; ?>
                            </td>
                        </tr>


                        <?php } ?>
                        <?php $x++; ?>
                        <?php } ?>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 col-lg-6">
            <div class="files-grid">
                <?= GridView::Widget([
                       'new' => '&nbsp;',
                        'dataProvider' => $fileProvider,
                        'controller' => 'upload',
                        'columns' => [
                            'category',
                            'filename',
                            'type',
                            [
                                'class' => ActionColumn::Class,
                                'header' => 'Actions',
                                'controller' => 'upload',
                                'template' => yii::$app->user->identity->inGroup('Global Admins') ? '{download} {delete}' : '{download}',
                                'buttons' => [
                                    'download' => function ($url, $model, $key)
                                        {
                                            return HTML::a('<span class="fa fa-download"></span>', ['/upload/download', 'id' => $model->id]);
                                        },
                                ]
                            ],
                        ],
                    ]);
                ?>
            </div>

        </div>
        <div class="col-md-12 col-lg-6">
            <div class="card">
                <div class="card-header">
                    Job Forms
                </div>
                <div class="card-body p-0">
                    <?= GridView::widget([
                        'new' => '&nbsp;',
                        'dataProvider' => $dataProvider,
                        //s'filterModel' => $searchModel,
                        'columns' => [
                            [
                                'label' => 'Form',
                                'value' => function($dataModel) {
                                    $data = $dataModel->data;
                                    return $data->formname;
                                }
                            ],

                            //'formid',
                            [
                                'format' => 'raw',
                                'attribute' => 'welder'
                            ],
                            [
                                'class' => \common\widgets\TraceabilityColumn::class,
                                'header' => 'Traceability',
                            ],


                            [
                                'class' => \common\widgets\ActionColumn::class,
                                'header' => 'Actions',
                                'buttons' => [
                                    'view' => function ($url, $model, $key) {
                                        return Html::a("<i class='fa fa-eye'></i>", ['/forms/'.$model->form.'/view', 'id' => $model->id], ['target' => '_blank']);
                                    },
                                    'pdf' => function ($url, $model, $key) {
                                        return Html::a("<i class='fa fa-file-pdf'></i>", ['/forms/'.$model->form.'/pdf', 'id' => $model->id], ['target' => '_blank']);
                                    },
                                    'update' => function ($url, $model, $key) {
                                        return Html::a("<i class='fa fa-pencil-alt'></i>", ['/forms/'.$model->form.'/update', 'id' => $model->id], ['target' => '_blank']);
                                    },
                                    'delete' => function ($url, $model, $key) {
                                        return Html::a("<i class='fa fa-trash'></i>", ['/forms/'.$model->form.'/delete', 'id' => $model->id], ['target' => '_blank']);
                                    },
                                ],
                                'template' => '{delete} {pdf} {view} {update}',
                            ],
                        ],
                    ]); ?>
                </div>
            </div>
        </div>
    </div>
    <?php }?>
    <div class="card mb-5">
        <div class="card-header">
            Job Status
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-6 text-center">
                    <label class="control-label"><label
                            class="control-label"><?= $model->getAttributeLabel('jobstatus').':  </label> '.$model->jobstatus ?>
                </div>
                <div class="col-6 text-center">
                    <label class="control-label"><label
                            class="control-label"><?= $model->getAttributeLabel('billingstatus').':  </label> '.$model->billingstatus ?>
                </div>
            </div>
            <div class="row">
                <div class="col-12 col-md-3">
                    <label class="control-label">Created by:</label> <?= $model->createdby_name ?>
                </div>
                <div class="col-12 col-md-3 ">
                    <label class="control-label">Created At:</label> <?= $model->created_at ?>
                </div>
                <div class="col-12 col-md-3 ">
                    <label class="control-label">Updated by:</label> <?= $model->updatedby_name ?>
                </div>
                <div class="col-12 col-md-3 ">
                    <label class="control-label">Updated At:</label> <?= $model->updated_at ?>
                </div>
            </div>
        </div>
    </div>
</div>