lockService = $lockService; } public static function middleware(): array { return [ //new Middleware('permission:/tool/lock_activity'), ]; } public function index(Request $request) { $data['route'] = $this->route; $data['title'] = $this->title; return view($this->template.'.index',$data); } public function lock(Request $request) { // Validate the input data $request->validate([ 'year' => 'required|integer|min:2000|max:' . date('Y'), 'copy_activity' => 'nullable|in:yes,no' ]); try { if ($request->copy_activity === 'yes') { $this->lockService->copyActivityToNextYear($request->year); } $this->lockService->lock($request->year); return redirect()->back()->with('success', 'Tahun Inventory ' . $request->year . ' berhasil dikunci' . ($request->copy_activity === 'ya' ? ' dan data aktivitas berhasil disalin ke tahun berikutnya' : '')); } catch (\Exception $e) { return redirect()->back()->withErrors(['error' => 'Tahun Inventory ' . $request->year . ' gagal dikunci. Mohon dicoba kembali.']); } } public function unlock(Request $request) { $request->validate([ 'year' => 'required|integer|min:2000|max:' . date('Y'), ]); try { $this->lockService->unlock($request->year); return redirect()->back()->with('success', 'Tahun Inventory ' . $request->year . ' berhasil dibuka'); } catch (\Exception $e) { return redirect()->back()->withErrors(['error' => 'Tahun Inventory ' . $request->year . 'gagal dibuka. Mohon dicoba kembali.']); } } public function grid(Request $request) { $_data = []; $data = $this->lockService->getAll(); foreach ($data as $key => $row) { if ($row->lock_status == 'locked') { $status = 'LOCKED'; } else { $status = 'OPEN'; } $buttonStyle = 'style="min-width: 120px;"'; // Adjust min-width as needed $action = $row->lock_status == 'locked' ? '
' . csrf_field() . '' . '' . '
' : '
' . csrf_field() . '' . '' . '
'; $_data[] = [ 'no' => $key+1, 'inventory_year' => $row->inventory_year, 'status' => $status, 'executed_time' => @$row->created_at ? date('d-m-Y H:i:s', strtotime(@$row->created_at)) : '', 'action' => $action, ]; } return response()->json($_data); } }