Add lot_prefix to products; compose LOT number from prefix + date suffix
Deploy / deploy (push) Successful in 14s

Products now have a configurable lot_prefix (e.g. "112"). In the batch form
the prefix is shown read-only next to the suffix input (JJMMTT), and the full
lot_number (e.g. "112-260912") is composed automatically and stored.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 20:35:37 +02:00
1 parent e9734c2590
commit 5c034ec895
6 files changed
+87 -12

No files matched your search

+34 -7
View File
@@ -31,12 +31,6 @@ class BatchResource extends Resource
{
return $form->schema([
Forms\Components\Section::make('Charge')->schema([
Forms\Components\TextInput::make('lot_number')
->label('LOT-Nummer')
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Forms\Components\Select::make('product_id')
->label('Produkt')
->relationship('product', 'title')
@@ -44,7 +38,7 @@ class BatchResource extends Resource
->preload()
->required()
->live()
->afterStateUpdated(function ($state, $set) {
->afterStateUpdated(function ($state, $set, $get) {
$set('size_id', null);
$set('recipe_id', null);
$set('origins', []);
@@ -62,8 +56,41 @@ class BatchResource extends Resource
])->toArray());
}
}
$suffix = $get('lot_suffix');
if ($suffix && $product?->lot_prefix) {
$set('lot_number', $product->lot_prefix . '-' . $suffix);
}
}),
Forms\Components\TextInput::make('lot_suffix')
->label('LOT-Nummer')
->prefix(fn (Get $get): ?string => Product::find($get('product_id'))?->lot_prefix
? Product::find($get('product_id'))->lot_prefix . ' -'
: null
)
->placeholder('JJMMTT')
->maxLength(50)
->required()
->dehydrated(false)
->live()
->afterStateHydrated(function ($component, $record) {
if (! $record?->lot_number) return;
$pos = strrpos($record->lot_number, '-');
$component->state($pos !== false
? substr($record->lot_number, $pos + 1)
: $record->lot_number
);
})
->afterStateUpdated(function ($state, $set, $get) {
$product = Product::find($get('product_id'));
$set('lot_number', $product?->lot_prefix
? $product->lot_prefix . '-' . $state
: $state
);
}),
Forms\Components\Hidden::make('lot_number'),
Forms\Components\Select::make('size_id')
->label('Variante (Verpackung)')
->options(fn (Get $get) => ProductSize::with('packing')
@@ -41,6 +41,11 @@ class ProductResource extends Resource {
Forms\Components\TextInput::make('title')
->label('Name')
->required(),
Forms\Components\TextInput::make('lot_prefix')
->label('Chargen-Präfix')
->placeholder('z.B. 112')
->unique(ignoreRecord: true)
->maxLength(20),
Placeholder::make('shopify_product_id')
->label('Shopify ID')
->content(fn ($record) => $record?->shopify_product_id
@@ -24,11 +24,31 @@ class BatchesRelationManager extends RelationManager
public function form(Form $form): Form
{
return $form->schema([
Forms\Components\TextInput::make('lot_number')
Forms\Components\TextInput::make('lot_suffix')
->label('LOT-Nummer')
->prefix(fn ($livewire): ?string => $livewire->getOwnerRecord()->lot_prefix
? $livewire->getOwnerRecord()->lot_prefix . ' -'
: null
)
->placeholder('JJMMTT')
->maxLength(50)
->required()
->unique(ignoreRecord: true)
->maxLength(255),
->dehydrated(false)
->live()
->afterStateHydrated(function ($component, $record) {
if (! $record?->lot_number) return;
$pos = strrpos($record->lot_number, '-');
$component->state($pos !== false
? substr($record->lot_number, $pos + 1)
: $record->lot_number
);
})
->afterStateUpdated(function ($state, $set, $livewire) {
$prefix = $livewire->getOwnerRecord()->lot_prefix;
$set('lot_number', $prefix ? "{$prefix}-{$state}" : $state);
}),
Forms\Components\Hidden::make('lot_number'),
Forms\Components\Select::make('size_id')
->label('Variante (Verpackung)')