From 3ba43b8579f527f4b2992eb6bf427e7c6fd89bfb Mon Sep 17 00:00:00 2001 From: majid Date: Tue, 4 Mar 2025 09:36:15 +0700 Subject: [PATCH] fix(surveyor): perbaikan luas tanah, bangunan, unit not found --- app/Http/Controllers/SurveyorController.php | 27 +++++-- resources/views/laporan/index.blade.php | 11 +-- .../components/apartemen-kantor.blade.php | 34 +++++---- .../surveyor/components/bangunan.blade.php | 6 ++ .../views/surveyor/components/tanah.blade.php | 6 ++ resources/views/surveyor/js/utils.blade.php | 71 +++++++++++-------- 6 files changed, 105 insertions(+), 50 deletions(-) diff --git a/app/Http/Controllers/SurveyorController.php b/app/Http/Controllers/SurveyorController.php index 0164cc4..01076f5 100644 --- a/app/Http/Controllers/SurveyorController.php +++ b/app/Http/Controllers/SurveyorController.php @@ -2007,7 +2007,21 @@ class SurveyorController extends Controller 'analisa_unit' => 'luas_unit', }; - $this->updateDetails($permohonan, $key, $request->input($key)); + + $jenis_jaminan_mapping = [ + 'luas_unit' => $request->input('jenis_legalistas_jaminan_unit_id'), + 'luas_bangunan' => $request->input('jenis_legalistas_jaminan_bangunan_id'), + 'luas_tanah' => $request->input('jenis_legalistas_jaminan_tanah_id'), + ]; + + + $jenis_jaminan_id = $jenis_jaminan_mapping[$key] ?? 0; + // dd($jenis_jaminan_id); + + $inputValue = $request->input($key); + + $cleanedValue = preg_replace('/\D/', '', $inputValue); + $this->updateDetails($permohonan, $key, $cleanedValue, $jenis_jaminan_id); } return response()->json([ @@ -2031,7 +2045,7 @@ class SurveyorController extends Controller ]); } - private function updateDetails($permohonan, $key, $newValue) + private function updateDetails($permohonan, $key, $newValue, $jenis_jaminan_id) { $document = $permohonan->documents->first(); @@ -2039,7 +2053,12 @@ class SurveyorController extends Controller throw new \Exception("Document not found"); } - $detailsUpdate = DetailDokumenJaminan::where('dokumen_jaminan_id', $document->id)->first(); + // dd($jenis_jaminan_id); + $detailsUpdate = DetailDokumenJaminan::where('dokumen_jaminan_id', $document->id) + ->where('jenis_legalitas_jaminan_id', $jenis_jaminan_id) + ->first(); + + // dd($detailsUpdate); if (!$detailsUpdate) { throw new \Exception("DetailDokumenJaminan not found"); @@ -2055,7 +2074,7 @@ class SurveyorController extends Controller if (array_key_exists($key, $datas)) { $datas[$key] = $newValue; } else { - throw new \Exception("Key '{$key}' not found in details"); + $datas[$key] = $newValue; } // Simpan kembali ke database diff --git a/resources/views/laporan/index.blade.php b/resources/views/laporan/index.blade.php index de09784..788f865 100644 --- a/resources/views/laporan/index.blade.php +++ b/resources/views/laporan/index.blade.php @@ -194,6 +194,8 @@ let laporanButton = ''; let resumeButton = ''; + + if(data.penilai.resume) { resumeButton = ` @@ -203,7 +205,7 @@ if(data.nilai_liquidasi==null) { laporanButton = ` - + Laporan `; } @@ -211,19 +213,20 @@ if(data.status_bayar=="sudah_bayar" && data.nilai_liquidasi >0) { if(data.penilai.type_penilai=='resume' && !data.penilai.resume){ laporanButton = ` - + Laporan `; } else { laporanButton = ` - + Laporan `; } } - return `${resumeButton} ${laporanButton}`; + + return `
${resumeButton} ${laporanButton}
`; }, } }, diff --git a/resources/views/surveyor/components/apartemen-kantor.blade.php b/resources/views/surveyor/components/apartemen-kantor.blade.php index effaaf2..3529e98 100644 --- a/resources/views/surveyor/components/apartemen-kantor.blade.php +++ b/resources/views/surveyor/components/apartemen-kantor.blade.php @@ -12,22 +12,28 @@ @if (isset($permohonan->documents)) @foreach ($permohonan->documents as $item) - @php - $luas_units = 'N/A'; - if ($item->detail) { - foreach ($item->detail as $luas) { - if (isset($luas->name) && $luas->name === 'Sertifikat') { - $details = json_decode($luas->details, true); - $luas_units = isset($details['luas_tanah']) ? $details['luas_tanah'] : 'N/A'; - break; - } - } + @php + $luas_tanah = 0; + $jenis_legalitas_jaminan_id = 0; + if ($item->detail) { + foreach ($item->detail as $luas) { + if (isset($luas->name) && $luas->jenis_legalitas_jaminan_id === 1) { + $jenis_legalitas_jaminan_id = $luas->jenis_legalitas_jaminan_id; + $details = json_decode($luas->details, true); + $luas_tanah = isset($details['luas_tanah']) ? $details['luas_tanah'] : 0; + break; } - @endphp - -

{{ $luas_units }} m2

- @endforeach + } + } + @endphp + + +

{{ $luas_tanah }} m2

+ @endforeach @endif
diff --git a/resources/views/surveyor/components/bangunan.blade.php b/resources/views/surveyor/components/bangunan.blade.php index 000dfb4..e10405a 100644 --- a/resources/views/surveyor/components/bangunan.blade.php +++ b/resources/views/surveyor/components/bangunan.blade.php @@ -14,9 +14,11 @@ @foreach ($permohonan->documents as $item) @php $luas_bangunan = 0; + $jenis_legalitas_jaminan_id = 0; if ($item->detail) { foreach ($item->detail as $luas) { if (isset($luas->name) && $luas->jenis_legalitas_jaminan_id === 10) { + $jenis_legalitas_jaminan_id = $luas->jenis_legalitas_jaminan_id; $details = json_decode($luas->details, true); $luas_bangunan = isset($details['luas_bangunan']) ? $details['luas_bangunan'] : 0; break; @@ -25,6 +27,10 @@ } @endphp +

{{ $luas_bangunan }} m2

@endforeach diff --git a/resources/views/surveyor/components/tanah.blade.php b/resources/views/surveyor/components/tanah.blade.php index 8d631fd..84409ec 100644 --- a/resources/views/surveyor/components/tanah.blade.php +++ b/resources/views/surveyor/components/tanah.blade.php @@ -14,9 +14,11 @@ @foreach ($permohonan->documents as $item) @php $luas_tanah = 0; + $jenis_legalitas_jaminan_id = 0; if ($item->detail) { foreach ($item->detail as $luas) { if (isset($luas->name) && $luas->jenis_legalitas_jaminan_id === 1) { + $jenis_legalitas_jaminan_id = $luas->jenis_legalitas_jaminan_id; $details = json_decode($luas->details, true); $luas_tanah = isset($details['luas_tanah']) ? $details['luas_tanah'] : 0; break; @@ -24,6 +26,10 @@ } } @endphp +

{{ $luas_tanah }} m2

@endforeach diff --git a/resources/views/surveyor/js/utils.blade.php b/resources/views/surveyor/js/utils.blade.php index ff4a2a7..ebcba62 100644 --- a/resources/views/surveyor/js/utils.blade.php +++ b/resources/views/surveyor/js/utils.blade.php @@ -27,39 +27,39 @@ function formatNumber(input) { - // Ambil posisi kursor saat ini - const cursorPosition = input.selectionStart; + // Ambil posisi kursor saat ini + const cursorPosition = input.selectionStart; - // Ambil nilai input tanpa "m²" dan karakter non-angka - let value = input.value.replace(/[^\d]/g, ''); + // Ambil nilai input tanpa "m²" dan karakter non-angka + let value = input.value.replace(/[^\d]/g, ''); - // Update nilai input dengan format angka dan "m²" - input.value = value ? value + ' m²' : 'm²'; + // Update nilai input dengan format angka dan "m²" + input.value = value ? value + ' m²' : 'm²'; - // Atur posisi kursor di depan "m²" - input.setSelectionRange(cursorPosition, cursorPosition); -} + // Atur posisi kursor di depan "m²" + input.setSelectionRange(cursorPosition, cursorPosition); + } function formatCurrency(value, isDiskon = false) { - // Ensure the value is a valid number - const numericValue = parseFloat(value); - if (isNaN(numericValue)) { - return 0; + // Ensure the value is a valid number + const numericValue = parseFloat(value); + if (isNaN(numericValue)) { + return 0; + } + + // Format the number with commas for thousands separators + const formattedValue = numericValue.toLocaleString('id-ID', { + style: 'currency', + currency: 'IDR', // Indonesian Rupiah + minimumFractionDigits: isDiskon ? 2 : 0, // Include decimals for discounts + maximumFractionDigits: isDiskon ? 2 : 0, + }); + + return formattedValue; } - // Format the number with commas for thousands separators - const formattedValue = numericValue.toLocaleString('id-ID', { - style: 'currency', - currency: 'IDR', // Indonesian Rupiah - minimumFractionDigits: isDiskon ? 2 : 0, // Include decimals for discounts - maximumFractionDigits: isDiskon ? 2 : 0, - }); - - return formattedValue; -} - function previewImage(input, previewId) { if (input.files && input.files[0]) { var reader = new FileReader(); @@ -352,9 +352,24 @@ const inputValue = document.getElementById(inputMap[params]).value; const data = { [params === 'jenis_asset' ? 'jenis_asset' : params.replace('analisa_', 'luas_')]: inputValue, - types: params + types: params, + ...(document.getElementById('jenis_legalistas_jaminan_bangunan_id') && { + jenis_legalistas_jaminan_bangunan_id: document.getElementById( + 'jenis_legalistas_jaminan_bangunan_id').value + }), + ...(document.getElementById('jenis_legalistas_jaminan_tanah_id') && { + jenis_legalistas_jaminan_tanah_id: document.getElementById('jenis_legalistas_jaminan_tanah_id') + .value + }), + ...(document.getElementById('jenis_legalistas_jaminan_unit_id') && { + jenis_legalistas_jaminan_unit_id: document.getElementById('jenis_legalistas_jaminan_unit_id') + .value + }) }; + console.log(data); + + $.ajax({ url: '{{ route('surveyor.update_analisa', ['id' => $permohonan->id]) }}', type: 'POST', @@ -505,9 +520,9 @@ function handleCurrencyInput(input) { - const value = input.value.replace(/[^\d]/g, ''); - input.value = formatCurrency(value); - } + const value = input.value.replace(/[^\d]/g, ''); + input.value = formatCurrency(value); + } function cleanCurrencyValue(value) { return value.replace(/[^\d]/g, '');