117 lines
2.8 KiB
PHP
117 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Maintenance\Models;
|
|
|
|
use App\Business;
|
|
use App\BusinessLocation;
|
|
use App\HoldingEntity;
|
|
use App\OrgUnit;
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class RepairDispatch extends Model
|
|
{
|
|
protected $table = 'maintenance_repair_dispatches';
|
|
|
|
protected $fillable = [
|
|
'business_id',
|
|
'material_list_id',
|
|
'material_line_id',
|
|
'dispatch_number',
|
|
'route_type',
|
|
'origin_location_id',
|
|
'holding_entity_id',
|
|
'org_unit_id',
|
|
'service_provider_id',
|
|
'external_party_name',
|
|
'external_address',
|
|
'quantity',
|
|
'status',
|
|
'sent_at',
|
|
'expected_return_at',
|
|
'repair_completed_at',
|
|
'return_dispatched_at',
|
|
'received_at',
|
|
'tracking_number_out',
|
|
'tracking_number_return',
|
|
'carrier',
|
|
'repair_cost',
|
|
'repair_report',
|
|
'send_notes',
|
|
'receive_notes',
|
|
'created_by',
|
|
'sent_by',
|
|
'received_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'quantity' => 'decimal:3',
|
|
'repair_cost' => 'integer',
|
|
'sent_at' => 'datetime',
|
|
'expected_return_at' => 'date',
|
|
'repair_completed_at' => 'datetime',
|
|
'return_dispatched_at' => 'datetime',
|
|
'received_at' => 'datetime',
|
|
];
|
|
|
|
public function business()
|
|
{
|
|
return $this->belongsTo(Business::class);
|
|
}
|
|
|
|
public function materialList()
|
|
{
|
|
return $this->belongsTo(MaterialList::class, 'material_list_id');
|
|
}
|
|
|
|
public function materialLine()
|
|
{
|
|
return $this->belongsTo(MaterialLine::class, 'material_line_id');
|
|
}
|
|
|
|
public function originLocation()
|
|
{
|
|
return $this->belongsTo(BusinessLocation::class, 'origin_location_id');
|
|
}
|
|
|
|
public function holdingEntity()
|
|
{
|
|
return $this->belongsTo(HoldingEntity::class, 'holding_entity_id');
|
|
}
|
|
|
|
public function orgUnit()
|
|
{
|
|
return $this->belongsTo(OrgUnit::class, 'org_unit_id');
|
|
}
|
|
|
|
public function serviceProvider()
|
|
{
|
|
return $this->belongsTo(ServiceProvider::class, 'service_provider_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function events()
|
|
{
|
|
return $this->hasMany(RepairDispatchEvent::class, 'repair_dispatch_id')->orderBy('id');
|
|
}
|
|
|
|
public function destinationLabel(): string
|
|
{
|
|
if ($this->route_type === 'internal') {
|
|
$parts = array_filter([
|
|
$this->holdingEntity?->name,
|
|
$this->orgUnit?->name,
|
|
]);
|
|
|
|
return $parts ? implode(' / ', $parts) : '—';
|
|
}
|
|
|
|
return $this->serviceProvider?->name
|
|
?: ($this->external_party_name ?: '—');
|
|
}
|
|
}
|