diff --git a/app/Filament/Pages/InvoiceDataDashboard.php b/app/Filament/Pages/InvoiceDataDashboard.php new file mode 100644 index 0000000..2fc648a --- /dev/null +++ b/app/Filament/Pages/InvoiceDataDashboard.php @@ -0,0 +1,111 @@ +forget(['selected_plant','dist_channel']); + $this->filtersForm->fill([ + 'plant' => null, + 'distribution_channel' => null, + ]); + } + + public function filtersForm(Form $form): Form + { + return $form + ->statePath('filters') // Store form state in 'filters' + ->schema([ + Section::make('') + ->schema([ + Select::make('plant') + ->label('Select Plant') + ->reactive() + // ->options(Plant::pluck('name', 'id')) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) + ->afterStateUpdated(function ($state,callable $set) { + session(['selected_plant' => $state]); + $set('distribution_channel', null); + session()->forget('distribution_channel'); + }), + Select::make('distribution_channel') + ->label('Distribution Channel') + ->options(function (callable $get) { + $plant = $get('plant'); + + if (!$plant) { + return []; + } + + $options = InvoiceDataValidation::where('plant_id', $plant) + ->whereNotNull('distribution_channel_desc') + ->where('distribution_channel_desc', '!=', '') + ->select('distribution_channel_desc') + ->distinct() + ->pluck('distribution_channel_desc', 'distribution_channel_desc') + ->toArray(); + + $hasEmpty = InvoiceDataValidation::where('plant_id', $plant) + ->where(function ($q) { + $q->whereNull('distribution_channel_desc') + ->orWhere('distribution_channel_desc', ''); + }) + ->exists(); + + if ($hasEmpty) { + $options['Challan'] = 'Challan'; + } + + return $options; + }) + ->afterStateUpdated(callback: function ($state,callable $set) { + session(['dist_channel' => $state]); + }) + ->reactive(), + ]) + ->columns(2), + ]); + } + + + public static function getNavigationLabel(): string + { + return 'Invoice Data Dashboard'; + } + + public function getHeading(): string + { + return 'Invoice Data Dashboard'; + } + + public static function canAccess(): bool + { + return Auth::check() && Auth::user()->can('view invoice data dashboard'); + } + + + +} diff --git a/resources/views/filament/pages/invoice-data-dashboard.blade.php b/resources/views/filament/pages/invoice-data-dashboard.blade.php new file mode 100644 index 0000000..04834de --- /dev/null +++ b/resources/views/filament/pages/invoice-data-dashboard.blade.php @@ -0,0 +1,13 @@ + +
+ {{-- Render the Select form fields --}} +
+ {{ $this->filtersForm($this->form) }} +
+ + {{-- Render the chart widget below the form --}} +
+ @livewire(\App\Filament\Widgets\InvoiceDataChart::class) +
+
+