Added item description, spec. value on exporter and Updated process order validations on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s

This commit is contained in:
dhanabalan
2026-02-27 01:10:23 +05:30
parent 62dcc122e8
commit ab534b4c46
2 changed files with 104 additions and 86 deletions

View File

@@ -24,13 +24,13 @@ class ProcessOrderImporter extends Importer
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('PLANT CODE')
->example('1000')
->example('1200')
->label('PLANT CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('line')
->exampleHeader('LINE NAME')
->example(' Polywrapped line')
->example(' Poly Wrapped Wire SFG')
->label('LINE NAME')
->relationship(resolveUsing: 'name'),
ImportColumn::make('item')
@@ -43,54 +43,54 @@ class ProcessOrderImporter extends Importer
ImportColumn::make('process_order')
->requiredMapping()
->exampleHeader('PROCESS ORDER')
->example('202500123456')
->example('2025002123456')
->label('PROCESS ORDER')
->rules(['required']),
ImportColumn::make('coil_number')
->exampleHeader('COIL NUMBER')
->example('01')
->label('COIL NUMBER'),
ImportColumn::make('order_quantity')
->requiredMapping()
->exampleHeader('ORDER QUANTITY')
->example('100')
->example('1000')
->label('ORDER QUANTITY')
->rules(['required']),
ImportColumn::make('coil_number')
->exampleHeader('COIL NUMBER')
// ->example('01')
->label('COIL NUMBER'),
ImportColumn::make('received_quantity')
->exampleHeader('RECEIVED QUANTITY')
->example('01')
// ->example('01')
->label('RECEIVED QUANTITY'),
ImportColumn::make('sfg_number')
->exampleHeader('SFG NUMBER')
->example('200000220613-72')
// ->example('200000220613-72')
->label('SFG NUMBER'),
ImportColumn::make('machine_name')
->exampleHeader('MACHINE NAME')
->example('WMIWRM13 - 2-L2')
// ->example('WMIWRM13 - 2-L2')
->label('MACHINE NAME'),
ImportColumn::make('scrap_quantity')
->exampleHeader('SCRAP QUANTITY')
->example('0')
// ->example('0')
->label('SCRAP QUANTITY'),
ImportColumn::make('rework_status')
->exampleHeader('REWORK STATUS')
->example('0')
// ->example('0')
->label('REWORK STATUS'),
ImportColumn::make('created_at')
->exampleHeader('CREATED AT')
->example('2026-02-20 13:00:00')
// ->example('2026-02-20 13:00:00')
->label('CREATED AT'),
ImportColumn::make('updated_at')
->exampleHeader('UPDATED AT')
->example('2026-02-20 13:00:00')
// ->example('2026-02-20 13:00:00')
->label('UPDATED AT'),
ImportColumn::make('created_by')
->exampleHeader('CREATED BY')
->example('RAW01234')
// ->example('RAW01234')
->label('CREATED BY'),
ImportColumn::make('updated_by')
->exampleHeader('UPDATED BY')
->example('RAW01234')
// ->example('RAW01234')
->label('UPDATED BY'),
];
}
@@ -98,12 +98,13 @@ class ProcessOrderImporter extends Importer
public function resolveRecord(): ?ProcessOrder
{
$warnMsg = [];
$plantCod = $this->data['plant'];
$plant = null;
$plantCod = trim($this->data['plant']) ?? '';
$plantId = null;
$item = null;
$iCode = trim($this->data['item']) ?? '';
$itemId = null;
$iCode = trim($this->data['item']);
$lineName = trim($this->data['line']);
$lineNam = trim($this->data['line']) ?? '';
$processOrder = trim($this->data['process_order'] ?? '');
$coilNo = trim($this->data['coil_number'] ?? '');
$sfgNo = trim($this->data['sfg_number'] ?? '');
@@ -120,18 +121,27 @@ class ProcessOrderImporter extends Importer
// $operatorName = $user->name;
if ($plantCod == null || $plantCod == '') {
$warnMsg[] = 'Plant code cannot be empty';
$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 ($iCode == null || $iCode == '') {
$warnMsg[] = 'Item code cannot be empty';
$warnMsg[] = "Item code can't be empty!";
} elseif (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
$warnMsg[] = 'Invalid item code found';
}
if ($processOrder == null || $processOrder == '') {
$warnMsg[] = 'Process order cannot be empty';
$warnMsg[] = "Process order can't be empty!";
}
if ($lineNam == null || $lineNam == '') {
$warnMsg[] = "Line name can't be empty!";
}
if ($orderQuan == null || $orderQuan == '') {
$warnMsg[] = 'Order quantity cannot be empty';
$warnMsg[] = "Order quantity can't be empty!";
} elseif ($orderQuan == 0 || $orderQuan == '0') {
$warnMsg[] = 'Order quantity cannot be zero';
$warnMsg[] = "Order quantity can't be zero!";
} elseif (Str::length($orderQuan) >= 1 && ! is_numeric($orderQuan)) {
$warnMsg[] = 'Invalid order quantity found!';
}
if ($coilNo == null || $coilNo == '') {
$coilNo = '0';
@@ -150,37 +160,46 @@ class ProcessOrderImporter extends Importer
$warnMsg[] = 'Invalid rework status found';
}
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$plantId = $plant->id;
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
$warnMsg[] = 'Invalid item code found';
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found!';
} else {
$itemCode = Item::where('code', $iCode)->first();
if (! $itemCode) {
$warnMsg[] = 'Item code not found';
} else {
if ($plantId) {
$itemCode = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
if (! $itemCode) {
$warnMsg[] = 'Item code not found for the given plant';
} else {
$itemId = $itemCode->id;
}
$plantId = $plant->id;
}
$itemCode = Item::where('code', $iCode)->first();
if (! $itemCode) {
$warnMsg[] = 'Item code not found!';
} else {
if ($plantId) {
$itemCode = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
if (! $itemCode) {
$warnMsg[] = 'Item code not found for the given plant!';
} else {
$itemId = $itemCode->id;
}
}
}
if ($plant && $itemCode && $processOrder != '') {
$lineExists = Line::where('name', $lineNam)->first();
if (! $lineExists) {
$warnMsg[] = 'Line name not found!';
} else {
if ($plantId) {
$lineAgainstPlant = Line::where('name', $lineNam)->where('plant_id', $plantId)->first();
if (! $lineAgainstPlant) {
$warnMsg[] = 'Line name not found for the given plant!';
} else {
$lineId = $lineAgainstPlant->id;
}
}
}
if ($plantId && $itemCode && $lineId && $processOrder != '') {
$existingOrder = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->first();
@@ -190,27 +209,9 @@ class ProcessOrderImporter extends Importer
}
}
if ($lineName != null && $lineName != '') {
$lineExists = Line::where('name', $lineName)->first();
if (! $lineExists) {
$warnMsg[] = 'Line name not found';
} else {
if ($plantId) {
$lineAgainstPlant = Line::where('name', $lineName)->where('plant_id', $plantId)->first();
if (! $lineAgainstPlant) {
$warnMsg[] = 'Line name not found for the given plant';
} else {
$lineId = $lineAgainstPlant->id;
}
}
}
} else {
$lineId = null;
}
// $user = User::where('name', $this->data['created_by'])->first();
// if (! $user) {
// $warnMsg[] = 'User not found';
// $warnMsg[] = 'User not found!';
// }
if (! $createdBy) {
@@ -224,7 +225,7 @@ class ProcessOrderImporter extends Importer
throw new RowImportFailedException(implode(', ', $warnMsg));
}
if ($lineName != null && $lineName != '') {
if ($coilNo != null && $coilNo != '' && $scrapQuan && $reworkStatus && $recQuan && $createdAt && $createdBy && $updatedAt && $updatedBy && Filament::auth()->user()->hasRole('Super Admin')) {
$existingCoil = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('line_id', $lineId)
@@ -267,11 +268,11 @@ class ProcessOrderImporter extends Importer
'updated_at' => $updatedAt,
]);
}
} elseif ($lineName == null || $lineName == '') {
} else {
$coilNo = '0';
$existing = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('coil_number', $coilNo)
// ->where('coil_number', $coilNo)
->first();
if (! $existing && ($coilNo == '0' || $coilNo == 0)) {
@@ -308,23 +309,25 @@ class ProcessOrderImporter extends Importer
]
);
} else {// $coilNo = '0'
if ($existing->rework_status == 1 && $reworkStatus == 0) {
if ($existing->process_order == $processOrder) {
throw new RowImportFailedException('Process order already exist for the given plant!');
} elseif ($existing->rework_status == 1 && $reworkStatus == 0) {
throw new RowImportFailedException('Rework coil number already exist for the given Plant and Process Order!');
} else {
ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('coil_number', $coilNo)
->update([
// 'order_quantity' => $orderQty,
'received_quantity' => $recQuan,
'scrap_quantity' => $scrapQuan,
// 'sfg_number' => $sfgNo,
// 'machine_name' => $machineId,
'rework_status' => $reworkStatus,
'updated_by' => $updatedBy,
// 'updated_at' => $updatedAt,
]);
}
ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('coil_number', $coilNo)
->update([
// 'order_quantity' => $orderQty,
'received_quantity' => $recQuan,
'scrap_quantity' => $scrapQuan,
// 'sfg_number' => $sfgNo,
// 'machine_name' => $machineId,
'rework_status' => $reworkStatus,
'updated_by' => $updatedBy,
// 'updated_at' => $updatedAt,
]);
}
}