Added invoice dashboard module get api

This commit is contained in:
dhanabalan
2025-07-12 14:03:12 +05:30
parent ea5af41f7f
commit 33acf73b5e
6 changed files with 774 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ class ModuleFilterController extends Controller
], 404); ], 404);
} }
// If 'line-name' is 'FG Lines', return actual FG Line names // If 'line-name' is 'FG Lines', return actual FG Line names
if (strtolower(trim($lineName)) === 'fg lines') { if (strtolower(trim($lineName)) == 'fg lines') {
$fgLines = \App\Models\Line::where('type', 'FG Line') $fgLines = \App\Models\Line::where('type', 'FG Line')
->orderBy('created_at', 'asc') ->orderBy('created_at', 'asc')
->pluck('name'); ->pluck('name');

View File

@@ -0,0 +1,91 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ModuleInvoiceDataController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
public function get_invoiceData(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('invoice-type-list');
if (empty($moduleName))
{
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invoice type can't be empty!"
], 404);
}
$headerValue = $request->header('invoice-type-list');
if ($headerValue != 'Invoice Type List') {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invalid value for 'invoice-type-list' header!"
], 404);
}
$invoiceTypes = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
return response()->json([
'status_code' => 'SUCCESS',
'status_description' => $invoiceTypes
], 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)
{
//
}
}

View File

@@ -0,0 +1,497 @@
<?php
namespace App\Http\Controllers;
use App\Models\InvoiceValidation;
use App\Models\Plant;
use Illuminate\Http\Request;
class ModuleInvoiceTypeController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
// public function get_invoiceCountData(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('invoice-name');
// if (empty($moduleName))
// {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => "Invoice name can't be empty!"
// ], 404);
// }
// $plantName = $request->header('plant-name');
// $selectedInvoice = strtolower(trim($request->header('invoice-name')));
// $activeFilter = strtolower(trim($request->header('filter-name')));
// $plant = Plant::where('name', $plantName)->first();
// if (!$plant) {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => "Plant '{$plantName}' not found!"
// ], 404);
// }
// $selectedPlant = $plant->id;
// if (empty($selectedInvoice) || empty($selectedPlant) || empty($activeFilter)) {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => 'Missing required headers: invoice-name, plant-name, or filter-name'
// ], 404);
// }
// $validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
// $filterHeader = $request->header('filter-name');
// if (!in_array($filterHeader, $validFilters)) {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
// ], 404);
// }
// $validInvoiceFilters = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
// $filterInvoice = $request->header('invoice-name');
// if (!in_array($filterInvoice, $validInvoiceFilters)) {
// return response()->json([
// 'status_code' => 'ERROR',
// 'status_description' => "Invalid invoice-name value! Accepted values are: " . implode(', ', $validInvoiceFilters)
// ], 404);
// }
// 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()->setTime(8, 0, 0);
// $endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
// } else {
// $startDate = now()->setTime(8, 0, 0);
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
// }
// $labels = [];
// $datasets = [];
// if ($activeFilter == 'yesterday' || $activeFilter == 'today')
// {
// // === Imported Invoices ===
// $importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
// ->whereBetween('created_at', [$startDate, $endDate]);
// if ($selectedInvoice == 'individual invoice') {
// $importedQuery->where('quantity', 1);
// } elseif ($selectedInvoice == 'serial invoice') {
// $importedQuery->whereNull('quantity');
// } elseif ($selectedInvoice == 'bundle invoice') {
// $importedQuery->where('quantity', '>', 1);
// }
// $importedCount = $importedQuery->distinct('invoice_number')->count('invoice_number');
// // === Completed Invoices ===
// $completedQuery = InvoiceValidation::select('invoice_number')
// ->where('plant_id', $selectedPlant)
// ->whereBetween('updated_at', [$startDate, $endDate]);
// if ($selectedInvoice == 'individual invoice') {
// $completedQuery->where('quantity', 1)
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
// } elseif ($selectedInvoice == 'serial invoice') {
// $completedQuery->whereNull('quantity')
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
// } elseif ($selectedInvoice == 'bundle invoice') {
// $completedQuery->where('quantity', '>', 1)
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
// }
// $completedCount = $completedQuery->count();
// $labels = ['Imported Invoice', 'Completed Invoice'];
// $datasets = [[
// 'label' => 'Invoices',
// 'data' => [$importedCount, $completedCount],
// ]];
// }
// elseif ($activeFilter == 'this week') {
// $labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
// $imported = array_fill(0, 7, 0);
// $completed = array_fill(0, 7, 0);
// for ($i = 0; $i < 7; $i++) {
// $dayStart = now()->startOfWeek()->addDays($i)->setTime(8, 0, 0);
// $dayEnd = $dayStart->copy()->addDay()->setTime(8, 0, 0);
// $importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
// ->whereBetween('created_at', [$dayStart, $dayEnd]);
// $completedQuery = InvoiceValidation::select('invoice_number')
// ->where('plant_id', $selectedPlant)
// ->whereBetween('updated_at', [$dayStart, $dayEnd]);
// if ($selectedInvoice == 'individual invoice') {
// $importedQuery->where('quantity', 1);
// $completedQuery->where('quantity', 1)
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
// } elseif ($selectedInvoice == 'serial invoice') {
// $importedQuery->whereNull('quantity');
// $completedQuery->whereNull('quantity')
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
// } elseif ($selectedInvoice == 'bundle invoice') {
// $importedQuery->where('quantity', '>', 1);
// $completedQuery->where('quantity', '>', 1)
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
// }
// $imported[$i] = $importedQuery->distinct('invoice_number')->count('invoice_number');
// $completed[$i] = $completedQuery->count();
// }
// $datasets = [
// ['label' => 'Imported Invoices', 'data' => $imported],
// ['label' => 'Completed Invoices', 'data' => $completed],
// ];
// }
// elseif ($activeFilter == 'this month') {
// $startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
// $endOfMonth = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
// $labels = [];
// $imported = [];
// $completed = [];
// $weekStart = $startOfMonth->copy();
// while ($weekStart < $endOfMonth) {
// $weekEnd = $weekStart->copy()->addDays(7);
// $label = $weekStart->format('M') . ' (' . $weekStart->format('j') . '-' . $weekEnd->subDay()->format('j') . ')';
// $labels[] = $label;
// $importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
// ->whereBetween('created_at', [$weekStart, $weekEnd]);
// $completedQuery = InvoiceValidation::select('invoice_number')
// ->where('plant_id', $selectedPlant)
// ->whereBetween('updated_at', [$weekStart, $weekEnd]);
// if ($selectedInvoice == 'individual invoice') {
// $importedQuery->where('quantity', 1);
// $completedQuery->where('quantity', 1)
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
// } elseif ($selectedInvoice == 'serial invoice') {
// $importedQuery->whereNull('quantity');
// $completedQuery->whereNull('quantity')
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
// } elseif ($selectedInvoice == 'bundle invoice') {
// $importedQuery->where('quantity', '>', 1);
// $completedQuery->where('quantity', '>', 1)
// ->groupBy('invoice_number')
// ->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
// }
// $imported[] = $importedQuery->distinct('invoice_number')->count('invoice_number');
// $completed[] = $completedQuery->count();
// $weekStart = $weekEnd;
// }
// $datasets = [
// ['label' => 'Imported Invoices', 'data' => $imported],
// ['label' => 'Completed Invoices', 'data' => $completed],
// ];
// }
// // Clean zero values to null
// foreach ($datasets as &$dataset) {
// $dataset['data'] = array_map(function ($value) {
// return ($value === null) ? 0 : $value;
// }, $dataset['data']);
// }
// return response()->json([
// 'status_code' => 'SUCCESS',
// 'labels' => $labels,
// 'datasets' => $datasets,
// ], 200);
// }
/**
* Store a newly created resource in storage.
*/
public function get_invoiceCountData(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');
$filterHeader = $request->header('filter-name');
$invoiceHeader = $request->header('invoice-name');
if (empty($plantName) || empty($invoiceHeader) || empty($filterHeader)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Missing required headers: plant-name, invoice-name, or filter-name"
], 404);
}
$validFilters = ['Today', 'Yesterday', 'This Week', 'This Month'];
if (!in_array($filterHeader, $validFilters)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invalid filter-name value! Accepted values are: " . implode(', ', $validFilters)
], 404);
}
$validInvoiceFilters = ['All Invoice', 'Serial Invoice', 'Individual Invoice', 'Bundle Invoice'];
if (!in_array($invoiceHeader, $validInvoiceFilters)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invalid invoice-name value! Accepted values are: " . implode(', ', $validInvoiceFilters)
], 404);
}
$plant = Plant::where('name', $plantName)->first();
if (!$plant) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant '{$plantName}' not found!"
], 404);
}
$selectedPlant = $plant->id;
$activeFilter = strtolower(trim($filterHeader));
$selectedInvoice = strtolower(trim($invoiceHeader));
// Set time range
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()->setTime(8, 0, 0);
$endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
} else {
$startDate = now()->setTime(8, 0, 0);
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
}
$labels = [];
$datasets = [];
// Map types for All Invoice
$invoiceTypes = $selectedInvoice == 'all invoice'
? [
'Individual Invoice' => fn($q) => $q->where('quantity', 1),
'Serial Invoice' => fn($q) => $q->whereNull('quantity'),
'Bundle Invoice' => fn($q) => $q->where('quantity', '>', 1)
]
: [
ucfirst($selectedInvoice) => match ($selectedInvoice) {
'individual invoice' => fn($q) => $q->where('quantity', 1),
'serial invoice' => fn($q) => $q->whereNull('quantity'),
'bundle invoice' => fn($q) => $q->where('quantity', '>', 1),
}
];
foreach ($invoiceTypes as $labelPrefix => $queryModifier) {
if ($activeFilter == 'yesterday' || $activeFilter == 'today') {
$importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
->whereBetween('created_at', [$startDate, $endDate]);
$queryModifier($importedQuery);
$importedCount = $importedQuery->distinct('invoice_number')->count('invoice_number');
$completedQuery = InvoiceValidation::select('invoice_number')
->where('plant_id', $selectedPlant)
->whereBetween('updated_at', [$startDate, $endDate]);
if ($selectedInvoice == 'serial invoice' || $labelPrefix == 'Serial Invoice') {
$queryModifier($completedQuery)
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
} else {
$queryModifier($completedQuery)
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
}
$completedCount = $completedQuery->count();
$labels = ['Imported Invoice', 'Completed Invoice'];
$datasets[] = [
'label' => "$labelPrefix",
'data' => [$importedCount, $completedCount],
];
}
elseif ($activeFilter == 'this week') {
$labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
$imported = array_fill(0, 7, 0);
$completed = array_fill(0, 7, 0);
for ($i = 0; $i < 7; $i++) {
$dayStart = now()->startOfWeek()->addDays($i)->setTime(8, 0, 0);
$dayEnd = $dayStart->copy()->addDay()->setTime(8, 0, 0);
$importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
->whereBetween('created_at', [$dayStart, $dayEnd]);
$queryModifier($importedQuery);
$imported[$i] = $importedQuery->distinct('invoice_number')->count('invoice_number');
$completedQuery = InvoiceValidation::select('invoice_number')
->where('plant_id', $selectedPlant)
->whereBetween('updated_at', [$dayStart, $dayEnd]);
if ($selectedInvoice == 'serial invoice' || $labelPrefix == 'Serial Invoice') {
$queryModifier($completedQuery)
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
} else {
$queryModifier($completedQuery)
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
}
$completed[$i] = $completedQuery->count();
}
$datasets[] = ['label' => "$labelPrefix Imported", 'data' => $imported];
$datasets[] = ['label' => "$labelPrefix Completed", 'data' => $completed];
}
elseif ($activeFilter == 'this month') {
$startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
$endOfMonth = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
$labels = [];
$imported = [];
$completed = [];
$weekStart = $startOfMonth->copy();
while ($weekStart < $endOfMonth) {
$weekEnd = $weekStart->copy()->addDays(7);
$label = $weekStart->format('M') . ' (' . $weekStart->format('j') . '-' . $weekEnd->subDay()->format('j') . ')';
$labels[] = $label;
$importedQuery = InvoiceValidation::where('plant_id', $selectedPlant)
->whereBetween('created_at', [$weekStart, $weekEnd]);
$queryModifier($importedQuery);
$imported[] = $importedQuery->distinct('invoice_number')->count('invoice_number');
$completedQuery = InvoiceValidation::select('invoice_number')
->where('plant_id', $selectedPlant)
->whereBetween('updated_at', [$weekStart, $weekEnd]);
if ($selectedInvoice == 'serial invoice' || $labelPrefix == 'Serial Invoice') {
$queryModifier($completedQuery)
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN scanned_status = 'Scanned' THEN 1 ELSE 0 END)");
} else {
$queryModifier($completedQuery)
->groupBy('invoice_number')
->havingRaw("COUNT(*) = SUM(CASE WHEN serial_number IS NOT NULL AND serial_number != '' THEN 1 ELSE 0 END)");
}
$completed[] = $completedQuery->count();
$weekStart = $weekEnd;
}
$datasets[] = ['label' => "$labelPrefix Imported", 'data' => $imported];
$datasets[] = ['label' => "$labelPrefix Completed", 'data' => $completed];
}
}
// Ensure 0 instead of null
foreach ($datasets as &$dataset) {
$dataset['data'] = array_map(fn($val) => $val === null ? 0 : $val, $dataset['data']);
}
return response()->json([
'status_code' => 'SUCCESS',
'labels' => $labels,
'datasets' => $datasets,
]);
}
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)
{
//
}
}

View File

@@ -93,7 +93,14 @@ class ModulePlantLineController extends Controller
if (empty($plantName)) { if (empty($plantName)) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant Name can't be empty!" 'status_description' => "Plant name can't be empty!"
], 404);
}
if (empty($chartName)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Chart name can't be empty!"
], 404); ], 404);
} }
@@ -106,8 +113,6 @@ class ModulePlantLineController extends Controller
], 404); ], 404);
} }
// Load only lines NOT equal to FG Line // Load only lines NOT equal to FG Line
$nonFgLines = Line::where('plant_id', $plant->id) $nonFgLines = Line::where('plant_id', $plant->id)
->where('type', '!=', 'FG Line') ->where('type', '!=', 'FG Line')

View File

@@ -0,0 +1,171 @@
<?php
namespace App\Http\Controllers;
use App\Models\Line;
use App\Models\Plant;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ModuleProductionLineStopController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
public function get_moduleProductionLineStop(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);
}
$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)
], 404);
}
$plantName = $request->header('plant-name');
$lineName = $request->header('line-name');
$filterName = strtolower(trim($request->header('filter-name')));
$plant = Plant::where('name', $plantName)->first();
if (!$plant) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant '{$plantName}' not found!"
], 404);
}
$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);
}
// Set time range
if ($filterName == 'yesterday') {
$startDate = now()->subDay()->setTime(8, 0, 0);
$endDate = now()->setTime(8, 0, 0);
} elseif ($filterName == 'this week') {
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
} elseif ($filterName == 'this month') {
$startDate = now()->startOfMonth();
$endDate = now()->endOfMonth();
} else {
$startDate = now()->setTime(8, 0, 0);
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
}
$query = DB::table('production_line_stops')
->join('line_stops as ls', 'production_line_stops.linestop_id', '=', 'ls.id')
->join('lines', 'production_line_stops.line_id', '=', 'lines.id')
->join('plants', 'production_line_stops.plant_id', '=', 'plants.id')
->select(
'ls.code',
'ls.reason',
DB::raw("SUM(production_line_stops.stop_hour) as total_stop_hours"),
DB::raw("SUM(production_line_stops.stop_min) as total_stop_minutes")
)
->where('plants.id', $plant->id)
->where('lines.id', $line->id)
->whereBetween('production_line_stops.created_at', [$startDate, $endDate])
->groupBy('ls.code', 'ls.reason')
->get();
if ($query->isEmpty()) {
return response()->json([
'status_code' => 'SUCCESS',
'labels' => ['No Data'],
'data' => [1],
], 200);
}
$labels = [];
$data = [];
$totalStopMinutes = 0;
foreach ($query as $row) {
$stopHours = $row->total_stop_hours;
$stopMinutes = $row->total_stop_minutes;
$visualTotal = $stopHours + ($stopMinutes / 100);
$labels[] = "{$row->code} - {$row->reason}";
$data[] = $visualTotal;
$totalStopMinutes += ($stopHours * 60) + $stopMinutes;
}
// Calculate available runtime
$remainingMinutes = 1440 - $totalStopMinutes;
$runtimeHours = floor($remainingMinutes / 60);
$runtimeMinutes = $remainingMinutes % 60;
$runtimeVisual = $runtimeHours + ($runtimeMinutes / 100);
$labels[] = 'Available Runtime';
$data[] = $runtimeVisual;
return response()->json([
'status_code' => 'SUCCESS',
'labels' => $labels,
'data' => $data,
], 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)
{
//
}
}

View File

@@ -7,8 +7,10 @@ use App\Http\Controllers\ModuleFGLineController;
use App\Http\Controllers\ModuleFilterController; use App\Http\Controllers\ModuleFilterController;
use App\Http\Controllers\ModuleFilterDataController; use App\Http\Controllers\ModuleFilterDataController;
use App\Http\Controllers\ModuleInvoiceDataController; use App\Http\Controllers\ModuleInvoiceDataController;
use App\Http\Controllers\ModuleInvoiceTypeController;
use App\Http\Controllers\ModulePlantController; use App\Http\Controllers\ModulePlantController;
use App\Http\Controllers\ModulePlantLineController; use App\Http\Controllers\ModulePlantLineController;
use App\Http\Controllers\ModuleProductionLineStopController;
use App\Http\Controllers\ModuleProductionOrderDataController; use App\Http\Controllers\ModuleProductionOrderDataController;
use App\Http\Controllers\ObdController; use App\Http\Controllers\ObdController;
use App\Http\Controllers\PalletController; use App\Http\Controllers\PalletController;
@@ -89,7 +91,11 @@ Route::get('get/module-filter-value/data', [ModuleFilterDataController::class, '
Route::get('get/module-production-order/data', [ModuleProductionOrderDataController::class, 'get_moduleProductionOrder']); Route::get('get/module-production-order/data', [ModuleProductionOrderDataController::class, 'get_moduleProductionOrder']);
Route::get('get/module-production-linestop/data', [ModuleProductionLineStopController::class, 'get_moduleProductionLineStop']);
//Invoice Dashboard Controller //Invoice Dashboard Controller
Route::get('get/module-invoice-type/data', [ModuleInvoiceDataController::class, 'get_invoiceData']); Route::get('get/module-invoice-type/data', [ModuleInvoiceDataController::class, 'get_invoiceData']);
Route::get('get/module-invoice-count/data', [ModuleInvoiceTypeController::class, 'get_invoiceCountData']);