changed logici n production mail report
This commit is contained in:
@@ -5,8 +5,11 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Resources\AlertMailRuleResource\Pages;
|
||||
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
|
||||
use App\Models\AlertMailRule;
|
||||
use App\Models\Plant;
|
||||
use Dotenv\Exception\ValidationException;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
@@ -14,6 +17,7 @@ use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Illuminate\Validation\ValidationException as ValidationValidationException;
|
||||
|
||||
class AlertMailRuleResource extends Resource
|
||||
{
|
||||
@@ -29,6 +33,13 @@ class AlertMailRuleResource extends Resource
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant')
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->options(fn () => Plant::pluck('name', 'id')->toArray())
|
||||
->required(fn ($get) => ! $get('is_active'))
|
||||
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
|
||||
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
|
||||
Forms\Components\Select::make('module')
|
||||
->label('Module')
|
||||
->required()
|
||||
@@ -56,15 +67,29 @@ class AlertMailRuleResource extends Resource
|
||||
'Hourly' => 'Hourly',
|
||||
'Daily' => 'Daily',
|
||||
]),
|
||||
Checkbox::make('is_active')
|
||||
->label('All Plants Reports')
|
||||
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
|
||||
->reactive(),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->default(fn () => Filament::auth()->user()?->name),
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->default(fn () => Filament::auth()->user()?->name),
|
||||
])
|
||||
->columns(4),
|
||||
->columns(5),
|
||||
]);
|
||||
}
|
||||
|
||||
// Optionally, also override for update/editing
|
||||
// public static function mutateFormDataBeforeSave(array $data): array
|
||||
// {
|
||||
// dd('test');
|
||||
// if ($data['is_active']) {
|
||||
// $data['plant'] = 'All Plants';
|
||||
// }
|
||||
// return $data;
|
||||
// }
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
@@ -73,6 +98,16 @@ class AlertMailRuleResource extends Resource
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant')
|
||||
->label('Plant')
|
||||
->sortable()
|
||||
->formatStateUsing(function ($state) {
|
||||
static $plants;
|
||||
if (! $plants) {
|
||||
$plants = Plant::pluck('name', 'id')->toArray();
|
||||
}
|
||||
return $plants[$state] ?? 'All Plants';
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('module')
|
||||
->label('Module')
|
||||
->sortable(),
|
||||
|
||||
Reference in New Issue
Block a user