Import Fun Completed and Sticker Master
This commit is contained in:
@@ -21,35 +21,121 @@ class ProductionQuantityResource 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('item_id')
|
||||
->relationship('item', 'code')
|
||||
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('item_id')
|
||||
// ->label('Item Code')
|
||||
// ->relationship('item', 'code')
|
||||
// ->required(),
|
||||
// // Forms\Components\TextInput::make('item_code')
|
||||
// // ->required()
|
||||
// // ->autocapitalize('item_code'),
|
||||
// // //->columnSpanFull(),
|
||||
// Virtual field for code input (not stored in DB)
|
||||
Forms\Components\TextInput::make('item_code')
|
||||
->label('Item Code')
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $get, callable $set) {
|
||||
// Only search when all parent IDs are selected
|
||||
if ($get('plant_id') && $get('line_id')) {
|
||||
$item = \App\Models\Item::where('code', $state)
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->where('line_id', $get('line_id'))
|
||||
->first();
|
||||
|
||||
if ($item) {
|
||||
$set('item_id', $item->id); // Set actual foreign key
|
||||
} else {
|
||||
$set('item_id', null); // Clear item_id if not found
|
||||
}
|
||||
}
|
||||
})
|
||||
->rules([
|
||||
function ($get) {
|
||||
return function ($attribute, $value, $fail) use ($get) {
|
||||
// Check if item exists with the given code and foreign keys
|
||||
$exists = \App\Models\Item::where('code', $value)
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->where('line_id', $get('line_id'))
|
||||
->exists();
|
||||
|
||||
if (!$exists) {
|
||||
// Custom error message
|
||||
$fail("The item code '{$value}' does not exist for the selected Plant/Block/Line.");
|
||||
}
|
||||
};
|
||||
},
|
||||
]),
|
||||
|
||||
Forms\Components\Hidden::make('item_id')
|
||||
->required(),
|
||||
// Forms\Components\TextInput::make('item_code')
|
||||
// ->required()
|
||||
// ->autocapitalize('item_code'),
|
||||
// //->columnSpanFull(),
|
||||
Forms\Components\TextInput::make('item_description')
|
||||
->label('Description')
|
||||
->required(),
|
||||
// Forms\Components\Select::make('item_id')
|
||||
// ->label('Description')
|
||||
// ->relationship('item', 'description')
|
||||
// ->required(),
|
||||
Forms\Components\TextInput::make('serial_number')
|
||||
->required()
|
||||
->autocapitalize('serial_number'),
|
||||
//->columnSpanFull(),
|
||||
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(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -61,13 +147,7 @@ class ProductionQuantityResource extends Resource
|
||||
->label('ID')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('plan_quantity')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('hourly_quantity')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('item_code')
|
||||
Tables\Columns\TextColumn::make('item.code')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('serial_number')
|
||||
->sortable(),
|
||||
@@ -75,8 +155,6 @@ class ProductionQuantityResource 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