lockService = $lockService; } public static function middleware(): array { return [ //new Middleware('permission:/tool/lock_activity'), ]; } public function index(Request $request) { if ($request->ajax()) { $locks = $this->lockService->getAll(); $result = datatables()->of($locks) ->editColumn('updated_at', function ($row) { return $row->created_at->format('d-m-Y H:i:s') ?? ''; }) ->addColumn('status', function ($row) { if ($row->lock_status == 'locked') { return 'LOCKED'; } else { return 'OPEN'; } }) ->addColumn('action', function ($row) { $buttonStyle = 'style="min-width: 120px;"'; // Adjust min-width as needed $action = $row->lock_status == 'locked' ? '
' . csrf_field() . '' . '' . '
' : '
' . csrf_field() . '' . '' . '
'; return $action; }) ->rawColumns(['status', 'action']) ->make(true); return $result; } return view('tool.lock.index'); } 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.']); } } }