From 4748e65ebe65dfda526bb13a652b64729160050a Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 18 May 2023 00:27:51 +0200 Subject: [PATCH 1/7] fix isReady not ignoring canceled regs --- app/Models/Application.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Models/Application.php b/app/Models/Application.php index 0e0ca26..35810ea 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -368,7 +368,10 @@ public function isReady(): bool } foreach ($dealership->children()->get() as $child) { - if ($child->status !== ApplicationStatus::Canceled && $child->status !== $dealership->status) { + if($child->status === ApplicationStatus::Canceled) { + continue; + } + if ($child->status !== $dealership->status) { return false; } // table numbers must be identical From c80a7ec1ab9a02f542eafd220c451fc4aa4b4263 Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 18 May 2023 00:55:49 +0200 Subject: [PATCH 2/7] fix Dealers with table number but without assigned table being ready --- app/Models/Application.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Models/Application.php b/app/Models/Application.php index 35810ea..fe3ac64 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -361,10 +361,14 @@ public function isReady(): bool return false; } - if ($this->type !== ApplicationType::Dealer) { - $dealership = $this->parent()->get()->first(); - } else { + if ($this->type === ApplicationType::Dealer) { $dealership = $this; + } else { + $dealership = $this->parent()->get()->first(); + } + + if (!empty($dealership->table_number) && $dealership->table_type_assigned === null) { + return false; } foreach ($dealership->children()->get() as $child) { From 844cbfcc815bd0b1283e98be897115253f8d6de0 Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 18 May 2023 00:59:01 +0200 Subject: [PATCH 3/7] highlight when assigned != requested table --- app/Filament/Resources/ApplicationResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index 8480737..aec5e6b 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -120,7 +120,7 @@ public static function table(Table $table): Table 'success' => ApplicationStatus::TableAccepted->value, 'danger' => ApplicationStatus::Canceled->value ]), - Tables\Columns\TextColumn::make('requestedTable.name'), + Tables\Columns\TextColumn::make('requestedTable.name')->icon(fn($record) => $record->table_type_requested !== $record->table_type_assigned ? 'heroicon-o-exclamation' : '')->iconPosition('after')->color(fn($record) => $record->table_type_requested !== $record->table_type_assigned ? 'warning' : ''), // FIXME: It is currently not possible to select 'null' to clear the assigned table here, therefore placeholder selection has been disabled. Tables\Columns\SelectColumn::make('table_type_assigned')->options(TableType::pluck('name', 'id')->toArray())->disablePlaceholderSelection(), Tables\Columns\TextColumn::make('type')->formatStateUsing(function (string $state) { From 248706390c5c4edefd339faa0e6ebb5e6d8e81f9 Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 18 May 2023 01:02:45 +0200 Subject: [PATCH 4/7] fix placeholder option being removed entirely for assigned table column (reintroduces exception when selecting placeholder) --- app/Filament/Resources/ApplicationResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index aec5e6b..b209cbe 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -122,7 +122,7 @@ public static function table(Table $table): Table ]), Tables\Columns\TextColumn::make('requestedTable.name')->icon(fn($record) => $record->table_type_requested !== $record->table_type_assigned ? 'heroicon-o-exclamation' : '')->iconPosition('after')->color(fn($record) => $record->table_type_requested !== $record->table_type_assigned ? 'warning' : ''), // FIXME: It is currently not possible to select 'null' to clear the assigned table here, therefore placeholder selection has been disabled. - Tables\Columns\SelectColumn::make('table_type_assigned')->options(TableType::pluck('name', 'id')->toArray())->disablePlaceholderSelection(), + Tables\Columns\SelectColumn::make('table_type_assigned')->options(TableType::pluck('name', 'id')->toArray()), Tables\Columns\TextColumn::make('type')->formatStateUsing(function (string $state) { return ucfirst($state); })->sortable(), From 08b51687ec4d203a19e8486647d892e54cc77250 Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 18 May 2023 01:04:54 +0200 Subject: [PATCH 5/7] highlight table mismatch only on Dealer --- app/Filament/Resources/ApplicationResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index b209cbe..c7776b4 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -120,7 +120,7 @@ public static function table(Table $table): Table 'success' => ApplicationStatus::TableAccepted->value, 'danger' => ApplicationStatus::Canceled->value ]), - Tables\Columns\TextColumn::make('requestedTable.name')->icon(fn($record) => $record->table_type_requested !== $record->table_type_assigned ? 'heroicon-o-exclamation' : '')->iconPosition('after')->color(fn($record) => $record->table_type_requested !== $record->table_type_assigned ? 'warning' : ''), + Tables\Columns\TextColumn::make('requestedTable.name')->icon(fn($record) => $record->type === ApplicationType::Dealer && $record->table_type_requested !== $record->table_type_assigned ? 'heroicon-o-exclamation' : '')->iconPosition('after')->color(fn($record) => $record->type === ApplicationType::Dealer && $record->table_type_requested !== $record->table_type_assigned ? 'warning' : ''), // FIXME: It is currently not possible to select 'null' to clear the assigned table here, therefore placeholder selection has been disabled. Tables\Columns\SelectColumn::make('table_type_assigned')->options(TableType::pluck('name', 'id')->toArray()), Tables\Columns\TextColumn::make('type')->formatStateUsing(function (string $state) { From 4801858663bc3235671426619e42304d89fa633e Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 18 May 2023 01:35:27 +0200 Subject: [PATCH 6/7] workaround for clearing assigned table in overview --- app/Filament/Resources/ApplicationResource.php | 6 +----- app/Models/Application.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index c7776b4..8ebfd80 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -10,9 +10,6 @@ use App\Http\Controllers\Applications\ApplicationController; use App\Models\Application; use App\Models\TableType; -use App\Notifications\AcceptedNotification; -use App\Notifications\OnHoldNotification; -use App\Notifications\WaitingListNotification; use Filament\Forms; use Filament\Notifications\Notification; use Filament\Resources\Form; @@ -121,8 +118,7 @@ public static function table(Table $table): Table 'danger' => ApplicationStatus::Canceled->value ]), Tables\Columns\TextColumn::make('requestedTable.name')->icon(fn($record) => $record->type === ApplicationType::Dealer && $record->table_type_requested !== $record->table_type_assigned ? 'heroicon-o-exclamation' : '')->iconPosition('after')->color(fn($record) => $record->type === ApplicationType::Dealer && $record->table_type_requested !== $record->table_type_assigned ? 'warning' : ''), - // FIXME: It is currently not possible to select 'null' to clear the assigned table here, therefore placeholder selection has been disabled. - Tables\Columns\SelectColumn::make('table_type_assigned')->options(TableType::pluck('name', 'id')->toArray()), + Tables\Columns\SelectColumn::make('tableTypeAssignedAutoNull')->options(TableType::pluck('name', 'id')->toArray()), Tables\Columns\TextColumn::make('type')->formatStateUsing(function (string $state) { return ucfirst($state); })->sortable(), diff --git a/app/Models/Application.php b/app/Models/Application.php index fe3ac64..82463c3 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -4,6 +4,7 @@ use App\Enums\ApplicationStatus; use App\Enums\ApplicationType; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Log; @@ -43,6 +44,7 @@ class Application extends Model protected static function boot() { parent::boot(); + // Automatically update application status from Waiting to TableAssigned on table type/number change // to allow accepting waiting dealerships via table assignment static::updating(function (Application $model) { @@ -350,6 +352,22 @@ public static function getAllApplicationsForExport() return json_decode(json_encode($applications), true); } + /** + * Sets table_type_assigned to `null` if input value is empty, converts to integer otherwise. + * + * Hacky fix for issues with selecting the placeholder in Filament\Tables\Columns\SelectColumn, + * which will attempt to set the int field 'table_type_assigned' to '' instead of null and + * triggers an exception in the process instead of storing the value. + */ + public function tableTypeAssignedAutoNull(): Attribute { + return Attribute::make( + get: fn (int|null $value, array $attributes) => $attributes['table_type_assigned'], + set: fn (mixed $value) => [ + 'table_type_assigned' => empty($value) ? null : intval($value), + ] + ); + } + /** * An application is considered ready if all related applications (parent/children) share the * same status (canceled child applications are ignored for this) and table number and the From afda5a4ee8c1c73bb25c8044d56514f4d7824f44 Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 18 May 2023 01:45:03 +0200 Subject: [PATCH 7/7] fix column labels on applications list --- app/Filament/Resources/ApplicationResource.php | 4 ++-- app/Models/User.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index 8ebfd80..49618d4 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -118,12 +118,12 @@ public static function table(Table $table): Table 'danger' => ApplicationStatus::Canceled->value ]), Tables\Columns\TextColumn::make('requestedTable.name')->icon(fn($record) => $record->type === ApplicationType::Dealer && $record->table_type_requested !== $record->table_type_assigned ? 'heroicon-o-exclamation' : '')->iconPosition('after')->color(fn($record) => $record->type === ApplicationType::Dealer && $record->table_type_requested !== $record->table_type_assigned ? 'warning' : ''), - Tables\Columns\SelectColumn::make('tableTypeAssignedAutoNull')->options(TableType::pluck('name', 'id')->toArray()), + Tables\Columns\SelectColumn::make('tableTypeAssignedAutoNull')->label('Assigned table')->options(TableType::pluck('name', 'id')->toArray()), Tables\Columns\TextColumn::make('type')->formatStateUsing(function (string $state) { return ucfirst($state); })->sortable(), Tables\Columns\TextInputColumn::make('table_number')->sortable()->searchable(), - Tables\Columns\IconColumn::make('is_ready')->getStateUsing(function (Application $record) { + Tables\Columns\IconColumn::make('is_ready')->label('Ready')->getStateUsing(function (Application $record) { return $record->isReady(); })->boolean(), Tables\Columns\TextColumn::make('dlrshp')->getStateUsing(function (Application $record) { diff --git a/app/Models/User.php b/app/Models/User.php index 2e91925..80e9a44 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -55,7 +55,8 @@ public function canAccessFilament(): bool "QL89R6583KNDG3WJ", // ??? "M728WGE7ZJKJVO63", // ??? "QL89R6580XKNDG3W", // Pattarchus(?) - "1243MK1XZWKXWJ68" // Jul + "1243MK1XZWKXWJ68", // Jul + "QL89R65833KNDG3W", // Fenrikur ]); } }