<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use app\base\Converter;
use yii\data\ActiveDataProvider;
use app\models\Hivarvreminderreport;
use yii\data\SqlDataProvider;

/**
 * HivarvreminderreportController implements the CRUD actions for Ostvisitreport model.
 */
class HivarvreminderreportController 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 Hivarvreminderreport();
		
		if ($model->load(Yii::$app->request->post())) {
            if (Yii::$app->request->isAjax) {
                Yii::$app->response->format = Response::FORMAT_JSON;
                return ActiveForm::validate($model);
            }
            
            if(!$model->validate()) {
                return $this->render('index', ['model' => $model]);
            } else {
				
			 			
				//$model->fromdate = Converter::toDisplay($model->fromdate);
               // $model->todate = Converter::toDisplay($model->todate);
			   //date('Y-m-d', strtotime('dd/mm/yyyy'));
			   
				$model->fromdate = date('Y-m-d', strtotime($model->fromdate));	
                $model->todate = date('Y-m-d', strtotime($model->todate));	

 $dataProvider = new SqlDataProvider([
               'sql' => 'SELECT * from v_arv_reminder where NextDueDate BETWEEN '."'".$model->fromdate."'".' AND '."'".$model->todate." '". ' order by hiv_visit_part_id', 
   	   
     'params' => [],
 ]);
 
  // 'sql' => 'SELECT * from v_arv_reminder  order by hiv_visit_part_id ', 
  //'sql' => 'SELECT * from v_arv_reminder where DATE_FORMAT(NextDueDate,"%d-%m-%Y") BETWEEN '."'".$model->fromdate."'".' AND '."'".$model->todate." '". ' order by hiv_visit_part_id', 	
  //'sql' => 'SELECT * from v_arv_reminder where NextDueDate BETWEEN '.$model->fromdate.' AND '.$model->todate.' order by hiv_visit_part_id ', 
       // $dataProvider = new ActiveDataProvider(['query' => $query,'pagination' => ['pagesize' => 10]]); 
	   
	    $model->fromdate = Converter::toDisplay($model->fromdate);
        $model->todate = Converter::toDisplay($model->todate);
		
		 return $this->render('index', ['model' => $model, 'dataProvider' => $dataProvider]);
		
		}
	}  
     return $this->render('index', ['model' => $model]);  
    }
		
      
}
