Compare commits
3 Commits
10b439f8e3
...
3e0633def2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e0633def2 | ||
|
|
cea7f86fed | ||
|
|
af3ae0803c |
@@ -3,9 +3,15 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Locator;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class LocatorImporter extends Importer
|
||||
{
|
||||
@@ -17,23 +23,27 @@ class LocatorImporter extends Importer
|
||||
ImportColumn::make('locator_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Locator Number')
|
||||
->example(['W01-A1A'])
|
||||
->label('Locator Number')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('locator_quantity')
|
||||
->requiredMapping()
|
||||
->numeric()
|
||||
->exampleHeader('Locator Quantity')
|
||||
->example(['0'])
|
||||
->label('Locator Quantity')
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('operator_id')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Operator ID')
|
||||
->example(['Admin'])
|
||||
->label('Operator ID')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant_id')
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship('plant', 'name')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['Ransar Industries-I'])
|
||||
->label('Plant')
|
||||
->rules(['required']),
|
||||
];
|
||||
@@ -41,12 +51,56 @@ class LocatorImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?Locator
|
||||
{
|
||||
// return Locator::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$locator = $this->data['locator_number'];
|
||||
// $locatorQuantity = $this->data['locator_quantity'];
|
||||
$palletQuantity = 0;
|
||||
$user = Filament::auth()->user()->name;
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Str::length($locator) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
}
|
||||
else {
|
||||
// $locat = Locator::where('name', $locator)->where('plant_id', $plant->id)->first();
|
||||
$palletQuantity = PalletValidation::where('locator_number', $locator)->where('plant_id', $plant->id)->distinct('pallet_number')->count('pallet_number');
|
||||
}
|
||||
}
|
||||
|
||||
return new Locator();
|
||||
// if (Str::length($locatorQuantity) < 0 || !is_numeric($locatorQuantity) || $locatorQuantity < 0 || $locatorQuantity > 2) {
|
||||
// $warnMsg[] = "Invalid locator quantity found";
|
||||
// }
|
||||
|
||||
// $user = User::where('name', $user)->first();
|
||||
// if (!$user) {
|
||||
// $warnMsg[] = "Operator ID not found";
|
||||
// }
|
||||
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
Locator::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'locator_number' => $locator
|
||||
],
|
||||
[
|
||||
'locator_quantity' => $palletQuantity,
|
||||
'operator_id' => $user
|
||||
]
|
||||
);
|
||||
return null;
|
||||
// // return Locator::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
// // 'email' => $this->data['email'],
|
||||
// // ]);
|
||||
|
||||
// return new Locator();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -89,7 +89,7 @@ class MachineImporter extends Importer
|
||||
'work_center' => $workCenter
|
||||
]
|
||||
);
|
||||
return null;//work_center plant_id line_id name
|
||||
return null;
|
||||
// // return Machine::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
// // 'email' => $this->data['email'],
|
||||
|
||||
@@ -330,7 +330,7 @@ class PalletFromLocator extends Page implements HasForms
|
||||
->orWhere('pallet_number', '');
|
||||
})
|
||||
->where('locator_number', $locatorNo)
|
||||
->orderByDesc('created_at')
|
||||
->orderBy('created_at', 'asc') //orderByDesc('created_at')
|
||||
->get()
|
||||
->map(function ($record) use($operatorName) {
|
||||
return [
|
||||
@@ -673,14 +673,14 @@ class PalletFromLocator extends Page implements HasForms
|
||||
$month = now()->format('m');
|
||||
$prefix = "EP-{$year}{$month}";
|
||||
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")
|
||||
->where('plant_id', $plantId)
|
||||
->orderByDesc('pallet_number')
|
||||
->first();
|
||||
|
||||
$newNumber = $lastPallet
|
||||
? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT)
|
||||
: '001';
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first(); //->where('plant_id', $plantId)
|
||||
$newNumber = '001'; // $lastPallet ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) : '001';
|
||||
if ($lastPallet) {
|
||||
$serialPart = substr($lastPallet->pallet_number, strlen($prefix));
|
||||
// OR
|
||||
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
|
||||
$newNumber = str_pad(intval($serialPart) + 1, strlen($serialPart), '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$newPalletNumber = "{$prefix}{$newNumber}";
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use App\Filament\Imports\LocatorImporter;
|
||||
use App\Filament\Resources\LocatorResource\Pages;
|
||||
use App\Filament\Resources\LocatorResource\RelationManagers;
|
||||
use App\Models\Locator;
|
||||
use App\Models\PalletValidation;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
@@ -17,6 +19,8 @@ use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Str;
|
||||
|
||||
class LocatorResource extends Resource
|
||||
{
|
||||
@@ -34,19 +38,87 @@ class LocatorResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required(),
|
||||
->required()
|
||||
// ->nullable(),
|
||||
->reactive()
|
||||
->default(function () {
|
||||
return optional(Locator::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) {
|
||||
$plantId = $get('plant_id');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$plantId) {
|
||||
$set('locPlantError', 'Please select a plant first.');
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('locPlantError', null);
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('locPlantError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('locPlantError') ? $get('locPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('locator_number')
|
||||
->label('Locator Number')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('locator_quantity')
|
||||
->minLength(7)
|
||||
->reactive()
|
||||
->required()
|
||||
->numeric()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
$locator = $get('locator_number');
|
||||
if (!$plantId) {
|
||||
$set('locNameError', 'Please select a plant first.');
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
return;
|
||||
}
|
||||
else if (!$locator || Str::length($locator) < 7) {
|
||||
$set('locNameError', 'Please scan the valid locator number.');
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('locNameError', null);
|
||||
$set('locator_quantity', PalletValidation::where('locator_number', $locator)->where('plant_id', $plantId)->distinct('pallet_number')->count('pallet_number'));
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('locNameError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('locNameError') ? $get('locNameError') : null)
|
||||
->hintColor('danger')
|
||||
->rule(function (callable $get) {
|
||||
return Rule::unique('locators', 'locator_number')
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->ignore($get('id')); // Ignore current record during updates
|
||||
}),
|
||||
Forms\Components\TextInput::make('locator_quantity')
|
||||
->label('Locator Quantity')
|
||||
->required()
|
||||
->readOnly()
|
||||
->numeric()
|
||||
->default(0),
|
||||
Forms\Components\Hidden::make('operator_id')
|
||||
->default(Filament::auth()->user()?->name)
|
||||
->required(),
|
||||
|
||||
->default(Filament::auth()->user()?->name)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class PalletValidationResource extends Resource
|
||||
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
|
||||
])
|
||||
->suffixAction(fn ($get,$set) =>
|
||||
Forms\Components\Actions\Action::make('addPallet')
|
||||
Forms\Components\Actions\Action::make('addPallet')
|
||||
->label('')
|
||||
->button()
|
||||
->icon('heroicon-o-plus')
|
||||
@@ -79,28 +79,23 @@ class PalletValidationResource extends Resource
|
||||
->action(function ($get, $set, $livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
session(['pallet_clicked_time' => now()->toDateTimeString()]);
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
$clickedTime = now();
|
||||
|
||||
$created = $operatorName;
|
||||
|
||||
session(['pallet_clicked_time' => $clickedTime->toDateTimeString()]);
|
||||
|
||||
session(['pallet_created_by' => $created]);
|
||||
session(['pallet_created_by' => Filament::auth()->user()->name]);
|
||||
|
||||
$year = now()->format('y');
|
||||
$month = now()->format('m');
|
||||
$prefix = "EP-{$year}{$month}";
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")
|
||||
->where('plant_id', $plantId)
|
||||
->orderByDesc('pallet_number')
|
||||
->first();
|
||||
$newNumber = $lastPallet
|
||||
? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT)
|
||||
: '001';
|
||||
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first(); //->where('plant_id', $plantId)
|
||||
$newNumber = '001'; // $lastPallet ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) : '001';
|
||||
if ($lastPallet) {
|
||||
$serialPart = substr($lastPallet->pallet_number, strlen($prefix));
|
||||
// OR
|
||||
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
|
||||
$newNumber = str_pad(intval($serialPart) + 1, strlen($serialPart), '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$newPalletNumber = "{$prefix}{$newNumber}";
|
||||
|
||||
$set('pallet_number', $newPalletNumber);
|
||||
@@ -326,8 +321,8 @@ class PalletValidationResource extends Resource
|
||||
->label('Locator Quantity')
|
||||
->options([
|
||||
0 => 0,
|
||||
1 => '1',
|
||||
2 => '2',
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
])
|
||||
->reactive(),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
|
||||
Reference in New Issue
Block a user