ranjith-dev #828
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Item;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@@ -56,6 +57,78 @@ class PlantController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getItemCode(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()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => 'Invalid authorization token!',
|
||||||
|
], 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plantCode = $request->header('plant-code');
|
||||||
|
|
||||||
|
$itemCode = $request->header('item-code');
|
||||||
|
|
||||||
|
if (! $plantCode) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant Code value can't be empty",
|
||||||
|
], 404);
|
||||||
|
} elseif (! $itemCode) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => 'Item code cannot be empty!',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$plant = Plant::where('code', $plantCode)->first();
|
||||||
|
$plantId = $plant->id;
|
||||||
|
|
||||||
|
if (! $plant) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant Code '{$plantCode}' not found!",
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCodeExist = Item::where('code', $itemCode)->first();
|
||||||
|
|
||||||
|
if (! $itemCodeExist) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => 'Item code not found',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemCodePlantExist = Item::where('code', $itemCode)->where('plant_id', $plantId)->first();
|
||||||
|
|
||||||
|
if (! $itemCodePlantExist) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Item code not found against plant code '$plantCode'",
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty(trim($itemCodePlantExist->description ?? ''))) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Description is empty in Item Master against item code '$itemCode'.",
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'SUCCESS',
|
||||||
|
'status_description' => [
|
||||||
|
'description' => $itemCodePlantExist->description,
|
||||||
|
],
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -234,3 +234,7 @@ Route::post('file/store', [SapFileController::class, 'store'])->name('file.store
|
|||||||
Route::get('/print-pallet/{pallet}/{plant}', [PalletPrintController::class, 'print'])->name('print.pallet');
|
Route::get('/print-pallet/{pallet}/{plant}', [PalletPrintController::class, 'print'])->name('print.pallet');
|
||||||
|
|
||||||
Route::post('vehicle/entry', [VehicleController::class, 'storeVehicleEntry']);
|
Route::post('vehicle/entry', [VehicleController::class, 'storeVehicleEntry']);
|
||||||
|
|
||||||
|
//..Item Code
|
||||||
|
|
||||||
|
Route::get('item-code', [PlantController::class, 'getItemCode']);
|
||||||
|
|||||||
Reference in New Issue
Block a user