feat: implement discount and transport features in the quote system
- Added maximum discount settings configurable by the administrator. - Implemented discount calculations in the quote confirmation process. - Introduced transport options with associated costs, including handling for exceeding maximum piece limits. - Updated frontend to display discounts and transport information in the quote summary. - Created new database migrations for storing discount and transport settings. - Developed a new Filament page for managing global discount settings. - Enhanced email templates to include discount and transport details. - Added tests to ensure proper functionality of discounts and transport calculations.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Impostazione extends Model
|
||||
{
|
||||
protected $table = 'impostazioni';
|
||||
|
||||
protected $fillable = ['chiave', 'valore'];
|
||||
|
||||
protected $casts = [
|
||||
'valore' => 'json',
|
||||
];
|
||||
|
||||
private const CACHE_KEY = 'impostazioni';
|
||||
|
||||
/** Valore dell'impostazione, o $default se non è mai stata salvata. */
|
||||
public static function valore(string $chiave, mixed $default = null): mixed
|
||||
{
|
||||
$tutte = Cache::rememberForever(self::CACHE_KEY, fn () => static::query()->pluck('valore', 'chiave')->all());
|
||||
|
||||
return $tutte[$chiave] ?? $default;
|
||||
}
|
||||
|
||||
public static function imposta(string $chiave, mixed $valore): void
|
||||
{
|
||||
static::query()->updateOrCreate(['chiave' => $chiave], ['valore' => $valore]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regola base di scontistica (%), valida per i clienti senza massimi personalizzati:
|
||||
* quella salvata dall'amministratore, altrimenti config/preventivi.php.
|
||||
*
|
||||
* @return array{max_1:float,max_2:float}
|
||||
*/
|
||||
public static function scontiBase(): array
|
||||
{
|
||||
return [
|
||||
'max_1' => (float) static::valore('sconti.max_1', config('preventivi.sconti.max_1')),
|
||||
'max_2' => (float) static::valore('sconti.max_2', config('preventivi.sconti.max_2')),
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(fn () => Cache::forget(self::CACHE_KEY));
|
||||
static::deleted(fn () => Cache::forget(self::CACHE_KEY));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user