<?php

namespace app\models;

use Yii;
use yii\base\Model;
use app\base\Converter;

/**
 * ContactForm is the model behind the contact form.
 */
class Hivarvreminderreport extends Model
{
    public $fromdate;
	public $todate;
	
   
    /**
     * @return array the validation rules.
     */
    public function rules()
    {
        return [
		  [['fromdate','todate'], 'required'],
		  [['todate'], 'dateValidate'],
		  		  
        ];
    }
	
	
    /**
     * @return array customized attribute labels
     */
    public function attributeLabels()
    {
        return [
            'fromdate' => 'Beginning Date',   
            'todate' => 'End Date', 			
        ];
    }
	
	public function dateValidate($attribute, $params) {
        if($this->fromdate != "" && $this->todate != "") {
            $this->fromdate = Converter::toStore($this->fromdate);
            $this->todate = Converter::toStore($this->todate);
            if($this->todate < $this->fromdate) {
                $this->fromdate = Converter::toDisplay($this->fromdate);
                $this->todate = Converter::toDisplay($this->todate);
                $this->addError($attribute, "End Date cannot be prior to Beginning Date");
            } else {
                $this->fromdate = Converter::toDisplay($this->fromdate);
                $this->todate = Converter::toDisplay($this->todate);
            }
        }
    }
}
