user()->can('shopfloor.oee.view')) { abort(403); } $business_id = $request->session()->get('user.business_id'); $date = $request->input('date', now()->toDateString()); $snapshots = OeeSnapshot::forBusiness($business_id) ->with('workCenter') ->where('snapshot_date', $date) ->orderBy('work_center_id') ->get(); if ($snapshots->isEmpty()) { $oeeService->calculateAllForDate($business_id, Carbon::parse($date)); $snapshots = OeeSnapshot::forBusiness($business_id) ->with('workCenter') ->where('snapshot_date', $date) ->orderBy('work_center_id') ->get(); } $workCenters = WorkCenter::forBusiness($business_id)->orderBy('name')->pluck('name', 'id'); return view('shopfloor::oee.index', compact('snapshots', 'date', 'workCenters')); } public function calculate(Request $request, OeeCalculationService $oeeService) { if (! auth()->user()->can('shopfloor.oee.view')) { abort(403); } $business_id = $request->session()->get('user.business_id'); $validated = $request->validate([ 'date' => 'nullable|date', 'work_center_id' => 'nullable|integer|exists:sf_work_centers,id', ]); $date = Carbon::parse($validated['date'] ?? now()->toDateString()); if (! empty($validated['work_center_id'])) { $oeeService->calculateForWorkCenter($business_id, (int) $validated['work_center_id'], $date); } else { $oeeService->calculateAllForDate($business_id, $date); } return redirect() ->action([self::class, 'index'], ['date' => $date->toDateString()]) ->with('status', ['success' => 1, 'msg' => __('shopfloor::lang.oee_calculated')]); } }