79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class InsurancePolicy extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'stabile_id',
|
|
'broker_rubrica_id',
|
|
'company_rubrica_id',
|
|
'policy_name',
|
|
'policy_number',
|
|
'policy_reference',
|
|
'status',
|
|
'started_at',
|
|
'expires_at',
|
|
'renewal_at',
|
|
'annual_amount',
|
|
'payment_split',
|
|
'payment_schedule_notes',
|
|
'coverage_summary',
|
|
'special_conditions',
|
|
'claim_form_template',
|
|
'policy_document_path',
|
|
'policy_document_name',
|
|
'policy_document_mime',
|
|
'signature_image_path',
|
|
'notes',
|
|
'metadata',
|
|
'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'started_at' => 'date',
|
|
'expires_at' => 'date',
|
|
'renewal_at' => 'date',
|
|
'annual_amount' => 'decimal:2',
|
|
'metadata' => 'array',
|
|
];
|
|
|
|
public function stabile()
|
|
{
|
|
return $this->belongsTo(Stabile::class, 'stabile_id');
|
|
}
|
|
|
|
public function brokerRubrica()
|
|
{
|
|
return $this->belongsTo(RubricaUniversale::class, 'broker_rubrica_id');
|
|
}
|
|
|
|
public function companyRubrica()
|
|
{
|
|
return $this->belongsTo(RubricaUniversale::class, 'company_rubrica_id');
|
|
}
|
|
|
|
public function claims()
|
|
{
|
|
return $this->hasMany(InsuranceClaim::class, 'insurance_policy_id');
|
|
}
|
|
|
|
public function getDisplayNameAttribute(): string
|
|
{
|
|
$label = trim((string) ($this->policy_name ?? ''));
|
|
if ($label !== '') {
|
|
return $label;
|
|
}
|
|
|
|
$label = trim((string) ($this->policy_number ?? ''));
|
|
if ($label !== '') {
|
|
return $label;
|
|
}
|
|
|
|
return 'Polizza #' . (int) $this->id;
|
|
}
|
|
} |