diff --git a/app/Http/Controllers/KJPPController.php b/app/Http/Controllers/KJPPController.php index 3a1b1c7..48eb5fc 100644 --- a/app/Http/Controllers/KJPPController.php +++ b/app/Http/Controllers/KJPPController.php @@ -521,7 +521,7 @@ class KJPPController extends Controller $filteredRecords = $query->count(); // Get the data for the current page - $data = $query->get(); + $data = $query->with('city')->get(); // Calculate the page count $pageCount = ceil($totalRecords / $request->get('size')); diff --git a/app/Http/Controllers/PenilaiController.php b/app/Http/Controllers/PenilaiController.php index 4583dcd..f6e7588 100644 --- a/app/Http/Controllers/PenilaiController.php +++ b/app/Http/Controllers/PenilaiController.php @@ -9,7 +9,7 @@ use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Facades\Excel; use Modules\Lpj\Exports\KertasKerjaExport; -use App\Http\Controllers\SurveyorController; +use Modules\Lpj\Http\Controllers\SurveyorController; class PenilaiController extends Controller { @@ -62,22 +62,42 @@ class PenilaiController extends Controller $basicData = $data->getCommonData(); $permohonan = Permohonan::with(['debiture.documents.jenisjaminan', 'region.teams.teamsUsers.user', 'penilaian'])->find($id); - return view('lpj::penilai.components.lpj-sederhana-standard', compact('permohonan', 'basicData')); + $jaminanId = $permohonan->debiture->documents->first()->jenis_jaminan_id; + $inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); + $forminspeksi = null; + if ($inpeksi) { + $forminspeksi = json_decode($inpeksi->data_form, true); + } + return view('lpj::penilai.components.lpj-sederhana-standard', compact('permohonan', 'basicData', 'forminspeksi')); } public function standard($id) { $permohonan = Permohonan::with(['debiture.documents.jenisjaminan', 'region.teams.teamsUsers.user', 'penilaian'])->find($id); - return view('lpj::penilai.components.lpj-sederhana-standard', compact('permohonan')); + + $jaminanId = $permohonan->debiture->documents->first()->jenis_jaminan_id; + + $inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); + $forminspeksi = null; + if ($inpeksi) { + $forminspeksi = json_decode($inpeksi->data_form, true); + } + + $data = new SurveyorController(); + $basicData = $data->getCommonData(); + + return view('lpj::penilai.components.lpj-sederhana-standard', compact('permohonan', 'forminspeksi', 'basicData')); } - public function resume(){ + public function resume() + { return view('lpj::resume.index'); } - public function memo(){ + public function memo() + { return view('lpj::resume.index'); - } + } /** diff --git a/app/Http/Controllers/SurveyorController.php b/app/Http/Controllers/SurveyorController.php index 200e871..445e095 100644 --- a/app/Http/Controllers/SurveyorController.php +++ b/app/Http/Controllers/SurveyorController.php @@ -189,36 +189,36 @@ class SurveyorController extends Controller 'lingkungan' => 'getLingkunganData', 'fakta' => 'getFactData' ]; - + $rules = []; $hasAssetDescriptionRules = false; - + $pisah = array_filter( - explode(',', $action), + explode(',', $action), function($act) use ($allowedActions) { return isset($allowedActions[trim($act)]); } ); - + foreach ($pisah as $act) { $act = trim($act); $method = $allowedActions[$act]; - + $actionRules = $this->$method($data, $request); $rules = array_merge($rules, $actionRules); - + if (in_array($act, ['apartemen-kantor', 'tanah', 'bangunan'])) { $hasAssetDescriptionRules = true; } } - + if ($hasAssetDescriptionRules) { $rules = array_merge($rules, $this->getAssetData($data)); } - + return $rules; } - + public function storeDenah(Request $request) { @@ -234,7 +234,7 @@ class SurveyorController extends Controller $maxSize = getMaxFileSize('Foto'); $validationRules['foto_denah'] = 'file|mimes:jpeg,jpg,png,pdf,svg|max:'. $maxSize; } - + $validatedData = $request->validate($validationRules); $formatJsonDenah = [ @@ -252,7 +252,7 @@ class SurveyorController extends Controller if ($inspeksi) { $existingDenah = json_decode($inspeksi->denah_form, true) ?? []; - + $updatedDenah = array_merge($existingDenah, $formatJsonDenah); $inspeksi->update([ @@ -555,7 +555,7 @@ class SurveyorController extends Controller $penilaian->update([ 'authorized_status' => 1, ]); - + $data['status'] = 'success'; $data['message']= 'Jadwal '.$request->noReg.' berhasil di aprove'; } catch (\Exception $e) { @@ -591,7 +591,7 @@ class SurveyorController extends Controller ->first(); if ($inspeksi) { - $existingData = $inspeksi->data_pembanding ?? []; + $existingData = json_decode($inspeksi->data_pembanding, true) ?? []; } } @@ -600,8 +600,8 @@ class SurveyorController extends Controller $existingFoto = null; - if ($existingData && isset($existingData[$i]['foto_objek'])) { - $existingFoto = $existingData[$i]['foto_objek']; + if ($existingData && isset($existingData['data_pembanding'][$i]['foto_objek'])) { + $existingFoto = $existingData['data_pembanding'][$i]['foto_objek']; } // Penanganan foto pembanding @@ -620,8 +620,8 @@ class SurveyorController extends Controller return $dataPembanding; } - - + + private function formatSinglePembanding($request, $index) { $fields = [ @@ -631,12 +631,12 @@ class SurveyorController extends Controller 'peruntukan', 'penawaran_transaksi', 'nomor_tlp', 'kordinat_lat', 'kordinat_lng', 'jenis_aset','foto_objek' ]; - + $pembanding = []; foreach ($fields as $field) { $inputName = "{$field}_pembanding"; $inputValue = $request->input($inputName); - + // Pastikan input adalah array dan index valid if (is_array($inputValue) && isset($inputValue[$index])) { $pembanding[$field] = $inputValue[$index]; @@ -645,10 +645,10 @@ class SurveyorController extends Controller } } - + return $pembanding; } - + private function handleupdateOrDeleteFile($file, $type, $prefix) @@ -680,54 +680,54 @@ class SurveyorController extends Controller 'status_nara_sumber', 'harga', 'nama_nara_sumber', 'kordinat_lat', 'kordinat_lng', 'jenis_aset', ]; - + $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id')) ->where('jenis_jaminan_id', $request->input('jenis_jaminan_id')) ->first(); - + if ($inspeksi) { $needsSave = false; - + // Handle foto_form $fotoForm = json_decode($inspeksi->foto_form, true) ?: []; if (!isset($fotoForm['object_jaminan'])) { $fotoForm['object_jaminan'] = [['foto_objek' => null]]; $needsSave = true; } - + // Handle data_form $dataForm = json_decode($inspeksi->data_form, true) ?: []; - + // Inisialisasi struktur data jika belum ada if(!isset($dataForm['bangunan'])) { $dataForm['bangunan'] = []; $needsSave = true; } - + if(!isset($dataForm['tanah'])) { $dataForm['tanah'] = []; $needsSave = true; } - + if (!isset($dataForm['asset'])) { $dataForm['asset'] = []; $needsSave = true; } - + // Update data dengan mempertahankan struktur sesuai/tidak sesuai foreach ($fields as $field) { if ($request->filled($field)) { $newValue = $request->input($field); - + // Fields untuk tanah if (in_array($field, ['luas_tanah'])) { - $cekLuas = $dataForm['tanah']['luas_tanah'] == 'sesuai' ? 'sesuai' : 'tidak sesuai'; + $cekLuas = $dataForm['tanah']['luas_tanah'] == 'sesuai' ? 'sesuai' : 'tidak sesuai'; $dataForm['tanah'][$field][$cekLuas] = $newValue; } // Fields untuk bangunan else if (in_array($field, ['luas_tanah_bagunan'])) { - $cekBanguan = $dataForm['bangunan']['luas_tanah_bagunan'] == 'sesuai' ? 'sesuai' : 'tidak sesuai'; + $cekBanguan = $dataForm['bangunan']['luas_tanah_bagunan'] == 'sesuai' ? 'sesuai' : 'tidak sesuai'; $dataForm['bangunan'][$field][$cekBanguan] = $newValue; } // Fields untuk alamat dalam asset @@ -736,12 +736,12 @@ class SurveyorController extends Controller if (!isset($dataForm['asset']['alamat'])) { $dataForm['asset']['alamat'] = []; } - + $alamatStatus = $dataForm['asset']['alamat'] == 'sesuai' ? 'sesuai' : 'tidak sesuai'; if (!isset($dataForm['asset']['alamat'][$alamatStatus])) { $dataForm['asset']['alamat'][$alamatStatus] = []; } - + $dataForm['asset']['alamat'][$alamatStatus][$field] = $newValue; } // Jenis asset dalam asset @@ -755,19 +755,19 @@ class SurveyorController extends Controller else { $dataForm['asset'][$field] = $newValue; } - + $needsSave = true; } } - + if ($needsSave) { $inspeksi->foto_form = json_encode($fotoForm); $inspeksi->data_form = json_encode($dataForm); $inspeksi->save(); } - + $existingFoto = $fotoForm['object_jaminan'][0]['foto_objek'] ?? null; - + // Gabungkan data dari tanah, bangunan, dan asset $objekPenilaian = array_merge( ['foto_objek' => $existingFoto], @@ -790,7 +790,7 @@ class SurveyorController extends Controller return $carry; }, []) ); - + } else { // Inisialisasi data baru $objekPenilaian = array_reduce($fields, function ($carry, $field) use ($request) { @@ -798,10 +798,10 @@ class SurveyorController extends Controller return $carry; }, ['foto_objek' => null]); } - + return $objekPenilaian; } - + private function saveInspeksi($formattedData) @@ -873,6 +873,7 @@ class SurveyorController extends Controller 'data_pembanding' => $this->formatDataPembanding($request) ]; + $inspeksi = $this->saveInspeksi($formattedData); DB::commit(); @@ -1041,7 +1042,6 @@ class SurveyorController extends Controller if (json_last_error() !== JSON_ERROR_NONE) { throw new \Exception('Error decoding comparison data: ' . json_last_error_msg()); } - } $fotoForm = json_decode($inspeksi->foto_form, true); @@ -1055,8 +1055,6 @@ class SurveyorController extends Controller $districts = District::where('city_code', $this->getCodeAlamat('city_code', $inspectionData))->get(); $villages = Village::where('district_code', $this->getCodeAlamat('district_code', $inspectionData))->get(); - - return view('lpj::surveyor.components.data-pembanding', compact( 'permohonan', 'id', @@ -1068,7 +1066,8 @@ class SurveyorController extends Controller 'cities', 'districts', 'villages', - 'provinces' + 'provinces', + 'inspeksi' )); } catch (\Exception $e) { @@ -1562,7 +1561,7 @@ class SurveyorController extends Controller - private function getCommonData() + public function getCommonData() { return [ 'branches' => Branch::all(), @@ -1809,11 +1808,9 @@ class SurveyorController extends Controller 'jarak_tps' => $data['jarak_tps'] ?? null, 'nama_tps' => $data['nama_tps'] ?? null, 'merupakan_daerah' => $data['merupakan_daerah'] ?? null, - 'fasilitas_dekat_object' => $this->getFieldData( - $data, - 'fasilitas_dekat_object', - false, - 'lainnya' + 'fasilitas_dekat_object' => $this->mapArrayWithInputs( + $data['fasilitas_dekat_object'] ?? [], + $data['fasilitas_dekat_object_input'] ?? [] ), ] ]; diff --git a/app/Http/Requests/FormSurveyorRequest.php b/app/Http/Requests/FormSurveyorRequest.php index 02c3d8a..fe19acf 100644 --- a/app/Http/Requests/FormSurveyorRequest.php +++ b/app/Http/Requests/FormSurveyorRequest.php @@ -76,7 +76,7 @@ class FormSurveyorRequest extends FormRequest 'hadap_mata_angin' => 'required', 'hadap_mata_angin_sesuai' => 'nullable', 'hadap_mata_angin_tidak_sesuai' => 'nullable', - 'bentuk_tanah' => 'nullable|array', + 'bentuk_tanah' => 'required|array', 'bentuk_tanah_lainnya' => 'nullable', 'kontur_tanah' => 'required|array', 'ketinggian_jalan' => 'required|array', @@ -102,8 +102,8 @@ class FormSurveyorRequest extends FormRequest 'luas_tanah_bangunan_sesuai' => 'nullable', 'luas_tanah_bagunan' => 'required', 'luas_tanah_bangunan_tidak_sesuai' => 'nullable', - 'jenis_bangunan' => 'required', - 'kondisi_bangunan' => 'nullable', + 'jenis_bangunan' => 'required|array', + 'kondisi_bangunan' => 'required|array', 'sifat_bangunan' => 'required|array', 'sifat_bangunan_input' => 'nullable|array', @@ -167,7 +167,7 @@ class FormSurveyorRequest extends FormRequest 'nama_tpu' => 'nullable', 'merupakan_daerah' => 'nullable', 'fasilitas_dekat_object' => 'nullable|array', - 'fasilitas_dekat_object_lainnya' => 'nullable', + 'fasilitas_dekat_object_input' => 'nullable|array', ]; } diff --git a/app/Models/KJPP.php b/app/Models/KJPP.php index a558797..30ade6c 100644 --- a/app/Models/KJPP.php +++ b/app/Models/KJPP.php @@ -2,7 +2,7 @@ namespace Modules\Lpj\Models; -use Modules\Location\Models\Province; +use Modules\Location\Models\City; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -25,4 +25,12 @@ class KJPP extends Model { return $this->hasMany(PenawaranDetailTender::class, 'kjpp_rekanan_id', 'id'); } + + public function city() + { + return $this->belongsTo(City::class, 'city_code', 'code'); + } + + + } diff --git a/resources/views/kjpp/index.blade.php b/resources/views/kjpp/index.blade.php index efb272b..4496fa4 100644 --- a/resources/views/kjpp/index.blade.php +++ b/resources/views/kjpp/index.blade.php @@ -48,6 +48,14 @@ Jenis Kantor + + Kota/Kabupaten + + + + Alamat + + Action @@ -131,6 +139,15 @@ jenis_kantor: { title: 'Jenis Kantor', }, + city: { + title: 'Kota/Kabupaten', + render: (item, data) => { + return data.city.name; + } + }, + address: { + title: 'Alamat KJPP', + }, actions: { title: 'Action', render: (item, data) => { diff --git a/resources/views/surveyor/components/bangunan.blade.php b/resources/views/surveyor/components/bangunan.blade.php index 9cc8e9d..6102d4f 100644 --- a/resources/views/surveyor/components/bangunan.blade.php +++ b/resources/views/surveyor/components/bangunan.blade.php @@ -22,7 +22,7 @@ @endforeach @endif -
+
diff --git a/resources/views/surveyor/components/tanah.blade.php b/resources/views/surveyor/components/tanah.blade.php index 751578e..03b2512 100644 --- a/resources/views/surveyor/components/tanah.blade.php +++ b/resources/views/surveyor/components/tanah.blade.php @@ -24,7 +24,7 @@ @endforeach @endif
-
+
-
+
diff --git a/resources/views/surveyor/js/utils.blade.php b/resources/views/surveyor/js/utils.blade.php index 61fbe17..3bffc19 100644 --- a/resources/views/surveyor/js/utils.blade.php +++ b/resources/views/surveyor/js/utils.blade.php @@ -32,7 +32,7 @@ input.value = value; } - + function formatCurrency(value) { if (!value) return ''; @@ -52,4 +52,119 @@ return formattedValue; } + + function previewImage(input, previewId) { + if (input.files && input.files[0]) { + var reader = new FileReader(); + reader.onload = function(e) { + $('#' + previewId).attr('src', e.target.result).show(); + } + reader.readAsDataURL(input.files[0]); + } else { + $('#' + previewId).hide(); + } + } + + function addClonableItem(containerId, itemClass) { + const container = document.getElementById(containerId); + if (!container) { + console.error(`Container with ID "${containerId}" not found.`); + return; + } + + const template = container.querySelector(`.${itemClass}`); + if (!template) { + console.error(`Template with class "${itemClass}" not found in container "${containerId}".`); + return; + } + + // Clone the template element + const newElement = template.cloneNode(true); + + // Reset all input fields comprehensively + const inputs = newElement.querySelectorAll('input, select, textarea'); + inputs.forEach(input => { + // Reset based on input type + switch (input.type) { + case 'text': + case 'number': + case 'email': + case 'tel': + case 'password': + case 'search': + case 'url': + case 'textarea': + input.value = ''; + break; + case 'checkbox': + case 'radio': + input.checked = false; + break; + case 'select-one': + case 'select-multiple': + input.selectedIndex = 0; + break; + case 'file': + input.value = ''; + break; + } + + // Remove any error classes or validation states + input.classList.remove('is-invalid', 'error'); + + // Reset any custom attributes if needed + input.removeAttribute('data-previous-value'); + }); + + // Reset select elements to their default state + const selects = newElement.querySelectorAll('select'); + selects.forEach(select => { + select.selectedIndex = 0; + }); + + // Make the delete button visible and bind the click event + const deleteButton = newElement.querySelector('.remove-btn'); + if (deleteButton) { + deleteButton.style.display = 'inline-block'; + deleteButton.addEventListener('click', () => { + newElement.remove(); + }); + } + + // Reset any custom data attributes + newElement.querySelectorAll('[data-clone-reset]').forEach(element => { + const resetValue = element.getAttribute('data-clone-reset'); + if (resetValue) { + if (element.tagName === 'INPUT' || element.tagName === 'SELECT' || element.tagName === + 'TEXTAREA') { + element.value = resetValue; + } else { + element.textContent = resetValue; + } + } + }); + + // Optional: Regenerate unique IDs if needed + const elementsWithId = newElement.querySelectorAll('[id]'); + elementsWithId.forEach(element => { + const originalId = element.id; + const newId = `${originalId}_${Date.now()}`; + element.id = newId; + + // Update any labels or references + const labels = newElement.querySelectorAll(`label[for="${originalId}"]`); + labels.forEach(label => { + label.setAttribute('for', newId); + }); + }); + + // Append the cloned element to the container + container.appendChild(newElement); + + // Optional: Trigger any custom events or reinitialize plugins + const event = new Event('cloneAdded', { + bubbles: true + }); + newElement.dispatchEvent(event); + }