solved total count issue in cumulative chart
This commit is contained in:
@@ -12,7 +12,7 @@ class CumulativeChart extends ChartWidget
|
|||||||
{
|
{
|
||||||
protected static ?string $heading = 'Production Line Count';
|
protected static ?string $heading = 'Production Line Count';
|
||||||
|
|
||||||
protected $listeners = ['cumulativeChart'];
|
//protected $listeners = ['cumulativeChart'];
|
||||||
|
|
||||||
protected static ?string $maxHeight = '400px';
|
protected static ?string $maxHeight = '400px';
|
||||||
|
|
||||||
@@ -85,25 +85,50 @@ class CumulativeChart extends ChartWidget
|
|||||||
{
|
{
|
||||||
$selectedPlant = session('selected_plant');
|
$selectedPlant = session('selected_plant');
|
||||||
$activeFilter = $this->filter;
|
$activeFilter = $this->filter;
|
||||||
|
|
||||||
// Define date range
|
// Define date range
|
||||||
switch ($activeFilter)
|
// switch ($activeFilter)
|
||||||
{
|
// {
|
||||||
|
// case 'yesterday':
|
||||||
|
// $startDate = now()->subDay()->startOfDay();
|
||||||
|
// $endDate = now()->subDay()->endOfDay();
|
||||||
|
// break;
|
||||||
|
// case 'this_week':
|
||||||
|
// $startDate = now()->startOfWeek();
|
||||||
|
// $endDate = now()->endOfWeek();
|
||||||
|
// break;
|
||||||
|
// case 'this_month':
|
||||||
|
// $startDate = now()->startOfMonth();
|
||||||
|
// $endDate = now()->endOfMonth();
|
||||||
|
// break;
|
||||||
|
// default: // today
|
||||||
|
// $startDate = now()->startOfDay();
|
||||||
|
// $endDate = now()->endOfDay();
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// Define date range with 8 AM shift boundaries
|
||||||
|
switch ($activeFilter) {
|
||||||
case 'yesterday':
|
case 'yesterday':
|
||||||
$startDate = now()->subDay()->startOfDay();
|
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||||
$endDate = now()->subDay()->endOfDay();
|
$endDate = now()->setTime(8, 0, 0);
|
||||||
|
$groupBy = 'EXTRACT(HOUR FROM created_at)';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'this_week':
|
case 'this_week':
|
||||||
$startDate = now()->startOfWeek();
|
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||||
$endDate = now()->endOfWeek();
|
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||||
|
$groupBy = 'EXTRACT(DOW FROM created_at)';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'this_month':
|
case 'this_month':
|
||||||
$startDate = now()->startOfMonth();
|
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||||
$endDate = now()->endOfMonth();
|
$endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||||
|
$groupBy = "FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // today
|
default: // today
|
||||||
$startDate = now()->startOfDay();
|
$startDate = now()->setTime(8, 0, 0);
|
||||||
$endDate = now()->endOfDay();
|
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||||
|
$groupBy = 'EXTRACT(HOUR FROM created_at)';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,12 +155,17 @@ class CumulativeChart extends ChartWidget
|
|||||||
|
|
||||||
//FG production from quality_validations
|
//FG production from quality_validations
|
||||||
$fgProduction = QualityValidation::select('line_id', \DB::raw('COUNT(*) as total_quantity'))
|
$fgProduction = QualityValidation::select('line_id', \DB::raw('COUNT(*) as total_quantity'))
|
||||||
->whereBetween('created_at', [$startDate, $endDate])
|
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||||
|
->where('created_at', '>=', $startDate)
|
||||||
|
->where('created_at', '<', $endDate)
|
||||||
->whereIn('line_id', $fgLineIds)
|
->whereIn('line_id', $fgLineIds)
|
||||||
->groupBy('line_id')
|
->groupBy('line_id')
|
||||||
|
->groupByRaw($groupBy)
|
||||||
|
->orderByRaw($groupBy)
|
||||||
->pluck('total_quantity', 'line_id')
|
->pluck('total_quantity', 'line_id')
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
|
|
||||||
//Non-FG production from production_quantities
|
//Non-FG production from production_quantities
|
||||||
$nonFgProduction = ProductionQuantity::select('line_id', \DB::raw('COUNT(*) as total_quantity'))
|
$nonFgProduction = ProductionQuantity::select('line_id', \DB::raw('COUNT(*) as total_quantity'))
|
||||||
->whereBetween('created_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
@@ -248,7 +278,6 @@ class CumulativeChart extends ChartWidget
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static function canView(): bool
|
// public static function canView(): bool
|
||||||
// {
|
// {
|
||||||
// return request()->routeIs([
|
// return request()->routeIs([
|
||||||
|
|||||||
Reference in New Issue
Block a user