diff --git a/app/Http/Controllers/SurveyorController.php b/app/Http/Controllers/SurveyorController.php index b2f411e..5e94681 100644 --- a/app/Http/Controllers/SurveyorController.php +++ b/app/Http/Controllers/SurveyorController.php @@ -9,6 +9,7 @@ use Maatwebsite\Excel\Facades\Excel; use Modules\Lpj\Exports\BasicDataSurveyorExport; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Storage; use Illuminate\Http\Response; use Modules\Lpj\Models\Permohonan; use Modules\Lpj\Models\Branch; @@ -94,97 +95,77 @@ class SurveyorController extends Controller 'branch', 'tujuanPenilaian', 'penilaian', - 'documents', + 'documents.jenisJaminan', ])->findOrFail($id); - + $surveyor = $id; $branches = Branch::all(); $provinces = Province::all(); $bentukTanah = BentukTanah::all(); - - $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(); - - $jenisJaminanIds = $permohonan->debiture->documents->pluck('jenisJaminan.id')->toArray(); // Convert to array - - $jaminanId = $jenisJaminanIds[0]; - $inpeksi = Inspeksi::where('permohonan_id', $id) - ->whereIn('jenis_jaminan_id', $jenisJaminanIds) - ->first(); - - if ($inpeksi) { - $forminspeksi = json_decode($inpeksi->data_form, true); - $formFoto = json_decode($inpeksi->foto_form, true); - $formDenah = json_decode($inpeksi->denah_form, true); - $formPembanding = json_decode($inpeksi->data_pembanding, true); - } else { - $forminspeksi = null; - $formFoto = null; - $formDenah = null; - $formPembanding = null; - } - + + // Get all inspeksi data for this permohonan + $inspeksiData = Inspeksi::where('permohonan_id', $id) + ->get() + ->keyBy('jenis_jaminan_id') + ->map(function ($item) { + return [ + 'data_form' => json_decode($item->data_form, true), + 'foto_form' => json_decode($item->foto_form, true), + 'denah_form' => json_decode($item->denah_form, true), + 'data_pembanding' => json_decode($item->data_pembanding, true), + ]; + }); + return view('lpj::surveyor.detail', compact( - 'denah', - 'analisa', 'permohonan', 'surveyor', 'branches', 'provinces', 'bentukTanah', - 'forminspeksi', - 'formDenah', - 'formFoto', - 'jaminanId', - - 'formPembanding' + 'inspeksiData' )); } + /** * Store form inspeksi. */ public function store(FormSurveyorRequest $request) { - $data = $request->validated(); - - - - if (!$data) { - return response()->json(['success' => false, 'message' => 'Invalid data'], 400); - } - try { - DB::beginTransaction(); + // Validate request data + $validatedData = $request->validated(); + + // Get action specific rules and process data + $processedData = $this->getActionSpecificRules( + $validatedData, + $request->input('type'), + $request + ); - $action = $request->input('type'); - $rules = $this->getActionSpecificRules($data, $action, $request); + // Find or create inspeksi record + $inspeksi = Inspeksi::updateOrCreate( + [ + 'permohonan_id' => $request->input('permohonan_id'), + 'jenis_jaminan_id' => $request->input('jenis_jaminan_id') + ], + [ + 'data_form' => json_encode($processedData), + 'name' => $request->input('type') + ] + ); - $data = $rules; + return response()->json([ + 'success' => true, + 'message' => 'Data berhasil disimpan', + 'data' => $processedData + ], 200); - - - // $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first(); - - // if (!$inspeksi) { - // Inspeksi::create([ - // 'permohonan_id' => $request->input('permohonan_id'), - // 'data_form' => json_encode($rules), - // 'name' => $request->input('type'), - // 'jenis_jaminan_id' => $request->input('jenis_jaminan_id'), - // ]); - // } else { - // $inspeksi->update(['data_form' => json_encode($rules)]); - // } - - DB::commit(); - - return response()->json(['success' => true, 'message' => 'Data saved successfully', 'data' => $data], 200); - } catch (Exception $e) { - DB::rollBack(); - return response()->json(['success' => false, 'message' => 'Failed to save data: ' . $e->getMessage()], 500); + } catch (\Exception $e) { + return response()->json([ + 'success' => false, + 'message' => 'Gagal menyimpan data', + 'error' => $e->getMessage() + ], 500); } } @@ -259,8 +240,11 @@ class SurveyorController extends Controller ]); } - return response()->json(['success' => true, 'message' => 'Data berhasil disimpan', - 'data' => $formatJsonDenah], 200); + return response()->json([ + 'success' => true, + 'message' => 'Data berhasil disimpan', + 'data' => $formatJsonDenah + ], 200); } catch (Exception $e) { return response()->json(['success' => false, 'message' => 'Data gagal disimpan: ' . $e->getMessage()], 500); } @@ -269,7 +253,128 @@ class SurveyorController extends Controller public function storeFoto(Request $request) { - $validatedData = $request->validate([ + $validatedData = $this->validateFotoRequest($request); + try { + + $photoCategories = [ + 'rute_menuju_lokasi' => ['foto_rute', 'name_rute'], + 'object_jaminan' => ['foto_objek', 'name_objek', 'deskripsi_objek'], + 'lingkungan' => ['foto_lingkungan', 'name_lingkungan'], + 'foto_lantai_unit' => ['foto_lantai_unit', 'name_lantai_unit'], + 'foto_lantai_lainnya' => ['foto_lantai_lainnya', 'name_lantai_lainnya'], + 'foto_rute_lainnya' => ['foto_rute_lainnya', 'name_rute_lainnya'], + ]; + + $inspeksi = Inspeksi::firstOrNew([ + 'permohonan_id' => $request->input('permohonan_id'), + 'jenis_jaminan_id' => $request->input('jenis_jaminan_id') + ]); + + // Get existing foto_form data if it exists + $existingData = $inspeksi->exists && $inspeksi->foto_form + ? json_decode($inspeksi->foto_form, true) + : []; + + $formatFotojson = $existingData; // Start with existing data + + // Process each photo category + foreach ($photoCategories as $category => $fields) { + // Only update if new files are provided + if ($this->categoryHasNewFiles($request, $fields)) { + // Delete old files for this category only + if (isset($existingData[$category])) { + $this->deleteFilesForCategory($existingData[$category]); + } + $formatFotojson[$category] = $this->processPhotoCategory($request, $fields); + } + } + + // Process single files + $singleFiles = ['foto_basement', 'foto_gerbang', 'pendamping']; + foreach ($singleFiles as $file) { + if ($request->hasFile($file)) { + // Delete old file if exists + if (isset($existingData[$file])) { + $this->deleteFile($existingData[$file]); + } + $formatFotojson[$file] = $this->uploadFile($request->file($file), $file); + } + } + + // Update record + $inspeksi->foto_form = json_encode($formatFotojson); + $inspeksi->save(); + + + + return response()->json(['success' => true, 'message' => 'Data berhasil disimpan', 'data' => $formatFotojson], 200); + } catch (Exception $e) { + return response()->json(['success' => false, 'message' => 'Failed to upload: ' . $e->getMessage()], 500); + } + } + + /** + * Process a photo category and its subcategories + */ + + private function processPhotoCategory(Request $request, array $fields) + { + $result = []; + $photoField = $fields[0]; + + if ($request->hasFile($photoField)) { + foreach ($request->file($photoField, []) as $key => $value) { + $item = []; + $item[$fields[1]] = $request->input($fields[1] . '.' . $key); + $item[$photoField] = $this->uploadFile($value, $photoField . '.' . $key); + + if (isset($fields[2])) { + $item[$fields[2]] = $request->input($fields[2] . '.' . $key); + } + + $result[] = $item; + } + } + + return $result; + } + + private function categoryHasNewFiles(Request $request, array $fields): bool +{ + $photoField = $fields[0]; // First element is usually the photo field + return $request->hasFile($photoField) || + (is_array($request->file($photoField)) && count($request->file($photoField)) > 0); +} + +private function deleteFilesForCategory($categoryData) +{ + if (!is_array($categoryData)) { + return; + } + + foreach ($categoryData as $item) { + if (isset($item['foto'])) { + $this->deleteOfFile($item['foto']); + } + } +} + +private function deleteOfFile($filePath) +{ + if ($filePath && Storage::exists($filePath)) { + Storage::delete($filePath); + } +} + + + + + /** + * Custom validation request for foto + */ + public function validateFotoRequest(Request $request) + { + return $request->validate([ 'permohonan_id' => 'required', 'jenis_jaminan_id' => 'required', 'pendamping' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', @@ -291,164 +396,96 @@ class SurveyorController extends Controller 'foto_gerbang' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'name_gerbang' => 'nullable|string|max:255', ]); - - try { - - $rute_menuju_lokasi = []; - $object_jaminan = []; - $lingkungan = []; - $foto_lantai_unit = []; - $foto_lantai_lainnya = []; - $foto_rute_lainnya = []; - - - foreach ($request->file('foto_rute', []) as $key => $value) { - $fotoRutePath = $this->uploadFile($request->file('foto_rute.' . $key), 'foto_rute.' . $key); - - $rute_menuju_lokasi[] = [ - 'name_rute' => $request->input('name_rute.' . $key), - 'foto_rute' => $fotoRutePath, - ]; - } - - foreach ($request->file('foto_objek', []) as $key => $value) { - $fotoObjekPath = $this->uploadFile($request->file('foto_objek.' . $key), 'foto_objek.' . $key); - $object_jaminan[] = [ - 'nama_objek' => $request->input('name_objek.' . $key), - 'foto_object' => $fotoObjekPath, - 'deskripsi_objek' => $request->input('deskripsi_objek.' . $key), - ]; - } - - foreach ($request->file('foto_lingkungan', []) as $key => $value) { - $fotoLingkunganPath = $this->uploadFile($request->file('foto_lingkungan.' . $key), 'foto_lingkungan.' . $key); - $lingkungan[] = [ - 'name_lingkungan' => $request->input('name_lingkungan.' . $key), - 'foto_lingkungan' => $fotoLingkunganPath, - - ]; - } - - foreach ($request->file('foto_lantai_unit', []) as $key => $value) { - $foto_lantai_unit_Path = $this->uploadFile($request->file('foto_lantai_unit.' . $key), 'foto_lantai_unit.' . $key); - $foto_lantai_unit[] = [ - 'name_lantai_unit' => $request->input('name_lantai_unit.' . $key), - 'foto_lantai_unit' => $foto_lantai_unit_Path, - - ]; - } - - foreach ($request->file('foto_rute_lainnya', []) as $key => $value) { - $foto_rute_lainnya_path = $this->uploadFile($request->file('foto_rute_lainnya.' . $key), 'foto_rute_lainnya.' . $key); - $foto_rute_lainnya[] = [ - 'name_rute_lainnya' => $request->input('name_rute_lainnya.' . $key), - 'foto_rute_lainnya' => $foto_rute_lainnya_path, - - ]; - } - - - foreach ($request->file('foto_lantai_lainnya', []) as $key => $value) { - $foto_lantai_lainnya_path = $this->uploadFile($request->file('foto_lantai_lainnya.' . $key), 'foto_lantai_lainnya.' . $key); - $foto_lantai_lainnya[] = [ - 'name_lantai_lainnya' => $request->input('name_lantai_lainnya.' . $key), - 'foto_lantai_lainnya' => $foto_lantai_lainnya_path, - - ]; - } - - - $basement = $this->uploadFile($request->file('foto_basement'), 'foto_basement'); - $gerbang = $this->uploadFile($request->file('foto_gerbang'), 'foto_gerbang'); - $pendamping = $this->uploadFile($request->file('pendamping'), 'pendamping'); - - - $formatFotojson = [ - 'rute_menuju_lokasi' => $rute_menuju_lokasi, - 'object_jaminan' => $object_jaminan, - 'lingkungan' => $lingkungan - ,'foto_lantai_unit' => $foto_lantai_unit, - 'foto_lantai_lainnya' => $foto_lantai_lainnya, - 'foto_rute_lainnya' => $foto_rute_lainnya, - 'foto_basement' => $basement, - 'foto_gerbang' => $gerbang, - 'pendamping' => $pendamping - ]; - - $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first(); - - if ($inspeksi) { - $inspeksi->update([ - 'foto_form' => json_encode($formatFotojson) - ]); - } else { - Inspeksi::create([ - 'permohonan_id' => $request->input('permohonan_id'), - 'foto_form' => json_encode($formatFotojson), - 'jenis_jaminan_id' => $request->input('jenis_jaminan_id') - ]); - } - - return response()->json(['success' => true, 'message' => 'Data berhasil disimpan', 'data' => $formatFotojson], 200); - } catch (Exception $e) { - return response()->json(['success' => false, 'message' => 'Failed to upload: ' . $e->getMessage()], 500); - } } - - public function submitSurveyor($id) - { - try { - // $cekButton = $this->checkButtonStatus($id); - // if (!$cekButton->buttonDisable) { - $permohonan = Permohonan::find($id); - $permohonan->update([ - 'status' => 'done', - ]); - return response()->json(['success' => true, 'message' => 'Form surveyor submitted successfully'], 200); - // } else { - // return response()->json(['error' => 'Something went wrong'], 400); - // } - } catch (Exception $e) { - return response()->json(['error' => 'Something went wrong', 'message' => $e->getMessage()], 500); +{ + try { + // Get button status check result + $buttonStatusCheck = $this->checkButtonStatus($id); + $buttonStatus = json_decode($buttonStatusCheck->getContent(), true); + + // Check if button should be disabled + if ($buttonStatus['buttonDisable']) { + return response()->json([ + 'success' => false, + 'message' => 'Form belum lengkap. Pastikan semua data telah diisi dengan benar.', + ], 422); } + + // If validation passes, update permohonan status + // $permohonan = Permohonan::findOrFail($id); + // $permohonan->update([ + // 'status' => 'done', + // 'submitted_at' => now() + // ]); + + return response()->json([ + 'success' => true, + 'message' => 'Form surveyor berhasil disubmit' + ], 200); + + } catch (\Exception $e) { + return response()->json([ + 'success' => false, + 'message' => 'Terjadi kesalahan', + 'error' => $e->getMessage() + ], 500); } +} + public function checkButtonStatus($id) { try { - - $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); - - if ($inpeksi) { - $forminspeksi = json_decode($inpeksi->data_form, true); - $formFoto = json_decode($inpeksi->foto_form, true); - - $buttonDisable = false; - if ( - $formFoto && count($formFoto) > 0 && - $forminspeksi - ) { - $buttonDisable = false; - } else { - $buttonDisable = true; - } - - return response()->json(['buttonDisable' => $buttonDisable]); - } else { + // Get all inspeksi records for this permohonan + $inspeksiRecords = Inspeksi::where('permohonan_id', $id)->get(); + + if ($inspeksiRecords->isEmpty()) { return response()->json(['buttonDisable' => true]); } + + foreach ($inspeksiRecords as $inspeksi) { + $dataForm = json_decode($inspeksi->data_form, true); + $fotoForm = json_decode($inspeksi->foto_form, true); + $denahForm = json_decode($inspeksi->denah_form, true); + $dataPembanding = json_decode($inspeksi->data_pembanding, true); + + // Get jenis jaminan to check if it needs denah + $jenisJaminan = JenisJaminan::find($inspeksi->jenis_jaminan_id); + $isTanahBangunan = !in_array( + strtoupper($jenisJaminan->name ?? ''), + ['KAPAL', 'PESAWAT', 'KENDARAAN', 'ALAT BERAT'] + ); + + // Check if required forms are empty or incomplete + if (empty($dataForm) || empty($fotoForm)) { + return response()->json(['buttonDisable' => true]); + } + + if ($isTanahBangunan && empty($denahForm)) { + return response()->json(['buttonDisable' => true]); + } + + if (empty($dataPembanding)) { + return response()->json(['buttonDisable' => true]); + } + } + + // If we get here, all checks passed + return response()->json(['buttonDisable' => false]); + } catch (\Exception $e) { - // return response()->json(['buttonDisable' => true]); return response()->json([ 'error' => 'Something went wrong', - 'message' => $e->getMessage() + 'message' => $e->getMessage(), + 'buttonDisable' => true ], 500); } } + @@ -558,9 +595,9 @@ class SurveyorController extends Controller $link_url_region = Teams::with('regions', 'teamsUsers') - ->whereHas('teamsUsers', function ($query) { - $query->where('user_id', Auth::user()->id); - })->first(); + ->whereHas('teamsUsers', function ($query) { + $query->where('user_id', Auth::user()->id); + })->first(); $branches = Branch::all(); $provinces = Province::all(); @@ -768,13 +805,12 @@ class SurveyorController extends Controller if (!$modelClass) { return redirect() - ->route('basicdata.'. $type .'.index') + ->route('basicdata.' . $type . '.index') ->with('error', 'Invalid type specified.'); } if ($type == 'spek-bangunan') { $validate['spek_kategori_bagunan_id'] = $request->spek_kategori_bagunan_id; - } @@ -782,12 +818,11 @@ class SurveyorController extends Controller $modelClass::create($data); return redirect() - ->route('basicdata.' . $type .'.index') + ->route('basicdata.' . $type . '.index') ->with('success', 'created successfully'); - } catch (Exeception $e) { return redirect() - ->route('basicdata.' . $type .'.index') + ->route('basicdata.' . $type . '.index') ->with('error', $th->getMessage()); } } @@ -836,7 +871,6 @@ class SurveyorController extends Controller $spekKategoriBagunan = null; if ($type == 'spek-bangunan') { $spekKategoriBagunan = SpekKategoritBangunan::all(); - } @@ -852,7 +886,6 @@ class SurveyorController extends Controller if ($type == 'spek-bangunan') { $validate['spek_kategori_bagunan_id'] = $request->spek_kategori_bagunan_id; - } // Check if the provided type exists in the modelClasses @@ -1011,7 +1044,7 @@ class SurveyorController extends Controller } $filteredRecords = $query->count(); - $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'jenisFasilitasKredit','penilaian'])->get(); + $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'jenisFasilitasKredit', 'penilaian'])->get(); $pageCount = ceil($totalRecords / $size); @@ -1162,10 +1195,10 @@ class SurveyorController extends Controller $query->where('jenis_jaminan_id', $jaminanId); } ]) - ->whereHas('debiture.documents', function ($query) use ($jaminanId) { - $query->where('jenis_jaminan_id', $jaminanId); - }) - ->findOrFail($id); + ->whereHas('debiture.documents', function ($query) use ($jaminanId) { + $query->where('jenis_jaminan_id', $jaminanId); + }) + ->findOrFail($id); } @@ -1277,7 +1310,7 @@ class SurveyorController extends Controller 'posisi-unit' => ['Posisi unit', 'posisi-unit'], 'bentuk-unit' => ['Bentuk unit', 'bentuk-unit'], 'fasilitas-objek' => ['Fasilitas Umum Dekat Objek', 'fasilitas-objek'], - ]; + ]; private function getAssetData(array $data): array { @@ -1294,12 +1327,27 @@ class SurveyorController extends Controller 'debitur_perwakilan' => $data['debitur_perwakilan'] ?? [], 'jenis_asset' => [ $data['jenis_asset'] => ($data['jenis_asset'] === 'sesuai') - ? $data['jenis_asset'] + ? $data['jenis_asset_name'] : ($data['jenis_asset_tidak_sesuai'] ?? null) ], 'alamat' => [ $data['alamat_sesuai'] => $alamatData ], + 'hub_cadeb' => [ + $data['hub_cadeb'] => $this->getFieldData( + $data, + 'hub_cadeb', + true + ) + ], + 'hub_cadeb_penghuni' => [ + $data['hub_cadeb_penghuni'] => $this->getFieldData( + $data, + 'hub_cadeb_penghuni', + true + ) + ], + 'kordinat_lng' => $data['kordinat_lng'] ?? null, 'kordinat_lat' => $data['kordinat_lat'] ?? null, ] @@ -1379,17 +1427,21 @@ class SurveyorController extends Controller return [ 'bangunan' => [ - 'luas_tanah_bagunan' => $data['luas_tanah_bagunan'] ?? null, - 'jenis_bangunan' => $data['jenis_bangunan'] ?? null, - 'kondisi_bangunan' => $data['kondisi_bangunan'] ?? null, - 'sifat_bangunan' => $data['sifat_bangunan'] ?? null, - 'sifat_bangunan_input' => $data['sifat_bangunan_input'] ?? null, - 'spesifikasi_bangunan' => $result ?? null, - 'sarana_pelengkap' => $this->mapArrayWithInputs( - $data['sarana_pelengkap'] ?? [], - $data['sarana_pelengkap_input'] ?? [] - ), - ], + 'luas_tanah_bagunan' => $this->getFieldData( + $data, + 'luas_tanah_bagunan', + true + ), + 'jenis_bangunan' => $data['jenis_bangunan'] ?? null, + 'kondisi_bangunan' => $data['kondisi_bangunan'] ?? null, + 'sifat_bangunan' => $data['sifat_bangunan'] ?? null, + 'sifat_bangunan_input' => $data['sifat_bangunan_input'] ?? null, + 'spesifikasi_bangunan' => $result ?? null, + 'sarana_pelengkap' => $this->mapArrayWithInputs( + $data['sarana_pelengkap'] ?? [], + $data['sarana_pelengkap_input'] ?? [] + ), + ], ]; } @@ -1397,27 +1449,27 @@ class SurveyorController extends Controller { return [ 'lingkungan' => [ - 'jarak_jalan_utama' => $data['jarak_jalan_utama'] ?? null, - 'jalan_linkungan' => $data['jalan_linkungan'] ?? null, - 'jarak_cbd_point' => $data['jarak_cbd_point'] ?? null, - 'nama_cbd_point' => $data['nama_cbd_point'] ?? null, - 'lebar_perkerasan_jalan' => $data['lebar_perkerasan_jalan'] ?? null, - 'perkerasan_jalan' => $data['perkerasan_jalan'] ?? null, - 'lalu_lintas' => $data['lalu_lintas'] ?? null, - 'gol_mas_sekitar' => $data['gol_mas_sekitar'] ?? null, - 'tingkat_keramaian' => $data['tingkat_keramaian'] ?? null, - 'terletak_diarea' => $data['terletak_diarea'] ?? null, - 'disekitar_lokasi' => $data['disekitar_lokasi'] ?? null, - 'kondisi_bangunan_sekitar' => $data['kondisi_bangunan_sekitar'] ?? null, - 'sifat_bangunan_sekitar' => $data['sifat_bangunan_sekitar'] ?? null, - 'dekat_makam' => $data['dekat_makam'] ?? null, - 'jarak_makam' => $data['jarak_makam'] ?? null, - 'nama_makam' => $data['nama_makam'] ?? null, - 'dekat_tps' => $data['dekat_tps'] ?? null, - 'jarak_tps' => $data['jarak_tps'] ?? null, - 'nama_tps' => $data['nama_tps'] ?? null, - 'merupakan_daerah' => $data['merupakan_daerah'] ?? null, - 'fasilitas_dekat_object' => $data['fasilitas_dekat_object'] ?? null, + 'jarak_jalan_utama' => $data['jarak_jalan_utama'] ?? null, + 'jalan_linkungan' => $data['jalan_linkungan'] ?? null, + 'jarak_cbd_point' => $data['jarak_cbd_point'] ?? null, + 'nama_cbd_point' => $data['nama_cbd_point'] ?? null, + 'lebar_perkerasan_jalan' => $data['lebar_perkerasan_jalan'] ?? null, + 'perkerasan_jalan' => $data['perkerasan_jalan'] ?? null, + 'lalu_lintas' => $data['lalu_lintas'] ?? null, + 'gol_mas_sekitar' => $data['gol_mas_sekitar'] ?? null, + 'tingkat_keramaian' => $data['tingkat_keramaian'] ?? null, + 'terletak_diarea' => $data['terletak_diarea'] ?? null, + 'disekitar_lokasi' => $data['disekitar_lokasi'] ?? null, + 'kondisi_bangunan_sekitar' => $data['kondisi_bangunan_sekitar'] ?? null, + 'sifat_bangunan_sekitar' => $data['sifat_bangunan_sekitar'] ?? null, + 'dekat_makam' => $data['dekat_makam'] ?? null, + 'jarak_makam' => $data['jarak_makam'] ?? null, + 'nama_makam' => $data['nama_makam'] ?? null, + 'dekat_tps' => $data['dekat_tps'] ?? null, + 'jarak_tps' => $data['jarak_tps'] ?? null, + 'nama_tps' => $data['nama_tps'] ?? null, + 'merupakan_daerah' => $data['merupakan_daerah'] ?? null, + 'fasilitas_dekat_object' => $data['fasilitas_dekat_object'] ?? null, ] ]; } @@ -1426,25 +1478,26 @@ class SurveyorController extends Controller { $factData = [ 'fakta' => [ - 'fakta_positif' => $data['fakta_positif'] ?? null, - 'fakta_negatif' => $data['fakta_negatif'] ?? null, - 'rute_menuju' => $data['rute_menuju'] ?? null, - 'batas_batas' => $this->mapArrayWithInputs( - $data['batas_batas'] ?? null, $data['batas_batas_input'] ?? null - ), - 'kondisi_lingkungan' => $data['kondisi_lingkungan'] ?? null, - 'kondisi_lain_bangunan' => $data['kondisi_lain_bangunan'] ?? null, - 'informasi_dokument' => $data['informasi_dokument'] ?? null, - 'peruntukan' => $data['peruntukan'] ?? null, - 'kdb' => $data['kdb'] ?? null, - 'kdh' => $data['kdh'] ?? null, - 'gsb' => $data['gsb'] ?? null, - 'max_lantai' => $data['max_lantai'] ?? null, - 'klb' => $data['klb'] ?? null, - 'gss' => $data['gss'] ?? null, - 'pelebaran_jalan' => $data['pelebaran_jalan'] ?? null, - 'nama_petugas' => $data['nama_petugas'] ?? null, - 'keterangan' => $data['keterangan'] ?? null, + 'fakta_positif' => $data['fakta_positif'] ?? null, + 'fakta_negatif' => $data['fakta_negatif'] ?? null, + 'rute_menuju' => $data['rute_menuju'] ?? null, + 'batas_batas' => $this->mapArrayWithInputs( + $data['batas_batas'] ?? null, + $data['batas_batas_input'] ?? null + ), + 'kondisi_lingkungan' => $data['kondisi_lingkungan'] ?? null, + 'kondisi_lain_bangunan' => $data['kondisi_lain_bangunan'] ?? null, + 'informasi_dokument' => $data['informasi_dokument'] ?? null, + 'peruntukan' => $data['peruntukan'] ?? null, + 'kdb' => $data['kdb'] ?? null, + 'kdh' => $data['kdh'] ?? null, + 'gsb' => $data['gsb'] ?? null, + 'max_lantai' => $data['max_lantai'] ?? null, + 'klb' => $data['klb'] ?? null, + 'gss' => $data['gss'] ?? null, + 'pelebaran_jalan' => $data['pelebaran_jalan'] ?? null, + 'nama_petugas' => $data['nama_petugas'] ?? null, + 'keterangan' => $data['keterangan'] ?? null, ] ]; @@ -1859,8 +1912,11 @@ class SurveyorController extends Controller { return [ 'action' => $data['action'] ?? null, - 'luas_unit' => $data['luas_unit'] ?? null, - 'luas_unit_tidak_sesuai' => $data['luas_unit_tidak_sesuai'] ?? null, + 'luas_unit' => $this->getFieldData( + $data, + 'luas_unit', + true + ), 'jenis_unit' => $data['jenis_unit'] ?? null, 'kondisi_unit' => $data['kondisi_unit'] ?? null, 'posisi_unit' => $data['posisi_unit'] ?? null, @@ -1872,7 +1928,7 @@ class SurveyorController extends Controller - /** + /** * Helper untuk upload file * * @param $file @@ -1936,7 +1992,7 @@ class SurveyorController extends Controller if ($checkKesesuaian) { return [ $data[$fieldName] ?? '' => ($data[$fieldName] ?? '') === 'sesuai' - ? ($data[$fieldName] ?? '') + ? ($data["{$fieldName}_sesuai"] ?? '') : ($data["{$fieldName}_tidak_sesuai"] ?? '') ]; } @@ -1968,5 +2024,4 @@ class SurveyorController extends Controller // Return Excel download return Excel::download(new BasicDataSurveyorExport($modelClass), $type . '.xlsx'); } - } diff --git a/app/Http/Requests/FormSurveyorRequest.php b/app/Http/Requests/FormSurveyorRequest.php index 0a3245b..3eeafe5 100644 --- a/app/Http/Requests/FormSurveyorRequest.php +++ b/app/Http/Requests/FormSurveyorRequest.php @@ -71,8 +71,10 @@ class FormSurveyorRequest extends FormRequest { return [ 'luas_tanah' => 'required', + 'luas_tanah_sesuai' => 'nullable', 'luas_tanah_tidak_sesuai' => 'nullable', 'hadap_mata_angin' => 'required', + 'hadap_mata_angin_sesuai' => 'nullable', 'hadap_mata_angin_tidak_sesuai' => 'nullable', 'bentuk_tanah' => 'nullable|array', 'bentuk_tanah_lainnya' => 'nullable', @@ -95,7 +97,9 @@ class FormSurveyorRequest extends FormRequest { return [ 'action' => 'required', + 'luas_tanah_bangunan_sesuai' => 'nullable', 'luas_tanah_bagunan' => 'required', + 'luas_tanah_bangunan_tidak_sesuai' => 'nullable', 'jenis_bangunan' => 'required', 'kondisi_bangunan' => 'nullable', 'sifat_bangunan' => 'required|array', @@ -116,6 +120,7 @@ class FormSurveyorRequest extends FormRequest return [ 'action' => 'required', 'luas_unit' => 'required', + 'luas_unit_sesuai' => 'nullable', 'luas_unit_tidak_sesuai' => 'nullable', 'jenis_unit' => 'required|array', 'kondisi_unit' => 'required|array', @@ -511,10 +516,19 @@ class FormSurveyorRequest extends FormRequest 'permohonan_id' => 'required', 'type' => 'required', 'debitur_perwakilan' => 'required|array', + 'jenis_asset_name' => 'nullable', 'jenis_asset' => 'required', 'jenis_asset_tidak_sesuai' => 'nullable', 'alamat_sesuai' => 'required', 'alamat_tidak_sesuai' => 'nullable', + + 'hub_cadeb' => 'required', + 'hub_cadeb_sesuai' => 'nullable', + 'hub_cadeb_tidak_sesuai' => 'nullable', + 'hub_cadeb_penghuni' => 'required', + 'hub_cadeb_penghuni_sesuai' => 'nullable', + 'hub_cadeb_penghuni_tidak_sesuai' => 'nullable', + 'nama_jalan' => 'nullable', 'desa_kelurahan' => 'nullable', 'kecamatan' => 'nullable', diff --git a/resources/views/surveyor/components/apartemen-kantor.blade.php b/resources/views/surveyor/components/apartemen-kantor.blade.php index 654f2d0..c965938 100644 --- a/resources/views/surveyor/components/apartemen-kantor.blade.php +++ b/resources/views/surveyor/components/apartemen-kantor.blade.php @@ -12,26 +12,44 @@
+ @if (isset($permohonan->debiture->documents)) + @foreach ($permohonan->debiture->documents as $item) + @php + $luas = $item->detail; + $details = json_decode($luas[0]->details, true); + $luas_unit = isset($details['luas_unit']) ? $details['luas_unit'] : 'N/A'; + @endphp + +

{{ $luas_unit }} m2

+ @endforeach + + @endif +
- - -
+ style="{{ old('luas_unit', $forminspeksi['luas_unit'] ?? '') == 'tidak sesuai' ? '' : 'display: none;' }}"> + + +
@@ -94,8 +112,8 @@ {{ in_array($item->name, old('lantai', $forminspeksi['lantai'] ?? [])) ? 'checked' : '' }} /> {{ $item->name }} - @endforeach diff --git a/resources/views/surveyor/components/bangunan.blade.php b/resources/views/surveyor/components/bangunan.blade.php index 1b0cf9f..284794c 100644 --- a/resources/views/surveyor/components/bangunan.blade.php +++ b/resources/views/surveyor/components/bangunan.blade.php @@ -15,6 +15,7 @@ $details = json_decode($luas[0]->details, true); $luas_bangunan = isset($details['luas_bangunan']) ? $details['luas_bangunan'] : 'N/A'; @endphp +

{{ $luas_bangunan }} m2

@endforeach diff --git a/resources/views/surveyor/components/card-tambah.blade.php b/resources/views/surveyor/components/card-tambah.blade.php index 0f9efe4..a720d4a 100644 --- a/resources/views/surveyor/components/card-tambah.blade.php +++ b/resources/views/surveyor/components/card-tambah.blade.php @@ -1,100 +1,72 @@
@foreach ($permohonan->debiture->documents as $dokumen) + @php + $jaminanId = $dokumen->jenisJaminan->id; + $currentInspeksi = $inspeksiData[$jaminanId] ?? null; + + $tanahBangunanTypes = ['KAPAL', 'PESAWAT', 'KENDARAAN', 'ALAT BERAT']; + + $href = [ + [ + 'label' => 'form inspeksi', + 'url' => route('surveyor.inspeksi', [ + 'id' => $permohonan->id, + 'jaminanId' => $jaminanId, + ]) . "?form=create-inspeksi&inspeksi={$permohonan->id}&jenis_jaminan={$jaminanId}", + 'show' => true, + 'icon' => !empty($currentInspeksi['data_form']), + ], + ]; + + if (!in_array(strtoupper($dokumen->jenisJaminan->name), $tanahBangunanTypes)) { + $href[] = [ + 'label' => 'denah tanah dan bangunan', + 'url' => route('surveyor.denah', [ + 'id' => $permohonan->id, + 'jaminanId' => $jaminanId, + ]) . "?form=create-denah&denah={$permohonan->id}&jenis_jaminan={$jaminanId}", + 'show' => true, + 'icon' => !empty($currentInspeksi['denah_form']), + ]; + } + + $href = array_merge($href, [ + [ + 'label' => 'foto', + 'url' => route('surveyor.foto', [ + 'id' => $permohonan->id, + 'jaminanId' => $jaminanId, + ]) . "?form=create-foto&foto={$permohonan->id}&jenis_jaminan={$jaminanId}", + 'show' => true, + 'icon' => !empty($currentInspeksi['foto_form']), + ], + [ + 'label' => 'data pembanding', + 'url' => route('surveyor.data-pembanding', [ + 'id' => $permohonan->id, + 'jaminanId' => $jaminanId, + ]) . "?form=data-pembanding&pembanding={$permohonan->id}&jenis_jaminan={$jaminanId}", + 'show' => true, + 'icon' => !empty($currentInspeksi['data_pembanding']), + ], + ]); + @endphp +
-
- - - - - - -
- - -
+
-
- - {{ $dokumen->jenisJaminan->name ?? '' }} - + {{ $dokumen->jenisJaminan->name ?? '' }} +
- @php - - $tanahBangunanTypes = ['KAPAL', 'PESAWAT', 'KENDARAAN', 'ALAT BERAT']; - - $href = [ - [ - 'label' => 'form inspeksi', - 'url' => - route('surveyor.inspeksi', [ - 'id' => $permohonan->id, - 'jaminanId' => $dokumen->jenisJaminan->id, - ]) . - "?form=create-inspeksi&inspeksi={$permohonan->id}&jenis_jaminan={$dokumen->jenisJaminan->id}", - 'show' => true, - 'icon' => $forminspeksi, - ], - ]; - - if (!in_array(strtoupper($dokumen->jenisJaminan->name), $tanahBangunanTypes)) { - $href[] = [ - 'label' => 'denah tanah dan bangunan', - 'url' => - route('surveyor.denah', [ - 'id' => $permohonan->id, - 'jaminanId' => $dokumen->jenisJaminan->id, - ]) . - "?form=create-denah&denah={$permohonan->id}&jenis_jaminan={$dokumen->jenisJaminan->id}", - 'show' => true, - 'icon' => $formDenah, - ]; - } - - // Tambahkan route lainnya - $href = array_merge($href, [ - [ - 'label' => 'foto', - 'url' => - route('surveyor.foto', [ - 'id' => $permohonan->id, - 'jaminanId' => $dokumen->jenisJaminan->id, - ]) . "?form=create-foto&foto={$permohonan->id}&jenis_jaminan={$dokumen->jenisJaminan->id}", - 'show' => true, - 'icon' => $formFoto, - ], - [ - 'label' => 'data pembanding', - 'url' => - route('surveyor.data-pembanding', [ - 'id' => $permohonan->id, - 'jaminanId' => $dokumen->jenisJaminan->id, - ]) . - "?form=data-pembanding&pembanding={$permohonan->id}&jenis_jaminan={$dokumen->jenisJaminan->id}", - 'show' => true, - 'icon' => $formPembanding, - ], - ]); - @endphp - @foreach ($href as $item) @if ($item['show'])
-
- +
diff --git a/resources/views/surveyor/components/foto.blade.php b/resources/views/surveyor/components/foto.blade.php index fd83d06..82ef211 100644 --- a/resources/views/surveyor/components/foto.blade.php +++ b/resources/views/surveyor/components/foto.blade.php @@ -621,10 +621,12 @@ }, success: function(response) { if (response.success) { - window.location.href = - '{{ route('surveyor.show', ['id' => $permohonan->id]) }}?form=foto'; + // window.location.href = + // '{{ route('surveyor.show', ['id' => $permohonan->id]) }}?form=foto'; toastrSuccessBuild(response.message); } + console.log(response); + }, error: function(xhr, status, error) { diff --git a/resources/views/surveyor/components/header.blade.php b/resources/views/surveyor/components/header.blade.php index e545f91..4674a06 100644 --- a/resources/views/surveyor/components/header.blade.php +++ b/resources/views/surveyor/components/header.blade.php @@ -1,17 +1,16 @@
- +
+

+ Form Inspeksi +

+ +
@@ -109,6 +108,7 @@ @if (isset($permohonan->debiture->documents)) @foreach ($permohonan->debiture->documents as $item)

{{ $item->jenisJaminan->name }}

+ @endforeach @endif
@@ -117,19 +117,18 @@ -
+ style="{{ isset($forminspeksi['asset']['jenis_asset']['tidak sesuai']) ? '' : 'display: none;' }}"> + {{ old('jenis_asset', isset($forminspeksi['asset']['alamat']['sesuai'])) ? 'checked' : '' }}> Ya
@@ -185,7 +184,7 @@
{{-- Alamat Sesuai --}} -