diff --git a/app/Http/Controllers/CharacteristicsController.php b/app/Http/Controllers/CharacteristicsController.php index d4e64232..8e115216 100644 --- a/app/Http/Controllers/CharacteristicsController.php +++ b/app/Http/Controllers/CharacteristicsController.php @@ -2660,7 +2660,7 @@ class CharacteristicsController extends Controller } catch (\Exception $e) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Error occurred while inserting new master characteristics for the serial number '{$serial}', {$e->getMessage()}", + 'status_description' => "Error occurred while searching serial number '{$serial}' to inserting new master characteristics for the job number '{$jobNo}', {$e->getMessage()}", // 'char_data' => $char ], 500); } @@ -2756,7 +2756,7 @@ class CharacteristicsController extends Controller } catch (\Exception $e) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Error occurred while inserting new master characteristics for the serial number '{$serial}', {$e->getMessage()}", + 'status_description' => "Error occurred while inserting new master characteristics for the job number '{$jobNo}' with serial number '{$serial}', {$e->getMessage()}", // 'char_data' => $char ], 500); } @@ -3043,7 +3043,7 @@ class CharacteristicsController extends Controller } catch (\Exception $e) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Error occurred while inserting new master characteristics for the serial number '{$serial}', {$e->getMessage()}", + 'status_description' => "Error occurred while searching serial number '{$serial}' to inserting new master characteristics for the job number '{$jobNo}', {$e->getMessage()}", // 'char_data' => $char ], 500); } @@ -3159,11 +3159,15 @@ class CharacteristicsController extends Controller $existSnoJob = ClassCharacteristic::where('gernr', $serial)->where('aufnr', '!=', $jobNo)->where('plant_id', $plantId)->first(); - if ($existing && $existSnoJob) { // // Skip duplicate warning... - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => "Duplicate serial number '{$serial}' found while updating exist master characteristics in job number '{$existSnoJob->aufnr}'!", - ], 404); + if ($existing) { // // Skip duplicate warning... + if ($existSnoJob) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Duplicate serial number '{$serial}' found while updating exist master characteristics in job number '{$existSnoJob->aufnr}'!", + ], 404); + } else { + $isInsertOrUpdate = true; + } } else { $isInsertOrUpdate = true; $insertData['created_by'] = $userName ?? null; @@ -3172,7 +3176,7 @@ class CharacteristicsController extends Controller } catch (\Exception $e) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Error occurred while inserting new master characteristics for the serial number '{$serial}', {$e->getMessage()}", + 'status_description' => "Error occurred while inserting new master characteristics for the job number '{$jobNo}' with serial number '{$serial}', {$e->getMessage()}", // 'char_data' => $char ], 500); } @@ -4071,13 +4075,21 @@ class CharacteristicsController extends Controller // $itemId = $serials->first()->item_id; // $itemcode = Item::where('id', $itemId)->value('code') ?? ''; + $receivedQty = (int) ($jobWorkCenter?->gamng ?? '0'); + $releasedQty = ClassCharacteristic::where('aufnr', $jobNumber)->where('machine_id', $machineId)->where('plant_id', $plantId)->count(); + $markedSerials = ClassCharacteristic::where('aufnr', $jobNumber)->where('machine_id', $machineId)->where('plant_id', $plantId)->get(['gernr', 'mark_status']); $allMarked = $markedSerials->every(function ($serial) { return strtolower($serial->mark_status) == 'marked'; }); - if ($allMarked) { + if ($receivedQty != $releasedQty) { + return response()->json([ + 'status_code' => 'SUCCESS', + 'status_description' => 'Has some partial serial numbers to mark!', + ], 200); + } elseif ($allMarked) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'All serial numbers are already marked!', // skip @@ -4982,7 +4994,7 @@ class CharacteristicsController extends Controller } elseif ($file && $file->getSize() > 1024 * 1024) { // 1 MB in bytes return response()->json([ 'status' => 'ERROR', - 'status_description' => 'File size must not exceed 1 MB (Megabyte).', + 'status_description' => 'PDF file size must not exceed 1 MB (Megabyte).', ], 404); } } @@ -4990,21 +5002,26 @@ class CharacteristicsController extends Controller if ($request->hasFile('file')) { $extension = strtolower($file->getClientOriginalExtension()); - if ($extension != 'png' && $extension != 'PNG') { + if ($extension != 'png' && $extension != 'PNG' && $extension != 'pdf' && $extension != 'PDF') { return response()->json([ 'status' => 'ERROR', - 'status_description' => "Only .PNG files are allowed for request type '{$requestType}'!", + 'status_description' => "Only .PNG and .PDF files are allowed for request type '{$requestType}'!", ], 404); - } elseif ($file && $file->getSize() > 50 * 1024) { + } elseif (($extension == 'png' || $extension == 'PNG') && $file && $file->getSize() > 50 * 1024) { return response()->json([ 'status' => 'ERROR', - 'status_description' => 'File size must not exceed 50 KB (Kilobyte).', + 'status_description' => 'PNG file size must not exceed 50 KB (Kilobyte).', + ], 404); + } elseif (($extension == 'pdf' || $extension == 'PDF') && $file && $file->getSize() > 1024 * 1024) { + return response()->json([ + 'status' => 'ERROR', + 'status_description' => 'PDF file size must not exceed 1 MB (Megabyte).', ], 404); } } else { return response()->json([ 'status' => 'ERROR', - 'status_description' => 'Quality approval image (.png) not found!', + 'status_description' => 'Quality approval document (.png or .pdf) not found!', ], 404); } } @@ -5572,7 +5589,6 @@ class CharacteristicsController extends Controller return response()->json([ 'work_flow_ids' => [$workFlowIds], ], 200); - } catch (\Exception $e) { return response()->json([ 'status_code' => 'ERROR', @@ -6873,7 +6889,11 @@ class CharacteristicsController extends Controller } else { $extension = ($requestType == 'Characteristic') ? 'pdf' : 'png'; $filePath = "uploads/LaserDocs/{$workFlowId}.{$extension}"; - $filename = "{$workFlowId}.{$extension}"; + $filePdfPath = "uploads/LaserDocs/{$workFlowId}.pdf"; + $filePngPath = "uploads/LaserDocs/{$workFlowId}.png"; + $fileName = "{$workFlowId}.{$extension}"; + $filePdfName = "{$workFlowId}.pdf"; + $filePngName = "{$workFlowId}.png"; $workFlowIdExist = RequestCharacteristic::where('work_flow_id', $workFlowId)->first(); @@ -6888,10 +6908,16 @@ class CharacteristicsController extends Controller // $filename .= '.pdf'; // } - if (! Storage::disk('local')->exists($filePath)) { + if ($requestType == 'Quality' && Storage::disk('local')->exists($filePngPath)) { + $fileName = $filePngName; + $filePath = $filePngPath; + } elseif (Storage::disk('local')->exists($filePdfPath)) { + $fileName = $filePdfName; + $filePath = $filePdfPath; + } elseif (! Storage::disk('local')->exists($filePath)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => ($requestType == 'Characteristic') ? "Characteristic approval document (.PDF) not found for the Work Flow ID '{$workFlowId}'!" : "Quality approval document (.PNG) not found for the Work Flow ID '{$workFlowId}'!", + 'status_description' => ($requestType == 'Characteristic') ? "Characteristic approval document (.PDF) not found for the Work Flow ID '{$workFlowId}'!" : "Quality approval document (.PNG or .PDF) not found for the Work Flow ID '{$workFlowId}'!", ], 404); } @@ -6900,7 +6926,7 @@ class CharacteristicsController extends Controller return Response::make($file, 200, [ 'Content-Type' => $mimeType, - 'Content-Disposition' => 'inline; filename="'.$filename.'"', + 'Content-Disposition' => 'inline; filename="'.$fileName.'"', ]); } }