1
0
forked from poc/pds

Added operator_id and production_order column, and searchable filter in view and removed chunkSize in import action

This commit is contained in:
dhanabalan
2025-04-23 14:32:36 +05:30
parent 3878359f81
commit b3d12b0a29

View File

@@ -10,6 +10,7 @@ use App\Models\Item;
use App\Models\ProductionQuantity;
use App\Models\Shift;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
@@ -46,7 +47,7 @@ class ProductionQuantityResource extends Resource
->required()
// ->nullable()
->reactive()
->columnSpan(1)
->columnSpan(2) //1
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () {
return optional(ProductionQuantity::latest()->first())->plant_id;
@@ -98,6 +99,7 @@ class ProductionQuantityResource extends Resource
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
->hintColor('danger'),
Forms\Components\Select::make('block_name')
->label('Block')
->required()
// ->nullable()
->columnSpan(1)
@@ -151,6 +153,7 @@ class ProductionQuantityResource extends Resource
Forms\Components\Select::make('shift_id')
->relationship('shift', 'name')
->required()
->columnSpan(1)
// ->nullable()
->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name')) {
@@ -202,6 +205,7 @@ class ProductionQuantityResource extends Resource
Forms\Components\Select::make('line_id')
->relationship('line', 'name')
->required()
->columnSpan(2)
// ->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Line::where('plant_id', $get('plant_id'))
@@ -288,12 +292,29 @@ class ProductionQuantityResource extends Resource
// // ->autocapitalize('item_code'),
// // //->columnSpanFull(),
// Virtual field for code input (not stored in DB)
Forms\Components\TextInput::make('production_order')
->label('Production Order')
->reactive()
->required()
->columnSpan(2)
->disabled(function ($get) {
return $get('item_code');
})
->default(function () {
// Get the latest 'item_id' foreign key from 'production_quantities' table
$latestProductionOrder = ProductionQuantity::latest()->first()->production_order;
return $latestProductionOrder ?? null;
}),
Forms\Components\TextInput::make('item_code')
->label('Item Code')
// ->required()
->reactive()
->columnSpan(2)
->autofocus(true)
->debounce(100)
->disabled(function ($get) {
return !$get('production_order');
})
// ->submitOnEnter()
->afterStateUpdated(function ($state, callable $get, callable $set) {
$set('success_msg', null);
@@ -672,6 +693,7 @@ class ProductionQuantityResource extends Resource
->title('Invalid Serial Number')
->body("Serial Number must contain alpha-numeric values only.")
->danger()
->duration(800)
->send();
return;
}
@@ -686,6 +708,7 @@ class ProductionQuantityResource extends Resource
->title('Invalid Serial Number')
->body("Serial Number must be at least 9 digits.")
->danger()
->duration(800)
->send();
return;
}
@@ -811,6 +834,7 @@ class ProductionQuantityResource extends Resource
Forms\Components\TextInput::make('recent_qr') //item_description
->label('Last scanned QR')
->reactive()
->columnSpan(2)
->default(function () {
// Get the latest 'item_id' foreign key from 'production_quantities' table
$latestProductionQuantity = ProductionQuantity::latest()->first();
@@ -831,8 +855,11 @@ class ProductionQuantityResource extends Resource
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
Forms\Components\Hidden::make('operator_id')
->default(Filament::auth()->user()->name),
])
->columns(6),
->columns(12), //6
]);
}
@@ -845,15 +872,20 @@ class ProductionQuantityResource extends Resource
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('item.code')
->sortable(),
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('serial_number')
->sortable(),
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('line.name')
->sortable(),
Tables\Columns\TextColumn::make('shift.name')
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->sortable(),
Tables\Columns\TextColumn::make('operator_id')
->label('Operator ID')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
@@ -883,8 +915,8 @@ class ProductionQuantityResource extends Resource
])
->headerActions([
ImportAction::make()
->importer(ProductionQuantityImporter::class)
->chunkSize(1000),
->importer(ProductionQuantityImporter::class),
// ->chunkSize(250),
// ->maxRows(100000),
ExportAction::make()
->exporter(ProductionQuantityExporter::class),