backoffice first commit

This commit is contained in:
2026-07-17 11:34:15 +02:00
parent 761db06329
commit 1c40ef6601
159 changed files with 25830 additions and 7875 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Preventivo extends Model
{
protected $table = 'preventivi';
protected $fillable = [
'cliente_id', 'token', 'numero', 'stato', 'totale', 'pdf_path', 'confirmed_at',
];
protected $casts = [
'totale' => 'decimal:2',
'confirmed_at' => 'datetime',
];
public const STATI = [
'bozza' => 'Bozza',
'inviato' => 'Inviato',
'in_lavorazione' => 'In lavorazione',
'chiuso' => 'Chiuso',
];
public function cliente(): BelongsTo
{
return $this->belongsTo(Cliente::class);
}
public function items(): HasMany
{
return $this->hasMany(PreventivoItem::class);
}
/** Ricalcola e salva il totale dagli item. */
public function ricalcolaTotale(): void
{
$this->totale = $this->items()->sum('prezzo_totale');
$this->save();
}
/** Numero progressivo assegnato alla conferma (max+1). */
public static function prossimoNumero(): int
{
return (int) static::max('numero') + 1;
}
}