Import Fun Completed and Sticker Master
This commit is contained in:
@@ -14,6 +14,8 @@ use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
class ProductionLineStopResource extends Resource
|
||||
{
|
||||
@@ -21,43 +23,154 @@ class ProductionLineStopResource extends Resource
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Master Entries';
|
||||
// protected static ?string $navigationParentItem = 'Display Transactions';
|
||||
|
||||
protected static ?string $navigationGroup = 'Production';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('lineStop_id')
|
||||
->relationship('linestop', 'code')
|
||||
->required(),
|
||||
Forms\Components\Select::make('lineStop_id')
|
||||
->relationship('linestop', 'reason')
|
||||
->required(),
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
->nullable()
|
||||
->reactive(),
|
||||
Forms\Components\Select::make('block_name')
|
||||
->required()
|
||||
->nullable()
|
||||
->reactive()
|
||||
->afterStateUpdated(fn ($set) => $set('shift_id', null)),
|
||||
Forms\Components\Select::make('shift_id')
|
||||
->relationship('shift', 'name')
|
||||
->required()
|
||||
->nullable()
|
||||
// ->options(fn (callable $get) =>
|
||||
// \App\Models\Shift::where('plant_id', $get('plant_id'))
|
||||
// ->pluck('name', 'id')
|
||||
// ->toArray() // Convert collection to array
|
||||
// )
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(fn ($set) => $set('line_id', null)),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->relationship('line', 'name')
|
||||
->required()
|
||||
->nullable()
|
||||
// ->options(fn (callable $get) =>
|
||||
// \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
// ->pluck('name', 'id')
|
||||
// ->toArray() // Convert collection to array
|
||||
// )
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
// Forms\Components\Select::make('linestop_id')
|
||||
// ->label('Line Stop Code')
|
||||
// ->relationship('linestop', 'code')
|
||||
// ->searchable()
|
||||
// ->required()
|
||||
// ->nullable()
|
||||
// ->reactive(),
|
||||
Forms\Components\Select::make('linestop_id')
|
||||
->label('Line Stop Code')
|
||||
// ->options(fn (callable $get) =>
|
||||
// \App\Models\LineStop::where('id', $get('linestop_id'))
|
||||
// ->pluck('code', 'id')
|
||||
// )
|
||||
->options(fn () => \App\Models\LineStop::pluck('code', 'id'))
|
||||
->required()
|
||||
->nullable()
|
||||
// ->reactive()
|
||||
->searchable()
|
||||
->live(debounce: 500) // Enable live updates
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$lineStopId = $get('linestop_id'); // Get entered linestop_id
|
||||
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$lineStopId) {
|
||||
$set('lineStop_reason', null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if item exists for the selected plant
|
||||
$lineStop = \App\Models\LineStop::where('id', $lineStopId)
|
||||
->where('id', $lineStopId)
|
||||
->first();
|
||||
|
||||
$set('lineStop_reason', $lineStop?->reason ?? null);
|
||||
|
||||
}),
|
||||
Forms\Components\TextInput::make('lineStop_reason')
|
||||
->label('Line Stop Reason')
|
||||
->required()
|
||||
->reactive()
|
||||
->readOnly(true),
|
||||
Forms\Components\DateTimePicker::make('from_datetime')
|
||||
->required(),
|
||||
->label('From DateTime')
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
||||
self::updateStopDuration($get, $set)
|
||||
),
|
||||
Forms\Components\DateTimePicker::make('to_datetime')
|
||||
->required(),
|
||||
->label('To DateTime')
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
||||
self::updateStopDuration($get, $set) //self means it calling the function within the class
|
||||
),
|
||||
Forms\Components\TextInput::make('stop_hour')
|
||||
->required()
|
||||
// ->dehydrated(false) // Don't send to backend
|
||||
->readOnly(true)
|
||||
->numeric(),
|
||||
Forms\Components\TextInput::make('stop_min')
|
||||
->required()
|
||||
// ->dehydrated(false)
|
||||
->readOnly(true)
|
||||
->numeric(),
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required(),
|
||||
Forms\Components\Select::make('block_id')
|
||||
->relationship('block', 'name')
|
||||
->required(),
|
||||
Forms\Components\Select::make('shift_id')
|
||||
->relationship('shift', 'name')
|
||||
->required(),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->relationship('line', 'name')
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function updateStopDuration(callable $get, callable $set)
|
||||
{
|
||||
$from = $get('from_datetime');
|
||||
$to = $get('to_datetime');
|
||||
|
||||
// Carbon is a PHP date and time library.
|
||||
|
||||
if ($from && $to) {
|
||||
$fromTime = Carbon::parse($from); //Carbon::parse($from) converts the from datetime string into a Carbon objec
|
||||
$toTime = Carbon::parse($to);
|
||||
|
||||
if ($fromTime->lt($toTime)) {
|
||||
$diffInMinutes = $fromTime->diffInMinutes($toTime);
|
||||
$set('stop_hour', floor($diffInMinutes / 60));
|
||||
$set('stop_min', $diffInMinutes % 60);
|
||||
} else {
|
||||
$set('stop_hour', 0);
|
||||
$set('stop_min', 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
@@ -86,8 +199,6 @@ class ProductionLineStopResource extends Resource
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('shift.name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('block.name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
|
||||
Reference in New Issue
Block a user