Changed process order chart logic in widget #1464
@@ -15,89 +15,89 @@ class ProcessOrderChart extends ChartWidget
|
|||||||
|
|
||||||
protected $listeners = ['processOrderChart'];
|
protected $listeners = ['processOrderChart'];
|
||||||
|
|
||||||
protected function getData(): array
|
// protected function getData(): array
|
||||||
{
|
// {
|
||||||
$activeFilter = $this->filter;
|
// $activeFilter = $this->filter;
|
||||||
|
|
||||||
$selectedPlant = session('selected_plant');
|
// $selectedPlant = session('selected_plant');
|
||||||
$selectedLine = session('selected_line');
|
// $selectedLine = session('selected_line');
|
||||||
|
|
||||||
// dd($selectedPlant, $selectedLine);
|
// // dd($selectedPlant, $selectedLine);
|
||||||
|
|
||||||
if (!$selectedPlant || !$selectedLine) {
|
// if (!$selectedPlant || !$selectedLine) {
|
||||||
return [
|
// return [
|
||||||
'datasets' => [],
|
// 'datasets' => [],
|
||||||
'labels' => [],
|
// 'labels' => [],
|
||||||
];
|
// ];
|
||||||
}
|
// }
|
||||||
|
|
||||||
if ($activeFilter == 'yesterday')
|
// if ($activeFilter == 'yesterday')
|
||||||
{
|
// {
|
||||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
// $startDate = now()->subDay()->setTime(8, 0, 0);
|
||||||
$endDate = now()->setTime(8, 0, 0);
|
// $endDate = now()->setTime(8, 0, 0);
|
||||||
$groupBy = "EXTRACT(HOUR FROM created_at)";
|
// $groupBy = "EXTRACT(HOUR FROM created_at)";
|
||||||
}
|
// }
|
||||||
else if ($activeFilter == 'this_week')
|
// else if ($activeFilter == 'this_week')
|
||||||
{
|
// {
|
||||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
// $startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
// $endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||||
$groupBy = "EXTRACT(DOW FROM created_at)";
|
// $groupBy = "EXTRACT(DOW FROM created_at)";
|
||||||
}
|
// }
|
||||||
else if ($activeFilter == 'this_month')
|
// else if ($activeFilter == 'this_month')
|
||||||
{
|
// {
|
||||||
$startDate = now()->startOfMonth();
|
// $startDate = now()->startOfMonth();
|
||||||
$endDate = now()->endOfMonth();
|
// $endDate = now()->endOfMonth();
|
||||||
$groupBy = "FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1";
|
// $groupBy = "FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1";
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
$startDate = now()->setTime(8, 0, 0);
|
// $startDate = now()->setTime(8, 0, 0);
|
||||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
// $endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||||
$groupBy = "EXTRACT(HOUR FROM created_at)";
|
// $groupBy = "EXTRACT(HOUR FROM created_at)";
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Get process orders for selected plant and line
|
// // Get process orders for selected plant and line
|
||||||
$processOrders = DB::table('process_orders')
|
// $processOrders = DB::table('process_orders')
|
||||||
->select('process_order')
|
// ->select('process_order')
|
||||||
->where('plant_id', $selectedPlant)
|
// ->where('plant_id', $selectedPlant)
|
||||||
->where('line_id', $selectedLine)
|
// ->where('line_id', $selectedLine)
|
||||||
->distinct();
|
// ->distinct();
|
||||||
|
|
||||||
// Get OK and Not OK counts against each process order
|
// // Get OK and Not OK counts against each process order
|
||||||
$records = CharacteristicValue::query()
|
// $records = CharacteristicValue::query()
|
||||||
->where('plant_id', $selectedPlant)
|
// ->where('plant_id', $selectedPlant)
|
||||||
->whereIn('process_order', $processOrders)
|
// ->whereIn('process_order', $processOrders)
|
||||||
->where('created_at', '>=', $startDate)
|
// ->where('created_at', '>=', $startDate)
|
||||||
->where('created_at', '<', $endDate)
|
// ->where('created_at', '<', $endDate)
|
||||||
->selectRaw("
|
// ->selectRaw("
|
||||||
process_order,
|
// process_order,
|
||||||
SUM(CASE WHEN status = 'Ok' THEN 1 ELSE 0 END) as ok_count,
|
// 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
|
// SUM(CASE WHEN status = 'NotOk' THEN 1 ELSE 0 END) as not_ok_count
|
||||||
")
|
// ")
|
||||||
->groupBy('process_order')
|
// ->groupBy('process_order')
|
||||||
->orderBy('process_order')
|
// ->orderBy('process_order')
|
||||||
->get();
|
// ->get();
|
||||||
|
|
||||||
return [
|
// return [
|
||||||
'datasets' => [
|
// 'datasets' => [
|
||||||
[
|
// [
|
||||||
'label' => 'OK',
|
// 'label' => 'OK',
|
||||||
'data' => $records->pluck('ok_count')
|
// 'data' => $records->pluck('ok_count')
|
||||||
->map(fn ($v) => (int) $v)
|
// ->map(fn ($v) => (int) $v)
|
||||||
->toArray(),
|
// ->toArray(),
|
||||||
'backgroundColor' => '#16A34A',
|
// 'backgroundColor' => '#16A34A',
|
||||||
],
|
// ],
|
||||||
[
|
// [
|
||||||
'label' => 'Not OK',
|
// 'label' => 'Not OK',
|
||||||
'data' => $records->pluck('not_ok_count')
|
// 'data' => $records->pluck('not_ok_count')
|
||||||
->map(fn ($v) => (int) $v)
|
// ->map(fn ($v) => (int) $v)
|
||||||
->toArray(),
|
// ->toArray(),
|
||||||
'backgroundColor' => '#DC2626',
|
// 'backgroundColor' => '#DC2626',
|
||||||
],
|
// ],
|
||||||
],
|
// ],
|
||||||
|
|
||||||
'labels' => $records->pluck('process_order')->toArray(),
|
// 'labels' => $records->pluck('process_order')->toArray(),
|
||||||
];
|
// ];
|
||||||
|
|
||||||
// $records = CharacteristicValue::query()
|
// $records = CharacteristicValue::query()
|
||||||
// ->selectRaw("
|
// ->selectRaw("
|
||||||
@@ -125,6 +125,76 @@ class ProcessOrderChart extends ChartWidget
|
|||||||
|
|
||||||
// 'labels' => $records->pluck('process_order')->toArray(),
|
// '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
|
protected function getType(): string
|
||||||
|
|||||||
Reference in New Issue
Block a user