<?php

namespace app\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%reimbursementmaster}}".
 *
 * @property integer $reimburse_master_id
 * @property string $reimburse_master_survey
 * @property string $reimburse_master_part_id
 * @property string $reimburse_master_visitcode
 * @property string $reimburse_master_visitdate
 * @property integer $reimburse_master_q1
 * @property integer $reimburse_master_q2
 * @property integer $reimburse_master_q3
 * @property string $reimburse_master_q4
 * @property string $status
 * @property integer $create_time
 * @property integer $create_user
 * @property integer $update_time
 * @property integer $update_user
 * @property integer $record_date
 */
class Reimbursementmaster extends \yii\db\ActiveRecord
{
	
	public $paystatus = ['1'=>'Yes','0' => 'No'];
	//public $reimflag;
	
	/**
	 * @inheritdoc
	 */
	public static function tableName()
	{
		return '{{%reimbursementmaster}}';
	}

	/**
	 * @inheritdoc
	 */
	public function behaviors()
	{
		return [
			[
				'class' => TimestampBehavior::className(),
				'createdAtAttribute' => 'create_time',
				'updatedAtAttribute' => 'update_time',
				'value' => date('U'),
			]
		];
	}

	/**
	 * @inheritdoc
	 */
	public function rules()
	{
		return [
			// [['reimburse_master_survey', 'reimburse_master_part_id', 'reimburse_master_visitcode', 'reimburse_master_visitdate', 'reimburse_master_q1', 'reimburse_master_q2', 'reimburse_master_q3', 'reimburse_master_q4', 'record_date'], 'required'],
			[['reimburse_master_survey', 'reimburse_master_part_id','reimburse_master_visitcode'], 'required'],
			[['reimflag'], 'safe'],
			[['reimburse_master_q1', 'reimburse_master_q2', 'reimburse_master_q3','reimflag', 'create_time', 'create_user', 'update_time', 'update_user', 'record_date'], 'integer'],
			[['reimburse_master_survey', 'reimburse_master_part_id', 'reimburse_master_visitcode', 'reimburse_master_visitdate'], 'string', 'max' => 11],
			[['reimburse_master_q4'], 'string', 'max' => 50], 
			[['status'], 'string', 'max' => 1],
			[['reimburse_master_visitdate', 'reimburse_master_q3', 'record_date'], 'default', 'value' => strtotime(date('Y/m/d'))],
		];
	}
	
	public function getVisits($id)
	{
		$Gmodel = \app\models\Visitmaster::find()->where(['NOT', ['visit_interval' => null]])->andWhere(["status" => 1])->andWhere(["visit_code" => $id])->one();
		if($Gmodel !== null) {			
				return $Gmodel->visit_name;
		} else
			return "-";
	}
	
	public function getPayment()
	{		
		return $this->paystatus[$this->reimburse_master_q1];
	}

	/* public function getVisit()
    {
        $query = $this->hasOne(Visitmaster::className(), ['visit_code' => 'reimburse_master_visitcode']);
        return $query;
    }*/
	
	/**
	 * @inheritdoc
	 */
	public function attributeLabels()
	{
		return [
			'reimburse_master_id' => Yii::t('app', 'Reimburse Master ID'),
			'reimburse_master_survey' => Yii::t('app', 'Survey'),
			'reimburse_master_part_id' => Yii::t('app', 'ICC Client ID'),
			'reimburse_master_visitcode' => Yii::t('app', 'Visit Code'),
			'reimburse_master_visitdate' => Yii::t('app', 'Visit Date'),
			'reimburse_master_q1' => Yii::t('app', 'Payment Status'),
			'reimburse_master_q2' => Yii::t('app', 'Amount'),
			'reimburse_master_q3' => Yii::t('app', 'Paid Date'),
			'reimburse_master_q4' => Yii::t('app', 'Voucher Number'),
			'status' => Yii::t('app', 'Status'),
			'create_time' => Yii::t('app', 'Create Time'),
			'create_user' => Yii::t('app', 'Create User'),
			'update_time' => Yii::t('app', 'Update Time'),
			'update_user' => Yii::t('app', 'Update User'),
			'record_date' => Yii::t('app', 'Record Date'),
		];
	}
}
