Files
pds/app/Filament/Pages/InvoiceDashboard.php
dhanabalan 25cfaa6479
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
Added from date and to date in invoice chart dashboard
2026-05-11 10:53:41 +05:30

100 lines
3.4 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Illuminate\Support\Facades\Auth;
use Filament\Forms\Components\DatePicker;
class InvoiceDashboard extends Page
{
use HasFiltersForm;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static ?string $navigationGroup = 'Invoice DashBoard';
protected static string $view = 'filament.pages.invoice-dashboard';
public function mount(): void
{
session()->forget(['selec_plant', 'select_invoice']);
session()->forget(['from_date']);
session()->forget(['to_date']);
$this->filtersForm->fill([
'plant' => null,
'invoice' => null,
'from_date' => null,
'to_date' => null,
]);
}
public function filtersForm(Form $form): Form
{
return $form
->statePath('filters') // Explicitly set where to store form data
->schema([
Select::make('plant')
->label('Select Plant')
//->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();
})
->reactive()
->afterStateUpdated(function ($state) {
session(['selec_plant' => $state]);
$this->dispatch('invoiceChart');
}),
Select::make('invoice')
->options([
'serial_invoice' => 'Serial Invoice',
'individual_material' => 'Individual Material Invoice',
'bundle_material' => 'Bundle Material Invoice',
])
->label('Select Invoice')
->reactive()
->default(0)
->afterStateUpdated(function ($state) {
session(['select_invoice' => $state]);
$this->dispatch('invoiceChart');
}),
DatePicker::make('created_from')
->label('Created From')
->reactive()
->afterStateUpdated(function ($state,callable $set) {
session(['from_date' => $state]);
$this->dispatch('invoiceChart');
}),
DatePicker::make('created_to')
->label('Created To')
->reactive()
->afterStateUpdated(function ($state,callable $set) {
session(['to_date' => $state]);
$this->dispatch('invoiceChart');
}),
])
->columns(4);
}
public static function getNavigationLabel(): string
{
return 'Invoice';
}
public static function canAccess(): bool
{
return Auth::check() && Auth::user()->can('view invoice dashboard');
}
}