Removed searchable func. and added filters func. to view report
This commit is contained in:
@@ -6,6 +6,7 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
|
|||||||
use App\Filament\Exports\InvoiceValidationExporter;
|
use App\Filament\Exports\InvoiceValidationExporter;
|
||||||
use App\Filament\Resources\InvoiceValidationResource\Pages;
|
use App\Filament\Resources\InvoiceValidationResource\Pages;
|
||||||
use App\Models\InvoiceValidation;
|
use App\Models\InvoiceValidation;
|
||||||
|
use App\Models\Item;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\StickerMaster;
|
use App\Models\StickerMaster;
|
||||||
use Auth;
|
use Auth;
|
||||||
@@ -14,6 +15,7 @@ use Filament\Actions\CreateAction;
|
|||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Components\Actions\Action as ActionsAction;
|
use Filament\Forms\Components\Actions\Action as ActionsAction;
|
||||||
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
use Filament\Forms\Components\FileUpload;
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
@@ -30,6 +32,7 @@ use Filament\Forms\Components\View;
|
|||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Tables\Actions\Action;
|
use Filament\Tables\Actions\Action;
|
||||||
use Filament\Tables\Actions\ExportAction;
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
@@ -193,6 +196,7 @@ class InvoiceValidationResource extends Resource
|
|||||||
public static function table(Table $table): Table
|
public static function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
|
->query(InvoiceValidation::query())
|
||||||
->columns([
|
->columns([
|
||||||
Tables\Columns\TextColumn::make('id')
|
Tables\Columns\TextColumn::make('id')
|
||||||
->label('ID')
|
->label('ID')
|
||||||
@@ -200,16 +204,13 @@ class InvoiceValidationResource extends Resource
|
|||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('invoice_number')
|
Tables\Columns\TextColumn::make('invoice_number')
|
||||||
->label('Invoice Number')
|
->label('Invoice Number')
|
||||||
->sortable()
|
->sortable(), //->searchable()
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('stickerMaster.item.code')
|
Tables\Columns\TextColumn::make('stickerMaster.item.code')
|
||||||
->label('Material Code')
|
->label('Material Code')
|
||||||
->sortable()
|
->sortable(), //->searchable()
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('serial_number')
|
Tables\Columns\TextColumn::make('serial_number')
|
||||||
->label('Serial Number')
|
->label('Serial Number')
|
||||||
->sortable()
|
->sortable(), //->searchable()
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('motor_scanned_status')
|
Tables\Columns\TextColumn::make('motor_scanned_status')
|
||||||
->label('Motor Scanned Status')
|
->label('Motor Scanned Status')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
@@ -267,7 +268,6 @@ class InvoiceValidationResource extends Resource
|
|||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
->headerActions([
|
->headerActions([
|
||||||
|
|
||||||
// Action::make('plant_id')
|
// Action::make('plant_id')
|
||||||
@@ -899,7 +899,122 @@ class InvoiceValidationResource extends Resource
|
|||||||
|
|
||||||
->filters([
|
->filters([
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
Filter::make('advanced_filters')
|
||||||
|
->label('Advanced Filters')
|
||||||
|
->form([
|
||||||
|
Select::make('Plant')
|
||||||
|
->label('Select Plant')
|
||||||
|
->nullable()
|
||||||
|
->options(function () {
|
||||||
|
return Plant::pluck('name', 'id');
|
||||||
|
})
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||||
|
$set('sticker_master_id', null);
|
||||||
|
}),
|
||||||
|
TextInput::make('invoice_number')
|
||||||
|
->label('Invoice Number')
|
||||||
|
->placeholder(placeholder: 'Enter Invoice Number'),
|
||||||
|
TextInput::make('serial_number')
|
||||||
|
->label('Serial Number')
|
||||||
|
->placeholder(placeholder: 'Enter Serial Number'),
|
||||||
|
Select::make('sticker_master_id')
|
||||||
|
->label('Search by Item Code')
|
||||||
|
->nullable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$pId = $get('Plant');
|
||||||
|
// if (empty($pId)) {
|
||||||
|
// return [];
|
||||||
|
// }
|
||||||
|
return Item::whereHas('stickerMasters', function ($query) use ($pId) {
|
||||||
|
if ($pId) {
|
||||||
|
$query->where('plant_id', $pId);
|
||||||
|
}
|
||||||
|
$query->whereHas('invoiceValidations');
|
||||||
|
})->pluck('code', 'id');
|
||||||
|
})
|
||||||
|
->searchable()
|
||||||
|
->reactive(),
|
||||||
|
DateTimePicker::make(name: 'created_from')
|
||||||
|
->label('Created From')
|
||||||
|
->placeholder(placeholder: 'Select From DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
DateTimePicker::make('created_to')
|
||||||
|
->label('Created To')
|
||||||
|
->placeholder(placeholder: 'Select To DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
])
|
])
|
||||||
|
->query(function ($query, array $data) {
|
||||||
|
// Hide all records initially if no filters are applied
|
||||||
|
if (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['sticker_master_id'])) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
|
||||||
|
$query->where('plant_id', $data['Plant']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['invoice_number'])) {
|
||||||
|
$query->where('invoice_number', 'like', '%' . $data['invoice_number'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['serial_number'])) {
|
||||||
|
$query->where('serial_number', 'like', '%' . $data['serial_number'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_from'])) {
|
||||||
|
$query->where('created_at', '>=', $data['created_from']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_to'])) {
|
||||||
|
$query->where('created_at', '<=', $data['created_to']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['sticker_master_id'])) {
|
||||||
|
$stickerMasterIds = StickerMaster::where('item_id', $data['sticker_master_id'])
|
||||||
|
->pluck('id')
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
if (!empty($stickerMasterIds)) {
|
||||||
|
$query->whereIn('sticker_master_id', $stickerMasterIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
|
if (!empty($data['Plant'])) {
|
||||||
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['invoice_number'])) {
|
||||||
|
$indicators[] = 'Invoice Number: ' . $data['invoice_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['serial_number'])) {
|
||||||
|
$indicators[] = 'Serial Number: ' . $data['serial_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_from'])) {
|
||||||
|
$indicators[] = 'From: ' . $data['created_from'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['created_to'])) {
|
||||||
|
$indicators[] = 'To: ' . $data['created_to'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($data['sticker_master_id'])) {
|
||||||
|
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
|
||||||
|
$indicators[] = 'Item Code: ' . $itemCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indicators;
|
||||||
|
})
|
||||||
|
|
||||||
|
])
|
||||||
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\ViewAction::make(),
|
Tables\Actions\ViewAction::make(),
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
|||||||
Reference in New Issue
Block a user