<?php

use app\base\Common;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use app\models\Artincenmaster;
use rmrevin\yii\fontawesome\FA;

/* @var $this yii\web\View */
/* @var $model app\models\Artincenmaster */
/* @var $form yii\widgets\ActiveForm */

$this->title = Yii::t('app', 'Create {modelClass} ', [
    'modelClass' => 'Artincenmaster',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Artincenmaster'), 'url' => ['index']];
$this->params['breadcrumbs'][] = Yii::t('app', 'Create');
$this->params['menu'] = [
	['label' => FA::icon('align-justify fa-fw'), 'linkOptions' => ['class'=>'btn btn-default', 'title'=>'List'], 'url' => ['/'.Yii::$app->controller->id]],
];

$Surveys = Common::getSurvey();
//$PIDs = ArrayHelper::map(Artincenmaster::find()->where(["art_inc_q1" => 0])->orderBy(["art_inc_part_id" => SORT_ASC])->all(), 'art_inc_part_id', 'art_inc_part_id');
$PIDs = Common::getArtrefillPIDs();
$JS = "
	$('.datepicker').datepicker({autoclose: true, startDate: '01-01-1900', endDate: '0', format: '".strtolower(Yii::$app->formatter->dateFormat)."'});
	
	$('#artincenmaster-art_inc_part_id').on('select2:unselect', function (evt) {
		$('#pid_list').html('');
		$('#pid_list').addClass('hidden');
		$('button[type=submit]').prop('disabled', false);
	});

	$('#artincenmaster-art_inc_part_id').on('select2:select', function (evt) {
		$('button[type=submit]').prop('disabled', true);
		var pid = $(this)[0].value;
		if(pid != '') {
		if(confirm('Have you checked nurse and all other entries prior to generating the incentives?   If Yes, Please click OK button and proceed')){
			if(confirm('Hope you know by hitting OK button, you are now assuring all entries have been checked and there is no error.  If Yes, Please click OK button and proceed')){
			
			var link = '".Url::toRoute(['indexpay', 'ajaxload' => true, 'ArtincenmasterpaySearch' => ['art_inc_q1' => 0, 'art_inc_part_id' => '']])."' + pid;
			$('#pid_list').removeClass('hidden');
			$('#pid_list').html('');
			$('#pid_list').load(link);
			// $.ajax({
			// 	type: 'post',
			// 	url: 'index',
			// 	data: 'art_inc_part_id='+pid,
			// 	success: function(result) {
			// 		// console.log(result)
			// 		if(result != 1)
			// 			$('button[type=submit]').prop('disabled', true);
			// 		else
			// 			$('button[type=submit]').prop('disabled', false);
			// 	}
			// });
		}
		$('button[type=submit]').prop('disabled', false);
		}
		else {
			alert('Please check and get back');
			$('button[type=submit]').prop('disabled', true);
		}
		}
		
	});

	$('button[type=submit]').click(function() {
    	val = '';
		$('#artincenmaster-art_inc_id').val(val);
    	$('input[type=checkbox].checkbox-row').each(function(){
    		if($(this).is(':checked')) {
    			val += $(this).val() + ',';
    			$('#artincenmaster-art_inc_id').val(val);
    		}
    	});
	});
";
$this->registerJs($JS);
?>
<div class="artincenmaster-form">
	<div class="panel panel-default">
		<div class="panel-heading">
			
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-lg-12">
					<?php
						$form = ActiveForm::begin(['options' => ['class' => 'form-horizontal']]);
						$template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div>',
						];
						$htemplate = [
							'options' => ['tag' => false],
							'template' => '{input}'
						];
					?>
					<?php // $form->errorSummary($model); ?>
					<?= $form->field($model, 'art_inc_id', $htemplate)->hiddenInput()->label("") ?>
					<?= $form->field($model, 'art_inc_survey', $template)->dropDownList($Surveys) ?>
					<?= $form->field($model, 'art_inc_part_id', $template)->widget(Select2::classname(), ['data' => $PIDs, 'options' => ['prompt' => $model->getAttributeLabel("art_inc_part_id")]])->hint("<strong>Please Bar Code Scan the ICC Client ID</strong>"); ?>
					<div id="pid_list" class="row-fluid popup"></div>
					<div class="form-group">
						<div class="col-sm-offset-5 col-sm-7">
							<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
							<?= Html::a('Cancel', ['/'.Yii::$app->controller->id], ['class' => 'btn btn-default']) ?>
						</div>
					</div>
					<?php ActiveForm::end(); ?>
				</div>
				<!-- /.col-lg-6 (nested) -->
			</div>
			<!-- /.row (nested) -->
		</div>
		<!-- /.panel-body -->
	</div>
	<!-- /.panel -->
</div>