<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\models\Licensechecksbe */
/* @var $form yii\widgets\ActiveForm */
$status = ['Complete' => 'Complete', 'Active' => 'Active', 'Awaiting key' => 'Awaiting Key'];
?>
<script>
$(function() {
	
	$('#employee').on('change', function(e) {
		id = $('#employee').val()
		$.ajax({
			
			type:'post',
			url:'/NGauge/user/getlicense',
			data:{id:id},
		})
		.done(function(result) {
			result = JSON.parse(result);
			$('#cpoints').val(result.points);
			$('#licenseid').val(result.licenseid);
			
		})
	});
})
</script>
<div class="licensechecksbe-form">
	<?php $form = ActiveForm::begin(); ?>
		<div class="card card-default">
			<div class="card card-header data-label">License Check</div>
			<div class="card card-body">
				<?php if ($model->status == 'Active') {?>
					<div class="row">
						<div class="col-sm-12 h4">Please go to the Following Link <?= HTML::A('Read a Key', 'https://www.viewdrivingrecord.service.gov.uk/driving-record/validate', ['target' => '_blank']) ?> and the last 8 characters of the license and the Key below.</div>
					</div>
				<?php } ?>
			<div class="row">
				<div class='col-12 col-md-4 col-lg-2 data-label'>Employee</div>
				<div class='col-12 col-md-8 col-lg-4'><?= $form->field($model, 'employee')->dropdownlist($employees, ['id'=>'employee', 'prompt' => 'Please Select'])->label(false)  ?></div>
				<div class='col-12 col-md-4 col-lg-2 data-label'>Date</div>
				<div class='col-12 col-md-8 col-lg-4'><?= $form->field($model, 'date')->widget(\kartik\date\DatePicker::class, ['size' => 'sm', 'pluginOptions' => ['convertFormat' => true, 'format' => 'dd/mm/yyyy']])->label(false) ?></div>
			</div>
			<div class="row">
				<div class='col-12 col-md-4 col-lg-2 data-label'>Current Points</div>
				<div class='col-12 col-md-8 col-lg-4'><?= $form->field($model, 'currentpoints')->textInput(['id' => 'cpoints'])->label(false) ?></div>
				<div class='col-12 col-md-4 col-lg-2 data-label'>License No</div>
				<div class='col-12 col-md-8 col-lg-4 pb-4'><?= $model->employeel ? substr($model->employeel->drivinglicense->licensenumber, -8) : null ?></div>
				<div class='col-12 col-md-4 col-lg-2 data-label'>Shared Key</div>
				<div class='col-12 col-md-8 col-lg-4'><?= $form->field($model, 'sharedkey')->textInput()->label(false) ?></div>
			</div>
			<div class="row">
				<div class='col-6 col-lg-2 data-label'>Changes Needed</div>
				<div class='col-6 col-lg-4 d-flex justify-content-end'><?= $form->field($model, 'amendmentsneeded')->checkbox(['label' => false])->label(false) ?></div>
				<div class='col-12 col-md-4 col-lg-2 data-label'>Details</div>
				<div class='col-12 col-md-8 col-lg-4'><?= $form->field($model, 'details')->textArea()->label(false) ?></div>
			</div>
			<div class="row">
				<div class='col-12 col-lg-2 data-label'>Comments</div>
				<div class='col-12 col-lg-10'><?= $form->field($model, 'comments')->textarea()->label(false) ?></div>
			</div>
			<div class="row">
				<div class='col-12 col-md-4 col-lg-2 data-label'>Status</div>
				<div class='col-12 col-md-8 col-lg-4'><?= $form->field($model, 'status')->dropdownlist($status, ['prompt' => 'Please Select'])->label(false) ?></div>
			</div>
		</div>
	</div>
	<?= $form->field($model, 'relatedid')->HiddenInput(['id' => 'licenseid'])->label(false) ?>
		<div class="form-group">
			<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
		</div>
	<?php ActiveForm::end(); ?>
</div>
