Added sap_msg_status, sap_msg_description columns in create page and Added uom column, report filter func.

This commit is contained in:
dhanabalan
2025-05-12 19:16:40 +05:30
parent e6563c9e31
commit 80c65e6a32

View File

@@ -8,12 +8,16 @@ use App\Filament\Imports\ProductionQuantityImporter;
use App\Filament\Resources\ProductionQuantityResource\Pages; use App\Filament\Resources\ProductionQuantityResource\Pages;
use App\Filament\Resources\ProductionQuantityResource\RelationManagers; use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
use App\Forms\Components\PlantSelect; use App\Forms\Components\PlantSelect;
use App\Models\Block;
use App\Models\Item; use App\Models\Item;
use App\Models\Line;
use App\Models\Plant;
use App\Models\ProductionQuantity; use App\Models\ProductionQuantity;
use App\Models\Shift; use App\Models\Shift;
use Carbon\Carbon; use Carbon\Carbon;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Hidden;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
@@ -25,13 +29,14 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section; use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ExportAction;
use Livewire\Livewire; use Livewire\Livewire;
// use Filament\Forms\Components\View; // use Filament\Forms\Components\View;
use Filament\Tables\Actions\FilamentExportBulkAction; use Filament\Tables\Actions\FilamentExportBulkAction;
use Filament\Tables\Filters\Filter;
class ProductionQuantityResource extends Resource class ProductionQuantityResource extends Resource
{ {
@@ -129,7 +134,7 @@ class ProductionQuantityResource extends Resource
return []; return [];
} }
return \App\Models\Block::where('plant_id', $get('plant_id')) return Block::where('plant_id', $get('plant_id'))
->pluck('name', 'id') ->pluck('name', 'id')
->toArray(); ->toArray();
}) })
@@ -235,7 +240,7 @@ class ProductionQuantityResource extends Resource
return []; return [];
} }
return \App\Models\Line::where('plant_id', $get('plant_id')) return Line::where('plant_id', $get('plant_id'))
->pluck('name', 'id') ->pluck('name', 'id')
->toArray(); ->toArray();
}) })
@@ -895,8 +900,10 @@ class ProductionQuantityResource extends Resource
->required(), ->required(),
Forms\Components\Hidden::make('success_msg') Forms\Components\Hidden::make('success_msg')
->required(), ->required(),
Forms\Components\Hidden::make('item_code') Forms\Components\Hidden::make('item_id')
->required(), ->required(),
Forms\Components\Hidden::make('sap_msg_status'),
Forms\Components\Hidden::make('sap_msg_description'),
//->unique(ignoreRecord: true), //->unique(ignoreRecord: true),
// ->autocapitalize('characters'), // ->autocapitalize('characters'),
// ->columnSpanFull(), // ->columnSpanFull(),
@@ -940,39 +947,265 @@ class ProductionQuantityResource extends Resource
->numeric() ->numeric()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('production_order') Tables\Columns\TextColumn::make('production_order')
->sortable() ->label('Production Order')
->searchable(), ->sortable(),// ->searchable(),
Tables\Columns\TextColumn::make('item.code')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('serial_number') Tables\Columns\TextColumn::make('serial_number')
->sortable() ->label('Serial Number')
->searchable(), ->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') Tables\Columns\TextColumn::make('line.name')
->label('Line')
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('shift.name') Tables\Columns\TextColumn::make('shift.name')
->label('Shift')
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('operator_id') Tables\Columns\TextColumn::make('sap_msg_status')
->label('Operator ID') ->label('SAP Message Status')
->sortable(),
Tables\Columns\TextColumn::make('sap_msg_description')
->label('SAP Message Description')
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('created_at') Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime() ->dateTime()
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at') Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->dateTime() ->dateTime()
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at') Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->dateTime() ->dateTime()
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('operator_id')
->label('Operator ID')
->sortable(),
]) ])
->filters([ ->filters([
Tables\Filters\TrashedFilter::make(), 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([ ->actions([
Tables\Actions\ViewAction::make(), Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),