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:
@@ -4,6 +4,7 @@ namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\ClienteResource\Pages;
|
||||
use App\Models\Cliente;
|
||||
use App\Models\Impostazione;
|
||||
use App\Support\ClienteCredenziali;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
@@ -63,6 +64,36 @@ class ClienteResource extends Resource
|
||||
? 'Generata automaticamente. Ricordati di copiarla dopo il salvataggio: non sarà più leggibile.'
|
||||
: 'Lascia vuoto per mantenere la password attuale, oppure genera/inserisci una nuova password.'),
|
||||
]),
|
||||
Forms\Components\Section::make('Scontistica')
|
||||
->description(fn () => sprintf(
|
||||
'Sconti che il cliente può applicare al preventivo prima dell\'invio. Lascia vuoto per la regola base (1° sconto fino al %s%%, sconto extra fino al %s%% sul totale già scontato).',
|
||||
static::percentuale(Impostazione::scontiBase()['max_1']),
|
||||
static::percentuale(Impostazione::scontiBase()['max_2']),
|
||||
))
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\Toggle::make('sconti_abilitati')
|
||||
->label('Può applicare sconti')
|
||||
->default(true)
|
||||
->live()
|
||||
->columnSpanFull(),
|
||||
Forms\Components\TextInput::make('sconto_max_1')
|
||||
->label('1° sconto massimo')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(100)
|
||||
->suffix('%')
|
||||
->placeholder(fn () => static::percentuale(Impostazione::scontiBase()['max_1']).' (regola base)')
|
||||
->visible(fn (Forms\Get $get) => (bool) $get('sconti_abilitati')),
|
||||
Forms\Components\TextInput::make('sconto_max_2')
|
||||
->label('Sconto extra massimo')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(100)
|
||||
->suffix('%')
|
||||
->placeholder(fn () => static::percentuale(Impostazione::scontiBase()['max_2']).' (regola base)')
|
||||
->visible(fn (Forms\Get $get) => (bool) $get('sconti_abilitati')),
|
||||
]),
|
||||
Forms\Components\Section::make('Anagrafica')
|
||||
->description('Campi facoltativi.')
|
||||
->columns(2)
|
||||
@@ -124,6 +155,19 @@ class ClienteResource extends Resource
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('username')->label('Nome utente')->copyable()->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('created_at')->label('Cliente dal')->dateTime('d/m/Y H:i'),
|
||||
Infolists\Components\TextEntry::make('scontistica')
|
||||
->label('Scontistica')
|
||||
->state(function (Cliente $record): string {
|
||||
if (! $record->sconti_abilitati) {
|
||||
return 'Disabilitata';
|
||||
}
|
||||
$massimi = $record->scontiMassimi();
|
||||
$base = $record->sconto_max_1 === null && $record->sconto_max_2 === null ? ' (regola base)' : '';
|
||||
|
||||
return sprintf('Fino al %s%% + extra fino al %s%%%s',
|
||||
static::percentuale($massimi['max_1']), static::percentuale($massimi['max_2']), $base);
|
||||
})
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Infolists\Components\Section::make('Anagrafica')
|
||||
->columns(3)
|
||||
@@ -140,6 +184,12 @@ class ClienteResource extends Resource
|
||||
]);
|
||||
}
|
||||
|
||||
/** 50.00 -> "50", 12.50 -> "12,5" */
|
||||
private static function percentuale(mixed $valore): string
|
||||
{
|
||||
return rtrim(rtrim(number_format((float) $valore, 2, ',', ''), '0'), ',');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user