ranjith-dev #410

Merged
jothi merged 5 commits from ranjith-dev into master 2026-02-26 07:35:46 +00:00
4 changed files with 260 additions and 191 deletions

View File

@@ -26,6 +26,8 @@ class ProductCharacteristicsMasterExporter extends Exporter
->label('PLANT CODE'), ->label('PLANT CODE'),
ExportColumn::make('item.code') ExportColumn::make('item.code')
->label('ITEM CODE'), ->label('ITEM CODE'),
ExportColumn::make('item.description')
->label('ITEM DESCRIPTION'),
ExportColumn::make('line.name') ExportColumn::make('line.name')
->label('LINE NAME'), // machine.workGroupMaster.name ->label('LINE NAME'), // machine.workGroupMaster.name
ExportColumn::make('machine.workGroupMaster.name') ExportColumn::make('machine.workGroupMaster.name')

View File

@@ -24,75 +24,77 @@ class ProductCharacteristicsMasterImporter extends Importer
{ {
return [ return [
ImportColumn::make('plant') ImportColumn::make('plant')
->label('PLANT CODE')
->requiredMapping() ->requiredMapping()
->exampleHeader('Plant Code') ->exampleHeader('PLANT CODE')
->example('1000') ->example(['1000', '1000'])
->label('Plant Code')
->relationship(resolveUsing: 'code') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
ImportColumn::make('item') ImportColumn::make('item')
->label('ITEM CODE')
->requiredMapping() ->requiredMapping()
->exampleHeader('Item Code') ->exampleHeader('ITEM CODE')
->example('630214') ->example(['123456', '123456'])
->label('Item Code')
->relationship(resolveUsing: 'code') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
ImportColumn::make('line') ImportColumn::make('line')
->label('LINE NAME')
->requiredMapping() ->requiredMapping()
->exampleHeader('Line Name') ->exampleHeader('LINE NAME')
->example('4 inch pump line') ->example(['4 inch pump line', '4 inch pump line'])
->label('Line Name')
->relationship(resolveUsing: 'name') ->relationship(resolveUsing: 'name')
->rules(['required']), ->rules(['required']),
ImportColumn::make('work_group_master_id') ImportColumn::make('work_group_master_id')
->label('Group Work Center') ->label('GROUP WORK CENTER')
->requiredMapping() ->requiredMapping()
->exampleHeader('Group Work Center') ->exampleHeader('GROUP WORK CENTER')
->example('RMGCGABC') ->example(['RMGSTR01', 'RMGSTR01'])
->relationship(resolveUsing: 'name') ->relationship(resolveUsing: 'name')
->rules(['required']), ->rules(['required']),
ImportColumn::make('machine') ImportColumn::make('machine')
->label('WORK CENTER')
->requiredMapping() ->requiredMapping()
->exampleHeader('Work Center') ->exampleHeader('WORK CENTER')
->example('RMGCE001') ->example(['RMISTR01', 'RMISTR02'])
->label('Work Center')
->relationship(resolveUsing: 'work_center') ->relationship(resolveUsing: 'work_center')
->rules(['required']), ->rules(['required']),
ImportColumn::make('characteristics_type') ImportColumn::make('characteristics_type')
->exampleHeader('Characteristics Type') ->label('CHARACTERISTICS TYPE')
->example('Process or Product') ->requiredMapping()
->label('Characteristics Type') ->exampleHeader('CHARACTERISTICS TYPE')
->example(['Product', 'Process'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('name') ImportColumn::make('name')
->exampleHeader('Characteristics Name') ->label('CHARACTERISTICS NAME')
->example('Body') ->requiredMapping()
->label('Characteristics Name') ->exampleHeader('CHARACTERISTICS NAME')
->example(['TEST01', 'TEST02'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('inspection_type') ImportColumn::make('inspection_type')
->exampleHeader('Inspection Type') ->label('INSPECTION TYPE')
->example('Visual or Value') ->requiredMapping()
->label('Inspection Type') ->exampleHeader('INSPECTION TYPE')
->example(['Value', 'Visual'])
->rules(['required']), ->rules(['required']),
ImportColumn::make('lower') ImportColumn::make('lower')
->exampleHeader('Lower') ->label('LOWER')
->example('0') ->requiredMapping()
->label('Lower') ->exampleHeader('LOWER')
->rules(['numeric']), ->example(['5', '0'])
->rules(['required']),
ImportColumn::make('middle') ImportColumn::make('middle')
->exampleHeader('Middle') ->label('MIDDLE')
->example('1') ->requiredMapping()
->label('Middle') ->exampleHeader('MIDDLE')
->numeric() ->example(['10', '0'])
->rules(['numeric']), ->rules(['required']),
ImportColumn::make('upper') ImportColumn::make('upper')
->exampleHeader('Upper') ->label('UPPER')
->example('2') ->requiredMapping()
->label('Upper') ->exampleHeader('UPPER')
->rules(['numeric']), ->example(['15', '0'])
ImportColumn::make('created_by') ->rules(['required']),
->exampleHeader('Created By') // ImportColumn::make('created_by'),
->example('Admin')
->label('Created By'),
// ImportColumn::make('updated_by'), // ImportColumn::make('updated_by'),
]; ];
@@ -102,117 +104,172 @@ class ProductCharacteristicsMasterImporter extends Importer
{ {
$warnMsg = []; $warnMsg = [];
$plantCod = $this->data['plant']; $plantCod = trim($this->data['plant']) ?? null;
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin' $itemCod = trim($this->data['item']) ?? null;
$lower = null; $lineNam = trim($this->data['line']) ?? null;
$middle = null; $groupWorkCenter = trim($this->data['work_group_master_id']) ?? null;
$upper = null; $workCenter = trim($this->data['machine']) ?? null;
$plantId = null; $charTyp = trim($this->data['characteristics_type']) ?? null;
$name = trim($this->data['name']); $charName = trim($this->data['name']) ?? null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { $inspectTyp = trim($this->data['inspection_type']) ?? null;
$warnMsg[] = 'Invalid plant code found'; $lower = trim($this->data['lower']) ?? null;
} else { $middle = trim($this->data['middle']) ?? null;
$plant = Plant::where('code', $plantCod)->first(); $upper = trim($this->data['upper']) ?? null;
if (! $plant) { $createdBy = Filament::auth()->user()->name;
$warnMsg[] = 'Plant not found'; $updatedBy = null;
} else {
$plantId = $plant->id;
$itemExists = Item::where('code', $this->data['item'])->first();
if (! $itemExists) {
$warnMsg[] = 'Item not found';
}
$itemAgainstPlant = Item::where('code', $this->data['item']) $plantId = null;
->where('plant_id', $plantId) $itemId = null;
->first(); $lineId = null;
$workGroupMasterId = null;
$machineId = null;
if ($plantCod == null || $plantCod == '') {
$warnMsg[] = "Plant code can't be empty!";
} elseif (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found!';
}
if ($itemCod == null || $itemCod == '') {
$warnMsg[] = "Item code can't be empty!";
} elseif (Str::length($itemCod) < 6 || ! ctype_alnum($itemCod)) {
$warnMsg[] = 'Invalid item code found!';
}
if ($lineNam == null || $lineNam == '') {
$warnMsg[] = "Line name can't be empty!";
}
if ($groupWorkCenter == null || $groupWorkCenter == '') {
$warnMsg[] = "Group work center can't be empty!";
}
if ($workCenter == null || $workCenter == '') {
$warnMsg[] = "Work center can't be empty!";
}
if ($charTyp == null || $charTyp == '') {
$warnMsg[] = "Characteristics type can't be empty!";
}
if ($charName == null || $charName == '') {
$warnMsg[] = "Characteristics name can't be empty!";
}
if ($inspectTyp == null || $inspectTyp == '') {
$warnMsg[] = "Inspection type can't be empty!";
}
if ($lower == null || $lower == '') {
$warnMsg[] = "Lower value can't be empty!";
}
if ($middle == null || $middle == '') {
$warnMsg[] = "Middle value can't be empty!";
}
if ($upper == null || $upper == '') {
$warnMsg[] = "Upper value can't be empty!";
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant code not found!';
} else {
$plantId = $plant->id;
$itemExists = Item::where('code', $itemCod)->first();
if (! $itemExists) {
$warnMsg[] = 'Item code not found!';
} else {
$itemAgainstPlant = Item::where('code', $itemCod)->where('plant_id', $plantId)->first();
if (! $itemAgainstPlant) { if (! $itemAgainstPlant) {
$warnMsg[] = 'Item code not found for the given plant'; $warnMsg[] = 'Item code not found for the given plant!';
} else { } else {
$itemId = $itemAgainstPlant->id; $itemId = $itemAgainstPlant->id;
} }
}
$lineExists = Line::where('name', $this->data['line'])->first(); $lineExists = Line::where('name', $lineNam)->first();
if (! $lineExists) { if (! $lineExists) {
$warnMsg[] = 'Line not found'; $warnMsg[] = 'Line name not found!';
} } else {
$lineAgainstPlant = Line::where('name', $lineNam)->where('plant_id', $plantId)->first();
$lineAgainstPlant = Line::where('name', $this->data['line'])
->where('plant_id', $plantId)
->first();
if (! $lineAgainstPlant) { if (! $lineAgainstPlant) {
$warnMsg[] = 'Line not found for the given plant'; $warnMsg[] = 'Line name not found for the given plant!';
} else { } else {
$LineId = $lineAgainstPlant->id; $lineId = $lineAgainstPlant->id;
}
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plantId)->first(); $WorkgroupMaster = WorkGroupMaster::where('name', $groupWorkCenter)->first();
if (! $WorkgroupMaster) { if (! $WorkgroupMaster) {
$warnMsg[] = 'Work Group Master value not found'; $warnMsg[] = 'Group work center not found!';
} else {
$workGroupMasterId = $WorkgroupMaster->id;
// 2. Now check if this WorkGroupMaster id exists in ANY of the 10 columns
$existsInLine = Line::where('plant_id', $plantId)
->where(function ($q) use ($workGroupMasterId) {
for ($i = 1; $i <= 10; $i++) {
$q->orWhere("work_group{$i}_id", $workGroupMasterId);
}
})
->exists();
if (! $existsInLine) {
$warnMsg[] = "Work Group Master '{$WorkgroupMaster->name}' is not mapped to any line in this plant";
} else { } else {
$workGroupMasterId = $WorkgroupMaster->id; $WorkgroupMaster = WorkGroupMaster::where('name', $groupWorkCenter)->where('plant_id', $plantId)->first();
if (! $WorkgroupMaster) {
$warnMsg[] = 'Group work center not found for the given plant!';
} else {
$workGroupMasterId = $WorkgroupMaster->id;
// 2. Now check if this WorkGroupMaster id exists in ANY of the 10 columns
$existsInLine = Line::where('plant_id', $plantId)->where('id', $lineId)
->where(function ($q) use ($workGroupMasterId) {
for ($i = 1; $i <= 10; $i++) {
$q->orWhere("work_group{$i}_id", $workGroupMasterId);
}
})
->exists();
if (! $existsInLine) {
$workGroupMasterId = null;
$warnMsg[] = "Group work center '{$WorkgroupMaster->name}' is not mapped for the given line!";
} else {
$workGroupMasterId = $WorkgroupMaster->id;
$machine = Machine::where('work_center', $workCenter)->first();
if (! $machine) {
$warnMsg[] = 'Work center not found!';
} else {
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->first();
if (! $machine) {
$warnMsg[] = 'Work center not found for the given plant!';
} else {
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('line_id', $lineId)->first();
if (! $machine) {
$warnMsg[] = 'Work center not found for the given line!';
} else {
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('line_id', $lineId)->where('work_group_master_id', $workGroupMasterId)->first();
if (! $machine) {
$warnMsg[] = 'Work center not found for the given group work center!';
} else {
$machineId = $machine->id;
}
}
}
}
}
}
} }
} }
}
$machine = Machine::where('work_center', $this->data['machine'])->first(); $user = User::where('name', $createdBy)->first();
if (! $machine) { if (! $user) {
$warnMsg[] = 'Work Center not found'; $warnMsg[] = 'Created by user not found!';
} else { } else {
$machineId = $machine->id; $updatedBy = $createdBy;
} }
$machineAgainstPlant = Machine::where('work_center', $this->data['machine']) if ($inspectTyp == 'Value') {
->where('plant_id', $plantId) if (is_null($upper) || is_null($lower) || is_null($middle)) {
->first(); $warnMsg[] = 'Upper, Lower, and Middle values are required.';
} elseif (! is_numeric($upper) || ! is_numeric($lower) || ! is_numeric($middle)) {
if (! $machineAgainstPlant) { $warnMsg[] = 'Upper, Lower, and Middle values must be numeric.';
$warnMsg[] = 'Work Center not found for the given plant'; } elseif ($lower == $upper) {
} else { if ($lower != $middle) {
$machineId = $machineAgainstPlant->id; $warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower = Middle = Upper.";
}
if ($name == null || $name == '') {
$warnMsg[] = "Name can't be empty";
}
$user = User::where('name', $this->data['created_by'])->first();
if (! $user) {
$warnMsg[] = 'Operator ID not found';
}
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
if (! $updatedBy) {
$warnMsg[] = 'Invalid updated by user name found';
}
if (($this->data['inspection_type'] ?? null) == 'Value') {
$lower = $this->data['lower'] ?? null;
$middle = $this->data['middle'] ?? null;
$upper = $this->data['upper'] ?? null;
if (is_null($upper) || is_null($lower) || is_null($middle)) {
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
} elseif (! is_numeric($upper) || ! is_numeric($lower) || ! is_numeric($middle)) {
$warnMsg[] = 'Upper, Lower, and Middle values must be numeric.';
} elseif (! ($lower <= $middle && $middle <= $upper)) {
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower ≤ Middle ≤ Upper.";
} }
} elseif (! ($lower < $middle && $middle < $upper)) {
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower < Middle < Upper.";
} }
} else {
$lower = null;
$middle = null;
$upper = null;
} }
} }
@@ -220,49 +277,33 @@ class ProductCharacteristicsMasterImporter extends Importer
throw new RowImportFailedException(implode(', ', $warnMsg)); throw new RowImportFailedException(implode(', ', $warnMsg));
} }
// $record = ProductCharacteristicsMaster::firstOrNew([ if ($machineId) {
// 'plant_id' => $plantId, $record = ProductCharacteristicsMaster::where('plant_id', $plantId)->where('line_id', $lineId)->where('work_group_master_id', $workGroupMasterId)->where('machine_id', $machineId)->where('item_id', $itemId)->first();
// 'item_id' => $itemId, // ->where('characteristics_type', $get('characteristics_type'))
// 'line_id' => $LineId, if ($record) {
// 'work_group_master_id' => $workGroupMasterId, $createdBy = $record->created_by;
// 'machine_id' => $machineId, }
// ]);
// // If record is new, fill all fields
// if (! $record->exists) {
// $record->name = $name;
// $record->characteristics_type = $this->data['characteristics_type'];
// $record->inspection_type = $this->data['inspection_type'];
// $record->lower = $this->data['lower'] ?? null;
// $record->upper = $this->data['upper'] ?? null;
// $record->middle = $this->data['middle'] ?? null;
// $record->created_by = $this->data['created_by'] ?? null;
// $record->updated_by = $updatedBy ?? null;
// } else {
// // Record exists → update only updated_by and updated_at
// $record->updated_by = $updatedBy ?? null;
// $record->touch();
// }
// $record->save();
ProductCharacteristicsMaster::updateOrCreate( ProductCharacteristicsMaster::updateOrCreate(
[ [
'plant_id' => $plantId, 'plant_id' => $plantId,
'item_id' => $itemId, 'item_id' => $itemId,
'line_id' => $LineId, 'line_id' => $lineId,
'work_group_master_id' => $workGroupMasterId, 'work_group_master_id' => $workGroupMasterId,
'machine_id' => $machineId, 'machine_id' => $machineId,
], // 'characteristics_type' => $charTyp,
[ ],
'name' => $name, [
'characteristics_type' => $this->data['characteristics_type'], 'name' => $charName,
'inspection_type' => $this->data['inspection_type'], 'characteristics_type' => $charTyp,
'lower' => $lower, 'inspection_type' => $inspectTyp,
'middle' => $middle, 'lower' => $lower,
'upper' => $upper, 'middle' => $middle,
// 'created_by' => user ?? $this->data['created_by'], 'upper' => $upper,
'created_by' => $this->data['created_by'] ?? null, 'created_by' => $createdBy,
'updated_by' => $updatedBy ?? null, 'updated_by' => $updatedBy,
]); ]);
}
return null; return null;

View File

@@ -27,6 +27,8 @@ use Filament\Tables\Filters\Filter;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Validation\Rule;
use Str;
class ProductCharacteristicsMasterResource extends Resource class ProductCharacteristicsMasterResource extends Resource
{ {
@@ -71,12 +73,31 @@ class ProductCharacteristicsMasterResource extends Resource
return []; return [];
} }
return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id'); return Item::where('plant_id', $plantId)->pluck('code', 'id');
}) })
->disabled(fn (Get $get) => ! empty($get('id'))) ->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->rules([
function (callable $get) {
return Rule::unique('product_characteristics_masters', 'item_id')
->where('plant_id', $get('plant_id'))
->where('line_id', $get('line_id'))
->where('work_group_master_id', $get('work_group_master_id'))
->where('machine_id', $get('machine_id'))
// ->where('characteristics_type', $get('characteristics_type'))
->ignore($get('id'));
},
// function (callable $get): Closure {
// return function (string $attribute, $value, Closure $fail) use ($get) {
// $rework = $get('rework_status');
// if ($value && Str::contains($value, '.') && $rework == 0) {
// $fail("Rework status should be 'Yes' for rework coil number '{$value}'!");
// }
// };
// },
])
->required(), ->required(),
Forms\Components\Select::make('line_id') Forms\Components\Select::make('line_id')
->label('Line') ->label('Line')
@@ -190,7 +211,7 @@ class ProductCharacteristicsMasterResource extends Resource
}) })
->required(), ->required(),
Forms\Components\TextInput::make('name') Forms\Components\TextInput::make('name')
->label('Name') ->label('Characteristics Name')
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
@@ -311,13 +332,13 @@ class ProductCharacteristicsMasterResource extends Resource
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('line.name') Tables\Columns\TextColumn::make('item.description')
->label('Line') ->label('Item Description')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('characteristics_type') Tables\Columns\TextColumn::make('line.name')
->label('Characteristics Type') ->label('Line')
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
@@ -331,10 +352,16 @@ class ProductCharacteristicsMasterResource extends Resource
->alignCenter() ->alignCenter()
->searchable() ->searchable()
->sortable(), ->sortable(),
// Tables\Columns\TextColumn::make('machine.work_center') Tables\Columns\TextColumn::make('characteristics_type')
// ->label('Work Center') ->label('Characteristics Type')
// ->alignCenter() ->alignCenter()
// ->sortable(), ->searchable()
->sortable(),
Tables\Columns\TextColumn::make('name')
->label('Characteristics Name')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('inspection_type') Tables\Columns\TextColumn::make('inspection_type')
->label('Inspection Type') ->label('Inspection Type')
->alignCenter() ->alignCenter()

View File

@@ -109,8 +109,8 @@ class CharacteristicsController extends Controller
->get([ ->get([
'line_id', 'line_id',
'machine_id', 'machine_id',
'characteristics_type',
'name', 'name',
'characteristics_type',
'inspection_type', 'inspection_type',
'lower', 'lower',
'middle', 'middle',
@@ -2142,7 +2142,6 @@ class CharacteristicsController extends Controller
public function getCharMaster(Request $request) public function getCharMaster(Request $request)
{ {
$expectedUser = env('API_AUTH_USER'); $expectedUser = env('API_AUTH_USER');
$expectedPw = env('API_AUTH_PW'); $expectedPw = env('API_AUTH_PW');
$header_auth = $request->header('Authorization'); $header_auth = $request->header('Authorization');
@@ -2282,8 +2281,8 @@ class CharacteristicsController extends Controller
$output = [ $output = [
'work_group_master' => $workGroupName ?? '', 'work_group_master' => $workGroupName ?? '',
'name' => $charMaster?->name ?? '', 'name' => $charMaster?->name ?? '',
'inspection_type' => $charMaster?->inspection_type ?? '',
'characteristics_type' => $charMaster?->characteristics_type ?? '', 'characteristics_type' => $charMaster?->characteristics_type ?? '',
'inspection_type' => $charMaster?->inspection_type ?? '',
'lower' => (string) $charMaster?->lower ?? '', 'lower' => (string) $charMaster?->lower ?? '',
'middle' => (string) $charMaster?->middle ?? '', 'middle' => (string) $charMaster?->middle ?? '',
'upper' => (string) $charMaster?->upper ?? '', 'upper' => (string) $charMaster?->upper ?? '',