<?php

use app\base\Common;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\data\SqlDataProvider;

use kartik\grid\GridView;
use kartik\widgets\DatePicker;
use rmrevin\yii\fontawesome\FA;

$Surveys = Common::getSurvey();
$Locations = Common::getLocations();
$PIDs = Common::getIncARTRefEarnedPIDs();
if(Yii::$app->params['SURVEY'] != '') {
    $Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
}
if(Yii::$app->params['SURVEY'] != '' && Yii::$app->params['LOCATION'] != '') {
    $Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
    $PIDs = Common::getIncARTRefEarnedPIDs(Yii::$app->params['SURVEY'], Yii::$app->params['LOCATION']);
}

$this->title = 'Incentive Report';
$this->params['breadcrumbs'][] = $this->title;
?>


<div class="attandance-form">
    <h1><?= Html::encode($this->title) ?></h1>
    <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(['enableAjaxValidation' => true, 'options' => ['class' => 'form-horizontal']]);
						$form = ActiveForm::begin(['enableAjaxValidation' => false, 'action' => ['index'], 'method' => 'get', '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>',
                        ];
                    ?>
                    <?= $form->field($model, 'pid', $template)->widget(Select2::classname(), ['data' => $PIDs, 'options' => ['prompt' => $model->getAttributeLabel("pid")]]); ?>
                    <div class="form-group">
                        <div class="col-sm-offset-5 col-sm-7">
                            <?= Html::submitButton(Yii::t('app', 'Go'), ['class' =>'btn btn-success']) ?>
                        </div>
                    </div>
					<?php ActiveForm::end(); ?>
                    <?php if(isset($dataProvider)) : ?>
                        <?= GridView::widget([
                            'dataProvider' => $dataProvider,                            
							'formatter' => ['class' => 'yii\i18n\Formatter','nullDisplay' => '-', 'dateFormat' => 'dd-MM-Y','datetimeFormat' => 'dd-MM-Y hh:mm:ss'], 
                            'options'=>['style' => 'white-space:nowrap;'],                         
                            'panel' => ['type' => GridView::TYPE_PRIMARY,'heading' => "<b> </b>",'afterOptions'=>['class'=>'grid_panel_remove']], 
                            'beforeHeader'=>[
                                [
                                    'columns'=>[
                                        ['content'=>'', 'options'=>['class'=>'col-md-2']],
                                       // ['content'=>'<h4>Overall</h4>', 'options'=>['colspan'=>3, 'class'=>'text-center col-md-4']],
                                       // ['content'=>'<h4>Today</h4>', 'options'=>['colspan'=>3, 'class'=>'text-center col-md-4']],
                                    ],
                                ]
                            ],
							'summary' => '',
                            'columns' => [
                                [
                                    'attribute' => 'type',
                                    'label' => '',
                                    'format' => 'raw',					
                                    'format' => 'raw',				
									
                                    'value' => function($data) {                                      
                                        $ajaxdata[$data['pidcol']] = $data['pid'];
                                        
								    $data["type"]=='Motivational'? $ajaxdata['hiv_counseling_part_id'] = $data['pid'] :  $ajaxdata['hiv_visit_part_id'] = $data['pid'];
										
								    if($data['allearned'] != ''  && $data["type"] == 'ART Refills')
									  return $data["type"].'<a href="#" link="'.Url::toRoute(['/hivvisit/indexmpr', 'ajaxload' => true,  'HivvisitmprSearch' => $ajaxdata]).'" header="List" data-link="'.Url::toRoute(['/hivvisit/indexmpr', 'ajaxload' => true,  'HivvisitmprSearch' => $ajaxdata]).'" data-toggle="modal" data-target="#modal-popup">'.FA::icon('info-circle').'</a>';	  
                                    else
                                      return "";
                                    }
                                ],                                           							
                               
                            ],
                        ]); ?>
                    <?php endif; ?>
                    
                </div>
                <!-- /.col-lg-6 (nested) -->
            </div>
            <!-- /.row (nested) -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>