diff --git a/app/Filament/Widgets/ItemOverview.php b/app/Filament/Widgets/ItemOverview.php index 9c8e9e37..357aa363 100644 --- a/app/Filament/Widgets/ItemOverview.php +++ b/app/Filament/Widgets/ItemOverview.php @@ -151,13 +151,31 @@ class ItemOverview extends ChartWidget // ); if (in_array($activeFilter, ['today', 'yesterday'])) { - $planQuantity = round(array_sum($orderedData) / 22.5, 2); + + // Get total monthly plan quantity + $monthlyPlanQuantity = \DB::table('YOUR_ACTUAL_PLAN_TABLE') + ->where('plant_id', $selectedPlant) + ->where('line_id', $selectedLine) + ->whereYear('created_at', $startDate->year) + ->whereMonth('created_at', $startDate->month) + ->sum('plan_quantity'); + + $weeksCount = (int) ceil($startDate->daysInMonth / 7); + + $weeklyPlan = $weeksCount > 0 + ? $monthlyPlanQuantity / $weeksCount + : 0; + + $dailyPlan = $weeklyPlan / 7; + + $hourlyPlan = round($dailyPlan / 22.5, 2); $planData = array_fill( 0, count($orderedData), - $planQuantity + $hourlyPlan ); + } elseif ($activeFilter === 'this_month') {