'hashed', 'sconti_abilitati' => 'boolean', 'sconto_max_1' => 'decimal:2', 'sconto_max_2' => 'decimal:2', ]; /** * Sconti massimi (%) che il cliente può applicare al preventivo: i suoi, se personalizzati, * altrimenti la regola base. Zero per entrambi se l'amministratore li ha disabilitati. * * @return array{max_1:float,max_2:float} */ public function scontiMassimi(): array { if (! $this->sconti_abilitati) { return ['max_1' => 0.0, 'max_2' => 0.0]; } return [ 'max_1' => (float) ($this->sconto_max_1 ?? Impostazione::scontiBase()['max_1']), 'max_2' => (float) ($this->sconto_max_2 ?? Impostazione::scontiBase()['max_2']), ]; } public function preventivi(): HasMany { return $this->hasMany(Preventivo::class); } protected static function booted(): void { static::deleting(function (Cliente $cliente): void { // Elimina di conseguenza i preventivi del cliente (con i relativi file) // e revoca i token API usati per l'accesso al configuratore. $cliente->preventivi()->get()->each->delete(); $cliente->tokens()->delete(); }); } public function getNominativoAttribute(): string { if ($this->ragione_sociale) { return $this->ragione_sociale; } $nome = trim("{$this->nome} {$this->cognome}"); return $nome !== '' ? $nome : $this->username; } public function getNomeCompletoAttribute(): string { $nome = trim("{$this->nome} {$this->cognome}"); return $nome !== '' ? $nome : $this->username; } }