diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index 8480737..49618d4 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; @@ -120,14 +117,13 @@ public static function table(Table $table): Table 'success' => ApplicationStatus::TableAccepted->value, 'danger' => ApplicationStatus::Canceled->value ]), - Tables\Columns\TextColumn::make('requestedTable.name'), - // 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('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')->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/Application.php b/app/Models/Application.php index 0e0ca26..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 @@ -361,14 +379,21 @@ 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) { - 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 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 ]); } }