From 91ed476cd8a694749c5909a97e83586b05511ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Parient=C3=A9?= Date: Tue, 16 Jun 2026 22:16:54 +0200 Subject: [PATCH] feat(fares): add auto-pricing settings Seed fares.auto_price (opt-in toggle, default off) and fares.low_cost_multiplier, with an idempotent data migration for existing installs. Render float-typed settings as numeric inputs on the Settings page. --- app/Filament/Pages/Settings.php | 2 +- ...16_000002_add_auto_fare_price_settings.php | 78 +++++++++++++++++++ database/seeders/SettingsSeeder.php | 20 +++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 database/migrations_data/2026_06_16_000002_add_auto_fare_price_settings.php diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index 532d503e..c7951536 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -191,7 +191,7 @@ class Settings extends Page ->integer(); } - if ($setting->type === 'number') { + if ($setting->type === 'number' || $setting->type === 'float') { return TextInput::make($setting->key) ->label($setting->name) ->helperText($setting->description) diff --git a/database/migrations_data/2026_06_16_000002_add_auto_fare_price_settings.php b/database/migrations_data/2026_06_16_000002_add_auto_fare_price_settings.php new file mode 100644 index 00000000..a8a9d130 --- /dev/null +++ b/database/migrations_data/2026_06_16_000002_add_auto_fare_price_settings.php @@ -0,0 +1,78 @@ + + */ + private array $settings = [ + [ + 'key' => 'fares.auto_price', + 'name' => 'Automatic fare pricing', + 'group' => 'fares', + 'value' => 'false', + 'type' => 'boolean', + 'options' => 'true,false', + 'description' => 'Compute PIREP fare prices from distance, seat category and airline type instead of using the configured fare/subfleet/flight prices', + ], + [ + 'key' => 'fares.low_cost_multiplier', + 'name' => 'Low-cost airline multiplier', + 'group' => 'fares', + 'value' => '0.8', + 'type' => 'float', + 'options' => '', + 'description' => 'Multiplier applied to the automatic fare price when the PIREP airline is flagged as low cost', + ], + ]; + + public function up(): void + { + if (!Schema::hasTable('settings')) { + return; + } + + foreach ($this->settings as $setting) { + $id = Setting::formatKey($setting['key']); + + if (Setting::where('id', $id)->exists()) { + continue; + } + + // id is not auto-derived from the key on create (the accessor is + // read-only and the model does not auto-increment), so set it + // explicitly the same way SettingsSeeder does. + $model = new Setting([ + 'key' => $setting['key'], + 'name' => $setting['name'], + 'value' => $setting['value'], + 'group' => $setting['group'], + 'type' => $setting['type'], + 'options' => $setting['options'], + 'description' => $setting['description'], + ]); + $model->id = $id; + $model->default = $setting['value']; + $model->save(); + } + } + + public function down(): void + { + if (!Schema::hasTable('settings')) { + return; + } + + foreach ($this->settings as $setting) { + Setting::where('id', Setting::formatKey($setting['key']))->delete(); + } + } +}; diff --git a/database/seeders/SettingsSeeder.php b/database/seeders/SettingsSeeder.php index f412cd1d..b7566d2d 100644 --- a/database/seeders/SettingsSeeder.php +++ b/database/seeders/SettingsSeeder.php @@ -786,6 +786,26 @@ class SettingsSeeder extends Seeder 'description' => 'Send out a discord notification when a pirep is filed', ], + // Fares + [ + 'key' => 'fares.auto_price', + 'name' => 'Automatic fare pricing', + 'group' => 'fares', + 'value' => 'false', + 'type' => 'boolean', + 'options' => 'true,false', + 'description' => 'Compute PIREP fare prices from distance, seat category and airline type instead of using the configured fare/subfleet/flight prices', + ], + [ + 'key' => 'fares.low_cost_multiplier', + 'name' => 'Low-cost airline multiplier', + 'group' => 'fares', + 'value' => '0.8', + 'type' => 'float', + 'options' => '', + 'description' => 'Multiplier applied to the automatic fare price when the PIREP airline is flagged as low cost', + ], + // Cron [ 'key' => 'cron.random_id',