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 $listeners = ['cumulativeChart'];
|
||||
//protected $listeners = ['cumulativeChart'];
|
||||
|
||||
protected static ?string $maxHeight = '400px';
|
||||
|
||||
@@ -85,25 +85,50 @@ class CumulativeChart extends ChartWidget
|
||||
{
|
||||
$selectedPlant = session('selected_plant');
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
// 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':
|
||||
$startDate = now()->subDay()->startOfDay();
|
||||
$endDate = now()->subDay()->endOfDay();
|
||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||
$endDate = now()->setTime(8, 0, 0);
|
||||
$groupBy = 'EXTRACT(HOUR FROM created_at)';
|
||||
break;
|
||||
|
||||
case 'this_week':
|
||||
$startDate = now()->startOfWeek();
|
||||
$endDate = now()->endOfWeek();
|
||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'EXTRACT(DOW FROM created_at)';
|
||||
break;
|
||||
|
||||
case 'this_month':
|
||||
$startDate = now()->startOfMonth();
|
||||
$endDate = now()->endOfMonth();
|
||||
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
||||
$endDate = now()->endOfMonth()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = "FLOOR((EXTRACT(DAY FROM created_at) - 1) / 7) + 1";
|
||||
break;
|
||||
|
||||
default: // today
|
||||
$startDate = now()->startOfDay();
|
||||
$endDate = now()->endOfDay();
|
||||
$startDate = now()->setTime(8, 0, 0);
|
||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
||||
$groupBy = 'EXTRACT(HOUR FROM created_at)';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -130,12 +155,17 @@ class CumulativeChart extends ChartWidget
|
||||
|
||||
//FG production from quality_validations
|
||||
$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)
|
||||
->groupBy('line_id')
|
||||
->groupByRaw($groupBy)
|
||||
->orderByRaw($groupBy)
|
||||
->pluck('total_quantity', 'line_id')
|
||||
->toArray();
|
||||
|
||||
|
||||
//Non-FG production from production_quantities
|
||||
$nonFgProduction = ProductionQuantity::select('line_id', \DB::raw('COUNT(*) as total_quantity'))
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
@@ -248,7 +278,6 @@ class CumulativeChart extends ChartWidget
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// public static function canView(): bool
|
||||
// {
|
||||
// return request()->routeIs([
|
||||
|
||||
Reference in New Issue
Block a user