<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use backend\models\Attributesvalues;
/* @var $this yii\web\View */
/* @var $model modules\forms\models\Dt213 */
/* @var $form yii\widgets\ActiveForm */
$this->registerJsFile('/js/touch_0.js');
$this->registerJsFile('/js/update179.js');
$users = \frontend\models\User::EmployeesU();
$wear = Attributesvalues::formArray('wear');
$milemeters = Attributesvalues::formArray('milemeters');
$yardschain = Attributesvalues::formArray('yardschain');
$passfail = Attributesvalues::formarray('passfail');

$model->weldersname = is_array($model->weldersname) == true ? $model->weldersname : json_decode($model->weldersname, true);
$model->date = is_integer($model->date) ? $model->date : date('d/m/Y', strtotime('today')); 
$model->insv1date = is_integer($model->insv1date) ? date('d/m/Y', $model->insv1date) : null; 
$model->insv2date = is_integer($model->insv2date) ? date('d/m/Y', $model->insv2date) : null; 
$model->insus1date = is_integer($model->insus1date) ? date('d/m/Y', $model->insus1date) : null; 
$model->insus2date = is_integer($model->insus2date) ? date('d/m/Y', $model->insus2date) : null; 

$stampno = Yii::$app->user->identity->stampno;
?>
<script>
	$(function() {
		init0();
	})
</script>
<div class="dt213-form">

    <?php $form = ActiveForm::begin(); ?>
	<table class="Table">
		<tr>
			<td rowspan="2"><?= yii\helpers\Html::IMG('/images/InlineLogo.png', ['alt' => '']) ?></td>
			<th rowspan="2">Welders Work Return - Aluminothermic Plain Line Repairs TEF/3035 Issue 1 December 2008</th>
			<td>Pad No</td>
		</tr>
		<tr>
    		<td><?= $form->field($model, 'padno')->textInput(['readonly' => true])->label(false) ?>	</td>
		</tr>
	</table>
	<table class="Table">
		<tr>
			<th class="DarkerBlue">Sheet</th>
			<td></td>
			<th class="DarkerBlue">Welders Name</th>
			<td><?= $form->field($model, 'weldersname')
			->widget(\kartik\select2\Select2::class,
['data' => $users,
 'id' => 'weldersname',
 'options' => [
 	'placeholder' => 'Select Operatives...', 
 	],
 'pluginOptions' => [
	'tags' => true,
 	'multiple' => true, 
  	'tokenSeparators' => ['; ', ''],
 	],
 	 ])->label(false)?></td>

			<th class="DarkerBlue">Week No</th>
			<td><?= $form->field($model, 'weekno')->textInput()->label(false) ?></td>
		</tr>
		<tr>
			<th class="DarkerBlue">From</th>
			<td><?= $form->field($model, 'from')->textInput()->label(false) ?></td>
			<th class="DarkerBlue">Signature</th>
			<td>
			<canvas class="canvas" id="canvas_0"></canvas>
			<?= \yii\helpers\Html::Button('Reset', ['OnCLick' => 'ClearCanvasX(0);', 'class' => 'btn btn-danger btn-sm']); ?>
			<?= $form->field($model, 'weldersignature')->hiddenInput(['id' => 'signature0'])->label(false) ?>	
			</td>
			<th class="DarkerBlue">Date</th>
			<td><?= $form->field($model, 'date')->widget(\kartik\date\DatePicker::class, ['pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
		</tr>
		<tr>
			<th class="DarkerBlue">Grade</th>
			<td><?= $form->field($model, 'grade')->textInput()->label(false) ?></td>
			<th class="DarkerBlue" rowspan="2" colspan="2">This return must highlight any changes from initial request.</th>
			<th class="DarkerBlue">JCN NO</th>
			<td><?= $form->field($model, 'jcnno')->textInput()->label(false) ?></td>
		</tr>
		<tr>
			<th class="DarkerBlue">Tel</th>
			<td><?= $form->field($model, 'telephoneno')->textInput()->label(false) ?></td>
			<th class="DarkerBlue">W/O No</th>
			<td><?= $form->field($model, 'workorderno')->textInput()->label(false) ?></td>
		</tr>
	</table>
	
    <table class="Table">
    	<tr>
    		<td class="nolb norb">&nbsp;</td>
    		<th class="DarkerBle">Site Details</th>
    	</tr>
    	<tr>
    		<th class="DarkerBlueC">REPAIR NO.</th>
    		<th class="DarkerBlueC">LOCATION</th>
    		<th class="DarkerBlueC" colspan="2">GPS CO-ORDINATES</th>
    		<th class="DarkerBlueC">FROM <br /> MILEAGE</th>
    		<th class="DarkerBlueC">TO <br /> MILEAGE</th>
    		<th class="DarkerBlueC">ELR</th>
    		<th class="DarkerBlueC">TRACK ID</th>
    		<th class="DarkerBlueC">RAIL<BR /> LH/RH</th>
    		<th class="DarkerBlue">&nbsp;</th>
    		<th class="DarkerBlue">&nbsp;</th>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">1</th>
    		<td><?= $form->field($model, 'r1location')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r1long')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r1lat')->textInput()->label(false) ?></td>
		    <td>
		    	<table class="Table">
		    		<tr>
		    			<td><?= $form->field($model, 'r1frommileage1')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r1frommileage2')->dropDownList($milemeters, ['id' => 'm2','prompt' => 'Please Select...']) ->label(false)?></td>
		    			<td><?= $form->field($model, 'r1frommileage3')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r1frommileage4')->dropDownList($yardschain, ['id' => 'm4','prompt' => 'Please Select...']) ->label(false)?></td>
		    		</tr>
		    	</table>
		    </td>
		    <td>
		    	<table class="Table notbb norb nolb">
		    		<tr>
		    			<td><?= $form->field($model, 'r1tomileage1')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r1tomileage2')->textInput()->dropDownList($milemeters, ['id' => 'm2','prompt' => 'Please Select...']) ->label(false)?></td>
		    			<td><?= $form->field($model, 'r1tomileage3')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r1tomileage4')->textInput()->dropDownList($yardschain, ['id' => 'm4','prompt' => 'Please Select...']) ->label(false)?></td>
		    		</tr>
		    	</table>
		    	
		    </td>
		    <td><?= $form->field($model, 'r1elr')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r1trackid')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r1rail')->dropDownList(Attributesvalues::formArray('rail'), ['prompt' => 'Please Select...'])->label(false) ?></td>
    	</tr>
    	<tr>
    		<th class="DarkerBlue">2</th>
    		<td><?= $form->field($model, 'r2location')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r2long')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r2lat')->textInput()->label(false) ?></td>
		    		    <td>
		    	<table class="Table">
		    		<tr>
		    			<td><?= $form->field($model, 'r2frommileage1')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r2frommileage2')->dropDownList($milemeters, ['id' => 'm2','prompt' => 'Please Select...']) ->label(false)?></td>
		    			<td><?= $form->field($model, 'r2frommileage3')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r2frommileage4')->dropDownList($yardschain, ['id' => 'm4','prompt' => 'Please Select...']) ->label(false)?></td>
		    		</tr>
		    	</table>
		    </td>
		    <td>
		    	<table class="Table notbb norb nolb">
		    		<tr>
		    			<td><?= $form->field($model, 'r2tomileage1')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r2tomileage2')->dropDownList($milemeters, ['id' => 'm2','prompt' => 'Please Select...']) ->label(false)?></td> 
		    			<td><?= $form->field($model, 'r2tomileage3')->textInput()->label(false) ?></td>
		    			<td><?= $form->field($model, 'r2tomileage4')->dropDownList($yardschain, ['id' => 'm4','prompt' => 'Please Select...']) ->label(false)?></td>
		    		</tr>
		    	</table>
		    	
		    </td>
		    <td><?= $form->field($model, 'r2elr')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r2trackid')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r2rail')->dropDownList(Attributesvalues::formArray('rail'), ['prompt' => 'Please Select...'])->label(false) ?></td>
    	</tr>
    </table>

    <table>
    	<tr>
    		<td class="nolb notb">&nbsp;</td>
    		<th class="DarkerBlueC" colspan="6">DEFECT DETAILS (FROM FORM TEF/3037)</th>
    		<th class="DarkerBlueC" colspan="5">WELDING DETAILS</th>
    	</tr>
    	<tr>
    		<th class="DarkerBlueC" rowspan="2">REPAIR No.</th>
    		<th class="DarkerBlueC" rowspan="2">DEFECT NO.</th>
    		<th class="DarkerBlueC" rowspan="2">DEFECT TYPE </th>
    		<th class="DarkerBlueC" rowspan="2">MIN  ACTION <br /> CODE 2F etc</th>
    		<th class="DarkerBlueC" rowspan="2">LAST U/S TEST<br />DATE</th>
    		<th class="DarkerBlueC" colspan="2">DEFECT</th>
    		<th class="DarkerBlueC" colspan="3">RAIL</th>
    		<th class="DarkerBlueC" colspan="2">EXCAVATION</th>
    	</tr>
  		<tr>
  			<th class="DarkerBlueC">LENGTH</th>	
  			<th class="DarkerBlueC">DEPTH</th>	
  			<th class="DarkerBlueC">SECTION</th>	
  			<th class="DarkerBlueC">GRADE</th>	
  			<th class="DarkerBlueC">WEAR</th>	
  			<th class="DarkerBlueC">SIZE</th>	
  			<th class="DarkerBlueC">MPI</th>	
  		</tr>
  		<tr>
  			<th class="DarkerBlueC" rowspan="2">1</th>
  	<td><?= $form->field($model, 'r1defectno')->textInput(['onchange' => "$('#stamp1').val('$stampno')"])->label(false) ?></td>
    <td><?= $form->field($model, 'r1defecttype')->textInput()->label(false) ?></td>
    <td><?= $form->field($model, 'r1minaction')->textInput()->label(false) ?></td>
    <td><?= $form->field($model, 'r1lastusdate')->textInput()->widget(\kartik\date\DatePicker::class, ['pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
    <td><?= $form->field($model, 'r1dlength')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
    <td><?= $form->field($model, 'r1ddepth')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
    <td><?= $form->field($model, 'r1section')->textInput()->label(false) ?></td>
    <td><?= $form->field($model, 'r1grade')->dropDownList(Attributesvalues::formArray('dt123grade'), ['prompt' => 'Please Select...'])->label(false) ?></td>
    <td><?= $form->field($model, 'r1wear')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
    <td><?= $form->field($model, 'r1size')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
    <td><?= $form->field($model, 'r1mpi')->dropdownlist(['no' => 'No', 'yes' => 'Yes'], ['prompt' => 'Please Select'])->label(false) ?></td>
    
  		</tr>
	 	<tr>
		  	<td rowspan="2" colspan="6"><?= $form->field($model, 'r1comments')->textArea(['rows' => 3])->label(false) ?></td>
	 		<th class="DarkerBlueC">GAS KIT NO</th>	
	 		<th class="DarkerBlueC">BATCH NO</th>	
	 		<th class="DarkerBlueC">PORTION NO</th>	
	 		<th class="DarkerBlueC">TAP TIME</th>	
	 		<th class="DarkerBlueC">STAMP NO</th>	
	 	</tr> 		
  		<tr>
  			<th class="DarkerBlue" valign="top">Welders Comments</th>
		    <td><?= $form->field($model, 'r1gaskitno')->dropDownList(Attributesvalues::formArray('gaskitno'), ['prompt' => 'Please Select...'])->label(false) ?></td>
		    <td><?= $form->field($model, 'r1batchno')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r1portionno')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r1taptime')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r1stampno')->textInput(['id' => 'stamp1'])->label(false) ?></td>
  		</tr>
  		<tr>
    		<th class="DarkerBlueC" rowspan="2">REPAIR No.</th>
    		<th class="DarkerBlueC" rowspan="2">DEFECT NO.</th>
    		<th class="DarkerBlueC" rowspan="2">DEFECT TYPE </th>
    		<th class="DarkerBlueC" rowspan="2">MIN  ACTION <br /> CODE 2F etc</th>
    		<th class="DarkerBlueC" rowspan="2">LAST U/S TEST<br />DATE</th>
    		<th class="DarkerBlueC" colspan="2">DEFECT</th>
    		<th class="DarkerBlueC" colspan="3">RAIL</th>
    		<th class="DarkerBlueC" colspan="2">EXCAVATION</th>
    	</tr>
  		<tr>
  			<th class="DarkerBlueC">LENGTH</th>	
  			<th class="DarkerBlueC">DEPTH</th>	
  			<th class="DarkerBlueC">SECTION</th>	
  			<th class="DarkerBlueC">GRADE</th>	
  			<th class="DarkerBlueC">WEAR</th>	
  			<th class="DarkerBlueC">SIZE</th>	
  			<th class="DarkerBlueC">MPI</th>	
  		</tr>
      		<tr>
			  	<th class="DarkerBlueC" rowspan="2">2</th>
			  	<td><?= $form->field($model, 'r2defectno')->textInput(['onchange' => "$('#stamp2').val('$stampno')"])->label(false) ?></td>
			    <td><?= $form->field($model, 'r2defecttype')->textInput()->label(false) ?></td>
			    <td><?= $form->field($model, 'r2minaction')->textInput()->label(false) ?></td>
			    <td><?= $form->field($model, 'r2lastusdate')->widget(\kartik\date\DatePicker::class, ['pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
			    <td><?= $form->field($model, 'r2dlength')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
				<td><?= $form->field($model, 'r2ddepth')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
				<td><?= $form->field($model, 'r2section')->textInput()->label(false) ?></td>
			    <td><?= $form->field($model, 'r2grade')->dropDownList(Attributesvalues::formArray('dt123grade'), ['prompt' => 'Please Select...'])->label(false) ?></td>
				<td><?= $form->field($model, 'r2wear')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
			    <td><?= $form->field($model, 'r2size')->widget(\kartik\typeahead\Typeahead::class, ['options' => ['placeholder' => 'Filter as you type ...'],'pluginOptions' => ['highlight' => true],'dataset' => [['local' => $wear, 'limit' => 10 ]]])->label(false) ?></td>
    		    <td><?= $form->field($model, 'r2mpi')->dropdownlist(['no' => 'No', 'yes' => 'Yes'], ['prompt' => 'Please Select'])->label(false) ?></td>
    		</tr>
	 	<tr>
		  	<td rowspan="2" colspan="6"><?= $form->field($model, 'r2comments')->textArea(['rows' => 3])->label(false) ?></td>
	 		<th class="DarkerBlueC">GAS KIT NO</th>	
	 		<th class="DarkerBlueC">BATCH NO</th>	
	 		<th class="DarkerBlueC">PORTION NO</th>	
	 		<th class="DarkerBlueC">TAP TIME</th>	
	 		<th class="DarkerBlueC">STAMP NO</th>	
	 	</tr> 		
  		<tr>
  			<th class="DarkerBlue" valign="top">Welders Comments</th>
		    <td><?= $form->field($model, 'r2gaskitno')->dropDownList(Attributesvalues::formArray('gaskitno'), ['prompt' => 'Please Select...'])->label(false) ?></td>
		    <td><?= $form->field($model, 'r2batchno')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r2portionno')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r2taptime')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'r2stampno')->textInput(['id' => 'stamp2'])->label(false) ?></td>
  		</tr>
    </table>

	<table class="Table">
		<tr>
			<th class="DarkerBlueC" colspan="8">INSPECTION</th>
		</tr>
		<tr>
			<th class="DarkerBlueC">VISUAL</th>
			<th class="DarkerBlueC">DATE INSPECTED</th>
			<th class="DarkerBlueC">INSPECTED BY</th>
			<th class="DarkerBlueC">RESULT <span class="fa fa-plus btn-attributes float-right" data-value="passfail"></span></th>
			<th class="DarkerBlueC">COMMENTS</th>
			<th class="DarkerBlueC">NWD NO</th>
		</tr>
		<tr>
			<td class="DarkerBlueC">1</td>
			<td><?= $form->field($model, 'insv1date')->widget(\kartik\date\DatePicker::class, ['pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
		    <td><?= $form->field($model, 'insv1by')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insv1result')->dropDownList($passfail, ['prompt'=>'Please Select']) ->label(false) ?></td>
		    <td><?= $form->field($model, 'insv1comments')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insv1nwdno')->textInput()->label(false) ?></td>
		</tr>
		<tr>
			<td class="DarkerBlueC">2</td>
			<td><?= $form->field($model, 'insv2date')->widget(\kartik\date\DatePicker::class, ['pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
		    <td><?= $form->field($model, 'insv2by')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insv2result')->dropDownList($passfail, ['prompt'=>'Please Select']) ->label(false) ?></td>
		    <td><?= $form->field($model, 'insv2comments')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insv2nwdno')->textInput()->label(false) ?></td>
		</tr>
		<tr>
			<th class="DarkerBlueC">ULTRASONIC</th>
			<th class="DarkerBlueC">DATE INSPECTED</th>
			<th class="DarkerBlueC">INSPECTED BY</th>
			<th class="DarkerBlueC">TECHNIQUE</th>
			<th class="DarkerBlueC">RESULT <span class="fa fa-plus btn-attributes float-right" data-value="passfail"></span></th>
			<th class="DarkerBlueC">COMMENTS</th>
			<th class="DarkerBlueC">RFD REF</th>
		</tr>
		<tr>
			<td class="DarkerBlueC">1</td>
		    <td><?= $form->field($model, 'insus1date')->widget(\kartik\date\DatePicker::class, ['pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
		    <td><?= $form->field($model, 'insus1by')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insus1teq')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insus1result')->dropDownList($passfail, ['prompt'=>'Please Select']) ->label(false) ?></td>
		    <td><?= $form->field($model, 'insus1comments')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insus1rfdno')->textInput()->label(false) ?></td>
		</tr>
		<tr>
			<td class="DarkerBlueC">2</td>
		    <td><?= $form->field($model, 'insus2date')->widget(\kartik\date\DatePicker::class, ['pluginOptions' => ['showMeridian' =>true, 'convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></td>
		    <td><?= $form->field($model, 'insus2by')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insus2teq')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insus2result')->dropDownList($passfail, ['prompt'=>'Please Select']) ->label(false) ?></td>
		    <td><?= $form->field($model, 'insus2comments')->textInput()->label(false) ?></td>
		    <td><?= $form->field($model, 'insus2rfdno')->textInput()->label(false) ?></td>			
		</tr>
	</table>
	
	<?= $form->field($model, 'jobno')->hiddenInput()->label(false);    ?>

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

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

</div>


<script>
function saveImages() {
	
	$("#signature0").val(document.getElementById('canvas_0').toDataURL());
}
</script>