findOrFail($id); $surveyor = $id; $branches = Branch::all(); $provinces = Province::all(); $bentukTanah = BentukTanah::all(); $konturTanah = KonturTanah::all(); $posisiKavling = PosisiKavling::all(); $ketinggianTanah = KetinggianTanah::all(); $kondisiFisikTanah = KondisiFisikTanah::all(); $jenisBangunan = JenisBangunan::all(); $kondisiBangunan = KondisiBangunan::all(); $sifatBangunan = SifatBangunan::all(); $spekKategoriBagunan = SpekKategoritBangunan::all(); $spekBangunan = SpekBangunan::all(); $saranaPelengkap = SaranaPelengkap::all(); $arahMataAngin = ArahMataAngin::all(); $jenisJaminanIds = $permohonan->debiture->documents; $buttonDisable = false; foreach ($jenisJaminanIds as $jenisJaminanId) { $denah = Denah::where('permohonan_id', $id) ->where('jenis_jaminan_id', $jenisJaminanId->jenis_jaminan_id) ->first(); $fotojaminan = FotoJaminan::where('permohonan_id', $id) ->where('jenis_jaminan_id', $jenisJaminanId->jenis_jaminan_id) ->first(); $analisa = Analisa::where('permohonan_id', $id) ->where('jenis_jaminan_id', $jenisJaminanId->jenis_jaminan_id) ->first(); // cek jika tidak ada if (!$denah || !$fotojaminan || !$analisa) { $buttonDisable = true; break; } } $denah = Denah::where('permohonan_id', $id)->get(); $fotojaminan = FotoJaminan::where('permohonan_id', $id)->get(); $analisa = Analisa::with('analisaUnit', 'analisaTanahBangunan', 'analisaLingkungan', 'analisaFakta', 'jenisJaminan') ->where('permohonan_id', $id) ->get(); return view('lpj::surveyor.detail', compact( 'buttonDisable', 'fotojaminan', 'denah', 'analisa', 'permohonan', 'surveyor', 'branches', 'provinces', 'bentukTanah', 'konturTanah', 'posisiKavling', 'kondisiFisikTanah', 'ketinggianTanah', 'kondisiBangunan', 'jenisBangunan', 'sifatBangunan', 'spekKategoriBagunan', 'spekBangunan', 'saranaPelengkap', 'arahMataAngin' )); } /** * Store form inspeksi. */ public function store(FormSurveyorRequest $request) { $validatedData = $request->validated(); DB::beginTransaction(); try { $analisa = Analisa::create($validatedData); if ($analisa) { $validatedData['analisa_id'] = $analisa->id; switch ($validatedData['action']) { case 'tanah_bangunan': $this->handleTanahBangunan($validatedData, $request); break; case 'unit': $this->handleUnit($validatedData); break; default: throw new \Exception('Invalid action type'); } AnalisaLingkungan::create($validatedData); $validatedData['foto_tempat'] = $this->uploadFile($request->file('foto_tempat'), 'foto_tempat'); AnalisaFakta::create($validatedData); } DB::commit(); return redirect()->route('surveyor.show', [ 'id' => $validatedData['permohonan_id'], 'form' => 'inspeksi' ])->with('success', 'Data form surveyor berhasil disimpan'); } catch (Exception $e) { DB::rollback(); return response()->json(['error' => 'Failed to save data', 'details' => $e->getMessage()], 500); } } private function handleTanahBangunan(array $validatedData, FormSurveyorRequest $request) { $analisaTanahBangunan = AnalisaTanahBagunan::create($validatedData); if ($analisaTanahBangunan) { $this->createSpekBangunanAnalisa($request, $analisaTanahBangunan); } } private function handleUnit(array $validatedData) { AnalisaUnit::create($validatedData); } private function createSpekBangunanAnalisa($request, $analisaTanahBangunan) { foreach ($request->input('kategori', []) as $spek) { $spek['analisa_tanah_bangunan_id'] = $analisaTanahBangunan->id; $spekBangunan = SpekBangunanAnalisa::create($spek); if ($spekBangunan) { $this->createSpekBangunanAnalisaDetails($request, $spekBangunan); } } } private function createSpekBangunanAnalisaDetails($request, $spekBangunan) { foreach ($request->input('name', []) as $detail) { $detail['spek_bangunan_analisa_id'] = $spekBangunan->id; SpekBagunanAnalisaDetail::create($detail); } } public function storeDenah(Request $request) { try { $validatedData = $request->validate([ 'foto_denah' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'luas' => 'required|numeric', 'permohonan_id' => 'required', 'jenis_jaminan_id' => 'required' ]); $validatedData['foto_denah'] = $this->uploadFile($request->file('foto_denah'), 'foto_denah'); Denah::create($validatedData); return redirect()->route('surveyor.show', [ 'id' => $validatedData['permohonan_id'], 'form' => 'denah' ])->with('success', 'Data foto berhasil disimpan'); } catch (Exception $e) { $failureRedirectUrl = route('surveyor.denah', [ 'id' => $validatedData['permohonan_id'], 'jenis_jaminan_id' => $validatedData['jenis_jaminan_id'] ]); $failureRedirectUrl .= '?form=create-denah&denah=' . $validatedData['permohonan_id'] . '&jenis_jaminan=' . $validatedData['jenis_jaminan_id']; return redirect($failureRedirectUrl) ->withInput() ->with(['error' => 'Gagal menyimpan data: ' . $e->getMessage()]); } } public function storeFoto(Request $request) { $validatedData = $request->validate([ 'permohonan_id' => 'required', 'jenis_jaminan_id' => 'required', 'analisa_type' => 'required|in:tanah_bangunan,unit', 'pendamping' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'foto_objek.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'name_objek.*' => 'required|string|max:255', 'foto_lingkungan.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'name_lingkungan.*' => 'required|string|max:255', 'foto_rute.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'name_rute.*' => 'required|string|max:255', 'lantai.*' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'name_lantai_unit.*' => 'nullable|string|max:255', 'foto_lantai_unit.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', ]); DB::beginTransaction(); try { $pendampingPath = $this->uploadFile($request->file('pendamping'), 'pendamping'); $fotojaminan = FotoJaminan::create([ 'pendamping' => $pendampingPath, 'permohonan_id' => $validatedData['permohonan_id'], 'jenis_jaminan_id' => $validatedData['jenis_jaminan_id'], ]); $this->processObjekUploads($request, $fotojaminan); $this->processLantaiUnitUploads($request, $fotojaminan); $this->processUploads('rute', $request, $fotojaminan); $this->processUploads('lingkungan', $request, $fotojaminan); DB::commit(); return redirect()->route('surveyor.show', [ 'id' => $validatedData['permohonan_id'], 'form' => 'foto' ])->with('success', 'Data foto berhasil disimpan'); } catch (Exception $e) { DB::rollBack(); return response()->json(['success' => false, 'message' => 'Failed to upload: ' . $e->getMessage()], 500); } } public function update(FormSurveyorRequest $request, $id) { $validatedData = $request->validated(); DB::beginTransaction(); try { // Update Analisa entity $analisa = Analisa::findOrFail($id); $analisa->update($validatedData); if ($analisa) { $validatedData['analisa_id'] = $analisa->id; $analisaTanahBangunan = AnalisaTanahBagunan::where('analisa_id', $analisa->id)->firstOrFail(); $analisaTanahBangunan->update($validatedData); if ($analisaTanahBangunan) { $this->updateSpekBangunanAnalisa($request, $analisaTanahBangunan); } $analisaLingkungan = AnalisaLingkungan::where('analisa_id', $analisa->id)->firstOrFail(); $analisaLingkungan->update($validatedData); if ($request->hasFile('foto_tempat')) { $validatedData['foto_tempat'] = $this->uploadFile($request->file('foto_tempat'), 'foto_tempat'); } $analisaFakta = AnalisaFakta::where('analisa_id', $analisa->id)->firstOrFail(); $analisaFakta->update($validatedData); } DB::commit(); return redirect()->route('surveyor.show', [ 'id' => $validatedData['permohonan_id'], 'form' => 'inspeksi' ])->with('success', 'Data form surveyor berhasil diperbarui'); } catch (Exception $e) { DB::rollback(); return response()->json(['error' => 'Failed to update data', 'details' => $e->getMessage()], 500); } } private function updateSpekBangunanAnalisa($request, $analisaTanahBangunan) { SpekBangunanAnalisa::where('analisa_tanah_bangunan_id', $analisaTanahBangunan->id)->delete(); foreach ($request->input('kategori', []) as $spek) { $spek['analisa_tanah_bangunan_id'] = $analisaTanahBangunan->id; $spekBangunan = SpekBangunanAnalisa::create($spek); if ($spekBangunan) { $this->updateSpekBangunanAnalisaDetails($request, $spekBangunan); } } } private function updateSpekBangunanAnalisaDetails($request, $spekBangunan) { // Delete existing SpekBagunanAnalisaDetail records SpekBagunanAnalisaDetail::where('spek_bangunan_analisa_id', $spekBangunan->id)->delete(); // Create new SpekBagunanAnalisaDetail records foreach ($request->input('name', []) as $detail) { $detail['spek_bangunan_analisa_id'] = $spekBangunan->id; SpekBagunanAnalisaDetail::create($detail); } } public function updateDenah(Request $request, $id): RedirectResponse { } private function processObjekUploads(Request $request, FotoJaminan $fotojaminan) { $fotoObjek = $request->file('foto_objek'); $nameObjek = $request->input('name_objek'); $analisaType = $request->input('analisa_type'); // Tambahkan input untuk tipe analisa if (!is_array($fotoObjek) || !is_array($nameObjek) || count($fotoObjek) !== count($nameObjek)) { throw new Exception("Mismatched foto_objek and name_objek inputs"); } // Definisikan labels berdasarkan tipe analisa $objekLabels = []; if ($analisaType === 'tanah_bangunan') { $objekLabels = [ 'Tampak Samping Kiri', 'Tampak Samping Kanan', 'Nomor Rumah/Unit' ]; } elseif ($analisaType === 'unit') { $objekLabels = [ 'Tampak Loby', 'Tampak Lift', 'Tampak Samping Kiri Unit', 'Tampak Samping Kanan Unit', 'Tampak Depan Unit', 'Nomor Unit' ]; } foreach ($fotoObjek as $index => $foto) { if (!isset($nameObjek[$index])) { throw new Exception("Missing description for foto_objek at index {$index}"); } // Pastikan index ada dalam objekLabels $label = isset($objekLabels[$index]) ? $objekLabels[$index] : "Foto {$index}"; $path = $this->uploadFile($foto, 'objek'); ObjekJaminan::create([ 'foto_jaminan_id' => $fotojaminan->id, 'name_objek' => $label . ': ' . $nameObjek[$index], 'foto_objek' => $path, ]); } } private function processUploads($type, Request $request, FotoJaminan $fotojaminan) { $files = $request->file("foto_{$type}"); $names = $request->input("name_{$type}"); if (!is_array($files) || !is_array($names) || count($files) !== count($names)) { throw new Exception("Mismatched foto_{$type} and name_{$type} inputs"); } foreach ($files as $index => $file) { if (!isset($names[$index])) { throw new Exception("Missing description for {$type} at index {$index}"); } $path = $this->uploadFile($file, $type); $data = [ 'foto_jaminan_id' => $fotojaminan->id, "name_{$type}" => $names[$index], "foto_{$type}" => $path, ]; switch ($type) { case 'rute': RuteJaminan::create($data); break; case 'lingkungan': Lingkungan::create($data); break; } } } private function processLantaiUnitUploads(Request $request, FotoJaminan $fotojaminan) { $lantaiFiles = $request->file('foto_lantai_unit'); $lantaiNames = $request->input('name_lantai_unit'); if (!$lantaiFiles) { return; } if (!is_array($lantaiFiles) || !is_array($lantaiNames) || count($lantaiFiles) !== count($lantaiNames)) { throw new Exception("Mismatched foto_lantai_unit and name_lantai_unit inputs"); } foreach ($lantaiFiles as $index => $file) { $path = $this->uploadFile($file, 'lantai'); LantaiUnit::create([ 'objek_jaminan_id' => $fotojaminan->id, 'name_lantai_unit' => "Lantai " . ($index + 1), 'foto_lantai_unit' => $path, ]); } } private function uploadFile($file, $type) { if (!$file->isValid()) { throw new Exception("Invalid file upload for {$type}"); } $fileName = time() . '_' . $file->getClientOriginalName(); $path = $file->storeAs("public/surveyor/{$type}", $fileName); if ($path === false) { throw new Exception("Failed to store file for {$type}"); } return str_replace('public/', '', $path); } public function dataForDatatables(Request $request) { if (is_null($this->user) || !$this->user->can('debitur.view')) { // abort(403, 'Sorry! You are not allowed to view users.'); } $query = Permohonan::query(); if ($request->has('search') && !empty($request->get('search'))) { $search = $request->get('search'); $query->where(function ($q) use ($search) { $q->where('nomor_registrasi', 'LIKE', '%' . $search . '%'); $q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%'); $q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%'); $q->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%'); $q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%'); $q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%'); $q->orWhere('status', 'LIKE', '%' . $search . '%'); }); } $query->whereRaw('LOWER(status) = ?', ['assign']); $query->whereHas('region.teams.teamsUsers.user', function ($q) { $q->where('id', Auth::user()->id); }); if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) { $order = $request->get('sortOrder'); $column = $request->get('sortField'); $query->orderBy($column, $order); } $totalRecords = $query->count(); $size = $request->get('size', 10); if ($size == 0) { $size = 10; } if ($request->has('page') && $request->has('size')) { $page = $request->get('page', 1); $offset = ($page - 1) * $size; $query->skip($offset)->take($size); } $filteredRecords = $query->count(); $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian', 'jenisFasilitasKredit'])->get(); $pageCount = ceil($totalRecords / $size); $currentPage = max(1, $request->get('page', 1)); return response()->json([ 'draw' => $request->get('draw'), 'recordsTotal' => $totalRecords, 'recordsFiltered' => $filteredRecords, 'pageCount' => $pageCount, 'page' => $currentPage, 'totalCount' => $totalRecords, 'data' => $data, ]); } /** * Form inspeksi. */ public function formInspeksi($id, $jaminanId) { $permohonan = $this->getPermohonanJaminanId($id, $jaminanId); $branches = Branch::all(); $provinces = Province::all(); $surveyor = $id; $branches = Branch::all(); $provinces = Province::all(); $bentukTanah = BentukTanah::all(); $konturTanah = KonturTanah::all(); $posisiKavling = PosisiKavling::all(); $ketinggianTanah = KetinggianTanah::all(); $kondisiFisikTanah = KondisiFisikTanah::all(); $jenisBangunan = JenisBangunan::all(); $kondisiBangunan = KondisiBangunan::all(); $sifatBangunan = SifatBangunan::all(); $spekKategoriBagunan = SpekKategoritBangunan::all(); $spekBangunan = SpekBangunan::all(); $saranaPelengkap = SaranaPelengkap::all(); $arahMataAngin = ArahMataAngin::all(); $lantai = Lantai::all(); $viewUnit = ViewUnit::all(); $golMasySekitar = GolonganMasySekitar::all(); $tingkatKeramaian = TingkatKeramaian::all(); $laluLintasLokasi = LaluLintasLokasi::all(); $perkerasanJalan = PerkerasanJalan::all(); $analisa = Analisa::with('analisaTanahBangunan', 'analisaLingkungan', 'analisaFakta', 'jenisJaminan') ->where('permohonan_id', $id) ->where('jenis_jaminan_id', $jaminanId) ->first(); // return response()->json($permohonan); return view('lpj::surveyor.components.inspeksi', compact( 'analisa', 'permohonan', 'surveyor', 'branches', 'provinces', 'bentukTanah', 'konturTanah', 'posisiKavling', 'kondisiFisikTanah', 'ketinggianTanah', 'kondisiBangunan', 'jenisBangunan', 'sifatBangunan', 'spekKategoriBagunan', 'spekBangunan', 'saranaPelengkap', 'arahMataAngin', 'lantai', 'viewUnit', 'golMasySekitar', 'tingkatKeramaian', 'laluLintasLokasi', 'perkerasanJalan' )); } /** * Denah. */ public function denah($id, $jaminanId) { $permohonan = $this->getPermohonanJaminanId($id, $jaminanId); $denah = Denah::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); return view('lpj::surveyor.components.denah', compact('permohonan', 'denah')); } /** * Foto. */ public function foto($id, $jaminanId) { $permohonan = $this->getPermohonanJaminanId($id, $jaminanId); $surveyor = $id; $branches = Branch::all(); $provinces = Province::all(); $fotoJaminan = FotoJaminan::with(['objekJaminan', 'lantaiUnit' ,'ruteJaminan', 'lingkungan'])->where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); return view('lpj::surveyor.components.foto', compact('permohonan', 'surveyor', 'branches', 'provinces', 'fotoJaminan')); } /** * Data pembanding. */ public function dataPembanding($id) { $permohonan = Permohonan::with( [ 'user', 'debiture.province', 'debiture.city', 'debiture.district', 'debiture.village', 'branch', 'tujuanPenilaian', 'penilaian' ], )->findOrFail($id); $surveyor = $id; $branches = Branch::all(); $provinces = Province::all(); return view('lpj::surveyor.detail', compact('permohonan', 'surveyor', 'branches', 'provinces')); } private function getHeader(string $type): array { return self::HEADERS[$type] ?? []; } public function data(Request $request) { $type = $request->route('type'); $header = $this->getHeader($request->route('type')); return view('lpj::surveyor.data.index', compact('header')); } public function createData($type) { $spekKategoriBagunan = SpekKategoritBangunan::all(); $header = $this->getHeader($type); return view('lpj::surveyor.data.form', compact('header', 'spekKategoriBagunan')); } public function storeData(SurveyorRequest $request, $type) { $validate = $request->validated(); if ($validate) { try { $type = $request->route('type'); $modelClass = $this->getModelClass($type); if (!$modelClass) { return redirect() ->route('basicdata.'. $type .'.index') ->with('error', 'Invalid type specified.'); } if ($type == 'spek-bangunan') { $validate['spek_kategori_bagunan_id'] = $request->spek_kategori_bagunan_id; } $data = array_merge($validate, ['status' => true]); $modelClass::create($data); return redirect() ->route('basicdata.' . $type .'.index') ->with('success', 'created successfully'); } catch (Exeception $e) { return response()->json(array('error' => $e->getMessage()), 400); // return redirect() // ->route('basicdata.' . $type .'.index') // ->with('error', $th->getMessage()); } } } public function editData($type, $id) { $dataMap = [ 'bentuk-tanah' => ['Bentuk Tanah', 'bentuk-tanah', BentukTanah::class], 'kontur-tanah' => ['Kontur Tanah', 'kontur-tanah', KonturTanah::class], 'posisi-kavling' => ['Posisi Kavling', 'posisi-kavling', PosisiKavling::class], 'ketinggian-tanah' => ['Ketinggian Tanah', 'ketinggian-tanah', KetinggianTanah::class], 'kondisi-fisik-tanah' => ['Kondisi Fisik Tanah', 'kondisi-fisik-tanah', KondisiFisikTanah::class], 'jenis-bangunan' => ['Jenis Bangunan', 'jenis-bangunan', JenisBangunan::class], 'kondisi-bangunan' => ['Kondisi Bangunan', 'kondisi-bangunan', KondisiBangunan::class], 'sifat-bangunan' => ['Sifat Bangunan', 'sifat-bangunan', SifatBangunan::class], 'spek-bangunan' => ['Spek Bangunan', 'spek-bangunan', SpekBangunan::class], 'spek-kategori-bangunan' => ['Spek Kategori Bangunan', 'spek-kategori-bangunan', SpekKategoritBangunan::class], 'sarana-pelengkap' => ['Sarana Pelengkap', 'sarana-pelengkap', SaranaPelengkap::class], 'lantai-unit' => ['Lantai Unit', 'lantai-unit', Lantai::class], 'view-unit' => ['View Unit', 'view-unit', ViewUnit::class], 'gol-mas-sekitar' => ['Golongan Masyarakat Sekitar', 'gol-mas-sekitar', GolonganMasySekitar::class], ]; if (!array_key_exists($type, $dataMap)) { return redirect()->back()->with('error', 'Invalid type specified.'); } [$headers, $routeName, $modelClass] = $dataMap[$type]; $header = $dataMap[$type] ?? ''; $model = $modelClass::findOrFail($id); if ($type == 'spek-bangunan') { $spekKategoriBagunan = SpekKategoritBangunan::all(); } return view('lpj::surveyor.data.form', compact('header', 'model', 'spekKategoriBagunan')); } public function updateData(SurveyorRequest $request, $type, $id) { $validate = $request->validated(); if ($validate) { $modelClass = $this->getModelClass($type); if ($type == 'spek-bangunan') { $validate['spek_kategori_bagunan_id'] = $request->spek_kategori_bagunan_id; } // Check if the provided type exists in the modelClasses if (!$modelClass) { return redirect() ->route('basicdata.' . $type . '.index') ->with('error', 'Invalid type specified.'); } $model = $modelClass::findOrFail($id); $model->update($validate); // Redirect back with a success message return redirect() ->route('basicdata.' . $type . '.index') ->with('success', 'Updated successfully'); } } public function dataForDatatablesData(Request $request, $type) { if (is_null($this->user) || !$this->user->can('jenis_aset.view')) { //abort(403, 'Sorry! You are not allowed to view users.'); } $models = [ 'Bentuk Tanah' => BentukTanah::class, 'Kontur Tanah' => KonturTanah::class, 'Posisi Kavling' => PosisiKavling::class, 'Ketinggian Tanah' => KetinggianTanah::class, 'Kondisi Fisik Tanah' => KondisiFisikTanah::class, 'Jenis Bangunan' => JenisBangunan::class, 'Kondisi Bangunan' => KondisiBangunan::class, 'Sifat Bangunan' => SifatBangunan::class, 'Spek Kategori Bangunan' => SpekKategoritBangunan::class, 'Spek Bangunan' => SpekBangunan::class, 'Sarana Pelengkap' => SaranaPelengkap::class, 'Lalu Lintas Depan Lokasi' => LaluLintasLokasi::class, 'Tingkat Keramaian' => TingkatKeramaian::class, 'Golongan Masyarakat Sekitar' => GolonganMasySekitar::class, 'Lantai Unit' => Lantai::class, 'View Unit' => ViewUnit::class, 'Perkerasan jalan' => PerkerasanJalan::class ]; if (array_key_exists($type, $models)) { $query = $models[$type]::query(); } else { throw new InvalidArgumentException("Invalid type: $type"); } if ($request->has('search') && !empty($request->get('search'))) { $search = $request->get('search'); $query->where(function ($q) use ($search) { $q->where('code', 'LIKE', "%$search%"); $q->orWhere('name', 'LIKE', "%$search%"); }); } // Apply sorting if provided if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) { $order = $request->get('sortOrder'); $column = $request->get('sortField'); $query->orderBy($column, $order); } // Get the total count of records $totalRecords = $query->count(); // Apply pagination if provided if ($request->has('page') && $request->has('size')) { $page = $request->get('page'); $size = $request->get('size'); $offset = ($page - 1) * $size; // Calculate the offset $query->skip($offset)->take($size); } // Get the filtered count of records $filteredRecords = $query->count(); // Get the data for the current page $data = $query->get(); // Calculate the page count $pageCount = ceil($totalRecords / $request->get('size')); // Calculate the current page number $currentPage = 0 + 1; // Return the response data as a JSON object return response()->json([ 'draw' => $request->get('draw'), 'recordsTotal' => $totalRecords, 'recordsFiltered' => $filteredRecords, 'pageCount' => $pageCount, 'page' => $currentPage, 'totalCount' => $totalRecords, 'data' => $data, ]); } public function destroy($id, $type) { try { $modelClass = $this->getModelClass($type); if (!$modelClass) { return response()->json(['success' => false, 'message' => 'Invalid type specified.'], 400); } $model = $modelClass::findOrFail($id); $model->delete(); return response()->json(['success' => true, 'message' => 'deleted successfully']); } catch (ModelNotFoundException $e) { return response()->json(['success' => false, 'message' => 'not found.'], 404); } catch (Exception $e) { return response()->json(['success' => false, 'message' => 'Failed to delete.'], 500); } } private function getPermohonanJaminanId($id, $jaminanId) { return Permohonan::with([ 'user', 'debiture.province', 'debiture.city', 'debiture.district', 'debiture.village', 'branch', 'tujuanPenilaian', 'penilaian', 'debiture.documents' => function ($query) use ($jaminanId) { $query->where('jenis_jaminan_id', $jaminanId); } ]) ->whereHas('debiture.documents', function ($query) use ($jaminanId) { $query->where('jenis_jaminan_id', $jaminanId); }) ->findOrFail($id); } public function submitSurveyor(Request $request, $id) { $permohonan = Permohonan::find($id); $permohonan->update([ 'status' => 'done', ]); return redirect() ->route('surveyor.index') ->with('success', 'form surveyor submitted successfully'); } public function validateSubmit() { } private function getModelClass(string $type): ?string { return $this->modelClasses[$type] ?? null; } private $modelClasses = [ 'bentuk-tanah' => BentukTanah::class, 'kontur-tanah' => KonturTanah::class, 'posisi-kavling' => PosisiKavling::class, 'ketinggian-tanah' => KetinggianTanah::class, 'kondisi-fisik-tanah' => KondisiFisikTanah::class, 'jenis-bangunan' => JenisBangunan::class, 'kondisi-bangunan' => KondisiBangunan::class, 'sifat-bangunan' => SifatBangunan::class, 'sarana-pelengkap' => SaranaPelengkap::class, 'lalu-lintas-lokasi' => LaluLintasLokasi::class, 'tingkat-keramaian' => TingkatKeramaian::class, 'gol-mas-sekitar' => GolonganMasySekitar::class, 'spek-kategori-bangunan' => SpekKategoritBangunan::class, 'spek-bangunan' => SpekBangunan::class, 'lantai-unit' => Lantai::class, 'view-unit' => ViewUnit::class, ]; private function getCommonData() { return [ 'branches' => Branch::all(), 'provinces' => Province::all(), 'bentukTanah' => BentukTanah::all(), 'konturTanah' => KonturTanah::all(), 'posisiKavling' => PosisiKavling::all(), 'ketinggianTanah' => KetinggianTanah::all(), 'kondisiFisikTanah' => KondisiFisikTanah::all(), 'jenisBangunan' => JenisBangunan::all(), 'kondisiBangunan' => KondisiBangunan::all(), 'sifatBangunan' => SifatBangunan::all(), 'spekKategoriBangunan' => SpekKategoritBangunan::all(), 'spekBangunan' => SpekBangunan::all(), 'saranaPelengkap' => SaranaPelengkap::all(), 'arahMataAngin' => ArahMataAngin::all(), 'lantai' => Lantai::all(), 'viewUnit' => ViewUnit::all(), 'golMasySekitar' => GolonganMasySekitar::all(), 'tingkatKeramaian' => TingkatKeramaian::all(), 'laluLintasLokasi' => LaluLintasLokasi::all(), ]; } private const HEADERS = [ 'bentuk-tanah' => ['Bentuk Tanah', 'bentuk-tanah'], 'kontur-tanah' => ['Kontur Tanah', 'kontur-tanah'], 'posisi-kavling' => ['Posisi Kavling', 'posisi-kavling'], 'ketinggian-tanah' => ['Ketinggian Tanah', 'ketinggian-tanah'], 'kondisi-fisik-tanah' => ['Kondisi Fisik Tanah', 'kondisi-fisik-tanah'], 'jenis-bangunan' => ['Jenis Bangunan', 'jenis-bangunan'], 'kondisi-bangunan' => ['Kondisi Bangunan', 'kondisi-bangunan'], 'sifat-bangunan' => ['Sifat Bangunan', 'sifat-bangunan'], 'sarana-pelengkap' => ['Sarana Pelengkap', 'sarana-pelengkap'], 'lalu-lintas-lokasi' => ['Lalu Lintas Depan Lokasi', 'lalu-lintas-lokasi'], 'tingkat-keramaian' => ['Tingkat Keramaian', 'tingkat-keramaian'], 'gol-mas-sekitar' => ['Golongan Masyarakat Sekitar', 'gol-mas-sekitar'], 'spek-kategori-bangunan' => ['Spek Kategori Bangunan', 'spek-kategori-bangunan'], 'spek-bangunan' => ['Spek Bangunan', 'spek-bangunan'], 'lantai-unit' => ['Lantai Unit', 'lantai-unit'], 'view-unit' => ['View Unit', 'view-unit'], 'perkerasan-jalan' => ['Perkerasan jalan', 'perkerasan-jalan'] ]; }