- 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.
80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Models\Impostazione;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Forms\Contracts\HasForms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
|
|
/**
|
|
* Regola base di scontistica: sconti massimi che ogni cliente può applicare al preventivo,
|
|
* salvo massimi personalizzati sulla sua scheda.
|
|
*
|
|
* @property Form $form
|
|
*/
|
|
class Scontistica extends Page implements HasForms
|
|
{
|
|
use InteractsWithForms;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-receipt-percent';
|
|
|
|
protected static ?string $navigationLabel = 'Scontistica';
|
|
|
|
protected static ?string $title = 'Scontistica globale';
|
|
|
|
protected static ?int $navigationSort = 3;
|
|
|
|
protected static string $view = 'filament.pages.scontistica';
|
|
|
|
/** @var array<string, mixed> */
|
|
public ?array $data = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->form->fill(Impostazione::scontiBase());
|
|
}
|
|
|
|
public function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->statePath('data')
|
|
->schema([
|
|
Forms\Components\Section::make('Regola base')
|
|
->description('Sconti massimi che i clienti possono applicare al preventivo prima dell\'invio: il 1° sull\'imponibile, lo sconto extra sul totale già scontato. Vale per tutti i clienti, salvo quelli con massimi personalizzati o sconti disabilitati nella loro scheda.')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\TextInput::make('max_1')
|
|
->label('1° sconto massimo')
|
|
->numeric()
|
|
->required()
|
|
->minValue(0)
|
|
->maxValue(100)
|
|
->step(0.01)
|
|
->suffix('%'),
|
|
Forms\Components\TextInput::make('max_2')
|
|
->label('Sconto extra massimo')
|
|
->numeric()
|
|
->required()
|
|
->minValue(0)
|
|
->maxValue(100)
|
|
->step(0.01)
|
|
->suffix('%'),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$dati = $this->form->getState();
|
|
|
|
Impostazione::imposta('sconti.max_1', (float) $dati['max_1']);
|
|
Impostazione::imposta('sconti.max_2', (float) $dati['max_2']);
|
|
|
|
Notification::make()->title('Scontistica salvata')->success()->send();
|
|
}
|
|
}
|