backoffice first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Cliente extends Model
|
||||
{
|
||||
protected $table = 'clienti';
|
||||
|
||||
protected $fillable = [
|
||||
'nome', 'cognome', 'ragione_sociale', 'email', 'telefono',
|
||||
'indirizzo', 'cap', 'citta', 'provincia', 'note',
|
||||
];
|
||||
|
||||
public function preventivi(): HasMany
|
||||
{
|
||||
return $this->hasMany(Preventivo::class);
|
||||
}
|
||||
|
||||
public function getNominativoAttribute(): string
|
||||
{
|
||||
if ($this->ragione_sociale) {
|
||||
return $this->ragione_sociale;
|
||||
}
|
||||
|
||||
return trim("{$this->nome} {$this->cognome}");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PreventivoItem extends Model
|
||||
{
|
||||
protected $table = 'preventivo_items';
|
||||
|
||||
protected $fillable = [
|
||||
'preventivo_id', 'sistema', 'type', 'nome_modello', 'larghezza', 'altezza',
|
||||
'quantita', 'prezzo_unitario', 'prezzo_totale', 'payload', 'immagine_path',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'payload' => 'array',
|
||||
'prezzo_unitario' => 'decimal:2',
|
||||
'prezzo_totale' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function preventivo(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Preventivo::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user