<?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 "dt205".
 *
 * @property string $id
 * @property integer $created_at
 * @property integer $updated_at
 * @property string $created_by
 * @property string $updated_by
 * @property string $actid
 * @property string $client
 * @property string $location
 * @property string $elr
 * @property string $line
 * @property string $startmileagem
 * @property string $startmileagey
 * @property string $finishmileagem
 * @property string $finishmileaged
 * @property string $plainline
 * @property string $sc
 * @property integer $inspectionvisual
 * @property integer $inspectionut
 * @property integer $inspectionema
 * @property string $gaugeattoebefore
 * @property string $gaugeattoeafter
 * @property string $sidewearreadinglh
 * @property string $sidewearreadingrh
 * @property string $railsectionlh
 * @property string $railsectionrh
 * @property integer $tgp8tested
 * @property string $raildepthlh
 * @property string $raildepthrh
 * @property string $railsteellh
 * @property string $railsteelrh
 * @property string $siteaaccess
 * @property string $prepwork
 * @property string $specialreqs
 * @property string $protectiondets
 * @property string $possessiontimerequired
 * @property string $grindingspec
 * @property integer $numberofgangs
 * @property integer $strequired
 * @property string $grindingsupervisorname
 * @property string $grindingsupervisorsign
 * @property integer $grindingsupervisorsigndate
 * @property integer $pointsnofacing
 * @property integer $pointsnotrailing
 * @property string $lhswitchblade0
 * @property string $lhstockrail0
 * @property string $lhthroughrail0
 * @property string $lhbellyrail0
 * @property string $rhswitchblade0
 * @property string $rhstockrail0
 * @property string $rhthroughrail0
 * @property string $rhbellyrail0
 * @property string $comments0
 * @property string $image0
 * @property integer $workcompleted0
 * @property integer $so53compliant0
 * @property integer $dpitested0
 * @property integer $mpitested0
 * @property integer $switchlubricated0
 * @property integer $switchoperational0
 * @property integer $uttested0
 * @property integer $tgp8tested0
 * @property string $pwaycomments0
 * @property string $gsmname
 * @property string $gsmsign
 * @property integer $gsmdate
 * @property string $gsmcomments
 * @property string $fplname
 * @property string $fplsign
 * @property integer $fpldate
 * @property string $ins053name
 * @property string $ins053sign
 * @property integer $ins053date
 * @property string $signature
 * @property integer $signaturedate
 * @property string $cglhsbbefore
 * @property string $cglhsbafter
 * @property string $cglhsblength
 * @property integer $cglhsbmpi
 * @property string $cglhsrbefore
 * @property string $cglhsrafter
 * @property string $cglhsrlength
 * @property integer $cglhsrmpi
 * @property string $cglhtrbefore
 * @property string $cglhtrafter
 * @property string $cglhtrlength
 * @property integer $cglhtrmpi
 * @property string $cglhbrbefore
 * @property string $cglhbrafter
 * @property string $cglhbrlength
 * @property integer $cglhbrmpi
 * @property string $cgrhsbbefore
 * @property string $cgrhsbafter
 * @property string $cgrhsblength
 * @property integer $cgrhsbmpi
 * @property string $cgrhsrbefore
 * @property string $cgrhsrafter
 * @property string $cgrhsrlength
 * @property integer $cgrhsrmpi
 * @property string $cgrhtrbefore
 * @property string $cgrhtrafter
 * @property string $cgrhtrlength
 * @property integer $cgrhtrmpi
 * @property string $cgrhbrbefore
 * @property string $cgrhbrafter
 * @property string $cgrhbrlength
 * @property integer $cgrhbrmpi
 * @property string $cgcomments
 */
class Dt205 extends Model {

    public $dates = ['created_at', 'updated_at', 'deleted_at'];
	public $uniqueidentifiers = ['actid'];
    public $securefields = [];
    public $id;
    public $created_at;
    public $updated_at;
    public $created_by;
    public $updated_by;
    public $actid;
    public $client;
    public $location;
    public $elr;
    public $line;
    public $startmileagem;
    public $startmileagey;
    public $finishmileagem;
    public $finishmileaged;
    public $plainline;
    public $sc;
    public $inspectionvisual;
    public $inspectionut;
    public $inspectionema;
    public $gaugeattoebefore;
    public $gaugeattoeafter;
    public $sidewearreadinglh;
    public $sidewearreadingrh;
    public $railsectionlh;
    public $railsectionrh;
    public $tgp8tested;
    public $raildepthlh;
    public $raildepthrh;
    public $railsteellh;
    public $railsteelrh;
    public $siteaaccess;
    public $prepwork;
    public $specialreqs;
    public $protectiondets;
    public $possessiontimerequired;
    public $grindingspec;
    public $numberofgangs;
    public $strequired;
    public $grindingsupervisorname;
    public $grindingsupervisorsign;
    public $grindingsupervisorsigndate;
    public $pointsnofacing;
    public $pointsnotrailing;
    public $lhswitchblade0;
    public $lhstockrail0;
    public $lhthroughrail0;
    public $lhbellyrail0;
    public $rhswitchblade0;
    public $rhstockrail0;
    public $rhthroughrail0;
    public $rhbellyrail0;
    public $comments0;
    public $image0;
    public $workcompleted0;
    public $so53compliant0;
    public $dpitested0;
    public $mpitested0;
    public $switchlubricated0;
    public $switchoperational0;
    public $uttested0;
    public $tgp8tested0;
    public $pwaycomments0;
    public $gsmname;
    public $gsmsign;
    public $gsmdate;
    public $gsmcomments;
    public $fplname;
    public $fplsign;
    public $fpldate;
    public $ins053name;
    public $ins053sign;
    public $ins053date;
    public $signature;
    public $signaturedate;
    public $cglhsbbefore;
    public $cglhsbafter;
    public $cglhsblength;
    public $cglhsbmpi;
    public $cglhsrbefore;
    public $cglhsrafter;
    public $cglhsrlength;
    public $cglhsrmpi;
    public $cglhtrbefore;
    public $cglhtrafter;
    public $cglhtrlength;
    public $cglhtrmpi;
    public $cglhbrbefore;
    public $cglhbrafter;
    public $cglhbrlength;
    public $cglhbrmpi;
    public $cgrhsbbefore;
    public $cgrhsbafter;
    public $cgrhsblength;
    public $cgrhsbmpi;
    public $cgrhsrbefore;
    public $cgrhsrafter;
    public $cgrhsrlength;
    public $cgrhsrmpi;
    public $cgrhtrbefore;
    public $cgrhtrafter;
    public $cgrhtrlength;
    public $cgrhtrmpi;
    public $cgrhbrbefore;
    public $cgrhbrafter;
    public $cgrhbrlength;
    public $cgrhbrmpi;
    public $cgcomments;
    public $pointsno;
    public $fplinscompleted;
    public $ins053completed;
    public $image1;
    public $lhswitchblade1;
    public $lhstockrail1;
    public $lhthroughrail1;
    public $lhbellyrail1;
    public $rhswitchblade1;
    public $rhstockrail1;
    public $rhthroughrail1;
    public $rhbellyrail1;
    public $comments1;
    
    public $direction;
    public $deleted_by;
    public $deleted_at;
    public $relatedid;
    public $deleted;
    public $jobno;
    public $padno;
    public $status;

    public $form = 'Dt205';
    public $formname = 'Hand Grinding Form (DT205)';
    public $formType = 'Grinding';

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

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['location', 'elr', 'line', 'startmileagem', 'startmileagey', 'finishmileagem', 'finishmileaged', 'plainline', 'sc', 'gaugeattoebefore', 'gaugeattoeafter', 'sidewearreadinglh', 'sidewearreadingrh', 'railsectionlh', 'railsectionrh', 'raildepthlh', 'raildepthrh', 'railsteellh', 'railsteelrh', 'siteaaccess', 'prepwork', 'specialreqs', 'protectiondets', 'possessiontimerequired', 'grindingspec', 'grindingsupervisorname', 'grindingsupervisorsign', 'lhswitchblade0', 'lhstockrail0', 'lhthroughrail0', 'lhbellyrail0', 'rhswitchblade0', 'rhstockrail0', 'rhthroughrail0', 'rhbellyrail0', 'comments0','lhswitchblade1', 'lhstockrail1', 'lhthroughrail1', 'lhbellyrail1', 'rhswitchblade1', 'rhstockrail1', 'rhthroughrail1', 'rhbellyrail1', 'comments1', 'image0','image1', 'pwaycomments0', 'gsmname', 'gsmsign', 'gsmcomments', 'fplname', 'fplsign', 'ins053name', 'ins053sign', 'signature', 'cglhsbbefore', 'cglhsbafter', 'cglhsblength', 'cglhsrbefore', 'cglhsrafter', 'cglhsrlength', 'cglhtrbefore', 'cglhtrafter', 'cglhtrlength', 'cglhbrbefore', 'cglhbrafter', 'cglhbrlength', 'cgrhsbbefore', 'cgrhsbafter', 'cgrhsblength', 'cgrhsrbefore', 'cgrhsrafter', 'cgrhsrlength', 'cgrhtrbefore', 'cgrhtrafter', 'cgrhtrlength', 'cgrhbrbefore', 'cgrhbrafter', 'cgrhbrlength', 'cgcomments', 'direction', 'pointsno'], 'string'],
            [['lhswitchblade1','rhswitchblade1','lhstockrail1','rhstockrail1','lhthroughrail1','rhthroughrail1', 'lhbellyrail1','rhbellyrail1'],'string'],
            [['inspectionvisual', 'inspectionut', 'inspectionema', 'tgp8tested', 'numberofgangs', 'strequired',  'pointsnofacing', 'pointsnotrailing', 'workcompleted0', 'so53compliant0', 'dpitested0', 'mpitested0', 'switchlubricated0', 'switchoperational0', 'uttested0', 'tgp8tested0',   'cglhsbmpi', 'cglhsrmpi', 'cglhtrmpi', 'cglhbrmpi', 'cgrhsbmpi', 'cgrhsrmpi', 'cgrhtrmpi', 'cgrhbrmpi', 'jobno'], 'integer'],
        	[['id', 'created_by', 'updated_by', 'fpldate', 'ins053date', 'signaturedate', 'actid', 'client'],'safe'],
        	[['fplinscompleted', 'ins053completed'], 'boolean'],
        	[['created_at', 'updated_at', 'deleted_at'], 'safe'],
        	[['deleted_by', 'relatedid', 'status', 'padno'], 'string'],
        	[['deleted',], 'boolean'],
        	//converted files from Widgets
        	[['grindingsupervisorsigndate','gsmdate',], 'safe']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attribute() {
        return [
            'id' => 'id',
            'created_at' => 'created_at',
            'updated_at' => 'updated_at',
            'created_by' => 'created_by',
            'updated_by' => 'updated_by',
            'actid' => 'actid',
            'client' => 'client',
            'location' => 'location',
            'elr' => 'elr',
            'line' => 'line',
            'startmileagem' => 'startmileagem',
            'startmileagey' => 'startmileagey',
            'finishmileagem' => 'finishmileagem',
            'finishmileaged' => 'finishmileaged',
            'plainline' => 'plainline',
            'sc' => 'sc',
            'inspectionvisual' => 'inspectionvisual',
            'inspectionut' => 'inspectionut',
            'inspectionema' => 'inspectionema',
            'gaugeattoebefore' => 'gaugeattoebefore',
            'gaugeattoeafter' => 'gaugeattoeafter',
            'sidewearreadinglh' => 'sidewearreadinglh',
            'sidewearreadingrh' => 'sidewearreadingrh',
            'railsectionlh' => 'railsectionlh',
            'railsectionrh' => 'railsectionrh',
            'tgp8tested' => 'tgp8tested',
            'raildepthlh' => 'raildepthlh',
            'raildepthrh' => 'raildepthrh',
            'railsteellh' => 'railsteellh',
            'railsteelrh' => 'railsteelrh',
            'siteaaccess' => 'siteaaccess',
            'prepwork' => 'prepwork',
            'specialreqs' => 'specialreqs',
            'protectiondets' => 'protectiondets',
            'possessiontimerequired' => 'possessiontimerequired',
            'grindingspec' => 'grindingspec',
            'numberofgangs' => 'numberofgangs',
            'strequired' => 'strequired',
            'grindingsupervisorname' => 'grindingsupervisorname',
            'grindingsupervisorsign' => 'grindingsupervisorsign',
            'grindingsupervisorsigndate' => 'grindingsupervisorsigndate',
            'pointsnofacing' => 'pointsnofacing',
            'pointsnotrailing' => 'pointsnotrailing',
            'lhswitchblade0' => 'lhswitchblade0',
            'lhstockrail0' => 'lhstockrail0',
            'lhthroughrail0' => 'lhthroughrail0',
            'lhbellyrail0' => 'lhbellyrail0',
            'rhswitchblade0' => 'rhswitchblade0',
            'rhstockrail0' => 'rhstockrail0',
            'rhthroughrail0' => 'rhthroughrail0',
            'rhbellyrail0' => 'rhbellyrail0',
            'comments0' => 'comments0',
            'image0' => 'image0',
            'workcompleted0' => 'workcompleted0',
            'so53compliant0' => 'so53compliant0',
            'dpitested0' => 'dpitested0',
            'mpitested0' => 'mpitested0',
            'switchlubricated0' => 'switchlubricated0',
            'switchoperational0' => 'switchoperational0',
            'uttested0' => 'uttested0',
            'tgp8tested0' => 'tgp8tested0',
            'pwaycomments0' => 'pwaycomments0',
            'gsmname' => 'gsmname',
            'gsmsign' => 'gsmsign',
            'gsmdate' => 'gsmdate',
            'gsmcomments' => 'gsmcomments',
            'fplname' => 'fplname',
            'fplsign' => 'fplsign',
            'fpldate' => 'fpldate',
            'ins053name' => 'ins053name',
            'ins053sign' => 'ins053sign',
            'ins053date' => 'ins053date',
            'signature' => 'signature',
            'signaturedate' => 'signaturedate',
            'cglhsbbefore' => 'cglhsbbefore',
            'cglhsbafter' => 'cglhsbafter',
            'cglhsblength' => 'cglhsblength',
            'cglhsbmpi' => 'cglhsbmpi',
            'cglhsrbefore' => 'cglhsrbefore',
            'cglhsrafter' => 'cglhsrafter',
            'cglhsrlength' => 'cglhsrlength',
            'cglhsrmpi' => 'cglhsrmpi',
            'cglhtrbefore' => 'cglhtrbefore',
            'cglhtrafter' => 'cglhtrafter',
            'cglhtrlength' => 'cglhtrlength',
            'cglhtrmpi' => 'cglhtrmpi',
            'cglhbrbefore' => 'cglhbrbefore',
            'cglhbrafter' => 'cglhbrafter',
            'cglhbrlength' => 'cglhbrlength',
            'cglhbrmpi' => 'cglhbrmpi',
            'cgrhsbbefore' => 'cgrhsbbefore',
            'cgrhsbafter' => 'cgrhsbafter',
            'cgrhsblength' => 'cgrhsblength',
            'cgrhsbmpi' => 'cgrhsbmpi',
            'cgrhsrbefore' => 'cgrhsrbefore',
            'cgrhsrafter' => 'cgrhsrafter',
            'cgrhsrlength' => 'cgrhsrlength',
            'cgrhsrmpi' => 'cgrhsrmpi',
            'cgrhtrbefore' => 'cgrhtrbefore',
            'cgrhtrafter' => 'cgrhtrafter',
            'cgrhtrlength' => 'cgrhtrlength',
            'cgrhtrmpi' => 'cgrhtrmpi',
            'cgrhbrbefore' => 'cgrhbrbefore',
            'cgrhbrafter' => 'cgrhbrafter',
            'cgrhbrlength' => 'cgrhbrlength',
            'cgrhbrmpi' => 'cgrhbrmpi',
            'cgcomments' => 'cgcomments',
        ];
    }
     /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'created_by' => 'Created By',
            'updated_by' => 'Updated By',
            'actid' => 'Actid',
            'client' => 'Client',
            'location' => 'Location',
            'elr' => 'Elr',
            'line' => 'Line',
            'startmileagem' => 'Startmileagem',
            'startmileagey' => 'Startmileagey',
            'finishmileagem' => 'Finishmileagem',
            'finishmileaged' => 'Finishmileaged',
            'plainline' => 'Plainline',
            'sc' => 'Sc',
            'inspectionvisual' => 'Inspectionvisual',
            'inspectionut' => 'Inspectionut',
            'inspectionema' => 'Inspectionema',
            'gaugeattoebefore' => 'Gaugeattoebefore',
            'gaugeattoeafter' => 'Gaugeattoeafter',
            'sidewearreadinglh' => 'Sidewearreadinglh',
            'sidewearreadingrh' => 'Sidewearreadingrh',
            'railsectionlh' => 'Railsectionlh',
            'railsectionrh' => 'Railsectionrh',
            'tgp8tested' => 'Tgp8tested',
            'raildepthlh' => 'Raildepthlh',
            'raildepthrh' => 'Raildepthrh',
            'railsteellh' => 'Railsteellh',
            'railsteelrh' => 'Railsteelrh',
            'siteaaccess' => 'Siteaaccess',
            'prepwork' => 'Prepwork',
            'specialreqs' => 'Specialreqs',
            'protectiondets' => 'Protectiondets',
            'possessiontimerequired' => 'Possessiontimerequired',
            'grindingspec' => 'Grindingspec',
            'numberofgangs' => 'Numberofgangs',
            'strequired' => 'Strequired',
            'grindingsupervisorname' => 'Grindingsupervisorname',
            'grindingsupervisorsign' => 'Grindingsupervisorsign',
            'grindingsupervisorsigndate' => 'Grindingsupervisorsigndate',
            'pointsnofacing' => 'Pointsnofacing',
            'pointsnotrailing' => 'Pointsnotrailing',
            'lhswitchblade0' => 'Lhswitchblade0',
            'lhstockrail0' => 'Lhstockrail0',
            'lhthroughrail0' => 'Lhthroughrail0',
            'lhbellyrail0' => 'Lhbellyrail0',
            'rhswitchblade0' => 'Rhswitchblade0',
            'rhstockrail0' => 'Rhstockrail0',
            'rhthroughrail0' => 'Rhthroughrail0',
            'rhbellyrail0' => 'Rhbellyrail0',
            'comments0' => 'Comments0',
            'image0' => 'Image0',
            'image1' => 'Image1',
            'workcompleted0' => 'Workcompleted0',
            'so53compliant0' => 'So53compliant0',
            'dpitested0' => 'Dpitested0',
            'mpitested0' => 'Mpitested0',
            'switchlubricated0' => 'Switchlubricated0',
            'switchoperational0' => 'Switchoperational0',
            'uttested0' => 'Uttested0',
            'tgp8tested0' => 'Tgp8tested0',
            'pwaycomments0' => 'Pwaycomments0',
            'gsmname' => 'Gsmname',
            'gsmsign' => 'Gsmsign',
            'gsmdate' => 'Gsmdate',
            'gsmcomments' => 'Gsmcomments',
            'fplname' => 'Fplname',
            'fplsign' => 'Fplsign',
            'fpldate' => 'Fpldate',
            'ins053name' => 'Ins053name',
            'ins053sign' => 'Ins053sign',
            'ins053date' => 'Ins053date',
            'signature' => 'Signature',
            'signaturedate' => 'Signaturedate',
            'cglhsbbefore' => 'Cglhsbbefore',
            'cglhsbafter' => 'Cglhsbafter',
            'cglhsblength' => 'Cglhsblength',
            'cglhsbmpi' => 'Cglhsbmpi',
            'cglhsrbefore' => 'Cglhsrbefore',
            'cglhsrafter' => 'Cglhsrafter',
            'cglhsrlength' => 'Cglhsrlength',
            'cglhsrmpi' => 'Cglhsrmpi',
            'cglhtrbefore' => 'Cglhtrbefore',
            'cglhtrafter' => 'Cglhtrafter',
            'cglhtrlength' => 'Cglhtrlength',
            'cglhtrmpi' => 'Cglhtrmpi',
            'cglhbrbefore' => 'Cglhbrbefore',
            'cglhbrafter' => 'Cglhbrafter',
            'cglhbrlength' => 'Cglhbrlength',
            'cglhbrmpi' => 'Cglhbrmpi',
            'cgrhsbbefore' => 'Cgrhsbbefore',
            'cgrhsbafter' => 'Cgrhsbafter',
            'cgrhsblength' => 'Cgrhsblength',
            'cgrhsbmpi' => 'Cgrhsbmpi',
            'cgrhsrbefore' => 'Cgrhsrbefore',
            'cgrhsrafter' => 'Cgrhsrafter',
            'cgrhsrlength' => 'Cgrhsrlength',
            'cgrhsrmpi' => 'Cgrhsrmpi',
            'cgrhtrbefore' => 'Cgrhtrbefore',
            'cgrhtrafter' => 'Cgrhtrafter',
            'cgrhtrlength' => 'Cgrhtrlength',
            'cgrhtrmpi' => 'Cgrhtrmpi',
            'cgrhbrbefore' => 'Cgrhbrbefore',
            'cgrhbrafter' => 'Cgrhbrafter',
            'cgrhbrlength' => 'Cgrhbrlength',
            'cgrhbrmpi' => 'Cgrhbrmpi',
            'cgcomments' => 'Cgcomments',
        ];
    }
    
    public function beforeValidate() {
		if (Yii::$app->controller->id == 'sync') {
			return parent::beforeValidate();
		} else {
			if ($this->client == '') {$this->client = null;}	
			if ($this->grindingsupervisorsigndate) {$this->grindingsupervisorsigndate = strtotime(str_replace('/','-',$this->grindingsupervisorsigndate));}	
			if ($this->gsmdate) {$this->gsmdate = strtotime(str_replace('/','-',$this->gsmdate));}	
			if ($this->signaturedate) {$this->signaturedate = strtotime(str_replace('/','-',$this->signaturedate));}	
			if ($this->fpldate) {$this->fpldate = strtotime(str_replace('/','-',$this->fpldate));}	
			if ($this->ins053date) {$this->ins053date = strtotime(str_replace('/','-',$this->ins053date));}	
            $this->padno = $this->padno == null ? User::Padno() : $this->padno;
            return parent::beforeValidate();
            
		}
    } 

        public function loadModeldata() {
			$this->grindingsupervisorsigndate = $this->grindingsupervisorsigndate !== null && $this->grindingsupervisorsigndate > 1 ? date('d/m/Y',$this->grindingsupervisorsigndate) : false ;
			$this->gsmdate = $this->gsmdate !== null && $this->gsmdate > 1 ? date('d/m/Y',$this->gsmdate) : false ;
			$this->signaturedate = $this->signaturedate !== null && $this->signaturedate > 1 ? date('d/m/Y',$this->signaturedate) : false ;
			$this->fpldate = $this->fpldate !== null && $this->fpldate > 1 ? date('d/m/Y',$this->fpldate) : false ;
			$this->ins053date = $this->ins053date !== null && $this->ins053date > 1 ? date('d/m/Y',$this->ins053date) : false ;
			return true;
		
	}
	public function getClientl() {
		return Accounts::findOne(['id' => $this->client]);
	}
	public function getAct() {
		return Activities::findOne(['id' => $this->actid]);
	}
	public function getActivity() {
		return Activities::findOne(['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'])->where(['id' => $this->actid])->asArray()->one();
           $this->jobno = $act['jobno'];
           $this->client = $act['relatedid'];
           $this->location = $act['location'];
           $this->elr = $act['elr'];
      //     $this->insdate = date('d/m/Y H:i', strtotime($act['sdate']));
        }
        return parent::init();
    }

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

}
