Added all get api for modules data
This commit is contained in:
103
app/Http/Controllers/ModuleChartController.php
Normal file
103
app/Http/Controllers/ModuleChartController.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ModuleList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleChartController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_moduleChart(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);
|
||||
}
|
||||
|
||||
$moduleName = $request->header('module-name');
|
||||
|
||||
if (empty($moduleName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Module Name can't be empty!"
|
||||
], 400);
|
||||
}
|
||||
|
||||
$exists = ModuleList::where('module_name', $moduleName)->exists();
|
||||
|
||||
if (!$exists) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Module Name '{$moduleName}' not found in system!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Fetch all unique dashboard names for the given module_name
|
||||
// $dashboardNames = ModuleList::where('module_name', $moduleName)
|
||||
// ->distinct()
|
||||
// ->pluck('dashboard_name');
|
||||
$dashboardNames = ModuleList::where('module_name', $moduleName)
|
||||
->orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->unique('dashboard_name')
|
||||
->pluck('dashboard_name')
|
||||
->values(); // reset array keys
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $dashboardNames
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
88
app/Http/Controllers/ModuleFilterController.php
Normal file
88
app/Http/Controllers/ModuleFilterController.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ModuleList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleFilterController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_moduleFilter(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);
|
||||
}
|
||||
|
||||
$lineName = $request->header('line-name');
|
||||
|
||||
if (empty($lineName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line name can't be empty!"
|
||||
], 400);
|
||||
}
|
||||
|
||||
$filterNames = ModuleList::orderBy('created_at', 'asc')
|
||||
->get()
|
||||
->unique('filter_name')
|
||||
->pluck('filter_name')
|
||||
->filter()
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $filterNames
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
144
app/Http/Controllers/ModuleFilterDataController.php
Normal file
144
app/Http/Controllers/ModuleFilterDataController.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionQuantity;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleFilterDataController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_moduleFilterData(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);
|
||||
}
|
||||
|
||||
$moduleName = $request->header('module-name');
|
||||
$chartName = $request->header('chart-name');
|
||||
$plantName = $request->header('plant-name');
|
||||
$lineName = $request->header('line-name');
|
||||
$filterName = $request->header('filter-name');
|
||||
|
||||
$requiredHeaders = [
|
||||
'module-name',
|
||||
'chart-name',
|
||||
'plant-name',
|
||||
'line-name',
|
||||
'filter-name',
|
||||
];
|
||||
|
||||
$missingHeaders = [];
|
||||
|
||||
foreach ($requiredHeaders as $header) {
|
||||
if (empty($request->header($header))) {
|
||||
$missingHeaders[] = $header;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($missingHeaders)) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Missing required headers: ' . implode(', ', $missingHeaders)
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Fetch plant ID
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Fetch line ID
|
||||
$line = Line::where('name', $lineName)->where('plant_id', $plant->id)->first();
|
||||
if (!$line) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line '{$lineName}' not found for plant '{$plantName}'"
|
||||
], 404);
|
||||
}
|
||||
|
||||
$activeFilter = strtolower(trim($request->header('filter-name')));
|
||||
|
||||
if ($activeFilter == 'yesterday') {
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
}
|
||||
elseif ($activeFilter == 'this_week') {
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
elseif ($activeFilter == 'this_month') {
|
||||
$startDate = now()->startOfMonth();
|
||||
$endDate = now()->endOfMonth();
|
||||
}
|
||||
else { // today or default
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
|
||||
$rowCount = ProductionQuantity::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $rowCount
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
94
app/Http/Controllers/ModulePlantController.php
Normal file
94
app/Http/Controllers/ModulePlantController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModulePlantController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_modulePlant(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);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
|
||||
if (empty($plantName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Name can't be empty!"
|
||||
], 400);
|
||||
}
|
||||
|
||||
$headerValue = $request->header('plant-name');
|
||||
|
||||
if ($headerValue != 'Plant List') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Invalid value for 'plant-name' header!"
|
||||
], 400);
|
||||
}
|
||||
|
||||
$plantNames = Plant::orderBy('created_at', 'asc')
|
||||
->pluck('name')
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $plantNames
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
118
app/Http/Controllers/ModulePlantLineController.php
Normal file
118
app/Http/Controllers/ModulePlantLineController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModulePlantLineController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function get_modulePlantLine(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);
|
||||
}
|
||||
|
||||
$plantName = $request->header('plant-name');
|
||||
|
||||
if (empty($plantName))
|
||||
{
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant Name can't be empty!"
|
||||
], 400);
|
||||
}
|
||||
|
||||
$plant = Plant::where('name', $plantName)->first();
|
||||
|
||||
if (!$plant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Plant '{$plantName}' not found!"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// // Get line names for the plant
|
||||
// $lineNames = Line::where('plant_id', $plant->id)
|
||||
// ->orderBy('created_at', 'asc')
|
||||
// ->pluck('name')
|
||||
// ->prepend('All Lines')
|
||||
// ->values();
|
||||
|
||||
// return response()->json([
|
||||
// 'status_code' => 'SUCCESS',
|
||||
// 'status_description' => $lineNames,
|
||||
// ], 200);
|
||||
|
||||
$lineNames = Line::where('plant_id', $plant->id)
|
||||
->orderBy('created_at', 'asc')
|
||||
->pluck('name');
|
||||
|
||||
if ($lineNames->isEmpty()) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "No lines found for plant '{$plantName}'"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Prepend 'All Lines'
|
||||
$lineNames->prepend('All Lines')->values();
|
||||
|
||||
return response()->json([
|
||||
'status_code' => 'SUCCESS',
|
||||
'status_description' => $lineNames,
|
||||
], 200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 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