From 80c65e6a32d9d3bab4d6c0ecb1febbc3f928e7eb Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 12 May 2025 19:16:40 +0530 Subject: [PATCH] Added sap_msg_status, sap_msg_description columns in create page and Added uom column, report filter func. --- .../Resources/ProductionQuantityResource.php | 259 +++++++++++++++++- 1 file changed, 246 insertions(+), 13 deletions(-) diff --git a/app/Filament/Resources/ProductionQuantityResource.php b/app/Filament/Resources/ProductionQuantityResource.php index eed794b83..622da3546 100644 --- a/app/Filament/Resources/ProductionQuantityResource.php +++ b/app/Filament/Resources/ProductionQuantityResource.php @@ -8,12 +8,16 @@ use App\Filament\Imports\ProductionQuantityImporter; use App\Filament\Resources\ProductionQuantityResource\Pages; use App\Filament\Resources\ProductionQuantityResource\RelationManagers; use App\Forms\Components\PlantSelect; +use App\Models\Block; use App\Models\Item; +use App\Models\Line; +use App\Models\Plant; use App\Models\ProductionQuantity; use App\Models\Shift; use Carbon\Carbon; use Filament\Facades\Filament; use Filament\Forms; +use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\Hidden; use Filament\Forms\Form; use Filament\Forms\Get; @@ -25,13 +29,14 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Filament\Forms\Components\Section; use Filament\Forms\Components\Select; +use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Notifications\Notification; use Filament\Tables\Actions\ExportAction; use Livewire\Livewire; // use Filament\Forms\Components\View; use Filament\Tables\Actions\FilamentExportBulkAction; - +use Filament\Tables\Filters\Filter; class ProductionQuantityResource extends Resource { @@ -129,7 +134,7 @@ class ProductionQuantityResource extends Resource return []; } - return \App\Models\Block::where('plant_id', $get('plant_id')) + return Block::where('plant_id', $get('plant_id')) ->pluck('name', 'id') ->toArray(); }) @@ -235,7 +240,7 @@ class ProductionQuantityResource extends Resource return []; } - return \App\Models\Line::where('plant_id', $get('plant_id')) + return Line::where('plant_id', $get('plant_id')) ->pluck('name', 'id') ->toArray(); }) @@ -895,8 +900,10 @@ class ProductionQuantityResource extends Resource ->required(), Forms\Components\Hidden::make('success_msg') ->required(), - Forms\Components\Hidden::make('item_code') + Forms\Components\Hidden::make('item_id') ->required(), + Forms\Components\Hidden::make('sap_msg_status'), + Forms\Components\Hidden::make('sap_msg_description'), //->unique(ignoreRecord: true), // ->autocapitalize('characters'), // ->columnSpanFull(), @@ -940,39 +947,265 @@ class ProductionQuantityResource extends Resource ->numeric() ->sortable(), Tables\Columns\TextColumn::make('production_order') - ->sortable() - ->searchable(), - Tables\Columns\TextColumn::make('item.code') - ->sortable() - ->searchable(), + ->label('Production Order') + ->sortable(),// ->searchable(), Tables\Columns\TextColumn::make('serial_number') - ->sortable() - ->searchable(), + ->label('Serial Number') + ->sortable(),// ->searchable(), + Tables\Columns\TextColumn::make('item.code') + ->label('Item Code') + ->sortable(),// ->searchable(), + Tables\Columns\TextColumn::make('item.uom') + ->alignCenter() + ->label('Unit of Measure'), Tables\Columns\TextColumn::make('line.name') + ->label('Line') ->sortable(), Tables\Columns\TextColumn::make('shift.name') + ->label('Shift') ->sortable(), Tables\Columns\TextColumn::make('plant.name') + ->label('Plant') ->sortable(), - Tables\Columns\TextColumn::make('operator_id') - ->label('Operator ID') + Tables\Columns\TextColumn::make('sap_msg_status') + ->label('SAP Message Status') + ->sortable(), + Tables\Columns\TextColumn::make('sap_msg_description') + ->label('SAP Message Description') ->sortable(), Tables\Columns\TextColumn::make('created_at') + ->label('Created At') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') + ->label('Updated At') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('deleted_at') + ->label('Deleted At') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('operator_id') + ->label('Operator ID') + ->sortable(), ]) ->filters([ Tables\Filters\TrashedFilter::make(), + Filter::make('advanced_filters') + ->label('Advanced Filters') + ->form([ + //plant + Select::make('Plant') + ->label('Select Plant') + ->nullable() + ->options(function () { + return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display + }) + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('Line', null); + $set('Block', null); + $set('Shift', null); + $set('Item', null); + $set('sap_msg_status', null); + }), + + //line + Select::make('Line') + ->label('Select line') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + + if (!$plantId ) { + return []; + } + return Line::where('plant_id', $plantId) + ->pluck('name', 'id'); + }) + ->reactive(), + + //block + Select::make('Block') + ->label('Select Block') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + + if (!$plantId ) { + return []; + } + return Block::where('plant_id', $get('Plant'))->pluck('name', 'id'); + }) + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('Shift', null); + }), + + //shift + Select::make('Shift') + ->label('Select Shift') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + $blockId = $get('Block'); + + if (!$plantId || !$blockId) { + return []; // Return empty if plant or block is not selected + } + + return Shift::where('plant_id', $plantId) + ->where('block_id', $blockId) + ->pluck('name', 'id'); + }) + ->reactive(), + + TextInput::make('production_order') + ->label('Production Order') + ->placeholder('Enter Production Order'), + + TextInput::make('serial_number') + ->label('Serial Number') + ->placeholder(placeholder: 'Enter Serial Number'), + + Select::make('Item') + ->label('Search by Item Code') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + + if (!$plantId ) { + return Item::distinct()->whereHas('productionQuantities')->pluck('code', 'id'); + } + else { + return Item::where('plant_id', $plantId)->whereHas('productionQuantities')->distinct()->pluck('code', 'id'); + } + // return Item::whereHas('stickerMasters', function ($query) use ($pId) { + // if ($pId) { + // $query->where('plant_id', $pId); + // } + // $query->whereHas('invoiceValidations'); + // })->pluck('code', 'id'); + }) + ->searchable() + ->reactive(), + + Select::make('sap_msg_status') + ->label('Select SAP Message Status') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + + if (!$plantId ) { + return ProductionQuantity::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status'); + } + else { + return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status'); + } + }) + // ->options(QualityValidation::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status')) + ->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) { + if (empty($data['Plant']) && empty($data['Shift']) && empty($data['Line']) && empty($data['production_order']) && empty($data['serial_number']) && empty($data['Item']) && empty($data['sap_msg_status']) && empty($data['created_from']) && empty($data['created_to'])) { + return $query->whereRaw('1 = 0'); + } + + if ($plant = $data['Plant'] ?? null) { + $query->where('plant_id', $plant); + } + + if ($shift = $data['Shift'] ?? null) { + $query->where('shift_id', $shift); + } + + if ($line = $data['Line'] ?? null) { + $query->where('line_id', $line); + } + + if (!empty($data['production_order'])) { + $query->where('production_order', 'like', '%' . $data['production_order'] . '%'); + } + + if (!empty($data['serial_number'])) { + $query->where('serial_number', 'like', '%' . $data['serial_number'] . '%'); + } + + if (!empty($data['Item'])) { + $query->where('item_id', $data['Item']); + } + + if (!empty($data['sap_msg_status'])) { + $query->where('sap_msg_status', $data['sap_msg_status']); + } + + if ($from = $data['created_from'] ?? null) { + $query->where('created_at', '>=', $from); + } + + if ($to = $data['created_to'] ?? null) { + $query->where('created_at', '<=', $to); + } + // return $query; + }) + ->indicateUsing(function (array $data) { + $indicators = []; + + if (!empty($data['Plant'])) { + $indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name'); + } + + if (!empty($data['Shift'])) { + $indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name'); + } + + if (!empty($data['Line'])) { + $indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name'); + } + + if (!empty($data['production_order'])) { + $indicators[] = 'Production Order: ' . $data['production_order']; + } + + if (!empty($data['serial_number'])) { + $indicators[] = 'Serial Number: ' . $data['serial_number']; + } + + if (!empty($data['Item'])) { + $indicators[] = 'Item Code: ' . Item::where('id', $data['Item'])->value('code'); + } + + if (!empty($data['sap_msg_status'])) { + $indicators[] = 'SAP Message Status: ' . $data['sap_msg_status']; + } + + if (!empty($data['created_from'])) { + $indicators[] = 'From: ' . $data['created_from']; + } + + if (!empty($data['created_to'])) { + $indicators[] = 'To: ' . $data['created_to']; + } + + return $indicators; + }) ]) + ->filtersFormMaxHeight('280px') ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(),