<?php

namespace App;

use App\Traits\ModelTimeFormat;
use Illuminate\Database\Eloquent\Model;

use App\Traits\ModelLogChanging;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class DischargeTask extends Model
{
    use ModelLogChanging;
    use ModelTimeFormat;

    const status = [
        '创建',
        '接单',
        '作业中',
        '完成'
    ];

    const types = [
        '装车',
        '卸车',
        '翻托',
        '卸车'
    ];

    const units = [
        'm3',
        '吨',
        '托',
        '件'
    ];

    protected $fillable = [
        'owner_id','type','numbers','status',
        'income_amount','income_unit','income_unit_price','income_total_cost','income_remark',
        'facilitator_id','expenditure_amount','expenditure_unit','expenditure_unit_price','expenditure_total_cost','expenditure_remark',
        'income_at','expenditure_at','warehouse_id'
    ];

    function owner(): BelongsTo
    {
        return $this->belongsTo(Owner::class);
    }

    function facilitator(): BelongsTo
    {
        return $this->belongsTo(Facilitator::class);
    }

    public function scopeFilter($query, $filters)
    {
        return $filters->apply($query);
    }

    public function warehouse(): BelongsTo
    {
        return $this->belongsTo(Warehouse::class);
    }


}
