This commit is contained in:
95
api/app/Models/Farmacia/ReceitaItem.php
Normal file
95
api/app/Models/Farmacia/ReceitaItem.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Farmacia;
|
||||
|
||||
use App\Models\Cadastro\Material\Material;
|
||||
use App\Models\Farmacia\Receita;
|
||||
use App\Models\Farmacia\ReceitaItemEntrega;
|
||||
use App\Models\Geral\MedidaTempo;
|
||||
use App\Models\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ReceitaItem extends Model
|
||||
{
|
||||
protected $table = 'farmacia_receita_item';
|
||||
|
||||
protected $casts = [
|
||||
'proxima_retirada' => 'datetime:Y-m-d',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'receita_id',
|
||||
'material_id',
|
||||
'quantidade',
|
||||
'intervalo_tempo',
|
||||
'intervalo_medida_tempo_id',
|
||||
'durante_tempo',
|
||||
'prescrito',
|
||||
'proxima_retirada',
|
||||
'observacao',
|
||||
'supervisor_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'created_lotacao_id',
|
||||
'created_centro_custo_id',
|
||||
'updated_at',
|
||||
'updated_lotacao_id',
|
||||
'updated_centro_custo_id',
|
||||
];
|
||||
|
||||
public function getPosologiaAttribute()
|
||||
{
|
||||
$posologia = '';
|
||||
|
||||
if (!is_null($this->quantidade)) {
|
||||
|
||||
$quantidade = (float) $this->quantidade;
|
||||
|
||||
$posologia .= fmod($quantidade, 1) == 0 ? (int) $quantidade : number_format($quantidade, 2, ',', '.');
|
||||
|
||||
if (!is_null($this->material->apresentacaoUnidadeMedida)) {
|
||||
|
||||
$posologia .= ' ' . Str::lower($this->material->apresentacaoUnidadeMedida->nome);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($this->intervalo_tempo)) {
|
||||
|
||||
$posologia .= " a cada {$this->intervalo_tempo}";
|
||||
|
||||
if (!is_null($this->intervaloMedidaTempo)) {
|
||||
|
||||
$posologia .= ' ' . Str::lower($this->intervaloMedidaTempo->nome);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_null($this->durante_tempo)) {
|
||||
|
||||
$posologia .= " durante {$this->durante_tempo} dia(s)";
|
||||
}
|
||||
|
||||
return empty($posologia) ? null : $posologia;
|
||||
}
|
||||
|
||||
public function receita()
|
||||
{
|
||||
return $this->belongsTo(Receita::class);
|
||||
}
|
||||
|
||||
public function material()
|
||||
{
|
||||
return $this->belongsTo(Material::class);
|
||||
}
|
||||
|
||||
public function intervaloMedidaTempo()
|
||||
{
|
||||
return $this->belongsTo(MedidaTempo::class);
|
||||
}
|
||||
|
||||
public function entregas()
|
||||
{
|
||||
return $this->hasMany(ReceitaItemEntrega::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user