This commit is contained in:
88
api/app/Models/Almoxarifado/RequisicaoRespostaItem.php
Normal file
88
api/app/Models/Almoxarifado/RequisicaoRespostaItem.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Almoxarifado;
|
||||
|
||||
use App\Models\Model;
|
||||
|
||||
class RequisicaoRespostaItem extends Model
|
||||
{
|
||||
protected $table = 'almoxarifado_requisicao_resposta_item';
|
||||
|
||||
protected $fillable = [
|
||||
'requisicao_item_id',
|
||||
'reserva_item_id',
|
||||
'saida_item_id',
|
||||
'motivo_id',
|
||||
'motivo_outro',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'requisicao_resposta_id',
|
||||
'created_at',
|
||||
'created_lotacao_id',
|
||||
'created_centro_custo_id',
|
||||
'updated_at',
|
||||
'updated_lotacao_id',
|
||||
'updated_centro_custo_id',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'quantidade_entrada',
|
||||
'quantidade_recebimento',
|
||||
];
|
||||
|
||||
public function requisicaoResposta()
|
||||
{
|
||||
return $this->belongsTo(RequisicaoResposta::class);
|
||||
}
|
||||
|
||||
public function requisicaoItem()
|
||||
{
|
||||
return $this->belongsTo(RequisicaoItem::class);
|
||||
}
|
||||
|
||||
public function reservaItem()
|
||||
{
|
||||
return $this->belongsTo(ReservaItem::class);
|
||||
}
|
||||
|
||||
public function saidaItem()
|
||||
{
|
||||
return $this->belongsTo(SaidaItem::class);
|
||||
}
|
||||
|
||||
public function motivo()
|
||||
{
|
||||
return $this->belongsTo(RequisicaoRespostaItemMotivo::class);
|
||||
}
|
||||
|
||||
public function entradaItens()
|
||||
{
|
||||
return $this->belongsToMany(EntradaItem::class, 'almoxarifado_requisicao_resposta_item_entrada_item')
|
||||
->using(RequisicaoRespostaItemEntradaItem::class)
|
||||
->as('pivotRequisicaoRespostaItemEntradaItem')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function recebimentos()
|
||||
{
|
||||
return $this->hasMany(RequisicaoRespostaItemRecebimento::class);
|
||||
}
|
||||
|
||||
public function getQuantidadeEntradaAttribute()
|
||||
{
|
||||
$quantidade = 0;
|
||||
|
||||
$this->entradaItens->map(function ($entradaItem) use (&$quantidade) {
|
||||
|
||||
$quantidade += (int) $entradaItem->quantidade;
|
||||
});
|
||||
|
||||
return $quantidade;
|
||||
}
|
||||
|
||||
public function getQuantidadeRecebimentoAttribute()
|
||||
{
|
||||
return $this->recebimentos->sum('quantidade');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user