Changed process order chart logic in widget
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 19s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Laravel Pint / pint (pull_request) Successful in 3m7s
Laravel Larastan / larastan (pull_request) Failing after 4m39s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 19s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Laravel Pint / pint (pull_request) Successful in 3m7s
Laravel Larastan / larastan (pull_request) Failing after 4m39s
This commit is contained in:
@@ -15,89 +15,89 @@ class ProcessOrderChart extends ChartWidget
|
||||
|
||||
protected $listeners = ['processOrderChart'];
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
// protected function getData(): array
|
||||
// {
|
||||
// $activeFilter = $this->filter;
|
||||
|
||||
$selectedPlant = session('selected_plant');
|
||||
$selectedLine = session('selected_line');
|
||||
// $selectedPlant = session('selected_plant');
|
||||
// $selectedLine = session('selected_line');
|
||||
|
||||
// dd($selectedPlant, $selectedLine);
|
||||
// // dd($selectedPlant, $selectedLine);
|
||||
|
||||
if (!$selectedPlant || !$selectedLine) {
|
||||
return [
|
||||
'datasets' => [],
|
||||
'labels' => [],
|
||||
];
|
||||
}
|
||||
// if (!$selectedPlant || !$selectedLine) {
|
||||
// return [
|
||||
// 'datasets' => [],
|
||||
// 'labels' => [],
|
||||
// ];
|
||||
// }
|
||||
|
||||
if ($activeFilter == 'yesterday')
|
||||
{
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
$groupBy = "EXTRACT(HOUR FROM created_at)";
|
||||
}
|
||||
else if ($activeFilter == 'this_week')
|
||||
{
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = "EXTRACT(DOW FROM created_at)";
|
||||
}
|
||||
else if ($activeFilter == 'this_month')
|
||||
{
|
||||
$startDate = now()->startOfMonth();
|
||||
$endDate = now()->endOfMonth();
|
||||
$groupBy = "FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1";
|
||||
}
|
||||
else
|
||||
{
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = "EXTRACT(HOUR FROM created_at)";
|
||||
}
|
||||
// if ($activeFilter == 'yesterday')
|
||||
// {
|
||||
// $startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
// $endDate = now()->setTime(8, 0, 0);
|
||||
// $groupBy = "EXTRACT(HOUR FROM created_at)";
|
||||
// }
|
||||
// else if ($activeFilter == 'this_week')
|
||||
// {
|
||||
// $startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
// $endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
// $groupBy = "EXTRACT(DOW FROM created_at)";
|
||||
// }
|
||||
// else if ($activeFilter == 'this_month')
|
||||
// {
|
||||
// $startDate = now()->startOfMonth();
|
||||
// $endDate = now()->endOfMonth();
|
||||
// $groupBy = "FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $startDate = now()->setTime(8, 0, 0);
|
||||
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
// $groupBy = "EXTRACT(HOUR FROM created_at)";
|
||||
// }
|
||||
|
||||
// Get process orders for selected plant and line
|
||||
$processOrders = DB::table('process_orders')
|
||||
->select('process_order')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->where('line_id', $selectedLine)
|
||||
->distinct();
|
||||
// // Get process orders for selected plant and line
|
||||
// $processOrders = DB::table('process_orders')
|
||||
// ->select('process_order')
|
||||
// ->where('plant_id', $selectedPlant)
|
||||
// ->where('line_id', $selectedLine)
|
||||
// ->distinct();
|
||||
|
||||
// Get OK and Not OK counts against each process order
|
||||
$records = CharacteristicValue::query()
|
||||
->where('plant_id', $selectedPlant)
|
||||
->whereIn('process_order', $processOrders)
|
||||
->where('created_at', '>=', $startDate)
|
||||
->where('created_at', '<', $endDate)
|
||||
->selectRaw("
|
||||
process_order,
|
||||
SUM(CASE WHEN status = 'Ok' THEN 1 ELSE 0 END) as ok_count,
|
||||
SUM(CASE WHEN status = 'NotOk' THEN 1 ELSE 0 END) as not_ok_count
|
||||
")
|
||||
->groupBy('process_order')
|
||||
->orderBy('process_order')
|
||||
->get();
|
||||
// // Get OK and Not OK counts against each process order
|
||||
// $records = CharacteristicValue::query()
|
||||
// ->where('plant_id', $selectedPlant)
|
||||
// ->whereIn('process_order', $processOrders)
|
||||
// ->where('created_at', '>=', $startDate)
|
||||
// ->where('created_at', '<', $endDate)
|
||||
// ->selectRaw("
|
||||
// process_order,
|
||||
// SUM(CASE WHEN status = 'Ok' THEN 1 ELSE 0 END) as ok_count,
|
||||
// SUM(CASE WHEN status = 'NotOk' THEN 1 ELSE 0 END) as not_ok_count
|
||||
// ")
|
||||
// ->groupBy('process_order')
|
||||
// ->orderBy('process_order')
|
||||
// ->get();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'OK',
|
||||
'data' => $records->pluck('ok_count')
|
||||
->map(fn ($v) => (int) $v)
|
||||
->toArray(),
|
||||
'backgroundColor' => '#16A34A',
|
||||
],
|
||||
[
|
||||
'label' => 'Not OK',
|
||||
'data' => $records->pluck('not_ok_count')
|
||||
->map(fn ($v) => (int) $v)
|
||||
->toArray(),
|
||||
'backgroundColor' => '#DC2626',
|
||||
],
|
||||
],
|
||||
// return [
|
||||
// 'datasets' => [
|
||||
// [
|
||||
// 'label' => 'OK',
|
||||
// 'data' => $records->pluck('ok_count')
|
||||
// ->map(fn ($v) => (int) $v)
|
||||
// ->toArray(),
|
||||
// 'backgroundColor' => '#16A34A',
|
||||
// ],
|
||||
// [
|
||||
// 'label' => 'Not OK',
|
||||
// 'data' => $records->pluck('not_ok_count')
|
||||
// ->map(fn ($v) => (int) $v)
|
||||
// ->toArray(),
|
||||
// 'backgroundColor' => '#DC2626',
|
||||
// ],
|
||||
// ],
|
||||
|
||||
'labels' => $records->pluck('process_order')->toArray(),
|
||||
];
|
||||
// 'labels' => $records->pluck('process_order')->toArray(),
|
||||
// ];
|
||||
|
||||
// $records = CharacteristicValue::query()
|
||||
// ->selectRaw("
|
||||
@@ -125,6 +125,76 @@ class ProcessOrderChart extends ChartWidget
|
||||
|
||||
// 'labels' => $records->pluck('process_order')->toArray(),
|
||||
// ];
|
||||
// }
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
$selectedPlant = session('selected_plant');
|
||||
$selectedLine = session('selected_line');
|
||||
|
||||
if (!$selectedPlant || !$selectedLine) {
|
||||
return [
|
||||
'datasets' => [],
|
||||
'labels' => [],
|
||||
];
|
||||
}
|
||||
|
||||
if ($activeFilter == 'yesterday') {
|
||||
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
|
||||
} else if ($activeFilter == 'this_week') {
|
||||
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->startOfWeek()->addWeek()->setTime(8, 0, 0);
|
||||
|
||||
} else if ($activeFilter == 'this_month') {
|
||||
|
||||
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endDate = now()->addMonthNoOverflow()->startOfMonth()->setTime(8, 0, 0);
|
||||
|
||||
} else {
|
||||
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
}
|
||||
|
||||
$records = CharacteristicValue::query()
|
||||
->where('plant_id', $selectedPlant)
|
||||
->whereIn('process_order', function ($query) use ($selectedPlant, $selectedLine) {
|
||||
$query->select('process_order')
|
||||
->from('process_orders')
|
||||
->where('plant_id', $selectedPlant)
|
||||
->where('line_id', $selectedLine)
|
||||
->distinct();
|
||||
})
|
||||
->where('created_at', '>=', $startDate)
|
||||
->where('created_at', '<', $endDate)
|
||||
->selectRaw("
|
||||
SUM(CASE WHEN status = 'Ok' THEN 1 ELSE 0 END) as ok_count,
|
||||
SUM(CASE WHEN status = 'NotOk' THEN 1 ELSE 0 END) as not_ok_count
|
||||
")
|
||||
->first();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Quantity',
|
||||
'data' => [
|
||||
(int) ($records->ok_count ?? 0),
|
||||
(int) ($records->not_ok_count ?? 0),
|
||||
],
|
||||
'backgroundColor' => [
|
||||
'#16A34A',
|
||||
'#DC2626',
|
||||
],
|
||||
],
|
||||
],
|
||||
'labels' => ['OK', 'Not OK'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
|
||||
Reference in New Issue
Block a user