1
0
forked from poc/pds

Updated navigation order and filter report and Added export pdf func.

This commit is contained in:
dhanabalan
2025-04-28 00:22:44 +05:30
parent a6b9f88101
commit 79b889ec39

View File

@@ -2,6 +2,7 @@
namespace App\Filament\Resources; namespace App\Filament\Resources;
use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
use App\Filament\Exports\ProductionLineStopExporter; use App\Filament\Exports\ProductionLineStopExporter;
use App\Filament\Imports\ProductionLineStopImporter; use App\Filament\Imports\ProductionLineStopImporter;
use App\Filament\Resources\ProductionLineStopResource\Pages; use App\Filament\Resources\ProductionLineStopResource\Pages;
@@ -39,6 +40,8 @@ class ProductionLineStopResource extends Resource
protected static ?string $navigationGroup = 'Production'; protected static ?string $navigationGroup = 'Production';
protected static ?int $navigationSort = 2;
public static function form(Form $form): Form public static function form(Form $form): Form
{ {
@@ -343,6 +346,7 @@ class ProductionLineStopResource extends Resource
public static function table(Table $table): Table public static function table(Table $table): Table
{ {
return $table return $table
->query(ProductionLineStop::query())
->columns([ ->columns([
Tables\Columns\TextColumn::make('id') Tables\Columns\TextColumn::make('id')
->label('ID') ->label('ID')
@@ -456,14 +460,14 @@ class ProductionLineStopResource extends Resource
TextInput::make('Line Stop Code'), TextInput::make('Line Stop Code'),
Select::make('reason') // Select::make('reason')
->label('Filter by Stop Reason') // ->label('Filter by Stop Reason')
->options(function () { // ->options(function () {
return \App\Models\Item::whereHas('stickerMasters', function ($query) { // return \App\Models\Item::whereHas('stickerMasters', function ($query) {
$query->whereHas('qualityValidations'); // $query->whereHas('qualityValidations');
})->pluck('code', 'id'); // })->pluck('code', 'id');
}) // })
->searchable(), // ->searchable(),
DateTimePicker::make(name: 'created_from') DateTimePicker::make(name: 'created_from')
->label('Created From') ->label('Created From')
@@ -474,8 +478,59 @@ class ProductionLineStopResource extends Resource
->label('Created To') ->label('Created To')
->reactive() ->reactive()
->native(false), ->native(false),
]), ])
->query(function ($query, array $data) {
if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $plant);
}
// Filter by Shift
if ($shift = $data['Shift'] ?? null) {
// Get shift data here, if needed, but no block_id filtering yet
$query->where('shift_id', $shift);
}
if ($block = $data['Block'] ?? null) {
// Use whereHas to filter by block_id in the Shift table
$query->whereHas('shift', function ($query) use ($block) {
$query->where('block_id', $block);
});
}
if ($line = $data['line'] ?? null) {
$query->where('line_id', $line);
}
if ($code = $data['Line Stop Code'] ?? null) {
// Find the linestop_id by code entered
$lineStop = \App\Models\LineStop::where('code', 'like', "%{$code}%")->first();
// If we find a matching LineStop, use its id to filter production_line_stops
if ($lineStop) {
$query->where('linestop_id', $lineStop->id);
} else {
// If no match found, you can either handle it as an error or return no results
$query->where('linestop_id', null); // This will return no results if no match
}
}
if ($reason = $data['reason'] ?? null) {
$query->where('reason_id', $reason);
}
if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from);
}
if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to);
}
return $query;
})
]) ])
->filtersFormMaxHeight('280px') ->filtersFormMaxHeight('280px')
->actions([ ->actions([
Tables\Actions\ViewAction::make(), Tables\Actions\ViewAction::make(),
@@ -486,6 +541,7 @@ class ProductionLineStopResource extends Resource
Tables\Actions\DeleteBulkAction::make(), Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(), Tables\Actions\RestoreBulkAction::make(),
FilamentExportBulkAction::make('export')
]), ]),
]) ])
->headerActions([ ->headerActions([