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;
use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
use App\Filament\Exports\ProductionLineStopExporter;
use App\Filament\Imports\ProductionLineStopImporter;
use App\Filament\Resources\ProductionLineStopResource\Pages;
@@ -39,6 +40,8 @@ class ProductionLineStopResource extends Resource
protected static ?string $navigationGroup = 'Production';
protected static ?int $navigationSort = 2;
public static function form(Form $form): Form
{
@@ -343,6 +346,7 @@ class ProductionLineStopResource extends Resource
public static function table(Table $table): Table
{
return $table
->query(ProductionLineStop::query())
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
@@ -456,14 +460,14 @@ class ProductionLineStopResource extends Resource
TextInput::make('Line Stop Code'),
Select::make('reason')
->label('Filter by Stop Reason')
->options(function () {
return \App\Models\Item::whereHas('stickerMasters', function ($query) {
$query->whereHas('qualityValidations');
})->pluck('code', 'id');
})
->searchable(),
// Select::make('reason')
// ->label('Filter by Stop Reason')
// ->options(function () {
// return \App\Models\Item::whereHas('stickerMasters', function ($query) {
// $query->whereHas('qualityValidations');
// })->pluck('code', 'id');
// })
// ->searchable(),
DateTimePicker::make(name: 'created_from')
->label('Created From')
@@ -474,8 +478,59 @@ class ProductionLineStopResource extends Resource
->label('Created To')
->reactive()
->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')
->actions([
Tables\Actions\ViewAction::make(),
@@ -486,6 +541,7 @@ class ProductionLineStopResource extends Resource
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
FilamentExportBulkAction::make('export')
]),
])
->headerActions([