59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Maintenance\Models;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class MissionCrewMember extends Model
|
|
{
|
|
protected $table = 'maintenance_mission_crew_members';
|
|
|
|
protected $fillable = [
|
|
'mission_id',
|
|
'user_id',
|
|
'person_name',
|
|
'role',
|
|
'is_lead',
|
|
'labor_hours',
|
|
'hourly_rate',
|
|
'labor_cost',
|
|
'per_diem',
|
|
'notes',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_lead' => 'boolean',
|
|
'labor_hours' => 'decimal:2',
|
|
'hourly_rate' => 'integer',
|
|
'labor_cost' => 'integer',
|
|
'per_diem' => 'integer',
|
|
];
|
|
|
|
public function mission()
|
|
{
|
|
return $this->belongsTo(FieldMission::class, 'mission_id');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function displayName(): string
|
|
{
|
|
if ($this->user) {
|
|
return trim($this->user->first_name.' '.($this->user->last_name ?? ''));
|
|
}
|
|
|
|
return $this->person_name ?: '—';
|
|
}
|
|
|
|
public function recalculateLaborCost(): void
|
|
{
|
|
$hours = (float) $this->labor_hours;
|
|
$rate = (int) $this->hourly_rate;
|
|
$this->labor_cost = (int) round($hours * $rate);
|
|
}
|
|
}
|