<?php

use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\data\SqlDataProvider;

use app\base\Common;
use kartik\grid\GridView;
use kartik\select2\Select2;
use kartik\widgets\DatePicker;
use rmrevin\yii\fontawesome\FA;

$this->title = Yii::t('app', Common::getMenuname());
$this->params['breadcrumbs'][] = $this->title;
$PIDs = Common::getIncEarnedPIDs();
?>


<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'], 
							'options'=>['style' => 'white-space:nowrap;'],                         
							'panel' => ['type' => GridView::TYPE_PRIMARY,'footer'=>false],
							
                                'columns' => [
                                ['class' => 'yii\grid\SerialColumn'],
                               
                                
                               
			'pid',
			'visitdate:date' ,			
			'amount',
			'paiddate:date' ,
			'voucherno' ,
			'inctype' ,	
                               
                                [
                                    'class' => 'app\behaviours\ActionColumns',
                                    'visible' => (!isset(Yii::$app->request->queryParams['ajaxload']) && !isset(Yii::$app->request->queryParams['ajaxlist'])),
                                    'template' => '<div class="nowrap">{pdf}</div>',
                                    'buttons' => [
                                        'pdf' => function($url, $model, $key) {     // render your custom button
                                            $options = array_merge([
                                                'title' => Yii::t('yii', 'PDF'),
                                                'target' => '_blank',
                                                'aria-label' => Yii::t('yii', 'PDF'),
                                                'data-pjax' => '0',
                                            ]);
                                            $url = Url::toRoute(['pdf', 'pid' => $model->pid]);
                                            return Html::a('<span class="glyphicon glyphicon-download-alt"></span>', $url, $options);
                                        }
                                    ]
                                ],
                            ],
                        ]); ?>
                    <?php endif; ?>
                    
                </div>
                <!-- /.col-lg-6 (nested) -->
            </div>
            <!-- /.row (nested) -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>