61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Client extends Model
|
|
{
|
|
protected $fillable = [
|
|
'type',
|
|
'name',
|
|
'vat_number',
|
|
'siret',
|
|
'email',
|
|
'phone',
|
|
'billing_address_line1',
|
|
'billing_address_line2',
|
|
'billing_postal_code',
|
|
'billing_city',
|
|
'billing_country_code',
|
|
'group_id',
|
|
'notes',
|
|
'is_active',
|
|
'default_tva_rate_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
/**
|
|
* Get the human-readable label for the client type.
|
|
*/
|
|
public function getTypeLabel(): string
|
|
{
|
|
return match($this->type) {
|
|
'pompes_funebres' => 'Pompes funèbres',
|
|
'famille' => 'Famille',
|
|
'entreprise' => 'Entreprise',
|
|
'collectivite' => 'Collectivité',
|
|
'autre' => 'Autre',
|
|
default => $this->type,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get the full billing address as a string.
|
|
*/
|
|
public function getBillingAddressAttribute(): ?string
|
|
{
|
|
$parts = array_filter([
|
|
$this->billing_address_line1,
|
|
$this->billing_address_line2,
|
|
$this->billing_postal_code ? $this->billing_postal_code . ' ' . $this->billing_city : $this->billing_city,
|
|
$this->billing_country_code,
|
|
]);
|
|
|
|
return !empty($parts) ? implode(', ', $parts) : null;
|
|
}
|
|
}
|