diff --git a/app/Filament/Widgets/ItemOverview.php b/app/Filament/Widgets/ItemOverview.php index 629af503..adf9a3bb 100644 --- a/app/Filament/Widgets/ItemOverview.php +++ b/app/Filament/Widgets/ItemOverview.php @@ -13,6 +13,8 @@ class ItemOverview extends ChartWidget { protected static ?string $heading = 'Hourly Production'; + public ?string $filter = 'today'; + protected int|string|array $columnSpan = '12'; protected static ?string $maxHeight = '400px'; @@ -150,6 +152,8 @@ class ItemOverview extends ChartWidget // $planQuantity // ); + $planData = []; + if ($activeFilter === 'today') { $monthlyPlanQuantity = \DB::table('production_plans') @@ -159,18 +163,16 @@ class ItemOverview extends ChartWidget ->whereMonth('created_at', $startDate->month) ->sum('plan_quantity'); - // Calculate daily target directly - $weeksCount = (int) ceil($startDate->daysInMonth / 7); + $weeksCount = (int) ceil(now()->daysInMonth / 7); $dailyPlan = $weeksCount > 0 ? round($monthlyPlanQuantity / ($weeksCount * 7), 2) : 0; - // Calculate hourly target $hourlyPlan = round($dailyPlan / 22.5, 2); - // Same hourly plan value for every hour - $planData = array_fill(0, 24, $hourlyPlan); + $planData = array_fill(0, count($orderedData), $hourlyPlan); + } if ($activeFilter === 'yesterday') { @@ -240,14 +242,7 @@ class ItemOverview extends ChartWidget // Monday through Sunday $planData = array_fill(0, 7, $dailyPlan); } - else { - // This Week: each day's production / 22.5 - // This Month: each week's production / 22.5 - $planData = array_map( - fn ($quantity) => round($quantity / 22.5, 2), - $orderedData - ); - } + return [ 'datasets' => [