From ee079a8aa84a137494c1a50dda489a0e1c26f6d2 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 11 Sep 2025 09:44:35 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(surveyor):=20perbaiki=20fung?= =?UTF-8?q?si=20calculateTotalLuas=20untuk=20mendukung=20format=20koma=20d?= =?UTF-8?q?esimal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Menambahkan logika menghapus format ribuan (titik) sebelum perhitungan luas. - Mengonversi koma menjadi titik untuk parsing **float** dengan benar. - Menggunakan **toLocaleString('id-ID')** untuk hasil sesuai format Indonesia. - Mendukung input angka dengan format Indonesia dan internasional. --- .../views/surveyor/components/denah.blade.php | 94 +++++++++++-------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/resources/views/surveyor/components/denah.blade.php b/resources/views/surveyor/components/denah.blade.php index deb149d..88bfad9 100644 --- a/resources/views/surveyor/components/denah.blade.php +++ b/resources/views/surveyor/components/denah.blade.php @@ -15,11 +15,11 @@ @include('lpj::assetsku.includenya') -
-
+
+

Denah

-
+
Back @@ -41,13 +41,13 @@
@if (isset($formDenah['denahs']) && is_array($formDenah['denahs']) && count($formDenah['denahs']) > 0) @foreach ($formDenah['denahs'] as $index => $denah) -
+
-
+
-
+
@if (isset($denah['foto_denah'])) @@ -68,9 +68,9 @@ @endif
-
+
@@ -78,26 +78,26 @@
-
+
-
+
-
-
+
@@ -115,45 +115,45 @@ @endforeach @else -
+
-
+
-
+
-
+
-
+
-
+
- +
-
+
-
@@ -164,18 +164,19 @@
-
+
-
+
- +
-
+
@@ -240,23 +241,38 @@ }); }); + /** + * Menghitung total luas dari semua input denah + * Mendukung format angka dengan koma sebagai pemisah desimal + * dan menghapus format ribuan (titik) sebelum perhitungan + */ function calculateTotalLuas() { let totalLuas = 0; const luasInputs = document.querySelectorAll('input[name="luas_denah[]"]'); luasInputs.forEach(input => { - const value = parseFloat(input.value.replace(/[^0-9.]/g, '')); + // Hapus format ribuan (titik) dan spasi + let cleanValue = input.value.replace(/\./g, '').replace(/\s/g, ''); + + // Ganti koma dengan titik untuk desimal + cleanValue = cleanValue.replace(',', '.'); + + // Parse ke float + const value = parseFloat(cleanValue); if (!isNaN(value)) { totalLuas += value; } }); const totalLuasInput = document.getElementById('totalLuas'); - totalLuasInput.value = totalLuas ? `${totalLuas.toLocaleString()} m²` : ''; + totalLuasInput.value = totalLuas ? `${totalLuas.toLocaleString('id-ID')} m²` : ''; + + // Log untuk debugging + console.log('Total luas dihitung:', totalLuas); } // Tambahkan event listener untuk setiap input luas_denah[] - document.addEventListener('input', function (e) { + document.addEventListener('input', function(e) { if (e.target && e.target.name === 'luas_denah[]') { calculateTotalLuas(); } @@ -271,17 +287,17 @@ denahItem.className = 'denah-item grid gap-5 mb-5 border p-4 rounded'; denahItem.innerHTML = `
-
+
-
+
-
+
@@ -289,25 +305,25 @@
-
+
-
+
- +
-
+