79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Almoxarifado;
|
|
|
|
use App\Models\Cadastro\Estabelecimento\CentroCusto;
|
|
use App\Models\Model;
|
|
|
|
class Entrada extends Model
|
|
{
|
|
protected $table = 'almoxarifado_entrada';
|
|
|
|
protected $casts = [
|
|
'finalizada' => 'boolean',
|
|
'finalizada_em' => 'datetime:d/m/Y',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'centro_custo_id',
|
|
'tipo_id',
|
|
'finalizada',
|
|
'finalizada_em',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
];
|
|
|
|
protected $with = [
|
|
'documento',
|
|
];
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
self::saved(function($model) {
|
|
$model = (object) $model->fresh()->getRawOriginal();
|
|
|
|
EntradaLog::create([
|
|
'entrada_id' => $model->id,
|
|
'centro_custo_id' => $model->centro_custo_id,
|
|
'tipo_id' => $model->tipo_id,
|
|
'finalizada' => $model->finalizada,
|
|
'finalizada_em' => $model->finalizada_em,
|
|
]);
|
|
});
|
|
}
|
|
|
|
public function centroCusto()
|
|
{
|
|
return $this->belongsTo(CentroCusto::class);
|
|
}
|
|
|
|
public function tipo()
|
|
{
|
|
return $this->belongsTo(EntradaTipo::class);
|
|
}
|
|
|
|
public function documento()
|
|
{
|
|
return $this->hasOne(EntradaDocumento::class);
|
|
}
|
|
|
|
public function itens()
|
|
{
|
|
return $this->hasMany(EntradaItem::class);
|
|
}
|
|
|
|
public function requisicaoResposta()
|
|
{
|
|
return $this->hasOne(RequisicaoResposta::class);
|
|
}
|
|
}
|