Added warning message on item code not found in sticker master #502

Merged
jothi merged 1 commits from ranjith-dev into master 2026-04-04 10:40:13 +00:00
Showing only changes of commit 9b8f178bed - Show all commits

View File

@@ -3,7 +3,6 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Item; use App\Models\Item;
use App\Models\MotorTestingMaster;
use App\Models\Plant; use App\Models\Plant;
use App\Models\StickerMaster; use App\Models\StickerMaster;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -34,43 +33,35 @@ class StickerMasterController extends Controller
$header_auth = $request->header('Authorization'); $header_auth = $request->header('Authorization');
$expectedToken = $expectedUser.':'.$expectedPw; $expectedToken = $expectedUser.':'.$expectedPw;
if ("Bearer " . $expectedToken != $header_auth) if ('Bearer '.$expectedToken != $header_auth) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!' 'status_description' => 'Invalid authorization token!',
], 403); ], 403);
} }
$plantCode = $request->header('plant-code'); $plantCode = $request->header('plant-code');
$itemCode = $request->header('item-code'); $itemCode = $request->header('item-code');
if ($plantCode == null || $plantCode == '') if ($plantCode == null || $plantCode == '') {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!" 'status_description' => "Plant code can't be empty!",
], 400); ], 400);
} } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
else if (Str::length($plantCode) < 4 || !is_numeric($plantCode) || !preg_match('/^[1-9]\d{3,}$/', $plantCode))
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Invalid plant code found!" 'status_description' => 'Invalid plant code found!',
], 400); ], 400);
} } elseif ($itemCode == null || $itemCode == '') {
else if ($itemCode == null || $itemCode == '')
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code can't be empty!" 'status_description' => "Item Code can't be empty!",
], 400); ], 400);
} } elseif (Str::length($itemCode) < 6 || ! ctype_alnum($itemCode)) {
else if (Str::length($itemCode) < 6 || !ctype_alnum($itemCode))
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Invalid item code found!" 'status_description' => 'Invalid item code found!',
], 400); ], 400);
} }
@@ -79,7 +70,7 @@ class StickerMasterController extends Controller
if (! $plant) { if (! $plant) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant not found!" 'status_description' => 'Plant not found!',
], 400); ], 400);
} }
@@ -87,51 +78,57 @@ class StickerMasterController extends Controller
$item = Item::where('code', $itemCode)->first(); $item = Item::where('code', $itemCode)->first();
if (!$item) if (! $item) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code not found in item table!" 'status_description' => 'Item Code not found in item table!',
], 404); ], 404);
} }
$item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first(); $item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first();
if (!$item) if (! $item) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code not found in item table for the plant : '$plant->name'!" 'status_description' => "Item Code not found in item table for the plant : '$plant->name'!",
], 404); ], 404);
} }
$stickerMaster = StickerMaster::where('plant_id', $plantId)->where('item_id', $item->id)->first(); $itemId = $item->id;
if (!$stickerMaster) $stickerMaster = StickerMaster::where('item_id', $itemId)->first();
{
if (! $stickerMaster) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code not found in sticker master table for the plant : '$plant->name'!" 'status_description' => 'Item Code not found in sticker master table!',
], 404); ], 404);
} }
$stickerMaster = StickerMaster::where('plant_id', $plantId)->where('item_id', $itemId)->first();
if (! $stickerMaster) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Item Code not found in sticker master table for the plant : '$plant->name'!",
], 404);
}
$serial_number_motor = $stickerMaster->serial_number_motor ?? null; $serial_number_motor = $stickerMaster->serial_number_motor ?? null;
$serial_number_pump = $stickerMaster->serial_number_pump ?? null; $serial_number_pump = $stickerMaster->serial_number_pump ?? null;
if ($serial_number_motor != 1 && $serial_number_pump != 1) { if ($serial_number_motor != 1 && $serial_number_pump != 1) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "The Item Code '$itemCode' does not have serial pump or serial motor selected!" 'status_description' => "The Item Code '$itemCode' does not have serial pump or serial motor selected!",
], 400); ], 400);
} }
$serialInfo = []; $serialInfo = [];
if ($serial_number_motor == 1 && $serial_number_pump == 1) if ($serial_number_motor == 1 && $serial_number_pump == 1) {
{
$serialInfo[] = 'Serial Pump'; $serialInfo[] = 'Serial Pump';
} } else {
else
{
if ($serial_number_motor == 1) { if ($serial_number_motor == 1) {
$serialInfo[] = 'Serial Motor'; $serialInfo[] = 'Serial Motor';
} }
@@ -144,6 +141,7 @@ class StickerMasterController extends Controller
'status_code' => 'SUCCESS', 'status_code' => 'SUCCESS',
'status_description' => implode(', ', $serialInfo), 'status_description' => implode(', ', $serialInfo),
]; ];
return response()->json($output, 200); return response()->json($output, 200);
} }
@@ -157,43 +155,35 @@ class StickerMasterController extends Controller
$header_auth = $request->header('Authorization'); $header_auth = $request->header('Authorization');
$expectedToken = $expectedUser.':'.$expectedPw; $expectedToken = $expectedUser.':'.$expectedPw;
if ("Bearer " . $expectedToken != $header_auth) if ('Bearer '.$expectedToken != $header_auth) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!' 'status_description' => 'Invalid authorization token!',
], 403); ], 403);
} }
$plantCode = $request->header('plant-code'); $plantCode = $request->header('plant-code');
$itemCode = $request->header('item-code'); $itemCode = $request->header('item-code');
if ($plantCode == null || $plantCode == '') if ($plantCode == null || $plantCode == '') {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!" 'status_description' => "Plant code can't be empty!",
], 400); ], 400);
} } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
else if (Str::length($plantCode) < 4 || !is_numeric($plantCode) || !preg_match('/^[1-9]\d{3,}$/', $plantCode))
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Invalid plant code found!" 'status_description' => 'Invalid plant code found!',
], 400); ], 400);
} } elseif ($itemCode == null || $itemCode == '') {
else if ($itemCode == null || $itemCode == '')
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code can't be empty!" 'status_description' => "Item Code can't be empty!",
], 400); ], 400);
} } elseif (Str::length($itemCode) < 6 || ! ctype_alnum($itemCode)) {
else if (Str::length($itemCode) < 6 || !ctype_alnum($itemCode))
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Invalid item code found!" 'status_description' => 'Invalid item code found!',
], 400); ], 400);
} }
@@ -202,7 +192,7 @@ class StickerMasterController extends Controller
if (! $plant) { if (! $plant) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant not found!" 'status_description' => 'Plant not found!',
], 400); ], 400);
} }
@@ -210,48 +200,56 @@ class StickerMasterController extends Controller
$item = Item::where('code', $itemCode)->first(); $item = Item::where('code', $itemCode)->first();
if (!$item) if (! $item) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code not found in item table!" 'status_description' => 'Item Code not found in item table!',
], 404); ], 404);
} }
$item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first(); $item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first();
if (!$item) if (! $item) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code not found in item table for the plant : '$plant->name'!" 'status_description' => "Item Code not found in item table for the plant : '$plant->name'!",
], 404); ], 404);
} }
$itemId = $item->id;
$description = $item ? $item->description : ''; $description = $item ? $item->description : '';
$uom = $item ? $item->uom : ''; $uom = $item ? $item->uom : '';
$category = $item ? $item->category : ''; // $category = $item ? $item->category : '';
$stickerMaster = StickerMaster::where('plant_id', $plantId)->where('item_id', $item->id)->first(); $stickerMaster = StickerMaster::where('item_id', $itemId)->first();
if (!$stickerMaster) if (! $stickerMaster) {
{
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item Code not found in sticker master table for the plant : '$plant->name'!" 'status_description' => 'Item Code not found in sticker master table!',
], 404);
}
$stickerMaster = StickerMaster::where('plant_id', $plantId)->where('item_id', $itemId)->first();
if (! $stickerMaster) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Item Code not found in sticker master table for the plant : '$plant->name'!",
], 404); ], 404);
} }
$output = [ $output = [
"item_description" => $description ?? "", 'item_description' => $description ?? '',
"uom" => $uom ?? "", 'uom' => $uom ?? '',
"Part_Validation_1" => $stickerMaster?->laser_part_validation1 ?? "", 'Part_Validation_1' => $stickerMaster?->laser_part_validation1 ?? '',
"Part_Validation_2" => $stickerMaster?->laser_part_validation2 ?? "", 'Part_Validation_2' => $stickerMaster?->laser_part_validation2 ?? '',
"Part_Validation_3" => $stickerMaster?->laser_part_validation3 ?? "", 'Part_Validation_3' => $stickerMaster?->laser_part_validation3 ?? '',
"Part_Validation_4" => $stickerMaster?->laser_part_validation4 ?? "", 'Part_Validation_4' => $stickerMaster?->laser_part_validation4 ?? '',
"Part_Validation_5" => $stickerMaster?->laser_part_validation5 ?? "", 'Part_Validation_5' => $stickerMaster?->laser_part_validation5 ?? '',
]; ];
return response()->json($output, 200); return response()->json($output, 200);