Added sticker master controller file
This commit is contained in:
140
app/Http/Controllers/StickerMasterController.php
Normal file
140
app/Http/Controllers/StickerMasterController.php
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Item;
|
||||||
|
use App\Models\MotorTestingMaster;
|
||||||
|
use App\Models\Plant;
|
||||||
|
use App\Models\StickerMaster;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class StickerMasterController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*/
|
||||||
|
public function get_master(Request $request)
|
||||||
|
{
|
||||||
|
$expectedUser = env('API_AUTH_USER');
|
||||||
|
$expectedPw = env('API_AUTH_PW');
|
||||||
|
$header_auth = $request->header('Authorization');
|
||||||
|
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||||
|
|
||||||
|
// if ("Bearer " . $expectedToken !== $header_auth)
|
||||||
|
// {
|
||||||
|
// return response("Unauthorized", 403)
|
||||||
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
// }
|
||||||
|
|
||||||
|
//$data = $request->all();
|
||||||
|
|
||||||
|
if ("Bearer " . $expectedToken !== $header_auth)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => 'Invalid authorization token'
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plantCode = $request->header('plant-code');
|
||||||
|
$itemCode = $request->header('item-code');
|
||||||
|
|
||||||
|
if ($plantCode == null || $plantCode == '')
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant name cannot be empty"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
else if ($itemCode == null || $itemCode == '')
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Item code cannot be empty"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plant = Plant::where('code', $plantCode)->first();
|
||||||
|
|
||||||
|
if (!$plant) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant not found"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plantId = $plant->id;
|
||||||
|
|
||||||
|
$item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first();
|
||||||
|
|
||||||
|
$description = $item ? $item->description : '';
|
||||||
|
|
||||||
|
$uom = $item ? $item->uom : '';
|
||||||
|
|
||||||
|
$category = $item ? $item->category : '';
|
||||||
|
|
||||||
|
$item = Item::where('code', $itemCode)->first();
|
||||||
|
|
||||||
|
if (!$item)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Item Code not found in item table for the plant : $plant->name"
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stickerMaster = StickerMaster::where('plant_id', $plant->id)->where('item_id', $item->id)->first();
|
||||||
|
|
||||||
|
if (!$stickerMaster)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Item Code not found in master table for the plant : $plant->name"
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = [
|
||||||
|
"item_description" => $description ?? "",
|
||||||
|
"uom" => $uom ?? "",
|
||||||
|
"Part_Validation_1" => $stickerMaster->laser_part_validation1 ?? "",
|
||||||
|
"Part_Validation_2" => $stickerMaster->laser_part_validation2 ?? "",
|
||||||
|
"Part_Validation_3" => "",
|
||||||
|
"Part_Validation_4" => "",
|
||||||
|
"Part_Validation_5" => ""
|
||||||
|
];
|
||||||
|
|
||||||
|
return response()->json($output, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*/
|
||||||
|
public function update(Request $request, string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*/
|
||||||
|
public function destroy(string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user