107 lines
2.3 KiB
PHP
Executable File
107 lines
2.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class TabellaMillesimaleConti extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'tabelle_millesimali';
|
|
|
|
protected $fillable = [
|
|
'gestione_id',
|
|
'codice',
|
|
'descrizione',
|
|
'intestazione_colonne',
|
|
'calcolo',
|
|
'gestione_tipo',
|
|
'decimali',
|
|
'unita_misura',
|
|
'totale_millesimi',
|
|
'attiva'
|
|
];
|
|
|
|
protected $casts = [
|
|
'totale_millesimi' => 'decimal:3',
|
|
'decimali' => 'integer',
|
|
'attiva' => 'boolean'
|
|
];
|
|
|
|
/**
|
|
* Relazione con la gestione
|
|
*/
|
|
public function gestione(): BelongsTo
|
|
{
|
|
return $this->belongsTo(GestioneCondominiale::class, 'gestione_id');
|
|
}
|
|
|
|
/**
|
|
* Voci di spesa collegate
|
|
*/
|
|
public function vociSpesa(): HasMany
|
|
{
|
|
return $this->hasMany(VoceSpesaMillesimale::class, 'tabella_millesimale_id');
|
|
}
|
|
|
|
/**
|
|
* Millesimi delle unità immobiliari
|
|
*/
|
|
public function millesimi(): HasMany
|
|
{
|
|
return $this->hasMany(MillesimiUnita::class, 'tabella_millesimale_id');
|
|
}
|
|
|
|
/**
|
|
* Scope per tipo di calcolo
|
|
*/
|
|
public function scopeByCalcolo($query, $calcolo)
|
|
{
|
|
return $query->where('calcolo', $calcolo);
|
|
}
|
|
|
|
/**
|
|
* Scope per tipo di gestione
|
|
*/
|
|
public function scopeByGestioneTipo($query, $tipo)
|
|
{
|
|
return $query->where('gestione_tipo', $tipo);
|
|
}
|
|
|
|
/**
|
|
* Scope attive
|
|
*/
|
|
public function scopeAttive($query)
|
|
{
|
|
return $query->where('attiva', true);
|
|
}
|
|
|
|
/**
|
|
* Verifica se è una tabella con millesimi
|
|
*/
|
|
public function hasMillesimi(): bool
|
|
{
|
|
return in_array($this->calcolo, ['M']) && $this->totale_millesimi > 0;
|
|
}
|
|
|
|
/**
|
|
* Verifica se è una tabella a consumi
|
|
*/
|
|
public function isConsumiIndividuali(): bool
|
|
{
|
|
return $this->calcolo === 'A' && $this->unita_misura === 'Cons.';
|
|
}
|
|
|
|
/**
|
|
* Totale millesimi formattato
|
|
*/
|
|
public function getTotaleMillesimiFormattedAttribute(): string
|
|
{
|
|
return number_format($this->totale_millesimi, $this->decimali, ',', '.');
|
|
}
|
|
}
|