134 lines
3.6 KiB
PHP
Executable File
134 lines
3.6 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 AssembleaVerbale extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'assemblee_verbali';
|
|
|
|
protected $fillable = [
|
|
'amministratore_id',
|
|
'stabile_id',
|
|
'data_assemblea',
|
|
'ora_inizio',
|
|
'ora_fine',
|
|
'tipo_assemblea',
|
|
'luogo',
|
|
'presidente',
|
|
'segretario',
|
|
'num_presenti',
|
|
'num_rappresentati',
|
|
'millesimi_presenti',
|
|
'millesimi_rappresentati',
|
|
'ordine_giorno',
|
|
'deliberazioni',
|
|
'allegati',
|
|
'note'
|
|
];
|
|
|
|
protected $casts = [
|
|
'data_assemblea' => 'date',
|
|
'num_presenti' => 'integer',
|
|
'num_rappresentati' => 'integer',
|
|
'millesimi_presenti' => 'decimal:3',
|
|
'millesimi_rappresentati' => 'decimal:3',
|
|
'ordine_giorno' => 'array',
|
|
'deliberazioni' => 'array',
|
|
'allegati' => 'array'
|
|
];
|
|
|
|
const TIPO_ORDINARIA = 'ordinaria';
|
|
const TIPO_STRAORDINARIA = 'straordinaria';
|
|
const TIPO_PRIMA_CONVOCAZIONE = 'prima_convocazione';
|
|
const TIPO_SECONDA_CONVOCAZIONE = 'seconda_convocazione';
|
|
|
|
public function amministratore(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Administrator::class);
|
|
}
|
|
|
|
public function stabile(): BelongsTo
|
|
{
|
|
return $this->belongsTo(StabileGescon::class);
|
|
}
|
|
|
|
public function destinatari(): HasMany
|
|
{
|
|
return $this->hasMany(DestinatarioComunicazione::class, 'assemblea_id');
|
|
}
|
|
|
|
public function scopeByTipo($query, $tipo)
|
|
{
|
|
return $query->where('tipo_assemblea', $tipo);
|
|
}
|
|
|
|
public function scopeByAnno($query, $anno)
|
|
{
|
|
return $query->whereYear('data_assemblea', $anno);
|
|
}
|
|
|
|
public function scopeByPeriodo($query, $dataInizio, $dataFine)
|
|
{
|
|
return $query->whereBetween('data_assemblea', [$dataInizio, $dataFine]);
|
|
}
|
|
|
|
public function getTotalePartecipantiAttribute()
|
|
{
|
|
return $this->num_presenti + $this->num_rappresentati;
|
|
}
|
|
|
|
public function getTotaleMillesimiAttribute()
|
|
{
|
|
return $this->millesimi_presenti + $this->millesimi_rappresentati;
|
|
}
|
|
|
|
public function getPercentualePartecipazione()
|
|
{
|
|
$totaleCondomini = $this->stabile->num_condomini ?? 0;
|
|
if ($totaleCondomini == 0) {
|
|
return 0;
|
|
}
|
|
return round(($this->totale_partecipanti / $totaleCondomini) * 100, 2);
|
|
}
|
|
|
|
public function getPercentualeMillesimi()
|
|
{
|
|
$totaleMillesimi = $this->stabile->millesimi_totali ?? 0;
|
|
if ($totaleMillesimi == 0) {
|
|
return 0;
|
|
}
|
|
return round(($this->totale_millesimi / $totaleMillesimi) * 100, 2);
|
|
}
|
|
|
|
public function getDurataAssembleaAttribute()
|
|
{
|
|
if (!$this->ora_inizio || !$this->ora_fine) {
|
|
return null;
|
|
}
|
|
|
|
$inizio = \Carbon\Carbon::createFromFormat('H:i:s', $this->ora_inizio);
|
|
$fine = \Carbon\Carbon::createFromFormat('H:i:s', $this->ora_fine);
|
|
|
|
return $fine->diff($inizio)->format('%H:%I');
|
|
}
|
|
|
|
public function getTipoAssembleaLabelAttribute()
|
|
{
|
|
$labels = [
|
|
self::TIPO_ORDINARIA => 'Ordinaria',
|
|
self::TIPO_STRAORDINARIA => 'Straordinaria',
|
|
self::TIPO_PRIMA_CONVOCAZIONE => 'Prima Convocazione',
|
|
self::TIPO_SECONDA_CONVOCAZIONE => 'Seconda Convocazione'
|
|
];
|
|
|
|
return $labels[$this->tipo_assemblea] ?? $this->tipo_assemblea;
|
|
}
|
|
}
|