<?php

use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt_was */
/* @var $form yii\widgets\ActiveForm */
//$form = ActiveForm::begin()

$siteinstructions = "Please log in with MAC RAIL on all COLAS RAIL  sites  - 01934 319 810<br>COSS contact:";
$safetyandevrioment = "First Aid, Burns kits, fire extinguishers must be carried on site at all times. Ensure all PPE <br> is fit for use. All materials to be removed from site after work.";
$special = "Preparation: tensors required, <br>On Site:<br>1) With COSS permission, trolley may be placed onto designated road / rail<br>2)Trolley to be loaded with all appropriate plant  consumables and equipment to carry out the work<br>3) All welds to be installed as prescribed in WPS, and process suppliers manual.<br><br>";
$safetyandevrioment1 = "All teams to ensure they receive COSS briefing and sign briefing sheet.<br>All materials to be removed from site after completion of work<br>All teams to sign out after completion of shift";

$name1 =  $model->namel1?->firstname ?: 'Report to Depot';
$name2 =  $model->namel2?->firstname ?: '';

!isset($job) ? $job = \modules\activities\models\Activities::findOne($model->actid) : null;
 ?>
<div class="witr-view">
    <table class="Table notbb nolb norb">
        <tr>
            <td class="notbb nolb norb" colspan="3" rowspan="3"><img
                    src="https://my.inlinetrack.co.uk/<?= yii::$app->params['settings']['logo']; ?>" alt="inline"></td>
            <td colspan="6" rowspan="3" class="Title">Work Instruction and Technical Review</td>
            <td>Doc Ref</td>
            <td>DT 184</td>
        </tr>
        <tr>
            <td>Issue No</td>
            <td>1</td>
        </tr>
        <tr>
            <td>Date</td>
            <td></td>
        </tr>
        <tr>
            <td colspan="11" class="LighterBlue"><br /></td>
        </tr>
        <tr>
            <td colspan="11" style="color: DarkRed; font-weight: bold;">1) Job and Possesion Information</td>
        </tr>

        <tr class="DarkerBlue">
            <th>Date</th>
            <th class="">Day</th>
            <th>Week</th>
            <th>ELR</th>
            <th>Start</th>
            <th>Finish</th>
            <th>IN JCN No</th>
            <th colspan="2">Location</th>
            <th colspan="2">Post Code</th>
        </tr>
        <?php if($job) { ?>
        <tr>
            <td><?= date("d/m/Y", strtotime(str_replace('/','-',$job->sdate)));?></td>
            <td><?= $job->day ?></td>
            <td><?= $job->weekno ?></td>
            <td><?= $job->elr ?></td>
            <td><?= $job->sdate;?></td>
            <td><?= $job->edate;?></td>
            <td><?= $job->jobno ?></td>
            <td colspan="2"><?= $job->location ?></td>
            <td colspan="2"><?= $job->postcode ?></td>
        </tr>
        <?php } ?>
        <tr>
            <td class="DarkerBlue" colspan="2" rowspan="">Customer</td>
            <td colspan="9" class="DarkerBlue nobb">Key Site Contacts and ILT Welding Resources</td>
        </tr>


        <tr>
            <?php  $companyl1 = $model->companyl1; ?>
            <td colspan="2"><?= $companyl1?->account_name ?></td>
            <td colspan="9" rowspan="3" class="" style="padding:0 0 0 0">
                <table class="table notbb nolb norb table-borderless">
                    <tr>
                        <td class="DarkerBlue" width="20%" colspan="">Name</td>
                        <td class="DarkerBlue" width="25%">Company</td>
                        <td class="DarkerBlue" width="20%">Grade</td>
                        <td class="DarkerBlue" width="15%">Sentinel No</td>
                        <td class="DarkerBlue" width="20%">Contact No</td>
                    </tr>
                    <tr>
                        <td colspan="">
                            <?= $name1 ?>
                        </td>
                        <td>
                            <?= $companyl1?->account_name ?>
                        </td>
                        <td> <?= $model->grade1 ?></td>
                        <td></td>
                        <td><?= $model->contactno1 ?></td>
                    </tr>
                    <tr>
                        <td colspan="">
                            <?= $name2 ?>
                        </td>
                        <td>
                            <?= empty($name2) == false && isset($companyl1) == true ? $companyl1->account_name : '&nbsp;' ?>
                        </td>
                        <td>
                            <?= empty($name2) == false ? $model->grade2 : '&nbsp;' ?>
                        </td>
                        <td></td>
                        <td>
                            <?= empty($name2) == false ? $model->contactno2 : '&nbsp;' ?>
                        </td>
                    </tr>

                    <?php  if($job) { ?>
                    <?php $welders = explode (',', $job->welder); ?>
                    <?php $users = frontend\models\User::find()->indexBy('username')->all(); ?>
                    <?php foreach ($welders as $key => $welder) { ?>
                        <?php $user = $users[$welder]; ?>
                        <tr>
                            <td colspan=""><?= $user->fullname ?></td>
                            <td>Inline Track</td>
                            <td><?= strlen($user->adv->position) > 1 ? $user->adv->position : $user->grade ?></td>
                            <td><?= $user->sentinelno ?></td>
                            <td><?= $user->contactno?></td>
                        </tr>
                        <?php } ?>
                    <?php } ?>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue">Customer Ref/Job No</td>
        </tr>
        <tr>
            <td colspan="2"><?= $job?->customerpono ?></td>
        </tr>


        <tr style="height: 10px !important;">

            <td colspan="2"></td>
            <td colspan="9">
                Level 1 – Welder Assistant/Gas Burner/Trainee Welder<br />

                Level 2 – Alumino Thermic Welder/Conductor Rail Welder/Weld Inspector/Grinding Operative/GSM/053-54
                Inspector<br />

                Level 3 – Alumino Thermic Welder/Switch & Crossing Welder
            </td>
        </tr>
        <tr>
            <td colspan="11" class="DarkerBlue">Vehicles</td>
        </tr>
        <tr>
            <th colspan="2">Operative</th>
            <th colspan="2">Vehicle</th>
            <th>End</th>
            <th>Distance</th>
            <th>Time</th>
            <th>Shift Length</th>
            <th colspan="3">Comments</th>
        </tr>
        <?php if($job?->times){ ?>
            <?php foreach ($job->times as $key => $row) { ?>
                <tr>
                    <td colspan="2"><?=$row->operativename ?></td>
                    <td colspan="2"><?= $row->vehicle?->reg ?></td>
                    <td><?=$row->postcodeto ?></td>
                    <td><?=$row->distance ?></td>
                    <td><?= sprintf('%02d:%02d:%02d', ($row->traveltime/3600),($row->traveltime/60%60), $row->traveltime%60); ?>
                    </td>
                    <td><?= $row->shifttime  ?></td>
                    <td colspan="3">
                        <?= $row->comments ?>
                    </td>
                </tr>
            <?php } ?>
        <?php } else { ?>
            <tr>
                    <td colspan="2">&nbsp;</td>
                    <td colspan="2">&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td colspan="3">&nbsp;</td>
                </tr>
        <?php } ?>

        <tr>
            <td colspan="11" class="DarkerBlue">Job Description</td>
        </tr>
        <tr>
            <td colspan="11" style="height: 100px;"><?= $job?->orderdata ?></td>
        </tr>

        <tr>
            <td colspan="11">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue" valign="bottom"><br>Location and Access Point</td>
            <td colspan="9"><?= $job?->location ?><br />
                <?= $job?->accesspoint ?></td>
        </tr>

        <tr style="height: 10px !important;">
            <td colspan="11"><br /></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue" valign="bottom">Site Instruction</td>
            <td colspan="9"><?= $model->siteinstructions ?></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue" valign="bottom">Facilities Provider</td>
            <td colspan="9"><?= $model->facilities_provider ?></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue" valign="bottom">Facilities Notes</td>
            <td colspan="9"><?= $model->facilities_notes ?></td>
        </tr>
        <tr style="height: 10px !important;">
            <td colspan="11"><br /></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue" valign="bottom">Safety and Environmental</td>
            <td colspan="9" style="color: Red;" align="center"><?= $safetyandevrioment ?></td>
        </tr>
        <tr style="height: 10px !important;">
            <td colspan="11"><br /></td>
        </tr>
        <tr>
            <td colspan="11" style="color: darkred; font-weight: bold;">2) Technical Requirements</td>
        </tr>
        <tr class="DarkerBlue">
            <td colspan="2">Rail Details</td>
            <td></td>
            <td>Grade</td>
            <td>Section</td>
            <td>Diff Wear</td>
            <td>Track Type</td>
            <td>Support</td>
            <td>Defect</td>
            <td>Weld</td>
            <td>No of Welds</td>
        </tr>
        <?php if($job){ ?>
        <tr>
            <td colspan="2" class="DarkerBlue"></td>
            <td class="DarkerBlue">1</td>
            <td><?= $job?->railgrade  ?></td>
            <td><?= $job?->railsection  ?></td>
            <td><?= $job?->railwear ?></td>
            <td><?= $job?->railtrack ?></td>
            <td><?= $job?->railsupport ?></td>
            <td><?= $job?->defectno1 ?></td>
            <td><?= $job?->weld ?></td>
            <td><?= $job?->noofwelds1  ?></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue"></td>
            <td class="DarkerBlue">2</td>
            <td><?= $job?->railgrade2  ?></td>
            <td><?= $job?->railsection2  ?></td>
            <td><?= $job?->railwear2 ?></td>
            <td><?= $job?->railtrack2 ?></td>
            <td><?= $job?->railsupport2 ?></td>
            <td><?= $job?->defectno2 ?></td>
            <td><?= $job?->weld2 ?></td>
            <td><?= $job?->noofwelds2  ?></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue"></td>
            <td class="DarkerBlue">3</td>
            <td><?= $job?->railgrade3  ?></td>
            <td><?= $job?->railsection3  ?></td>
            <td><?= $job?->railwear3 ?></td>
            <td><?= $job?->railtrack3 ?></td>
            <td><?= $job?->railsupport3 ?></td>
            <td><?= $job?->defectno3 ?></td>
            <td><?= $job?->weld3 ?></td>
            <td><?= $job?->noofwelds3  ?></td>
        </tr>
        <?php } ?>
        <tr>
            <td colspan="11">&nbsp;</td>
        </tr>
        <tr class="DarkerBlue">
            <td colspan="2">Welding Procedure</td>
            <td></td>
            <td colspan="2">Process</td>
            <td>Fuel Gas</td>
            <td>Consumable</td>

            <td>WPS No</td>
            <td colspan="3">Notes</td>
        </tr>
        <tr>
            <?php $dtwps1 = !empty($job->weldprocess1) ? $job?->dtwps1 : null; ?>
            <?php $dtwps2 = !empty($job->weldprocess2) ? $job?->dtwps2 : null; ?>
            <?php $dtwps3 = !empty($job->weldprocess3) ? $job?->dtwps3 : null; ?>
            <td colspan="2" class="DarkerBlue"></td>
            <td class="DarkerBlue">1</td>
            <td colspan="2">
                <?= $dtwps1?->process ?>
            </td>
            <td>
                <?= $job?->fuelgas  ?>
            </td>
            <td>
                <?= $dtwps1?->consumable ?>
            </td>
            <td>
                <?= $dtwps1?->wpsno ?>
            </td>
            <td colspan="3"><?= $job?->notes ?></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue"></td>
            <td class="DarkerBlue">2</td>
            <td colspan="2"> <?= $dtwps2?->process  ?></td>
            <td><?= $job?->fuelgas  ?></td>
            <td><?= $dtwps2?->consumable ?></td>
            <td><?= $dtwps2?->wpsno ?></td>
            <td colspan="3"><?= $job?->notes2 ?></td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue"></td>
            <td class="DarkerBlue">3</td>
            <td colspan="2"> <?= $dtwps3?->process  ?></td>
            <td><?= $job?->fuelgas  ?></td>
            <td><?= $dtwps3?->consumable ?></td>
            <td><?= $dtwps3?->wpsno ?></td>
            <td colspan="3"><?= $job?->notes3 ?></td>
        </tr>

        <tr>
            <td colspan="11">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue" valign="Top" align="left">Special Instructions <br>method of work</td>
            <td colspan="9"><?= $special ?></td>
        </tr>
        <tr>
            <td colspan="11">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue" valign="Top" align="left">Safety<br> and<br>Environmental</td>
            <td colspan="9"><?= $safetyandevrioment1  ?></td>
        </tr>

        <tr>
            <td colspan="11">&nbsp;</td>
        </tr>
        <tr class="DarkerBlue">
            <td colspan="7">RISK AND HAZARDS</td>
            <td>ILT RA ref</td>
            <td colspan="3">Safety Contact</td>
        </tr>
        <tr>
            <td colspan="7">
                1. Site access, slipping, tripping, falling<br>
                2. Loading/unloading (Manual Handling)<br>
                3. Defective plant<br>
                4. Improper use of plant<br>
                5. Sparks and Fire<br>
                6. Heat and fumes
            </td>
            <td></td>
            <td colspan="3">Accidents<br><br>Incidents<br><br>ILT H&S
                <?php $hscontact = $model->hscontactl; ?>
                <?php $ocm = $model->ocm; ?>
                Contact<br><?= $hscontact?->username ?? 'Gary Stevens' ?>
                /
                <?= $hscontact?->contactno ?? '07983174286' ?></td>
        </tr>

        <tr class="DarkerBlue">
            <td colspan="8">Special Control Measures</td>
            <td colspan="3" class="DarkerBlueC">ON CALL MANAGER</td>
        </tr>
        <tr>
            <td Colspan="8" style="border-bottom: none;">
                1. Use Authorised access point (See Above)<br>
                2. Apply manual handling (Methods Statement)<br>
                3. Correct Use of Plant<br>
            </td>
            <td colspan="3" align="Center">
                <?= $ocm?->username ?? 'Gary Stevens' ?>
            </td>
        </tr>
        <tr>
            <td Colspan="8" style="border-bottom: none; border-top: none;">4. All PPE to be checked and used<br></td>
            <td class="DarkerBlueC" colspan="3">Technical Support</td>
        </tr>
        <tr>
            <td Colspan="8" style="border-top: none;">5. Method Statements, COSHH Issued and briefed</td>

            <td align="center" colspan="3">
                <?= $ocm?->contactno ?? '07983174286' ?></td>
        </tr>
        <tr>
            <td colspan="11" style="color: darkred; font-weight: bold;">3) Customer Confirmation ( for ILT office use)
            </td>
        </tr>
        <tr>
            <td colspan="3" class="DarkerBlue">planned date agreed with customer:</td>
            <td colspan="9" style="border-bottom: none; ">
                <?php if ($model->planneddate) {echo date('d/m/Y', $model->planneddate);} else {echo '';}  ?></td>
        </tr>
        <tr>
            <td colspan="3" class="DarkerBlue">amendments agreed with customer</td>
            <td colspan="9" style="border-bottom: none; border-top: none;">
                <?php if ($model->amendmentdate) {echo date('d/m/Y', $model->amendmentdate);} else {echo '';} ?></td>
        </tr>
        <tr>
            <td colspan="3" class="DarkerBlue">non compliances agreed with customer </td>
            <td colspan="3" style="border-bottom: none; border-top: none; border-right: none;"></td>
            <td style="border-bottom: none; border-top: none; border-right: none; border-left: none;">non applicable
            </td>
            <td colspan="4" style="border-bottom: none; border-top: none; border-left: none;"></td>
        </tr>
        <tr>
            <td colspan="3" class="DarkerBlue Title">Further Information</td>
            <td colspan="2" style="border-right: none;"></td>
            <td colspan="6" style="border-left: none;"><?= $model->furtherinfo ?></td>
        </tr>

        <tr>
            <td colspan="3">Work Instruction Issued by:</td>
            <td colspan="4">
                <img height="40px" src="<?= $model->sign ?>" />
            </td>
            <td>Date </td>
            <td colspan="3"><?php if ($model->signdate) {echo date('d/m/Y', $model->signdate);} else {echo '';} ?></td>
        </tr>

        <tr>
            <td colspan="11">Work Instruction and technical review prepared in compliance with ISO 3834 pt 2
            </td>
        </tr>


    </table>
    <div class="extra-buttons">
        <?= Yii::$app->controller->action->id == 'view' ?  Html::a('Send', ['forms/dtwas/sendwitr', 'id' => $formModel->id], ['class' => 'btn btn-success']) : null ; ?>
    </div>
</div>
<style>
.table.table-borderless {
    border: none;
}
</style>