<?php

namespace modules\forms\models;

use Yii;
use Yii\base\Model;
use modules\activities\models\Activities;
use modules\users\models\User;
use modules\custom\models\Accounts;


/**
 * This is the model class For table "dt131".
 *
 * @property string $id
 * @property string $actid
 * @property string $ref
 * @property string $contract
 * @property string $name
 * @property string $dob
 * @property string $jobtitle
 * @property string $ninumber
 * @property string $homeaddress1
 * @property string $homeaddress2
 * @property string $hometown
 * @property string $homecounty
 * @property string $homepostcode
 * @property string $hometel
 * @property string $employer
 * @property string $employeraddress1
 * @property string $employeraddress2
 * @property string $employertown
 * @property string $employercounty
 * @property string $employerpostcode
 * @property string $employerphoneno
 * @property string $employersign
 * @property string $employersigndate
 * @property string $details
 * @property string $detailsdate
 * @property string $detailstime
 * @property string $detailslocation
 * @property integer $detailsnwraili
 * @property string $detailselr
 * @property string $detailsmileage
 * @property string $about
 * @property integer $ppeworn
 * @property string $ppedetails
 * @property string $firstaidername
 * @property string $firstaidgiven
 * @property integer $attendedhospital
 * @property string $hospitalname
 * @property string $lostmandays
 * @property string $witnesses
 * @property string $actiontaken
 * @property integer $confirmedlineman
 * @property string $linemanname
 * @property string $linemantitle
 * @property string $linemansign
 * @property string $linemansigndate
 * @property integer $riddor95
 * @property string $riddor95initial
 * @property string $findings
 * @property string $conclusions
 * @property string $inmmediatecauses
 * @property string $underlyingcauses
 * @property string $remedialaction
 * @property string $recommendations
 * @property string $supervisorsigned
 * @property string $hseqmansign
 * @property string $superprint
 * @property string $hseqprint
 * @property string $linemandate
 * @property string $hseqdate
 * @property integer $created_at
 * @property integer $created_by
 * @property integer $updated_at
 * @property integer $updated_by
 */
class Dt131 extends Model {

    public $id;
public $actid;
public $ref;
public $contract;
public $name;
public $dob;
public $jobtitle;
public $ninumber;
public $homeaddress1;
public $homeaddress2;
public $hometown;
public $homecounty;
public $homepostcode;
public $hometel;
public $employer;
public $employeraddress1;
public $employeraddress2;
public $employertown;
public $employercounty;
public $employerpostcode;
public $employerphoneno;
public $employersign;
public $employersigndate;
public $details;
public $detailsdate;
public $detailstime;
public $detailslocation;
public $detailsnwraili;
public $detailselr;
public $detailsmileage;
public $about;
public $ppeworn;
public $ppedetails;
public $firstaidername;
public $firstaidgiven;
public $attendedhospital;
public $hospitalname;
public $lostmandays;
public $witnesses;
public $actiontaken;
public $confirmedlineman;
public $linemanname;
public $linemantitle;
public $linemansign;
public $linemansigndate;
public $riddor95;
public $riddor95initial;
public $findings;
public $conclusions;
public $inmmediatecauses;
public $underlyingcauses;
public $remedialaction;
public $recommendations;
public $supervisorsigned;
public $hseqmansign;
public $superprint;
public $hseqprint;
public $linemandate;
public $hseqdate;
public $created_at;
public $created_by;
public $updated_at;
public $updated_by;
public $deleted_at;
public $deleted_by;
public $relatedid;
public $status;

public $padno;
public $jobno;
public $deleted;
public $created_by2;
public $updated_by2;

public $printlayout = 'Portrait';
public $form = 'DT131';
public $formname = 'Accident Report Form (DT131)';

    
    public $createpath = '/forms/dt131/create';
    public $formType = 'Accidents';
    public $formLayout = '/dt131/_form.php';
    public $viewLayout = '@modules/forms/views/dt131/_view.php';
    public $dates = ['created_at', 'updated_at', 'deleted_at'];
	public $uniqueidentifiers = ['actid'];
    public $securefields = [];
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'dt131';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['ref', 'contract', 'name', 'dob', 'jobtitle', 'ninumber', 'homeaddress1', 'homeaddress2', 'hometown', 'homecounty', 'homepostcode', 'hometel', 'employer', 'employeraddress1', 'employeraddress2', 'employertown', 'employercounty', 'employerpostcode', 'employerphoneno', 'employersign', 'details', 'detailstime', 'detailslocation', 'detailselr', 'detailsmileage', 'about', 'ppedetails', 'firstaidername', 'firstaidgiven', 'hospitalname', 'lostmandays', 'witnesses', 'actiontaken', 'linemanname', 'linemantitle', 'linemansign', 'riddor95initial', 'findings', 'conclusions', 'inmmediatecauses', 'underlyingcauses', 'remedialaction', 'recommendations', 'supervisorsigned', 'hseqmansign', 'superprint', 'hseqprint'], 'string'],
            [['actid','employersigndate', 'detailsdate', 'linemansigndate', 'linemandate', 'hseqdate'], 'safe'],
            [['detailsnwraili', 'ppeworn', 'attendedhospital', 'confirmedlineman', 'riddor95'], 'integer'],	
			//Defaults
			[['deleted'], 'boolean'],
			[['created_at', 'updated_at', 'deleted_at'], 'safe'],
			[['created_by', 'updated_by', 'id'],'safe'],
			//Redundant
			[['created_by2', 'updated_by2'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'actid' => 'Actid',
            'ref' => 'Ref',
            'contract' => 'Contract',
            'name' => 'Name',
            'dob' => 'Dob',
            'jobtitle' => 'Jobtitle',
            'ninumber' => 'Ninumber',
            'homeaddress1' => 'Homeaddress1',
            'homeaddress2' => 'Homeaddress2',
            'hometown' => 'Hometown',
            'homecounty' => 'Homecounty',
            'homepostcode' => 'Homepostcode',
            'hometel' => 'Hometel',
            'employer' => 'Employer',
            'employeraddress1' => 'Employeraddress1',
            'employeraddress2' => 'Employeraddress2',
            'employertown' => 'Employertown',
            'employercounty' => 'Employercounty',
            'employerpostcode' => 'Employerpostcode',
            'employerphoneno' => 'Employerphoneno',
            'employersign' => 'Employersign',
            'employersigndate' => 'Employersigndate',
            'details' => 'Details',
            'detailsdate' => 'Detailsdate',
            'detailstime' => 'Detailstime',
            'detailslocation' => 'Detailslocation',
            'detailsnwraili' => 'Detailsnwraili',
            'detailselr' => 'Detailselr',
            'detailsmileage' => 'Detailsmileage',
            'about' => 'About',
            'ppeworn' => 'Ppeworn',
            'ppedetails' => 'Ppedetails',
            'firstaidername' => 'Firstaidername',
            'firstaidgiven' => 'Firstaidgiven',
            'attendedhospital' => 'Attendedhospital',
            'hospitalname' => 'Hospitalname',
            'lostmandays' => 'Lostmandays',
            'witnesses' => 'Witnesses',
            'actiontaken' => 'Actiontaken',
            'confirmedlineman' => 'Confirmedlineman',
            'linemanname' => 'Linemanname',
            'linemantitle' => 'Linemantitle',
            'linemansign' => 'Linemansign',
            'linemansigndate' => 'Linemansigndate',
            'riddor95' => 'Riddor95',
            'riddor95initial' => 'Riddor95initial',
            'findings' => 'Findings',
            'conclusions' => 'Conclusions',
            'inmmediatecauses' => 'Inmmediatecauses',
            'underlyingcauses' => 'Underlyingcauses',
            'remedialaction' => 'Remedialaction',
            'recommendations' => 'Recommendations',
            'supervisorsigned' => 'Supervisorsigned',
            'hseqmansign' => 'Hseqmansign',
            'superprint' => 'Superprint',
            'hseqprint' => 'Hseqprint',
            'linemandate' => 'Linemandate',
            'hseqdate' => 'Hseqdate',
            'created_at' => 'Created At',
            'created_by' => 'Created By',
            'updated_at' => 'Updated At',
            'updated_by' => 'Updated By',
        ];
    }
       
    public function getActivity()
    {
		return Activities::findOne(['id' => $this->actid]);
	}
	public function getAccount()
	{
		return Accounts::findOne(['accountid' => $this->company])
		    ->joinwith('activity');
	} 
    public function getUser()
    {
        return User::findOne(['id' => $this->created_by]);
    }
    public function beforeValidate(){
        $this->padno = $this->padno == null ? User::Padno() : $this->padno;
        return parent::beforeValidate();
    }

        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;
    }
}
