diff --git a/app/Filament/Widgets/ItemOverview.php b/app/Filament/Widgets/ItemOverview.php index 0a30cf7d..7143f1f1 100644 --- a/app/Filament/Widgets/ItemOverview.php +++ b/app/Filament/Widgets/ItemOverview.php @@ -161,12 +161,19 @@ class ItemOverview extends ChartWidget } elseif ($activeFilter === 'this_month') { - $monthlyPlan = round(array_sum($orderedData) / 22.5, 2); + $monthlyPlanQuantity = \DB::table('production_plans') + ->where('plant_id', $selectedPlant) + ->where('line_id', $selectedLine) + ->whereYear('created_at', $startDate->year) + ->whereMonth('created_at', $startDate->month) + ->sum('plan_quantity'); + // Number of weeks in the current month $weeksCount = count($orderedData); + // Split the total monthly plan equally across all weeks $weeklyPlan = $weeksCount > 0 - ? round($monthlyPlan / $weeksCount, 2) + ? round($monthlyPlanQuantity / $weeksCount, 2) : 0; $planData = array_fill(