Added GuardPatrolEntry Dashboard and Added masters with transaction Policy
This commit is contained in:
108
app/Filament/Pages/GuardPatrolEntryDashboard.php
Normal file
108
app/Filament/Pages/GuardPatrolEntryDashboard.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\GuardPatrolEntry;
|
||||
use App\Models\Plant;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class GuardPatrolEntryDashboard extends Page
|
||||
{
|
||||
use HasFiltersForm;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static ?string $navigationGroup = 'Guard DashBoard';
|
||||
|
||||
protected static string $view = 'filament.pages.guard-patrol-entry-dashboard';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
session()->forget(['select_guard_plant', 'select_guard_date']);
|
||||
$this->filtersForm->fill([
|
||||
'plant' => null,
|
||||
'date' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function filtersForm(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters') // Explicitly set where to store form data
|
||||
->schema([
|
||||
Select::make('plant')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Select Plant')
|
||||
->reactive()
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get){
|
||||
// $this->dispatch('invoiceChart');
|
||||
if(!$state)
|
||||
{
|
||||
$set('date', now()->format('Y-m-d')); // H:i:s
|
||||
session(['select_guard_plant' => $state]);
|
||||
session(['select_guard_date' => $get('date')]);
|
||||
} else {
|
||||
if(!$get('date'))
|
||||
{
|
||||
$set('date', now()->format('Y-m-d'));
|
||||
session(['select_guard_plant' => $state]);
|
||||
session(['select_guard_date' => $get('date')]);
|
||||
} else {
|
||||
session(['select_guard_plant' => $state]);
|
||||
session(['select_guard_date' => $get('date')]);
|
||||
}
|
||||
}
|
||||
$this->dispatch('loadGuardData', $state, $get('date')); //->format('Y-m-d')
|
||||
}),
|
||||
DatePicker::make('date')
|
||||
->label('Select Date')
|
||||
->placeholder('Select Date')
|
||||
->reactive()
|
||||
->required()
|
||||
->beforeOrEqual(now())
|
||||
->default(now()->format('Y-m-d'))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get){
|
||||
if(!$get('plant'))
|
||||
{
|
||||
$set('date', now()->format('Y-m-d'));
|
||||
session(['select_guard_plant' => $get('plant')]);
|
||||
session(['select_guard_date' => $state]);
|
||||
} else {
|
||||
if(!$get('date'))
|
||||
{
|
||||
$set('date', now()->format('Y-m-d'));
|
||||
session(['select_guard_plant' => $get('plant')]);
|
||||
session(['select_guard_date' => $state]);
|
||||
} else {
|
||||
$records = GuardPatrolEntry::whereDate('patrol_time', $state)->where('plant_id', $get('plant'))->orderBy('patrol_time', 'asc')->first(); //desc
|
||||
//dd($get('plant'), $state, $records->patrol_time);//->toTimeString()
|
||||
session(['select_guard_plant' => $get('plant')]);
|
||||
session(['select_guard_date' => $state]);
|
||||
}
|
||||
}
|
||||
// $this->dispatch('invoiceChart');
|
||||
$this->dispatch('loadGuardData', $get('plant'), $state);//->format('Y-m-d')
|
||||
})
|
||||
])
|
||||
->columns(2);
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Guard Patrol Entry';
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view guard patrol entry dashboard');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user