<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\bootstrap4\Modal;
Use backend\models\Attributesvalues;
use kartik\time\TimePicker;
use kartik\datetime\DateTimePicker;
use kartik\date\DatePicker;
use kartik\typeahead\TypeaheadBasic;
use kartik\typeahead\Typeahead;
use kartik\select2\Select2;
use modules\users\models\User;
use modules\custom\models\Accounts;
use frontend\models\Activities;
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt125 */
/* @var $form yii\widgets\ActiveForm */
//_form

//Select2 user query
$clients = Accounts::getActive();
$passfail = Attributesvalues::formarray('passfail');
$smallwear = Attributesvalues::formarray('smallwear');
$wear = Attributesvalues::formarray('wear');

if (Yii::$app->user->identity->username == "JustinHTyler") {
	$model->result = "PASS"; $model->repf = "PASS"; $model->rtpf = "PASS"; $model->rc1 = "PASS";  $model->rc2 = "PASS"; $model->rc3 = "PASS"; $model->rc4 = "PASS"; $model->rc5 = "PASS"; $model->rc6 = "PASS"; $model->rc7 = "PASS"; $model->rc8 = "PASS"; $model->rc9 = "PASS"; $model->rc10 = "PASS"; 
	$model->rc11 = "PASS"; $model->rc12 = "PASS"; $model->rc13 = "PASS"; $model->rc14 = "PASS"; $model->rc15 = "PASS"; $model->rc16 = "PASS"; $model->rc17 = "PASS"; $model->rc18 = "PASS"; $model->rc19 = "PASS"; $model->rc20 = "PASS"; 
	$model->rc21 = "PASS"; $model->rc22 = "PASS"; $model->rc23 = "PASS"; $model->rc24 = "PASS"; $model->rc25 = "PASS"; $model->rc26 = "PASS"; $model->rc27 = "PASS"; $model->rc28 = "PASS"; $model->rc29 = "PASS"; $model->rc30 = "PASS";
	$model->rc31 = "PASS"; $model->rc32 = "PASS"; $model->rc33 = "PASS"; $model->rc34 = "PASS"; $model->rc35 = "PASS"; $model->rc36 = "PASS"; $model->rc37 = "PASS"; $model->rc38 = "PASS"; $model->rc39 = "PASS"; $model->rc40 = "PASS"; $model->rc41 = "PASS"; $model->rc42 = "PASS"; 	
}

?>
<?php
	$time = new \DateTime('now');
	$today = $time->format('d/n/Y');
/*
if (yii::$app->controller->action->id == 'create') {
	$injobno = Yii::$app->getRequest()->getQueryParam('injobno');
	$site = Yii::$app->getRequest()->getQueryParam('site');
	$starttime = Yii::$app->getRequest()->getQueryParam('starttime');
	$finishtime = Yii::$app->getRequest()->getQueryParam('finishtime');
	$client = Yii::$app->getRequest()->getQueryParam('company');
	$contact = Yii::$app->getRequest()->getQueryParam('contact');
	$contactno = Yii::$app->getRequest()->getQueryParam('contactno');
	$contactemail = Yii::$app->getRequest()->getQueryParam('contactemail');
	$weldersdepot = Yii::$app->getRequest()->getQueryParam('weldersdepot');
	$weldprocess = Yii::$app->getRequest()->getQueryParam('weldprocess');
	$noofwelds = Yii::$app->getRequest()->getQueryParam('noofwelds');
	$actid = Yii::$app->getRequest()->getQueryParam('actid');
	//$welders = Yii::$app->getRequest()->getQueryParam('welders');
    //$model->insepectorid = explode(',', $welders);
	$model->injobno = $injobno;
    $model->site = $site;
    $model->dateinspected = $starttime;
    $model->company = $client;
    $model->weldprocess = $weldprocess;
    $model->weldersdepot = $weldersdepot;
	$model->stampno = Yii::$app->user->identity->stampno;
}
*/
$this->title = 'Thermic Weld Inspection Form (DT122)';
?>
<?php
//$this->registerJsFile('/js/touch.js'); //load canvas drawing 
$this->registerJsFile('/js/touch_1.js');//load canvas_1 
$this->registerJsFile('/js/updatesignatures.js'); //load canvas drawing 
//$this->registerJsFile('/js/touch_2.js'); //load canvas_2 
//$this->registerJsFile('/js/touch_3.js'); //load canvas_3 ?>
<script>
window.onload = function() {
    //	init(); //Drawing
    init1(); //canvas_1
    //	init2(); //canvas_2
    //	init3(); //canvas_3
}
</script>
<div>
    <?php $form = ActiveForm::begin(); ?>
    <table class="table table-borderless">
        <tr>
            <td class="DarkerBlue" width="16.67%">IN Job No</td>
            <td class="DarkerBlue" width="16.67%">Weld ID</td>
            <td class="DarkerBlue" width="16.67%">Date Installed</td>
            <td class="DarkerBlue" width="16.67%">Site</td>
            <td class="DarkerBlue" width="16.67%">ELR</td>
            <td class="DarkerBlue" width="16.66%">Track ID</td>
        </tr>
        <tr>
            <td width="16.67%"><?= $form->field($model, 'injobno')->textinput(['id' => 'injobno'])->label(false)?></td>
            <td><?= $form->field($model, 'weldid')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td width="16.67%" valign="top">
                <?= $form->field($model, 'dateinspected')->widget(DatePicker::class, [
                    'type' => 1,
                    'pluginOptions' => [
                            'format' => 'dd/mm/yyyy',
                            'todayHighlight' => true],])->label(false);?>
        </td>
            <td width="16.67%">
                <?= $form->field($model, 'site')->textInput(['maxlength' => 100, 'id' => 'location']) ->label(false)?>
            </td>
            <td width="16.67%">
                <?= $form->field($model, 'elr')->textInput(['maxlength' => 100, 'placeholder' => 'N/A']) ->label(false)?>
            </td>
            <td width="16.67%"><?= $form->field($model, 'trackid')->textInput([]) ->label(false)?></td>
        </tr>
        <tr>
            <td class="DarkerBlue">Mileage</td>
            <td class="DarkerBlue">Rail LH/RH</td>
            <td class="DarkerBlue">Company</td>
            <td class="DarkerBlue">Welder Depot</td>
            <td class="DarkerBlue">Stamp No</td>
            <td class="DarkerBlue">Weld Process
            
            <span class="fa fa-plus btn-attributes float-right" data-value="process"></span>
            </td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'mileage')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td><?= $form->field($model, 'raillhrh')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td><?= $form->field($model, 'company')->dropDownList($clients, ['id' => 'client', 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'weldersdepot')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td><?= $form->field($model, 'stampno')->textInput([])->label(false)?></td>
            <td><?= $form->field($model, 'weldprocess')->dropDownList(Attributesvalues::formarray('process'), ['prompt' => 'Please Select...']) ->label(false)?>
            </td>
        </tr>
        <tr>
            <td class="DarkerBlue">
                Rail Profile L/H
                <span class="fa fa-plus btn-attributes float-right" data-value="profile"></span>
            </td>
            <td class="DarkerBlue">
                Steel Grade L/H
                <span class="fa fa-plus btn-attributes float-right" data-value="railgrade"></span>
            </td>
            <td class="DarkerBlue">Rail Wear L/H</td>
            <td class="DarkerBlue">
                Moulds Used
                <span class="fa fa-plus btn-attributes float-right" data-value="mouldused"></span>
            </td>
            <td class="DarkerBlue">Portion No.</td>
            <td class="DarkerBlue">Batch No.</td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'railprofilelh')->dropDownList(Attributesvalues::formarray('profile'), ['prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'steelgradelh')->dropDownList(Attributesvalues::formarray('railgrade'), ['prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'railwearlh')->widget(Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]]) ->label(false);?>
            </td>
            <td><?= $form->field($model, 'mouldused')->dropDownList(Attributesvalues::formarray('mouldused'), ['prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'portionno')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td><?= $form->field($model, 'batchno')->textInput(['maxlength' => 100]) ->label(false)?></td>
        </tr>
    </table>
    <table class="table">
        <tr>
            <td class="DarkerBlue">Rail Profile R/H
            <span class="fa fa-plus btn-attributes float-right" data-value="profile"></span>
            </td>
            <td class="DarkerBlue">
                Steel Grade R/H 
                <span class="fa fa-plus btn-attributes float-right" data-value="railgrade"></span>
            </td>
            <td class="DarkerBlue">Rail Wear R/H 
            </td>
            <td class="DarkerBlue" style="width: 25%;">Wide Gap Batch No. </td>
            <td class="DarkerBlue" style="width: 25%;">Wide Gap Portion No. </td>
        </tr>
        <tr>
            <td style="width: 16.67%;">
                <?= $form->field($model, 'railprofilerh')->dropDownList(Attributesvalues::formarray('profile'), [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td style="width: 16.67%;">
                <?= $form->field($model, 'steelgraderh')->dropDownList(Attributesvalues::formarray('railgrade'), [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td style="width: 16.67%;">
                <?= $form->field($model, 'railwearrh')->widget(Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]]) ->label(false);?>
            </td>
            <td style="width: 25%;">
                <?= $form->field($model, 'widegapbatchno')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td style="width: 25%;">
                <?= $form->field($model, 'widegapportionno')->textInput(['maxlength' => 100]) ->label(false)?></td>
        </tr>
    </table>

    <table class="Table">
        <tr>
            <td colspan="1" class="DarkerBlue">
                Running Table
                <span class="fa fa-plus btn-attributes float-right" data-value="passfail"></span>
            </td>
            <td><?= $form->field($model, 'rtpf')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
        </tr>
        <tr>
            <td>-50cm</td>
            <td>-37.5cm</td>
            <td>-25cm</td>
            <td>-12.5cm</td>
            <td colspan='2'>WELD</td>
            <td>12.5cm</td>
            <td>25cm</td>
            <td>37.5cm</td>
            <td>50cm</td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'rt1')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'rt2')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'rt3')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'rt4')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td colspan="2">
                <?= $form->field($model, 'rt5')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'rt6')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'rt7')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'rt8')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 'rt9')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
        </tr>
    </table>
    <table class="Table">
        <tr>
            <td colspan="1" class="DarkerBlue">Running Edge</td>
            <td><?= $form->field($model, 'repf')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
        </tr>
        <tr>
            <td>-50cm</td>
            <td>-37.5cm</td>
            <td>-25cm</td>
            <td>-12.5cm</td>
            <td colspan='2'>WELD</td>
            <td>12.5cm</td>
            <td>25cm</td>
            <td>37.5cm</td>
            <td>50cm</td>
        </tr>
        <tr>
            <td><?= $form->field($model, 're1')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 're2')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 're3')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 're4')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td colspan="2">
                <?= $form->field($model, 're5')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 're6')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 're7')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 're8')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td><?= $form->field($model, 're9')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
        </tr>
    </table>
    <table class="Table">
        <tr>
            <td colspan="2" class="DarkerBlue">Rejection Criteria</td>
            <td colspan="1" class="DarkerBlue">Result</td>
            <td colspan="2" class="DarkerBlue">Rejection Criteria</td>
            <td colspan="1" class="DarkerBlue">Result</td>
        </tr>
        <tr>
            <td colspan="2" class="DarkerBlue"></td>
            <td colspan="1" class="DarkerBlue">Pass/Fail</td>
            <td colspan="2" class="DarkerBlue"></td>
            <td colspan="1" class="DarkerBlue">Pass/Fail</td>
        </tr>
        <?php 
            $x = 1;
            $y= 22;
            ?>
        <?php while($x < 22){ ?>
        <?php 
                $fielda ='rc'.$x;
                $fieldb ='rc'.$y;
                $td = explode('||', $model->getAttributeLabel($fielda));
                $tdb = explode('||', $model->getAttributeLabel($fieldb));
            ?>
        <tr>
            <td><?= $td[0]  ?></td>
            <td><?= $td[1]  ?></td>
            <td><?= $form->field($model, $fielda)->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            <td><?= $tdb[0]  ?></td>
            <td><?= $tdb[1]  ?></td>
            <td><?= $form->field($model, $fieldb)->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
        </tr>
        <?php $x++; $y++;?>
        <?php } ?>


    </table>

    <table class="Table">
        <tr>
            <td colspan="4" class="Title">Additional Information</td>
        </tr>
        <tr>
            <td class="DarkerBlue">Welds made at Lineside</td>
            <td class="DarkerBlue">Between tensors</td>
            <td class="DarkerBlue">Low ambient temp</td>
            <td class="DarkerBlue">Steel sleepers</td>
        </tr>
        <tr>
            <td><?= $form->field($model, 'weldsmadeatlineside')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td><?= $form->field($model, 'betweentensors')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td><?= $form->field($model, 'lowambtemp')->textInput(['maxlength' => 100]) ->label(false)?></td>
            <td><?= $form->field($model, 'steelsleepers')->textInput(['maxlength' => 100]) ->label(false)?></td>

        </tr>
        <tr>
            <td class=DarkerBlue>Welder Comments</td>

            <td colspan="3"><?= $form->field($model, 'welderscomments')->textArea(['rows' => 3]) ->label(false)?></td>
        </tr>
        <tr>
            <td class="DarkerBlue">Result</td>
            <td>
                <?= $form->field($model,'result')->dropDownList($passfail, [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td class="DarkerBlue">
                Action Required
                <span class="fa fa-plus btn-attributes float-right" data-value="dt122actionrequired"></span>
            </td>
            <td>
                <?= $form->field($model,'actionrequired')->dropDownList(Attributesvalues::formarray('dt122actionrequired'), [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
        </tr>
        <tr>
            <td class="DarkerBlue">
                UIC Code
                <span class="fa fa-plus btn-attributes float-right" data-value="dt122uiccode"></span>
            </td>

            <td><?= $form->field($model, 'uiccode')->dropDownList(Attributesvalues::formarray('dt122uiccode'), [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>

            <td colspan="2"></td>
        </tr>
    </table>
    <table class="Table">
        <tr>
            <td class="DarkerBlue" style="width: 16.67%;">
            Min Action Code
            <span class="fa fa-plus btn-attributes float-right" data-value="dt122minactioncode"></span>
            
            </td>
            <td style="width: 16.67%;">
                <?= $form->field($model, 'minactioncode')->dropDownList(Attributesvalues::formarray('dt122minactioncode'), [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td class="DarkerBlue" style="width: 16.67%;">
            Removal Method
            <span class="fa fa-plus btn-attributes float-right" data-value="dt122removalmethod"></span>
            </td>
            <td style="width: 16.67%;">
                <?= $form->field($model, 'removalmethod')->dropDownList(Attributesvalues::formarray('dt122removalmethod'), [ 'prompt' => 'Please Select...']) ->label(false)?>
            </td>
            <td class="DarkerBlue" style="width: 16.67%;">Removal Deadline</td>
            <td style="width: 16.67%;">
            
                <?= $form->field($model, 'removedeadline')->widget(DatePicker::class, ['type' => 1, 'pluginOptions' => [
                    'format' => 'dd/m/yyyy','todayHighlight' => true]])
                ->label(false)
        ;?></td>
        </tr>
    </table>
    <table class="Table">
        <tr >
            <td colspan="3"  class="DarkerBlue">Inspector Comments</td>
        </tr>
        <tr>
            <td colspan="3"><?= $form->field($model, 'inspectorcomments')->textArea(['rows' => 3]) ->label(false)?></td>
        </tr>
        <tr >
            <td class="DarkerBlue">Date of Inspection</td>
            <td class="DarkerBlue">Inspectors I.D.</td>
            <td class="DarkerBlue">Signature</td>
        </tr>
        <tr>
            <td style="width: 33%;" valign="top">
            <?= $form->field($model, 'inspectiondate')
                ->widget(DatePicker::class, [
                    'type' => 1,
                    'pluginOptions' => [
                    'format' => 'dd/mm/yyyy',
                    'convertFormat' => true,
                    'todayHighlight' => true
                ]])
                    ->label(false); ?>
                </td>
            <td width="33%" valign="top">
                <?=$form->field($model, 'insepectorid')->dropdownlist(User::Employeesu(), ['prompt' => 'Please Select...'])->label(false)?>
            </td>
            <td>
                <div id="canvas1">
                    <canvas id="canvas_1" class="canvas1">
                    </canvas>
                </div>

                <?= Html::button('Reset', [ 'class' => 'btn btn-primary', 'onclick' => 'ClearCanvas1();' ]); ?>
                <?= $form->field($model, 'signatureloc')->hiddenInput(['id' => 'signature1']) ->label(false)?>
            </td>
        </tr>
    </table>
    <div class="form-group">
        <?= Html::submitButton('Save', ['class' => 'btn btn-primary', 'onclick' => 'saveImage11()']) ?>
    </div>
    <?php ActiveForm::end(); ?>
</div>
<?php Modal::begin (['id' => 'modal', 'size' => 'modal-lg']);
	    echo "<div id='modalContent'></div>";
    Modal::end(); ?>

<script>
function saveImage11() {
    $("#signature1").val(document.getElementById('canvas_1').toDataURL())
}
</script>