<?php
namespace modules\forms\models;

use Yii;
use \common\models\DynamicModel;
use \kartik\date\DatePicker;
use \yii\helpers\ArrayHelper;


use modules\activities\models\Activities;
use modules\users\models\User;
use modules\custom\models\Accounts;

/**
 * This is the model class For table "dt078".
 *
 * @property string $id
 * @property string $created_by
 * @property string $updated_by
 * @property string $deleted_by
 * @property string $actid
 * @property string $relatedid
 * @property string $name
 * @property string $signednameop
 * @property string $signednamesup
 * @property int $created_at
 * @property int $updated_at
 * @property int $deleted_at
 * @property int $jobno
 * @property int $date
 * @property string $status
 * @property string $padno
 * @property string $natindno
 * @property string $reason
 * @property string $medication
 * @property string $advice
 * @property string $opsigned
 * @property string $supsigned
 * @property int $selfpescribed
 * @property int $pescribed
 * @property int $maywork
 * @property int $accompanied
 * @property int $safety
 * @property int $stooddown
 */
class Dt078 extends \yii\base\Model {
	
    public $dates = ['created_at', 'updated_at', 'deleted_at', 'date', 'startdate', 'finishdate'];
	public $uniqueidentifiers = ['actid', 'relatedid', 'name', 'signednameop', 'signednamesup'];
   	public $securefields = ['natindno'];
    
    public $id;
    public $created_by;
    public $updated_by;
    public $deleted_by;
    public $actid;
    public $relatedid;
    public $name;
    public $signednameop;
    public $signednamesup;
    public $created_at;
    public $updated_at;
    public $deleted_at;
    public $jobno;
    public $date;
    public $status;
    public $padno;
    public $natindno;
    public $reason;
    public $medication;
    public $advice;
    public $opsigned;
    public $supsigned;
    public $selfpescribed;
    public $pescribed;
    public $maywork;
    public $accompanied;
    public $safety;
    public $stooddown;
    public $startdate;
    public $finishdate;
    public $duration;


    public $form = 'Dt078';
    public $formname = 'MEDICATION DECLARATION FORM (DT078)';
    public $createpath = '/forms/dt078/create';
    public $formType = 'Medical';
    public $formLayout = '/dt078/_form.php';
    public $viewLayout = '@modules/forms/views/dt078/_view.php';
    public $printlayout = 'Portrait';

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'created_by', 'updated_by', 'deleted_by', 'actid', 'relatedid', 'name', 'signednameop', 'signednamesup', 'status', 'padno', 'natindno', 'reason', 'medication', 'advice', 'opsigned', 'supsigned','maywork', 'accompanied', 'safety', 'stooddown'], 'string'],
            [[ 'jobno', 'selfpescribed', 'pescribed','duration'], 'integer'],
        	[['created_at', 'updated_at', 'deleted_at',], 'safe'],
            [['date', 'startdate', 'finishdate'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() : array
    {
        return [
            'id' => 'ID',
            'created_by' => 'Created By',
            'updated_by' => 'Updated By',
            'deleted_by' => 'Deleted By',
            'actid' => 'Actid',
            'relatedid' => 'Relatedid',
            'name' => 'Name',
            'signednameop' => 'Signednameop',
            'signednamesup' => 'Signednamesup',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'deleted_at' => 'Deleted At',
            'jobno' => 'Jobno',
            'date' => 'Date',
            'status' => 'Status',
            'padno' => 'Padno',
            'natindno' => 'Natindno',
            'reason' => 'Reason',
            'medication' => 'Medication',
            'advice' => 'Advice',
            'opsigned' => 'Opsigned',
            'supsigned' => 'Supsigned',
            'selfpescribed' => 'Selfpescribed',
            'pescribed' => 'Pescribed',
            'maywork' => 'Maywork',
            'accompanied' => 'Accompanied',
            'safety' => 'Safety',
            'stooddown' => 'Stooddown',
        ];
    }
    
    public function getEmployeen() {
		return User::findOne(['id' => $this->name]);
    }    
    
    public function getOp() {
		return User::findOne(['id' => $this->signednameop]);
    }    
    
    public function getSup() {
		return User::findOne(['id' => $this->signednamesup]);
	}
	    public static function adminFormButtons($buttons, $model){
      $_this = new self();
        $buttons[$_this->formType]['items'][] = [
            'label' => $_this->formname,
            'url' => [$_this->createpath, 'actid' => $model->id],
            'linkOptions' =>  ['target'=>'_blank'],
        ];
        return $buttons;
    }
}
