<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\data\SqlDataProvider;
use yii\data\ActiveDataProvider;

use app\base\Converter;
use app\models\Settings;
use app\models\VVisitstatus;
use app\models\Misreport;

use kartik\mpdf\Pdf;

/**
 * VisitschedulereportController implements the CRUD actions for Clientreport model.
 */
class CohortreimstatusController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['error'],
                        'allow' => true,
                    ],
                    [
                        'actions' => ['index'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }
			
	
		 
    /**
     * Lists all Arvmaster models.
     * @return mixed
     */
    public function actionIndex()
    {
        $model = new Misreport();
        if ($model->load(Yii::$app->request->post()) || $model->load(Yii::$app->request->get())) {
			//$pid=model->pid;
            if(!$model->validate()) {
                return $this->render('index', ['model' => $model]);
            } else {
				if($model->pid != "") 
				 $query = VVisitstatus::find()->where(["participant_id"=> $model->pid])->orderBy(["visit" => SORT_DESC]);
				else
				 $query = VVisitstatus::find()->orderBy(["participant_id" => SORT_ASC,"visit" => SORT_DESC]);
			 
                $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => false, 'pagination' => ['pagesize' => 20]]);                
                return $this->render('index', ['model' => $model, 'dataProvider' => $dataProvider]);
            }
        }
        return $this->render('index', ['model' => $model]);
    }

  
}
