Updated rework coil functionality #332

Merged
jothi merged 1 commits from ranjith-dev into master 2026-02-12 13:29:23 +00:00

View File

@@ -755,7 +755,7 @@ class PdfController extends Controller
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Coil number can't be empty!", 'status_description' => "Coil number can't be empty!",
], 404); ], 404);
} elseif (! is_numeric($coilNo) || Str::length($coilNo) <= 0 || !preg_match('/^\d+(\.\d+)?$/', $coilNo) } elseif (! is_numeric($coilNo) || Str::length($coilNo) <= 0 || ! preg_match('/^\d+(\.\d+)?$/', $coilNo)
) { // !ctype_digit($data['plant_code']) ) { // !ctype_digit($data['plant_code'])
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
@@ -880,7 +880,7 @@ class PdfController extends Controller
if ($rework == null || $rework == '' || ! $rework) { if ($rework == null || $rework == '' || ! $rework) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Rework can't be empty!", 'status_description' => "Rework value can't be empty!",
], 404); ], 404);
} }
@@ -898,8 +898,61 @@ class PdfController extends Controller
} }
} }
$coilNo = (string) $coilNo;
try { try {
if ($rework == 'Yes') { if ($rework == 'Yes') {
if ($coilNo && Str::contains($coilNo, '.')) {
// Contains dot
$coilMain = explode('.', $coilNo)[0]; // 333
$existingCoil = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('line_id', $lineNamePlantId)
->where('coil_number', $coilMain)
->first();
if (! $existingCoil) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Coil number '{$coilMain}' not exist against plant code '{$plantCode}' and process order '{$processOrder}'!",
], 404);
} elseif ($existingCoil->rework_status == 0) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Rework coil number '{$coilMain}' not exist against plant code '{$plantCode}' and process order '{$processOrder}'!",
], 404);
}
$existingCoil = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('line_id', $lineNamePlantId)
->where('coil_number', $coilNo)
->first();
if (! $existingCoil) {
ProcessOrder::Create(
[
'plant_id' => $plantId,
'line_id' => $lineNamePlantId,
'process_order' => $processOrder,
'item_id' => $itemId,
'coil_number' => $coilNo,
'order_quantity' => $orderQty,
'received_quantity' => $receivedQty,
'scrap_quantity' => $scrapQty,
'sfg_number' => $sfgNo,
'machine_name' => $machineId,
'rework_status' => 1,
'created_by' => $createdBy,
]
);
return response()->json([
'status_code' => 'SUCCESS',
'status_description' => 'Record Updated Successfully (Rework).',
]);
} else {
$updated = ProcessOrder::where('plant_id', $plantId) $updated = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder) ->where('process_order', $processOrder)
->where('line_id', $lineNamePlantId) ->where('line_id', $lineNamePlantId)
@@ -914,19 +967,56 @@ class PdfController extends Controller
'updated_by' => $createdBy, 'updated_by' => $createdBy,
'updated_at' => now(), 'updated_at' => now(),
]); ]);
}
} else {
$existingCoil = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('line_id', $lineNamePlantId)
->where('coil_number', $coilNo)
->first();
if (! $existingCoil) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Coil number '{$coilNo}' not exist against plant code '{$plantCode}' and process order '{$processOrder}'!",
], 404);
}
$updated = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('line_id', $lineNamePlantId)
->where('coil_number', $coilNo)
->update([
// 'order_quantity' => $orderQty,
'received_quantity' => $receivedQty,
'scrap_quantity' => $scrapQty,
// 'sfg_number' => $sfgNo,
// 'machine_name' => $machineId,
'rework_status' => 1,
'updated_by' => $createdBy,
'updated_at' => now(),
]);
}
if ($updated == 0) { if ($updated == 0) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'No matching record found for rework coil number!', 'status_description' => "No matching record found for rework coil number '{$coilNo}'!",
], 404); ], 404);
} else { } else {
return response()->json([ return response()->json([
'status_code' => 'SUCCESS', 'status_code' => 'SUCCESS',
'status_description' => 'Record Updated Successfully (Rework)', 'status_description' => 'Record Updated Successfully (Rework).',
]); ]);
} }
} else { } else {
if ($coilNo && Str::contains($coilNo, '.')) {
return response()->json([
'status_code' => 'ERROR',
'status_description1' => "Rework value should be 'Yes' for rework coil number '{$coilNo}'!",
], 404);
}
$existing = ProcessOrder::where('plant_id', $plantId) $existing = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder) ->where('process_order', $processOrder)
->where('coil_number', $coilNo) ->where('coil_number', $coilNo)
@@ -935,7 +1025,8 @@ class PdfController extends Controller
if ($existing) { if ($existing) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!", 'status_description' => "Coil number '{$coilNo}' already exist against plant code '{$plantCode}' and process order '{$processOrder}'!",
// "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!",
], 404); ], 404);
} }
@@ -958,7 +1049,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'SUCCESS', 'status_code' => 'SUCCESS',
'status_description' => 'Record Inserted Successfully', 'status_description' => 'Record Inserted Successfully.',
]); ]);
} }
} catch (\Exception $e) { } catch (\Exception $e) {