<?php

namespace App;

use App\Traits\ModelTimeFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

use App\Traits\ModelLogChanging;

class InventoryAccountMission extends Model
{
    use ModelLogChanging;

    use ModelTimeFormat;
    protected $fillable=[
        'id','inventory_account_id','location','commodity_id', 'produced_at', 'valid_at','stored_at','batch_number','erp_type_position','quality','stored_amount','valid_amount',
        'verified_amount','re_checked_amount','difference_amount','occupied_amount','checked',
    ];
    public function commodity(){
        return $this->belongsTo('App\Commodity','commodity_id','id');
    }
    public function stockInventoryPersons(){
        return $this->hasMany('App\Sign','signable_id','id')
            ->where('signable_type','inventory_account_missions')->where('field','盘点人');
    }
    public function createSignStockInventoryPersons(){
        return Sign::query()->firstOrCreate([
            'signable_type'=>'inventory_account_missions',
            'signable_id'=>$this['id'],
            'field'=>'盘点人',
            'mark'=>Auth::user()['name'],
        ]);
    }
}
