From 17c0426dc4f261797c33b87cf9f16690e304d980 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Thu, 29 Oct 2026 11:06:36 +0530 Subject: [PATCH] changed logic in item overview --- app/Filament/Widgets/ItemOverview.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Filament/Widgets/ItemOverview.php b/app/Filament/Widgets/ItemOverview.php index ca69cd18..cca295bb 100644 --- a/app/Filament/Widgets/ItemOverview.php +++ b/app/Filament/Widgets/ItemOverview.php @@ -183,25 +183,27 @@ class ItemOverview extends ChartWidget ); } elseif ($activeFilter === 'this_week') { - $weeklyPlanQuantity = \DB::table('production_plans') + + // Get the total plan quantity for the current month + $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'); - $daysCount = count($orderedData); + // Number of calendar weeks in the current month + $weeksCount = (int) ceil($startDate->daysInMonth / 7); - $dailyPlan = $daysCount > 0 - ? round($weeklyPlanQuantity / $daysCount, 2) + // Monthly plan -> weekly plan -> daily plan + $weeklyPlan = $weeksCount > 0 + ? $monthlyPlanQuantity / $weeksCount : 0; - $planData = array_fill( - 0, - $daysCount, - $dailyPlan - ); + $dailyPlan = round($weeklyPlan / 7, 2); + // Monday through Sunday + $planData = array_fill(0, 7, $dailyPlan); } else { // This Week: each day's production / 22.5