<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use rmrevin\yii\fontawesome\FA;
use yii\widgets\Pjax;
use yii\helpers\ArrayHelper;
use app\models\Arvmaster;
use app\models\Hivvisit;
use app\base\Converter;

$HModel = new Hivvisit();

/* @var $this yii\web\View */
/* @var $searchModel app\models\HivvisitSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Hivvisits');
$this->params['breadcrumbs'][] = $this->title;
$this->params['menu'] = [
	['label' => FA::icon('plus fa-fw'), 'linkOptions' => ['class'=>'btn btn-default', 'title'=>'Create'], 'url' => ['create']],
];
?>
<div class="hivvisit-index">
    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
	<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
		'formatter' => ['class' => 'yii\i18n\Formatter','nullDisplay' => '-', 'dateFormat' => 'dd-MM-Y','datetimeFormat' => 'dd-MM-Y hh:mm:ss'],
        'options'=>['style' => 'white-space:nowrap;'],
	/*	 'rowOptions' => function ($model) {
        if(Converter::toStore($model->hiv_visit_q3) >= $model->getScrdate()) {
            return ['class' => 'danger'];
        }
    },
	*/
	'columns' => [
            [
            	'class' => 'yii\grid\SerialColumn',
            	'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
            ],

			// 'hiv_visit_id',
			// 'hiv_visit_survey',
			// 'hiv_visit_loc',
			// 'hiv_visit_part_id',
			// 'hiv_visit_q1',
			// 'hiv_visit_q2',
			// 'hiv_visit_q3',
			[
				'attribute' => 'hiv_visit_part_id',
				 'label' => 'Client ID',
				 'contentOptions' => ['style' =>'width:100px;  min-width:100px;'],
				
			],
			/*
			[
				'attribute' => 'scrdate',
				'visible' => isset(Yii::$app->request->queryParams['ajaxload']),
				 'label' => 'Scr.Date',
				 'contentOptions' => ['style' =>'width:90px;  min-width:90px;'],
				 'format' => 'date',
				
			],
			*/										
				[
					'attribute' => 'hiv_visit_q1',
		            'label' => 'Visit',
		            'contentOptions' => ['style' =>'width:120px;  min-width:120px;'],
					// 'contentOptions' => ['class' => 'col-md-1'],
	                'noWrap' => true,
		            'filterType'=>GridView::FILTER_SELECT2,
		            'filter'=>$HModel->q1Dum, 
		            'filterInputOptions'=>['placeholder'=>''],
	                'value' => function($data) {						
	                   return $data->getVisits();
	                }
				],
				
			[
				'attribute' => 'hiv_visit_q3',
				'label' => 'HIV Visit Date',
				'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
				//'format' => 'date',
			    'contentOptions' => ['class' => 'col-md-1'],
							
			],
			
			[
				'attribute' => 'hiv_visit_q3',
				'visible' => isset(Yii::$app->request->queryParams['ajaxload']),
				'label' => 'Visit Date',
				//'format' => 'date',				
				'contentOptions' => ['style' =>'width:80px;  min-width:80px;'],
							
			],
			
			[
				'attribute' => 'hiv_visit_q4',
				'visible' => isset(Yii::$app->request->queryParams['ajaxload']),
				'label' => 'ARV Disp',
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                	$data->hiv_visit_q4 = (string)$data->hiv_visit_q4;
                    return (!empty($data->hiv_visit_q4) || $data->hiv_visit_q4 == '0') ? $data->yes_no[$data->hiv_visit_q4] : '-';
                    // return $data->yes_no[$data->hiv_visit_q4];
                },
	            'filterType'=>GridView::FILTER_SELECT2,
	            'filter'=>$searchModel->yes_no, 
	            'filterInputOptions'=>['placeholder'=>''],
			],
			
			[
				'attribute' => 'hiv_visit_q4',
				'label' => 'ARV Dispensed',
				'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                	$data->hiv_visit_q4 = (string)$data->hiv_visit_q4;
                    return (!empty($data->hiv_visit_q4) || $data->hiv_visit_q4 == '0') ? $data->yes_no[$data->hiv_visit_q4] : '-';
                    // return $data->yes_no[$data->hiv_visit_q4];
                },
	            'filterType'=>GridView::FILTER_SELECT2,
	            'filter'=>$searchModel->yes_no, 
	            'filterInputOptions'=>['placeholder'=>''],
			],
			// [
			// 	'attribute' => 'hiv_visit_q5',
			// 	'label' => 'ARV Changed',
			// 	'contentOptions' => ['class' => 'col-md-1'],
   //              'value' => function($data) {
   //                  return ($data->hiv_visit_q5 != null) ? $data->yes_no[$data->hiv_visit_q5] : "-";
   //              },
	  //           'filterType'=>GridView::FILTER_SELECT2,
	  //           'filter'=>$searchModel->yes_no, 
	  //           'filterInputOptions'=>['placeholder'=>''],
			// ],
			[
				'attribute' => 'hiv_visit_q6a',
				'label' => 'ARV1',
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                    return $data->getARV($data->hiv_visit_q6a);
                },
	            'filterType'=>GridView::FILTER_SELECT2,
	            'filter'=>ArrayHelper::map(Arvmaster::find()->orderBy('arv_mstr_code')->asArray()->all(), 'arv_mstr_code', 'arv_mstr_name'), 
	            'filterInputOptions'=>['placeholder'=>''],
			],
			[
				'attribute' => 'hiv_visit_q6',
				'label' => 'ARV1 Qty',
				'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                    return ($data->hiv_visit_q6 != null) ? $data->hiv_visit_q6 : "-";
                }
			],
			
			[
				'attribute' => 'hiv_visit_q6',
				'label' => 'Qty',
				'visible' => isset(Yii::$app->request->queryParams['ajaxload']),
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                    return ($data->hiv_visit_q6 != null) ? $data->hiv_visit_q6 : "-";
                }
			],
			
			[
				'attribute' => 'hiv_visit_q7a',
				'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
				'label' => 'ARV2',
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                    return $data->getARV($data->hiv_visit_q7a);
                },
	            'filterType'=>GridView::FILTER_SELECT2,
	            'filter'=>ArrayHelper::map(Arvmaster::find()->orderBy('arv_mstr_code')->asArray()->all(), 'arv_mstr_code', 'arv_mstr_name'), 
	            'filterInputOptions'=>['placeholder'=>''],
			],
			[
				'attribute' => 'hiv_visit_q7',
				'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
				'label' => 'ARV2 Qty',
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                    return ($data->hiv_visit_q7 != null) ? $data->hiv_visit_q7 : "-";
                }
			],
			[
				'attribute' => 'hiv_visit_q8a',
				'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
				'label' => 'ARV3',
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                    return $data->getARV($data->hiv_visit_q8a);
                },
	            'filterType'=>GridView::FILTER_SELECT2,
	            'filter'=>ArrayHelper::map(Arvmaster::find()->orderBy('arv_mstr_code')->asArray()->all(), 'arv_mstr_code', 'arv_mstr_name'), 
	            'filterInputOptions'=>['placeholder'=>''],
			],
			[
				'attribute' => 'hiv_visit_q8',
				'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
				'label' => 'ARV3 Qty',
				'contentOptions' => ['class' => 'col-md-1'],
                'value' => function($data) {
                    return ($data->hiv_visit_q8 != null) ? $data->hiv_visit_q8 : "-";
                }
			],
		/*	
			[
				'attribute' => 'incvisit',	
                'visible' => isset(Yii::$app->request->queryParams['ajaxload']),				
				'label' => 'Earned Incentive',				
				'contentOptions' => ['class' => 'col-md-1'],
            ],
		*/
			// 'hiv_visit_q4',
			// 'hiv_visit_q5',
			// 'hiv_visit_q6',
			// 'hiv_visit_q7',
			// 'hiv_visit_q8',
			// 'hiv_visit_q9',
			// 'hiv_visit_q10',
			// 'hiv_visit_q11',
			// 'status',
			// 'create_time:datetime',
			// 'create_user',
			// 'update_time:datetime',
			// 'update_user',
			[
				'attribute' => 'record_date',
				//'format' => 'date',
				'contentOptions' => ['class' => 'col-md-1'],
			],

            [
            	'class' => 'app\behaviours\ActionColumns',
            	'visible' => !isset(Yii::$app->request->queryParams['ajaxload']),
            	'contentOptions' => ['class' => 'nowrap'],
            ],
        ],
    ]); ?>
</div>
