<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "fix_car_t".
 *
 * @property integer $id
 * @property integer $car_id
 * @property string $car_no
 * @property string $engine_no
 * @property string $car_frame_no
 * @property string $new_price
 * @property integer $brand_id
 * @property integer $series_id
 * @property integer $displacement_id
 * @property string $car_year
 * @property string $id_man
 * @property string $id_phone
 * @property string $link_man
 * @property string $link_phone
 * @property string $company
 * @property string $insurer1_no
 * @property string $insurer2_no
 * @property string $receive_date
 * @property string $receive_type
 * @property string $accident_type
 * @property string $responsibility
 * @property integer $replace_car_id
 * @property integer $driver_id
 * @property integer $direction_id
 * @property integer $range_id
 * @property string $address
 * @property string $report_no
 * @property string $receive_mileage
 * @property string $receive_oil
 * @property string $factory_mileage
 * @property string $factory_oil
 * @property string $finish_date
 * @property string $submit_date
 * @property string $remark
 * @property integer $status
 * @property integer $user_id
 * @property string $baoan_man
 * @property string $baoan_time
 * @property string $baoan_address
 * @property string $chuxian_time
 * @property string $shigu_info
 * @property string $lipei_company
 * @property string $zhuche_money
 * @property string $sanzhe_money
 * @property string $wusun_money
 * @property string $tuoche
 * @property string $tuoche_money
 * @property string $dingsun_hour_money
 * @property string $dingsun_huanjian_money
 * @property integer $peifu_bili
 * @property string $peifu_money
 * @property string $kehu_money
 * @property integer $return_status
 * @property string $return_remark
 * @property integer $return_time
 * @property string $created_at
 * @property string $updated_at
 */
class FixCarT extends \common\models\Base
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'fix_car_t';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['car_id', 'brand_id', 'series_id', 'displacement_id', 'replace_car_id', 'driver_id', 'direction_id', 'range_id', 'status', 'user_id', 'peifu_bili','return_status','return_time'], 'integer'],
            [['receive_date', 'finish_date', 'submit_date', 'created_at', 'updated_at'], 'safe'],
            [['zhuche_money', 'sanzhe_money', 'wusun_money', 'tuoche_money', 'dingsun_hour_money', 'dingsun_huanjian_money', 'peifu_money', 'kehu_money'], 'number'],
            [['car_no', 'car_year', 'id_phone', 'link_man', 'link_phone', 'receive_type', 'report_no', 'receive_mileage', 'receive_oil', 'factory_mileage', 'factory_oil', 'baoan_time', 'chuxian_time'], 'string', 'max' => 50],
            [['engine_no', 'car_frame_no', 'new_price', 'id_man', 'company', 'insurer1_no', 'insurer2_no', 'accident_type', 'responsibility', 'baoan_man', 'baoan_address', 'lipei_company', 'tuoche','return_remark'], 'string', 'max' => 100],
            [['address', 'remark', 'shigu_info'], 'string', 'max' => 200],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'car_id' => 'Car ID',
            'car_no' => 'Car No',
            'engine_no' => 'Engine No',
            'car_frame_no' => 'Car Frame No',
            'new_price' => 'New Price',
            'brand_id' => 'Brand ID',
            'series_id' => 'Series ID',
            'displacement_id' => 'Displacement ID',
            'car_year' => 'Car Year',
            'id_man' => 'Id Man',
            'id_phone' => 'Id Phone',
            'link_man' => 'Link Man',
            'link_phone' => 'Link Phone',
            'company' => 'Company',
            'insurer1_no' => 'Insurer1 No',
            'insurer2_no' => 'Insurer2 No',
            'receive_date' => 'Receive Date',
            'receive_type' => 'Receive Type',
            'accident_type' => 'Accident Type',
            'responsibility' => 'Responsibility',
            'replace_car_id' => 'Replace Car ID',
            'driver_id' => 'Driver ID',
            'direction_id' => 'Direction ID',
            'range_id' => 'Range ID',
            'address' => 'Address',
            'report_no' => 'Report No',
            'receive_mileage' => 'Receive Mileage',
            'receive_oil' => 'Receive Oil',
            'factory_mileage' => 'Factory Mileage',
            'factory_oil' => 'Factory Oil',
            'finish_date' => 'Finish Date',
            'submit_date' => 'Submit Date',
            'remark' => 'Remark',
            'status' => 'Status',
            'user_id' => 'User ID',
            'baoan_man' => 'Baoan Man',
            'baoan_time' => 'Baoan Time',
            'baoan_address' => 'Baoan Address',
            'chuxian_time' => 'Chuxian Time',
            'shigu_info' => 'Shigu Info',
            'lipei_company' => 'Lipei Company',
            'zhuche_money' => 'Zhuche Money',
            'sanzhe_money' => 'Sanzhe Money',
            'wusun_money' => 'Wusun Money',
            'tuoche' => 'Tuoche',
            'tuoche_money' => 'Tuoche Money',
            'dingsun_hour_money' => 'Dingsun Hour Money',
            'dingsun_huanjian_money' => 'Dingsun Huanjian Money',
            'peifu_bili' => 'Peifu Bili',
            'peifu_money' => 'Peifu Money',
            'kehu_money' => 'Kehu Money',
            'return_status' => 'Return Status',
            'return_remark' => 'Return Remark',
            'return_time' => 'Return Time',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getUser()
    {
        return $this->hasOne(UserT::className(),['id'=>'user_id']);
    }

    public function getDriver()
    {
        return $this->hasOne(UserT::className(),['id'=>'driver_id']);
    }

    public function getCar()
    {
        return $this->hasOne(CarT::className(),['id'=>'car_id']);
    }

    public function getStatus()
    {
        $result = '';
        switch($this->status) {
            case 1:
                $result = '维修调度';
                break;
            case 2:
//                $result = '司机接车';
                $result = '提单完成';
                break;
            case 3:
                $result = '前台派工';
                break;
            case 4:
                $result = '查勘定损';
                break;
            case 5:
                $result = '技工维修';
                break;
            case 6:
                $result = '总检';
                break;
            case 7:
                $result = '财务结算';
                break;
            default:
                $result = '待处理';
        }
        return $result;
    }

    public function getDirection()
    {
        return $this->hasOne(DirectionT::className(),['id'=>'direction_id']);
    }

    public function getRange()
    {
        return $this->hasOne(RangeT::className(),['id'=>'range_id']);
    }

    public function getBrand()
    {
        return $this->hasOne(BrandT::className(),['id'=>'brand_id']);
    }

    public function getSeries()
    {
        return $this->hasOne(SeriesT::className(),['id'=>'series_id']);
    }

    public function getDisplacement()
    {
        return $this->hasOne(DisplacementT::className(),['id'=>'displacement_id']);
    }

    public function getItems()
    {
        return $this->hasMany(FixItemT::className(),['fix_id'=>'id']);
    }
}
