diff --git a/app/Filament/Resources/BlockResource.php b/app/Filament/Resources/BlockResource.php index 860c282..e73ab46 100644 --- a/app/Filament/Resources/BlockResource.php +++ b/app/Filament/Resources/BlockResource.php @@ -15,6 +15,7 @@ use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Filament\Forms\Components\Section; +use Illuminate\Validation\Rule; class BlockResource extends Resource { @@ -34,7 +35,7 @@ class BlockResource extends Resource ->schema([ Forms\Components\TextInput::make('name') ->required() - ->unique(ignoreRecord: true) + // ->unique(ignoreRecord: true) ->placeholder('Scan the valid name') ->autofocus(true) ->reactive() @@ -54,12 +55,20 @@ class BlockResource extends Resource 'class' => $get('bNameError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('bNameError') ? $get('bNameError') : null) - ->hintColor('danger'), + ->hintColor('danger') + ->rule(function (callable $get) { + return Rule::unique('blocks', 'name') + ->where('plant_id', $get('plant_id')) + ->ignore($get('id')); // Ignore current record during updates + }), Forms\Components\Select::make('plant_id') ->relationship('plant', 'name') // ->unique(ignoreRecord: true) ->required() ->reactive() + ->default(function () { + return optional(Block::latest()->first())->plant_id; + }) ->disabled(fn (Get $get) => !empty($get('id'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { $nameId = $get('plant_id'); diff --git a/app/Filament/Resources/ItemResource.php b/app/Filament/Resources/ItemResource.php index d026c9b..0d4b0a1 100644 --- a/app/Filament/Resources/ItemResource.php +++ b/app/Filament/Resources/ItemResource.php @@ -18,6 +18,7 @@ use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Filament\Forms\Components\Section; +use Illuminate\Validation\Rule; class ItemResource extends Resource { @@ -41,6 +42,9 @@ class ItemResource extends Resource // ->preload() // ->nullable(), ->reactive() + ->default(function () { + return optional(Item::latest()->first())->plant_id; + }) ->disabled(fn (Get $get) => !empty($get('id'))) // ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { @@ -64,7 +68,7 @@ class ItemResource extends Resource ->required() ->placeholder('Scan the valid code') ->autofocus(true) - ->unique(ignoreRecord: true) + // ->unique(ignoreRecord: true) ->alphaNum() ->minLength(6) // ->autocapitalize('characters') @@ -95,7 +99,12 @@ class ItemResource extends Resource 'class' => $get('iCodeError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('iCodeError') ? $get('iCodeError') : null) - ->hintColor('danger'), + ->hintColor('danger') + ->rule(function (callable $get) { + return Rule::unique('items', 'code') + ->where('plant_id', $get('plant_id')) + ->ignore($get('id')); // Ignore current record during updates + }), Forms\Components\TextInput::make('hourly_quantity') ->required() ->label('Hourly Quantity') @@ -183,7 +192,8 @@ class ItemResource extends Resource ]) ->headerActions([ ImportAction::make() - ->importer(ItemImporter::class), + ->importer(ItemImporter::class) + ->maxRows(100000), ExportAction::make() ->exporter(ItemExporter::class), ]); diff --git a/app/Filament/Resources/LineResource.php b/app/Filament/Resources/LineResource.php index 50c2a26..08f4348 100644 --- a/app/Filament/Resources/LineResource.php +++ b/app/Filament/Resources/LineResource.php @@ -16,6 +16,7 @@ use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Filament\Forms\Components\Section; +use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Unique; class LineResource extends Resource @@ -38,6 +39,9 @@ class LineResource extends Resource ->required() // ->nullable(), ->reactive() + ->default(function () { + return optional(Line::latest()->first())->plant_id; + }) ->disabled(fn (Get $get) => !empty($get('id'))) // ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { @@ -88,16 +92,16 @@ class LineResource extends Resource } else { - $exists = Line::where('name', $lineNam) - ->where('plant_id', $get('plant_id')) - ->exists(); + // $exists = Line::where('name', $lineNam) + // ->where('plant_id', $get('plant_id')) + // ->exists(); - if ($exists) { - $set('name', null); - $set('lNameError', 'The name has already been taken.'); - // $set('lNameError', 'The combination of name and plant ID must be unique.'); - return; - } + // if ($exists) { + // $set('name', null); + // $set('lNameError', 'The name has already been taken.'); + // // $set('lNameError', 'The combination of name and plant ID must be unique.'); + // return; + // } $set('lNameError', null); } }) @@ -105,7 +109,12 @@ class LineResource extends Resource 'class' => $get('lNameError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('lNameError') ? $get('lNameError') : null) - ->hintColor('danger'), + ->hintColor('danger') + ->rule(function (callable $get) { + return Rule::unique('lines', 'name') + ->where('plant_id', $get('plant_id')) + ->ignore($get('id')); // Ignore current record during updates + }), Forms\Components\TextInput::make('type') ->required() ->placeholder('Scan the valid type') diff --git a/app/Filament/Resources/PlantResource.php b/app/Filament/Resources/PlantResource.php index 09be083..df4848d 100644 --- a/app/Filament/Resources/PlantResource.php +++ b/app/Filament/Resources/PlantResource.php @@ -71,6 +71,9 @@ class PlantResource extends Resource ->relationship('company', 'name') ->required() ->reactive() + ->default(function () { + return optional(Plant::latest()->first())->company_id; + }) ->disabled(fn (Get $get) => !empty($get('id'))) ->afterStateUpdated(function ($state, callable $set, callable $get) { $companyId = $get('company_id'); diff --git a/app/Filament/Resources/ShiftResource.php b/app/Filament/Resources/ShiftResource.php index 2fd3a2e..9e420a1 100644 --- a/app/Filament/Resources/ShiftResource.php +++ b/app/Filament/Resources/ShiftResource.php @@ -4,6 +4,7 @@ namespace App\Filament\Resources; use App\Filament\Imports\ShiftImporter; use App\Filament\Resources\ShiftResource\Pages; +use App\Models\Plant; use App\Models\Shift; use Carbon\Carbon; use Filament\Forms; @@ -16,6 +17,7 @@ use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; use Filament\Forms\Components\Section; +use Illuminate\Validation\Rule; class ShiftResource extends Resource { @@ -38,6 +40,9 @@ class ShiftResource extends Resource ->required() // ->nullable() ->reactive() + ->default(function () { + return optional(Shift::latest()->first())->plant_id; + }) ->disabled(fn (Get $get) => !empty($get('id'))) // ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { @@ -62,6 +67,9 @@ class ShiftResource extends Resource ->required() // ->nullable() ->reactive() + ->default(function () { + return optional(Shift::latest()->first())->block_id; + }) ->disabled(fn (Get $get) => !empty($get('id'))) // ->options(fn (callable $get) => // \App\Models\Block::where('plant_id', $get('plant_id')) @@ -109,17 +117,17 @@ class ShiftResource extends Resource } else { - $exists = Shift::where('plant_id', $get('plant_id')) - ->where('block_id', $get('block_id')) - ->where('name', $nameId) - ->latest() - ->exists(); - if ($exists) - { - $set('start_time', null); - $set('sNameError', 'Scanned name already exist.'); - return; - } + // $exists = Shift::where('plant_id', $get('plant_id')) + // ->where('block_id', $get('block_id')) + // ->where('name', $nameId) + // ->latest() + // ->exists(); + // if ($exists) + // { + // $set('start_time', null); + // $set('sNameError', 'Scanned name already exist.'); + // return; + // } $set('sNameError', null); } }) @@ -127,7 +135,13 @@ class ShiftResource extends Resource 'class' => $get('sNameError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('sNameError') ? $get('sNameError') : null) - ->hintColor('danger'), + ->hintColor('danger') + ->rule(function (callable $get) { + return Rule::unique('shifts', 'name') + ->where('plant_id', $get('plant_id')) + ->where('block_id', $get('block_id')) + ->ignore($get('id')); // Ignore current record during updates + }), Forms\Components\TimePicker::make('start_time') ->required() ->label('Start Time') @@ -146,18 +160,18 @@ class ShiftResource extends Resource } else { - $exists = Shift::where('plant_id', $get('plant_id')) - ->where('block_id', $get('block_id')) - ->where('name', $get('name')) - ->latest() - ->exists(); - if ($exists) - { - $set('start_time', null); - $set('sStartTimeError', null); - $set('sNameError', 'Scanned name already exist.'); - return; - } + // $exists = Shift::where('plant_id', $get('plant_id')) + // ->where('block_id', $get('block_id')) + // ->where('name', $get('name')) + // ->latest() + // ->exists(); + // if ($exists) + // { + // $set('start_time', null); + // $set('sStartTimeError', null); + // $set('sNameError', 'Scanned name already exist.'); + // return; + // } $set('sStartTimeError', null); } }) diff --git a/storage/app/.gitignore b/storage/app/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/private/.gitignore b/storage/app/private/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/testing/.gitignore b/storage/framework/testing/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore old mode 100644 new mode 100755 diff --git a/storage/logs/.gitignore b/storage/logs/.gitignore old mode 100644 new mode 100755