diff --git a/app/Http/Controllers/CharacteristicsController.php b/app/Http/Controllers/CharacteristicsController.php index b27c5ae..5aba9d3 100644 --- a/app/Http/Controllers/CharacteristicsController.php +++ b/app/Http/Controllers/CharacteristicsController.php @@ -11,6 +11,7 @@ use App\Models\Machine; use App\Models\Plant; use App\Models\ProductCharacteristicsMaster; use App\Models\RequestCharacteristic; +use App\Models\StickerMaster; use App\Models\User; use App\Models\WorkGroupMaster; use Illuminate\Http\Request; @@ -41,7 +42,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 403); + ], 401); } $plantCode = $request->header('plant-code'); @@ -224,8 +225,10 @@ class CharacteristicsController extends Controller $expectedToken = $expectedUser.':'.$expectedPw; if ('Bearer '.$expectedToken != $header_auth) { - return response('ERROR: Unauthorized', 403) - ->header('Content-Type', 'text/plain'); + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token!', + ], 401); } $userName = $request->header('user-name'); @@ -246,18 +249,20 @@ class CharacteristicsController extends Controller $jobNo = $data['aufnr'] ?? ''; $serialNumber = $data['gernr'] ?? ''; $itemCode = $data['item_code'] ?? ''; + $modelType = $data['model_type'] ?? ''; + $expectedTime = $data['expected_time'] ?? 0; $characteristics = $data['characteristics']; if ($plantCode == null || $plantCode == '' || ! $plantCode) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", - ], 400); + ], 404); } elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code']) return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid plant code found!', - ], 400); + ], 404); } if ($workCenter == null || $workCenter == '' || ! $workCenter) { @@ -267,6 +272,34 @@ class CharacteristicsController extends Controller ], 404); } + if ($modelType == null || $modelType == '' || ! $modelType) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Marked model type can't be empty!", + ], 404); + } + + if ($modelType != 'MOTOR' && $modelType != 'PUMP' && $modelType != 'PUMPSET' && $modelType != 'NAME_PLATE') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have valid marked model type to proceed!", + ], 404); + } + + if ($expectedTime == null || $expectedTime == '' || ! $expectedTime) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Expected time can't be empty or zero!", + ], 404); + } elseif (! is_numeric($expectedTime)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid expected time found!', + ], 404); + } else { + $expectedTime = (float) $expectedTime; + } + $plant = Plant::where('code', $plantCode)->first(); if (! $plant) { @@ -323,13 +356,18 @@ class CharacteristicsController extends Controller if (Str::length($jobNo) < 7) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Job number '$jobNo' should contain minimum 7 digits!", - ], 400); + 'status_description' => "Job number '{$jobNo}' should contain minimum 7 digits!", + ], 404); } elseif (! is_numeric($jobNo)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Job number '$jobNo' should contain only numeric values!", - ], 400); + 'status_description' => "Job number '{$jobNo}' should contain only numeric values!", + ], 404); + } elseif (! preg_match('/^[1-9]\d{6,}$/', $jobNo)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Job number '{$jobNo}' should not begin with '0'!", + ], 404); } $job = ClassCharacteristic::where('aufnr', $jobNo)->first(); @@ -374,29 +412,39 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' should contain minimum 9 digits!", - ], 400); + ], 404); } elseif (! ctype_alnum($serialNumber)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' should contain only alpha-numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' should not begin with '0'!", + ], 404); } if ($itemCode == null || $itemCode == '' || ! $itemCode) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Item code can't be empty!", - ], 400); + ], 404); } elseif (Str::length($itemCode) < 6) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Item code should contain minimum 6 digits!', - ], 400); + 'status_description' => "Item code '{$itemCode}' should contain minimum 6 digits!", + ], 404); } elseif (! ctype_alnum($itemCode)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Item code should contain only alpha-numeric values!', - ], 400); + 'status_description' => "Item code '{$itemCode}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should not begin with '0'!", + ], 404); } $item = Item::where('code', $itemCode)->first(); @@ -453,13 +501,9 @@ class CharacteristicsController extends Controller ], 404); } - $sNoWorkCenter = ClassCharacteristic::where('gernr', $serialNumber) - ->where('plant_id', $plantId) - ->where('item_id', $itemId) - ->where('machine_id', $machineId) - ->first(); + $curStat = ClassCharacteristic::where('plant_id', $plantId)->where('machine_id', $machineId)->where('gernr', $serialNumber)->where('item_id', $itemId)->first(); - if (! $sNoWorkCenter) { + if (! $curStat) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' not found for the work center '{$workCenter}'!", @@ -473,35 +517,106 @@ class CharacteristicsController extends Controller ], 404); } + $curHead = null; + $hasMvhs = false; if ($jobNo != null && $jobNo != '' && $jobNo) { - // $sNoJob = ClassCharacteristic::where('aufnr', $jobNo) - // ->where('plant_id', $plantId) - // ->where('gernr', $serialNumber) - // ->where('item_id', $itemId) - // ->first(); - // if (!$sNoJob) { - // return response()->json([ - // 'status_code' => "ERROR", - // 'status_description' => "Serial number '{$serialNumber}' not found for the job number '$jobNo'!" - // ], 404); - // } + $curStat = ClassCharacteristic::where('plant_id', $plantId)->where('machine_id', $machineId)->where('aufnr', $jobNo)->where('gernr', $serialNumber)->where('item_id', $itemId)->first(); - $sNoJob = ClassCharacteristic::where('aufnr', $jobNo) - ->where('plant_id', $plantId) - ->where('machine_id', $machineId) - ->where('gernr', $serialNumber) - ->where('item_id', $itemId) - ->first(); - - if (! $sNoJob) { + if (! $curStat) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' not found for the job number '$jobNo'!", ], 404); + } else { + $curHead = $curStat?->zmm_heading; + if (Str::contains($curHead, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $hasMvhs = true; + } + } + } else { + $curHead = $curStat?->zmm_heading; + if (Str::contains($curHead, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $hasMvhs = true; } } - $col = ['marked_by', 'man_marked_by', 'motor_marked_by', 'pump_marked_by']; + $mvhsCnt = 1; + if ($hasMvhs == true) { + $stick = StickerMaster::where('item_id', $itemId)->first(); + + if (! $stick) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master!", + ], 404); + } + + $stickPlant = StickerMaster::where('item_id', $itemId) + ->where('plant_id', $plantId) + ->first(); + + if (! $stickPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master for the plant code '{$plantCode}'!", + ], 404); + } else { + $curMvhs = trim($stickPlant?->laser_part_validation2); + if ($curMvhs == null || $curMvhs == '' || ! is_numeric($curMvhs) || Str::length($curMvhs) <= 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid MVHS master count found in sticker master!', + ], 404); + } elseif (! preg_match('/^[1-9]$/', $curMvhs)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'The MVHS master count should be between 1 to 9.', // "MVHS master count '{$curMvhs}' should contain only numeric values between 1 to 9!" + ], 404); + } elseif ($modelType == 'PUMPSET') { + $mvhsCnt = 1; + } else { + $mvhsCnt = $curMvhs; + } + } + } else { + if ($modelType == 'NAME_PLATE') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have name plate model to proceed!", + ], 404); + } elseif (Str::contains($curHead, 'PUMP', ignoreCase: true) && ! Str::contains($curHead, 'PUMP SET', ignoreCase: true) && ! Str::contains($curHead, 'PUMPSET', ignoreCase: true)) { + if ($modelType == 'MOTOR') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have motor model to proceed!", + ], 404); + } elseif ($modelType == 'PUMPSET') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have pumpset model to proceed!", + ], 404); + } + } elseif (Str::contains($curHead, 'MOTOR', ignoreCase: true)) { + if ($modelType == 'PUMP') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have pump model to proceed!", + ], 404); + } elseif ($modelType == 'PUMPSET') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have pumpset model to proceed!", + ], 404); + } + } elseif (! Str::contains($curHead, 'PUMPSET', ignoreCase: true)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have valid model type to proceed!", + ], 404); + } + } + + $col = ['marked_by', 'man_marked_by', 'motor_marked_by', 'pump_marked_by', 'name_plate_marked_by']; $missingUsers = []; $missingUsersPlant = []; $missingUsersRight = []; @@ -560,148 +675,353 @@ class CharacteristicsController extends Controller $isAuto = false; foreach ($data['characteristics'] as $char) { - - // $values = [ - // 'mark_status' => $char['mark_status'] ?? null, - // 'marked_datetime' => $char['marked_datetime'] ?? null, - // 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - // 'man_marked_status' => $char['man_marked_status'] ?? null, - // 'man_marked_datetime' => $char['man_marked_datetime'] ?? null, - // 'man_marked_by' => ($char['man_marked_by'] == 'jothi') ? 'Admin' : $char['man_marked_by'] ?? null, - // 'motor_marked_status' => $char['motor_marked_status'] ?? null, - // 'pump_marked_status' => $char['pump_marked_status'] ?? null, - // 'motor_pump_pumpset_status' => $char['motor_pump_pumpset_status'] ?? null, - // 'part_validation_1' => $char['part_validation_1'] ?? null, - // 'part_validation_2' => $char['part_validation_2'] ?? null, - // 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, - // 'pending_released_status' => $char['pending_released_status'] ?? null, - // 'expected_time' => $char['expected_time'] ?? null, - // 'updated_by' => $userName ?? null, - // ]; - + $curMarkStat = $curStat->mark_status ?? null; + $curMotorMarkStat = $curStat->motor_marked_status ?? null; + $curPumpMarkStat = $curStat->pump_marked_status ?? null; + $curNamePlateMarkStat = $curStat->name_plate_marked_status ?? null; + $curMarkBy = $curStat->marked_by ?? null; + $curMotorMarkBy = $curStat->motor_marked_by ?? null; + $curPumpMarkBy = $curStat->pump_marked_by ?? null; + $curNamePlateMarkBy = $curStat->name_plate_marked_by ?? null; + $curManualMarkBy = $curStat->man_marked_by ?? null; + $curWindNo = $curStat->winded_serial_number ?? null; + $curMMach = $curStat->motor_machine_name ?? null; + $curPMach = $curStat->pump_machine_name ?? null; + $curNpMach = $curStat->name_plate_machine_name ?? null; + $curPsMach = $curStat->pumpset_machine_name ?? null; + $curPart1 = $curStat->part_validation_1 ?? null; + $curPart2 = $curStat->part_validation_2 ?? null; + $slUser = $curStat->samlight_logged_name ?? null; + $curWorkFlow = $curStat->has_work_flow_id ?? '0'; if ($jobNo != null && $jobNo != '' && $jobNo) { - $curStat = ClassCharacteristic::where('plant_id', $plantId) - ->where('machine_id', $machineId) - ->where('aufnr', $jobNo) - ->where('gernr', $serialNumber) - ->where('item_id', $itemId) - ->first(); + // $curStat = ClassCharacteristic::where('plant_id', $plantId)->where('machine_id', $machineId)->where('aufnr', $jobNo)->where('gernr', $serialNumber)->where('item_id', $itemId)->first(); + if ($modelType == 'MOTOR' && ($curMarkStat == 'Marked' || $curMotorMarkStat == 'Marked')) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Motor serial number '{$serialNumber}' already marked in auto mode!", + ], 404); + } elseif ($modelType == 'PUMP' && ($curMarkStat == 'Marked' || $curPumpMarkStat == 'Marked')) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$serialNumber}' already marked in auto mode!", + ], 404); + } elseif ($modelType == 'NAME_PLATE' && ($curMarkStat == 'Marked' || $curNamePlateMarkStat == 'Marked')) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Name plate serial number '{$serialNumber}' already marked in auto mode!", + ], 404); + } elseif ($modelType == 'PUMPSET' && $curMarkStat == 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pumpset serial number '{$serialNumber}' already marked in auto mode!", + ], 404); + } + + $physiCnt = (intval($curStat->marked_physical_count ?? 0.0) ?: 0.0) + 1; + // $physiCnt = (($curStat->marked_physical_count == null || $curStat->marked_physical_count == '' || $curStat->marked_physical_count == '0') ? 0 : (int) $curStat->marked_physical_count) + 1; + // marked_expected_time + $motPhysiCnt = intval($curStat->motor_marked_physical_count ?? 0) ?: 0; + $pumPhysiCnt = intval($curStat->pump_marked_physical_count ?? 0) ?: 0; + + $expecTim = (floatval($curStat->marked_expected_time ?? 0.0) ?: 0.0) + $expectedTime; + $motExpecTim = floatval($curStat->motor_expected_time ?? 0.0) ?: 0.0; + $pumExpecTim = floatval($curStat->pump_expected_time ?? 0.0) ?: 0.0; + $napExpecTim = floatval($curStat->name_plate_expected_time ?? 0.0) ?: 0.0; + + if ($char['motor_pump_pumpset_status'] == '3') { + if ($modelType == 'MOTOR') { + $motPhysiCnt = $motPhysiCnt + 1; + $motExpecTim = $motExpecTim + $expectedTime; + if ($motPhysiCnt >= $mvhsCnt) { + $curMotorMarkStat = 'Marked'; + } + $curMotorMarkBy = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? $curMotorMarkBy; + } elseif ($modelType == 'PUMP') { + $pumPhysiCnt = $pumPhysiCnt + 1; + $pumExpecTim = $pumExpecTim + $expectedTime; + if ($pumPhysiCnt >= $mvhsCnt) { + $curPumpMarkStat = 'Marked'; + } + $curPumpMarkBy = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? $curPumpMarkBy; + } elseif ($modelType == 'NAME_PLATE') { + $napExpecTim = $napExpecTim + $expectedTime; + $curNamePlateMarkStat = 'Marked'; + $curNamePlateMarkBy = ($char['name_plate_marked_by'] == 'jothi') ? 'Admin' : $char['name_plate_marked_by'] ?? $curNamePlateMarkBy; + } + + if ($modelType == 'PUMPSET' && $physiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } elseif ($hasMvhs == true && $curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked' && $curNamePlateMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } elseif ($hasMvhs == false && $curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } - if ($char['mark_status'] == 'Stopped') { $values = [ - 'mark_status' => $char['mark_status'] ?? null, - 'marked_datetime' => $char['marked_datetime'] ?? null, - 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - 'updated_by' => $userName ?? null, - ]; - } elseif ($char['motor_pump_pumpset_status'] == '3') { - $values = [ - 'mark_status' => $char['mark_status'] ?? null, - 'marked_datetime' => $char['marked_datetime'] ?? null, - 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - 'motor_marked_status' => $char['motor_marked_status'] ?? null, - 'motor_marked_by' => ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null, - 'pump_marked_status' => $char['pump_marked_status'] ?? null, - 'pump_marked_by' => ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null, + 'mark_status' => $curMarkStat, + 'marked_datetime' => $char['marked_datetime'] ?? now(), + 'marked_physical_count' => (string) $physiCnt, + 'marked_expected_time' => (string) $expecTim, + 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? $curMarkBy, + 'motor_marked_status' => $curMotorMarkStat, + 'motor_marked_physical_count' => (string) $motPhysiCnt, + 'motor_expected_time' => (string) $motExpecTim, + 'motor_marked_by' => $curMotorMarkBy, + 'pump_marked_status' => $curPumpMarkStat, + 'pump_marked_physical_count' => (string) $pumPhysiCnt, + 'pump_expected_time' => (string) $pumExpecTim, + 'pump_marked_by' => $curPumpMarkBy, + 'name_plate_marked_status' => $curNamePlateMarkStat, + 'name_plate_expected_time' => (string) $napExpecTim, + 'name_plate_marked_by' => $curNamePlateMarkBy, 'motor_pump_pumpset_status' => '3', - 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? null, - 'part_validation_1' => $char['part_validation_1'] ?? null, - 'part_validation_2' => $char['part_validation_2'] ?? null, - 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, + 'winded_serial_number' => $char['winded_serial_number'] ?? $curWindNo, + 'motor_machine_name' => $char['motor_machine_name'] ?? $curMMach, + 'pump_machine_name' => $char['pump_machine_name'] ?? $curPMach, + 'name_plate_machine_name' => $char['name_plate_machine_name'] ?? $curNpMach, + 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? $curPsMach, + 'part_validation_1' => $char['part_validation_1'] ?? $curPart1, + 'part_validation_2' => $char['part_validation_2'] ?? $curPart2, + 'samlight_logged_name' => $char['samlight_logged_name'] ?? $slUser, // 'pending_released_status' => $char['pending_released_status'] ?? null, - 'motor_expected_time' => $char['motor_expected_time'] ?? null, - 'pump_expected_time' => $char['pump_expected_time'] ?? null, + 'has_work_flow_id' => $char['has_work_flow_id'] ?? $curWorkFlow, 'updated_by' => $userName ?? null, ]; - } elseif ($char['motor_pump_pumpset_status'] == '2') { - if ($curStat->motor_marked_status == null || $curStat->motor_marked_status == '') { - $values = [ - // 'mark_status' => $char['mark_status'] ?? null, - 'marked_datetime' => $char['marked_datetime'] ?? null, - // 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - 'pump_marked_status' => $char['pump_marked_status'] ?? null, - 'pump_marked_by' => ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null, - 'motor_pump_pumpset_status' => '3', - 'pump_machine_name' => $char['pump_machine_name'] ?? null, - 'part_validation_1' => $char['part_validation_1'] ?? null, - 'part_validation_2' => $char['part_validation_2'] ?? null, - 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, - // 'pending_released_status' => $char['pending_released_status'] ?? null, - 'pump_expected_time' => $char['pump_expected_time'] ?? null, - 'updated_by' => $userName ?? null, - ]; - } else { - $values = [ - 'mark_status' => $char['mark_status'] ?? null, - 'marked_datetime' => $char['marked_datetime'] ?? null, - 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - 'pump_marked_status' => $char['pump_marked_status'] ?? null, - 'pump_marked_by' => ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null, - 'motor_pump_pumpset_status' => '3', - 'pump_machine_name' => $char['pump_machine_name'] ?? null, - 'part_validation_1' => $char['part_validation_1'] ?? null, - 'part_validation_2' => $char['part_validation_2'] ?? null, - 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, - // 'pending_released_status' => $char['pending_released_status'] ?? null, - 'pump_expected_time' => $char['pump_expected_time'] ?? null, - 'updated_by' => $userName ?? null, - ]; + // $values = array_merge($values1 ?? [], $values2 ?? [], $values3 ?? [], $values4 ?? [], $values5 ?? []); + } elseif ($hasMvhs == true && $char['motor_pump_pumpset_status'] == '4') { + if ($modelType == 'NAME_PLATE') { + $napExpecTim = $napExpecTim + $expectedTime; + $curNamePlateMarkStat = 'Marked'; + $curNamePlateMarkBy = ($char['name_plate_marked_by'] == 'jothi') ? 'Admin' : $char['name_plate_marked_by'] ?? $curNamePlateMarkBy; } - } elseif ($char['motor_pump_pumpset_status'] == '1') { - if ($curStat->pump_marked_status == null || $curStat->pump_marked_status == '') { - $values = [ - // 'mark_status' => $char['mark_status'] ?? null, - 'marked_datetime' => $char['marked_datetime'] ?? null, - // 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - 'motor_marked_status' => $char['motor_marked_status'] ?? null, - 'motor_marked_by' => ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null, - 'motor_pump_pumpset_status' => '3', - 'motor_machine_name' => $char['motor_machine_name'] ?? null, - 'part_validation_1' => $char['part_validation_1'] ?? null, - 'part_validation_2' => $char['part_validation_2'] ?? null, - 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, - // 'pending_released_status' => $char['pending_released_status'] ?? null, - 'motor_expected_time' => $char['motor_expected_time'] ?? null, - 'updated_by' => $userName ?? null, - ]; - } else { - $values = [ - 'mark_status' => $char['mark_status'] ?? null, - 'marked_datetime' => $char['marked_datetime'] ?? null, - 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - 'motor_marked_status' => $char['motor_marked_status'] ?? null, - 'motor_marked_by' => ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null, - 'motor_pump_pumpset_status' => '3', - 'motor_machine_name' => $char['motor_machine_name'] ?? null, - 'part_validation_1' => $char['part_validation_1'] ?? null, - 'part_validation_2' => $char['part_validation_2'] ?? null, - 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, - // 'pending_released_status' => $char['pending_released_status'] ?? null, - 'motor_expected_time' => $char['motor_expected_time'] ?? null, - 'updated_by' => $userName ?? null, - ]; + + if ($modelType == 'PUMPSET' && $physiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } elseif ($curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked' && $curNamePlateMarkStat == 'Marked') { + $curMarkStat = 'Marked'; } - } else { + $values = [ - 'mark_status' => $char['mark_status'] ?? null, - 'marked_datetime' => $char['marked_datetime'] ?? null, - 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null, - 'motor_marked_status' => $char['motor_marked_status'] ?? null, - 'motor_marked_by' => ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null, - 'pump_marked_status' => $char['pump_marked_status'] ?? null, - 'pump_marked_by' => ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null, - 'motor_pump_pumpset_status' => $char['motor_pump_pumpset_status'] ?? null, - 'motor_machine_name' => $char['motor_machine_name'] ?? null, - 'pump_machine_name' => $char['pump_machine_name'] ?? null, - 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? null, - 'part_validation_1' => $char['part_validation_1'] ?? null, - 'part_validation_2' => $char['part_validation_2'] ?? null, - 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, + 'mark_status' => $curMarkStat, + 'marked_datetime' => $char['marked_datetime'] ?? now(), + 'marked_physical_count' => (string) $physiCnt, + 'marked_expected_time' => (string) $expecTim, + 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? $curMarkBy, + 'name_plate_marked_status' => $curNamePlateMarkStat, + 'name_plate_expected_time' => (string) $napExpecTim, + 'name_plate_marked_by' => $curNamePlateMarkBy, + 'motor_pump_pumpset_status' => '3', + // 'winded_serial_number' => $char['winded_serial_number'] ?? $curWindNo, + 'name_plate_machine_name' => $char['name_plate_machine_name'] ?? $curNpMach, + 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? $curPsMach, + // 'part_validation_1' => $char['part_validation_1'] ?? $curPart1, + // 'part_validation_2' => $char['part_validation_2'] ?? $curPart2, + 'samlight_logged_name' => $char['samlight_logged_name'] ?? $slUser, // 'pending_released_status' => $char['pending_released_status'] ?? null, - 'motor_expected_time' => $char['motor_expected_time'] ?? null, - 'pump_expected_time' => $char['pump_expected_time'] ?? null, + 'has_work_flow_id' => $char['has_work_flow_id'] ?? $curWorkFlow, 'updated_by' => $userName ?? null, ]; + // $values = array_merge($values1 ?? [], $values2 ?? [], $values3 ?? [], $values4 ?? [], $values5 ?? []); + } elseif ($char['motor_pump_pumpset_status'] == '2') { + if ($modelType == 'PUMP') { + $pumPhysiCnt = $pumPhysiCnt + 1; + $pumExpecTim = $pumExpecTim + $expectedTime; + if ($pumPhysiCnt >= $mvhsCnt) { + $curPumpMarkStat = 'Marked'; + } + $curPumpMarkBy = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? $curPumpMarkBy; + } + + if ($modelType == 'PUMPSET' && $physiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } elseif ($hasMvhs == true && $curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked' && $curNamePlateMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } elseif ($hasMvhs == false && $curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } + + $values = [ + 'mark_status' => $curMarkStat, + 'marked_datetime' => $char['marked_datetime'] ?? now(), + 'marked_physical_count' => (string) $physiCnt, + 'marked_expected_time' => (string) $expecTim, + 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? $curMarkBy, + 'pump_marked_status' => $curPumpMarkStat, + 'pump_marked_physical_count' => (string) $pumPhysiCnt, + 'pump_expected_time' => (string) $pumExpecTim, + 'pump_marked_by' => $curPumpMarkBy, + 'motor_pump_pumpset_status' => '3', + // 'winded_serial_number' => $char['winded_serial_number'] ?? $curWindNo, + 'pump_machine_name' => $char['pump_machine_name'] ?? $curPMach, + 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? $curPsMach, + // 'part_validation_1' => $char['part_validation_1'] ?? $curPart1, + // 'part_validation_2' => $char['part_validation_2'] ?? $curPart2, + 'samlight_logged_name' => $char['samlight_logged_name'] ?? $slUser, + // 'pending_released_status' => $char['pending_released_status'] ?? null, + 'has_work_flow_id' => $char['has_work_flow_id'] ?? $curWorkFlow, + 'updated_by' => $userName ?? null, + ]; + // $values = array_merge($values1 ?? [], $values2 ?? [], $values3 ?? [], $values4 ?? [], $values5 ?? []); + } elseif ($char['motor_pump_pumpset_status'] == '1') { + if ($modelType == 'MOTOR') { + $motPhysiCnt = $motPhysiCnt + 1; + $motExpecTim = $motExpecTim + $expectedTime; + if ($motPhysiCnt >= $mvhsCnt) { + $curMotorMarkStat = 'Marked'; + } + $curMotorMarkBy = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? $curMotorMarkBy; + } + + if ($modelType == 'PUMPSET' && $physiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } elseif ($hasMvhs == true && $curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked' && $curNamePlateMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } elseif ($hasMvhs == false && $curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } + + $values = [ + 'mark_status' => $curMarkStat, + 'marked_datetime' => $char['marked_datetime'] ?? now(), + 'marked_physical_count' => (string) $physiCnt, + 'marked_expected_time' => (string) $expecTim, + 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? $curMarkBy, + 'motor_marked_status' => $curMotorMarkStat, + 'motor_marked_physical_count' => (string) $motPhysiCnt, + 'motor_expected_time' => (string) $motExpecTim, + 'motor_marked_by' => $curMotorMarkBy, + 'motor_pump_pumpset_status' => '3', + 'winded_serial_number' => $char['winded_serial_number'] ?? $curWindNo, + 'motor_machine_name' => $char['motor_machine_name'] ?? $curMMach, + 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? $curPsMach, + 'part_validation_1' => $char['part_validation_1'] ?? $curPart1, + 'part_validation_2' => $char['part_validation_2'] ?? $curPart2, + 'samlight_logged_name' => $char['samlight_logged_name'] ?? $slUser, + // 'pending_released_status' => $char['pending_released_status'] ?? null, + 'has_work_flow_id' => $char['has_work_flow_id'] ?? $curWorkFlow, + 'updated_by' => $userName ?? null, + ]; + // $values = array_merge($values1 ?? [], $values2 ?? [], $values3 ?? [], $values4 ?? [], $values5 ?? []); + } elseif ($hasMvhs == true) { + if ($modelType == 'MOTOR') { + $motPhysiCnt = $motPhysiCnt + 1; + $motExpecTim = $motExpecTim + $expectedTime; + if ($motPhysiCnt >= $mvhsCnt) { + $curMotorMarkStat = 'Marked'; + } + $curMotorMarkBy = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? $curMotorMarkBy; + } elseif ($modelType == 'PUMP') { + $pumPhysiCnt = $pumPhysiCnt + 1; + $pumExpecTim = $pumExpecTim + $expectedTime; + if ($pumPhysiCnt >= $mvhsCnt) { + $curPumpMarkStat = 'Marked'; + } + $curPumpMarkBy = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? $curPumpMarkBy; + } elseif ($modelType == 'NAME_PLATE') { + $napExpecTim = $napExpecTim + $expectedTime; + $curNamePlateMarkStat = 'Marked'; + $curNamePlateMarkBy = ($char['name_plate_marked_by'] == 'jothi') ? 'Admin' : $char['name_plate_marked_by'] ?? $curNamePlateMarkBy; + } + + if ($modelType == 'PUMPSET' && $physiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } elseif ($curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked' && $curNamePlateMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } + + $values = [ + 'mark_status' => $curMarkStat, + 'marked_datetime' => $char['marked_datetime'] ?? now(), + 'marked_physical_count' => (string) $physiCnt, + 'marked_expected_time' => (string) $expecTim, + 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? $curMarkBy, + 'motor_marked_status' => $curMotorMarkStat, + 'motor_marked_physical_count' => (string) $motPhysiCnt, + 'motor_expected_time' => (string) $motExpecTim, + 'motor_marked_by' => $curMotorMarkBy, + 'pump_marked_status' => $curPumpMarkStat, + 'pump_marked_physical_count' => (string) $pumPhysiCnt, + 'pump_expected_time' => (string) $pumExpecTim, + 'pump_marked_by' => $curPumpMarkBy, + 'name_plate_marked_status' => $curNamePlateMarkStat, + 'name_plate_expected_time' => (string) $napExpecTim, + 'name_plate_marked_by' => $curNamePlateMarkBy, + 'motor_pump_pumpset_status' => null, + 'winded_serial_number' => $char['winded_serial_number'] ?? $curWindNo, + 'motor_machine_name' => $curMMach, // $char['motor_machine_name'] ?? + 'pump_machine_name' => $curPMach, // $char['pump_machine_name'] ?? + 'name_plate_machine_name' => $curNpMach, // $char['name_plate_machine_name'] ?? + 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? $curPsMach, + 'part_validation_1' => $char['part_validation_1'] ?? $curPart1, + 'part_validation_2' => $char['part_validation_2'] ?? $curPart2, + 'samlight_logged_name' => $char['samlight_logged_name'] ?? $slUser, + // 'pending_released_status' => $char['pending_released_status'] ?? null, + 'has_work_flow_id' => $char['has_work_flow_id'] ?? $curWorkFlow, + 'updated_by' => $userName ?? null, + ]; + // $values = array_merge($values1 ?? [], $values2 ?? [], $values3 ?? [], $values4 ?? [], $values5 ?? []); + } else { + if ($modelType == 'MOTOR') { + $motPhysiCnt = $motPhysiCnt + 1; + $motExpecTim = $motExpecTim + $expectedTime; + if ($motPhysiCnt >= $mvhsCnt) { + $curMotorMarkStat = 'Marked'; + } + $curMotorMarkBy = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? $curMotorMarkBy; + } elseif ($modelType == 'PUMP') { + $pumPhysiCnt = $pumPhysiCnt + 1; + $pumExpecTim = $pumExpecTim + $expectedTime; + if ($pumPhysiCnt >= $mvhsCnt) { + $curPumpMarkStat = 'Marked'; + } + $curPumpMarkBy = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? $curPumpMarkBy; + } + + if ($modelType == 'PUMPSET' && $physiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } elseif ($curMotorMarkStat == 'Marked' && $curPumpMarkStat == 'Marked') { + $curMarkStat = 'Marked'; + } elseif (Str::contains($curHead, 'PUMP', ignoreCase: true) && ! Str::contains($curHead, 'PUMP SET', ignoreCase: true) && ! Str::contains($curHead, 'PUMPSET', ignoreCase: true)) { + if ($modelType == 'PUMP' && $pumPhysiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } + } elseif (Str::contains($curHead, 'MOTOR', ignoreCase: true)) { + if ($modelType == 'MOTOR' && $motPhysiCnt >= $mvhsCnt) { + $curMarkStat = 'Marked'; + } + } + + $values = [ + 'mark_status' => $curMarkStat, + 'marked_datetime' => $char['marked_datetime'] ?? now(), + 'marked_physical_count' => (string) $physiCnt, + 'marked_expected_time' => (string) $expecTim, + 'marked_by' => ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? $curMarkBy, + 'motor_marked_status' => $curMotorMarkStat, + 'motor_marked_physical_count' => (string) $motPhysiCnt, + 'motor_expected_time' => (string) $motExpecTim, + 'motor_marked_by' => $curMotorMarkBy, + 'pump_marked_status' => $curPumpMarkStat, + 'pump_marked_physical_count' => (string) $pumPhysiCnt, + 'pump_expected_time' => (string) $pumExpecTim, + 'pump_marked_by' => $curPumpMarkBy, + 'name_plate_marked_status' => $curNamePlateMarkStat, + 'name_plate_expected_time' => (string) $napExpecTim, + 'name_plate_marked_by' => $curNamePlateMarkBy, + 'motor_pump_pumpset_status' => null, + 'winded_serial_number' => $char['winded_serial_number'] ?? $curWindNo, + 'motor_machine_name' => $char['motor_machine_name'] ?? $curMMach, + 'pump_machine_name' => $char['pump_machine_name'] ?? $curPMach, + 'name_plate_machine_name' => $curNpMach, // $char['name_plate_machine_name'] ?? + 'pumpset_machine_name' => $char['pumpset_machine_name'] ?? $curPsMach, + 'part_validation_1' => $char['part_validation_1'] ?? $curPart1, + 'part_validation_2' => $char['part_validation_2'] ?? $curPart2, + 'samlight_logged_name' => $char['samlight_logged_name'] ?? $slUser, + // 'pending_released_status' => $char['pending_released_status'] ?? null, + 'has_work_flow_id' => $char['has_work_flow_id'] ?? $curWorkFlow, + 'updated_by' => $userName ?? null, + ]; + // $values = array_merge($values1 ?? [], $values2 ?? [], $values3 ?? [], $values4 ?? [], $values5 ?? []); } $isAuto = true; @@ -714,18 +1034,36 @@ class CharacteristicsController extends Controller $updatedRows += $affected; } else { - $curStat = ClassCharacteristic::where('plant_id', $plantId) - ->where('machine_id', $machineId) - ->where('gernr', $serialNumber) - ->where('item_id', $itemId) - ->first(); + // $curStat = ClassCharacteristic::where('plant_id', $plantId)->where('machine_id', $machineId)->where('gernr', $serialNumber)->where('item_id', $itemId)->first(); + if ($modelType == 'MOTOR' && $curMarkStat != 'Marked' && $curMotorMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Motor serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } elseif ($modelType == 'PUMP' && $curMarkStat != 'Marked' && $curPumpMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } elseif ($modelType == 'NAME_PLATE' && $curMarkStat != 'Marked' && $curNamePlateMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Name plate serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } elseif ($modelType == 'PUMPSET' && $curMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pumpset serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } - $manStat = ($curStat->man_marked_status == null || $curStat->man_marked_status == '' || $curStat->man_marked_status == '0') ? 0 : (int) $curStat->man_marked_status; + $manStat = (intval($curStat->man_marked_status ?? 0) ?: 0) + 1; + // $manStat = ($curStat->man_marked_status == null || $curStat->man_marked_status == '' || $curStat->man_marked_status == '0') ? 0 : (int) $curStat->man_marked_status; $values = [ - 'man_marked_status' => (string) ($manStat + 1), - 'man_marked_datetime' => $char['man_marked_datetime'] ?? null, - 'man_marked_by' => ($char['man_marked_by'] == 'jothi') ? 'Admin' : $char['man_marked_by'] ?? null, - 'samlight_logged_name' => $char['samlight_logged_name'] ?? null, + 'man_marked_status' => (string) $manStat, + 'man_marked_datetime' => $char['man_marked_datetime'] ?? now(), + 'man_marked_by' => ($char['man_marked_by'] == 'jothi') ? 'Admin' : $char['man_marked_by'] ?? $curManualMarkBy, + 'samlight_logged_name' => $char['samlight_logged_name'] ?? $slUser, 'updated_by' => $userName ?? null, ]; @@ -743,12 +1081,12 @@ class CharacteristicsController extends Controller if ($updatedRows == 0) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => $isAuto ? "Failed to update auto marked status for the serial number '{$serialNumber}'." : "Failed to update manual marked status for the serial number '{$serialNumber}'.", - ], 500); + 'status_description' => $isAuto ? 'Failed to update auto marked status for the '.strtolower($modelType)."serial number '{$serialNumber}'." : 'Failed to update manual marked status for the '.strtolower($modelType)."serial number '{$serialNumber}'.", + ], 404); } else { return response()->json([ 'status_code' => 'SUCCESS', - 'status_description' => $isAuto ? "Successfully auto marked status updated for the serial number '{$serialNumber}'." : "Successfully manual marked status updated for the serial number '{$serialNumber}'.", + 'status_description' => $isAuto ? 'Successfully auto marked status updated for the '.strtolower($modelType)." serial number '{$serialNumber}'." : 'Successfully manual marked status updated for the '.strtolower($modelType)."serial number '{$serialNumber}'.", ], 200); } } @@ -765,7 +1103,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 403); + ], 401); } $userName = $request->header('user-name'); @@ -783,8 +1121,8 @@ class CharacteristicsController extends Controller $plantCode = $data['plant_code']; $workCenter = $data['work_center']; - $itemCode = $data['item_code'] ?? ''; $jobNo = $data['aufnr'] ?? ''; + $itemCode = $data['item_code'] ?? ''; $serialNumbers = $data['serial_numbers'] ?? ''; $characteristics = $data['characteristics']; @@ -792,12 +1130,12 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", - ], 400); + ], 404); } elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code']) return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid plant code found!', - ], 400); + ], 404); } if ($workCenter == null || $workCenter == '' || ! $workCenter) { @@ -848,9 +1186,7 @@ class CharacteristicsController extends Controller ], 404); } - $machine = Machine::where('work_center', $workCenter) - ->where('plant_id', $plantId) - ->first(); + $machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->first(); if (! $machine) { return response()->json([ @@ -861,20 +1197,21 @@ class CharacteristicsController extends Controller $machineId = $machine->id; - $availFields = ['class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_amps', 'zmm_brand', 'zmm_degreeofprotection', 'zmm_delivery', 'zmm_dir_rot', 'zmm_discharge', 'zmm_discharge_max', 'zmm_discharge_min', 'zmm_duty', 'zmm_eff_motor', 'zmm_eff_pump', 'zmm_frequency', 'zmm_head', 'zmm_heading', 'zmm_head_max', 'zmm_head_minimum', 'zmm_idx_eff_mtr', 'zmm_idx_eff_pump', 'zmm_kvacode', 'zmm_maxambtemp', 'zmm_mincoolingflow', 'zmm_motorseries', 'zmm_motor_model', 'zmm_outlet', 'zmm_phase', 'zmm_pressure', 'zmm_pumpflowtype', 'zmm_pumpseries', 'zmm_pump_model', 'zmm_ratedpower', 'zmm_region', 'zmm_servicefactor', 'zmm_servicefactormaximumamps', 'zmm_speed', 'zmm_suction', 'zmm_suctionxdelivery', 'zmm_supplysource', 'zmm_temperature', 'zmm_thrustload', 'zmm_volts', 'zmm_wire', 'zmm_package', 'zmm_pvarrayrating', 'zmm_isi', 'zmm_isimotor', 'zmm_isipump', 'zmm_isipumpset', 'zmm_pumpset_model', 'zmm_stages', 'zmm_headrange', 'zmm_overall_efficiency', 'zmm_connection', 'zmm_min_bore_size', 'zmm_isireference', 'zmm_category', 'zmm_submergence', 'zmm_capacitorstart', 'zmm_capacitorrun', 'zmm_inch', 'zmm_motor_type', 'zmm_dismantle_direction', 'zmm_eff_ovrall', 'zmm_bodymoc', 'zmm_rotormoc', 'zmm_dlwl', 'zmm_inputpower', 'zmm_imp_od', 'zmm_ambtemp', 'zmm_de', 'zmm_dischargerange', 'zmm_efficiency_class', 'zmm_framesize', 'zmm_impellerdiameter', 'zmm_insulationclass', 'zmm_maxflow', 'zmm_minhead', 'zmm_mtrlofconst', 'zmm_nde', 'zmm_powerfactor', 'zmm_tagno', 'zmm_year', 'zmm_laser_name', 'zmm_logo_cp', 'zmm_logo_ce', 'zmm_logo_nsf', 'zmm_beenote', 'zmm_beenumber', 'zmm_beestar', 'zmm_codeclass', 'zmm_colour', 'zmm_grade', 'zmm_grwt_pset', 'zmm_grwt_cable', 'zmm_grwt_motor', 'zmm_grwt_pf', 'zmm_grwt_pump', 'zmm_isivalve', 'zmm_isi_wc', 'zmm_labelperiod', 'zmm_length', 'zmm_license_cml_no', 'zmm_mfgmonyr', 'zmm_modelyear', 'zmm_motoridentification', 'zmm_newt_pset', 'zmm_newt_cable', 'zmm_newt_motor', 'zmm_newt_pf', 'zmm_newt_pump', 'zmm_packtype', 'zmm_panel', 'zmm_performance_factor', 'zmm_pumpidentification', 'zmm_psettype', 'zmm_size', 'zmm_eff_ttl', 'zmm_type', 'zmm_usp', 'mark_status', 'marked_datetime', 'marked_by', 'man_marked_status', 'man_marked_datetime', 'man_marked_by', 'motor_marked_status', 'motor_marked_by', 'pump_marked_status', 'pump_marked_by', 'motor_pump_pumpset_status', 'motor_machine_name', 'pump_machine_name', 'pumpset_machine_name', 'part_validation_1', 'part_validation_2', 'samlight_logged_name', 'pending_released_status', 'motor_expected_time', 'pump_expected_time']; + $availFields = ['class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_amps', 'zmm_brand', 'zmm_degreeofprotection', 'zmm_delivery', 'zmm_dir_rot', 'zmm_discharge', 'zmm_discharge_max', 'zmm_discharge_min', 'zmm_duty', 'zmm_eff_motor', 'zmm_eff_pump', 'zmm_frequency', 'zmm_head', 'zmm_heading', 'zmm_head_max', 'zmm_head_minimum', 'zmm_idx_eff_mtr', 'zmm_idx_eff_pump', 'zmm_kvacode', 'zmm_maxambtemp', 'zmm_mincoolingflow', 'zmm_motorseries', 'zmm_motor_model', 'zmm_outlet', 'zmm_phase', 'zmm_pressure', 'zmm_pumpflowtype', 'zmm_pumpseries', 'zmm_pump_model', 'zmm_ratedpower', 'zmm_region', 'zmm_servicefactor', 'zmm_servicefactormaximumamps', 'zmm_speed', 'zmm_suction', 'zmm_suctionxdelivery', 'zmm_supplysource', 'zmm_temperature', 'zmm_thrustload', 'zmm_volts', 'zmm_wire', 'zmm_package', 'zmm_pvarrayrating', 'zmm_isi', 'zmm_isimotor', 'zmm_isipump', 'zmm_isipumpset', 'zmm_pumpset_model', 'zmm_stages', 'zmm_headrange', 'zmm_overall_efficiency', 'zmm_connection', 'zmm_min_bore_size', 'zmm_isireference', 'zmm_category', 'zmm_submergence', 'zmm_capacitorstart', 'zmm_capacitorrun', 'zmm_inch', 'zmm_motor_type', 'zmm_dismantle_direction', 'zmm_eff_ovrall', 'zmm_bodymoc', 'zmm_rotormoc', 'zmm_dlwl', 'zmm_inputpower', 'zmm_imp_od', 'zmm_ambtemp', 'zmm_de', 'zmm_dischargerange', 'zmm_efficiency_class', 'zmm_framesize', 'zmm_impellerdiameter', 'zmm_insulationclass', 'zmm_maxflow', 'zmm_minhead', 'zmm_mtrlofconst', 'zmm_nde', 'zmm_powerfactor', 'zmm_tagno', 'zmm_year', 'zmm_laser_name', 'zmm_logo_cp', 'zmm_logo_ce', 'zmm_logo_nsf', 'zmm_beenote', 'zmm_beenumber', 'zmm_beestar', 'zmm_codeclass', 'zmm_colour', 'zmm_grade', 'zmm_grwt_pset', 'zmm_grwt_cable', 'zmm_grwt_motor', 'zmm_grwt_pf', 'zmm_grwt_pump', 'zmm_isivalve', 'zmm_isi_wc', 'zmm_labelperiod', 'zmm_length', 'zmm_license_cml_no', 'zmm_mfgmonyr', 'zmm_modelyear', 'zmm_motoridentification', 'zmm_newt_pset', 'zmm_newt_cable', 'zmm_newt_motor', 'zmm_newt_pf', 'zmm_newt_pump', 'zmm_packtype', 'zmm_panel', 'zmm_performance_factor', 'zmm_pumpidentification', 'zmm_psettype', 'zmm_size', 'zmm_eff_ttl', 'zmm_type', 'zmm_usp', 'marked_datetime', 'marked_by', 'motor_pump_pumpset_status', 'motor_machine_name', 'pump_machine_name', 'name_plate_machine_name', 'pumpset_machine_name', 'pending_released_status', 'has_work_flow_id']; // 'mark_status','marked_physical_count', 'marked_expected_time', 'man_marked_status', 'man_marked_datetime', 'man_marked_by', 'motor_marked_status', 'motor_marked_physical_count', 'motor_expected_time', 'motor_marked_by', 'pump_marked_status', 'pump_marked_physical_count', 'pump_expected_time', 'pump_marked_by', 'name_plate_marked_status', 'name_plate_expected_time', 'name_plate_marked_by', 'winded_serial_number', 'part_validation_1', 'part_validation_2', 'samlight_logged_name', if ($itemCode != '' && $itemCode != null && $itemCode && Str::length($itemCode) > 0) { - $existingJob = ClassCharacteristic::where('plant_id', $plantId) + $existingJob = ClassCharacteristic::where('aufnr', $jobNo) + // ->where('plant_id', $plantId) // ->where('machine_id', $machineId) - ->where('aufnr', $jobNo) ->first(); if ($existingJob) { + $curPlant = Plant::where('id', $existingJob->plant_id)->first(); $curMachine = Machine::where('id', $existingJob->machine_id)->first(); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Duplicate job number '{$jobNo}' found for the plant code '{$plantCode}' and work center '$curMachine->work_center'!", + 'status_description' => "Duplicate job number '{$jobNo}' found for the plant code '{$curPlant->code}' and work center '$curMachine->work_center'!", ], 404); } @@ -882,12 +1219,17 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Item Code should contain minimum 6 digits!', - ], 400); + ], 404); } elseif (! ctype_alnum($itemCode)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Item Code should contain alpha-numeric values!', - ], 400); + 'status_description' => "Item Code '{$itemCode}' should contain alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should not begin with '0'!", + ], 404); } $item = Item::where('code', $itemCode)->first(); @@ -947,11 +1289,45 @@ class CharacteristicsController extends Controller ], 404); } - $col = ['marked_by', 'man_marked_by', 'motor_marked_by', 'pump_marked_by']; + $col = ['marked_by']; // , 'man_marked_by', 'motor_marked_by', 'pump_marked_by', 'name_plate_marked_by' $missingUsers = []; $missingUsersPlant = []; $missingUsersRight = []; foreach ($characteristics as $ch) { + $curHead = $ch['zmm_heading'] ?? null; + if (Str::contains($curHead, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $stick = StickerMaster::where('item_id', $itemId)->first(); + + if (! $stick) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master!", + ], 404); + } + + $stickPlant = StickerMaster::where('item_id', $itemId)->where('plant_id', $plantId)->first(); + + if (! $stickPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master for the plant code '{$plantCode}'!", + ], 404); + } else { + $curMvhs = trim($stickPlant?->laser_part_validation2); + if ($curMvhs == null || $curMvhs == '' || ! is_numeric($curMvhs) || Str::length($curMvhs) <= 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid MVHS master count found in sticker master!', + ], 404); + } elseif (! preg_match('/^[1-9]$/', $curMvhs)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'The MVHS master count should be between 1 to 9.', + ], 404); + } + } + } + foreach ($col as $field) { if (! empty($ch[$field])) { $markUser = $ch[$field]; @@ -1003,6 +1379,8 @@ class CharacteristicsController extends Controller } $dupSerials = []; + $duplicateSerials = []; + $seenSerialNumbers = []; foreach ($serialNumbers as $serial) { try { $existing = ClassCharacteristic::where('plant_id', $plantId) @@ -1013,6 +1391,12 @@ class CharacteristicsController extends Controller if ($existing) { $dupSerials[] = $serial; } + + if (in_array($serial, $seenSerialNumbers)) { + $duplicateSerials[] = $serial; + } else { + $seenSerialNumbers[] = $serial; + } } catch (\Exception $e) { return response()->json([ 'status_code' => 'ERROR', @@ -1022,12 +1406,19 @@ class CharacteristicsController extends Controller } } - if (! empty($dupSerials)) { + if (! empty($duplicateSerials)) { + $uniqueDupSerials = array_unique($duplicateSerials); + + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Following serial number(s) are already exist in POST API : '".implode(', ', $uniqueDupSerials)."'!", + ], 404); + } elseif (! empty($dupSerials)) { $uniqueDupSerials = array_unique($dupSerials); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Following serial number(s) already exist in cloud : '".implode(', ', $uniqueDupSerials)."'!", + 'status_description' => "Following serial number(s) are already exist in cloud : '".implode(', ', $uniqueDupSerials)."'!", ], 404); } @@ -1051,12 +1442,13 @@ class CharacteristicsController extends Controller } $insertData['marked_by'] = ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null; - $insertData['man_marked_by'] = ($char['man_marked_by'] == 'jothi') ? 'Admin' : $char['man_marked_by'] ?? null; - $insertData['motor_marked_by'] = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null; - $insertData['pump_marked_by'] = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null; + // $insertData['man_marked_by'] = ($char['man_marked_by'] == 'jothi') ? 'Admin' : $char['man_marked_by'] ?? null; + // $insertData['motor_marked_by'] = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null; + // $insertData['pump_marked_by'] = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null; + // $insertData['name_plate_marked_by'] = ($char['name_plate_marked_by'] == 'jothi') ? 'Admin' : $char['name_plate_marked_by'] ?? null; $existing = ClassCharacteristic::where('plant_id', $plantId) - ->where('item_id', $itemId) + // ->where('item_id', $itemId) ->where('gernr', $serial) ->first(); @@ -1065,7 +1457,7 @@ class CharacteristicsController extends Controller // $existing->update($insertData); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Duplicate serial number '$serial' found while inserting new master characteristics for the job number '$jobNo'.", + 'status_description' => "Duplicate serial number '$serial' found while inserting new master characteristics in job number '$existing->aufnr'!", ], 404); } else { $isInsert = true; @@ -1110,6 +1502,26 @@ class CharacteristicsController extends Controller ], 404); } + $existingJob = ClassCharacteristic::where('aufnr', $jobNo)->first(); + + if (! $existingJob) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Job number '{$jobNo}' not found!", + ], 404); + } + + $existingJob = ClassCharacteristic::where('plant_id', $plantId) + ->where('aufnr', $jobNo) + ->first(); + + if (! $existingJob) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Job number '{$jobNo}' not found for the plant code '{$plantCode}'!", + ], 404); + } + $existingJob = ClassCharacteristic::where('plant_id', $plantId) ->where('machine_id', $machineId) ->where('aufnr', $jobNo) @@ -1124,20 +1536,93 @@ class CharacteristicsController extends Controller $itemId = $existingJob->item_id; + $item = Item::where('id', $itemId)->first(); + + $itemCode = $item?->code; + if (empty($serialNumbers) || ! is_array($serialNumbers) || count($serialNumbers) == 0) { $hasNewSno = false; // return response()->json([ // 'status_code' => "ERROR", // 'status_description' => "Serial numbers can't be empty!" // ], 404); + foreach ($characteristics as $ch) { + $curHead = $ch['zmm_heading'] ?? null; + if (Str::contains($curHead, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $stick = StickerMaster::where('item_id', $itemId)->first(); + + if (! $stick) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master!", + ], 404); + } + + $stickPlant = StickerMaster::where('item_id', $itemId)->where('plant_id', $plantId)->first(); + + if (! $stickPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master for the plant code '{$plantCode}'!", + ], 404); + } else { + $curMvhs = trim($stickPlant?->laser_part_validation2); + if ($curMvhs == null || $curMvhs == '' || ! is_numeric($curMvhs) || Str::length($curMvhs) <= 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid MVHS master count found in sticker master!', + ], 404); + } elseif (! preg_match('/^[1-9]$/', $curMvhs)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'The MVHS master count should be between 1 to 9.', + ], 404); + } + } + } + } } else { $hasNewSno = true; - $col = ['marked_by', 'man_marked_by', 'motor_marked_by', 'pump_marked_by']; + $col = ['marked_by']; // , 'man_marked_by', 'motor_marked_by', 'pump_marked_by', 'name_plate_marked_by' $missingUsers = []; $missingUsersPlant = []; $missingUsersRight = []; foreach ($characteristics as $ch) { + $curHead = $ch['zmm_heading'] ?? null; + if (Str::contains($curHead, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $stick = StickerMaster::where('item_id', $itemId)->first(); + + if (! $stick) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master!", + ], 404); + } + + $stickPlant = StickerMaster::where('item_id', $itemId)->where('plant_id', $plantId)->first(); + + if (! $stickPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master for the plant code '{$plantCode}'!", + ], 404); + } else { + $curMvhs = trim($stickPlant?->laser_part_validation2); + if ($curMvhs == null || $curMvhs == '' || ! is_numeric($curMvhs) || Str::length($curMvhs) <= 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid MVHS master count found in sticker master!', + ], 404); + } elseif (! preg_match('/^[1-9]$/', $curMvhs)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'The MVHS master count should be between 1 to 9.', + ], 404); + } + } + } + foreach ($col as $field) { if (! empty($ch[$field])) { $markUser = $ch[$field]; @@ -1189,6 +1674,8 @@ class CharacteristicsController extends Controller } $dupSerials = []; + $duplicateSerials = []; + $seenSerialNumbers = []; foreach ($serialNumbers as $serial) { try { $existing = ClassCharacteristic::where('plant_id', $plantId) @@ -1196,9 +1683,20 @@ class CharacteristicsController extends Controller ->where('gernr', $serial) ->first(); - if ($existing) { + $existSnoJob = ClassCharacteristic::where('plant_id', $plantId) + ->where('gernr', $serial) + ->where('aufnr', '!=', $jobNo) + ->first(); + + if ($existing && $existSnoJob) { $dupSerials[] = $serial; } + + if (in_array($serial, $seenSerialNumbers)) { + $duplicateSerials[] = $serial; + } else { + $seenSerialNumbers[] = $serial; + } } catch (\Exception $e) { return response()->json([ 'status_code' => 'ERROR', @@ -1208,12 +1706,19 @@ class CharacteristicsController extends Controller } } - if (! empty($dupSerials)) { + if (! empty($duplicateSerials)) { + $uniqueDupSerials = array_unique($duplicateSerials); + + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Following serial number(s) are already exist in POST API : '".implode(', ', $uniqueDupSerials)."'!", + ], 404); + } elseif (! empty($dupSerials)) { // // Skip duplicate warning... $uniqueDupSerials = array_unique($dupSerials); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Following serial number(s) already exist in cloud : '".implode(', ', $uniqueDupSerials)."'!", + 'status_description' => "Following serial number(s) are already exist in cloud : '".implode(', ', $uniqueDupSerials)."'!", ], 404); } } @@ -1225,7 +1730,7 @@ class CharacteristicsController extends Controller ], 404); } - $masterFields = ['class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_amps', 'zmm_brand', 'zmm_degreeofprotection', 'zmm_delivery', 'zmm_dir_rot', 'zmm_discharge', 'zmm_discharge_max', 'zmm_discharge_min', 'zmm_duty', 'zmm_eff_motor', 'zmm_eff_pump', 'zmm_frequency', 'zmm_head', 'zmm_heading', 'zmm_head_max', 'zmm_head_minimum', 'zmm_idx_eff_mtr', 'zmm_idx_eff_pump', 'zmm_kvacode', 'zmm_maxambtemp', 'zmm_mincoolingflow', 'zmm_motorseries', 'zmm_motor_model', 'zmm_outlet', 'zmm_phase', 'zmm_pressure', 'zmm_pumpflowtype', 'zmm_pumpseries', 'zmm_pump_model', 'zmm_ratedpower', 'zmm_region', 'zmm_servicefactor', 'zmm_servicefactormaximumamps', 'zmm_speed', 'zmm_suction', 'zmm_suctionxdelivery', 'zmm_supplysource', 'zmm_temperature', 'zmm_thrustload', 'zmm_volts', 'zmm_wire', 'zmm_package', 'zmm_pvarrayrating', 'zmm_isi', 'zmm_isimotor', 'zmm_isipump', 'zmm_isipumpset', 'zmm_pumpset_model', 'zmm_stages', 'zmm_headrange', 'zmm_overall_efficiency', 'zmm_connection', 'zmm_min_bore_size', 'zmm_isireference', 'zmm_category', 'zmm_submergence', 'zmm_capacitorstart', 'zmm_capacitorrun', 'zmm_inch', 'zmm_motor_type', 'zmm_dismantle_direction', 'zmm_eff_ovrall', 'zmm_bodymoc', 'zmm_rotormoc', 'zmm_dlwl', 'zmm_inputpower', 'zmm_imp_od', 'zmm_ambtemp', 'zmm_de', 'zmm_dischargerange', 'zmm_efficiency_class', 'zmm_framesize', 'zmm_impellerdiameter', 'zmm_insulationclass', 'zmm_maxflow', 'zmm_minhead', 'zmm_mtrlofconst', 'zmm_nde', 'zmm_powerfactor', 'zmm_tagno', 'zmm_year', 'zmm_laser_name', 'zmm_logo_cp', 'zmm_logo_ce', 'zmm_logo_nsf']; + $masterFields = ['class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_amps', 'zmm_brand', 'zmm_degreeofprotection', 'zmm_delivery', 'zmm_dir_rot', 'zmm_discharge', 'zmm_discharge_max', 'zmm_discharge_min', 'zmm_duty', 'zmm_eff_motor', 'zmm_eff_pump', 'zmm_frequency', 'zmm_head', 'zmm_heading', 'zmm_head_max', 'zmm_head_minimum', 'zmm_idx_eff_mtr', 'zmm_idx_eff_pump', 'zmm_kvacode', 'zmm_maxambtemp', 'zmm_mincoolingflow', 'zmm_motorseries', 'zmm_motor_model', 'zmm_outlet', 'zmm_phase', 'zmm_pressure', 'zmm_pumpflowtype', 'zmm_pumpseries', 'zmm_pump_model', 'zmm_ratedpower', 'zmm_region', 'zmm_servicefactor', 'zmm_servicefactormaximumamps', 'zmm_speed', 'zmm_suction', 'zmm_suctionxdelivery', 'zmm_supplysource', 'zmm_temperature', 'zmm_thrustload', 'zmm_volts', 'zmm_wire', 'zmm_package', 'zmm_pvarrayrating', 'zmm_isi', 'zmm_isimotor', 'zmm_isipump', 'zmm_isipumpset', 'zmm_pumpset_model', 'zmm_stages', 'zmm_headrange', 'zmm_overall_efficiency', 'zmm_connection', 'zmm_min_bore_size', 'zmm_isireference', 'zmm_category', 'zmm_submergence', 'zmm_capacitorstart', 'zmm_capacitorrun', 'zmm_inch', 'zmm_motor_type', 'zmm_dismantle_direction', 'zmm_eff_ovrall', 'zmm_bodymoc', 'zmm_rotormoc', 'zmm_dlwl', 'zmm_inputpower', 'zmm_imp_od', 'zmm_ambtemp', 'zmm_de', 'zmm_dischargerange', 'zmm_efficiency_class', 'zmm_framesize', 'zmm_impellerdiameter', 'zmm_insulationclass', 'zmm_maxflow', 'zmm_minhead', 'zmm_mtrlofconst', 'zmm_nde', 'zmm_powerfactor', 'zmm_tagno', 'zmm_year', 'zmm_laser_name', 'zmm_logo_cp', 'zmm_logo_ce', 'zmm_logo_nsf', 'pending_released_status']; $isInsertOrUpdate = false; @@ -1287,19 +1792,25 @@ class CharacteristicsController extends Controller } $insertData['marked_by'] = ($char['marked_by'] == 'jothi') ? 'Admin' : $char['marked_by'] ?? null; - $insertData['man_marked_by'] = ($char['man_marked_by'] == 'jothi') ? 'Admin' : $char['man_marked_by'] ?? null; - $insertData['motor_marked_by'] = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null; - $insertData['pump_marked_by'] = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null; + // $insertData['man_marked_by'] = ($char['man_marked_by'] == 'jothi') ? 'Admin' : $char['man_marked_by'] ?? null; + // $insertData['motor_marked_by'] = ($char['motor_marked_by'] == 'jothi') ? 'Admin' : $char['motor_marked_by'] ?? null; + // $insertData['pump_marked_by'] = ($char['pump_marked_by'] == 'jothi') ? 'Admin' : $char['pump_marked_by'] ?? null; + // $insertData['name_plate_marked_by'] = ($char['name_plate_marked_by'] == 'jothi') ? 'Admin' : $char['name_plate_marked_by'] ?? null; $existing = ClassCharacteristic::where('plant_id', $plantId) - ->where('item_id', $itemId) + // ->where('item_id', $itemId) ->where('gernr', $serial) ->first(); - if ($existing) { + $existSnoJob = ClassCharacteristic::where('plant_id', $plantId) + ->where('gernr', $serial) + ->where('aufnr', '!=', $jobNo) + ->first(); + + if ($existing && $existSnoJob) { // // Skip duplicate warning... return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Duplicate serial number '$serial' found in job number '$existing->aufnr'!", + 'status_description' => "Duplicate serial number '$serial' found while updating exist master characteristics in job number '$existSnoJob->aufnr'!", ], 404); } else { $isInsertOrUpdate = true; @@ -1335,7 +1846,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 403); + ], 401); } $userName = $request->header('user-name'); @@ -1348,12 +1859,14 @@ class CharacteristicsController extends Controller $itemCode = $request->header('item-code'); + $modelType = $request->header('model-type'); + $serialNumber = $request->header('serial-number'); if (! $userName) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "User Name can't be empty!", + 'status_description' => "User name can't be empty!", ], 404); } elseif ($userName == 'jothi') { $userName = 'Admin'; @@ -1363,18 +1876,30 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", - ], 400); + ], 404); } elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code']) return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid plant code found!', - ], 400); + ], 404); } if (! $workCenter || $workCenter == null || $workCenter == '') { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Work Center can't be empty!", + 'status_description' => "Work center can't be empty!", + ], 404); + } + + if (! $modelType || $modelType == null || $modelType == '') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Model type can't be empty!", + ], 404); + } elseif ($modelType != 'MOTOR' && $modelType != 'PUMP' && $modelType != 'NAME_PLATE' && $modelType != 'PUMPSET') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Unknown model type found!', ], 404); } @@ -1442,12 +1967,17 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' should contain minimum 7 digits!", - ], 400); + ], 404); } elseif (! is_numeric($jobNumber)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' should contain only numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[1-9]\d{6,}$/', $jobNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Job number '{$jobNumber}' should not begin with '0'!", + ], 404); } $job = ClassCharacteristic::where('aufnr', $jobNumber)->first(); @@ -1456,7 +1986,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'SUCCESS', 'status_description' => "Job number '{$jobNumber}' not found!", - ], 400); + ], 404); } $jobPlant = ClassCharacteristic::where('aufnr', $jobNumber) @@ -1467,7 +1997,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found for the plant code '{$plantCode}'!", - ], 400); + ], 404); } $jobWorkCenter = ClassCharacteristic::where('aufnr', $jobNumber) @@ -1479,10 +2009,10 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found for the work center '{$workCenter}'!", - ], 400); + ], 404); } - $columnsToShow = ['mark_status', 'marked_datetime', 'marked_by', 'man_marked_status', 'man_marked_datetime', 'man_marked_by', 'motor_marked_status', 'motor_marked_by', 'pump_marked_status', 'pump_marked_by', 'motor_pump_pumpset_status', 'motor_machine_name', 'pump_machine_name', 'pumpset_machine_name', 'part_validation_1', 'part_validation_2', 'samlight_logged_name', 'pending_released_status', 'motor_expected_time', 'pump_expected_time']; + $columnsToShow = ['mark_status', 'marked_datetime', 'marked_physical_count', 'marked_expected_time', 'marked_by', 'man_marked_status', 'man_marked_datetime', 'man_marked_by', 'motor_marked_status', 'motor_marked_physical_count', 'motor_expected_time', 'motor_marked_by', 'pump_marked_status', 'pump_marked_physical_count', 'pump_expected_time', 'pump_marked_by', 'name_plate_marked_status', 'name_plate_expected_time', 'name_plate_marked_by', 'motor_pump_pumpset_status', 'winded_serial_number', 'motor_machine_name', 'pump_machine_name', 'name_plate_machine_name', 'pumpset_machine_name', 'part_validation_1', 'part_validation_2', 'samlight_logged_name', 'pending_released_status', 'has_work_flow_id']; $characteristicsColumns = ['class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_amps', 'zmm_brand', 'zmm_degreeofprotection', 'zmm_delivery', 'zmm_dir_rot', 'zmm_discharge', 'zmm_discharge_max', 'zmm_discharge_min', 'zmm_duty', 'zmm_eff_motor', 'zmm_eff_pump', 'zmm_frequency', 'zmm_head', 'zmm_heading', 'zmm_head_max', 'zmm_head_minimum', 'zmm_idx_eff_mtr', 'zmm_idx_eff_pump', 'zmm_kvacode', 'zmm_maxambtemp', 'zmm_mincoolingflow', 'zmm_motorseries', 'zmm_motor_model', 'zmm_outlet', 'zmm_phase', 'zmm_pressure', 'zmm_pumpflowtype', 'zmm_pumpseries', 'zmm_pump_model', 'zmm_ratedpower', 'zmm_region', 'zmm_servicefactor', 'zmm_servicefactormaximumamps', 'zmm_speed', 'zmm_suction', 'zmm_suctionxdelivery', 'zmm_supplysource', 'zmm_temperature', 'zmm_thrustload', 'zmm_volts', 'zmm_wire', 'zmm_package', 'zmm_pvarrayrating', 'zmm_isi', 'zmm_isimotor', 'zmm_isipump', 'zmm_isipumpset', 'zmm_pumpset_model', 'zmm_stages', 'zmm_headrange', 'zmm_overall_efficiency', 'zmm_connection', 'zmm_min_bore_size', 'zmm_isireference', 'zmm_category', 'zmm_submergence', 'zmm_capacitorstart', 'zmm_capacitorrun', 'zmm_inch', 'zmm_motor_type', 'zmm_dismantle_direction', 'zmm_eff_ovrall', 'zmm_bodymoc', 'zmm_rotormoc', 'zmm_dlwl', 'zmm_inputpower', 'zmm_imp_od', 'zmm_ambtemp', 'zmm_de', 'zmm_dischargerange', 'zmm_efficiency_class', 'zmm_framesize', 'zmm_impellerdiameter', 'zmm_insulationclass', 'zmm_maxflow', 'zmm_minhead', 'zmm_mtrlofconst', 'zmm_nde', 'zmm_powerfactor', 'zmm_tagno', 'zmm_year', 'zmm_laser_name', 'zmm_logo_cp', 'zmm_logo_ce', 'zmm_logo_nsf']; @@ -1497,7 +2027,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'No characteristics data found for the provided Plant, Work Center, and Job Number!', - ], 400); + ], 404); } $serials = ClassCharacteristic::where('plant_id', $plantId) @@ -1524,7 +2054,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'All serial numbers are already marked.', - ], 400); + ], 404); } $serialNumbers = $serials->map(function ($serial) use ($columnsToShow) { @@ -1537,6 +2067,7 @@ class CharacteristicsController extends Controller $otherData['man_marked_by'] = ($otherData['man_marked_by'] == 'Admin') ? 'jothi' : $otherData['man_marked_by'] ?? ''; $otherData['motor_marked_by'] = ($otherData['motor_marked_by'] == 'Admin') ? 'jothi' : $otherData['motor_marked_by'] ?? ''; $otherData['pump_marked_by'] = ($otherData['pump_marked_by'] == 'Admin') ? 'jothi' : $otherData['pump_marked_by'] ?? ''; + $otherData['name_plate_marked_by'] = ($otherData['name_plate_marked_by'] == 'Admin') ? 'jothi' : $otherData['name_plate_marked_by'] ?? ''; // $otherData['pending_released_status'] = (string)$otherData['pending_released_status'] ?? ''; return array_merge(['gernr' => $serial->gernr], $otherData); @@ -1564,24 +2095,34 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' should contain minimum 9 digits!", - ], 400); + ], 404); } elseif (! ctype_alnum($serialNumber)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' should contain only alpha-numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' should not begin with '0'!", + ], 404); } if (Str::length($itemCode) < 6) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Item code should contain minimum 6 digits!', - ], 400); + ], 404); } elseif (! ctype_alnum($itemCode)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Item code '{$itemCode}' should contain only alpha-numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should not begin with '0'!", + ], 404); } $item = Item::where('code', $itemCode)->first(); @@ -1651,6 +2192,106 @@ class CharacteristicsController extends Controller ], 404); } + $curHead = null; + $curHead = $serialExists?->zmm_heading; + if (Str::contains($curHead, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $stick = StickerMaster::where('item_id', $itemId)->first(); + + if (! $stick) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master!", + ], 404); + } + + $stickPlant = StickerMaster::where('item_id', $itemId) + ->where('plant_id', $plantId) + ->first(); + + if (! $stickPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master for the plant code '{$plantCode}'!", + ], 404); + } else { + $curMvhs = trim($stickPlant?->laser_part_validation2); + if ($curMvhs == null || $curMvhs == '' || ! is_numeric($curMvhs) || Str::length($curMvhs) <= 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid MVHS master count found in sticker master!', + ], 404); + } elseif (! preg_match('/^[1-9]$/', $curMvhs)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'The MVHS master count should be between 1 to 9.', // "MVHS master count '{$curMvhs}' should contain only numeric values between 1 to 9!" + ], 404); + } + } + } else { + if ($modelType == 'NAME_PLATE') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have name plate model to proceed!", + ], 404); + } elseif (Str::contains($curHead, 'PUMP', ignoreCase: true) && ! Str::contains($curHead, 'PUMP SET', ignoreCase: true) && ! Str::contains($curHead, 'PUMPSET', ignoreCase: true)) { + if ($modelType == 'MOTOR') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have motor model to proceed!", + ], 404); + } elseif ($modelType == 'PUMPSET') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have pumpset model to proceed!", + ], 404); + } + } elseif (Str::contains($curHead, 'MOTOR', ignoreCase: true)) { + if ($modelType == 'PUMP') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have pump model to proceed!", + ], 404); + } elseif ($modelType == 'PUMPSET') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have pumpset model to proceed!", + ], 404); + } + } elseif (! Str::contains($curHead, 'PUMPSET', ignoreCase: true)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' doesn't have valid model type to proceed!", + ], 404); + } + } + + $curMarkStat = $serialExists->mark_status ?? null; + $curMotorMarkStat = $serialExists->motor_marked_status ?? null; + $curPumpMarkStat = $serialExists->pump_marked_status ?? null; + $curNamePlateMarkStat = $serialExists->name_plate_marked_status ?? null; + + if ($modelType == 'MOTOR' && $curMarkStat != 'Marked' && $curMotorMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Motor serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } elseif ($modelType == 'PUMP' && $curMarkStat != 'Marked' && $curPumpMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } elseif ($modelType == 'NAME_PLATE' && $curMarkStat != 'Marked' && $curNamePlateMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Name plate serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } elseif ($modelType == 'PUMPSET' && $curMarkStat != 'Marked') { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pumpset serial number '{$serialNumber}' doesn't marked in auto mode!", + ], 404); + } + if ($serialExists->mark_status != 'Marked' && $serialExists->motor_marked_status != 'Marked' && $serialExists->pump_marked_status != 'Marked') { // "Serial number '{$serialNumber}' is not marked yet.
Please proceed with marking first."; return response()->json([ @@ -1687,6 +2328,7 @@ class CharacteristicsController extends Controller $charArray['man_marked_by'] = ($charArray['man_marked_by'] == 'Admin') ? 'jothi' : $charArray['man_marked_by'] ?? ''; $charArray['motor_marked_by'] = ($charArray['motor_marked_by'] == 'Admin') ? 'jothi' : $charArray['motor_marked_by'] ?? ''; $charArray['pump_marked_by'] = ($charArray['pump_marked_by'] == 'Admin') ? 'jothi' : $charArray['pump_marked_by'] ?? ''; + $charArray['name_plate_marked_by'] = ($charArray['name_plate_marked_by'] == 'Admin') ? 'jothi' : $charArray['name_plate_marked_by'] ?? ''; foreach ($charArray as $key => $value) { if ($value instanceof \Carbon\Carbon) { @@ -1724,7 +2366,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 403); + ], 401); } $userName = $request->header('user-name'); @@ -1752,12 +2394,12 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", - ], 400); + ], 404); } elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code']) return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid plant code found!', - ], 400); + ], 404); } if (! $workCenter || $workCenter == null || $workCenter == '') { @@ -1829,12 +2471,17 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' should contain minimum 7 digits!", - ], 400); + ], 404); } elseif (! is_numeric($jobNumber)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' should contain only numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[1-9]\d{6,}$/', $jobNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Job number '{$jobNumber}' should not begin with '0'!", + ], 404); } $job = ClassCharacteristic::where('aufnr', $jobNumber)->first(); @@ -1843,7 +2490,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found!", - ], 400); + ], 404); } $jobPlant = ClassCharacteristic::where('aufnr', $jobNumber) @@ -1854,7 +2501,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found for the plant code '{$plantCode}'!", - ], 400); + ], 404); } $jobWorkCenter = ClassCharacteristic::where('aufnr', $jobNumber) @@ -1866,10 +2513,49 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found for the work center '{$workCenter}'!", - ], 400); + ], 404); + } else { + $itemId = $jobWorkCenter?->item_id; + + $item = Item::where('id', $itemId)->first(); + + $itemCode = $item?->code; + + if (Str::contains($jobWorkCenter?->zmm_heading, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $stick = StickerMaster::where('item_id', $itemId)->first(); + + if (! $stick) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master!", + ], 404); + } + + $stickPlant = StickerMaster::where('item_id', $itemId)->where('plant_id', $plantId)->first(); + + if (! $stickPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master for the plant code '{$plantCode}'!", + ], 404); + } else { + $curMvhs = trim($stickPlant?->laser_part_validation2); + if ($curMvhs == null || $curMvhs == '' || ! is_numeric($curMvhs) || Str::length($curMvhs) <= 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid MVHS master count found in sticker master!', + ], 404); + } elseif (! preg_match('/^[1-9]$/', $curMvhs)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'The MVHS master count should be between 1 to 9.', + ], 404); + } + } + } } - // $columnsToShow = ['mark_status','marked_datetime','marked_by','man_marked_status','man_marked_datetime','man_marked_by','motor_marked_status','pump_marked_status','motor_pump_pumpset_status','part_validation_1','part_validation_2','samlight_logged_name','pending_released_status','motor_expected_time','pump_expected_time']; + // $columnsToShow = ['mark_status', 'marked_datetime', 'marked_physical_count', 'marked_expected_time', 'marked_by', 'man_marked_status', 'man_marked_datetime', 'man_marked_by', 'motor_marked_status', 'motor_marked_physical_count', 'motor_expected_time', 'motor_marked_by', 'pump_marked_status', 'pump_marked_physical_count', 'pump_expected_time', 'pump_marked_by', 'name_plate_marked_status', 'name_plate_expected_time', 'name_plate_marked_by', 'motor_pump_pumpset_status', 'winded_serial_number', 'motor_machine_name', 'pump_machine_name', 'name_plate_machine_name', 'pumpset_machine_name', 'part_validation_1', 'part_validation_2', 'samlight_logged_name', 'pending_released_status', 'has_work_flow_id']; $characteristicsColumns = ['class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_amps', 'zmm_brand', 'zmm_degreeofprotection', 'zmm_delivery', 'zmm_dir_rot', 'zmm_discharge', 'zmm_discharge_max', 'zmm_discharge_min', 'zmm_duty', 'zmm_eff_motor', 'zmm_eff_pump', 'zmm_frequency', 'zmm_head', 'zmm_heading', 'zmm_head_max', 'zmm_head_minimum', 'zmm_idx_eff_mtr', 'zmm_idx_eff_pump', 'zmm_kvacode', 'zmm_maxambtemp', 'zmm_mincoolingflow', 'zmm_motorseries', 'zmm_motor_model', 'zmm_outlet', 'zmm_phase', 'zmm_pressure', 'zmm_pumpflowtype', 'zmm_pumpseries', 'zmm_pump_model', 'zmm_ratedpower', 'zmm_region', 'zmm_servicefactor', 'zmm_servicefactormaximumamps', 'zmm_speed', 'zmm_suction', 'zmm_suctionxdelivery', 'zmm_supplysource', 'zmm_temperature', 'zmm_thrustload', 'zmm_volts', 'zmm_wire', 'zmm_package', 'zmm_pvarrayrating', 'zmm_isi', 'zmm_isimotor', 'zmm_isipump', 'zmm_isipumpset', 'zmm_pumpset_model', 'zmm_stages', 'zmm_headrange', 'zmm_overall_efficiency', 'zmm_connection', 'zmm_min_bore_size', 'zmm_isireference', 'zmm_category', 'zmm_submergence', 'zmm_capacitorstart', 'zmm_capacitorrun', 'zmm_inch', 'zmm_motor_type', 'zmm_dismantle_direction', 'zmm_eff_ovrall', 'zmm_bodymoc', 'zmm_rotormoc', 'zmm_dlwl', 'zmm_inputpower', 'zmm_imp_od', 'zmm_ambtemp', 'zmm_de', 'zmm_dischargerange', 'zmm_efficiency_class', 'zmm_framesize', 'zmm_impellerdiameter', 'zmm_insulationclass', 'zmm_maxflow', 'zmm_minhead', 'zmm_mtrlofconst', 'zmm_nde', 'zmm_powerfactor', 'zmm_tagno', 'zmm_year', 'zmm_laser_name', 'zmm_logo_cp', 'zmm_logo_ce', 'zmm_logo_nsf']; @@ -1884,7 +2570,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'No characteristics data found for the provided Plant, Work Center, and Job Number!', - ], 400); + ], 404); } // $serials = ClassCharacteristic::where('plant_id', $plantId) @@ -1910,7 +2596,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'All serial numbers are already marked!', - ], 400); + ], 404); } else { return response()->json([ 'status_code' => 'SUCCESS', @@ -1921,7 +2607,7 @@ class CharacteristicsController extends Controller // return response()->json([ // 'status_code' => "ERROR", // 'status_description' => "Item Code or Serial Number should be empty while checking job number characteristics!" - // ], 400); + // ], 404); if (! $jobNumber) { return response()->json([ 'status_code' => 'ERROR', @@ -1931,36 +2617,51 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' should contain minimum 7 digits!", - ], 400); + ], 404); } elseif (! is_numeric($jobNumber)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' should contain only numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[1-9]\d{6,}$/', $jobNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Job number '{$jobNumber}' should not begin with '0'!", + ], 404); } if (Str::length($serialNumber) < 9) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' should contain minimum 9 digits!", - ], 400); + ], 404); } elseif (! ctype_alnum($serialNumber)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' should contain only alpha-numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' should not begin with '0'!", + ], 404); } if (Str::length($itemCode) < 6) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Item code should contain minimum 6 digits!', - ], 400); + ], 404); } elseif (! ctype_alnum($itemCode)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Item code '{$itemCode}' should contain only alpha-numeric values!", - ], 400); + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should not begin with '0'!", + ], 404); } $job = ClassCharacteristic::where('aufnr', $jobNumber)->first(); @@ -1969,7 +2670,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found!", - ], 400); + ], 404); } $jobPlant = ClassCharacteristic::where('aufnr', $jobNumber) @@ -1980,7 +2681,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found for the plant code '{$plantCode}'!", - ], 400); + ], 404); } $jobWorkCenter = ClassCharacteristic::where('aufnr', $jobNumber) @@ -1992,7 +2693,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Job number '{$jobNumber}' not found for the work center '{$workCenter}'!", - ], 400); + ], 404); } $item = Item::where('code', $itemCode)->first(); @@ -2074,6 +2775,41 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => "Serial number '{$serialNumber}' with item code '{$itemCode}' not found for job number '{$jobNumber}'!", ], 404); + } else { + if (Str::contains($serialExists?->zmm_heading, 'PRESSURE BOOSTER SYSTEM', ignoreCase: true)) { + $stick = StickerMaster::where('item_id', $itemId)->first(); + + if (! $stick) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master!", + ], 404); + } + + $stickPlant = StickerMaster::where('item_id', $itemId) + ->where('plant_id', $plantId) + ->first(); + + if (! $stickPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found in sticker master for the plant code '{$plantCode}'!", + ], 404); + } else { + $curMvhs = trim($stickPlant?->laser_part_validation2); + if ($curMvhs == null || $curMvhs == '' || ! is_numeric($curMvhs) || Str::length($curMvhs) <= 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid MVHS master count found in sticker master!', + ], 404); + } elseif (! preg_match('/^[1-9]$/', $curMvhs)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'The MVHS master count should be between 1 to 9.', + ], 404); + } + } + } } $markedSerials = ClassCharacteristic::where('plant_id', $plantId) @@ -2089,7 +2825,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'All serial numbers are already marked!', - ], 400); + ], 404); } // if ($serialExists->mark_status != 'Marked' && $serialExists->mark_status != 'marked') @@ -2100,9 +2836,9 @@ class CharacteristicsController extends Controller // ], 404); // } - // $columnsToShow = ['mark_status','marked_datetime','marked_by','man_marked_status','man_marked_datetime','man_marked_by','motor_marked_status','pump_marked_status','motor_pump_pumpset_status','part_validation_1','part_validation_2','samlight_logged_name','pending_released_status','motor_expected_time','pump_expected_time']; + // $columnsToShow = ['mark_status', 'marked_datetime', 'marked_physical_count', 'marked_expected_time', 'marked_by', 'man_marked_status', 'man_marked_datetime', 'man_marked_by', 'motor_marked_status', 'motor_marked_physical_count', 'motor_expected_time', 'motor_marked_by', 'pump_marked_status', 'pump_marked_physical_count', 'pump_expected_time', 'pump_marked_by', 'name_plate_marked_status', 'name_plate_expected_time', 'name_plate_marked_by', 'motor_pump_pumpset_status', 'winded_serial_number', 'motor_machine_name', 'pump_machine_name', 'name_plate_machine_name', 'pumpset_machine_name', 'part_validation_1', 'part_validation_2', 'samlight_logged_name', 'pending_released_status', 'has_work_flow_id']; - // $characteristicsColumns = ['class','arbid','gamng','lmnga','zz1_cn_bill_ord','zmm_amps','zmm_brand','zmm_degreeofprotection','zmm_delivery','zmm_dir_rot','zmm_discharge','zmm_discharge_max','zmm_discharge_min','zmm_duty','zmm_eff_motor','zmm_eff_pump','zmm_frequency','zmm_head','zmm_heading','zmm_head_max','zmm_head_minimum','zmm_idx_eff_mtr','zmm_idx_eff_pump','zmm_kvacode','zmm_maxambtemp','zmm_mincoolingflow','zmm_motorseries','zmm_motor_model','zmm_outlet','zmm_phase','zmm_pressure','zmm_pumpflowtype','zmm_pumpseries','zmm_pump_model','zmm_ratedpower','zmm_region','zmm_servicefactor','zmm_servicefactormaximumamps','zmm_speed','zmm_suction','zmm_suctionxdelivery','zmm_supplysource','zmm_temperature','zmm_thrustload','zmm_volts','zmm_wire','zmm_package','zmm_pvarrayrating','zmm_isi','zmm_isimotor','zmm_isipump','zmm_isipumpset','zmm_pumpset_model','zmm_stages','zmm_headrange','zmm_overall_efficiency','zmm_connection','zmm_min_bore_size','zmm_isireference','zmm_category','zmm_submergence','zmm_capacitorstart','zmm_capacitorrun','zmm_inch','zmm_motor_type','zmm_dismantle_direction','zmm_eff_ovrall','zmm_bodymoc','zmm_rotormoc','zmm_dlwl','zmm_inputpower','zmm_imp_od','zmm_ambtemp','zmm_de','zmm_dischargerange','zmm_efficiency_class','zmm_framesize','zmm_impellerdiameter','zmm_insulationclass','zmm_maxflow','zmm_minhead','zmm_mtrlofconst','zmm_nde','zmm_powerfactor','zmm_tagno','zmm_year','zmm_laser_name']; + // $characteristicsColumns = ['class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_amps', 'zmm_brand', 'zmm_degreeofprotection', 'zmm_delivery', 'zmm_dir_rot', 'zmm_discharge', 'zmm_discharge_max', 'zmm_discharge_min', 'zmm_duty', 'zmm_eff_motor', 'zmm_eff_pump', 'zmm_frequency', 'zmm_head', 'zmm_heading', 'zmm_head_max', 'zmm_head_minimum', 'zmm_idx_eff_mtr', 'zmm_idx_eff_pump', 'zmm_kvacode', 'zmm_maxambtemp', 'zmm_mincoolingflow', 'zmm_motorseries', 'zmm_motor_model', 'zmm_outlet', 'zmm_phase', 'zmm_pressure', 'zmm_pumpflowtype', 'zmm_pumpseries', 'zmm_pump_model', 'zmm_ratedpower', 'zmm_region', 'zmm_servicefactor', 'zmm_servicefactormaximumamps', 'zmm_speed', 'zmm_suction', 'zmm_suctionxdelivery', 'zmm_supplysource', 'zmm_temperature', 'zmm_thrustload', 'zmm_volts', 'zmm_wire', 'zmm_package', 'zmm_pvarrayrating', 'zmm_isi', 'zmm_isimotor', 'zmm_isipump', 'zmm_isipumpset', 'zmm_pumpset_model', 'zmm_stages', 'zmm_headrange', 'zmm_overall_efficiency', 'zmm_connection', 'zmm_min_bore_size', 'zmm_isireference', 'zmm_category', 'zmm_submergence', 'zmm_capacitorstart', 'zmm_capacitorrun', 'zmm_inch', 'zmm_motor_type', 'zmm_dismantle_direction', 'zmm_eff_ovrall', 'zmm_bodymoc', 'zmm_rotormoc', 'zmm_dlwl', 'zmm_inputpower', 'zmm_imp_od', 'zmm_ambtemp', 'zmm_de', 'zmm_dischargerange', 'zmm_efficiency_class', 'zmm_framesize', 'zmm_impellerdiameter', 'zmm_insulationclass', 'zmm_maxflow', 'zmm_minhead', 'zmm_mtrlofconst', 'zmm_nde', 'zmm_powerfactor', 'zmm_tagno', 'zmm_year', 'zmm_laser_name', 'zmm_logo_cp', 'zmm_logo_ce', 'zmm_logo_nsf', 'zmm_beenote', 'zmm_beenumber', 'zmm_beestar', 'zmm_codeclass', 'zmm_colour', 'zmm_grade', 'zmm_grwt_pset', 'zmm_grwt_cable', 'zmm_grwt_motor', 'zmm_grwt_pf', 'zmm_grwt_pump', 'zmm_isivalve', 'zmm_isi_wc', 'zmm_labelperiod', 'zmm_length', 'zmm_license_cml_no', 'zmm_mfgmonyr', 'zmm_modelyear', 'zmm_motoridentification', 'zmm_newt_pset', 'zmm_newt_cable', 'zmm_newt_motor', 'zmm_newt_pf', 'zmm_newt_pump', 'zmm_packtype', 'zmm_panel', 'zmm_performance_factor', 'zmm_pumpidentification', 'zmm_psettype', 'zmm_size', 'zmm_eff_ttl', 'zmm_type', 'zmm_usp']; // $characteristicsData = ClassCharacteristic::where('aufnr', $jobNumber) // ->where('plant_id', $plantId) @@ -2115,27 +2851,41 @@ class CharacteristicsController extends Controller // return response()->json([ // 'status_code' => "ERROR", // 'status_description' => 'No characteristics data found for the provided Plant, Work Center, and Job Number!' - // ], 400); + // ], 404); // } return response()->json([ 'ZMM_HEADING' => $serialExists->zmm_heading ?? '', 'MARK_STATUS' => $serialExists->mark_status ?? '', 'MARKED_DATETIME' => $serialExists->marked_datetime, + 'MARKED_PHYSICAL_COUNT' => $serialExists->marked_physical_count ?? '0', + 'MARKED_EXPECTED_TIME' => $serialExists->marked_expected_time ?? '0', 'MARKED_BY' => ($serialExists->marked_by == 'Admin') ? 'jothi' : $serialExists->marked_by ?? '', - 'MAN_MARKED_STATUS' => $serialExists->man_marked_status ?? '', + 'MAN_MARKED_STATUS' => $serialExists->man_marked_status ?? '0', 'MAN_MARKED_DATETIME' => $serialExists->man_marked_datetime ?? '', 'MAN_MARKED_BY' => ($serialExists->man_marked_by == 'Admin') ? 'jothi' : $serialExists->man_marked_by ?? '', 'MOTOR_MARKED_STATUS' => $serialExists->motor_marked_status ?? '', + 'MOTOR_MARKED_PHYSICAL_COUNT' => $serialExists->motor_marked_physical_count ?? '0', + 'MOTOR_EXPECTED_TIME' => $serialExists->motor_expected_time ?? '0', 'MOTOR_MARKED_BY' => ($serialExists->motor_marked_by == 'Admin') ? 'jothi' : $serialExists->motor_marked_by ?? '', 'PUMP_MARKED_STATUS' => $serialExists->pump_marked_status ?? '', + 'PUMP_MARKED_PHYSICAL_COUNT' => $serialExists->pump_marked_physical_count ?? '0', + 'PUMP_EXPECTED_TIME' => $serialExists->pump_expected_time ?? '0', 'PUMP_MARKED_BY' => ($serialExists->pump_marked_by == 'Admin') ? 'jothi' : $serialExists->pump_marked_by ?? '', + 'NAME_PLATE_MARKED_STATUS' => $serialExists->name_plate_marked_status ?? '', + 'NAME_PLATE_EXPECTED_TIME' => $serialExists->name_plate_expected_time ?? '0', + 'NAME_PLATE_MARKED_BY' => ($serialExists->name_plate_marked_by == 'Admin') ? 'jothi' : $serialExists->name_plate_marked_by ?? '', 'MOTOR_PUMP_PUMPSET_STATUS' => $serialExists->motor_pump_pumpset_status ?? '', + 'WINDED_SERIAL_NUMBER' => $serialExists->winded_serial_number ?? '', 'MOTOR_MACHINE_NAME' => $serialExists->motor_machine_name ?? '', 'PUMP_MACHINE_NAME' => $serialExists->pump_machine_name ?? '', + 'NAME_PLATE_MACHINE_NAME' => $serialExists->name_plate_machine_name ?? '', 'PUMPSET_MACHINE_NAME' => $serialExists->pumpset_machine_name ?? '', - 'MOTOR_EXPECTED_TIME' => $serialExists->motor_expected_time ?? '', - 'PUMP_EXPECTED_TIME' => $serialExists->pump_expected_time ?? '', + 'PART_VALIDATION_1' => $serialExists->part_validation_1 ?? '', + 'PART_VALIDATION_2' => $serialExists->part_validation_2 ?? '', + 'PENDING_RELEASED_STATUS' => (string) $serialExists->pending_released_status ?? '0', + 'SAMLIGHT_LOGGED_NAME' => $serialExists->samlight_logged_name ?? '', + 'HAS_WORK_FLOW_ID' => $serialExists->has_work_flow_id ?? '0', ], 200); } } @@ -2151,7 +2901,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 403); + ], 401); } $plantCode = $request->header('plant-code'); @@ -2163,32 +2913,32 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", - ], 400); + ], 404); } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid plant code found!', - ], 400); + ], 404); } elseif ($itemCode == null || $itemCode == '') { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Item Code can't be empty!", - ], 400); + ], 404); } elseif (Str::length($itemCode) < 6 || ! ctype_alnum($itemCode)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid item code found!', - ], 400); + ], 404); } elseif ($lineName == null || $lineName == '') { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Line name can't be empty!", - ], 400); + ], 404); } elseif ($workCenter == null || $workCenter == '') { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Work center can't be empty!", - ], 400); + ], 404); } $plant = Plant::where('code', $plantCode)->first(); @@ -2197,7 +2947,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Plant not found!', - ], 400); + ], 404); } $plantId = $plant->id; @@ -2331,7 +3081,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 404); + ], 401); } $plantCode = $request->header('plant-code'); @@ -2474,6 +3224,11 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => 'Coil number should contain only numeric values!', ], 404); + } elseif (Str::length($coilNo) > 1 && ! Str::contains($coilNo, '.') && ! preg_match('/^[1-9][0-9]*$/', $coilNo)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Coil number '{$coilNo}' should not begin with '0'!", + ], 404); } if ($status == null || $status == '' || ! $status) { @@ -2540,7 +3295,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'SUCCESS', - 'status_description' => 'Characteristics values inserted successfully', + 'status_description' => 'Characteristics values inserted successfully.', ], 200); } @@ -2565,7 +3320,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 403); + ], 401); } $userName = $request->header('user-name'); @@ -2733,6 +3488,8 @@ class CharacteristicsController extends Controller $ItemId = $item->id; + // ..Initial Logic + $pCode = CharacteristicApproverMaster::where('plant_id', $plantId)->first(); if (! $pCode) { return response()->json([ @@ -2837,6 +3594,8 @@ class CharacteristicsController extends Controller ], 404); } + // ..Both Has Pending and Completed Logic + $pendingCharacteristics = []; $unknownCharacteristics = []; $appTypExist = null; @@ -2995,6 +3754,8 @@ class CharacteristicsController extends Controller } } + // ..Has Pending Scenario + return response()->json([ 'work_flow_ids' => [$workFlowIds], ], 200); @@ -3153,7 +3914,7 @@ class CharacteristicsController extends Controller return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', - ], 403); + ], 401); } $userName = $request->header('user-name');