<?php

namespace modules\forms\models;

use Yii;

use modules\activities\models\Activities;
use modules\custom\models\Accounts;
use modules\users\models\User;
use yii\base\Model;
/**
 * This is the model class For table "dt213".
 *
 * @property string $id
 * @property integer $created_at
 * @property integer $updated_at
 * @property string $created_by
 * @property string $updated_by
 * @property string $deleted_by
 * @property integer $deleted_at
 * @property integer $deleted
 * @property string $actid
 * @property string $client
 * @property string $weldersname
 * @property string $weldersignature
 * @property integer $weekno
 * @property integer $date
 * @property string $padno
 * @property string $from
 * @property string $grade
 * @property string $telephoneno
 * @property string $jcnno
 * @property string $workorderno
 * @property string $r1location
 * @property string $r1long
 * @property string $r1lat
 * @property string $r1frommileage
 * @property string $r1tomileage
 * @property string $r1elr
 * @property string $r1trackid
 * @property string $r1rail
 * @property string $r1defectno
 * @property string $r1defecttype
 * @property string $r1minaction
 * @property string $r1lastusdate
 * @property string $r1dlength
 * @property string $r1ddepth
 * @property string $r1section
 * @property string $r1grade
 * @property string $r1wear
 * @property string $r1size
 * @property string $r1mpi
 * @property string $r1gaskitno
 * @property string $r1batchno
 * @property string $r1portionno
 * @property string $r1taptime
 * @property string $r1stampno
 * @property string $r1comments
 * @property string $r2location
 * @property string $r2long
 * @property string $r2lat
 * @property string $r2frommileage
 * @property string $r2tomileage
 * @property string $r2elr
 * @property string $r2trackid
 * @property string $r2rail
 * @property string $r2defectno
 * @property string $r2defecttype
 * @property string $r2minaction
 * @property string $r2lastusdate
 * @property string $r2dlength
 * @property string $r2ddepth
 * @property string $r2section
 * @property string $r2grade
 * @property string $r2wear
 * @property string $r2size
 * @property string $r2mpi
 * @property string $r2gaskitno
 * @property string $r2batchno
 * @property string $r2portionno
 * @property string $r2taptime
 * @property string $r2stampno
 * @property string $r2comments
 * @property integer $insv1date
 * @property string $insv1by
 * @property string $insv1result
 * @property string $insv1comments
 * @property string $insv1nwdno
 * @property integer $insv2date
 * @property string $insv2by
 * @property string $insv2result
 * @property string $insv2comments
 * @property string $insv2nwdno
 * @property integer $insus1date
 * @property string $insus1by
 * @property string $insus1teq
 * @property string $insus1result
 * @property string $insus1comments
 * @property string $insus1rfdno
 * @property integer $insus2date
 * @property string $insus2by
 * @property string $insus2teq
 * @property string $insus2result
 * @property string $insus2comments
 * @property string $insus2rfdno
 */
class Dt213 extends Model
{

    public $dates = ['created_at', 'updated_at', 'deleted_at', 'date'];
	public $uniqueidentifiers = ['actid', 'clientid','insv1date', 'insv2date', 'insus1date', 'insus2date'];
    public $securefields = [];

    public $id;
    public $created_at;
    public $updated_at;
    public $created_by;
    public $updated_by;
    public $created_by2;
    public $updated_by2;
    public $deleted_by;
    public $deleted_at;
    public $deleted;
    public $actid;
    public $relatedid;
    public $jobno;
    public $client;
    public $weldersname;
    public $weldersignature;
    public $weekno;
    public $date;
    public $padno;
    public $from;
    public $grade;
    public $telephoneno;
    public $jcnno;
    public $workorderno;
    public $r1location;
    public $r1long;
    public $r1lat;
    public $r1frommileage;
    public $r1tomileage;
    public $r1elr;
    public $r1trackid;
    public $r1rail;
    public $r1defectno;
    public $r1defecttype;
    public $r1minaction;
    public $r1lastusdate;
    public $r1dlength;
    public $r1ddepth;
    public $r1section;
    public $r1grade;
    public $r1wear;
    public $r1size;
    public $r1mpi;
    public $r1gaskitno;
    public $r1batchno;
    public $r1portionno;
    public $r1taptime;
    public $r1stampno;
    public $r1comments;
    public $r2location;
    public $r2long;
    public $r2lat;
    public $r2frommileage;
    public $r2tomileage;
    public $r2elr;
    public $r2trackid;
    public $r2rail;
    public $r2defectno;
    public $r2defecttype;
    public $r2minaction;
    public $r2lastusdate;
    public $r2dlength;
    public $r2ddepth;
    public $r2section;
    public $r2grade;
    public $r2wear;
    public $r2size;
    public $r2mpi;
    public $r2gaskitno;
    public $r2batchno;
    public $r2portionno;
    public $r2taptime;
    public $r2stampno;
    public $r2comments;
    public $insv1date;
    public $insv1by;
    public $insv1result;
    public $insv1comments;
    public $insv1nwdno;
    public $insv2date;
    public $insv2by;
    public $insv2result;
    public $insv2comments;
    public $insv2nwdno;
    public $insus1date;
    public $insus1by;
    public $insus1teq;
    public $insus1result;
    public $insus1comments;
    public $insus1rfdno;
    public $insus2date;
    public $insus2by;
    public $insus2teq;
    public $insus2result;
    public $insus2comments;
    public $insus2rfdno;


    public $r1frommileage1;
    public $r2frommileage1;
    public $r1frommileage2;
    public $r2frommileage2;
    public $r1frommileage3;
    public $r2frommileage3;
    public $r1frommileage4;
    public $r2frommileage4;
    public $r1tomileage1;
    public $r2tomileage1;
    public $r1tomileage2;
    public $r2tomileage2;
    public $r1tomileage3;
    public $r2tomileage3;
    public $r1tomileage4;
    public $r2tomileage4;
    public $status;
    public $clientid;
    public $clientint;
    public $clientname;
    


    public $form = 'Dt213';
    public $formname = 'Welders Work Return - Aluminothermic Plain Line Repairs (DT213)';
    public $formType = 'Thermic';

    
    
    public $createpath = '/forms/dt213/create';
    public $formLayout = '/dt213/_form.php';
    public $viewLayout = '@modules/forms/views/dt213/_view.php';
    public $printlayout = 'Landscape';

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'created_by', 'updated_by', 'deleted_by','clientid', 'actid', 'clientname', 'weldersignature', 'padno', 'from', 'grade', 'telephoneno', 'jcnno', 'workorderno', 'r1location', 'r1long', 'r1lat', 'r1frommileage1', 'r1frommileage2', 'r1frommileage3', 'r1frommileage4', 'r1tomileage1', 'r1tomileage2', 'r1tomileage3', 'r1tomileage4', 'r1elr', 'r1trackid', 'r1rail', 'r1defectno', 'r1defecttype', 'r1minaction', 'r1lastusdate', 'r1dlength', 'r1ddepth', 'r1section', 'r1grade', 'r1wear', 'r1size', 'r1mpi', 'r1gaskitno', 'r1batchno', 'r1portionno', 'r1taptime', 'r1stampno', 'r1comments', 'r2location', 'r2long', 'r2lat', 'r2frommileage1', 'r2frommileage2', 'r2frommileage3', 'r2frommileage4', 'r2tomileage1', 'r2tomileage2', 'r2tomileage3', 'r2tomileage4', 'r2elr', 'r2trackid', 'r2rail', 'r2defectno', 'r2defecttype', 'r2minaction', 'r2lastusdate', 'r2dlength', 'r2ddepth', 'r2section', 'r2grade', 'r2wear', 'r2size', 'r2mpi', 'r2gaskitno', 'r2batchno', 'r2portionno', 'r2taptime', 'r2stampno', 'r2comments', 'insv1by', 'insv1result', 'insv1comments', 'insv1nwdno', 'insv2by', 'insv2result', 'insv2comments', 'insv2nwdno', 'insus1by', 'insus1teq', 'insus1result', 'insus1comments', 'insus1rfdno', 'insus2by', 'insus2teq', 'insus2result', 'insus2comments', 'insus2rfdno'], 'string'],
            [['weekno','clientint'], 'integer'],
            [['date','created_at', 'updated_at', 'deleted_at',  'insv1date', 'insv2date', 'insus1date', 'insus2date','weldersname'],'safe'],
            [['deleted' ], 'boolean']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'created_by' => 'Created By',
            'updated_by' => 'Updated By',
            'deleted_by' => 'Deleted By',
            'deleted_at' => 'Deleted At',
            'deleted' => 'Deleted',
            'actid' => 'Actid',
            'clientname' => 'Client Name',
            'weldersname' => 'Weldersname',
            'weldersignature' => 'Weldersignature',
            'weekno' => 'Weekno',
            'date' => 'Date',
            'padno' => 'Padno',
            'from' => 'From',
            'grade' => 'Grade',
            'telephoneno' => 'Telephoneno',
            'jcnno' => 'Jcnno',
            'workorderno' => 'Workorderno',
            'r1location' => 'R1location',
            'r1long' => 'R1long',
            'r1lat' => 'R1lat',
            'r1frommileage' => 'R1frommileage',
            'r1tomileage' => 'R1tomileage',
            'r1elr' => 'R1elr',
            'r1trackid' => 'R1trackid',
            'r1rail' => 'R1rail',
            'r1defectno' => 'R1defectno',
            'r1defecttype' => 'R1defecttype',
            'r1minaction' => 'R1minaction',
            'r1lastusdate' => 'R1lastusdate',
            'r1dlength' => 'R1dlength',
            'r1ddepth' => 'R1ddepth',
            'r1section' => 'R1section',
            'r1grade' => 'R1grade',
            'r1wear' => 'R1wear',
            'r1size' => 'R1size',
            'r1mpi' => 'R1mpi',
            'r1gaskitno' => 'R1gaskitno',
            'r1batchno' => 'R1batchno',
            'r1portionno' => 'R1portionno',
            'r1taptime' => 'R1taptime',
            'r1stampno' => 'R1stampno',
            'r1comments' => 'R1comments',
            'r2location' => 'R2location',
            'r2long' => 'R2long',
            'r2lat' => 'R2lat',
            'r2frommileage' => 'R2frommileage',
            'r2tomileage' => 'R2tomileage',
            'r2elr' => 'R2elr',
            'r2trackid' => 'R2trackid',
            'r2rail' => 'R2rail',
            'r2defectno' => 'R2defectno',
            'r2defecttype' => 'R2defecttype',
            'r2minaction' => 'R2minaction',
            'r2lastusdate' => 'R2lastusdate',
            'r2dlength' => 'R2dlength',
            'r2ddepth' => 'R2ddepth',
            'r2section' => 'R2section',
            'r2grade' => 'R2grade',
            'r2wear' => 'R2wear',
            'r2size' => 'R2size',
            'r2mpi' => 'R2mpi',
            'r2gaskitno' => 'R2gaskitno',
            'r2batchno' => 'R2batchno',
            'r2portionno' => 'R2portionno',
            'r2taptime' => 'R2taptime',
            'r2stampno' => 'R2stampno',
            'r2comments' => 'R2comments',
            'insv1date' => 'Insv1date',
            'insv1by' => 'Insv1by',
            'insv1result' => 'Insv1result',
            'insv1comments' => 'Insv1comments',
            'insv1nwdno' => 'Insv1nwdno',
            'insv2date' => 'Insv2date',
            'insv2by' => 'Insv2by',
            'insv2result' => 'Insv2result',
            'insv2comments' => 'Insv2comments',
            'insv2nwdno' => 'Insv2nwdno',
            'insus1date' => 'Insus1date',
            'insus1by' => 'Insus1by',
            'insus1teq' => 'Insus1teq',
            'insus1result' => 'Insus1result',
            'insus1comments' => 'Insus1comments',
            'insus1rfdno' => 'Insus1rfdno',
            'insus2date' => 'Insus2date',
            'insus2by' => 'Insus2by',
            'insus2teq' => 'Insus2teq',
            'insus2result' => 'Insus2result',
            'insus2comments' => 'Insus2comments',
            'insus2rfdno' => 'Insus2rfdno',
        ];
    }
    /*
    public function attributes(){
        return [
            'id' => 'id',
'created_at' => 'created_at',
'updated_at' => 'updated_at',
'created_by' => 'created_by',
'updated_by' => 'updated_by',
'deleted_by' => 'deleted_by',
'deleted_at' => 'deleted_at',
'deleted' => 'deleted',
'actid' => 'actid',
'client' => 'client',
'weldersname' => 'weldersname',
'weldersignature' => 'weldersignature',
'weekno' => 'weekno',
'date' => 'date',
'padno' => 'padno',
'from' => 'from',
'grade' => 'grade',
'telephoneno' => 'telephoneno',
'jcnno' => 'jcnno',
'workorderno' => 'workorderno',
'r1location' => 'r1location',
'r1long' => 'r1long',
'r1lat' => 'r1lat',
'r1frommileage' => 'r1frommileage',
'r1tomileage' => 'r1tomileage',
'r1elr' => 'r1elr',
'r1trackid' => 'r1trackid',
'r1rail' => 'r1rail',
'r1defectno' => 'r1defectno',
'r1defecttype' => 'r1defecttype',
'r1minaction' => 'r1minaction',
'r1lastusdate' => 'r1lastusdate',
'r1dlength' => 'r1dlength',
'r1ddepth' => 'r1ddepth',
'r1section' => 'r1section',
'r1grade' => 'r1grade',
'r1wear' => 'r1wear',
'r1size' => 'r1size',
'r1mpi' => 'r1mpi',
'r1gaskitno' => 'r1gaskitno',
'r1batchno' => 'r1batchno',
'r1portionno' => 'r1portionno',
'r1taptime' => 'r1taptime',
'r1stampno' => 'r1stampno',
'r1comments' => 'r1comments',
'r2location' => 'r2location',
'r2long' => 'r2long',
'r2lat' => 'r2lat',
'r2frommileage' => 'r2frommileage',
'r2tomileage' => 'r2tomileage',
'r2elr' => 'r2elr',
'r2trackid' => 'r2trackid',
'r2rail' => 'r2rail',
'r2defectno' => 'r2defectno',
'r2defecttype' => 'r2defecttype',
'r2minaction' => 'r2minaction',
'r2lastusdate' => 'r2lastusdate',
'r2dlength' => 'r2dlength',
'r2ddepth' => 'r2ddepth',
'r2section' => 'r2section',
'r2grade' => 'r2grade',
'r2wear' => 'r2wear',
'r2size' => 'r2size',
'r2mpi' => 'r2mpi',
'r2gaskitno' => 'r2gaskitno',
'r2batchno' => 'r2batchno',
'r2portionno' => 'r2portionno',
'r2taptime' => 'r2taptime',
'r2stampno' => 'r2stampno',
'r2comments' => 'r2comments',
'insv1date' => 'insv1date',
'insv1by' => 'insv1by',
'insv1result' => 'insv1result',
'insv1comments' => 'insv1comments',
'insv1nwdno' => 'insv1nwdno',
'insv2date' => 'insv2date',
'insv2by' => 'insv2by',
'insv2result' => 'insv2result',
'insv2comments' => 'insv2comments',
'insv2nwdno' => 'insv2nwdno',
'insus1date' => 'insus1date',
'insus1by' => 'insus1by',
'insus1teq' => 'insus1teq',
'insus1result' => 'insus1result',
'insus1comments' => 'insus1comments',
'insus1rfdno' => 'insus1rfdno',
'insus2date' => 'insus2date',
'insus2by' => 'insus2by',
'insus2teq' => 'insus2teq',
'insus2result' => 'insus2result',
'insus2comments' => 'insus2comments',
'insus2rfdno' => 'insus2rfdno',

        ];
    }
*/


	public function getClientl() {
		return $this->hasOne(Accounts::class , ['id' => $this->clientid]);
	}
	public function getAct() {
		return $this->hasOne(Activities::class , ['id' => $this->actid]);
	}
	public function getActivity() {
		return $this->hasOne(Activities::class , ['id' => $this->actid]);
    }
    
    public function init()
    {
        // Parameters 
        if(Yii::$app->controller->action->id == 'create' && $this->actid !== null ){
           $act = Activities::find()->select(['jobno', 'relatedid', 'location', 'sdate', 'elr', 'weekno'])->where(['id' => $this->actid])->asArray()->one();
           $this->jobno = $act['jobno'];
           $this->jcn = $act['jobno'];
           $this->client = $act['relatedid'];
      //     $this->site = $act['location'];
         //  $this->elr = $act['elr'];
           $this->weekno = $act['weekno'];
           $this->date = date('d/m/Y H:i', strtotime($act['sdate']));
        }
        return parent::init();
    }

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