<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\date\DatePicker;

use yii\helpers\Arrayhelper;

use modules\custom\models\Accounts;
use modules\users\models\User;
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt058 */
/* @var $form yii\widgets\ActiveForm */
$excesscodes = $model::excessCodes();
$reason = $model::reasonCodes();
$method = $model::methodOfRequest();
$accounts = Accounts::getActive();
$welders = User::employeesU();;
if (!$model->actid) {$model->actid = Yii::$app->getRequest()->getQueryParam('actid');}
if (!$model->site) {$model->site = Yii::$app->getRequest()->getQueryParam('site');}
if (!$model->clientid) {$model->clientid = Yii::$app->getRequest()->getQueryParam('clientid');}

//$this->registerJsFile('/js/touch.js'); //load canvas drawing 
$this->registerJsFile('/js/touch_0.js');//load canvas_0
//$this->registerJsFile('/js/touch_1.js');//load canvas_1 
//$this->registerJsFile('/js/touch_2.js'); //load canvas_2 
//$this->registerJsFile('/js/touch_3.js'); //load canvas_3 
$this->registerJsFile('/js/updatesignatures.js'); //load canvas_3
?>
<script>
window.onload = function() {
    //init(); //Drawing
    init0(); //canvas_0
    //init1(); //canvas_1
    //init2(); //canvas_2
    //init3(); //canvas_3
}
</script>

<style>
.DarkerBlue {
    padding-left: 10px;
}
</style>
<div class="dt058-form">

    <?php $form = ActiveForm::begin(); ?>
	<p>
	Part 1 of this form is to be completed by an Inline employee. <BR />
                (Permission from the Inline on call manager must be given at all times).<BR />
                Part 2 is to be completed by the clients site representative and NOT an Inline Employee.<BR />
				</p>

    <table class="Table">
        <tr>
            <th colspan="2">PART 1</th>
            <th class="DarkerBlue">TimeSheet ID</th>
            <td><?= $form->field($model, 'tspadno')->textInput()->label(false) ?></td>
        </tr>
        <tr>
            <th class="DarkerBlue">Site</th>
            <td><?= $form->field($model, 'site')->textInput()->label(false) ?></td>
            <th class="DarkerBlue">Client Company Name</th>
            <td><?= $form->field($model, 'clientid')->dropdownlist($accounts, ['prompt' => 'Please Select'])->label(false) ?>
            </td>
        </tr>
    </table>

    <table class="table table-borderless">
        <tr>
            <th class="DarkerBlue">EMPLOYEE'S NAME</th>
            <th class="DarkerBlue">EXCESS CODE</th>
            <th class="DarkerBlue">PERSON REQUESTING<BR /> AUTHORISING EXCESS</th>
            <th class="DarkerBlue">METHOD OF REQUEST<BR /> AUTHORISATION</th>
            <th class="DarkerBlue">REASON CODE </th>
        </tr>
        <tr>
            <td><?= $form->field($model, 'employeename1')->dropdownList($welders, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'excesscode1')->dropdownList($excesscodes, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'requestor1')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'methodofrequest1')->dropdownList($method, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'reasoncode1')->dropdownList($reason, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'employeename2')->dropdownList($welders, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'excesscode2')->dropdownList($excesscodes, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'requestor2')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'methodofrequest2')->dropdownList($method, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'reasoncode2')->dropdownList($reason, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'employeename3')->dropdownList($welders, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'excesscode3')->dropdownList($excesscodes, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td><?= $form->field($model, 'requestor3')->textInput()->label(false) ?></td>
            <td><?= $form->field($model, 'methodofrequest3')->dropdownList($method, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
            <td> <?= $form->field($model, 'reasoncode3')->dropdownList($reason, ['prompt'=> 'Please Select'])->label(false) ?>
            </td>
        </tr>
    </table>
    <table class="table table-borderless table-condensed">
        <tr>
            <td rowspan="6" valign="middle">Excess Code</td>
            <td>A</td>
            <td colspan="4">More than thirteen turns of duty in any fourteen day period.</td>
        </tr>
        <tr>
            <td>B</td>
            <td colspan="4">More than twelve hours of work per turn of duty (Including Travel Time))</td>
        </tr>
        <tr>
            <td>C</td>
            <td colspan="4">More than seventy-two hours of work per week.</td>
        </tr>
        <tr>
            <td>D</td>
            <td colspan="4">Less than twelve hours between booking off from a turn of duty and booking on for the next turn of duty.
            </td>
        </tr>
        <tr>
            <td>E</td>
            <td colspan="4">For regular shift patterns which rotate or alternate on a weekly basis, with less than eight hours of
                rest during the weekly shift changeover.</td>
        </tr>
        <tr>
            <td colspan="3" class="nolb norb">&nbsp;</td>
        </tr>
        <tr>
            <td rowspan="4" valign="middle">Reason Code</td>
            <td>1</td>
            <td>Adverse weather conditions.</td>
			<td rowspan="3" valign="middle" class="text-right">Method of Request/Authorisation Code</td>
            <td>W</td>
            <td>Written (letter,Text, Email etc)</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Equipment failure.</td>
			
			<td>O</td>
            <td>Oral (telephone or spoken in person)</td>
        </tr>
        <tr>
            <td>3</td>
            <td>Emergency Site Requirements</td>
			<td>R</td>
            <td>Retrospective</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Accident or Incident.</td>
        </tr>
    </table>
    <br />



    PART 2
	<br />
    <table class="table table-borderless table-condensed">
        <tr>
            <th class="DarkerBlueC" colspan="8">EXCESS HOURS RISK ASSESMENT</th>
        </tr>
        <tr>
            <th class="DarkerBlue" colspan="2">L = Likelihood</th>
            <th class="DarkerBlue" colspan="3">S = Severity</th>
            <th class="DarkerBlue" colspan="3">RF = Risk Factor</th>
        </tr>
        <tr>
            <th class="DarkerBlue" colspan="4">RISK</th>
            <th class="DarkerBlue" colspan="4">CONTROLS</th>
        </tr>
        <tr>
            <th class="DarkerBlue">RISK</th>
            <th class="DarkerBlue">L</th>
            <th class="DarkerBlue">S</th>
            <th class="DarkerBlue">RF</th>
            <th class="DarkerBlue">&nbsp;</th>
            <th class="DarkerBlue">L</th>
            <th class="DarkerBlue">S</th>
            <th class="DarkerBlue">R</th>
        </tr>

        <tr>
            <td>Substandard work due to fatigue</td>
            <td>2</td>
            <td>4</td>
            <td>8</td>
            <td>Increased levels of supervision, downscale work loads</td>
            <td>1</td>
            <td>4</td>
            <td>4</td>
        </tr>
        <tr>

            <td>Substandard work due to fatigue</td>
            <td>2</td>
            <td>4</td>
            <td>8</td>
            <td>Supervisory monitoring/mentoring</td>
            <td>1</td>
            <td>4</td>
            <td>4</td>
        </tr>
        <tr>

            <td>Accident whilst driving home at end of shift</td>
            <td>3</td>
            <td>5</td>
            <td>15</td>
            <td>Offer/Provide lodgings</td>
            <td>0</td>
            <td>0</td>
            <td>0</td>
        </tr>
        <tr>

            <td>Inability to achieve 12hr break due to increased shift time including travel</td>
            <td>3</td>
            <td>5</td>
            <td>15</td>
            <td>Offer/Provide lodgings</td>
            <td>0</td>
            <td>0</td>
            <td>0</td>
        </tr>

    </table>

    N.B Exceedance of working hours must not extend beyond a maximum of 4hrs. <br />
    I have assessed the reasons for the authorisation/request for the above excess hours and therefore confirm that they
    will <br />
    not exceed a maximum 4hrs and will not contravene Network Rail's Standard NR/L2/ERG/003 ISSUE 5. <br />
    Arrangements for relief will be made where required. <br />

    <table class="table table-borderless">
        <tr>
            <th class="DarkerBlue">Signature of nominated client's site representative</th>
            <td>
                <canvas id="canvas_0"></canvas>
                <?= Html::button('Reset', [ 'class' => 'btn btn-primary', 'onclick' => 'ClearCanvasX(0);' ]); ?>
                <?= $form->field($model, 'clientrepsignrepsign')->hiddenInput(['id' => 'signature0'])->label(false) ?>

            </td>
            <th class="DarkerBlue">Date</th>
            <td><?= $form->field($model, 'date')->widget(DatePicker::class, ['name'=>'date', 'type' => 1, 'pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy', 'useCurrent' => true]])->label(false) ?>
            </td>
        </tr>
        <tr>
            <th class="DarkerBlue">Client Print</th>
            <td><?= $form->field($model, 'clientsiterepprint')->textInput()->label(false) ?></td>
        </tr>
    </table>
    <br />
    Rev2/Feb2017/GJS


    <div class="form-group">
        <?= Html::submitButton( 'Save', ['class' =>  'btn btn-primary', 'onclick' => 'saveImages()']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<script>
x = 0;

function saveImages() {
    while (x < 1) {
        id = "signature" + x;
        cavid = "canvas_" + x;
        document.getElementById(id).value = document.getElementById(cavid).toDataURL();
        x++
    }
}
</script>