Updated validation logic on importer and exporter
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
This commit is contained in:
@@ -29,7 +29,7 @@ class ProductCharacteristicsMasterExporter extends Exporter
|
|||||||
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')
|
||||||
->label('WORK GROUP MASTER'),
|
->label('GROUP WORK CENTER'),
|
||||||
ExportColumn::make('machine.work_center')
|
ExportColumn::make('machine.work_center')
|
||||||
->label('WORK CENTER'),
|
->label('WORK CENTER'),
|
||||||
ExportColumn::make('characteristics_type')
|
ExportColumn::make('characteristics_type')
|
||||||
|
|||||||
@@ -176,20 +176,7 @@ class ProcessOrderImporter extends Importer
|
|||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// return ProcessOrder::create([
|
$lineId = null;
|
||||||
// 'plant_id' => $plant->id,
|
|
||||||
// 'item_id' => $itemCode->id,
|
|
||||||
// 'line_id' => $lineId,
|
|
||||||
// 'process_order' => trim($this->data['process_order']),
|
|
||||||
// 'coil_number' => $coilNo,
|
|
||||||
// 'order_quantity' => $orderQuan,
|
|
||||||
// 'received_quantity' => $recQuan,
|
|
||||||
// 'sfg_number' => $sfgNo,
|
|
||||||
// 'machine_name' => $machineName,
|
|
||||||
// 'scrap_quantity' => $scrapQuan,
|
|
||||||
// 'rework_status' => $reworkStatus,
|
|
||||||
// 'created_by' => $createdBy,
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
if($lineName != null && $lineName != ''){
|
if($lineName != null && $lineName != ''){
|
||||||
|
|
||||||
@@ -233,7 +220,7 @@ class ProcessOrderImporter extends Importer
|
|||||||
'scrap_quantity' => $scrapQuan,
|
'scrap_quantity' => $scrapQuan,
|
||||||
// 'sfg_number' => $sfgNo,
|
// 'sfg_number' => $sfgNo,
|
||||||
// 'machine_name' => $machineId,
|
// 'machine_name' => $machineId,
|
||||||
'rework_status' => 1,
|
'rework_status' => $reworkStatus,
|
||||||
'updated_by' => $updatedBy,
|
'updated_by' => $updatedBy,
|
||||||
'updated_at' => $updatedAt,
|
'updated_at' => $updatedAt,
|
||||||
]);
|
]);
|
||||||
@@ -279,7 +266,7 @@ class ProcessOrderImporter extends Importer
|
|||||||
'scrap_quantity' => $scrapQuan,
|
'scrap_quantity' => $scrapQuan,
|
||||||
// 'sfg_number' => $sfgNo,
|
// 'sfg_number' => $sfgNo,
|
||||||
// 'machine_name' => $machineId,
|
// 'machine_name' => $machineId,
|
||||||
'rework_status' => 1,
|
'rework_status' => $reworkStatus,
|
||||||
'updated_by' => $updatedBy,
|
'updated_by' => $updatedBy,
|
||||||
'updated_at' => $updatedAt,
|
'updated_at' => $updatedAt,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
|||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Filament\Facades\Filament;
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class ProductCharacteristicsMasterImporter extends Importer
|
class ProductCharacteristicsMasterImporter extends Importer
|
||||||
@@ -75,7 +75,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('lower')
|
ImportColumn::make('lower')
|
||||||
->exampleHeader('Lower')
|
->exampleHeader('Lower')
|
||||||
->example('-0.2')
|
->example('0')
|
||||||
->label('Lower')
|
->label('Lower')
|
||||||
->rules(['numeric']),
|
->rules(['numeric']),
|
||||||
ImportColumn::make('middle')
|
ImportColumn::make('middle')
|
||||||
@@ -86,7 +86,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->rules(['numeric']),
|
->rules(['numeric']),
|
||||||
ImportColumn::make('upper')
|
ImportColumn::make('upper')
|
||||||
->exampleHeader('Upper')
|
->exampleHeader('Upper')
|
||||||
->example('0.2')
|
->example('2')
|
||||||
->label('Upper')
|
->label('Upper')
|
||||||
->rules(['numeric']),
|
->rules(['numeric']),
|
||||||
ImportColumn::make('created_by')
|
ImportColumn::make('created_by')
|
||||||
@@ -103,7 +103,12 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
|
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plantCod = $this->data['plant'];
|
$plantCod = $this->data['plant'];
|
||||||
$plant = null;
|
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||||
|
$lower = null;
|
||||||
|
$middle = null;
|
||||||
|
$upper = null;
|
||||||
|
$plantId = null;
|
||||||
|
$name = trim($this->data['name']);
|
||||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$warnMsg[] = 'Invalid plant code found';
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
} else {
|
} else {
|
||||||
@@ -111,13 +116,14 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
if (! $plant) {
|
if (! $plant) {
|
||||||
$warnMsg[] = 'Plant not found';
|
$warnMsg[] = 'Plant not found';
|
||||||
} else {
|
} else {
|
||||||
|
$plantId = $plant->id;
|
||||||
$itemExists = Item::where('code', $this->data['item'])->first();
|
$itemExists = Item::where('code', $this->data['item'])->first();
|
||||||
if (! $itemExists) {
|
if (! $itemExists) {
|
||||||
$warnMsg[] = 'Item not found';
|
$warnMsg[] = 'Item not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemAgainstPlant = Item::where('code', $this->data['item'])
|
$itemAgainstPlant = Item::where('code', $this->data['item'])
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plantId)
|
||||||
->first();
|
->first();
|
||||||
if (! $itemAgainstPlant) {
|
if (! $itemAgainstPlant) {
|
||||||
$warnMsg[] = 'Item code not found for the given plant';
|
$warnMsg[] = 'Item code not found for the given plant';
|
||||||
@@ -131,7 +137,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lineAgainstPlant = Line::where('name', $this->data['line'])
|
$lineAgainstPlant = Line::where('name', $this->data['line'])
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plantId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $lineAgainstPlant) {
|
if (! $lineAgainstPlant) {
|
||||||
@@ -140,7 +146,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$LineId = $lineAgainstPlant->id;
|
$LineId = $lineAgainstPlant->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plant->id)->first();
|
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plantId)->first();
|
||||||
if (! $WorkgroupMaster) {
|
if (! $WorkgroupMaster) {
|
||||||
$warnMsg[] = 'Work Group Master value not found';
|
$warnMsg[] = 'Work Group Master value not found';
|
||||||
} else {
|
} else {
|
||||||
@@ -148,7 +154,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$workGroupMasterId = $WorkgroupMaster->id;
|
$workGroupMasterId = $WorkgroupMaster->id;
|
||||||
|
|
||||||
// 2. Now check if this WorkGroupMaster id exists in ANY of the 10 columns
|
// 2. Now check if this WorkGroupMaster id exists in ANY of the 10 columns
|
||||||
$existsInLine = Line::where('plant_id', $plant->id)
|
$existsInLine = Line::where('plant_id', $plantId)
|
||||||
->where(function ($q) use ($workGroupMasterId) {
|
->where(function ($q) use ($workGroupMasterId) {
|
||||||
for ($i = 1; $i <= 10; $i++) {
|
for ($i = 1; $i <= 10; $i++) {
|
||||||
$q->orWhere("work_group{$i}_id", $workGroupMasterId);
|
$q->orWhere("work_group{$i}_id", $workGroupMasterId);
|
||||||
@@ -171,7 +177,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
$machineAgainstPlant = Machine::where('work_center', $this->data['machine'])
|
$machineAgainstPlant = Machine::where('work_center', $this->data['machine'])
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plantId)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $machineAgainstPlant) {
|
if (! $machineAgainstPlant) {
|
||||||
@@ -180,15 +186,24 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$machineId = $machineAgainstPlant->id;
|
$machineId = $machineAgainstPlant->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($name == null || $name == '') {
|
||||||
|
$warnMsg[] = "Name can't be empty";
|
||||||
|
}
|
||||||
|
|
||||||
$user = User::where('name', $this->data['created_by'])->first();
|
$user = User::where('name', $this->data['created_by'])->first();
|
||||||
if (! $user) {
|
if (! $user) {
|
||||||
$warnMsg[] = 'Operator ID not found';
|
$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') {
|
if (($this->data['inspection_type'] ?? null) == 'Value') {
|
||||||
$upper = $this->data['upper'] ?? null;
|
|
||||||
$lower = $this->data['lower'] ?? null;
|
$lower = $this->data['lower'] ?? null;
|
||||||
$middle = $this->data['middle'] ?? null;
|
$middle = $this->data['middle'] ?? null;
|
||||||
|
$upper = $this->data['upper'] ?? null;
|
||||||
|
|
||||||
if (is_null($upper) || is_null($lower) || is_null($middle)) {
|
if (is_null($upper) || is_null($lower) || is_null($middle)) {
|
||||||
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
|
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
|
||||||
@@ -203,64 +218,55 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
} else {
|
}
|
||||||
$record = ProductCharacteristicsMaster::firstOrNew([
|
|
||||||
'plant_id' => $plant->id,
|
// $record = ProductCharacteristicsMaster::firstOrNew([
|
||||||
|
// 'plant_id' => $plantId,
|
||||||
|
// 'item_id' => $itemId,
|
||||||
|
// 'line_id' => $LineId,
|
||||||
|
// 'work_group_master_id' => $workGroupMasterId,
|
||||||
|
// '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(
|
||||||
|
[
|
||||||
|
'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,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => $name,
|
||||||
|
'characteristics_type' => $this->data['characteristics_type'],
|
||||||
|
'inspection_type' => $this->data['inspection_type'],
|
||||||
|
'lower' => $lower,
|
||||||
|
'middle' => $middle,
|
||||||
|
'upper' => $upper,
|
||||||
|
// 'created_by' => user ?? $this->data['created_by'],
|
||||||
|
'created_by' => $this->data['created_by'] ?? null,
|
||||||
|
'updated_by' => $updatedBy ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$currentUser = Auth::check() ? Auth::user()->name : ($this->data['created_by'] ?? 'System');
|
|
||||||
|
|
||||||
// If record is new, fill all fields
|
|
||||||
if (! $record->exists) {
|
|
||||||
$record->name = $this->data['name'];
|
|
||||||
$record->characteristics_type = $this->data['characteristics_type'];
|
|
||||||
$record->inspection_type = $this->data['inspection_type'];
|
|
||||||
$record->upper = $this->data['upper'] ?? null;
|
|
||||||
$record->lower = $this->data['lower'] ?? null;
|
|
||||||
$record->middle = $this->data['middle'] ?? null;
|
|
||||||
$record->created_by = $currentUser;
|
|
||||||
} else {
|
|
||||||
// Record exists → update only updated_by and updated_at
|
|
||||||
$record->updated_by = $currentUser;
|
|
||||||
$record->touch();
|
|
||||||
}
|
|
||||||
|
|
||||||
$record->save();
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// ProductCharacteristicsMaster::updateOrCreate(
|
|
||||||
// [
|
|
||||||
// 'plant_id' => $plant->id,
|
|
||||||
// 'item_id' => $itemId,
|
|
||||||
// 'line_id' => $LineId,
|
|
||||||
// 'work_group_master_id' => $workGroupMasterId,
|
|
||||||
// 'machine_id'=> $machineId,
|
|
||||||
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'name' => $this->data['name'],
|
|
||||||
// 'characteristics_type' => $this->data['characteristics_type'],
|
|
||||||
// 'inspection_type' => $this->data['inspection_type'],
|
|
||||||
// 'upper' => $this->data['upper'] ?? null,
|
|
||||||
// 'lower' => $this->data['lower'] ?? null,
|
|
||||||
// 'middle' => $this->data['middle'] ?? null,
|
|
||||||
// //'created_by' => user ?? $this->data['created_by'],
|
|
||||||
// 'created_by' => Auth::check() ? Auth::user()->name :($this->data['created_by'] ?? null)
|
|
||||||
// ]
|
|
||||||
// );
|
|
||||||
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return new WorkGroupMaster();
|
// return new WorkGroupMaster();
|
||||||
|
|
||||||
// return new ProductCharacteristicsMaster();
|
// return new ProductCharacteristicsMaster();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user