diff --git a/app/Http/Controllers/Activity/FormKehutananController.php b/app/Http/Controllers/Activity/FormKehutananController.php index 147e27d..4b9d4cd 100644 --- a/app/Http/Controllers/Activity/FormKehutananController.php +++ b/app/Http/Controllers/Activity/FormKehutananController.php @@ -139,7 +139,7 @@ class FormKehutananController implements HasMiddleware // Retrieve data $data = $this->data($sector, $code, $inventoryYear, $instansi); - return view('form.index-kehutanan', $data); + return view('modules.form.index-kehutanan', $data); } public function import(Request $request, $inventoryYear, $instansi = null) diff --git a/app/Http/Controllers/Activity/LivestockManureController.php b/app/Http/Controllers/Activity/LivestockManureController.php index a8369a2..a1c39f0 100644 --- a/app/Http/Controllers/Activity/LivestockManureController.php +++ b/app/Http/Controllers/Activity/LivestockManureController.php @@ -13,6 +13,9 @@ use Illuminate\Routing\Controllers\Middleware; class LivestockManureController implements HasMiddleware { + protected $title = 'Jenis Pengelolaan Kotoran Ternak'; + protected $template = 'modules.form.livestock-manure'; + protected $route = 'modules.pertanian.kotoran-ternak'; protected $service; public function __construct(LivestockManureService $service) @@ -26,69 +29,62 @@ class LivestockManureController implements HasMiddleware //new Middleware('permission:/agriculture/kotoran_ternak'), ]; } - - public function index(Request $request) + public function grid() { - if ($request->ajax()) { - $data = $this->service->getAll(); + $_data = []; + $data = $this->service->getAll(); - $result = datatables()::of($data) - ->addColumn('no_baris', function ($lm) { - return $lm->row_num; - }) - ->addColumn('status', function ($lm) { - if ($lm->active_status == 1) { - return 'Aktif'; - } else { - return 'Tidak Aktif'; - } - }) - ->editColumn('ef_direct_n2o_n', function ($lm) { - if ($lm->ef_direct_n2o_n === 0) { - return 0; // Show 0 as is - } + foreach ($data as $key => $row) { - $output = getFormattedValue($lm->ef_direct_n2o_n, 2); - return $output; - }) - ->editColumn('ef_evaporation_n', function ($lm) { - if ($lm->ef_evaporation_n === 0) { - return 0; // Show 0 as is - } + $btn = 'Edit'; + $btn .= '
'; - $output = getFormattedValue($lm->ef_evaporation_n); - return $output; - }) - ->addColumn('action', function ($lm) { - $btn = 'Edit'; - $btn .= ' '; + } + + if ($row->active_status == 1) { + $status = 'Aktif'; + } else { + $status = 'Tidak Aktif'; + } + + $_data[] = [ + 'no' => $key+1, + 'no_baris' => @$row->row_num, + 'ef_direct_n2o_n' => $row->ef_direct_n2o_n === 0 ? 0 : getFormattedValue($row->ef_direct_n2o_n, 2), + 'ef_evaporation_n' => $row->ef_evaporation_n === 0 ? 0 : getFormattedValue($row->ef_evaporation_n), + 'name' => $row->name, + 'description' => $row->description, + 'status' => $status, + 'action' => @$btn, + ]; - if ($lm->active_status == 0) { - $btn .= ' '; - } - - return $btn; - }) - ->rawColumns(['no_baris', 'status', 'action']) - ->make(true); - - return $result; } - return view('form.livestock-manure.index'); + return response()->json($_data); + } + public function index(Request $request) + { + $data['route'] = $this->route; + $data['title'] = $this->title; + + return view($this->template.'.index',$data); } public function create() { - return view('form.livestock-manure.create'); + $data['route'] = $this->route; + $data['title'] = $this->title; + return view($this->template.'.create',$data); } public function store(Request $request) @@ -111,7 +107,7 @@ class LivestockManureController implements HasMiddleware ]); $this->service->create($data); - return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil ditambahkan.'); + return redirect()->route($this->route.'.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil ditambahkan.'); } catch (\Exception $e) { return back()->withErrors(['error' => 'Jenis Pengelolaan Kotoran Ternak gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]); } @@ -119,8 +115,10 @@ class LivestockManureController implements HasMiddleware public function edit($id) { - $lm = $this->service->find($id); - return view('form.livestock-manure.edit', compact('lm')); + $data['lm'] = $this->service->find($id); + $data['route'] = $this->route; + $data['title'] = $this->title; + return view($this->template.'.edit', $data); } public function update(Request $request, LivestockManure $kotoran_ternak) @@ -130,7 +128,7 @@ class LivestockManureController implements HasMiddleware // 'required', // 'string', // 'max:255', - // new UniqueInSchema('activity', 'livestock_manure', 'code', $lm->id), + // new UniqueInSchema('activity', 'livestock_manure', 'code', $row->id), // ], 'name' => 'required|string|max:255', 'ef_direct_n2o_n' => 'nullable', @@ -149,7 +147,7 @@ class LivestockManureController implements HasMiddleware $this->service->update($kotoran_ternak, $data); - return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil diperbarui.'); + return redirect()->route($this->route.'.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil diperbarui.'); } catch (\Exception $e) { return back()->withErrors(['error' => 'Jenis Pengelolaan Kotoran Ternak gagal diperbarui. Silakan coba lagi. Error: ' . $e->getMessage()]); } @@ -166,7 +164,7 @@ class LivestockManureController implements HasMiddleware $record->save(); } - return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil dihapus.'); + return redirect()->route($this->route.'.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil dihapus.'); } catch (\Exception $e) { return back()->withErrors(['error' => 'Jenis Pengelolaan Kotoran Ternak gagal dihapus. Silakan coba lagi. Error: ' . $e->getMessage()]); } @@ -176,7 +174,7 @@ class LivestockManureController implements HasMiddleware { try { $this->service->setAktif($id); - return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil diaktifkan.'); + return redirect()->route($this->route.'.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil diaktifkan.'); } catch (\Exception $e) { return back()->withErrors(['error' => 'Gagal mengaktifkan Jenis Pengelolaan Kotoran Ternak. Silakan coba lagi. Error: ' . $e->getMessage()]); } diff --git a/resources/views/modules/form/index-kehutanan.blade.php b/resources/views/modules/form/index-kehutanan.blade.php index cf9602f..a1e34a7 100644 --- a/resources/views/modules/form/index-kehutanan.blade.php +++ b/resources/views/modules/form/index-kehutanan.blade.php @@ -19,10 +19,10 @@ 'instansi' => $instansi, ]; - $routeImport = route('folu.import', $param); - $routeExport = route('folu.export', $param); - $routeExportTemplate = route('folu.export', array_merge($param, ['isTemplate' => true])); - $routeApproval = route('folu.approval', $param); + $routeImport = route('modules.folu.import', $param); + $routeExport = route('modules.folu.export', $param); + $routeExportTemplate = route('modules.folu.export', array_merge($param, ['isTemplate' => true])); + $routeApproval = route('modules.folu.approval', $param); $internal = $internal ?? null; $limitInternal = $internal !== null && !$agencies->isNotEmpty(); @@ -33,54 +33,19 @@