feat: add previous configuration handling for user selections in quotes
- Implemented session storage management for the last configuration choices made by the user. - Added functionality to prompt users when changing models to retain their previous selections. - Introduced methods to apply previous choices to the newly loaded model, including finishes, handles, glass types, and options. - Enhanced user experience by ensuring selections are automatically applied where applicable.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* Geometria delle lastre di una tipologia: per ogni riga
|
||||
* LV = (L - detrazione_larghezza) / divisore, HV = H - detrazione_altezza, ripetuta `quantita` volte.
|
||||
* Es. F2: 2 x (L - 312) / 2; traslante anta + fisso: (L - 162) / 2 e (L - 362) / 2, cioè L/2 - 81 e L/2 - 181.
|
||||
*/
|
||||
class RegolaVetro extends Model
|
||||
{
|
||||
protected $table = 'regole_vetro';
|
||||
|
||||
protected $fillable = [
|
||||
'sistema_id', 'codice', 'descrizione', 'lastre', 'note',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'lastre' => 'array',
|
||||
];
|
||||
|
||||
public function sistema(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Sistema::class);
|
||||
}
|
||||
|
||||
public function modelli(): HasMany
|
||||
{
|
||||
return $this->hasMany(Modello::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Misure in mm delle lastre per un serramento L x H, senza arrotondamenti.
|
||||
*
|
||||
* @return array<int,array{descrizione:?string,quantita:int,larghezza:float,altezza:float}>
|
||||
*/
|
||||
public function calcolaLastre(float $larghezza, float $altezza): array
|
||||
{
|
||||
return array_map(fn (array $lastra) => [
|
||||
'descrizione' => $lastra['descrizione'] ?? null,
|
||||
'quantita' => max(1, (int) ($lastra['quantita'] ?? 1)),
|
||||
'larghezza' => ($larghezza - (float) ($lastra['detrazione_larghezza'] ?? 0)) / max(1, (float) ($lastra['divisore'] ?? 1)),
|
||||
'altezza' => $altezza - (float) ($lastra['detrazione_altezza'] ?? 0),
|
||||
], $this->lastre ?? []);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user