'decimal:2', 'istat_percentuale' => 'decimal:3', 'istat_importo' => 'decimal:2', 'importo_1' => 'decimal:2', 'importo_2' => 'decimal:2', 'importo_3' => 'decimal:2', 'importo_4' => 'decimal:2', 'bollo' => 'decimal:2', 'totale' => 'decimal:2', 'data_emissione' => 'date', 'data_scadenza' => 'date', 'saldo_progressivo' => 'decimal:2', ]; public function affitto() { return $this->belongsTo(AffittoImmobile::class, 'affitto_id'); } public function generateNumeroRicevuta(): string { $affitto = $this->affitto; $stabileCode = $affitto?->stabile?->codice_univoco ?: ($affitto?->stabile?->codice_stabile ?: $affitto?->codice_stabile_legacy); $anno = $this->anno ?: date('Y'); $mese = str_pad((string) ($this->mese ?: 0), 2, '0', STR_PAD_LEFT); $base = $stabileCode ? "AFF-{$stabileCode}-{$this->affitto_id}-{$anno}{$mese}" : "AFF-{$this->affitto_id}-{$anno}{$mese}"; $code = $base; $exists = self::where('n_ricevuta', $code)->whereKeyNot($this->id)->exists(); if ($exists) { $code = $base . '-' . ($this->id ?? uniqid()); } return $code; } }