MAJOR IMPLEMENTATION COMPLETED: ✅ Modern database structure with Laravel best practices ✅ Complete Eloquent relationships (Amministratore→Stabili→Movements) ✅ 8-character alphanumeric codes system (ADM, ANA, MOV, ALL prefixes) ✅ Multi-database architecture for administrators ✅ Complete property management (anagrafica_condominiale, diritti_reali, contratti) ✅ Distribution system for multi-server deployment ✅ Universal responsive UI with permission-based sidebar NEW MODELS & MIGRATIONS: - AnagraficaCondominiale: Complete person/entity management - ContattoAnagrafica: Multi-contact system with usage flags - DirittoReale: Property rights with quotas and percentages - ContrattoLocazione: Rental contracts with landlord/tenant - TipoUtilizzo: Property usage types (residential, commercial, etc.) - Enhanced Stabile: Cadastral data, SDI, rate configuration - Enhanced UnitaImmobiliare: Modern structure with backward compatibility SERVICES & CONTROLLERS: - DistributionService: Multi-server deployment and migration - FileManagerController: Administrator folder management - DistributionController: API for server-to-server communication - MultiDatabaseService: Dynamic database connections READY FOR PRODUCTION: ✅ Database schema: Complete and tested ✅ Models relationships: All working and verified ✅ Code generation: Automatic 8-char codes implemented ✅ Testing: Successful data creation confirmed ✅ Documentation: Complete internal technical docs NEXT PHASE: Millésimal tables, expense categories, cost distribution engine
70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Banca extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'banche';
|
|
|
|
protected $fillable = [
|
|
'stabile_id',
|
|
'denominazione',
|
|
'iban',
|
|
'bic_swift',
|
|
'agenzia',
|
|
'indirizzo_agenzia',
|
|
'tipo_conto',
|
|
'saldo_iniziale',
|
|
'data_apertura',
|
|
'stato',
|
|
'note',
|
|
];
|
|
|
|
protected $casts = [
|
|
'saldo_iniziale' => 'decimal:2',
|
|
'data_apertura' => 'date',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Relazione con Stabile
|
|
*/
|
|
public function stabile()
|
|
{
|
|
return $this->belongsTo(Stabile::class, 'stabile_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* Relazione con Movimenti Bancari
|
|
*/
|
|
public function movimentiBancari()
|
|
{
|
|
return $this->hasMany(MovimentoBancario::class, 'banca_id');
|
|
}
|
|
|
|
/**
|
|
* Scope per conti attivi
|
|
*/
|
|
public function scopeAttivi($query)
|
|
{
|
|
return $query->where('stato', 'attivo');
|
|
}
|
|
|
|
/**
|
|
* Calcola il saldo attuale
|
|
*/
|
|
public function getSaldoAttualeAttribute()
|
|
{
|
|
$movimenti = $this->movimentiBancari()
|
|
->selectRaw('SUM(CASE WHEN tipo_movimento = "entrata" THEN importo ELSE -importo END) as saldo')
|
|
->first();
|
|
|
|
return $this->saldo_iniziale + ($movimenti->saldo ?? 0);
|
|
}
|
|
} |