This commit is contained in:
70
api/app/Models/Almoxarifado/ReservaItem.php
Normal file
70
api/app/Models/Almoxarifado/ReservaItem.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Almoxarifado;
|
||||
|
||||
use App\Models\Cadastro\Material\Material;
|
||||
use App\Models\Model;
|
||||
|
||||
class ReservaItem extends Model
|
||||
{
|
||||
protected $table = 'almoxarifado_reserva_item';
|
||||
|
||||
protected $casts = [
|
||||
'escolheu_entrada_item_manualmente' => 'boolean',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'material_id',
|
||||
'escolheu_entrada_item_manualmente',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'reserva_id',
|
||||
'created_at',
|
||||
'created_lotacao_id',
|
||||
'created_centro_custo_id',
|
||||
'updated_at',
|
||||
'updated_lotacao_id',
|
||||
'updated_centro_custo_id',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'quantidade',
|
||||
];
|
||||
|
||||
public function reserva()
|
||||
{
|
||||
return $this->belongsTo(Reserva::class);
|
||||
}
|
||||
|
||||
public function material()
|
||||
{
|
||||
return $this->belongsTo(Material::class);
|
||||
}
|
||||
|
||||
public function entradaItens()
|
||||
{
|
||||
return $this->belongsToMany(EntradaItem::class, 'almoxarifado_reserva_item_entrada_item')
|
||||
->using(ReservaItemEntradaItem::class)
|
||||
->as('pivotReservaItemEntradaItem')
|
||||
->withPivot(['quantidade_saida'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function requisicaoRespostaItem()
|
||||
{
|
||||
return $this->hasOne(RequisicaoRespostaItem::class);
|
||||
}
|
||||
|
||||
public function getQuantidadeAttribute()
|
||||
{
|
||||
$quantidade = 0;
|
||||
|
||||
$this->entradaItens->map(function ($entradaItem) use (&$quantidade) {
|
||||
|
||||
$quantidade += (int) $entradaItem->pivotReservaItemEntradaItem->quantidade_saida;
|
||||
});
|
||||
|
||||
return $quantidade;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user