77 lines
1.6 KiB
PHP
77 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\Maintenance\Models;
|
|
|
|
use App\Business;
|
|
use App\Contact;
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class ServiceContract extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'maintenance_service_contracts';
|
|
|
|
protected $fillable = [
|
|
'business_id',
|
|
'equipment_id',
|
|
'customer_id',
|
|
'contract_code',
|
|
'title',
|
|
'contract_type',
|
|
'start_date',
|
|
'end_date',
|
|
'response_hours',
|
|
'resolution_hours',
|
|
'coverage_amount',
|
|
'status',
|
|
'terms',
|
|
'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'start_date' => 'date',
|
|
'end_date' => 'date',
|
|
'coverage_amount' => 'decimal:2',
|
|
];
|
|
|
|
public function business()
|
|
{
|
|
return $this->belongsTo(Business::class);
|
|
}
|
|
|
|
public function equipment()
|
|
{
|
|
return $this->belongsTo(Equipment::class, 'equipment_id');
|
|
}
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Contact::class, 'customer_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
if ($this->status !== 'active') {
|
|
return false;
|
|
}
|
|
|
|
$today = now()->startOfDay();
|
|
if ($this->start_date && $this->start_date->gt($today)) {
|
|
return false;
|
|
}
|
|
if ($this->end_date && $this->end_date->lt($today)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|