<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use kartik\datetime\DateTimePicker;
use kartik\select2\Select2;
use frontend\models\Users;
use backend\models\Attributesvalues;

$this->registerJsFile('/js/moment.js');
$this->registerJsFile('/js/moment-duration-format.js');
$users = \frontend\models\User::EmployeesU();

$model->welder = is_array(explode(',', $model->welder)) ? explode(',', $model->welder) : $model->welder;
?>


<?php $form = ActiveForm::begin(['options' => ['autocomplete' => 'off']]); ?>

<div>
	Name:     <?=$form->field($model, 'welder')->widget(Select2::class, ['id' => 'welders', 'data' => $users, 'options' => ['placeholder' => 'Select Operatives...', 'multiple' => true],])    ->label(false) ?>
	Start Date:<?= $form->field($model, "sdate")->widget(DateTimePicker::class, ['size' => 'sm', 'id'=>'starttime', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'dd/mm/yyyy hh:ii','autoclose'=>true,]])->label(false) ?>
	Return Date:<?= $form->field($model, "edate")->widget(DateTimePicker::class, ['size' => 'sm', 'id'=>'finishtime', 'pluginOptions' => ['showMeridian' =>false, 'format' => 'dd/mm/yyyy hh:ii','autoclose'=>true,]])->label(false) ?>
	Period Off:<?= $form->field($model, "shiftlength")->textinput(['id' => 'shiftlength', 'onclick' => 'period()'])->Label(false) ?>		
	Reason for Absence:
			<?= $form->field($model, 'jobstatus')->dropdownList(Attributesvalues::formArray('absence_types'), ['id' => 'jobstatus']) ->label(false) ?>
			<?= $form->field($model, 'comments')->hiddenInput(['rows' => 2, 'id' => 'description']) ->label(false) ?>
			<?= $form->field($model, 'details')->textArea(['rows' => 2, 'id' => 'details', 'onchange' => 'periodoff()'])  ->label(false) ?>
	

    <?php ActiveForm::end(); ?>
    <?= Html::submitButton('Save', ['class' => 'btn btn-primary', 'onclick' => 'event1()']) ?>
    	
    </div>

<script>
function event1() {
var company = "Inline Track Welding Ltd";
start = document.getElementById('activities-sdate').value;
finish = document.getElementById('activities-edate').value;
var space = " - ";
var res = company + space + start + space + finish;
document.getElementById("description").value = res;
};

function period()
{
jobstatus = document.getElementById('jobstatus').value;
start = document.getElementById('activities-sdate').value;
finish = document.getElementById('activities-edate').value;
var date1 =  moment(start, 'DD/MM/YYYY hh:mm');
var date2 =  moment(finish, 'DD/MM/YYYY hh:mm');
if (jobstatus == 'Training') {
var diffDays = date2.diff(date1, 'hours');
var shiftl = diffDays;
} else {
	
var diffDays = date2.diff(date1, 'days');
var shiftl = diffDays * 8;
}
//if (shiftl == '32') {shiftl = 40}
document.getElementById('shiftlength').value = shiftl;

	};



</script>